1865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount/* 2865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount * Copyright (C) 2008 The Android Open Source Project 3865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount * 4865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount * Licensed under the Apache License, Version 2.0 (the "License"); 5865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount * you may not use this file except in compliance with the License. 6865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount * You may obtain a copy of the License at 7865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount * 8865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount * http://www.apache.org/licenses/LICENSE-2.0 9865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount * 10865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount * Unless required by applicable law or agreed to in writing, software 11865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount * distributed under the License is distributed on an "AS IS" BASIS, 12865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount * See the License for the specific language governing permissions and 14865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount * limitations under the License. 15865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount */ 16865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 17865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccountpackage com.android.providers.userdictionary; 18865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 19865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 20c5885c466b80dfda79a364e5623348469f8eb8dbAmith Yamasaniimport java.util.HashMap; 21c5885c466b80dfda79a364e5623348469f8eb8dbAmith Yamasani 229d0d421e99b46318170660a14c794f6c9b5e59d6Christopher Tateimport android.app.backup.BackupManager; 23865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccountimport android.content.ContentProvider; 24865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccountimport android.content.ContentUris; 25865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccountimport android.content.ContentValues; 26865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccountimport android.content.Context; 27865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccountimport android.content.UriMatcher; 28865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccountimport android.database.Cursor; 29865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccountimport android.database.SQLException; 30865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccountimport android.database.sqlite.SQLiteDatabase; 31865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccountimport android.database.sqlite.SQLiteOpenHelper; 32865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccountimport android.database.sqlite.SQLiteQueryBuilder; 33865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccountimport android.net.Uri; 34865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccountimport android.provider.UserDictionary; 35865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccountimport android.provider.UserDictionary.Words; 36865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccountimport android.text.TextUtils; 37865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccountimport android.util.Log; 38865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 39865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount/** 40865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount * Provides access to a database of user defined words. Each item has a word and a frequency. 41865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount */ 42865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccountpublic class UserDictionaryProvider extends ContentProvider { 43865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 44865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount private static final String AUTHORITY = UserDictionary.AUTHORITY; 45865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 46865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount private static final String TAG = "UserDictionaryProvider"; 47865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 48865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount private static final Uri CONTENT_URI = UserDictionary.CONTENT_URI; 49865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 50865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount private static final String DATABASE_NAME = "user_dict.db"; 51865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount private static final int DATABASE_VERSION = 1; 52865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 53865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount private static final String USERDICT_TABLE_NAME = "words"; 54865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 55865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount private static HashMap<String, String> sDictProjectionMap; 56865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 57865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount private static final UriMatcher sUriMatcher; 58865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 59865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount private static final int WORDS = 1; 60865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 61865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount private static final int WORD_ID = 2; 62c5885c466b80dfda79a364e5623348469f8eb8dbAmith Yamasani 63c5885c466b80dfda79a364e5623348469f8eb8dbAmith Yamasani private BackupManager mBackupManager; 64c5885c466b80dfda79a364e5623348469f8eb8dbAmith Yamasani 65865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount /** 66865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount * This class helps open, create, and upgrade the database file. 67865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount */ 68865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount private static class DatabaseHelper extends SQLiteOpenHelper { 69865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 70865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount DatabaseHelper(Context context) { 71865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount super(context, DATABASE_NAME, null, DATABASE_VERSION); 72865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount } 73865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 74865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount @Override 75865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount public void onCreate(SQLiteDatabase db) { 76865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount db.execSQL("CREATE TABLE " + USERDICT_TABLE_NAME + " (" 77865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount + Words._ID + " INTEGER PRIMARY KEY," 78865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount + Words.WORD + " TEXT," 79865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount + Words.FREQUENCY + " INTEGER," 80865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount + Words.LOCALE + " TEXT," 81865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount + Words.APP_ID + " INTEGER" 82865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount + ");"); 83865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount } 84865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 85865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount @Override 86865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 87865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount Log.w(TAG, "Upgrading database from version " + oldVersion + " to " 88865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount + newVersion + ", which will destroy all old data"); 89865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount db.execSQL("DROP TABLE IF EXISTS " + USERDICT_TABLE_NAME); 90865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount onCreate(db); 91865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount } 92865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount } 93865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 94865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount private DatabaseHelper mOpenHelper; 95865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 96865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount @Override 97865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount public boolean onCreate() { 98865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount mOpenHelper = new DatabaseHelper(getContext()); 99c5885c466b80dfda79a364e5623348469f8eb8dbAmith Yamasani mBackupManager = new BackupManager(getContext()); 100865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount return true; 101865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount } 102865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 103865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount @Override 104865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, 105865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount String sortOrder) { 106865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); 107865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 108865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount switch (sUriMatcher.match(uri)) { 109865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount case WORDS: 110865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount qb.setTables(USERDICT_TABLE_NAME); 111865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount qb.setProjectionMap(sDictProjectionMap); 112865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount break; 113865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 114865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount case WORD_ID: 115865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount qb.setTables(USERDICT_TABLE_NAME); 116865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount qb.setProjectionMap(sDictProjectionMap); 117865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount qb.appendWhere("_id" + "=" + uri.getPathSegments().get(1)); 118865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount break; 119865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 120865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount default: 121865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount throw new IllegalArgumentException("Unknown URI " + uri); 122865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount } 123865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 124865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount // If no sort order is specified use the default 125865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount String orderBy; 126865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount if (TextUtils.isEmpty(sortOrder)) { 127865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount orderBy = Words.DEFAULT_SORT_ORDER; 128865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount } else { 129865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount orderBy = sortOrder; 130865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount } 131865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 132865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount // Get the database and run the query 133865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount SQLiteDatabase db = mOpenHelper.getReadableDatabase(); 134865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy); 135865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 136865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount // Tell the cursor what uri to watch, so it knows when its source data changes 137865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount c.setNotificationUri(getContext().getContentResolver(), uri); 138865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount return c; 139865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount } 140865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 141865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount @Override 142865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount public String getType(Uri uri) { 143865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount switch (sUriMatcher.match(uri)) { 144865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount case WORDS: 145865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount return Words.CONTENT_TYPE; 146865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 147865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount case WORD_ID: 148865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount return Words.CONTENT_ITEM_TYPE; 149865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 150865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount default: 151865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount throw new IllegalArgumentException("Unknown URI " + uri); 152865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount } 153865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount } 154865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 155865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount @Override 156865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount public Uri insert(Uri uri, ContentValues initialValues) { 157865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount // Validate the requested uri 158865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount if (sUriMatcher.match(uri) != WORDS) { 159865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount throw new IllegalArgumentException("Unknown URI " + uri); 160865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount } 161865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 162865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount ContentValues values; 163865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount if (initialValues != null) { 164865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount values = new ContentValues(initialValues); 165865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount } else { 166865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount values = new ContentValues(); 167865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount } 168865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 169865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount if (values.containsKey(Words.WORD) == false) { 170865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount throw new SQLException("Word must be specified"); 171865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount } 172865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 173865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount if (values.containsKey(Words.FREQUENCY) == false) { 174865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount values.put(Words.FREQUENCY, "1"); 175865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount } 176865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 177865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount if (values.containsKey(Words.LOCALE) == false) { 178865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount values.put(Words.LOCALE, (String) null); 179865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount } 180865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 181865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount values.put(Words.APP_ID, 0); 182865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 183865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount SQLiteDatabase db = mOpenHelper.getWritableDatabase(); 184865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount long rowId = db.insert(USERDICT_TABLE_NAME, Words.WORD, values); 185865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount if (rowId > 0) { 186865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount Uri wordUri = ContentUris.withAppendedId(UserDictionary.Words.CONTENT_URI, rowId); 187865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount getContext().getContentResolver().notifyChange(wordUri, null); 188c5885c466b80dfda79a364e5623348469f8eb8dbAmith Yamasani mBackupManager.dataChanged(); 189865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount return wordUri; 190865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount } 191865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 192865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount throw new SQLException("Failed to insert row into " + uri); 193865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount } 194865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 195865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount @Override 196865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount public int delete(Uri uri, String where, String[] whereArgs) { 197865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount SQLiteDatabase db = mOpenHelper.getWritableDatabase(); 198865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount int count; 199865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount switch (sUriMatcher.match(uri)) { 200865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount case WORDS: 201865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount count = db.delete(USERDICT_TABLE_NAME, where, whereArgs); 202865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount break; 203865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 204865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount case WORD_ID: 205865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount String wordId = uri.getPathSegments().get(1); 206865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount count = db.delete(USERDICT_TABLE_NAME, Words._ID + "=" + wordId 207865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount + (!TextUtils.isEmpty(where) ? " AND (" + where + ')' : ""), whereArgs); 208865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount break; 209865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 210865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount default: 211865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount throw new IllegalArgumentException("Unknown URI " + uri); 212865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount } 213865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 214865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount getContext().getContentResolver().notifyChange(uri, null); 215c5885c466b80dfda79a364e5623348469f8eb8dbAmith Yamasani mBackupManager.dataChanged(); 216865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount return count; 217865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount } 218865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 219865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount @Override 220865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount public int update(Uri uri, ContentValues values, String where, String[] whereArgs) { 221865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount SQLiteDatabase db = mOpenHelper.getWritableDatabase(); 222865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount int count; 223865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount switch (sUriMatcher.match(uri)) { 224865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount case WORDS: 225865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount count = db.update(USERDICT_TABLE_NAME, values, where, whereArgs); 226865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount break; 227865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 228865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount case WORD_ID: 229865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount String wordId = uri.getPathSegments().get(1); 230865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount count = db.update(USERDICT_TABLE_NAME, values, Words._ID + "=" + wordId 231865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount + (!TextUtils.isEmpty(where) ? " AND (" + where + ')' : ""), whereArgs); 232865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount break; 233865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 234865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount default: 235865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount throw new IllegalArgumentException("Unknown URI " + uri); 236865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount } 237865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 238865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount getContext().getContentResolver().notifyChange(uri, null); 239c5885c466b80dfda79a364e5623348469f8eb8dbAmith Yamasani mBackupManager.dataChanged(); 240865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount return count; 241865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount } 242865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 243865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount static { 244865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH); 245865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount sUriMatcher.addURI(AUTHORITY, "words", WORDS); 246865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount sUriMatcher.addURI(AUTHORITY, "words/#", WORD_ID); 247865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount 248865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount sDictProjectionMap = new HashMap<String, String>(); 249865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount sDictProjectionMap.put(Words._ID, Words._ID); 250865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount sDictProjectionMap.put(Words.WORD, Words.WORD); 251865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount sDictProjectionMap.put(Words.FREQUENCY, Words.FREQUENCY); 252865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount sDictProjectionMap.put(Words.LOCALE, Words.LOCALE); 253865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount sDictProjectionMap.put(Words.APP_ID, Words.APP_ID); 254865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount } 255865b14b5faf8df8c090efa181ee5c5641f362fcandroid-build SharedAccount} 256