如何将预置联系人置顶【上】
0赞[QUESTION]
如何将预置联系人置顶?
[ANSWER]
具体置顶的方法介绍如下:
分别修改Contacts和ContactsProvider下的文件。
1.Contacts中修改一个文件:
文件路径为/packages/apps/Contacts/src/com/android/contacts/util/PreDefineContactsService.java
修改内容如下icfans:
@@ -85,21 +101,33 @@ public class PreDefineContactsService extends IntentService {
for (int i = 0; i < INSERT_PRESET_NUMBER_COUNT; i++) {
int
photoId = getResources().getIdentifier(
INSERT_PRESET_PHOTO[i], "drawable",
"plugin.sprd.contactsdefaultcontact");
final ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
ContentProviderOperation.Builder builder;
- builder = ContentProviderOperation
- .newInsert(RawContacts.CONTENT_URI);
+ //builder = ContentProviderOperation
+ //.newInsert(RawContacts.CONTENT_URI);
+ builder = ContentProviderOperation
+ .newInsert(RawContacts.CONTENT_URI
+ .buildUpon()
+ .appendQueryParameter("caller_is_sticky",
+ "1").build()); //uri中添加条件caller_is_sticky = 1
2.ContactsProvider中修改四个文件:
1)在strings.xml文件中给置顶的联系人标识label(字符串的名字任取),文件路径为/res/values/strings.xml
修改内容如下:
@@ -81,4 +81,5 @@
<string name="debug_dump_email_body">Attached is my contacts database with all my contacts information. Handle with care.</string>
<string name="phone">"Phone"</string>
+ <string name="build_contacts_title">"ECC"</string>
</resources>
2)在TransactionContext.java文件中添加两个方法,文件路径为/packages/providers/ContactsProvider/src/com/android/providers/contacts/TransactionContext.java
修改内容如下:
@ -44,6 +44,8 @@ public class TransactionContext {
private HashSet<Long> mStaleSearchIndexContacts;
private HashMap<Long, Object> mUpdatedSyncStates;
+ private HashSet<Long> mStickyRawContacts = null;
+
public TransactionContext(boolean forProfile) {
mForProfile = forProfile;
}
@@ -141,13 +143,32 @@ public class TransactionContext {
if (mInsertedRawContactsAccounts == null) mInsertedRawContactsAccounts = Maps.newHashMap();
return mInsertedRawContactsAccounts.containsKey(rawContactId);
}
+ public boolean isNeedStickyRawContact(long rawContactId) { //再判断是否是置顶联系人
+ if (mStickyRawContacts == null || mStickyRawContacts.isEmpty()) {
+ return false;
+ }
+ for (long id : mStickyRawContacts) {
+ if (rawContactId == id){
+ //Log.d("TransactionContext", "isNeedStickyRawContact rawContactId:"+rawContactId+" return true");
+ return true;
+ }
+ }
+ return false;
+ }
+ public void stickyRawContactInserted(long rawContactId) { //先得到置顶联系人集合
+ if (mStickyRawContacts == null) {
+ mStickyRawContacts = Sets.newHashSet();
+ }
+ mStickyRawContacts.add(rawContactId);
+ }
public void clearExceptSearchIndexUpdates() {
mInsertedRawContactsAccounts = null;
mUpdatedRawContacts = null;
mUpdatedSyncStates = null;
mDirtyRawContacts = null;
mChangedRawContacts = null;
+ mStickyRawContacts = null;
}