Update the current IME label
Bug: 5069983 Change-Id: I84d6ac7c39b5f3a035aa04c35065280a14024c47
This commit is contained in:
@@ -33,13 +33,11 @@
|
||||
android:id="@android:id/widget_frame"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginLeft="10dip"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="vertical" />
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="15dip"
|
||||
android:layout_marginRight="6dip"
|
||||
android:layout_marginTop="6dip"
|
||||
android:layout_marginBottom="6dip"
|
||||
|
@@ -19,16 +19,18 @@ package com.android.settings.inputmethod;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Settings.SpellCheckersSettingsActivity;
|
||||
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.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.database.ContentObserver;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
@@ -74,6 +76,9 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
|
||||
private InputMethodManager mImm;
|
||||
private List<InputMethodInfo> mImis;
|
||||
private boolean mIsOnlyImeSettings;
|
||||
private Handler mHandler;
|
||||
@SuppressWarnings("unused")
|
||||
private SettingsObserver mSettingsObserver;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
@@ -122,6 +127,9 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
|
||||
if (scp != null) {
|
||||
scp.setFragmentIntent(this, intent);
|
||||
}
|
||||
|
||||
mHandler = new Handler();
|
||||
mSettingsObserver = new SettingsObserver(mHandler, getActivity());
|
||||
}
|
||||
|
||||
private void updateInputMethodSelectorSummary(int value) {
|
||||
@@ -269,6 +277,22 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
|
||||
((InputMethodPreference)pref).updateSummary();
|
||||
}
|
||||
}
|
||||
updateCurrentImeName();
|
||||
}
|
||||
|
||||
private void updateCurrentImeName() {
|
||||
final Context context = getActivity();
|
||||
if (context == null || mImm == null) return;
|
||||
final Preference curPref = getPreferenceScreen().findPreference(KEY_CURRENT_INPUT_METHOD);
|
||||
if (curPref != null) {
|
||||
final CharSequence curIme = InputMethodAndSubtypeUtil.getCurrentInputMethodName(
|
||||
context, getContentResolver(), mImm, mImis, getPackageManager());
|
||||
if (!TextUtils.isEmpty(curIme)) {
|
||||
synchronized(this) {
|
||||
curPref.setSummary(curIme);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private InputMethodPreference getInputMethodPreference(InputMethodInfo imi, int imiSize) {
|
||||
@@ -333,4 +357,19 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
|
||||
root.addPreference(mInputMethodPreferenceList.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
private class SettingsObserver extends ContentObserver {
|
||||
public SettingsObserver(Handler handler, Context context) {
|
||||
super(handler);
|
||||
final ContentResolver cr = context.getContentResolver();
|
||||
cr.registerContentObserver(
|
||||
Settings.Secure.getUriFor(Settings.Secure.DEFAULT_INPUT_METHOD), false, this);
|
||||
cr.registerContentObserver(Settings.Secure.getUriFor(
|
||||
Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE), false, this);
|
||||
}
|
||||
|
||||
@Override public void onChange(boolean selfChange) {
|
||||
updateCurrentImeName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -19,7 +19,9 @@ package com.android.settings.inputmethod;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceScreen;
|
||||
@@ -28,6 +30,7 @@ import android.provider.Settings.SettingNotFoundException;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.inputmethod.InputMethodInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.view.inputmethod.InputMethodSubtype;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -148,6 +151,28 @@ public class InputMethodAndSubtypeUtil {
|
||||
return set;
|
||||
}
|
||||
|
||||
public static CharSequence getCurrentInputMethodName(Context context, ContentResolver resolver,
|
||||
InputMethodManager imm, List<InputMethodInfo> imis, PackageManager pm) {
|
||||
if (resolver == null || imis == null) return null;
|
||||
final String currentInputMethodId = Settings.Secure.getString(resolver,
|
||||
Settings.Secure.DEFAULT_INPUT_METHOD);
|
||||
if (TextUtils.isEmpty(currentInputMethodId)) return null;
|
||||
for (InputMethodInfo imi : imis) {
|
||||
if (currentInputMethodId.equals(imi.getId())) {
|
||||
final InputMethodSubtype subtype = imm.getCurrentInputMethodSubtype();
|
||||
final CharSequence imiLabel = imi.loadLabel(pm);
|
||||
final CharSequence summary = subtype != null
|
||||
? TextUtils.concat(subtype.getDisplayName(context,
|
||||
imi.getPackageName(), imi.getServiceInfo().applicationInfo),
|
||||
(TextUtils.isEmpty(imiLabel) ?
|
||||
"" : " - " + imiLabel))
|
||||
: imiLabel;
|
||||
return summary;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void saveInputMethodSubtypeList(SettingsPreferenceFragment context,
|
||||
ContentResolver resolver, List<InputMethodInfo> inputMethodInfos,
|
||||
boolean hasHardKeyboard) {
|
||||
|
Reference in New Issue
Block a user