Search in sources :

Example 56 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project android_frameworks_base by DirtyUnicorns.

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();
    }
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) InputMethodInfo(android.view.inputmethod.InputMethodInfo) TypedArray(android.content.res.TypedArray) ArrayList(java.util.ArrayList) List(java.util.List) LocaleList(android.os.LocaleList) OnCancelListener(android.content.DialogInterface.OnCancelListener) IInputContext(com.android.internal.view.IInputContext) Context(android.content.Context) InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) Drawable(android.graphics.drawable.Drawable) View(android.view.View) TextView(android.widget.TextView) ImeSubtypeListItem(com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem) ContextThemeWrapper(android.view.ContextThemeWrapper) Switch(android.widget.Switch) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.content.DialogInterface.OnClickListener) CompoundButton(android.widget.CompoundButton)

Example 57 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project android_frameworks_base by DirtyUnicorns.

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;
    }
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) InputMethodInfo(android.view.inputmethod.InputMethodInfo) Pair(android.util.Pair)

Example 58 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project android_frameworks_base by DirtyUnicorns.

the class InputMethodManagerService method notifySuggestionPicked.

@Override
public boolean notifySuggestionPicked(SuggestionSpan span, String originalString, int index) {
    if (!calledFromValidUser()) {
        return false;
    }
    synchronized (mMethodMap) {
        final InputMethodInfo targetImi = mSecureSuggestionSpans.get(span);
        // TODO: Do not send the intent if the process of the targetImi is already dead.
        if (targetImi != null) {
            final String[] suggestions = span.getSuggestions();
            if (index < 0 || index >= suggestions.length)
                return false;
            final String className = span.getNotificationTargetClassName();
            final Intent intent = new Intent();
            // Ensures that only a class in the original IME package will receive the
            // notification.
            intent.setClassName(targetImi.getPackageName(), className);
            intent.setAction(SuggestionSpan.ACTION_SUGGESTION_PICKED);
            intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_BEFORE, originalString);
            intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_AFTER, suggestions[index]);
            intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_HASHCODE, span.hashCode());
            final long ident = Binder.clearCallingIdentity();
            try {
                mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT);
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
            return true;
        }
    }
    return false;
}
Also used : PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Example 59 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project android_frameworks_base by DirtyUnicorns.

the class InputMethodManagerService method resetSelectedInputMethodAndSubtypeLocked.

private void resetSelectedInputMethodAndSubtypeLocked(String newDefaultIme) {
    InputMethodInfo imi = mMethodMap.get(newDefaultIme);
    int lastSubtypeId = NOT_A_SUBTYPE_ID;
    // newDefaultIme is empty when there is no candidate for the selected IME.
    if (imi != null && !TextUtils.isEmpty(newDefaultIme)) {
        String subtypeHashCode = mSettings.getLastSubtypeForInputMethodLocked(newDefaultIme);
        if (subtypeHashCode != null) {
            try {
                lastSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode(imi, Integer.parseInt(subtypeHashCode));
            } catch (NumberFormatException e) {
                Slog.w(TAG, "HashCode for subtype looks broken: " + subtypeHashCode, e);
            }
        }
    }
    setSelectedInputMethodAndSubtypeLocked(imi, lastSubtypeId, false);
}
Also used : InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Example 60 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project android_frameworks_base by ParanoidAndroid.

the class InputMethodUtils method getDefaultEnabledImes.

public static ArrayList<InputMethodInfo> getDefaultEnabledImes(Context context, boolean isSystemReady, ArrayList<InputMethodInfo> imis) {
    final ArrayList<InputMethodInfo> retval = new ArrayList<InputMethodInfo>();
    boolean auxilialyImeAdded = false;
    for (int i = 0; i < imis.size(); ++i) {
        final InputMethodInfo imi = imis.get(i);
        if (isDefaultEnabledIme(isSystemReady, imi, context)) {
            retval.add(imi);
            if (imi.isAuxiliaryIme()) {
                auxilialyImeAdded = true;
            }
        }
    }
    if (auxilialyImeAdded) {
        return retval;
    }
    for (int i = 0; i < imis.size(); ++i) {
        final InputMethodInfo imi = imis.get(i);
        if (isSystemAuxilialyImeThatHashAutomaticSubtype(imi)) {
            retval.add(imi);
        }
    }
    return retval;
}
Also used : ArrayList(java.util.ArrayList) InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Aggregations

InputMethodInfo (android.view.inputmethod.InputMethodInfo)309 InputMethodSubtype (android.view.inputmethod.InputMethodSubtype)113 ArrayList (java.util.ArrayList)80 RemoteException (android.os.RemoteException)53 ServiceInfo (android.content.pm.ServiceInfo)34 ComponentName (android.content.ComponentName)33 Intent (android.content.Intent)33 Context (android.content.Context)32 InputMethodManager (android.view.inputmethod.InputMethodManager)29 ApplicationInfo (android.content.pm.ApplicationInfo)27 PendingIntent (android.app.PendingIntent)24 Test (org.junit.Test)24 ResolveInfo (android.content.pm.ResolveInfo)19 ImeSubtypeListItem (com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem)15 InputMethodPreference (com.android.settingslib.inputmethod.InputMethodPreference)14 List (java.util.List)14 PackageManager (android.content.pm.PackageManager)13 Drawable (android.graphics.drawable.Drawable)13 SmallTest (android.test.suitebuilder.annotation.SmallTest)12 Printer (android.util.Printer)12