diff options
author | Linux Build Service Account <lnxbuild@localhost> | 2015-09-10 10:05:55 -0700 |
---|---|---|
committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2015-09-10 10:05:55 -0700 |
commit | 88393a3ee15010fbbd97f7ab8866bdf1ebf4ffeb (patch) | |
tree | 364ea3f92b670220cf4605e3f80e3c2cb7f816bb /src/com/android/providers | |
parent | e60467284a006f192925a33ae2afbafb21bb0a31 (diff) | |
parent | cce7fa32a6bc960478eb217446cff58ad6fa0bab (diff) | |
download | packages_providers_ContactsProvider-88393a3ee15010fbbd97f7ab8866bdf1ebf4ffeb.zip packages_providers_ContactsProvider-88393a3ee15010fbbd97f7ab8866bdf1ebf4ffeb.tar.gz packages_providers_ContactsProvider-88393a3ee15010fbbd97f7ab8866bdf1ebf4ffeb.tar.bz2 |
Merge "Add local group feature supports" into ui_dev_2.0
Diffstat (limited to 'src/com/android/providers')
-rw-r--r-- | src/com/android/providers/contacts/ContactsDatabaseHelper.java | 91 | ||||
-rw-r--r-- | src/com/android/providers/contacts/ContactsProvider2.java | 75 |
2 files changed, 159 insertions, 7 deletions
diff --git a/src/com/android/providers/contacts/ContactsDatabaseHelper.java b/src/com/android/providers/contacts/ContactsDatabaseHelper.java index 1d43fbc..c84c97f 100644 --- a/src/com/android/providers/contacts/ContactsDatabaseHelper.java +++ b/src/com/android/providers/contacts/ContactsDatabaseHelper.java @@ -285,11 +285,11 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper { */ public static final String GROUP_MEMBER_COUNT = " LEFT OUTER JOIN (SELECT " - + "data.data1 AS member_count_group_id, " - + "COUNT(data.raw_contact_id) AS group_member_count " - + "FROM data " + + "view_data.data1 AS member_count_group_id, " + + "COUNT(DISTINCT view_data.contact_id) AS group_member_count " + + "FROM view_data " + "WHERE " - + "data.mimetype_id = (SELECT _id FROM mimetypes WHERE " + + "view_data.mimetype_id = (SELECT _id FROM mimetypes WHERE " + "mimetypes.mimetype = '" + GroupMembership.CONTENT_ITEM_TYPE + "')" + "GROUP BY member_count_group_id) AS member_count_table" // End of inner query + " ON (groups._id = member_count_table.member_count_group_id)"; @@ -1597,6 +1597,9 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper { // Add the legacy API support views, etc. LegacyApiSupport.createDatabase(db); + createPhoneAccount(db); + createDefaultGroups4PhoneAccount(db); + if (mDatabaseOptimizationEnabled) { // This will create a sqlite_stat1 table that is used for query optimization db.execSQL("ANALYZE;"); @@ -3478,6 +3481,7 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper { insertNameLookup(db); rebuildSortKeys(db); createContactsIndexes(db, rebuildSqliteStats); + rebuildDefaultGroupTitles(db, locales.getPrimaryLocale()); FastScrollingIndexCache.getInstance(mContext).invalidate(); // Update the ICU version used to generate the locale derived data @@ -3487,6 +3491,35 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper { } /** + * change the default groups' title according to the locale + */ + private void rebuildDefaultGroupTitles(SQLiteDatabase db, Locale locale) { + String[] PROJECTION = new String[] {Groups._ID, Groups.TITLE_RES}; + Cursor cursor = db.query(Tables.GROUPS, PROJECTION, Groups.TITLE_RES + " IS NOT NULL ", null + ,null, null, Groups._ID); + + if (cursor == null) { + return; + } + + try { + long groupId = -1; + int titleRes = 0; + ContentValues values = new ContentValues(); + while (cursor.moveToNext()) { + groupId = cursor.getLong(0); + titleRes = cursor.getInt(1); + values.clear(); + values.put(Groups.TITLE, mContext.getResources().getString(titleRes)); + db.update(Tables.GROUPS, values, Groups._ID + " = ?", new String[] { + String.valueOf(groupId)}); + } + } finally { + cursor.close(); + } + } + + /** * Regenerates all locale-sensitive data if needed: * nickname_lookup, name_lookup and sort keys. Invalidates the fast * scrolling index cache. @@ -5989,4 +6022,54 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper { " WHERE " + SearchIndexColumns.CONTACT_ID + "=CAST(? AS int)", new String[] {String.valueOf(contactId)}); } + + private void createDefaultGroups4PhoneAccount(SQLiteDatabase db) { + // 3 default groups + String[] title = new String[3]; + int[] titleRes = new int[3]; + + title[0] = mContext.getResources().getString(R.string.group_title_co_workers); + titleRes[0] = R.string.group_title_co_workers; + + title[1] = mContext.getResources().getString(R.string.group_title_family); + titleRes[1] = R.string.group_title_family; + + title[2] = mContext.getResources().getString(R.string.group_title_friends); + titleRes[2] = R.string.group_title_friends; + + for (int i = 0; i < title.length; i++) { + db.execSQL("INSERT INTO " + Tables.GROUPS + " (" + + GroupsColumns.ACCOUNT_ID + "," + + Groups.SOURCE_ID + "," + + Groups.VERSION + "," + + Groups.DIRTY + "," + + Groups.TITLE + "," + + Groups.TITLE_RES + "," + + Groups.NOTES + "," + + Groups.SYSTEM_ID + "," + + Groups.DELETED + "," + + Groups.GROUP_VISIBLE + "," + + Groups.SHOULD_SYNC + "," + + Groups.AUTO_ADD + "," + + Groups.FAVORITES + "," + + Groups.GROUP_IS_READ_ONLY + "," + + Groups.SYNC1 + ", " + + Groups.SYNC2 + ", " + + Groups.SYNC3 + ", " + + Groups.SYNC4 + ") " + + "VALUES (1,1,1,0,'" + + title[i] + "'," + titleRes[i] + + ",NULL,NULL,0,1,1,0,0,1,'','','','');" + ); + } + } + + public void createPhoneAccount(SQLiteDatabase db) { + String sql = "INSERT INTO " + Tables.ACCOUNTS + + "(" + AccountsColumns.ACCOUNT_NAME + "," + + AccountsColumns.ACCOUNT_TYPE + ") " + + "VALUES ('" + AccountWithDataSet.PHONE_NAME + "','" + + AccountWithDataSet.ACCOUNT_TYPE_PHONE + "')"; + db.execSQL(sql); + } } diff --git a/src/com/android/providers/contacts/ContactsProvider2.java b/src/com/android/providers/contacts/ContactsProvider2.java index 8fe1acd..55bae54 100644 --- a/src/com/android/providers/contacts/ContactsProvider2.java +++ b/src/com/android/providers/contacts/ContactsProvider2.java @@ -302,6 +302,10 @@ public class ContactsProvider2 extends AbstractContactsProvider + Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC"; private static String WITHOUT_SIM_FLAG = "no_sim"; + private boolean isWhereAppended = false; + + public static final String ADD_GROUP_MEMBERS = "add_group_members"; + private static final int CONTACTS = 1000; private static final int CONTACTS_ID = 1001; private static final int CONTACTS_LOOKUP = 1002; @@ -533,6 +537,22 @@ public class ContactsProvider2 extends AbstractContactsProvider + " FROM " + Tables.GROUPS + " WHERE " + Groups.TITLE + "=?)))"; + private static final String CONTACTS_IN_GROUP_ID_SELECT = + Contacts._ID + " IN " + + "(SELECT DISTINCT " + + Data.CONTACT_ID + + " FROM " + Views.DATA + + " WHERE " + Data.MIMETYPE + " = '" + GroupMembership.CONTENT_ITEM_TYPE + + "' AND " + Data.DATA1 + " = ?)"; + + private static final String CONTACTS_NOT_IN_GROUP_ID_SELECT = + Contacts._ID + " NOT IN " + + "(SELECT DISTINCT " + + Data.CONTACT_ID + + " FROM " + Views.DATA + + " WHERE " + Data.MIMETYPE + " = '" + GroupMembership.CONTENT_ITEM_TYPE + + "' AND " + Data.DATA1 + " = ?)"; + /** Sql for updating DIRTY flag on multiple raw contacts */ private static final String UPDATE_RAW_CONTACT_SET_DIRTY_SQL = "UPDATE " + Tables.RAW_CONTACTS + @@ -1207,6 +1227,7 @@ public class ContactsProvider2 extends AbstractContactsProvider matcher.addURI(ContactsContract.AUTHORITY, "contacts/strequent/", CONTACTS_STREQUENT); matcher.addURI(ContactsContract.AUTHORITY, "contacts/strequent/filter/*", CONTACTS_STREQUENT_FILTER); + matcher.addURI(ContactsContract.AUTHORITY, "contacts/group", CONTACTS_GROUP); matcher.addURI(ContactsContract.AUTHORITY, "contacts/group/*", CONTACTS_GROUP); matcher.addURI(ContactsContract.AUTHORITY, "contacts/frequent", CONTACTS_FREQUENT); matcher.addURI(ContactsContract.AUTHORITY, "contacts/delete_usage", CONTACTS_DELETE_USAGE); @@ -5357,13 +5378,43 @@ public class ContactsProvider2 extends AbstractContactsProvider filterParam = uri.getLastPathSegment(); } - // If the query consists of a single word, we can do snippetizing after-the-fact for - // a performance boost. Otherwise, we can't defer. + // If the query consists of a single word, we can do snippetizing + // after-the-fact for a performance boost. Otherwise, we can't defer. snippetDeferred = isSingleWordQuery(filterParam) && deferredSnipRequested && snippetNeeded(projection); setTablesAndProjectionMapForContactsWithSnippet( qb, uri, projection, filterParam, directoryId, snippetDeferred); + long groupId = -1; + try { + groupId = Long.parseLong(uri.getQueryParameter(Groups._ID)); + } catch (Exception exception) { + groupId = -1; + } + if (groupId != -1) { + StringBuilder groupBuilder = new StringBuilder(); + if (uri.getBooleanQueryParameter(ADD_GROUP_MEMBERS, false)) { + // filter all the contacts that are NOT assigned to the + // group whose id is 'groupId' + groupBuilder.append(Contacts._ID + " NOT IN (" + " SELECT DISTINCT " + + Data.CONTACT_ID + + " FROM " + Views.DATA + " WHERE " + Data.MIMETYPE + " = '" + + GroupMembership.CONTENT_ITEM_TYPE + "' AND " + Data.DATA1 + + " = " + groupId + ")"); + } else { + // filter all the contacts that are assigned to the + // group whose id is 'groupId' + groupBuilder.append(Contacts._ID + " IN (" + " SELECT DISTINCT " + + Data.CONTACT_ID + + " FROM " + Views.DATA + " WHERE " + Data.MIMETYPE + " = '" + + GroupMembership.CONTENT_ITEM_TYPE + "' AND " + Data.DATA1 + + " = " + groupId + ")"); + } + if (isWhereAppended) { + qb.appendWhere(" AND "); + } + qb.appendWhere(groupBuilder.toString()); + } break; } @@ -5545,7 +5596,23 @@ public class ContactsProvider2 extends AbstractContactsProvider case CONTACTS_GROUP: { setTablesAndProjectionMapForContacts(qb, projection); - if (uri.getPathSegments().size() > 2) { + appendLocalDirectoryAndAccountSelectionIfNeeded(qb, directoryId, uri); + long groupId = -1; + try { + groupId = Long.parseLong(uri.getQueryParameter(Groups._ID)); + } catch (Exception exception) { + groupId = -1; + } + if (groupId != -1) { + qb.appendWhere(" AND "); + if (uri.getBooleanQueryParameter(ADD_GROUP_MEMBERS, false)) { + qb.appendWhere(CONTACTS_NOT_IN_GROUP_ID_SELECT); + } else { + qb.appendWhere(CONTACTS_IN_GROUP_ID_SELECT); + } + selectionArgs = insertSelectionArg(selectionArgs, String.valueOf(groupId)); + } else if (uri.getPathSegments().size() > 2) { + qb.appendWhere(" AND "); qb.appendWhere(CONTACTS_IN_GROUP_SELECT); String groupMimeTypeId = String.valueOf( mDbHelper.get().getMimeTypeId(GroupMembership.CONTENT_ITEM_TYPE)); @@ -7326,6 +7393,7 @@ public class ContactsProvider2 extends AbstractContactsProvider private void setTablesAndProjectionMapForContactsWithSnippet(SQLiteQueryBuilder qb, Uri uri, String[] projection, String filter, long directoryId, boolean deferSnippeting) { + isWhereAppended = false; StringBuilder sb = new StringBuilder(); sb.append(Views.CONTACTS); @@ -7376,6 +7444,7 @@ public class ContactsProvider2 extends AbstractContactsProvider if (!TextUtils.isEmpty(sbWhere.toString())) { if ("true".equals(withoutSim)) { qb.appendWhere(sbWhere.toString()); + isWhereAppended = true; } else { sb.append(sbWhere.toString()); } |