Android中删除常用联系人(下)
16lz
2022-01-09
添加移除常用联系功能,需要修改的另外一个应用程序是com.android.contacts。 在MTK6575平台上,需要修改的文件有:
modified : packages / apps / Contacts / src / com / android / contacts / activities / DialtactsActivity . java modified : packages / apps / Contacts / src / com / android / contacts / activities / PeopleActivity . java modified : packages / apps / Contacts / src / com / android / contacts / group / GroupDetailFragment . java modified : packages / apps / Contacts / src / com / android / contacts / list / ContactTileAdapter . java modified : packages / apps / Contacts / src / com / android / contacts / list / ContactTileListFragment . java modified : packages / apps / Contacts / src / com / android / contacts / list / ContactTileView . java modified : packages / apps / Contacts / src / com / android / contacts / list / PhoneFavoriteFragment . java modified : packages / apps / Contacts / res / values - zh - rCN / strings . xml modified : packages / apps / Contacts / res / values - zh - rTW / strings . xml modified : packages / apps / Contacts / res / values / strings . xml文件packages/apps/Contacts/src/com/android/contacts/activities/DialtactsActivity.java的主要修改如下:
@@ - 935 , 17 + 939 , 95 @@ public class DialtactsActivity extends TransactionSafeActivity implements Provid enterSearchUi (); } }; - + /*robin_20120509*/ private PhoneFavoriteFragment . Listener mPhoneFavoriteListener = new PhoneFavoriteFragment . Listener () { @Override - public void onContactSelected ( Uri contactUri ) { + public void onContactClick ( Uri contactUri ) { PhoneNumberInteraction . startInteractionForPhoneCall ( DialtactsActivity . this , contactUri , CALL_ORIGIN_DIALTACTS ); } + @Override + public boolean onContactLongClick ( Uri contactUri , int type ) { + if ( type == ViewTypes . FREQUENT ) + { + final Uri contactLookUpUri = contactUri ; + Runnable r = new Runnable (){ + + @Override + public void run () { + removeFrequentContact ( contactLookUpUri ); + }}; + showRemoveFrequentContactAlertDialog ( r ); + return true ; + } + return false ; + } }; + Handler handler = new Handler (); + IContentProvider mContentProvider ; + final static String ContactsProvider_CALL_METHOD_UPDATE_FAKE_TIMES_USED = "CALL_METHOD_update_FAKE_TIMES_USED_Stat" ; + void removeFrequentContact ( Uri contactUri ) + { + IContentProvider cp = null ; + synchronized ( this ) { + cp = mContentProvider ; + if ( cp == null ) { + cp = mContentProvider = getContentResolver (). acquireProvider ( ContactsContract . AUTHORITY ); + } + } + try { + Bundle bundle = new Bundle (); + bundle . putString ( "Uri" , contactUri . toString ()); + Bundle b = cp . call ( ContactsProvider_CALL_METHOD_UPDATE_FAKE_TIMES_USED , "" , bundle ); + if ( b != null ) { + int v = b . getInt ( "count" , 0 ); + if ( v > 0 ) + { + Toast . makeText ( this , R . string . remove_frequent_contact_succes , Toast . LENGTH_SHORT ). show (); + return ; + } + } + Toast . makeText ( this , R . string . remove_frequent_contact_fail , Toast . LENGTH_SHORT ). show (); + // If the response Bundle is null, we fall through + // to the query interface below. + } catch (RemoteException e) { + Log.w(TAG, "", e); + // Not supported by the remote side? Fall through + // to query(). + } + } + +AlertDialog removeFrequentContactAlertDialog; +void showRemoveFrequentContactAlertDialog(final Runnable runnable) +{ + AlertDialog.Builder dialogBuilder=new AlertDialog.Builder(this); + dialogBuilder.setMessage(R.string.remove_frequent_contact_alert); + dialogBuilder.setCancelable(true); + DialogInterface.OnClickListener negativeListener=new DialogInterface.OnClickListener(){ + + @Override + public void onClick(DialogInterface arg0, int arg1) { + + }}; + DialogInterface.OnClickListener positiveListener=new DialogInterface.OnClickListener(){ + @Override + public void onClick(DialogInterface arg0, int arg1) { + handler.post(runnable); + + } + }; + dialogBuilder.setNegativeButton(android.R.string.cancel, negativeListener); + dialogBuilder.setPositiveButton(android.R.string.ok, positiveListener); + removeFrequentContactAlertDialog=dialogBuilder.create(); + removeFrequentContactAlertDialog.show(); +} +/*robin_20120509*/文件packages/apps/Contacts/src/com/android/contacts/activities/PeopleActivity.java的主要修改如下:
@@ - 1340 , 19 + 1345 , 97 @@ public class PeopleActivity extends ContactsActivity startActivity ( new Intent ( Settings . ACTION_MANAGE_APPLICATIONS_SETTINGS )); } } - + /*[robin_20120509*/ private final class StrequentContactListFragmentListener implements ContactTileListFragment . Listener { @Override - public void onContactSelected ( Uri contactUri , Rect targetRect ) { + public void onContactClick ( Uri contactUri , Rect targetRect ) { if ( PhoneCapabilityTester . isUsingTwoPanes ( PeopleActivity . this )) { QuickContact . showQuickContact ( PeopleActivity . this , targetRect , contactUri , 0 , null ); } else { startActivity ( new Intent ( Intent . ACTION_VIEW , contactUri )); } } + @Override + public boolean onContactLongClick ( Uri contactUri , Rect targetRect , int type ) { + if ( type == ViewTypes . FREQUENT ) + { + final Uri contactLookUpUri = contactUri ; + Runnable r = new Runnable (){ + + @Override + public void run () { + // TODO Auto-generated method stub + removeFrequentContact(contactLookUpUri); + }}; + showRemoveFrequentContactAlertDialog(r); + return true; + } + return false; + } + } + Handler handler=new Handler(); + IContentProvider mContentProvider; + final static String ContactsProvider_CALL_METHOD_UPDATE_FAKE_TIMES_USED="CALL_METHOD_update_FAKE_TIMES_USED_Stat"; + void removeFrequentContact(Uri contactUri) + { + IContentProvider cp = null; + synchronized (this) { + cp = mContentProvider; + if (cp == null) { + cp = mContentProvider =getContentResolver().acquireProvider(ContactsContract.AUTHORITY); + } + } + try { + Bundle bundle=new Bundle(); + bundle.putString("Uri", contactUri.toString()); + Bundle b = cp.call(ContactsProvider_CALL_METHOD_UPDATE_FAKE_TIMES_USED, "ID_TYPE_CONTACT", bundle); + if (b != null) { + int v = b.getInt("count",0); + if(v>0) + { + Toast.makeText(this, R.string.remove_frequent_contact_succes, Toast.LENGTH_SHORT).show(); + return; + } + } + Toast.makeText(this, R.string.remove_frequent_contact_fail, Toast.LENGTH_SHORT).show(); + /* If the response Bundle is null, we fall through + to the query interface below.*/ + } catch (RemoteException e) { + Log.w(TAG, "", e); + /** Not supported by the remote side? Fall through + to query().*/ + } } +AlertDialog removeFrequentContactAlertDialog; +void showRemoveFrequentContactAlertDialog(final Runnable runnable) +{ + AlertDialog.Builder dialogBuilder=new AlertDialog.Builder(this); + dialogBuilder.setMessage(R.string.remove_frequent_contact_alert); + dialogBuilder.setCancelable(true); + DialogInterface.OnClickListener negativeListener=new DialogInterface.OnClickListener(){ + + @Override + public void onClick(DialogInterface arg0, int arg1) { + /* TODO Auto-generated method stub*/ + + }}; + DialogInterface.OnClickListener positiveListener=new DialogInterface.OnClickListener(){ + + @Override + public void onClick(DialogInterface arg0, int arg1) { + /* TODO Auto-generated method stub*/ + handler.post(runnable); + + } + }; + dialogBuilder.setNegativeButton(android.R.string.cancel, negativeListener); + dialogBuilder.setPositiveButton(android.R.string.ok, positiveListener); + removeFrequentContactAlertDialog=dialogBuilder.create(); + removeFrequentContactAlertDialog.show(); +} +/*robin_20120509]*/ private final class GroupBrowserActionListener implements OnGroupBrowserActionListener {packages/apps/Contacts/src/com/android/contacts/calllog/CallLogAdapter.java文件修改如下
@@ - 398 , 7 + 398 , 18 @@ implements CallLogGroupBuilder . GroupCreator , OnScrollListener { if ( OperatorUtils . getOptrProperties (). equals ( "OP02" )) { contactInfo . photoId = ( slotId == 0 ) ? - 3 : - 4 ; } else { - contactInfo . photoId = SimCardUtils . isSimUsimType ( slotId ) ? - 2 : - 1 ; + // contactInfo.photoId = SimCardUtils.isSimUsimType(slotId) ? -2 : -1; + if(SimCardUtils.isSimUsimType(slotId)){ + if(slotId == 0) + contactInfo.photoId = -5; + else + contactInfo.photoId = -6; + }else{ + if(slotId == 0) + contactInfo.photoId = -7; + else + contactInfo.photoId = -8; + } } }文件packages/apps/Contacts/src/com/android/contacts/list/ContactTileAdapter.java的主要修改如下:
@@ - 276 , 12 + 277 , 20 @@ public class ContactTileAdapter extends BaseAdapter { } else { boolean isUsim = SimCardUtils . isSimUsimType ( slotId ); if ( isUsim ) { - Log . i ( TAG , "-----------usim" ); - contact . photoUri = Uri . parse ( "content://usim" ); + //Log.i(TAG, "-----------usim"); + //contact.photoUri = Uri.parse("content://usim"); + if(slotId == 0) + contact.photoUri = Uri.parse("content://usim1"); + else + contact.photoUri = Uri.parse("content://usim2"); } else { - Log.i(TAG, "-----------sim"); - contact.photoUri = Uri.parse("content://sim"); - } + //Log.i(TAG, "-----------sim"); + //contact.photoUri = Uri.parse("content://sim"); + if(slotId == 0) + contact.photoUri = Uri.parse("content://sim1"); + else + contact.photoUri = Uri.parse("content://sim2"); + } } /* * New feature by Mediatek End @@ -524,10 +533,28 @@ public class ContactTileAdapter extends BaseAdapter { @Override public void onClick(ContactTileView contactTileView) { if (mListener != null) { - mListener.onContactSelected(contactTileView.getLookupUri(), + mListener.onContactClick(contactTileView.getLookupUri(), ContactsUtils.getTargetRectFromView(mContext, contactTileView)); } } + /*robin_20120509*/ + @Override + public boolean onLongClick(ContactTileView contactTileView) { + ContactTileRow v=null; + int type=-1; + ViewParent p=contactTileView.getParent(); + if(p instanceof ContactTileRow) + { + v=(ContactTileRow)p; + type=v.getItemViewType(); + if (type==ViewTypes.FREQUENT&&mListener != null) { + return mListener.onContactLongClick(contactTileView.getLookupUri(), + ContactsUtils.getTargetRectFromView(mContext, contactTileView),type); + } + } + return false; + } + //robin_20120509] }; /** @@ -544,7 +571,10 @@ public class ContactTileAdapter extends BaseAdapter { mItemViewType = itemViewType; mLayoutResId = getLayoutResourceId(mItemViewType); } - + int getItemViewType() + { + return mItemViewType; + } /** * Configures the row to add {@link ContactEntry}s information to the views */ @@ -707,7 +737,7 @@ public class ContactTileAdapter extends BaseAdapter { public int indexSimOrPhone; } - private static class ViewTypes { + public static class ViewTypes { public static final int COUNT = 4; public static final int STARRED = 0; public static final int DIVIDER = 1; @@ -716,7 +746,8 @@ public class ContactTileAdapter extends BaseAdapter { } public interface Listener { - public void onContactSelected(Uri contactUri, Rect targetRect); + public void onContactClick(Uri contactUri, Rect targetRect); + public boolean onContactLongClick(Uri contactUri, Rect targetRect,int type); }文件apps/Contacts/src/com/android/contacts/list/ContactTileListFragment.java主要修改如下:
@@ - 56 , 7 + 56 , 8 @@ public class ContactTileListFragment extends Fragment { private static final String TAG = ContactTileListFragment . class . getSimpleName (); public interface Listener { - public void onContactSelected ( Uri contactUri , Rect targetRect ); + public void onContactClick ( Uri contactUri , Rect targetRect ); + public boolean onContactLongClick ( Uri contactUri , Rect targetRect , int type ); } private static int LOADER_CONTACTS = 1 ; @@ - 221 , 11 + 222 , 18 @@ public class ContactTileListFragment extends Fragment { private ContactTileAdapter . Listener mAdapterListener = new ContactTileAdapter . Listener () { @Override - public void onContactSelected ( Uri contactUri , Rect targetRect ) { + public void onContactClick ( Uri contactUri , Rect targetRect ) { if ( mListener != null ) { - mListener . onContactSelected ( contactUri , targetRect ); + mListener . onContactClick ( contactUri , targetRect ); } } + @Override + public boolean onContactLongClick ( Uri contactUri , Rect targetRect , int type ) { + if ( mListener != null ) { + return mListener . onContactLongClick ( contactUri , targetRect , type ); + } + return false ; + } };文件packages/apps/Contacts/src/com/android/contacts/list/ContactTileView.java修改如下:
@@ - 72 , 11 + 72 , 21 @@ public class ContactTileView extends FrameLayout { } } }; - + OnLongClickListener listener2 = new OnLongClickListener () { + @Override + public boolean onLongClick ( View v ) { + if ( mListener != null ) { + return mListener . onLongClick ( ContactTileView . this ); + } + return false ; + } + }; if ( mPushState != null ) { mPushState . setOnClickListener ( listener ); + mPushState . setOnLongClickListener ( listener2 ); } else { setOnClickListener ( listener ); + setOnLongClickListener ( listener2 ); } } @@ - 166 , 5 + 176 , 6 @@ public class ContactTileView extends FrameLayout { public interface Listener { void onClick ( ContactTileView contactTileView ); + boolean onLongClick ( ContactTileView contactTileView ); } }文件packages/apps/Contacts/src/com/android/contacts/list/PhoneFavoriteFragment.java的主要修改如下:
@@ - 74 , 7 + 74 , 8 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen private static final int REQUEST_CODE_ACCOUNT_FILTER = 1 ; public interface Listener { - public void onContactSelected ( Uri contactUri ); + public void onContactClick ( Uri contactUri ); + public boolean onContactLongClick ( Uri contactUri , int type ); } private class ContactTileLoaderListener implements LoaderManager . LoaderCallbacks < Cursor > { @@ - 189 , 11 + 190 , 18 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen private class ContactTileAdapterListener implements ContactTileAdapter . Listener { @Override - public void onContactSelected ( Uri contactUri , Rect targetRect ) { + public void onContactClick ( Uri contactUri , Rect targetRect ) { if ( mListener != null ) { - mListener . onContactSelected ( contactUri ); + mListener . onContactClick ( contactUri ); } } + @Override + public boolean onContactLongClick ( Uri contactUri , Rect targetRect , int type ) { + if ( mListener != null ) { + return mListener . onContactLongClick ( contactUri , type ); + } + return false ; + } } private class FilterHeaderClickListener implements OnClickListener { @@ - 426 , 7 + 434 , 7 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen } else { final int localPosition = position - mContactTileAdapter . getCount () - 1 ; if ( mListener != null ) { - mListener . onContactSelected ( mAllContactsAdapter . getDataUri ( localPosition )); + mListener . onContactClick ( mAllContactsAdapter . getDataUri ( localPosition )); } } }文件packages/apps/Contacts/src/com/android/contacts/group/GroupDetailFragment.java修改如下:
@@ - 256 , 9 + 256 , 13 @@ public class GroupDetailFragment extends Fragment implements OnScrollListener { new ContactTileAdapter . Listener () { @Override - public void onContactSelected ( Uri contactUri , Rect targetRect ) { + public void onContactClick ( Uri contactUri , Rect targetRect ) { mListener . onContactSelected ( contactUri ); } + @Override + public boolean onContactLongClick ( Uri contactUri , Rect targetRect , int type ) { + return false ; + } };文件packages/apps/Contacts/res/values/strings.xml修改如下:
@@ - 2139 , 4 + 2139 , 7 @@ < string name = "error_save_usim_contact_email_lost" > "Failed to save Email address because the USIM storage for Email is full." < /string> <string name="error_import_usim_contact_email_lost">"Failure caused by USIM storage full for Email.\nCompleted: <xliff:g id="items">%d</ xliff : g > \n Incomp < string name = "user_profile_cannot_sd_card" > Cannot share the content with this method .</ string > + < string name = "remove_frequent_contact_alert" > Do you want to remove this contact from frequent ?</ string > + < string name = "remove_frequent_contact_succes" > succes to remove contact from frequent list !</ string > + < string name = "remove_frequent_contact_fail" > fail to remove contact from frequent list !</ string > </ resources >文件packages/apps/Contacts/res/values-zh-rCN/strings.xml修改如下:
@@ - 868 , 4 + 868 , 7 @@ < string name = "user_profile_cannot_sd_card" > "无法通过该方式共享个人信息." < /string> <!-- The previous lines are provided and maintained by Mediatek Inc. --> <string name="activity_not_found_error">找不到相关的应用程序!</ string > + < string name = "remove_frequent_contact_alert" >你想把该联系人从常用联系人列表中移除吗?</ string > + < string name = "remove_frequent_contact_succes" >移除常用联系人成功!</ string > + < string name = "remove_frequent_contact_fail" >抱歉,移除常用聯繫人失敗!</ string > </ resources >文件packages/apps/Contacts/res/values-zh-rTW/strings.xml修改如下:
@@ - 888 , 4 + 888 , 7 @@ < string name = "user_profile_cannot_sd_card" > "無法通過該方式共享個人信息" < /string> <!-- The previous lines are provided and maintained by Mediatek Inc. --> <string name="activity_not_found_error">找不到相關的應用程式!</ string > + < string name = "remove_frequent_contact_alert" >你想把該聯繫人從常用聯繫人列表中移除嗎?</ string > + < string name = "remove_frequent_contact_succes" >移除常用聯繫人成功!</ string > + < string name = "remove_frequent_contact_fail" >抱歉,从常用联系人列表中移除联系人失败!</ string > </ resources >结束!
更多相关文章
- Android(安卓)OpenGL学习笔记(二)之----三角形的绘制.
- Android(安卓)中各种XML文件的作用
- Android中的strings文件中字符串的拼接
- Android(安卓)字体加粗的两种方法
- Android(安卓)清单文件属性大全
- Android动态分析工具Droidbox
- 读取android手机流量信息
- Android(安卓)P 系统设置默认值
- NPM 和webpack 的基础使用