Merge "Avoid using collection interface, using array instead"

main
Tadashi G. Takaoka 2012-03-13 05:19:47 -07:00 committed by Android (Google) Code Review
commit e1a91d0b26
6 changed files with 31 additions and 42 deletions

View File

@ -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<Key> 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<Key> 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);
}

View File

@ -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;
}

View File

@ -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<Key> mKeys;
public final Set<Key> mShiftKeys;
/** Array of keys and icons in this keyboard */
public final Key[] mKeys;
public final Key[] mShiftKeys;
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;
public final Map<Integer, List<Integer>> mAdditionalProximityChars;
private final Map<Integer, List<Integer>> 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<Key> mKeys = new HashSet<Key>();
public final Set<Key> mShiftKeys = new HashSet<Key>();
public final ArrayList<Key> mKeys = new ArrayList<Key>();
public final ArrayList<Key> mShiftKeys = new ArrayList<Key>();
public final KeyboardIconsSet mIconsSet = new KeyboardIconsSet();
// TODO: Should be in Key instead of Keyboard.Params?
public final Map<Integer, List<Integer>> mAdditionalProximityChars =

View File

@ -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<PointerTracker> sTrackers = new ArrayList<PointerTracker>();
private static final ArrayList<PointerTracker> sTrackers = new ArrayList<PointerTracker>();
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<Key> 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<PointerTracker> trackers = sTrackers;
final ArrayList<PointerTracker> 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) {

View File

@ -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<Key> keys, TouchPositionCorrection touchPositionCorrection,
int mostCommonKeyWidth, int mostCommonKeyHeight, final Key[] keys,
TouchPositionCorrection touchPositionCorrection,
Map<Integer, List<Integer>> 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.<Key> emptySet(),
null, Collections.<Integer, List<Integer>> emptyMap());
return new ProximityInfo("", 1, 1, 1, 1, 1, 1, EMPTY_KEY_ARRAY, null,
Collections.<Integer, List<Integer>> 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<Key> 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<Key> keys,
private void computeNearestNeighbors(int defaultWidth, final Key[] keys,
TouchPositionCorrection touchPositionCorrection,
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) {
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) {

View File

@ -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<Integer, Integer> ATTR_ID_TO_ICON_ID = new HashMap<Integer, Integer>();
private static final Map<String, Integer> NAME_TO_ICON_ID = new HashMap<String, Integer>();
private static final HashMap<Integer, Integer> ATTR_ID_TO_ICON_ID
= new HashMap<Integer, Integer>();
private static final HashMap<String, Integer> NAME_TO_ICON_ID = new HashMap<String, Integer>();
private static final String[] ICON_NAMES = new String[NUM_ICONS + 1];
private static final int ATTR_UNDEFINED = 0;