use of android.view.inputmethod.InputMethodSubtype in project android_frameworks_base by ResurrectionRemix.
the class TextServicesManagerService method getCurrentSpellCheckerSubtype.
// TODO: Respect allowImplicitlySelectedSubtype
// TODO: Save SpellCheckerSubtype by supported languages by looking at "locale".
@Override
public SpellCheckerSubtype getCurrentSpellCheckerSubtype(String locale, boolean allowImplicitlySelectedSubtype) {
// TODO: Make this work even for non-current users?
if (!calledFromValidUser()) {
return null;
}
final int subtypeHashCode;
final SpellCheckerInfo sci;
final Locale systemLocale;
synchronized (mSpellCheckerMap) {
subtypeHashCode = mSettings.getSelectedSpellCheckerSubtype(SpellCheckerSubtype.SUBTYPE_ID_NONE);
if (DBG) {
Slog.w(TAG, "getCurrentSpellCheckerSubtype: " + subtypeHashCode);
}
sci = getCurrentSpellChecker(null);
systemLocale = mContext.getResources().getConfiguration().locale;
}
if (sci == null || sci.getSubtypeCount() == 0) {
if (DBG) {
Slog.w(TAG, "Subtype not found.");
}
return null;
}
if (subtypeHashCode == SpellCheckerSubtype.SUBTYPE_ID_NONE && !allowImplicitlySelectedSubtype) {
return null;
}
String candidateLocale = null;
if (subtypeHashCode == 0) {
// Spell checker language settings == "auto"
final InputMethodManager imm = mContext.getSystemService(InputMethodManager.class);
if (imm != null) {
final InputMethodSubtype currentInputMethodSubtype = imm.getCurrentInputMethodSubtype();
if (currentInputMethodSubtype != null) {
final String localeString = currentInputMethodSubtype.getLocale();
if (!TextUtils.isEmpty(localeString)) {
// 1. Use keyboard locale if available in the spell checker
candidateLocale = localeString;
}
}
}
if (candidateLocale == null) {
// 2. Use System locale if available in the spell checker
candidateLocale = systemLocale.toString();
}
}
SpellCheckerSubtype candidate = null;
for (int i = 0; i < sci.getSubtypeCount(); ++i) {
final SpellCheckerSubtype scs = sci.getSubtypeAt(i);
if (subtypeHashCode == 0) {
final String scsLocale = scs.getLocale();
if (candidateLocale.equals(scsLocale)) {
return scs;
} else if (candidate == null) {
if (candidateLocale.length() >= 2 && scsLocale.length() >= 2 && candidateLocale.startsWith(scsLocale)) {
// Fall back to the applicable language
candidate = scs;
}
}
} else if (scs.hashCode() == subtypeHashCode) {
if (DBG) {
Slog.w(TAG, "Return subtype " + scs.hashCode() + ", input= " + locale + ", " + scs.getLocale());
}
// 3. Use the user specified spell check language
return scs;
}
}
// spell check languages
return candidate;
}
use of android.view.inputmethod.InputMethodSubtype in project android_frameworks_base by ResurrectionRemix.
the class InputMethodManagerService method getCurrentInputMethodSubtypeLocked.
private InputMethodSubtype getCurrentInputMethodSubtypeLocked() {
if (mCurMethodId == null) {
return null;
}
final boolean subtypeIsSelected = mSettings.isSubtypeSelected();
final InputMethodInfo imi = mMethodMap.get(mCurMethodId);
if (imi == null || imi.getSubtypeCount() == 0) {
return null;
}
if (!subtypeIsSelected || mCurrentSubtype == null || !InputMethodUtils.isValidSubtypeId(imi, mCurrentSubtype.hashCode())) {
int subtypeId = mSettings.getSelectedInputMethodSubtypeId(mCurMethodId);
if (subtypeId == NOT_A_SUBTYPE_ID) {
// If there are no selected subtypes, the framework will try to find
// the most applicable subtype from explicitly or implicitly enabled
// subtypes.
List<InputMethodSubtype> explicitlyOrImplicitlyEnabledSubtypes = mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true);
// just returns it.
if (explicitlyOrImplicitlyEnabledSubtypes.size() == 1) {
mCurrentSubtype = explicitlyOrImplicitlyEnabledSubtypes.get(0);
} else if (explicitlyOrImplicitlyEnabledSubtypes.size() > 1) {
mCurrentSubtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes, explicitlyOrImplicitlyEnabledSubtypes, InputMethodUtils.SUBTYPE_MODE_KEYBOARD, null, true);
if (mCurrentSubtype == null) {
mCurrentSubtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes, explicitlyOrImplicitlyEnabledSubtypes, null, null, true);
}
}
} else {
mCurrentSubtype = InputMethodUtils.getSubtypes(imi).get(subtypeId);
}
}
return mCurrentSubtype;
}
use of android.view.inputmethod.InputMethodSubtype in project android_frameworks_base by ResurrectionRemix.
the class InputMethodManagerService method findLastResortApplicableShortcutInputMethodAndSubtypeLocked.
// If there are no selected shortcuts, tries finding the most applicable ones.
private Pair<InputMethodInfo, InputMethodSubtype> findLastResortApplicableShortcutInputMethodAndSubtypeLocked(String mode) {
List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked();
InputMethodInfo mostApplicableIMI = null;
InputMethodSubtype mostApplicableSubtype = null;
boolean foundInSystemIME = false;
// Search applicable subtype for each InputMethodInfo
for (InputMethodInfo imi : imis) {
final String imiId = imi.getId();
if (foundInSystemIME && !imiId.equals(mCurMethodId)) {
continue;
}
InputMethodSubtype subtype = null;
final List<InputMethodSubtype> enabledSubtypes = mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true);
// 1. Search by the current subtype's locale from enabledSubtypes.
if (mCurrentSubtype != null) {
subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes, enabledSubtypes, mode, mCurrentSubtype.getLocale(), false);
}
// 3. Search the first enabled subtype matched with mode from enabledSubtypes.
if (subtype == null) {
subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes, enabledSubtypes, mode, null, true);
}
final ArrayList<InputMethodSubtype> overridingImplicitlyEnabledSubtypes = InputMethodUtils.getOverridingImplicitlyEnabledSubtypes(imi, mode);
final ArrayList<InputMethodSubtype> subtypesForSearch = overridingImplicitlyEnabledSubtypes.isEmpty() ? InputMethodUtils.getSubtypes(imi) : overridingImplicitlyEnabledSubtypes;
// 4. Search by the current subtype's locale from all subtypes.
if (subtype == null && mCurrentSubtype != null) {
subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes, subtypesForSearch, mode, mCurrentSubtype.getLocale(), false);
}
// 6. Search the first enabled subtype matched with mode from all subtypes.
if (subtype == null) {
subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes, subtypesForSearch, mode, null, true);
}
if (subtype != null) {
if (imiId.equals(mCurMethodId)) {
// The current input method is the most applicable IME.
mostApplicableIMI = imi;
mostApplicableSubtype = subtype;
break;
} else if (!foundInSystemIME) {
// The system input method is 2nd applicable IME.
mostApplicableIMI = imi;
mostApplicableSubtype = subtype;
if ((imi.getServiceInfo().applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
foundInSystemIME = true;
}
}
}
}
if (DEBUG) {
if (mostApplicableIMI != null) {
Slog.w(TAG, "Most applicable shortcut input method was:" + mostApplicableIMI.getId());
if (mostApplicableSubtype != null) {
Slog.w(TAG, "Most applicable shortcut input method subtype was:" + "," + mostApplicableSubtype.getMode() + "," + mostApplicableSubtype.getLocale());
}
}
}
if (mostApplicableIMI != null) {
return new Pair<>(mostApplicableIMI, mostApplicableSubtype);
} else {
return null;
}
}
use of android.view.inputmethod.InputMethodSubtype in project android_frameworks_base by ResurrectionRemix.
the class InputMethodManagerService method shouldShowImeSwitcherLocked.
private boolean shouldShowImeSwitcherLocked(int visibility) {
if (!mShowOngoingImeSwitcherForPhones)
return false;
if (mSwitchingDialog != null)
return false;
if (isScreenLocked())
return false;
if ((visibility & InputMethodService.IME_ACTIVE) == 0)
return false;
if (mWindowManagerInternal.isHardKeyboardAvailable()) {
if (mHardKeyboardBehavior == HardKeyboardBehavior.WIRELESS_AFFORDANCE) {
// SHOW_IME_WITH_HARD_KEYBOARD settings finds a good place to live.
return true;
}
} else if ((visibility & InputMethodService.IME_VISIBLE) == 0) {
return false;
}
List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked();
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 = mSettings.getEnabledInputMethodSubtypeListLocked(mContext, 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 ResurrectionRemix.
the class InputMethodManagerService method showInputMethodMenu.
private void showInputMethodMenu(boolean showAuxSubtypes) {
if (DEBUG)
Slog.v(TAG, "Show switching menu. showAuxSubtypes=" + showAuxSubtypes);
final Context context = mContext;
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 = mSettings.getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked(mContext);
if (immis == null || immis.size() == 0) {
return;
}
hideInputMethodMenuLocked();
final List<ImeSubtypeListItem> imList = mSwitchingController.getSortedInputMethodAndSubtypeListLocked(showAuxSubtypes, 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 Context settingsContext = new ContextThemeWrapper(context, com.android.internal.R.style.Theme_DeviceDefault_Settings);
mDialogBuilder = new AlertDialog.Builder(settingsContext);
mDialogBuilder.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
hideInputMethodMenu();
}
});
final Context dialogContext = mDialogBuilder.getContext();
final TypedArray a = dialogContext.obtainStyledAttributes(null, com.android.internal.R.styleable.DialogPreference, com.android.internal.R.attr.alertDialogStyle, 0);
final Drawable dialogIcon = a.getDrawable(com.android.internal.R.styleable.DialogPreference_dialogIcon);
a.recycle();
mDialogBuilder.setIcon(dialogIcon);
final LayoutInflater inflater = dialogContext.getSystemService(LayoutInflater.class);
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(mWindowManagerInternal.isHardKeyboardAvailable() ? View.VISIBLE : View.GONE);
final Switch hardKeySwitch = (Switch) mSwitchingDialogTitleView.findViewById(com.android.internal.R.id.hard_keyboard_switch);
hardKeySwitch.setChecked(mShowImeWithHardKeyboard);
hardKeySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mSettings.setShowImeWithHardKeyboard(isChecked);
// Ensure that the input method dialog is dismissed when changing
// the hardware keyboard state.
hideInputMethodMenu();
}
});
final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(dialogContext, com.android.internal.R.layout.input_method_switch_item, imList, checkedItem);
final OnClickListener choiceListener = new OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
synchronized (mMethodMap) {
if (mIms == null || mIms.length <= which || mSubtypeIds == null || mSubtypeIds.length <= which) {
return;
}
final 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);
}
}
}
};
mDialogBuilder.setSingleChoiceItems(adapter, checkedItem, choiceListener);
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");
updateSystemUi(mCurToken, mImeWindowVis, mBackDisposition);
mSwitchingDialog.show();
}
}
Aggregations