Merge "Support automatic language"
This commit is contained in:
@@ -31,6 +31,7 @@ import android.preference.Preference;
|
|||||||
import android.preference.PreferenceCategory;
|
import android.preference.PreferenceCategory;
|
||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.inputmethod.InputMethodInfo;
|
import android.view.inputmethod.InputMethodInfo;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.view.inputmethod.InputMethodSubtype;
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
@@ -40,6 +41,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment {
|
public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment {
|
||||||
|
private static final String TAG =InputMethodAndSubtypeEnabler.class.getSimpleName();
|
||||||
private AlertDialog mDialog = null;
|
private AlertDialog mDialog = null;
|
||||||
private boolean mHaveHardKeyboard;
|
private boolean mHaveHardKeyboard;
|
||||||
final private HashMap<String, List<Preference>> mInputMethodAndSubtypePrefsMap =
|
final private HashMap<String, List<Preference>> mInputMethodAndSubtypePrefsMap =
|
||||||
@@ -223,37 +225,55 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment {
|
|||||||
if (!TextUtils.isEmpty(mInputMethodId) && !mInputMethodId.equals(imiId)) {
|
if (!TextUtils.isEmpty(mInputMethodId) && !mInputMethodId.equals(imiId)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
PreferenceCategory keyboardSettingsCategory = new PreferenceCategory(context);
|
final PreferenceCategory keyboardSettingsCategory = new PreferenceCategory(context);
|
||||||
root.addPreference(keyboardSettingsCategory);
|
root.addPreference(keyboardSettingsCategory);
|
||||||
PackageManager pm = getPackageManager();
|
final PackageManager pm = getPackageManager();
|
||||||
CharSequence label = imi.loadLabel(pm);
|
final CharSequence label = imi.loadLabel(pm);
|
||||||
|
|
||||||
keyboardSettingsCategory.setTitle(label);
|
keyboardSettingsCategory.setTitle(label);
|
||||||
keyboardSettingsCategory.setKey(imiId);
|
keyboardSettingsCategory.setKey(imiId);
|
||||||
// TODO: Use toggle Preference if images are ready.
|
// TODO: Use toggle Preference if images are ready.
|
||||||
CheckBoxPreference autoCB = new CheckBoxPreference(context);
|
final CheckBoxPreference autoCB = new CheckBoxPreference(context);
|
||||||
autoCB.setTitle(R.string.use_system_language_to_select_input_method_subtypes);
|
|
||||||
mSubtypeAutoSelectionCBMap.put(imiId, autoCB);
|
mSubtypeAutoSelectionCBMap.put(imiId, autoCB);
|
||||||
keyboardSettingsCategory.addPreference(autoCB);
|
keyboardSettingsCategory.addPreference(autoCB);
|
||||||
|
|
||||||
PreferenceCategory activeInputMethodsCategory = new PreferenceCategory(context);
|
final PreferenceCategory activeInputMethodsCategory = new PreferenceCategory(context);
|
||||||
activeInputMethodsCategory.setTitle(R.string.active_input_method_subtypes);
|
activeInputMethodsCategory.setTitle(R.string.active_input_method_subtypes);
|
||||||
root.addPreference(activeInputMethodsCategory);
|
root.addPreference(activeInputMethodsCategory);
|
||||||
|
|
||||||
ArrayList<Preference> subtypePreferences = new ArrayList<Preference>();
|
boolean isAutoSubtype = false;
|
||||||
|
CharSequence autoSubtypeLabel = null;
|
||||||
|
final ArrayList<Preference> subtypePreferences = new ArrayList<Preference>();
|
||||||
if (subtypeCount > 0) {
|
if (subtypeCount > 0) {
|
||||||
for (int j = 0; j < subtypeCount; ++j) {
|
for (int j = 0; j < subtypeCount; ++j) {
|
||||||
final InputMethodSubtype subtype = imi.getSubtypeAt(j);
|
final InputMethodSubtype subtype = imi.getSubtypeAt(j);
|
||||||
final CharSequence subtypeLabel = subtype.getDisplayName(context,
|
final CharSequence subtypeLabel = subtype.getDisplayName(context,
|
||||||
imi.getPackageName(), imi.getServiceInfo().applicationInfo);
|
imi.getPackageName(), imi.getServiceInfo().applicationInfo);
|
||||||
final CheckBoxPreference chkbxPref = new CheckBoxPreference(context);
|
if (subtype.overridesImplicitlyEnabledSubtype()) {
|
||||||
chkbxPref.setKey(imiId + subtype.hashCode());
|
if (!isAutoSubtype) {
|
||||||
chkbxPref.setTitle(subtypeLabel);
|
isAutoSubtype = true;
|
||||||
activeInputMethodsCategory.addPreference(chkbxPref);
|
autoSubtypeLabel = subtypeLabel;
|
||||||
subtypePreferences.add(chkbxPref);
|
}
|
||||||
|
} else {
|
||||||
|
final CheckBoxPreference chkbxPref = new CheckBoxPreference(context);
|
||||||
|
chkbxPref.setKey(imiId + subtype.hashCode());
|
||||||
|
chkbxPref.setTitle(subtypeLabel);
|
||||||
|
activeInputMethodsCategory.addPreference(chkbxPref);
|
||||||
|
subtypePreferences.add(chkbxPref);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
mInputMethodAndSubtypePrefsMap.put(imiId, subtypePreferences);
|
mInputMethodAndSubtypePrefsMap.put(imiId, subtypePreferences);
|
||||||
}
|
}
|
||||||
|
if (isAutoSubtype) {
|
||||||
|
if (TextUtils.isEmpty(autoSubtypeLabel)) {
|
||||||
|
Log.w(TAG, "Title for auto subtype is empty.");
|
||||||
|
autoCB.setTitle("---");
|
||||||
|
} else {
|
||||||
|
autoCB.setTitle(autoSubtypeLabel);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
autoCB.setTitle(R.string.use_system_language_to_select_input_method_subtypes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
@@ -23,7 +23,6 @@ import android.content.DialogInterface;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.provider.Settings;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
Reference in New Issue
Block a user