@@ -40,6 +40,9 @@ public class UserDictionary {
4040 public static final Uri CONTENT_URI =
4141 Uri .parse ("content://" + AUTHORITY );
4242
43+ private static final int FREQUENCY_MIN = 0 ;
44+ private static final int FREQUENCY_MAX = 255 ;
45+
4346 /**
4447 * Contains the user defined words.
4548 */
@@ -87,48 +90,90 @@ public static class Words implements BaseColumns {
8790 */
8891 public static final String APP_ID = "appid" ;
8992
90- /** The locale type to specify that the word is common to all locales. */
93+ /**
94+ * An optional shortcut for this word. When the shortcut is typed, supporting IMEs should
95+ * suggest the word in this row as an alternate spelling too.
96+ */
97+ public static final String SHORTCUT = "shortcut" ;
98+
99+ /**
100+ * @deprecated Use {@link #addWord(Context, String, int, String, Locale)}.
101+ */
102+ @ Deprecated
91103 public static final int LOCALE_TYPE_ALL = 0 ;
92-
93- /** The locale type to specify that the word is for the current locale. */
104+
105+ /**
106+ * @deprecated Use {@link #addWord(Context, String, int, String, Locale)}.
107+ */
108+ @ Deprecated
94109 public static final int LOCALE_TYPE_CURRENT = 1 ;
95-
110+
96111 /**
97112 * Sort by descending order of frequency.
98113 */
99114 public static final String DEFAULT_SORT_ORDER = FREQUENCY + " DESC" ;
100115
101116 /** Adds a word to the dictionary, with the given frequency and the specified
102117 * specified locale type.
118+ *
119+ * @deprecated Please use
120+ * {@link #addWord(Context, String, int, String, Locale)} instead.
121+ *
103122 * @param context the current application context
104123 * @param word the word to add to the dictionary. This should not be null or
105124 * empty.
106125 * @param localeType the locale type for this word. It should be one of
107126 * {@link #LOCALE_TYPE_ALL} or {@link #LOCALE_TYPE_CURRENT}.
108127 */
109- public static void addWord (Context context , String word ,
128+ @ Deprecated
129+ public static void addWord (Context context , String word ,
110130 int frequency , int localeType ) {
111- final ContentResolver resolver = context .getContentResolver ();
112131
113- if (TextUtils . isEmpty ( word ) || localeType < 0 || localeType > 1 ) {
132+ if (localeType != LOCALE_TYPE_ALL && localeType != LOCALE_TYPE_CURRENT ) {
114133 return ;
115134 }
116-
117- if (frequency < 0 ) frequency = 0 ;
118- if (frequency > 255 ) frequency = 255 ;
119135
120- String locale = null ;
136+ final Locale locale ;
121137
122- // TODO: Verify if this is the best way to get the current locale
123138 if (localeType == LOCALE_TYPE_CURRENT ) {
124- locale = Locale .getDefault ().toString ();
139+ locale = Locale .getDefault ();
140+ } else {
141+ locale = null ;
125142 }
126- ContentValues values = new ContentValues (4 );
143+
144+ addWord (context , word , frequency , null , locale );
145+ }
146+
147+ /** Adds a word to the dictionary, with the given frequency and the specified
148+ * locale type.
149+ *
150+ * @param context the current application context
151+ * @param word the word to add to the dictionary. This should not be null or
152+ * empty.
153+ * @param shortcut optional shortcut spelling for this word. When the shortcut
154+ * is typed, the word may be suggested by applications that support it. May be null.
155+ * @param locale the locale to insert the word for, or null to insert the word
156+ * for all locales.
157+ */
158+ public static void addWord (Context context , String word ,
159+ int frequency , String shortcut , Locale locale ) {
160+ final ContentResolver resolver = context .getContentResolver ();
161+
162+ if (TextUtils .isEmpty (word )) {
163+ return ;
164+ }
165+
166+ if (frequency < FREQUENCY_MIN ) frequency = FREQUENCY_MIN ;
167+ if (frequency > FREQUENCY_MAX ) frequency = FREQUENCY_MAX ;
168+
169+ final int COLUMN_COUNT = 5 ;
170+ ContentValues values = new ContentValues (COLUMN_COUNT );
127171
128172 values .put (WORD , word );
129173 values .put (FREQUENCY , frequency );
130- values .put (LOCALE , locale );
174+ values .put (LOCALE , null == locale ? null : locale . toString () );
131175 values .put (APP_ID , 0 ); // TODO: Get App UID
176+ values .put (SHORTCUT , shortcut );
132177
133178 Uri result = resolver .insert (CONTENT_URI , values );
134179 // It's ok if the insert doesn't succeed because the word
0 commit comments