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

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

Add "passwordInput" attribute to case tag of Keyboard

This change also introduces number password (a.k.a. PIN) layout. The
text password layout will follow.

Bug: 3384942
Change-Id: I50b5e413e47a28d5285fd0468115e11ce46c7f18
parent 810a9ff9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -168,6 +168,7 @@
            <enum name="web" value="4" />
            <enum name="phone" value="5" />
        </attr>
        <attr name="passwordInput" format="boolean" />
        <attr name="hasSettingsKey" format="string" />
        <attr name="voiceKeyEnabled" format="string" />
        <attr name="hasVoiceKey" format="string" />
+184 −115
Original line number Diff line number Diff line
@@ -31,6 +31,69 @@
>
    <include
        latin:keyboardLayout="@xml/kbd_key_styles" />
    <switch>
        <case
            latin:passwordInput="true"
        >
            <!-- This row is intentionally not marked as a top row -->
            <Row>
                <Spacer
                    latin:horizontalGap="32.076%p" />
                <Key
                    latin:keyLabel="1" />
                <Key
                    latin:keyLabel="2" />
                <Key
                    latin:keyLabel="3" />
                <Spacer
                    latin:horizontalGap="22.272%p" />
                <Key
                    latin:keyStyle="deleteKeyStyle"
                    latin:keyWidth="9.804%p"
                    latin:keyEdgeFlags="right" />
            </Row>
            <Row>
                <Spacer
                    latin:horizontalGap="32.076%p" />
                <Key
                    latin:keyLabel="4" />
                <Key
                    latin:keyLabel="5" />
                <Key
                    latin:keyLabel="6" />
                <Spacer
                    latin:horizontalGap="17.371%p" />
                <Key
                    latin:keyStyle="returnKeyStyle"
                    latin:keyWidth="14.706%p"
                    latin:keyEdgeFlags="right" />
            </Row>
            <Row>
                <Spacer
                    latin:horizontalGap="32.076%p" />
                <Key
                    latin:keyLabel="7" />
                <Key
                    latin:keyLabel="8" />
                <Key
                    latin:keyLabel="9" />
                <!-- There is an empty area below the "Enter" key and right of the "9" key. To
                     ignore the touch event on the area, "9" is intentionally not marked as a right
                     edge key. -->
            </Row>
            <!-- This row is intentionally not marked as a bottom row -->
            <Row>
                <Spacer
                    latin:horizontalGap="44.026%p" />
                <Key
                    latin:keyLabel="0" />
                <!-- There is an empty area below the "Enter" key and right of the "#" key. To
                     ignore the touch event on the area, "#" is intentionally not marked as a right
                     edge key. -->
            </Row>
        </case>
        <!-- latin:passwordInput="false" -->
        <default>
            <!-- This row is intentionally not marked as a top row -->
            <Row>
                <Key
@@ -91,8 +154,9 @@
                    latin:keyEdgeFlags="right" />
            </Row>
            <Row>
        <!-- There is an empty area bellow the "More" key and left of the "(" key.  To ignore
             the touch event on the area, "(" is intentionally not marked as a left edge key. -->
                <!-- There is an empty area below the "More" key and left of the "(" key. To
                     ignore the touch event on the area, "(" is intentionally not marked as a left
                     edge key. -->
                <Spacer
                    latin:horizontalGap="16.406%p" />
                <Key
@@ -112,13 +176,15 @@
                    latin:keyLabel="8" />
                <Key
                    latin:keyLabel="9" />
        <!-- There is an empty area bellow the "Enter" key and right of the "9" key.  To ignore
             the touch event on the area, "9" is intentionally not marked as a right edge key. -->
                <!-- There is an empty area below the "Enter" key and right of the "9" key. To
                     ignore the touch event on the area, "9" is intentionally not marked as a right
                     edge key. -->
            </Row>
            <!-- This row is intentionally not marked as a bottom row -->
            <Row>
        <!-- There is an empty area bellow the "More" key and left of the "space" key.  To ignore
             the touch event on the area, "space" is intentionally not marked as a left edge key. -->
                <!-- There is an empty area below the "More" key and left of the "space" key. To
                     ignore the touch event on the area, "space" is intentionally not marked as a
                     left edge key. -->
                <Spacer
                    latin:horizontalGap="8.362%p" />
                <Key
@@ -144,7 +210,10 @@
                            latin:keyWidth="8.042%p" />
                    </case>
                </switch>
        <!-- There is an empty area bellow the "Enter" key and right of the "#" key.  To ignore
             the touch event on the area, "#" is intentionally not marked as a right edge key. -->
                <!-- There is an empty area below the "Enter" key and right of the "#" key. To
                     ignore the touch event on the area, "#" is intentionally not marked as a right
                     edge key. -->
            </Row>
        </default>
    </switch>
</Keyboard>
+18 −8
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.inputmethod.keyboard;

import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.Utils;

import android.view.inputmethod.EditorInfo;

@@ -41,6 +42,7 @@ public class KeyboardId {
    public final int mMode;
    public final int mXmlId;
    public final int mColorScheme;
    public final boolean mPasswordInput;
    public final boolean mHasSettingsKey;
    public final boolean mVoiceKeyEnabled;
    public final boolean mHasVoiceKey;
@@ -50,21 +52,25 @@ public class KeyboardId {

    private final int mHashCode;

    public KeyboardId(String xmlName, int xmlId, Locale locale, int orientation, int mode,
            int colorScheme, boolean hasSettingsKey, boolean voiceKeyEnabled, boolean hasVoiceKey,
            int imeOptions, boolean enableShiftLock) {
    public KeyboardId(String xmlName, int xmlId, int colorScheme, Locale locale, int orientation,
            int mode, EditorInfo attribute, boolean hasSettingsKey, boolean voiceKeyEnabled,
            boolean hasVoiceKey, boolean enableShiftLock) {
        final int inputType = (attribute != null) ? attribute.inputType : 0;
        final int imeOptions = (attribute != null) ? attribute.imeOptions : 0;
        this.mLocale = locale;
        this.mOrientation = orientation;
        this.mMode = mode;
        this.mXmlId = xmlId;
        this.mColorScheme = colorScheme;
        this.mPasswordInput = Utils.isPasswordInputType(inputType)
                || Utils.isVisiblePasswordInputType(inputType);
        this.mHasSettingsKey = hasSettingsKey;
        this.mVoiceKeyEnabled = voiceKeyEnabled;
        this.mHasVoiceKey = hasVoiceKey;
        // We are interested only in {@link EditorInfo#IME_MASK_ACTION} enum value and
        // {@link EditorInfo#IME_FLAG_NO_ENTER_ACTION}.
        this.mImeAction = imeOptions
                & (EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION);
        this.mImeAction = imeOptions & (
                EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION);
        this.mEnableShiftLock = enableShiftLock;
        this.mXmlName = xmlName;

@@ -74,6 +80,7 @@ public class KeyboardId {
                mode,
                xmlId,
                colorScheme,
                mPasswordInput,
                hasSettingsKey,
                voiceKeyEnabled,
                hasVoiceKey,
@@ -113,6 +120,7 @@ public class KeyboardId {
            && other.mMode == this.mMode
            && other.mXmlId == this.mXmlId
            && other.mColorScheme == this.mColorScheme
            && other.mPasswordInput == this.mPasswordInput
            && other.mHasSettingsKey == this.mHasSettingsKey
            && other.mVoiceKeyEnabled == this.mVoiceKeyEnabled
            && other.mHasVoiceKey == this.mHasVoiceKey
@@ -127,17 +135,19 @@ public class KeyboardId {

    @Override
    public String toString() {
        return String.format("[%s.xml %s %s %s imeOptions=%s %s%s%s%s%s]",
        return String.format("[%s.xml %s %s %s imeAction=%s %s%s%s%s%s%s]",
                mXmlName,
                mLocale,
                (mOrientation == 1 ? "port" : "land"),
                modeName(mMode),
                imeOptionsName(mImeAction),
                colorSchemeName(mColorScheme),
                (mPasswordInput ? " passwordInput" : ""),
                (mHasSettingsKey ? " hasSettingsKey" : ""),
                (mVoiceKeyEnabled ? " voiceKeyEnabled" : ""),
                (mHasVoiceKey ? " hasVoiceKey" : ""),
                (mEnableShiftLock ? " enableShiftLock" : ""));
                (mEnableShiftLock ? " enableShiftLock" : ""),
                colorSchemeName(mColorScheme)
        );
    }

    public static String modeName(int mode) {
+7 −4
Original line number Diff line number Diff line
@@ -419,6 +419,8 @@ public class KeyboardParser {
        try {
            final boolean modeMatched = matchInteger(a,
                    R.styleable.Keyboard_Case_mode, id.mMode);
            final boolean passwordInputMatched = matchBoolean(a,
                    R.styleable.Keyboard_Case_passwordInput, id.mPasswordInput);
            final boolean settingsKeyMatched = matchBoolean(a,
                    R.styleable.Keyboard_Case_hasSettingsKey, id.mHasSettingsKey);
            final boolean voiceEnabledMatched = matchBoolean(a,
@@ -435,15 +437,16 @@ public class KeyboardParser {
                    R.styleable.Keyboard_Case_imeAction, id.mImeAction);
            final boolean languageCodeMatched = matchString(a,
                    R.styleable.Keyboard_Case_languageCode, id.mLocale.getLanguage());
            final boolean selected = modeMatched && settingsKeyMatched && voiceEnabledMatched
                    && voiceKeyMatched && colorSchemeMatched && imeActionMatched
                    && languageCodeMatched;
            final boolean selected = modeMatched && passwordInputMatched && settingsKeyMatched
                    && voiceEnabledMatched && voiceKeyMatched && colorSchemeMatched
                    && imeActionMatched && languageCodeMatched;

            if (DEBUG) Log.d(TAG, String.format("<%s%s%s%s%s%s%s%s> %s", TAG_CASE,
            if (DEBUG) Log.d(TAG, String.format("<%s%s%s%s%s%s%s%s%s> %s", TAG_CASE,
                    textAttr(KeyboardId.modeName(
                            a.getInt(R.styleable.Keyboard_Case_mode, -1)), "mode"),
                    textAttr(KeyboardId.colorSchemeName(
                            a.getInt(R.styleable.KeyboardView_colorScheme, -1)), "colorSchemeName"),
                    booleanAttr(a, R.styleable.Keyboard_Case_passwordInput, "passwordInput"),
                    booleanAttr(a, R.styleable.Keyboard_Case_hasSettingsKey, "hasSettingsKey"),
                    booleanAttr(a, R.styleable.Keyboard_Case_voiceKeyEnabled, "voiceKeyEnabled"),
                    booleanAttr(a, R.styleable.Keyboard_Case_hasVoiceKey, "hasVoiceKey"),
+22 −22
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.content.SharedPreferences;
import android.content.res.Resources;
import android.util.Log;
import android.view.InflateException;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;

import java.lang.ref.SoftReference;
@@ -66,8 +67,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
    private final HashMap<KeyboardId, SoftReference<LatinKeyboard>> mKeyboardCache =
            new HashMap<KeyboardId, SoftReference<LatinKeyboard>>();

    // TODO: clean mMode up and use mAttribute instead.
    private int mMode = KeyboardId.MODE_TEXT; /* default value */
    private int mImeOptions;
    private EditorInfo mAttribute;
    private boolean mIsSymbols;
    /** mIsAutoCorrectionActive indicates that auto corrected word will be input instead of
     * what user actually typed. */
@@ -128,10 +130,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
        final int orientation = res.getConfiguration().orientation;
        final int mode = mMode;
        final int colorScheme = getColorScheme();
        final boolean hasSettingsKey = mHasSettingsKey;
        final boolean voiceKeyEnabled = mVoiceKeyEnabled;
        final boolean hasVoiceKey = voiceKeyEnabled && !mVoiceButtonOnPrimary;
        final int imeOptions = mImeOptions;
        final boolean hasVoiceKey = mVoiceKeyEnabled && !mVoiceButtonOnPrimary;
        // Note: This comment is only applied for phone number keyboard layout.
        // On non-xlarge device, "@integer/key_switch_alpha_symbol" key code is used to switch
        // between "phone keyboard" and "phone symbols keyboard".  But on xlarge device,
@@ -140,26 +139,25 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
        // mSymbolsId and mSymbolsShiftedId to "phone keyboard" and "phone symbols keyboard"
        // respectively here for xlarge device's layout switching.
        int xmlId = mode == KeyboardId.MODE_PHONE ? R.xml.kbd_phone : R.xml.kbd_symbols;
        mSymbolsId = new KeyboardId(
                res.getResourceEntryName(xmlId), xmlId, locale, orientation, mode, colorScheme,
                hasSettingsKey, voiceKeyEnabled, hasVoiceKey, imeOptions, true);
        final String xmlName = res.getResourceEntryName(xmlId);
        mSymbolsId = new KeyboardId(xmlName, xmlId, colorScheme, locale, orientation, mode,
                mAttribute, mHasSettingsKey, mVoiceKeyEnabled, hasVoiceKey, true);
        xmlId = mode == KeyboardId.MODE_PHONE ? R.xml.kbd_phone_symbols : R.xml.kbd_symbols_shift;
        mSymbolsShiftedId = new KeyboardId(
                res.getResourceEntryName(xmlId), xmlId, locale, orientation, mode, colorScheme,
                hasSettingsKey, voiceKeyEnabled, hasVoiceKey, imeOptions, true);
        mSymbolsShiftedId = new KeyboardId(xmlName, xmlId, colorScheme, locale, orientation, mode,
                mAttribute, mHasSettingsKey, mVoiceKeyEnabled, hasVoiceKey, true);
    }

    private boolean hasVoiceKey(boolean isSymbols) {
        return mVoiceKeyEnabled && (isSymbols != mVoiceButtonOnPrimary);
    }

    public void loadKeyboard(int mode, int imeOptions, boolean voiceKeyEnabled,
    public void loadKeyboard(int mode, EditorInfo attribute, boolean voiceKeyEnabled,
            boolean voiceButtonOnPrimary) {
        mAutoModeSwitchState = AUTO_MODE_SWITCH_STATE_ALPHA;
        try {
            if (mInputView == null) return;
            final Keyboard oldKeyboard = mInputView.getKeyboard();
            loadKeyboardInternal(mode, imeOptions, voiceKeyEnabled, voiceButtonOnPrimary, false);
            loadKeyboardInternal(mode, attribute, voiceKeyEnabled, voiceButtonOnPrimary, false);
            final Keyboard newKeyboard = mInputView.getKeyboard();
            if (newKeyboard.isAlphaKeyboard()) {
                final boolean localeChanged = (oldKeyboard == null)
@@ -167,23 +165,25 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
                mInputMethodService.mHandler.startDisplayLanguageOnSpacebar(localeChanged);
            }
        } catch (RuntimeException e) {
            Log.w(TAG, e);
            LatinImeLogger.logOnException(mode + "," + imeOptions, e);
            // Get KeyboardId to record which keyboard has been failed to load.
            final KeyboardId id = getKeyboardId(mode, attribute, false);
            Log.w(TAG, "loading keyboard failed: " + id, e);
            LatinImeLogger.logOnException(id.toString(), e);
        }
    }

    private void loadKeyboardInternal(int mode, int imeOptions, boolean voiceButtonEnabled,
    private void loadKeyboardInternal(int mode, EditorInfo attribute, boolean voiceButtonEnabled,
            boolean voiceButtonOnPrimary, boolean isSymbols) {
        if (mInputView == null) return;

        mMode = mode;
        mImeOptions = imeOptions;
        mAttribute = attribute;
        mVoiceKeyEnabled = voiceButtonEnabled;
        mVoiceButtonOnPrimary = voiceButtonOnPrimary;
        mIsSymbols = isSymbols;
        // Update the settings key state because number of enabled IMEs could have been changed
        mHasSettingsKey = getSettingsKeyMode(mPrefs, mInputMethodService);
        final KeyboardId id = getKeyboardId(mode, imeOptions, isSymbols);
        final KeyboardId id = getKeyboardId(mode, attribute, isSymbols);

        final Keyboard oldKeyboard = mInputView.getKeyboard();
        if (oldKeyboard != null && oldKeyboard.mId.equals(id))
@@ -228,7 +228,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
        return keyboard;
    }

    private KeyboardId getKeyboardId(int mode, int imeOptions, boolean isSymbols) {
    private KeyboardId getKeyboardId(int mode, EditorInfo attribute, boolean isSymbols) {
        final boolean hasVoiceKey = hasVoiceKey(isSymbols);
        final int charColorId = getColorScheme();
        final int xmlId;
@@ -260,8 +260,8 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
        final int orientation = res.getConfiguration().orientation;
        final Locale locale = mSubtypeSwitcher.getInputLocale();
        return new KeyboardId(
                res.getResourceEntryName(xmlId), xmlId, locale, orientation, mode, charColorId,
                mHasSettingsKey, mVoiceKeyEnabled, hasVoiceKey, imeOptions, enableShiftLock);
                res.getResourceEntryName(xmlId), xmlId, charColorId, locale, orientation, mode,
                attribute, mHasSettingsKey, mVoiceKeyEnabled, hasVoiceKey, enableShiftLock);
    }

    public int getKeyboardMode() {
@@ -566,7 +566,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
    }

    private void toggleKeyboardMode() {
        loadKeyboardInternal(mMode, mImeOptions, mVoiceKeyEnabled, mVoiceButtonOnPrimary,
        loadKeyboardInternal(mMode, mAttribute, mVoiceKeyEnabled, mVoiceButtonOnPrimary,
                !mIsSymbols);
        if (mIsSymbols) {
            mAutoModeSwitchState = AUTO_MODE_SWITCH_STATE_SYMBOL_BEGIN;
Loading