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

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

Avoid using collection interface, using array instead

Change-Id: Ie0554362b73967bfcbbab6ad19c24683066a608e
parent edf5daa8
Loading
Loading
Loading
Loading
+4 −5
Original line number Original line Diff line number Diff line
@@ -36,7 +36,6 @@ import com.android.inputmethod.keyboard.KeyboardView;
import java.util.Collections;
import java.util.Collections;
import java.util.LinkedList;
import java.util.LinkedList;
import java.util.List;
import java.util.List;
import java.util.Set;


/**
/**
 * Exposes a virtual view sub-tree for {@link KeyboardView} and generates
 * Exposes a virtual view sub-tree for {@link KeyboardView} and generates
@@ -135,9 +134,9 @@ public class AccessibilityEntityProvider extends AccessibilityNodeProviderCompat
            ViewCompat.onInitializeAccessibilityNodeInfo(mKeyboardView, info);
            ViewCompat.onInitializeAccessibilityNodeInfo(mKeyboardView, info);


            // Add the virtual children of the root View.
            // Add the virtual children of the root View.
            // TODO(alanv): Need to assign a unique ID to each key.
            // TODO: Need to assign a unique ID to each key.
            final Keyboard keyboard = mKeyboardView.getKeyboard();
            final Keyboard keyboard = mKeyboardView.getKeyboard();
            final Set<Key> keys = keyboard.mKeys;
            final Key[] keys = keyboard.mKeys;
            for (Key key : keys) {
            for (Key key : keys) {
                final int childVirtualViewId = generateVirtualViewIdForKey(key);
                final int childVirtualViewId = generateVirtualViewIdForKey(key);
                info.addChild(mKeyboardView, childVirtualViewId);
                info.addChild(mKeyboardView, childVirtualViewId);
@@ -342,8 +341,8 @@ public class AccessibilityEntityProvider extends AccessibilityNodeProviderCompat


        mVirtualViewIdToKey.clear();
        mVirtualViewIdToKey.clear();


        final Set<Key> keySet = keyboard.mKeys;
        final Key[] keys = keyboard.mKeys;
        for (Key key : keySet) {
        for (Key key : keys) {
            final int virtualViewId = generateVirtualViewIdForKey(key);
            final int virtualViewId = generateVirtualViewIdForKey(key);
            mVirtualViewIdToKey.put(virtualViewId, key);
            mVirtualViewIdToKey.put(virtualViewId, key);
        }
        }
+1 −1
Original line number Original line Diff line number Diff line
@@ -17,7 +17,7 @@
package com.android.inputmethod.compat;
package com.android.inputmethod.compat;


public class MotionEventCompatUtils {
public class MotionEventCompatUtils {
    // TODO(alanv): Remove after these are added to MotionEventCompat.
    // TODO: Remove after these are added to MotionEventCompat.
    public static final int ACTION_HOVER_ENTER = 0x9;
    public static final int ACTION_HOVER_ENTER = 0x9;
    public static final int ACTION_HOVER_EXIT = 0xA;
    public static final int ACTION_HOVER_EXIT = 0xA;
}
}
+9 −12
Original line number Original line Diff line number Diff line
@@ -40,12 +40,9 @@ import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.List;
import java.util.Map;
import java.util.Map;
import java.util.Set;


/**
/**
 * Loads an XML description of a keyboard and stores the attributes of the keys. A keyboard
 * Loads an XML description of a keyboard and stores the attributes of the keys. A keyboard
@@ -125,16 +122,16 @@ public class Keyboard {
    /** Maximum column for more keys keyboard */
    /** Maximum column for more keys keyboard */
    public final int mMaxMoreKeysKeyboardColumn;
    public final int mMaxMoreKeysKeyboardColumn;


    /** List of keys and icons in this keyboard */
    /** Array of keys and icons in this keyboard */
    public final Set<Key> mKeys;
    public final Key[] mKeys;
    public final Set<Key> mShiftKeys;
    public final Key[] mShiftKeys;
    public final KeyboardIconsSet mIconsSet;
    public final KeyboardIconsSet mIconsSet;


    private final Map<Integer, Key> mKeyCache = new HashMap<Integer, Key>();
    private final HashMap<Integer, Key> mKeyCache = new HashMap<Integer, Key>();


    private final ProximityInfo mProximityInfo;
    private final ProximityInfo mProximityInfo;


    public final Map<Integer, List<Integer>> mAdditionalProximityChars;
    private final Map<Integer, List<Integer>> mAdditionalProximityChars;


    public Keyboard(Params params) {
    public Keyboard(Params params) {
        mId = params.mId;
        mId = params.mId;
@@ -149,8 +146,8 @@ public class Keyboard {
        mTopPadding = params.mTopPadding;
        mTopPadding = params.mTopPadding;
        mVerticalGap = params.mVerticalGap;
        mVerticalGap = params.mVerticalGap;


        mKeys = Collections.unmodifiableSet(params.mKeys);
        mKeys = params.mKeys.toArray(new Key[params.mKeys.size()]);
        mShiftKeys = Collections.unmodifiableSet(params.mShiftKeys);
        mShiftKeys = params.mShiftKeys.toArray(new Key[params.mShiftKeys.size()]);
        mIconsSet = params.mIconsSet;
        mIconsSet = params.mIconsSet;
        mAdditionalProximityChars = params.mAdditionalProximityChars;
        mAdditionalProximityChars = params.mAdditionalProximityChars;


@@ -225,8 +222,8 @@ public class Keyboard {
        public int GRID_WIDTH;
        public int GRID_WIDTH;
        public int GRID_HEIGHT;
        public int GRID_HEIGHT;


        public final Set<Key> mKeys = new HashSet<Key>();
        public final ArrayList<Key> mKeys = new ArrayList<Key>();
        public final Set<Key> mShiftKeys = new HashSet<Key>();
        public final ArrayList<Key> mShiftKeys = new ArrayList<Key>();
        public final KeyboardIconsSet mIconsSet = new KeyboardIconsSet();
        public final KeyboardIconsSet mIconsSet = new KeyboardIconsSet();
        // TODO: Should be in Key instead of Keyboard.Params?
        // TODO: Should be in Key instead of Keyboard.Params?
        public final Map<Integer, List<Integer>> mAdditionalProximityChars =
        public final Map<Integer, List<Integer>> mAdditionalProximityChars =
+3 −7
Original line number Original line Diff line number Diff line
@@ -25,8 +25,6 @@ import com.android.inputmethod.keyboard.internal.PointerTrackerQueue;
import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.LatinImeLogger;


import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;


public class PointerTracker {
public class PointerTracker {
    private static final String TAG = PointerTracker.class.getSimpleName();
    private static final String TAG = PointerTracker.class.getSimpleName();
@@ -109,7 +107,7 @@ public class PointerTracker {
    private static LatinKeyboardView.PointerTrackerParams sParams;
    private static LatinKeyboardView.PointerTrackerParams sParams;
    private static int sTouchNoiseThresholdDistanceSquared;
    private static int sTouchNoiseThresholdDistanceSquared;


    private static final List<PointerTracker> sTrackers = new ArrayList<PointerTracker>();
    private static final ArrayList<PointerTracker> sTrackers = new ArrayList<PointerTracker>();
    private static PointerTrackerQueue sPointerTrackerQueue;
    private static PointerTrackerQueue sPointerTrackerQueue;


    public final int mPointerId;
    public final int mPointerId;
@@ -120,7 +118,6 @@ public class PointerTracker {
    private KeyboardActionListener mListener = EMPTY_LISTENER;
    private KeyboardActionListener mListener = EMPTY_LISTENER;


    private Keyboard mKeyboard;
    private Keyboard mKeyboard;
    private Set<Key> mKeys;
    private int mKeyQuarterWidthSquared;
    private int mKeyQuarterWidthSquared;
    private final TextView mKeyPreviewText;
    private final TextView mKeyPreviewText;


@@ -180,7 +177,7 @@ public class PointerTracker {
    }
    }


    public static PointerTracker getPointerTracker(final int id, KeyEventHandler handler) {
    public static PointerTracker getPointerTracker(final int id, KeyEventHandler handler) {
        final List<PointerTracker> trackers = sTrackers;
        final ArrayList<PointerTracker> trackers = sTrackers;


        // Create pointer trackers until we can get 'id+1'-th tracker, if needed.
        // Create pointer trackers until we can get 'id+1'-th tracker, if needed.
        for (int i = trackers.size(); i <= id; i++) {
        for (int i = trackers.size(); i <= id; i++) {
@@ -303,7 +300,6 @@ public class PointerTracker {
    private void setKeyDetectorInner(KeyDetector keyDetector) {
    private void setKeyDetectorInner(KeyDetector keyDetector) {
        mKeyDetector = keyDetector;
        mKeyDetector = keyDetector;
        mKeyboard = keyDetector.getKeyboard();
        mKeyboard = keyDetector.getKeyboard();
        mKeys = mKeyboard.mKeys;
        final int keyQuarterWidth = mKeyboard.mMostCommonKeyWidth / 4;
        final int keyQuarterWidth = mKeyboard.mMostCommonKeyWidth / 4;
        mKeyQuarterWidthSquared = keyQuarterWidth * keyQuarterWidth;
        mKeyQuarterWidthSquared = keyQuarterWidth * keyQuarterWidth;
    }
    }
@@ -691,7 +687,7 @@ public class PointerTracker {
    }
    }


    private boolean isMajorEnoughMoveToBeOnNewKey(int x, int y, Key newKey) {
    private boolean isMajorEnoughMoveToBeOnNewKey(int x, int y, Key newKey) {
        if (mKeys == null || mKeyDetector == null)
        if (mKeyDetector == null)
            throw new NullPointerException("keyboard and/or key detector not set");
            throw new NullPointerException("keyboard and/or key detector not set");
        Key curKey = mCurrentKey;
        Key curKey = mCurrentKey;
        if (newKey == curKey) {
        if (newKey == curKey) {
+11 −14
Original line number Original line Diff line number Diff line
@@ -28,7 +28,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.HashMap;
import java.util.List;
import java.util.List;
import java.util.Map;
import java.util.Map;
import java.util.Set;


public class ProximityInfo {
public class ProximityInfo {
    public static final int MAX_PROXIMITY_CHARS_SIZE = 16;
    public static final int MAX_PROXIMITY_CHARS_SIZE = 16;
@@ -50,8 +49,8 @@ public class ProximityInfo {
    private final String mLocaleStr;
    private final String mLocaleStr;


    ProximityInfo(String localeStr, int gridWidth, int gridHeight, int minWidth, int height,
    ProximityInfo(String localeStr, int gridWidth, int gridHeight, int minWidth, int height,
            int mostCommonKeyWidth,
            int mostCommonKeyWidth, int mostCommonKeyHeight, final Key[] keys,
            int mostCommonKeyHeight, Set<Key> keys, TouchPositionCorrection touchPositionCorrection,
            TouchPositionCorrection touchPositionCorrection,
            Map<Integer, List<Integer>> additionalProximityChars) {
            Map<Integer, List<Integer>> additionalProximityChars) {
        if (TextUtils.isEmpty(localeStr)) {
        if (TextUtils.isEmpty(localeStr)) {
            mLocaleStr = "";
            mLocaleStr = "";
@@ -77,8 +76,8 @@ public class ProximityInfo {
    }
    }


    public static ProximityInfo createDummyProximityInfo() {
    public static ProximityInfo createDummyProximityInfo() {
        return new ProximityInfo("", 1, 1, 1, 1, 1, 1, Collections.<Key> emptySet(),
        return new ProximityInfo("", 1, 1, 1, 1, 1, 1, EMPTY_KEY_ARRAY, null,
                null, Collections.<Integer, List<Integer>> emptyMap());
                Collections.<Integer, List<Integer>> emptyMap());
    }
    }


    public static ProximityInfo createSpellCheckerProximityInfo(final int[] proximity) {
    public static ProximityInfo createSpellCheckerProximityInfo(final int[] proximity) {
@@ -106,8 +105,7 @@ public class ProximityInfo {
    private native void releaseProximityInfoNative(long nativeProximityInfo);
    private native void releaseProximityInfoNative(long nativeProximityInfo);


    private final void setProximityInfo(Key[][] gridNeighborKeys, int keyboardWidth,
    private final void setProximityInfo(Key[][] gridNeighborKeys, int keyboardWidth,
            int keyboardHeight, Set<Key> keys,
            int keyboardHeight, final Key[] keys, TouchPositionCorrection touchPositionCorrection) {
            TouchPositionCorrection touchPositionCorrection) {
        final int[] proximityCharsArray = new int[mGridSize * MAX_PROXIMITY_CHARS_SIZE];
        final int[] proximityCharsArray = new int[mGridSize * MAX_PROXIMITY_CHARS_SIZE];
        Arrays.fill(proximityCharsArray, KeyDetector.NOT_A_CODE);
        Arrays.fill(proximityCharsArray, KeyDetector.NOT_A_CODE);
        for (int i = 0; i < mGridSize; ++i) {
        for (int i = 0; i < mGridSize; ++i) {
@@ -117,7 +115,7 @@ public class ProximityInfo {
                        gridNeighborKeys[i][j].mCode;
                        gridNeighborKeys[i][j].mCode;
            }
            }
        }
        }
        final int keyCount = keys.size();
        final int keyCount = keys.length;
        final int[] keyXCoordinates = new int[keyCount];
        final int[] keyXCoordinates = new int[keyCount];
        final int[] keyYCoordinates = new int[keyCount];
        final int[] keyYCoordinates = new int[keyCount];
        final int[] keyWidths = new int[keyCount];
        final int[] keyWidths = new int[keyCount];
@@ -132,8 +130,8 @@ public class ProximityInfo {
            sweetSpotCenterYs = new float[keyCount];
            sweetSpotCenterYs = new float[keyCount];
            sweetSpotRadii = new float[keyCount];
            sweetSpotRadii = new float[keyCount];
            calculateSweetSpotParams = true;
            calculateSweetSpotParams = true;
            int i = 0;
            for (int i = 0; i < keyCount; i++) {
            for (final Key key : keys) {
                final Key key = keys[i];
                keyXCoordinates[i] = key.mX;
                keyXCoordinates[i] = key.mX;
                keyYCoordinates[i] = key.mY;
                keyYCoordinates[i] = key.mY;
                keyWidths[i] = key.mWidth;
                keyWidths[i] = key.mWidth;
@@ -156,7 +154,6 @@ public class ProximityInfo {
                                hitBoxWidth * hitBoxWidth + hitBoxHeight * hitBoxHeight);
                                hitBoxWidth * hitBoxWidth + hitBoxHeight * hitBoxHeight);
                    }
                    }
                }
                }
                i++;
            }
            }
        } else {
        } else {
            sweetSpotCenterXs = sweetSpotCenterYs = sweetSpotRadii = null;
            sweetSpotCenterXs = sweetSpotCenterYs = sweetSpotRadii = null;
@@ -186,17 +183,17 @@ public class ProximityInfo {
        }
        }
    }
    }


    private void computeNearestNeighbors(int defaultWidth, Set<Key> keys,
    private void computeNearestNeighbors(int defaultWidth, final Key[] keys,
            TouchPositionCorrection touchPositionCorrection,
            TouchPositionCorrection touchPositionCorrection,
            Map<Integer, List<Integer>> additionalProximityChars) {
            Map<Integer, List<Integer>> additionalProximityChars) {
        final Map<Integer, Key> keyCodeMap = new HashMap<Integer, Key>();
        final HashMap<Integer, Key> keyCodeMap = new HashMap<Integer, Key>();
        for (final Key key : keys) {
        for (final Key key : keys) {
            keyCodeMap.put(key.mCode, key);
            keyCodeMap.put(key.mCode, key);
        }
        }
        final int thresholdBase = (int) (defaultWidth * SEARCH_DISTANCE);
        final int thresholdBase = (int) (defaultWidth * SEARCH_DISTANCE);
        final int threshold = thresholdBase * thresholdBase;
        final int threshold = thresholdBase * thresholdBase;
        // Round-up so we don't have any pixels outside the grid
        // Round-up so we don't have any pixels outside the grid
        final Key[] neighborKeys = new Key[keys.size()];
        final Key[] neighborKeys = new Key[keys.length];
        final int gridWidth = mGridWidth * mCellWidth;
        final int gridWidth = mGridWidth * mCellWidth;
        final int gridHeight = mGridHeight * mCellHeight;
        final int gridHeight = mGridHeight * mCellHeight;
        for (int x = 0; x < gridWidth; x += mCellWidth) {
        for (int x = 0; x < gridWidth; x += mCellWidth) {
Loading