summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2011-06-15 15:09:41 +0900
committerJean Chalard <jchalard@google.com>2012-01-18 17:57:34 +0900
commitbf063f25421b08f118524890914fbdbfa63dbdaf (patch)
tree5ce62a1a9c15df973e3f6108ad4445b4f24d6ea9
parentd7eb9d4b59640175877a6f53f32b6e3e3d7154e9 (diff)
downloadandroid_packages_providers_UserDictionaryProvider-bf063f25421b08f118524890914fbdbfa63dbdaf.tar.gz
android_packages_providers_UserDictionaryProvider-bf063f25421b08f118524890914fbdbfa63dbdaf.tar.bz2
android_packages_providers_UserDictionaryProvider-bf063f25421b08f118524890914fbdbfa63dbdaf.zip
Add shortcut support for the user dict provider.
This needs support to the framework by change Id3ca792f. Bug: 4646172 Change-Id: Ib318c047a617f3bebbd390cca3e4a585ca0d1118
-rw-r--r--src/com/android/providers/userdictionary/DictionaryBackupAgent.java18
-rw-r--r--src/com/android/providers/userdictionary/UserDictionaryProvider.java38
2 files changed, 47 insertions, 9 deletions
diff --git a/src/com/android/providers/userdictionary/DictionaryBackupAgent.java b/src/com/android/providers/userdictionary/DictionaryBackupAgent.java
index d6ef196..6432a01 100644
--- a/src/com/android/providers/userdictionary/DictionaryBackupAgent.java
+++ b/src/com/android/providers/userdictionary/DictionaryBackupAgent.java
@@ -61,13 +61,15 @@ public class DictionaryBackupAgent extends BackupAgentHelper {
private static final int COLUMN_FREQUENCY = 2;
private static final int COLUMN_LOCALE = 3;
private static final int COLUMN_APPID = 4;
+ private static final int COLUMN_SHORTCUT = 5;
private static final String[] PROJECTION = {
Words._ID,
Words.WORD,
Words.FREQUENCY,
Words.LOCALE,
- Words.APP_ID
+ Words.APP_ID,
+ Words.SHORTCUT
};
@Override
@@ -161,7 +163,11 @@ public class DictionaryBackupAgent extends BackupAgentHelper {
int frequency = cursor.getInt(COLUMN_FREQUENCY);
String locale = cursor.getString(COLUMN_LOCALE);
int appId = cursor.getInt(COLUMN_APPID);
- String out = name + "|" + frequency + "|" + locale + "|" + appId;
+ String shortcut = cursor.getString(COLUMN_SHORTCUT);
+ if (TextUtils.isEmpty(shortcut)) shortcut = "";
+ // TODO: escape the string
+ String out = name + SEPARATOR + frequency + SEPARATOR + locale + SEPARATOR + appId
+ + SEPARATOR + shortcut;
byte[] line = out.getBytes();
writeInt(sizeBytes, 0, line.length);
gzip.write(sizeBytes);
@@ -206,6 +212,7 @@ public class DictionaryBackupAgent extends BackupAgentHelper {
}
String line = new String(dictionary, pos, length);
pos += length;
+ // TODO: unescape the string
StringTokenizer st = new StringTokenizer(line, SEPARATOR);
String word;
String frequency;
@@ -214,9 +221,12 @@ public class DictionaryBackupAgent extends BackupAgentHelper {
frequency = st.nextToken();
String locale = null;
String appid = null;
+ String shortcut = null;
if (st.hasMoreTokens()) locale = st.nextToken();
if ("null".equalsIgnoreCase(locale)) locale = null;
if (st.hasMoreTokens()) appid = st.nextToken();
+ if (st.hasMoreTokens()) shortcut = st.nextToken();
+ if (TextUtils.isEmpty(shortcut)) shortcut = null;
int frequencyInt = Integer.parseInt(frequency);
int appidInt = appid != null? Integer.parseInt(appid) : 0;
@@ -226,8 +236,10 @@ public class DictionaryBackupAgent extends BackupAgentHelper {
cv.put(Words.FREQUENCY, frequencyInt);
cv.put(Words.LOCALE, locale);
cv.put(Words.APP_ID, appidInt);
+ cv.put(Words.SHORTCUT, shortcut);
// Remove duplicate first
- getContentResolver().delete(contentUri, Words.WORD + "=?", new String[] {word});
+ getContentResolver().delete(contentUri, Words.WORD + "=? and "
+ + Words.SHORTCUT + "=?", new String[] {word, shortcut});
getContentResolver().insert(contentUri, cv);
}
} catch (NoSuchElementException nsee) {
diff --git a/src/com/android/providers/userdictionary/UserDictionaryProvider.java b/src/com/android/providers/userdictionary/UserDictionaryProvider.java
index 1ff59e2..4505325 100644
--- a/src/com/android/providers/userdictionary/UserDictionaryProvider.java
+++ b/src/com/android/providers/userdictionary/UserDictionaryProvider.java
@@ -41,6 +41,19 @@ import android.util.Log;
*/
public class UserDictionaryProvider extends ContentProvider {
+ /**
+ * DB versions are as follow:
+ *
+ * Version 1:
+ * Up to IceCreamSandwich 4.0.3 - API version 15
+ * Contient ID (INTEGER PRIMARY KEY), WORD (TEXT), FREQUENCY (INTEGER),
+ * LOCALE (TEXT), APP_ID (INTEGER).
+ *
+ * Version 2:
+ * From IceCreamSandwich, 4.1 - API version 16
+ * Adds SHORTCUT (TEXT).
+ */
+
private static final String AUTHORITY = UserDictionary.AUTHORITY;
private static final String TAG = "UserDictionaryProvider";
@@ -48,7 +61,7 @@ public class UserDictionaryProvider extends ContentProvider {
private static final Uri CONTENT_URI = UserDictionary.CONTENT_URI;
private static final String DATABASE_NAME = "user_dict.db";
- private static final int DATABASE_VERSION = 1;
+ private static final int DATABASE_VERSION = 2;
private static final String USERDICT_TABLE_NAME = "words";
@@ -79,15 +92,23 @@ public class UserDictionaryProvider extends ContentProvider {
+ Words.FREQUENCY + " INTEGER,"
+ Words.LOCALE + " TEXT,"
+ Words.APP_ID + " INTEGER"
+ + Words.SHORTCUT + " TEXT,"
+ ");");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
- + newVersion + ", which will destroy all old data");
- db.execSQL("DROP TABLE IF EXISTS " + USERDICT_TABLE_NAME);
- onCreate(db);
+ if (oldVersion == 1 && newVersion == 2) {
+ Log.i(TAG, "Upgrading database from version " + oldVersion
+ + " to version 2: adding " + Words.SHORTCUT + " column");
+ db.execSQL("ALTER TABLE " + USERDICT_TABLE_NAME
+ + " ADD " + Words.SHORTCUT + " TEXT;");
+ } else {
+ Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
+ + newVersion + ", which will destroy all old data");
+ db.execSQL("DROP TABLE IF EXISTS " + USERDICT_TABLE_NAME);
+ onCreate(db);
+ }
}
}
@@ -177,7 +198,11 @@ public class UserDictionaryProvider extends ContentProvider {
if (values.containsKey(Words.LOCALE) == false) {
values.put(Words.LOCALE, (String) null);
}
-
+
+ if (values.containsKey(Words.SHORTCUT) == false) {
+ values.put(Words.SHORTCUT, (String) null);
+ }
+
values.put(Words.APP_ID, 0);
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
@@ -251,5 +276,6 @@ public class UserDictionaryProvider extends ContentProvider {
sDictProjectionMap.put(Words.FREQUENCY, Words.FREQUENCY);
sDictProjectionMap.put(Words.LOCALE, Words.LOCALE);
sDictProjectionMap.put(Words.APP_ID, Words.APP_ID);
+ sDictProjectionMap.put(Words.SHORTCUT, Words.SHORTCUT);
}
}