Merge "Use Set to group Keys in Keyboard instead of List"
This commit is contained in:
commit
4af75010a1
5 changed files with 79 additions and 26 deletions
|
@ -37,6 +37,7 @@ import com.android.inputmethod.latin.R;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
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_NO_KEY_PREVIEW = 0x02;
|
||||||
private static final int ACTION_FLAGS_ALT_CODE_WHILE_TYPING = 0x04;
|
private static final int ACTION_FLAGS_ALT_CODE_WHILE_TYPING = 0x04;
|
||||||
|
|
||||||
|
private final int mHashCode;
|
||||||
|
|
||||||
/** The current pressed state of this key */
|
/** The current pressed state of this key */
|
||||||
private boolean mPressed;
|
private boolean mPressed;
|
||||||
/** If this is a sticky key, is its highlight on? */
|
/** If this is a sticky key, is its highlight on? */
|
||||||
|
@ -204,6 +207,8 @@ public class Key {
|
||||||
mX = x + mHorizontalGap / 2;
|
mX = x + mHorizontalGap / 2;
|
||||||
mY = y;
|
mY = y;
|
||||||
mHitBox.set(x, y, x + width + 1, y + height);
|
mHitBox.set(x, y, x + width + 1, y + height);
|
||||||
|
|
||||||
|
mHashCode = hashCode(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -279,10 +284,6 @@ public class Key {
|
||||||
KeyboardIconsSet.ICON_UNDEFINED));
|
KeyboardIconsSet.ICON_UNDEFINED));
|
||||||
final int shiftedIconId = style.getInt(keyAttr, R.styleable.Keyboard_Key_keyIconShifted,
|
final int shiftedIconId = style.getInt(keyAttr, R.styleable.Keyboard_Key_keyIconShifted,
|
||||||
KeyboardIconsSet.ICON_UNDEFINED);
|
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);
|
mHintLabel = style.getText(keyAttr, R.styleable.Keyboard_Key_keyHintLabel);
|
||||||
|
|
||||||
mLabel = style.getText(keyAttr, R.styleable.Keyboard_Key_keyLabel);
|
mLabel = style.getText(keyAttr, R.styleable.Keyboard_Key_keyLabel);
|
||||||
|
@ -306,8 +307,61 @@ public class Key {
|
||||||
}
|
}
|
||||||
mAltCode = style.getInt(keyAttr,
|
mAltCode = style.getInt(keyAttr,
|
||||||
R.styleable.Keyboard_Key_altCode, Keyboard.CODE_DUMMY);
|
R.styleable.Keyboard_Key_altCode, Keyboard.CODE_DUMMY);
|
||||||
|
mHashCode = hashCode(this);
|
||||||
|
|
||||||
keyAttr.recycle();
|
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) {
|
public void markAsLeftEdge(KeyboardParams params) {
|
||||||
|
|
|
@ -26,7 +26,6 @@ import com.android.inputmethod.keyboard.internal.KeyboardShiftState;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -106,8 +105,8 @@ public class Keyboard {
|
||||||
public final boolean mIsRtlKeyboard;
|
public final boolean mIsRtlKeyboard;
|
||||||
|
|
||||||
/** List of keys and icons in this keyboard */
|
/** List of keys and icons in this keyboard */
|
||||||
public final List<Key> mKeys;
|
public final Set<Key> mKeys;
|
||||||
public final List<Key> mShiftKeys;
|
public final Set<Key> mShiftKeys;
|
||||||
public final Set<Key> mShiftLockKeys;
|
public final Set<Key> mShiftLockKeys;
|
||||||
public final Map<Key, Drawable> mShiftedIcons;
|
public final Map<Key, Drawable> mShiftedIcons;
|
||||||
public final Map<Key, Drawable> mUnshiftedIcons;
|
public final Map<Key, Drawable> mUnshiftedIcons;
|
||||||
|
@ -134,8 +133,8 @@ public class Keyboard {
|
||||||
mTopPadding = params.mTopPadding;
|
mTopPadding = params.mTopPadding;
|
||||||
mVerticalGap = params.mVerticalGap;
|
mVerticalGap = params.mVerticalGap;
|
||||||
|
|
||||||
mKeys = Collections.unmodifiableList(params.mKeys);
|
mKeys = Collections.unmodifiableSet(params.mKeys);
|
||||||
mShiftKeys = Collections.unmodifiableList(params.mShiftKeys);
|
mShiftKeys = Collections.unmodifiableSet(params.mShiftKeys);
|
||||||
mShiftLockKeys = Collections.unmodifiableSet(params.mShiftLockKeys);
|
mShiftLockKeys = Collections.unmodifiableSet(params.mShiftLockKeys);
|
||||||
mShiftedIcons = Collections.unmodifiableMap(params.mShiftedIcons);
|
mShiftedIcons = Collections.unmodifiableMap(params.mShiftedIcons);
|
||||||
mUnshiftedIcons = Collections.unmodifiableMap(params.mUnshiftedIcons);
|
mUnshiftedIcons = Collections.unmodifiableMap(params.mUnshiftedIcons);
|
||||||
|
@ -170,12 +169,12 @@ public class Keyboard {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Remove this method.
|
// TODO: Remove this method.
|
||||||
public boolean hasShiftLockKey() {
|
boolean hasShiftLockKey() {
|
||||||
return !mShiftLockKeys.isEmpty();
|
return !mShiftLockKeys.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Remove this method.
|
// TODO: Remove this method.
|
||||||
public void setShiftLocked(boolean newShiftLockState) {
|
void setShiftLocked(boolean newShiftLockState) {
|
||||||
for (final Key key : mShiftLockKeys) {
|
for (final Key key : mShiftLockKeys) {
|
||||||
// To represent "shift locked" state. The highlight is handled by background image that
|
// To represent "shift locked" state. The highlight is handled by background image that
|
||||||
// might be a StateListDrawable.
|
// might be a StateListDrawable.
|
||||||
|
@ -191,7 +190,7 @@ public class Keyboard {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Remove this method.
|
// TODO: Remove this method.
|
||||||
public void setShifted(boolean newShiftState) {
|
void setShifted(boolean newShiftState) {
|
||||||
if (!mShiftState.isShiftLocked()) {
|
if (!mShiftState.isShiftLocked()) {
|
||||||
for (final Key key : mShiftKeys) {
|
for (final Key key : mShiftKeys) {
|
||||||
key.setIcon(newShiftState ? mShiftedIcons.get(key) : mUnshiftedIcons.get(key));
|
key.setIcon(newShiftState ? mShiftedIcons.get(key) : mUnshiftedIcons.get(key));
|
||||||
|
@ -206,7 +205,7 @@ public class Keyboard {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Remove this method
|
// TODO: Remove this method
|
||||||
public void setAutomaticTemporaryUpperCase() {
|
void setAutomaticTemporaryUpperCase() {
|
||||||
mShiftState.setAutomaticTemporaryUpperCase();
|
mShiftState.setAutomaticTemporaryUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ import com.android.inputmethod.latin.R;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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();
|
||||||
|
@ -118,7 +119,7 @@ public class PointerTracker {
|
||||||
private KeyboardActionListener mListener = EMPTY_LISTENER;
|
private KeyboardActionListener mListener = EMPTY_LISTENER;
|
||||||
|
|
||||||
private Keyboard mKeyboard;
|
private Keyboard mKeyboard;
|
||||||
private List<Key> mKeys;
|
private Set<Key> mKeys;
|
||||||
private int mKeyQuarterWidthSquared;
|
private int mKeyQuarterWidthSquared;
|
||||||
private final TextView mKeyPreviewText;
|
private final TextView mKeyPreviewText;
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ import com.android.inputmethod.latin.spellcheck.SpellCheckerProximityInfo;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
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;
|
||||||
|
@ -44,7 +44,7 @@ public class ProximityInfo {
|
||||||
private final Key[][] mGridNeighbors;
|
private final Key[][] mGridNeighbors;
|
||||||
|
|
||||||
ProximityInfo(int gridWidth, int gridHeight, int minWidth, int height, int keyWidth,
|
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;
|
mGridWidth = gridWidth;
|
||||||
mGridHeight = gridHeight;
|
mGridHeight = gridHeight;
|
||||||
mGridSize = mGridWidth * mGridHeight;
|
mGridSize = mGridWidth * mGridHeight;
|
||||||
|
@ -62,7 +62,7 @@ public class ProximityInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ProximityInfo createDummyProximityInfo() {
|
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) {
|
public static ProximityInfo createSpellCheckerProximityInfo(final int[] proximity) {
|
||||||
|
@ -87,9 +87,9 @@ 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, List<Key> keys,
|
int keyboardHeight, Set<Key> keys,
|
||||||
TouchPositionCorrection touchPositionCorrection) {
|
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);
|
Arrays.fill(proximityCharsArray, KeyDetector.NOT_A_CODE);
|
||||||
for (int i = 0; i < mGridSize; ++i) {
|
for (int i = 0; i < mGridSize; ++i) {
|
||||||
final int proximityCharsLength = gridNeighborKeys[i].length;
|
final int proximityCharsLength = gridNeighborKeys[i].length;
|
||||||
|
@ -118,8 +118,8 @@ public class ProximityInfo {
|
||||||
calculateSweetSpotParams = false;
|
calculateSweetSpotParams = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < keyCount; ++i) {
|
int i = 0;
|
||||||
final Key key = keys.get(i);
|
for (final Key key : keys) {
|
||||||
keyXCoordinates[i] = key.mX;
|
keyXCoordinates[i] = key.mX;
|
||||||
keyYCoordinates[i] = key.mY;
|
keyYCoordinates[i] = key.mY;
|
||||||
keyWidths[i] = key.mWidth;
|
keyWidths[i] = key.mWidth;
|
||||||
|
@ -142,6 +142,7 @@ public class ProximityInfo {
|
||||||
hitBoxWidth * hitBoxWidth + hitBoxHeight * hitBoxHeight);
|
hitBoxWidth * hitBoxWidth + hitBoxHeight * hitBoxHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
mNativeProximityInfo = setProximityInfoNative(MAX_PROXIMITY_CHARS_SIZE,
|
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) {
|
TouchPositionCorrection touchPositionCorrection) {
|
||||||
final int thresholdBase = (int) (defaultWidth * SEARCH_DISTANCE);
|
final int thresholdBase = (int) (defaultWidth * SEARCH_DISTANCE);
|
||||||
final int threshold = thresholdBase * thresholdBase;
|
final int threshold = thresholdBase * thresholdBase;
|
||||||
|
|
|
@ -23,10 +23,8 @@ import com.android.inputmethod.keyboard.Keyboard;
|
||||||
import com.android.inputmethod.keyboard.KeyboardId;
|
import com.android.inputmethod.keyboard.KeyboardId;
|
||||||
import com.android.inputmethod.latin.LatinImeLogger;
|
import com.android.inputmethod.latin.LatinImeLogger;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -59,8 +57,8 @@ public class KeyboardParams {
|
||||||
public int GRID_WIDTH;
|
public int GRID_WIDTH;
|
||||||
public int GRID_HEIGHT;
|
public int GRID_HEIGHT;
|
||||||
|
|
||||||
public final List<Key> mKeys = new ArrayList<Key>();
|
public final Set<Key> mKeys = new HashSet<Key>();
|
||||||
public final List<Key> mShiftKeys = new ArrayList<Key>();
|
public final Set<Key> mShiftKeys = new HashSet<Key>();
|
||||||
public final Set<Key> mShiftLockKeys = 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> mShiftedIcons = new HashMap<Key, Drawable>();
|
||||||
public final Map<Key, Drawable> mUnshiftedIcons = new HashMap<Key, Drawable>();
|
public final Map<Key, Drawable> mUnshiftedIcons = new HashMap<Key, Drawable>();
|
||||||
|
|
Loading…
Reference in a new issue