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

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

Refactor KeyDetector to share more methods

Bug: 2959169
Change-Id: I87060049cad6f9d6432b6c4a246c15587ae0d837
parent 83b3cf56
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -19,11 +19,12 @@ package com.android.inputmethod.latin;
import android.inputmethodservice.Keyboard;
import android.inputmethodservice.Keyboard.Key;

import java.util.Arrays;
import java.util.List;

abstract class KeyDetector {
    protected Keyboard mKeyboard;
    protected Key[] mKeys;
    private Key[] mKeys;

    protected int mCorrectionX;
    protected int mCorrectionY;
@@ -50,6 +51,13 @@ abstract class KeyDetector {
        return y + mCorrectionY;
    }

    protected Key[] getKeys() {
        if (mKeys == null)
            throw new IllegalStateException("keyboard isn't set");
        // mKeyboard is guaranteed not null at setKeybaord() method
        return mKeys;
    }

    public void setProximityCorrectionEnabled(boolean enabled) {
        mProximityCorrectOn = enabled;
    }
@@ -62,7 +70,13 @@ abstract class KeyDetector {
        mProximityThresholdSquare = threshold * threshold;
    }

    abstract public int[] newCodeArray();
    public int[] newCodeArray() {
        int[] codes = new int[getMaxNearbyKeys()];
        Arrays.fill(codes, LatinKeyboardBaseView.NOT_A_KEY);
        return codes;
    }

    abstract protected int getMaxNearbyKeys();

    abstract public int getKeyIndexAndNearbyCodes(int x, int y, int[] allKeys);
}
 No newline at end of file
+3 −8
Original line number Diff line number Diff line
@@ -27,20 +27,15 @@ class ProximityKeyDetector extends KeyDetector {
    private int[] mDistances = new int[MAX_NEARBY_KEYS];

    @Override
    public int[] newCodeArray() {
        int[] codes = new int[MAX_NEARBY_KEYS];
        Arrays.fill(codes, LatinKeyboardBaseView.NOT_A_KEY);
        return codes;
    protected int getMaxNearbyKeys() {
        return MAX_NEARBY_KEYS;
    }

    @Override
    public int getKeyIndexAndNearbyCodes(int x, int y, int[] allKeys) {
        final Key[] keys = getKeys();
        final int touchX = getTouchX(x);
        final int touchY = getTouchY(y);
        final Key[] keys = mKeys;
        if (keys == null)
            throw new IllegalStateException("keyboard isn't set");
        // mKeyboard is guaranteed not null at setKeybaord() method
        int primaryIndex = LatinKeyboardBaseView.NOT_A_KEY;
        int closestKey = LatinKeyboardBaseView.NOT_A_KEY;
        int closestKeyDist = mProximityThresholdSquare + 1;