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

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

Remove LatinKeyboard class

Change-Id: I68c667b00dadf2ed9f1c62fb7da37d2cf499cd81
parent 4112dc05
Loading
Loading
Loading
Loading
+16 −13
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import android.util.Log;
import android.util.Xml;
import android.view.inputmethod.EditorInfo;

import com.android.inputmethod.keyboard.internal.KeyboardBuilder;
import com.android.inputmethod.keyboard.internal.KeyboardParams;
import com.android.inputmethod.keyboard.internal.XmlParseUtils;
import com.android.inputmethod.latin.LatinIME;
import com.android.inputmethod.latin.LatinImeLogger;
@@ -72,8 +74,8 @@ public class KeyboardSet {
        Params() {}
    }

    private static final HashMap<KeyboardId, SoftReference<LatinKeyboard>> sKeyboardCache =
            new HashMap<KeyboardId, SoftReference<LatinKeyboard>>();
    private static final HashMap<KeyboardId, SoftReference<Keyboard>> sKeyboardCache =
            new HashMap<KeyboardId, SoftReference<Keyboard>>();

    public static void clearKeyboardCache() {
        sKeyboardCache.clear();
@@ -84,16 +86,16 @@ public class KeyboardSet {
        mParams = params;
    }

    public LatinKeyboard getMainKeyboard() {
    public Keyboard getMainKeyboard() {
        return getKeyboard(false, false);
    }

    public LatinKeyboard getSymbolsKeyboard() {
    public Keyboard getSymbolsKeyboard() {
        return getKeyboard(true, false);
    }

    public LatinKeyboard getSymbolsShiftedKeyboard() {
        final LatinKeyboard keyboard = getKeyboard(true, true);
    public Keyboard getSymbolsShiftedKeyboard() {
        final Keyboard keyboard = getKeyboard(true, true);
        // TODO: Remove this logic once we introduce initial keyboard shift state attribute.
        // Symbol shift keyboard may have a shift key that has a caps lock style indicator (a.k.a.
        // sticky shift key). To show or dismiss the indicator, we need to call setShiftLocked()
@@ -102,11 +104,11 @@ public class KeyboardSet {
        return keyboard;
    }

    private LatinKeyboard getKeyboard(boolean isSymbols, boolean isShift) {
    private Keyboard getKeyboard(boolean isSymbols, boolean isShift) {
        final int elementState = Builder.getElementState(mParams.mMode, isSymbols, isShift);
        final int xmlId = mParams.mElementKeyboards.get(elementState);
        final KeyboardId id = Builder.getKeyboardId(elementState, isSymbols, mParams);
        final LatinKeyboard keyboard = getKeyboard(mContext, xmlId, id);
        final Keyboard keyboard = getKeyboard(mContext, xmlId, id);
        return keyboard;
    }

@@ -115,15 +117,16 @@ public class KeyboardSet {
        return Builder.getKeyboardId(elementState, false, mParams);
    }

    private static LatinKeyboard getKeyboard(Context context, int xmlId, KeyboardId id) {
    private static Keyboard getKeyboard(Context context, int xmlId, KeyboardId id) {
        final Resources res = context.getResources();
        final SubtypeSwitcher subtypeSwitcher = SubtypeSwitcher.getInstance();
        final SoftReference<LatinKeyboard> ref = sKeyboardCache.get(id);
        LatinKeyboard keyboard = (ref == null) ? null : ref.get();
        final SoftReference<Keyboard> ref = sKeyboardCache.get(id);
        Keyboard keyboard = (ref == null) ? null : ref.get();
        if (keyboard == null) {
            final Locale savedLocale = LocaleUtils.setSystemLocale(res, id.mLocale);
            try {
                final LatinKeyboard.Builder builder = new LatinKeyboard.Builder(context);
                final KeyboardBuilder<KeyboardParams> builder =
                        new KeyboardBuilder<KeyboardParams>(context, new KeyboardParams());
                builder.load(xmlId, id);
                builder.setTouchPositionCorrectionEnabled(
                        subtypeSwitcher.currentSubtypeContainsExtraValueKey(
@@ -132,7 +135,7 @@ public class KeyboardSet {
            } finally {
                LocaleUtils.setSystemLocale(res, savedLocale);
            }
            sKeyboardCache.put(id, new SoftReference<LatinKeyboard>(keyboard));
            sKeyboardCache.put(id, new SoftReference<Keyboard>(keyboard));

            if (DEBUG_CACHE) {
                Log.d(TAG, "keyboard cache size=" + sKeyboardCache.size() + ": "
+13 −15
Original line number Diff line number Diff line
@@ -171,7 +171,7 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
    }

    public boolean isAlphabetMode() {
        final Keyboard keyboard = getLatinKeyboard();
        final Keyboard keyboard = getKeyboard();
        return keyboard != null && keyboard.mId.isAlphabetKeyboard();
    }

@@ -180,12 +180,12 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
    }

    public boolean isShiftedOrShiftLocked() {
        final Keyboard keyboard = getLatinKeyboard();
        final Keyboard keyboard = getKeyboard();
        return keyboard != null && keyboard.isShiftedOrShiftLocked();
    }

    public boolean isManualTemporaryUpperCase() {
        final Keyboard keyboard = getLatinKeyboard();
        final Keyboard keyboard = getKeyboard();
        return keyboard != null && keyboard.isManualTemporaryUpperCase();
    }

@@ -195,11 +195,9 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
        return false;
    }

    public LatinKeyboard getLatinKeyboard() {
    public Keyboard getKeyboard() {
        if (mKeyboardView != null) {
            final Keyboard keyboard = mKeyboardView.getKeyboard();
            if (keyboard instanceof LatinKeyboard)
                return (LatinKeyboard)keyboard;
            return mKeyboardView.getKeyboard();
        }
        return null;
    }
@@ -208,11 +206,11 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
    @Override
    public void setShifted(int shiftMode) {
        mInputMethodService.mHandler.cancelUpdateShiftState();
        LatinKeyboard latinKeyboard = getLatinKeyboard();
        if (latinKeyboard == null)
        Keyboard keyboard = getKeyboard();
        if (keyboard == null)
            return;
        if (shiftMode == AUTOMATIC_SHIFT) {
            latinKeyboard.setAutomaticTemporaryUpperCase();
            keyboard.setAutomaticTemporaryUpperCase();
        } else {
            final boolean shifted = (shiftMode == MANUAL_SHIFT);
            // On non-distinct multi touch panel device, we should also turn off the shift locked
@@ -220,9 +218,9 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
            // On the other hand, on distinct multi touch panel device, turning off the shift
            // locked state with shift key pressing is handled by onReleaseShift().
            if (!hasDistinctMultitouch() && !shifted && mState.isShiftLocked()) {
                latinKeyboard.setShiftLocked(false);
                keyboard.setShiftLocked(false);
            }
            latinKeyboard.setShifted(shifted);
            keyboard.setShifted(shifted);
        }
        mKeyboardView.invalidateAllKeys();
    }
@@ -231,10 +229,10 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
    @Override
    public void setShiftLocked(boolean shiftLocked) {
        mInputMethodService.mHandler.cancelUpdateShiftState();
        LatinKeyboard latinKeyboard = getLatinKeyboard();
        if (latinKeyboard == null)
        Keyboard keyboard = getKeyboard();
        if (keyboard == null)
            return;
        latinKeyboard.setShiftLocked(shiftLocked);
        keyboard.setShiftLocked(shiftLocked);
        mKeyboardView.invalidateAllKeys();
        if (!shiftLocked) {
            // To be able to turn off caps lock by "double tap" on shift key, we should ignore
+0 −53
Original line number Diff line number Diff line
/*
 * Copyright (C) 2008 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.android.inputmethod.keyboard;

import android.content.Context;

import com.android.inputmethod.keyboard.internal.KeyboardBuilder;
import com.android.inputmethod.keyboard.internal.KeyboardParams;

// TODO: We should remove this class
public class LatinKeyboard extends Keyboard {
    private LatinKeyboard(KeyboardParams params) {
        super(params);
    }

    public static class Builder extends KeyboardBuilder<KeyboardParams> {
        public Builder(Context context) {
            super(context, new KeyboardParams());
        }

        @Override
        public Builder load(int xmlId, KeyboardId id) {
            super.load(xmlId, id);
            return this;
        }

        @Override
        public LatinKeyboard build() {
            return new LatinKeyboard(mParams);
        }
    }

    @Override
    public Key[] getNearestKeys(int x, int y) {
        // Avoid dead pixels at edges of the keyboard
        return super.getNearestKeys(Math.max(0, Math.min(x, mOccupiedWidth - 1)),
                Math.max(0, Math.min(y, mOccupiedHeight - 1)));
    }
}
+17 −21
Original line number Diff line number Diff line
@@ -220,8 +220,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
        @Override
        public boolean onDoubleTap(MotionEvent firstDown) {
            final Keyboard keyboard = getKeyboard();
            if (ENABLE_CAPSLOCK_BY_DOUBLETAP && keyboard instanceof LatinKeyboard
                    && ((LatinKeyboard) keyboard).mId.isAlphabetKeyboard()) {
            if (ENABLE_CAPSLOCK_BY_DOUBLETAP && keyboard.mId.isAlphabetKeyboard()) {
                final int pointerIndex = firstDown.getActionIndex();
                final int id = firstDown.getPointerId(pointerIndex);
                final PointerTracker tracker = getPointerTracker(id);
@@ -452,16 +451,14 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
    protected boolean onLongPress(Key parentKey, PointerTracker tracker) {
        final int primaryCode = parentKey.mCode;
        final Keyboard keyboard = getKeyboard();
        if (keyboard instanceof LatinKeyboard) {
            final LatinKeyboard latinKeyboard = (LatinKeyboard) keyboard;
            if (primaryCode == Keyboard.CODE_DIGIT0 && latinKeyboard.mId.isPhoneKeyboard()) {
        if (primaryCode == Keyboard.CODE_DIGIT0 && keyboard.mId.isPhoneKeyboard()) {
            tracker.onLongPressed();
            // Long pressing on 0 in phone number keypad gives you a '+'.
            invokeCodeInput(Keyboard.CODE_PLUS);
            invokeReleaseKey(primaryCode);
            return true;
        }
            if (primaryCode == Keyboard.CODE_SHIFT && latinKeyboard.mId.isAlphabetKeyboard()) {
        if (primaryCode == Keyboard.CODE_SHIFT && keyboard.mId.isAlphabetKeyboard()) {
            tracker.onLongPressed();
            invokeCodeInput(Keyboard.CODE_CAPSLOCK);
            invokeReleaseKey(primaryCode);
@@ -475,7 +472,6 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
                return true;
            }
        }
        }
        return openMoreKeysPanel(parentKey, tracker);
    }

+10 −11
Original line number Diff line number Diff line
@@ -65,7 +65,6 @@ import com.android.inputmethod.keyboard.KeyboardActionListener;
import com.android.inputmethod.keyboard.KeyboardId;
import com.android.inputmethod.keyboard.KeyboardSwitcher;
import com.android.inputmethod.keyboard.KeyboardView;
import com.android.inputmethod.keyboard.LatinKeyboard;
import com.android.inputmethod.keyboard.LatinKeyboardView;
import com.android.inputmethod.latin.suggestions.SuggestionsView;

@@ -293,13 +292,13 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
            case MSG_FADEOUT_LANGUAGE_ON_SPACEBAR:
                setSpacebarTextFadeFactor(inputView,
                        (1.0f + mFinalFadeoutFactorOfLanguageOnSpacebar) / 2,
                        (LatinKeyboard)msg.obj);
                        (Keyboard)msg.obj);
                sendMessageDelayed(obtainMessage(MSG_DISMISS_LANGUAGE_ON_SPACEBAR, msg.obj),
                        mDurationOfFadeoutLanguageOnSpacebar);
                break;
            case MSG_DISMISS_LANGUAGE_ON_SPACEBAR:
                setSpacebarTextFadeFactor(inputView, mFinalFadeoutFactorOfLanguageOnSpacebar,
                        (LatinKeyboard)msg.obj);
                        (Keyboard)msg.obj);
                break;
            }
        }
@@ -340,10 +339,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
        }

        private static void setSpacebarTextFadeFactor(LatinKeyboardView inputView,
                float fadeFactor, LatinKeyboard oldKeyboard) {
                float fadeFactor, Keyboard oldKeyboard) {
            if (inputView == null) return;
            final Keyboard keyboard = inputView.getKeyboard();
            if (keyboard instanceof LatinKeyboard && keyboard == oldKeyboard) {
            if (keyboard == oldKeyboard) {
                inputView.updateSpacebar(fadeFactor,
                        SubtypeSwitcher.getInstance().needsToDisplayLanguage(
                                keyboard.mId.mLocale));
@@ -356,7 +355,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
            removeMessages(MSG_DISMISS_LANGUAGE_ON_SPACEBAR);
            final LatinKeyboardView inputView = latinIme.mKeyboardSwitcher.getKeyboardView();
            if (inputView != null) {
                final LatinKeyboard keyboard = latinIme.mKeyboardSwitcher.getLatinKeyboard();
                final Keyboard keyboard = latinIme.mKeyboardSwitcher.getKeyboard();
                // The language is always displayed when the delay is negative.
                final boolean needsToDisplayLanguage = localeChanged
                        || mDelayBeforeFadeoutLanguageOnSpacebar < 0;
@@ -1718,7 +1717,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
        }
        // getSuggestedWordBuilder handles gracefully a null value of prevWord
        final SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(mWordComposer,
                prevWord, mKeyboardSwitcher.getLatinKeyboard().getProximityInfo(), mCorrectionMode);
                prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(), mCorrectionMode);

        boolean autoCorrectionAvailable = !mInputAttributes.mInputTypeNoAutoCorrect
                && mSuggest.hasAutoCorrection();
@@ -1867,7 +1866,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
            // pressed space on purpose of displaying the suggestion strip punctuation.
            final int rawPrimaryCode = suggestion.charAt(0);
            // Maybe apply the "bidi mirrored" conversions for parentheses
            final LatinKeyboard keyboard = mKeyboardSwitcher.getLatinKeyboard();
            final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
            final boolean isRtl = keyboard != null && keyboard.mIsRtlKeyboard;
            final int primaryCode = Key.getRtlParenthesisCode(rawPrimaryCode, isRtl);

@@ -1969,7 +1968,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
        final CharSequence prevWord = EditingUtils.getThisWord(getCurrentInputConnection(),
                mSettingsValues.mWordSeparators);
        SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(sEmptyWordComposer,
                prevWord, mKeyboardSwitcher.getLatinKeyboard().getProximityInfo(), mCorrectionMode);
                prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(), mCorrectionMode);

        if (builder.size() > 0) {
            // Explicitly supply an empty typed word (the no-second-arg version of
@@ -2095,7 +2094,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
    // "ic" must not be null
    private void restartSuggestionsOnWordBeforeCursor(final InputConnection ic,
            final CharSequence word) {
        mWordComposer.setComposingWord(word, mKeyboardSwitcher.getLatinKeyboard());
        mWordComposer.setComposingWord(word, mKeyboardSwitcher.getKeyboard());
        mComposingStateManager.onStartComposingText();
        ic.deleteSurroundingText(word.length(), 0);
        ic.setComposingText(word, 1);
@@ -2436,7 +2435,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar

        final Printer p = new PrintWriterPrinter(fout);
        p.println("LatinIME state :");
        final Keyboard keyboard = mKeyboardSwitcher.getLatinKeyboard();
        final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
        final int keyboardMode = keyboard != null ? keyboard.mId.mMode : -1;
        p.println("  Keyboard mode = " + keyboardMode);
        p.println("  mIsSuggestionsRequested=" + mInputAttributes.mIsSettingsSuggestionStripOn);
Loading