Use internal personal dictionary settings on JBMR2 or before

Bug: 9117704
Change-Id: I7e20b03daa23b59211235183cf48d933e32845e4
main
Satoshi Kataoka 2013-06-27 14:10:50 +09:00
parent d9e08beebf
commit a2bfd46adf
2 changed files with 44 additions and 11 deletions

View File

@ -25,6 +25,7 @@ import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
@ -51,7 +52,10 @@ import java.util.TreeSet;
public final class SettingsFragment extends InputMethodSettingsFragment
implements SharedPreferences.OnSharedPreferenceChangeListener {
private static final String TAG = SettingsFragment.class.getSimpleName();
private static final boolean DBG_USE_INTERNAL_USER_DICTIONARY_SETTINGS = false;
private static final boolean DBG_USE_INTERNAL_PERSONAL_DICTIONARY_SETTINGS = false;
private static final boolean USE_INTERNAL_PERSONAL_DICTIONARY_SETTIGS =
DBG_USE_INTERNAL_PERSONAL_DICTIONARY_SETTINGS
|| Build.VERSION.SDK_INT <= 18 /* Build.VERSION.JELLY_BEAN_MR2 */;
private ListPreference mVoicePreference;
private ListPreference mShowCorrectionSuggestionsPreference;
@ -212,10 +216,11 @@ public final class SettingsFragment extends InputMethodSettingsFragment
final Preference editPersonalDictionary =
findPreference(Settings.PREF_EDIT_PERSONAL_DICTIONARY);
final Intent editPersonalDictionaryIntent = editPersonalDictionary.getIntent();
final ResolveInfo ri = context.getPackageManager().resolveActivity(
final ResolveInfo ri = USE_INTERNAL_PERSONAL_DICTIONARY_SETTIGS ? null
: context.getPackageManager().resolveActivity(
editPersonalDictionaryIntent, PackageManager.MATCH_DEFAULT_ONLY);
if (DBG_USE_INTERNAL_USER_DICTIONARY_SETTINGS || ri == null) {
updateUserDictionaryPreference(editPersonalDictionary);
if (ri == null) {
overwriteUserDictionaryPreference(editPersonalDictionary);
}
if (!Settings.readFromBuildConfigIfGestureInputEnabled(res)) {
@ -470,7 +475,7 @@ public final class SettingsFragment extends InputMethodSettingsFragment
});
}
private void updateUserDictionaryPreference(Preference userDictionaryPreference) {
private void overwriteUserDictionaryPreference(Preference userDictionaryPreference) {
final Activity activity = getActivity();
final TreeSet<String> localeList = UserDictionaryList.getUserDictionaryLocalesSet(activity);
if (null == localeList) {

View File

@ -17,6 +17,7 @@
package com.android.inputmethod.latin.userdictionary;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
@ -25,10 +26,14 @@ import android.preference.PreferenceFragment;
import android.preference.PreferenceGroup;
import android.provider.UserDictionary;
import android.text.TextUtils;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.utils.LocaleUtils;
import java.util.List;
import java.util.Locale;
import java.util.TreeSet;
@ -52,7 +57,7 @@ public class UserDictionaryList extends PreferenceFragment {
final Cursor cursor = activity.managedQuery(UserDictionary.Words.CONTENT_URI,
new String[] { UserDictionary.Words.LOCALE },
null, null, null);
final TreeSet<String> localeList = new TreeSet<String>();
final TreeSet<String> localeSet = new TreeSet<String>();
boolean addedAllLocale = false;
if (null == cursor) {
// The user dictionary service is not present or disabled. Return null.
@ -62,7 +67,7 @@ public class UserDictionaryList extends PreferenceFragment {
do {
final String locale = cursor.getString(columnIndex);
final boolean allLocale = TextUtils.isEmpty(locale);
localeList.add(allLocale ? "" : locale);
localeSet.add(allLocale ? "" : locale);
if (allLocale) {
addedAllLocale = true;
}
@ -71,10 +76,33 @@ public class UserDictionaryList extends PreferenceFragment {
if (!UserDictionarySettings.IS_SHORTCUT_API_SUPPORTED && !addedAllLocale) {
// For ICS, we need to show "For all languages" in case that the keyboard locale
// is different from the system locale
localeList.add("");
localeSet.add("");
}
localeList.add(Locale.getDefault().toString());
return localeList;
final InputMethodManager imm =
(InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
final List<InputMethodInfo> imis = imm.getEnabledInputMethodList();
for (final InputMethodInfo imi : imis) {
final List<InputMethodSubtype> subtypes =
imm.getEnabledInputMethodSubtypeList(
imi, true /* allowsImplicitlySelectedSubtypes */);
for (InputMethodSubtype subtype : subtypes) {
final String locale = subtype.getLocale();
if (!TextUtils.isEmpty(locale)) {
localeSet.add(locale);
}
}
}
// We come here after we have collected locales from existing user dictionary entries and
// enabled subtypes. If we already have the locale-without-country version of the system
// locale, we don't add the system locale to avoid confusion even though it's technically
// correct to add it.
if (!localeSet.contains(Locale.getDefault().getLanguage().toString())) {
localeSet.add(Locale.getDefault().toString());
}
return localeSet;
}
/**