use of android.view.inputmethod.InputMethodSubtype in project android_frameworks_base by ParanoidAndroid.
the class QuickSettingsModel method getCurrentInputMethodName.
private static String 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 summary = subtype != null ? subtype.getDisplayName(context, imi.getPackageName(), imi.getServiceInfo().applicationInfo) : context.getString(R.string.quick_settings_ime_label);
return summary.toString();
}
}
return null;
}
use of android.view.inputmethod.InputMethodSubtype in project android_frameworks_base by ParanoidAndroid.
the class QuickSettingsModel method needsToShowImeSwitchOngoingNotification.
/* This implementation is taken from
InputMethodManagerService.needsToShowImeSwitchOngoingNotification(). */
private boolean needsToShowImeSwitchOngoingNotification(InputMethodManager imm) {
List<InputMethodInfo> imis = imm.getEnabledInputMethodList();
final int N = imis.size();
if (N > 2)
return true;
if (N < 1)
return false;
int nonAuxCount = 0;
int auxCount = 0;
InputMethodSubtype nonAuxSubtype = null;
InputMethodSubtype auxSubtype = null;
for (int i = 0; i < N; ++i) {
final InputMethodInfo imi = imis.get(i);
final List<InputMethodSubtype> subtypes = imm.getEnabledInputMethodSubtypeList(imi, true);
final int subtypeCount = subtypes.size();
if (subtypeCount == 0) {
++nonAuxCount;
} else {
for (int j = 0; j < subtypeCount; ++j) {
final InputMethodSubtype subtype = subtypes.get(j);
if (!subtype.isAuxiliary()) {
++nonAuxCount;
nonAuxSubtype = subtype;
} else {
++auxCount;
auxSubtype = subtype;
}
}
}
}
if (nonAuxCount > 1 || auxCount > 1) {
return true;
} else if (nonAuxCount == 1 && auxCount == 1) {
if (nonAuxSubtype != null && auxSubtype != null && (nonAuxSubtype.getLocale().equals(auxSubtype.getLocale()) || auxSubtype.overridesImplicitlyEnabledSubtype() || nonAuxSubtype.overridesImplicitlyEnabledSubtype()) && nonAuxSubtype.containsExtraValueKey(TAG_TRY_SUPPRESSING_IME_SWITCHER)) {
return false;
}
return true;
}
return false;
}
use of android.view.inputmethod.InputMethodSubtype in project android_frameworks_base by ParanoidAndroid.
the class InputMethodButton method needsToShowIMEButtonWhenVisibilityAuto.
// Refer to InputMethodManagerService.needsToShowImeSwitchOngoingNotification()
private boolean needsToShowIMEButtonWhenVisibilityAuto() {
List<InputMethodInfo> imis = mImm.getEnabledInputMethodList();
final int N = imis.size();
if (N > 2)
return true;
if (N < 1)
return false;
int nonAuxCount = 0;
int auxCount = 0;
InputMethodSubtype nonAuxSubtype = null;
InputMethodSubtype auxSubtype = null;
for (int i = 0; i < N; ++i) {
final InputMethodInfo imi = imis.get(i);
final List<InputMethodSubtype> subtypes = mImm.getEnabledInputMethodSubtypeList(imi, true);
final int subtypeCount = subtypes.size();
if (subtypeCount == 0) {
++nonAuxCount;
} else {
for (int j = 0; j < subtypeCount; ++j) {
final InputMethodSubtype subtype = subtypes.get(j);
if (!subtype.isAuxiliary()) {
++nonAuxCount;
nonAuxSubtype = subtype;
} else {
++auxCount;
auxSubtype = subtype;
}
}
}
}
if (nonAuxCount > 1 || auxCount > 1) {
return true;
} else if (nonAuxCount == 1 && auxCount == 1) {
if (nonAuxSubtype != null && auxSubtype != null && (nonAuxSubtype.getLocale().equals(auxSubtype.getLocale()) || auxSubtype.overridesImplicitlyEnabledSubtype() || nonAuxSubtype.overridesImplicitlyEnabledSubtype()) && nonAuxSubtype.containsExtraValueKey(TAG_TRY_SUPPRESSING_IME_SWITCHER)) {
return false;
}
return true;
}
return false;
}
use of android.view.inputmethod.InputMethodSubtype in project android_frameworks_base by ParanoidAndroid.
the class KeyguardPasswordView method hasMultipleEnabledIMEsOrSubtypes.
/**
* Method adapted from com.android.inputmethod.latin.Utils
*
* @param imm The input method manager
* @param shouldIncludeAuxiliarySubtypes
* @return true if we have multiple IMEs to choose from
*/
private boolean hasMultipleEnabledIMEsOrSubtypes(InputMethodManager imm, final boolean shouldIncludeAuxiliarySubtypes) {
final List<InputMethodInfo> enabledImis = imm.getEnabledInputMethodList();
// Number of the filtered IMEs
int filteredImisCount = 0;
for (InputMethodInfo imi : enabledImis) {
// We can return true immediately after we find two or more filtered IMEs.
if (filteredImisCount > 1)
return true;
final List<InputMethodSubtype> subtypes = imm.getEnabledInputMethodSubtypeList(imi, true);
// IMEs that have no subtypes should be counted.
if (subtypes.isEmpty()) {
++filteredImisCount;
continue;
}
int auxCount = 0;
for (InputMethodSubtype subtype : subtypes) {
if (subtype.isAuxiliary()) {
++auxCount;
}
}
final int nonAuxCount = subtypes.size() - auxCount;
// subtypes should be counted as well.
if (nonAuxCount > 0 || (shouldIncludeAuxiliarySubtypes && auxCount > 1)) {
++filteredImisCount;
continue;
}
}
return filteredImisCount > 1 || // input method subtype (The current IME should be LatinIME.)
imm.getEnabledInputMethodSubtypeList(null, false).size() > 1;
}
use of android.view.inputmethod.InputMethodSubtype in project android_frameworks_base by ParanoidAndroid.
the class InputMethodManagerService method showInputMethodMenuInternal.
private void showInputMethodMenuInternal(boolean showSubtypes) {
if (DEBUG)
Slog.v(TAG, "Show switching menu");
final Context context = getUiContext();
final boolean isScreenLocked = isScreenLocked();
final String lastInputMethodId = mSettings.getSelectedInputMethod();
int lastInputMethodSubtypeId = mSettings.getSelectedInputMethodSubtypeId(lastInputMethodId);
if (DEBUG)
Slog.v(TAG, "Current IME: " + lastInputMethodId);
synchronized (mMethodMap) {
final HashMap<InputMethodInfo, List<InputMethodSubtype>> immis = getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked();
if (immis == null || immis.size() == 0) {
return;
}
hideInputMethodMenuLocked();
final List<ImeSubtypeListItem> imList = mImListManager.getSortedInputMethodAndSubtypeList(showSubtypes, mInputShown, isScreenLocked);
if (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID) {
final InputMethodSubtype currentSubtype = getCurrentInputMethodSubtypeLocked();
if (currentSubtype != null) {
final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId);
lastInputMethodSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode(currentImi, currentSubtype.hashCode());
}
}
final int N = imList.size();
mIms = new InputMethodInfo[N];
mSubtypeIds = new int[N];
int checkedItem = 0;
for (int i = 0; i < N; ++i) {
final ImeSubtypeListItem item = imList.get(i);
mIms[i] = item.mImi;
mSubtypeIds[i] = item.mSubtypeId;
if (mIms[i].getId().equals(lastInputMethodId)) {
int subtypeId = mSubtypeIds[i];
if ((subtypeId == NOT_A_SUBTYPE_ID) || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0) || (subtypeId == lastInputMethodSubtypeId)) {
checkedItem = i;
}
}
}
final TypedArray a = context.obtainStyledAttributes(null, com.android.internal.R.styleable.DialogPreference, com.android.internal.R.attr.alertDialogStyle, 0);
mDialogBuilder = new AlertDialog.Builder(context).setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
hideInputMethodMenu();
}
}).setIcon(a.getDrawable(com.android.internal.R.styleable.DialogPreference_dialogTitle));
a.recycle();
final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View tv = inflater.inflate(com.android.internal.R.layout.input_method_switch_dialog_title, null);
mDialogBuilder.setCustomTitle(tv);
// Setup layout for a toggle switch of the hardware keyboard
mSwitchingDialogTitleView = tv;
mSwitchingDialogTitleView.findViewById(com.android.internal.R.id.hard_keyboard_section).setVisibility(mWindowManagerService.isHardKeyboardAvailable() ? View.VISIBLE : View.GONE);
final Switch hardKeySwitch = ((Switch) mSwitchingDialogTitleView.findViewById(com.android.internal.R.id.hard_keyboard_switch));
hardKeySwitch.setChecked(mWindowManagerService.isHardKeyboardEnabled());
hardKeySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mWindowManagerService.setHardKeyboardEnabled(isChecked);
// Ensure that the input method dialog is dismissed when changing
// the hardware keyboard state.
hideInputMethodMenu();
}
});
final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(context, com.android.internal.R.layout.simple_list_item_2_single_choice, imList, checkedItem);
mDialogBuilder.setSingleChoiceItems(adapter, checkedItem, new AlertDialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
synchronized (mMethodMap) {
if (mIms == null || mIms.length <= which || mSubtypeIds == null || mSubtypeIds.length <= which) {
return;
}
InputMethodInfo im = mIms[which];
int subtypeId = mSubtypeIds[which];
adapter.mCheckedItem = which;
adapter.notifyDataSetChanged();
hideInputMethodMenu();
if (im != null) {
if ((subtypeId < 0) || (subtypeId >= im.getSubtypeCount())) {
subtypeId = NOT_A_SUBTYPE_ID;
}
setInputMethodLocked(im.getId(), subtypeId);
}
}
}
});
if (showSubtypes && !isScreenLocked) {
mDialogBuilder.setPositiveButton(com.android.internal.R.string.configure_input_methods, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
showConfigureInputMethods();
}
});
}
mSwitchingDialog = mDialogBuilder.create();
mSwitchingDialog.setCanceledOnTouchOutside(true);
mSwitchingDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG);
mSwitchingDialog.getWindow().getAttributes().privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
mSwitchingDialog.getWindow().getAttributes().setTitle("Select input method");
mSwitchingDialog.show();
}
}
Aggregations