diff options
Diffstat (limited to 'src/com/android/settings/inputmethod')
-rw-r--r-- | src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java | 73 | ||||
-rw-r--r-- | src/com/android/settings/inputmethod/UserDictionaryList.java | 109 |
2 files changed, 131 insertions, 51 deletions
diff --git a/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java b/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java index 31c6879..c72f0ba 100644 --- a/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java +++ b/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java @@ -18,25 +18,21 @@ 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 com.android.settings.VoiceInputOutputSettings; import android.app.Activity; import android.content.Context; -import android.content.Intent; import android.content.res.Configuration; -import android.database.Cursor; import android.os.Bundle; import android.preference.ListPreference; import android.preference.Preference; -import android.preference.PreferenceGroup; import android.preference.PreferenceScreen; import android.provider.Settings; import android.view.inputmethod.InputMethodManager; -import android.provider.UserDictionary; -import java.util.Locale; -import java.util.TreeMap; +import java.util.Set; public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment implements Preference.OnPreferenceChangeListener{ @@ -45,8 +41,8 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment private static final String KEY_CURRENT_INPUT_METHOD = "current_input_method"; private static final String KEY_INPUT_METHOD_SELECTOR = "input_method_selector"; private static final String KEY_LANGUAGE_SETTINGS_CATEGORY = "language_settings_category"; - private static final String USER_DICTIONARY_SETTINGS_INTENT_ACTION = - "android.settings.USER_DICTIONARY_SETTINGS"; + private static final String KEY_USER_DICTIONARY_SETTINGS = "key_user_dictionary_settings"; + private int mDefaultInputMethodSelectorVisibility = 0; private ListPreference mShowInputMethodSelectorPref; @@ -70,9 +66,6 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment } else { mLanguagePref = findPreference(KEY_PHONE_LANGUAGE); } - - createUserDictSettings((PreferenceGroup) findPreference(KEY_LANGUAGE_SETTINGS_CATEGORY)); - mShowInputMethodSelectorPref = (ListPreference)findPreference( KEY_INPUT_METHOD_SELECTOR); mShowInputMethodSelectorPref.setOnPreferenceChangeListener(this); @@ -91,49 +84,26 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment } } - /** - * 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) { + private void updateUserDictionaryPreference(Preference userDictionaryPreference) { final Activity activity = getActivity(); - final Cursor locales = activity.managedQuery(UserDictionary.Words.CONTENT_URI, - new String[] { UserDictionary.Words.LOCALE }, - null, null, null); - final TreeMap<String, Preference> prefs = new TreeMap<String, Preference>(); - int order = findPreference(KEY_PHONE_LANGUAGE).getOrder(); - if (!locales.moveToFirst()) { - prefs.put("", createUserDictionaryPreference(null, activity, ++order)); + final Set<String> localeList = UserDictionaryList.getUserDictionaryLocalesList(activity); + if (localeList.size() <= 1) { + userDictionaryPreference.setTitle(R.string.user_dict_single_settings_title); + userDictionaryPreference.setFragment(UserDictionarySettings.class.getName()); + // If the size of localeList is 0, we don't set the locale parameter in the + // extras. This will be interpreted by the UserDictionarySettings class as + // meaning "the current locale". + // Note that with the current code for UserDictionaryList#getUserDictionaryLocalesList() + // the locale list always has at least one element, since it always includes the current + // locale explicitly. @see UserDictionaryList.getUserDictionaryLocalesList(). + if (localeList.size() == 1) { + final String locale = (String)localeList.toArray()[0]; + userDictionaryPreference.getExtras().putString("locale", locale); + } } else { - final int columnIndex = locales.getColumnIndex(UserDictionary.Words.LOCALE); - do { - final String locale = locales.getString(columnIndex); - if (locale != null && !prefs.containsKey(locale)) - prefs.put(locale, createUserDictionaryPreference(locale, activity, ++order)); - } while (locales.moveToNext()); - } - for (final Preference p : prefs.values()) { - userDictGroup.addPreference(p); - } - } - - /** - * 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, - int order) { - final Preference newPref = new Preference(getActivity()); - newPref.setOrder(order); - newPref.setTitle(activity.getString(R.string.user_dict_settings_title)); - final Intent intent = new Intent(USER_DICTIONARY_SETTINGS_INTENT_ACTION); - if (null != locale) { - newPref.setSummary(new Locale(locale).getDisplayName()); - intent.putExtra("locale", locale); + userDictionaryPreference.setTitle(R.string.user_dict_multiple_settings_title); + userDictionaryPreference.setFragment(UserDictionaryList.class.getName()); } - newPref.setIntent(intent); - return newPref; } @Override @@ -148,6 +118,7 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment } } + updateUserDictionaryPreference(findPreference(KEY_USER_DICTIONARY_SETTINGS)); mShowInputMethodSelectorPref.setOnPreferenceChangeListener(this); } 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()); + } +} |