From b4fbbe57f574ce6e6a5827156f875fe7d3eb5089 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 13 Mar 2012 20:53:15 +0900 Subject: [PATCH] Avoid using collection interface, using array instead Change-Id: Ie0554362b73967bfcbbab6ad19c24683066a608e --- .../AccessibilityEntityProvider.java | 9 +++---- .../compat/MotionEventCompatUtils.java | 2 +- .../inputmethod/keyboard/Keyboard.java | 21 +++++++--------- .../inputmethod/keyboard/PointerTracker.java | 10 +++----- .../inputmethod/keyboard/ProximityInfo.java | 25 ++++++++----------- .../keyboard/internal/KeyboardIconsSet.java | 6 ++--- 6 files changed, 31 insertions(+), 42 deletions(-) diff --git a/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java b/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java index dc7c12ba6..dd43166af 100644 --- a/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java +++ b/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java @@ -36,7 +36,6 @@ import com.android.inputmethod.keyboard.KeyboardView; import java.util.Collections; import java.util.LinkedList; import java.util.List; -import java.util.Set; /** * Exposes a virtual view sub-tree for {@link KeyboardView} and generates @@ -135,9 +134,9 @@ public class AccessibilityEntityProvider extends AccessibilityNodeProviderCompat ViewCompat.onInitializeAccessibilityNodeInfo(mKeyboardView, info); // 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 Set keys = keyboard.mKeys; + final Key[] keys = keyboard.mKeys; for (Key key : keys) { final int childVirtualViewId = generateVirtualViewIdForKey(key); info.addChild(mKeyboardView, childVirtualViewId); @@ -342,8 +341,8 @@ public class AccessibilityEntityProvider extends AccessibilityNodeProviderCompat mVirtualViewIdToKey.clear(); - final Set keySet = keyboard.mKeys; - for (Key key : keySet) { + final Key[] keys = keyboard.mKeys; + for (Key key : keys) { final int virtualViewId = generateVirtualViewIdForKey(key); mVirtualViewIdToKey.put(virtualViewId, key); } diff --git a/java/src/com/android/inputmethod/compat/MotionEventCompatUtils.java b/java/src/com/android/inputmethod/compat/MotionEventCompatUtils.java index eca922e68..9a523011a 100644 --- a/java/src/com/android/inputmethod/compat/MotionEventCompatUtils.java +++ b/java/src/com/android/inputmethod/compat/MotionEventCompatUtils.java @@ -17,7 +17,7 @@ package com.android.inputmethod.compat; 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_EXIT = 0xA; } diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index b7f1ddde6..a726878c2 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -40,12 +40,9 @@ import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; /** * 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 */ public final int mMaxMoreKeysKeyboardColumn; - /** List of keys and icons in this keyboard */ - public final Set mKeys; - public final Set mShiftKeys; + /** Array of keys and icons in this keyboard */ + public final Key[] mKeys; + public final Key[] mShiftKeys; public final KeyboardIconsSet mIconsSet; - private final Map mKeyCache = new HashMap(); + private final HashMap mKeyCache = new HashMap(); private final ProximityInfo mProximityInfo; - public final Map> mAdditionalProximityChars; + private final Map> mAdditionalProximityChars; public Keyboard(Params params) { mId = params.mId; @@ -149,8 +146,8 @@ public class Keyboard { mTopPadding = params.mTopPadding; mVerticalGap = params.mVerticalGap; - mKeys = Collections.unmodifiableSet(params.mKeys); - mShiftKeys = Collections.unmodifiableSet(params.mShiftKeys); + mKeys = params.mKeys.toArray(new Key[params.mKeys.size()]); + mShiftKeys = params.mShiftKeys.toArray(new Key[params.mShiftKeys.size()]); mIconsSet = params.mIconsSet; mAdditionalProximityChars = params.mAdditionalProximityChars; @@ -225,8 +222,8 @@ public class Keyboard { public int GRID_WIDTH; public int GRID_HEIGHT; - public final Set mKeys = new HashSet(); - public final Set mShiftKeys = new HashSet(); + public final ArrayList mKeys = new ArrayList(); + public final ArrayList mShiftKeys = new ArrayList(); public final KeyboardIconsSet mIconsSet = new KeyboardIconsSet(); // TODO: Should be in Key instead of Keyboard.Params? public final Map> mAdditionalProximityChars = diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 7a9915be0..316177fbb 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -25,8 +25,6 @@ import com.android.inputmethod.keyboard.internal.PointerTrackerQueue; import com.android.inputmethod.latin.LatinImeLogger; import java.util.ArrayList; -import java.util.List; -import java.util.Set; public class PointerTracker { private static final String TAG = PointerTracker.class.getSimpleName(); @@ -109,7 +107,7 @@ public class PointerTracker { private static LatinKeyboardView.PointerTrackerParams sParams; private static int sTouchNoiseThresholdDistanceSquared; - private static final List sTrackers = new ArrayList(); + private static final ArrayList sTrackers = new ArrayList(); private static PointerTrackerQueue sPointerTrackerQueue; public final int mPointerId; @@ -120,7 +118,6 @@ public class PointerTracker { private KeyboardActionListener mListener = EMPTY_LISTENER; private Keyboard mKeyboard; - private Set mKeys; private int mKeyQuarterWidthSquared; private final TextView mKeyPreviewText; @@ -180,7 +177,7 @@ public class PointerTracker { } public static PointerTracker getPointerTracker(final int id, KeyEventHandler handler) { - final List trackers = sTrackers; + final ArrayList trackers = sTrackers; // Create pointer trackers until we can get 'id+1'-th tracker, if needed. for (int i = trackers.size(); i <= id; i++) { @@ -303,7 +300,6 @@ public class PointerTracker { private void setKeyDetectorInner(KeyDetector keyDetector) { mKeyDetector = keyDetector; mKeyboard = keyDetector.getKeyboard(); - mKeys = mKeyboard.mKeys; final int keyQuarterWidth = mKeyboard.mMostCommonKeyWidth / 4; mKeyQuarterWidthSquared = keyQuarterWidth * keyQuarterWidth; } @@ -691,7 +687,7 @@ public class PointerTracker { } 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"); Key curKey = mCurrentKey; if (newKey == curKey) { diff --git a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java index 8a65a5fc6..e2a48306a 100644 --- a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java +++ b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java @@ -28,7 +28,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; public class ProximityInfo { public static final int MAX_PROXIMITY_CHARS_SIZE = 16; @@ -50,8 +49,8 @@ public class ProximityInfo { private final String mLocaleStr; ProximityInfo(String localeStr, int gridWidth, int gridHeight, int minWidth, int height, - int mostCommonKeyWidth, - int mostCommonKeyHeight, Set keys, TouchPositionCorrection touchPositionCorrection, + int mostCommonKeyWidth, int mostCommonKeyHeight, final Key[] keys, + TouchPositionCorrection touchPositionCorrection, Map> additionalProximityChars) { if (TextUtils.isEmpty(localeStr)) { mLocaleStr = ""; @@ -77,8 +76,8 @@ public class ProximityInfo { } public static ProximityInfo createDummyProximityInfo() { - return new ProximityInfo("", 1, 1, 1, 1, 1, 1, Collections. emptySet(), - null, Collections.> emptyMap()); + return new ProximityInfo("", 1, 1, 1, 1, 1, 1, EMPTY_KEY_ARRAY, null, + Collections.> emptyMap()); } public static ProximityInfo createSpellCheckerProximityInfo(final int[] proximity) { @@ -106,8 +105,7 @@ public class ProximityInfo { private native void releaseProximityInfoNative(long nativeProximityInfo); private final void setProximityInfo(Key[][] gridNeighborKeys, int keyboardWidth, - int keyboardHeight, Set keys, - TouchPositionCorrection touchPositionCorrection) { + int keyboardHeight, final Key[] keys, TouchPositionCorrection touchPositionCorrection) { final int[] proximityCharsArray = new int[mGridSize * MAX_PROXIMITY_CHARS_SIZE]; Arrays.fill(proximityCharsArray, KeyDetector.NOT_A_CODE); for (int i = 0; i < mGridSize; ++i) { @@ -117,7 +115,7 @@ public class ProximityInfo { gridNeighborKeys[i][j].mCode; } } - final int keyCount = keys.size(); + final int keyCount = keys.length; final int[] keyXCoordinates = new int[keyCount]; final int[] keyYCoordinates = new int[keyCount]; final int[] keyWidths = new int[keyCount]; @@ -132,8 +130,8 @@ public class ProximityInfo { sweetSpotCenterYs = new float[keyCount]; sweetSpotRadii = new float[keyCount]; calculateSweetSpotParams = true; - int i = 0; - for (final Key key : keys) { + for (int i = 0; i < keyCount; i++) { + final Key key = keys[i]; keyXCoordinates[i] = key.mX; keyYCoordinates[i] = key.mY; keyWidths[i] = key.mWidth; @@ -156,7 +154,6 @@ public class ProximityInfo { hitBoxWidth * hitBoxWidth + hitBoxHeight * hitBoxHeight); } } - i++; } } else { sweetSpotCenterXs = sweetSpotCenterYs = sweetSpotRadii = null; @@ -186,17 +183,17 @@ public class ProximityInfo { } } - private void computeNearestNeighbors(int defaultWidth, Set keys, + private void computeNearestNeighbors(int defaultWidth, final Key[] keys, TouchPositionCorrection touchPositionCorrection, Map> additionalProximityChars) { - final Map keyCodeMap = new HashMap(); + final HashMap keyCodeMap = new HashMap(); for (final Key key : keys) { keyCodeMap.put(key.mCode, key); } final int thresholdBase = (int) (defaultWidth * SEARCH_DISTANCE); final int threshold = thresholdBase * thresholdBase; // 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 gridHeight = mGridHeight * mCellHeight; for (int x = 0; x < gridWidth; x += mCellWidth) { diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java index ca711ec7d..9b9c86179 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java @@ -24,7 +24,6 @@ import android.util.Log; import com.android.inputmethod.latin.R; import java.util.HashMap; -import java.util.Map; public class KeyboardIconsSet { private static final String TAG = KeyboardIconsSet.class.getSimpleName(); @@ -35,8 +34,9 @@ public class KeyboardIconsSet { private final Drawable[] mIcons = new Drawable[NUM_ICONS + 1]; - private static final Map ATTR_ID_TO_ICON_ID = new HashMap(); - private static final Map NAME_TO_ICON_ID = new HashMap(); + private static final HashMap ATTR_ID_TO_ICON_ID + = new HashMap(); + private static final HashMap NAME_TO_ICON_ID = new HashMap(); private static final String[] ICON_NAMES = new String[NUM_ICONS + 1]; private static final int ATTR_UNDEFINED = 0;