diff options
author | Jay Shrauner <shrauner@google.com> | 2013-10-17 13:59:48 -0700 |
---|---|---|
committer | Jay Shrauner <shrauner@google.com> | 2014-04-18 11:23:49 -0700 |
commit | d4dbd063cf88e70b045607aa865b2fdb2329bf45 (patch) | |
tree | 19152c84d27e399f62f79b645205953e0b682ab2 /src/com/android/providers/contacts/ContactsDatabaseHelper.java | |
parent | 30268f9198a8b25aa0c9d90c0c2390f7a4bffb0d (diff) | |
download | packages_providers_ContactsProvider-d4dbd063cf88e70b045607aa865b2fdb2329bf45.zip packages_providers_ContactsProvider-d4dbd063cf88e70b045607aa865b2fdb2329bf45.tar.gz packages_providers_ContactsProvider-d4dbd063cf88e70b045607aa865b2fdb2329bf45.tar.bz2 |
Support secondary locales
Add support for tracking a secondary locale in addition to the current
primary locale for CP2. Switch to using parseable ICU language tag
(eg, "en-US") for locale tag written to DB. Secondary locale is set to
previous locale on locale change and persisted in CP2 DB and prefs.
Bug:8715226
Change-Id: Ia68397fd9118d89f3a45ac54f991f86bad42870e
Diffstat (limited to 'src/com/android/providers/contacts/ContactsDatabaseHelper.java')
-rw-r--r-- | src/com/android/providers/contacts/ContactsDatabaseHelper.java | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/com/android/providers/contacts/ContactsDatabaseHelper.java b/src/com/android/providers/contacts/ContactsDatabaseHelper.java index 82cf310..265846c 100644 --- a/src/com/android/providers/contacts/ContactsDatabaseHelper.java +++ b/src/com/android/providers/contacts/ContactsDatabaseHelper.java @@ -3266,9 +3266,9 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper { * Checks whether the current ICU code version matches that used to build * the locale specific data in the ContactsDB. */ - public boolean needsToUpdateLocaleData(Locale locale) { + public boolean needsToUpdateLocaleData(LocaleSet locales) { final String dbLocale = getProperty(DbProperties.LOCALE, ""); - if (!dbLocale.equals(locale.toString())) { + if (!dbLocale.equals(locales.toString())) { return true; } final String curICUVersion = ICU.getIcuVersion(); @@ -3283,16 +3283,17 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper { } private void upgradeLocaleData(SQLiteDatabase db, boolean rebuildSqliteStats) { - final Locale locale = Locale.getDefault(); - Log.i(TAG, "Upgrading locale data for " + locale + final String dbLocale = getProperty(DbProperties.LOCALE, ""); + final LocaleSet locales = LocaleSet.getDefault(); + Log.i(TAG, "Upgrading locale data for " + locales + " (ICU v" + ICU.getIcuVersion() + ")"); final long start = SystemClock.elapsedRealtime(); initializeCache(db); - rebuildLocaleData(db, locale, rebuildSqliteStats); + rebuildLocaleData(db, locales, rebuildSqliteStats); Log.i(TAG, "Locale update completed in " + (SystemClock.elapsedRealtime() - start) + "ms"); } - private void rebuildLocaleData(SQLiteDatabase db, Locale locale, boolean rebuildSqliteStats) { + private void rebuildLocaleData(SQLiteDatabase db, LocaleSet locales, boolean rebuildSqliteStats) { db.execSQL("DROP INDEX raw_contact_sort_key1_index"); db.execSQL("DROP INDEX raw_contact_sort_key2_index"); db.execSQL("DROP INDEX IF EXISTS name_lookup_index"); @@ -3306,7 +3307,7 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper { // Update the ICU version used to generate the locale derived data // so we can tell when we need to rebuild with new ICU versions. setProperty(db, DbProperties.ICU_VERSION, ICU.getIcuVersion()); - setProperty(db, DbProperties.LOCALE, locale.toString()); + setProperty(db, DbProperties.LOCALE, locales.toString()); } /** @@ -3314,19 +3315,19 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper { * nickname_lookup, name_lookup and sort keys. Invalidates the fast * scrolling index cache. */ - public void setLocale(Locale locale) { - if (!needsToUpdateLocaleData(locale)) { + public void setLocale(LocaleSet locales) { + if (!needsToUpdateLocaleData(locales)) { return; } - Log.i(TAG, "Switching to locale " + locale + Log.i(TAG, "Switching to locale " + locales + " (ICU v" + ICU.getIcuVersion() + ")"); final long start = SystemClock.elapsedRealtime(); SQLiteDatabase db = getWritableDatabase(); - db.setLocale(locale); + db.setLocale(locales.getPrimaryLocale()); db.beginTransaction(); try { - rebuildLocaleData(db, locale, true); + rebuildLocaleData(db, locales, true); db.setTransactionSuccessful(); } finally { db.endTransaction(); |