summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/inputmethod/UserDictionaryList.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/inputmethod/UserDictionaryList.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/inputmethod/UserDictionaryList.java')
-rw-r--r--src/com/android/settings/inputmethod/UserDictionaryList.java109
1 files changed, 109 insertions, 0 deletions
diff --git a/src/com/android/settings/inputmethod/UserDictionaryList.java b/src/com/android/settings/inputmethod/UserDictionaryList.java
new file mode 100644
index 0000000..5db2841
--- /dev/null
+++ b/src/com/android/settings/inputmethod/UserDictionaryList.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.inputmethod;
+
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.UserDictionarySettings;
+import com.android.settings.Utils;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.database.Cursor;
+import android.os.Bundle;
+import android.preference.Preference;
+import android.preference.PreferenceGroup;
+import android.provider.UserDictionary;
+
+import java.util.Locale;
+import java.util.Set;
+import java.util.TreeSet;
+
+public class UserDictionaryList extends SettingsPreferenceFragment {
+
+ private static final String USER_DICTIONARY_SETTINGS_INTENT_ACTION =
+ "android.settings.USER_DICTIONARY_SETTINGS";
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+ setPreferenceScreen(getPreferenceManager().createPreferenceScreen(getActivity()));
+ }
+
+ static Set<String> getUserDictionaryLocalesList(Activity activity) {
+ final Cursor cursor = activity.managedQuery(UserDictionary.Words.CONTENT_URI,
+ new String[] { UserDictionary.Words.LOCALE },
+ null, null, null);
+ final Set<String> localeList = new TreeSet<String>();
+ if (cursor.moveToFirst()) {
+ final int columnIndex = cursor.getColumnIndex(UserDictionary.Words.LOCALE);
+ do {
+ String locale = cursor.getString(columnIndex);
+ localeList.add(null != locale ? locale : "");
+ } while (cursor.moveToNext());
+ }
+ localeList.add(Locale.getDefault().toString());
+ return localeList;
+ }
+
+ /**
+ * Creates the entries that allow the user to go into the user dictionary for each locale.
+ * @param userDictGroup The group to put the settings in.
+ */
+ protected void createUserDictSettings(PreferenceGroup userDictGroup) {
+ final Activity activity = getActivity();
+ userDictGroup.removeAll();
+ final Set<String> localeList = UserDictionaryList.getUserDictionaryLocalesList(activity);
+
+ if (localeList.isEmpty()) {
+ userDictGroup.addPreference(createUserDictionaryPreference(null, activity));
+ } else {
+ for (String locale : localeList) {
+ userDictGroup.addPreference(createUserDictionaryPreference(locale, activity));
+ }
+ }
+ }
+
+ /**
+ * Create a single User Dictionary Preference object, with its parameters set.
+ * @param locale The locale for which this user dictionary is for.
+ * @return The corresponding preference.
+ */
+ protected Preference createUserDictionaryPreference(String locale, Activity activity) {
+ final Preference newPref = new Preference(getActivity());
+ final Intent intent = new Intent(USER_DICTIONARY_SETTINGS_INTENT_ACTION);
+ if (null == locale) {
+ newPref.setTitle(Locale.getDefault().getDisplayName());
+ } else {
+ if ("".equals(locale))
+ newPref.setTitle(getString(R.string.user_dict_settings_all_languages));
+ else
+ newPref.setTitle(Utils.createLocaleFromString(locale).getDisplayName());
+ intent.putExtra("locale", locale);
+ newPref.getExtras().putString("locale", locale);
+ }
+ newPref.setIntent(intent);
+ newPref.setFragment(UserDictionarySettings.class.getName());
+ return newPref;
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ createUserDictSettings(getPreferenceScreen());
+ }
+}