am 4af75010: Merge "Use Set to group Keys in Keyboard instead of List"

* commit '4af75010a13b4fb09d5db1e10420f37ee4dea2fd':
  Use Set to group Keys in Keyboard instead of List
main
Tadashi G. Takaoka 2011-12-16 04:28:44 -08:00 committed by Android Git Automerger
commit 954a5efc73
5 changed files with 79 additions and 26 deletions

View File

@ -37,6 +37,7 @@ import com.android.inputmethod.latin.R;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@ -116,6 +117,8 @@ public class Key {
private static final int ACTION_FLAGS_NO_KEY_PREVIEW = 0x02;
private static final int ACTION_FLAGS_ALT_CODE_WHILE_TYPING = 0x04;
private final int mHashCode;
/** The current pressed state of this key */
private boolean mPressed;
/** If this is a sticky key, is its highlight on? */
@ -204,6 +207,8 @@ public class Key {
mX = x + mHorizontalGap / 2;
mY = y;
mHitBox.set(x, y, x + width + 1, y + height);
mHashCode = hashCode(this);
}
/**
@ -279,10 +284,6 @@ public class Key {
KeyboardIconsSet.ICON_UNDEFINED));
final int shiftedIconId = style.getInt(keyAttr, R.styleable.Keyboard_Key_keyIconShifted,
KeyboardIconsSet.ICON_UNDEFINED);
if (shiftedIconId != KeyboardIconsSet.ICON_UNDEFINED) {
final Drawable shiftedIcon = iconsSet.getIcon(shiftedIconId);
params.addShiftedIcon(this, shiftedIcon);
}
mHintLabel = style.getText(keyAttr, R.styleable.Keyboard_Key_keyHintLabel);
mLabel = style.getText(keyAttr, R.styleable.Keyboard_Key_keyLabel);
@ -306,8 +307,61 @@ public class Key {
}
mAltCode = style.getInt(keyAttr,
R.styleable.Keyboard_Key_altCode, Keyboard.CODE_DUMMY);
mHashCode = hashCode(this);
keyAttr.recycle();
if (shiftedIconId != KeyboardIconsSet.ICON_UNDEFINED) {
final Drawable shiftedIcon = iconsSet.getIcon(shiftedIconId);
params.addShiftedIcon(this, shiftedIcon);
}
}
private static int hashCode(Key key) {
return Arrays.hashCode(new Object[] {
key.mX,
key.mY,
key.mWidth,
key.mHeight,
key.mCode,
key.mLabel,
key.mHintLabel,
// Key can be distinguishable without the following members.
// key.mAltCode,
// key.mOutputText,
// key.mActionFlags,
// key.mLabelFlags,
// key.mIcon,
// key.mPreviewIcon,
// key.mBackgroundType,
// key.mHorizontalGap,
// key.mVerticalGap,
// key.mVisualInsetLeft,
// key.mVisualInsetRight,
// Arrays.hashCode(key.mMoreKeys),
// key.mMaxMoreKeysColumn,
});
}
private boolean equals(Key o) {
if (this == o) return true;
return o.mX == mX
&& o.mY == mY
&& o.mWidth == mWidth
&& o.mHeight == mHeight
&& o.mCode == mCode
&& TextUtils.equals(o.mLabel, mLabel)
&& TextUtils.equals(o.mHintLabel, mHintLabel);
}
@Override
public int hashCode() {
return mHashCode;
}
@Override
public boolean equals(Object o) {
return o instanceof Key && equals((Key)o);
}
public void markAsLeftEdge(KeyboardParams params) {

View File

@ -26,7 +26,6 @@ import com.android.inputmethod.keyboard.internal.KeyboardShiftState;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -106,8 +105,8 @@ public class Keyboard {
public final boolean mIsRtlKeyboard;
/** List of keys and icons in this keyboard */
public final List<Key> mKeys;
public final List<Key> mShiftKeys;
public final Set<Key> mKeys;
public final Set<Key> mShiftKeys;
public final Set<Key> mShiftLockKeys;
public final Map<Key, Drawable> mShiftedIcons;
public final Map<Key, Drawable> mUnshiftedIcons;
@ -134,8 +133,8 @@ public class Keyboard {
mTopPadding = params.mTopPadding;
mVerticalGap = params.mVerticalGap;
mKeys = Collections.unmodifiableList(params.mKeys);
mShiftKeys = Collections.unmodifiableList(params.mShiftKeys);
mKeys = Collections.unmodifiableSet(params.mKeys);
mShiftKeys = Collections.unmodifiableSet(params.mShiftKeys);
mShiftLockKeys = Collections.unmodifiableSet(params.mShiftLockKeys);
mShiftedIcons = Collections.unmodifiableMap(params.mShiftedIcons);
mUnshiftedIcons = Collections.unmodifiableMap(params.mUnshiftedIcons);
@ -170,12 +169,12 @@ public class Keyboard {
}
// TODO: Remove this method.
public boolean hasShiftLockKey() {
boolean hasShiftLockKey() {
return !mShiftLockKeys.isEmpty();
}
// TODO: Remove this method.
public void setShiftLocked(boolean newShiftLockState) {
void setShiftLocked(boolean newShiftLockState) {
for (final Key key : mShiftLockKeys) {
// To represent "shift locked" state. The highlight is handled by background image that
// might be a StateListDrawable.
@ -191,7 +190,7 @@ public class Keyboard {
}
// TODO: Remove this method.
public void setShifted(boolean newShiftState) {
void setShifted(boolean newShiftState) {
if (!mShiftState.isShiftLocked()) {
for (final Key key : mShiftKeys) {
key.setIcon(newShiftState ? mShiftedIcons.get(key) : mUnshiftedIcons.get(key));
@ -206,7 +205,7 @@ public class Keyboard {
}
// TODO: Remove this method
public void setAutomaticTemporaryUpperCase() {
void setAutomaticTemporaryUpperCase() {
mShiftState.setAutomaticTemporaryUpperCase();
}

View File

@ -29,6 +29,7 @@ import com.android.inputmethod.latin.R;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class PointerTracker {
private static final String TAG = PointerTracker.class.getSimpleName();
@ -118,7 +119,7 @@ public class PointerTracker {
private KeyboardActionListener mListener = EMPTY_LISTENER;
private Keyboard mKeyboard;
private List<Key> mKeys;
private Set<Key> mKeys;
private int mKeyQuarterWidthSquared;
private final TextView mKeyPreviewText;

View File

@ -24,7 +24,7 @@ import com.android.inputmethod.latin.spellcheck.SpellCheckerProximityInfo;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
public class ProximityInfo {
public static final int MAX_PROXIMITY_CHARS_SIZE = 16;
@ -44,7 +44,7 @@ public class ProximityInfo {
private final Key[][] mGridNeighbors;
ProximityInfo(int gridWidth, int gridHeight, int minWidth, int height, int keyWidth,
int keyHeight, List<Key> keys, TouchPositionCorrection touchPositionCorrection) {
int keyHeight, Set<Key> keys, TouchPositionCorrection touchPositionCorrection) {
mGridWidth = gridWidth;
mGridHeight = gridHeight;
mGridSize = mGridWidth * mGridHeight;
@ -62,7 +62,7 @@ public class ProximityInfo {
}
public static ProximityInfo createDummyProximityInfo() {
return new ProximityInfo(1, 1, 1, 1, 1, 1, Collections.<Key>emptyList(), null);
return new ProximityInfo(1, 1, 1, 1, 1, 1, Collections.<Key>emptySet(), null);
}
public static ProximityInfo createSpellCheckerProximityInfo(final int[] proximity) {
@ -87,9 +87,9 @@ public class ProximityInfo {
private native void releaseProximityInfoNative(long nativeProximityInfo);
private final void setProximityInfo(Key[][] gridNeighborKeys, int keyboardWidth,
int keyboardHeight, List<Key> keys,
int keyboardHeight, Set<Key> keys,
TouchPositionCorrection touchPositionCorrection) {
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);
for (int i = 0; i < mGridSize; ++i) {
final int proximityCharsLength = gridNeighborKeys[i].length;
@ -118,8 +118,8 @@ public class ProximityInfo {
calculateSweetSpotParams = false;
}
for (int i = 0; i < keyCount; ++i) {
final Key key = keys.get(i);
int i = 0;
for (final Key key : keys) {
keyXCoordinates[i] = key.mX;
keyYCoordinates[i] = key.mY;
keyWidths[i] = key.mWidth;
@ -142,6 +142,7 @@ public class ProximityInfo {
hitBoxWidth * hitBoxWidth + hitBoxHeight * hitBoxHeight);
}
}
i++;
}
mNativeProximityInfo = setProximityInfoNative(MAX_PROXIMITY_CHARS_SIZE,
@ -166,7 +167,7 @@ public class ProximityInfo {
}
}
private void computeNearestNeighbors(int defaultWidth, List<Key> keys,
private void computeNearestNeighbors(int defaultWidth, Set<Key> keys,
TouchPositionCorrection touchPositionCorrection) {
final int thresholdBase = (int) (defaultWidth * SEARCH_DISTANCE);
final int threshold = thresholdBase * thresholdBase;

View File

@ -23,10 +23,8 @@ import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardId;
import com.android.inputmethod.latin.LatinImeLogger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -59,8 +57,8 @@ public class KeyboardParams {
public int GRID_WIDTH;
public int GRID_HEIGHT;
public final List<Key> mKeys = new ArrayList<Key>();
public final List<Key> mShiftKeys = new ArrayList<Key>();
public final Set<Key> mKeys = new HashSet<Key>();
public final Set<Key> mShiftKeys = new HashSet<Key>();
public final Set<Key> mShiftLockKeys = new HashSet<Key>();
public final Map<Key, Drawable> mShiftedIcons = new HashMap<Key, Drawable>();
public final Map<Key, Drawable> mUnshiftedIcons = new HashMap<Key, Drawable>();