Refactor InputMethodSubtypePreference constructor
Change-Id: I959c0be5ebe4f39ca0b06e3f1b262a10f214c5bd
This commit is contained in:
@@ -267,7 +267,7 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final CheckBoxPreference chkbxPref = new InputMethodSubtypePreference(
|
final CheckBoxPreference chkbxPref = new InputMethodSubtypePreference(
|
||||||
context, subtype.getLocale(), mSystemLocale, mCollator);
|
context, subtype, imi, mCollator);
|
||||||
chkbxPref.setKey(imiId + subtype.hashCode());
|
chkbxPref.setKey(imiId + subtype.hashCode());
|
||||||
chkbxPref.setTitle(subtypeLabel);
|
chkbxPref.setTitle(subtypeLabel);
|
||||||
subtypePreferences.add(chkbxPref);
|
subtypePreferences.add(chkbxPref);
|
||||||
|
|||||||
@@ -21,8 +21,13 @@ import android.preference.CheckBoxPreference;
|
|||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.inputmethod.InputMethodInfo;
|
||||||
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
|
|
||||||
|
import com.android.internal.inputmethod.InputMethodUtils;
|
||||||
|
|
||||||
import java.text.Collator;
|
import java.text.Collator;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Input method subtype preference.
|
* Input method subtype preference.
|
||||||
@@ -37,16 +42,23 @@ class InputMethodSubtypePreference extends CheckBoxPreference {
|
|||||||
private final boolean mIsSystemLanguage;
|
private final boolean mIsSystemLanguage;
|
||||||
private final Collator mCollator;
|
private final Collator mCollator;
|
||||||
|
|
||||||
public InputMethodSubtypePreference(
|
public InputMethodSubtypePreference(final Context context, final InputMethodSubtype subtype,
|
||||||
Context context, String subtypeLocale, String systemLocale, Collator collator) {
|
final InputMethodInfo imi, final Collator collator) {
|
||||||
super(context);
|
super(context);
|
||||||
if (TextUtils.isEmpty(subtypeLocale)) {
|
setKey(imi.getId() + subtype.hashCode());
|
||||||
|
final CharSequence subtypeLabel = subtype.getDisplayName(context,
|
||||||
|
imi.getPackageName(), imi.getServiceInfo().applicationInfo);
|
||||||
|
setTitle(subtypeLabel);
|
||||||
|
final String subtypeLocaleString = subtype.getLocale();
|
||||||
|
if (TextUtils.isEmpty(subtypeLocaleString)) {
|
||||||
mIsSystemLocale = false;
|
mIsSystemLocale = false;
|
||||||
mIsSystemLanguage = false;
|
mIsSystemLanguage = false;
|
||||||
} else {
|
} else {
|
||||||
mIsSystemLocale = subtypeLocale.equals(systemLocale);
|
final Locale systemLocale = context.getResources().getConfiguration().locale;
|
||||||
|
mIsSystemLocale = subtypeLocaleString.equals(systemLocale.toString());
|
||||||
mIsSystemLanguage = mIsSystemLocale
|
mIsSystemLanguage = mIsSystemLocale
|
||||||
|| subtypeLocale.startsWith(systemLocale.substring(0, 2));
|
|| InputMethodUtils.getLanguageFromLocaleString(subtypeLocaleString)
|
||||||
|
.equals(systemLocale.getLanguage());
|
||||||
}
|
}
|
||||||
mCollator = collator;
|
mCollator = collator;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user