summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/UserDictionarySettings.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2011-05-12 15:06:16 +0900
committerJean Chalard <jchalard@google.com>2011-05-18 12:54:20 +0900
commit71ad1f4e3e819a40a830a148a2d1bd7b10fed09d (patch)
treed2fc1ff10742740977fcb7f1d4c6000846fce67f /src/com/android/settings/UserDictionarySettings.java
parent309f385794e6a399e3f06c15e4fbf757f975fb0d (diff)
downloadpackages_apps_Settings-71ad1f4e3e819a40a830a148a2d1bd7b10fed09d.zip
packages_apps_Settings-71ad1f4e3e819a40a830a148a2d1bd7b10fed09d.tar.gz
packages_apps_Settings-71ad1f4e3e819a40a830a148a2d1bd7b10fed09d.tar.bz2
Change the interface for user dictionary multiple locales.
The user dictionary interface now works the following way: * Locale gathering - The current locale is always considered as present, even if there are no words for it in the user dictionary. - Any locale for which at least one word is registered is considered present. - A null locale is considered a valid locale meaning "all languages". - If no words are present at all, since the current locale is always considered present, the system will consider there is exactly one locale present - and allow editing this user dictionary. * Options display - If only one locale is present, the interface is the same as for Honeycomb: display a "User dictionary" PreferenceScreen that brings up the dictionary editor interface. - If there are several locales present, then the user dictionary option will jump to a screen that will display a list of available locales. * Word insertion - Inserting a word will always use the locale of the currently displayed dictionary. If it is the "all languages" null pseudo-locale, that will still hold and the word will be added to this pseudo-locale. It is worthy to note that the "All languages" locale is only accessible if for some reason there are already words with a null locale in the database before this is installed. For example, if an application has inserted some words that way, or if the user inserted words with a previous version of the settings application. On a freshly flashed device, barring the use of third-party application that would add such words, it is not possible to access the "all languages" locale any more because there is no interface to do it, though it works if such words are inside. Bug: 3479738 Change-Id: Iba323e5aeb3f4f575896903a4e8bef6ffb3ea306
Diffstat (limited to 'src/com/android/settings/UserDictionarySettings.java')
-rw-r--r--src/com/android/settings/UserDictionarySettings.java86
1 files changed, 70 insertions, 16 deletions
diff --git a/src/com/android/settings/UserDictionarySettings.java b/src/com/android/settings/UserDictionarySettings.java
index d0ab472..22112d7 100644
--- a/src/com/android/settings/UserDictionarySettings.java
+++ b/src/com/android/settings/UserDictionarySettings.java
@@ -46,6 +46,7 @@ import android.widget.TextView;
import com.android.settings.SettingsPreferenceFragment.SettingsDialogFragment;
+import java.util.Arrays;
import java.util.Locale;
public class UserDictionarySettings extends ListFragment implements DialogCreatable {
@@ -63,23 +64,29 @@ public class UserDictionarySettings extends ListFragment implements DialogCreata
// Either the locale is empty (means the word is applicable to all locales)
// or the word equals our current locale
- private static final String QUERY_SELECTION = UserDictionary.Words.LOCALE + "=? OR "
- + UserDictionary.Words.LOCALE + " is null";
+ private static final String QUERY_SELECTION =
+ UserDictionary.Words.LOCALE + "=?";
+ private static final String QUERY_SELECTION_ALL_LOCALES =
+ UserDictionary.Words.LOCALE + " is null";
private static final String DELETE_SELECTION = UserDictionary.Words.WORD + "=?";
private static final String EXTRA_WORD = "word";
-
+
private static final int OPTIONS_MENU_ADD = Menu.FIRST;
private static final int DIALOG_ADD_OR_EDIT = 0;
-
+
+ private static final int FREQUENCY_FOR_USER_DICTIONARY_ADDS = 250;
+
/** The word being edited in the dialog (null means the user is adding a word). */
private String mDialogEditingWord;
private View mView;
private Cursor mCursor;
-
+
+ protected String mLocale;
+
private boolean mAddedWordAlready;
private boolean mAutoReturn;
@@ -102,9 +109,24 @@ public class UserDictionarySettings extends ListFragment implements DialogCreata
super.onActivityCreated(savedInstanceState);
final Intent intent = getActivity().getIntent();
- final String locale = intent.getStringExtra("locale");
+ final String localeFromIntent =
+ null == intent ? null : intent.getStringExtra("locale");
+
+ final Bundle arguments = getArguments();
+ final String localeFromArguments =
+ null == arguments ? null : arguments.getString("locale");
+
+ final String locale;
+ if (null != localeFromArguments) {
+ locale = localeFromArguments;
+ } else if (null != localeFromIntent) {
+ locale = localeFromIntent;
+ } else {
+ locale = null;
+ }
- mCursor = createCursor(null != locale ? locale : Locale.getDefault().toString());
+ mLocale = locale;
+ mCursor = createCursor(locale);
TextView emptyView = (TextView)mView.findViewById(R.id.empty);
emptyView.setText(R.string.user_dict_settings_empty_text);
@@ -143,10 +165,27 @@ public class UserDictionarySettings extends ListFragment implements DialogCreata
}
private Cursor createCursor(final String locale) {
- // Case-insensitive sort
- return getActivity().managedQuery(UserDictionary.Words.CONTENT_URI, QUERY_PROJECTION,
- QUERY_SELECTION, new String[] { locale },
- "UPPER(" + UserDictionary.Words.WORD + ")");
+ // 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 + ")");
+ } else {
+ 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 + ")");
+ }
}
private ListAdapter createAdapter() {
@@ -155,7 +194,7 @@ public class UserDictionarySettings extends ListFragment implements DialogCreata
new String[] { UserDictionary.Words.WORD, UserDictionary.Words._ID },
new int[] { android.R.id.text1, R.id.delete_button }, this);
}
-
+
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
String word = getWord(position);
@@ -237,13 +276,28 @@ public class UserDictionarySettings extends ListFragment implements DialogCreata
// The user was editing a word, so do a delete/add
deleteWord(mDialogEditingWord);
}
-
+
// Disallow duplicates
deleteWord(word);
-
+
// TODO: present UI for picking whether to add word to all locales, or current.
- UserDictionary.Words.addWord(getActivity(), word.toString(),
- 250, UserDictionary.Words.LOCALE_TYPE_ALL);
+ if (null == mLocale) {
+ // Null means insert with the default system locale.
+ UserDictionary.Words.addWord(getActivity(), word.toString(),
+ FREQUENCY_FOR_USER_DICTIONARY_ADDS, UserDictionary.Words.LOCALE_TYPE_CURRENT);
+ } else if ("".equals(mLocale)) {
+ // Empty string means insert for all languages.
+ UserDictionary.Words.addWord(getActivity(), word.toString(),
+ FREQUENCY_FOR_USER_DICTIONARY_ADDS, UserDictionary.Words.LOCALE_TYPE_ALL);
+ } else {
+ // TODO: fix the framework so that it can accept a locale when we add a word
+ // to the user dictionary instead of querying the system locale.
+ final Locale prevLocale = Locale.getDefault();
+ Locale.setDefault(Utils.createLocaleFromString(mLocale));
+ UserDictionary.Words.addWord(getActivity(), word.toString(),
+ FREQUENCY_FOR_USER_DICTIONARY_ADDS, UserDictionary.Words.LOCALE_TYPE_CURRENT);
+ Locale.setDefault(prevLocale);
+ }
if (!mCursor.requery()) {
throw new IllegalStateException("can't requery on already-closed cursor.");
}