private int syncContactNames(Context context){
  final ContentResolver contentResolver=context.getContentResolver();
  final Cursor cursor=contentResolver.query(ContactNotifications.CONTENT_URI,null,null,null,null);
  if (cursor == null) {
    return 0;
  }
  if (cursor.getCount() == 0) {
    return 0;
  }
  int count=0;
  int updatedCount=0;
  String id;
  String contactName;
  String contactLookup;
  String contactId;
  while (cursor.moveToNext()) {
    count++;
    id=cursor.getString(cursor.getColumnIndexOrThrow(ContactNotifications._ID));
    contactName=cursor.getString(cursor.getColumnIndexOrThrow(ContactNotifications.CONTACT_NAME));
    contactId=cursor.getString(cursor.getColumnIndexOrThrow(ContactNotifications.CONTACT_ID));
    contactLookup=cursor.getString(cursor.getColumnIndexOrThrow(ContactNotifications.CONTACT_LOOKUPKEY));
    ContactIdentification contactInfo=SmsPopupUtils.getPersonNameByLookup(context,contactLookup,contactId);
    if (contactInfo != null) {
      boolean runUpdate=false;
      ContentValues vals=new ContentValues();
      if (contactName == null || !contactName.equals(contactInfo.contactName)) {
        vals.put(ContactNotifications.CONTACT_NAME,contactInfo.contactName);
        runUpdate=true;
      }
      if (contactId == null || !contactId.equals(contactInfo.contactId)) {
        vals.put(ContactNotifications.CONTACT_ID,contactInfo.contactId);
        runUpdate=true;
      }
      if (contactLookup == null || !contactLookup.equals(contactInfo.contactLookup)) {
        vals.put(ContactNotifications.CONTACT_LOOKUPKEY,contactInfo.contactLookup);
        runUpdate=true;
      }
      if (runUpdate && 1 == contentResolver.update(ContactNotifications.buildContactUri(id),vals,null,null)) {
        updatedCount++;
      }
    }
  }
  if (cursor != null) {
    cursor.close();
  }
  if (BuildConfig.DEBUG)   Log.v("Sync Contacts: " + updatedCount + " / "+ count);
  return updatedCount;
}

private int syncContactNames ( Context context ) { final ContentResolver contentResolver = context . getContentResolver ( ) ; final Cursor cursor = contentResolver . query ( ContactNotifications . CONTENT_URI , null , null , null , null ) ; if ( cursor == null ) { return 0 ; } if ( cursor . getCount ( ) == 0 ) { return 0 ; } int count = 0 ; int updatedCount = 0 ; String id ; String contactName ; String contactLookup ; String contactId ; while ( cursor . moveToNext ( ) ) { count ++ ; id = cursor . getString ( cursor . getColumnIndexOrThrow ( ContactNotifications . _ID ) ) ; contactName = cursor . getString ( cursor . getColumnIndexOrThrow ( ContactNotifications . CONTACT_NAME ) ) ; contactId = cursor . getString ( cursor . getColumnIndexOrThrow ( ContactNotifications . CONTACT_ID ) ) ; contactLookup = cursor . getString ( cursor . getColumnIndexOrThrow ( ContactNotifications . CONTACT_LOOKUPKEY ) ) ; ContactIdentification contactInfo = SmsPopupUtils . getPersonNameByLookup ( context , contactLookup , contactId ) ; if ( contactInfo != null ) { boolean runUpdate = false ; ContentValues vals = new ContentValues ( ) ; if ( contactName == null || ! contactName . equals ( contactInfo . contactName ) ) { vals . put ( ContactNotifications . CONTACT_NAME , contactInfo . contactName ) ; runUpdate = true ; } if ( contactId == null || ! contactId . equals ( contactInfo . contactId ) ) { vals . put ( ContactNotifications . CONTACT_ID , contactInfo . contactId ) ; runUpdate = true ; } if ( contactLookup == null || ! contactLookup . equals ( contactInfo . contactLookup ) ) { vals . put ( ContactNotifications . CONTACT_LOOKUPKEY , contactInfo . contactLookup ) ; runUpdate = true ; } if ( runUpdate && 1 == contentResolver . update ( ContactNotifications . buildContactUri ( id ) , vals , null , null ) ) { updatedCount ++ ; } } } if ( cursor != null ) { cursor . close ( ) ; } if ( BuildConfig . DEBUG ) Log . v ( "Sync Contacts: " + updatedCount + " / " + count ) ; return updatedCount ; }
any custom contact notifications are stored in a local database , including the contact names so we can quickly display them on the configuration screens . this function will loop through the locally stored contacts and check to see if the system contact name has changed at all ( from either a manual edit or some sort of sync event ) . if so , it will update the local database with the new name .
