From 3040c8bcdd7d4979e48e77b5c779dd2bf14ee9ad Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 28 Jun 2011 00:54:14 +0900 Subject: Draw popup hint "..." by text rendering Bug: 4959808 Change-Id: I30456b91852904c6801cbdd6476406fd60e84551 --- .../android/inputmethod/keyboard/KeyboardView.java | 26 +++++++++------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index 840e52894..157c2b4e0 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -100,7 +100,6 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { // Miscellaneous constants private static final int[] LONG_PRESSABLE_STATE_SET = { android.R.attr.state_long_pressable }; - private static final int HINT_ICON_VERTICAL_ADJUSTMENT_PIXEL = -1; // XML attribute private final int mKeyTextColor; @@ -125,12 +124,14 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { private final int mPreviewOffset; private final int mPreviewHeight; private final int mPopupLayout; - private final Drawable mKeyPopupHintIcon; private final int mKeyHintLetterColor; private final int mKeyHintLabelColor; private final int mKeyUppercaseLetterInactivatedColor; private final int mKeyUppercaseLetterActivatedColor; + // HORIZONTAL ELLIPSIS "...", character for popup hint. + private static final String POPUP_HINT_CHAR = "\u2026"; + // Main keyboard private Keyboard mKeyboard; private int mKeyLetterSize; @@ -369,7 +370,6 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { mKeyTextColor = a.getColor(R.styleable.KeyboardView_keyTextColor, 0xFF000000); mKeyTextInactivatedColor = a.getColor( R.styleable.KeyboardView_keyTextInactivatedColor, 0xFF000000); - mKeyPopupHintIcon = a.getDrawable(R.styleable.KeyboardView_keyPopupHintIcon); mKeyHintLetterColor = a.getColor(R.styleable.KeyboardView_keyHintLetterColor, 0); mKeyHintLabelColor = a.getColor(R.styleable.KeyboardView_keyHintLabelColor, 0); mKeyUppercaseLetterInactivatedColor = a.getColor( @@ -838,19 +838,15 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { } } - // Draw popup hint icon "...". - // TODO: Draw "..." by text. + // Draw popup hint "..." at the bottom right corner of the key. if (key.hasPopupHint()) { - final int drawableWidth = keyDrawWidth; - final int drawableHeight = key.mHeight; - final int drawableX = 0; - final int drawableY = HINT_ICON_VERTICAL_ADJUSTMENT_PIXEL; - final Drawable hintIcon = mKeyPopupHintIcon; - drawIcon(canvas, hintIcon, drawableX, drawableY, drawableWidth, drawableHeight); - if (DEBUG_SHOW_ALIGN) { - drawRectangle(canvas, drawableX, drawableY, drawableWidth, drawableHeight, - 0x80c0c000, new Paint()); - } + paint.setTextSize(mKeyHintLetterSize); + paint.setColor(mKeyHintLabelColor); + final int hintX = keyDrawWidth - getLabelCharWidth(paint); + // Using y-coordinate "key.mHeight - paint.descent()" draws "..." just on the bottom + // edge of the key. So we use slightly higher position by multiply descent length by 2. + final int hintY = key.mHeight - (int)paint.descent() * 2; + canvas.drawText(POPUP_HINT_CHAR, hintX, hintY, paint); } canvas.translate(-keyDrawX - kbdPaddingLeft, -key.mY - kbdPaddingTop); -- cgit v1.2.3-83-g751a From 87089985b1ca396557d1350e9433c958a39adf11 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 28 Jun 2011 02:08:40 +0900 Subject: Render sliding spacebar language switch arrows by text Change-Id: Ief1a4f12a3d4840c36aa7a082f44b5b1ff894dd1 --- .../sym_keyboard_feedback_language_arrows_left.png | Bin 3397 -> 0 bytes ...sym_keyboard_feedback_language_arrows_right.png | Bin 3388 -> 0 bytes .../sym_keyboard_language_arrows_left.png | Bin 3220 -> 0 bytes .../sym_keyboard_language_arrows_right.png | Bin 3286 -> 0 bytes .../sym_keyboard_feedback_language_arrows_left.png | Bin 3126 -> 0 bytes ...sym_keyboard_feedback_language_arrows_right.png | Bin 3121 -> 0 bytes .../sym_keyboard_language_arrows_left.png | Bin 3001 -> 0 bytes .../sym_keyboard_language_arrows_right.png | Bin 3032 -> 0 bytes .../sym_keyboard_feedback_language_arrows_left.png | Bin 3624 -> 0 bytes ...sym_keyboard_feedback_language_arrows_right.png | Bin 3602 -> 0 bytes .../sym_keyboard_language_arrows_left.png | Bin 3356 -> 0 bytes .../sym_keyboard_language_arrows_right.png | Bin 3461 -> 0 bytes java/res/values/attrs.xml | 4 -- java/res/values/keyboard-icons-black.xml | 4 -- java/res/values/keyboard-icons-ics.xml | 4 -- java/res/values/keyboard-icons-white.xml | 4 -- .../inputmethod/keyboard/LatinKeyboard.java | 79 +++++---------------- .../keyboard/internal/SlidingLocaleDrawable.java | 36 ++++------ 18 files changed, 33 insertions(+), 98 deletions(-) delete mode 100644 java/res/drawable-hdpi/sym_keyboard_feedback_language_arrows_left.png delete mode 100644 java/res/drawable-hdpi/sym_keyboard_feedback_language_arrows_right.png delete mode 100644 java/res/drawable-hdpi/sym_keyboard_language_arrows_left.png delete mode 100644 java/res/drawable-hdpi/sym_keyboard_language_arrows_right.png delete mode 100644 java/res/drawable-mdpi/sym_keyboard_feedback_language_arrows_left.png delete mode 100644 java/res/drawable-mdpi/sym_keyboard_feedback_language_arrows_right.png delete mode 100644 java/res/drawable-mdpi/sym_keyboard_language_arrows_left.png delete mode 100644 java/res/drawable-mdpi/sym_keyboard_language_arrows_right.png delete mode 100644 java/res/drawable-xhdpi/sym_keyboard_feedback_language_arrows_left.png delete mode 100644 java/res/drawable-xhdpi/sym_keyboard_feedback_language_arrows_right.png delete mode 100644 java/res/drawable-xhdpi/sym_keyboard_language_arrows_left.png delete mode 100644 java/res/drawable-xhdpi/sym_keyboard_language_arrows_right.png (limited to 'java/src') diff --git a/java/res/drawable-hdpi/sym_keyboard_feedback_language_arrows_left.png b/java/res/drawable-hdpi/sym_keyboard_feedback_language_arrows_left.png deleted file mode 100644 index 5d1cb7833..000000000 Binary files a/java/res/drawable-hdpi/sym_keyboard_feedback_language_arrows_left.png and /dev/null differ diff --git a/java/res/drawable-hdpi/sym_keyboard_feedback_language_arrows_right.png b/java/res/drawable-hdpi/sym_keyboard_feedback_language_arrows_right.png deleted file mode 100644 index 3a56d4745..000000000 Binary files a/java/res/drawable-hdpi/sym_keyboard_feedback_language_arrows_right.png and /dev/null differ diff --git a/java/res/drawable-hdpi/sym_keyboard_language_arrows_left.png b/java/res/drawable-hdpi/sym_keyboard_language_arrows_left.png deleted file mode 100644 index 79f235f25..000000000 Binary files a/java/res/drawable-hdpi/sym_keyboard_language_arrows_left.png and /dev/null differ diff --git a/java/res/drawable-hdpi/sym_keyboard_language_arrows_right.png b/java/res/drawable-hdpi/sym_keyboard_language_arrows_right.png deleted file mode 100644 index e1444e85b..000000000 Binary files a/java/res/drawable-hdpi/sym_keyboard_language_arrows_right.png and /dev/null differ diff --git a/java/res/drawable-mdpi/sym_keyboard_feedback_language_arrows_left.png b/java/res/drawable-mdpi/sym_keyboard_feedback_language_arrows_left.png deleted file mode 100644 index eecb02694..000000000 Binary files a/java/res/drawable-mdpi/sym_keyboard_feedback_language_arrows_left.png and /dev/null differ diff --git a/java/res/drawable-mdpi/sym_keyboard_feedback_language_arrows_right.png b/java/res/drawable-mdpi/sym_keyboard_feedback_language_arrows_right.png deleted file mode 100644 index 7e10ae3af..000000000 Binary files a/java/res/drawable-mdpi/sym_keyboard_feedback_language_arrows_right.png and /dev/null differ diff --git a/java/res/drawable-mdpi/sym_keyboard_language_arrows_left.png b/java/res/drawable-mdpi/sym_keyboard_language_arrows_left.png deleted file mode 100644 index 7067a8bf5..000000000 Binary files a/java/res/drawable-mdpi/sym_keyboard_language_arrows_left.png and /dev/null differ diff --git a/java/res/drawable-mdpi/sym_keyboard_language_arrows_right.png b/java/res/drawable-mdpi/sym_keyboard_language_arrows_right.png deleted file mode 100644 index f7a133d9e..000000000 Binary files a/java/res/drawable-mdpi/sym_keyboard_language_arrows_right.png and /dev/null differ diff --git a/java/res/drawable-xhdpi/sym_keyboard_feedback_language_arrows_left.png b/java/res/drawable-xhdpi/sym_keyboard_feedback_language_arrows_left.png deleted file mode 100644 index a90b8dacf..000000000 Binary files a/java/res/drawable-xhdpi/sym_keyboard_feedback_language_arrows_left.png and /dev/null differ diff --git a/java/res/drawable-xhdpi/sym_keyboard_feedback_language_arrows_right.png b/java/res/drawable-xhdpi/sym_keyboard_feedback_language_arrows_right.png deleted file mode 100644 index 1123bf36e..000000000 Binary files a/java/res/drawable-xhdpi/sym_keyboard_feedback_language_arrows_right.png and /dev/null differ diff --git a/java/res/drawable-xhdpi/sym_keyboard_language_arrows_left.png b/java/res/drawable-xhdpi/sym_keyboard_language_arrows_left.png deleted file mode 100644 index 226f2e617..000000000 Binary files a/java/res/drawable-xhdpi/sym_keyboard_language_arrows_left.png and /dev/null differ diff --git a/java/res/drawable-xhdpi/sym_keyboard_language_arrows_right.png b/java/res/drawable-xhdpi/sym_keyboard_language_arrows_right.png deleted file mode 100644 index 1e02e7e46..000000000 Binary files a/java/res/drawable-xhdpi/sym_keyboard_language_arrows_right.png and /dev/null differ diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index 6b063efff..61ebf96bf 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -309,9 +309,5 @@ - - - - diff --git a/java/res/values/keyboard-icons-black.xml b/java/res/values/keyboard-icons-black.xml index 708d452cc..e2c688995 100644 --- a/java/res/values/keyboard-icons-black.xml +++ b/java/res/values/keyboard-icons-black.xml @@ -38,9 +38,5 @@ @drawable/sym_keyboard_space_led @drawable/sym_bkeyboard_voice_off - @null - @null - @drawable/sym_keyboard_feedback_language_arrows_left - @drawable/sym_keyboard_feedback_language_arrows_right diff --git a/java/res/values/keyboard-icons-ics.xml b/java/res/values/keyboard-icons-ics.xml index 86fb7bb96..c81315284 100644 --- a/java/res/values/keyboard-icons-ics.xml +++ b/java/res/values/keyboard-icons-ics.xml @@ -52,9 +52,5 @@ @drawable/sym_keyboard_space_led @drawable/sym_keyboard_voice_off_holo - @drawable/sym_keyboard_language_arrows_left - @drawable/sym_keyboard_language_arrows_right - @null - @null diff --git a/java/res/values/keyboard-icons-white.xml b/java/res/values/keyboard-icons-white.xml index 63df28476..8bc7539fa 100644 --- a/java/res/values/keyboard-icons-white.xml +++ b/java/res/values/keyboard-icons-white.xml @@ -34,9 +34,5 @@ @drawable/sym_keyboard_space_led @drawable/sym_keyboard_voice_off_holo - @drawable/sym_keyboard_language_arrows_left - @drawable/sym_keyboard_language_arrows_right - @drawable/sym_keyboard_feedback_language_arrows_left - @drawable/sym_keyboard_feedback_language_arrows_right diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java index 1966d2d65..9d58f69ff 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java @@ -23,9 +23,6 @@ import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; -import android.graphics.ColorFilter; -import android.graphics.ColorMatrix; -import android.graphics.ColorMatrixColorFilter; import android.graphics.Paint; import android.graphics.Paint.Align; import android.graphics.PorterDuff; @@ -61,8 +58,6 @@ public class LatinKeyboard extends Keyboard { private final int mSpaceKeyIndex; private final boolean mAutoCorrectionSpacebarLedEnabled; private final Drawable mAutoCorrectionSpacebarLedIcon; - private final Drawable mSpacebarArrowLeftIcon; - private final Drawable mSpacebarArrowRightIcon; private final int mSpacebarTextColor; private final int mSpacebarTextShadowColor; private float mSpacebarTextFadeFactor = 0.0f; @@ -77,6 +72,11 @@ public class LatinKeyboard extends Keyboard { private final Drawable mEnabledShortcutIcon; private final Drawable mDisabledShortcutIcon; + // BLACK LEFT-POINTING TRIANGLE and two spaces. + public static final String ARROW_LEFT = "\u25C0 "; + // Two spaces and BLACK RIGHT-POINTING TRIANGLE. + public static final String ARROW_RIGHT = " \u25B6"; + // Minimum width of spacebar dragging to trigger the language switch (represented by the number // of the most common key width of this keyboard). private static final int SPACEBAR_DRAG_WIDTH = 3; @@ -131,10 +131,6 @@ public class LatinKeyboard extends Keyboard { mSpacebarTextColor = a.getColor(R.styleable.LatinKeyboard_spacebarTextColor, 0); mSpacebarTextShadowColor = a.getColor( R.styleable.LatinKeyboard_spacebarTextShadowColor, 0); - mSpacebarArrowLeftIcon = a.getDrawable( - R.styleable.LatinKeyboard_spacebarArrowLeftIcon); - mSpacebarArrowRightIcon = a.getDrawable( - R.styleable.LatinKeyboard_spacebarArrowRightIcon); a.recycle(); // The threshold is "key width" x 1.25 @@ -165,12 +161,6 @@ public class LatinKeyboard extends Keyboard { return newColor; } - private static ColorFilter getSpacebarDrawableFilter(float fadeFactor) { - final ColorMatrix colorMatrix = new ColorMatrix(); - colorMatrix.setScale(1, 1, 1, fadeFactor); - return new ColorMatrixColorFilter(colorMatrix); - } - public void updateShortcutKey(boolean available, LatinKeyboardView view) { if (mShortcutKey == null) return; @@ -214,59 +204,40 @@ public class LatinKeyboard extends Keyboard { } // Layout local language name and left and right arrow on spacebar. - private static String layoutSpacebar(Paint paint, Locale locale, Drawable icon, Drawable lArrow, - Drawable rArrow, int width, int height, float origTextSize) { - final float arrowWidth; - if (lArrow != null && rArrow != null) { - arrowWidth = lArrow.getIntrinsicWidth(); - } else { - arrowWidth = 0; - } - final float maxTextWidth = width - (arrowWidth + arrowWidth); + private static String layoutSpacebar(Paint paint, Locale locale, int width, + float origTextSize) { final Rect bounds = new Rect(); // Estimate appropriate language name text size to fit in maxTextWidth. - String language = SubtypeSwitcher.getFullDisplayName(locale, true); + String language = ARROW_LEFT + SubtypeSwitcher.getFullDisplayName(locale, true) + + ARROW_RIGHT; int textWidth = getTextWidth(paint, language, origTextSize, bounds); // Assuming text width and text size are proportional to each other. - float textSize = origTextSize * Math.min(maxTextWidth / textWidth, 1.0f); + float textSize = origTextSize * Math.min(width / textWidth, 1.0f); // allow variable text size textWidth = getTextWidth(paint, language, textSize, bounds); // If text size goes too small or text does not fit, use middle or short name final boolean useMiddleName = (textSize / origTextSize < MINIMUM_SCALE_OF_LANGUAGE_NAME) - || (textWidth > maxTextWidth); + || (textWidth > width); final boolean useShortName; if (useMiddleName) { - language = SubtypeSwitcher.getMiddleDisplayLanguage(locale); + language = ARROW_LEFT + SubtypeSwitcher.getMiddleDisplayLanguage(locale) + ARROW_RIGHT; textWidth = getTextWidth(paint, language, origTextSize, bounds); - textSize = origTextSize * Math.min(maxTextWidth / textWidth, 1.0f); + textSize = origTextSize * Math.min(width / textWidth, 1.0f); useShortName = (textSize / origTextSize < MINIMUM_SCALE_OF_LANGUAGE_NAME) - || (textWidth > maxTextWidth); + || (textWidth > width); } else { useShortName = false; } if (useShortName) { - language = SubtypeSwitcher.getShortDisplayLanguage(locale); + language = ARROW_LEFT + SubtypeSwitcher.getShortDisplayLanguage(locale) + ARROW_RIGHT; textWidth = getTextWidth(paint, language, origTextSize, bounds); - textSize = origTextSize * Math.min(maxTextWidth / textWidth, 1.0f); + textSize = origTextSize * Math.min(width / textWidth, 1.0f); } paint.setTextSize(textSize); - // Place left and right arrow just before and after language text. - if (lArrow != null && rArrow != null) { - final float textHeight = -paint.ascent() + paint.descent(); - final float baseline = (icon != null) ? height * SPACEBAR_LANGUAGE_BASELINE - : height / 2 + textHeight / 2; - final int arrowHeight = lArrow.getIntrinsicHeight(); - final int top = (int)(baseline - arrowHeight); - final float remains = (width - textWidth) / 2; - lArrow.setBounds((int)(remains - arrowWidth), top, (int)remains, (int)baseline); - rArrow.setBounds((int)(remains + textWidth), top, - (int)(remains + textWidth + arrowWidth), (int)baseline); - } - return language; } @@ -311,9 +282,8 @@ public class LatinKeyboard extends Keyboard { defaultTextSize = 14; } - final String language = layoutSpacebar(paint, inputLocale, mSpaceIcon, - mSpacebarArrowLeftIcon, mSpacebarArrowRightIcon, width, height, - getTextSizeFromTheme(mTheme, textStyle, defaultTextSize)); + final String language = layoutSpacebar(paint, inputLocale, width, getTextSizeFromTheme( + mTheme, textStyle, defaultTextSize)); // Draw language text with shadow // In case there is no space icon, we will place the language text at the center of @@ -326,19 +296,6 @@ public class LatinKeyboard extends Keyboard { canvas.drawText(language, width / 2, baseline - descent - 1, paint); paint.setColor(getSpacebarTextColor(mSpacebarTextColor, textFadeFactor)); canvas.drawText(language, width / 2, baseline - descent, paint); - - // Put arrows that are already laid out on either side of the text - // Because language switch is disabled on phone and number layouts, hide arrows. - // TODO: Sort out how to enable language switch on these layouts. - if (mSpacebarArrowLeftIcon != null && mSpacebarArrowRightIcon != null - && mSubtypeSwitcher.useSpacebarLanguageSwitcher() - && mSubtypeSwitcher.getEnabledKeyboardLocaleCount() > 1 - && !(isPhoneKeyboard() || isNumberKeyboard())) { - mSpacebarArrowLeftIcon.setColorFilter(getSpacebarDrawableFilter(textFadeFactor)); - mSpacebarArrowRightIcon.setColorFilter(getSpacebarDrawableFilter(textFadeFactor)); - mSpacebarArrowLeftIcon.draw(canvas); - mSpacebarArrowRightIcon.draw(canvas); - } } // Draw the spacebar icon at the bottom diff --git a/java/src/com/android/inputmethod/keyboard/internal/SlidingLocaleDrawable.java b/java/src/com/android/inputmethod/keyboard/internal/SlidingLocaleDrawable.java index 78a3a7e9d..ef3ea4c12 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/SlidingLocaleDrawable.java +++ b/java/src/com/android/inputmethod/keyboard/internal/SlidingLocaleDrawable.java @@ -46,8 +46,7 @@ public class SlidingLocaleDrawable extends Drawable { private final int mSpacebarTextColor; private final TextPaint mTextPaint; private final int mMiddleX; - private final Drawable mLeftDrawable; - private final Drawable mRightDrawable; + private final boolean mDrawArrows; private final int mThreshold; private int mDiff; @@ -65,20 +64,18 @@ public class SlidingLocaleDrawable extends Drawable { textPaint.setTextSize(LatinKeyboard.getTextSizeFromTheme( context.getTheme(), android.R.style.TextAppearance_Medium, 18)); textPaint.setColor(Color.TRANSPARENT); - textPaint.setTextAlign(Align.CENTER); textPaint.setAntiAlias(true); mTextPaint = textPaint; mMiddleX = (background != null) ? (mWidth - mBackground.getIntrinsicWidth()) / 2 : 0; - final TypedArray lka = context.obtainStyledAttributes( - null, R.styleable.LatinKeyboard, R.attr.latinKeyboardStyle, R.style.LatinKeyboard); - mLeftDrawable = lka.getDrawable(R.styleable.LatinKeyboard_spacebarArrowPreviewLeftIcon); - mRightDrawable = lka.getDrawable(R.styleable.LatinKeyboard_spacebarArrowPreviewRightIcon); - lka.recycle(); - final TypedArray kva = context.obtainStyledAttributes( + final TypedArray a = context.obtainStyledAttributes( null, R.styleable.KeyboardView, R.attr.keyboardViewStyle, R.style.KeyboardView); - mSpacebarTextColor = kva.getColor(R.styleable.KeyboardView_keyPreviewTextColor, 0); - kva.recycle(); + mSpacebarTextColor = a.getColor(R.styleable.KeyboardView_keyPreviewTextColor, 0); + final int spacebarPreviewBackrgound = a.getResourceId( + R.styleable.KeyboardView_keyPreviewSpacebarBackground, 0); + // If spacebar preview background is transparent, we need not draw arrows. + mDrawArrows = (spacebarPreviewBackrgound != R.drawable.transparent); + a.recycle(); mThreshold = ViewConfiguration.get(context).getScaledTouchSlop(); } @@ -105,8 +102,6 @@ public class SlidingLocaleDrawable extends Drawable { final int width = mWidth; final int height = mHeight; final int diff = mDiff; - final Drawable lArrow = mLeftDrawable; - final Drawable rArrow = mRightDrawable; canvas.clipRect(0, 0, width, height); if (mCurrentLanguage == null) { SubtypeSwitcher subtypeSwitcher = SubtypeSwitcher.getInstance(); @@ -114,20 +109,19 @@ public class SlidingLocaleDrawable extends Drawable { mNextLanguage = subtypeSwitcher.getNextInputLanguageName(); mPrevLanguage = subtypeSwitcher.getPreviousInputLanguageName(); } - // Draw language text with shadow + // Draw language text. final float baseline = mHeight * LatinKeyboard.SPACEBAR_LANGUAGE_BASELINE - paint.descent(); paint.setColor(mSpacebarTextColor); + paint.setTextAlign(Align.CENTER); canvas.drawText(mCurrentLanguage, width / 2 + diff, baseline, paint); canvas.drawText(mNextLanguage, diff - width / 2, baseline, paint); canvas.drawText(mPrevLanguage, diff + width + width / 2, baseline, paint); - - if (lArrow != null && rArrow != null) { - Keyboard.setDefaultBounds(lArrow); - rArrow.setBounds(width - rArrow.getIntrinsicWidth(), 0, width, - rArrow.getIntrinsicHeight()); - lArrow.draw(canvas); - rArrow.draw(canvas); + if (mDrawArrows) { + paint.setTextAlign(Align.LEFT); + canvas.drawText(LatinKeyboard.ARROW_LEFT, 0, baseline, paint); + paint.setTextAlign(Align.RIGHT); + canvas.drawText(LatinKeyboard.ARROW_RIGHT, width, baseline, paint); } } if (mBackground != null) { -- cgit v1.2.3-83-g751a From d87f28f1457f5490df3796fa2a8d815b2bcde152 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 28 Jun 2011 03:01:35 +0900 Subject: Use left/right-edge popup preview background Bug: 4902361 Change-Id: Iafbadd0e44c0db2fb6a0875c964304bec6ac8cb0 --- .../drawable/keyboard_key_feedback_left_ics.xml | 21 ++++++++++++++++ .../drawable/keyboard_key_feedback_right_ics.xml | 21 ++++++++++++++++ java/res/values/attrs.xml | 4 +++ java/res/values/styles.xml | 4 +++ .../android/inputmethod/keyboard/KeyboardView.java | 29 +++++++++++++++------- 5 files changed, 70 insertions(+), 9 deletions(-) create mode 100644 java/res/drawable/keyboard_key_feedback_left_ics.xml create mode 100644 java/res/drawable/keyboard_key_feedback_right_ics.xml (limited to 'java/src') diff --git a/java/res/drawable/keyboard_key_feedback_left_ics.xml b/java/res/drawable/keyboard_key_feedback_left_ics.xml new file mode 100644 index 000000000..b68b37f6b --- /dev/null +++ b/java/res/drawable/keyboard_key_feedback_left_ics.xml @@ -0,0 +1,21 @@ + + + + + + + diff --git a/java/res/drawable/keyboard_key_feedback_right_ics.xml b/java/res/drawable/keyboard_key_feedback_right_ics.xml new file mode 100644 index 000000000..830678a5a --- /dev/null +++ b/java/res/drawable/keyboard_key_feedback_right_ics.xml @@ -0,0 +1,21 @@ + + + + + + + diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index 6b063efff..d89f55a50 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -68,6 +68,10 @@ + + + + diff --git a/java/res/values/styles.xml b/java/res/values/styles.xml index 1f1488e26..08301be5c 100644 --- a/java/res/values/styles.xml +++ b/java/res/values/styles.xml @@ -51,6 +51,8 @@ #CCE0E4E5 @layout/key_preview @drawable/keyboard_key_feedback + @null + @null @drawable/keyboard_key_feedback #FFFFFFFF @dimen/key_preview_offset @@ -152,6 +154,8 @@ #66E0E4E5 #FFFFFFFF @drawable/keyboard_key_feedback_ics + @drawable/keyboard_key_feedback_left_ics + @drawable/keyboard_key_feedback_right_ics @drawable/transparent #FFFFFFFF @dimen/key_preview_height_ics diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index 52e2a6a6d..da738b24c 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -118,6 +118,8 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { private final float mKeyHysteresisDistance; private final float mVerticalCorrection; private final Drawable mPreviewBackground; + private final Drawable mPreviewLeftBackground; + private final Drawable mPreviewRightBackground; private final Drawable mPreviewSpacebarBackground; private final int mPreviewTextColor; private final float mPreviewTextRatio; @@ -203,6 +205,9 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { private static final String KEY_LABEL_REFERENCE_CHAR = "M"; private final int mKeyLabelHorizontalPadding; + private static final int MEASURESPEC_UNSPECIFIED = MeasureSpec.makeMeasureSpec( + 0, MeasureSpec.UNSPECIFIED); + private final UIHandler mHandler = new UIHandler(this); public static class UIHandler extends StaticInnerHandlerWrapper { @@ -354,6 +359,8 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { mShowKeyPreviewPopup = false; } mPreviewBackground = a.getDrawable(R.styleable.KeyboardView_keyPreviewBackground); + mPreviewLeftBackground = a.getDrawable(R.styleable.KeyboardView_keyPreviewLeftBackground); + mPreviewRightBackground = a.getDrawable(R.styleable.KeyboardView_keyPreviewRightBackground); mPreviewSpacebarBackground = a.getDrawable( R.styleable.KeyboardView_keyPreviewSpacebarBackground); mPreviewOffset = a.getDimensionPixelOffset(R.styleable.KeyboardView_keyPreviewOffset, 0); @@ -1016,21 +1023,25 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { } else { previewText.setBackgroundDrawable(mPreviewBackground); } - // Set the preview background state - previewText.getBackground().setState( - key.mPopupCharacters != null ? LONG_PRESSABLE_STATE_SET : EMPTY_STATE_SET); - previewText.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), - MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); + previewText.measure(MEASURESPEC_UNSPECIFIED, MEASURESPEC_UNSPECIFIED); final int previewWidth = Math.max(previewText.getMeasuredWidth(), keyDrawWidth + previewText.getPaddingLeft() + previewText.getPaddingRight()); final int previewHeight = mPreviewHeight; getLocationInWindow(mCoordinates); - final int previewX = keyDrawX - (previewWidth - keyDrawWidth) / 2 + mCoordinates[0]; + int previewX = keyDrawX - (previewWidth - keyDrawWidth) / 2 + mCoordinates[0]; final int previewY = key.mY - previewHeight + mCoordinates[1] + mPreviewOffset; + if (previewX < 0 && mPreviewLeftBackground != null) { + previewText.setBackgroundDrawable(mPreviewLeftBackground); + previewX = 0; + } else if (previewX + previewWidth > getWidth() && mPreviewRightBackground != null) { + previewText.setBackgroundDrawable(mPreviewRightBackground); + previewX = getWidth() - previewWidth; + } - // Place the key preview. - // TODO: Adjust position of key previews which touch screen edges + // Set the preview background state + previewText.getBackground().setState( + key.mPopupCharacters != null ? LONG_PRESSABLE_STATE_SET : EMPTY_STATE_SET); FrameLayoutCompatUtils.placeViewAt( previewText, previewX, previewY, previewWidth, previewHeight); previewText.setVisibility(VISIBLE); @@ -1147,7 +1158,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { miniKeyboardView.setKeyboard(keyboard); container.measure(MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.AT_MOST), - MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); + MEASURESPEC_UNSPECIFIED); return miniKeyboardView; } -- cgit v1.2.3-83-g751a From 670e1c6b71e6c78855b4452ee75bd1d919021b03 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 28 Jun 2011 19:13:52 +0900 Subject: Add visual debug mode Change-Id: Ife131a398c0753b5b0e6e8969fe7bbc2a3bdab96 --- java/src/com/android/inputmethod/keyboard/KeyboardView.java | 2 +- java/src/com/android/inputmethod/latin/LatinImeLogger.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index da738b24c..58360275d 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -89,7 +89,7 @@ import java.util.WeakHashMap; */ public class KeyboardView extends View implements PointerTracker.UIProxy { private static final String TAG = KeyboardView.class.getSimpleName(); - private static final boolean DEBUG_SHOW_ALIGN = false; + private static final boolean DEBUG_SHOW_ALIGN = LatinImeLogger.sVISUALDEBUG; private static final boolean DEBUG_KEYBOARD_GRID = false; private static final boolean ENABLE_CAPSLOCK_BY_LONGPRESS = true; diff --git a/java/src/com/android/inputmethod/latin/LatinImeLogger.java b/java/src/com/android/inputmethod/latin/LatinImeLogger.java index e460471a5..ae8eb374b 100644 --- a/java/src/com/android/inputmethod/latin/LatinImeLogger.java +++ b/java/src/com/android/inputmethod/latin/LatinImeLogger.java @@ -27,6 +27,7 @@ import java.util.List; public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChangeListener { public static boolean sDBG = false; + public static boolean sVISUALDEBUG = false; @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { -- cgit v1.2.3-83-g751a From b9e56cde8b75b3c773c8433efec15a6d16fbf95d Mon Sep 17 00:00:00 2001 From: satok Date: Tue, 28 Jun 2011 21:33:17 +0900 Subject: Show subtype settings preference for new design Change-Id: I6164ab6ae3d97e2095778a4a6fd9f36c508af7b0 --- java/res/xml/prefs.xml | 8 ++++---- java/src/com/android/inputmethod/latin/Settings.java | 4 ---- 2 files changed, 4 insertions(+), 8 deletions(-) (limited to 'java/src') diff --git a/java/res/xml/prefs.xml b/java/res/xml/prefs.xml index f68ee0168..5252c0486 100644 --- a/java/res/xml/prefs.xml +++ b/java/res/xml/prefs.xml @@ -18,6 +18,10 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:title="@string/english_ime_settings" android:key="english_ime_settings"> + @@ -60,10 +64,6 @@ android:entryValues="@array/voice_input_modes_values" android:entries="@array/voice_input_modes" android:defaultValue="@string/voice_mode_main" /> - Date: Tue, 28 Jun 2011 16:32:39 +0900 Subject: Cleanup key drawing code This change also modifies 9-patch drawables to fix the following issues. In order to draw key background drawable just on the coordinates we want, we have to know where an actual "visible" part is in the drawable. The only clue we can use is "padding" of the drawable. To achieve this, the 9-patch drawable must have its "visible" part marked as "content". Please refer the Bug: 4948171 for more detailed explanation. This change also reverts the following "black" drawables back from Gingerbread because recent change broke these (I70019a91). * drawable-hdpi/sym_bkeyboard_*.png * drawable-hdpi/btn_keyboard_key_*_stone.9.png Bug: 4948171 Change-Id: I6e4d03b3144caa95c793aac97af22df34c5f454f --- .../btn_keyboard_key_dark_normal.9.png | Bin 472 -> 506 bytes .../btn_keyboard_key_dark_normal_off.9.png | Bin 649 -> 657 bytes .../btn_keyboard_key_dark_normal_on.9.png | Bin 944 -> 1048 bytes .../btn_keyboard_key_dark_pressed.9.png | Bin 663 -> 972 bytes .../btn_keyboard_key_dark_pressed_off.9.png | Bin 869 -> 1082 bytes .../btn_keyboard_key_dark_pressed_on.9.png | Bin 1119 -> 1440 bytes .../btn_keyboard_key_fulltrans_normal.9.png | Bin 1370 -> 1785 bytes .../btn_keyboard_key_fulltrans_pressed.9.png | Bin 1315 -> 1701 bytes .../btn_keyboard_key_light_normal.9.png | Bin 448 -> 505 bytes .../btn_keyboard_key_light_popup_selected.9.png | Bin 453 -> 301 bytes .../btn_keyboard_key_light_pressed.9.png | Bin 649 -> 835 bytes .../drawable-hdpi/btn_keyboard_key_normal.9.png | Bin 904 -> 1134 bytes .../btn_keyboard_key_normal_off.9.png | Bin 1076 -> 1243 bytes .../btn_keyboard_key_normal_off_stone.9.png | Bin 2059 -> 2389 bytes .../drawable-hdpi/btn_keyboard_key_normal_on.9.png | Bin 1137 -> 1307 bytes .../btn_keyboard_key_normal_on_stone.9.png | Bin 2029 -> 2409 bytes .../btn_keyboard_key_normal_stone.9.png | Bin 1719 -> 2213 bytes .../drawable-hdpi/btn_keyboard_key_pressed.9.png | Bin 831 -> 1088 bytes .../btn_keyboard_key_pressed_off.9.png | Bin 1041 -> 1233 bytes .../btn_keyboard_key_pressed_on.9.png | Bin 1086 -> 1271 bytes java/res/drawable-hdpi/sym_bkeyboard_123_mic.png | Bin 2583 -> 2576 bytes java/res/drawable-hdpi/sym_bkeyboard_delete.png | Bin 1856 -> 2314 bytes java/res/drawable-hdpi/sym_bkeyboard_mic.png | Bin 1453 -> 1410 bytes java/res/drawable-hdpi/sym_bkeyboard_return.png | Bin 1426 -> 1111 bytes java/res/drawable-hdpi/sym_bkeyboard_search.png | Bin 2045 -> 1612 bytes java/res/drawable-hdpi/sym_bkeyboard_settings.png | Bin 1710 -> 729 bytes java/res/drawable-hdpi/sym_bkeyboard_shift.png | Bin 1820 -> 1474 bytes .../drawable-hdpi/sym_bkeyboard_shift_locked.png | Bin 1467 -> 1115 bytes java/res/drawable-hdpi/sym_bkeyboard_space.png | Bin 790 -> 358 bytes java/res/drawable-hdpi/sym_bkeyboard_tab.png | Bin 1123 -> 1008 bytes .../btn_keyboard_key_dark_normal.9.png | Bin 377 -> 458 bytes .../btn_keyboard_key_dark_normal_off.9.png | Bin 545 -> 588 bytes .../btn_keyboard_key_dark_normal_on.9.png | Bin 806 -> 960 bytes .../btn_keyboard_key_dark_pressed.9.png | Bin 514 -> 849 bytes .../btn_keyboard_key_dark_pressed_off.9.png | Bin 687 -> 957 bytes .../btn_keyboard_key_dark_pressed_on.9.png | Bin 940 -> 1293 bytes .../btn_keyboard_key_fulltrans_normal.9.png | Bin 1068 -> 1553 bytes .../btn_keyboard_key_fulltrans_pressed.9.png | Bin 1021 -> 1461 bytes .../btn_keyboard_key_light_normal.9.png | Bin 355 -> 454 bytes .../btn_keyboard_key_light_popup_selected.9.png | Bin 389 -> 258 bytes .../btn_keyboard_key_light_pressed.9.png | Bin 526 -> 717 bytes .../drawable-mdpi/btn_keyboard_key_normal.9.png | Bin 726 -> 991 bytes .../btn_keyboard_key_normal_off.9.png | Bin 860 -> 1083 bytes .../btn_keyboard_key_normal_off_stone.9.png | Bin 2389 -> 2389 bytes .../drawable-mdpi/btn_keyboard_key_normal_on.9.png | Bin 926 -> 1151 bytes .../btn_keyboard_key_normal_on_stone.9.png | Bin 2408 -> 2409 bytes .../btn_keyboard_key_normal_stone.9.png | Bin 2213 -> 2213 bytes .../drawable-mdpi/btn_keyboard_key_pressed.9.png | Bin 664 -> 956 bytes .../btn_keyboard_key_pressed_off.9.png | Bin 836 -> 1078 bytes .../btn_keyboard_key_pressed_on.9.png | Bin 886 -> 1119 bytes .../btn_keyboard_key_dark_normal.9.png | Bin 546 -> 571 bytes .../btn_keyboard_key_dark_normal_off.9.png | Bin 735 -> 727 bytes .../btn_keyboard_key_dark_normal_on.9.png | Bin 1069 -> 1110 bytes .../btn_keyboard_key_dark_pressed.9.png | Bin 709 -> 1007 bytes .../btn_keyboard_key_dark_pressed_off.9.png | Bin 924 -> 1128 bytes .../btn_keyboard_key_dark_pressed_on.9.png | Bin 1244 -> 1486 bytes .../btn_keyboard_key_fulltrans_pressed.9.png | Bin 1389 -> 1869 bytes .../btn_keyboard_key_light_normal.9.png | Bin 529 -> 548 bytes .../btn_keyboard_key_light_popup_selected.9.png | Bin 535 -> 359 bytes .../btn_keyboard_key_light_pressed.9.png | Bin 722 -> 860 bytes .../drawable-xhdpi/btn_keyboard_key_normal.9.png | Bin 1004 -> 1172 bytes .../btn_keyboard_key_normal_off.9.png | Bin 1176 -> 1278 bytes .../btn_keyboard_key_normal_off_stone.9.png | Bin 2117 -> 2833 bytes .../btn_keyboard_key_normal_on.9.png | Bin 1271 -> 1345 bytes .../btn_keyboard_key_normal_on_stone.9.png | Bin 2131 -> 2867 bytes .../btn_keyboard_key_normal_stone.9.png | Bin 1787 -> 2658 bytes .../drawable-xhdpi/btn_keyboard_key_pressed.9.png | Bin 921 -> 1131 bytes .../btn_keyboard_key_pressed_off.9.png | Bin 1131 -> 1273 bytes .../btn_keyboard_key_pressed_on.9.png | Bin 1197 -> 1312 bytes java/res/drawable/btn_keyboard_key_fulltrans.xml | 26 -- java/res/drawable/btn_keyboard_key_popup.xml | 2 +- java/res/drawable/btn_keyboard_key_popup_ics.xml | 2 +- java/res/values-land/dimens.xml | 31 +- java/res/values-sw600dp-land/dimens.xml | 22 +- java/res/values-sw600dp/dimens.xml | 27 +- java/res/values-sw768dp-land/dimens.xml | 32 +- java/res/values-sw768dp/dimens.xml | 38 +- java/res/values/attrs.xml | 7 +- java/res/values/dimens.xml | 48 ++- java/res/values/styles.xml | 21 +- java/res/values/themes-gingerbread.xml | 2 +- java/src/com/android/inputmethod/keyboard/Key.java | 9 +- .../com/android/inputmethod/keyboard/Keyboard.java | 15 +- .../android/inputmethod/keyboard/KeyboardId.java | 11 + .../android/inputmethod/keyboard/KeyboardView.java | 467 ++++++++++++--------- .../inputmethod/keyboard/LatinKeyboard.java | 10 + .../inputmethod/keyboard/LatinKeyboardView.java | 13 - .../android/inputmethod/keyboard/MiniKeyboard.java | 30 +- .../inputmethod/keyboard/PointerTracker.java | 4 - .../keyboard/internal/KeyboardParser.java | 17 +- 90 files changed, 477 insertions(+), 357 deletions(-) delete mode 100644 java/res/drawable/btn_keyboard_key_fulltrans.xml (limited to 'java/src') diff --git a/java/res/drawable-hdpi/btn_keyboard_key_dark_normal.9.png b/java/res/drawable-hdpi/btn_keyboard_key_dark_normal.9.png index 50cc49fdb..bc130cab6 100644 Binary files a/java/res/drawable-hdpi/btn_keyboard_key_dark_normal.9.png and b/java/res/drawable-hdpi/btn_keyboard_key_dark_normal.9.png differ diff --git a/java/res/drawable-hdpi/btn_keyboard_key_dark_normal_off.9.png b/java/res/drawable-hdpi/btn_keyboard_key_dark_normal_off.9.png index dabf77ec6..43099899c 100644 Binary files a/java/res/drawable-hdpi/btn_keyboard_key_dark_normal_off.9.png and b/java/res/drawable-hdpi/btn_keyboard_key_dark_normal_off.9.png differ diff --git a/java/res/drawable-hdpi/btn_keyboard_key_dark_normal_on.9.png b/java/res/drawable-hdpi/btn_keyboard_key_dark_normal_on.9.png index 6e7d74c88..2d1acf22f 100644 Binary files a/java/res/drawable-hdpi/btn_keyboard_key_dark_normal_on.9.png and b/java/res/drawable-hdpi/btn_keyboard_key_dark_normal_on.9.png differ diff --git a/java/res/drawable-hdpi/btn_keyboard_key_dark_pressed.9.png b/java/res/drawable-hdpi/btn_keyboard_key_dark_pressed.9.png index ddb77c224..af5ea6bd2 100644 Binary files a/java/res/drawable-hdpi/btn_keyboard_key_dark_pressed.9.png and b/java/res/drawable-hdpi/btn_keyboard_key_dark_pressed.9.png differ diff --git a/java/res/drawable-hdpi/btn_keyboard_key_dark_pressed_off.9.png b/java/res/drawable-hdpi/btn_keyboard_key_dark_pressed_off.9.png index 1e9227e1c..3e25a9817 100644 Binary files a/java/res/drawable-hdpi/btn_keyboard_key_dark_pressed_off.9.png and b/java/res/drawable-hdpi/btn_keyboard_key_dark_pressed_off.9.png differ diff --git a/java/res/drawable-hdpi/btn_keyboard_key_dark_pressed_on.9.png b/java/res/drawable-hdpi/btn_keyboard_key_dark_pressed_on.9.png index 7207b2ece..fc7ba2aeb 100644 Binary files a/java/res/drawable-hdpi/btn_keyboard_key_dark_pressed_on.9.png and b/java/res/drawable-hdpi/btn_keyboard_key_dark_pressed_on.9.png differ diff --git a/java/res/drawable-hdpi/btn_keyboard_key_fulltrans_normal.9.png b/java/res/drawable-hdpi/btn_keyboard_key_fulltrans_normal.9.png index a524168c9..116329016 100644 Binary files a/java/res/drawable-hdpi/btn_keyboard_key_fulltrans_normal.9.png and b/java/res/drawable-hdpi/btn_keyboard_key_fulltrans_normal.9.png differ diff --git a/java/res/drawable-hdpi/btn_keyboard_key_fulltrans_pressed.9.png b/java/res/drawable-hdpi/btn_keyboard_key_fulltrans_pressed.9.png index 4395e978a..207c90d6c 100644 Binary files a/java/res/drawable-hdpi/btn_keyboard_key_fulltrans_pressed.9.png and b/java/res/drawable-hdpi/btn_keyboard_key_fulltrans_pressed.9.png differ diff --git a/java/res/drawable-hdpi/btn_keyboard_key_light_normal.9.png b/java/res/drawable-hdpi/btn_keyboard_key_light_normal.9.png index 9d85c7b74..005c4e498 100644 Binary files a/java/res/drawable-hdpi/btn_keyboard_key_light_normal.9.png and b/java/res/drawable-hdpi/btn_keyboard_key_light_normal.9.png differ diff --git a/java/res/drawable-hdpi/btn_keyboard_key_light_popup_selected.9.png b/java/res/drawable-hdpi/btn_keyboard_key_light_popup_selected.9.png index 77e17dbae..9a07acd91 100644 Binary files a/java/res/drawable-hdpi/btn_keyboard_key_light_popup_selected.9.png and b/java/res/drawable-hdpi/btn_keyboard_key_light_popup_selected.9.png differ diff --git a/java/res/drawable-hdpi/btn_keyboard_key_light_pressed.9.png b/java/res/drawable-hdpi/btn_keyboard_key_light_pressed.9.png index a409639e7..be420a7af 100644 Binary files a/java/res/drawable-hdpi/btn_keyboard_key_light_pressed.9.png and b/java/res/drawable-hdpi/btn_keyboard_key_light_pressed.9.png differ diff --git a/java/res/drawable-hdpi/btn_keyboard_key_normal.9.png b/java/res/drawable-hdpi/btn_keyboard_key_normal.9.png index 6ec7e6592..3e25180f0 100644 Binary files a/java/res/drawable-hdpi/btn_keyboard_key_normal.9.png and b/java/res/drawable-hdpi/btn_keyboard_key_normal.9.png differ diff --git a/java/res/drawable-hdpi/btn_keyboard_key_normal_off.9.png b/java/res/drawable-hdpi/btn_keyboard_key_normal_off.9.png index 995780cbf..bad360f77 100644 Binary files a/java/res/drawable-hdpi/btn_keyboard_key_normal_off.9.png and b/java/res/drawable-hdpi/btn_keyboard_key_normal_off.9.png differ diff --git a/java/res/drawable-hdpi/btn_keyboard_key_normal_off_stone.9.png b/java/res/drawable-hdpi/btn_keyboard_key_normal_off_stone.9.png index 1388b6694..cdd6c8b79 100644 Binary files a/java/res/drawable-hdpi/btn_keyboard_key_normal_off_stone.9.png and b/java/res/drawable-hdpi/btn_keyboard_key_normal_off_stone.9.png differ diff --git a/java/res/drawable-hdpi/btn_keyboard_key_normal_on.9.png b/java/res/drawable-hdpi/btn_keyboard_key_normal_on.9.png index 7215782eb..49f519860 100644 Binary files a/java/res/drawable-hdpi/btn_keyboard_key_normal_on.9.png and b/java/res/drawable-hdpi/btn_keyboard_key_normal_on.9.png differ diff --git a/java/res/drawable-hdpi/btn_keyboard_key_normal_on_stone.9.png b/java/res/drawable-hdpi/btn_keyboard_key_normal_on_stone.9.png index 5a94cb6ac..d8421746a 100644 Binary files a/java/res/drawable-hdpi/btn_keyboard_key_normal_on_stone.9.png and b/java/res/drawable-hdpi/btn_keyboard_key_normal_on_stone.9.png differ diff --git a/java/res/drawable-hdpi/btn_keyboard_key_normal_stone.9.png b/java/res/drawable-hdpi/btn_keyboard_key_normal_stone.9.png index c6373a8af..44c2ad637 100644 Binary files a/java/res/drawable-hdpi/btn_keyboard_key_normal_stone.9.png and b/java/res/drawable-hdpi/btn_keyboard_key_normal_stone.9.png differ diff --git a/java/res/drawable-hdpi/btn_keyboard_key_pressed.9.png b/java/res/drawable-hdpi/btn_keyboard_key_pressed.9.png index 0bd49a0e7..e784eddf8 100644 Binary files a/java/res/drawable-hdpi/btn_keyboard_key_pressed.9.png and b/java/res/drawable-hdpi/btn_keyboard_key_pressed.9.png differ diff --git a/java/res/drawable-hdpi/btn_keyboard_key_pressed_off.9.png b/java/res/drawable-hdpi/btn_keyboard_key_pressed_off.9.png index 634419f1b..a4731cf1a 100644 Binary files a/java/res/drawable-hdpi/btn_keyboard_key_pressed_off.9.png and b/java/res/drawable-hdpi/btn_keyboard_key_pressed_off.9.png differ diff --git a/java/res/drawable-hdpi/btn_keyboard_key_pressed_on.9.png b/java/res/drawable-hdpi/btn_keyboard_key_pressed_on.9.png index 8474f9f42..03e163c9c 100644 Binary files a/java/res/drawable-hdpi/btn_keyboard_key_pressed_on.9.png and b/java/res/drawable-hdpi/btn_keyboard_key_pressed_on.9.png differ diff --git a/java/res/drawable-hdpi/sym_bkeyboard_123_mic.png b/java/res/drawable-hdpi/sym_bkeyboard_123_mic.png index af6082d04..3e4eff698 100644 Binary files a/java/res/drawable-hdpi/sym_bkeyboard_123_mic.png and b/java/res/drawable-hdpi/sym_bkeyboard_123_mic.png differ diff --git a/java/res/drawable-hdpi/sym_bkeyboard_delete.png b/java/res/drawable-hdpi/sym_bkeyboard_delete.png index 999a182f4..1d24cc85c 100644 Binary files a/java/res/drawable-hdpi/sym_bkeyboard_delete.png and b/java/res/drawable-hdpi/sym_bkeyboard_delete.png differ diff --git a/java/res/drawable-hdpi/sym_bkeyboard_mic.png b/java/res/drawable-hdpi/sym_bkeyboard_mic.png index 5c73600d9..512f46080 100644 Binary files a/java/res/drawable-hdpi/sym_bkeyboard_mic.png and b/java/res/drawable-hdpi/sym_bkeyboard_mic.png differ diff --git a/java/res/drawable-hdpi/sym_bkeyboard_return.png b/java/res/drawable-hdpi/sym_bkeyboard_return.png index 91bb397ff..426e1599e 100644 Binary files a/java/res/drawable-hdpi/sym_bkeyboard_return.png and b/java/res/drawable-hdpi/sym_bkeyboard_return.png differ diff --git a/java/res/drawable-hdpi/sym_bkeyboard_search.png b/java/res/drawable-hdpi/sym_bkeyboard_search.png index 0ac08145b..1b6f884fa 100644 Binary files a/java/res/drawable-hdpi/sym_bkeyboard_search.png and b/java/res/drawable-hdpi/sym_bkeyboard_search.png differ diff --git a/java/res/drawable-hdpi/sym_bkeyboard_settings.png b/java/res/drawable-hdpi/sym_bkeyboard_settings.png index 5b6217aa0..08ba18f28 100644 Binary files a/java/res/drawable-hdpi/sym_bkeyboard_settings.png and b/java/res/drawable-hdpi/sym_bkeyboard_settings.png differ diff --git a/java/res/drawable-hdpi/sym_bkeyboard_shift.png b/java/res/drawable-hdpi/sym_bkeyboard_shift.png index 5ef01b8bd..5a22dd309 100644 Binary files a/java/res/drawable-hdpi/sym_bkeyboard_shift.png and b/java/res/drawable-hdpi/sym_bkeyboard_shift.png differ diff --git a/java/res/drawable-hdpi/sym_bkeyboard_shift_locked.png b/java/res/drawable-hdpi/sym_bkeyboard_shift_locked.png index 7d36dcb34..566449126 100644 Binary files a/java/res/drawable-hdpi/sym_bkeyboard_shift_locked.png and b/java/res/drawable-hdpi/sym_bkeyboard_shift_locked.png differ diff --git a/java/res/drawable-hdpi/sym_bkeyboard_space.png b/java/res/drawable-hdpi/sym_bkeyboard_space.png index 77518cc93..cd0ebe2f4 100644 Binary files a/java/res/drawable-hdpi/sym_bkeyboard_space.png and b/java/res/drawable-hdpi/sym_bkeyboard_space.png differ diff --git a/java/res/drawable-hdpi/sym_bkeyboard_tab.png b/java/res/drawable-hdpi/sym_bkeyboard_tab.png index 5db4cef2b..3466e1271 100644 Binary files a/java/res/drawable-hdpi/sym_bkeyboard_tab.png and b/java/res/drawable-hdpi/sym_bkeyboard_tab.png differ diff --git a/java/res/drawable-mdpi/btn_keyboard_key_dark_normal.9.png b/java/res/drawable-mdpi/btn_keyboard_key_dark_normal.9.png index 4e337fa08..49329f094 100644 Binary files a/java/res/drawable-mdpi/btn_keyboard_key_dark_normal.9.png and b/java/res/drawable-mdpi/btn_keyboard_key_dark_normal.9.png differ diff --git a/java/res/drawable-mdpi/btn_keyboard_key_dark_normal_off.9.png b/java/res/drawable-mdpi/btn_keyboard_key_dark_normal_off.9.png index fe18497d8..46e9db092 100644 Binary files a/java/res/drawable-mdpi/btn_keyboard_key_dark_normal_off.9.png and b/java/res/drawable-mdpi/btn_keyboard_key_dark_normal_off.9.png differ diff --git a/java/res/drawable-mdpi/btn_keyboard_key_dark_normal_on.9.png b/java/res/drawable-mdpi/btn_keyboard_key_dark_normal_on.9.png index 00aab3d5a..ee60e4864 100644 Binary files a/java/res/drawable-mdpi/btn_keyboard_key_dark_normal_on.9.png and b/java/res/drawable-mdpi/btn_keyboard_key_dark_normal_on.9.png differ diff --git a/java/res/drawable-mdpi/btn_keyboard_key_dark_pressed.9.png b/java/res/drawable-mdpi/btn_keyboard_key_dark_pressed.9.png index ac0bfd3c1..c6876f76e 100644 Binary files a/java/res/drawable-mdpi/btn_keyboard_key_dark_pressed.9.png and b/java/res/drawable-mdpi/btn_keyboard_key_dark_pressed.9.png differ diff --git a/java/res/drawable-mdpi/btn_keyboard_key_dark_pressed_off.9.png b/java/res/drawable-mdpi/btn_keyboard_key_dark_pressed_off.9.png index ea2f35789..1f8f318d1 100644 Binary files a/java/res/drawable-mdpi/btn_keyboard_key_dark_pressed_off.9.png and b/java/res/drawable-mdpi/btn_keyboard_key_dark_pressed_off.9.png differ diff --git a/java/res/drawable-mdpi/btn_keyboard_key_dark_pressed_on.9.png b/java/res/drawable-mdpi/btn_keyboard_key_dark_pressed_on.9.png index 6195ac0d4..2bb7b64f4 100644 Binary files a/java/res/drawable-mdpi/btn_keyboard_key_dark_pressed_on.9.png and b/java/res/drawable-mdpi/btn_keyboard_key_dark_pressed_on.9.png differ diff --git a/java/res/drawable-mdpi/btn_keyboard_key_fulltrans_normal.9.png b/java/res/drawable-mdpi/btn_keyboard_key_fulltrans_normal.9.png index 20f3d5087..4b1a78cfb 100644 Binary files a/java/res/drawable-mdpi/btn_keyboard_key_fulltrans_normal.9.png and b/java/res/drawable-mdpi/btn_keyboard_key_fulltrans_normal.9.png differ diff --git a/java/res/drawable-mdpi/btn_keyboard_key_fulltrans_pressed.9.png b/java/res/drawable-mdpi/btn_keyboard_key_fulltrans_pressed.9.png index 1ed3065c5..697683e29 100644 Binary files a/java/res/drawable-mdpi/btn_keyboard_key_fulltrans_pressed.9.png and b/java/res/drawable-mdpi/btn_keyboard_key_fulltrans_pressed.9.png differ diff --git a/java/res/drawable-mdpi/btn_keyboard_key_light_normal.9.png b/java/res/drawable-mdpi/btn_keyboard_key_light_normal.9.png index 50cd06ae3..f5ce40cf6 100644 Binary files a/java/res/drawable-mdpi/btn_keyboard_key_light_normal.9.png and b/java/res/drawable-mdpi/btn_keyboard_key_light_normal.9.png differ diff --git a/java/res/drawable-mdpi/btn_keyboard_key_light_popup_selected.9.png b/java/res/drawable-mdpi/btn_keyboard_key_light_popup_selected.9.png index 125ff1335..ca73b9249 100644 Binary files a/java/res/drawable-mdpi/btn_keyboard_key_light_popup_selected.9.png and b/java/res/drawable-mdpi/btn_keyboard_key_light_popup_selected.9.png differ diff --git a/java/res/drawable-mdpi/btn_keyboard_key_light_pressed.9.png b/java/res/drawable-mdpi/btn_keyboard_key_light_pressed.9.png index 7ce52f0f5..73f2006d4 100644 Binary files a/java/res/drawable-mdpi/btn_keyboard_key_light_pressed.9.png and b/java/res/drawable-mdpi/btn_keyboard_key_light_pressed.9.png differ diff --git a/java/res/drawable-mdpi/btn_keyboard_key_normal.9.png b/java/res/drawable-mdpi/btn_keyboard_key_normal.9.png index 7ba18dd25..12bc97928 100644 Binary files a/java/res/drawable-mdpi/btn_keyboard_key_normal.9.png and b/java/res/drawable-mdpi/btn_keyboard_key_normal.9.png differ diff --git a/java/res/drawable-mdpi/btn_keyboard_key_normal_off.9.png b/java/res/drawable-mdpi/btn_keyboard_key_normal_off.9.png index bda9b8394..44bd414a1 100644 Binary files a/java/res/drawable-mdpi/btn_keyboard_key_normal_off.9.png and b/java/res/drawable-mdpi/btn_keyboard_key_normal_off.9.png differ diff --git a/java/res/drawable-mdpi/btn_keyboard_key_normal_off_stone.9.png b/java/res/drawable-mdpi/btn_keyboard_key_normal_off_stone.9.png index fad0ec458..cdd6c8b79 100644 Binary files a/java/res/drawable-mdpi/btn_keyboard_key_normal_off_stone.9.png and b/java/res/drawable-mdpi/btn_keyboard_key_normal_off_stone.9.png differ diff --git a/java/res/drawable-mdpi/btn_keyboard_key_normal_on.9.png b/java/res/drawable-mdpi/btn_keyboard_key_normal_on.9.png index 0c16ed509..43fdf5b88 100644 Binary files a/java/res/drawable-mdpi/btn_keyboard_key_normal_on.9.png and b/java/res/drawable-mdpi/btn_keyboard_key_normal_on.9.png differ diff --git a/java/res/drawable-mdpi/btn_keyboard_key_normal_on_stone.9.png b/java/res/drawable-mdpi/btn_keyboard_key_normal_on_stone.9.png index 215f8157c..d8421746a 100644 Binary files a/java/res/drawable-mdpi/btn_keyboard_key_normal_on_stone.9.png and b/java/res/drawable-mdpi/btn_keyboard_key_normal_on_stone.9.png differ diff --git a/java/res/drawable-mdpi/btn_keyboard_key_normal_stone.9.png b/java/res/drawable-mdpi/btn_keyboard_key_normal_stone.9.png index 88acdd748..44c2ad637 100644 Binary files a/java/res/drawable-mdpi/btn_keyboard_key_normal_stone.9.png and b/java/res/drawable-mdpi/btn_keyboard_key_normal_stone.9.png differ diff --git a/java/res/drawable-mdpi/btn_keyboard_key_pressed.9.png b/java/res/drawable-mdpi/btn_keyboard_key_pressed.9.png index 39b9314a1..1c1f3d711 100644 Binary files a/java/res/drawable-mdpi/btn_keyboard_key_pressed.9.png and b/java/res/drawable-mdpi/btn_keyboard_key_pressed.9.png differ diff --git a/java/res/drawable-mdpi/btn_keyboard_key_pressed_off.9.png b/java/res/drawable-mdpi/btn_keyboard_key_pressed_off.9.png index bdcf06e1b..dacb675a9 100644 Binary files a/java/res/drawable-mdpi/btn_keyboard_key_pressed_off.9.png and b/java/res/drawable-mdpi/btn_keyboard_key_pressed_off.9.png differ diff --git a/java/res/drawable-mdpi/btn_keyboard_key_pressed_on.9.png b/java/res/drawable-mdpi/btn_keyboard_key_pressed_on.9.png index 79621a9e6..3daa69f31 100644 Binary files a/java/res/drawable-mdpi/btn_keyboard_key_pressed_on.9.png and b/java/res/drawable-mdpi/btn_keyboard_key_pressed_on.9.png differ diff --git a/java/res/drawable-xhdpi/btn_keyboard_key_dark_normal.9.png b/java/res/drawable-xhdpi/btn_keyboard_key_dark_normal.9.png index eae1e3a54..d0090a305 100644 Binary files a/java/res/drawable-xhdpi/btn_keyboard_key_dark_normal.9.png and b/java/res/drawable-xhdpi/btn_keyboard_key_dark_normal.9.png differ diff --git a/java/res/drawable-xhdpi/btn_keyboard_key_dark_normal_off.9.png b/java/res/drawable-xhdpi/btn_keyboard_key_dark_normal_off.9.png index 13bad8f1a..2baf7d90c 100644 Binary files a/java/res/drawable-xhdpi/btn_keyboard_key_dark_normal_off.9.png and b/java/res/drawable-xhdpi/btn_keyboard_key_dark_normal_off.9.png differ diff --git a/java/res/drawable-xhdpi/btn_keyboard_key_dark_normal_on.9.png b/java/res/drawable-xhdpi/btn_keyboard_key_dark_normal_on.9.png index 853b8bc6e..6812f9e8f 100644 Binary files a/java/res/drawable-xhdpi/btn_keyboard_key_dark_normal_on.9.png and b/java/res/drawable-xhdpi/btn_keyboard_key_dark_normal_on.9.png differ diff --git a/java/res/drawable-xhdpi/btn_keyboard_key_dark_pressed.9.png b/java/res/drawable-xhdpi/btn_keyboard_key_dark_pressed.9.png index 1edfd64fe..a932249a8 100644 Binary files a/java/res/drawable-xhdpi/btn_keyboard_key_dark_pressed.9.png and b/java/res/drawable-xhdpi/btn_keyboard_key_dark_pressed.9.png differ diff --git a/java/res/drawable-xhdpi/btn_keyboard_key_dark_pressed_off.9.png b/java/res/drawable-xhdpi/btn_keyboard_key_dark_pressed_off.9.png index dfdbfadd3..16416f000 100644 Binary files a/java/res/drawable-xhdpi/btn_keyboard_key_dark_pressed_off.9.png and b/java/res/drawable-xhdpi/btn_keyboard_key_dark_pressed_off.9.png differ diff --git a/java/res/drawable-xhdpi/btn_keyboard_key_dark_pressed_on.9.png b/java/res/drawable-xhdpi/btn_keyboard_key_dark_pressed_on.9.png index 0e2733e17..3ca93fdb3 100644 Binary files a/java/res/drawable-xhdpi/btn_keyboard_key_dark_pressed_on.9.png and b/java/res/drawable-xhdpi/btn_keyboard_key_dark_pressed_on.9.png differ diff --git a/java/res/drawable-xhdpi/btn_keyboard_key_fulltrans_pressed.9.png b/java/res/drawable-xhdpi/btn_keyboard_key_fulltrans_pressed.9.png index 00c447604..df3b5ba2d 100644 Binary files a/java/res/drawable-xhdpi/btn_keyboard_key_fulltrans_pressed.9.png and b/java/res/drawable-xhdpi/btn_keyboard_key_fulltrans_pressed.9.png differ diff --git a/java/res/drawable-xhdpi/btn_keyboard_key_light_normal.9.png b/java/res/drawable-xhdpi/btn_keyboard_key_light_normal.9.png index ea13a7fdf..aa4f44fdd 100644 Binary files a/java/res/drawable-xhdpi/btn_keyboard_key_light_normal.9.png and b/java/res/drawable-xhdpi/btn_keyboard_key_light_normal.9.png differ diff --git a/java/res/drawable-xhdpi/btn_keyboard_key_light_popup_selected.9.png b/java/res/drawable-xhdpi/btn_keyboard_key_light_popup_selected.9.png index 057c5716e..4539255c2 100644 Binary files a/java/res/drawable-xhdpi/btn_keyboard_key_light_popup_selected.9.png and b/java/res/drawable-xhdpi/btn_keyboard_key_light_popup_selected.9.png differ diff --git a/java/res/drawable-xhdpi/btn_keyboard_key_light_pressed.9.png b/java/res/drawable-xhdpi/btn_keyboard_key_light_pressed.9.png index 5d8e46de0..568392444 100644 Binary files a/java/res/drawable-xhdpi/btn_keyboard_key_light_pressed.9.png and b/java/res/drawable-xhdpi/btn_keyboard_key_light_pressed.9.png differ diff --git a/java/res/drawable-xhdpi/btn_keyboard_key_normal.9.png b/java/res/drawable-xhdpi/btn_keyboard_key_normal.9.png index f53b40419..026005d6f 100644 Binary files a/java/res/drawable-xhdpi/btn_keyboard_key_normal.9.png and b/java/res/drawable-xhdpi/btn_keyboard_key_normal.9.png differ diff --git a/java/res/drawable-xhdpi/btn_keyboard_key_normal_off.9.png b/java/res/drawable-xhdpi/btn_keyboard_key_normal_off.9.png index 3c6ae6be8..38c5f244b 100644 Binary files a/java/res/drawable-xhdpi/btn_keyboard_key_normal_off.9.png and b/java/res/drawable-xhdpi/btn_keyboard_key_normal_off.9.png differ diff --git a/java/res/drawable-xhdpi/btn_keyboard_key_normal_off_stone.9.png b/java/res/drawable-xhdpi/btn_keyboard_key_normal_off_stone.9.png index eebe7d391..dec219304 100644 Binary files a/java/res/drawable-xhdpi/btn_keyboard_key_normal_off_stone.9.png and b/java/res/drawable-xhdpi/btn_keyboard_key_normal_off_stone.9.png differ diff --git a/java/res/drawable-xhdpi/btn_keyboard_key_normal_on.9.png b/java/res/drawable-xhdpi/btn_keyboard_key_normal_on.9.png index 655bfb2c6..f1223e50e 100644 Binary files a/java/res/drawable-xhdpi/btn_keyboard_key_normal_on.9.png and b/java/res/drawable-xhdpi/btn_keyboard_key_normal_on.9.png differ diff --git a/java/res/drawable-xhdpi/btn_keyboard_key_normal_on_stone.9.png b/java/res/drawable-xhdpi/btn_keyboard_key_normal_on_stone.9.png index 336248aae..3c77b3ccd 100644 Binary files a/java/res/drawable-xhdpi/btn_keyboard_key_normal_on_stone.9.png and b/java/res/drawable-xhdpi/btn_keyboard_key_normal_on_stone.9.png differ diff --git a/java/res/drawable-xhdpi/btn_keyboard_key_normal_stone.9.png b/java/res/drawable-xhdpi/btn_keyboard_key_normal_stone.9.png index bb1c72bb3..099472889 100644 Binary files a/java/res/drawable-xhdpi/btn_keyboard_key_normal_stone.9.png and b/java/res/drawable-xhdpi/btn_keyboard_key_normal_stone.9.png differ diff --git a/java/res/drawable-xhdpi/btn_keyboard_key_pressed.9.png b/java/res/drawable-xhdpi/btn_keyboard_key_pressed.9.png index f73911674..ec35db54d 100644 Binary files a/java/res/drawable-xhdpi/btn_keyboard_key_pressed.9.png and b/java/res/drawable-xhdpi/btn_keyboard_key_pressed.9.png differ diff --git a/java/res/drawable-xhdpi/btn_keyboard_key_pressed_off.9.png b/java/res/drawable-xhdpi/btn_keyboard_key_pressed_off.9.png index 34a948f4e..bd30464d6 100644 Binary files a/java/res/drawable-xhdpi/btn_keyboard_key_pressed_off.9.png and b/java/res/drawable-xhdpi/btn_keyboard_key_pressed_off.9.png differ diff --git a/java/res/drawable-xhdpi/btn_keyboard_key_pressed_on.9.png b/java/res/drawable-xhdpi/btn_keyboard_key_pressed_on.9.png index 520f12d3f..a3ff5d1bb 100644 Binary files a/java/res/drawable-xhdpi/btn_keyboard_key_pressed_on.9.png and b/java/res/drawable-xhdpi/btn_keyboard_key_pressed_on.9.png differ diff --git a/java/res/drawable/btn_keyboard_key_fulltrans.xml b/java/res/drawable/btn_keyboard_key_fulltrans.xml deleted file mode 100644 index bad2a931d..000000000 --- a/java/res/drawable/btn_keyboard_key_fulltrans.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - diff --git a/java/res/drawable/btn_keyboard_key_popup.xml b/java/res/drawable/btn_keyboard_key_popup.xml index 860cfd5d5..9e3670d22 100644 --- a/java/res/drawable/btn_keyboard_key_popup.xml +++ b/java/res/drawable/btn_keyboard_key_popup.xml @@ -17,5 +17,5 @@ - + diff --git a/java/res/drawable/btn_keyboard_key_popup_ics.xml b/java/res/drawable/btn_keyboard_key_popup_ics.xml index 8f797ac3c..b99679ba1 100644 --- a/java/res/drawable/btn_keyboard_key_popup_ics.xml +++ b/java/res/drawable/btn_keyboard_key_popup_ics.xml @@ -17,5 +17,5 @@ - + diff --git a/java/res/values-land/dimens.xml b/java/res/values-land/dimens.xml index d6e096278..d5ca25063 100644 --- a/java/res/values-land/dimens.xml +++ b/java/res/values-land/dimens.xml @@ -24,24 +24,33 @@ 45%p - 0.020in 0.280in - 0.00in + 0.0in + + 0.02in 0.00in - 0.04in - 0.01in + 1.21mm + 0.35mm + + 1.40mm + 1.00mm + + 1.66mm + 0.86mm + 0.03in 0.00in - 0.0in + 1.79mm + 0.88mm - 8dip + 8dip - 55% - 68% - 35% - 28% - 45% + 65% + 74% + 40% + 30% + 52% 40% 90% 0.08in diff --git a/java/res/values-sw600dp-land/dimens.xml b/java/res/values-sw600dp-land/dimens.xml index 5d1fbc748..5016f4247 100644 --- a/java/res/values-sw600dp-land/dimens.xml +++ b/java/res/values-sw600dp-land/dimens.xml @@ -22,20 +22,28 @@ 45.0mm 45%p - - - 1.3mm - 1.3mm + + 0dp 1.1mm 0.0mm - 1.3mm - 1.3mm + 2.21mm + 1.97mm + + 1.96mm + 2.31mm + + 2.34mm + 2.22mm + + 1.66mm + 1.66mm 1.1mm 0.0mm + 13.0mm - 18dip + 18dip 45% 45% diff --git a/java/res/values-sw600dp/dimens.xml b/java/res/values-sw600dp/dimens.xml index 675f40c2e..1a82b0c6c 100644 --- a/java/res/values-sw600dp/dimens.xml +++ b/java/res/values-sw600dp/dimens.xml @@ -23,18 +23,27 @@ 48.0mm 50%p -35.0%p - - - 1.0mm - 1.0mm + 10.0mm + + 0.0mm 1.1mm 0.0mm - 1.0mm - 1.0mm + 1.80mm + 1.67mm + + 1.80mm + 1.44mm + + 2.22mm + 1.90mm + + 1.37mm + 1.53mm 1.1mm 0.0mm - 12dip + + 6dip 15.6mm @@ -42,7 +51,9 @@ -13.0mm - 6dip + 6dip + 3dp + 3dp 37% 37% diff --git a/java/res/values-sw768dp-land/dimens.xml b/java/res/values-sw768dp-land/dimens.xml index 2201ce8a3..8cbd37e17 100644 --- a/java/res/values-sw768dp-land/dimens.xml +++ b/java/res/values-sw768dp-land/dimens.xml @@ -22,27 +22,35 @@ 58.0mm 45%p - - - 1.6mm - 1.6mm + + 0.0mm 1.1mm 0.0mm - 1.6mm - 1.6mm + + 2.65mm + 2.34mm + + 1.96mm + 2.31mm + + 2.80mm + 2.60mm + + 2.25mm + 2.22mm 1.1mm 0.0mm + 13.0mm - 0.0mm - 18dip + 18dip - 38% - 38% - 26% + 43% + 42% + 28% 23% - 26% + 28% 24% 17.0mm diff --git a/java/res/values-sw768dp/dimens.xml b/java/res/values-sw768dp/dimens.xml index 2e41db52a..81a68e233 100644 --- a/java/res/values-sw768dp/dimens.xml +++ b/java/res/values-sw768dp/dimens.xml @@ -23,19 +23,27 @@ 48.0mm 50%p -35.0%p - - - 1.1mm - 1.1mm + + 0.0mm 1.1mm 0.0mm - 1.1mm - 1.1mm + + 2.05mm + 2.11mm + + 1.80mm + 1.44mm + + 2.25mm + 1.96mm + + 1.75mm + 1.79mm 1.1mm 0.0mm + 10.0mm - 0.0mm - 40dip + 12dip @@ -44,14 +52,16 @@ -13.0mm - 6dip + 6dip + 3dp + 3dp - 38% - 38% - 26% + 40% + 42% + 28% 23% - 26% - 25% + 28% + 26% 50% 15.0mm 0.1in diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index 4470d7b4e..c5897c853 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -51,6 +51,12 @@ + + + + + + @@ -199,7 +205,6 @@ - diff --git a/java/res/values/dimens.xml b/java/res/values/dimens.xml index c1ef86930..36074b3b8 100644 --- a/java/res/values/dimens.xml +++ b/java/res/values/dimens.xml @@ -19,26 +19,33 @@ --> - + 1.285in 50%p -61.8%p - - - 0.035in - 0.000in + 0.330in - 0.00in - 0.06in - 0.0in - 16dip + + 16dip 8dip - 0.06in - 0.01in + 0dp + 0.02in + 0.06in + 2.04mm + 0.70mm + + 2.45mm + 0.90mm + + 2.12mm + 1.02mm + 0.03in 0.06in - 38dip + 6dp + 2.37mm + 0.90mm @@ -49,19 +56,20 @@ to user's finger. --> -0.05in - - 4dip - - 45% - 55% - 29% - 23% - 36% + 55% + 65% + 34% + 25% + 44% 35% 82% 80sp 0.1in + 4dip + 2dp + 2dp + 80sp 0.05in diff --git a/java/res/values/styles.xml b/java/res/values/styles.xml index 08301be5c..29b9d589c 100644 --- a/java/res/values/styles.xml +++ b/java/res/values/styles.xml @@ -49,6 +49,9 @@ #E0E0E4E5 #66E0E4E5 #CCE0E4E5 + @dimen/key_label_horizontal_padding + @dimen/key_hint_letter_padding + @dimen/key_uppercase_letter_padding @layout/key_preview @drawable/keyboard_key_feedback @null @@ -72,8 +75,8 @@ + diff --git a/java/res/values/styles.xml b/java/res/values/styles.xml index c0cc8fbda..f731d0133 100644 --- a/java/res/values/styles.xml +++ b/java/res/values/styles.xml @@ -92,7 +92,6 @@ #FFFFFFFF #FFFCAE00 #FFFCAE00 - #20FFFFFF @integer/candidate_count_in_strip @@ -191,9 +190,8 @@ diff --git a/java/src/com/android/inputmethod/latin/CandidateView.java b/java/src/com/android/inputmethod/latin/CandidateView.java index f499bc0bb..d46b4b5b5 100644 --- a/java/src/com/android/inputmethod/latin/CandidateView.java +++ b/java/src/com/android/inputmethod/latin/CandidateView.java @@ -272,9 +272,10 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo private static final int AUTO_CORRECT_BOLD = 0x01; private static final int AUTO_CORRECT_UNDERLINE = 0x02; private static final int AUTO_CORRECT_INVERT = 0x04; + private static final int VALID_TYPED_WORD_BOLD = 0x08; private final TextPaint mPaint; - private final int mAutoCorrectHighlight; + private final int mSuggestionStripOption; private final ArrayList mTexts = new ArrayList(); @@ -285,7 +286,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo super(words, dividers, infos); final TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.CandidateView, defStyle, R.style.CandidateViewStyle); - mAutoCorrectHighlight = a.getInt(R.styleable.CandidateView_autoCorrectHighlight, 0); + mSuggestionStripOption = a.getInt(R.styleable.CandidateView_suggestionStripOption, 0); mColorTypedWord = a.getColor(R.styleable.CandidateView_colorTypedWord, 0); mColorAutoCorrect = a.getColor(R.styleable.CandidateView_colorAutoCorrect, 0); mColorSuggestedCandidate = a.getColor(R.styleable.CandidateView_colorSuggested, 0); @@ -313,15 +314,23 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo return mColorTypedWord; } - private CharSequence getStyledCandidateWord(CharSequence word, boolean isAutoCorrect) { - if (!isAutoCorrect) + private CharSequence getStyledCandidateWord(SuggestedWords suggestions, int pos) { + final CharSequence word = suggestions.getWord(pos); + final boolean isAutoCorrect = pos == 1 && willAutoCorrect(suggestions); + final boolean isTypedWordValid = pos == 0 && suggestions.mTypedWordValid; + if (!isAutoCorrect && !isTypedWordValid) return word; + final int len = word.length(); final Spannable spannedWord = new SpannableString(word); - if ((mAutoCorrectHighlight & AUTO_CORRECT_BOLD) != 0) + final int option = mSuggestionStripOption; + if ((isAutoCorrect && (option & AUTO_CORRECT_BOLD) != 0) + || (isTypedWordValid && (option & VALID_TYPED_WORD_BOLD) != 0)) { spannedWord.setSpan(BOLD_SPAN, 0, len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); - if ((mAutoCorrectHighlight & AUTO_CORRECT_UNDERLINE) != 0) + } + if (isAutoCorrect && (option & AUTO_CORRECT_UNDERLINE) != 0) { spannedWord.setSpan(UNDERLINE_SPAN, 0, len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); + } return spannedWord; } @@ -370,7 +379,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo } public CharSequence getInvertedText(CharSequence text) { - if ((mAutoCorrectHighlight & AUTO_CORRECT_INVERT) == 0) + if ((mSuggestionStripOption & AUTO_CORRECT_INVERT) == 0) return null; final int len = text.length(); final Spannable word = new SpannableString(text); @@ -457,9 +466,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo mTexts.clear(); final int count = Math.min(suggestions.size(), countInStrip); for (int pos = 0; pos < count; pos++) { - final CharSequence word = suggestions.getWord(pos); - final boolean isAutoCorrect = pos == 1 && willAutoCorrect(suggestions); - final CharSequence styled = getStyledCandidateWord(word, isAutoCorrect); + final CharSequence styled = getStyledCandidateWord(suggestions, pos); mTexts.add(styled); } for (int pos = count; pos < countInStrip; pos++) { -- cgit v1.2.3-83-g751a From 6dde878d515f7bf5268d16a8fe4921d8821c5ae7 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 23 Aug 2011 12:22:24 +0900 Subject: Move some methods from LatinKeyboardView up into LatinKeyboardBaseView Bug: 5182291 Change-Id: I699ecef6fb8ea492d96fca1939f51faf0aac7fa6 --- .../inputmethod/keyboard/LatinKeyboard.java | 2 +- .../keyboard/LatinKeyboardBaseView.java | 83 ++++++++++++++++++++++ .../inputmethod/keyboard/LatinKeyboardView.java | 82 --------------------- 3 files changed, 84 insertions(+), 83 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java index 1b6f57b92..3b3e1f87e 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java @@ -141,7 +141,7 @@ public class LatinKeyboard extends Keyboard { } } - public void setSpacebarTextFadeFactor(float fadeFactor, LatinKeyboardView view) { + public void setSpacebarTextFadeFactor(float fadeFactor, LatinKeyboardBaseView view) { mSpacebarTextFadeFactor = fadeFactor; updateSpacebarForLocale(false); if (view != null) diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java index e0c6bbbb2..4a7b2bd60 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java @@ -20,6 +20,7 @@ import android.content.Context; import android.content.pm.PackageManager; import android.content.res.Resources; import android.content.res.TypedArray; +import android.graphics.Canvas; import android.os.Message; import android.os.SystemClock; import android.util.AttributeSet; @@ -34,11 +35,14 @@ import android.widget.PopupWindow; import com.android.inputmethod.accessibility.AccessibilityUtils; import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy; +import com.android.inputmethod.deprecated.VoiceProxy; import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy; import com.android.inputmethod.keyboard.PointerTracker.TimerProxy; import com.android.inputmethod.keyboard.internal.MiniKeyboardBuilder; +import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.StaticInnerHandlerWrapper; +import com.android.inputmethod.latin.Utils; import java.util.WeakHashMap; @@ -266,6 +270,20 @@ public class LatinKeyboardBaseView extends KeyboardView implements PointerTracke return mKeyTimerHandler; } + @Override + public void setKeyPreviewPopupEnabled(boolean previewEnabled, int delay) { + final Keyboard keyboard = getKeyboard(); + if (keyboard instanceof LatinKeyboard) { + final LatinKeyboard latinKeyboard = (LatinKeyboard)keyboard; + if (latinKeyboard.isPhoneKeyboard() || latinKeyboard.isNumberKeyboard()) { + // Phone and number keyboard never shows popup preview. + super.setKeyPreviewPopupEnabled(false, delay); + return; + } + } + super.setKeyPreviewPopupEnabled(previewEnabled, delay); + } + /** * Attaches a keyboard to this view. The keyboard can be switched at any time and the * view will re-layout itself to accommodate the keyboard. @@ -365,6 +383,15 @@ public class LatinKeyboardBaseView extends KeyboardView implements PointerTracke return mPopupPanel != null; } + public void setSpacebarTextFadeFactor(float fadeFactor, LatinKeyboard oldKeyboard) { + final Keyboard keyboard = getKeyboard(); + // We should not set text fade factor to the keyboard which does not display the language on + // its spacebar. + if (keyboard instanceof LatinKeyboard && keyboard == oldKeyboard) { + ((LatinKeyboard)keyboard).setSpacebarTextFadeFactor(fadeFactor, this); + } + } + /** * Called when a key is long pressed. By default this will open mini keyboard associated * with this key. @@ -374,6 +401,42 @@ public class LatinKeyboardBaseView extends KeyboardView implements PointerTracke * method on the base class if the subclass doesn't wish to handle the call. */ protected boolean onLongPress(Key parentKey, PointerTracker tracker) { + final int primaryCode = parentKey.mCode; + final Keyboard keyboard = getKeyboard(); + if (keyboard instanceof LatinKeyboard) { + final LatinKeyboard latinKeyboard = (LatinKeyboard) keyboard; + if (primaryCode == Keyboard.CODE_DIGIT0 && latinKeyboard.isPhoneKeyboard()) { + tracker.onLongPressed(); + // Long pressing on 0 in phone number keypad gives you a '+'. + return invokeOnKey(Keyboard.CODE_PLUS); + } + if (primaryCode == Keyboard.CODE_SHIFT && latinKeyboard.isAlphaKeyboard()) { + tracker.onLongPressed(); + return invokeOnKey(Keyboard.CODE_CAPSLOCK); + } + } + if (primaryCode == Keyboard.CODE_SETTINGS || primaryCode == Keyboard.CODE_SPACE) { + // Both long pressing settings key and space key invoke IME switcher dialog. + if (getKeyboardActionListener().onCustomRequest( + LatinIME.CODE_SHOW_INPUT_METHOD_PICKER)) { + tracker.onLongPressed(); + return true; + } else { + return openPopupPanel(parentKey, tracker); + } + } else { + return openPopupPanel(parentKey, tracker); + } + } + + private boolean invokeOnKey(int primaryCode) { + getKeyboardActionListener().onCodeInput(primaryCode, null, + KeyboardActionListener.NOT_A_TOUCH_COORDINATE, + KeyboardActionListener.NOT_A_TOUCH_COORDINATE); + return true; + } + + private boolean openPopupPanel(Key parentKey, PointerTracker tracker) { PopupPanel popupPanel = mPopupPanelCache.get(parentKey); if (popupPanel == null) { popupPanel = onCreatePopupPanel(parentKey); @@ -556,6 +619,26 @@ public class LatinKeyboardBaseView extends KeyboardView implements PointerTracke return dismissPopupPanel(); } + @Override + public void draw(Canvas c) { + Utils.GCUtils.getInstance().reset(); + boolean tryGC = true; + for (int i = 0; i < Utils.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) { + try { + super.draw(c); + tryGC = false; + } catch (OutOfMemoryError e) { + tryGC = Utils.GCUtils.getInstance().tryGCOrWait("LatinKeyboardView", e); + } + } + } + + @Override + protected void onAttachedToWindow() { + // Token is available from here. + VoiceProxy.getInstance().onAttachedToWindow(); + } + @Override public boolean dispatchTouchEvent(MotionEvent event) { // Drop non-hover touch events when touch exploration is enabled. diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index dad37e728..42ce7c440 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -22,8 +22,6 @@ import android.util.AttributeSet; import android.util.Log; import android.view.MotionEvent; -import com.android.inputmethod.deprecated.VoiceProxy; -import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.Utils; @@ -52,20 +50,6 @@ public class LatinKeyboardView extends LatinKeyboardBaseView { super(context, attrs, defStyle); } - @Override - public void setKeyPreviewPopupEnabled(boolean previewEnabled, int delay) { - final Keyboard keyboard = getKeyboard(); - if (keyboard instanceof LatinKeyboard) { - final LatinKeyboard latinKeyboard = (LatinKeyboard)keyboard; - if (latinKeyboard.isPhoneKeyboard() || latinKeyboard.isNumberKeyboard()) { - // Phone and number keyboard never shows popup preview. - super.setKeyPreviewPopupEnabled(false, delay); - return; - } - } - super.setKeyPreviewPopupEnabled(previewEnabled, delay); - } - @Override public void setKeyboard(Keyboard newKeyboard) { super.setKeyboard(newKeyboard); @@ -74,52 +58,6 @@ public class LatinKeyboardView extends LatinKeyboardBaseView { mJumpThresholdSquare = jumpThreshold * jumpThreshold; } - public void setSpacebarTextFadeFactor(float fadeFactor, LatinKeyboard oldKeyboard) { - final Keyboard keyboard = getKeyboard(); - // We should not set text fade factor to the keyboard which does not display the language on - // its spacebar. - if (keyboard instanceof LatinKeyboard && keyboard == oldKeyboard) { - ((LatinKeyboard)keyboard).setSpacebarTextFadeFactor(fadeFactor, this); - } - } - - @Override - protected boolean onLongPress(Key key, PointerTracker tracker) { - final int primaryCode = key.mCode; - final Keyboard keyboard = getKeyboard(); - if (keyboard instanceof LatinKeyboard) { - final LatinKeyboard latinKeyboard = (LatinKeyboard) keyboard; - if (primaryCode == Keyboard.CODE_DIGIT0 && latinKeyboard.isPhoneKeyboard()) { - tracker.onLongPressed(); - // Long pressing on 0 in phone number keypad gives you a '+'. - return invokeOnKey(Keyboard.CODE_PLUS); - } - if (primaryCode == Keyboard.CODE_SHIFT && latinKeyboard.isAlphaKeyboard()) { - tracker.onLongPressed(); - return invokeOnKey(Keyboard.CODE_CAPSLOCK); - } - } - if (primaryCode == Keyboard.CODE_SETTINGS || primaryCode == Keyboard.CODE_SPACE) { - // Both long pressing settings key and space key invoke IME switcher dialog. - if (getKeyboardActionListener().onCustomRequest( - LatinIME.CODE_SHOW_INPUT_METHOD_PICKER)) { - tracker.onLongPressed(); - return true; - } else { - return super.onLongPress(key, tracker); - } - } else { - return super.onLongPress(key, tracker); - } - } - - private boolean invokeOnKey(int primaryCode) { - getKeyboardActionListener().onCodeInput(primaryCode, null, - KeyboardActionListener.NOT_A_TOUCH_COORDINATE, - KeyboardActionListener.NOT_A_TOUCH_COORDINATE); - return true; - } - /** * This function checks to see if we need to handle any sudden jumps in the pointer location * that could be due to a multi-touch being treated as a move by the firmware or hardware. @@ -211,24 +149,4 @@ public class LatinKeyboardView extends LatinKeyboardBaseView { return super.onTouchEvent(me); } - - @Override - public void draw(Canvas c) { - Utils.GCUtils.getInstance().reset(); - boolean tryGC = true; - for (int i = 0; i < Utils.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) { - try { - super.draw(c); - tryGC = false; - } catch (OutOfMemoryError e) { - tryGC = Utils.GCUtils.getInstance().tryGCOrWait("LatinKeyboardView", e); - } - } - } - - @Override - protected void onAttachedToWindow() { - // Token is available from here. - VoiceProxy.getInstance().onAttachedToWindow(); - } } -- cgit v1.2.3-83-g751a From a6e912cf9849f5c979303042ce83820a8dc560d0 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 23 Aug 2011 14:30:26 +0900 Subject: Fix a bug with the string pool. This also adds some optional debug code to detect more easily possible future occurrences of the same problem. Bug: 5195017 Change-Id: I2558b468e46f7090de868f1ec2dc9e24895d670f --- .../com/android/inputmethod/latin/StringBuilderPool.java | 16 +++++++++++++++- java/src/com/android/inputmethod/latin/Suggest.java | 9 ++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/latin/StringBuilderPool.java b/java/src/com/android/inputmethod/latin/StringBuilderPool.java index 66f123731..a663ed43e 100644 --- a/java/src/com/android/inputmethod/latin/StringBuilderPool.java +++ b/java/src/com/android/inputmethod/latin/StringBuilderPool.java @@ -26,12 +26,20 @@ import java.util.List; public class StringBuilderPool { // Singleton private static final StringBuilderPool sInstance = new StringBuilderPool(); + private static final boolean DEBUG = false; private StringBuilderPool() {} - // TODO: Make this a normal array with a size of 20 + // TODO: Make this a normal array with a size of 20, or a ConcurrentQueue private final List mPool = Collections.synchronizedList(new ArrayList()); public static StringBuilder getStringBuilder(final int initialSize) { + // TODO: although the pool is synchronized, the following is not thread-safe. + // Two threads entering this at the same time could take the same size of the pool and the + // second to attempt removing this index from the pool would crash with an + // IndexOutOfBoundsException. + // At the moment this pool is only used in Suggest.java and only in one thread so it's + // okay. The simplest thing to do here is probably to replace the ArrayList with a + // ConcurrentQueue. final int poolSize = sInstance.mPool.size(); final StringBuilder sb = poolSize > 0 ? (StringBuilder) sInstance.mPool.remove(poolSize - 1) : new StringBuilder(initialSize); @@ -40,6 +48,12 @@ public class StringBuilderPool { } public static void recycle(final StringBuilder garbage) { + if (DEBUG) { + final int gid = garbage.hashCode(); + for (final StringBuilder q : sInstance.mPool) { + if (gid == q.hashCode()) throw new RuntimeException("Duplicate id " + gid); + } + } sInstance.mPool.add(garbage); } diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index e3cb6987a..29b629576 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -284,7 +284,14 @@ public class Suggest implements Dictionary.WordCallback { } protected void addBigramToSuggestions(CharSequence bigram) { - mSuggestions.add(bigram); + // TODO: Try to be a little more shrewd with resource allocation. + // At the moment we copy this object because the StringBuilders are pooled (see + // StringBuilderPool.java) and when we are finished using mSuggestions and + // mBigramSuggestions we will take everything from both and insert them back in the + // pool, so we can't allow the same object to be in both lists at the same time. + final StringBuilder sb = StringBuilderPool.getStringBuilder(getApproxMaxWordLength()); + sb.append(bigram); + mSuggestions.add(sb); } // TODO: cleanup dictionaries looking up and suggestions building with SuggestedWords.Builder -- cgit v1.2.3-83-g751a From f94df382fb3f73c03cfef5f0a28856bf3f1c73da Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 23 Aug 2011 14:58:45 +0900 Subject: Remove screen orientation confirmation hack Bug: 4311428 Change-Id: Ie7e094ded9c7c1fe811b7eb97bc33ffecb29a73c --- .../com/android/inputmethod/latin/LatinIME.java | 66 ++++------------------ 1 file changed, 10 insertions(+), 56 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index afbdd36a9..394414d03 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -113,7 +113,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // Key events coming any faster than this are long-presses. private static final int QUICK_PRESS = 200; - private static final int SCREEN_ORIENTATION_CHANGE_DETECTION_DELAY = 2; + private static final int START_INPUT_VIEW_DELAY_WHEN_SCREEN_ORIENTATION_STARTED = 10; private static final int ACCUMULATE_START_INPUT_VIEW_DELAY = 20; private static final int RESTORE_KEYBOARD_STATE_DELAY = 500; @@ -198,8 +198,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // Member variables for remembering the current device orientation. private int mDisplayOrientation; - private int mDisplayWidth; - private int mDisplayHeight; // Object for reacting to adding/removing a dictionary pack. private BroadcastReceiver mDictionaryPackInstallReceiver = @@ -219,31 +217,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private static final int MSG_DISMISS_LANGUAGE_ON_SPACEBAR = 5; private static final int MSG_SPACE_TYPED = 6; private static final int MSG_SET_BIGRAM_PREDICTIONS = 7; - private static final int MSG_CONFIRM_ORIENTATION_CHANGE = 8; + private static final int MSG_START_ORIENTATION_CHANGE = 8; private static final int MSG_START_INPUT_VIEW = 9; private static final int MSG_RESTORE_KEYBOARD_LAYOUT = 10; - private static class OrientationChangeArgs { - public final int mOldWidth; - public final int mOldHeight; - private int mRetryCount; - - public OrientationChangeArgs(int oldw, int oldh) { - mOldWidth = oldw; - mOldHeight = oldh; - mRetryCount = 0; - } - - public boolean hasTimedOut() { - mRetryCount++; - return mRetryCount >= 10; - } - - public boolean hasOrientationChangeFinished(DisplayMetrics dm) { - return dm.widthPixels != mOldWidth && dm.heightPixels != mOldHeight; - } - } - public UIHandler(LatinIME outerInstance) { super(outerInstance); } @@ -291,18 +268,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar (LatinKeyboard)msg.obj); } break; - case MSG_CONFIRM_ORIENTATION_CHANGE: { - final OrientationChangeArgs args = (OrientationChangeArgs)msg.obj; - final Resources res = latinIme.mResources; - final DisplayMetrics dm = res.getDisplayMetrics(); - if (args.hasTimedOut() || args.hasOrientationChangeFinished(dm)) { - latinIme.setDisplayGeometry(res.getConfiguration(), dm); - } else { - // It seems orientation changing is on going. - postConfirmOrientationChange(args); - } - break; - } case MSG_START_INPUT_VIEW: latinIme.onStartInputView((EditorInfo)msg.obj, false); break; @@ -411,22 +376,16 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } } - private void postConfirmOrientationChange(OrientationChangeArgs args) { - removeMessages(MSG_CONFIRM_ORIENTATION_CHANGE); - // Will confirm whether orientation change has finished or not again. - sendMessageDelayed(obtainMessage(MSG_CONFIRM_ORIENTATION_CHANGE, args), - SCREEN_ORIENTATION_CHANGE_DETECTION_DELAY); - } - - public void startOrientationChanging(int oldw, int oldh) { - postConfirmOrientationChange(new OrientationChangeArgs(oldw, oldh)); + public void startOrientationChanging() { + sendMessageDelayed(obtainMessage(MSG_START_ORIENTATION_CHANGE), + START_INPUT_VIEW_DELAY_WHEN_SCREEN_ORIENTATION_STARTED); final LatinIME latinIme = getOuterInstance(); latinIme.mKeyboardSwitcher.getKeyboardState().save(); postRestoreKeyboardLayout(); } public boolean postStartInputView(EditorInfo attribute) { - if (hasMessages(MSG_CONFIRM_ORIENTATION_CHANGE) || hasMessages(MSG_START_INPUT_VIEW)) { + if (hasMessages(MSG_START_ORIENTATION_CHANGE) || hasMessages(MSG_START_INPUT_VIEW)) { removeMessages(MSG_START_INPUT_VIEW); // Postpone onStartInputView by ACCUMULATE_START_INPUT_VIEW_DELAY and see if // orientation change has finished. @@ -438,12 +397,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } } - private void setDisplayGeometry(Configuration conf, DisplayMetrics metric) { - mDisplayOrientation = conf.orientation; - mDisplayWidth = metric.widthPixels; - mDisplayHeight = metric.heightPixels; - } - @Override public void onCreate() { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); @@ -481,7 +434,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } } - setDisplayGeometry(res.getConfiguration(), res.getDisplayMetrics()); + mDisplayOrientation = res.getConfiguration().orientation; // Register to receive ringer mode change and network state change. // Also receive installation and removal of a dictionary pack. @@ -609,8 +562,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar public void onConfigurationChanged(Configuration conf) { mSubtypeSwitcher.onConfigurationChanged(conf); // If orientation changed while predicting, commit the change - if (conf.orientation != mDisplayOrientation) { - mHandler.startOrientationChanging(mDisplayWidth, mDisplayHeight); + if (mDisplayOrientation != conf.orientation) { + mDisplayOrientation = conf.orientation; + mHandler.startOrientationChanging(); final InputConnection ic = getCurrentInputConnection(); commitTyped(ic); if (ic != null) ic.finishComposingText(); // For voice input -- cgit v1.2.3-83-g751a From f9da4c548f7baa003d8dcee04b42d3652cf2ebc3 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 23 Aug 2011 14:05:39 +0900 Subject: Remove password field special handling Change-Id: Iaf1b4bbb54be7a4cade856d1ba363e976774f442 --- java/res/values/donottranslate.xml | 2 +- java/res/xml-sw600dp/kbd_key_styles.xml | 15 -------------- java/res/xml-sw600dp/kbd_rows_symbols_shift.xml | 19 ------------------ java/res/xml-sw768dp/kbd_key_styles.xml | 15 -------------- java/res/xml-sw768dp/kbd_rows_symbols_shift.xml | 19 ------------------ java/res/xml/kbd_key_styles.xml | 23 ---------------------- java/res/xml/kbd_rows_symbols_shift.xml | 13 ------------ java/res/xml/kbd_symbols_shift_row4.xml | 8 ++++---- java/src/com/android/inputmethod/keyboard/Key.java | 6 +----- .../keyboard/internal/PopupCharactersParser.java | 7 ------- 10 files changed, 6 insertions(+), 121 deletions(-) (limited to 'java/src') diff --git a/java/res/values/donottranslate.xml b/java/res/values/donottranslate.xml index f55e9bf53..5cd995be9 100644 --- a/java/res/values/donottranslate.xml +++ b/java/res/values/donottranslate.xml @@ -35,7 +35,7 @@ = \\ < - \\ ^ [ { + ~ \\ { Tab diff --git a/java/res/xml-sw600dp/kbd_key_styles.xml b/java/res/xml-sw600dp/kbd_key_styles.xml index 15a3d1df5..b93d3007f 100644 --- a/java/res/xml-sw600dp/kbd_key_styles.xml +++ b/java/res/xml-sw600dp/kbd_key_styles.xml @@ -118,19 +118,4 @@ latin:keyLabelOption="fontNormal|hasPopupHint" latin:keyOutputText="@string/keylabel_for_popular_domain" latin:popupCharacters="@string/alternates_for_popular_domain" /> - - - - - - - - - diff --git a/java/res/xml-sw600dp/kbd_rows_symbols_shift.xml b/java/res/xml-sw600dp/kbd_rows_symbols_shift.xml index 2909acb6f..c5143d9c8 100644 --- a/java/res/xml-sw600dp/kbd_rows_symbols_shift.xml +++ b/java/res/xml-sw600dp/kbd_rows_symbols_shift.xml @@ -33,28 +33,21 @@ - - - - - - - - - diff --git a/java/res/xml-sw768dp/kbd_rows_symbols_shift.xml b/java/res/xml-sw768dp/kbd_rows_symbols_shift.xml index 1f43a0f91..82bc4b26e 100644 --- a/java/res/xml-sw768dp/kbd_rows_symbols_shift.xml +++ b/java/res/xml-sw768dp/kbd_rows_symbols_shift.xml @@ -37,28 +37,21 @@ - - - - - - - - - - - @@ -61,16 +56,12 @@ + latin:keyStyle="functionalKeyStyle" /> + latin:keyStyle="functionalKeyStyle" /> @@ -57,14 +57,14 @@ latin:keyLabel="„" latin:popupCharacters="“,”,„,‟,«,»,‘,’,‚,‛" latin:keyWidth="9.2%p" - latin:keyStyle="nonPasswordFunctionalKeyStyle" /> + latin:keyStyle="functionalKeyStyle" /> + latin:keyStyle="functionalKeyStyle" /> diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index 397b7b16b..f56b52388 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -295,12 +295,8 @@ public class Key { mY = y; mWidth = keyWidth - mHorizontalGap; - CharSequence[] popupCharacters = style.getTextArray( + final CharSequence[] popupCharacters = style.getTextArray( keyAttr, R.styleable.Keyboard_Key_popupCharacters); - if (params.mId.mPasswordInput) { - popupCharacters = PopupCharactersParser.filterOut( - res, popupCharacters, PopupCharactersParser.NON_ASCII_FILTER); - } // In Arabic symbol layouts, we'd like to keep digits in popup characters regardless of // config_digit_popup_characters_enabled. if (params.mId.isAlphabetKeyboard() && !res.getBoolean( diff --git a/java/src/com/android/inputmethod/keyboard/internal/PopupCharactersParser.java b/java/src/com/android/inputmethod/keyboard/internal/PopupCharactersParser.java index 032489e66..7c5abe32a 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/PopupCharactersParser.java +++ b/java/src/com/android/inputmethod/keyboard/internal/PopupCharactersParser.java @@ -196,13 +196,6 @@ public class PopupCharactersParser { } }; - public static final CodeFilter NON_ASCII_FILTER = new CodeFilter() { - @Override - public boolean shouldFilterOut(int code) { - return code < 0x20 || code > 0x7e; - } - }; - public static CharSequence[] filterOut(Resources res, CharSequence[] popupCharacters, CodeFilter filter) { if (popupCharacters == null || popupCharacters.length < 1) { -- cgit v1.2.3-83-g751a From c403a46f6d787b79768895272d53d296100677dd Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 23 Aug 2011 15:57:51 +0900 Subject: Extract sudden jumping touch event hack into separate class Bug: 5182291 Change-Id: I6a88ed4df3ec98e31ea4966d82da56f7fca342ac --- .../sudden-jumping-touch-event-device-list.xml | 27 ++++ .../inputmethod/keyboard/KeyboardSwitcher.java | 8 +- .../inputmethod/keyboard/LatinKeyboard.java | 2 +- .../keyboard/LatinKeyboardBaseView.java | 13 +- .../inputmethod/keyboard/LatinKeyboardView.java | 152 -------------------- .../keyboard/SuddenJumpingTouchEventHandler.java | 158 +++++++++++++++++++++ .../com/android/inputmethod/latin/LatinIME.java | 12 +- 7 files changed, 208 insertions(+), 164 deletions(-) create mode 100644 java/res/values/sudden-jumping-touch-event-device-list.xml delete mode 100644 java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java create mode 100644 java/src/com/android/inputmethod/keyboard/SuddenJumpingTouchEventHandler.java (limited to 'java/src') diff --git a/java/res/values/sudden-jumping-touch-event-device-list.xml b/java/res/values/sudden-jumping-touch-event-device-list.xml new file mode 100644 index 000000000..275a262d9 --- /dev/null +++ b/java/res/values/sudden-jumping-touch-event-device-list.xml @@ -0,0 +1,27 @@ + + + + + + passion + + sholes + + diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 8bf82807a..ec19cce6c 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -61,7 +61,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha private SharedPreferences mPrefs; private View mCurrentInputView; - private LatinKeyboardView mKeyboardView; + private LatinKeyboardBaseView mKeyboardView; private LatinIME mInputMethodService; private String mPackageName; private Resources mResources; @@ -745,7 +745,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } } - public LatinKeyboardView getKeyboardView() { + public LatinKeyboardBaseView getKeyboardView() { return mKeyboardView; } @@ -781,7 +781,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } } - mKeyboardView = (LatinKeyboardView) mCurrentInputView.findViewById(R.id.keyboard_view); + mKeyboardView = (LatinKeyboardBaseView) mCurrentInputView.findViewById(R.id.keyboard_view); mKeyboardView.setKeyboardActionListener(mInputMethodService); // This always needs to be set since the accessibility state can @@ -819,7 +819,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha final LatinKeyboard keyboard = getLatinKeyboard(); if (keyboard != null && keyboard.needsAutoCorrectionSpacebarLed()) { final Key invalidatedKey = keyboard.onAutoCorrectionStateChanged(isAutoCorrection); - final LatinKeyboardView keyboardView = getKeyboardView(); + final LatinKeyboardBaseView keyboardView = getKeyboardView(); if (keyboardView != null) keyboardView.invalidateKey(invalidatedKey); } diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java index 3b3e1f87e..d31d3e39f 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java @@ -154,7 +154,7 @@ public class LatinKeyboard extends Keyboard { return newColor; } - public void updateShortcutKey(boolean available, LatinKeyboardView view) { + public void updateShortcutKey(boolean available, LatinKeyboardBaseView view) { if (mShortcutKey == null) return; mShortcutKey.setEnabled(available); diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java index 4a7b2bd60..4b85bcbec 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java @@ -53,11 +53,14 @@ import java.util.WeakHashMap; * @attr ref R.styleable#KeyboardView_verticalCorrection * @attr ref R.styleable#KeyboardView_popupLayout */ -public class LatinKeyboardBaseView extends KeyboardView implements PointerTracker.KeyEventHandler { +public class LatinKeyboardBaseView extends KeyboardView implements PointerTracker.KeyEventHandler, + SuddenJumpingTouchEventHandler.ProcessMotionEvent { private static final String TAG = LatinKeyboardBaseView.class.getSimpleName(); private static final boolean ENABLE_CAPSLOCK_BY_DOUBLETAP = true; + private final SuddenJumpingTouchEventHandler mTouchScreenRegulator; + // Timing constants private final int mKeyRepeatInterval; @@ -213,6 +216,8 @@ public class LatinKeyboardBaseView extends KeyboardView implements PointerTracke public LatinKeyboardBaseView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); + mTouchScreenRegulator = new SuddenJumpingTouchEventHandler(getContext(), this); + final TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.KeyboardView, defStyle, R.style.KeyboardView); mVerticalCorrection = a.getDimensionPixelOffset( @@ -300,6 +305,7 @@ public class LatinKeyboardBaseView extends KeyboardView implements PointerTracke keyboard, -getPaddingLeft(), -getPaddingTop() + mVerticalCorrection); mKeyDetector.setProximityThreshold(keyboard.mMostCommonKeyWidth); PointerTracker.setKeyDetector(mKeyDetector); + mTouchScreenRegulator.setKeyboard(keyboard); mPopupPanelCache.clear(); } @@ -481,6 +487,11 @@ public class LatinKeyboardBaseView extends KeyboardView implements PointerTracke @Override public boolean onTouchEvent(MotionEvent me) { + return mTouchScreenRegulator.onTouchEvent(me); + } + + @Override + public boolean processMotionEvent(MotionEvent me) { final boolean nonDistinctMultitouch = !mHasDistinctMultitouch; final int action = me.getActionMasked(); final int pointerCount = me.getPointerCount(); diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java deleted file mode 100644 index 42ce7c440..000000000 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (C) 2008 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 android.content.Context; -import android.graphics.Canvas; -import android.util.AttributeSet; -import android.util.Log; -import android.view.MotionEvent; - -import com.android.inputmethod.latin.LatinImeLogger; -import com.android.inputmethod.latin.Utils; - -// TODO: We should remove this class -public class LatinKeyboardView extends LatinKeyboardBaseView { - private static final String TAG = LatinKeyboardView.class.getSimpleName(); - private static boolean DEBUG_MODE = LatinImeLogger.sDBG; - - /** Whether we've started dropping move events because we found a big jump */ - private boolean mDroppingEvents; - /** - * Whether multi-touch disambiguation needs to be disabled if a real multi-touch event has - * occured - */ - private boolean mDisableDisambiguation; - /** The distance threshold at which we start treating the touch session as a multi-touch */ - private int mJumpThresholdSquare = Integer.MAX_VALUE; - private int mLastX; - private int mLastY; - - public LatinKeyboardView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public LatinKeyboardView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - } - - @Override - public void setKeyboard(Keyboard newKeyboard) { - super.setKeyboard(newKeyboard); - // One-seventh of the keyboard width seems like a reasonable threshold - final int jumpThreshold = newKeyboard.mOccupiedWidth / 7; - mJumpThresholdSquare = jumpThreshold * jumpThreshold; - } - - /** - * This function checks to see if we need to handle any sudden jumps in the pointer location - * that could be due to a multi-touch being treated as a move by the firmware or hardware. - * Once a sudden jump is detected, all subsequent move events are discarded - * until an UP is received.

- * When a sudden jump is detected, an UP event is simulated at the last position and when - * the sudden moves subside, a DOWN event is simulated for the second key. - * @param me the motion event - * @return true if the event was consumed, so that it doesn't continue to be handled by - * {@link LatinKeyboardBaseView}. - */ - private boolean handleSuddenJump(MotionEvent me) { - // If device has distinct multi touch panel, there is no need to check sudden jump. - if (hasDistinctMultitouch()) - return false; - final int action = me.getAction(); - final int x = (int) me.getX(); - final int y = (int) me.getY(); - boolean result = false; - - // Real multi-touch event? Stop looking for sudden jumps - if (me.getPointerCount() > 1) { - mDisableDisambiguation = true; - } - if (mDisableDisambiguation) { - // If UP, reset the multi-touch flag - if (action == MotionEvent.ACTION_UP) mDisableDisambiguation = false; - return false; - } - - switch (action) { - case MotionEvent.ACTION_DOWN: - // Reset the "session" - mDroppingEvents = false; - mDisableDisambiguation = false; - break; - case MotionEvent.ACTION_MOVE: - // Is this a big jump? - final int distanceSquare = (mLastX - x) * (mLastX - x) + (mLastY - y) * (mLastY - y); - // Check the distance. - if (distanceSquare > mJumpThresholdSquare) { - // If we're not yet dropping events, start dropping and send an UP event - if (!mDroppingEvents) { - mDroppingEvents = true; - // Send an up event - MotionEvent translated = MotionEvent.obtain( - me.getEventTime(), me.getEventTime(), - MotionEvent.ACTION_UP, - mLastX, mLastY, me.getMetaState()); - super.onTouchEvent(translated); - translated.recycle(); - } - result = true; - } else if (mDroppingEvents) { - // If moves are small and we're already dropping events, continue dropping - result = true; - } - break; - case MotionEvent.ACTION_UP: - if (mDroppingEvents) { - // Send a down event first, as we dropped a bunch of sudden jumps and assume that - // the user is releasing the touch on the second key. - MotionEvent translated = MotionEvent.obtain(me.getEventTime(), me.getEventTime(), - MotionEvent.ACTION_DOWN, - x, y, me.getMetaState()); - super.onTouchEvent(translated); - translated.recycle(); - mDroppingEvents = false; - // Let the up event get processed as well, result = false - } - break; - } - // Track the previous coordinate - mLastX = x; - mLastY = y; - return result; - } - - @Override - public boolean onTouchEvent(MotionEvent me) { - if (getKeyboard() == null) return true; - - // If there was a sudden jump, return without processing the actual motion event. - if (handleSuddenJump(me)) { - if (DEBUG_MODE) - Log.w(TAG, "onTouchEvent: ignore sudden jump " + me); - return true; - } - - return super.onTouchEvent(me); - } -} diff --git a/java/src/com/android/inputmethod/keyboard/SuddenJumpingTouchEventHandler.java b/java/src/com/android/inputmethod/keyboard/SuddenJumpingTouchEventHandler.java new file mode 100644 index 000000000..5344c27d4 --- /dev/null +++ b/java/src/com/android/inputmethod/keyboard/SuddenJumpingTouchEventHandler.java @@ -0,0 +1,158 @@ +/* + * 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 android.content.Context; +import android.os.Build; +import android.util.Log; +import android.view.MotionEvent; + +import com.android.inputmethod.latin.LatinImeLogger; +import com.android.inputmethod.latin.R; + +public class SuddenJumpingTouchEventHandler { + private static final String TAG = SuddenJumpingTouchEventHandler.class.getSimpleName(); + private static boolean DEBUG_MODE = LatinImeLogger.sDBG; + + public interface ProcessMotionEvent { + public boolean processMotionEvent(MotionEvent me); + } + + private final ProcessMotionEvent mView; + private final boolean mNeedsSuddenJumpingHack; + + /** Whether we've started dropping move events because we found a big jump */ + private boolean mDroppingEvents; + /** + * Whether multi-touch disambiguation needs to be disabled if a real multi-touch event has + * occured + */ + private boolean mDisableDisambiguation; + /** The distance threshold at which we start treating the touch session as a multi-touch */ + private int mJumpThresholdSquare = Integer.MAX_VALUE; + private int mLastX; + private int mLastY; + + public SuddenJumpingTouchEventHandler(Context context, ProcessMotionEvent view) { + mView = view; + final String[] deviceList = context.getResources().getStringArray( + R.array.sudden_jumping_touch_event_device_list); + mNeedsSuddenJumpingHack = needsSuddenJumpingHack(Build.DEVICE, deviceList); + } + + private static boolean needsSuddenJumpingHack(String deviceName, String[] deviceList) { + for (String device : deviceList) { + if (device.equalsIgnoreCase(deviceName)) { + return true; + } + } + return false; + } + + public void setKeyboard(Keyboard newKeyboard) { + // One-seventh of the keyboard width seems like a reasonable threshold + final int jumpThreshold = newKeyboard.mOccupiedWidth / 7; + mJumpThresholdSquare = jumpThreshold * jumpThreshold; + } + + /** + * This function checks to see if we need to handle any sudden jumps in the pointer location + * that could be due to a multi-touch being treated as a move by the firmware or hardware. + * Once a sudden jump is detected, all subsequent move events are discarded + * until an UP is received.

+ * When a sudden jump is detected, an UP event is simulated at the last position and when + * the sudden moves subside, a DOWN event is simulated for the second key. + * @param me the motion event + * @return true if the event was consumed, so that it doesn't continue to be handled by + * {@link LatinKeyboardBaseView}. + */ + private boolean handleSuddenJumping(MotionEvent me) { + if (!mNeedsSuddenJumpingHack) + return false; + final int action = me.getAction(); + final int x = (int) me.getX(); + final int y = (int) me.getY(); + boolean result = false; + + // Real multi-touch event? Stop looking for sudden jumps + if (me.getPointerCount() > 1) { + mDisableDisambiguation = true; + } + if (mDisableDisambiguation) { + // If UP, reset the multi-touch flag + if (action == MotionEvent.ACTION_UP) mDisableDisambiguation = false; + return false; + } + + switch (action) { + case MotionEvent.ACTION_DOWN: + // Reset the "session" + mDroppingEvents = false; + mDisableDisambiguation = false; + break; + case MotionEvent.ACTION_MOVE: + // Is this a big jump? + final int distanceSquare = (mLastX - x) * (mLastX - x) + (mLastY - y) * (mLastY - y); + // Check the distance. + if (distanceSquare > mJumpThresholdSquare) { + // If we're not yet dropping events, start dropping and send an UP event + if (!mDroppingEvents) { + mDroppingEvents = true; + // Send an up event + MotionEvent translated = MotionEvent.obtain( + me.getEventTime(), me.getEventTime(), + MotionEvent.ACTION_UP, + mLastX, mLastY, me.getMetaState()); + mView.processMotionEvent(translated); + translated.recycle(); + } + result = true; + } else if (mDroppingEvents) { + // If moves are small and we're already dropping events, continue dropping + result = true; + } + break; + case MotionEvent.ACTION_UP: + if (mDroppingEvents) { + // Send a down event first, as we dropped a bunch of sudden jumps and assume that + // the user is releasing the touch on the second key. + MotionEvent translated = MotionEvent.obtain(me.getEventTime(), me.getEventTime(), + MotionEvent.ACTION_DOWN, + x, y, me.getMetaState()); + mView.processMotionEvent(translated); + translated.recycle(); + mDroppingEvents = false; + // Let the up event get processed as well, result = false + } + break; + } + // Track the previous coordinate + mLastX = x; + mLastY = y; + return result; + } + + public boolean onTouchEvent(MotionEvent me) { + // If there was a sudden jump, return without processing the actual motion event. + if (handleSuddenJumping(me)) { + if (DEBUG_MODE) + Log.w(TAG, "onTouchEvent: ignore sudden jump " + me); + return true; + } + return mView.processMotionEvent(me); + } +} diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index afbdd36a9..e72b43ae9 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -67,7 +67,7 @@ import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.keyboard.KeyboardSwitcher.KeyboardLayoutState; import com.android.inputmethod.keyboard.KeyboardView; import com.android.inputmethod.keyboard.LatinKeyboard; -import com.android.inputmethod.keyboard.LatinKeyboardView; +import com.android.inputmethod.keyboard.LatinKeyboardBaseView; import java.io.FileDescriptor; import java.io.PrintWriter; @@ -252,7 +252,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar public void handleMessage(Message msg) { final LatinIME latinIme = getOuterInstance(); final KeyboardSwitcher switcher = latinIme.mKeyboardSwitcher; - final LatinKeyboardView inputView = switcher.getKeyboardView(); + final LatinKeyboardBaseView inputView = switcher.getKeyboardView(); switch (msg.what) { case MSG_UPDATE_SUGGESTIONS: latinIme.updateSuggestions(); @@ -365,7 +365,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar final LatinIME latinIme = getOuterInstance(); removeMessages(MSG_FADEOUT_LANGUAGE_ON_SPACEBAR); removeMessages(MSG_DISMISS_LANGUAGE_ON_SPACEBAR); - final LatinKeyboardView inputView = latinIme.mKeyboardSwitcher.getKeyboardView(); + final LatinKeyboardBaseView inputView = latinIme.mKeyboardSwitcher.getKeyboardView(); if (inputView != null) { final LatinKeyboard keyboard = latinIme.mKeyboardSwitcher.getLatinKeyboard(); // The language is always displayed when the delay is negative. @@ -656,7 +656,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } final KeyboardSwitcher switcher = mKeyboardSwitcher; - LatinKeyboardView inputView = switcher.getKeyboardView(); + LatinKeyboardBaseView inputView = switcher.getKeyboardView(); if (DEBUG) { Log.d(TAG, "onStartInputView: attribute:" + ((attribute == null) ? "none" @@ -1544,7 +1544,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar commitTyped(getCurrentInputConnection()); mVoiceProxy.handleClose(); requestHideSelf(0); - LatinKeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); + LatinKeyboardBaseView inputView = mKeyboardSwitcher.getKeyboardView(); if (inputView != null) inputView.closing(); } @@ -2116,7 +2116,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (!mSettingsValues.mVibrateOn) { return; } - LatinKeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); + LatinKeyboardBaseView inputView = mKeyboardSwitcher.getKeyboardView(); if (inputView != null) { inputView.performHapticFeedback( HapticFeedbackConstants.KEYBOARD_TAP, -- cgit v1.2.3-83-g751a From 32572948d7e3956efebcbd69d7c7d8403bb659e6 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 23 Aug 2011 12:08:36 +0900 Subject: Refactor and rename popup mini keyoard related classes Change-Id: Ia92ec4612090b03829db9a87ce68d701db6e15bc --- .../android/inputmethod/keyboard/KeyDetector.java | 4 + .../keyboard/LatinKeyboardBaseView.java | 3 +- .../android/inputmethod/keyboard/MiniKeyboard.java | 250 +++- .../keyboard/MiniKeyboardKeyDetector.java | 59 - .../inputmethod/keyboard/PointerTracker.java | 4 +- .../keyboard/PopupMiniKeyboardView.java | 52 +- .../keyboard/internal/MiniKeyboardBuilder.java | 259 ---- .../keyboard/MiniKeyboardBuilderTests.java | 1416 ++++++++++++++++++++ .../internal/MiniKeyboardBuilderTests.java | 1416 -------------------- 9 files changed, 1718 insertions(+), 1745 deletions(-) delete mode 100644 java/src/com/android/inputmethod/keyboard/MiniKeyboardKeyDetector.java delete mode 100644 java/src/com/android/inputmethod/keyboard/internal/MiniKeyboardBuilder.java create mode 100644 tests/src/com/android/inputmethod/keyboard/MiniKeyboardBuilderTests.java delete mode 100644 tests/src/com/android/inputmethod/keyboard/internal/MiniKeyboardBuilderTests.java (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/keyboard/KeyDetector.java b/java/src/com/android/inputmethod/keyboard/KeyDetector.java index 0a3acb48b..3298c41cf 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyDetector.java +++ b/java/src/com/android/inputmethod/keyboard/KeyDetector.java @@ -91,6 +91,10 @@ public class KeyDetector { mProximityThresholdSquare = threshold * threshold; } + public boolean alwaysAllowsSlidingInput() { + return false; + } + /** * Computes maximum size of the array that can contain all nearby key indices returned by * {@link #getKeyIndexAndNearbyCodes}. diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java index 4b85bcbec..2af4594f4 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java @@ -38,7 +38,6 @@ import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy; import com.android.inputmethod.deprecated.VoiceProxy; import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy; import com.android.inputmethod.keyboard.PointerTracker.TimerProxy; -import com.android.inputmethod.keyboard.internal.MiniKeyboardBuilder; import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.StaticInnerHandlerWrapper; @@ -374,7 +373,7 @@ public class LatinKeyboardBaseView extends KeyboardView implements PointerTracke final PopupMiniKeyboardView miniKeyboardView = (PopupMiniKeyboardView)container.findViewById(R.id.mini_keyboard_view); final Keyboard parentKeyboard = getKeyboard(); - final Keyboard miniKeyboard = new MiniKeyboardBuilder( + final Keyboard miniKeyboard = new MiniKeyboard.Builder( this, parentKeyboard.mPopupKeyboardResId, parentKey, parentKeyboard).build(); miniKeyboardView.setKeyboard(miniKeyboard); diff --git a/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java b/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java index 08e7d7e19..17c253963 100644 --- a/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java @@ -16,12 +16,18 @@ package com.android.inputmethod.keyboard; -import com.android.inputmethod.keyboard.internal.MiniKeyboardBuilder.MiniKeyboardParams; +import android.graphics.Paint; +import android.graphics.Rect; + +import com.android.inputmethod.keyboard.internal.KeyboardBuilder; +import com.android.inputmethod.keyboard.internal.KeyboardParams; +import com.android.inputmethod.keyboard.internal.PopupCharactersParser; +import com.android.inputmethod.latin.R; public class MiniKeyboard extends Keyboard { private final int mDefaultKeyCoordX; - public MiniKeyboard(MiniKeyboardParams params) { + private MiniKeyboard(Builder.MiniKeyboardParams params) { super(params); mDefaultKeyCoordX = params.getDefaultKeyCoordX() + params.mDefaultKeyWidth / 2; } @@ -29,4 +35,244 @@ public class MiniKeyboard extends Keyboard { public int getDefaultCoordX() { return mDefaultKeyCoordX; } + + public static class Builder extends KeyboardBuilder { + private final CharSequence[] mPopupCharacters; + + public static class MiniKeyboardParams extends KeyboardParams { + /* package */int mTopRowAdjustment; + public int mNumRows; + public int mNumColumns; + public int mLeftKeys; + public int mRightKeys; // includes default key. + + public MiniKeyboardParams() { + super(); + } + + /* package for test */MiniKeyboardParams(int numKeys, int maxColumns, int keyWidth, + int rowHeight, int coordXInParent, int parentKeyboardWidth) { + super(); + setParameters(numKeys, maxColumns, keyWidth, rowHeight, coordXInParent, + parentKeyboardWidth); + } + + /** + * Set keyboard parameters of mini keyboard. + * + * @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 void setParameters(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); + } + mDefaultKeyWidth = keyWidth; + mDefaultRowHeight = rowHeight; + + final int numRows = (numKeys + maxColumns - 1) / maxColumns; + mNumRows = numRows; + final int numColumns = getOptimizedColumns(numKeys, maxColumns); + mNumColumns = numColumns; + + 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); + int leftKeys, rightKeys; + if (numLeftKeys > maxLeftKeys) { + leftKeys = maxLeftKeys; + rightKeys = numColumns - maxLeftKeys; + } else if (numRightKeys > maxRightKeys) { + leftKeys = numColumns - maxRightKeys; + rightKeys = maxRightKeys; + } else { + leftKeys = numLeftKeys; + rightKeys = numRightKeys; + } + // Shift right if the left edge of mini keyboard is on the edge of parent keyboard + // unless the parent key is on the left edge. + if (leftKeys * keyWidth >= coordXInParent && leftKeys > 0) { + leftKeys--; + rightKeys++; + } + // Shift left if the right edge of mini keyboard is on the edge of parent keyboard + // unless the parent key is on the right edge. + if (rightKeys * keyWidth + coordXInParent >= parentKeyboardWidth && rightKeys > 1) { + leftKeys++; + rightKeys--; + } + mLeftKeys = leftKeys; + mRightKeys = rightKeys; + + // Centering of the top row. + final boolean onEdge = (leftKeys == 0 || rightKeys == 1); + if (numRows < 2 || onEdge || getTopRowEmptySlots(numKeys, numColumns) % 2 == 0) { + mTopRowAdjustment = 0; + } else if (mLeftKeys < mRightKeys - 1) { + mTopRowAdjustment = 1; + } else { + mTopRowAdjustment = -1; + } + + mWidth = mOccupiedWidth = mNumColumns * mDefaultKeyWidth; + mHeight = mOccupiedHeight = mNumRows * mDefaultRowHeight + mVerticalGap; + } + + // 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; + } + + private static int getTopRowEmptySlots(int numKeys, int numColumns) { + final int remainingKeys = numKeys % numColumns; + if (remainingKeys == 0) { + return 0; + } else { + return numColumns - remainingKeys; + } + } + + private int getOptimizedColumns(int numKeys, int maxColumns) { + int numColumns = Math.min(numKeys, maxColumns); + while (getTopRowEmptySlots(numKeys, numColumns) >= mNumRows) { + numColumns--; + } + return numColumns; + } + + public int getDefaultKeyCoordX() { + return mLeftKeys * mDefaultKeyWidth; + } + + public int getX(int n, int row) { + final int x = getColumnPos(n) * mDefaultKeyWidth + getDefaultKeyCoordX(); + if (isTopRow(row)) { + return x + mTopRowAdjustment * (mDefaultKeyWidth / 2); + } + return x; + } + + public int getY(int row) { + return (mNumRows - 1 - row) * mDefaultRowHeight + mTopPadding; + } + + public int getRowFlags(int row) { + int rowFlags = 0; + if (row == 0) + rowFlags |= Keyboard.EDGE_TOP; + if (isTopRow(row)) + rowFlags |= Keyboard.EDGE_BOTTOM; + return rowFlags; + } + + private boolean isTopRow(int rowCount) { + return rowCount == mNumRows - 1; + } + } + + public Builder(KeyboardView view, int xmlId, Key parentKey, Keyboard parentKeyboard) { + super(view.getContext(), new MiniKeyboardParams()); + load(parentKeyboard.mId.cloneWithNewXml(mResources.getResourceEntryName(xmlId), xmlId)); + + // HACK: Current mini keyboard design totally relies on the 9-patch + // padding about horizontal + // and vertical key spacing. To keep the visual of mini keyboard as + // is, these hacks are + // needed to keep having the same horizontal and vertical key + // spacing. + mParams.mHorizontalGap = 0; + mParams.mVerticalGap = mParams.mTopPadding = parentKeyboard.mVerticalGap / 2; + // TODO: When we have correctly padded key background 9-patch + // drawables for mini keyboard, + // revert the above hacks and uncomment the following lines. + // mParams.mHorizontalGap = parentKeyboard.mHorizontalGap; + // mParams.mVerticalGap = parentKeyboard.mVerticalGap; + + mParams.mIsRtlKeyboard = parentKeyboard.mIsRtlKeyboard; + mPopupCharacters = parentKey.mPopupCharacters; + + final int keyWidth = getMaxKeyWidth(view, mPopupCharacters, mParams.mDefaultKeyWidth); + mParams.setParameters(mPopupCharacters.length, parentKey.mMaxPopupColumn, keyWidth, + parentKeyboard.mDefaultRowHeight, parentKey.mX + + (mParams.mDefaultKeyWidth - keyWidth) / 2, view.getMeasuredWidth()); + } + + private static int getMaxKeyWidth(KeyboardView view, CharSequence[] popupCharacters, + int minKeyWidth) { + Paint paint = null; + Rect bounds = null; + int maxWidth = 0; + for (CharSequence popupSpec : popupCharacters) { + final CharSequence label = PopupCharactersParser.getLabel(popupSpec.toString()); + // If the label is single letter, minKeyWidth is enough to hold + // the label. + if (label != null && label.length() > 1) { + if (paint == null) { + paint = new Paint(); + paint.setAntiAlias(true); + } + final int labelSize = view.getDefaultLabelSizeAndSetPaint(paint); + paint.setTextSize(labelSize); + if (bounds == null) + bounds = new Rect(); + paint.getTextBounds(label.toString(), 0, label.length(), bounds); + if (maxWidth < bounds.width()) + maxWidth = bounds.width(); + } + } + final int horizontalPadding = (int) view.getContext().getResources() + .getDimension(R.dimen.mini_keyboard_key_horizontal_padding); + return Math.max(minKeyWidth, maxWidth + horizontalPadding); + } + + @Override + public MiniKeyboard build() { + final MiniKeyboardParams 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(mResources, params, label, params.getX(n, row), + params.getY(row), params.mDefaultKeyWidth, params.mDefaultRowHeight, + params.getRowFlags(row)); + params.onAddKey(key); + } + return new MiniKeyboard(params); + } + } } diff --git a/java/src/com/android/inputmethod/keyboard/MiniKeyboardKeyDetector.java b/java/src/com/android/inputmethod/keyboard/MiniKeyboardKeyDetector.java deleted file mode 100644 index 84bd44c30..000000000 --- a/java/src/com/android/inputmethod/keyboard/MiniKeyboardKeyDetector.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2010 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 java.util.List; - -public class MiniKeyboardKeyDetector extends KeyDetector { - private final int mSlideAllowanceSquare; - private final int mSlideAllowanceSquareTop; - - public MiniKeyboardKeyDetector(float slideAllowance) { - super(/* keyHysteresisDistance */0); - mSlideAllowanceSquare = (int)(slideAllowance * slideAllowance); - // Top slide allowance is slightly longer (sqrt(2) times) than other edges. - mSlideAllowanceSquareTop = mSlideAllowanceSquare * 2; - } - - @Override - protected int getMaxNearbyKeys() { - // No nearby key will be returned. - return 1; - } - - @Override - public int getKeyIndexAndNearbyCodes(int x, int y, final int[] allCodes) { - final List keys = getKeyboard().mKeys; - final int touchX = getTouchX(x); - final int touchY = getTouchY(y); - - int nearestIndex = NOT_A_KEY; - int nearestDist = (y < 0) ? mSlideAllowanceSquareTop : mSlideAllowanceSquare; - final int keyCount = keys.size(); - for (int index = 0; index < keyCount; index++) { - final int dist = keys.get(index).squaredDistanceToEdge(touchX, touchY); - if (dist < nearestDist) { - nearestIndex = index; - nearestDist = dist; - } - } - - if (allCodes != null && nearestIndex != NOT_A_KEY) - allCodes[0] = keys.get(nearestIndex).mCode; - return nearestIndex; - } -} diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 1f8119a0f..d33cb442b 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -438,9 +438,9 @@ public class PointerTracker { private void onDownEventInternal(int x, int y, long eventTime) { int keyIndex = onDownKey(x, y, eventTime); // Sliding key is allowed when 1) enabled by configuration, 2) this pointer starts sliding - // from modifier key, or 3) this pointer is on mini-keyboard. + // from modifier key, or 3) this pointer's KeyDetector always allows sliding input. mIsAllowedSlidingKeyInput = sConfigSlidingKeyInputEnabled || isModifierInternal(keyIndex) - || mKeyDetector instanceof MiniKeyboardKeyDetector; + || mKeyDetector.alwaysAllowsSlidingInput(); mKeyboardLayoutHasBeenChanged = false; mKeyAlreadyProcessed = false; mIsRepeatableKey = false; diff --git a/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java b/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java index fb932e3e8..1230dfb44 100644 --- a/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java @@ -28,6 +28,8 @@ import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy; import com.android.inputmethod.keyboard.PointerTracker.TimerProxy; import com.android.inputmethod.latin.R; +import java.util.List; + /** * A view that renders a virtual {@link MiniKeyboard}. It handles rendering of keys and detecting * key presses and touch movements. @@ -43,6 +45,51 @@ public class PopupMiniKeyboardView extends KeyboardView implements PopupPanel { private int mOriginX; private int mOriginY; + private static class MiniKeyboardKeyDetector extends KeyDetector { + private final int mSlideAllowanceSquare; + private final int mSlideAllowanceSquareTop; + + public MiniKeyboardKeyDetector(float slideAllowance) { + super(/* keyHysteresisDistance */0); + mSlideAllowanceSquare = (int)(slideAllowance * slideAllowance); + // Top slide allowance is slightly longer (sqrt(2) times) than other edges. + mSlideAllowanceSquareTop = mSlideAllowanceSquare * 2; + } + + @Override + public boolean alwaysAllowsSlidingInput() { + return true; + } + + @Override + protected int getMaxNearbyKeys() { + // No nearby key will be returned. + return 1; + } + + @Override + public int getKeyIndexAndNearbyCodes(int x, int y, final int[] allCodes) { + final List keys = getKeyboard().mKeys; + final int touchX = getTouchX(x); + final int touchY = getTouchY(y); + + int nearestIndex = NOT_A_KEY; + int nearestDist = (y < 0) ? mSlideAllowanceSquareTop : mSlideAllowanceSquare; + final int keyCount = keys.size(); + for (int index = 0; index < keyCount; index++) { + final int dist = keys.get(index).squaredDistanceToEdge(touchX, touchY); + if (dist < nearestDist) { + nearestIndex = index; + nearestDist = dist; + } + } + + if (allCodes != null && nearestIndex != NOT_A_KEY) + allCodes[0] = keys.get(nearestIndex).mCode; + return nearestIndex; + } + } + private static final TimerProxy EMPTY_TIMER_PROXY = new TimerProxy() { @Override public void startKeyRepeatTimer(long delay, int keyIndex, PointerTracker tracker) {} @@ -145,11 +192,6 @@ public class PopupMiniKeyboardView extends KeyboardView implements PopupPanel { return EMPTY_TIMER_PROXY; } - @Override - protected void onSizeChanged(int w, int h, int oldw, int oldh) { - // Do nothing for the mini keyboard. - } - @Override public void setKeyPreviewPopupEnabled(boolean previewEnabled, int delay) { // Mini keyboard needs no pop-up key preview displayed, so we pass always false with a diff --git a/java/src/com/android/inputmethod/keyboard/internal/MiniKeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/internal/MiniKeyboardBuilder.java deleted file mode 100644 index 31a291cef..000000000 --- a/java/src/com/android/inputmethod/keyboard/internal/MiniKeyboardBuilder.java +++ /dev/null @@ -1,259 +0,0 @@ -/* - * Copyright (C) 2010 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.internal; - -import android.graphics.Paint; -import android.graphics.Rect; - -import com.android.inputmethod.keyboard.Key; -import com.android.inputmethod.keyboard.Keyboard; -import com.android.inputmethod.keyboard.KeyboardView; -import com.android.inputmethod.keyboard.MiniKeyboard; -import com.android.inputmethod.latin.R; - -public class MiniKeyboardBuilder extends - KeyboardBuilder { - private final CharSequence[] mPopupCharacters; - - public static class MiniKeyboardParams extends KeyboardParams { - /* package */ int mTopRowAdjustment; - public int mNumRows; - public int mNumColumns; - public int mLeftKeys; - public int mRightKeys; // includes default key. - - public MiniKeyboardParams() { - super(); - } - - /* package for test */ MiniKeyboardParams(int numKeys, int maxColumns, int keyWidth, - int rowHeight, int coordXInParent, int parentKeyboardWidth) { - super(); - setParameters( - numKeys, maxColumns, keyWidth, rowHeight, coordXInParent, parentKeyboardWidth); - } - - /** - * Set keyboard parameters of mini keyboard. - * - * @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 void setParameters(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); - } - mDefaultKeyWidth = keyWidth; - mDefaultRowHeight = rowHeight; - - final int numRows = (numKeys + maxColumns - 1) / maxColumns; - mNumRows = numRows; - final int numColumns = getOptimizedColumns(numKeys, maxColumns); - mNumColumns = numColumns; - - 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); - int leftKeys, rightKeys; - if (numLeftKeys > maxLeftKeys) { - leftKeys = maxLeftKeys; - rightKeys = numColumns - maxLeftKeys; - } else if (numRightKeys > maxRightKeys) { - leftKeys = numColumns - maxRightKeys; - rightKeys = maxRightKeys; - } else { - leftKeys = numLeftKeys; - rightKeys = numRightKeys; - } - // Shift right if the left edge of mini keyboard is on the edge of parent keyboard - // unless the parent key is on the left edge. - if (leftKeys * keyWidth >= coordXInParent && leftKeys > 0) { - leftKeys--; - rightKeys++; - } - // Shift left if the right edge of mini keyboard is on the edge of parent keyboard - // unless the parent key is on the right edge. - if (rightKeys * keyWidth + coordXInParent >= parentKeyboardWidth && rightKeys > 1) { - leftKeys++; - rightKeys--; - } - mLeftKeys = leftKeys; - mRightKeys = rightKeys; - - // Centering of the top row. - final boolean onEdge = (leftKeys == 0 || rightKeys == 1); - if (numRows < 2 || onEdge || getTopRowEmptySlots(numKeys, numColumns) % 2 == 0) { - mTopRowAdjustment = 0; - } else if (mLeftKeys < mRightKeys - 1) { - mTopRowAdjustment = 1; - } else { - mTopRowAdjustment = -1; - } - - mWidth = mOccupiedWidth = mNumColumns * mDefaultKeyWidth; - mHeight = mOccupiedHeight = mNumRows * mDefaultRowHeight + mVerticalGap; - } - - // 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; - } - - private static int getTopRowEmptySlots(int numKeys, int numColumns) { - final int remainingKeys = numKeys % numColumns; - if (remainingKeys == 0) { - return 0; - } else { - return numColumns - remainingKeys; - } - } - - private int getOptimizedColumns(int numKeys, int maxColumns) { - int numColumns = Math.min(numKeys, maxColumns); - while (getTopRowEmptySlots(numKeys, numColumns) >= mNumRows) { - numColumns--; - } - return numColumns; - } - - public int getDefaultKeyCoordX() { - return mLeftKeys * mDefaultKeyWidth; - } - - public int getX(int n, int row) { - final int x = getColumnPos(n) * mDefaultKeyWidth + getDefaultKeyCoordX(); - if (isTopRow(row)) { - return x + mTopRowAdjustment * (mDefaultKeyWidth / 2); - } - return x; - } - - public int getY(int row) { - return (mNumRows - 1 - row) * mDefaultRowHeight + mTopPadding; - } - - public int getRowFlags(int row) { - int rowFlags = 0; - if (row == 0) rowFlags |= Keyboard.EDGE_TOP; - if (isTopRow(row)) rowFlags |= Keyboard.EDGE_BOTTOM; - return rowFlags; - } - - private boolean isTopRow(int rowCount) { - return rowCount == mNumRows - 1; - } - } - - public MiniKeyboardBuilder(KeyboardView view, int xmlId, Key parentKey, - Keyboard parentKeyboard) { - super(view.getContext(), new MiniKeyboardParams()); - load(parentKeyboard.mId.cloneWithNewXml(mResources.getResourceEntryName(xmlId), xmlId)); - - // HACK: Current mini keyboard design totally relies on the 9-patch padding about horizontal - // and vertical key spacing. To keep the visual of mini keyboard as is, these hacks are - // needed to keep having the same horizontal and vertical key spacing. - mParams.mHorizontalGap = 0; - mParams.mVerticalGap = mParams.mTopPadding = parentKeyboard.mVerticalGap / 2; - // TODO: When we have correctly padded key background 9-patch drawables for mini keyboard, - // revert the above hacks and uncomment the following lines. - //mParams.mHorizontalGap = parentKeyboard.mHorizontalGap; - //mParams.mVerticalGap = parentKeyboard.mVerticalGap; - - mParams.mIsRtlKeyboard = parentKeyboard.mIsRtlKeyboard; - mPopupCharacters = parentKey.mPopupCharacters; - - final int keyWidth = getMaxKeyWidth(view, mPopupCharacters, mParams.mDefaultKeyWidth); - mParams.setParameters( - mPopupCharacters.length, parentKey.mMaxPopupColumn, - keyWidth, parentKeyboard.mDefaultRowHeight, - parentKey.mX + (mParams.mDefaultKeyWidth - keyWidth) / 2, - view.getMeasuredWidth()); - } - - private static int getMaxKeyWidth(KeyboardView view, CharSequence[] popupCharacters, - int minKeyWidth) { - Paint paint = null; - Rect bounds = null; - int maxWidth = 0; - for (CharSequence popupSpec : popupCharacters) { - final CharSequence label = PopupCharactersParser.getLabel(popupSpec.toString()); - // If the label is single letter, minKeyWidth is enough to hold the label. - if (label != null && label.length() > 1) { - if (paint == null) { - paint = new Paint(); - paint.setAntiAlias(true); - } - final int labelSize = view.getDefaultLabelSizeAndSetPaint(paint); - paint.setTextSize(labelSize); - if (bounds == null) bounds = new Rect(); - paint.getTextBounds(label.toString(), 0, label.length(), bounds); - if (maxWidth < bounds.width()) - maxWidth = bounds.width(); - } - } - final int horizontalPadding = (int)view.getContext().getResources().getDimension( - R.dimen.mini_keyboard_key_horizontal_padding); - return Math.max(minKeyWidth, maxWidth + horizontalPadding); - } - - @Override - public MiniKeyboard build() { - final MiniKeyboardParams 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(mResources, params, label, params.getX(n, row), params.getY(row), - params.mDefaultKeyWidth, params.mDefaultRowHeight, params.getRowFlags(row)); - params.onAddKey(key); - } - return new MiniKeyboard(params); - } -} diff --git a/tests/src/com/android/inputmethod/keyboard/MiniKeyboardBuilderTests.java b/tests/src/com/android/inputmethod/keyboard/MiniKeyboardBuilderTests.java new file mode 100644 index 000000000..a143bbad5 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/MiniKeyboardBuilderTests.java @@ -0,0 +1,1416 @@ +/* + * 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.MiniKeyboard.Builder.MiniKeyboardParams; + +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; + + private static final int KEYBOARD_WIDTH = WIDTH * 10; + private static final int XPOS_L0 = WIDTH * 0; + private static final int XPOS_L1 = WIDTH * 1; + private static final int XPOS_L2 = WIDTH * 2; + private static final int XPOS_M0 = WIDTH * 5; + private static final int XPOS_R3 = WIDTH * 6; + private static final int XPOS_R2 = WIDTH * 7; + private static final int XPOS_R1 = WIDTH * 8; + private static final int XPOS_R0 = WIDTH * 9; + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + public void testLayoutError() { + MiniKeyboardParams params = null; + try { + params = new MiniKeyboardParams(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 testLayout1KeyM0() { + MiniKeyboardParams params = new MiniKeyboardParams(1, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_M0, KEYBOARD_WIDTH); + assertEquals("1 key M0 columns", 1, params.mNumColumns); + assertEquals("1 key M0 rows", 1, params.mNumRows); + assertEquals("1 key M0 left", 0, params.mLeftKeys); + assertEquals("1 key M0 right", 1, params.mRightKeys); + assertEquals("1 key M0 [1]", 0, params.getColumnPos(0)); + assertEquals("1 key M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("1 key M0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |[1] + public void testLayout1KeyL0() { + MiniKeyboardParams params = new MiniKeyboardParams(1, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L0, KEYBOARD_WIDTH); + assertEquals("1 key L0 columns", 1, params.mNumColumns); + assertEquals("1 key L0 rows", 1, params.mNumRows); + assertEquals("1 key L0 left", 0, params.mLeftKeys); + assertEquals("1 key L0 right", 1, params.mRightKeys); + assertEquals("1 key L0 [1]", 0, params.getColumnPos(0)); + assertEquals("1 key L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("1 key L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [1] + public void testLayout1KeyL1() { + MiniKeyboardParams params = new MiniKeyboardParams(1, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L1, KEYBOARD_WIDTH); + assertEquals("1 key L1 columns", 1, params.mNumColumns); + assertEquals("1 key L1 rows", 1, params.mNumRows); + assertEquals("1 key L1 left", 0, params.mLeftKeys); + assertEquals("1 key L1 right", 1, params.mRightKeys); + assertEquals("1 key L1 [1]", 0, params.getColumnPos(0)); + assertEquals("1 key L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("1 key L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ ___ [1] + public void testLayout1KeyL2() { + MiniKeyboardParams params = new MiniKeyboardParams(1, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L2, KEYBOARD_WIDTH); + assertEquals("1 key L2 columns", 1, params.mNumColumns); + assertEquals("1 key L2 rows", 1, params.mNumRows); + assertEquals("1 key L2 left", 0, params.mLeftKeys); + assertEquals("1 key L2 right", 1, params.mRightKeys); + assertEquals("1 key L2 [1]", 0, params.getColumnPos(0)); + assertEquals("1 key L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("1 key L2 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // [1]| + public void testLayout1KeyR0() { + MiniKeyboardParams params = new MiniKeyboardParams(1, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R0, KEYBOARD_WIDTH); + assertEquals("1 key R0 columns", 1, params.mNumColumns); + assertEquals("1 key R0 rows", 1, params.mNumRows); + assertEquals("1 key R0 left", 0, params.mLeftKeys); + assertEquals("1 key R0 right", 1, params.mRightKeys); + assertEquals("1 key R0 [1]", 0, params.getColumnPos(0)); + assertEquals("1 key R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("1 key R0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // [1] ___| + public void testLayout1KeyR1() { + MiniKeyboardParams params = new MiniKeyboardParams(1, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R1, KEYBOARD_WIDTH); + assertEquals("1 key R1 columns", 1, params.mNumColumns); + assertEquals("1 key R1 rows", 1, params.mNumRows); + assertEquals("1 key R1 left", 0, params.mLeftKeys); + assertEquals("1 key R1 right", 1, params.mRightKeys); + assertEquals("1 key R1 [1]", 0, params.getColumnPos(0)); + assertEquals("1 key R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("1 key R1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // [1] ___ ___| + public void testLayout1KeyR2() { + MiniKeyboardParams params = new MiniKeyboardParams(1, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R2, KEYBOARD_WIDTH); + assertEquals("1 key R2 columns", 1, params.mNumColumns); + assertEquals("1 key R2 rows", 1, params.mNumRows); + assertEquals("1 key R2 left", 0, params.mLeftKeys); + assertEquals("1 key R2 right", 1, params.mRightKeys); + assertEquals("1 key R2 [1]", 0, params.getColumnPos(0)); + assertEquals("1 key R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("1 key R2 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // [1] [2] + public void testLayout2KeyM0() { + MiniKeyboardParams params = new MiniKeyboardParams(2, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_M0, KEYBOARD_WIDTH); + assertEquals("2 key M0 columns", 2, params.mNumColumns); + assertEquals("2 key M0 rows", 1, params.mNumRows); + assertEquals("2 key M0 left", 0, params.mLeftKeys); + assertEquals("2 key M0 right", 2, params.mRightKeys); + assertEquals("2 key M0 [1]", 0, params.getColumnPos(0)); + assertEquals("2 key M0 [2]", 1, params.getColumnPos(1)); + assertEquals("2 key M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("2 key M0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |[1] [2] + public void testLayout2KeyL0() { + MiniKeyboardParams params = new MiniKeyboardParams(2, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L0, KEYBOARD_WIDTH); + assertEquals("2 key L0 columns", 2, params.mNumColumns); + assertEquals("2 key L0 rows", 1, params.mNumRows); + assertEquals("2 key L0 left", 0, params.mLeftKeys); + assertEquals("2 key L0 right", 2, params.mRightKeys); + assertEquals("2 key L0 [1]", 0, params.getColumnPos(0)); + assertEquals("2 key L0 [2]", 1, params.getColumnPos(1)); + assertEquals("2 key L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("2 key L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [1] [2] + public void testLayout2KeyL1() { + MiniKeyboardParams params = new MiniKeyboardParams(2, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L1, KEYBOARD_WIDTH); + assertEquals("2 key L1 columns", 2, params.mNumColumns); + assertEquals("2 key L1 rows", 1, params.mNumRows); + assertEquals("2 key L1 left", 0, params.mLeftKeys); + assertEquals("2 key L1 right", 2, params.mRightKeys); + assertEquals("2 key L1 [1]", 0, params.getColumnPos(0)); + assertEquals("2 key L1 [2]", 1, params.getColumnPos(1)); + assertEquals("2 key L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("2 key L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ ___ [1] [2] + public void testLayout2KeyL2() { + MiniKeyboardParams params = new MiniKeyboardParams(2, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L2, KEYBOARD_WIDTH); + assertEquals("2 key L2 columns", 2, params.mNumColumns); + assertEquals("2 key L2 rows", 1, params.mNumRows); + assertEquals("2 key L2 left", 0, params.mLeftKeys); + assertEquals("2 key L2 right", 2, params.mRightKeys); + assertEquals("2 key L2 [1]", 0, params.getColumnPos(0)); + assertEquals("2 key L2 [2]", 1, params.getColumnPos(1)); + assertEquals("2 key L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("2 key L2 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // [2] [1]| + public void testLayout2KeyR0() { + MiniKeyboardParams params = new MiniKeyboardParams(2, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R0, KEYBOARD_WIDTH); + assertEquals("2 key R0 columns", 2, params.mNumColumns); + assertEquals("2 key R0 rows", 1, params.mNumRows); + assertEquals("2 key R0 left", 1, params.mLeftKeys); + assertEquals("2 key R0 right", 1, params.mRightKeys); + assertEquals("2 key R0 [1]", 0, params.getColumnPos(0)); + assertEquals("2 key R0 [2]", -1, params.getColumnPos(1)); + assertEquals("2 key R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("2 key R0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [2] [1] ___| + public void testLayout2KeyR1() { + MiniKeyboardParams params = new MiniKeyboardParams(2, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R1, KEYBOARD_WIDTH); + assertEquals("2 key R1 columns", 2, params.mNumColumns); + assertEquals("2 key R1 rows", 1, params.mNumRows); + assertEquals("2 key R1 left", 1, params.mLeftKeys); + assertEquals("2 key R1 right", 1, params.mRightKeys); + assertEquals("2 key R1 [1]", 0, params.getColumnPos(0)); + assertEquals("2 key R1 [2]", -1, params.getColumnPos(1)); + assertEquals("2 key R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("2 key R1 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [1] [2] ___ ___| + public void testLayout2KeyR2() { + MiniKeyboardParams params = new MiniKeyboardParams(2, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R2, KEYBOARD_WIDTH); + assertEquals("2 key R2 columns", 2, params.mNumColumns); + assertEquals("2 key R2 rows", 1, params.mNumRows); + assertEquals("2 key R2 left", 0, params.mLeftKeys); + assertEquals("2 key R2 right", 2, params.mRightKeys); + assertEquals("2 key R2 [1]", 0, params.getColumnPos(0)); + assertEquals("2 key R2 [2]", 1, params.getColumnPos(1)); + assertEquals("2 key R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("2 key R2 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // [3] [1] [2] + public void testLayout3KeyM0() { + MiniKeyboardParams params = new MiniKeyboardParams(3, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_M0, KEYBOARD_WIDTH); + 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 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |[1] [2] [3] + public void testLayout3KeyL0() { + MiniKeyboardParams params = new MiniKeyboardParams(3, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L0, KEYBOARD_WIDTH); + assertEquals("3 key L0 columns", 3, params.mNumColumns); + assertEquals("3 key L0 rows", 1, params.mNumRows); + assertEquals("3 key L0 left", 0, params.mLeftKeys); + assertEquals("3 key L0 right", 3, params.mRightKeys); + assertEquals("3 key L0 [1]", 0, params.getColumnPos(0)); + assertEquals("3 key L0 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key L0 [3]", 2, params.getColumnPos(2)); + assertEquals("3 key L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [1] [2] [3] + public void testLayout3KeyL1() { + MiniKeyboardParams params = new MiniKeyboardParams(3, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L1, KEYBOARD_WIDTH); + assertEquals("3 key L1 columns", 3, params.mNumColumns); + assertEquals("3 key L1 rows", 1, params.mNumRows); + assertEquals("3 key L1 left", 0, params.mLeftKeys); + assertEquals("3 key L1 right", 3, params.mRightKeys); + assertEquals("3 key L1 [1]", 0, params.getColumnPos(0)); + assertEquals("3 key L1 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key L1 [3]", 2, params.getColumnPos(2)); + assertEquals("3 key L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ ___ [3] [1] [2] + public void testLayout3KeyL2() { + MiniKeyboardParams params = new MiniKeyboardParams(3, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L2, KEYBOARD_WIDTH); + assertEquals("3 key L2 columns", 3, params.mNumColumns); + assertEquals("3 key L2 rows", 1, params.mNumRows); + assertEquals("3 key L2 left", 1, params.mLeftKeys); + assertEquals("3 key L2 right", 2, params.mRightKeys); + assertEquals("3 key L2 [1]", 0, params.getColumnPos(0)); + assertEquals("3 key L2 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key L2 [3]", -1, params.getColumnPos(2)); + assertEquals("3 key L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [3] [2] [1]| + public void testLayout3KeyR0() { + MiniKeyboardParams params = new MiniKeyboardParams(3, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R0, KEYBOARD_WIDTH); + assertEquals("3 key R0 columns", 3, params.mNumColumns); + assertEquals("3 key R0 rows", 1, params.mNumRows); + assertEquals("3 key R0 left", 2, params.mLeftKeys); + assertEquals("3 key R0 right", 1, params.mRightKeys); + assertEquals("3 key R0 [1]", 0, params.getColumnPos(0)); + assertEquals("3 key R0 [2]", -1, params.getColumnPos(1)); + assertEquals("3 key R0 [3]", -2, params.getColumnPos(2)); + assertEquals("3 key R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key R0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [3] [2] [1] ___| + public void testLayout3KeyR1() { + MiniKeyboardParams params = new MiniKeyboardParams(3, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R1, KEYBOARD_WIDTH); + assertEquals("3 key R1 columns", 3, params.mNumColumns); + assertEquals("3 key R1 rows", 1, params.mNumRows); + assertEquals("3 key R1 left", 2, params.mLeftKeys); + assertEquals("3 key R1 right", 1, params.mRightKeys); + assertEquals("3 key R1 [1]", 0, params.getColumnPos(0)); + assertEquals("3 key R1 [2]", -1, params.getColumnPos(1)); + assertEquals("3 key R1 [3]", -2, params.getColumnPos(2)); + assertEquals("3 key R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key R1 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [3] [1] [2] ___ ___| + public void testLayout3KeyR2() { + MiniKeyboardParams params = new MiniKeyboardParams(3, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R2, KEYBOARD_WIDTH); + assertEquals("3 key R2 columns", 3, params.mNumColumns); + assertEquals("3 key R2 rows", 1, params.mNumRows); + assertEquals("3 key R2 left", 1, params.mLeftKeys); + assertEquals("3 key R2 right", 2, params.mRightKeys); + assertEquals("3 key R2 [1]", 0, params.getColumnPos(0)); + assertEquals("3 key R2 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key R2 [3]", -1, params.getColumnPos(2)); + assertEquals("3 key R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key R2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [3] [1] [2] [4] + public void testLayout4KeyM0() { + MiniKeyboardParams params = new MiniKeyboardParams(4, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_M0, KEYBOARD_WIDTH); + 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 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |[1] [2] [3] [4] + public void testLayout4KeyL0() { + MiniKeyboardParams params = new MiniKeyboardParams(4, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L0, KEYBOARD_WIDTH); + assertEquals("4 key L0 columns", 4, params.mNumColumns); + assertEquals("4 key L0 rows", 1, params.mNumRows); + assertEquals("4 key L0 left", 0, params.mLeftKeys); + assertEquals("4 key L0 right", 4, params.mRightKeys); + assertEquals("4 key L0 [1]", 0, params.getColumnPos(0)); + assertEquals("4 key L0 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key L0 [3]", 2, params.getColumnPos(2)); + assertEquals("4 key L0 [4]", 3, params.getColumnPos(3)); + assertEquals("4 key L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [1] [2] [3] [4] + public void testLayout4KeyL1() { + MiniKeyboardParams params = new MiniKeyboardParams(4, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L1, KEYBOARD_WIDTH); + assertEquals("4 key L1 columns", 4, params.mNumColumns); + assertEquals("4 key L1 rows", 1, params.mNumRows); + assertEquals("4 key L1 left", 0, params.mLeftKeys); + assertEquals("4 key L1 right", 4, params.mRightKeys); + assertEquals("4 key L1 [1]", 0, params.getColumnPos(0)); + assertEquals("4 key L1 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key L1 [3]", 2, params.getColumnPos(2)); + assertEquals("4 key L1 [4]", 3, params.getColumnPos(3)); + assertEquals("4 key L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ ___ [3] [1] [2] [4] + public void testLayout4KeyL2() { + MiniKeyboardParams params = new MiniKeyboardParams(4, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L2, KEYBOARD_WIDTH); + assertEquals("4 key L2 columns", 4, params.mNumColumns); + assertEquals("4 key L2 rows", 1, params.mNumRows); + assertEquals("4 key L2 left", 1, params.mLeftKeys); + assertEquals("4 key L2 right", 3, params.mRightKeys); + assertEquals("4 key L2 [1]", 0, params.getColumnPos(0)); + assertEquals("4 key L2 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key L2 [3]", -1, params.getColumnPos(2)); + assertEquals("4 key L2 [4]", 2, params.getColumnPos(3)); + assertEquals("4 key L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [4] [3] [2] [1]| + public void testLayout4KeyR0() { + MiniKeyboardParams params = new MiniKeyboardParams(4, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R0, KEYBOARD_WIDTH); + assertEquals("4 key R0 columns", 4, params.mNumColumns); + assertEquals("4 key R0 rows", 1, params.mNumRows); + assertEquals("4 key R0 left", 3, params.mLeftKeys); + assertEquals("4 key R0 right", 1, params.mRightKeys); + assertEquals("4 key R0 [1]", 0, params.getColumnPos(0)); + assertEquals("4 key R0 [2]", -1, params.getColumnPos(1)); + assertEquals("4 key R0 [3]", -2, params.getColumnPos(2)); + assertEquals("4 key R0 [4]", -3, params.getColumnPos(3)); + assertEquals("4 key R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key R0 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [4] [3] [2] [1] ___| + public void testLayout4KeyR1() { + MiniKeyboardParams params = new MiniKeyboardParams(4, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R1, KEYBOARD_WIDTH); + assertEquals("4 key R1 columns", 4, params.mNumColumns); + assertEquals("4 key R1 rows", 1, params.mNumRows); + assertEquals("4 key R1 left", 3, params.mLeftKeys); + assertEquals("4 key R1 right", 1, params.mRightKeys); + assertEquals("4 key R1 [1]", 0, params.getColumnPos(0)); + assertEquals("4 key R1 [2]", -1, params.getColumnPos(1)); + assertEquals("4 key R1 [3]", -2, params.getColumnPos(2)); + assertEquals("4 key R1 [4]", -3, params.getColumnPos(3)); + assertEquals("4 key R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key R1 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [4] [3] [1] [2] ___ ___| + public void testLayout4KeyR2() { + MiniKeyboardParams params = new MiniKeyboardParams(4, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R2, KEYBOARD_WIDTH); + assertEquals("4 key R2 columns", 4, params.mNumColumns); + assertEquals("4 key R2 rows", 1, params.mNumRows); + assertEquals("4 key R2 left", 2, params.mLeftKeys); + assertEquals("4 key R2 right", 2, params.mRightKeys); + assertEquals("4 key R2 [1]", 0, params.getColumnPos(0)); + assertEquals("4 key R2 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key R2 [3]", -1, params.getColumnPos(2)); + assertEquals("4 key R2 [4]", -2, params.getColumnPos(3)); + assertEquals("4 key R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key R2 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [5] [3] [1] [2] [4] + public void testLayout5KeyM0() { + MiniKeyboardParams params = new MiniKeyboardParams(5, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_M0, KEYBOARD_WIDTH); + 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 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // |[1] [2] [3] [4] [5] + public void testLayout5KeyL0() { + MiniKeyboardParams params = new MiniKeyboardParams(5, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L0, KEYBOARD_WIDTH); + assertEquals("5 key L0 columns", 5, params.mNumColumns); + assertEquals("5 key L0 rows", 1, params.mNumRows); + assertEquals("5 key L0 left", 0, params.mLeftKeys); + assertEquals("5 key L0 right", 5, params.mRightKeys); + assertEquals("5 key L0 [1]", 0, params.getColumnPos(0)); + assertEquals("5 key L0 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key L0 [3]", 2, params.getColumnPos(2)); + assertEquals("5 key L0 [4]", 3, params.getColumnPos(3)); + assertEquals("5 key L0 [5]", 4, params.getColumnPos(4)); + assertEquals("5 key L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [1] [2] [3] [4] [5] + public void testLayout5KeyL1() { + MiniKeyboardParams params = new MiniKeyboardParams(5, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L1, KEYBOARD_WIDTH); + assertEquals("5 key L1 columns", 5, params.mNumColumns); + assertEquals("5 key L1 rows", 1, params.mNumRows); + assertEquals("5 key L1 left", 0, params.mLeftKeys); + assertEquals("5 key L1 right", 5, params.mRightKeys); + assertEquals("5 key L1 [1]", 0, params.getColumnPos(0)); + assertEquals("5 key L1 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key L1 [3]", 2, params.getColumnPos(2)); + assertEquals("5 key L1 [4]", 3, params.getColumnPos(3)); + assertEquals("5 key L1 [5]", 4, params.getColumnPos(4)); + assertEquals("5 key L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ ___ [3] [1] [2] [4] [5] + public void testLayout5KeyL2() { + MiniKeyboardParams params = new MiniKeyboardParams(5, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L2, KEYBOARD_WIDTH); + assertEquals("5 key L2 columns", 5, params.mNumColumns); + assertEquals("5 key L2 rows", 1, params.mNumRows); + assertEquals("5 key L2 left", 1, params.mLeftKeys); + assertEquals("5 key L2 right", 4, params.mRightKeys); + assertEquals("5 key L2 [1]", 0, params.getColumnPos(0)); + assertEquals("5 key L2 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key L2 [3]", -1, params.getColumnPos(2)); + assertEquals("5 key L2 [4]", 2, params.getColumnPos(3)); + assertEquals("5 key L2 [5]", 3, params.getColumnPos(4)); + assertEquals("5 key L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [5] [4] [3] [2] [1]| + public void testLayout5KeyR0() { + MiniKeyboardParams params = new MiniKeyboardParams(5, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R0, KEYBOARD_WIDTH); + assertEquals("5 key R0 columns", 5, params.mNumColumns); + assertEquals("5 key R0 rows", 1, params.mNumRows); + assertEquals("5 key R0 left", 4, params.mLeftKeys); + assertEquals("5 key R0 right", 1, params.mRightKeys); + assertEquals("5 key R0 [1]", 0, params.getColumnPos(0)); + assertEquals("5 key R0 [2]", -1, params.getColumnPos(1)); + assertEquals("5 key R0 [3]", -2, params.getColumnPos(2)); + assertEquals("5 key R0 [4]", -3, params.getColumnPos(3)); + assertEquals("5 key R0 [5]", -4, params.getColumnPos(4)); + assertEquals("5 key R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key R0 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [5] [4] [3] [2] [1] ___| + public void testLayout5KeyR1() { + MiniKeyboardParams params = new MiniKeyboardParams(5, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R1, KEYBOARD_WIDTH); + assertEquals("5 key R1 columns", 5, params.mNumColumns); + assertEquals("5 key R1 rows", 1, params.mNumRows); + assertEquals("5 key R1 left", 4, params.mLeftKeys); + assertEquals("5 key R1 right", 1, params.mRightKeys); + assertEquals("5 key R1 [1]", 0, params.getColumnPos(0)); + assertEquals("5 key R1 [2]", -1, params.getColumnPos(1)); + assertEquals("5 key R1 [3]", -2, params.getColumnPos(2)); + assertEquals("5 key R1 [4]", -3, params.getColumnPos(3)); + assertEquals("5 key R1 [5]", -4, params.getColumnPos(4)); + assertEquals("5 key R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key R1 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [5] [4] [3] [1] [2] ___ ___| + public void testLayout5KeyR2() { + MiniKeyboardParams params = new MiniKeyboardParams(5, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R2, KEYBOARD_WIDTH); + assertEquals("5 key R2 columns", 5, params.mNumColumns); + assertEquals("5 key R2 rows", 1, params.mNumRows); + assertEquals("5 key R2 left", 3, params.mLeftKeys); + assertEquals("5 key R2 right", 2, params.mRightKeys); + assertEquals("5 key R2 [1]", 0, params.getColumnPos(0)); + assertEquals("5 key R2 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key R2 [3]", -1, params.getColumnPos(2)); + assertEquals("5 key R2 [4]", -2, params.getColumnPos(3)); + assertEquals("5 key R2 [5]", -3, params.getColumnPos(4)); + assertEquals("5 key R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key R2 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [6] [4] [5] + // [3] [1] [2] + public void testLayout6KeyM0() { + MiniKeyboardParams params = new MiniKeyboardParams(6, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_M0, KEYBOARD_WIDTH); + assertEquals("6 key columns", 3, params.mNumColumns); + assertEquals("6 key rows", 2, params.mNumRows); + assertEquals("6 key left", 1, params.mLeftKeys); + assertEquals("6 key right", 2, 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]", 0, params.getColumnPos(3)); + assertEquals("6 key [5]", 1, params.getColumnPos(4)); + assertEquals("6 key [6]", -1, params.getColumnPos(5)); + assertEquals("6 key adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |[4] [5] [6] + // |[1] [2] [3] + public void testLayout6KeyL0() { + MiniKeyboardParams params = new MiniKeyboardParams(6, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L0, KEYBOARD_WIDTH); + assertEquals("6 key L0 columns", 3, params.mNumColumns); + assertEquals("6 key L0 rows", 2, params.mNumRows); + assertEquals("6 key L0 left", 0, params.mLeftKeys); + assertEquals("6 key L0 right", 3, params.mRightKeys); + assertEquals("6 key L0 [1]", 0, params.getColumnPos(0)); + assertEquals("6 key L0 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key L0 [3]", 2, params.getColumnPos(2)); + assertEquals("6 key L0 [4]", 0, params.getColumnPos(3)); + assertEquals("6 key L0 [5]", 1, params.getColumnPos(4)); + assertEquals("6 key L0 [6]", 2, params.getColumnPos(5)); + assertEquals("6 key L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [4] [5] [6] + // |___ [1] [2] [3] + public void testLayout6KeyL1() { + MiniKeyboardParams params = new MiniKeyboardParams(6, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L1, KEYBOARD_WIDTH); + assertEquals("6 key L1 columns", 3, params.mNumColumns); + assertEquals("6 key L1 rows", 2, params.mNumRows); + assertEquals("6 key L1 left", 0, params.mLeftKeys); + assertEquals("6 key L1 right", 3, params.mRightKeys); + assertEquals("6 key L1 [1]", 0, params.getColumnPos(0)); + assertEquals("6 key L1 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key L1 [3]", 2, params.getColumnPos(2)); + assertEquals("6 key L1 [4]", 0, params.getColumnPos(3)); + assertEquals("6 key L1 [5]", 1, params.getColumnPos(4)); + assertEquals("6 key L1 [6]", 2, params.getColumnPos(5)); + assertEquals("6 key L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ ___ [6] [4] [5] + // |___ ___ [3] [1] [2] + public void testLayout6KeyL2() { + MiniKeyboardParams params = new MiniKeyboardParams(6, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L2, KEYBOARD_WIDTH); + assertEquals("6 key L2 columns", 3, params.mNumColumns); + assertEquals("6 key L2 rows", 2, params.mNumRows); + assertEquals("6 key L2 left", 1, params.mLeftKeys); + assertEquals("6 key L2 right", 2, params.mRightKeys); + assertEquals("6 key L2 [1]", 0, params.getColumnPos(0)); + assertEquals("6 key L2 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key L2 [3]", -1, params.getColumnPos(2)); + assertEquals("6 key L2 [4]", 0, params.getColumnPos(3)); + assertEquals("6 key L2 [5]", 1, params.getColumnPos(4)); + assertEquals("6 key L2 [6]", -1, params.getColumnPos(5)); + assertEquals("6 key L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [6] [5] [4]| + // [3] [2] [1]| + public void testLayout6KeyR0() { + MiniKeyboardParams params = new MiniKeyboardParams(6, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R0, KEYBOARD_WIDTH); + assertEquals("6 key R0 columns", 3, params.mNumColumns); + assertEquals("6 key R0 rows", 2, params.mNumRows); + assertEquals("6 key R0 left", 2, params.mLeftKeys); + assertEquals("6 key R0 right", 1, params.mRightKeys); + assertEquals("6 key R0 [1]", 0, params.getColumnPos(0)); + assertEquals("6 key R0 [2]", -1, params.getColumnPos(1)); + assertEquals("6 key R0 [3]", -2, params.getColumnPos(2)); + assertEquals("6 key R0 [4]", 0, params.getColumnPos(3)); + assertEquals("6 key R0 [5]", -1, params.getColumnPos(4)); + assertEquals("6 key R0 [6]", -2, params.getColumnPos(5)); + assertEquals("6 key R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key R0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [6] [5] [4] ___| + // [3] [2] [1] ___| + public void testLayout6KeyR1() { + MiniKeyboardParams params = new MiniKeyboardParams(6, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R1, KEYBOARD_WIDTH); + assertEquals("6 key R1 columns", 3, params.mNumColumns); + assertEquals("6 key R1 rows", 2, params.mNumRows); + assertEquals("6 key R1 left", 2, params.mLeftKeys); + assertEquals("6 key R1 right", 1, params.mRightKeys); + assertEquals("6 key R1 [1]", 0, params.getColumnPos(0)); + assertEquals("6 key R1 [2]", -1, params.getColumnPos(1)); + assertEquals("6 key R1 [3]", -2, params.getColumnPos(2)); + assertEquals("6 key R1 [4]", 0, params.getColumnPos(3)); + assertEquals("6 key R1 [5]", -1, params.getColumnPos(4)); + assertEquals("6 key R1 [6]", -2, params.getColumnPos(5)); + assertEquals("6 key R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key R1 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [6] [4] [5] ___ ___| + // [3] [1] [2] ___ ___| + public void testLayout6KeyR2() { + MiniKeyboardParams params = new MiniKeyboardParams(6, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R2, KEYBOARD_WIDTH); + assertEquals("6 key R2 columns", 3, params.mNumColumns); + assertEquals("6 key R2 rows", 2, params.mNumRows); + assertEquals("6 key R2 left", 1, params.mLeftKeys); + assertEquals("6 key R2 right", 2, params.mRightKeys); + assertEquals("6 key R2 [1]", 0, params.getColumnPos(0)); + assertEquals("6 key R2 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key R2 [3]", -1, params.getColumnPos(2)); + assertEquals("6 key R2 [4]", 0, params.getColumnPos(3)); + assertEquals("6 key R2 [5]", 1, params.getColumnPos(4)); + assertEquals("6 key R2 [6]", -1, params.getColumnPos(5)); + assertEquals("6 key R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key R2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [7] [5] [6] + // [3] [1] [2] [4] + public void testLayout7KeyM0() { + MiniKeyboardParams params = new MiniKeyboardParams(7, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_M0, KEYBOARD_WIDTH); + assertEquals("7 key columns", 4, params.mNumColumns); + assertEquals("7 key rows", 2, params.mNumRows); + assertEquals("7 key left", 1, 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]", 0, params.getColumnPos(4)); + assertEquals("7 key [6]", 1, params.getColumnPos(5)); + assertEquals("7 key [7]", -1, params.getColumnPos(6)); + assertEquals("7 key adjust", 1, params.mTopRowAdjustment); + assertEquals("7 key default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |[5] [6] [7] + // |[1] [2] [3] [4] + public void testLayout7KeyL0() { + MiniKeyboardParams params = new MiniKeyboardParams(7, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L0, KEYBOARD_WIDTH); + assertEquals("7 key L0 columns", 4, params.mNumColumns); + assertEquals("7 key L0 rows", 2, params.mNumRows); + assertEquals("7 key L0 left", 0, params.mLeftKeys); + assertEquals("7 key L0 right", 4, params.mRightKeys); + assertEquals("7 key L0 [1]", 0, params.getColumnPos(0)); + assertEquals("7 key L0 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key L0 [3]", 2, params.getColumnPos(2)); + assertEquals("7 key L0 [4]", 3, params.getColumnPos(3)); + assertEquals("7 key L0 [5]", 0, params.getColumnPos(4)); + assertEquals("7 key L0 [6]", 1, params.getColumnPos(5)); + assertEquals("7 key L0 [7]", 2, params.getColumnPos(6)); + assertEquals("7 key L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [5] [6] [7] + // |___ [1] [2] [3] [4] + public void testLayout7KeyL1() { + MiniKeyboardParams params = new MiniKeyboardParams(7, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L1, KEYBOARD_WIDTH); + assertEquals("7 key L1 columns", 4, params.mNumColumns); + assertEquals("7 key L1 rows", 2, params.mNumRows); + assertEquals("7 key L1 left", 0, params.mLeftKeys); + assertEquals("7 key L1 right", 4, params.mRightKeys); + assertEquals("7 key L1 [1]", 0, params.getColumnPos(0)); + assertEquals("7 key L1 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key L1 [3]", 2, params.getColumnPos(2)); + assertEquals("7 key L1 [4]", 3, params.getColumnPos(3)); + assertEquals("7 key L1 [5]", 0, params.getColumnPos(4)); + assertEquals("7 key L1 [6]", 1, params.getColumnPos(5)); + assertEquals("7 key L1 [7]", 2, params.getColumnPos(6)); + assertEquals("7 key L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ ___ [7] [5] [6] + // |___ ___ [3] [1] [2] [4] + public void testLayout7KeyL2() { + MiniKeyboardParams params = new MiniKeyboardParams(7, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L2, KEYBOARD_WIDTH); + assertEquals("7 key L2 columns", 4, params.mNumColumns); + assertEquals("7 key L2 rows", 2, params.mNumRows); + assertEquals("7 key L2 left", 1, params.mLeftKeys); + assertEquals("7 key L2 right", 3, params.mRightKeys); + assertEquals("7 key L2 [1]", 0, params.getColumnPos(0)); + assertEquals("7 key L2 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key L2 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key L2 [4]", 2, params.getColumnPos(3)); + assertEquals("7 key L2 [5]", 0, params.getColumnPos(4)); + assertEquals("7 key L2 [6]", 1, params.getColumnPos(5)); + assertEquals("7 key L2 [7]", -1, params.getColumnPos(6)); + assertEquals("7 key L2 adjust", 1, params.mTopRowAdjustment); + assertEquals("7 key L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [7] [6] [5]| + // [4] [3] [2] [1]| + public void testLayout7KeyR0() { + MiniKeyboardParams params = new MiniKeyboardParams(7, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R0, KEYBOARD_WIDTH); + assertEquals("7 key R0 columns", 4, params.mNumColumns); + assertEquals("7 key R0 rows", 2, params.mNumRows); + assertEquals("7 key R0 left", 3, params.mLeftKeys); + assertEquals("7 key R0 right", 1, params.mRightKeys); + assertEquals("7 key R0 [1]", 0, params.getColumnPos(0)); + assertEquals("7 key R0 [2]", -1, params.getColumnPos(1)); + assertEquals("7 key R0 [3]", -2, params.getColumnPos(2)); + assertEquals("7 key R0 [4]", -3, params.getColumnPos(3)); + assertEquals("7 key R0 [5]", 0, params.getColumnPos(4)); + assertEquals("7 key R0 [6]", -1, params.getColumnPos(5)); + assertEquals("7 key R0 [7]", -2, params.getColumnPos(6)); + assertEquals("7 key R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key R0 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [7] [6] [5] ___| + // [4] [3] [2] [1] ___| + public void testLayout7KeyR1() { + MiniKeyboardParams params = new MiniKeyboardParams(7, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R1, KEYBOARD_WIDTH); + assertEquals("7 key R1 columns", 4, params.mNumColumns); + assertEquals("7 key R1 rows", 2, params.mNumRows); + assertEquals("7 key R1 left", 3, params.mLeftKeys); + assertEquals("7 key R1 right", 1, params.mRightKeys); + assertEquals("7 key R1 [1]", 0, params.getColumnPos(0)); + assertEquals("7 key R1 [2]", -1, params.getColumnPos(1)); + assertEquals("7 key R1 [3]", -2, params.getColumnPos(2)); + assertEquals("7 key R1 [4]", -3, params.getColumnPos(3)); + assertEquals("7 key R1 [5]", 0, params.getColumnPos(4)); + assertEquals("7 key R1 [6]", -1, params.getColumnPos(5)); + assertEquals("7 key R1 [7]", -2, params.getColumnPos(6)); + assertEquals("7 key R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key R1 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [7] [5] [6] ___ ___| + // [4] [3] [1] [2] ___ ___| + public void testLayout7KeyR2() { + MiniKeyboardParams params = new MiniKeyboardParams(7, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R2, KEYBOARD_WIDTH); + assertEquals("7 key R2 columns", 4, params.mNumColumns); + assertEquals("7 key R2 rows", 2, params.mNumRows); + assertEquals("7 key R2 left", 2, params.mLeftKeys); + assertEquals("7 key R2 right", 2, params.mRightKeys); + assertEquals("7 key R2 [1]", 0, params.getColumnPos(0)); + assertEquals("7 key R2 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key R2 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key R2 [4]", -2, params.getColumnPos(3)); + assertEquals("7 key R2 [5]", 0, params.getColumnPos(4)); + assertEquals("7 key R2 [6]", 1, params.getColumnPos(5)); + assertEquals("7 key R2 [7]", -1, params.getColumnPos(6)); + assertEquals("7 key R2 adjust", -1, params.mTopRowAdjustment); + assertEquals("7 key R2 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [7] [6] [5] [3] [1] [2] [4] ___| + public void testLayout7KeyR3Max7() { + MiniKeyboardParams params = new MiniKeyboardParams(7, 7, WIDTH, + HEIGHT, XPOS_R3, KEYBOARD_WIDTH); + assertEquals("7 key R2 columns", 7, params.mNumColumns); + assertEquals("7 key R2 rows", 1, params.mNumRows); + assertEquals("7 key R2 left", 4, params.mLeftKeys); + assertEquals("7 key R2 right", 3, params.mRightKeys); + assertEquals("7 key R2 [1]", 0, params.getColumnPos(0)); + assertEquals("7 key R2 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key R2 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key R2 [4]", 2, params.getColumnPos(3)); + assertEquals("7 key R2 [5]", -2, params.getColumnPos(4)); + assertEquals("7 key R2 [6]", -3, params.getColumnPos(5)); + assertEquals("7 key R2 [7]", -4, params.getColumnPos(6)); + assertEquals("7 key R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key R2 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [7] [5] [6] [8] + // [3] [1] [2] [4] + public void testLayout8KeyM0() { + MiniKeyboardParams params = new MiniKeyboardParams(8, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_M0, KEYBOARD_WIDTH); + assertEquals("8 key M0 columns", 4, params.mNumColumns); + assertEquals("8 key M0 rows", 2, params.mNumRows); + assertEquals("8 key M0 left", 1, params.mLeftKeys); + assertEquals("8 key M0 right", 3, params.mRightKeys); + assertEquals("8 key M0 [1]", 0, params.getColumnPos(0)); + assertEquals("8 key M0 [2]", 1, params.getColumnPos(1)); + assertEquals("8 key M0 [3]", -1, params.getColumnPos(2)); + assertEquals("8 key M0 [4]", 2, params.getColumnPos(3)); + assertEquals("8 key M0 [5]", 0, params.getColumnPos(4)); + assertEquals("8 key M0 [6]", 1, params.getColumnPos(5)); + assertEquals("8 key M0 [7]", -1, params.getColumnPos(6)); + assertEquals("8 key M0 [8]", 2, params.getColumnPos(7)); + assertEquals("8 key M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |[5] [6] [7] [8] + // |[1] [2] [3] [4] + public void testLayout8KeyL0() { + MiniKeyboardParams params = new MiniKeyboardParams(8, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L0, KEYBOARD_WIDTH); + assertEquals("8 key L0 columns", 4, params.mNumColumns); + assertEquals("8 key L0 rows", 2, params.mNumRows); + assertEquals("8 key L0 left", 0, params.mLeftKeys); + assertEquals("8 key L0 right", 4, params.mRightKeys); + assertEquals("8 key L0 [1]", 0, params.getColumnPos(0)); + assertEquals("8 key L0 [2]", 1, params.getColumnPos(1)); + assertEquals("8 key L0 [3]", 2, params.getColumnPos(2)); + assertEquals("8 key L0 [4]", 3, params.getColumnPos(3)); + assertEquals("8 key L0 [5]", 0, params.getColumnPos(4)); + assertEquals("8 key L0 [6]", 1, params.getColumnPos(5)); + assertEquals("8 key L0 [7]", 2, params.getColumnPos(6)); + assertEquals("8 key L0 [8]", 3, params.getColumnPos(7)); + assertEquals("8 key L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [5] [6] [7] [8] + // |___ [1] [2] [3] [4] + public void testLayout8KeyL1() { + MiniKeyboardParams params = new MiniKeyboardParams(8, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L1, KEYBOARD_WIDTH); + assertEquals("8 key L1 columns", 4, params.mNumColumns); + assertEquals("8 key L1 rows", 2, params.mNumRows); + assertEquals("8 key L1 left", 0, params.mLeftKeys); + assertEquals("8 key L1 right", 4, params.mRightKeys); + assertEquals("8 key L1 [1]", 0, params.getColumnPos(0)); + assertEquals("8 key L1 [2]", 1, params.getColumnPos(1)); + assertEquals("8 key L1 [3]", 2, params.getColumnPos(2)); + assertEquals("8 key L1 [4]", 3, params.getColumnPos(3)); + assertEquals("8 key L1 [5]", 0, params.getColumnPos(4)); + assertEquals("8 key L1 [6]", 1, params.getColumnPos(5)); + assertEquals("8 key L1 [7]", 2, params.getColumnPos(6)); + assertEquals("8 key L1 [8]", 3, params.getColumnPos(7)); + assertEquals("8 key L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ ___ [7] [5] [6] [8] + // |___ ___ [3] [1] [2] [4] + public void testLayout8KeyL2() { + MiniKeyboardParams params = new MiniKeyboardParams(8, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L2, KEYBOARD_WIDTH); + assertEquals("8 key L2 columns", 4, params.mNumColumns); + assertEquals("8 key L2 rows", 2, params.mNumRows); + assertEquals("8 key L2 left", 1, params.mLeftKeys); + assertEquals("8 key L2 right", 3, params.mRightKeys); + assertEquals("8 key L2 [1]", 0, params.getColumnPos(0)); + assertEquals("8 key L2 [2]", 1, params.getColumnPos(1)); + assertEquals("8 key L2 [3]", -1, params.getColumnPos(2)); + assertEquals("8 key L2 [4]", 2, params.getColumnPos(3)); + assertEquals("8 key L2 [5]", 0, params.getColumnPos(4)); + assertEquals("8 key L2 [6]", 1, params.getColumnPos(5)); + assertEquals("8 key L2 [7]", -1, params.getColumnPos(6)); + assertEquals("8 key L2 [8]", 2, params.getColumnPos(7)); + assertEquals("8 key L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [8] [7] [6] [5]| + // [4] [3] [2] [1]| + public void testLayout8KeyR0() { + MiniKeyboardParams params = new MiniKeyboardParams(8, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R0, KEYBOARD_WIDTH); + assertEquals("8 key R0 columns", 4, params.mNumColumns); + assertEquals("8 key R0 rows", 2, params.mNumRows); + assertEquals("8 key R0 left", 3, params.mLeftKeys); + assertEquals("8 key R0 right", 1, params.mRightKeys); + assertEquals("8 key R0 [1]", 0, params.getColumnPos(0)); + assertEquals("8 key R0 [2]", -1, params.getColumnPos(1)); + assertEquals("8 key R0 [3]", -2, params.getColumnPos(2)); + assertEquals("8 key R0 [4]", -3, params.getColumnPos(3)); + assertEquals("8 key R0 [5]", 0, params.getColumnPos(4)); + assertEquals("8 key R0 [6]", -1, params.getColumnPos(5)); + assertEquals("8 key R0 [7]", -2, params.getColumnPos(6)); + assertEquals("8 key R0 [8]", -3, params.getColumnPos(7)); + assertEquals("8 key R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key R0 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [8] [7] [6] [5] ___| + // [4] [3] [2] [1] ___| + public void testLayout8KeyR1() { + MiniKeyboardParams params = new MiniKeyboardParams(8, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R1, KEYBOARD_WIDTH); + assertEquals("8 key R1 columns", 4, params.mNumColumns); + assertEquals("8 key R1 rows", 2, params.mNumRows); + assertEquals("8 key R1 left", 3, params.mLeftKeys); + assertEquals("8 key R1 right", 1, params.mRightKeys); + assertEquals("8 key R1 [1]", 0, params.getColumnPos(0)); + assertEquals("8 key R1 [2]", -1, params.getColumnPos(1)); + assertEquals("8 key R1 [3]", -2, params.getColumnPos(2)); + assertEquals("8 key R1 [4]", -3, params.getColumnPos(3)); + assertEquals("8 key R1 [5]", 0, params.getColumnPos(4)); + assertEquals("8 key R1 [6]", -1, params.getColumnPos(5)); + assertEquals("8 key R1 [7]", -2, params.getColumnPos(6)); + assertEquals("8 key R1 [8]", -3, params.getColumnPos(7)); + assertEquals("8 key R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key R1 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [8] [7] [5] [6] ___ ___| + // [4] [3] [1] [2] ___ ___| + public void testLayout8KeyR2() { + MiniKeyboardParams params = new MiniKeyboardParams(8, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R2, KEYBOARD_WIDTH); + assertEquals("8 key R2 columns", 4, params.mNumColumns); + assertEquals("8 key R2 rows", 2, params.mNumRows); + assertEquals("8 key R2 left", 2, params.mLeftKeys); + assertEquals("8 key R2 right", 2, params.mRightKeys); + assertEquals("8 key R2 [1]", 0, params.getColumnPos(0)); + assertEquals("8 key R2 [2]", 1, params.getColumnPos(1)); + assertEquals("8 key R2 [3]", -1, params.getColumnPos(2)); + assertEquals("8 key R2 [4]", -2, params.getColumnPos(3)); + assertEquals("8 key R2 [5]", 0, params.getColumnPos(4)); + assertEquals("8 key R2 [6]", 1, params.getColumnPos(5)); + assertEquals("8 key R2 [7]", -1, params.getColumnPos(6)); + assertEquals("8 key R2 [8]", -2, params.getColumnPos(7)); + assertEquals("8 key R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key R2 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [8] [6] [7] [9] + // [5] [3] [1] [2] [4] + public void testLayout9KeyM0() { + MiniKeyboardParams params = new MiniKeyboardParams(9, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_M0, KEYBOARD_WIDTH); + assertEquals("9 key M0 columns", 5, params.mNumColumns); + assertEquals("9 key M0 rows", 2, params.mNumRows); + assertEquals("9 key M0 left", 2, params.mLeftKeys); + assertEquals("9 key M0 right", 3, params.mRightKeys); + assertEquals("9 key M0 [1]", 0, params.getColumnPos(0)); + assertEquals("9 key M0 [2]", 1, params.getColumnPos(1)); + assertEquals("9 key M0 [3]", -1, params.getColumnPos(2)); + assertEquals("9 key M0 [4]", 2, params.getColumnPos(3)); + assertEquals("9 key M0 [5]", -2, params.getColumnPos(4)); + assertEquals("9 key M0 [6]", 0, params.getColumnPos(5)); + assertEquals("9 key M0 [7]", 1, params.getColumnPos(6)); + assertEquals("9 key M0 [8]", -1, params.getColumnPos(7)); + assertEquals("9 key M0 [9]", 2, params.getColumnPos(8)); + assertEquals("9 key M0 adjust", -1, params.mTopRowAdjustment); + assertEquals("9 key M0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // |[6] [7] [8] [9] + // |[1] [2] [3] [4] [5] + public void testLayout9KeyL0() { + MiniKeyboardParams params = new MiniKeyboardParams(9, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L0, KEYBOARD_WIDTH); + assertEquals("9 key L0 columns", 5, params.mNumColumns); + assertEquals("9 key L0 rows", 2, params.mNumRows); + assertEquals("9 key L0 left", 0, params.mLeftKeys); + assertEquals("9 key L0 right", 5, params.mRightKeys); + assertEquals("9 key L0 [1]", 0, params.getColumnPos(0)); + assertEquals("9 key L0 [2]", 1, params.getColumnPos(1)); + assertEquals("9 key L0 [3]", 2, params.getColumnPos(2)); + assertEquals("9 key L0 [4]", 3, params.getColumnPos(3)); + assertEquals("9 key L0 [5]", 4, params.getColumnPos(4)); + assertEquals("9 key L0 [6]", 0, params.getColumnPos(5)); + assertEquals("9 key L0 [7]", 1, params.getColumnPos(6)); + assertEquals("9 key L0 [8]", 2, params.getColumnPos(7)); + assertEquals("9 key L0 [9]", 3, params.getColumnPos(8)); + assertEquals("9 key L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("9 key L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [6] [7] [8] [9] + // |___ [1] [2] [3] [4] [5] + public void testLayout9KeyL1() { + MiniKeyboardParams params = new MiniKeyboardParams(9, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L1, KEYBOARD_WIDTH); + assertEquals("9 key L1 columns", 5, params.mNumColumns); + assertEquals("9 key L1 rows", 2, params.mNumRows); + assertEquals("9 key L1 left", 0, params.mLeftKeys); + assertEquals("9 key L1 right", 5, params.mRightKeys); + assertEquals("9 key L1 [1]", 0, params.getColumnPos(0)); + assertEquals("9 key L1 [2]", 1, params.getColumnPos(1)); + assertEquals("9 key L1 [3]", 2, params.getColumnPos(2)); + assertEquals("9 key L1 [4]", 3, params.getColumnPos(3)); + assertEquals("9 key L1 [5]", 4, params.getColumnPos(4)); + assertEquals("9 key L1 [6]", 0, params.getColumnPos(5)); + assertEquals("9 key L1 [7]", 1, params.getColumnPos(6)); + assertEquals("9 key L1 [8]", 2, params.getColumnPos(7)); + assertEquals("9 key L1 [9]", 3, params.getColumnPos(8)); + assertEquals("9 key L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("9 key L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ ___ [8] [6] [7] [9] + // |___ ___ [3] [1] [2] [4] [5] + public void testLayout9KeyL2() { + MiniKeyboardParams params = new MiniKeyboardParams(9, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L2, KEYBOARD_WIDTH); + assertEquals("9 key L2 columns", 5, params.mNumColumns); + assertEquals("9 key L2 rows", 2, params.mNumRows); + assertEquals("9 key L2 left", 1, params.mLeftKeys); + assertEquals("9 key L2 right", 4, params.mRightKeys); + assertEquals("9 key L2 [1]", 0, params.getColumnPos(0)); + assertEquals("9 key L2 [2]", 1, params.getColumnPos(1)); + assertEquals("9 key L2 [3]", -1, params.getColumnPos(2)); + assertEquals("9 key L2 [4]", 2, params.getColumnPos(3)); + assertEquals("9 key L2 [5]", 3, params.getColumnPos(4)); + assertEquals("9 key L2 [6]", 0, params.getColumnPos(5)); + assertEquals("9 key L2 [7]", 1, params.getColumnPos(6)); + assertEquals("9 key L2 [8]", -1, params.getColumnPos(7)); + assertEquals("9 key L2 [9]", 2, params.getColumnPos(8)); + assertEquals("9 key L2 adjust", 1, params.mTopRowAdjustment); + assertEquals("9 key L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [9] [8] [7] [6]| + // [5] [4] [3] [2] [1]| + public void testLayout9KeyR0() { + MiniKeyboardParams params = new MiniKeyboardParams(9, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R0, KEYBOARD_WIDTH); + assertEquals("9 key R0 columns", 5, params.mNumColumns); + assertEquals("9 key R0 rows", 2, params.mNumRows); + assertEquals("9 key R0 left", 4, params.mLeftKeys); + assertEquals("9 key R0 right", 1, params.mRightKeys); + assertEquals("9 key R0 [1]", 0, params.getColumnPos(0)); + assertEquals("9 key R0 [2]", -1, params.getColumnPos(1)); + assertEquals("9 key R0 [3]", -2, params.getColumnPos(2)); + assertEquals("9 key R0 [4]", -3, params.getColumnPos(3)); + assertEquals("9 key R0 [5]", -4, params.getColumnPos(4)); + assertEquals("9 key R0 [6]", 0, params.getColumnPos(5)); + assertEquals("9 key R0 [7]", -1, params.getColumnPos(6)); + assertEquals("9 key R0 [8]", -2, params.getColumnPos(7)); + assertEquals("9 key R0 [9]", -3, params.getColumnPos(8)); + assertEquals("9 key R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("9 key R0 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [9] [8] [7] [6] ___| + // [5] [4] [3] [2] [1] ___| + public void testLayout9KeyR1() { + MiniKeyboardParams params = new MiniKeyboardParams(9, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R1, KEYBOARD_WIDTH); + assertEquals("9 key R1 columns", 5, params.mNumColumns); + assertEquals("9 key R1 rows", 2, params.mNumRows); + assertEquals("9 key R1 left", 4, params.mLeftKeys); + assertEquals("9 key R1 right", 1, params.mRightKeys); + assertEquals("9 key R1 [1]", 0, params.getColumnPos(0)); + assertEquals("9 key R1 [2]", -1, params.getColumnPos(1)); + assertEquals("9 key R1 [3]", -2, params.getColumnPos(2)); + assertEquals("9 key R1 [4]", -3, params.getColumnPos(3)); + assertEquals("9 key R1 [5]", -4, params.getColumnPos(4)); + assertEquals("9 key R1 [6]", 0, params.getColumnPos(5)); + assertEquals("9 key R1 [7]", -1, params.getColumnPos(6)); + assertEquals("9 key R1 [8]", -2, params.getColumnPos(7)); + assertEquals("9 key R1 [9]", -3, params.getColumnPos(8)); + assertEquals("9 key R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("9 key R1 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [9] [8] [6] [7] ___ ___| + // [5] [4] [3] [1] [2] ___ ___| + public void testLayout9KeyR2() { + MiniKeyboardParams params = new MiniKeyboardParams(9, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R2, KEYBOARD_WIDTH); + assertEquals("9 key R2 columns", 5, params.mNumColumns); + assertEquals("9 key R2 rows", 2, params.mNumRows); + assertEquals("9 key R2 left", 3, params.mLeftKeys); + assertEquals("9 key R2 right", 2, params.mRightKeys); + assertEquals("9 key R2 [1]", 0, params.getColumnPos(0)); + assertEquals("9 key R2 [2]", 1, params.getColumnPos(1)); + assertEquals("9 key R2 [3]", -1, params.getColumnPos(2)); + assertEquals("9 key R2 [4]", -2, params.getColumnPos(3)); + assertEquals("9 key R2 [5]", -3, params.getColumnPos(4)); + assertEquals("9 key R2 [6]", 0, params.getColumnPos(5)); + assertEquals("9 key R2 [7]", 1, params.getColumnPos(6)); + assertEquals("9 key R2 [8]", -1, params.getColumnPos(7)); + assertEquals("9 key R2 [9]", -2, params.getColumnPos(8)); + assertEquals("9 key R2 adjust", -1, params.mTopRowAdjustment); + assertEquals("9 key R2 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [A] [8] [6] [7] [9] + // [5] [3] [1] [2] [4] + public void testLayout10KeyM0() { + MiniKeyboardParams params = new MiniKeyboardParams(10, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_M0, KEYBOARD_WIDTH); + assertEquals("10 key M0 columns", 5, params.mNumColumns); + assertEquals("10 key M0 rows", 2, params.mNumRows); + assertEquals("10 key M0 left", 2, params.mLeftKeys); + assertEquals("10 key M0 right", 3, params.mRightKeys); + assertEquals("10 key M0 [1]", 0, params.getColumnPos(0)); + assertEquals("10 key M0 [2]", 1, params.getColumnPos(1)); + assertEquals("10 key M0 [3]", -1, params.getColumnPos(2)); + assertEquals("10 key M0 [4]", 2, params.getColumnPos(3)); + assertEquals("10 key M0 [5]", -2, params.getColumnPos(4)); + assertEquals("10 key M0 [6]", 0, params.getColumnPos(5)); + assertEquals("10 key M0 [7]", 1, params.getColumnPos(6)); + assertEquals("10 key M0 [8]", -1, params.getColumnPos(7)); + assertEquals("10 key M0 [9]", 2, params.getColumnPos(8)); + assertEquals("10 key M0 [A]", -2, params.getColumnPos(9)); + assertEquals("10 key M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("10 key M0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // |[6] [7] [8] [9] [A] + // |[1] [2] [3] [4] [5] + public void testLayout10KeyL0() { + MiniKeyboardParams params = new MiniKeyboardParams(10, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L0, KEYBOARD_WIDTH); + assertEquals("10 key L0 columns", 5, params.mNumColumns); + assertEquals("10 key L0 rows", 2, params.mNumRows); + assertEquals("10 key L0 left", 0, params.mLeftKeys); + assertEquals("10 key L0 right", 5, params.mRightKeys); + assertEquals("10 key L0 [1]", 0, params.getColumnPos(0)); + assertEquals("10 key L0 [2]", 1, params.getColumnPos(1)); + assertEquals("10 key L0 [3]", 2, params.getColumnPos(2)); + assertEquals("10 key L0 [4]", 3, params.getColumnPos(3)); + assertEquals("10 key L0 [5]", 4, params.getColumnPos(4)); + assertEquals("10 key L0 [6]", 0, params.getColumnPos(5)); + assertEquals("10 key L0 [7]", 1, params.getColumnPos(6)); + assertEquals("10 key L0 [8]", 2, params.getColumnPos(7)); + assertEquals("10 key L0 [9]", 3, params.getColumnPos(8)); + assertEquals("10 key L0 [A]", 4, params.getColumnPos(9)); + assertEquals("10 key L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("10 key L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [6] [7] [8] [9] [A] + // |___ [1] [2] [3] [4] [5] + public void testLayout10KeyL1() { + MiniKeyboardParams params = new MiniKeyboardParams(10, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L1, KEYBOARD_WIDTH); + assertEquals("10 key L1 columns", 5, params.mNumColumns); + assertEquals("10 key L1 rows", 2, params.mNumRows); + assertEquals("10 key L1 left", 0, params.mLeftKeys); + assertEquals("10 key L1 right", 5, params.mRightKeys); + assertEquals("10 key L1 [1]", 0, params.getColumnPos(0)); + assertEquals("10 key L1 [2]", 1, params.getColumnPos(1)); + assertEquals("10 key L1 [3]", 2, params.getColumnPos(2)); + assertEquals("10 key L1 [4]", 3, params.getColumnPos(3)); + assertEquals("10 key L1 [5]", 4, params.getColumnPos(4)); + assertEquals("10 key L1 [6]", 0, params.getColumnPos(5)); + assertEquals("10 key L1 [7]", 1, params.getColumnPos(6)); + assertEquals("10 key L1 [8]", 2, params.getColumnPos(7)); + assertEquals("10 key L1 [9]", 3, params.getColumnPos(8)); + assertEquals("10 key L1 [A]", 4, params.getColumnPos(9)); + assertEquals("10 key L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("10 key L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ ___ [8] [6] [7] [9] [A] + // |___ ___ [3] [1] [2] [4] [5] + public void testLayout10KeyL2() { + MiniKeyboardParams params = new MiniKeyboardParams(10, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_L2, KEYBOARD_WIDTH); + assertEquals("10 key L2 columns", 5, params.mNumColumns); + assertEquals("10 key L2 rows", 2, params.mNumRows); + assertEquals("10 key L2 left", 1, params.mLeftKeys); + assertEquals("10 key L2 right", 4, params.mRightKeys); + assertEquals("10 key L2 [1]", 0, params.getColumnPos(0)); + assertEquals("10 key L2 [2]", 1, params.getColumnPos(1)); + assertEquals("10 key L2 [3]", -1, params.getColumnPos(2)); + assertEquals("10 key L2 [4]", 2, params.getColumnPos(3)); + assertEquals("10 key L2 [5]", 3, params.getColumnPos(4)); + assertEquals("10 key L2 [6]", 0, params.getColumnPos(5)); + assertEquals("10 key L2 [7]", 1, params.getColumnPos(6)); + assertEquals("10 key L2 [8]", -1, params.getColumnPos(7)); + assertEquals("10 key L2 [9]", 2, params.getColumnPos(8)); + assertEquals("10 key L2 [A]", 3, params.getColumnPos(9)); + assertEquals("10 key L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("10 key L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [A] [9] [8] [7] [6]| + // [5] [4] [3] [2] [1]| + public void testLayout10KeyR0() { + MiniKeyboardParams params = new MiniKeyboardParams(10, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R0, KEYBOARD_WIDTH); + assertEquals("10 key R0 columns", 5, params.mNumColumns); + assertEquals("10 key R0 rows", 2, params.mNumRows); + assertEquals("10 key R0 left", 4, params.mLeftKeys); + assertEquals("10 key R0 right", 1, params.mRightKeys); + assertEquals("10 key R0 [1]", 0, params.getColumnPos(0)); + assertEquals("10 key R0 [2]", -1, params.getColumnPos(1)); + assertEquals("10 key R0 [3]", -2, params.getColumnPos(2)); + assertEquals("10 key R0 [4]", -3, params.getColumnPos(3)); + assertEquals("10 key R0 [5]", -4, params.getColumnPos(4)); + assertEquals("10 key R0 [6]", 0, params.getColumnPos(5)); + assertEquals("10 key R0 [7]", -1, params.getColumnPos(6)); + assertEquals("10 key R0 [8]", -2, params.getColumnPos(7)); + assertEquals("10 key R0 [9]", -3, params.getColumnPos(8)); + assertEquals("10 key R0 [A]", -4, params.getColumnPos(9)); + assertEquals("10 key R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("10 key R0 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [A] [9] [8] [7] [6] ___| + // [5] [4] [3] [2] [1] ___| + public void testLayout10KeyR1() { + MiniKeyboardParams params = new MiniKeyboardParams(10, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R1, KEYBOARD_WIDTH); + assertEquals("10 key R1 columns", 5, params.mNumColumns); + assertEquals("10 key R1 rows", 2, params.mNumRows); + assertEquals("10 key R1 left", 4, params.mLeftKeys); + assertEquals("10 key R1 right", 1, params.mRightKeys); + assertEquals("10 key R1 [1]", 0, params.getColumnPos(0)); + assertEquals("10 key R1 [2]", -1, params.getColumnPos(1)); + assertEquals("10 key R1 [3]", -2, params.getColumnPos(2)); + assertEquals("10 key R1 [4]", -3, params.getColumnPos(3)); + assertEquals("10 key R1 [5]", -4, params.getColumnPos(4)); + assertEquals("10 key R1 [6]", 0, params.getColumnPos(5)); + assertEquals("10 key R1 [7]", -1, params.getColumnPos(6)); + assertEquals("10 key R1 [8]", -2, params.getColumnPos(7)); + assertEquals("10 key R1 [9]", -3, params.getColumnPos(8)); + assertEquals("10 key R1 [A]", -4, params.getColumnPos(9)); + assertEquals("10 key R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("10 key R1 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [A] [9] [8] [6] [7] ___ ___| + // [5] [4] [3] [1] [2] ___ ___| + public void testLayout10KeyR2() { + MiniKeyboardParams params = new MiniKeyboardParams(10, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_R2, KEYBOARD_WIDTH); + assertEquals("10 key R2 columns", 5, params.mNumColumns); + assertEquals("10 key R2 rows", 2, params.mNumRows); + assertEquals("10 key R2 left", 3, params.mLeftKeys); + assertEquals("10 key R2 right", 2, params.mRightKeys); + assertEquals("10 key R2 [1]", 0, params.getColumnPos(0)); + assertEquals("10 key R2 [2]", 1, params.getColumnPos(1)); + assertEquals("10 key R2 [3]", -1, params.getColumnPos(2)); + assertEquals("10 key R2 [4]", -2, params.getColumnPos(3)); + assertEquals("10 key R2 [5]", -3, params.getColumnPos(4)); + assertEquals("10 key R2 [6]", 0, params.getColumnPos(5)); + assertEquals("10 key R2 [7]", 1, params.getColumnPos(6)); + assertEquals("10 key R2 [8]", -1, params.getColumnPos(7)); + assertEquals("10 key R2 [9]", -2, params.getColumnPos(8)); + assertEquals("10 key R2 [A]", -3, params.getColumnPos(9)); + assertEquals("10 key R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("10 key R2 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [B] [9] [A] + // [7] [5] [6] [8] + // [3] [1] [2] [4] + public void testLayout11KeyM0() { + MiniKeyboardParams params = new MiniKeyboardParams(11, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_M0, KEYBOARD_WIDTH); + assertEquals("11 key M0 columns", 4, params.mNumColumns); + assertEquals("11 key M0 rows", 3, params.mNumRows); + assertEquals("11 key M0 left", 1, params.mLeftKeys); + assertEquals("11 key M0 right", 3, params.mRightKeys); + assertEquals("11 key M0 [1]", 0, params.getColumnPos(0)); + assertEquals("11 key M0 [2]", 1, params.getColumnPos(1)); + assertEquals("11 key M0 [3]", -1, params.getColumnPos(2)); + assertEquals("11 key M0 [4]", 2, params.getColumnPos(3)); + assertEquals("11 key M0 [5]", 0, params.getColumnPos(4)); + assertEquals("11 key M0 [6]", 1, params.getColumnPos(5)); + assertEquals("11 key M0 [7]", -1, params.getColumnPos(6)); + assertEquals("11 key M0 [8]", 2, params.getColumnPos(7)); + assertEquals("11 key M0 [9]", 0, params.getColumnPos(8)); + assertEquals("11 key M0 [A]", 1, params.getColumnPos(9)); + assertEquals("11 key M0 [B]", -1, params.getColumnPos(10)); + assertEquals("11 key M0 adjust", 1, params.mTopRowAdjustment); + assertEquals("11 key M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [B] [9] [A] [C] + // [7] [5] [6] [8] + // [3] [1] [2] [4] + public void testLayout12KeyM0() { + MiniKeyboardParams params = new MiniKeyboardParams(12, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_M0, KEYBOARD_WIDTH); + assertEquals("12 key M0 columns", 4, params.mNumColumns); + assertEquals("12 key M0 rows", 3, params.mNumRows); + assertEquals("12 key M0 left", 1, params.mLeftKeys); + assertEquals("12 key M0 right", 3, params.mRightKeys); + assertEquals("12 key M0 [1]", 0, params.getColumnPos(0)); + assertEquals("12 key M0 [2]", 1, params.getColumnPos(1)); + assertEquals("12 key M0 [3]", -1, params.getColumnPos(2)); + assertEquals("12 key M0 [4]", 2, params.getColumnPos(3)); + assertEquals("12 key M0 [5]", 0, params.getColumnPos(4)); + assertEquals("12 key M0 [6]", 1, params.getColumnPos(5)); + assertEquals("12 key M0 [7]", -1, params.getColumnPos(6)); + assertEquals("12 key M0 [8]", 2, params.getColumnPos(7)); + assertEquals("12 key M0 [9]", 0, params.getColumnPos(8)); + assertEquals("12 key M0 [A]", 1, params.getColumnPos(9)); + assertEquals("12 key M0 [B]", -1, params.getColumnPos(10)); + assertEquals("12 key M0 [C]", 2, params.getColumnPos(11)); + assertEquals("12 key M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("12 key M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + + // [D] [B] [C] + // [A] [8] [6] [7] [9] + // [5] [3] [1] [2] [4] + public void testLayout13KeyM0() { + MiniKeyboardParams params = new MiniKeyboardParams(13, MAX_COLUMNS, WIDTH, + HEIGHT, XPOS_M0, KEYBOARD_WIDTH); + assertEquals("13 key M0 columns", 5, params.mNumColumns); + assertEquals("13 key M0 rows", 3, params.mNumRows); + assertEquals("13 key M0 left", 2, params.mLeftKeys); + assertEquals("13 key M0 right", 3, params.mRightKeys); + assertEquals("13 key M0 [1]", 0, params.getColumnPos(0)); + assertEquals("13 key M0 [2]", 1, params.getColumnPos(1)); + assertEquals("13 key M0 [3]", -1, params.getColumnPos(2)); + assertEquals("13 key M0 [4]", 2, params.getColumnPos(3)); + assertEquals("13 key M0 [5]", -2, params.getColumnPos(4)); + assertEquals("13 key M0 [6]", 0, params.getColumnPos(5)); + assertEquals("13 key M0 [7]", 1, params.getColumnPos(6)); + assertEquals("13 key M0 [8]", -1, params.getColumnPos(7)); + assertEquals("13 key M0 [9]", 2, params.getColumnPos(8)); + assertEquals("13 key M0 [A]", -2, params.getColumnPos(9)); + assertEquals("13 key M0 [B]", 0, params.getColumnPos(10)); + assertEquals("13 key M0 [C]", 1, params.getColumnPos(11)); + assertEquals("13 key M0 [D]", -1, params.getColumnPos(12)); + assertEquals("13 key M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("13 key M0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/internal/MiniKeyboardBuilderTests.java b/tests/src/com/android/inputmethod/keyboard/internal/MiniKeyboardBuilderTests.java deleted file mode 100644 index 1c5661bf0..000000000 --- a/tests/src/com/android/inputmethod/keyboard/internal/MiniKeyboardBuilderTests.java +++ /dev/null @@ -1,1416 +0,0 @@ -/* - * 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.internal; - -import com.android.inputmethod.keyboard.internal.MiniKeyboardBuilder.MiniKeyboardParams; - -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; - - private static final int KEYBOARD_WIDTH = WIDTH * 10; - private static final int XPOS_L0 = WIDTH * 0; - private static final int XPOS_L1 = WIDTH * 1; - private static final int XPOS_L2 = WIDTH * 2; - private static final int XPOS_M0 = WIDTH * 5; - private static final int XPOS_R3 = WIDTH * 6; - private static final int XPOS_R2 = WIDTH * 7; - private static final int XPOS_R1 = WIDTH * 8; - private static final int XPOS_R0 = WIDTH * 9; - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - public void testLayoutError() { - MiniKeyboardParams params = null; - try { - params = new MiniKeyboardParams(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 testLayout1KeyM0() { - MiniKeyboardParams params = new MiniKeyboardParams(1, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_M0, KEYBOARD_WIDTH); - assertEquals("1 key M0 columns", 1, params.mNumColumns); - assertEquals("1 key M0 rows", 1, params.mNumRows); - assertEquals("1 key M0 left", 0, params.mLeftKeys); - assertEquals("1 key M0 right", 1, params.mRightKeys); - assertEquals("1 key M0 [1]", 0, params.getColumnPos(0)); - assertEquals("1 key M0 adjust", 0, params.mTopRowAdjustment); - assertEquals("1 key M0 default", WIDTH * 0, params.getDefaultKeyCoordX()); - } - - // |[1] - public void testLayout1KeyL0() { - MiniKeyboardParams params = new MiniKeyboardParams(1, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L0, KEYBOARD_WIDTH); - assertEquals("1 key L0 columns", 1, params.mNumColumns); - assertEquals("1 key L0 rows", 1, params.mNumRows); - assertEquals("1 key L0 left", 0, params.mLeftKeys); - assertEquals("1 key L0 right", 1, params.mRightKeys); - assertEquals("1 key L0 [1]", 0, params.getColumnPos(0)); - assertEquals("1 key L0 adjust", 0, params.mTopRowAdjustment); - assertEquals("1 key L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); - } - - // |___ [1] - public void testLayout1KeyL1() { - MiniKeyboardParams params = new MiniKeyboardParams(1, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L1, KEYBOARD_WIDTH); - assertEquals("1 key L1 columns", 1, params.mNumColumns); - assertEquals("1 key L1 rows", 1, params.mNumRows); - assertEquals("1 key L1 left", 0, params.mLeftKeys); - assertEquals("1 key L1 right", 1, params.mRightKeys); - assertEquals("1 key L1 [1]", 0, params.getColumnPos(0)); - assertEquals("1 key L1 adjust", 0, params.mTopRowAdjustment); - assertEquals("1 key L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); - } - - // |___ ___ [1] - public void testLayout1KeyL2() { - MiniKeyboardParams params = new MiniKeyboardParams(1, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L2, KEYBOARD_WIDTH); - assertEquals("1 key L2 columns", 1, params.mNumColumns); - assertEquals("1 key L2 rows", 1, params.mNumRows); - assertEquals("1 key L2 left", 0, params.mLeftKeys); - assertEquals("1 key L2 right", 1, params.mRightKeys); - assertEquals("1 key L2 [1]", 0, params.getColumnPos(0)); - assertEquals("1 key L2 adjust", 0, params.mTopRowAdjustment); - assertEquals("1 key L2 default", WIDTH * 0, params.getDefaultKeyCoordX()); - } - - // [1]| - public void testLayout1KeyR0() { - MiniKeyboardParams params = new MiniKeyboardParams(1, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R0, KEYBOARD_WIDTH); - assertEquals("1 key R0 columns", 1, params.mNumColumns); - assertEquals("1 key R0 rows", 1, params.mNumRows); - assertEquals("1 key R0 left", 0, params.mLeftKeys); - assertEquals("1 key R0 right", 1, params.mRightKeys); - assertEquals("1 key R0 [1]", 0, params.getColumnPos(0)); - assertEquals("1 key R0 adjust", 0, params.mTopRowAdjustment); - assertEquals("1 key R0 default", WIDTH * 0, params.getDefaultKeyCoordX()); - } - - // [1] ___| - public void testLayout1KeyR1() { - MiniKeyboardParams params = new MiniKeyboardParams(1, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R1, KEYBOARD_WIDTH); - assertEquals("1 key R1 columns", 1, params.mNumColumns); - assertEquals("1 key R1 rows", 1, params.mNumRows); - assertEquals("1 key R1 left", 0, params.mLeftKeys); - assertEquals("1 key R1 right", 1, params.mRightKeys); - assertEquals("1 key R1 [1]", 0, params.getColumnPos(0)); - assertEquals("1 key R1 adjust", 0, params.mTopRowAdjustment); - assertEquals("1 key R1 default", WIDTH * 0, params.getDefaultKeyCoordX()); - } - - // [1] ___ ___| - public void testLayout1KeyR2() { - MiniKeyboardParams params = new MiniKeyboardParams(1, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R2, KEYBOARD_WIDTH); - assertEquals("1 key R2 columns", 1, params.mNumColumns); - assertEquals("1 key R2 rows", 1, params.mNumRows); - assertEquals("1 key R2 left", 0, params.mLeftKeys); - assertEquals("1 key R2 right", 1, params.mRightKeys); - assertEquals("1 key R2 [1]", 0, params.getColumnPos(0)); - assertEquals("1 key R2 adjust", 0, params.mTopRowAdjustment); - assertEquals("1 key R2 default", WIDTH * 0, params.getDefaultKeyCoordX()); - } - - // [1] [2] - public void testLayout2KeyM0() { - MiniKeyboardParams params = new MiniKeyboardParams(2, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_M0, KEYBOARD_WIDTH); - assertEquals("2 key M0 columns", 2, params.mNumColumns); - assertEquals("2 key M0 rows", 1, params.mNumRows); - assertEquals("2 key M0 left", 0, params.mLeftKeys); - assertEquals("2 key M0 right", 2, params.mRightKeys); - assertEquals("2 key M0 [1]", 0, params.getColumnPos(0)); - assertEquals("2 key M0 [2]", 1, params.getColumnPos(1)); - assertEquals("2 key M0 adjust", 0, params.mTopRowAdjustment); - assertEquals("2 key M0 default", WIDTH * 0, params.getDefaultKeyCoordX()); - } - - // |[1] [2] - public void testLayout2KeyL0() { - MiniKeyboardParams params = new MiniKeyboardParams(2, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L0, KEYBOARD_WIDTH); - assertEquals("2 key L0 columns", 2, params.mNumColumns); - assertEquals("2 key L0 rows", 1, params.mNumRows); - assertEquals("2 key L0 left", 0, params.mLeftKeys); - assertEquals("2 key L0 right", 2, params.mRightKeys); - assertEquals("2 key L0 [1]", 0, params.getColumnPos(0)); - assertEquals("2 key L0 [2]", 1, params.getColumnPos(1)); - assertEquals("2 key L0 adjust", 0, params.mTopRowAdjustment); - assertEquals("2 key L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); - } - - // |___ [1] [2] - public void testLayout2KeyL1() { - MiniKeyboardParams params = new MiniKeyboardParams(2, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L1, KEYBOARD_WIDTH); - assertEquals("2 key L1 columns", 2, params.mNumColumns); - assertEquals("2 key L1 rows", 1, params.mNumRows); - assertEquals("2 key L1 left", 0, params.mLeftKeys); - assertEquals("2 key L1 right", 2, params.mRightKeys); - assertEquals("2 key L1 [1]", 0, params.getColumnPos(0)); - assertEquals("2 key L1 [2]", 1, params.getColumnPos(1)); - assertEquals("2 key L1 adjust", 0, params.mTopRowAdjustment); - assertEquals("2 key L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); - } - - // |___ ___ [1] [2] - public void testLayout2KeyL2() { - MiniKeyboardParams params = new MiniKeyboardParams(2, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L2, KEYBOARD_WIDTH); - assertEquals("2 key L2 columns", 2, params.mNumColumns); - assertEquals("2 key L2 rows", 1, params.mNumRows); - assertEquals("2 key L2 left", 0, params.mLeftKeys); - assertEquals("2 key L2 right", 2, params.mRightKeys); - assertEquals("2 key L2 [1]", 0, params.getColumnPos(0)); - assertEquals("2 key L2 [2]", 1, params.getColumnPos(1)); - assertEquals("2 key L2 adjust", 0, params.mTopRowAdjustment); - assertEquals("2 key L2 default", WIDTH * 0, params.getDefaultKeyCoordX()); - } - - // [2] [1]| - public void testLayout2KeyR0() { - MiniKeyboardParams params = new MiniKeyboardParams(2, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R0, KEYBOARD_WIDTH); - assertEquals("2 key R0 columns", 2, params.mNumColumns); - assertEquals("2 key R0 rows", 1, params.mNumRows); - assertEquals("2 key R0 left", 1, params.mLeftKeys); - assertEquals("2 key R0 right", 1, params.mRightKeys); - assertEquals("2 key R0 [1]", 0, params.getColumnPos(0)); - assertEquals("2 key R0 [2]", -1, params.getColumnPos(1)); - assertEquals("2 key R0 adjust", 0, params.mTopRowAdjustment); - assertEquals("2 key R0 default", WIDTH * 1, params.getDefaultKeyCoordX()); - } - - // [2] [1] ___| - public void testLayout2KeyR1() { - MiniKeyboardParams params = new MiniKeyboardParams(2, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R1, KEYBOARD_WIDTH); - assertEquals("2 key R1 columns", 2, params.mNumColumns); - assertEquals("2 key R1 rows", 1, params.mNumRows); - assertEquals("2 key R1 left", 1, params.mLeftKeys); - assertEquals("2 key R1 right", 1, params.mRightKeys); - assertEquals("2 key R1 [1]", 0, params.getColumnPos(0)); - assertEquals("2 key R1 [2]", -1, params.getColumnPos(1)); - assertEquals("2 key R1 adjust", 0, params.mTopRowAdjustment); - assertEquals("2 key R1 default", WIDTH * 1, params.getDefaultKeyCoordX()); - } - - // [1] [2] ___ ___| - public void testLayout2KeyR2() { - MiniKeyboardParams params = new MiniKeyboardParams(2, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R2, KEYBOARD_WIDTH); - assertEquals("2 key R2 columns", 2, params.mNumColumns); - assertEquals("2 key R2 rows", 1, params.mNumRows); - assertEquals("2 key R2 left", 0, params.mLeftKeys); - assertEquals("2 key R2 right", 2, params.mRightKeys); - assertEquals("2 key R2 [1]", 0, params.getColumnPos(0)); - assertEquals("2 key R2 [2]", 1, params.getColumnPos(1)); - assertEquals("2 key R2 adjust", 0, params.mTopRowAdjustment); - assertEquals("2 key R2 default", WIDTH * 0, params.getDefaultKeyCoordX()); - } - - // [3] [1] [2] - public void testLayout3KeyM0() { - MiniKeyboardParams params = new MiniKeyboardParams(3, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_M0, KEYBOARD_WIDTH); - 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 adjust", 0, params.mTopRowAdjustment); - assertEquals("3 key default", WIDTH * 1, params.getDefaultKeyCoordX()); - } - - // |[1] [2] [3] - public void testLayout3KeyL0() { - MiniKeyboardParams params = new MiniKeyboardParams(3, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L0, KEYBOARD_WIDTH); - assertEquals("3 key L0 columns", 3, params.mNumColumns); - assertEquals("3 key L0 rows", 1, params.mNumRows); - assertEquals("3 key L0 left", 0, params.mLeftKeys); - assertEquals("3 key L0 right", 3, params.mRightKeys); - assertEquals("3 key L0 [1]", 0, params.getColumnPos(0)); - assertEquals("3 key L0 [2]", 1, params.getColumnPos(1)); - assertEquals("3 key L0 [3]", 2, params.getColumnPos(2)); - assertEquals("3 key L0 adjust", 0, params.mTopRowAdjustment); - assertEquals("3 key L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); - } - - // |___ [1] [2] [3] - public void testLayout3KeyL1() { - MiniKeyboardParams params = new MiniKeyboardParams(3, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L1, KEYBOARD_WIDTH); - assertEquals("3 key L1 columns", 3, params.mNumColumns); - assertEquals("3 key L1 rows", 1, params.mNumRows); - assertEquals("3 key L1 left", 0, params.mLeftKeys); - assertEquals("3 key L1 right", 3, params.mRightKeys); - assertEquals("3 key L1 [1]", 0, params.getColumnPos(0)); - assertEquals("3 key L1 [2]", 1, params.getColumnPos(1)); - assertEquals("3 key L1 [3]", 2, params.getColumnPos(2)); - assertEquals("3 key L1 adjust", 0, params.mTopRowAdjustment); - assertEquals("3 key L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); - } - - // |___ ___ [3] [1] [2] - public void testLayout3KeyL2() { - MiniKeyboardParams params = new MiniKeyboardParams(3, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L2, KEYBOARD_WIDTH); - assertEquals("3 key L2 columns", 3, params.mNumColumns); - assertEquals("3 key L2 rows", 1, params.mNumRows); - assertEquals("3 key L2 left", 1, params.mLeftKeys); - assertEquals("3 key L2 right", 2, params.mRightKeys); - assertEquals("3 key L2 [1]", 0, params.getColumnPos(0)); - assertEquals("3 key L2 [2]", 1, params.getColumnPos(1)); - assertEquals("3 key L2 [3]", -1, params.getColumnPos(2)); - assertEquals("3 key L2 adjust", 0, params.mTopRowAdjustment); - assertEquals("3 key L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); - } - - // [3] [2] [1]| - public void testLayout3KeyR0() { - MiniKeyboardParams params = new MiniKeyboardParams(3, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R0, KEYBOARD_WIDTH); - assertEquals("3 key R0 columns", 3, params.mNumColumns); - assertEquals("3 key R0 rows", 1, params.mNumRows); - assertEquals("3 key R0 left", 2, params.mLeftKeys); - assertEquals("3 key R0 right", 1, params.mRightKeys); - assertEquals("3 key R0 [1]", 0, params.getColumnPos(0)); - assertEquals("3 key R0 [2]", -1, params.getColumnPos(1)); - assertEquals("3 key R0 [3]", -2, params.getColumnPos(2)); - assertEquals("3 key R0 adjust", 0, params.mTopRowAdjustment); - assertEquals("3 key R0 default", WIDTH * 2, params.getDefaultKeyCoordX()); - } - - // [3] [2] [1] ___| - public void testLayout3KeyR1() { - MiniKeyboardParams params = new MiniKeyboardParams(3, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R1, KEYBOARD_WIDTH); - assertEquals("3 key R1 columns", 3, params.mNumColumns); - assertEquals("3 key R1 rows", 1, params.mNumRows); - assertEquals("3 key R1 left", 2, params.mLeftKeys); - assertEquals("3 key R1 right", 1, params.mRightKeys); - assertEquals("3 key R1 [1]", 0, params.getColumnPos(0)); - assertEquals("3 key R1 [2]", -1, params.getColumnPos(1)); - assertEquals("3 key R1 [3]", -2, params.getColumnPos(2)); - assertEquals("3 key R1 adjust", 0, params.mTopRowAdjustment); - assertEquals("3 key R1 default", WIDTH * 2, params.getDefaultKeyCoordX()); - } - - // [3] [1] [2] ___ ___| - public void testLayout3KeyR2() { - MiniKeyboardParams params = new MiniKeyboardParams(3, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R2, KEYBOARD_WIDTH); - assertEquals("3 key R2 columns", 3, params.mNumColumns); - assertEquals("3 key R2 rows", 1, params.mNumRows); - assertEquals("3 key R2 left", 1, params.mLeftKeys); - assertEquals("3 key R2 right", 2, params.mRightKeys); - assertEquals("3 key R2 [1]", 0, params.getColumnPos(0)); - assertEquals("3 key R2 [2]", 1, params.getColumnPos(1)); - assertEquals("3 key R2 [3]", -1, params.getColumnPos(2)); - assertEquals("3 key R2 adjust", 0, params.mTopRowAdjustment); - assertEquals("3 key R2 default", WIDTH * 1, params.getDefaultKeyCoordX()); - } - - // [3] [1] [2] [4] - public void testLayout4KeyM0() { - MiniKeyboardParams params = new MiniKeyboardParams(4, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_M0, KEYBOARD_WIDTH); - 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 adjust", 0, params.mTopRowAdjustment); - assertEquals("4 key default", WIDTH * 1, params.getDefaultKeyCoordX()); - } - - // |[1] [2] [3] [4] - public void testLayout4KeyL0() { - MiniKeyboardParams params = new MiniKeyboardParams(4, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L0, KEYBOARD_WIDTH); - assertEquals("4 key L0 columns", 4, params.mNumColumns); - assertEquals("4 key L0 rows", 1, params.mNumRows); - assertEquals("4 key L0 left", 0, params.mLeftKeys); - assertEquals("4 key L0 right", 4, params.mRightKeys); - assertEquals("4 key L0 [1]", 0, params.getColumnPos(0)); - assertEquals("4 key L0 [2]", 1, params.getColumnPos(1)); - assertEquals("4 key L0 [3]", 2, params.getColumnPos(2)); - assertEquals("4 key L0 [4]", 3, params.getColumnPos(3)); - assertEquals("4 key L0 adjust", 0, params.mTopRowAdjustment); - assertEquals("4 key L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); - } - - // |___ [1] [2] [3] [4] - public void testLayout4KeyL1() { - MiniKeyboardParams params = new MiniKeyboardParams(4, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L1, KEYBOARD_WIDTH); - assertEquals("4 key L1 columns", 4, params.mNumColumns); - assertEquals("4 key L1 rows", 1, params.mNumRows); - assertEquals("4 key L1 left", 0, params.mLeftKeys); - assertEquals("4 key L1 right", 4, params.mRightKeys); - assertEquals("4 key L1 [1]", 0, params.getColumnPos(0)); - assertEquals("4 key L1 [2]", 1, params.getColumnPos(1)); - assertEquals("4 key L1 [3]", 2, params.getColumnPos(2)); - assertEquals("4 key L1 [4]", 3, params.getColumnPos(3)); - assertEquals("4 key L1 adjust", 0, params.mTopRowAdjustment); - assertEquals("4 key L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); - } - - // |___ ___ [3] [1] [2] [4] - public void testLayout4KeyL2() { - MiniKeyboardParams params = new MiniKeyboardParams(4, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L2, KEYBOARD_WIDTH); - assertEquals("4 key L2 columns", 4, params.mNumColumns); - assertEquals("4 key L2 rows", 1, params.mNumRows); - assertEquals("4 key L2 left", 1, params.mLeftKeys); - assertEquals("4 key L2 right", 3, params.mRightKeys); - assertEquals("4 key L2 [1]", 0, params.getColumnPos(0)); - assertEquals("4 key L2 [2]", 1, params.getColumnPos(1)); - assertEquals("4 key L2 [3]", -1, params.getColumnPos(2)); - assertEquals("4 key L2 [4]", 2, params.getColumnPos(3)); - assertEquals("4 key L2 adjust", 0, params.mTopRowAdjustment); - assertEquals("4 key L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); - } - - // [4] [3] [2] [1]| - public void testLayout4KeyR0() { - MiniKeyboardParams params = new MiniKeyboardParams(4, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R0, KEYBOARD_WIDTH); - assertEquals("4 key R0 columns", 4, params.mNumColumns); - assertEquals("4 key R0 rows", 1, params.mNumRows); - assertEquals("4 key R0 left", 3, params.mLeftKeys); - assertEquals("4 key R0 right", 1, params.mRightKeys); - assertEquals("4 key R0 [1]", 0, params.getColumnPos(0)); - assertEquals("4 key R0 [2]", -1, params.getColumnPos(1)); - assertEquals("4 key R0 [3]", -2, params.getColumnPos(2)); - assertEquals("4 key R0 [4]", -3, params.getColumnPos(3)); - assertEquals("4 key R0 adjust", 0, params.mTopRowAdjustment); - assertEquals("4 key R0 default", WIDTH * 3, params.getDefaultKeyCoordX()); - } - - // [4] [3] [2] [1] ___| - public void testLayout4KeyR1() { - MiniKeyboardParams params = new MiniKeyboardParams(4, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R1, KEYBOARD_WIDTH); - assertEquals("4 key R1 columns", 4, params.mNumColumns); - assertEquals("4 key R1 rows", 1, params.mNumRows); - assertEquals("4 key R1 left", 3, params.mLeftKeys); - assertEquals("4 key R1 right", 1, params.mRightKeys); - assertEquals("4 key R1 [1]", 0, params.getColumnPos(0)); - assertEquals("4 key R1 [2]", -1, params.getColumnPos(1)); - assertEquals("4 key R1 [3]", -2, params.getColumnPos(2)); - assertEquals("4 key R1 [4]", -3, params.getColumnPos(3)); - assertEquals("4 key R1 adjust", 0, params.mTopRowAdjustment); - assertEquals("4 key R1 default", WIDTH * 3, params.getDefaultKeyCoordX()); - } - - // [4] [3] [1] [2] ___ ___| - public void testLayout4KeyR2() { - MiniKeyboardParams params = new MiniKeyboardParams(4, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R2, KEYBOARD_WIDTH); - assertEquals("4 key R2 columns", 4, params.mNumColumns); - assertEquals("4 key R2 rows", 1, params.mNumRows); - assertEquals("4 key R2 left", 2, params.mLeftKeys); - assertEquals("4 key R2 right", 2, params.mRightKeys); - assertEquals("4 key R2 [1]", 0, params.getColumnPos(0)); - assertEquals("4 key R2 [2]", 1, params.getColumnPos(1)); - assertEquals("4 key R2 [3]", -1, params.getColumnPos(2)); - assertEquals("4 key R2 [4]", -2, params.getColumnPos(3)); - assertEquals("4 key R2 adjust", 0, params.mTopRowAdjustment); - assertEquals("4 key R2 default", WIDTH * 2, params.getDefaultKeyCoordX()); - } - - // [5] [3] [1] [2] [4] - public void testLayout5KeyM0() { - MiniKeyboardParams params = new MiniKeyboardParams(5, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_M0, KEYBOARD_WIDTH); - 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 adjust", 0, params.mTopRowAdjustment); - assertEquals("5 key default", WIDTH * 2, params.getDefaultKeyCoordX()); - } - - // |[1] [2] [3] [4] [5] - public void testLayout5KeyL0() { - MiniKeyboardParams params = new MiniKeyboardParams(5, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L0, KEYBOARD_WIDTH); - assertEquals("5 key L0 columns", 5, params.mNumColumns); - assertEquals("5 key L0 rows", 1, params.mNumRows); - assertEquals("5 key L0 left", 0, params.mLeftKeys); - assertEquals("5 key L0 right", 5, params.mRightKeys); - assertEquals("5 key L0 [1]", 0, params.getColumnPos(0)); - assertEquals("5 key L0 [2]", 1, params.getColumnPos(1)); - assertEquals("5 key L0 [3]", 2, params.getColumnPos(2)); - assertEquals("5 key L0 [4]", 3, params.getColumnPos(3)); - assertEquals("5 key L0 [5]", 4, params.getColumnPos(4)); - assertEquals("5 key L0 adjust", 0, params.mTopRowAdjustment); - assertEquals("5 key L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); - } - - // |___ [1] [2] [3] [4] [5] - public void testLayout5KeyL1() { - MiniKeyboardParams params = new MiniKeyboardParams(5, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L1, KEYBOARD_WIDTH); - assertEquals("5 key L1 columns", 5, params.mNumColumns); - assertEquals("5 key L1 rows", 1, params.mNumRows); - assertEquals("5 key L1 left", 0, params.mLeftKeys); - assertEquals("5 key L1 right", 5, params.mRightKeys); - assertEquals("5 key L1 [1]", 0, params.getColumnPos(0)); - assertEquals("5 key L1 [2]", 1, params.getColumnPos(1)); - assertEquals("5 key L1 [3]", 2, params.getColumnPos(2)); - assertEquals("5 key L1 [4]", 3, params.getColumnPos(3)); - assertEquals("5 key L1 [5]", 4, params.getColumnPos(4)); - assertEquals("5 key L1 adjust", 0, params.mTopRowAdjustment); - assertEquals("5 key L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); - } - - // |___ ___ [3] [1] [2] [4] [5] - public void testLayout5KeyL2() { - MiniKeyboardParams params = new MiniKeyboardParams(5, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L2, KEYBOARD_WIDTH); - assertEquals("5 key L2 columns", 5, params.mNumColumns); - assertEquals("5 key L2 rows", 1, params.mNumRows); - assertEquals("5 key L2 left", 1, params.mLeftKeys); - assertEquals("5 key L2 right", 4, params.mRightKeys); - assertEquals("5 key L2 [1]", 0, params.getColumnPos(0)); - assertEquals("5 key L2 [2]", 1, params.getColumnPos(1)); - assertEquals("5 key L2 [3]", -1, params.getColumnPos(2)); - assertEquals("5 key L2 [4]", 2, params.getColumnPos(3)); - assertEquals("5 key L2 [5]", 3, params.getColumnPos(4)); - assertEquals("5 key L2 adjust", 0, params.mTopRowAdjustment); - assertEquals("5 key L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); - } - - // [5] [4] [3] [2] [1]| - public void testLayout5KeyR0() { - MiniKeyboardParams params = new MiniKeyboardParams(5, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R0, KEYBOARD_WIDTH); - assertEquals("5 key R0 columns", 5, params.mNumColumns); - assertEquals("5 key R0 rows", 1, params.mNumRows); - assertEquals("5 key R0 left", 4, params.mLeftKeys); - assertEquals("5 key R0 right", 1, params.mRightKeys); - assertEquals("5 key R0 [1]", 0, params.getColumnPos(0)); - assertEquals("5 key R0 [2]", -1, params.getColumnPos(1)); - assertEquals("5 key R0 [3]", -2, params.getColumnPos(2)); - assertEquals("5 key R0 [4]", -3, params.getColumnPos(3)); - assertEquals("5 key R0 [5]", -4, params.getColumnPos(4)); - assertEquals("5 key R0 adjust", 0, params.mTopRowAdjustment); - assertEquals("5 key R0 default", WIDTH * 4, params.getDefaultKeyCoordX()); - } - - // [5] [4] [3] [2] [1] ___| - public void testLayout5KeyR1() { - MiniKeyboardParams params = new MiniKeyboardParams(5, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R1, KEYBOARD_WIDTH); - assertEquals("5 key R1 columns", 5, params.mNumColumns); - assertEquals("5 key R1 rows", 1, params.mNumRows); - assertEquals("5 key R1 left", 4, params.mLeftKeys); - assertEquals("5 key R1 right", 1, params.mRightKeys); - assertEquals("5 key R1 [1]", 0, params.getColumnPos(0)); - assertEquals("5 key R1 [2]", -1, params.getColumnPos(1)); - assertEquals("5 key R1 [3]", -2, params.getColumnPos(2)); - assertEquals("5 key R1 [4]", -3, params.getColumnPos(3)); - assertEquals("5 key R1 [5]", -4, params.getColumnPos(4)); - assertEquals("5 key R1 adjust", 0, params.mTopRowAdjustment); - assertEquals("5 key R1 default", WIDTH * 4, params.getDefaultKeyCoordX()); - } - - // [5] [4] [3] [1] [2] ___ ___| - public void testLayout5KeyR2() { - MiniKeyboardParams params = new MiniKeyboardParams(5, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R2, KEYBOARD_WIDTH); - assertEquals("5 key R2 columns", 5, params.mNumColumns); - assertEquals("5 key R2 rows", 1, params.mNumRows); - assertEquals("5 key R2 left", 3, params.mLeftKeys); - assertEquals("5 key R2 right", 2, params.mRightKeys); - assertEquals("5 key R2 [1]", 0, params.getColumnPos(0)); - assertEquals("5 key R2 [2]", 1, params.getColumnPos(1)); - assertEquals("5 key R2 [3]", -1, params.getColumnPos(2)); - assertEquals("5 key R2 [4]", -2, params.getColumnPos(3)); - assertEquals("5 key R2 [5]", -3, params.getColumnPos(4)); - assertEquals("5 key R2 adjust", 0, params.mTopRowAdjustment); - assertEquals("5 key R2 default", WIDTH * 3, params.getDefaultKeyCoordX()); - } - - // [6] [4] [5] - // [3] [1] [2] - public void testLayout6KeyM0() { - MiniKeyboardParams params = new MiniKeyboardParams(6, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_M0, KEYBOARD_WIDTH); - assertEquals("6 key columns", 3, params.mNumColumns); - assertEquals("6 key rows", 2, params.mNumRows); - assertEquals("6 key left", 1, params.mLeftKeys); - assertEquals("6 key right", 2, 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]", 0, params.getColumnPos(3)); - assertEquals("6 key [5]", 1, params.getColumnPos(4)); - assertEquals("6 key [6]", -1, params.getColumnPos(5)); - assertEquals("6 key adjust", 0, params.mTopRowAdjustment); - assertEquals("6 key default", WIDTH * 1, params.getDefaultKeyCoordX()); - } - - // |[4] [5] [6] - // |[1] [2] [3] - public void testLayout6KeyL0() { - MiniKeyboardParams params = new MiniKeyboardParams(6, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L0, KEYBOARD_WIDTH); - assertEquals("6 key L0 columns", 3, params.mNumColumns); - assertEquals("6 key L0 rows", 2, params.mNumRows); - assertEquals("6 key L0 left", 0, params.mLeftKeys); - assertEquals("6 key L0 right", 3, params.mRightKeys); - assertEquals("6 key L0 [1]", 0, params.getColumnPos(0)); - assertEquals("6 key L0 [2]", 1, params.getColumnPos(1)); - assertEquals("6 key L0 [3]", 2, params.getColumnPos(2)); - assertEquals("6 key L0 [4]", 0, params.getColumnPos(3)); - assertEquals("6 key L0 [5]", 1, params.getColumnPos(4)); - assertEquals("6 key L0 [6]", 2, params.getColumnPos(5)); - assertEquals("6 key L0 adjust", 0, params.mTopRowAdjustment); - assertEquals("6 key L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); - } - - // |___ [4] [5] [6] - // |___ [1] [2] [3] - public void testLayout6KeyL1() { - MiniKeyboardParams params = new MiniKeyboardParams(6, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L1, KEYBOARD_WIDTH); - assertEquals("6 key L1 columns", 3, params.mNumColumns); - assertEquals("6 key L1 rows", 2, params.mNumRows); - assertEquals("6 key L1 left", 0, params.mLeftKeys); - assertEquals("6 key L1 right", 3, params.mRightKeys); - assertEquals("6 key L1 [1]", 0, params.getColumnPos(0)); - assertEquals("6 key L1 [2]", 1, params.getColumnPos(1)); - assertEquals("6 key L1 [3]", 2, params.getColumnPos(2)); - assertEquals("6 key L1 [4]", 0, params.getColumnPos(3)); - assertEquals("6 key L1 [5]", 1, params.getColumnPos(4)); - assertEquals("6 key L1 [6]", 2, params.getColumnPos(5)); - assertEquals("6 key L1 adjust", 0, params.mTopRowAdjustment); - assertEquals("6 key L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); - } - - // |___ ___ [6] [4] [5] - // |___ ___ [3] [1] [2] - public void testLayout6KeyL2() { - MiniKeyboardParams params = new MiniKeyboardParams(6, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L2, KEYBOARD_WIDTH); - assertEquals("6 key L2 columns", 3, params.mNumColumns); - assertEquals("6 key L2 rows", 2, params.mNumRows); - assertEquals("6 key L2 left", 1, params.mLeftKeys); - assertEquals("6 key L2 right", 2, params.mRightKeys); - assertEquals("6 key L2 [1]", 0, params.getColumnPos(0)); - assertEquals("6 key L2 [2]", 1, params.getColumnPos(1)); - assertEquals("6 key L2 [3]", -1, params.getColumnPos(2)); - assertEquals("6 key L2 [4]", 0, params.getColumnPos(3)); - assertEquals("6 key L2 [5]", 1, params.getColumnPos(4)); - assertEquals("6 key L2 [6]", -1, params.getColumnPos(5)); - assertEquals("6 key L2 adjust", 0, params.mTopRowAdjustment); - assertEquals("6 key L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); - } - - // [6] [5] [4]| - // [3] [2] [1]| - public void testLayout6KeyR0() { - MiniKeyboardParams params = new MiniKeyboardParams(6, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R0, KEYBOARD_WIDTH); - assertEquals("6 key R0 columns", 3, params.mNumColumns); - assertEquals("6 key R0 rows", 2, params.mNumRows); - assertEquals("6 key R0 left", 2, params.mLeftKeys); - assertEquals("6 key R0 right", 1, params.mRightKeys); - assertEquals("6 key R0 [1]", 0, params.getColumnPos(0)); - assertEquals("6 key R0 [2]", -1, params.getColumnPos(1)); - assertEquals("6 key R0 [3]", -2, params.getColumnPos(2)); - assertEquals("6 key R0 [4]", 0, params.getColumnPos(3)); - assertEquals("6 key R0 [5]", -1, params.getColumnPos(4)); - assertEquals("6 key R0 [6]", -2, params.getColumnPos(5)); - assertEquals("6 key R0 adjust", 0, params.mTopRowAdjustment); - assertEquals("6 key R0 default", WIDTH * 2, params.getDefaultKeyCoordX()); - } - - // [6] [5] [4] ___| - // [3] [2] [1] ___| - public void testLayout6KeyR1() { - MiniKeyboardParams params = new MiniKeyboardParams(6, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R1, KEYBOARD_WIDTH); - assertEquals("6 key R1 columns", 3, params.mNumColumns); - assertEquals("6 key R1 rows", 2, params.mNumRows); - assertEquals("6 key R1 left", 2, params.mLeftKeys); - assertEquals("6 key R1 right", 1, params.mRightKeys); - assertEquals("6 key R1 [1]", 0, params.getColumnPos(0)); - assertEquals("6 key R1 [2]", -1, params.getColumnPos(1)); - assertEquals("6 key R1 [3]", -2, params.getColumnPos(2)); - assertEquals("6 key R1 [4]", 0, params.getColumnPos(3)); - assertEquals("6 key R1 [5]", -1, params.getColumnPos(4)); - assertEquals("6 key R1 [6]", -2, params.getColumnPos(5)); - assertEquals("6 key R1 adjust", 0, params.mTopRowAdjustment); - assertEquals("6 key R1 default", WIDTH * 2, params.getDefaultKeyCoordX()); - } - - // [6] [4] [5] ___ ___| - // [3] [1] [2] ___ ___| - public void testLayout6KeyR2() { - MiniKeyboardParams params = new MiniKeyboardParams(6, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R2, KEYBOARD_WIDTH); - assertEquals("6 key R2 columns", 3, params.mNumColumns); - assertEquals("6 key R2 rows", 2, params.mNumRows); - assertEquals("6 key R2 left", 1, params.mLeftKeys); - assertEquals("6 key R2 right", 2, params.mRightKeys); - assertEquals("6 key R2 [1]", 0, params.getColumnPos(0)); - assertEquals("6 key R2 [2]", 1, params.getColumnPos(1)); - assertEquals("6 key R2 [3]", -1, params.getColumnPos(2)); - assertEquals("6 key R2 [4]", 0, params.getColumnPos(3)); - assertEquals("6 key R2 [5]", 1, params.getColumnPos(4)); - assertEquals("6 key R2 [6]", -1, params.getColumnPos(5)); - assertEquals("6 key R2 adjust", 0, params.mTopRowAdjustment); - assertEquals("6 key R2 default", WIDTH * 1, params.getDefaultKeyCoordX()); - } - - // [7] [5] [6] - // [3] [1] [2] [4] - public void testLayout7KeyM0() { - MiniKeyboardParams params = new MiniKeyboardParams(7, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_M0, KEYBOARD_WIDTH); - assertEquals("7 key columns", 4, params.mNumColumns); - assertEquals("7 key rows", 2, params.mNumRows); - assertEquals("7 key left", 1, 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]", 0, params.getColumnPos(4)); - assertEquals("7 key [6]", 1, params.getColumnPos(5)); - assertEquals("7 key [7]", -1, params.getColumnPos(6)); - assertEquals("7 key adjust", 1, params.mTopRowAdjustment); - assertEquals("7 key default", WIDTH * 1, params.getDefaultKeyCoordX()); - } - - // |[5] [6] [7] - // |[1] [2] [3] [4] - public void testLayout7KeyL0() { - MiniKeyboardParams params = new MiniKeyboardParams(7, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L0, KEYBOARD_WIDTH); - assertEquals("7 key L0 columns", 4, params.mNumColumns); - assertEquals("7 key L0 rows", 2, params.mNumRows); - assertEquals("7 key L0 left", 0, params.mLeftKeys); - assertEquals("7 key L0 right", 4, params.mRightKeys); - assertEquals("7 key L0 [1]", 0, params.getColumnPos(0)); - assertEquals("7 key L0 [2]", 1, params.getColumnPos(1)); - assertEquals("7 key L0 [3]", 2, params.getColumnPos(2)); - assertEquals("7 key L0 [4]", 3, params.getColumnPos(3)); - assertEquals("7 key L0 [5]", 0, params.getColumnPos(4)); - assertEquals("7 key L0 [6]", 1, params.getColumnPos(5)); - assertEquals("7 key L0 [7]", 2, params.getColumnPos(6)); - assertEquals("7 key L0 adjust", 0, params.mTopRowAdjustment); - assertEquals("7 key L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); - } - - // |___ [5] [6] [7] - // |___ [1] [2] [3] [4] - public void testLayout7KeyL1() { - MiniKeyboardParams params = new MiniKeyboardParams(7, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L1, KEYBOARD_WIDTH); - assertEquals("7 key L1 columns", 4, params.mNumColumns); - assertEquals("7 key L1 rows", 2, params.mNumRows); - assertEquals("7 key L1 left", 0, params.mLeftKeys); - assertEquals("7 key L1 right", 4, params.mRightKeys); - assertEquals("7 key L1 [1]", 0, params.getColumnPos(0)); - assertEquals("7 key L1 [2]", 1, params.getColumnPos(1)); - assertEquals("7 key L1 [3]", 2, params.getColumnPos(2)); - assertEquals("7 key L1 [4]", 3, params.getColumnPos(3)); - assertEquals("7 key L1 [5]", 0, params.getColumnPos(4)); - assertEquals("7 key L1 [6]", 1, params.getColumnPos(5)); - assertEquals("7 key L1 [7]", 2, params.getColumnPos(6)); - assertEquals("7 key L1 adjust", 0, params.mTopRowAdjustment); - assertEquals("7 key L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); - } - - // |___ ___ [7] [5] [6] - // |___ ___ [3] [1] [2] [4] - public void testLayout7KeyL2() { - MiniKeyboardParams params = new MiniKeyboardParams(7, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L2, KEYBOARD_WIDTH); - assertEquals("7 key L2 columns", 4, params.mNumColumns); - assertEquals("7 key L2 rows", 2, params.mNumRows); - assertEquals("7 key L2 left", 1, params.mLeftKeys); - assertEquals("7 key L2 right", 3, params.mRightKeys); - assertEquals("7 key L2 [1]", 0, params.getColumnPos(0)); - assertEquals("7 key L2 [2]", 1, params.getColumnPos(1)); - assertEquals("7 key L2 [3]", -1, params.getColumnPos(2)); - assertEquals("7 key L2 [4]", 2, params.getColumnPos(3)); - assertEquals("7 key L2 [5]", 0, params.getColumnPos(4)); - assertEquals("7 key L2 [6]", 1, params.getColumnPos(5)); - assertEquals("7 key L2 [7]", -1, params.getColumnPos(6)); - assertEquals("7 key L2 adjust", 1, params.mTopRowAdjustment); - assertEquals("7 key L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); - } - - // [7] [6] [5]| - // [4] [3] [2] [1]| - public void testLayout7KeyR0() { - MiniKeyboardParams params = new MiniKeyboardParams(7, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R0, KEYBOARD_WIDTH); - assertEquals("7 key R0 columns", 4, params.mNumColumns); - assertEquals("7 key R0 rows", 2, params.mNumRows); - assertEquals("7 key R0 left", 3, params.mLeftKeys); - assertEquals("7 key R0 right", 1, params.mRightKeys); - assertEquals("7 key R0 [1]", 0, params.getColumnPos(0)); - assertEquals("7 key R0 [2]", -1, params.getColumnPos(1)); - assertEquals("7 key R0 [3]", -2, params.getColumnPos(2)); - assertEquals("7 key R0 [4]", -3, params.getColumnPos(3)); - assertEquals("7 key R0 [5]", 0, params.getColumnPos(4)); - assertEquals("7 key R0 [6]", -1, params.getColumnPos(5)); - assertEquals("7 key R0 [7]", -2, params.getColumnPos(6)); - assertEquals("7 key R0 adjust", 0, params.mTopRowAdjustment); - assertEquals("7 key R0 default", WIDTH * 3, params.getDefaultKeyCoordX()); - } - - // [7] [6] [5] ___| - // [4] [3] [2] [1] ___| - public void testLayout7KeyR1() { - MiniKeyboardParams params = new MiniKeyboardParams(7, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R1, KEYBOARD_WIDTH); - assertEquals("7 key R1 columns", 4, params.mNumColumns); - assertEquals("7 key R1 rows", 2, params.mNumRows); - assertEquals("7 key R1 left", 3, params.mLeftKeys); - assertEquals("7 key R1 right", 1, params.mRightKeys); - assertEquals("7 key R1 [1]", 0, params.getColumnPos(0)); - assertEquals("7 key R1 [2]", -1, params.getColumnPos(1)); - assertEquals("7 key R1 [3]", -2, params.getColumnPos(2)); - assertEquals("7 key R1 [4]", -3, params.getColumnPos(3)); - assertEquals("7 key R1 [5]", 0, params.getColumnPos(4)); - assertEquals("7 key R1 [6]", -1, params.getColumnPos(5)); - assertEquals("7 key R1 [7]", -2, params.getColumnPos(6)); - assertEquals("7 key R1 adjust", 0, params.mTopRowAdjustment); - assertEquals("7 key R1 default", WIDTH * 3, params.getDefaultKeyCoordX()); - } - - // [7] [5] [6] ___ ___| - // [4] [3] [1] [2] ___ ___| - public void testLayout7KeyR2() { - MiniKeyboardParams params = new MiniKeyboardParams(7, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R2, KEYBOARD_WIDTH); - assertEquals("7 key R2 columns", 4, params.mNumColumns); - assertEquals("7 key R2 rows", 2, params.mNumRows); - assertEquals("7 key R2 left", 2, params.mLeftKeys); - assertEquals("7 key R2 right", 2, params.mRightKeys); - assertEquals("7 key R2 [1]", 0, params.getColumnPos(0)); - assertEquals("7 key R2 [2]", 1, params.getColumnPos(1)); - assertEquals("7 key R2 [3]", -1, params.getColumnPos(2)); - assertEquals("7 key R2 [4]", -2, params.getColumnPos(3)); - assertEquals("7 key R2 [5]", 0, params.getColumnPos(4)); - assertEquals("7 key R2 [6]", 1, params.getColumnPos(5)); - assertEquals("7 key R2 [7]", -1, params.getColumnPos(6)); - assertEquals("7 key R2 adjust", -1, params.mTopRowAdjustment); - assertEquals("7 key R2 default", WIDTH * 2, params.getDefaultKeyCoordX()); - } - - // [7] [6] [5] [3] [1] [2] [4] ___| - public void testLayout7KeyR3Max7() { - MiniKeyboardParams params = new MiniKeyboardParams(7, 7, WIDTH, - HEIGHT, XPOS_R3, KEYBOARD_WIDTH); - assertEquals("7 key R2 columns", 7, params.mNumColumns); - assertEquals("7 key R2 rows", 1, params.mNumRows); - assertEquals("7 key R2 left", 4, params.mLeftKeys); - assertEquals("7 key R2 right", 3, params.mRightKeys); - assertEquals("7 key R2 [1]", 0, params.getColumnPos(0)); - assertEquals("7 key R2 [2]", 1, params.getColumnPos(1)); - assertEquals("7 key R2 [3]", -1, params.getColumnPos(2)); - assertEquals("7 key R2 [4]", 2, params.getColumnPos(3)); - assertEquals("7 key R2 [5]", -2, params.getColumnPos(4)); - assertEquals("7 key R2 [6]", -3, params.getColumnPos(5)); - assertEquals("7 key R2 [7]", -4, params.getColumnPos(6)); - assertEquals("7 key R2 adjust", 0, params.mTopRowAdjustment); - assertEquals("7 key R2 default", WIDTH * 4, params.getDefaultKeyCoordX()); - } - - // [7] [5] [6] [8] - // [3] [1] [2] [4] - public void testLayout8KeyM0() { - MiniKeyboardParams params = new MiniKeyboardParams(8, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_M0, KEYBOARD_WIDTH); - assertEquals("8 key M0 columns", 4, params.mNumColumns); - assertEquals("8 key M0 rows", 2, params.mNumRows); - assertEquals("8 key M0 left", 1, params.mLeftKeys); - assertEquals("8 key M0 right", 3, params.mRightKeys); - assertEquals("8 key M0 [1]", 0, params.getColumnPos(0)); - assertEquals("8 key M0 [2]", 1, params.getColumnPos(1)); - assertEquals("8 key M0 [3]", -1, params.getColumnPos(2)); - assertEquals("8 key M0 [4]", 2, params.getColumnPos(3)); - assertEquals("8 key M0 [5]", 0, params.getColumnPos(4)); - assertEquals("8 key M0 [6]", 1, params.getColumnPos(5)); - assertEquals("8 key M0 [7]", -1, params.getColumnPos(6)); - assertEquals("8 key M0 [8]", 2, params.getColumnPos(7)); - assertEquals("8 key M0 adjust", 0, params.mTopRowAdjustment); - assertEquals("8 key M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); - } - - // |[5] [6] [7] [8] - // |[1] [2] [3] [4] - public void testLayout8KeyL0() { - MiniKeyboardParams params = new MiniKeyboardParams(8, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L0, KEYBOARD_WIDTH); - assertEquals("8 key L0 columns", 4, params.mNumColumns); - assertEquals("8 key L0 rows", 2, params.mNumRows); - assertEquals("8 key L0 left", 0, params.mLeftKeys); - assertEquals("8 key L0 right", 4, params.mRightKeys); - assertEquals("8 key L0 [1]", 0, params.getColumnPos(0)); - assertEquals("8 key L0 [2]", 1, params.getColumnPos(1)); - assertEquals("8 key L0 [3]", 2, params.getColumnPos(2)); - assertEquals("8 key L0 [4]", 3, params.getColumnPos(3)); - assertEquals("8 key L0 [5]", 0, params.getColumnPos(4)); - assertEquals("8 key L0 [6]", 1, params.getColumnPos(5)); - assertEquals("8 key L0 [7]", 2, params.getColumnPos(6)); - assertEquals("8 key L0 [8]", 3, params.getColumnPos(7)); - assertEquals("8 key L0 adjust", 0, params.mTopRowAdjustment); - assertEquals("8 key L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); - } - - // |___ [5] [6] [7] [8] - // |___ [1] [2] [3] [4] - public void testLayout8KeyL1() { - MiniKeyboardParams params = new MiniKeyboardParams(8, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L1, KEYBOARD_WIDTH); - assertEquals("8 key L1 columns", 4, params.mNumColumns); - assertEquals("8 key L1 rows", 2, params.mNumRows); - assertEquals("8 key L1 left", 0, params.mLeftKeys); - assertEquals("8 key L1 right", 4, params.mRightKeys); - assertEquals("8 key L1 [1]", 0, params.getColumnPos(0)); - assertEquals("8 key L1 [2]", 1, params.getColumnPos(1)); - assertEquals("8 key L1 [3]", 2, params.getColumnPos(2)); - assertEquals("8 key L1 [4]", 3, params.getColumnPos(3)); - assertEquals("8 key L1 [5]", 0, params.getColumnPos(4)); - assertEquals("8 key L1 [6]", 1, params.getColumnPos(5)); - assertEquals("8 key L1 [7]", 2, params.getColumnPos(6)); - assertEquals("8 key L1 [8]", 3, params.getColumnPos(7)); - assertEquals("8 key L1 adjust", 0, params.mTopRowAdjustment); - assertEquals("8 key L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); - } - - // |___ ___ [7] [5] [6] [8] - // |___ ___ [3] [1] [2] [4] - public void testLayout8KeyL2() { - MiniKeyboardParams params = new MiniKeyboardParams(8, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L2, KEYBOARD_WIDTH); - assertEquals("8 key L2 columns", 4, params.mNumColumns); - assertEquals("8 key L2 rows", 2, params.mNumRows); - assertEquals("8 key L2 left", 1, params.mLeftKeys); - assertEquals("8 key L2 right", 3, params.mRightKeys); - assertEquals("8 key L2 [1]", 0, params.getColumnPos(0)); - assertEquals("8 key L2 [2]", 1, params.getColumnPos(1)); - assertEquals("8 key L2 [3]", -1, params.getColumnPos(2)); - assertEquals("8 key L2 [4]", 2, params.getColumnPos(3)); - assertEquals("8 key L2 [5]", 0, params.getColumnPos(4)); - assertEquals("8 key L2 [6]", 1, params.getColumnPos(5)); - assertEquals("8 key L2 [7]", -1, params.getColumnPos(6)); - assertEquals("8 key L2 [8]", 2, params.getColumnPos(7)); - assertEquals("8 key L2 adjust", 0, params.mTopRowAdjustment); - assertEquals("8 key L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); - } - - // [8] [7] [6] [5]| - // [4] [3] [2] [1]| - public void testLayout8KeyR0() { - MiniKeyboardParams params = new MiniKeyboardParams(8, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R0, KEYBOARD_WIDTH); - assertEquals("8 key R0 columns", 4, params.mNumColumns); - assertEquals("8 key R0 rows", 2, params.mNumRows); - assertEquals("8 key R0 left", 3, params.mLeftKeys); - assertEquals("8 key R0 right", 1, params.mRightKeys); - assertEquals("8 key R0 [1]", 0, params.getColumnPos(0)); - assertEquals("8 key R0 [2]", -1, params.getColumnPos(1)); - assertEquals("8 key R0 [3]", -2, params.getColumnPos(2)); - assertEquals("8 key R0 [4]", -3, params.getColumnPos(3)); - assertEquals("8 key R0 [5]", 0, params.getColumnPos(4)); - assertEquals("8 key R0 [6]", -1, params.getColumnPos(5)); - assertEquals("8 key R0 [7]", -2, params.getColumnPos(6)); - assertEquals("8 key R0 [8]", -3, params.getColumnPos(7)); - assertEquals("8 key R0 adjust", 0, params.mTopRowAdjustment); - assertEquals("8 key R0 default", WIDTH * 3, params.getDefaultKeyCoordX()); - } - - // [8] [7] [6] [5] ___| - // [4] [3] [2] [1] ___| - public void testLayout8KeyR1() { - MiniKeyboardParams params = new MiniKeyboardParams(8, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R1, KEYBOARD_WIDTH); - assertEquals("8 key R1 columns", 4, params.mNumColumns); - assertEquals("8 key R1 rows", 2, params.mNumRows); - assertEquals("8 key R1 left", 3, params.mLeftKeys); - assertEquals("8 key R1 right", 1, params.mRightKeys); - assertEquals("8 key R1 [1]", 0, params.getColumnPos(0)); - assertEquals("8 key R1 [2]", -1, params.getColumnPos(1)); - assertEquals("8 key R1 [3]", -2, params.getColumnPos(2)); - assertEquals("8 key R1 [4]", -3, params.getColumnPos(3)); - assertEquals("8 key R1 [5]", 0, params.getColumnPos(4)); - assertEquals("8 key R1 [6]", -1, params.getColumnPos(5)); - assertEquals("8 key R1 [7]", -2, params.getColumnPos(6)); - assertEquals("8 key R1 [8]", -3, params.getColumnPos(7)); - assertEquals("8 key R1 adjust", 0, params.mTopRowAdjustment); - assertEquals("8 key R1 default", WIDTH * 3, params.getDefaultKeyCoordX()); - } - - // [8] [7] [5] [6] ___ ___| - // [4] [3] [1] [2] ___ ___| - public void testLayout8KeyR2() { - MiniKeyboardParams params = new MiniKeyboardParams(8, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R2, KEYBOARD_WIDTH); - assertEquals("8 key R2 columns", 4, params.mNumColumns); - assertEquals("8 key R2 rows", 2, params.mNumRows); - assertEquals("8 key R2 left", 2, params.mLeftKeys); - assertEquals("8 key R2 right", 2, params.mRightKeys); - assertEquals("8 key R2 [1]", 0, params.getColumnPos(0)); - assertEquals("8 key R2 [2]", 1, params.getColumnPos(1)); - assertEquals("8 key R2 [3]", -1, params.getColumnPos(2)); - assertEquals("8 key R2 [4]", -2, params.getColumnPos(3)); - assertEquals("8 key R2 [5]", 0, params.getColumnPos(4)); - assertEquals("8 key R2 [6]", 1, params.getColumnPos(5)); - assertEquals("8 key R2 [7]", -1, params.getColumnPos(6)); - assertEquals("8 key R2 [8]", -2, params.getColumnPos(7)); - assertEquals("8 key R2 adjust", 0, params.mTopRowAdjustment); - assertEquals("8 key R2 default", WIDTH * 2, params.getDefaultKeyCoordX()); - } - - // [8] [6] [7] [9] - // [5] [3] [1] [2] [4] - public void testLayout9KeyM0() { - MiniKeyboardParams params = new MiniKeyboardParams(9, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_M0, KEYBOARD_WIDTH); - assertEquals("9 key M0 columns", 5, params.mNumColumns); - assertEquals("9 key M0 rows", 2, params.mNumRows); - assertEquals("9 key M0 left", 2, params.mLeftKeys); - assertEquals("9 key M0 right", 3, params.mRightKeys); - assertEquals("9 key M0 [1]", 0, params.getColumnPos(0)); - assertEquals("9 key M0 [2]", 1, params.getColumnPos(1)); - assertEquals("9 key M0 [3]", -1, params.getColumnPos(2)); - assertEquals("9 key M0 [4]", 2, params.getColumnPos(3)); - assertEquals("9 key M0 [5]", -2, params.getColumnPos(4)); - assertEquals("9 key M0 [6]", 0, params.getColumnPos(5)); - assertEquals("9 key M0 [7]", 1, params.getColumnPos(6)); - assertEquals("9 key M0 [8]", -1, params.getColumnPos(7)); - assertEquals("9 key M0 [9]", 2, params.getColumnPos(8)); - assertEquals("9 key M0 adjust", -1, params.mTopRowAdjustment); - assertEquals("9 key M0 default", WIDTH * 2, params.getDefaultKeyCoordX()); - } - - // |[6] [7] [8] [9] - // |[1] [2] [3] [4] [5] - public void testLayout9KeyL0() { - MiniKeyboardParams params = new MiniKeyboardParams(9, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L0, KEYBOARD_WIDTH); - assertEquals("9 key L0 columns", 5, params.mNumColumns); - assertEquals("9 key L0 rows", 2, params.mNumRows); - assertEquals("9 key L0 left", 0, params.mLeftKeys); - assertEquals("9 key L0 right", 5, params.mRightKeys); - assertEquals("9 key L0 [1]", 0, params.getColumnPos(0)); - assertEquals("9 key L0 [2]", 1, params.getColumnPos(1)); - assertEquals("9 key L0 [3]", 2, params.getColumnPos(2)); - assertEquals("9 key L0 [4]", 3, params.getColumnPos(3)); - assertEquals("9 key L0 [5]", 4, params.getColumnPos(4)); - assertEquals("9 key L0 [6]", 0, params.getColumnPos(5)); - assertEquals("9 key L0 [7]", 1, params.getColumnPos(6)); - assertEquals("9 key L0 [8]", 2, params.getColumnPos(7)); - assertEquals("9 key L0 [9]", 3, params.getColumnPos(8)); - assertEquals("9 key L0 adjust", 0, params.mTopRowAdjustment); - assertEquals("9 key L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); - } - - // |___ [6] [7] [8] [9] - // |___ [1] [2] [3] [4] [5] - public void testLayout9KeyL1() { - MiniKeyboardParams params = new MiniKeyboardParams(9, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L1, KEYBOARD_WIDTH); - assertEquals("9 key L1 columns", 5, params.mNumColumns); - assertEquals("9 key L1 rows", 2, params.mNumRows); - assertEquals("9 key L1 left", 0, params.mLeftKeys); - assertEquals("9 key L1 right", 5, params.mRightKeys); - assertEquals("9 key L1 [1]", 0, params.getColumnPos(0)); - assertEquals("9 key L1 [2]", 1, params.getColumnPos(1)); - assertEquals("9 key L1 [3]", 2, params.getColumnPos(2)); - assertEquals("9 key L1 [4]", 3, params.getColumnPos(3)); - assertEquals("9 key L1 [5]", 4, params.getColumnPos(4)); - assertEquals("9 key L1 [6]", 0, params.getColumnPos(5)); - assertEquals("9 key L1 [7]", 1, params.getColumnPos(6)); - assertEquals("9 key L1 [8]", 2, params.getColumnPos(7)); - assertEquals("9 key L1 [9]", 3, params.getColumnPos(8)); - assertEquals("9 key L1 adjust", 0, params.mTopRowAdjustment); - assertEquals("9 key L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); - } - - // |___ ___ [8] [6] [7] [9] - // |___ ___ [3] [1] [2] [4] [5] - public void testLayout9KeyL2() { - MiniKeyboardParams params = new MiniKeyboardParams(9, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L2, KEYBOARD_WIDTH); - assertEquals("9 key L2 columns", 5, params.mNumColumns); - assertEquals("9 key L2 rows", 2, params.mNumRows); - assertEquals("9 key L2 left", 1, params.mLeftKeys); - assertEquals("9 key L2 right", 4, params.mRightKeys); - assertEquals("9 key L2 [1]", 0, params.getColumnPos(0)); - assertEquals("9 key L2 [2]", 1, params.getColumnPos(1)); - assertEquals("9 key L2 [3]", -1, params.getColumnPos(2)); - assertEquals("9 key L2 [4]", 2, params.getColumnPos(3)); - assertEquals("9 key L2 [5]", 3, params.getColumnPos(4)); - assertEquals("9 key L2 [6]", 0, params.getColumnPos(5)); - assertEquals("9 key L2 [7]", 1, params.getColumnPos(6)); - assertEquals("9 key L2 [8]", -1, params.getColumnPos(7)); - assertEquals("9 key L2 [9]", 2, params.getColumnPos(8)); - assertEquals("9 key L2 adjust", 1, params.mTopRowAdjustment); - assertEquals("9 key L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); - } - - // [9] [8] [7] [6]| - // [5] [4] [3] [2] [1]| - public void testLayout9KeyR0() { - MiniKeyboardParams params = new MiniKeyboardParams(9, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R0, KEYBOARD_WIDTH); - assertEquals("9 key R0 columns", 5, params.mNumColumns); - assertEquals("9 key R0 rows", 2, params.mNumRows); - assertEquals("9 key R0 left", 4, params.mLeftKeys); - assertEquals("9 key R0 right", 1, params.mRightKeys); - assertEquals("9 key R0 [1]", 0, params.getColumnPos(0)); - assertEquals("9 key R0 [2]", -1, params.getColumnPos(1)); - assertEquals("9 key R0 [3]", -2, params.getColumnPos(2)); - assertEquals("9 key R0 [4]", -3, params.getColumnPos(3)); - assertEquals("9 key R0 [5]", -4, params.getColumnPos(4)); - assertEquals("9 key R0 [6]", 0, params.getColumnPos(5)); - assertEquals("9 key R0 [7]", -1, params.getColumnPos(6)); - assertEquals("9 key R0 [8]", -2, params.getColumnPos(7)); - assertEquals("9 key R0 [9]", -3, params.getColumnPos(8)); - assertEquals("9 key R0 adjust", 0, params.mTopRowAdjustment); - assertEquals("9 key R0 default", WIDTH * 4, params.getDefaultKeyCoordX()); - } - - // [9] [8] [7] [6] ___| - // [5] [4] [3] [2] [1] ___| - public void testLayout9KeyR1() { - MiniKeyboardParams params = new MiniKeyboardParams(9, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R1, KEYBOARD_WIDTH); - assertEquals("9 key R1 columns", 5, params.mNumColumns); - assertEquals("9 key R1 rows", 2, params.mNumRows); - assertEquals("9 key R1 left", 4, params.mLeftKeys); - assertEquals("9 key R1 right", 1, params.mRightKeys); - assertEquals("9 key R1 [1]", 0, params.getColumnPos(0)); - assertEquals("9 key R1 [2]", -1, params.getColumnPos(1)); - assertEquals("9 key R1 [3]", -2, params.getColumnPos(2)); - assertEquals("9 key R1 [4]", -3, params.getColumnPos(3)); - assertEquals("9 key R1 [5]", -4, params.getColumnPos(4)); - assertEquals("9 key R1 [6]", 0, params.getColumnPos(5)); - assertEquals("9 key R1 [7]", -1, params.getColumnPos(6)); - assertEquals("9 key R1 [8]", -2, params.getColumnPos(7)); - assertEquals("9 key R1 [9]", -3, params.getColumnPos(8)); - assertEquals("9 key R1 adjust", 0, params.mTopRowAdjustment); - assertEquals("9 key R1 default", WIDTH * 4, params.getDefaultKeyCoordX()); - } - - // [9] [8] [6] [7] ___ ___| - // [5] [4] [3] [1] [2] ___ ___| - public void testLayout9KeyR2() { - MiniKeyboardParams params = new MiniKeyboardParams(9, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R2, KEYBOARD_WIDTH); - assertEquals("9 key R2 columns", 5, params.mNumColumns); - assertEquals("9 key R2 rows", 2, params.mNumRows); - assertEquals("9 key R2 left", 3, params.mLeftKeys); - assertEquals("9 key R2 right", 2, params.mRightKeys); - assertEquals("9 key R2 [1]", 0, params.getColumnPos(0)); - assertEquals("9 key R2 [2]", 1, params.getColumnPos(1)); - assertEquals("9 key R2 [3]", -1, params.getColumnPos(2)); - assertEquals("9 key R2 [4]", -2, params.getColumnPos(3)); - assertEquals("9 key R2 [5]", -3, params.getColumnPos(4)); - assertEquals("9 key R2 [6]", 0, params.getColumnPos(5)); - assertEquals("9 key R2 [7]", 1, params.getColumnPos(6)); - assertEquals("9 key R2 [8]", -1, params.getColumnPos(7)); - assertEquals("9 key R2 [9]", -2, params.getColumnPos(8)); - assertEquals("9 key R2 adjust", -1, params.mTopRowAdjustment); - assertEquals("9 key R2 default", WIDTH * 3, params.getDefaultKeyCoordX()); - } - - // [A] [8] [6] [7] [9] - // [5] [3] [1] [2] [4] - public void testLayout10KeyM0() { - MiniKeyboardParams params = new MiniKeyboardParams(10, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_M0, KEYBOARD_WIDTH); - assertEquals("10 key M0 columns", 5, params.mNumColumns); - assertEquals("10 key M0 rows", 2, params.mNumRows); - assertEquals("10 key M0 left", 2, params.mLeftKeys); - assertEquals("10 key M0 right", 3, params.mRightKeys); - assertEquals("10 key M0 [1]", 0, params.getColumnPos(0)); - assertEquals("10 key M0 [2]", 1, params.getColumnPos(1)); - assertEquals("10 key M0 [3]", -1, params.getColumnPos(2)); - assertEquals("10 key M0 [4]", 2, params.getColumnPos(3)); - assertEquals("10 key M0 [5]", -2, params.getColumnPos(4)); - assertEquals("10 key M0 [6]", 0, params.getColumnPos(5)); - assertEquals("10 key M0 [7]", 1, params.getColumnPos(6)); - assertEquals("10 key M0 [8]", -1, params.getColumnPos(7)); - assertEquals("10 key M0 [9]", 2, params.getColumnPos(8)); - assertEquals("10 key M0 [A]", -2, params.getColumnPos(9)); - assertEquals("10 key M0 adjust", 0, params.mTopRowAdjustment); - assertEquals("10 key M0 default", WIDTH * 2, params.getDefaultKeyCoordX()); - } - - // |[6] [7] [8] [9] [A] - // |[1] [2] [3] [4] [5] - public void testLayout10KeyL0() { - MiniKeyboardParams params = new MiniKeyboardParams(10, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L0, KEYBOARD_WIDTH); - assertEquals("10 key L0 columns", 5, params.mNumColumns); - assertEquals("10 key L0 rows", 2, params.mNumRows); - assertEquals("10 key L0 left", 0, params.mLeftKeys); - assertEquals("10 key L0 right", 5, params.mRightKeys); - assertEquals("10 key L0 [1]", 0, params.getColumnPos(0)); - assertEquals("10 key L0 [2]", 1, params.getColumnPos(1)); - assertEquals("10 key L0 [3]", 2, params.getColumnPos(2)); - assertEquals("10 key L0 [4]", 3, params.getColumnPos(3)); - assertEquals("10 key L0 [5]", 4, params.getColumnPos(4)); - assertEquals("10 key L0 [6]", 0, params.getColumnPos(5)); - assertEquals("10 key L0 [7]", 1, params.getColumnPos(6)); - assertEquals("10 key L0 [8]", 2, params.getColumnPos(7)); - assertEquals("10 key L0 [9]", 3, params.getColumnPos(8)); - assertEquals("10 key L0 [A]", 4, params.getColumnPos(9)); - assertEquals("10 key L0 adjust", 0, params.mTopRowAdjustment); - assertEquals("10 key L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); - } - - // |___ [6] [7] [8] [9] [A] - // |___ [1] [2] [3] [4] [5] - public void testLayout10KeyL1() { - MiniKeyboardParams params = new MiniKeyboardParams(10, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L1, KEYBOARD_WIDTH); - assertEquals("10 key L1 columns", 5, params.mNumColumns); - assertEquals("10 key L1 rows", 2, params.mNumRows); - assertEquals("10 key L1 left", 0, params.mLeftKeys); - assertEquals("10 key L1 right", 5, params.mRightKeys); - assertEquals("10 key L1 [1]", 0, params.getColumnPos(0)); - assertEquals("10 key L1 [2]", 1, params.getColumnPos(1)); - assertEquals("10 key L1 [3]", 2, params.getColumnPos(2)); - assertEquals("10 key L1 [4]", 3, params.getColumnPos(3)); - assertEquals("10 key L1 [5]", 4, params.getColumnPos(4)); - assertEquals("10 key L1 [6]", 0, params.getColumnPos(5)); - assertEquals("10 key L1 [7]", 1, params.getColumnPos(6)); - assertEquals("10 key L1 [8]", 2, params.getColumnPos(7)); - assertEquals("10 key L1 [9]", 3, params.getColumnPos(8)); - assertEquals("10 key L1 [A]", 4, params.getColumnPos(9)); - assertEquals("10 key L1 adjust", 0, params.mTopRowAdjustment); - assertEquals("10 key L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); - } - - // |___ ___ [8] [6] [7] [9] [A] - // |___ ___ [3] [1] [2] [4] [5] - public void testLayout10KeyL2() { - MiniKeyboardParams params = new MiniKeyboardParams(10, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_L2, KEYBOARD_WIDTH); - assertEquals("10 key L2 columns", 5, params.mNumColumns); - assertEquals("10 key L2 rows", 2, params.mNumRows); - assertEquals("10 key L2 left", 1, params.mLeftKeys); - assertEquals("10 key L2 right", 4, params.mRightKeys); - assertEquals("10 key L2 [1]", 0, params.getColumnPos(0)); - assertEquals("10 key L2 [2]", 1, params.getColumnPos(1)); - assertEquals("10 key L2 [3]", -1, params.getColumnPos(2)); - assertEquals("10 key L2 [4]", 2, params.getColumnPos(3)); - assertEquals("10 key L2 [5]", 3, params.getColumnPos(4)); - assertEquals("10 key L2 [6]", 0, params.getColumnPos(5)); - assertEquals("10 key L2 [7]", 1, params.getColumnPos(6)); - assertEquals("10 key L2 [8]", -1, params.getColumnPos(7)); - assertEquals("10 key L2 [9]", 2, params.getColumnPos(8)); - assertEquals("10 key L2 [A]", 3, params.getColumnPos(9)); - assertEquals("10 key L2 adjust", 0, params.mTopRowAdjustment); - assertEquals("10 key L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); - } - - // [A] [9] [8] [7] [6]| - // [5] [4] [3] [2] [1]| - public void testLayout10KeyR0() { - MiniKeyboardParams params = new MiniKeyboardParams(10, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R0, KEYBOARD_WIDTH); - assertEquals("10 key R0 columns", 5, params.mNumColumns); - assertEquals("10 key R0 rows", 2, params.mNumRows); - assertEquals("10 key R0 left", 4, params.mLeftKeys); - assertEquals("10 key R0 right", 1, params.mRightKeys); - assertEquals("10 key R0 [1]", 0, params.getColumnPos(0)); - assertEquals("10 key R0 [2]", -1, params.getColumnPos(1)); - assertEquals("10 key R0 [3]", -2, params.getColumnPos(2)); - assertEquals("10 key R0 [4]", -3, params.getColumnPos(3)); - assertEquals("10 key R0 [5]", -4, params.getColumnPos(4)); - assertEquals("10 key R0 [6]", 0, params.getColumnPos(5)); - assertEquals("10 key R0 [7]", -1, params.getColumnPos(6)); - assertEquals("10 key R0 [8]", -2, params.getColumnPos(7)); - assertEquals("10 key R0 [9]", -3, params.getColumnPos(8)); - assertEquals("10 key R0 [A]", -4, params.getColumnPos(9)); - assertEquals("10 key R0 adjust", 0, params.mTopRowAdjustment); - assertEquals("10 key R0 default", WIDTH * 4, params.getDefaultKeyCoordX()); - } - - // [A] [9] [8] [7] [6] ___| - // [5] [4] [3] [2] [1] ___| - public void testLayout10KeyR1() { - MiniKeyboardParams params = new MiniKeyboardParams(10, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R1, KEYBOARD_WIDTH); - assertEquals("10 key R1 columns", 5, params.mNumColumns); - assertEquals("10 key R1 rows", 2, params.mNumRows); - assertEquals("10 key R1 left", 4, params.mLeftKeys); - assertEquals("10 key R1 right", 1, params.mRightKeys); - assertEquals("10 key R1 [1]", 0, params.getColumnPos(0)); - assertEquals("10 key R1 [2]", -1, params.getColumnPos(1)); - assertEquals("10 key R1 [3]", -2, params.getColumnPos(2)); - assertEquals("10 key R1 [4]", -3, params.getColumnPos(3)); - assertEquals("10 key R1 [5]", -4, params.getColumnPos(4)); - assertEquals("10 key R1 [6]", 0, params.getColumnPos(5)); - assertEquals("10 key R1 [7]", -1, params.getColumnPos(6)); - assertEquals("10 key R1 [8]", -2, params.getColumnPos(7)); - assertEquals("10 key R1 [9]", -3, params.getColumnPos(8)); - assertEquals("10 key R1 [A]", -4, params.getColumnPos(9)); - assertEquals("10 key R1 adjust", 0, params.mTopRowAdjustment); - assertEquals("10 key R1 default", WIDTH * 4, params.getDefaultKeyCoordX()); - } - - // [A] [9] [8] [6] [7] ___ ___| - // [5] [4] [3] [1] [2] ___ ___| - public void testLayout10KeyR2() { - MiniKeyboardParams params = new MiniKeyboardParams(10, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_R2, KEYBOARD_WIDTH); - assertEquals("10 key R2 columns", 5, params.mNumColumns); - assertEquals("10 key R2 rows", 2, params.mNumRows); - assertEquals("10 key R2 left", 3, params.mLeftKeys); - assertEquals("10 key R2 right", 2, params.mRightKeys); - assertEquals("10 key R2 [1]", 0, params.getColumnPos(0)); - assertEquals("10 key R2 [2]", 1, params.getColumnPos(1)); - assertEquals("10 key R2 [3]", -1, params.getColumnPos(2)); - assertEquals("10 key R2 [4]", -2, params.getColumnPos(3)); - assertEquals("10 key R2 [5]", -3, params.getColumnPos(4)); - assertEquals("10 key R2 [6]", 0, params.getColumnPos(5)); - assertEquals("10 key R2 [7]", 1, params.getColumnPos(6)); - assertEquals("10 key R2 [8]", -1, params.getColumnPos(7)); - assertEquals("10 key R2 [9]", -2, params.getColumnPos(8)); - assertEquals("10 key R2 [A]", -3, params.getColumnPos(9)); - assertEquals("10 key R2 adjust", 0, params.mTopRowAdjustment); - assertEquals("10 key R2 default", WIDTH * 3, params.getDefaultKeyCoordX()); - } - - // [B] [9] [A] - // [7] [5] [6] [8] - // [3] [1] [2] [4] - public void testLayout11KeyM0() { - MiniKeyboardParams params = new MiniKeyboardParams(11, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_M0, KEYBOARD_WIDTH); - assertEquals("11 key M0 columns", 4, params.mNumColumns); - assertEquals("11 key M0 rows", 3, params.mNumRows); - assertEquals("11 key M0 left", 1, params.mLeftKeys); - assertEquals("11 key M0 right", 3, params.mRightKeys); - assertEquals("11 key M0 [1]", 0, params.getColumnPos(0)); - assertEquals("11 key M0 [2]", 1, params.getColumnPos(1)); - assertEquals("11 key M0 [3]", -1, params.getColumnPos(2)); - assertEquals("11 key M0 [4]", 2, params.getColumnPos(3)); - assertEquals("11 key M0 [5]", 0, params.getColumnPos(4)); - assertEquals("11 key M0 [6]", 1, params.getColumnPos(5)); - assertEquals("11 key M0 [7]", -1, params.getColumnPos(6)); - assertEquals("11 key M0 [8]", 2, params.getColumnPos(7)); - assertEquals("11 key M0 [9]", 0, params.getColumnPos(8)); - assertEquals("11 key M0 [A]", 1, params.getColumnPos(9)); - assertEquals("11 key M0 [B]", -1, params.getColumnPos(10)); - assertEquals("11 key M0 adjust", 1, params.mTopRowAdjustment); - assertEquals("11 key M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); - } - - // [B] [9] [A] [C] - // [7] [5] [6] [8] - // [3] [1] [2] [4] - public void testLayout12KeyM0() { - MiniKeyboardParams params = new MiniKeyboardParams(12, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_M0, KEYBOARD_WIDTH); - assertEquals("12 key M0 columns", 4, params.mNumColumns); - assertEquals("12 key M0 rows", 3, params.mNumRows); - assertEquals("12 key M0 left", 1, params.mLeftKeys); - assertEquals("12 key M0 right", 3, params.mRightKeys); - assertEquals("12 key M0 [1]", 0, params.getColumnPos(0)); - assertEquals("12 key M0 [2]", 1, params.getColumnPos(1)); - assertEquals("12 key M0 [3]", -1, params.getColumnPos(2)); - assertEquals("12 key M0 [4]", 2, params.getColumnPos(3)); - assertEquals("12 key M0 [5]", 0, params.getColumnPos(4)); - assertEquals("12 key M0 [6]", 1, params.getColumnPos(5)); - assertEquals("12 key M0 [7]", -1, params.getColumnPos(6)); - assertEquals("12 key M0 [8]", 2, params.getColumnPos(7)); - assertEquals("12 key M0 [9]", 0, params.getColumnPos(8)); - assertEquals("12 key M0 [A]", 1, params.getColumnPos(9)); - assertEquals("12 key M0 [B]", -1, params.getColumnPos(10)); - assertEquals("12 key M0 [C]", 2, params.getColumnPos(11)); - assertEquals("12 key M0 adjust", 0, params.mTopRowAdjustment); - assertEquals("12 key M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); - } - - - // [D] [B] [C] - // [A] [8] [6] [7] [9] - // [5] [3] [1] [2] [4] - public void testLayout13KeyM0() { - MiniKeyboardParams params = new MiniKeyboardParams(13, MAX_COLUMNS, WIDTH, - HEIGHT, XPOS_M0, KEYBOARD_WIDTH); - assertEquals("13 key M0 columns", 5, params.mNumColumns); - assertEquals("13 key M0 rows", 3, params.mNumRows); - assertEquals("13 key M0 left", 2, params.mLeftKeys); - assertEquals("13 key M0 right", 3, params.mRightKeys); - assertEquals("13 key M0 [1]", 0, params.getColumnPos(0)); - assertEquals("13 key M0 [2]", 1, params.getColumnPos(1)); - assertEquals("13 key M0 [3]", -1, params.getColumnPos(2)); - assertEquals("13 key M0 [4]", 2, params.getColumnPos(3)); - assertEquals("13 key M0 [5]", -2, params.getColumnPos(4)); - assertEquals("13 key M0 [6]", 0, params.getColumnPos(5)); - assertEquals("13 key M0 [7]", 1, params.getColumnPos(6)); - assertEquals("13 key M0 [8]", -1, params.getColumnPos(7)); - assertEquals("13 key M0 [9]", 2, params.getColumnPos(8)); - assertEquals("13 key M0 [A]", -2, params.getColumnPos(9)); - assertEquals("13 key M0 [B]", 0, params.getColumnPos(10)); - assertEquals("13 key M0 [C]", 1, params.getColumnPos(11)); - assertEquals("13 key M0 [D]", -1, params.getColumnPos(12)); - assertEquals("13 key M0 adjust", 0, params.mTopRowAdjustment); - assertEquals("13 key M0 default", WIDTH * 2, params.getDefaultKeyCoordX()); - } -} -- cgit v1.2.3-83-g751a From 0ee3b694833df5488900f521adbd818a6a2e90a5 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 23 Aug 2011 17:55:46 +0900 Subject: Fix an excessive fallback problem. LatinIME has several fallbacks to ensure a dictionary is used. However, it should now be possible to deactivate the main dictionary through the dictionary pack settings. In this case, Latin IME should not fallback to the built-in dictionary. Change-Id: Ibd992ad89793169f04a968b40781fce819b87b6f --- .../inputmethod/latin/DictionaryFactory.java | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/latin/DictionaryFactory.java b/java/src/com/android/inputmethod/latin/DictionaryFactory.java index ffd204dac..9642151d7 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryFactory.java +++ b/java/src/com/android/inputmethod/latin/DictionaryFactory.java @@ -64,24 +64,10 @@ public class DictionaryFactory { } } - // null == dictList is not supposed to be possible, but better safe than sorry and it's - // safer for future extension. In this case, rather than returning null, it should be safer - // to return an empty DictionaryCollection. - if (null == dictList) { - return new DictionaryCollection(); - } else { - if (dictList.isEmpty()) { - // The list may be empty if no dictionaries have been added. The getter should not - // return an empty list, but if it does we end up here. Likewise, if the files - // we found could not be opened by the native code for any reason (format mismatch, - // file too big to fit in memory, etc) then we could have an empty list. In this - // case we want to fall back on the resource. - return new DictionaryCollection(createBinaryDictionary(context, fallbackResId, - locale)); - } else { - return new DictionaryCollection(dictList); - } - } + // If the list is empty, that means we should not use any dictionary (for example, the user + // explicitly disabled the main dictionary), so the following is okay. dictList is never + // null, but if for some reason it is, DictionaryCollection handles it gracefully. + return new DictionaryCollection(dictList); } /** -- cgit v1.2.3-83-g751a From c84bc3460d2fb386a1db2a2c8b135b746fa706cd Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 23 Aug 2011 17:57:02 +0900 Subject: Rename LatinKeyboardBaseView to LatinKeyboardView Bug: 5182291 Change-Id: I5089a14902b9f4ff1ab4f34e3f7a42aca5040d3e --- .../accessibility/AccessibleKeyboardViewProxy.java | 6 +- .../inputmethod/keyboard/KeyboardSwitcher.java | 8 +- .../inputmethod/keyboard/LatinKeyboard.java | 4 +- .../keyboard/LatinKeyboardBaseView.java | 691 --------------------- .../inputmethod/keyboard/LatinKeyboardView.java | 691 +++++++++++++++++++++ .../keyboard/PopupMiniKeyboardView.java | 4 +- .../android/inputmethod/keyboard/PopupPanel.java | 2 +- .../keyboard/SuddenJumpingTouchEventHandler.java | 2 +- .../com/android/inputmethod/latin/LatinIME.java | 12 +- 9 files changed, 710 insertions(+), 710 deletions(-) delete mode 100644 java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java create mode 100644 java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java index 3dca9aae6..8185619f9 100644 --- a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java +++ b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java @@ -35,7 +35,7 @@ import com.android.inputmethod.compat.InputTypeCompatUtils; import com.android.inputmethod.compat.MotionEventCompatUtils; import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.KeyDetector; -import com.android.inputmethod.keyboard.LatinKeyboardBaseView; +import com.android.inputmethod.keyboard.LatinKeyboardView; import com.android.inputmethod.keyboard.PointerTracker; public class AccessibleKeyboardViewProxy { @@ -47,7 +47,7 @@ public class AccessibleKeyboardViewProxy { private InputMethodService mInputMethod; private FlickGestureDetector mGestureDetector; - private LatinKeyboardBaseView mView; + private LatinKeyboardView mView; private AccessibleKeyboardActionListener mListener; private AudioManagerCompatWrapper mAudioManager; @@ -65,7 +65,7 @@ public class AccessibleKeyboardViewProxy { return sInstance; } - public static void setView(LatinKeyboardBaseView view) { + public static void setView(LatinKeyboardView view) { sInstance.mView = view; } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index ec19cce6c..8bf82807a 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -61,7 +61,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha private SharedPreferences mPrefs; private View mCurrentInputView; - private LatinKeyboardBaseView mKeyboardView; + private LatinKeyboardView mKeyboardView; private LatinIME mInputMethodService; private String mPackageName; private Resources mResources; @@ -745,7 +745,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } } - public LatinKeyboardBaseView getKeyboardView() { + public LatinKeyboardView getKeyboardView() { return mKeyboardView; } @@ -781,7 +781,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } } - mKeyboardView = (LatinKeyboardBaseView) mCurrentInputView.findViewById(R.id.keyboard_view); + mKeyboardView = (LatinKeyboardView) mCurrentInputView.findViewById(R.id.keyboard_view); mKeyboardView.setKeyboardActionListener(mInputMethodService); // This always needs to be set since the accessibility state can @@ -819,7 +819,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha final LatinKeyboard keyboard = getLatinKeyboard(); if (keyboard != null && keyboard.needsAutoCorrectionSpacebarLed()) { final Key invalidatedKey = keyboard.onAutoCorrectionStateChanged(isAutoCorrection); - final LatinKeyboardBaseView keyboardView = getKeyboardView(); + final LatinKeyboardView keyboardView = getKeyboardView(); if (keyboardView != null) keyboardView.invalidateKey(invalidatedKey); } diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java index d31d3e39f..1b6f57b92 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java @@ -141,7 +141,7 @@ public class LatinKeyboard extends Keyboard { } } - public void setSpacebarTextFadeFactor(float fadeFactor, LatinKeyboardBaseView view) { + public void setSpacebarTextFadeFactor(float fadeFactor, LatinKeyboardView view) { mSpacebarTextFadeFactor = fadeFactor; updateSpacebarForLocale(false); if (view != null) @@ -154,7 +154,7 @@ public class LatinKeyboard extends Keyboard { return newColor; } - public void updateShortcutKey(boolean available, LatinKeyboardBaseView view) { + public void updateShortcutKey(boolean available, LatinKeyboardView view) { if (mShortcutKey == null) return; mShortcutKey.setEnabled(available); diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java deleted file mode 100644 index 2af4594f4..000000000 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java +++ /dev/null @@ -1,691 +0,0 @@ -/* - * 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 android.content.Context; -import android.content.pm.PackageManager; -import android.content.res.Resources; -import android.content.res.TypedArray; -import android.graphics.Canvas; -import android.os.Message; -import android.os.SystemClock; -import android.util.AttributeSet; -import android.util.Log; -import android.view.GestureDetector; -import android.view.LayoutInflater; -import android.view.MotionEvent; -import android.view.View; -import android.view.ViewConfiguration; -import android.view.accessibility.AccessibilityEvent; -import android.widget.PopupWindow; - -import com.android.inputmethod.accessibility.AccessibilityUtils; -import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy; -import com.android.inputmethod.deprecated.VoiceProxy; -import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy; -import com.android.inputmethod.keyboard.PointerTracker.TimerProxy; -import com.android.inputmethod.latin.LatinIME; -import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.StaticInnerHandlerWrapper; -import com.android.inputmethod.latin.Utils; - -import java.util.WeakHashMap; - -/** - * A view that is responsible for detecting key presses and touch movements. - * - * @attr ref R.styleable#KeyboardView_keyHysteresisDistance - * @attr ref R.styleable#KeyboardView_verticalCorrection - * @attr ref R.styleable#KeyboardView_popupLayout - */ -public class LatinKeyboardBaseView extends KeyboardView implements PointerTracker.KeyEventHandler, - SuddenJumpingTouchEventHandler.ProcessMotionEvent { - private static final String TAG = LatinKeyboardBaseView.class.getSimpleName(); - - private static final boolean ENABLE_CAPSLOCK_BY_DOUBLETAP = true; - - private final SuddenJumpingTouchEventHandler mTouchScreenRegulator; - - // Timing constants - private final int mKeyRepeatInterval; - - // XML attribute - private final float mVerticalCorrection; - private final int mPopupLayout; - - // Mini keyboard - private PopupWindow mPopupWindow; - private PopupPanel mPopupPanel; - private int mPopupPanelPointerTrackerId; - private final WeakHashMap mPopupPanelCache = - new WeakHashMap(); - - /** Listener for {@link KeyboardActionListener}. */ - private KeyboardActionListener mKeyboardActionListener; - - private final boolean mHasDistinctMultitouch; - private int mOldPointerCount = 1; - private int mOldKeyIndex; - - protected KeyDetector mKeyDetector; - - // To detect double tap. - protected GestureDetector mGestureDetector; - - private final KeyTimerHandler mKeyTimerHandler = new KeyTimerHandler(this); - - private static class KeyTimerHandler extends StaticInnerHandlerWrapper - implements TimerProxy { - private static final int MSG_REPEAT_KEY = 1; - private static final int MSG_LONGPRESS_KEY = 2; - private static final int MSG_IGNORE_DOUBLE_TAP = 3; - - private boolean mInKeyRepeat; - - public KeyTimerHandler(LatinKeyboardBaseView outerInstance) { - super(outerInstance); - } - - @Override - public void handleMessage(Message msg) { - final LatinKeyboardBaseView keyboardView = getOuterInstance(); - final PointerTracker tracker = (PointerTracker) msg.obj; - switch (msg.what) { - case MSG_REPEAT_KEY: - tracker.onRepeatKey(msg.arg1); - startKeyRepeatTimer(keyboardView.mKeyRepeatInterval, msg.arg1, tracker); - break; - case MSG_LONGPRESS_KEY: - keyboardView.openMiniKeyboardIfRequired(msg.arg1, tracker); - break; - } - } - - @Override - public void startKeyRepeatTimer(long delay, int keyIndex, PointerTracker tracker) { - mInKeyRepeat = true; - sendMessageDelayed(obtainMessage(MSG_REPEAT_KEY, keyIndex, 0, tracker), delay); - } - - public void cancelKeyRepeatTimer() { - mInKeyRepeat = false; - removeMessages(MSG_REPEAT_KEY); - } - - public boolean isInKeyRepeat() { - return mInKeyRepeat; - } - - @Override - public void startLongPressTimer(long delay, int keyIndex, PointerTracker tracker) { - cancelLongPressTimer(); - sendMessageDelayed(obtainMessage(MSG_LONGPRESS_KEY, keyIndex, 0, tracker), delay); - } - - @Override - public void cancelLongPressTimer() { - removeMessages(MSG_LONGPRESS_KEY); - } - - @Override - public void cancelKeyTimers() { - cancelKeyRepeatTimer(); - cancelLongPressTimer(); - removeMessages(MSG_IGNORE_DOUBLE_TAP); - } - - public void startIgnoringDoubleTap() { - sendMessageDelayed(obtainMessage(MSG_IGNORE_DOUBLE_TAP), - ViewConfiguration.getDoubleTapTimeout()); - } - - public boolean isIgnoringDoubleTap() { - return hasMessages(MSG_IGNORE_DOUBLE_TAP); - } - - public void cancelAllMessages() { - cancelKeyTimers(); - } - } - - private class DoubleTapListener extends GestureDetector.SimpleOnGestureListener { - private boolean mProcessingShiftDoubleTapEvent = false; - - @Override - public boolean onDoubleTap(MotionEvent firstDown) { - final Keyboard keyboard = getKeyboard(); - if (ENABLE_CAPSLOCK_BY_DOUBLETAP && keyboard instanceof LatinKeyboard - && ((LatinKeyboard) keyboard).isAlphaKeyboard()) { - final int pointerIndex = firstDown.getActionIndex(); - final int id = firstDown.getPointerId(pointerIndex); - final PointerTracker tracker = getPointerTracker(id); - // If the first down event is on shift key. - if (tracker.isOnShiftKey((int) firstDown.getX(), (int) firstDown.getY())) { - mProcessingShiftDoubleTapEvent = true; - return true; - } - } - mProcessingShiftDoubleTapEvent = false; - return false; - } - - @Override - public boolean onDoubleTapEvent(MotionEvent secondTap) { - if (mProcessingShiftDoubleTapEvent - && secondTap.getAction() == MotionEvent.ACTION_DOWN) { - final MotionEvent secondDown = secondTap; - final int pointerIndex = secondDown.getActionIndex(); - final int id = secondDown.getPointerId(pointerIndex); - final PointerTracker tracker = getPointerTracker(id); - // If the second down event is also on shift key. - if (tracker.isOnShiftKey((int) secondDown.getX(), (int) secondDown.getY())) { - // Detected a double tap on shift key. If we are in the ignoring double tap - // mode, it means we have already turned off caps lock in - // {@link KeyboardSwitcher#onReleaseShift} . - final boolean ignoringDoubleTap = mKeyTimerHandler.isIgnoringDoubleTap(); - if (!ignoringDoubleTap) - onDoubleTapShiftKey(tracker); - return true; - } - // Otherwise these events should not be handled as double tap. - mProcessingShiftDoubleTapEvent = false; - } - return mProcessingShiftDoubleTapEvent; - } - } - - public LatinKeyboardBaseView(Context context, AttributeSet attrs) { - this(context, attrs, R.attr.keyboardViewStyle); - } - - public LatinKeyboardBaseView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - - mTouchScreenRegulator = new SuddenJumpingTouchEventHandler(getContext(), this); - - final TypedArray a = context.obtainStyledAttributes( - attrs, R.styleable.KeyboardView, defStyle, R.style.KeyboardView); - mVerticalCorrection = a.getDimensionPixelOffset( - R.styleable.KeyboardView_verticalCorrection, 0); - mPopupLayout = a.getResourceId(R.styleable.KeyboardView_popupLayout, 0); - a.recycle(); - - final Resources res = getResources(); - final float keyHysteresisDistance = res.getDimension(R.dimen.key_hysteresis_distance); - mKeyDetector = new KeyDetector(keyHysteresisDistance); - - final boolean ignoreMultitouch = true; - mGestureDetector = new GestureDetector( - getContext(), new DoubleTapListener(), null, ignoreMultitouch); - mGestureDetector.setIsLongpressEnabled(false); - - mHasDistinctMultitouch = context.getPackageManager() - .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT); - mKeyRepeatInterval = res.getInteger(R.integer.config_key_repeat_interval); - - PointerTracker.init(mHasDistinctMultitouch, getContext()); - } - - public void startIgnoringDoubleTap() { - if (ENABLE_CAPSLOCK_BY_DOUBLETAP) - mKeyTimerHandler.startIgnoringDoubleTap(); - } - - public void setKeyboardActionListener(KeyboardActionListener listener) { - mKeyboardActionListener = listener; - PointerTracker.setKeyboardActionListener(listener); - } - - /** - * Returns the {@link KeyboardActionListener} object. - * @return the listener attached to this keyboard - */ - @Override - public KeyboardActionListener getKeyboardActionListener() { - return mKeyboardActionListener; - } - - @Override - public KeyDetector getKeyDetector() { - return mKeyDetector; - } - - @Override - public DrawingProxy getDrawingProxy() { - return this; - } - - @Override - public TimerProxy getTimerProxy() { - return mKeyTimerHandler; - } - - @Override - public void setKeyPreviewPopupEnabled(boolean previewEnabled, int delay) { - final Keyboard keyboard = getKeyboard(); - if (keyboard instanceof LatinKeyboard) { - final LatinKeyboard latinKeyboard = (LatinKeyboard)keyboard; - if (latinKeyboard.isPhoneKeyboard() || latinKeyboard.isNumberKeyboard()) { - // Phone and number keyboard never shows popup preview. - super.setKeyPreviewPopupEnabled(false, delay); - return; - } - } - super.setKeyPreviewPopupEnabled(previewEnabled, delay); - } - - /** - * Attaches a keyboard to this view. The keyboard can be switched at any time and the - * view will re-layout itself to accommodate the keyboard. - * @see Keyboard - * @see #getKeyboard() - * @param keyboard the keyboard to display in this view - */ - @Override - public void setKeyboard(Keyboard keyboard) { - // Remove any pending messages, except dismissing preview - mKeyTimerHandler.cancelKeyTimers(); - super.setKeyboard(keyboard); - mKeyDetector.setKeyboard( - keyboard, -getPaddingLeft(), -getPaddingTop() + mVerticalCorrection); - mKeyDetector.setProximityThreshold(keyboard.mMostCommonKeyWidth); - PointerTracker.setKeyDetector(mKeyDetector); - mTouchScreenRegulator.setKeyboard(keyboard); - mPopupPanelCache.clear(); - } - - /** - * Returns whether the device has distinct multi-touch panel. - * @return true if the device has distinct multi-touch panel. - */ - public boolean hasDistinctMultitouch() { - return mHasDistinctMultitouch; - } - - /** - * When enabled, calls to {@link KeyboardActionListener#onCodeInput} will include key - * codes for adjacent keys. When disabled, only the primary key code will be - * reported. - * @param enabled whether or not the proximity correction is enabled - */ - public void setProximityCorrectionEnabled(boolean enabled) { - mKeyDetector.setProximityCorrectionEnabled(enabled); - } - - /** - * Returns true if proximity correction is enabled. - */ - public boolean isProximityCorrectionEnabled() { - return mKeyDetector.isProximityCorrectionEnabled(); - } - - @Override - public void cancelAllMessages() { - mKeyTimerHandler.cancelAllMessages(); - super.cancelAllMessages(); - } - - private boolean openMiniKeyboardIfRequired(int keyIndex, PointerTracker tracker) { - // Check if we have a popup layout specified first. - if (mPopupLayout == 0) { - return false; - } - - // Check if we are already displaying popup panel. - if (mPopupPanel != null) - return false; - final Key parentKey = tracker.getKey(keyIndex); - if (parentKey == null) - return false; - return onLongPress(parentKey, tracker); - } - - private void onDoubleTapShiftKey(@SuppressWarnings("unused") PointerTracker tracker) { - // When shift key is double tapped, the first tap is correctly processed as usual tap. And - // the second tap is treated as this double tap event, so that we need not mark tracker - // calling setAlreadyProcessed() nor remove the tracker from mPointerQueue. - mKeyboardActionListener.onCodeInput(Keyboard.CODE_CAPSLOCK, null, 0, 0); - } - - // This default implementation returns a popup mini keyboard panel. - protected PopupPanel onCreatePopupPanel(Key parentKey) { - if (parentKey.mPopupCharacters == null) - return null; - - final View container = LayoutInflater.from(getContext()).inflate(mPopupLayout, null); - if (container == null) - throw new NullPointerException(); - - final PopupMiniKeyboardView miniKeyboardView = - (PopupMiniKeyboardView)container.findViewById(R.id.mini_keyboard_view); - final Keyboard parentKeyboard = getKeyboard(); - final Keyboard miniKeyboard = new MiniKeyboard.Builder( - this, parentKeyboard.mPopupKeyboardResId, parentKey, parentKeyboard).build(); - miniKeyboardView.setKeyboard(miniKeyboard); - - container.measure(MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.AT_MOST), - MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); - - return miniKeyboardView; - } - - @Override - protected boolean needsToDimKeyboard() { - return mPopupPanel != null; - } - - public void setSpacebarTextFadeFactor(float fadeFactor, LatinKeyboard oldKeyboard) { - final Keyboard keyboard = getKeyboard(); - // We should not set text fade factor to the keyboard which does not display the language on - // its spacebar. - if (keyboard instanceof LatinKeyboard && keyboard == oldKeyboard) { - ((LatinKeyboard)keyboard).setSpacebarTextFadeFactor(fadeFactor, this); - } - } - - /** - * Called when a key is long pressed. By default this will open mini keyboard associated - * with this key. - * @param parentKey the key that was long pressed - * @param tracker the pointer tracker which pressed the parent key - * @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 parentKey, PointerTracker tracker) { - final int primaryCode = parentKey.mCode; - final Keyboard keyboard = getKeyboard(); - if (keyboard instanceof LatinKeyboard) { - final LatinKeyboard latinKeyboard = (LatinKeyboard) keyboard; - if (primaryCode == Keyboard.CODE_DIGIT0 && latinKeyboard.isPhoneKeyboard()) { - tracker.onLongPressed(); - // Long pressing on 0 in phone number keypad gives you a '+'. - return invokeOnKey(Keyboard.CODE_PLUS); - } - if (primaryCode == Keyboard.CODE_SHIFT && latinKeyboard.isAlphaKeyboard()) { - tracker.onLongPressed(); - return invokeOnKey(Keyboard.CODE_CAPSLOCK); - } - } - if (primaryCode == Keyboard.CODE_SETTINGS || primaryCode == Keyboard.CODE_SPACE) { - // Both long pressing settings key and space key invoke IME switcher dialog. - if (getKeyboardActionListener().onCustomRequest( - LatinIME.CODE_SHOW_INPUT_METHOD_PICKER)) { - tracker.onLongPressed(); - return true; - } else { - return openPopupPanel(parentKey, tracker); - } - } else { - return openPopupPanel(parentKey, tracker); - } - } - - private boolean invokeOnKey(int primaryCode) { - getKeyboardActionListener().onCodeInput(primaryCode, null, - KeyboardActionListener.NOT_A_TOUCH_COORDINATE, - KeyboardActionListener.NOT_A_TOUCH_COORDINATE); - return true; - } - - private boolean openPopupPanel(Key parentKey, PointerTracker tracker) { - PopupPanel popupPanel = mPopupPanelCache.get(parentKey); - if (popupPanel == null) { - popupPanel = onCreatePopupPanel(parentKey); - if (popupPanel == null) - return false; - mPopupPanelCache.put(parentKey, popupPanel); - } - if (mPopupWindow == null) { - mPopupWindow = new PopupWindow(getContext()); - mPopupWindow.setBackgroundDrawable(null); - mPopupWindow.setAnimationStyle(R.style.PopupMiniKeyboardAnimation); - // Allow popup window to be drawn off the screen. - mPopupWindow.setClippingEnabled(false); - } - mPopupPanel = popupPanel; - mPopupPanelPointerTrackerId = tracker.mPointerId; - - popupPanel.showPopupPanel(this, parentKey, tracker, mPopupWindow); - final int translatedX = popupPanel.translateX(tracker.getLastX()); - final int translatedY = popupPanel.translateY(tracker.getLastY()); - tracker.onShowPopupPanel(translatedX, translatedY, SystemClock.uptimeMillis(), popupPanel); - - invalidateAllKeys(); - return true; - } - - private PointerTracker getPointerTracker(final int id) { - return PointerTracker.getPointerTracker(id, this); - } - - public boolean isInSlidingKeyInput() { - if (mPopupPanel != null) { - return true; - } else { - return PointerTracker.isAnyInSlidingKeyInput(); - } - } - - public int getPointerCount() { - return mOldPointerCount; - } - - @Override - public boolean onTouchEvent(MotionEvent me) { - return mTouchScreenRegulator.onTouchEvent(me); - } - - @Override - public boolean processMotionEvent(MotionEvent me) { - final boolean nonDistinctMultitouch = !mHasDistinctMultitouch; - final int action = me.getActionMasked(); - final int pointerCount = me.getPointerCount(); - final int oldPointerCount = mOldPointerCount; - mOldPointerCount = pointerCount; - - // TODO: cleanup this code into a multi-touch to single-touch event converter class? - // If the device does not have distinct multi-touch support panel, ignore all multi-touch - // events except a transition from/to single-touch. - if (nonDistinctMultitouch && pointerCount > 1 && oldPointerCount > 1) { - return true; - } - - // Gesture detector must be enabled only when mini-keyboard is not on the screen. - if (mPopupPanel == null && mGestureDetector != null - && mGestureDetector.onTouchEvent(me)) { - PointerTracker.dismissAllKeyPreviews(); - mKeyTimerHandler.cancelKeyTimers(); - return true; - } - - final long eventTime = me.getEventTime(); - final int index = me.getActionIndex(); - final int id = me.getPointerId(index); - final int x, y; - if (mPopupPanel != null && id == mPopupPanelPointerTrackerId) { - x = mPopupPanel.translateX((int)me.getX(index)); - y = mPopupPanel.translateY((int)me.getY(index)); - } else { - x = (int)me.getX(index); - y = (int)me.getY(index); - } - - if (mKeyTimerHandler.isInKeyRepeat()) { - final PointerTracker tracker = getPointerTracker(id); - // Key repeating timer will be canceled if 2 or more keys are in action, and current - // event (UP or DOWN) is non-modifier key. - if (pointerCount > 1 && !tracker.isModifier()) { - mKeyTimerHandler.cancelKeyRepeatTimer(); - } - // Up event will pass through. - } - - // TODO: cleanup this code into a multi-touch to single-touch event converter class? - // Translate mutli-touch event to single-touch events on the device that has no distinct - // multi-touch panel. - if (nonDistinctMultitouch) { - // Use only main (id=0) pointer tracker. - PointerTracker tracker = getPointerTracker(0); - if (pointerCount == 1 && oldPointerCount == 2) { - // Multi-touch to single touch transition. - // Send a down event for the latest pointer if the key is different from the - // previous key. - final int newKeyIndex = tracker.getKeyIndexOn(x, y); - if (mOldKeyIndex != newKeyIndex) { - tracker.onDownEvent(x, y, eventTime, this); - if (action == MotionEvent.ACTION_UP) - tracker.onUpEvent(x, y, eventTime); - } - } else if (pointerCount == 2 && oldPointerCount == 1) { - // Single-touch to multi-touch transition. - // Send an up event for the last pointer. - final int lastX = tracker.getLastX(); - final int lastY = tracker.getLastY(); - mOldKeyIndex = tracker.getKeyIndexOn(lastX, lastY); - tracker.onUpEvent(lastX, lastY, eventTime); - } else if (pointerCount == 1 && oldPointerCount == 1) { - processMotionEvent(tracker, action, x, y, eventTime, this); - } else { - Log.w(TAG, "Unknown touch panel behavior: pointer count is " + pointerCount - + " (old " + oldPointerCount + ")"); - } - return true; - } - - if (action == MotionEvent.ACTION_MOVE) { - for (int i = 0; i < pointerCount; i++) { - final PointerTracker tracker = getPointerTracker(me.getPointerId(i)); - final int px, py; - if (mPopupPanel != null && tracker.mPointerId == mPopupPanelPointerTrackerId) { - px = mPopupPanel.translateX((int)me.getX(i)); - py = mPopupPanel.translateY((int)me.getY(i)); - } else { - px = (int)me.getX(i); - py = (int)me.getY(i); - } - tracker.onMoveEvent(px, py, eventTime); - } - } else { - processMotionEvent(getPointerTracker(id), action, x, y, eventTime, this); - } - - return true; - } - - private static void processMotionEvent(PointerTracker tracker, int action, int x, int y, - long eventTime, PointerTracker.KeyEventHandler handler) { - switch (action) { - case MotionEvent.ACTION_DOWN: - case MotionEvent.ACTION_POINTER_DOWN: - tracker.onDownEvent(x, y, eventTime, handler); - break; - case MotionEvent.ACTION_UP: - case MotionEvent.ACTION_POINTER_UP: - tracker.onUpEvent(x, y, eventTime); - break; - case MotionEvent.ACTION_MOVE: - tracker.onMoveEvent(x, y, eventTime); - break; - case MotionEvent.ACTION_CANCEL: - tracker.onCancelEvent(x, y, eventTime); - break; - } - } - - @Override - public void closing() { - super.closing(); - dismissPopupPanel(); - mPopupPanelCache.clear(); - } - - @Override - public boolean dismissPopupPanel() { - if (mPopupWindow != null && mPopupWindow.isShowing()) { - mPopupWindow.dismiss(); - mPopupPanel = null; - mPopupPanelPointerTrackerId = -1; - invalidateAllKeys(); - return true; - } - return false; - } - - public boolean handleBack() { - return dismissPopupPanel(); - } - - @Override - public void draw(Canvas c) { - Utils.GCUtils.getInstance().reset(); - boolean tryGC = true; - for (int i = 0; i < Utils.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) { - try { - super.draw(c); - tryGC = false; - } catch (OutOfMemoryError e) { - tryGC = Utils.GCUtils.getInstance().tryGCOrWait("LatinKeyboardView", e); - } - } - } - - @Override - protected void onAttachedToWindow() { - // Token is available from here. - VoiceProxy.getInstance().onAttachedToWindow(); - } - - @Override - public boolean dispatchTouchEvent(MotionEvent event) { - // Drop non-hover touch events when touch exploration is enabled. - if (AccessibilityUtils.getInstance().isTouchExplorationEnabled()) { - return false; - } - - return super.dispatchTouchEvent(event); - } - - @Override - public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { - if (AccessibilityUtils.getInstance().isTouchExplorationEnabled()) { - final PointerTracker tracker = getPointerTracker(0); - return AccessibleKeyboardViewProxy.getInstance().dispatchPopulateAccessibilityEvent( - event, tracker) || super.dispatchPopulateAccessibilityEvent(event); - } - - return super.dispatchPopulateAccessibilityEvent(event); - } - - /** - * Receives hover events from the input framework. This method overrides - * View.dispatchHoverEvent(MotionEvent) on SDK version ICS or higher. On - * lower SDK versions, this method is never called. - * - * @param event The motion event to be dispatched. - * @return {@code true} if the event was handled by the view, {@code false} - * otherwise - */ - public boolean dispatchHoverEvent(MotionEvent event) { - if (AccessibilityUtils.getInstance().isTouchExplorationEnabled()) { - final PointerTracker tracker = getPointerTracker(0); - return AccessibleKeyboardViewProxy.getInstance().dispatchHoverEvent(event, tracker); - } - - // Reflection doesn't support calling superclass methods. - return false; - } -} diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java new file mode 100644 index 000000000..be04b5a52 --- /dev/null +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -0,0 +1,691 @@ +/* + * 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 android.content.Context; +import android.content.pm.PackageManager; +import android.content.res.Resources; +import android.content.res.TypedArray; +import android.graphics.Canvas; +import android.os.Message; +import android.os.SystemClock; +import android.util.AttributeSet; +import android.util.Log; +import android.view.GestureDetector; +import android.view.LayoutInflater; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewConfiguration; +import android.view.accessibility.AccessibilityEvent; +import android.widget.PopupWindow; + +import com.android.inputmethod.accessibility.AccessibilityUtils; +import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy; +import com.android.inputmethod.deprecated.VoiceProxy; +import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy; +import com.android.inputmethod.keyboard.PointerTracker.TimerProxy; +import com.android.inputmethod.latin.LatinIME; +import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.StaticInnerHandlerWrapper; +import com.android.inputmethod.latin.Utils; + +import java.util.WeakHashMap; + +/** + * A view that is responsible for detecting key presses and touch movements. + * + * @attr ref R.styleable#KeyboardView_keyHysteresisDistance + * @attr ref R.styleable#KeyboardView_verticalCorrection + * @attr ref R.styleable#KeyboardView_popupLayout + */ +public class LatinKeyboardView extends KeyboardView implements PointerTracker.KeyEventHandler, + SuddenJumpingTouchEventHandler.ProcessMotionEvent { + private static final String TAG = LatinKeyboardView.class.getSimpleName(); + + private static final boolean ENABLE_CAPSLOCK_BY_DOUBLETAP = true; + + private final SuddenJumpingTouchEventHandler mTouchScreenRegulator; + + // Timing constants + private final int mKeyRepeatInterval; + + // XML attribute + private final float mVerticalCorrection; + private final int mPopupLayout; + + // Mini keyboard + private PopupWindow mPopupWindow; + private PopupPanel mPopupPanel; + private int mPopupPanelPointerTrackerId; + private final WeakHashMap mPopupPanelCache = + new WeakHashMap(); + + /** Listener for {@link KeyboardActionListener}. */ + private KeyboardActionListener mKeyboardActionListener; + + private final boolean mHasDistinctMultitouch; + private int mOldPointerCount = 1; + private int mOldKeyIndex; + + protected KeyDetector mKeyDetector; + + // To detect double tap. + protected GestureDetector mGestureDetector; + + private final KeyTimerHandler mKeyTimerHandler = new KeyTimerHandler(this); + + private static class KeyTimerHandler extends StaticInnerHandlerWrapper + implements TimerProxy { + private static final int MSG_REPEAT_KEY = 1; + private static final int MSG_LONGPRESS_KEY = 2; + private static final int MSG_IGNORE_DOUBLE_TAP = 3; + + private boolean mInKeyRepeat; + + public KeyTimerHandler(LatinKeyboardView outerInstance) { + super(outerInstance); + } + + @Override + public void handleMessage(Message msg) { + final LatinKeyboardView keyboardView = getOuterInstance(); + final PointerTracker tracker = (PointerTracker) msg.obj; + switch (msg.what) { + case MSG_REPEAT_KEY: + tracker.onRepeatKey(msg.arg1); + startKeyRepeatTimer(keyboardView.mKeyRepeatInterval, msg.arg1, tracker); + break; + case MSG_LONGPRESS_KEY: + keyboardView.openMiniKeyboardIfRequired(msg.arg1, tracker); + break; + } + } + + @Override + public void startKeyRepeatTimer(long delay, int keyIndex, PointerTracker tracker) { + mInKeyRepeat = true; + sendMessageDelayed(obtainMessage(MSG_REPEAT_KEY, keyIndex, 0, tracker), delay); + } + + public void cancelKeyRepeatTimer() { + mInKeyRepeat = false; + removeMessages(MSG_REPEAT_KEY); + } + + public boolean isInKeyRepeat() { + return mInKeyRepeat; + } + + @Override + public void startLongPressTimer(long delay, int keyIndex, PointerTracker tracker) { + cancelLongPressTimer(); + sendMessageDelayed(obtainMessage(MSG_LONGPRESS_KEY, keyIndex, 0, tracker), delay); + } + + @Override + public void cancelLongPressTimer() { + removeMessages(MSG_LONGPRESS_KEY); + } + + @Override + public void cancelKeyTimers() { + cancelKeyRepeatTimer(); + cancelLongPressTimer(); + removeMessages(MSG_IGNORE_DOUBLE_TAP); + } + + public void startIgnoringDoubleTap() { + sendMessageDelayed(obtainMessage(MSG_IGNORE_DOUBLE_TAP), + ViewConfiguration.getDoubleTapTimeout()); + } + + public boolean isIgnoringDoubleTap() { + return hasMessages(MSG_IGNORE_DOUBLE_TAP); + } + + public void cancelAllMessages() { + cancelKeyTimers(); + } + } + + private class DoubleTapListener extends GestureDetector.SimpleOnGestureListener { + private boolean mProcessingShiftDoubleTapEvent = false; + + @Override + public boolean onDoubleTap(MotionEvent firstDown) { + final Keyboard keyboard = getKeyboard(); + if (ENABLE_CAPSLOCK_BY_DOUBLETAP && keyboard instanceof LatinKeyboard + && ((LatinKeyboard) keyboard).isAlphaKeyboard()) { + final int pointerIndex = firstDown.getActionIndex(); + final int id = firstDown.getPointerId(pointerIndex); + final PointerTracker tracker = getPointerTracker(id); + // If the first down event is on shift key. + if (tracker.isOnShiftKey((int) firstDown.getX(), (int) firstDown.getY())) { + mProcessingShiftDoubleTapEvent = true; + return true; + } + } + mProcessingShiftDoubleTapEvent = false; + return false; + } + + @Override + public boolean onDoubleTapEvent(MotionEvent secondTap) { + if (mProcessingShiftDoubleTapEvent + && secondTap.getAction() == MotionEvent.ACTION_DOWN) { + final MotionEvent secondDown = secondTap; + final int pointerIndex = secondDown.getActionIndex(); + final int id = secondDown.getPointerId(pointerIndex); + final PointerTracker tracker = getPointerTracker(id); + // If the second down event is also on shift key. + if (tracker.isOnShiftKey((int) secondDown.getX(), (int) secondDown.getY())) { + // Detected a double tap on shift key. If we are in the ignoring double tap + // mode, it means we have already turned off caps lock in + // {@link KeyboardSwitcher#onReleaseShift} . + final boolean ignoringDoubleTap = mKeyTimerHandler.isIgnoringDoubleTap(); + if (!ignoringDoubleTap) + onDoubleTapShiftKey(tracker); + return true; + } + // Otherwise these events should not be handled as double tap. + mProcessingShiftDoubleTapEvent = false; + } + return mProcessingShiftDoubleTapEvent; + } + } + + public LatinKeyboardView(Context context, AttributeSet attrs) { + this(context, attrs, R.attr.keyboardViewStyle); + } + + public LatinKeyboardView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + + mTouchScreenRegulator = new SuddenJumpingTouchEventHandler(getContext(), this); + + final TypedArray a = context.obtainStyledAttributes( + attrs, R.styleable.KeyboardView, defStyle, R.style.KeyboardView); + mVerticalCorrection = a.getDimensionPixelOffset( + R.styleable.KeyboardView_verticalCorrection, 0); + mPopupLayout = a.getResourceId(R.styleable.KeyboardView_popupLayout, 0); + a.recycle(); + + final Resources res = getResources(); + final float keyHysteresisDistance = res.getDimension(R.dimen.key_hysteresis_distance); + mKeyDetector = new KeyDetector(keyHysteresisDistance); + + final boolean ignoreMultitouch = true; + mGestureDetector = new GestureDetector( + getContext(), new DoubleTapListener(), null, ignoreMultitouch); + mGestureDetector.setIsLongpressEnabled(false); + + mHasDistinctMultitouch = context.getPackageManager() + .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT); + mKeyRepeatInterval = res.getInteger(R.integer.config_key_repeat_interval); + + PointerTracker.init(mHasDistinctMultitouch, getContext()); + } + + public void startIgnoringDoubleTap() { + if (ENABLE_CAPSLOCK_BY_DOUBLETAP) + mKeyTimerHandler.startIgnoringDoubleTap(); + } + + public void setKeyboardActionListener(KeyboardActionListener listener) { + mKeyboardActionListener = listener; + PointerTracker.setKeyboardActionListener(listener); + } + + /** + * Returns the {@link KeyboardActionListener} object. + * @return the listener attached to this keyboard + */ + @Override + public KeyboardActionListener getKeyboardActionListener() { + return mKeyboardActionListener; + } + + @Override + public KeyDetector getKeyDetector() { + return mKeyDetector; + } + + @Override + public DrawingProxy getDrawingProxy() { + return this; + } + + @Override + public TimerProxy getTimerProxy() { + return mKeyTimerHandler; + } + + @Override + public void setKeyPreviewPopupEnabled(boolean previewEnabled, int delay) { + final Keyboard keyboard = getKeyboard(); + if (keyboard instanceof LatinKeyboard) { + final LatinKeyboard latinKeyboard = (LatinKeyboard)keyboard; + if (latinKeyboard.isPhoneKeyboard() || latinKeyboard.isNumberKeyboard()) { + // Phone and number keyboard never shows popup preview. + super.setKeyPreviewPopupEnabled(false, delay); + return; + } + } + super.setKeyPreviewPopupEnabled(previewEnabled, delay); + } + + /** + * Attaches a keyboard to this view. The keyboard can be switched at any time and the + * view will re-layout itself to accommodate the keyboard. + * @see Keyboard + * @see #getKeyboard() + * @param keyboard the keyboard to display in this view + */ + @Override + public void setKeyboard(Keyboard keyboard) { + // Remove any pending messages, except dismissing preview + mKeyTimerHandler.cancelKeyTimers(); + super.setKeyboard(keyboard); + mKeyDetector.setKeyboard( + keyboard, -getPaddingLeft(), -getPaddingTop() + mVerticalCorrection); + mKeyDetector.setProximityThreshold(keyboard.mMostCommonKeyWidth); + PointerTracker.setKeyDetector(mKeyDetector); + mTouchScreenRegulator.setKeyboard(keyboard); + mPopupPanelCache.clear(); + } + + /** + * Returns whether the device has distinct multi-touch panel. + * @return true if the device has distinct multi-touch panel. + */ + public boolean hasDistinctMultitouch() { + return mHasDistinctMultitouch; + } + + /** + * When enabled, calls to {@link KeyboardActionListener#onCodeInput} will include key + * codes for adjacent keys. When disabled, only the primary key code will be + * reported. + * @param enabled whether or not the proximity correction is enabled + */ + public void setProximityCorrectionEnabled(boolean enabled) { + mKeyDetector.setProximityCorrectionEnabled(enabled); + } + + /** + * Returns true if proximity correction is enabled. + */ + public boolean isProximityCorrectionEnabled() { + return mKeyDetector.isProximityCorrectionEnabled(); + } + + @Override + public void cancelAllMessages() { + mKeyTimerHandler.cancelAllMessages(); + super.cancelAllMessages(); + } + + private boolean openMiniKeyboardIfRequired(int keyIndex, PointerTracker tracker) { + // Check if we have a popup layout specified first. + if (mPopupLayout == 0) { + return false; + } + + // Check if we are already displaying popup panel. + if (mPopupPanel != null) + return false; + final Key parentKey = tracker.getKey(keyIndex); + if (parentKey == null) + return false; + return onLongPress(parentKey, tracker); + } + + private void onDoubleTapShiftKey(@SuppressWarnings("unused") PointerTracker tracker) { + // When shift key is double tapped, the first tap is correctly processed as usual tap. And + // the second tap is treated as this double tap event, so that we need not mark tracker + // calling setAlreadyProcessed() nor remove the tracker from mPointerQueue. + mKeyboardActionListener.onCodeInput(Keyboard.CODE_CAPSLOCK, null, 0, 0); + } + + // This default implementation returns a popup mini keyboard panel. + protected PopupPanel onCreatePopupPanel(Key parentKey) { + if (parentKey.mPopupCharacters == null) + return null; + + final View container = LayoutInflater.from(getContext()).inflate(mPopupLayout, null); + if (container == null) + throw new NullPointerException(); + + final PopupMiniKeyboardView miniKeyboardView = + (PopupMiniKeyboardView)container.findViewById(R.id.mini_keyboard_view); + final Keyboard parentKeyboard = getKeyboard(); + final Keyboard miniKeyboard = new MiniKeyboard.Builder( + this, parentKeyboard.mPopupKeyboardResId, parentKey, parentKeyboard).build(); + miniKeyboardView.setKeyboard(miniKeyboard); + + container.measure(MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.AT_MOST), + MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); + + return miniKeyboardView; + } + + @Override + protected boolean needsToDimKeyboard() { + return mPopupPanel != null; + } + + public void setSpacebarTextFadeFactor(float fadeFactor, LatinKeyboard oldKeyboard) { + final Keyboard keyboard = getKeyboard(); + // We should not set text fade factor to the keyboard which does not display the language on + // its spacebar. + if (keyboard instanceof LatinKeyboard && keyboard == oldKeyboard) { + ((LatinKeyboard)keyboard).setSpacebarTextFadeFactor(fadeFactor, this); + } + } + + /** + * Called when a key is long pressed. By default this will open mini keyboard associated + * with this key. + * @param parentKey the key that was long pressed + * @param tracker the pointer tracker which pressed the parent key + * @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 parentKey, PointerTracker tracker) { + final int primaryCode = parentKey.mCode; + final Keyboard keyboard = getKeyboard(); + if (keyboard instanceof LatinKeyboard) { + final LatinKeyboard latinKeyboard = (LatinKeyboard) keyboard; + if (primaryCode == Keyboard.CODE_DIGIT0 && latinKeyboard.isPhoneKeyboard()) { + tracker.onLongPressed(); + // Long pressing on 0 in phone number keypad gives you a '+'. + return invokeOnKey(Keyboard.CODE_PLUS); + } + if (primaryCode == Keyboard.CODE_SHIFT && latinKeyboard.isAlphaKeyboard()) { + tracker.onLongPressed(); + return invokeOnKey(Keyboard.CODE_CAPSLOCK); + } + } + if (primaryCode == Keyboard.CODE_SETTINGS || primaryCode == Keyboard.CODE_SPACE) { + // Both long pressing settings key and space key invoke IME switcher dialog. + if (getKeyboardActionListener().onCustomRequest( + LatinIME.CODE_SHOW_INPUT_METHOD_PICKER)) { + tracker.onLongPressed(); + return true; + } else { + return openPopupPanel(parentKey, tracker); + } + } else { + return openPopupPanel(parentKey, tracker); + } + } + + private boolean invokeOnKey(int primaryCode) { + getKeyboardActionListener().onCodeInput(primaryCode, null, + KeyboardActionListener.NOT_A_TOUCH_COORDINATE, + KeyboardActionListener.NOT_A_TOUCH_COORDINATE); + return true; + } + + private boolean openPopupPanel(Key parentKey, PointerTracker tracker) { + PopupPanel popupPanel = mPopupPanelCache.get(parentKey); + if (popupPanel == null) { + popupPanel = onCreatePopupPanel(parentKey); + if (popupPanel == null) + return false; + mPopupPanelCache.put(parentKey, popupPanel); + } + if (mPopupWindow == null) { + mPopupWindow = new PopupWindow(getContext()); + mPopupWindow.setBackgroundDrawable(null); + mPopupWindow.setAnimationStyle(R.style.PopupMiniKeyboardAnimation); + // Allow popup window to be drawn off the screen. + mPopupWindow.setClippingEnabled(false); + } + mPopupPanel = popupPanel; + mPopupPanelPointerTrackerId = tracker.mPointerId; + + popupPanel.showPopupPanel(this, parentKey, tracker, mPopupWindow); + final int translatedX = popupPanel.translateX(tracker.getLastX()); + final int translatedY = popupPanel.translateY(tracker.getLastY()); + tracker.onShowPopupPanel(translatedX, translatedY, SystemClock.uptimeMillis(), popupPanel); + + invalidateAllKeys(); + return true; + } + + private PointerTracker getPointerTracker(final int id) { + return PointerTracker.getPointerTracker(id, this); + } + + public boolean isInSlidingKeyInput() { + if (mPopupPanel != null) { + return true; + } else { + return PointerTracker.isAnyInSlidingKeyInput(); + } + } + + public int getPointerCount() { + return mOldPointerCount; + } + + @Override + public boolean onTouchEvent(MotionEvent me) { + return mTouchScreenRegulator.onTouchEvent(me); + } + + @Override + public boolean processMotionEvent(MotionEvent me) { + final boolean nonDistinctMultitouch = !mHasDistinctMultitouch; + final int action = me.getActionMasked(); + final int pointerCount = me.getPointerCount(); + final int oldPointerCount = mOldPointerCount; + mOldPointerCount = pointerCount; + + // TODO: cleanup this code into a multi-touch to single-touch event converter class? + // If the device does not have distinct multi-touch support panel, ignore all multi-touch + // events except a transition from/to single-touch. + if (nonDistinctMultitouch && pointerCount > 1 && oldPointerCount > 1) { + return true; + } + + // Gesture detector must be enabled only when mini-keyboard is not on the screen. + if (mPopupPanel == null && mGestureDetector != null + && mGestureDetector.onTouchEvent(me)) { + PointerTracker.dismissAllKeyPreviews(); + mKeyTimerHandler.cancelKeyTimers(); + return true; + } + + final long eventTime = me.getEventTime(); + final int index = me.getActionIndex(); + final int id = me.getPointerId(index); + final int x, y; + if (mPopupPanel != null && id == mPopupPanelPointerTrackerId) { + x = mPopupPanel.translateX((int)me.getX(index)); + y = mPopupPanel.translateY((int)me.getY(index)); + } else { + x = (int)me.getX(index); + y = (int)me.getY(index); + } + + if (mKeyTimerHandler.isInKeyRepeat()) { + final PointerTracker tracker = getPointerTracker(id); + // Key repeating timer will be canceled if 2 or more keys are in action, and current + // event (UP or DOWN) is non-modifier key. + if (pointerCount > 1 && !tracker.isModifier()) { + mKeyTimerHandler.cancelKeyRepeatTimer(); + } + // Up event will pass through. + } + + // TODO: cleanup this code into a multi-touch to single-touch event converter class? + // Translate mutli-touch event to single-touch events on the device that has no distinct + // multi-touch panel. + if (nonDistinctMultitouch) { + // Use only main (id=0) pointer tracker. + PointerTracker tracker = getPointerTracker(0); + if (pointerCount == 1 && oldPointerCount == 2) { + // Multi-touch to single touch transition. + // Send a down event for the latest pointer if the key is different from the + // previous key. + final int newKeyIndex = tracker.getKeyIndexOn(x, y); + if (mOldKeyIndex != newKeyIndex) { + tracker.onDownEvent(x, y, eventTime, this); + if (action == MotionEvent.ACTION_UP) + tracker.onUpEvent(x, y, eventTime); + } + } else if (pointerCount == 2 && oldPointerCount == 1) { + // Single-touch to multi-touch transition. + // Send an up event for the last pointer. + final int lastX = tracker.getLastX(); + final int lastY = tracker.getLastY(); + mOldKeyIndex = tracker.getKeyIndexOn(lastX, lastY); + tracker.onUpEvent(lastX, lastY, eventTime); + } else if (pointerCount == 1 && oldPointerCount == 1) { + processMotionEvent(tracker, action, x, y, eventTime, this); + } else { + Log.w(TAG, "Unknown touch panel behavior: pointer count is " + pointerCount + + " (old " + oldPointerCount + ")"); + } + return true; + } + + if (action == MotionEvent.ACTION_MOVE) { + for (int i = 0; i < pointerCount; i++) { + final PointerTracker tracker = getPointerTracker(me.getPointerId(i)); + final int px, py; + if (mPopupPanel != null && tracker.mPointerId == mPopupPanelPointerTrackerId) { + px = mPopupPanel.translateX((int)me.getX(i)); + py = mPopupPanel.translateY((int)me.getY(i)); + } else { + px = (int)me.getX(i); + py = (int)me.getY(i); + } + tracker.onMoveEvent(px, py, eventTime); + } + } else { + processMotionEvent(getPointerTracker(id), action, x, y, eventTime, this); + } + + return true; + } + + private static void processMotionEvent(PointerTracker tracker, int action, int x, int y, + long eventTime, PointerTracker.KeyEventHandler handler) { + switch (action) { + case MotionEvent.ACTION_DOWN: + case MotionEvent.ACTION_POINTER_DOWN: + tracker.onDownEvent(x, y, eventTime, handler); + break; + case MotionEvent.ACTION_UP: + case MotionEvent.ACTION_POINTER_UP: + tracker.onUpEvent(x, y, eventTime); + break; + case MotionEvent.ACTION_MOVE: + tracker.onMoveEvent(x, y, eventTime); + break; + case MotionEvent.ACTION_CANCEL: + tracker.onCancelEvent(x, y, eventTime); + break; + } + } + + @Override + public void closing() { + super.closing(); + dismissPopupPanel(); + mPopupPanelCache.clear(); + } + + @Override + public boolean dismissPopupPanel() { + if (mPopupWindow != null && mPopupWindow.isShowing()) { + mPopupWindow.dismiss(); + mPopupPanel = null; + mPopupPanelPointerTrackerId = -1; + invalidateAllKeys(); + return true; + } + return false; + } + + public boolean handleBack() { + return dismissPopupPanel(); + } + + @Override + public void draw(Canvas c) { + Utils.GCUtils.getInstance().reset(); + boolean tryGC = true; + for (int i = 0; i < Utils.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) { + try { + super.draw(c); + tryGC = false; + } catch (OutOfMemoryError e) { + tryGC = Utils.GCUtils.getInstance().tryGCOrWait("LatinKeyboardView", e); + } + } + } + + @Override + protected void onAttachedToWindow() { + // Token is available from here. + VoiceProxy.getInstance().onAttachedToWindow(); + } + + @Override + public boolean dispatchTouchEvent(MotionEvent event) { + // Drop non-hover touch events when touch exploration is enabled. + if (AccessibilityUtils.getInstance().isTouchExplorationEnabled()) { + return false; + } + + return super.dispatchTouchEvent(event); + } + + @Override + public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { + if (AccessibilityUtils.getInstance().isTouchExplorationEnabled()) { + final PointerTracker tracker = getPointerTracker(0); + return AccessibleKeyboardViewProxy.getInstance().dispatchPopulateAccessibilityEvent( + event, tracker) || super.dispatchPopulateAccessibilityEvent(event); + } + + return super.dispatchPopulateAccessibilityEvent(event); + } + + /** + * Receives hover events from the input framework. This method overrides + * View.dispatchHoverEvent(MotionEvent) on SDK version ICS or higher. On + * lower SDK versions, this method is never called. + * + * @param event The motion event to be dispatched. + * @return {@code true} if the event was handled by the view, {@code false} + * otherwise + */ + public boolean dispatchHoverEvent(MotionEvent event) { + if (AccessibilityUtils.getInstance().isTouchExplorationEnabled()) { + final PointerTracker tracker = getPointerTracker(0); + return AccessibleKeyboardViewProxy.getInstance().dispatchHoverEvent(event, tracker); + } + + // Reflection doesn't support calling superclass methods. + return false; + } +} diff --git a/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java b/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java index 1230dfb44..2396222bc 100644 --- a/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java @@ -41,7 +41,7 @@ public class PopupMiniKeyboardView extends KeyboardView implements PopupPanel { private final KeyDetector mKeyDetector; private final int mVerticalCorrection; - private LatinKeyboardBaseView mParentKeyboardView; + private LatinKeyboardView mParentKeyboardView; private int mOriginX; private int mOriginY; @@ -200,7 +200,7 @@ public class PopupMiniKeyboardView extends KeyboardView implements PopupPanel { } @Override - public void showPopupPanel(LatinKeyboardBaseView parentKeyboardView, Key parentKey, + public void showPopupPanel(LatinKeyboardView parentKeyboardView, Key parentKey, PointerTracker tracker, PopupWindow window) { mParentKeyboardView = parentKeyboardView; final View container = (View)getParent(); diff --git a/java/src/com/android/inputmethod/keyboard/PopupPanel.java b/java/src/com/android/inputmethod/keyboard/PopupPanel.java index dc526e74f..db637c50b 100644 --- a/java/src/com/android/inputmethod/keyboard/PopupPanel.java +++ b/java/src/com/android/inputmethod/keyboard/PopupPanel.java @@ -26,7 +26,7 @@ public interface PopupPanel extends PointerTracker.KeyEventHandler { * @param tracker the pointer tracker that pressesd the parent key * @param window PopupWindow to be used to show this popup panel */ - public void showPopupPanel(LatinKeyboardBaseView parentKeyboardView, Key parentKey, + public void showPopupPanel(LatinKeyboardView parentKeyboardView, Key parentKey, PointerTracker tracker, PopupWindow window); /** diff --git a/java/src/com/android/inputmethod/keyboard/SuddenJumpingTouchEventHandler.java b/java/src/com/android/inputmethod/keyboard/SuddenJumpingTouchEventHandler.java index 5344c27d4..c4251ccfc 100644 --- a/java/src/com/android/inputmethod/keyboard/SuddenJumpingTouchEventHandler.java +++ b/java/src/com/android/inputmethod/keyboard/SuddenJumpingTouchEventHandler.java @@ -78,7 +78,7 @@ public class SuddenJumpingTouchEventHandler { * the sudden moves subside, a DOWN event is simulated for the second key. * @param me the motion event * @return true if the event was consumed, so that it doesn't continue to be handled by - * {@link LatinKeyboardBaseView}. + * {@link LatinKeyboardView}. */ private boolean handleSuddenJumping(MotionEvent me) { if (!mNeedsSuddenJumpingHack) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 48bcd3b92..394414d03 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -67,7 +67,7 @@ import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.keyboard.KeyboardSwitcher.KeyboardLayoutState; import com.android.inputmethod.keyboard.KeyboardView; import com.android.inputmethod.keyboard.LatinKeyboard; -import com.android.inputmethod.keyboard.LatinKeyboardBaseView; +import com.android.inputmethod.keyboard.LatinKeyboardView; import java.io.FileDescriptor; import java.io.PrintWriter; @@ -229,7 +229,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar public void handleMessage(Message msg) { final LatinIME latinIme = getOuterInstance(); final KeyboardSwitcher switcher = latinIme.mKeyboardSwitcher; - final LatinKeyboardBaseView inputView = switcher.getKeyboardView(); + final LatinKeyboardView inputView = switcher.getKeyboardView(); switch (msg.what) { case MSG_UPDATE_SUGGESTIONS: latinIme.updateSuggestions(); @@ -330,7 +330,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar final LatinIME latinIme = getOuterInstance(); removeMessages(MSG_FADEOUT_LANGUAGE_ON_SPACEBAR); removeMessages(MSG_DISMISS_LANGUAGE_ON_SPACEBAR); - final LatinKeyboardBaseView inputView = latinIme.mKeyboardSwitcher.getKeyboardView(); + final LatinKeyboardView inputView = latinIme.mKeyboardSwitcher.getKeyboardView(); if (inputView != null) { final LatinKeyboard keyboard = latinIme.mKeyboardSwitcher.getLatinKeyboard(); // The language is always displayed when the delay is negative. @@ -610,7 +610,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } final KeyboardSwitcher switcher = mKeyboardSwitcher; - LatinKeyboardBaseView inputView = switcher.getKeyboardView(); + LatinKeyboardView inputView = switcher.getKeyboardView(); if (DEBUG) { Log.d(TAG, "onStartInputView: attribute:" + ((attribute == null) ? "none" @@ -1498,7 +1498,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar commitTyped(getCurrentInputConnection()); mVoiceProxy.handleClose(); requestHideSelf(0); - LatinKeyboardBaseView inputView = mKeyboardSwitcher.getKeyboardView(); + LatinKeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); if (inputView != null) inputView.closing(); } @@ -2070,7 +2070,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (!mSettingsValues.mVibrateOn) { return; } - LatinKeyboardBaseView inputView = mKeyboardSwitcher.getKeyboardView(); + LatinKeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); if (inputView != null) { inputView.performHapticFeedback( HapticFeedbackConstants.KEYBOARD_TAP, -- cgit v1.2.3-83-g751a From 57f05f44123fd458203a6f776f2ff904889d2616 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 24 Aug 2011 12:44:33 +0900 Subject: Move some static methods from SubtypeSwitcher to Utils Change-Id: I3ea8ffcdefcefaa82ae76a31bb65977009d8a040 --- .../languageswitcher/InputLanguageSelection.java | 5 ++-- .../deprecated/voice/RecognitionView.java | 3 ++- .../inputmethod/keyboard/LatinKeyboard.java | 6 ++--- .../android/inputmethod/latin/SubtypeSwitcher.java | 30 +--------------------- java/src/com/android/inputmethod/latin/Utils.java | 28 ++++++++++++++++++++ 5 files changed, 36 insertions(+), 36 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java b/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java index e75559e62..7eb5acda8 100644 --- a/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java +++ b/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java @@ -21,7 +21,6 @@ import com.android.inputmethod.latin.DictionaryFactory; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.Settings; import com.android.inputmethod.latin.SharedPreferencesCompat; -import com.android.inputmethod.latin.SubtypeSwitcher; import com.android.inputmethod.latin.Utils; import org.xmlpull.v1.XmlPullParserException; @@ -237,12 +236,12 @@ public class InputLanguageSelection extends PreferenceActivity { if (finalSize == 0) { preprocess[finalSize++] = - new LocaleEntry(SubtypeSwitcher.getFullDisplayName(l, false), l); + new LocaleEntry(Utils.getFullDisplayName(l, false), l); } else { if (s.equals("zz_ZZ")) { // ignore this locale } else { - final String displayName = SubtypeSwitcher.getFullDisplayName(l, false); + final String displayName = Utils.getFullDisplayName(l, false); preprocess[finalSize++] = new LocaleEntry(displayName, l); } } diff --git a/java/src/com/android/inputmethod/deprecated/voice/RecognitionView.java b/java/src/com/android/inputmethod/deprecated/voice/RecognitionView.java index dcb826e8f..71d15dc3d 100644 --- a/java/src/com/android/inputmethod/deprecated/voice/RecognitionView.java +++ b/java/src/com/android/inputmethod/deprecated/voice/RecognitionView.java @@ -18,6 +18,7 @@ package com.android.inputmethod.deprecated.voice; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.SubtypeSwitcher; +import com.android.inputmethod.latin.Utils; import android.content.Context; import android.content.res.Resources; @@ -221,7 +222,7 @@ public class RecognitionView { Locale locale = SubtypeSwitcher.getInstance().getInputLocale(); mLanguage.setVisibility(View.VISIBLE); - mLanguage.setText(SubtypeSwitcher.getFullDisplayName(locale, true)); + mLanguage.setText(Utils.getFullDisplayName(locale, true)); mPopupLayout.setBackgroundDrawable(mListeningBorder); break; diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java index 1b6f57b92..e18d3a6a8 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java @@ -216,7 +216,7 @@ public class LatinKeyboard extends Keyboard { final Rect bounds = new Rect(); // Estimate appropriate language name text size to fit in maxTextWidth. - String language = SubtypeSwitcher.getFullDisplayName(locale, true); + String language = Utils.getFullDisplayName(locale, true); int textWidth = getTextWidth(paint, language, origTextSize, bounds); // Assuming text width and text size are proportional to each other. float textSize = origTextSize * Math.min(width / textWidth, 1.0f); @@ -228,7 +228,7 @@ public class LatinKeyboard extends Keyboard { final boolean useShortName; if (useMiddleName) { - language = SubtypeSwitcher.getMiddleDisplayLanguage(locale); + language = Utils.getMiddleDisplayLanguage(locale); textWidth = getTextWidth(paint, language, origTextSize, bounds); textSize = origTextSize * Math.min(width / textWidth, 1.0f); useShortName = (textSize / origTextSize < MINIMUM_SCALE_OF_LANGUAGE_NAME) @@ -238,7 +238,7 @@ public class LatinKeyboard extends Keyboard { } if (useShortName) { - language = SubtypeSwitcher.getShortDisplayLanguage(locale); + language = Utils.getShortDisplayLanguage(locale); textWidth = getTextWidth(paint, language, origTextSize, bounds); textSize = origTextSize * Math.min(width / textWidth, 1.0f); } diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index 0a391a77e..369b11c11 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -492,36 +492,8 @@ public class SubtypeSwitcher { KeyboardSwitcher.getInstance().getKeyboardView().getWindowToken()); } - public static String getFullDisplayName(Locale locale, boolean returnsNameInThisLocale) { - if (returnsNameInThisLocale) { - return toTitleCase(SubtypeLocale.getFullDisplayName(locale), locale); - } else { - return toTitleCase(locale.getDisplayName(), locale); - } - } - - public static String getDisplayLanguage(Locale locale) { - return toTitleCase(SubtypeLocale.getFullDisplayName(locale), locale); - } - - public static String getMiddleDisplayLanguage(Locale locale) { - return toTitleCase((Utils.constructLocaleFromString( - locale.getLanguage()).getDisplayLanguage(locale)), locale); - } - - public static String getShortDisplayLanguage(Locale locale) { - return toTitleCase(locale.getLanguage(), locale); - } - - private static String toTitleCase(String s, Locale locale) { - if (s.length() == 0) { - return s; - } - return s.toUpperCase(locale).charAt(0) + s.substring(1); - } - public String getInputLanguageName() { - return getDisplayLanguage(getInputLocale()); + return Utils.getDisplayLanguage(getInputLocale()); } ///////////////////////////// diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java index 36fbfd951..ff051dcbb 100644 --- a/java/src/com/android/inputmethod/latin/Utils.java +++ b/java/src/com/android/inputmethod/latin/Utils.java @@ -769,4 +769,32 @@ public class Utils { StringBuilderPool.recycle((StringBuilder)garbage); } } + + public static String getFullDisplayName(Locale locale, boolean returnsNameInThisLocale) { + if (returnsNameInThisLocale) { + return toTitleCase(SubtypeLocale.getFullDisplayName(locale), locale); + } else { + return toTitleCase(locale.getDisplayName(), locale); + } + } + + public static String getDisplayLanguage(Locale locale) { + return toTitleCase(SubtypeLocale.getFullDisplayName(locale), locale); + } + + public static String getMiddleDisplayLanguage(Locale locale) { + return toTitleCase((constructLocaleFromString( + locale.getLanguage()).getDisplayLanguage(locale)), locale); + } + + public static String getShortDisplayLanguage(Locale locale) { + return toTitleCase(locale.getLanguage(), locale); + } + + private static String toTitleCase(String s, Locale locale) { + if (s.length() <= 1) { + return s; + } + return s.toUpperCase(locale).charAt(0) + s.substring(1); + } } -- cgit v1.2.3-83-g751a From af52c0ea04c6563feaa6ea7dbac5dd87c2a48cc6 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 23 Aug 2011 17:27:48 +0900 Subject: Implement "forceAscii" private IME option This change also introduces "AsciiCapable" extra value for subtype that indicates the subtype can input any ASCII code point from its keyboard layout. Only if the input field has "forceAscii" private IME option and the current subtype doesn't have "AsciiCapable" extra value, the en_US keyboard layout will be used for the input field. Bug: 3384942 Change-Id: I25e2553e37ecb5002df1164e45f6273845fe463b --- java/res/xml/method.xml | 22 ++++++++++++++++++++-- .../inputmethod/keyboard/KeyboardSwitcher.java | 15 ++++++++++----- .../inputmethod/keyboard/LatinKeyboard.java | 9 ++++----- .../com/android/inputmethod/latin/LatinIME.java | 12 ++++++++++++ .../android/inputmethod/latin/SubtypeSwitcher.java | 5 ++++- 5 files changed, 50 insertions(+), 13 deletions(-) (limited to 'java/src') diff --git a/java/res/xml/method.xml b/java/res/xml/method.xml index 0bf560d5a..452294e04 100644 --- a/java/res/xml/method.xml +++ b/java/res/xml/method.xml @@ -31,13 +31,13 @@ android:label="@string/subtype_en_US" android:imeSubtypeLocale="en_US" android:imeSubtypeMode="keyboard" - android:imeSubtypeExtraValue="TrySuppressingImeSwitcher" + android:imeSubtypeExtraValue="TrySuppressingImeSwitcher,AsciiCapable" /> diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 8bf82807a..b1212f424 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -258,8 +258,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha final SoftReference ref = mKeyboardCache.get(id); LatinKeyboard keyboard = (ref == null) ? null : ref.get(); if (keyboard == null) { - final Locale savedLocale = Utils.setSystemLocale( - mResources, mSubtypeSwitcher.getInputLocale()); + final Locale savedLocale = Utils.setSystemLocale(mResources, id.mLocale); try { keyboard = new LatinKeyboard.Builder(mThemeContext).load(id).build(); } finally { @@ -319,13 +318,19 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha final boolean hasSettingsKey = settingsKeyEnabled && !noSettingsKey; final int f2KeyMode = getF2KeyMode(settingsKeyEnabled, noSettingsKey); final boolean hasShortcutKey = voiceKeyEnabled && (isSymbols != voiceKeyOnMain); + final boolean forceAscii = Utils.inPrivateImeOptions( + mPackageName, LatinIME.IME_OPTION_FORCE_ASCII, editorInfo); + final boolean asciiCapable = mSubtypeSwitcher.currentSubtypeContainsExtraValueKey( + LatinIME.SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE); + final Locale locale = (forceAscii && !asciiCapable) + ? Locale.US : mSubtypeSwitcher.getInputLocale(); final Configuration conf = mResources.getConfiguration(); final DisplayMetrics dm = mResources.getDisplayMetrics(); return new KeyboardId( - mResources.getResourceEntryName(xmlId), xmlId, mSubtypeSwitcher.getInputLocale(), - conf.orientation, dm.widthPixels, mode, editorInfo, - hasSettingsKey, f2KeyMode, noSettingsKey, voiceKeyEnabled, hasShortcutKey); + mResources.getResourceEntryName(xmlId), xmlId, locale, conf.orientation, + dm.widthPixels, mode, editorInfo, hasSettingsKey, f2KeyMode, noSettingsKey, + voiceKeyEnabled, hasShortcutKey); } public int getKeyboardMode() { diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java index 1b6f57b92..133a9bad2 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java @@ -141,7 +141,7 @@ public class LatinKeyboard extends Keyboard { } } - public void setSpacebarTextFadeFactor(float fadeFactor, LatinKeyboardView view) { + public void setSpacebarTextFadeFactor(float fadeFactor, KeyboardView view) { mSpacebarTextFadeFactor = fadeFactor; updateSpacebarForLocale(false); if (view != null) @@ -154,7 +154,7 @@ public class LatinKeyboard extends Keyboard { return newColor; } - public void updateShortcutKey(boolean available, LatinKeyboardView view) { + public void updateShortcutKey(boolean available, KeyboardView view) { if (mShortcutKey == null) return; mShortcutKey.setEnabled(available); @@ -193,9 +193,8 @@ public class LatinKeyboard extends Keyboard { && Utils.hasMultipleEnabledIMEsOrSubtypes(imm, true /* include aux subtypes */); mSpaceKey.setNeedsSpecialPopupHint(shouldShowInputMethodPicker); // If application locales are explicitly selected. - if (mSubtypeSwitcher.needsToDisplayLanguage()) { - mSpaceKey.setIcon(getSpaceDrawable( - mSubtypeSwitcher.getInputLocale(), isAutoCorrection)); + if (mSubtypeSwitcher.needsToDisplayLanguage(mId.mLocale)) { + mSpaceKey.setIcon(getSpaceDrawable(mId.mLocale, isAutoCorrection)); } else if (isAutoCorrection) { mSpaceKey.setIcon(getSpaceDrawable(null, true)); } else { diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 394414d03..552517bc8 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -106,6 +106,18 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar */ public static final String IME_OPTION_NO_SETTINGS_KEY = "noSettingsKey"; + /** + * The private IME option used to indicate that the given text field needs + * ASCII code points input. + */ + public static final String IME_OPTION_FORCE_ASCII = "forceAscii"; + + /** + * The subtype extra value used to indicate that the subtype keyboard layout is capable for + * typing ASCII characters. + */ + public static final String SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE = "AsciiCapable"; + private static final int EXTENDED_TOUCHABLE_REGION_HEIGHT = 100; // How many continuous deletes at which to start deleting at a higher speed. diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index 0a391a77e..4e6268c1c 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -415,7 +415,10 @@ public class SubtypeSwitcher { return mEnabledKeyboardSubtypesOfCurrentInputMethod.size(); } - public boolean needsToDisplayLanguage() { + public boolean needsToDisplayLanguage(Locale keyboardLocale) { + if (!keyboardLocale.equals(mInputLocale)) { + return false; + } return mNeedsToDisplayLanguage; } -- cgit v1.2.3-83-g751a From 7b1f74bb9ddae952f4da6c8d9bbb0057984b0988 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Wed, 24 Aug 2011 12:45:52 +0900 Subject: Refactoring: cut out a method for caching a word list This is preparation to have the decrypting/unzipping code moved over to LatinIME. Bug: 5095140 Change-Id: Ic3fdcc3de673b46cef2eb9ebe6a52cbdd614e50a --- .../latin/BinaryDictionaryFileDumper.java | 66 +++++++++++++--------- .../inputmethod/latin/BinaryDictionaryGetter.java | 12 ++-- 2 files changed, 44 insertions(+), 34 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java index ed5f83b3b..1f756eafb 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java @@ -63,10 +63,10 @@ public class BinaryDictionaryFileDumper { } /** - * Queries a content provider for the list of dictionaries for a specific locale + * Queries a content provider for the list of word lists for a specific locale * available to copy into Latin IME. */ - private static List getDictIdList(final Locale locale, final Context context) { + private static List getWordListIds(final Locale locale, final Context context) { final ContentResolver resolver = context.getContentResolver(); final Uri dictionaryPackUri = getProviderUri(locale.toString()); @@ -88,41 +88,51 @@ public class BinaryDictionaryFileDumper { } /** - * Queries a content provider for dictionary data for some locale and cache the returned files + * Caches a word list the id of which is passed as an argument. + */ + private static AssetFileAddress cacheWordList(final String id, final Locale locale, + final ContentResolver resolver, final Context context) { + final Uri wordListUri = getProviderUri(id); + try { + final AssetFileDescriptor afd = resolver.openAssetFileDescriptor(wordListUri, "r"); + if (null == afd) return null; + final String fileName = copyFileTo(afd.createInputStream(), + BinaryDictionaryGetter.getCacheFileName(id, locale, context)); + afd.close(); + if (0 >= resolver.delete(wordListUri, null, null)) { + // I'd rather not print the word list ID to the log out of security concerns + Log.e(TAG, "Could not have the dictionary pack delete a word list"); + } + return AssetFileAddress.makeFromFileName(fileName); + } catch (FileNotFoundException e) { + // This may only come from openAssetFileDescriptor + return null; + } catch (IOException e) { + // Can't read the file for some reason. + Log.e(TAG, "Cannot read a word list from the dictionary pack : " + e); + } + return null; + } + + /** + * Queries a content provider for word list data for some locale and cache the returned files * - * This will query a content provider for dictionary data for a given locale, and copy the - * files locally so that they can be mmap'ed. This may overwrite previously cached dictionaries + * This will query a content provider for word list data for a given locale, and copy the + * files locally so that they can be mmap'ed. This may overwrite previously cached word lists * with newer versions if a newer version is made available by the content provider. - * @returns the addresses of the files, or null if no data could be obtained. + * @returns the addresses of the word list files, or null if no data could be obtained. * @throw FileNotFoundException if the provider returns non-existent data. * @throw IOException if the provider-returned data could not be read. */ - public static List cacheDictionariesFromContentProvider(final Locale locale, + public static List cacheWordListsFromContentProvider(final Locale locale, final Context context) { final ContentResolver resolver = context.getContentResolver(); - final List idList = getDictIdList(locale, context); + final List idList = getWordListIds(locale, context); final List fileAddressList = new ArrayList(); for (String id : idList) { - final Uri wordListUri = getProviderUri(id); - AssetFileDescriptor afd = null; - try { - afd = resolver.openAssetFileDescriptor(wordListUri, "r"); - } catch (FileNotFoundException e) { - // leave null inside afd and continue - } - if (null == afd) continue; - try { - final String fileName = copyFileTo(afd.createInputStream(), - BinaryDictionaryGetter.getCacheFileName(id, locale, context)); - afd.close(); - if (0 >= resolver.delete(wordListUri, null, null)) { - // I'd rather not print the word list ID to the log out of security concerns - Log.e(TAG, "Could not have the dictionary pack delete a word list"); - } - fileAddressList.add(AssetFileAddress.makeFromFileName(fileName)); - } catch (IOException e) { - // Can't read the file for some reason. Continue onto the next file. - Log.e(TAG, "Cannot read a word list from the dictionary pack : " + e); + final AssetFileAddress afd = cacheWordList(id, locale, resolver, context); + if (null != afd) { + fileAddressList.add(afd); } } return fileAddressList; diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java index 5d2dab0a9..38344300c 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java @@ -205,7 +205,7 @@ class BinaryDictionaryGetter { * @param context the context on which to open the files upon. * @return an array of binary dictionary files, which may be empty but may not be null. */ - private static File[] getCachedDictionaryList(final Locale locale, + private static File[] getCachedWordLists(final Locale locale, final Context context) { final String directoryName = getCacheDirectoryForLocale(locale, context); final File[] cacheFiles = new File(directoryName).listFiles(); @@ -235,11 +235,11 @@ class BinaryDictionaryGetter { public static List getDictionaryFiles(final Locale locale, final Context context, final int fallbackResId) { - // cacheDictionariesFromContentProvider returns the list of files it copied to local + // cacheWordListsFromContentProvider returns the list of files it copied to local // storage, but we don't really care about what was copied NOW: what we want is the // list of everything we ever cached, so we ignore the return value. - BinaryDictionaryFileDumper.cacheDictionariesFromContentProvider(locale, context); - final File[] cachedDictionaryList = getCachedDictionaryList(locale, context); + BinaryDictionaryFileDumper.cacheWordListsFromContentProvider(locale, context); + final File[] cachedWordLists = getCachedWordLists(locale, context); final String mainDictId = getMainDictId(locale); @@ -247,8 +247,8 @@ class BinaryDictionaryGetter { boolean foundMainDict = false; final ArrayList fileList = new ArrayList(); - // cachedDictionaryList may not be null, see doc for getCachedDictionaryList - for (final File f : cachedDictionaryList) { + // cachedWordLists may not be null, see doc for getCachedDictionaryList + for (final File f : cachedWordLists) { final String wordListId = getWordListIdFromFileName(f.getName()); if (wordListId.equals(mainDictId)) { foundMainDict = true; -- cgit v1.2.3-83-g751a From 38d512c0b24f3e5ce595e0b4b9092f84af380517 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Wed, 24 Aug 2011 16:32:29 +0900 Subject: Call the decrypt/unzip routines upon copying a dictionary. Bug: 5095140 Change-Id: I7000f752bc9b7fd6a7af4839b2f225c085300128 --- .../latin/BinaryDictionaryFileDumper.java | 143 +++++++++++++++------ .../android/inputmethod/latin/FileTransforms.java | 40 ++++++ 2 files changed, 143 insertions(+), 40 deletions(-) create mode 100644 java/src/com/android/inputmethod/latin/FileTransforms.java (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java index 1f756eafb..24bb7b78a 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java @@ -87,29 +87,112 @@ public class BinaryDictionaryFileDumper { return list; } + /** - * Caches a word list the id of which is passed as an argument. + * Helper method to encapsulate exception handling. + */ + private static AssetFileDescriptor openAssetFileDescriptor(final ContentResolver resolver, + final Uri uri) { + try { + return resolver.openAssetFileDescriptor(uri, "r"); + } catch (FileNotFoundException e) { + // I don't want to log the word list URI here for security concerns + Log.e(TAG, "Could not find a word list from the dictionary provider."); + return null; + } + } + + /** + * Caches a word list the id of which is passed as an argument. This will write the file + * to the cache file name designated by its id and locale, overwriting it if already present + * and creating it (and its containing directory) if necessary. */ private static AssetFileAddress cacheWordList(final String id, final Locale locale, final ContentResolver resolver, final Context context) { + + final int COMPRESSED_CRYPTED_COMPRESSED = 0; + final int CRYPTED_COMPRESSED = 1; + final int COMPRESSED_CRYPTED = 2; + final int COMPRESSED_ONLY = 3; + final int CRYPTED_ONLY = 4; + final int NONE = 5; + final int MODE_MIN = COMPRESSED_CRYPTED_COMPRESSED; + final int MODE_MAX = NONE; + final Uri wordListUri = getProviderUri(id); - try { - final AssetFileDescriptor afd = resolver.openAssetFileDescriptor(wordListUri, "r"); - if (null == afd) return null; - final String fileName = copyFileTo(afd.createInputStream(), - BinaryDictionaryGetter.getCacheFileName(id, locale, context)); - afd.close(); - if (0 >= resolver.delete(wordListUri, null, null)) { - // I'd rather not print the word list ID to the log out of security concerns - Log.e(TAG, "Could not have the dictionary pack delete a word list"); + final String outputFileName = BinaryDictionaryGetter.getCacheFileName(id, locale, context); + + for (int mode = MODE_MIN; mode <= MODE_MAX; ++mode) { + InputStream originalSourceStream = null; + InputStream inputStream = null; + FileOutputStream outputStream = null; + AssetFileDescriptor afd = null; + try { + // Open input. + afd = openAssetFileDescriptor(resolver, wordListUri); + // If we can't open it at all, don't even try a number of times. + if (null == afd) return null; + originalSourceStream = afd.createInputStream(); + // Open output. + outputStream = new FileOutputStream(outputFileName); + // Get the appropriate decryption method for this try + switch (mode) { + case COMPRESSED_CRYPTED_COMPRESSED: + inputStream = FileTransforms.getUncompressedStream( + FileTransforms.getDecryptedStream( + FileTransforms.getUncompressedStream( + originalSourceStream))); + break; + case CRYPTED_COMPRESSED: + inputStream = FileTransforms.getUncompressedStream( + FileTransforms.getDecryptedStream(originalSourceStream)); + break; + case COMPRESSED_CRYPTED: + inputStream = FileTransforms.getDecryptedStream( + FileTransforms.getUncompressedStream(originalSourceStream)); + break; + case COMPRESSED_ONLY: + inputStream = FileTransforms.getUncompressedStream(originalSourceStream); + break; + case CRYPTED_ONLY: + inputStream = FileTransforms.getDecryptedStream(originalSourceStream); + break; + case NONE: + inputStream = originalSourceStream; + break; + } + copyFileTo(inputStream, outputStream); + if (0 >= resolver.delete(wordListUri, null, null)) { + Log.e(TAG, "Could not have the dictionary pack delete a word list"); + } + // Success! Close files (through the finally{} clause) and return. + return AssetFileAddress.makeFromFileName(outputFileName); + } catch (Exception e) { + Log.e(TAG, "Can't open word list in mode " + mode + " : " + e); + // Try the next method. + } finally { + // Ignore exceptions while closing files. + try { + // afd.close() will close inputStream, we should not call inputStream.close(). + if (null != afd) afd.close(); + } catch (Exception e) { + Log.e(TAG, "Exception while closing a cross-process file descriptor : " + e); + } + try { + if (null != outputStream) outputStream.close(); + } catch (Exception e) { + Log.e(TAG, "Exception while closing a file : " + e); + } } - return AssetFileAddress.makeFromFileName(fileName); - } catch (FileNotFoundException e) { - // This may only come from openAssetFileDescriptor - return null; - } catch (IOException e) { - // Can't read the file for some reason. - Log.e(TAG, "Cannot read a word list from the dictionary pack : " + e); + } + + // We could not copy the file at all. This is very unexpected. + // I'd rather not print the word list ID to the log out of security concerns + Log.e(TAG, "Could not copy a word list. Will not be able to use it."); + // If we can't copy it we should probably delete it to avoid trying to copy it over + // and over each time we open LatinIME. + if (0 >= resolver.delete(wordListUri, null, null)) { + Log.e(TAG, "In addition, we were unable to delete it."); } return null; } @@ -139,35 +222,15 @@ public class BinaryDictionaryFileDumper { } /** - * Accepts a resource number as dictionary data for some locale and returns the name of a file. - * - * This will make the resource the cached dictionary for this locale, overwriting any previous - * cached data. - */ - public static String getDictionaryFileFromResource(int resource, Locale locale, - Context context) throws FileNotFoundException, IOException { - final Resources res = context.getResources(); - final Locale savedLocale = Utils.setSystemLocale(res, locale); - final InputStream stream = res.openRawResource(resource); - Utils.setSystemLocale(res, savedLocale); - return copyFileTo(stream, - BinaryDictionaryGetter.getCacheFileName(Integer.toString(resource), - locale, context)); - } - - /** - * Copies the data in an input stream to a target file, creating the file if necessary and - * overwriting it if it already exists. + * Copies the data in an input stream to a target file. * @param input the stream to be copied. - * @param outputFileName the name of a file to copy the data to. It is created if necessary. + * @param outputFile an outputstream to copy the data to. */ - private static String copyFileTo(final InputStream input, final String outputFileName) + private static void copyFileTo(final InputStream input, final FileOutputStream output) throws FileNotFoundException, IOException { final byte[] buffer = new byte[FILE_READ_BUFFER_SIZE]; - final FileOutputStream output = new FileOutputStream(outputFileName); for (int readBytes = input.read(buffer); readBytes >= 0; readBytes = input.read(buffer)) output.write(buffer, 0, readBytes); input.close(); - return outputFileName; } } diff --git a/java/src/com/android/inputmethod/latin/FileTransforms.java b/java/src/com/android/inputmethod/latin/FileTransforms.java new file mode 100644 index 000000000..d0374e01e --- /dev/null +++ b/java/src/com/android/inputmethod/latin/FileTransforms.java @@ -0,0 +1,40 @@ +/* + * 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.latin; + +import android.util.Log; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.zip.GZIPInputStream; + +public class FileTransforms { + public static OutputStream getCryptedStream(OutputStream out) { + // Crypt the stream. + return out; + } + + public static InputStream getDecryptedStream(InputStream in) { + // Decrypt the stream. + return in; + } + + public static InputStream getUncompressedStream(InputStream in) throws IOException { + return new GZIPInputStream(in); + } +} -- cgit v1.2.3-83-g751a From 580e1d7ac0cb90a464a3b3aed88047f85a4ab41f Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 24 Aug 2011 17:35:42 +0900 Subject: Fix suggestions strip press state to align vertically This change also tweaks more_suggestions_hint drawables to eliminate unnecessarily padding at the bottom. Bug: 5204563 Change-Id: If5ec731c9a490da0116a020e8fd405c7d025d707 --- java/res/drawable-hdpi/more_suggestions_hint.png | Bin 249 -> 242 bytes java/res/drawable-mdpi/more_suggestions_hint.png | Bin 226 -> 222 bytes java/res/drawable-xhdpi/more_suggestions_hint.png | Bin 322 -> 310 bytes .../com/android/inputmethod/latin/CandidateView.java | 9 +++++---- 4 files changed, 5 insertions(+), 4 deletions(-) (limited to 'java/src') diff --git a/java/res/drawable-hdpi/more_suggestions_hint.png b/java/res/drawable-hdpi/more_suggestions_hint.png index 4515f4434..93604752b 100644 Binary files a/java/res/drawable-hdpi/more_suggestions_hint.png and b/java/res/drawable-hdpi/more_suggestions_hint.png differ diff --git a/java/res/drawable-mdpi/more_suggestions_hint.png b/java/res/drawable-mdpi/more_suggestions_hint.png index 6168de353..7352810d3 100644 Binary files a/java/res/drawable-mdpi/more_suggestions_hint.png and b/java/res/drawable-mdpi/more_suggestions_hint.png differ diff --git a/java/res/drawable-xhdpi/more_suggestions_hint.png b/java/res/drawable-xhdpi/more_suggestions_hint.png index f577a3617..35fb42087 100644 Binary files a/java/res/drawable-xhdpi/more_suggestions_hint.png and b/java/res/drawable-xhdpi/more_suggestions_hint.png differ diff --git a/java/src/com/android/inputmethod/latin/CandidateView.java b/java/src/com/android/inputmethod/latin/CandidateView.java index d46b4b5b5..5f20c70b4 100644 --- a/java/src/com/android/inputmethod/latin/CandidateView.java +++ b/java/src/com/android/inputmethod/latin/CandidateView.java @@ -413,8 +413,10 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo // TODO: This "more suggestions hint" should have nicely designed icon. word.setCompoundDrawablesWithIntrinsicBounds( null, null, null, mMoreCandidateHint); + // HACK: To align with other TextView that has no compound drawables. + word.setCompoundDrawablePadding(-mMoreCandidateHint.getIntrinsicHeight()); } else { - word.setCompoundDrawables(null, null, null, null); + word.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null); } // Disable this candidate if the suggestion is null or empty. @@ -426,7 +428,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo word.setText(text); // TextView.setText() resets text scale x to 1.0. word.setTextScaleX(scaleX); stripView.addView(word); - setLayoutWeight(word, getCandidateWeight(index), mCandidateStripHeight); + setLayoutWeight(word, getCandidateWeight(index), MATCH_PARENT); if (DBG) { final CharSequence debugInfo = getDebugInfo(suggestions, pos); @@ -526,8 +528,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo mPreviewPopup = new PopupWindow(context); mPreviewText = (TextView) inflater.inflate(R.layout.candidate_preview, null); - mPreviewPopup.setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT, - ViewGroup.LayoutParams.WRAP_CONTENT); + mPreviewPopup.setWindowLayoutMode(WRAP_CONTENT, WRAP_CONTENT); mPreviewPopup.setContentView(mPreviewText); mPreviewPopup.setBackgroundDrawable(null); -- cgit v1.2.3-83-g751a From 20973de72b8e3ba607d17e50bb4fbc3cc815a6eb Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Wed, 24 Aug 2011 20:27:04 +0900 Subject: Avoid unnecessary output to the system log. The message this removes gets printed under normal conditions. Normally dictionary files are compressed then crypted, but not compressed a second time; however LatinIME tries to open a compressed-crypted-compressed file first, because it could not do it afterwards and we want to support this case. So under normal operations, the first method LatinIME tries is actually expected to fail. Also, if we decide to stop compressing or/and encrypting dicts LatinIME supports it as a valid use case. It should not print errors to the log. If the file cannot be open at all, then it is an unexpected case, and Latin IME still reports to the log. Change-Id: Ic5228c51365a101af1d03e2c893484d3050b5a1c --- .../src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java index 24bb7b78a..a4f20181c 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java @@ -168,7 +168,9 @@ public class BinaryDictionaryFileDumper { // Success! Close files (through the finally{} clause) and return. return AssetFileAddress.makeFromFileName(outputFileName); } catch (Exception e) { - Log.e(TAG, "Can't open word list in mode " + mode + " : " + e); + if (DEBUG) { + Log.i(TAG, "Can't open word list in mode " + mode + " : " + e); + } // Try the next method. } finally { // Ignore exceptions while closing files. -- cgit v1.2.3-83-g751a From a16621ada43c7b499857bc8967e454994098bff3 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Wed, 24 Aug 2011 21:36:18 +0900 Subject: Add a debug variable ...that was missing Change-Id: Ia3b17909f295e0a93dee633c8d67c0e03840023e --- java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java | 1 + 1 file changed, 1 insertion(+) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java index a4f20181c..89944407e 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java @@ -41,6 +41,7 @@ import java.util.Locale; */ public class BinaryDictionaryFileDumper { private static final String TAG = BinaryDictionaryFileDumper.class.getSimpleName(); + private static final boolean DEBUG = false; /** * The size of the temporary buffer to copy files. -- cgit v1.2.3-83-g751a From de4e8dedccc7b6db6df4c3f75d9f2458432c558a Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Thu, 25 Aug 2011 18:04:21 +0900 Subject: Allow sharing dictionaries between similar locales. Bug: 5058488 Change-Id: Ib12013f58afad957a8205b439f87480cc12ea06f --- .../latin/BinaryDictionaryFileDumper.java | 39 +++-- .../inputmethod/latin/BinaryDictionaryGetter.java | 63 +++++++-- .../com/android/inputmethod/latin/LocaleUtils.java | 157 +++++++++++++++++++++ .../android/inputmethod/latin/WordListInfo.java | 29 ++++ 4 files changed, 259 insertions(+), 29 deletions(-) create mode 100644 java/src/com/android/inputmethod/latin/LocaleUtils.java create mode 100644 java/src/com/android/inputmethod/latin/WordListInfo.java (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java index 89944407e..e95172d1f 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java @@ -67,25 +67,34 @@ public class BinaryDictionaryFileDumper { * Queries a content provider for the list of word lists for a specific locale * available to copy into Latin IME. */ - private static List getWordListIds(final Locale locale, final Context context) { + private static List getWordListWordListInfos(final Locale locale, + final Context context) { final ContentResolver resolver = context.getContentResolver(); final Uri dictionaryPackUri = getProviderUri(locale.toString()); final Cursor c = resolver.query(dictionaryPackUri, DICTIONARY_PROJECTION, null, null, null); - if (null == c) return Collections.emptyList(); + if (null == c) return Collections.emptyList(); if (c.getCount() <= 0 || !c.moveToFirst()) { c.close(); - return Collections.emptyList(); + return Collections.emptyList(); } - final List list = new ArrayList(); - do { - final String id = c.getString(0); - if (TextUtils.isEmpty(id)) continue; - list.add(id); - } while (c.moveToNext()); - c.close(); - return list; + try { + final List list = new ArrayList(); + do { + final String wordListId = c.getString(0); + final String wordListLocale = c.getString(1); + if (TextUtils.isEmpty(wordListId)) continue; + list.add(new WordListInfo(wordListId, wordListLocale)); + } while (c.moveToNext()); + c.close(); + return list; + } catch (Exception e) { + // Just in case we hit a problem in communication with the dictionary pack. + // We don't want to die. + Log.e(TAG, "Exception communicating with the dictionary pack : " + e); + return Collections.emptyList(); + } } @@ -108,7 +117,7 @@ public class BinaryDictionaryFileDumper { * to the cache file name designated by its id and locale, overwriting it if already present * and creating it (and its containing directory) if necessary. */ - private static AssetFileAddress cacheWordList(final String id, final Locale locale, + private static AssetFileAddress cacheWordList(final String id, final String locale, final ContentResolver resolver, final Context context) { final int COMPRESSED_CRYPTED_COMPRESSED = 0; @@ -213,10 +222,10 @@ public class BinaryDictionaryFileDumper { public static List cacheWordListsFromContentProvider(final Locale locale, final Context context) { final ContentResolver resolver = context.getContentResolver(); - final List idList = getWordListIds(locale, context); + final List idList = getWordListWordListInfos(locale, context); final List fileAddressList = new ArrayList(); - for (String id : idList) { - final AssetFileAddress afd = cacheWordList(id, locale, resolver, context); + for (WordListInfo id : idList) { + final AssetFileAddress afd = cacheWordList(id.mId, id.mLocale, resolver, context); if (null != afd) { fileAddressList.add(afd); } diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java index 38344300c..360c944d2 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java @@ -108,12 +108,19 @@ class BinaryDictionaryGetter { return sb.toString(); } + /** + * Helper method to get the top level cache directory. + */ + private static String getWordListCacheDirectory(final Context context) { + return context.getFilesDir() + File.separator + "dicts"; + } + /** * Find out the cache directory associated with a specific locale. */ - private static String getCacheDirectoryForLocale(Locale locale, Context context) { - final String relativeDirectoryName = replaceFileNameDangerousCharacters(locale.toString()); - final String absoluteDirectoryName = context.getFilesDir() + File.separator + private static String getCacheDirectoryForLocale(final String locale, final Context context) { + final String relativeDirectoryName = replaceFileNameDangerousCharacters(locale); + final String absoluteDirectoryName = getWordListCacheDirectory(context) + File.separator + relativeDirectoryName; final File directory = new File(absoluteDirectoryName); if (!directory.exists()) { @@ -135,11 +142,11 @@ class BinaryDictionaryGetter { * named like the locale, except it will also escape characters that look dangerous * to some file systems. * @param id the id of the dictionary for which to get a file name - * @param locale the locale for which to get the file name + * @param locale the locale for which to get the file name as a string * @param context the context to use for getting the directory * @return the name of the file to be created */ - public static String getCacheFileName(String id, Locale locale, Context context) { + public static String getCacheFileName(String id, String locale, Context context) { final String fileName = replaceFileNameDangerousCharacters(id); return getCacheDirectoryForLocale(locale, context) + File.separator + fileName; } @@ -198,26 +205,54 @@ class BinaryDictionaryGetter { } } + /** + * Helper method to the list of cache directories, one for each distinct locale. + */ + private static File[] getCachedDirectoryList(final Context context) { + return new File(getWordListCacheDirectory(context)).listFiles(); + } + /** * Returns the list of cached files for a specific locale. * - * @param locale the locale to find the dictionary files for. + * @param locale the locale to find the dictionary files for, as a string. * @param context the context on which to open the files upon. * @return an array of binary dictionary files, which may be empty but may not be null. */ - private static File[] getCachedWordLists(final Locale locale, + private static File[] getCachedWordLists(final String locale, final Context context) { - final String directoryName = getCacheDirectoryForLocale(locale, context); - final File[] cacheFiles = new File(directoryName).listFiles(); - if (null == cacheFiles) return EMPTY_FILE_ARRAY; - return cacheFiles; + final File[] directoryList = getCachedDirectoryList(context); + if (null == directoryList) return EMPTY_FILE_ARRAY; + final ArrayList cacheFiles = new ArrayList(); + for (File directory : directoryList) { + if (!directory.isDirectory()) continue; + final String dirLocale = getWordListIdFromFileName(directory.getName()); + if (LocaleUtils.isMatch(LocaleUtils.getMatchLevel(dirLocale, locale))) { + final File[] wordLists = directory.listFiles(); + if (null != wordLists) { + for (File wordList : wordLists) { + cacheFiles.add(wordList); + } + } + } + } + if (cacheFiles.isEmpty()) return EMPTY_FILE_ARRAY; + return cacheFiles.toArray(EMPTY_FILE_ARRAY); } /** - * Returns the id of the main dict for a specified locale. + * Returns the id associated with the main word list for a specified locale. + * + * Word lists stored in Android Keyboard's resources are referred to as the "main" + * word lists. Since they can be updated like any other list, we need to assign a + * unique ID to them. This ID is just the name of the language (locale-wise) they + * are for, and this method returns this ID. */ private static String getMainDictId(final Locale locale) { - return locale.toString(); + // This works because we don't include by default different dictionaries for + // different countries. This actually needs to return the id that we would + // like to use for word lists included in resources, and the following is okay. + return locale.getLanguage().toString(); } /** @@ -239,7 +274,7 @@ class BinaryDictionaryGetter { // storage, but we don't really care about what was copied NOW: what we want is the // list of everything we ever cached, so we ignore the return value. BinaryDictionaryFileDumper.cacheWordListsFromContentProvider(locale, context); - final File[] cachedWordLists = getCachedWordLists(locale, context); + final File[] cachedWordLists = getCachedWordLists(locale.toString(), context); final String mainDictId = getMainDictId(locale); diff --git a/java/src/com/android/inputmethod/latin/LocaleUtils.java b/java/src/com/android/inputmethod/latin/LocaleUtils.java new file mode 100644 index 000000000..054f1f9b8 --- /dev/null +++ b/java/src/com/android/inputmethod/latin/LocaleUtils.java @@ -0,0 +1,157 @@ +/* + * 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.latin; + +import android.text.TextUtils; + +/** + * A class to help with handling Locales in string form. + * + * This file has the same meaning and features (and shares all of its code) with + * the one in the dictionary pack. They need to be kept synchronized; for any + * update/bugfix to this file, consider also updating/fixing the version in the + * dictionary pack. + */ +public class LocaleUtils { + + private final static String TAG = LocaleUtils.class.getSimpleName(); + + // Locale match level constants. + // A higher level of match is guaranteed to have a higher numerical value. + // Some room is left within constants to add match cases that may arise necessary + // in the future, for example differentiating between the case where the countries + // are both present and different, and the case where one of the locales does not + // specify the countries. This difference is not needed now. + + // Nothing matches. + public static final int LOCALE_NO_MATCH = 0; + // The languages matches, but the country are different. Or, the reference locale requires a + // country and the tested locale does not have one. + public static final int LOCALE_LANGUAGE_MATCH_COUNTRY_DIFFER = 3; + // The languages and country match, but the variants are different. Or, the reference locale + // requires a variant and the tested locale does not have one. + public static final int LOCALE_LANGUAGE_AND_COUNTRY_MATCH_VARIANT_DIFFER = 6; + // The required locale is null or empty so it will accept anything, and the tested locale + // is non-null and non-empty. + public static final int LOCALE_ANY_MATCH = 10; + // The language matches, and the tested locale specifies a country but the reference locale + // does not require one. + public static final int LOCALE_LANGUAGE_MATCH = 15; + // The language and the country match, and the tested locale specifies a variant but the + // reference locale does not require one. + public static final int LOCALE_LANGUAGE_AND_COUNTRY_MATCH = 20; + // The compared locales are fully identical. This is the best match level. + public static final int LOCALE_FULL_MATCH = 30; + + // The level at which a match is "normally" considered a locale match with standard algorithms. + // Don't use this directly, use #isMatch to test. + private static final int LOCALE_MATCH = LOCALE_ANY_MATCH; + + // Make this match the maximum match level. If this evolves to have more than 2 digits + // when written in base 10, also adjust the getMatchLevelSortedString method. + private static final int MATCH_LEVEL_MAX = 30; + + /** + * Return how well a tested locale matches a reference locale. + * + * This will check the tested locale against the reference locale and return a measure of how + * a well it matches the reference. The general idea is that the tested locale has to match + * every specified part of the required locale. A full match occur when they are equal, a + * partial match when the tested locale agrees with the reference locale but is more specific, + * and a difference when the tested locale does not comply with all requirements from the + * reference locale. + * In more detail, if the reference locale specifies at least a language and the testedLocale + * does not specify one, or specifies a different one, LOCALE_NO_MATCH is returned. If the + * reference locale is empty or null, it will match anything - in the form of LOCALE_FULL_MATCH + * if the tested locale is empty or null, and LOCALE_ANY_MATCH otherwise. If the reference and + * tested locale agree on the language, but not on the country, + * LOCALE_LANGUAGE_MATCH_COUNTRY_DIFFER is returned if the reference locale specifies a country, + * and LOCALE_LANGUAGE_MATCH otherwise. + * If they agree on both the language and the country, but not on the variant, + * LOCALE_LANGUAGE_AND_COUNTRY_MATCH_VARIANT_DIFFER is returned if the reference locale + * specifies a variant, and LOCALE_LANGUAGE_AND_COUNTRY_MATCH otherwise. If everything matches, + * LOCALE_FULL_MATCH is returned. + * Examples: + * en <=> en_US => LOCALE_LANGUAGE_MATCH + * en_US <=> en => LOCALE_LANGUAGE_MATCH_COUNTRY_DIFFER + * en_US_POSIX <=> en_US_Android => LOCALE_LANGUAGE_AND_COUNTRY_MATCH_VARIANT_DIFFER + * en_US <=> en_US_Android => LOCALE_LANGUAGE_AND_COUNTRY_MATCH + * sp_US <=> en_US => LOCALE_NO_MATCH + * de <=> de => LOCALE_FULL_MATCH + * en_US <=> en_US => LOCALE_FULL_MATCH + * "" <=> en_US => LOCALE_ANY_MATCH + * + * @param referenceLocale the reference locale to test against. + * @param testedLocale the locale to test. + * @return a constant that measures how well the tested locale matches the reference locale. + */ + public static int getMatchLevel(String referenceLocale, String testedLocale) { + if (TextUtils.isEmpty(referenceLocale)) { + return TextUtils.isEmpty(testedLocale) ? LOCALE_FULL_MATCH : LOCALE_ANY_MATCH; + } + if (null == testedLocale) return LOCALE_NO_MATCH; + String[] referenceParams = referenceLocale.split("_", 3); + String[] testedParams = testedLocale.split("_", 3); + // By spec of String#split, [0] cannot be null and length cannot be 0. + if (!referenceParams[0].equals(testedParams[0])) return LOCALE_NO_MATCH; + switch (referenceParams.length) { + case 1: + return 1 == testedParams.length ? LOCALE_FULL_MATCH : LOCALE_LANGUAGE_MATCH; + case 2: + if (1 == testedParams.length) return LOCALE_LANGUAGE_MATCH_COUNTRY_DIFFER; + if (!referenceParams[1].equals(testedParams[1])) + return LOCALE_LANGUAGE_MATCH_COUNTRY_DIFFER; + if (3 == testedParams.length) return LOCALE_LANGUAGE_AND_COUNTRY_MATCH; + return LOCALE_FULL_MATCH; + case 3: + if (1 == testedParams.length) return LOCALE_LANGUAGE_MATCH_COUNTRY_DIFFER; + if (!referenceParams[1].equals(testedParams[1])) + return LOCALE_LANGUAGE_MATCH_COUNTRY_DIFFER; + if (2 == testedParams.length) return LOCALE_LANGUAGE_AND_COUNTRY_MATCH_VARIANT_DIFFER; + if (!referenceParams[2].equals(testedParams[2])) + return LOCALE_LANGUAGE_AND_COUNTRY_MATCH_VARIANT_DIFFER; + return LOCALE_FULL_MATCH; + } + // It should be impossible to come here + return LOCALE_NO_MATCH; + } + + /** + * Return a string that represents this match level, with better matches first. + * + * The strings are sorted in lexicographic order: a better match will always be less than + * a worse match when compared together. + */ + public static String getMatchLevelSortedString(int matchLevel) { + // This works because the match levels are 0~99 (actually 0~30) + // Ideally this should use a number of digits equals to the 1og10 of the greater matchLevel + return String.format("%02d", MATCH_LEVEL_MAX - matchLevel); + } + + /** + * Find out whether a match level should be considered a match. + * + * This method takes a match level as returned by the #getMatchLevel method, and returns whether + * it should be considered a match in the usual sense with standard Locale functions. + * + * @param level the match level, as returned by getMatchLevel. + * @return whether this is a match or not. + */ + public static boolean isMatch(int level) { + return LOCALE_MATCH <= level; + } +} diff --git a/java/src/com/android/inputmethod/latin/WordListInfo.java b/java/src/com/android/inputmethod/latin/WordListInfo.java new file mode 100644 index 000000000..54f04d78f --- /dev/null +++ b/java/src/com/android/inputmethod/latin/WordListInfo.java @@ -0,0 +1,29 @@ +/** + * 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.latin; + +/** + * Information container for a word list. + */ +public class WordListInfo { + public final String mId; + public final String mLocale; + public WordListInfo(final String id, final String locale) { + mId = id; + mLocale = locale; + } +} -- cgit v1.2.3-83-g751a From f3f3189adbce15d609d5e06632f8e0630db890d1 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Fri, 26 Aug 2011 15:45:05 +0900 Subject: Wrap up popup mini keyboard Bug: 5218641 Change-Id: I88b3e7efa1f7c009c8a8e4f5453a5c4df2f91cfc --- .../android/inputmethod/keyboard/PopupMiniKeyboardView.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java b/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java index 2396222bc..c3b5825f5 100644 --- a/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java @@ -213,9 +213,10 @@ public class PopupMiniKeyboardView extends KeyboardView implements PopupPanel { final int pointY = parentKey.mY; final int miniKeyboardLeft = pointX - miniKeyboard.getDefaultCoordX() + parentKeyboardView.getPaddingLeft(); - final int x = Math.max(0, Math.min(miniKeyboardLeft, + final int x = wrapUp(Math.max(0, Math.min(miniKeyboardLeft, parentKeyboardView.getWidth() - miniKeyboard.mOccupiedWidth)) - - container.getPaddingLeft() + mCoordinates[0]; + - container.getPaddingLeft() + mCoordinates[0], + container.getMeasuredWidth(), 0, parentKeyboardView.getWidth()); final int y = pointY - parentKeyboard.mVerticalGap - (container.getMeasuredHeight() - container.getPaddingBottom()) + parentKeyboardView.getPaddingTop() + mCoordinates[1]; @@ -232,6 +233,14 @@ public class PopupMiniKeyboardView extends KeyboardView implements PopupPanel { mOriginY = y + container.getPaddingTop() - mCoordinates[1]; } + private static int wrapUp(int x, int width, int left, int right) { + if (x < left) + return left; + if (x + width > right) + return right - width; + return x; + } + @Override public boolean dismissPopupPanel() { return mParentKeyboardView.dismissPopupPanel(); -- cgit v1.2.3-83-g751a From c04bbc1ae9be81d25a356407c27a8e7fa22028bf Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Fri, 26 Aug 2011 15:13:30 +0900 Subject: Fix "touch to save" colors Bug: 5218662 Change-Id: I094b2ceb7438148eb5bdf620b188f598e8442a07 --- .../keyboard_popup_panel_background_holo.9.png | Bin 4047 -> 0 bytes .../keyboard_popup_panel_background_holo.9.png | Bin 3730 -> 0 bytes java/res/layout/candidates_strip.xml | 31 +------ java/res/values/styles.xml | 89 +++++++++++++++----- .../android/inputmethod/latin/CandidateView.java | 93 ++++++++++++++------- 5 files changed, 133 insertions(+), 80 deletions(-) delete mode 100644 java/res/drawable-hdpi/keyboard_popup_panel_background_holo.9.png delete mode 100644 java/res/drawable-mdpi/keyboard_popup_panel_background_holo.9.png (limited to 'java/src') diff --git a/java/res/drawable-hdpi/keyboard_popup_panel_background_holo.9.png b/java/res/drawable-hdpi/keyboard_popup_panel_background_holo.9.png deleted file mode 100644 index 4002dbe65..000000000 Binary files a/java/res/drawable-hdpi/keyboard_popup_panel_background_holo.9.png and /dev/null differ diff --git a/java/res/drawable-mdpi/keyboard_popup_panel_background_holo.9.png b/java/res/drawable-mdpi/keyboard_popup_panel_background_holo.9.png deleted file mode 100644 index 7be7ab7e2..000000000 Binary files a/java/res/drawable-mdpi/keyboard_popup_panel_background_holo.9.png and /dev/null differ diff --git a/java/res/layout/candidates_strip.xml b/java/res/layout/candidates_strip.xml index bcc1322b6..46cd691a7 100644 --- a/java/res/layout/candidates_strip.xml +++ b/java/res/layout/candidates_strip.xml @@ -25,35 +25,6 @@ - -