Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cb389ef0 authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka
Browse files

Refactor to utilize InputMethodSubtype

Change-Id: I76fbc8a395eb8dab996c02c86d7328f07865f8cf
parent 43ebd8a0
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.text.InputType;
import android.util.Log;
import android.util.Xml;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodSubtype;

import com.android.inputmethod.compat.EditorInfoCompatUtils;
import com.android.inputmethod.keyboard.KeyboardSet.Params.ElementParams;
@@ -242,7 +243,10 @@ public class KeyboardSet {
            return this;
        }

        public Builder setSubtype(Locale inputLocale, boolean asciiCapable) {
        public Builder setSubtype(InputMethodSubtype subtype) {
            final Locale inputLocale = SubtypeLocale.getSubtypeLocale(subtype);
            final boolean asciiCapable = subtype.containsExtraValueKey(
                    LatinIME.SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE);
            final boolean deprecatedForceAscii = StringUtils.inPrivateImeOptions(
                    mPackageName, LatinIME.IME_OPTION_FORCE_ASCII, mEditorInfo);
            final boolean forceAscii = EditorInfoCompatUtils.hasFlagForceAscii(
+2 −5
Original line number Diff line number Diff line
@@ -137,10 +137,7 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions {
        final KeyboardSet.Builder builder = new KeyboardSet.Builder(mThemeContext, editorInfo);
        builder.setScreenGeometry(mThemeContext.getResources().getConfiguration().orientation,
                mThemeContext.getResources().getDisplayMetrics().widthPixels);
        builder.setSubtype(
                mSubtypeSwitcher.getInputLocale(),
                mSubtypeSwitcher.currentSubtypeContainsExtraValueKey(
                        LatinIME.SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE));
        builder.setSubtype(mSubtypeSwitcher.getCurrentSubtype());
        builder.setOptions(
                settingsValues.isVoiceKeyEnabled(editorInfo),
                settingsValues.isVoiceKeyOnMain(),
@@ -384,7 +381,7 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions {

    public void onNetworkStateChanged() {
        if (mKeyboardView != null) {
            mKeyboardView.updateShortcutKey(SubtypeSwitcher.getInstance().isShortcutImeReady());
            mKeyboardView.updateShortcutKey(mSubtypeSwitcher.isShortcutImeReady());
        }
    }

+1 −3
Original line number Diff line number Diff line
@@ -713,9 +713,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
            mSuggest.setAutoCorrectionThreshold(mSettingsValues.mAutoCorrectionThreshold);
        }

        if (mSubtypeSwitcher.isKeyboardMode()) {
        switcher.loadKeyboard(editorInfo, mSettingsValues);
        }

        if (mSuggestionsView != null)
            mSuggestionsView.clear();
+11 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.inputmethod.latin;

import android.content.Context;
import android.content.res.Resources;
import android.view.inputmethod.InputMethodSubtype;

import java.util.Locale;

@@ -120,4 +121,14 @@ public class SubtypeLocale {
        // - It also does not work with unicode surrogate code points.
        return s.toUpperCase(locale).charAt(0) + s.substring(1);
    }

    public static String getSubtypeLocaleString(InputMethodSubtype subtype) {
        final String keyboardLocale = subtype.getExtraValueOf(
                LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LOCALE);
        return keyboardLocale != null ? keyboardLocale : subtype.getLocale();
    }

    public static Locale getSubtypeLocale(InputMethodSubtype subtype) {
        return LocaleUtils.constructLocaleFromString(getSubtypeLocaleString(subtype));
    }
}
+8 −15
Original line number Diff line number Diff line
@@ -419,30 +419,23 @@ public class SubtypeSwitcher {
        }
    }

    public boolean isKeyboardMode() {
    // TODO: Remove this method
    private boolean isKeyboardMode() {
        return KEYBOARD_MODE.equals(getCurrentSubtypeMode());
    }

    /////////////////////////////
    // Other utility functions //
    /////////////////////////////

    public String getCurrentSubtypeExtraValue() {
        // If null, return what an empty ExtraValue would return : the empty string.
        return mCurrentSubtype.getExtraValue();
    // TODO: Remove this method
    private String getCurrentSubtypeMode() {
        return mCurrentSubtype.getMode();
    }

    // TODO: Remove this method
    public boolean currentSubtypeContainsExtraValueKey(String key) {
        // If null, return what an empty ExtraValue would return : false.
        return mCurrentSubtype.containsExtraValueKey(key);
    }

    public String getCurrentSubtypeExtraValueOf(String key) {
        // If null, return what an empty ExtraValue would return : null.
        return mCurrentSubtype.getExtraValueOf(key);
    }

    public String getCurrentSubtypeMode() {
        return mCurrentSubtype.getMode();
    public InputMethodSubtype getCurrentSubtype() {
        return mCurrentSubtype;
    }
}