android.provider.UserDictionary Java Examples
The following examples show how to use
android.provider.UserDictionary.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserDictionaryAddWordContents.java From openboard with GNU General Public License v3.0 | 6 votes |
private boolean hasWord(final String word, final Context context) { final Cursor cursor; // mLocale == "" indicates this is an entry for all languages. Here, mLocale can't // be null at all (it's ensured by the updateLocale method). if ("".equals(mLocale)) { cursor = context.getContentResolver().query(UserDictionary.Words.CONTENT_URI, HAS_WORD_PROJECTION, HAS_WORD_SELECTION_ALL_LOCALES, new String[] { word }, null /* sort order */); } else { cursor = context.getContentResolver().query(UserDictionary.Words.CONTENT_URI, HAS_WORD_PROJECTION, HAS_WORD_SELECTION_ONE_LOCALE, new String[] { word, mLocale }, null /* sort order */); } try { if (null == cursor) return false; return cursor.getCount() > 0; } finally { if (null != cursor) cursor.close(); } }
Example #2
Source File: PersonalDictionaryLookup.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 6 votes |
public void open() { Log.i(mTag, "open()"); // Schedule the initial load to run immediately. It's possible that the first call to // isValidWord occurs before the dictionary has actually loaded, so it should not // assume that the dictionary has been loaded. loadPersonalDictionary(); // Register the observer to be notified on changes to the personal dictionary and all // individual items. // // If the user is interacting with the Personal Dictionary settings UI, or with the // "Add to dictionary" drop-down option, duplicate notifications will be sent for the same // edit: if a new entry is added, there is a notification for the entry itself, and // separately for the entire dictionary. However, when used programmatically, // only notifications for the specific edits are sent. Thus, the observer is registered to // receive every possible notification, and instead has throttling logic to avoid doing too // many reloads. mResolver.registerContentObserver( UserDictionary.Words.CONTENT_URI, true /* notifyForDescendents */, mPersonalDictionaryContentObserver); }
Example #3
Source File: UserDictionarySettings.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 6 votes |
@SuppressWarnings("deprecation") private Cursor createCursor(final String locale) { // Locale can be any of: // - The string representation of a locale, as returned by Locale#toString() // - The empty string. This means we want a cursor returning words valid for all locales. // - null. This means we want a cursor for the current locale, whatever this is. // Note that this contrasts with the data inside the database, where NULL means "all // locales" and there should never be an empty string. The confusion is called by the // historical use of null for "all locales". // TODO: it should be easy to make this more readable by making the special values // human-readable, like "all_locales" and "current_locales" strings, provided they // can be guaranteed not to match locales that may exist. if ("".equals(locale)) { // Case-insensitive sort return getActivity().managedQuery(UserDictionary.Words.CONTENT_URI, QUERY_PROJECTION, QUERY_SELECTION_ALL_LOCALES, null, "UPPER(" + UserDictionary.Words.WORD + ")"); } final String queryLocale = null != locale ? locale : Locale.getDefault().toString(); return getActivity().managedQuery(UserDictionary.Words.CONTENT_URI, QUERY_PROJECTION, QUERY_SELECTION, new String[] { queryLocale }, "UPPER(" + UserDictionary.Words.WORD + ")"); }
Example #4
Source File: UserDictionaryAddWordContents.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 6 votes |
private boolean hasWord(final String word, final Context context) { final Cursor cursor; // mLocale == "" indicates this is an entry for all languages. Here, mLocale can't // be null at all (it's ensured by the updateLocale method). if ("".equals(mLocale)) { cursor = context.getContentResolver().query(UserDictionary.Words.CONTENT_URI, HAS_WORD_PROJECTION, HAS_WORD_SELECTION_ALL_LOCALES, new String[] { word }, null /* sort order */); } else { cursor = context.getContentResolver().query(UserDictionary.Words.CONTENT_URI, HAS_WORD_PROJECTION, HAS_WORD_SELECTION_ONE_LOCALE, new String[] { word, mLocale }, null /* sort order */); } try { if (null == cursor) return false; return cursor.getCount() > 0; } finally { if (null != cursor) cursor.close(); } }
Example #5
Source File: UserDictionaryAddWordContents.java From Indic-Keyboard with Apache License 2.0 | 6 votes |
private boolean hasWord(final String word, final Context context) { final Cursor cursor; // mLocale == "" indicates this is an entry for all languages. Here, mLocale can't // be null at all (it's ensured by the updateLocale method). if ("".equals(mLocale)) { cursor = context.getContentResolver().query(UserDictionary.Words.CONTENT_URI, HAS_WORD_PROJECTION, HAS_WORD_SELECTION_ALL_LOCALES, new String[] { word }, null /* sort order */); } else { cursor = context.getContentResolver().query(UserDictionary.Words.CONTENT_URI, HAS_WORD_PROJECTION, HAS_WORD_SELECTION_ONE_LOCALE, new String[] { word, mLocale }, null /* sort order */); } try { if (null == cursor) return false; return cursor.getCount() > 0; } finally { if (null != cursor) cursor.close(); } }
Example #6
Source File: UserDictionarySettings.java From Indic-Keyboard with Apache License 2.0 | 6 votes |
@SuppressWarnings("deprecation") private Cursor createCursor(final String locale) { // Locale can be any of: // - The string representation of a locale, as returned by Locale#toString() // - The empty string. This means we want a cursor returning words valid for all locales. // - null. This means we want a cursor for the current locale, whatever this is. // Note that this contrasts with the data inside the database, where NULL means "all // locales" and there should never be an empty string. The confusion is called by the // historical use of null for "all locales". // TODO: it should be easy to make this more readable by making the special values // human-readable, like "all_locales" and "current_locales" strings, provided they // can be guaranteed not to match locales that may exist. if ("".equals(locale)) { // Case-insensitive sort return getActivity().managedQuery(UserDictionary.Words.CONTENT_URI, QUERY_PROJECTION, QUERY_SELECTION_ALL_LOCALES, null, "UPPER(" + UserDictionary.Words.WORD + ")"); } final String queryLocale = null != locale ? locale : Locale.getDefault().toString(); return getActivity().managedQuery(UserDictionary.Words.CONTENT_URI, QUERY_PROJECTION, QUERY_SELECTION, new String[] { queryLocale }, "UPPER(" + UserDictionary.Words.WORD + ")"); }
Example #7
Source File: UserDictionarySettings.java From Android-Keyboard with Apache License 2.0 | 6 votes |
@SuppressWarnings("deprecation") private Cursor createCursor(final String locale) { // Locale can be any of: // - The string representation of a locale, as returned by Locale#toString() // - The empty string. This means we want a cursor returning words valid for all locales. // - null. This means we want a cursor for the current locale, whatever this is. // Note that this contrasts with the data inside the database, where NULL means "all // locales" and there should never be an empty string. The confusion is called by the // historical use of null for "all locales". // TODO: it should be easy to make this more readable by making the special values // human-readable, like "all_locales" and "current_locales" strings, provided they // can be guaranteed not to match locales that may exist. if ("".equals(locale)) { // Case-insensitive sort return getActivity().managedQuery(UserDictionary.Words.CONTENT_URI, QUERY_PROJECTION, QUERY_SELECTION_ALL_LOCALES, null, "UPPER(" + UserDictionary.Words.WORD + ")"); } final String queryLocale = null != locale ? locale : Locale.getDefault().toString(); return getActivity().managedQuery(UserDictionary.Words.CONTENT_URI, QUERY_PROJECTION, QUERY_SELECTION, new String[] { queryLocale }, "UPPER(" + UserDictionary.Words.WORD + ")"); }
Example #8
Source File: UserDictionaryAddWordContents.java From Android-Keyboard with Apache License 2.0 | 6 votes |
private boolean hasWord(final String word, final Context context) { final Cursor cursor; // mLocale == "" indicates this is an entry for all languages. Here, mLocale can't // be null at all (it's ensured by the updateLocale method). if ("".equals(mLocale)) { cursor = context.getContentResolver().query(UserDictionary.Words.CONTENT_URI, HAS_WORD_PROJECTION, HAS_WORD_SELECTION_ALL_LOCALES, new String[] { word }, null /* sort order */); } else { cursor = context.getContentResolver().query(UserDictionary.Words.CONTENT_URI, HAS_WORD_PROJECTION, HAS_WORD_SELECTION_ONE_LOCALE, new String[] { word, mLocale }, null /* sort order */); } try { if (null == cursor) return false; return cursor.getCount() > 0; } finally { if (null != cursor) cursor.close(); } }
Example #9
Source File: PersonalDictionaryLookup.java From openboard with GNU General Public License v3.0 | 6 votes |
public void open() { Log.i(mTag, "open()"); // Schedule the initial load to run immediately. It's possible that the first call to // isValidWord occurs before the dictionary has actually loaded, so it should not // assume that the dictionary has been loaded. loadPersonalDictionary(); // Register the observer to be notified on changes to the personal dictionary and all // individual items. // // If the user is interacting with the Personal Dictionary settings UI, or with the // "Add to dictionary" drop-down option, duplicate notifications will be sent for the same // edit: if a new entry is added, there is a notification for the entry itself, and // separately for the entire dictionary. However, when used programmatically, // only notifications for the specific edits are sent. Thus, the observer is registered to // receive every possible notification, and instead has throttling logic to avoid doing too // many reloads. mResolver.registerContentObserver( UserDictionary.Words.CONTENT_URI, true /* notifyForDescendents */, mPersonalDictionaryContentObserver); }
Example #10
Source File: PersonalDictionaryLookup.java From Indic-Keyboard with Apache License 2.0 | 6 votes |
public void open() { Log.i(mTag, "open()"); // Schedule the initial load to run immediately. It's possible that the first call to // isValidWord occurs before the dictionary has actually loaded, so it should not // assume that the dictionary has been loaded. loadPersonalDictionary(); // Register the observer to be notified on changes to the personal dictionary and all // individual items. // // If the user is interacting with the Personal Dictionary settings UI, or with the // "Add to dictionary" drop-down option, duplicate notifications will be sent for the same // edit: if a new entry is added, there is a notification for the entry itself, and // separately for the entire dictionary. However, when used programmatically, // only notifications for the specific edits are sent. Thus, the observer is registered to // receive every possible notification, and instead has throttling logic to avoid doing too // many reloads. mResolver.registerContentObserver( UserDictionary.Words.CONTENT_URI, true /* notifyForDescendents */, mPersonalDictionaryContentObserver); }
Example #11
Source File: UserDictionarySettings.java From openboard with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("deprecation") private Cursor createCursor(final String locale) { // Locale can be any of: // - The string representation of a locale, as returned by Locale#toString() // - The empty string. This means we want a cursor returning words valid for all locales. // - null. This means we want a cursor for the current locale, whatever this is. // Note that this contrasts with the data inside the database, where NULL means "all // locales" and there should never be an empty string. The confusion is called by the // historical use of null for "all locales". // TODO: it should be easy to make this more readable by making the special values // human-readable, like "all_locales" and "current_locales" strings, provided they // can be guaranteed not to match locales that may exist. if ("".equals(locale)) { // Case-insensitive sort return getActivity().managedQuery(UserDictionary.Words.CONTENT_URI, QUERY_PROJECTION, QUERY_SELECTION_ALL_LOCALES, null, "UPPER(" + UserDictionary.Words.WORD + ")"); } final String queryLocale = null != locale ? locale : Locale.getDefault().toString(); return getActivity().managedQuery(UserDictionary.Words.CONTENT_URI, QUERY_PROJECTION, QUERY_SELECTION, new String[] { queryLocale }, "UPPER(" + UserDictionary.Words.WORD + ")"); }
Example #12
Source File: UserDictionarySettings.java From Indic-Keyboard with Apache License 2.0 | 5 votes |
public static void deleteWord(final String word, final String shortcut, final ContentResolver resolver) { if (!IS_SHORTCUT_API_SUPPORTED) { resolver.delete(UserDictionary.Words.CONTENT_URI, DELETE_SELECTION_SHORTCUT_UNSUPPORTED, new String[] { word }); } else if (TextUtils.isEmpty(shortcut)) { resolver.delete( UserDictionary.Words.CONTENT_URI, DELETE_SELECTION_WITHOUT_SHORTCUT, new String[] { word }); } else { resolver.delete( UserDictionary.Words.CONTENT_URI, DELETE_SELECTION_WITH_SHORTCUT, new String[] { word, shortcut }); } }
Example #13
Source File: UserDictionarySettings.java From Indic-Keyboard with Apache License 2.0 | 5 votes |
private String getShortcut(final int position) { if (!IS_SHORTCUT_API_SUPPORTED) return null; if (null == mCursor) return null; mCursor.moveToPosition(position); // Handle a possible race-condition if (mCursor.isAfterLast()) return null; return mCursor.getString( mCursor.getColumnIndexOrThrow(UserDictionary.Words.SHORTCUT)); }
Example #14
Source File: UserDictionarySettings.java From Indic-Keyboard with Apache License 2.0 | 5 votes |
private String getWord(final int position) { if (null == mCursor) return null; mCursor.moveToPosition(position); // Handle a possible race-condition if (mCursor.isAfterLast()) return null; return mCursor.getString( mCursor.getColumnIndexOrThrow(UserDictionary.Words.WORD)); }
Example #15
Source File: UserDictionarySettings.java From Indic-Keyboard with Apache License 2.0 | 5 votes |
public MyAdapter(final Context context, final int layout, final Cursor c, final String[] from, final int[] to) { super(context, layout, c, from, to, 0 /* flags */); if (null != c) { final String alphabet = context.getString(R.string.user_dict_fast_scroll_alphabet); final int wordColIndex = c.getColumnIndexOrThrow(UserDictionary.Words.WORD); mIndexer = new AlphabetIndexer(c, wordColIndex, alphabet); } setViewBinder(mViewBinder); }
Example #16
Source File: UserDictionaryCompatUtils.java From Indic-Keyboard with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") public static void addWord(final Context context, final String word, final int freq, final String shortcut, final Locale locale) { if (BuildCompatUtils.EFFECTIVE_SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { addWordWithShortcut(context, word, freq, shortcut, locale); return; } // Fall back to the pre-JellyBean method. final Locale currentLocale = context.getResources().getConfiguration().locale; final int localeType = currentLocale.equals(locale) ? UserDictionary.Words.LOCALE_TYPE_CURRENT : UserDictionary.Words.LOCALE_TYPE_ALL; UserDictionary.Words.addWord(context, word, freq, localeType); }
Example #17
Source File: UserDictionaryCompatUtils.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") public static void addWord(final Context context, final String word, final int freq, final String shortcut, final Locale locale) { if (BuildCompatUtils.EFFECTIVE_SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { addWordWithShortcut(context, word, freq, shortcut, locale); return; } // Fall back to the pre-JellyBean method. final Locale currentLocale = context.getResources().getConfiguration().locale; final int localeType = currentLocale.equals(locale) ? UserDictionary.Words.LOCALE_TYPE_CURRENT : UserDictionary.Words.LOCALE_TYPE_ALL; UserDictionary.Words.addWord(context, word, freq, localeType); }
Example #18
Source File: PersonalDictionaryLookupTest.java From Indic-Keyboard with Apache License 2.0 | 5 votes |
/** * Adds the given word to the personal dictionary. * * @param word the word to add * @param locale the locale of the word to add * @param frequency the frequency of the word to add * @return the Uri for the given word */ @SuppressLint("NewApi") private Uri addWord(final String word, final Locale locale, int frequency, String shortcut) { // Add the given word for the given locale. UserDictionary.Words.addWord(mContext, word, frequency, shortcut, locale); // Obtain an Uri for the given word. Cursor cursor = mContentResolver.query(UserDictionary.Words.CONTENT_URI, null, UserDictionary.Words.WORD + "='" + word + "'", null, null); assertTrue(cursor.moveToFirst()); Uri uri = Uri.withAppendedPath(UserDictionary.Words.CONTENT_URI, cursor.getString(cursor.getColumnIndex(UserDictionary.Words._ID))); // Add the row to the backup for later clearing. mAddedBackup.add(uri); return uri; }
Example #19
Source File: UserDictionarySettings.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 5 votes |
public MyAdapter(final Context context, final int layout, final Cursor c, final String[] from, final int[] to) { super(context, layout, c, from, to, 0 /* flags */); if (null != c) { final String alphabet = context.getString(R.string.user_dict_fast_scroll_alphabet); final int wordColIndex = c.getColumnIndexOrThrow(UserDictionary.Words.WORD); mIndexer = new AlphabetIndexer(c, wordColIndex, alphabet); } setViewBinder(mViewBinder); }
Example #20
Source File: UserDictionarySettings.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 5 votes |
public static void deleteWord(final String word, final String shortcut, final ContentResolver resolver) { if (!IS_SHORTCUT_API_SUPPORTED) { resolver.delete(UserDictionary.Words.CONTENT_URI, DELETE_SELECTION_SHORTCUT_UNSUPPORTED, new String[] { word }); } else if (TextUtils.isEmpty(shortcut)) { resolver.delete( UserDictionary.Words.CONTENT_URI, DELETE_SELECTION_WITHOUT_SHORTCUT, new String[] { word }); } else { resolver.delete( UserDictionary.Words.CONTENT_URI, DELETE_SELECTION_WITH_SHORTCUT, new String[] { word, shortcut }); } }
Example #21
Source File: UserDictionarySettings.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 5 votes |
private String getShortcut(final int position) { if (!IS_SHORTCUT_API_SUPPORTED) return null; if (null == mCursor) return null; mCursor.moveToPosition(position); // Handle a possible race-condition if (mCursor.isAfterLast()) return null; return mCursor.getString( mCursor.getColumnIndexOrThrow(UserDictionary.Words.SHORTCUT)); }
Example #22
Source File: UserDictionarySettings.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 5 votes |
private String getWord(final int position) { if (null == mCursor) return null; mCursor.moveToPosition(position); // Handle a possible race-condition if (mCursor.isAfterLast()) return null; return mCursor.getString( mCursor.getColumnIndexOrThrow(UserDictionary.Words.WORD)); }
Example #23
Source File: UserDictionarySettings.java From Android-Keyboard with Apache License 2.0 | 5 votes |
public MyAdapter(final Context context, final int layout, final Cursor c, final String[] from, final int[] to) { super(context, layout, c, from, to, 0 /* flags */); if (null != c) { final String alphabet = context.getString(R.string.user_dict_fast_scroll_alphabet); final int wordColIndex = c.getColumnIndexOrThrow(UserDictionary.Words.WORD); mIndexer = new AlphabetIndexer(c, wordColIndex, alphabet); } setViewBinder(mViewBinder); }
Example #24
Source File: UserDictionarySettings.java From Android-Keyboard with Apache License 2.0 | 5 votes |
public static void deleteWord(final String word, final String shortcut, final ContentResolver resolver) { if (!IS_SHORTCUT_API_SUPPORTED) { resolver.delete(UserDictionary.Words.CONTENT_URI, DELETE_SELECTION_SHORTCUT_UNSUPPORTED, new String[] { word }); } else if (TextUtils.isEmpty(shortcut)) { resolver.delete( UserDictionary.Words.CONTENT_URI, DELETE_SELECTION_WITHOUT_SHORTCUT, new String[] { word }); } else { resolver.delete( UserDictionary.Words.CONTENT_URI, DELETE_SELECTION_WITH_SHORTCUT, new String[] { word, shortcut }); } }
Example #25
Source File: UserDictionarySettings.java From Android-Keyboard with Apache License 2.0 | 5 votes |
private String getShortcut(final int position) { if (!IS_SHORTCUT_API_SUPPORTED) return null; if (null == mCursor) return null; mCursor.moveToPosition(position); // Handle a possible race-condition if (mCursor.isAfterLast()) return null; return mCursor.getString( mCursor.getColumnIndexOrThrow(UserDictionary.Words.SHORTCUT)); }
Example #26
Source File: UserDictionarySettings.java From Android-Keyboard with Apache License 2.0 | 5 votes |
private String getWord(final int position) { if (null == mCursor) return null; mCursor.moveToPosition(position); // Handle a possible race-condition if (mCursor.isAfterLast()) return null; return mCursor.getString( mCursor.getColumnIndexOrThrow(UserDictionary.Words.WORD)); }
Example #27
Source File: UserDictionarySettings.java From openboard with GNU General Public License v3.0 | 5 votes |
public MyAdapter(final Context context, final int layout, final Cursor c, final String[] from, final int[] to) { super(context, layout, c, from, to, 0 /* flags */); if (null != c) { final String alphabet = context.getString(R.string.user_dict_fast_scroll_alphabet); final int wordColIndex = c.getColumnIndexOrThrow(UserDictionary.Words.WORD); mIndexer = new AlphabetIndexer(c, wordColIndex, alphabet); } setViewBinder(mViewBinder); }
Example #28
Source File: UserDictionarySettings.java From openboard with GNU General Public License v3.0 | 5 votes |
public static void deleteWord(final String word, final String shortcut, final ContentResolver resolver) { if (!IS_SHORTCUT_API_SUPPORTED) { resolver.delete(UserDictionary.Words.CONTENT_URI, DELETE_SELECTION_SHORTCUT_UNSUPPORTED, new String[] { word }); } else if (TextUtils.isEmpty(shortcut)) { resolver.delete( UserDictionary.Words.CONTENT_URI, DELETE_SELECTION_WITHOUT_SHORTCUT, new String[] { word }); } else { resolver.delete( UserDictionary.Words.CONTENT_URI, DELETE_SELECTION_WITH_SHORTCUT, new String[] { word, shortcut }); } }
Example #29
Source File: UserDictionarySettings.java From openboard with GNU General Public License v3.0 | 5 votes |
private String getShortcut(final int position) { if (!IS_SHORTCUT_API_SUPPORTED) return null; if (null == mCursor) return null; mCursor.moveToPosition(position); // Handle a possible race-condition if (mCursor.isAfterLast()) return null; return mCursor.getString( mCursor.getColumnIndexOrThrow(UserDictionary.Words.SHORTCUT)); }
Example #30
Source File: UserDictionarySettings.java From openboard with GNU General Public License v3.0 | 5 votes |
private String getWord(final int position) { if (null == mCursor) return null; mCursor.moveToPosition(position); // Handle a possible race-condition if (mCursor.isAfterLast()) return null; return mCursor.getString( mCursor.getColumnIndexOrThrow(UserDictionary.Words.WORD)); }