Fuchangle

来自Test
跳转至: 导航搜索

基本信息

  • 编号:GD05_SWV_003_005_001
  • 版本信息:V0.1
  • 维护人员:付长乐
  • 维护部门:软件五部

任务名称

在联系人列表后面添加同步图标(Google,facebook,skype...)

问题描述及问题原因

1.有些客制化需求会要求在从Google、facebook、skype等账户同步过来的联系人后面添加对应的icon图标显示

关键词

为联系人添加Google同步图标

工作指南

1.首先需要准备对应账户的icon放置到packages/app/ContactsCommon/res/下对应的drawable文件夹下


如图所示:


2. 修改代码:DefaultContactListAdapter.java
函数: protected void bindView(View itemView, int partition, Cursor cursor, int position)

在view.setExtentionIcon(pulginStatus, contactId);后添加代码
/*add by fuchangle*/

       Cursor cursor2 = getContext().getContentResolver().query(ContactsContract.RawContacts.CONTENT_URI,

new String[]{ContactsContract.RawContacts.ACCOUNT_NAME, ContactsContract.RawContacts.ACCOUNT_TYPE}, ContactsContract.RawContacts.CONTACT_ID +"=?", new String[]{String.valueOf(contactId)}, null);

       if (cursor2 != null && cursor2.getCount() >0){

cursor2.moveToFirst();

 //         account = new ContactAccount();
//          account.setAccountName(cursor2.getString(cursor2.getColumnIndex(ContactsContract.RawContacts.ACCOUNT_NAME)));

String accounttype = cursor2.getString(cursor2.getColumnIndex(ContactsContract.RawContacts.ACCOUNT_TYPE)); String googleaccount = "com.google"; Log.i("DefaultContactListAdapter accounttype", "============= " + String.valueOf(accounttype)+ "============"); if(accounttype.equals(googleaccount)){ view.setAcconticon(true, 0); }else if(accounttype.indexOf("com.facebook")!= -1){ view.setAcconticon(true, 1); }else if(accounttype.indexOf("whatsapp")!= -1){ view.setAcconticon(true, 2); }else if(accounttype.indexOf("skype")!= -1){ view.setAcconticon(true, 3); }else{ view.setAcconticon(false,4); } cursor2.close(); }else{ view.setAcconticon(false,3); } /*add by fuchangle end*/ 以上添加的代码主要是通过遍历联系人数据库来获取哪些联系人是通过数据账户同步到联系人列表的,然后通过联系人ContactsContract.RawContacts.ACCOUNT_TYPE 这个属性来判断属于哪种账户,从而达到显示相对应的图标目的

3. 修改ContactListItemView.java
3.1在文件最后面添加以下自定义代码:
/*add by fuchangle*/ private ImageView mAccounIcon; private static int[]accounticon = { R.drawable.google_syn, R.drawable.facebook_syn, R.drawable.whatsapp_syn, R.drawable.skype_syn, };

    public void setAcconticon(boolean enable, int resid) {
       if (enable) {
           if (mAccounIcon == null) {
               getAcconticon(resid);
           }
           mAccounIcon.setVisibility(View.VISIBLE);
       } else {
           if (mAccounIcon != null) {
               mAccounIcon.setVisibility(View.GONE);
           }
       }
   }


   public void getAcconticon(int resid) {
       if (mAccounIcon == null){
           mAccounIcon = new ImageView(mContext);
       }
       mAccounIcon.setBackgroundDrawable(null);
       mAccounIcon.setImageResource(accounticon[resid]);
       addView(mAccounIcon);
   }

/*add by fuchangle end*/


3.2 在protected void onLayout(boolean changed, int left, int top, int right, int bottom)函数中添加图标的显示位置
在条件if (mPhotoPosition == PhotoPosition.LEFT) {

        // Photo is the left most view. All the other Views should on the right of the photo.
        if (photoView != null) {
          .....
          .....

加入代码

   /*add by fchangle*/

if(mAccounIcon != null){ mAccounIcon.layout( rightBound - mPhotoViewWidth/2, photoTop + mPhotoViewHeight/4, rightBound, photoTop + mPhotoViewHeight*3/4); }

    /*add by fchangle end*/
}else if(mKeepHorizontalPaddingForPhotoView){
   ......

}

==注意事项==

软件类