Search in sources :

Example 11 with InputMethodSubtype

use of android.view.inputmethod.InputMethodSubtype in project platform_frameworks_base by android.

the class InputMethodUtilsTest method verifyEquality.

private static void verifyEquality(InputMethodInfo expected, InputMethodInfo actual) {
    assertEquals(expected, actual);
    assertEquals(expected.getSubtypeCount(), actual.getSubtypeCount());
    for (int subtypeIndex = 0; subtypeIndex < expected.getSubtypeCount(); ++subtypeIndex) {
        final InputMethodSubtype expectedSubtype = expected.getSubtypeAt(subtypeIndex);
        final InputMethodSubtype actualSubtype = actual.getSubtypeAt(subtypeIndex);
        verifyEquality(expectedSubtype, actualSubtype);
    }
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype)

Example 12 with InputMethodSubtype

use of android.view.inputmethod.InputMethodSubtype in project platform_frameworks_base by android.

the class InputMethodSubtypeSwitchingControllerTest method assertNextInputMethod.

private void assertNextInputMethod(final ControllerImpl controller, final boolean onlyCurrentIme, final ImeSubtypeListItem currentItem, final ImeSubtypeListItem nextItem, final ImeSubtypeListItem prevItem) {
    InputMethodSubtype subtype = null;
    if (currentItem.mSubtypeName != null) {
        subtype = createDummySubtype(currentItem.mSubtypeName.toString());
    }
    final ImeSubtypeListItem nextIme = controller.getNextInputMethod(onlyCurrentIme, currentItem.mImi, subtype, true);
    assertEquals(nextItem, nextIme);
    final ImeSubtypeListItem prevIme = controller.getNextInputMethod(onlyCurrentIme, currentItem.mImi, subtype, false);
    assertEquals(prevItem, prevIme);
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) ImeSubtypeListItem(com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem)

Example 13 with InputMethodSubtype

use of android.view.inputmethod.InputMethodSubtype in project platform_frameworks_base by android.

the class InputMethodSubtypeSwitchingControllerTest method addDummyImeSubtypeListItems.

private static void addDummyImeSubtypeListItems(List<ImeSubtypeListItem> items, String imeName, String imeLabel, List<String> subtypeLocales, boolean supportsSwitchingToNextInputMethod) {
    final ResolveInfo ri = new ResolveInfo();
    final ServiceInfo si = new ServiceInfo();
    final ApplicationInfo ai = new ApplicationInfo();
    ai.packageName = DUMMY_PACKAGE_NAME;
    ai.enabled = true;
    si.applicationInfo = ai;
    si.enabled = true;
    si.packageName = DUMMY_PACKAGE_NAME;
    si.name = imeName;
    si.exported = true;
    si.nonLocalizedLabel = imeLabel;
    ri.serviceInfo = si;
    List<InputMethodSubtype> subtypes = null;
    if (subtypeLocales != null) {
        subtypes = new ArrayList<>();
        for (String subtypeLocale : subtypeLocales) {
            subtypes.add(createDummySubtype(subtypeLocale));
        }
    }
    final InputMethodInfo imi = new InputMethodInfo(ri, DUMMY_IS_AUX_IME, DUMMY_SETTING_ACTIVITY_NAME, subtypes, DUMMY_IS_DEFAULT_RES_ID, DUMMY_FORCE_DEFAULT, supportsSwitchingToNextInputMethod);
    if (subtypes == null) {
        items.add(new ImeSubtypeListItem(imeName, null, /* variableName */
        imi, NOT_A_SUBTYPE_ID, null, SYSTEM_LOCALE));
    } else {
        for (int i = 0; i < subtypes.size(); ++i) {
            final String subtypeLocale = subtypeLocales.get(i);
            items.add(new ImeSubtypeListItem(imeName, subtypeLocale, imi, i, subtypeLocale, SYSTEM_LOCALE));
        }
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) ApplicationInfo(android.content.pm.ApplicationInfo) InputMethodInfo(android.view.inputmethod.InputMethodInfo) ImeSubtypeListItem(com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem)

Example 14 with InputMethodSubtype

use of android.view.inputmethod.InputMethodSubtype in project platform_frameworks_base by android.

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 15 with InputMethodSubtype

use of android.view.inputmethod.InputMethodSubtype in project platform_frameworks_base by android.

the class InputMethodManagerService method setSelectedInputMethodAndSubtypeLocked.

private void setSelectedInputMethodAndSubtypeLocked(InputMethodInfo imi, int subtypeId, boolean setSubtypeOnly) {
    // Update the history of InputMethod and Subtype
    mSettings.saveCurrentInputMethodAndSubtypeToHistory(mCurMethodId, mCurrentSubtype);
    mCurUserActionNotificationSequenceNumber = Math.max(mCurUserActionNotificationSequenceNumber + 1, 1);
    if (DEBUG) {
        Slog.d(TAG, "Bump mCurUserActionNotificationSequenceNumber:" + mCurUserActionNotificationSequenceNumber);
    }
    if (mCurClient != null && mCurClient.client != null) {
        executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(MSG_SET_USER_ACTION_NOTIFICATION_SEQUENCE_NUMBER, mCurUserActionNotificationSequenceNumber, mCurClient));
    }
    // Set Subtype here
    if (imi == null || subtypeId < 0) {
        mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID);
        mCurrentSubtype = null;
    } else {
        if (subtypeId < imi.getSubtypeCount()) {
            InputMethodSubtype subtype = imi.getSubtypeAt(subtypeId);
            mSettings.putSelectedSubtype(subtype.hashCode());
            mCurrentSubtype = subtype;
        } else {
            mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID);
            // If the subtype is not specified, choose the most applicable one
            mCurrentSubtype = getCurrentInputMethodSubtypeLocked();
        }
    }
    if (!setSubtypeOnly) {
        // Set InputMethod here
        mSettings.putSelectedInputMethod(imi != null ? imi.getId() : "");
    }
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype)

Aggregations

InputMethodSubtype (android.view.inputmethod.InputMethodSubtype)195 InputMethodInfo (android.view.inputmethod.InputMethodInfo)92 ArrayList (java.util.ArrayList)48 Locale (java.util.Locale)17 LocaleList (android.os.LocaleList)15 ImeSubtypeListItem (com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem)15 InputMethodManager (android.view.inputmethod.InputMethodManager)14 Context (android.content.Context)12 SmallTest (android.test.suitebuilder.annotation.SmallTest)10 View (android.view.View)9 TextView (android.widget.TextView)9 RichInputMethodSubtype (com.android.inputmethod.latin.RichInputMethodSubtype)8 List (java.util.List)8 Intent (android.content.Intent)7 Pair (android.util.Pair)7 AlertDialog (android.app.AlertDialog)6 PendingIntent (android.app.PendingIntent)6 DialogInterface (android.content.DialogInterface)6 OnCancelListener (android.content.DialogInterface.OnCancelListener)6 TypedArray (android.content.res.TypedArray)6