Automatically layout mini keyboard

Bug: 2214959

Change-Id: I06370e1c9e0683666ad19454a2fb501008af95c0
main
Tadashi G. Takaoka 2011-01-19 20:59:57 +09:00
parent 251cb11f0d
commit 04c96ab966
20 changed files with 578 additions and 196 deletions

View File

@ -20,14 +20,14 @@
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="alternates_for_a">á,à,â,ã,ä,å,æ</string>
<string name="alternates_for_e">3,é,ě,è,ê,ë</string>
<string name="alternates_for_i">í,ì,î,ï,8</string>
<string name="alternates_for_o">ó,ò,ô,õ,ö,œ,ø,9</string>
<string name="alternates_for_u">ů,ú,ù,û,ü,7</string>
<string name="alternates_for_i">8,í,ì,î,ï</string>
<string name="alternates_for_o">9,ó,ò,ô,õ,ö,œ,ø</string>
<string name="alternates_for_u">7,ů,ú,ù,û,ü</string>
<string name="alternates_for_s">š,§,ß</string>
<string name="alternates_for_n">ň,ñ</string>
<string name="alternates_for_c">č,ç</string>
<string name="alternates_for_d">ď</string>
<string name="alternates_for_r">ř,4</string>
<string name="alternates_for_t">ť,5</string>
<string name="alternates_for_r">4</string>
<string name="alternates_for_t">5</string>
<string name="alternates_for_z">ž</string>
</resources>

View File

@ -20,16 +20,16 @@
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="alternates_for_a">á,à,â,ą,ã</string>
<string name="alternates_for_e">3,é,è,ê,ë,ę,€</string>
<string name="alternates_for_i">í,ì,î,ï,8</string>
<string name="alternates_for_o">ó,ò,ô,õ,9</string>
<string name="alternates_for_u">ú,ù,û,ū,7</string>
<string name="alternates_for_i">8,í,ì,î,ï</string>
<string name="alternates_for_o">9,ó,ò,ô,õ</string>
<string name="alternates_for_u">7,ú,ù,û,ū</string>
<string name="alternates_for_s">ś,š,ş,ß</string>
<string name="alternates_for_n">ń,ñ,ň</string>
<string name="alternates_for_c">ç,ć,č</string>
<string name="alternates_for_y">ý,ÿ,ü,6</string>
<string name="alternates_for_y">6,ý,ÿ,ü</string>
<string name="alternates_for_d">ð,ď</string>
<string name="alternates_for_r">ř,4</string>
<string name="alternates_for_t">ť,þ,5</string>
<string name="alternates_for_r">4</string>
<string name="alternates_for_t">5,ť,þ</string>
<string name="alternates_for_z">ź,ž,ż</string>
<string name="alternates_for_l">ł</string>
<string name="alternates_for_v">w</string>

View File

@ -19,7 +19,7 @@
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="alternates_for_a">ä</string>
<string name="alternates_for_o">ö,9</string>
<string name="alternates_for_o">9</string>
<string name="alternates_for_y">ý,ÿ</string>
<string name="alternates_for_z">6</string>
</resources>

View File

@ -20,7 +20,7 @@
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="alternates_for_a">à,á,â,ã,ä,å,ā,æ</string>
<string name="alternates_for_e">3,è,é,ê,ë,ē</string>
<string name="alternates_for_i">ì,í,î,ï,ī,8</string>
<string name="alternates_for_o">ò,ó,ô,õ,ö,ō,œ,ø,9</string>
<string name="alternates_for_u">ù,ú,û,ü,ū,7</string>
<string name="alternates_for_i">8,ì,í,î,ï,ī</string>
<string name="alternates_for_o">9,ò,ó,ô,õ,ö,ō,œ,ø</string>
<string name="alternates_for_u">7,ù,ú,û,ü,ū</string>
</resources>

View File

@ -20,5 +20,5 @@
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="alternates_for_a">á</string>
<string name="alternates_for_e">3,é</string>
<string name="alternates_for_o">ó,9</string>
<string name="alternates_for_o">9</string>
</resources>

View File

@ -20,6 +20,6 @@
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="alternates_for_a">à,á</string>
<string name="alternates_for_e">3,è,é</string>
<string name="alternates_for_o">ò,ó,9</string>
<string name="alternates_for_o">9,ò,ó</string>
<string name="alternates_for_s">§</string>
</resources>

View File

@ -20,15 +20,15 @@
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="alternates_for_a">ä,á,à,â,ą,ã</string>
<string name="alternates_for_e">3,é,è,ê,ë,ę,€</string>
<string name="alternates_for_i">í,ì,î,ï,8</string>
<string name="alternates_for_o">ö,ó,ò,ô,õ,9</string>
<string name="alternates_for_u">ü,ú,ù,û,ū,7</string>
<string name="alternates_for_i">8,í,ì,î,ï</string>
<string name="alternates_for_o">9,ö,ó,ò,ô,õ</string>
<string name="alternates_for_u">7,ü,ú,ù,û,ū</string>
<string name="alternates_for_s">ś,š,ş,ß</string>
<string name="alternates_for_n">ń,ñ,ň</string>
<string name="alternates_for_c">ç,ć,č</string>
<string name="alternates_for_d">ð,ď</string>
<string name="alternates_for_r">ř,4</string>
<string name="alternates_for_t">ť,þ,5</string>
<string name="alternates_for_r">4</string>
<string name="alternates_for_t">5,ť,þ</string>
<string name="alternates_for_z">ź,ž,ż</string>
<string name="alternates_for_l">ł</string>
<string name="alternates_for_v">w</string>

View File

@ -19,8 +19,8 @@
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="alternates_for_a">ą</string>
<string name="alternates_for_e">ę,3</string>
<string name="alternates_for_o">ó,9</string>
<string name="alternates_for_e">3</string>
<string name="alternates_for_o">9</string>
<string name="alternates_for_s">ś</string>
<string name="alternates_for_n">ń</string>
<string name="alternates_for_c">ć</string>

View File

@ -18,5 +18,5 @@
*/
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="alternates_for_o">ò,ó,ö,ô,õ,œ,ø,9</string>
<string name="alternates_for_o">9,ò,ó,ö,ô,õ,œ,ø</string>
</resources>

View File

@ -18,6 +18,6 @@
*/
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="alternates_for_cyrillic_e">ё5</string>
<string name="alternates_for_cyrillic_e">5,ё</string>
<string name="alternates_for_cyrillic_soft_sign">ъ</string>
</resources>

View File

@ -20,16 +20,16 @@
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="alternates_for_a">á,à,â,ą,ã</string>
<string name="alternates_for_e">3,é,è,ê,ë,ę,€</string>
<string name="alternates_for_i">í,ì,î,ï,8</string>
<string name="alternates_for_o">ó,ò,ô,õ,9</string>
<string name="alternates_for_u">ú,ù,û,ū,7</string>
<string name="alternates_for_i">8,í,ì,î,ï</string>
<string name="alternates_for_o">9,ó,ò,ô,õ</string>
<string name="alternates_for_u">7,ú,ù,û,ū</string>
<string name="alternates_for_s">ś,š,ş,ß</string>
<string name="alternates_for_n">ń,ñ,ň</string>
<string name="alternates_for_c">ç,ć,č</string>
<string name="alternates_for_y">ý,ÿ,ü,6</string>
<string name="alternates_for_y">6,ý,ÿ,ü</string>
<string name="alternates_for_d">ð,ď</string>
<string name="alternates_for_r">ř,4</string>
<string name="alternates_for_t">ť,þ,5</string>
<string name="alternates_for_r">4</string>
<string name="alternates_for_t">5,ť,þ</string>
<string name="alternates_for_z">ź,ž,ż</string>
<string name="alternates_for_l">ł</string>
<string name="alternates_for_v">w</string>

View File

@ -18,8 +18,8 @@
*/
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="alternates_for_o">ö,ò,ó,ô,õ,œ,ø,9</string>
<string name="alternates_for_u">ü,ù,ú,û,7</string>
<string name="alternates_for_o">9,ö,ò,ó,ô,õ,œ,ø</string>
<string name="alternates_for_u">7,ü,ù,ú,û</string>
<string name="alternates_for_s">ş,§,ß</string>
<string name="alternates_for_g">ğ</string>
</resources>

View File

@ -33,10 +33,12 @@
<!-- Whether or not Popup on key press is enabled by default -->
<bool name="config_default_popup_preview">false</bool>
<bool name="config_use_spacebar_language_switcher">false</bool>
<!-- Showing mini keyboard, just above the touched point if true, aligned to the key if false -->
<bool name="config_show_mini_keyboard_at_touched_point">true</bool>
<!-- The language is never displayed if == 0, always displayed if < 0 -->
<integer name="config_delay_before_fadeout_language_on_spacebar">1200</integer>
<!-- This configuration is the index of the array {@link KeyboardSwitcher.KEYBOARD_THEMES}. -->
<string name="config_default_keyboard_theme_id" translatable="false">5</string>
<string name="config_text_size_of_language_on_spacebar" translatable="false">medium</string>
<integer name="config_max_popup_keyboard_column">9</integer>
<integer name="config_max_popup_keyboard_column">5</integer>
</resources>

View File

@ -40,6 +40,8 @@
<bool name="config_default_quick_fixes">true</bool>
<bool name="config_default_bigram_suggestions">true</bool>
<bool name="config_use_spacebar_language_switcher">true</bool>
<!-- Showing mini keyboard, just above the touched point if true, aligned to the key if false -->
<bool name="config_show_mini_keyboard_at_touched_point">false</bool>
<!-- The language is never displayed if == 0, always displayed if < 0 -->
<integer name="config_delay_before_fadeout_language_on_spacebar">-1</integer>
<integer name="config_duration_of_fadeout_language_on_spacebar">50</integer>
@ -61,7 +63,7 @@
<!-- This configuration is the index of the array {@link KeyboardSwitcher.KEYBOARD_THEMES}. -->
<string name="config_default_keyboard_theme_id" translatable="false">4</string>
<string name="config_text_size_of_language_on_spacebar" translatable="false">small</string>
<integer name="config_max_popup_keyboard_column">9</integer>
<integer name="config_max_popup_keyboard_column">10</integer>
<!-- Whether or not auto-correction should be enabled by default -->
<bool name="enable_autocorrect">true</bool>
<string-array name="auto_correction_threshold_values" translatable="false">

View File

@ -20,13 +20,13 @@
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="alternates_for_a">à,á,â,ã,ä,å,æ</string>
<string name="alternates_for_e">3,è,é,ê,ë</string>
<string name="alternates_for_i">ì,í,î,ï,8</string>
<string name="alternates_for_o">ò,ó,ô,õ,ö,œ,ø,9</string>
<string name="alternates_for_u">ù,ú,û,ü,7</string>
<string name="alternates_for_i">8,ì,í,î,ï</string>
<string name="alternates_for_o">9,ò,ó,ô,õ,ö,œ,ø</string>
<string name="alternates_for_u">7,ù,ú,û,ü</string>
<string name="alternates_for_s">§,ß</string>
<string name="alternates_for_n">ñ</string>
<string name="alternates_for_c">ç</string>
<string name="alternates_for_y">ý,ÿ,6</string>
<string name="alternates_for_y">6,ý,ÿ</string>
<string name="alternates_for_q">1</string>
<string name="alternates_for_w">2</string>
<string name="alternates_for_d"></string>

View File

@ -125,7 +125,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
// Popup mini keyboard
private PopupWindow mMiniKeyboardPopup;
private KeyboardView mMiniKeyboard;
private KeyboardView mMiniKeyboardView;
private View mMiniKeyboardParent;
private final WeakHashMap<Key, View> mMiniKeyboardCache = new WeakHashMap<Key, View>();
private int mMiniKeyboardOriginX;
@ -134,6 +134,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
private int[] mWindowOffset;
private final float mMiniKeyboardSlideAllowance;
private int mMiniKeyboardTrackerId;
private final boolean mConfigShowMiniKeyboardAtTouchedPoint;
/** Listener for {@link KeyboardActionListener}. */
private KeyboardActionListener mKeyboardActionListener;
@ -296,7 +297,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
public KeyboardView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
TypedArray a = context.obtainStyledAttributes(
final TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.KeyboardView, defStyle, R.style.KeyboardView);
int previewLayout = 0;
int keyTextSize = 0;
@ -381,6 +382,8 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
mMiniKeyboardPopup = new PopupWindow(context);
mMiniKeyboardPopup.setBackgroundDrawable(null);
mMiniKeyboardPopup.setAnimationStyle(R.style.MiniKeyboardAnimation);
// Allow popup window to be drawn off the screen.
mMiniKeyboardPopup.setClippingEnabled(false);
mPaint = new Paint();
mPaint.setAntiAlias(true);
@ -395,6 +398,8 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
// TODO: Refer frameworks/base/core/res/res/values/config.xml
mDisambiguateSwipe = res.getBoolean(R.bool.config_swipeDisambiguation);
mMiniKeyboardSlideAllowance = res.getDimension(R.dimen.mini_keyboard_slide_allowance);
mConfigShowMiniKeyboardAtTouchedPoint = res.getBoolean(
R.bool.config_show_mini_keyboard_at_touched_point);
GestureDetector.SimpleOnGestureListener listener =
new GestureDetector.SimpleOnGestureListener() {
@ -535,10 +540,6 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
return mColorScheme;
}
public void setPopupParent(View v) {
mMiniKeyboardParent = v;
}
public void setPopupOffset(int x, int y) {
mPopupPreviewOffsetX = x;
mPopupPreviewOffsetY = y;
@ -798,7 +799,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
mInvalidatedKey = null;
// Overlay a dark rectangle to dim the keyboard
if (mMiniKeyboard != null) {
if (mMiniKeyboardView != null) {
paint.setColor((int) (mBackgroundDimAmount * 0xFF) << 24);
canvas.drawRect(0, 0, getWidth(), getHeight(), paint);
}
@ -1052,7 +1053,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
Key popupKey = tracker.getKey(keyIndex);
if (popupKey == null)
return false;
boolean result = onLongPress(popupKey);
boolean result = onLongPress(popupKey, tracker);
if (result) {
dismissKeyPreview();
mMiniKeyboardTrackerId = tracker.mPointerId;
@ -1077,14 +1078,13 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
}
private View inflateMiniKeyboardContainer(Key popupKey) {
int popupKeyboardResId = mKeyboard.getPopupKeyboardResId();
View container = LayoutInflater.from(getContext()).inflate(mPopupLayout, null);
final View container = LayoutInflater.from(getContext()).inflate(mPopupLayout, null);
if (container == null)
throw new NullPointerException();
KeyboardView miniKeyboard =
final KeyboardView miniKeyboardView =
(KeyboardView)container.findViewById(R.id.KeyboardView);
miniKeyboard.setOnKeyboardActionListener(new KeyboardActionListener() {
miniKeyboardView.setOnKeyboardActionListener(new KeyboardActionListener() {
@Override
public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) {
mKeyboardActionListener.onCodeInput(primaryCode, keyCodes, x, y);
@ -1117,14 +1117,14 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
}
});
// Override default ProximityKeyDetector.
miniKeyboard.mKeyDetector = new MiniKeyboardKeyDetector(mMiniKeyboardSlideAllowance);
miniKeyboardView.mKeyDetector = new MiniKeyboardKeyDetector(mMiniKeyboardSlideAllowance);
// Remove gesture detector on mini-keyboard
miniKeyboard.mGestureDetector = null;
miniKeyboardView.mGestureDetector = null;
Keyboard keyboard = new MiniKeyboardBuilder(this, popupKeyboardResId, popupKey)
.build();
miniKeyboard.setKeyboard(keyboard);
miniKeyboard.setPopupParent(this);
final Keyboard keyboard = new MiniKeyboardBuilder(this, mKeyboard.getPopupKeyboardResId(),
popupKey).build();
miniKeyboardView.setKeyboard(keyboard);
miniKeyboardView.mMiniKeyboardParent = this;
container.measure(MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.AT_MOST),
MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.AT_MOST));
@ -1152,7 +1152,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
* @return true if the long press is handled, false otherwise. Subclasses should call the
* method on the base class if the subclass doesn't wish to handle the call.
*/
protected boolean onLongPress(Key popupKey) {
protected boolean onLongPress(Key popupKey, PointerTracker tracker) {
if (popupKey.mPopupCharacters == null)
return false;
@ -1161,93 +1161,51 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
container = inflateMiniKeyboardContainer(popupKey);
mMiniKeyboardCache.put(popupKey, container);
}
mMiniKeyboard = (KeyboardView)container.findViewById(R.id.KeyboardView);
mMiniKeyboardView = (KeyboardView)container.findViewById(R.id.KeyboardView);
final MiniKeyboard miniKeyboard = (MiniKeyboard)mMiniKeyboardView.getKeyboard();
if (mWindowOffset == null) {
mWindowOffset = new int[2];
getLocationInWindow(mWindowOffset);
}
// Get width of a key in the mini popup keyboard = "miniKeyWidth".
// On the other hand, "popupKey.width" is width of the pressed key on the main keyboard.
// We adjust the position of mini popup keyboard with the edge key in it:
// a) When we have the leftmost key in popup keyboard directly above the pressed key
// Right edges of both keys should be aligned for consistent default selection
// b) When we have the rightmost key in popup keyboard directly above the pressed key
// Left edges of both keys should be aligned for consistent default selection
final List<Key> miniKeys = mMiniKeyboard.getKeyboard().getKeys();
final int miniKeyWidth = miniKeys.size() > 0 ? miniKeys.get(0).mWidth : 0;
// HACK: Have the leftmost number in the popup characters right above the key
boolean isNumberAtLeftmost =
hasMultiplePopupChars(popupKey) && isNumberAtLeftmostPopupChar(popupKey);
int popupX = popupKey.mX + mWindowOffset[0];
popupX += getPaddingLeft();
if (isNumberAtLeftmost) {
popupX += popupKey.mWidth - miniKeyWidth; // adjustment for a) described above
popupX -= container.getPaddingLeft();
} else {
popupX += miniKeyWidth; // adjustment for b) described above
popupX -= container.getMeasuredWidth();
popupX += container.getPaddingRight();
}
int popupY = popupKey.mY + mWindowOffset[1];
popupY += getPaddingTop();
popupY -= container.getMeasuredHeight();
popupY += container.getPaddingBottom();
final int pointX = (mConfigShowMiniKeyboardAtTouchedPoint) ? tracker.getLastX()
: popupKey.mX + popupKey.mWidth / 2;
final int popupX = pointX - miniKeyboard.getDefaultCoordX()
- container.getPaddingLeft()
+ getPaddingLeft() + mWindowOffset[0];
final int popupY = popupKey.mY - mKeyboard.getVerticalGap()
- (container.getMeasuredHeight() - container.getPaddingBottom())
+ getPaddingTop() + mWindowOffset[1];
final int x = popupX;
final int y = mShowPreview && isOneRowKeys(miniKeys) ? mPopupPreviewDisplayedY : popupY;
final int y = mShowPreview && isOneRowKeys(miniKeyboard.getKeys())
? mPopupPreviewDisplayedY : popupY;
int adjustedX = x;
if (x < 0) {
adjustedX = 0;
} else if (x > (getMeasuredWidth() - container.getMeasuredWidth())) {
adjustedX = getMeasuredWidth() - container.getMeasuredWidth();
}
mMiniKeyboardOriginX = adjustedX + container.getPaddingLeft() - mWindowOffset[0];
mMiniKeyboardOriginX = x + container.getPaddingLeft() - mWindowOffset[0];
mMiniKeyboardOriginY = y + container.getPaddingTop() - mWindowOffset[1];
mMiniKeyboard.setPopupOffset(adjustedX, y);
Keyboard baseMiniKeyboard = mMiniKeyboard.getKeyboard();
if (baseMiniKeyboard != null && baseMiniKeyboard.setShifted(mKeyboard == null
? false : mKeyboard.isShiftedOrShiftLocked())) {
mMiniKeyboard.invalidateAllKeys();
mMiniKeyboardView.setPopupOffset(x, y);
if (miniKeyboard.setShifted(
mKeyboard == null ? false : mKeyboard.isShiftedOrShiftLocked())) {
mMiniKeyboardView.invalidateAllKeys();
}
// Mini keyboard needs no pop-up key preview displayed.
mMiniKeyboard.setPreviewEnabled(false);
mMiniKeyboardView.setPreviewEnabled(false);
mMiniKeyboardPopup.setContentView(container);
mMiniKeyboardPopup.setWidth(container.getMeasuredWidth());
mMiniKeyboardPopup.setHeight(container.getMeasuredHeight());
mMiniKeyboardPopup.showAtLocation(this, Gravity.NO_GRAVITY, x, y);
// Inject down event on the key to mini keyboard.
long eventTime = SystemClock.uptimeMillis();
final long eventTime = SystemClock.uptimeMillis();
mMiniKeyboardPopupTime = eventTime;
MotionEvent downEvent = generateMiniKeyboardMotionEvent(MotionEvent.ACTION_DOWN, popupKey.mX
+ popupKey.mWidth / 2, popupKey.mY + popupKey.mHeight / 2, eventTime);
mMiniKeyboard.onTouchEvent(downEvent);
final MotionEvent downEvent = generateMiniKeyboardMotionEvent(MotionEvent.ACTION_DOWN,
pointX, popupKey.mY + popupKey.mHeight / 2, eventTime);
mMiniKeyboardView.onTouchEvent(downEvent);
downEvent.recycle();
invalidateAllKeys();
return true;
}
private static boolean hasMultiplePopupChars(Key key) {
if (key.mPopupCharacters != null && key.mPopupCharacters.length > 1) {
return true;
}
return false;
}
private static boolean isNumberAtLeftmostPopupChar(Key key) {
if (key.mPopupCharacters != null && isAsciiDigit(key.mPopupCharacters[0].charAt(0))) {
return true;
}
return false;
}
private static boolean isAsciiDigit(char c) {
return (c < 0x80) && Character.isDigit(c);
}
private MotionEvent generateMiniKeyboardMotionEvent(int action, int x, int y, long eventTime) {
return MotionEvent.obtain(mMiniKeyboardPopupTime, eventTime, action,
x - mMiniKeyboardOriginX, y - mMiniKeyboardOriginY, 0);
@ -1273,8 +1231,8 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
}
public boolean isInSlidingKeyInput() {
if (mMiniKeyboard != null) {
return mMiniKeyboard.isInSlidingKeyInput();
if (mMiniKeyboardView != null) {
return mMiniKeyboardView.isInSlidingKeyInput();
} else {
return mPointerQueue.isInSlidingKeyInput();
}
@ -1302,7 +1260,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
mSwipeTracker.addMovement(me);
// Gesture detector must be enabled only when mini-keyboard is not on the screen.
if (mMiniKeyboard == null
if (mMiniKeyboardView == null
&& mGestureDetector != null && mGestureDetector.onTouchEvent(me)) {
dismissKeyPreview();
mHandler.cancelKeyTimers();
@ -1317,14 +1275,14 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
// Needs to be called after the gesture detector gets a turn, as it may have
// displayed the mini keyboard
if (mMiniKeyboard != null) {
if (mMiniKeyboardView != null) {
final int miniKeyboardPointerIndex = me.findPointerIndex(mMiniKeyboardTrackerId);
if (miniKeyboardPointerIndex >= 0 && miniKeyboardPointerIndex < pointerCount) {
final int miniKeyboardX = (int)me.getX(miniKeyboardPointerIndex);
final int miniKeyboardY = (int)me.getY(miniKeyboardPointerIndex);
MotionEvent translated = generateMiniKeyboardMotionEvent(action,
miniKeyboardX, miniKeyboardY, eventTime);
mMiniKeyboard.onTouchEvent(translated);
mMiniKeyboardView.onTouchEvent(translated);
translated.recycle();
}
return true;
@ -1422,7 +1380,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
private void dismissPopupKeyboard() {
if (mMiniKeyboardPopup.isShowing()) {
mMiniKeyboardPopup.dismiss();
mMiniKeyboard = null;
mMiniKeyboardView = null;
mMiniKeyboardOriginX = 0;
mMiniKeyboardOriginY = 0;
invalidateAllKeys();

View File

@ -94,7 +94,7 @@ public class LatinKeyboardView extends KeyboardView {
}
@Override
protected boolean onLongPress(Key key) {
protected boolean onLongPress(Key key, PointerTracker tracker) {
int primaryCode = key.mCode;
if (primaryCode == Keyboard.CODE_SETTINGS) {
return invokeOnKey(Keyboard.CODE_SETTINGS_LONGPRESS);
@ -102,7 +102,7 @@ public class LatinKeyboardView extends KeyboardView {
// Long pressing on 0 in phone number keypad gives you a '+'.
return invokeOnKey('+');
} else {
return super.onLongPress(key);
return super.onLongPress(key, tracker);
}
}

View File

@ -0,0 +1,35 @@
/*
* Copyright (C) 2011 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.android.inputmethod.keyboard;
import android.content.Context;
public class MiniKeyboard extends Keyboard {
private int mDefaultKeyCoordX;
public MiniKeyboard(Context context, int xmlLayoutResId, KeyboardId id) {
super(context, xmlLayoutResId, id);
}
public void setDefaultCoordX(int pos) {
mDefaultKeyCoordX = pos;
}
public int getDefaultCoordX() {
return mDefaultKeyCoordX;
}
}

View File

@ -27,44 +27,141 @@ import java.util.List;
public class MiniKeyboardBuilder {
private final Resources mRes;
private final Keyboard mKeyboard;
private final MiniKeyboard mKeyboard;
private final CharSequence[] mPopupCharacters;
private final int mMiniKeyboardKeyHorizontalPadding;
private final int mKeyWidth;
private final int mMaxColumns;
private final int mNumRows;
private int mColPos;
private int mRowPos;
private int mX;
private int mY;
private final MiniKeyboardLayoutParams mParams;
/* package */ static class MiniKeyboardLayoutParams {
public final int mKeyWidth;
public final int mRowHeight;
/* package */ final boolean mTopRowNeedsCentering;
public final int mNumRows;
public final int mNumColumns;
public final int mLeftKeys;
public final int mRightKeys; // includes default key.
/**
* The object holding mini keyboard layout parameters.
*
* @param numKeys number of keys in this mini keyboard.
* @param maxColumns number of maximum columns of this mini keyboard.
* @param keyWidth mini keyboard key width in pixel, including horizontal gap.
* @param rowHeight mini keyboard row height in pixel, including vertical gap.
* @param coordXInParent coordinate x of the popup key in parent keyboard.
* @param parentKeyboardWidth parent keyboard width in pixel.
*/
public MiniKeyboardLayoutParams(int numKeys, int maxColumns, int keyWidth, int rowHeight,
int coordXInParent, int parentKeyboardWidth) {
if (parentKeyboardWidth / keyWidth < maxColumns)
throw new IllegalArgumentException("Keyboard is too small to hold mini keyboard: "
+ parentKeyboardWidth + " " + keyWidth + " " + maxColumns);
final int numRows = (numKeys + maxColumns - 1) / maxColumns;
mKeyWidth = keyWidth;
mRowHeight = rowHeight;
mNumRows = numRows;
final int numColumns = Math.min(numKeys, maxColumns);
final int topRowKeys = numKeys % numColumns;
mNumColumns = numColumns;
mTopRowNeedsCentering = topRowKeys != 0 && (numColumns - topRowKeys) % 2 != 0;
final int numLeftKeys = (numColumns - 1) / 2;
final int numRightKeys = numColumns - numLeftKeys; // including default key.
final int maxLeftKeys = coordXInParent / keyWidth;
final int maxRightKeys = Math.max(1, (parentKeyboardWidth - coordXInParent) / keyWidth);
if (numLeftKeys > maxLeftKeys) {
mLeftKeys = maxLeftKeys;
mRightKeys = numColumns - maxLeftKeys;
} else if (numRightKeys > maxRightKeys) {
mLeftKeys = numColumns - maxRightKeys;
mRightKeys = maxRightKeys;
} else {
mLeftKeys = numLeftKeys;
mRightKeys = numRightKeys;
}
}
// Return key position according to column count (0 is default).
/* package */ int getColumnPos(int n) {
final int col = n % mNumColumns;
if (col == 0) {
// default position.
return 0;
}
int pos = 0;
int right = 1; // include default position key.
int left = 0;
int i = 0;
while (true) {
// Assign right key if available.
if (right < mRightKeys) {
pos = right;
right++;
i++;
}
if (i >= col)
break;
// Assign left key if available.
if (left < mLeftKeys) {
left++;
pos = -left;
i++;
}
if (i >= col)
break;
}
return pos;
}
public int getDefaultKeyCoordX() {
return mLeftKeys * mKeyWidth;
}
public int getX(int n, int row) {
final int x = getColumnPos(n) * mKeyWidth + getDefaultKeyCoordX();
if (isLastRow(row) && mTopRowNeedsCentering)
return x - mKeyWidth / 2;
return x;
}
public int getY(int row) {
return (mNumRows - 1 - row) * mRowHeight;
}
public int getRowFlags(int row) {
int rowFlags = 0;
if (row == 0) rowFlags |= Keyboard.EDGE_TOP;
if (isLastRow(row)) rowFlags |= Keyboard.EDGE_BOTTOM;
return rowFlags;
}
private boolean isLastRow(int rowCount) {
return rowCount == mNumRows - 1;
}
}
public MiniKeyboardBuilder(KeyboardView view, int layoutTemplateResId, Key popupKey) {
final Context context = view.getContext();
mRes = context.getResources();
final Keyboard keyboard = new Keyboard(context, layoutTemplateResId, null);
final MiniKeyboard keyboard = new MiniKeyboard(context, layoutTemplateResId, null);
mKeyboard = keyboard;
mPopupCharacters = popupKey.mPopupCharacters;
mMiniKeyboardKeyHorizontalPadding = (int)mRes.getDimension(
R.dimen.mini_keyboard_key_horizontal_padding);
mKeyWidth = getMaxKeyWidth(view, mPopupCharacters, mKeyboard.getKeyWidth());
final int maxColumns = popupKey.mMaxPopupColumn;
mMaxColumns = maxColumns;
final int numKeys = mPopupCharacters.length;
int numRows = numKeys / maxColumns;
if (numKeys % maxColumns != 0) numRows++;
mNumRows = numRows;
keyboard.setHeight((keyboard.getRowHeight() + keyboard.getVerticalGap()) * numRows
- keyboard.getVerticalGap());
if (numRows > 1) {
mColPos = numKeys % maxColumns;
if (mColPos > 0) mColPos = maxColumns - mColPos;
// Centering top-row keys.
mX = mColPos * (mKeyWidth + keyboard.getHorizontalGap()) / 2;
}
mKeyboard.setMinWidth(0);
final int keyWidth = getMaxKeyWidth(view, mPopupCharacters, keyboard.getKeyWidth());
final MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(
mPopupCharacters.length, popupKey.mMaxPopupColumn,
keyWidth, keyboard.getRowHeight(),
popupKey.mX + (popupKey.mWidth + popupKey.mGap) / 2 - keyWidth / 2,
view.getMeasuredWidth());
mParams = params;
keyboard.setHeight(params.mNumRows * params.mRowHeight - keyboard.getVerticalGap());
keyboard.setMinWidth(params.mNumColumns * params.mKeyWidth);
keyboard.setDefaultCoordX(params.getDefaultKeyCoordX() + params.mKeyWidth / 2);
}
private int getMaxKeyWidth(KeyboardView view, CharSequence[] popupCharacters, int minKeyWidth) {
private static int getMaxKeyWidth(KeyboardView view, CharSequence[] popupCharacters,
int minKeyWidth) {
Paint paint = null;
Rect bounds = null;
int maxWidth = 0;
@ -84,46 +181,22 @@ public class MiniKeyboardBuilder {
maxWidth = bounds.width();
}
}
return Math.max(minKeyWidth, maxWidth + mMiniKeyboardKeyHorizontalPadding);
final int horizontalPadding = (int)view.getContext().getResources().getDimension(
R.dimen.mini_keyboard_key_horizontal_padding);
return Math.max(minKeyWidth, maxWidth + horizontalPadding);
}
public Keyboard build() {
final Keyboard keyboard = mKeyboard;
public MiniKeyboard build() {
final MiniKeyboard keyboard = mKeyboard;
final List<Key> keys = keyboard.getKeys();
for (CharSequence label : mPopupCharacters) {
refresh();
final Key key = new Key(mRes, keyboard, label, mX, mY, mKeyWidth, getRowFlags());
final MiniKeyboardLayoutParams params = mParams;
for (int n = 0; n < mPopupCharacters.length; n++) {
final CharSequence label = mPopupCharacters[n];
final int row = n / params.mNumColumns;
final Key key = new Key(mRes, keyboard, label, params.getX(n, row), params.getY(row),
params.mKeyWidth, params.getRowFlags(row));
keys.add(key);
advance();
}
return keyboard;
}
private int getRowFlags() {
final int rowPos = mRowPos;
int rowFlags = 0;
if (rowPos == 0) rowFlags |= Keyboard.EDGE_TOP;
if (rowPos == mNumRows - 1) rowFlags |= Keyboard.EDGE_BOTTOM;
return rowFlags;
}
private void refresh() {
if (mColPos >= mMaxColumns) {
final Keyboard keyboard = mKeyboard;
// TODO: Allocate key position depending the precedence of popup characters.
mX = 0;
mY += keyboard.getRowHeight() + keyboard.getVerticalGap();
mColPos = 0;
mRowPos++;
}
}
private void advance() {
final Keyboard keyboard = mKeyboard;
// TODO: Allocate key position depending the precedence of popup characters.
mX += mKeyWidth + keyboard.getHorizontalGap();
if (mX > keyboard.getMinWidth())
keyboard.setMinWidth(mX);
mColPos++;
}
}

View File

@ -0,0 +1,312 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.android.inputmethod.keyboard;
import com.android.inputmethod.keyboard.MiniKeyboardBuilder.MiniKeyboardLayoutParams;
import android.test.AndroidTestCase;
public class MiniKeyboardBuilderTests extends AndroidTestCase {
private static final int MAX_COLUMNS = 5;
private static final int WIDTH = 10;
private static final int HEIGHT = 10;
@Override
protected void setUp() throws Exception {
super.setUp();
}
public void testLayoutError() {
MiniKeyboardLayoutParams params = null;
try {
params = new MiniKeyboardLayoutParams(
10, MAX_COLUMNS + 1, WIDTH, HEIGHT,
WIDTH * 2, WIDTH * MAX_COLUMNS);
fail("Should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Too small keyboard to hold mini keyboard.
}
assertNull("Too small keyboard to hold mini keyboard", params);
}
// Mini keyboard layout test.
// "[n]" represents n-th key position in mini keyboard.
// "[1]" is the default key.
// [1]
public void testLayout1Key() {
MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(
1, MAX_COLUMNS, WIDTH, HEIGHT,
WIDTH * 5, WIDTH * 10);
assertEquals("1 key columns", 1, params.mNumColumns);
assertEquals("1 key rows", 1, params.mNumRows);
assertEquals("1 key left", 0, params.mLeftKeys);
assertEquals("1 key right", 1, params.mRightKeys);
assertEquals("1 key [1]", 0, params.getColumnPos(0));
assertEquals("1 key centering", false, params.mTopRowNeedsCentering);
assertEquals("1 key default", 0, params.getDefaultKeyCoordX());
}
// [1] [2]
public void testLayout2Key() {
MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(
2, MAX_COLUMNS, WIDTH, HEIGHT,
WIDTH * 5, WIDTH * 10);
assertEquals("2 key columns", 2, params.mNumColumns);
assertEquals("2 key rows", 1, params.mNumRows);
assertEquals("2 key left", 0, params.mLeftKeys);
assertEquals("2 key right", 2, params.mRightKeys);
assertEquals("2 key [1]", 0, params.getColumnPos(0));
assertEquals("2 key [2]", 1, params.getColumnPos(1));
assertEquals("2 key centering", false, params.mTopRowNeedsCentering);
assertEquals("2 key default", 0, params.getDefaultKeyCoordX());
}
// [3] [1] [2]
public void testLayout3Key() {
MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(
3, MAX_COLUMNS, WIDTH, HEIGHT,
WIDTH * 5, WIDTH * 10);
assertEquals("3 key columns", 3, params.mNumColumns);
assertEquals("3 key rows", 1, params.mNumRows);
assertEquals("3 key left", 1, params.mLeftKeys);
assertEquals("3 key right", 2, params.mRightKeys);
assertEquals("3 key [1]", 0, params.getColumnPos(0));
assertEquals("3 key [2]", 1, params.getColumnPos(1));
assertEquals("3 key [3]", -1, params.getColumnPos(2));
assertEquals("3 key centering", false, params.mTopRowNeedsCentering);
assertEquals("3 key default", WIDTH, params.getDefaultKeyCoordX());
}
// [3] [1] [2] [4]
public void testLayout4Key() {
MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(
4, MAX_COLUMNS, WIDTH, HEIGHT,
WIDTH * 5, WIDTH * 10);
assertEquals("4 key columns", 4, params.mNumColumns);
assertEquals("4 key rows", 1, params.mNumRows);
assertEquals("4 key left", 1, params.mLeftKeys);
assertEquals("4 key right", 3, params.mRightKeys);
assertEquals("4 key [1]", 0, params.getColumnPos(0));
assertEquals("4 key [2]", 1, params.getColumnPos(1));
assertEquals("4 key [3]", -1, params.getColumnPos(2));
assertEquals("4 key [4]", 2, params.getColumnPos(3));
assertEquals("4 key centering", false, params.mTopRowNeedsCentering);
assertEquals("4 key default", WIDTH, params.getDefaultKeyCoordX());
}
// [5] [3] [1] [2] [4]
public void testLayout5Key() {
MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(
5, MAX_COLUMNS, WIDTH, HEIGHT,
WIDTH * 5, WIDTH * 10);
assertEquals("5 key columns", 5, params.mNumColumns);
assertEquals("5 key rows", 1, params.mNumRows);
assertEquals("5 key left", 2, params.mLeftKeys);
assertEquals("5 key right", 3, params.mRightKeys);
assertEquals("5 key [1]", 0, params.getColumnPos(0));
assertEquals("5 key [2]", 1, params.getColumnPos(1));
assertEquals("5 key [3]", -1, params.getColumnPos(2));
assertEquals("5 key [4]", 2, params.getColumnPos(3));
assertEquals("5 key [5]", -2, params.getColumnPos(4));
assertEquals("5 key centering", false, params.mTopRowNeedsCentering);
assertEquals("5 key default", WIDTH * 2, params.getDefaultKeyCoordX());
}
// [6]
// [5] [3] [1] [2] [4]
public void testLayout6Key() {
MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(
6, MAX_COLUMNS, WIDTH, HEIGHT,
WIDTH * 5, WIDTH * 10);
assertEquals("6 key columns", 5, params.mNumColumns);
assertEquals("6 key rows", 2, params.mNumRows);
assertEquals("6 key left", 2, params.mLeftKeys);
assertEquals("6 key right", 3, params.mRightKeys);
assertEquals("6 key [1]", 0, params.getColumnPos(0));
assertEquals("6 key [2]", 1, params.getColumnPos(1));
assertEquals("6 key [3]", -1, params.getColumnPos(2));
assertEquals("6 key [4]", 2, params.getColumnPos(3));
assertEquals("6 key [5]", -2, params.getColumnPos(4));
assertEquals("6 key [6]", 0, params.getColumnPos(5));
assertEquals("6 key centering", false, params.mTopRowNeedsCentering);
assertEquals("6 key default", WIDTH * 2, params.getDefaultKeyCoordX());
}
// [6] [7]
// [5] [3] [1] [2] [4]
public void testLayout7Key() {
MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(
7, MAX_COLUMNS, WIDTH, HEIGHT,
WIDTH * 5, WIDTH * 10);
assertEquals("7 key columns", 5, params.mNumColumns);
assertEquals("7 key rows", 2, params.mNumRows);
assertEquals("7 key left", 2, params.mLeftKeys);
assertEquals("7 key right", 3, params.mRightKeys);
assertEquals("7 key [1]", 0, params.getColumnPos(0));
assertEquals("7 key [2]", 1, params.getColumnPos(1));
assertEquals("7 key [3]", -1, params.getColumnPos(2));
assertEquals("7 key [4]", 2, params.getColumnPos(3));
assertEquals("7 key [5]", -2, params.getColumnPos(4));
assertEquals("7 key [6]", 0, params.getColumnPos(5));
assertEquals("7 key [7]", 1, params.getColumnPos(6));
assertEquals("7 key centering", true, params.mTopRowNeedsCentering);
assertEquals("7 key default", WIDTH * 2, params.getDefaultKeyCoordX());
}
// [8] [6] [7]
// [5] [3] [1] [2] [4]
public void testLayout8Key() {
MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(
8, MAX_COLUMNS, WIDTH, HEIGHT,
WIDTH * 5, WIDTH * 10);
assertEquals("8 key columns", 5, params.mNumColumns);
assertEquals("8 key rows", 2, params.mNumRows);
assertEquals("8 key left", 2, params.mLeftKeys);
assertEquals("8 key right", 3, params.mRightKeys);
assertEquals("8 key [1]", 0, params.getColumnPos(0));
assertEquals("8 key [2]", 1, params.getColumnPos(1));
assertEquals("8 key [3]", -1, params.getColumnPos(2));
assertEquals("8 key [4]", 2, params.getColumnPos(3));
assertEquals("8 key [5]", -2, params.getColumnPos(4));
assertEquals("8 key [6]", 0, params.getColumnPos(5));
assertEquals("8 key [7]", 1, params.getColumnPos(6));
assertEquals("8 key [8]", -1, params.getColumnPos(7));
assertEquals("8 key centering", false, params.mTopRowNeedsCentering);
assertEquals("8 key default", WIDTH * 2, params.getDefaultKeyCoordX());
}
// [8] [6] [7] [9]
// [5] [3] [1] [2] [4]
public void testLayout9Key() {
MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(
9, MAX_COLUMNS, WIDTH, HEIGHT,
WIDTH * 5, WIDTH * 10);
assertEquals("9 key columns", 5, params.mNumColumns);
assertEquals("9 key rows", 2, params.mNumRows);
assertEquals("9 key left", 2, params.mLeftKeys);
assertEquals("9 key right", 3, params.mRightKeys);
assertEquals("9 key [1]", 0, params.getColumnPos(0));
assertEquals("9 key [2]", 1, params.getColumnPos(1));
assertEquals("9 key [3]", -1, params.getColumnPos(2));
assertEquals("9 key [4]", 2, params.getColumnPos(3));
assertEquals("9 key [5]", -2, params.getColumnPos(4));
assertEquals("9 key [6]", 0, params.getColumnPos(5));
assertEquals("9 key [7]", 1, params.getColumnPos(6));
assertEquals("9 key [8]", -1, params.getColumnPos(7));
assertEquals("9 key [9]", 2, params.getColumnPos(8));
assertEquals("9 key centering", true, params.mTopRowNeedsCentering);
assertEquals("9 key default", WIDTH * 2, params.getDefaultKeyCoordX());
}
// Nine keys test. There is no key space for mini keyboard at left of the parent key.
// [6] [7] [8] [9]
// [1] [2] [3] [4] [5]
public void testLayout9KeyLeft() {
MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(
9, MAX_COLUMNS, WIDTH, HEIGHT,
0, WIDTH * 10);
assertEquals("9 key left columns", 5, params.mNumColumns);
assertEquals("9 key left rows", 2, params.mNumRows);
assertEquals("9 key left left", 0, params.mLeftKeys);
assertEquals("9 key left right", 5, params.mRightKeys);
assertEquals("9 key left [1]", 0, params.getColumnPos(0));
assertEquals("9 key left [2]", 1, params.getColumnPos(1));
assertEquals("9 key left [3]", 2, params.getColumnPos(2));
assertEquals("9 key left [4]", 3, params.getColumnPos(3));
assertEquals("9 key left [5]", 4, params.getColumnPos(4));
assertEquals("9 key left [6]", 0, params.getColumnPos(5));
assertEquals("9 key left [7]", 1, params.getColumnPos(6));
assertEquals("9 key left [8]", 2, params.getColumnPos(7));
assertEquals("9 key left [9]", 3, params.getColumnPos(8));
assertEquals("9 key left centering", true, params.mTopRowNeedsCentering);
assertEquals("9 key left default", 0, params.getDefaultKeyCoordX());
}
// Nine keys test. There is only one key space for mini keyboard at left of the parent key.
// [8] [6] [7] [9]
// [3] [1] [2] [4] [5]
public void testLayout9KeyNearLeft() {
MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(
9, MAX_COLUMNS, WIDTH, HEIGHT,
WIDTH, WIDTH * 10);
assertEquals("9 key near left columns", 5, params.mNumColumns);
assertEquals("9 key near left rows", 2, params.mNumRows);
assertEquals("9 key near left left", 1, params.mLeftKeys);
assertEquals("9 key near left right", 4, params.mRightKeys);
assertEquals("9 key near left [1]", 0, params.getColumnPos(0));
assertEquals("9 key near left [2]", 1, params.getColumnPos(1));
assertEquals("9 key near left [3]", -1, params.getColumnPos(2));
assertEquals("9 key near left [4]", 2, params.getColumnPos(3));
assertEquals("9 key near left [5]", 3, params.getColumnPos(4));
assertEquals("9 key near left [6]", 0, params.getColumnPos(5));
assertEquals("9 key near left [7]", 1, params.getColumnPos(6));
assertEquals("9 key near left [8]", -1, params.getColumnPos(7));
assertEquals("9 key near left [9]", 2, params.getColumnPos(8));
assertEquals("9 key near left centering", true, params.mTopRowNeedsCentering);
assertEquals("9 key near left default", WIDTH, params.getDefaultKeyCoordX());
}
// Nine keys test. There is no key space for mini keyboard at right of the parent key.
// [9] [8] [7] [6]
// [5] [4] [3] [2] [1]
public void testLayout9KeyRight() {
MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(
9, MAX_COLUMNS, WIDTH, HEIGHT,
WIDTH * 9, WIDTH * 10);
assertEquals("9 key right columns", 5, params.mNumColumns);
assertEquals("9 key right rows", 2, params.mNumRows);
assertEquals("9 key right left", 4, params.mLeftKeys);
assertEquals("9 key right right", 1, params.mRightKeys);
assertEquals("9 key right [1]", 0, params.getColumnPos(0));
assertEquals("9 key right [2]", -1, params.getColumnPos(1));
assertEquals("9 key right [3]", -2, params.getColumnPos(2));
assertEquals("9 key right [4]", -3, params.getColumnPos(3));
assertEquals("9 key right [5]", -4, params.getColumnPos(4));
assertEquals("9 key right [6]", 0, params.getColumnPos(5));
assertEquals("9 key right [7]", -1, params.getColumnPos(6));
assertEquals("9 key right [8]", -2, params.getColumnPos(7));
assertEquals("9 key right [9]", -3, params.getColumnPos(8));
assertEquals("9 key right centering", true, params.mTopRowNeedsCentering);
assertEquals("9 key right default", WIDTH * 4, params.getDefaultKeyCoordX());
}
// Nine keys test. There is only one key space for mini keyboard at right of the parent key.
// [9] [8] [6] [7]
// [5] [4] [3] [1] [2]
public void testLayout9KeyNearRight() {
MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(
9, MAX_COLUMNS, WIDTH, HEIGHT,
WIDTH * 8, WIDTH * 10);
assertEquals("9 key near right columns", 5, params.mNumColumns);
assertEquals("9 key near right rows", 2, params.mNumRows);
assertEquals("9 key near right left", 3, params.mLeftKeys);
assertEquals("9 key near right right", 2, params.mRightKeys);
assertEquals("9 key near right [1]", 0, params.getColumnPos(0));
assertEquals("9 key near right [2]", 1, params.getColumnPos(1));
assertEquals("9 key near right [3]", -1, params.getColumnPos(2));
assertEquals("9 key near right [4]", -2, params.getColumnPos(3));
assertEquals("9 key near right [5]", -3, params.getColumnPos(4));
assertEquals("9 key near right [6]", 0, params.getColumnPos(5));
assertEquals("9 key near right [7]", 1, params.getColumnPos(6));
assertEquals("9 key near right [8]", -1, params.getColumnPos(7));
assertEquals("9 key near right [9]", -2, params.getColumnPos(8));
assertEquals("9 key near right centering", true, params.mTopRowNeedsCentering);
assertEquals("9 key near right default", WIDTH * 3, params.getDefaultKeyCoordX());
}
}