bigbaicai

芯方式是以半导体人、电子工程师等电子行业相关领域从业人员为核心的知识经验学习、分享、交流社群。 凭借开放、合作、共赢的运营理念,聚集了来自国内外知名院校和顶尖科技公司的半导体人、电子工程师。 我们致力于营造专业、认真、有温度的分享交流环境,将高质量的内容和方案成规模地生产和分享,帮助个人和团队在芯方式找到有价值的Key。 http://www.icfans.com/

如何将预置联系人置顶【下】

0
阅读(141) 评论(1)


如何将预置联系人置顶【下】


3)在ContactsDatabaseHelper.java文件中更改updateRawContactDisplayName方法,增加数“isSticky”,对是否是置顶联系人做出判断,文件路为/src/com/android/providers/contacts/ContactsDatabaseHelper.java
修改内容如下icfans
@@ -3289,12 +3289,22 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper {
* Regenerates sort keys for all contacts.
*/
private void rebuildSortKeys(SQLiteDatabase db) {
- Cursor cursor = db.query(Tables.RAW_CONTACTS, new String[]{RawContacts._ID},
- null, null, null, null, null);
+ //Cursor cursor = db.query(Tables.RAW_CONTACTS, new String[]{RawContacts._ID},
+ //null, null, null, null, null);
+ Cursor cursor = db.query(Tables.RAW_CONTACTS, new String[] {RawContacts._ID,RawContactsColumns.PHONEBOOK_LABEL_PRIMARY,
+ RawContactsColumns.PHONEBOOK_LABEL_ALTERNATIVE},null, null, null, null, null);
try {
while (cursor.moveToNext()) {
lo
ng rawContactId = cursor.getLong(0);
- updateRawContactDisplayName(db, rawContactId);


+ //updateRawContactDisplayName(db, rawContactId);
+ String phoneBookLabelPri=cursor.getString(1);
+ String phoneBookLabelAlt=cursor.getString(2);
+ if(mContext.getString(R.string.build_contacts_title).equals(phoneBookLabelPri) ||
+ mContext.getString(R.string.build_contacts_title).equals(phoneBookLabelAlt)){
+ updateRawContactDisplayName(db, rawContactId,true);
+ }else{
+ updateRawContactDisplayName(db, rawContactId);
+ }
}
} finally {
cursor.close();
@@ -5347,7 +5358,12 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper {
* Updates a raw contact display name based on data rows, e.g. structured name,
* organization, email etc.
*/
+ //public void updateRawContactDisplayName(SQLiteDatabase db, long rawContactId) {
public void updateRawContactDisplayName(SQLiteDatabase db, long rawContactId) {
+ updateRawContactDisplayName(db, rawContactId, false);
+ }
+ +
public void updateRawContactDisplayName(SQLiteDatabase db, long rawContactId, boolean isSticky) {
if (mNameSplitter == null) {
createNameSplitter();
}
@@ -5545,17 +5561,17 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper {
sortKeyAlternative = sortNameAlternative;
}
- String phonebookLabelPrimary = "";
- String phonebookLabelAlternative = "";
+ String phonebookLabelPrimary = "ECC";
+ String phonebookLabelAlternative = "ECC";
int
phonebookBucketPrimary = 0;
int
phonebookBucketAlternative = 0;
ContactLocaleUtils localeUtils = ContactLocaleUtils.getInstance();
- if (sortKeyPrimary != null) {
+ if (sortKeyPrimary != null && !isSticky) {
phonebookBucketPrimary = localeUtils.getBucketIndex(sortKeyPrimary);
phonebookLabelPrimary = localeUtils.getBucketLabel(phonebookBucketPrimary);
}
- if (sortKeyAlternative != null) {
+ if (sortKeyAlternative != null && !isSticky) {
phonebookBucketAlternative = localeUtils.getBucketIndex(sortKeyAlternative);
phonebookLabelAlternative = localeUtils.getBucketLabel(phonebookBucketAlternative);
}
4)在ContactsProvider2.java中调用以上文件中修改的方法,文件路径为/src/com/android/providers/contacts/ContactsProvider2.java
修改内容如下:
@@ -1836,6 +1836,7 @@ public class ContactsProvider2 extends AbstractContactsProvider
PreferenceManager.getDefaultSharedPreferences(getContext());
if (!needsToUpdateLocaleData(prefs, currentLocale,
mContactsHelper, mProfileHelper)) {
+ getContext().getContentResolver().notifyChange(ProviderStatus.CONTENT_URI, null, false);
return;
}
@@ -2463,7 +2464,8 @@ public class ContactsProvider2 extends AbstractContactsProvider
final SQLiteDatabase db = mDbHelper.get().getWritableDatabase();
for (long rawContactId : mTransactionContext.get().getInsertedRawContactIds()) {
- mDbHelper.get().updateRawContactDisplayName(db, rawContactId);
+ //mDbHelper.get().updateRawContactDisplayName(db, rawContactId);
+ mDbHelper.get().updateRawContactDisplayName(db, rawContactId, mTransactionContext.get().isNeedStickyRawContact(rawContactId));
mDbHelper.get().updateRawContactIdentity(db, rawContactId);
lo
ng contactId = mAggregator.get().onRawContactInsert(mTransactionContext.get(), db,
rawContactId);
@@ -2657,6 +2659,9 @@ public class ContactsProvider2 extends AbstractContactsProvider
inv
alidateFastScrollingIndexCache();
id = insertRawContact(uri, values, callerIsSyncAdapter);
mSyncToNetwork |= !callerIsSyncAdapter;
+ if (readBooleanQueryParameter(uri, "caller_is_sticky", false)){
+ mTransactionContext.get().stickyRawContactInserted(id);
+ }
break;
}
【注意】
文件修改完成,分别对Contacts和ContactsProvider进行编译,将Contacts.apk和ContactsProvider.apk分别push后,恢复出厂设置,手机开机后新建一些联系人,可以实现预置联系人置顶的效果。
1)push Contacts.apk命令
adb push out/target/product/sp9820a_c110/system/priv-app/Contacts.apk system/priv-app
2) push ContactsProvider.apk命令
adb push out/target/product/sp9820a_c110/system/priv-app/ContactsProvider.apk system/priv-app

  1. 感谢分享!http://www.doorock.com 提供FAE(IC应用技术支持)共享服务的,有兴趣可以去看看。