From 8632bff2d5a8e1160989008dea6eff4b94b065dd Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Fri, 20 May 2011 12:09:57 +0900 Subject: Fix copyright author from Google to AOSP Change-Id: Iaceedc783181e43af6dd48ece218a42eace66532 --- .../inputmethod/deprecated/languageswitcher/InputLanguageSelection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java') diff --git a/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java b/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java index b8655d112..fe70eef96 100644 --- a/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java +++ b/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2009 Google Inc. + * Copyright (C) 2008-2009 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 -- cgit v1.2.3-83-g751a From 72934bd5967d0127f71fd4d66158b18b4e6ceefe Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 22 Jun 2011 11:53:02 +0900 Subject: Move keyboard related internal class to separate package Change-Id: Ic1459066b865cde5104b3734193f76c997959c68 --- .../languageswitcher/InputLanguageSelection.java | 2 +- java/src/com/android/inputmethod/keyboard/Key.java | 449 ------- .../android/inputmethod/keyboard/KeyDetector.java | 2 + .../android/inputmethod/keyboard/KeyStyles.java | 259 ---- .../com/android/inputmethod/keyboard/Keyboard.java | 5 +- .../inputmethod/keyboard/KeyboardParser.java | 712 ---------- .../inputmethod/keyboard/KeyboardShiftState.java | 133 -- .../inputmethod/keyboard/KeyboardSwitcher.java | 3 + .../android/inputmethod/keyboard/KeyboardView.java | 4 + .../inputmethod/keyboard/LatinKeyboard.java | 2 + .../inputmethod/keyboard/LatinKeyboardView.java | 1 + .../android/inputmethod/keyboard/MiniKeyboard.java | 2 + .../inputmethod/keyboard/MiniKeyboardBuilder.java | 246 ---- .../keyboard/MiniKeyboardKeyDetector.java | 2 + .../inputmethod/keyboard/ModifierKeyState.java | 83 -- .../inputmethod/keyboard/PointerTracker.java | 3 + .../keyboard/PointerTrackerKeyState.java | 98 -- .../inputmethod/keyboard/PointerTrackerQueue.java | 83 -- .../keyboard/PopupCharactersParser.java | 176 --- .../keyboard/PopupMiniKeyboardView.java | 1 + .../android/inputmethod/keyboard/PopupPanel.java | 2 + .../inputmethod/keyboard/ProximityInfo.java | 1 + java/src/com/android/inputmethod/keyboard/Row.java | 72 - .../inputmethod/keyboard/ShiftKeyState.java | 69 - .../keyboard/SlidingLocaleDrawable.java | 157 --- .../android/inputmethod/keyboard/SwipeTracker.java | 157 --- .../android/inputmethod/keyboard/internal/Key.java | 450 +++++++ .../inputmethod/keyboard/internal/KeyStyles.java | 259 ++++ .../keyboard/internal/KeyboardParser.java | 714 ++++++++++ .../keyboard/internal/KeyboardShiftState.java | 135 ++ .../keyboard/internal/MiniKeyboardBuilder.java | 249 ++++ .../keyboard/internal/ModifierKeyState.java | 85 ++ .../keyboard/internal/PointerTrackerKeyState.java | 101 ++ .../keyboard/internal/PointerTrackerQueue.java | 85 ++ .../keyboard/internal/PopupCharactersParser.java | 177 +++ .../android/inputmethod/keyboard/internal/Row.java | 73 + .../keyboard/internal/ShiftKeyState.java | 69 + .../keyboard/internal/SlidingLocaleDrawable.java | 159 +++ .../keyboard/internal/SwipeTracker.java | 157 +++ .../inputmethod/keyboard/KeyStylesTests.java | 90 -- .../keyboard/MiniKeyboardBuilderTests.java | 1416 -------------------- .../keyboard/PopupCharactersParserTests.java | 207 --- .../keyboard/internal/KeyStylesTests.java | 90 ++ .../internal/MiniKeyboardBuilderTests.java | 1416 ++++++++++++++++++++ .../internal/PopupCharactersParserTests.java | 209 +++ .../inputmethod/latin/EventRingBufferTests.java | 2 +- .../android/inputmethod/latin/SuggestHelper.java | 2 +- 47 files changed, 4458 insertions(+), 4411 deletions(-) delete mode 100644 java/src/com/android/inputmethod/keyboard/Key.java delete mode 100644 java/src/com/android/inputmethod/keyboard/KeyStyles.java delete mode 100644 java/src/com/android/inputmethod/keyboard/KeyboardParser.java delete mode 100644 java/src/com/android/inputmethod/keyboard/KeyboardShiftState.java delete mode 100644 java/src/com/android/inputmethod/keyboard/MiniKeyboardBuilder.java delete mode 100644 java/src/com/android/inputmethod/keyboard/ModifierKeyState.java delete mode 100644 java/src/com/android/inputmethod/keyboard/PointerTrackerKeyState.java delete mode 100644 java/src/com/android/inputmethod/keyboard/PointerTrackerQueue.java delete mode 100644 java/src/com/android/inputmethod/keyboard/PopupCharactersParser.java delete mode 100644 java/src/com/android/inputmethod/keyboard/Row.java delete mode 100644 java/src/com/android/inputmethod/keyboard/ShiftKeyState.java delete mode 100644 java/src/com/android/inputmethod/keyboard/SlidingLocaleDrawable.java delete mode 100644 java/src/com/android/inputmethod/keyboard/SwipeTracker.java create mode 100644 java/src/com/android/inputmethod/keyboard/internal/Key.java create mode 100644 java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java create mode 100644 java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java create mode 100644 java/src/com/android/inputmethod/keyboard/internal/KeyboardShiftState.java create mode 100644 java/src/com/android/inputmethod/keyboard/internal/MiniKeyboardBuilder.java create mode 100644 java/src/com/android/inputmethod/keyboard/internal/ModifierKeyState.java create mode 100644 java/src/com/android/inputmethod/keyboard/internal/PointerTrackerKeyState.java create mode 100644 java/src/com/android/inputmethod/keyboard/internal/PointerTrackerQueue.java create mode 100644 java/src/com/android/inputmethod/keyboard/internal/PopupCharactersParser.java create mode 100644 java/src/com/android/inputmethod/keyboard/internal/Row.java create mode 100644 java/src/com/android/inputmethod/keyboard/internal/ShiftKeyState.java create mode 100644 java/src/com/android/inputmethod/keyboard/internal/SlidingLocaleDrawable.java create mode 100644 java/src/com/android/inputmethod/keyboard/internal/SwipeTracker.java delete mode 100644 tests/src/com/android/inputmethod/keyboard/KeyStylesTests.java delete mode 100644 tests/src/com/android/inputmethod/keyboard/MiniKeyboardBuilderTests.java delete mode 100644 tests/src/com/android/inputmethod/keyboard/PopupCharactersParserTests.java create mode 100644 tests/src/com/android/inputmethod/keyboard/internal/KeyStylesTests.java create mode 100644 tests/src/com/android/inputmethod/keyboard/internal/MiniKeyboardBuilderTests.java create mode 100644 tests/src/com/android/inputmethod/keyboard/internal/PopupCharactersParserTests.java (limited to 'java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java') diff --git a/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java b/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java index fe70eef96..cf6cd0f5e 100644 --- a/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java +++ b/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java @@ -16,7 +16,7 @@ package com.android.inputmethod.deprecated.languageswitcher; -import com.android.inputmethod.keyboard.KeyboardParser; +import com.android.inputmethod.keyboard.internal.KeyboardParser; import com.android.inputmethod.latin.DictionaryFactory; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.Settings; diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java deleted file mode 100644 index e5ee272a2..000000000 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ /dev/null @@ -1,449 +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 com.android.inputmethod.keyboard.KeyStyles.KeyStyle; -import com.android.inputmethod.keyboard.KeyboardParser.ParseException; -import com.android.inputmethod.latin.R; - -import android.content.res.Resources; -import android.content.res.TypedArray; -import android.content.res.XmlResourceParser; -import android.graphics.drawable.Drawable; -import android.text.TextUtils; -import android.util.Xml; - -import java.util.ArrayList; - -/** - * Class for describing the position and characteristics of a single key in the keyboard. - */ -public class Key { - /** - * The key code (unicode or custom code) that this key generates. - */ - public final int mCode; - - /** Label to display */ - public final CharSequence mLabel; - /** Hint letter to display on the key in conjunction with the label */ - public final CharSequence mHintLetter; - /** Option of the label */ - public final int mLabelOption; - public static final int LABEL_OPTION_ALIGN_LEFT = 0x01; - public static final int LABEL_OPTION_ALIGN_RIGHT = 0x02; - public static final int LABEL_OPTION_ALIGN_BOTTOM = 0x08; - public static final int LABEL_OPTION_FONT_NORMAL = 0x10; - private static final int LABEL_OPTION_POPUP_HINT = 0x20; - private static final int LABEL_OPTION_HAS_UPPERCASE_LETTER = 0x40; - - /** Icon to display instead of a label. Icon takes precedence over a label */ - private Drawable mIcon; - /** Preview version of the icon, for the preview popup */ - private Drawable mPreviewIcon; - - /** Width of the key, not including the gap */ - public final int mWidth; - /** Height of the key, not including the gap */ - public final int mHeight; - /** The horizontal gap around this key */ - public final int mGap; - /** The visual insets */ - public final int mVisualInsetsLeft; - public final int mVisualInsetsRight; - /** Whether this key is sticky, i.e., a toggle key */ - public final boolean mSticky; - /** X coordinate of the key in the keyboard layout */ - public final int mX; - /** Y coordinate of the key in the keyboard layout */ - public final int mY; - /** Text to output when pressed. This can be multiple characters, like ".com" */ - public final CharSequence mOutputText; - /** Popup characters */ - public final CharSequence[] mPopupCharacters; - /** Popup keyboard maximum column number */ - public final int mMaxPopupColumn; - - /** - * Flags that specify the anchoring to edges of the keyboard for detecting touch events - * that are just out of the boundary of the key. This is a bit mask of - * {@link Keyboard#EDGE_LEFT}, {@link Keyboard#EDGE_RIGHT}, - * {@link Keyboard#EDGE_TOP} and {@link Keyboard#EDGE_BOTTOM}. - */ - public final int mEdgeFlags; - /** Whether this is a functional key which has different key top than normal key */ - public final boolean mFunctional; - /** Whether this key repeats itself when held down */ - public final boolean mRepeatable; - - /** The Keyboard that this key belongs to */ - private final Keyboard mKeyboard; - - /** The current pressed state of this key */ - public boolean mPressed; - /** If this is a sticky key, is its highlight on? */ - public boolean mHighlightOn; - /** Key is enabled and responds on press */ - public boolean mEnabled = true; - - // keyWidth constants - private static final int KEYWIDTH_FILL_RIGHT = 0; - private static final int KEYWIDTH_FILL_BOTH = -1; - - private final static int[] KEY_STATE_NORMAL_ON = { - android.R.attr.state_checkable, - android.R.attr.state_checked - }; - - private final static int[] KEY_STATE_PRESSED_ON = { - android.R.attr.state_pressed, - android.R.attr.state_checkable, - android.R.attr.state_checked - }; - - private final static int[] KEY_STATE_NORMAL_OFF = { - android.R.attr.state_checkable - }; - - private final static int[] KEY_STATE_PRESSED_OFF = { - android.R.attr.state_pressed, - android.R.attr.state_checkable - }; - - private final static int[] KEY_STATE_NORMAL = { - }; - - private final static int[] KEY_STATE_PRESSED = { - android.R.attr.state_pressed - }; - - // functional normal state (with properties) - private static final int[] KEY_STATE_FUNCTIONAL_NORMAL = { - android.R.attr.state_single - }; - - // functional pressed state (with properties) - private static final int[] KEY_STATE_FUNCTIONAL_PRESSED = { - android.R.attr.state_single, - android.R.attr.state_pressed - }; - - /** - * This constructor is being used only for key in popup mini keyboard. - */ - public Key(Resources res, Keyboard keyboard, CharSequence popupCharacter, int x, int y, - int width, int height, int edgeFlags) { - mKeyboard = keyboard; - mHeight = height - keyboard.getVerticalGap(); - mGap = keyboard.getHorizontalGap(); - mVisualInsetsLeft = mVisualInsetsRight = 0; - mWidth = width - mGap; - mEdgeFlags = edgeFlags; - mHintLetter = null; - mLabelOption = 0; - mFunctional = false; - mSticky = false; - mRepeatable = false; - mPopupCharacters = null; - mMaxPopupColumn = 0; - final String popupSpecification = popupCharacter.toString(); - mLabel = PopupCharactersParser.getLabel(popupSpecification); - mOutputText = PopupCharactersParser.getOutputText(popupSpecification); - mCode = PopupCharactersParser.getCode(res, popupSpecification); - mIcon = PopupCharactersParser.getIcon(res, popupSpecification); - // Horizontal gap is divided equally to both sides of the key. - mX = x + mGap / 2; - mY = y; - } - - /** - * Create a key with the given top-left coordinate and extract its attributes from the XML - * parser. - * @param res resources associated with the caller's context - * @param row the row that this key belongs to. The row must already be attached to - * a {@link Keyboard}. - * @param x the x coordinate of the top-left - * @param y the y coordinate of the top-left - * @param parser the XML parser containing the attributes for this key - * @param keyStyles active key styles set - */ - public Key(Resources res, Row row, int x, int y, XmlResourceParser parser, - KeyStyles keyStyles) { - mKeyboard = row.getKeyboard(); - - final TypedArray keyboardAttr = res.obtainAttributes(Xml.asAttributeSet(parser), - R.styleable.Keyboard); - int keyWidth; - try { - mHeight = KeyboardParser.getDimensionOrFraction(keyboardAttr, - R.styleable.Keyboard_rowHeight, - mKeyboard.getKeyboardHeight(), row.mDefaultHeight) - row.mVerticalGap; - mGap = KeyboardParser.getDimensionOrFraction(keyboardAttr, - R.styleable.Keyboard_horizontalGap, - mKeyboard.getDisplayWidth(), row.mDefaultHorizontalGap); - keyWidth = KeyboardParser.getDimensionOrFraction(keyboardAttr, - R.styleable.Keyboard_keyWidth, - mKeyboard.getDisplayWidth(), row.mDefaultWidth); - } finally { - keyboardAttr.recycle(); - } - - final TypedArray keyAttr = res.obtainAttributes(Xml.asAttributeSet(parser), - R.styleable.Keyboard_Key); - try { - final KeyStyle style; - if (keyAttr.hasValue(R.styleable.Keyboard_Key_keyStyle)) { - String styleName = keyAttr.getString(R.styleable.Keyboard_Key_keyStyle); - style = keyStyles.getKeyStyle(styleName); - if (style == null) - throw new ParseException("Unknown key style: " + styleName, parser); - } else { - style = keyStyles.getEmptyKeyStyle(); - } - - final int keyboardWidth = mKeyboard.getDisplayWidth(); - int keyXPos = KeyboardParser.getDimensionOrFraction(keyAttr, - R.styleable.Keyboard_Key_keyXPos, keyboardWidth, x); - if (keyXPos < 0) { - // If keyXPos is negative, the actual x-coordinate will be k + keyXPos. - keyXPos += keyboardWidth; - if (keyXPos < x) { - // keyXPos shouldn't be less than x because drawable area for this key starts - // at x. Or, this key will overlaps the adjacent key on its left hand side. - keyXPos = x; - } - } - if (keyWidth == KEYWIDTH_FILL_RIGHT) { - // If keyWidth is zero, the actual key width will be determined to fill out the - // area up to the right edge of the keyboard. - keyWidth = keyboardWidth - keyXPos; - } else if (keyWidth <= KEYWIDTH_FILL_BOTH) { - // If keyWidth is negative, the actual key width will be determined to fill out the - // area between the nearest key on the left hand side and the right edge of the - // keyboard. - keyXPos = x; - keyWidth = keyboardWidth - keyXPos; - } - - // Horizontal gap is divided equally to both sides of the key. - mX = keyXPos + mGap / 2; - mY = y; - mWidth = keyWidth - mGap; - - final CharSequence[] popupCharacters = style.getTextArray(keyAttr, - R.styleable.Keyboard_Key_popupCharacters); - if (res.getBoolean(R.bool.config_digit_popup_characters_enabled)) { - mPopupCharacters = popupCharacters; - } else { - mPopupCharacters = filterOutDigitPopupCharacters(popupCharacters); - } - mMaxPopupColumn = style.getInt(keyboardAttr, - R.styleable.Keyboard_Key_maxPopupKeyboardColumn, - mKeyboard.getMaxPopupKeyboardColumn()); - - mRepeatable = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isRepeatable, false); - mFunctional = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isFunctional, false); - mSticky = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isSticky, false); - mEnabled = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_enabled, true); - mEdgeFlags = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyEdgeFlags, 0) - | row.mRowEdgeFlags; - - mVisualInsetsLeft = KeyboardParser.getDimensionOrFraction(keyAttr, - R.styleable.Keyboard_Key_visualInsetsLeft, mKeyboard.getDisplayHeight(), 0); - mVisualInsetsRight = KeyboardParser.getDimensionOrFraction(keyAttr, - R.styleable.Keyboard_Key_visualInsetsRight, mKeyboard.getDisplayHeight(), 0); - mPreviewIcon = style.getDrawable(keyAttr, R.styleable.Keyboard_Key_iconPreview); - Keyboard.setDefaultBounds(mPreviewIcon); - mIcon = style.getDrawable(keyAttr, R.styleable.Keyboard_Key_keyIcon); - Keyboard.setDefaultBounds(mIcon); - mHintLetter = style.getText(keyAttr, R.styleable.Keyboard_Key_keyHintLetter); - - mLabel = style.getText(keyAttr, R.styleable.Keyboard_Key_keyLabel); - mLabelOption = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyLabelOption, 0); - mOutputText = style.getText(keyAttr, R.styleable.Keyboard_Key_keyOutputText); - // Choose the first letter of the label as primary code if not - // specified. - final int code = style.getInt(keyAttr, R.styleable.Keyboard_Key_code, - Keyboard.CODE_UNSPECIFIED); - if (code == Keyboard.CODE_UNSPECIFIED && !TextUtils.isEmpty(mLabel)) { - mCode = mLabel.charAt(0); - } else if (code != Keyboard.CODE_UNSPECIFIED) { - mCode = code; - } else { - mCode = Keyboard.CODE_DUMMY; - } - - final Drawable shiftedIcon = style.getDrawable(keyAttr, - R.styleable.Keyboard_Key_shiftedIcon); - if (shiftedIcon != null) - mKeyboard.getShiftedIcons().put(this, shiftedIcon); - } finally { - keyAttr.recycle(); - } - } - - public boolean hasPopupHint() { - return (mLabelOption & LABEL_OPTION_POPUP_HINT) != 0; - } - - public boolean hasUppercaseLetter() { - return (mLabelOption & LABEL_OPTION_HAS_UPPERCASE_LETTER) != 0; - } - - private static boolean isDigitPopupCharacter(CharSequence label) { - return label != null && label.length() == 1 && Character.isDigit(label.charAt(0)); - } - - private static CharSequence[] filterOutDigitPopupCharacters(CharSequence[] popupCharacters) { - if (popupCharacters == null || popupCharacters.length < 1) - return null; - if (popupCharacters.length == 1 && isDigitPopupCharacter( - PopupCharactersParser.getLabel(popupCharacters[0].toString()))) - return null; - ArrayList filtered = null; - for (int i = 0; i < popupCharacters.length; i++) { - final CharSequence popupSpec = popupCharacters[i]; - if (isDigitPopupCharacter(PopupCharactersParser.getLabel(popupSpec.toString()))) { - if (filtered == null) { - filtered = new ArrayList(); - for (int j = 0; j < i; j++) - filtered.add(popupCharacters[j]); - } - } else if (filtered != null) { - filtered.add(popupSpec); - } - } - if (filtered == null) - return popupCharacters; - if (filtered.size() == 0) - return null; - return filtered.toArray(new CharSequence[filtered.size()]); - } - - public Drawable getIcon() { - return mIcon; - } - - public Drawable getPreviewIcon() { - return mPreviewIcon; - } - - public void setIcon(Drawable icon) { - mIcon = icon; - } - - public void setPreviewIcon(Drawable icon) { - mPreviewIcon = icon; - } - - /** - * Informs the key that it has been pressed, in case it needs to change its appearance or - * state. - * @see #onReleased() - */ - public void onPressed() { - mPressed = true; - } - - /** - * Informs the key that it has been released, in case it needs to change its appearance or - * state. - * @see #onPressed() - */ - public void onReleased() { - mPressed = false; - } - - /** - * Detects if a point falls on this key. - * @param x the x-coordinate of the point - * @param y the y-coordinate of the point - * @return whether or not the point falls on the key. If the key is attached to an edge, it will - * assume that all points between the key and the edge are considered to be on the key. - */ - public boolean isOnKey(int x, int y) { - final int flags = mEdgeFlags; - final boolean leftEdge = (flags & Keyboard.EDGE_LEFT) != 0; - final boolean rightEdge = (flags & Keyboard.EDGE_RIGHT) != 0; - final boolean topEdge = (flags & Keyboard.EDGE_TOP) != 0; - final boolean bottomEdge = (flags & Keyboard.EDGE_BOTTOM) != 0; - final int left = mX - mGap / 2; - final int right = left + mWidth + mGap; - final int top = mY; - final int bottom = top + mHeight + mKeyboard.getVerticalGap(); - // In order to mitigate rounding errors, we use (left <= x <= right) here. - return (x >= left || leftEdge) && (x <= right || rightEdge) - && (y >= top || topEdge) && (y <= bottom || bottomEdge); - } - - /** - * Returns the square of the distance to the nearest edge of the key and the given point. - * @param x the x-coordinate of the point - * @param y the y-coordinate of the point - * @return the square of the distance of the point from the nearest edge of the key - */ - public int squaredDistanceToEdge(int x, int y) { - final int left = mX; - final int right = left + mWidth; - final int top = mY; - final int bottom = top + mHeight; - final int edgeX = x < left ? left : (x > right ? right : x); - final int edgeY = y < top ? top : (y > bottom ? bottom : y); - final int dx = x - edgeX; - final int dy = y - edgeY; - return dx * dx + dy * dy; - } - - /** - * Returns the drawable state for the key, based on the current state and type of the key. - * @return the drawable state of the key. - * @see android.graphics.drawable.StateListDrawable#setState(int[]) - */ - public int[] getCurrentDrawableState() { - final boolean pressed = mPressed; - if (!mSticky && mFunctional) { - if (pressed) { - return KEY_STATE_FUNCTIONAL_PRESSED; - } else { - return KEY_STATE_FUNCTIONAL_NORMAL; - } - } - - int[] states = KEY_STATE_NORMAL; - - if (mHighlightOn) { - if (pressed) { - states = KEY_STATE_PRESSED_ON; - } else { - states = KEY_STATE_NORMAL_ON; - } - } else { - if (mSticky) { - if (pressed) { - states = KEY_STATE_PRESSED_OFF; - } else { - states = KEY_STATE_NORMAL_OFF; - } - } else { - if (pressed) { - states = KEY_STATE_PRESSED; - } - } - } - return states; - } -} diff --git a/java/src/com/android/inputmethod/keyboard/KeyDetector.java b/java/src/com/android/inputmethod/keyboard/KeyDetector.java index 7add43a6d..818f3f925 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyDetector.java +++ b/java/src/com/android/inputmethod/keyboard/KeyDetector.java @@ -18,6 +18,8 @@ package com.android.inputmethod.keyboard; import android.util.Log; +import com.android.inputmethod.keyboard.internal.Key; + import java.util.Arrays; import java.util.List; diff --git a/java/src/com/android/inputmethod/keyboard/KeyStyles.java b/java/src/com/android/inputmethod/keyboard/KeyStyles.java deleted file mode 100644 index ce5ee5495..000000000 --- a/java/src/com/android/inputmethod/keyboard/KeyStyles.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; - -import com.android.inputmethod.keyboard.KeyboardParser.ParseException; -import com.android.inputmethod.latin.R; - -import android.content.res.TypedArray; -import android.content.res.XmlResourceParser; -import android.graphics.drawable.Drawable; -import android.util.Log; - -import java.util.ArrayList; -import java.util.HashMap; - -public class KeyStyles { - private static final String TAG = "KeyStyles"; - private static final boolean DEBUG = false; - - private final HashMap mStyles = - new HashMap(); - private static final KeyStyle EMPTY_KEY_STYLE = new EmptyKeyStyle(); - - public interface KeyStyle { - public CharSequence[] getTextArray(TypedArray a, int index); - public Drawable getDrawable(TypedArray a, int index); - public CharSequence getText(TypedArray a, int index); - public int getInt(TypedArray a, int index, int defaultValue); - public int getFlag(TypedArray a, int index, int defaultValue); - public boolean getBoolean(TypedArray a, int index, boolean defaultValue); - } - - /* package */ static class EmptyKeyStyle implements KeyStyle { - private EmptyKeyStyle() { - // Nothing to do. - } - - @Override - public CharSequence[] getTextArray(TypedArray a, int index) { - return parseTextArray(a, index); - } - - @Override - public Drawable getDrawable(TypedArray a, int index) { - return a.getDrawable(index); - } - - @Override - public CharSequence getText(TypedArray a, int index) { - return a.getText(index); - } - - @Override - public int getInt(TypedArray a, int index, int defaultValue) { - return a.getInt(index, defaultValue); - } - - @Override - public int getFlag(TypedArray a, int index, int defaultValue) { - return a.getInt(index, defaultValue); - } - - @Override - public boolean getBoolean(TypedArray a, int index, boolean defaultValue) { - return a.getBoolean(index, defaultValue); - } - - protected static CharSequence[] parseTextArray(TypedArray a, int index) { - if (!a.hasValue(index)) - return null; - final CharSequence text = a.getText(index); - return parseCsvText(text); - } - - /* package */ static CharSequence[] parseCsvText(CharSequence text) { - final int size = text.length(); - if (size == 0) return null; - if (size == 1) return new CharSequence[] { text }; - final StringBuilder sb = new StringBuilder(); - ArrayList list = null; - int start = 0; - for (int pos = 0; pos < size; pos++) { - final char c = text.charAt(pos); - if (c == ',') { - if (list == null) list = new ArrayList(); - if (sb.length() == 0) { - list.add(text.subSequence(start, pos)); - } else { - list.add(sb.toString()); - sb.setLength(0); - } - start = pos + 1; - continue; - } else if (c == '\\') { - if (start == pos) { - // Skip escape character at the beginning of the value. - start++; - pos++; - } else { - if (start < pos && sb.length() == 0) - sb.append(text.subSequence(start, pos)); - pos++; - if (pos < size) - sb.append(text.charAt(pos)); - } - } else if (sb.length() > 0) { - sb.append(c); - } - } - if (list == null) { - return new CharSequence[] { sb.length() > 0 ? sb : text.subSequence(start, size) }; - } else { - list.add(sb.length() > 0 ? sb : text.subSequence(start, size)); - return list.toArray(new CharSequence[list.size()]); - } - } - } - - private static class DeclaredKeyStyle extends EmptyKeyStyle { - private final HashMap mAttributes = new HashMap(); - - @Override - public CharSequence[] getTextArray(TypedArray a, int index) { - return a.hasValue(index) - ? super.getTextArray(a, index) : (CharSequence[])mAttributes.get(index); - } - - @Override - public Drawable getDrawable(TypedArray a, int index) { - return a.hasValue(index) - ? super.getDrawable(a, index) : (Drawable)mAttributes.get(index); - } - - @Override - public CharSequence getText(TypedArray a, int index) { - return a.hasValue(index) - ? super.getText(a, index) : (CharSequence)mAttributes.get(index); - } - - @Override - public int getInt(TypedArray a, int index, int defaultValue) { - final Integer value = (Integer)mAttributes.get(index); - return super.getInt(a, index, (value != null) ? value : defaultValue); - } - - @Override - public int getFlag(TypedArray a, int index, int defaultValue) { - final Integer value = (Integer)mAttributes.get(index); - return super.getFlag(a, index, defaultValue) | (value != null ? value : 0); - } - - @Override - public boolean getBoolean(TypedArray a, int index, boolean defaultValue) { - final Boolean value = (Boolean)mAttributes.get(index); - return super.getBoolean(a, index, (value != null) ? value : defaultValue); - } - - private DeclaredKeyStyle() { - super(); - } - - private void parseKeyStyleAttributes(TypedArray keyAttr) { - // TODO: Currently not all Key attributes can be declared as style. - readInt(keyAttr, R.styleable.Keyboard_Key_code); - readText(keyAttr, R.styleable.Keyboard_Key_keyLabel); - readFlag(keyAttr, R.styleable.Keyboard_Key_keyLabelOption); - readTextArray(keyAttr, R.styleable.Keyboard_Key_popupCharacters); - readInt(keyAttr, R.styleable.Keyboard_Key_maxPopupKeyboardColumn); - readText(keyAttr, R.styleable.Keyboard_Key_keyOutputText); - readDrawable(keyAttr, R.styleable.Keyboard_Key_keyIcon); - readDrawable(keyAttr, R.styleable.Keyboard_Key_iconPreview); - readText(keyAttr, R.styleable.Keyboard_Key_keyHintLetter); - readDrawable(keyAttr, R.styleable.Keyboard_Key_shiftedIcon); - readBoolean(keyAttr, R.styleable.Keyboard_Key_isFunctional); - readBoolean(keyAttr, R.styleable.Keyboard_Key_isSticky); - readBoolean(keyAttr, R.styleable.Keyboard_Key_isRepeatable); - readBoolean(keyAttr, R.styleable.Keyboard_Key_enabled); - } - - private void readDrawable(TypedArray a, int index) { - if (a.hasValue(index)) - mAttributes.put(index, a.getDrawable(index)); - } - - private void readText(TypedArray a, int index) { - if (a.hasValue(index)) - mAttributes.put(index, a.getText(index)); - } - - private void readInt(TypedArray a, int index) { - if (a.hasValue(index)) - mAttributes.put(index, a.getInt(index, 0)); - } - - private void readFlag(TypedArray a, int index) { - final Integer value = (Integer)mAttributes.get(index); - if (a.hasValue(index)) - mAttributes.put(index, a.getInt(index, 0) | (value != null ? value : 0)); - } - - private void readBoolean(TypedArray a, int index) { - if (a.hasValue(index)) - mAttributes.put(index, a.getBoolean(index, false)); - } - - private void readTextArray(TypedArray a, int index) { - final CharSequence[] value = parseTextArray(a, index); - if (value != null) - mAttributes.put(index, value); - } - - private void addParent(DeclaredKeyStyle parentStyle) { - mAttributes.putAll(parentStyle.mAttributes); - } - } - - public void parseKeyStyleAttributes(TypedArray keyStyleAttr, TypedArray keyAttrs, - XmlResourceParser parser) { - String styleName = keyStyleAttr.getString(R.styleable.Keyboard_KeyStyle_styleName); - if (DEBUG) Log.d(TAG, String.format("<%s styleName=%s />", - KeyboardParser.TAG_KEY_STYLE, styleName)); - if (mStyles.containsKey(styleName)) - throw new ParseException("duplicate key style declared: " + styleName, parser); - - final DeclaredKeyStyle style = new DeclaredKeyStyle(); - if (keyStyleAttr.hasValue(R.styleable.Keyboard_KeyStyle_parentStyle)) { - String parentStyle = keyStyleAttr.getString( - R.styleable.Keyboard_KeyStyle_parentStyle); - final DeclaredKeyStyle parent = mStyles.get(parentStyle); - if (parent == null) - throw new ParseException("Unknown parentStyle " + parent, parser); - style.addParent(parent); - } - style.parseKeyStyleAttributes(keyAttrs); - mStyles.put(styleName, style); - } - - public KeyStyle getKeyStyle(String styleName) { - return mStyles.get(styleName); - } - - public KeyStyle getEmptyKeyStyle() { - return EMPTY_KEY_STYLE; - } -} diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index 58629ba51..36f36de2b 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -21,6 +21,9 @@ import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.util.Log; +import com.android.inputmethod.keyboard.internal.Key; +import com.android.inputmethod.keyboard.internal.KeyboardParser; +import com.android.inputmethod.keyboard.internal.KeyboardShiftState; import com.android.inputmethod.latin.R; import org.xmlpull.v1.XmlPullParserException; @@ -448,7 +451,7 @@ public class Keyboard { } } - protected static void setDefaultBounds(Drawable drawable) { + public static void setDefaultBounds(Drawable drawable) { if (drawable != null) drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java b/java/src/com/android/inputmethod/keyboard/KeyboardParser.java deleted file mode 100644 index 20af12bc5..000000000 --- a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java +++ /dev/null @@ -1,712 +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 android.content.Context; -import android.content.res.Resources; -import android.content.res.TypedArray; -import android.content.res.XmlResourceParser; -import android.util.Log; -import android.util.TypedValue; -import android.util.Xml; -import android.view.InflateException; - -import com.android.inputmethod.compat.EditorInfoCompatUtils; -import com.android.inputmethod.latin.R; - -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; - -import java.io.IOException; -import java.util.Arrays; -import java.util.List; - -/** - * Parser for BaseKeyboard. - * - * This class parses Keyboard XML file and fill out keys in Keyboard. - * The Keyboard XML file looks like: - *
- *   >!-- xml/keyboard.xml --<
- *   >Keyboard keyboard_attributes*<
- *     >!-- Keyboard Content --<
- *     >Row row_attributes*<
- *       >!-- Row Content --<
- *       >Key key_attributes* /<
- *       >Spacer horizontalGap="0.2in" /<
- *       >include keyboardLayout="@xml/other_keys"<
- *       ...
- *     >/Row<
- *     >include keyboardLayout="@xml/other_rows"<
- *     ...
- *   >/Keyboard<
- * 
- * The XML file which is included in other file must have >merge< as root element, such as: - *
- *   >!-- xml/other_keys.xml --<
- *   >merge<
- *     >Key key_attributes* /<
- *     ...
- *   >/merge<
- * 
- * and - *
- *   >!-- xml/other_rows.xml --<
- *   >merge<
- *     >Row row_attributes*<
- *       >Key key_attributes* /<
- *     >/Row<
- *     ...
- *   >/merge<
- * 
- * You can also use switch-case-default tags to select Rows and Keys. - *
- *   >switch<
- *     >case case_attribute*<
- *       >!-- Any valid tags at switch position --<
- *     >/case<
- *     ...
- *     >default<
- *       >!-- Any valid tags at switch position --<
- *     >/default<
- *   >/switch<
- * 
- * You can declare Key style and specify styles within Key tags. - *
- *     >switch<
- *       >case colorScheme="white"<
- *         >key-style styleName="shift-key" parentStyle="modifier-key"
- *           keyIcon="@drawable/sym_keyboard_shift"
- *         /<
- *       >/case<
- *       >case colorScheme="black"<
- *         >key-style styleName="shift-key" parentStyle="modifier-key"
- *           keyIcon="@drawable/sym_bkeyboard_shift"
- *         /<
- *       >/case<
- *     >/switch<
- *     ...
- *     >Key keyStyle="shift-key" ... /<
- * 
- */ - -public class KeyboardParser { - private static final String TAG = KeyboardParser.class.getSimpleName(); - private static final boolean DEBUG = false; - - // Keyboard XML Tags - private static final String TAG_KEYBOARD = "Keyboard"; - private static final String TAG_ROW = "Row"; - private static final String TAG_KEY = "Key"; - private static final String TAG_SPACER = "Spacer"; - private static final String TAG_INCLUDE = "include"; - private static final String TAG_MERGE = "merge"; - private static final String TAG_SWITCH = "switch"; - private static final String TAG_CASE = "case"; - private static final String TAG_DEFAULT = "default"; - public static final String TAG_KEY_STYLE = "key-style"; - - private final Keyboard mKeyboard; - private final Context mContext; - private final Resources mResources; - - private int mHorizontalEdgesPadding; - private int mCurrentX = 0; - private int mCurrentY = 0; - private int mMaxRowWidth = 0; - private int mTotalHeight = 0; - private Row mCurrentRow = null; - private final KeyStyles mKeyStyles = new KeyStyles(); - - public KeyboardParser(Keyboard keyboard, Context context) { - mKeyboard = keyboard; - mContext = context; - final Resources res = context.getResources(); - mResources = res; - mHorizontalEdgesPadding = (int)res.getDimension(R.dimen.keyboard_horizontal_edges_padding); - } - - public int getMaxRowWidth() { - return mMaxRowWidth; - } - - public int getTotalHeight() { - return mTotalHeight; - } - - public void parseKeyboard(int resId) throws XmlPullParserException, IOException { - if (DEBUG) Log.d(TAG, String.format("<%s> %s", TAG_KEYBOARD, mKeyboard.mId)); - final XmlResourceParser parser = mResources.getXml(resId); - int event; - while ((event = parser.next()) != XmlPullParser.END_DOCUMENT) { - if (event == XmlPullParser.START_TAG) { - final String tag = parser.getName(); - if (TAG_KEYBOARD.equals(tag)) { - parseKeyboardAttributes(parser); - startKeyboard(); - parseKeyboardContent(parser, mKeyboard.getKeys()); - break; - } else { - throw new IllegalStartTag(parser, TAG_KEYBOARD); - } - } - } - } - - public static String parseKeyboardLocale( - Context context, int resId) throws XmlPullParserException, IOException { - final Resources res = context.getResources(); - final XmlResourceParser parser = res.getXml(resId); - if (parser == null) return ""; - int event; - while ((event = parser.next()) != XmlPullParser.END_DOCUMENT) { - if (event == XmlPullParser.START_TAG) { - final String tag = parser.getName(); - if (TAG_KEYBOARD.equals(tag)) { - final TypedArray keyboardAttr = res.obtainAttributes(Xml.asAttributeSet(parser), - R.styleable.Keyboard); - return keyboardAttr.getString(R.styleable.Keyboard_keyboardLocale); - } else { - throw new IllegalStartTag(parser, TAG_KEYBOARD); - } - } - } - return ""; - } - - private void parseKeyboardAttributes(XmlResourceParser parser) { - final Keyboard keyboard = mKeyboard; - final TypedArray keyboardAttr = mContext.obtainStyledAttributes( - Xml.asAttributeSet(parser), R.styleable.Keyboard, R.attr.keyboardStyle, - R.style.Keyboard); - final TypedArray keyAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser), - R.styleable.Keyboard_Key); - try { - final int displayHeight = keyboard.getDisplayHeight(); - final int keyboardHeight = (int)keyboardAttr.getDimension( - R.styleable.Keyboard_keyboardHeight, displayHeight / 2); - final int maxKeyboardHeight = getDimensionOrFraction(keyboardAttr, - R.styleable.Keyboard_maxKeyboardHeight, displayHeight, displayHeight / 2); - int minKeyboardHeight = getDimensionOrFraction(keyboardAttr, - R.styleable.Keyboard_minKeyboardHeight, displayHeight, displayHeight / 2); - if (minKeyboardHeight < 0) { - // Specified fraction was negative, so it should be calculated against display - // width. - final int displayWidth = keyboard.getDisplayWidth(); - minKeyboardHeight = -getDimensionOrFraction(keyboardAttr, - R.styleable.Keyboard_minKeyboardHeight, displayWidth, displayWidth / 2); - } - // Keyboard height will not exceed maxKeyboardHeight and will not be less than - // minKeyboardHeight. - final int height = Math.max( - Math.min(keyboardHeight, maxKeyboardHeight), minKeyboardHeight); - final int width = keyboard.getDisplayWidth(); - - keyboard.setKeyboardHeight(height); - keyboard.setKeyWidth(getDimensionOrFraction(keyboardAttr, - R.styleable.Keyboard_keyWidth, width, width / 10)); - keyboard.setRowHeight(getDimensionOrFraction(keyboardAttr, - R.styleable.Keyboard_rowHeight, height, 50)); - keyboard.setHorizontalGap(getDimensionOrFraction(keyboardAttr, - R.styleable.Keyboard_horizontalGap, width, 0)); - keyboard.setVerticalGap(getDimensionOrFraction(keyboardAttr, - R.styleable.Keyboard_verticalGap, height, 0)); - keyboard.setPopupKeyboardResId(keyboardAttr.getResourceId( - R.styleable.Keyboard_popupKeyboardTemplate, 0)); - - keyboard.setMaxPopupKeyboardColumn(keyAttr.getInt( - R.styleable.Keyboard_Key_maxPopupKeyboardColumn, 5)); - } finally { - keyAttr.recycle(); - keyboardAttr.recycle(); - } - } - - private void parseKeyboardContent(XmlResourceParser parser, List keys) - throws XmlPullParserException, IOException { - int event; - while ((event = parser.next()) != XmlPullParser.END_DOCUMENT) { - if (event == XmlPullParser.START_TAG) { - final String tag = parser.getName(); - if (TAG_ROW.equals(tag)) { - Row row = new Row(mResources, mKeyboard, parser); - if (DEBUG) Log.d(TAG, String.format("<%s>", TAG_ROW)); - if (keys != null) - startRow(row); - parseRowContent(parser, row, keys); - } else if (TAG_INCLUDE.equals(tag)) { - parseIncludeKeyboardContent(parser, keys); - } else if (TAG_SWITCH.equals(tag)) { - parseSwitchKeyboardContent(parser, keys); - } else if (TAG_KEY_STYLE.equals(tag)) { - parseKeyStyle(parser, keys); - } else { - throw new IllegalStartTag(parser, TAG_ROW); - } - } else if (event == XmlPullParser.END_TAG) { - final String tag = parser.getName(); - if (TAG_KEYBOARD.equals(tag)) { - endKeyboard(mKeyboard.getVerticalGap()); - break; - } else if (TAG_CASE.equals(tag) || TAG_DEFAULT.equals(tag) - || TAG_MERGE.equals(tag)) { - if (DEBUG) Log.d(TAG, String.format("", tag)); - break; - } else if (TAG_KEY_STYLE.equals(tag)) { - continue; - } else { - throw new IllegalEndTag(parser, TAG_ROW); - } - } - } - } - - private void parseRowContent(XmlResourceParser parser, Row row, List keys) - throws XmlPullParserException, IOException { - int event; - while ((event = parser.next()) != XmlPullParser.END_DOCUMENT) { - if (event == XmlPullParser.START_TAG) { - final String tag = parser.getName(); - if (TAG_KEY.equals(tag)) { - parseKey(parser, row, keys); - } else if (TAG_SPACER.equals(tag)) { - parseSpacer(parser, row, keys); - } else if (TAG_INCLUDE.equals(tag)) { - parseIncludeRowContent(parser, row, keys); - } else if (TAG_SWITCH.equals(tag)) { - parseSwitchRowContent(parser, row, keys); - } else if (TAG_KEY_STYLE.equals(tag)) { - parseKeyStyle(parser, keys); - } else { - throw new IllegalStartTag(parser, TAG_KEY); - } - } else if (event == XmlPullParser.END_TAG) { - final String tag = parser.getName(); - if (TAG_ROW.equals(tag)) { - if (DEBUG) Log.d(TAG, String.format("", TAG_ROW)); - if (keys != null) - endRow(); - break; - } else if (TAG_CASE.equals(tag) || TAG_DEFAULT.equals(tag) - || TAG_MERGE.equals(tag)) { - if (DEBUG) Log.d(TAG, String.format("", tag)); - break; - } else if (TAG_KEY_STYLE.equals(tag)) { - continue; - } else { - throw new IllegalEndTag(parser, TAG_KEY); - } - } - } - } - - private void parseKey(XmlResourceParser parser, Row row, List keys) - throws XmlPullParserException, IOException { - if (keys == null) { - checkEndTag(TAG_KEY, parser); - } else { - Key key = new Key(mResources, row, mCurrentX, mCurrentY, parser, mKeyStyles); - if (DEBUG) Log.d(TAG, String.format("<%s%s keyLabel=%s code=%d popupCharacters=%s />", - TAG_KEY, (key.mEnabled ? "" : " disabled"), key.mLabel, key.mCode, - Arrays.toString(key.mPopupCharacters))); - checkEndTag(TAG_KEY, parser); - keys.add(key); - if (key.mCode == Keyboard.CODE_SHIFT) - mKeyboard.getShiftKeys().add(key); - endKey(key); - } - } - - private void parseSpacer(XmlResourceParser parser, Row row, List keys) - throws XmlPullParserException, IOException { - if (keys == null) { - checkEndTag(TAG_SPACER, parser); - } else { - if (DEBUG) Log.d(TAG, String.format("<%s />", TAG_SPACER)); - final TypedArray keyboardAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser), - R.styleable.Keyboard); - if (keyboardAttr.hasValue(R.styleable.Keyboard_horizontalGap)) - throw new IllegalAttribute(parser, "horizontalGap"); - final int defaultWidth = (row != null) ? row.mDefaultWidth : 0; - final int keyWidth = getDimensionOrFraction(keyboardAttr, R.styleable.Keyboard_keyWidth, - mKeyboard.getDisplayWidth(), defaultWidth); - keyboardAttr.recycle(); - - final TypedArray keyAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser), - R.styleable.Keyboard_Key); - int keyXPos = KeyboardParser.getDimensionOrFraction(keyAttr, - R.styleable.Keyboard_Key_keyXPos, mKeyboard.getDisplayWidth(), mCurrentX); - if (keyXPos < 0) { - // If keyXPos is negative, the actual x-coordinate will be display_width + keyXPos. - keyXPos += mKeyboard.getDisplayWidth(); - } - - checkEndTag(TAG_SPACER, parser); - setSpacer(keyXPos, keyWidth); - } - } - - private void parseIncludeKeyboardContent(XmlResourceParser parser, List keys) - throws XmlPullParserException, IOException { - parseIncludeInternal(parser, null, keys); - } - - private void parseIncludeRowContent(XmlResourceParser parser, Row row, List keys) - throws XmlPullParserException, IOException { - parseIncludeInternal(parser, row, keys); - } - - private void parseIncludeInternal(XmlResourceParser parser, Row row, List keys) - throws XmlPullParserException, IOException { - if (keys == null) { - checkEndTag(TAG_INCLUDE, parser); - } else { - final TypedArray a = mResources.obtainAttributes(Xml.asAttributeSet(parser), - R.styleable.Keyboard_Include); - final int keyboardLayout = a.getResourceId( - R.styleable.Keyboard_Include_keyboardLayout, 0); - a.recycle(); - - checkEndTag(TAG_INCLUDE, parser); - if (keyboardLayout == 0) - throw new ParseException("No keyboardLayout attribute in ", parser); - if (DEBUG) Log.d(TAG, String.format("<%s keyboardLayout=%s />", - TAG_INCLUDE, mResources.getResourceEntryName(keyboardLayout))); - parseMerge(mResources.getLayout(keyboardLayout), row, keys); - } - } - - private void parseMerge(XmlResourceParser parser, Row row, List keys) - throws XmlPullParserException, IOException { - int event; - while ((event = parser.next()) != XmlPullParser.END_DOCUMENT) { - if (event == XmlPullParser.START_TAG) { - final String tag = parser.getName(); - if (TAG_MERGE.equals(tag)) { - if (row == null) { - parseKeyboardContent(parser, keys); - } else { - parseRowContent(parser, row, keys); - } - break; - } else { - throw new ParseException( - "Included keyboard layout must have root element", parser); - } - } - } - } - - private void parseSwitchKeyboardContent(XmlResourceParser parser, List keys) - throws XmlPullParserException, IOException { - parseSwitchInternal(parser, null, keys); - } - - private void parseSwitchRowContent(XmlResourceParser parser, Row row, List keys) - throws XmlPullParserException, IOException { - parseSwitchInternal(parser, row, keys); - } - - private void parseSwitchInternal(XmlResourceParser parser, Row row, List keys) - throws XmlPullParserException, IOException { - if (DEBUG) Log.d(TAG, String.format("<%s> %s", TAG_SWITCH, mKeyboard.mId)); - boolean selected = false; - int event; - while ((event = parser.next()) != XmlPullParser.END_DOCUMENT) { - if (event == XmlPullParser.START_TAG) { - final String tag = parser.getName(); - if (TAG_CASE.equals(tag)) { - selected |= parseCase(parser, row, selected ? null : keys); - } else if (TAG_DEFAULT.equals(tag)) { - selected |= parseDefault(parser, row, selected ? null : keys); - } else { - throw new IllegalStartTag(parser, TAG_KEY); - } - } else if (event == XmlPullParser.END_TAG) { - final String tag = parser.getName(); - if (TAG_SWITCH.equals(tag)) { - if (DEBUG) Log.d(TAG, String.format("", TAG_SWITCH)); - break; - } else { - throw new IllegalEndTag(parser, TAG_KEY); - } - } - } - } - - private boolean parseCase(XmlResourceParser parser, Row row, List keys) - throws XmlPullParserException, IOException { - final boolean selected = parseCaseCondition(parser); - if (row == null) { - // Processing Rows. - parseKeyboardContent(parser, selected ? keys : null); - } else { - // Processing Keys. - parseRowContent(parser, row, selected ? keys : null); - } - return selected; - } - - private boolean parseCaseCondition(XmlResourceParser parser) { - final KeyboardId id = mKeyboard.mId; - if (id == null) - return true; - - final TypedArray a = mResources.obtainAttributes(Xml.asAttributeSet(parser), - R.styleable.Keyboard_Case); - final TypedArray viewAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser), - R.styleable.KeyboardView); - try { - final boolean modeMatched = matchTypedValue(a, - R.styleable.Keyboard_Case_mode, id.mMode, KeyboardId.modeName(id.mMode)); - final boolean navigateActionMatched = matchBoolean(a, - R.styleable.Keyboard_Case_navigateAction, id.mNavigateAction); - final boolean passwordInputMatched = matchBoolean(a, - R.styleable.Keyboard_Case_passwordInput, id.mPasswordInput); - final boolean settingsKeyMatched = matchBoolean(a, - R.styleable.Keyboard_Case_hasSettingsKey, id.mHasSettingsKey); - final boolean voiceEnabledMatched = matchBoolean(a, - R.styleable.Keyboard_Case_voiceKeyEnabled, id.mVoiceKeyEnabled); - final boolean voiceKeyMatched = matchBoolean(a, - R.styleable.Keyboard_Case_hasVoiceKey, id.mHasVoiceKey); - final boolean colorSchemeMatched = matchInteger(viewAttr, - R.styleable.KeyboardView_colorScheme, id.mColorScheme); - // As noted at {@link KeyboardId} class, we are interested only in enum value masked by - // {@link android.view.inputmethod.EditorInfo#IME_MASK_ACTION} and - // {@link android.view.inputmethod.EditorInfo#IME_FLAG_NO_ENTER_ACTION}. So matching - // this attribute with id.mImeOptions as integer value is enough for our purpose. - final boolean imeActionMatched = matchInteger(a, - R.styleable.Keyboard_Case_imeAction, id.mImeAction); - final boolean localeCodeMatched = matchString(a, - R.styleable.Keyboard_Case_localeCode, id.mLocale.toString()); - final boolean languageCodeMatched = matchString(a, - R.styleable.Keyboard_Case_languageCode, id.mLocale.getLanguage()); - final boolean countryCodeMatched = matchString(a, - R.styleable.Keyboard_Case_countryCode, id.mLocale.getCountry()); - final boolean selected = modeMatched && navigateActionMatched && passwordInputMatched - && settingsKeyMatched && voiceEnabledMatched && voiceKeyMatched - && colorSchemeMatched && imeActionMatched && localeCodeMatched - && languageCodeMatched && countryCodeMatched; - - if (DEBUG) Log.d(TAG, String.format("<%s%s%s%s%s%s%s%s%s%s%s%s> %s", TAG_CASE, - textAttr(a.getString(R.styleable.Keyboard_Case_mode), "mode"), - textAttr(KeyboardId.colorSchemeName( - viewAttr.getInt( - R.styleable.KeyboardView_colorScheme, -1)), "colorScheme"), - booleanAttr(a, R.styleable.Keyboard_Case_navigateAction, "navigateAction"), - booleanAttr(a, R.styleable.Keyboard_Case_passwordInput, "passwordInput"), - booleanAttr(a, R.styleable.Keyboard_Case_hasSettingsKey, "hasSettingsKey"), - booleanAttr(a, R.styleable.Keyboard_Case_voiceKeyEnabled, "voiceKeyEnabled"), - booleanAttr(a, R.styleable.Keyboard_Case_hasVoiceKey, "hasVoiceKey"), - textAttr(EditorInfoCompatUtils.imeOptionsName( - a.getInt(R.styleable.Keyboard_Case_imeAction, -1)), "imeAction"), - textAttr(a.getString(R.styleable.Keyboard_Case_localeCode), "localeCode"), - textAttr(a.getString(R.styleable.Keyboard_Case_languageCode), "languageCode"), - textAttr(a.getString(R.styleable.Keyboard_Case_countryCode), "countryCode"), - Boolean.toString(selected))); - - return selected; - } finally { - a.recycle(); - viewAttr.recycle(); - } - } - - private static boolean matchInteger(TypedArray a, int index, int value) { - // If does not have "index" attribute, that means this is wild-card for the - // attribute. - return !a.hasValue(index) || a.getInt(index, 0) == value; - } - - private static boolean matchBoolean(TypedArray a, int index, boolean value) { - // If does not have "index" attribute, that means this is wild-card for the - // attribute. - return !a.hasValue(index) || a.getBoolean(index, false) == value; - } - - private static boolean matchString(TypedArray a, int index, String value) { - // If does not have "index" attribute, that means this is wild-card for the - // attribute. - return !a.hasValue(index) || stringArrayContains(a.getString(index).split("\\|"), value); - } - - private static boolean matchTypedValue(TypedArray a, int index, int intValue, String strValue) { - // If does not have "index" attribute, that means this is wild-card for the - // attribute. - final TypedValue v = a.peekValue(index); - if (v == null) - return true; - - if (isIntegerValue(v)) { - return intValue == a.getInt(index, 0); - } else if (isStringValue(v)) { - return stringArrayContains(a.getString(index).split("\\|"), strValue); - } - return false; - } - - private static boolean stringArrayContains(String[] array, String value) { - for (final String elem : array) { - if (elem.equals(value)) - return true; - } - return false; - } - - private boolean parseDefault(XmlResourceParser parser, Row row, List keys) - throws XmlPullParserException, IOException { - if (DEBUG) Log.d(TAG, String.format("<%s>", TAG_DEFAULT)); - if (row == null) { - parseKeyboardContent(parser, keys); - } else { - parseRowContent(parser, row, keys); - } - return true; - } - - private void parseKeyStyle(XmlResourceParser parser, List keys) { - TypedArray keyStyleAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser), - R.styleable.Keyboard_KeyStyle); - TypedArray keyAttrs = mResources.obtainAttributes(Xml.asAttributeSet(parser), - R.styleable.Keyboard_Key); - try { - if (!keyStyleAttr.hasValue(R.styleable.Keyboard_KeyStyle_styleName)) - throw new ParseException("<" + TAG_KEY_STYLE - + "/> needs styleName attribute", parser); - if (keys != null) - mKeyStyles.parseKeyStyleAttributes(keyStyleAttr, keyAttrs, parser); - } finally { - keyStyleAttr.recycle(); - keyAttrs.recycle(); - } - } - - private static void checkEndTag(String tag, XmlResourceParser parser) - throws XmlPullParserException, IOException { - if (parser.next() == XmlPullParser.END_TAG && tag.equals(parser.getName())) - return; - throw new NonEmptyTag(tag, parser); - } - - private void startKeyboard() { - mCurrentY += (int)mResources.getDimension(R.dimen.keyboard_top_padding); - } - - private void startRow(Row row) { - mCurrentX = 0; - setSpacer(mCurrentX, mHorizontalEdgesPadding); - mCurrentRow = row; - } - - private void endRow() { - if (mCurrentRow == null) - throw new InflateException("orphant end row tag"); - setSpacer(mCurrentX, mHorizontalEdgesPadding); - if (mCurrentX > mMaxRowWidth) - mMaxRowWidth = mCurrentX; - mCurrentY += mCurrentRow.mDefaultHeight; - mCurrentRow = null; - } - - private void endKey(Key key) { - mCurrentX = key.mX - key.mGap / 2 + key.mWidth + key.mGap; - } - - private void endKeyboard(int defaultVerticalGap) { - mCurrentY += (int)mResources.getDimension(R.dimen.keyboard_bottom_padding); - mTotalHeight = mCurrentY - defaultVerticalGap; - } - - private void setSpacer(int keyXPos, int width) { - mCurrentX = keyXPos + width; - } - - public static int getDimensionOrFraction(TypedArray a, int index, int base, int defValue) { - final TypedValue value = a.peekValue(index); - if (value == null) - return defValue; - if (isFractionValue(value)) { - // Round it to avoid values like 47.9999 from getting truncated - return Math.round(a.getFraction(index, base, base, defValue)); - } else if (isDimensionValue(value)) { - return a.getDimensionPixelOffset(index, defValue); - } else if (isIntegerValue(value)) { - // For enum value. - return a.getInt(index, defValue); - } - return defValue; - } - - private static boolean isFractionValue(TypedValue v) { - return v.type == TypedValue.TYPE_FRACTION; - } - - private static boolean isDimensionValue(TypedValue v) { - return v.type == TypedValue.TYPE_DIMENSION; - } - - private static boolean isIntegerValue(TypedValue v) { - return v.type >= TypedValue.TYPE_FIRST_INT && v.type <= TypedValue.TYPE_LAST_INT; - } - - private static boolean isStringValue(TypedValue v) { - return v.type == TypedValue.TYPE_STRING; - } - - @SuppressWarnings("serial") - public static class ParseException extends InflateException { - public ParseException(String msg, XmlResourceParser parser) { - super(msg + " at line " + parser.getLineNumber()); - } - } - - @SuppressWarnings("serial") - private static class IllegalStartTag extends ParseException { - public IllegalStartTag(XmlResourceParser parser, String parent) { - super("Illegal start tag " + parser.getName() + " in " + parent, parser); - } - } - - @SuppressWarnings("serial") - private static class IllegalEndTag extends ParseException { - public IllegalEndTag(XmlResourceParser parser, String parent) { - super("Illegal end tag " + parser.getName() + " in " + parent, parser); - } - } - - @SuppressWarnings("serial") - private static class IllegalAttribute extends ParseException { - public IllegalAttribute(XmlResourceParser parser, String attribute) { - super("Tag " + parser.getName() + " has illegal attribute " + attribute, parser); - } - } - - @SuppressWarnings("serial") - private static class NonEmptyTag extends ParseException { - public NonEmptyTag(String tag, XmlResourceParser parser) { - super(tag + " must be empty tag", parser); - } - } - - private static String textAttr(String value, String name) { - return value != null ? String.format(" %s=%s", name, value) : ""; - } - - private static String booleanAttr(TypedArray a, int index, String name) { - return a.hasValue(index) ? String.format(" %s=%s", name, a.getBoolean(index, false)) : ""; - } -} diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardShiftState.java b/java/src/com/android/inputmethod/keyboard/KeyboardShiftState.java deleted file mode 100644 index e015b5158..000000000 --- a/java/src/com/android/inputmethod/keyboard/KeyboardShiftState.java +++ /dev/null @@ -1,133 +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 android.util.Log; - -public class KeyboardShiftState { - private static final String TAG = "KeyboardShiftState"; - private static final boolean DEBUG = KeyboardSwitcher.DEBUG_STATE; - - private static final int NORMAL = 0; - private static final int MANUAL_SHIFTED = 1; - private static final int MANUAL_SHIFTED_FROM_AUTO = 2; - private static final int AUTO_SHIFTED = 3; - private static final int SHIFT_LOCKED = 4; - private static final int SHIFT_LOCK_SHIFTED = 5; - - private int mState = NORMAL; - - public boolean setShifted(boolean newShiftState) { - final int oldState = mState; - if (newShiftState) { - switch (oldState) { - case NORMAL: - mState = MANUAL_SHIFTED; - break; - case AUTO_SHIFTED: - mState = MANUAL_SHIFTED_FROM_AUTO; - break; - case SHIFT_LOCKED: - mState = SHIFT_LOCK_SHIFTED; - break; - } - } else { - switch (oldState) { - case MANUAL_SHIFTED: - case MANUAL_SHIFTED_FROM_AUTO: - case AUTO_SHIFTED: - mState = NORMAL; - break; - case SHIFT_LOCK_SHIFTED: - mState = SHIFT_LOCKED; - break; - } - } - if (DEBUG) - Log.d(TAG, "setShifted(" + newShiftState + "): " + toString(oldState) + " > " + this); - return mState != oldState; - } - - public void setShiftLocked(boolean newShiftLockState) { - final int oldState = mState; - if (newShiftLockState) { - switch (oldState) { - case NORMAL: - case MANUAL_SHIFTED: - case MANUAL_SHIFTED_FROM_AUTO: - case AUTO_SHIFTED: - mState = SHIFT_LOCKED; - break; - } - } else { - switch (oldState) { - case SHIFT_LOCKED: - case SHIFT_LOCK_SHIFTED: - mState = NORMAL; - break; - } - } - if (DEBUG) - Log.d(TAG, "setShiftLocked(" + newShiftLockState + "): " + toString(oldState) - + " > " + this); - } - - public void setAutomaticTemporaryUpperCase() { - final int oldState = mState; - mState = AUTO_SHIFTED; - if (DEBUG) - Log.d(TAG, "setAutomaticTemporaryUpperCase: " + toString(oldState) + " > " + this); - } - - public boolean isShiftedOrShiftLocked() { - return mState != NORMAL; - } - - public boolean isShiftLocked() { - return mState == SHIFT_LOCKED || mState == SHIFT_LOCK_SHIFTED; - } - - public boolean isAutomaticTemporaryUpperCase() { - return mState == AUTO_SHIFTED; - } - - public boolean isManualTemporaryUpperCase() { - return mState == MANUAL_SHIFTED || mState == MANUAL_SHIFTED_FROM_AUTO - || mState == SHIFT_LOCK_SHIFTED; - } - - public boolean isManualTemporaryUpperCaseFromAuto() { - return mState == MANUAL_SHIFTED_FROM_AUTO; - } - - @Override - public String toString() { - return toString(mState); - } - - private static String toString(int state) { - switch (state) { - case NORMAL: return "NORMAL"; - case MANUAL_SHIFTED: return "MANUAL_SHIFTED"; - case MANUAL_SHIFTED_FROM_AUTO: return "MANUAL_SHIFTED_FROM_AUTO"; - case AUTO_SHIFTED: return "AUTO_SHIFTED"; - case SHIFT_LOCKED: return "SHIFT_LOCKED"; - case SHIFT_LOCK_SHIFTED: return "SHIFT_LOCK_SHIFTED"; - default: return "UKNOWN"; - } - } -} diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 1218a5abd..157337cca 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -27,6 +27,9 @@ import android.view.View; import android.view.inputmethod.EditorInfo; import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; +import com.android.inputmethod.keyboard.internal.Key; +import com.android.inputmethod.keyboard.internal.ModifierKeyState; +import com.android.inputmethod.keyboard.internal.ShiftKeyState; import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index f73cdc083..4c6f29a92 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -47,6 +47,10 @@ import android.widget.LinearLayout; import android.widget.PopupWindow; import android.widget.TextView; +import com.android.inputmethod.keyboard.internal.Key; +import com.android.inputmethod.keyboard.internal.MiniKeyboardBuilder; +import com.android.inputmethod.keyboard.internal.PointerTrackerQueue; +import com.android.inputmethod.keyboard.internal.SwipeTracker; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java index 020fb56ca..e741625ca 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java @@ -33,6 +33,8 @@ import android.graphics.Rect; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; +import com.android.inputmethod.keyboard.internal.Key; +import com.android.inputmethod.keyboard.internal.SlidingLocaleDrawable; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.SubtypeSwitcher; diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index 901df6ab7..d25d1f098 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -24,6 +24,7 @@ import android.util.Log; import android.view.MotionEvent; import com.android.inputmethod.deprecated.VoiceProxy; +import com.android.inputmethod.keyboard.internal.Key; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.Utils; diff --git a/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java b/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java index 2d6766f2d..d3d3fa59f 100644 --- a/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java @@ -18,6 +18,8 @@ package com.android.inputmethod.keyboard; import android.content.Context; +import com.android.inputmethod.keyboard.internal.Key; + import java.util.List; public class MiniKeyboard extends Keyboard { diff --git a/java/src/com/android/inputmethod/keyboard/MiniKeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/MiniKeyboardBuilder.java deleted file mode 100644 index 6e939123d..000000000 --- a/java/src/com/android/inputmethod/keyboard/MiniKeyboardBuilder.java +++ /dev/null @@ -1,246 +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 com.android.inputmethod.latin.R; - -import android.content.Context; -import android.content.res.Resources; -import android.graphics.Paint; -import android.graphics.Rect; - -import java.util.List; - -public class MiniKeyboardBuilder { - private final Resources mRes; - private final MiniKeyboard mKeyboard; - private final CharSequence[] mPopupCharacters; - private final MiniKeyboardLayoutParams mParams; - - /* package */ static class MiniKeyboardLayoutParams { - public final int mKeyWidth; - public final int mRowHeight; - /* package */ final int mTopRowAdjustment; - public final int mNumRows; - public final int mNumColumns; - public final int mLeftKeys; - public final int mRightKeys; // includes default key. - - /** - * The object holding mini keyboard layout parameters. - * - * @param numKeys number of keys in this mini keyboard. - * @param maxColumns number of maximum columns of this mini keyboard. - * @param keyWidth mini keyboard key width in pixel, including horizontal gap. - * @param rowHeight mini keyboard row height in pixel, including vertical gap. - * @param coordXInParent coordinate x of the popup key in parent keyboard. - * @param parentKeyboardWidth parent keyboard width in pixel. - */ - public MiniKeyboardLayoutParams(int numKeys, int maxColumns, int keyWidth, int rowHeight, - int coordXInParent, int parentKeyboardWidth) { - if (parentKeyboardWidth / keyWidth < maxColumns) - throw new IllegalArgumentException("Keyboard is too small to hold mini keyboard: " - + parentKeyboardWidth + " " + keyWidth + " " + maxColumns); - mKeyWidth = keyWidth; - mRowHeight = 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; - } - } - - // 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 * mKeyWidth; - } - - public int getX(int n, int row) { - final int x = getColumnPos(n) * mKeyWidth + getDefaultKeyCoordX(); - if (isTopRow(row)) { - return x + mTopRowAdjustment * (mKeyWidth / 2); - } - return x; - } - - public int getY(int row) { - return (mNumRows - 1 - row) * mRowHeight; - } - - public int getRowFlags(int row) { - int rowFlags = 0; - if (row == 0) rowFlags |= Keyboard.EDGE_TOP; - if (isTopRow(row)) rowFlags |= Keyboard.EDGE_BOTTOM; - return rowFlags; - } - - private boolean isTopRow(int rowCount) { - return rowCount == mNumRows - 1; - } - } - - public MiniKeyboardBuilder(KeyboardView view, int layoutTemplateResId, Key parentKey, - Keyboard parentKeyboard) { - final Context context = view.getContext(); - mRes = context.getResources(); - final MiniKeyboard keyboard = new MiniKeyboard( - context, layoutTemplateResId, parentKeyboard); - mKeyboard = keyboard; - mPopupCharacters = parentKey.mPopupCharacters; - - final int keyWidth = getMaxKeyWidth(view, mPopupCharacters, keyboard.getKeyWidth()); - final MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams( - mPopupCharacters.length, parentKey.mMaxPopupColumn, - keyWidth, parentKeyboard.getRowHeight(), - parentKey.mX + (parentKey.mWidth + parentKey.mGap) / 2 - keyWidth / 2, - view.getMeasuredWidth()); - mParams = params; - - keyboard.setRowHeight(params.mRowHeight); - keyboard.setHeight(params.mNumRows * params.mRowHeight); - keyboard.setMinWidth(params.mNumColumns * params.mKeyWidth); - keyboard.setDefaultCoordX(params.getDefaultKeyCoordX() + params.mKeyWidth / 2); - } - - 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.getLabelSizeAndSetPaint(label, 0, 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); - } - - public MiniKeyboard build() { - final MiniKeyboard keyboard = mKeyboard; - final List keys = keyboard.getKeys(); - final MiniKeyboardLayoutParams params = mParams; - for (int n = 0; n < mPopupCharacters.length; n++) { - final CharSequence label = mPopupCharacters[n]; - final int row = n / params.mNumColumns; - final Key key = new Key(mRes, keyboard, label, params.getX(n, row), params.getY(row), - params.mKeyWidth, params.mRowHeight, params.getRowFlags(row)); - keys.add(key); - } - return keyboard; - } -} diff --git a/java/src/com/android/inputmethod/keyboard/MiniKeyboardKeyDetector.java b/java/src/com/android/inputmethod/keyboard/MiniKeyboardKeyDetector.java index cc5c3bbfe..9170c3bd1 100644 --- a/java/src/com/android/inputmethod/keyboard/MiniKeyboardKeyDetector.java +++ b/java/src/com/android/inputmethod/keyboard/MiniKeyboardKeyDetector.java @@ -16,6 +16,8 @@ package com.android.inputmethod.keyboard; +import com.android.inputmethod.keyboard.internal.Key; + import java.util.List; public class MiniKeyboardKeyDetector extends KeyDetector { diff --git a/java/src/com/android/inputmethod/keyboard/ModifierKeyState.java b/java/src/com/android/inputmethod/keyboard/ModifierKeyState.java deleted file mode 100644 index ebbc79a9e..000000000 --- a/java/src/com/android/inputmethod/keyboard/ModifierKeyState.java +++ /dev/null @@ -1,83 +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 android.util.Log; - -public class ModifierKeyState { - protected static final String TAG = "ModifierKeyState"; - protected static final boolean DEBUG = KeyboardSwitcher.DEBUG_STATE; - - protected static final int RELEASING = 0; - protected static final int PRESSING = 1; - protected static final int MOMENTARY = 2; - - protected final String mName; - protected int mState = RELEASING; - - public ModifierKeyState(String name) { - mName = name; - } - - public void onPress() { - final int oldState = mState; - mState = PRESSING; - if (DEBUG) - Log.d(TAG, mName + ".onPress: " + toString(oldState) + " > " + this); - } - - public void onRelease() { - final int oldState = mState; - mState = RELEASING; - if (DEBUG) - Log.d(TAG, mName + ".onRelease: " + toString(oldState) + " > " + this); - } - - public void onOtherKeyPressed() { - final int oldState = mState; - if (oldState == PRESSING) - mState = MOMENTARY; - if (DEBUG) - Log.d(TAG, mName + ".onOtherKeyPressed: " + toString(oldState) + " > " + this); - } - - public boolean isPressing() { - return mState == PRESSING; - } - - public boolean isReleasing() { - return mState == RELEASING; - } - - public boolean isMomentary() { - return mState == MOMENTARY; - } - - @Override - public String toString() { - return toString(mState); - } - - protected String toString(int state) { - switch (state) { - case RELEASING: return "RELEASING"; - case PRESSING: return "PRESSING"; - case MOMENTARY: return "MOMENTARY"; - default: return "UNKNOWN"; - } - } -} diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 0a727ad42..d8d2bffbe 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -17,6 +17,9 @@ package com.android.inputmethod.keyboard; import com.android.inputmethod.keyboard.KeyboardView.UIHandler; +import com.android.inputmethod.keyboard.internal.Key; +import com.android.inputmethod.keyboard.internal.PointerTrackerKeyState; +import com.android.inputmethod.keyboard.internal.PointerTrackerQueue; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.SubtypeSwitcher; diff --git a/java/src/com/android/inputmethod/keyboard/PointerTrackerKeyState.java b/java/src/com/android/inputmethod/keyboard/PointerTrackerKeyState.java deleted file mode 100644 index eecbb26f3..000000000 --- a/java/src/com/android/inputmethod/keyboard/PointerTrackerKeyState.java +++ /dev/null @@ -1,98 +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; - -/** - * This class keeps track of a key index and a position where {@link PointerTracker} is. - */ -/* package */ class PointerTrackerKeyState { - private final KeyDetector mKeyDetector; - - // The position and time at which first down event occurred. - private long mDownTime; - private long mUpTime; - - // The current key index where this pointer is. - private int mKeyIndex = KeyDetector.NOT_A_KEY; - // The position where mKeyIndex was recognized for the first time. - private int mKeyX; - private int mKeyY; - - // Last pointer position. - private int mLastX; - private int mLastY; - - public PointerTrackerKeyState(KeyDetector keyDetecor) { - mKeyDetector = keyDetecor; - } - - public int getKeyIndex() { - return mKeyIndex; - } - - public int getKeyX() { - return mKeyX; - } - - public int getKeyY() { - return mKeyY; - } - - public long getDownTime() { - return mDownTime; - } - - public long getUpTime() { - return mUpTime; - } - - public int getLastX() { - return mLastX; - } - - public int getLastY() { - return mLastY; - } - - public int onDownKey(int x, int y, long eventTime) { - mDownTime = eventTime; - return onMoveToNewKey(onMoveKeyInternal(x, y), x, y); - } - - private int onMoveKeyInternal(int x, int y) { - mLastX = x; - mLastY = y; - return mKeyDetector.getKeyIndexAndNearbyCodes(x, y, null); - } - - public int onMoveKey(int x, int y) { - return onMoveKeyInternal(x, y); - } - - public int onMoveToNewKey(int keyIndex, int x, int y) { - mKeyIndex = keyIndex; - mKeyX = x; - mKeyY = y; - return keyIndex; - } - - public int onUpKey(int x, int y, long eventTime) { - mUpTime = eventTime; - mKeyIndex = KeyDetector.NOT_A_KEY; - return onMoveKeyInternal(x, y); - } -} diff --git a/java/src/com/android/inputmethod/keyboard/PointerTrackerQueue.java b/java/src/com/android/inputmethod/keyboard/PointerTrackerQueue.java deleted file mode 100644 index 9e287c67d..000000000 --- a/java/src/com/android/inputmethod/keyboard/PointerTrackerQueue.java +++ /dev/null @@ -1,83 +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.LinkedList; - -public class PointerTrackerQueue { - private LinkedList mQueue = new LinkedList(); - - public void add(PointerTracker tracker) { - mQueue.add(tracker); - } - - public void releaseAllPointersOlderThan(PointerTracker tracker, long eventTime) { - if (mQueue.lastIndexOf(tracker) < 0) { - return; - } - final LinkedList queue = mQueue; - int oldestPos = 0; - for (PointerTracker t = queue.get(oldestPos); t != tracker; t = queue.get(oldestPos)) { - if (t.isModifier()) { - oldestPos++; - } else { - t.onPhantomUpEvent(t.getLastX(), t.getLastY(), eventTime, true); - queue.remove(oldestPos); - } - } - } - - public void releaseAllPointers(long eventTime) { - releaseAllPointersExcept(null, eventTime, true); - } - - public void releaseAllPointersExcept(PointerTracker tracker, long eventTime, - boolean updateReleasedKeyGraphics) { - for (PointerTracker t : mQueue) { - if (t == tracker) - continue; - t.onPhantomUpEvent(t.getLastX(), t.getLastY(), eventTime, updateReleasedKeyGraphics); - } - mQueue.clear(); - if (tracker != null) - mQueue.add(tracker); - } - - public void remove(PointerTracker tracker) { - mQueue.remove(tracker); - } - - public boolean isInSlidingKeyInput() { - for (final PointerTracker tracker : mQueue) { - if (tracker.isInSlidingKeyInput()) - return true; - } - return false; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder("["); - for (PointerTracker tracker : mQueue) { - if (sb.length() > 1) - sb.append(" "); - sb.append(String.format("%d", tracker.mPointerId)); - } - sb.append("]"); - return sb.toString(); - } -} diff --git a/java/src/com/android/inputmethod/keyboard/PopupCharactersParser.java b/java/src/com/android/inputmethod/keyboard/PopupCharactersParser.java deleted file mode 100644 index ff78ee5c9..000000000 --- a/java/src/com/android/inputmethod/keyboard/PopupCharactersParser.java +++ /dev/null @@ -1,176 +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 com.android.inputmethod.latin.R; - -import android.content.res.Resources; -import android.graphics.drawable.Drawable; -import android.text.TextUtils; - -/** - * String parser of popupCharacters attribute of Key. - * The string is comma separated texts each of which represents one popup key. - * Each popup key text is one of the following: - * - A single letter (Letter) - * - Label optionally followed by keyOutputText or code (keyLabel|keyOutputText). - * - Icon followed by keyOutputText or code (@drawable/icon|@integer/key_code) - * Special character, comma ',' backslash '\', and bar '|' can be escaped by '\' - * character. - * Note that the character '@' and '\' are also parsed by XML parser and CSV parser as well. - */ -public class PopupCharactersParser { - private static final char ESCAPE = '\\'; - private static final String LABEL_END = "|"; - private static final String PREFIX_AT = "@"; - private static final String PREFIX_ICON = PREFIX_AT + "drawable/"; - private static final String PREFIX_CODE = PREFIX_AT + "integer/"; - - private PopupCharactersParser() { - // Intentional empty constructor for utility class. - } - - private static boolean hasIcon(String popupSpec) { - if (popupSpec.startsWith(PREFIX_ICON)) { - final int end = indexOfLabelEnd(popupSpec, 0); - if (end > 0) - return true; - throw new PopupCharactersParserError("outputText or code not specified: " + popupSpec); - } - return false; - } - - private static boolean hasCode(String popupSpec) { - final int end = indexOfLabelEnd(popupSpec, 0); - if (end > 0 && end + 1 < popupSpec.length() - && popupSpec.substring(end + 1).startsWith(PREFIX_CODE)) { - return true; - } - return false; - } - - private static String parseEscape(String text) { - if (text.indexOf(ESCAPE) < 0) - return text; - final int length = text.length(); - final StringBuilder sb = new StringBuilder(); - for (int pos = 0; pos < length; pos++) { - final char c = text.charAt(pos); - if (c == ESCAPE && pos + 1 < length) { - sb.append(text.charAt(++pos)); - } else { - sb.append(c); - } - } - return sb.toString(); - } - - private static int indexOfLabelEnd(String popupSpec, int start) { - if (popupSpec.indexOf(ESCAPE, start) < 0) { - final int end = popupSpec.indexOf(LABEL_END, start); - if (end == 0) - throw new PopupCharactersParserError(LABEL_END + " at " + start + ": " + popupSpec); - return end; - } - final int length = popupSpec.length(); - for (int pos = start; pos < length; pos++) { - final char c = popupSpec.charAt(pos); - if (c == ESCAPE && pos + 1 < length) { - pos++; - } else if (popupSpec.startsWith(LABEL_END, pos)) { - return pos; - } - } - return -1; - } - - public static String getLabel(String popupSpec) { - if (hasIcon(popupSpec)) - return null; - final int end = indexOfLabelEnd(popupSpec, 0); - final String label = (end > 0) ? parseEscape(popupSpec.substring(0, end)) - : parseEscape(popupSpec); - if (TextUtils.isEmpty(label)) - throw new PopupCharactersParserError("Empty label: " + popupSpec); - return label; - } - - public static String getOutputText(String popupSpec) { - if (hasCode(popupSpec)) - return null; - final int end = indexOfLabelEnd(popupSpec, 0); - if (end > 0) { - if (indexOfLabelEnd(popupSpec, end + 1) >= 0) - throw new PopupCharactersParserError("Multiple " + LABEL_END + ": " - + popupSpec); - final String outputText = parseEscape(popupSpec.substring(end + LABEL_END.length())); - if (!TextUtils.isEmpty(outputText)) - return outputText; - throw new PopupCharactersParserError("Empty outputText: " + popupSpec); - } - final String label = getLabel(popupSpec); - if (label == null) - throw new PopupCharactersParserError("Empty label: " + popupSpec); - // Code is automatically generated for one letter label. See {@link getCode()}. - if (label.length() == 1) - return null; - return label; - } - - public static int getCode(Resources res, String popupSpec) { - if (hasCode(popupSpec)) { - final int end = indexOfLabelEnd(popupSpec, 0); - if (indexOfLabelEnd(popupSpec, end + 1) >= 0) - throw new PopupCharactersParserError("Multiple " + LABEL_END + ": " + popupSpec); - final int resId = getResourceId(res, - popupSpec.substring(end + LABEL_END.length() + PREFIX_AT.length())); - final int code = res.getInteger(resId); - return code; - } - if (indexOfLabelEnd(popupSpec, 0) > 0) - return Keyboard.CODE_DUMMY; - final String label = getLabel(popupSpec); - // Code is automatically generated for one letter label. - if (label != null && label.length() == 1) - return label.charAt(0); - return Keyboard.CODE_DUMMY; - } - - public static Drawable getIcon(Resources res, String popupSpec) { - if (hasIcon(popupSpec)) { - int end = popupSpec.indexOf(LABEL_END, PREFIX_ICON.length() + 1); - int resId = getResourceId(res, popupSpec.substring(PREFIX_AT.length(), end)); - return res.getDrawable(resId); - } - return null; - } - - private static int getResourceId(Resources res, String name) { - String packageName = res.getResourcePackageName(R.string.english_ime_name); - int resId = res.getIdentifier(name, null, packageName); - if (resId == 0) - throw new PopupCharactersParserError("Unknown resource: " + name); - return resId; - } - - @SuppressWarnings("serial") - public static class PopupCharactersParserError extends RuntimeException { - public PopupCharactersParserError(String message) { - super(message); - } - } -} diff --git a/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java b/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java index ff64c73cd..2085404dc 100644 --- a/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java @@ -25,6 +25,7 @@ import android.view.MotionEvent; import android.view.View; import android.widget.PopupWindow; +import com.android.inputmethod.keyboard.internal.Key; import com.android.inputmethod.latin.R; /** diff --git a/java/src/com/android/inputmethod/keyboard/PopupPanel.java b/java/src/com/android/inputmethod/keyboard/PopupPanel.java index 6f2b16148..72fa7406a 100644 --- a/java/src/com/android/inputmethod/keyboard/PopupPanel.java +++ b/java/src/com/android/inputmethod/keyboard/PopupPanel.java @@ -19,6 +19,8 @@ package com.android.inputmethod.keyboard; import android.view.MotionEvent; import android.widget.PopupWindow; +import com.android.inputmethod.keyboard.internal.Key; + public interface PopupPanel { /** * Show popup panel. diff --git a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java index 33acc6907..a6a07e518 100644 --- a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java +++ b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java @@ -16,6 +16,7 @@ package com.android.inputmethod.keyboard; +import com.android.inputmethod.keyboard.internal.Key; import com.android.inputmethod.latin.Utils; import java.util.Arrays; diff --git a/java/src/com/android/inputmethod/keyboard/Row.java b/java/src/com/android/inputmethod/keyboard/Row.java deleted file mode 100644 index 40d7e1472..000000000 --- a/java/src/com/android/inputmethod/keyboard/Row.java +++ /dev/null @@ -1,72 +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 com.android.inputmethod.latin.R; - -import android.content.res.Resources; -import android.content.res.TypedArray; -import android.content.res.XmlResourceParser; -import android.util.Xml; - -/** - * Container for keys in the keyboard. All keys in a row are at the same Y-coordinate. - * Some of the key size defaults can be overridden per row from what the {@link Keyboard} - * defines. - */ -public class Row { - /** Default width of a key in this row. */ - public final int mDefaultWidth; - /** Default height of a key in this row. */ - public final int mDefaultHeight; - /** Default horizontal gap between keys in this row. */ - public final int mDefaultHorizontalGap; - /** Vertical gap following this row. */ - public final int mVerticalGap; - /** - * Edge flags for this row of keys. Possible values that can be assigned are - * {@link Keyboard#EDGE_TOP EDGE_TOP} and {@link Keyboard#EDGE_BOTTOM EDGE_BOTTOM} - */ - public final int mRowEdgeFlags; - - private final Keyboard mKeyboard; - - public Row(Resources res, Keyboard keyboard, XmlResourceParser parser) { - this.mKeyboard = keyboard; - final int keyboardWidth = keyboard.getDisplayWidth(); - final int keyboardHeight = keyboard.getKeyboardHeight(); - TypedArray a = res.obtainAttributes(Xml.asAttributeSet(parser), - R.styleable.Keyboard); - mDefaultWidth = KeyboardParser.getDimensionOrFraction(a, - R.styleable.Keyboard_keyWidth, keyboardWidth, keyboard.getKeyWidth()); - mDefaultHeight = KeyboardParser.getDimensionOrFraction(a, - R.styleable.Keyboard_rowHeight, keyboardHeight, keyboard.getRowHeight()); - mDefaultHorizontalGap = KeyboardParser.getDimensionOrFraction(a, - R.styleable.Keyboard_horizontalGap, keyboardWidth, keyboard.getHorizontalGap()); - mVerticalGap = KeyboardParser.getDimensionOrFraction(a, - R.styleable.Keyboard_verticalGap, keyboardHeight, keyboard.getVerticalGap()); - a.recycle(); - a = res.obtainAttributes(Xml.asAttributeSet(parser), - R.styleable.Keyboard_Row); - mRowEdgeFlags = a.getInt(R.styleable.Keyboard_Row_rowEdgeFlags, 0); - a.recycle(); - } - - public Keyboard getKeyboard() { - return mKeyboard; - } -} diff --git a/java/src/com/android/inputmethod/keyboard/ShiftKeyState.java b/java/src/com/android/inputmethod/keyboard/ShiftKeyState.java deleted file mode 100644 index ba15624f0..000000000 --- a/java/src/com/android/inputmethod/keyboard/ShiftKeyState.java +++ /dev/null @@ -1,69 +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 android.util.Log; - -public class ShiftKeyState extends ModifierKeyState { - private static final int PRESSING_ON_SHIFTED = 3; // both temporary shifted & shift locked - private static final int IGNORING = 4; - - public ShiftKeyState(String name) { - super(name); - } - - @Override - public void onOtherKeyPressed() { - int oldState = mState; - if (oldState == PRESSING) { - mState = MOMENTARY; - } else if (oldState == PRESSING_ON_SHIFTED) { - mState = IGNORING; - } - if (DEBUG) - Log.d(TAG, mName + ".onOtherKeyPressed: " + toString(oldState) + " > " + this); - } - - public void onPressOnShifted() { - int oldState = mState; - mState = PRESSING_ON_SHIFTED; - if (DEBUG) - Log.d(TAG, mName + ".onPressOnShifted: " + toString(oldState) + " > " + this); - } - - public boolean isPressingOnShifted() { - return mState == PRESSING_ON_SHIFTED; - } - - public boolean isIgnoring() { - return mState == IGNORING; - } - - @Override - public String toString() { - return toString(mState); - } - - @Override - protected String toString(int state) { - switch (state) { - case PRESSING_ON_SHIFTED: return "PRESSING_ON_SHIFTED"; - case IGNORING: return "IGNORING"; - default: return super.toString(state); - } - } -} diff --git a/java/src/com/android/inputmethod/keyboard/SlidingLocaleDrawable.java b/java/src/com/android/inputmethod/keyboard/SlidingLocaleDrawable.java deleted file mode 100644 index dd271de64..000000000 --- a/java/src/com/android/inputmethod/keyboard/SlidingLocaleDrawable.java +++ /dev/null @@ -1,157 +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 android.content.Context; -import android.content.res.TypedArray; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.ColorFilter; -import android.graphics.Paint; -import android.graphics.Paint.Align; -import android.graphics.PixelFormat; -import android.graphics.drawable.Drawable; -import android.text.TextPaint; -import android.view.ViewConfiguration; - -import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.SubtypeSwitcher; - -/** - * Animation to be displayed on the spacebar preview popup when switching languages by swiping the - * spacebar. It draws the current, previous and next languages and moves them by the delta of touch - * movement on the spacebar. - */ -public class SlidingLocaleDrawable extends Drawable { - private static final int SLIDE_SPEED_MULTIPLIER_RATIO = 150; - private final int mWidth; - private final int mHeight; - private final Drawable mBackground; - private final int mSpacebarTextColor; - private final TextPaint mTextPaint; - private final int mMiddleX; - private final Drawable mLeftDrawable; - private final Drawable mRightDrawable; - private final int mThreshold; - - private int mDiff; - private boolean mHitThreshold; - private String mCurrentLanguage; - private String mNextLanguage; - private String mPrevLanguage; - - public SlidingLocaleDrawable(Context context, Drawable background, int width, int height) { - mBackground = background; - Keyboard.setDefaultBounds(mBackground); - mWidth = width; - mHeight = height; - final TextPaint textPaint = new TextPaint(); - 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 = (mWidth - mBackground.getIntrinsicWidth()) / 2; - - final TypedArray a = context.obtainStyledAttributes( - null, R.styleable.LatinKeyboard, R.attr.latinKeyboardStyle, R.style.LatinKeyboard); - mSpacebarTextColor = a.getColor(R.styleable.LatinKeyboard_spacebarTextColor, 0); - mLeftDrawable = a.getDrawable(R.styleable.LatinKeyboard_spacebarArrowPreviewLeftIcon); - mRightDrawable = a.getDrawable(R.styleable.LatinKeyboard_spacebarArrowPreviewRightIcon); - a.recycle(); - - mThreshold = ViewConfiguration.get(context).getScaledTouchSlop(); - } - - void setDiff(int diff) { - if (diff == Integer.MAX_VALUE) { - mHitThreshold = false; - mCurrentLanguage = null; - return; - } - mDiff = Math.max(diff, diff * SLIDE_SPEED_MULTIPLIER_RATIO / 100); - if (mDiff > mWidth) mDiff = mWidth; - if (mDiff < -mWidth) mDiff = -mWidth; - if (Math.abs(mDiff) > mThreshold) mHitThreshold = true; - invalidateSelf(); - } - - - @Override - public void draw(Canvas canvas) { - canvas.save(); - if (mHitThreshold) { - Paint paint = mTextPaint; - 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(); - mCurrentLanguage = subtypeSwitcher.getInputLanguageName(); - mNextLanguage = subtypeSwitcher.getNextInputLanguageName(); - mPrevLanguage = subtypeSwitcher.getPreviousInputLanguageName(); - } - // Draw language text with shadow - final float baseline = mHeight * LatinKeyboard.SPACEBAR_LANGUAGE_BASELINE - - paint.descent(); - paint.setColor(mSpacebarTextColor); - 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); - - Keyboard.setDefaultBounds(lArrow); - rArrow.setBounds(width - rArrow.getIntrinsicWidth(), 0, width, - rArrow.getIntrinsicHeight()); - lArrow.draw(canvas); - rArrow.draw(canvas); - } - if (mBackground != null) { - canvas.translate(mMiddleX, 0); - mBackground.draw(canvas); - } - canvas.restore(); - } - - @Override - public int getOpacity() { - return PixelFormat.TRANSLUCENT; - } - - @Override - public void setAlpha(int alpha) { - // Ignore - } - - @Override - public void setColorFilter(ColorFilter cf) { - // Ignore - } - - @Override - public int getIntrinsicWidth() { - return mWidth; - } - - @Override - public int getIntrinsicHeight() { - return mHeight; - } -} diff --git a/java/src/com/android/inputmethod/keyboard/SwipeTracker.java b/java/src/com/android/inputmethod/keyboard/SwipeTracker.java deleted file mode 100644 index 975b13b50..000000000 --- a/java/src/com/android/inputmethod/keyboard/SwipeTracker.java +++ /dev/null @@ -1,157 +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 android.view.MotionEvent; - -public class SwipeTracker { - private static final int NUM_PAST = 4; - private static final int LONGEST_PAST_TIME = 200; - - final EventRingBuffer mBuffer = new EventRingBuffer(NUM_PAST); - - private float mYVelocity; - private float mXVelocity; - - public void addMovement(MotionEvent ev) { - if (ev.getAction() == MotionEvent.ACTION_DOWN) { - mBuffer.clear(); - return; - } - long time = ev.getEventTime(); - final int count = ev.getHistorySize(); - for (int i = 0; i < count; i++) { - addPoint(ev.getHistoricalX(i), ev.getHistoricalY(i), ev.getHistoricalEventTime(i)); - } - addPoint(ev.getX(), ev.getY(), time); - } - - private void addPoint(float x, float y, long time) { - final EventRingBuffer buffer = mBuffer; - while (buffer.size() > 0) { - long lastT = buffer.getTime(0); - if (lastT >= time - LONGEST_PAST_TIME) - break; - buffer.dropOldest(); - } - buffer.add(x, y, time); - } - - public void computeCurrentVelocity(int units) { - computeCurrentVelocity(units, Float.MAX_VALUE); - } - - public void computeCurrentVelocity(int units, float maxVelocity) { - final EventRingBuffer buffer = mBuffer; - final float oldestX = buffer.getX(0); - final float oldestY = buffer.getY(0); - final long oldestTime = buffer.getTime(0); - - float accumX = 0; - float accumY = 0; - final int count = buffer.size(); - for (int pos = 1; pos < count; pos++) { - final int dur = (int)(buffer.getTime(pos) - oldestTime); - if (dur == 0) continue; - float dist = buffer.getX(pos) - oldestX; - float vel = (dist / dur) * units; // pixels/frame. - if (accumX == 0) accumX = vel; - else accumX = (accumX + vel) * .5f; - - dist = buffer.getY(pos) - oldestY; - vel = (dist / dur) * units; // pixels/frame. - if (accumY == 0) accumY = vel; - else accumY = (accumY + vel) * .5f; - } - mXVelocity = accumX < 0.0f ? Math.max(accumX, -maxVelocity) - : Math.min(accumX, maxVelocity); - mYVelocity = accumY < 0.0f ? Math.max(accumY, -maxVelocity) - : Math.min(accumY, maxVelocity); - } - - public float getXVelocity() { - return mXVelocity; - } - - public float getYVelocity() { - return mYVelocity; - } - - public static class EventRingBuffer { - private final int bufSize; - private final float xBuf[]; - private final float yBuf[]; - private final long timeBuf[]; - private int top; // points new event - private int end; // points oldest event - private int count; // the number of valid data - - public EventRingBuffer(int max) { - this.bufSize = max; - xBuf = new float[max]; - yBuf = new float[max]; - timeBuf = new long[max]; - clear(); - } - - public void clear() { - top = end = count = 0; - } - - public int size() { - return count; - } - - // Position 0 points oldest event - private int index(int pos) { - return (end + pos) % bufSize; - } - - private int advance(int index) { - return (index + 1) % bufSize; - } - - public void add(float x, float y, long time) { - xBuf[top] = x; - yBuf[top] = y; - timeBuf[top] = time; - top = advance(top); - if (count < bufSize) { - count++; - } else { - end = advance(end); - } - } - - public float getX(int pos) { - return xBuf[index(pos)]; - } - - public float getY(int pos) { - return yBuf[index(pos)]; - } - - public long getTime(int pos) { - return timeBuf[index(pos)]; - } - - public void dropOldest() { - count--; - end = advance(end); - } - } -} diff --git a/java/src/com/android/inputmethod/keyboard/internal/Key.java b/java/src/com/android/inputmethod/keyboard/internal/Key.java new file mode 100644 index 000000000..c5946ef00 --- /dev/null +++ b/java/src/com/android/inputmethod/keyboard/internal/Key.java @@ -0,0 +1,450 @@ +/* + * 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 com.android.inputmethod.keyboard.Keyboard; +import com.android.inputmethod.keyboard.internal.KeyStyles.KeyStyle; +import com.android.inputmethod.keyboard.internal.KeyboardParser.ParseException; +import com.android.inputmethod.latin.R; + +import android.content.res.Resources; +import android.content.res.TypedArray; +import android.content.res.XmlResourceParser; +import android.graphics.drawable.Drawable; +import android.text.TextUtils; +import android.util.Xml; + +import java.util.ArrayList; + +/** + * Class for describing the position and characteristics of a single key in the keyboard. + */ +public class Key { + /** + * The key code (unicode or custom code) that this key generates. + */ + public final int mCode; + + /** Label to display */ + public final CharSequence mLabel; + /** Hint letter to display on the key in conjunction with the label */ + public final CharSequence mHintLetter; + /** Option of the label */ + public final int mLabelOption; + public static final int LABEL_OPTION_ALIGN_LEFT = 0x01; + public static final int LABEL_OPTION_ALIGN_RIGHT = 0x02; + public static final int LABEL_OPTION_ALIGN_BOTTOM = 0x08; + public static final int LABEL_OPTION_FONT_NORMAL = 0x10; + private static final int LABEL_OPTION_POPUP_HINT = 0x20; + private static final int LABEL_OPTION_HAS_UPPERCASE_LETTER = 0x40; + + /** Icon to display instead of a label. Icon takes precedence over a label */ + private Drawable mIcon; + /** Preview version of the icon, for the preview popup */ + private Drawable mPreviewIcon; + + /** Width of the key, not including the gap */ + public final int mWidth; + /** Height of the key, not including the gap */ + public final int mHeight; + /** The horizontal gap around this key */ + public final int mGap; + /** The visual insets */ + public final int mVisualInsetsLeft; + public final int mVisualInsetsRight; + /** Whether this key is sticky, i.e., a toggle key */ + public final boolean mSticky; + /** X coordinate of the key in the keyboard layout */ + public final int mX; + /** Y coordinate of the key in the keyboard layout */ + public final int mY; + /** Text to output when pressed. This can be multiple characters, like ".com" */ + public final CharSequence mOutputText; + /** Popup characters */ + public final CharSequence[] mPopupCharacters; + /** Popup keyboard maximum column number */ + public final int mMaxPopupColumn; + + /** + * Flags that specify the anchoring to edges of the keyboard for detecting touch events + * that are just out of the boundary of the key. This is a bit mask of + * {@link Keyboard#EDGE_LEFT}, {@link Keyboard#EDGE_RIGHT}, + * {@link Keyboard#EDGE_TOP} and {@link Keyboard#EDGE_BOTTOM}. + */ + public final int mEdgeFlags; + /** Whether this is a functional key which has different key top than normal key */ + public final boolean mFunctional; + /** Whether this key repeats itself when held down */ + public final boolean mRepeatable; + + /** The Keyboard that this key belongs to */ + private final Keyboard mKeyboard; + + /** The current pressed state of this key */ + public boolean mPressed; + /** If this is a sticky key, is its highlight on? */ + public boolean mHighlightOn; + /** Key is enabled and responds on press */ + public boolean mEnabled = true; + + // keyWidth constants + private static final int KEYWIDTH_FILL_RIGHT = 0; + private static final int KEYWIDTH_FILL_BOTH = -1; + + private final static int[] KEY_STATE_NORMAL_ON = { + android.R.attr.state_checkable, + android.R.attr.state_checked + }; + + private final static int[] KEY_STATE_PRESSED_ON = { + android.R.attr.state_pressed, + android.R.attr.state_checkable, + android.R.attr.state_checked + }; + + private final static int[] KEY_STATE_NORMAL_OFF = { + android.R.attr.state_checkable + }; + + private final static int[] KEY_STATE_PRESSED_OFF = { + android.R.attr.state_pressed, + android.R.attr.state_checkable + }; + + private final static int[] KEY_STATE_NORMAL = { + }; + + private final static int[] KEY_STATE_PRESSED = { + android.R.attr.state_pressed + }; + + // functional normal state (with properties) + private static final int[] KEY_STATE_FUNCTIONAL_NORMAL = { + android.R.attr.state_single + }; + + // functional pressed state (with properties) + private static final int[] KEY_STATE_FUNCTIONAL_PRESSED = { + android.R.attr.state_single, + android.R.attr.state_pressed + }; + + /** + * This constructor is being used only for key in popup mini keyboard. + */ + public Key(Resources res, Keyboard keyboard, CharSequence popupCharacter, int x, int y, + int width, int height, int edgeFlags) { + mKeyboard = keyboard; + mHeight = height - keyboard.getVerticalGap(); + mGap = keyboard.getHorizontalGap(); + mVisualInsetsLeft = mVisualInsetsRight = 0; + mWidth = width - mGap; + mEdgeFlags = edgeFlags; + mHintLetter = null; + mLabelOption = 0; + mFunctional = false; + mSticky = false; + mRepeatable = false; + mPopupCharacters = null; + mMaxPopupColumn = 0; + final String popupSpecification = popupCharacter.toString(); + mLabel = PopupCharactersParser.getLabel(popupSpecification); + mOutputText = PopupCharactersParser.getOutputText(popupSpecification); + mCode = PopupCharactersParser.getCode(res, popupSpecification); + mIcon = PopupCharactersParser.getIcon(res, popupSpecification); + // Horizontal gap is divided equally to both sides of the key. + mX = x + mGap / 2; + mY = y; + } + + /** + * Create a key with the given top-left coordinate and extract its attributes from the XML + * parser. + * @param res resources associated with the caller's context + * @param row the row that this key belongs to. The row must already be attached to + * a {@link Keyboard}. + * @param x the x coordinate of the top-left + * @param y the y coordinate of the top-left + * @param parser the XML parser containing the attributes for this key + * @param keyStyles active key styles set + */ + public Key(Resources res, Row row, int x, int y, XmlResourceParser parser, + KeyStyles keyStyles) { + mKeyboard = row.getKeyboard(); + + final TypedArray keyboardAttr = res.obtainAttributes(Xml.asAttributeSet(parser), + R.styleable.Keyboard); + int keyWidth; + try { + mHeight = KeyboardParser.getDimensionOrFraction(keyboardAttr, + R.styleable.Keyboard_rowHeight, + mKeyboard.getKeyboardHeight(), row.mDefaultHeight) - row.mVerticalGap; + mGap = KeyboardParser.getDimensionOrFraction(keyboardAttr, + R.styleable.Keyboard_horizontalGap, + mKeyboard.getDisplayWidth(), row.mDefaultHorizontalGap); + keyWidth = KeyboardParser.getDimensionOrFraction(keyboardAttr, + R.styleable.Keyboard_keyWidth, + mKeyboard.getDisplayWidth(), row.mDefaultWidth); + } finally { + keyboardAttr.recycle(); + } + + final TypedArray keyAttr = res.obtainAttributes(Xml.asAttributeSet(parser), + R.styleable.Keyboard_Key); + try { + final KeyStyle style; + if (keyAttr.hasValue(R.styleable.Keyboard_Key_keyStyle)) { + String styleName = keyAttr.getString(R.styleable.Keyboard_Key_keyStyle); + style = keyStyles.getKeyStyle(styleName); + if (style == null) + throw new ParseException("Unknown key style: " + styleName, parser); + } else { + style = keyStyles.getEmptyKeyStyle(); + } + + final int keyboardWidth = mKeyboard.getDisplayWidth(); + int keyXPos = KeyboardParser.getDimensionOrFraction(keyAttr, + R.styleable.Keyboard_Key_keyXPos, keyboardWidth, x); + if (keyXPos < 0) { + // If keyXPos is negative, the actual x-coordinate will be k + keyXPos. + keyXPos += keyboardWidth; + if (keyXPos < x) { + // keyXPos shouldn't be less than x because drawable area for this key starts + // at x. Or, this key will overlaps the adjacent key on its left hand side. + keyXPos = x; + } + } + if (keyWidth == KEYWIDTH_FILL_RIGHT) { + // If keyWidth is zero, the actual key width will be determined to fill out the + // area up to the right edge of the keyboard. + keyWidth = keyboardWidth - keyXPos; + } else if (keyWidth <= KEYWIDTH_FILL_BOTH) { + // If keyWidth is negative, the actual key width will be determined to fill out the + // area between the nearest key on the left hand side and the right edge of the + // keyboard. + keyXPos = x; + keyWidth = keyboardWidth - keyXPos; + } + + // Horizontal gap is divided equally to both sides of the key. + mX = keyXPos + mGap / 2; + mY = y; + mWidth = keyWidth - mGap; + + final CharSequence[] popupCharacters = style.getTextArray(keyAttr, + R.styleable.Keyboard_Key_popupCharacters); + if (res.getBoolean(R.bool.config_digit_popup_characters_enabled)) { + mPopupCharacters = popupCharacters; + } else { + mPopupCharacters = filterOutDigitPopupCharacters(popupCharacters); + } + mMaxPopupColumn = style.getInt(keyboardAttr, + R.styleable.Keyboard_Key_maxPopupKeyboardColumn, + mKeyboard.getMaxPopupKeyboardColumn()); + + mRepeatable = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isRepeatable, false); + mFunctional = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isFunctional, false); + mSticky = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isSticky, false); + mEnabled = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_enabled, true); + mEdgeFlags = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyEdgeFlags, 0) + | row.mRowEdgeFlags; + + mVisualInsetsLeft = KeyboardParser.getDimensionOrFraction(keyAttr, + R.styleable.Keyboard_Key_visualInsetsLeft, mKeyboard.getDisplayHeight(), 0); + mVisualInsetsRight = KeyboardParser.getDimensionOrFraction(keyAttr, + R.styleable.Keyboard_Key_visualInsetsRight, mKeyboard.getDisplayHeight(), 0); + mPreviewIcon = style.getDrawable(keyAttr, R.styleable.Keyboard_Key_iconPreview); + Keyboard.setDefaultBounds(mPreviewIcon); + mIcon = style.getDrawable(keyAttr, R.styleable.Keyboard_Key_keyIcon); + Keyboard.setDefaultBounds(mIcon); + mHintLetter = style.getText(keyAttr, R.styleable.Keyboard_Key_keyHintLetter); + + mLabel = style.getText(keyAttr, R.styleable.Keyboard_Key_keyLabel); + mLabelOption = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyLabelOption, 0); + mOutputText = style.getText(keyAttr, R.styleable.Keyboard_Key_keyOutputText); + // Choose the first letter of the label as primary code if not + // specified. + final int code = style.getInt(keyAttr, R.styleable.Keyboard_Key_code, + Keyboard.CODE_UNSPECIFIED); + if (code == Keyboard.CODE_UNSPECIFIED && !TextUtils.isEmpty(mLabel)) { + mCode = mLabel.charAt(0); + } else if (code != Keyboard.CODE_UNSPECIFIED) { + mCode = code; + } else { + mCode = Keyboard.CODE_DUMMY; + } + + final Drawable shiftedIcon = style.getDrawable(keyAttr, + R.styleable.Keyboard_Key_shiftedIcon); + if (shiftedIcon != null) + mKeyboard.getShiftedIcons().put(this, shiftedIcon); + } finally { + keyAttr.recycle(); + } + } + + public boolean hasPopupHint() { + return (mLabelOption & LABEL_OPTION_POPUP_HINT) != 0; + } + + public boolean hasUppercaseLetter() { + return (mLabelOption & LABEL_OPTION_HAS_UPPERCASE_LETTER) != 0; + } + + private static boolean isDigitPopupCharacter(CharSequence label) { + return label != null && label.length() == 1 && Character.isDigit(label.charAt(0)); + } + + private static CharSequence[] filterOutDigitPopupCharacters(CharSequence[] popupCharacters) { + if (popupCharacters == null || popupCharacters.length < 1) + return null; + if (popupCharacters.length == 1 && isDigitPopupCharacter( + PopupCharactersParser.getLabel(popupCharacters[0].toString()))) + return null; + ArrayList filtered = null; + for (int i = 0; i < popupCharacters.length; i++) { + final CharSequence popupSpec = popupCharacters[i]; + if (isDigitPopupCharacter(PopupCharactersParser.getLabel(popupSpec.toString()))) { + if (filtered == null) { + filtered = new ArrayList(); + for (int j = 0; j < i; j++) + filtered.add(popupCharacters[j]); + } + } else if (filtered != null) { + filtered.add(popupSpec); + } + } + if (filtered == null) + return popupCharacters; + if (filtered.size() == 0) + return null; + return filtered.toArray(new CharSequence[filtered.size()]); + } + + public Drawable getIcon() { + return mIcon; + } + + public Drawable getPreviewIcon() { + return mPreviewIcon; + } + + public void setIcon(Drawable icon) { + mIcon = icon; + } + + public void setPreviewIcon(Drawable icon) { + mPreviewIcon = icon; + } + + /** + * Informs the key that it has been pressed, in case it needs to change its appearance or + * state. + * @see #onReleased() + */ + public void onPressed() { + mPressed = true; + } + + /** + * Informs the key that it has been released, in case it needs to change its appearance or + * state. + * @see #onPressed() + */ + public void onReleased() { + mPressed = false; + } + + /** + * Detects if a point falls on this key. + * @param x the x-coordinate of the point + * @param y the y-coordinate of the point + * @return whether or not the point falls on the key. If the key is attached to an edge, it will + * assume that all points between the key and the edge are considered to be on the key. + */ + public boolean isOnKey(int x, int y) { + final int flags = mEdgeFlags; + final boolean leftEdge = (flags & Keyboard.EDGE_LEFT) != 0; + final boolean rightEdge = (flags & Keyboard.EDGE_RIGHT) != 0; + final boolean topEdge = (flags & Keyboard.EDGE_TOP) != 0; + final boolean bottomEdge = (flags & Keyboard.EDGE_BOTTOM) != 0; + final int left = mX - mGap / 2; + final int right = left + mWidth + mGap; + final int top = mY; + final int bottom = top + mHeight + mKeyboard.getVerticalGap(); + // In order to mitigate rounding errors, we use (left <= x <= right) here. + return (x >= left || leftEdge) && (x <= right || rightEdge) + && (y >= top || topEdge) && (y <= bottom || bottomEdge); + } + + /** + * Returns the square of the distance to the nearest edge of the key and the given point. + * @param x the x-coordinate of the point + * @param y the y-coordinate of the point + * @return the square of the distance of the point from the nearest edge of the key + */ + public int squaredDistanceToEdge(int x, int y) { + final int left = mX; + final int right = left + mWidth; + final int top = mY; + final int bottom = top + mHeight; + final int edgeX = x < left ? left : (x > right ? right : x); + final int edgeY = y < top ? top : (y > bottom ? bottom : y); + final int dx = x - edgeX; + final int dy = y - edgeY; + return dx * dx + dy * dy; + } + + /** + * Returns the drawable state for the key, based on the current state and type of the key. + * @return the drawable state of the key. + * @see android.graphics.drawable.StateListDrawable#setState(int[]) + */ + public int[] getCurrentDrawableState() { + final boolean pressed = mPressed; + if (!mSticky && mFunctional) { + if (pressed) { + return KEY_STATE_FUNCTIONAL_PRESSED; + } else { + return KEY_STATE_FUNCTIONAL_NORMAL; + } + } + + int[] states = KEY_STATE_NORMAL; + + if (mHighlightOn) { + if (pressed) { + states = KEY_STATE_PRESSED_ON; + } else { + states = KEY_STATE_NORMAL_ON; + } + } else { + if (mSticky) { + if (pressed) { + states = KEY_STATE_PRESSED_OFF; + } else { + states = KEY_STATE_NORMAL_OFF; + } + } else { + if (pressed) { + states = KEY_STATE_PRESSED; + } + } + } + return states; + } +} diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java b/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java new file mode 100644 index 000000000..dc2f4a15a --- /dev/null +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java @@ -0,0 +1,259 @@ +/* + * 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 com.android.inputmethod.keyboard.internal.KeyboardParser.ParseException; +import com.android.inputmethod.latin.R; + +import android.content.res.TypedArray; +import android.content.res.XmlResourceParser; +import android.graphics.drawable.Drawable; +import android.util.Log; + +import java.util.ArrayList; +import java.util.HashMap; + +public class KeyStyles { + private static final String TAG = "KeyStyles"; + private static final boolean DEBUG = false; + + private final HashMap mStyles = + new HashMap(); + private static final KeyStyle EMPTY_KEY_STYLE = new EmptyKeyStyle(); + + public interface KeyStyle { + public CharSequence[] getTextArray(TypedArray a, int index); + public Drawable getDrawable(TypedArray a, int index); + public CharSequence getText(TypedArray a, int index); + public int getInt(TypedArray a, int index, int defaultValue); + public int getFlag(TypedArray a, int index, int defaultValue); + public boolean getBoolean(TypedArray a, int index, boolean defaultValue); + } + + /* package */ static class EmptyKeyStyle implements KeyStyle { + private EmptyKeyStyle() { + // Nothing to do. + } + + @Override + public CharSequence[] getTextArray(TypedArray a, int index) { + return parseTextArray(a, index); + } + + @Override + public Drawable getDrawable(TypedArray a, int index) { + return a.getDrawable(index); + } + + @Override + public CharSequence getText(TypedArray a, int index) { + return a.getText(index); + } + + @Override + public int getInt(TypedArray a, int index, int defaultValue) { + return a.getInt(index, defaultValue); + } + + @Override + public int getFlag(TypedArray a, int index, int defaultValue) { + return a.getInt(index, defaultValue); + } + + @Override + public boolean getBoolean(TypedArray a, int index, boolean defaultValue) { + return a.getBoolean(index, defaultValue); + } + + protected static CharSequence[] parseTextArray(TypedArray a, int index) { + if (!a.hasValue(index)) + return null; + final CharSequence text = a.getText(index); + return parseCsvText(text); + } + + /* package */ static CharSequence[] parseCsvText(CharSequence text) { + final int size = text.length(); + if (size == 0) return null; + if (size == 1) return new CharSequence[] { text }; + final StringBuilder sb = new StringBuilder(); + ArrayList list = null; + int start = 0; + for (int pos = 0; pos < size; pos++) { + final char c = text.charAt(pos); + if (c == ',') { + if (list == null) list = new ArrayList(); + if (sb.length() == 0) { + list.add(text.subSequence(start, pos)); + } else { + list.add(sb.toString()); + sb.setLength(0); + } + start = pos + 1; + continue; + } else if (c == '\\') { + if (start == pos) { + // Skip escape character at the beginning of the value. + start++; + pos++; + } else { + if (start < pos && sb.length() == 0) + sb.append(text.subSequence(start, pos)); + pos++; + if (pos < size) + sb.append(text.charAt(pos)); + } + } else if (sb.length() > 0) { + sb.append(c); + } + } + if (list == null) { + return new CharSequence[] { sb.length() > 0 ? sb : text.subSequence(start, size) }; + } else { + list.add(sb.length() > 0 ? sb : text.subSequence(start, size)); + return list.toArray(new CharSequence[list.size()]); + } + } + } + + private static class DeclaredKeyStyle extends EmptyKeyStyle { + private final HashMap mAttributes = new HashMap(); + + @Override + public CharSequence[] getTextArray(TypedArray a, int index) { + return a.hasValue(index) + ? super.getTextArray(a, index) : (CharSequence[])mAttributes.get(index); + } + + @Override + public Drawable getDrawable(TypedArray a, int index) { + return a.hasValue(index) + ? super.getDrawable(a, index) : (Drawable)mAttributes.get(index); + } + + @Override + public CharSequence getText(TypedArray a, int index) { + return a.hasValue(index) + ? super.getText(a, index) : (CharSequence)mAttributes.get(index); + } + + @Override + public int getInt(TypedArray a, int index, int defaultValue) { + final Integer value = (Integer)mAttributes.get(index); + return super.getInt(a, index, (value != null) ? value : defaultValue); + } + + @Override + public int getFlag(TypedArray a, int index, int defaultValue) { + final Integer value = (Integer)mAttributes.get(index); + return super.getFlag(a, index, defaultValue) | (value != null ? value : 0); + } + + @Override + public boolean getBoolean(TypedArray a, int index, boolean defaultValue) { + final Boolean value = (Boolean)mAttributes.get(index); + return super.getBoolean(a, index, (value != null) ? value : defaultValue); + } + + private DeclaredKeyStyle() { + super(); + } + + private void parseKeyStyleAttributes(TypedArray keyAttr) { + // TODO: Currently not all Key attributes can be declared as style. + readInt(keyAttr, R.styleable.Keyboard_Key_code); + readText(keyAttr, R.styleable.Keyboard_Key_keyLabel); + readFlag(keyAttr, R.styleable.Keyboard_Key_keyLabelOption); + readTextArray(keyAttr, R.styleable.Keyboard_Key_popupCharacters); + readInt(keyAttr, R.styleable.Keyboard_Key_maxPopupKeyboardColumn); + readText(keyAttr, R.styleable.Keyboard_Key_keyOutputText); + readDrawable(keyAttr, R.styleable.Keyboard_Key_keyIcon); + readDrawable(keyAttr, R.styleable.Keyboard_Key_iconPreview); + readText(keyAttr, R.styleable.Keyboard_Key_keyHintLetter); + readDrawable(keyAttr, R.styleable.Keyboard_Key_shiftedIcon); + readBoolean(keyAttr, R.styleable.Keyboard_Key_isFunctional); + readBoolean(keyAttr, R.styleable.Keyboard_Key_isSticky); + readBoolean(keyAttr, R.styleable.Keyboard_Key_isRepeatable); + readBoolean(keyAttr, R.styleable.Keyboard_Key_enabled); + } + + private void readDrawable(TypedArray a, int index) { + if (a.hasValue(index)) + mAttributes.put(index, a.getDrawable(index)); + } + + private void readText(TypedArray a, int index) { + if (a.hasValue(index)) + mAttributes.put(index, a.getText(index)); + } + + private void readInt(TypedArray a, int index) { + if (a.hasValue(index)) + mAttributes.put(index, a.getInt(index, 0)); + } + + private void readFlag(TypedArray a, int index) { + final Integer value = (Integer)mAttributes.get(index); + if (a.hasValue(index)) + mAttributes.put(index, a.getInt(index, 0) | (value != null ? value : 0)); + } + + private void readBoolean(TypedArray a, int index) { + if (a.hasValue(index)) + mAttributes.put(index, a.getBoolean(index, false)); + } + + private void readTextArray(TypedArray a, int index) { + final CharSequence[] value = parseTextArray(a, index); + if (value != null) + mAttributes.put(index, value); + } + + private void addParent(DeclaredKeyStyle parentStyle) { + mAttributes.putAll(parentStyle.mAttributes); + } + } + + public void parseKeyStyleAttributes(TypedArray keyStyleAttr, TypedArray keyAttrs, + XmlResourceParser parser) { + String styleName = keyStyleAttr.getString(R.styleable.Keyboard_KeyStyle_styleName); + if (DEBUG) Log.d(TAG, String.format("<%s styleName=%s />", + KeyboardParser.TAG_KEY_STYLE, styleName)); + if (mStyles.containsKey(styleName)) + throw new ParseException("duplicate key style declared: " + styleName, parser); + + final DeclaredKeyStyle style = new DeclaredKeyStyle(); + if (keyStyleAttr.hasValue(R.styleable.Keyboard_KeyStyle_parentStyle)) { + String parentStyle = keyStyleAttr.getString( + R.styleable.Keyboard_KeyStyle_parentStyle); + final DeclaredKeyStyle parent = mStyles.get(parentStyle); + if (parent == null) + throw new ParseException("Unknown parentStyle " + parent, parser); + style.addParent(parent); + } + style.parseKeyStyleAttributes(keyAttrs); + mStyles.put(styleName, style); + } + + public KeyStyle getKeyStyle(String styleName) { + return mStyles.get(styleName); + } + + public KeyStyle getEmptyKeyStyle() { + return EMPTY_KEY_STYLE; + } +} diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java new file mode 100644 index 000000000..f54cf0bea --- /dev/null +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java @@ -0,0 +1,714 @@ +/* + * 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.content.Context; +import android.content.res.Resources; +import android.content.res.TypedArray; +import android.content.res.XmlResourceParser; +import android.util.Log; +import android.util.TypedValue; +import android.util.Xml; +import android.view.InflateException; + +import com.android.inputmethod.compat.EditorInfoCompatUtils; +import com.android.inputmethod.keyboard.Keyboard; +import com.android.inputmethod.keyboard.KeyboardId; +import com.android.inputmethod.latin.R; + +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +/** + * Parser for BaseKeyboard. + * + * This class parses Keyboard XML file and fill out keys in Keyboard. + * The Keyboard XML file looks like: + *
+ *   >!-- xml/keyboard.xml --<
+ *   >Keyboard keyboard_attributes*<
+ *     >!-- Keyboard Content --<
+ *     >Row row_attributes*<
+ *       >!-- Row Content --<
+ *       >Key key_attributes* /<
+ *       >Spacer horizontalGap="0.2in" /<
+ *       >include keyboardLayout="@xml/other_keys"<
+ *       ...
+ *     >/Row<
+ *     >include keyboardLayout="@xml/other_rows"<
+ *     ...
+ *   >/Keyboard<
+ * 
+ * The XML file which is included in other file must have >merge< as root element, such as: + *
+ *   >!-- xml/other_keys.xml --<
+ *   >merge<
+ *     >Key key_attributes* /<
+ *     ...
+ *   >/merge<
+ * 
+ * and + *
+ *   >!-- xml/other_rows.xml --<
+ *   >merge<
+ *     >Row row_attributes*<
+ *       >Key key_attributes* /<
+ *     >/Row<
+ *     ...
+ *   >/merge<
+ * 
+ * You can also use switch-case-default tags to select Rows and Keys. + *
+ *   >switch<
+ *     >case case_attribute*<
+ *       >!-- Any valid tags at switch position --<
+ *     >/case<
+ *     ...
+ *     >default<
+ *       >!-- Any valid tags at switch position --<
+ *     >/default<
+ *   >/switch<
+ * 
+ * You can declare Key style and specify styles within Key tags. + *
+ *     >switch<
+ *       >case colorScheme="white"<
+ *         >key-style styleName="shift-key" parentStyle="modifier-key"
+ *           keyIcon="@drawable/sym_keyboard_shift"
+ *         /<
+ *       >/case<
+ *       >case colorScheme="black"<
+ *         >key-style styleName="shift-key" parentStyle="modifier-key"
+ *           keyIcon="@drawable/sym_bkeyboard_shift"
+ *         /<
+ *       >/case<
+ *     >/switch<
+ *     ...
+ *     >Key keyStyle="shift-key" ... /<
+ * 
+ */ + +public class KeyboardParser { + private static final String TAG = KeyboardParser.class.getSimpleName(); + private static final boolean DEBUG = false; + + // Keyboard XML Tags + private static final String TAG_KEYBOARD = "Keyboard"; + private static final String TAG_ROW = "Row"; + private static final String TAG_KEY = "Key"; + private static final String TAG_SPACER = "Spacer"; + private static final String TAG_INCLUDE = "include"; + private static final String TAG_MERGE = "merge"; + private static final String TAG_SWITCH = "switch"; + private static final String TAG_CASE = "case"; + private static final String TAG_DEFAULT = "default"; + public static final String TAG_KEY_STYLE = "key-style"; + + private final Keyboard mKeyboard; + private final Context mContext; + private final Resources mResources; + + private int mHorizontalEdgesPadding; + private int mCurrentX = 0; + private int mCurrentY = 0; + private int mMaxRowWidth = 0; + private int mTotalHeight = 0; + private Row mCurrentRow = null; + private final KeyStyles mKeyStyles = new KeyStyles(); + + public KeyboardParser(Keyboard keyboard, Context context) { + mKeyboard = keyboard; + mContext = context; + final Resources res = context.getResources(); + mResources = res; + mHorizontalEdgesPadding = (int)res.getDimension(R.dimen.keyboard_horizontal_edges_padding); + } + + public int getMaxRowWidth() { + return mMaxRowWidth; + } + + public int getTotalHeight() { + return mTotalHeight; + } + + public void parseKeyboard(int resId) throws XmlPullParserException, IOException { + if (DEBUG) Log.d(TAG, String.format("<%s> %s", TAG_KEYBOARD, mKeyboard.mId)); + final XmlResourceParser parser = mResources.getXml(resId); + int event; + while ((event = parser.next()) != XmlPullParser.END_DOCUMENT) { + if (event == XmlPullParser.START_TAG) { + final String tag = parser.getName(); + if (TAG_KEYBOARD.equals(tag)) { + parseKeyboardAttributes(parser); + startKeyboard(); + parseKeyboardContent(parser, mKeyboard.getKeys()); + break; + } else { + throw new IllegalStartTag(parser, TAG_KEYBOARD); + } + } + } + } + + public static String parseKeyboardLocale( + Context context, int resId) throws XmlPullParserException, IOException { + final Resources res = context.getResources(); + final XmlResourceParser parser = res.getXml(resId); + if (parser == null) return ""; + int event; + while ((event = parser.next()) != XmlPullParser.END_DOCUMENT) { + if (event == XmlPullParser.START_TAG) { + final String tag = parser.getName(); + if (TAG_KEYBOARD.equals(tag)) { + final TypedArray keyboardAttr = res.obtainAttributes(Xml.asAttributeSet(parser), + R.styleable.Keyboard); + return keyboardAttr.getString(R.styleable.Keyboard_keyboardLocale); + } else { + throw new IllegalStartTag(parser, TAG_KEYBOARD); + } + } + } + return ""; + } + + private void parseKeyboardAttributes(XmlResourceParser parser) { + final Keyboard keyboard = mKeyboard; + final TypedArray keyboardAttr = mContext.obtainStyledAttributes( + Xml.asAttributeSet(parser), R.styleable.Keyboard, R.attr.keyboardStyle, + R.style.Keyboard); + final TypedArray keyAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser), + R.styleable.Keyboard_Key); + try { + final int displayHeight = keyboard.getDisplayHeight(); + final int keyboardHeight = (int)keyboardAttr.getDimension( + R.styleable.Keyboard_keyboardHeight, displayHeight / 2); + final int maxKeyboardHeight = getDimensionOrFraction(keyboardAttr, + R.styleable.Keyboard_maxKeyboardHeight, displayHeight, displayHeight / 2); + int minKeyboardHeight = getDimensionOrFraction(keyboardAttr, + R.styleable.Keyboard_minKeyboardHeight, displayHeight, displayHeight / 2); + if (minKeyboardHeight < 0) { + // Specified fraction was negative, so it should be calculated against display + // width. + final int displayWidth = keyboard.getDisplayWidth(); + minKeyboardHeight = -getDimensionOrFraction(keyboardAttr, + R.styleable.Keyboard_minKeyboardHeight, displayWidth, displayWidth / 2); + } + // Keyboard height will not exceed maxKeyboardHeight and will not be less than + // minKeyboardHeight. + final int height = Math.max( + Math.min(keyboardHeight, maxKeyboardHeight), minKeyboardHeight); + final int width = keyboard.getDisplayWidth(); + + keyboard.setKeyboardHeight(height); + keyboard.setKeyWidth(getDimensionOrFraction(keyboardAttr, + R.styleable.Keyboard_keyWidth, width, width / 10)); + keyboard.setRowHeight(getDimensionOrFraction(keyboardAttr, + R.styleable.Keyboard_rowHeight, height, 50)); + keyboard.setHorizontalGap(getDimensionOrFraction(keyboardAttr, + R.styleable.Keyboard_horizontalGap, width, 0)); + keyboard.setVerticalGap(getDimensionOrFraction(keyboardAttr, + R.styleable.Keyboard_verticalGap, height, 0)); + keyboard.setPopupKeyboardResId(keyboardAttr.getResourceId( + R.styleable.Keyboard_popupKeyboardTemplate, 0)); + + keyboard.setMaxPopupKeyboardColumn(keyAttr.getInt( + R.styleable.Keyboard_Key_maxPopupKeyboardColumn, 5)); + } finally { + keyAttr.recycle(); + keyboardAttr.recycle(); + } + } + + private void parseKeyboardContent(XmlResourceParser parser, List keys) + throws XmlPullParserException, IOException { + int event; + while ((event = parser.next()) != XmlPullParser.END_DOCUMENT) { + if (event == XmlPullParser.START_TAG) { + final String tag = parser.getName(); + if (TAG_ROW.equals(tag)) { + Row row = new Row(mResources, mKeyboard, parser); + if (DEBUG) Log.d(TAG, String.format("<%s>", TAG_ROW)); + if (keys != null) + startRow(row); + parseRowContent(parser, row, keys); + } else if (TAG_INCLUDE.equals(tag)) { + parseIncludeKeyboardContent(parser, keys); + } else if (TAG_SWITCH.equals(tag)) { + parseSwitchKeyboardContent(parser, keys); + } else if (TAG_KEY_STYLE.equals(tag)) { + parseKeyStyle(parser, keys); + } else { + throw new IllegalStartTag(parser, TAG_ROW); + } + } else if (event == XmlPullParser.END_TAG) { + final String tag = parser.getName(); + if (TAG_KEYBOARD.equals(tag)) { + endKeyboard(mKeyboard.getVerticalGap()); + break; + } else if (TAG_CASE.equals(tag) || TAG_DEFAULT.equals(tag) + || TAG_MERGE.equals(tag)) { + if (DEBUG) Log.d(TAG, String.format("", tag)); + break; + } else if (TAG_KEY_STYLE.equals(tag)) { + continue; + } else { + throw new IllegalEndTag(parser, TAG_ROW); + } + } + } + } + + private void parseRowContent(XmlResourceParser parser, Row row, List keys) + throws XmlPullParserException, IOException { + int event; + while ((event = parser.next()) != XmlPullParser.END_DOCUMENT) { + if (event == XmlPullParser.START_TAG) { + final String tag = parser.getName(); + if (TAG_KEY.equals(tag)) { + parseKey(parser, row, keys); + } else if (TAG_SPACER.equals(tag)) { + parseSpacer(parser, row, keys); + } else if (TAG_INCLUDE.equals(tag)) { + parseIncludeRowContent(parser, row, keys); + } else if (TAG_SWITCH.equals(tag)) { + parseSwitchRowContent(parser, row, keys); + } else if (TAG_KEY_STYLE.equals(tag)) { + parseKeyStyle(parser, keys); + } else { + throw new IllegalStartTag(parser, TAG_KEY); + } + } else if (event == XmlPullParser.END_TAG) { + final String tag = parser.getName(); + if (TAG_ROW.equals(tag)) { + if (DEBUG) Log.d(TAG, String.format("", TAG_ROW)); + if (keys != null) + endRow(); + break; + } else if (TAG_CASE.equals(tag) || TAG_DEFAULT.equals(tag) + || TAG_MERGE.equals(tag)) { + if (DEBUG) Log.d(TAG, String.format("", tag)); + break; + } else if (TAG_KEY_STYLE.equals(tag)) { + continue; + } else { + throw new IllegalEndTag(parser, TAG_KEY); + } + } + } + } + + private void parseKey(XmlResourceParser parser, Row row, List keys) + throws XmlPullParserException, IOException { + if (keys == null) { + checkEndTag(TAG_KEY, parser); + } else { + Key key = new Key(mResources, row, mCurrentX, mCurrentY, parser, mKeyStyles); + if (DEBUG) Log.d(TAG, String.format("<%s%s keyLabel=%s code=%d popupCharacters=%s />", + TAG_KEY, (key.mEnabled ? "" : " disabled"), key.mLabel, key.mCode, + Arrays.toString(key.mPopupCharacters))); + checkEndTag(TAG_KEY, parser); + keys.add(key); + if (key.mCode == Keyboard.CODE_SHIFT) + mKeyboard.getShiftKeys().add(key); + endKey(key); + } + } + + private void parseSpacer(XmlResourceParser parser, Row row, List keys) + throws XmlPullParserException, IOException { + if (keys == null) { + checkEndTag(TAG_SPACER, parser); + } else { + if (DEBUG) Log.d(TAG, String.format("<%s />", TAG_SPACER)); + final TypedArray keyboardAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser), + R.styleable.Keyboard); + if (keyboardAttr.hasValue(R.styleable.Keyboard_horizontalGap)) + throw new IllegalAttribute(parser, "horizontalGap"); + final int defaultWidth = (row != null) ? row.mDefaultWidth : 0; + final int keyWidth = getDimensionOrFraction(keyboardAttr, R.styleable.Keyboard_keyWidth, + mKeyboard.getDisplayWidth(), defaultWidth); + keyboardAttr.recycle(); + + final TypedArray keyAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser), + R.styleable.Keyboard_Key); + int keyXPos = KeyboardParser.getDimensionOrFraction(keyAttr, + R.styleable.Keyboard_Key_keyXPos, mKeyboard.getDisplayWidth(), mCurrentX); + if (keyXPos < 0) { + // If keyXPos is negative, the actual x-coordinate will be display_width + keyXPos. + keyXPos += mKeyboard.getDisplayWidth(); + } + + checkEndTag(TAG_SPACER, parser); + setSpacer(keyXPos, keyWidth); + } + } + + private void parseIncludeKeyboardContent(XmlResourceParser parser, List keys) + throws XmlPullParserException, IOException { + parseIncludeInternal(parser, null, keys); + } + + private void parseIncludeRowContent(XmlResourceParser parser, Row row, List keys) + throws XmlPullParserException, IOException { + parseIncludeInternal(parser, row, keys); + } + + private void parseIncludeInternal(XmlResourceParser parser, Row row, List keys) + throws XmlPullParserException, IOException { + if (keys == null) { + checkEndTag(TAG_INCLUDE, parser); + } else { + final TypedArray a = mResources.obtainAttributes(Xml.asAttributeSet(parser), + R.styleable.Keyboard_Include); + final int keyboardLayout = a.getResourceId( + R.styleable.Keyboard_Include_keyboardLayout, 0); + a.recycle(); + + checkEndTag(TAG_INCLUDE, parser); + if (keyboardLayout == 0) + throw new ParseException("No keyboardLayout attribute in ", parser); + if (DEBUG) Log.d(TAG, String.format("<%s keyboardLayout=%s />", + TAG_INCLUDE, mResources.getResourceEntryName(keyboardLayout))); + parseMerge(mResources.getLayout(keyboardLayout), row, keys); + } + } + + private void parseMerge(XmlResourceParser parser, Row row, List keys) + throws XmlPullParserException, IOException { + int event; + while ((event = parser.next()) != XmlPullParser.END_DOCUMENT) { + if (event == XmlPullParser.START_TAG) { + final String tag = parser.getName(); + if (TAG_MERGE.equals(tag)) { + if (row == null) { + parseKeyboardContent(parser, keys); + } else { + parseRowContent(parser, row, keys); + } + break; + } else { + throw new ParseException( + "Included keyboard layout must have root element", parser); + } + } + } + } + + private void parseSwitchKeyboardContent(XmlResourceParser parser, List keys) + throws XmlPullParserException, IOException { + parseSwitchInternal(parser, null, keys); + } + + private void parseSwitchRowContent(XmlResourceParser parser, Row row, List keys) + throws XmlPullParserException, IOException { + parseSwitchInternal(parser, row, keys); + } + + private void parseSwitchInternal(XmlResourceParser parser, Row row, List keys) + throws XmlPullParserException, IOException { + if (DEBUG) Log.d(TAG, String.format("<%s> %s", TAG_SWITCH, mKeyboard.mId)); + boolean selected = false; + int event; + while ((event = parser.next()) != XmlPullParser.END_DOCUMENT) { + if (event == XmlPullParser.START_TAG) { + final String tag = parser.getName(); + if (TAG_CASE.equals(tag)) { + selected |= parseCase(parser, row, selected ? null : keys); + } else if (TAG_DEFAULT.equals(tag)) { + selected |= parseDefault(parser, row, selected ? null : keys); + } else { + throw new IllegalStartTag(parser, TAG_KEY); + } + } else if (event == XmlPullParser.END_TAG) { + final String tag = parser.getName(); + if (TAG_SWITCH.equals(tag)) { + if (DEBUG) Log.d(TAG, String.format("", TAG_SWITCH)); + break; + } else { + throw new IllegalEndTag(parser, TAG_KEY); + } + } + } + } + + private boolean parseCase(XmlResourceParser parser, Row row, List keys) + throws XmlPullParserException, IOException { + final boolean selected = parseCaseCondition(parser); + if (row == null) { + // Processing Rows. + parseKeyboardContent(parser, selected ? keys : null); + } else { + // Processing Keys. + parseRowContent(parser, row, selected ? keys : null); + } + return selected; + } + + private boolean parseCaseCondition(XmlResourceParser parser) { + final KeyboardId id = mKeyboard.mId; + if (id == null) + return true; + + final TypedArray a = mResources.obtainAttributes(Xml.asAttributeSet(parser), + R.styleable.Keyboard_Case); + final TypedArray viewAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser), + R.styleable.KeyboardView); + try { + final boolean modeMatched = matchTypedValue(a, + R.styleable.Keyboard_Case_mode, id.mMode, KeyboardId.modeName(id.mMode)); + final boolean navigateActionMatched = matchBoolean(a, + R.styleable.Keyboard_Case_navigateAction, id.mNavigateAction); + final boolean passwordInputMatched = matchBoolean(a, + R.styleable.Keyboard_Case_passwordInput, id.mPasswordInput); + final boolean settingsKeyMatched = matchBoolean(a, + R.styleable.Keyboard_Case_hasSettingsKey, id.mHasSettingsKey); + final boolean voiceEnabledMatched = matchBoolean(a, + R.styleable.Keyboard_Case_voiceKeyEnabled, id.mVoiceKeyEnabled); + final boolean voiceKeyMatched = matchBoolean(a, + R.styleable.Keyboard_Case_hasVoiceKey, id.mHasVoiceKey); + final boolean colorSchemeMatched = matchInteger(viewAttr, + R.styleable.KeyboardView_colorScheme, id.mColorScheme); + // As noted at {@link KeyboardId} class, we are interested only in enum value masked by + // {@link android.view.inputmethod.EditorInfo#IME_MASK_ACTION} and + // {@link android.view.inputmethod.EditorInfo#IME_FLAG_NO_ENTER_ACTION}. So matching + // this attribute with id.mImeOptions as integer value is enough for our purpose. + final boolean imeActionMatched = matchInteger(a, + R.styleable.Keyboard_Case_imeAction, id.mImeAction); + final boolean localeCodeMatched = matchString(a, + R.styleable.Keyboard_Case_localeCode, id.mLocale.toString()); + final boolean languageCodeMatched = matchString(a, + R.styleable.Keyboard_Case_languageCode, id.mLocale.getLanguage()); + final boolean countryCodeMatched = matchString(a, + R.styleable.Keyboard_Case_countryCode, id.mLocale.getCountry()); + final boolean selected = modeMatched && navigateActionMatched && passwordInputMatched + && settingsKeyMatched && voiceEnabledMatched && voiceKeyMatched + && colorSchemeMatched && imeActionMatched && localeCodeMatched + && languageCodeMatched && countryCodeMatched; + + if (DEBUG) Log.d(TAG, String.format("<%s%s%s%s%s%s%s%s%s%s%s%s> %s", TAG_CASE, + textAttr(a.getString(R.styleable.Keyboard_Case_mode), "mode"), + textAttr(KeyboardId.colorSchemeName( + viewAttr.getInt( + R.styleable.KeyboardView_colorScheme, -1)), "colorScheme"), + booleanAttr(a, R.styleable.Keyboard_Case_navigateAction, "navigateAction"), + booleanAttr(a, R.styleable.Keyboard_Case_passwordInput, "passwordInput"), + booleanAttr(a, R.styleable.Keyboard_Case_hasSettingsKey, "hasSettingsKey"), + booleanAttr(a, R.styleable.Keyboard_Case_voiceKeyEnabled, "voiceKeyEnabled"), + booleanAttr(a, R.styleable.Keyboard_Case_hasVoiceKey, "hasVoiceKey"), + textAttr(EditorInfoCompatUtils.imeOptionsName( + a.getInt(R.styleable.Keyboard_Case_imeAction, -1)), "imeAction"), + textAttr(a.getString(R.styleable.Keyboard_Case_localeCode), "localeCode"), + textAttr(a.getString(R.styleable.Keyboard_Case_languageCode), "languageCode"), + textAttr(a.getString(R.styleable.Keyboard_Case_countryCode), "countryCode"), + Boolean.toString(selected))); + + return selected; + } finally { + a.recycle(); + viewAttr.recycle(); + } + } + + private static boolean matchInteger(TypedArray a, int index, int value) { + // If does not have "index" attribute, that means this is wild-card for the + // attribute. + return !a.hasValue(index) || a.getInt(index, 0) == value; + } + + private static boolean matchBoolean(TypedArray a, int index, boolean value) { + // If does not have "index" attribute, that means this is wild-card for the + // attribute. + return !a.hasValue(index) || a.getBoolean(index, false) == value; + } + + private static boolean matchString(TypedArray a, int index, String value) { + // If does not have "index" attribute, that means this is wild-card for the + // attribute. + return !a.hasValue(index) || stringArrayContains(a.getString(index).split("\\|"), value); + } + + private static boolean matchTypedValue(TypedArray a, int index, int intValue, String strValue) { + // If does not have "index" attribute, that means this is wild-card for the + // attribute. + final TypedValue v = a.peekValue(index); + if (v == null) + return true; + + if (isIntegerValue(v)) { + return intValue == a.getInt(index, 0); + } else if (isStringValue(v)) { + return stringArrayContains(a.getString(index).split("\\|"), strValue); + } + return false; + } + + private static boolean stringArrayContains(String[] array, String value) { + for (final String elem : array) { + if (elem.equals(value)) + return true; + } + return false; + } + + private boolean parseDefault(XmlResourceParser parser, Row row, List keys) + throws XmlPullParserException, IOException { + if (DEBUG) Log.d(TAG, String.format("<%s>", TAG_DEFAULT)); + if (row == null) { + parseKeyboardContent(parser, keys); + } else { + parseRowContent(parser, row, keys); + } + return true; + } + + private void parseKeyStyle(XmlResourceParser parser, List keys) { + TypedArray keyStyleAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser), + R.styleable.Keyboard_KeyStyle); + TypedArray keyAttrs = mResources.obtainAttributes(Xml.asAttributeSet(parser), + R.styleable.Keyboard_Key); + try { + if (!keyStyleAttr.hasValue(R.styleable.Keyboard_KeyStyle_styleName)) + throw new ParseException("<" + TAG_KEY_STYLE + + "/> needs styleName attribute", parser); + if (keys != null) + mKeyStyles.parseKeyStyleAttributes(keyStyleAttr, keyAttrs, parser); + } finally { + keyStyleAttr.recycle(); + keyAttrs.recycle(); + } + } + + private static void checkEndTag(String tag, XmlResourceParser parser) + throws XmlPullParserException, IOException { + if (parser.next() == XmlPullParser.END_TAG && tag.equals(parser.getName())) + return; + throw new NonEmptyTag(tag, parser); + } + + private void startKeyboard() { + mCurrentY += (int)mResources.getDimension(R.dimen.keyboard_top_padding); + } + + private void startRow(Row row) { + mCurrentX = 0; + setSpacer(mCurrentX, mHorizontalEdgesPadding); + mCurrentRow = row; + } + + private void endRow() { + if (mCurrentRow == null) + throw new InflateException("orphant end row tag"); + setSpacer(mCurrentX, mHorizontalEdgesPadding); + if (mCurrentX > mMaxRowWidth) + mMaxRowWidth = mCurrentX; + mCurrentY += mCurrentRow.mDefaultHeight; + mCurrentRow = null; + } + + private void endKey(Key key) { + mCurrentX = key.mX - key.mGap / 2 + key.mWidth + key.mGap; + } + + private void endKeyboard(int defaultVerticalGap) { + mCurrentY += (int)mResources.getDimension(R.dimen.keyboard_bottom_padding); + mTotalHeight = mCurrentY - defaultVerticalGap; + } + + private void setSpacer(int keyXPos, int width) { + mCurrentX = keyXPos + width; + } + + public static int getDimensionOrFraction(TypedArray a, int index, int base, int defValue) { + final TypedValue value = a.peekValue(index); + if (value == null) + return defValue; + if (isFractionValue(value)) { + // Round it to avoid values like 47.9999 from getting truncated + return Math.round(a.getFraction(index, base, base, defValue)); + } else if (isDimensionValue(value)) { + return a.getDimensionPixelOffset(index, defValue); + } else if (isIntegerValue(value)) { + // For enum value. + return a.getInt(index, defValue); + } + return defValue; + } + + private static boolean isFractionValue(TypedValue v) { + return v.type == TypedValue.TYPE_FRACTION; + } + + private static boolean isDimensionValue(TypedValue v) { + return v.type == TypedValue.TYPE_DIMENSION; + } + + private static boolean isIntegerValue(TypedValue v) { + return v.type >= TypedValue.TYPE_FIRST_INT && v.type <= TypedValue.TYPE_LAST_INT; + } + + private static boolean isStringValue(TypedValue v) { + return v.type == TypedValue.TYPE_STRING; + } + + @SuppressWarnings("serial") + public static class ParseException extends InflateException { + public ParseException(String msg, XmlResourceParser parser) { + super(msg + " at line " + parser.getLineNumber()); + } + } + + @SuppressWarnings("serial") + private static class IllegalStartTag extends ParseException { + public IllegalStartTag(XmlResourceParser parser, String parent) { + super("Illegal start tag " + parser.getName() + " in " + parent, parser); + } + } + + @SuppressWarnings("serial") + private static class IllegalEndTag extends ParseException { + public IllegalEndTag(XmlResourceParser parser, String parent) { + super("Illegal end tag " + parser.getName() + " in " + parent, parser); + } + } + + @SuppressWarnings("serial") + private static class IllegalAttribute extends ParseException { + public IllegalAttribute(XmlResourceParser parser, String attribute) { + super("Tag " + parser.getName() + " has illegal attribute " + attribute, parser); + } + } + + @SuppressWarnings("serial") + private static class NonEmptyTag extends ParseException { + public NonEmptyTag(String tag, XmlResourceParser parser) { + super(tag + " must be empty tag", parser); + } + } + + private static String textAttr(String value, String name) { + return value != null ? String.format(" %s=%s", name, value) : ""; + } + + private static String booleanAttr(TypedArray a, int index, String name) { + return a.hasValue(index) ? String.format(" %s=%s", name, a.getBoolean(index, false)) : ""; + } +} diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardShiftState.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardShiftState.java new file mode 100644 index 000000000..0cde4e5b5 --- /dev/null +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardShiftState.java @@ -0,0 +1,135 @@ +/* + * 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.util.Log; + +import com.android.inputmethod.keyboard.KeyboardSwitcher; + +public class KeyboardShiftState { + private static final String TAG = "KeyboardShiftState"; + private static final boolean DEBUG = KeyboardSwitcher.DEBUG_STATE; + + private static final int NORMAL = 0; + private static final int MANUAL_SHIFTED = 1; + private static final int MANUAL_SHIFTED_FROM_AUTO = 2; + private static final int AUTO_SHIFTED = 3; + private static final int SHIFT_LOCKED = 4; + private static final int SHIFT_LOCK_SHIFTED = 5; + + private int mState = NORMAL; + + public boolean setShifted(boolean newShiftState) { + final int oldState = mState; + if (newShiftState) { + switch (oldState) { + case NORMAL: + mState = MANUAL_SHIFTED; + break; + case AUTO_SHIFTED: + mState = MANUAL_SHIFTED_FROM_AUTO; + break; + case SHIFT_LOCKED: + mState = SHIFT_LOCK_SHIFTED; + break; + } + } else { + switch (oldState) { + case MANUAL_SHIFTED: + case MANUAL_SHIFTED_FROM_AUTO: + case AUTO_SHIFTED: + mState = NORMAL; + break; + case SHIFT_LOCK_SHIFTED: + mState = SHIFT_LOCKED; + break; + } + } + if (DEBUG) + Log.d(TAG, "setShifted(" + newShiftState + "): " + toString(oldState) + " > " + this); + return mState != oldState; + } + + public void setShiftLocked(boolean newShiftLockState) { + final int oldState = mState; + if (newShiftLockState) { + switch (oldState) { + case NORMAL: + case MANUAL_SHIFTED: + case MANUAL_SHIFTED_FROM_AUTO: + case AUTO_SHIFTED: + mState = SHIFT_LOCKED; + break; + } + } else { + switch (oldState) { + case SHIFT_LOCKED: + case SHIFT_LOCK_SHIFTED: + mState = NORMAL; + break; + } + } + if (DEBUG) + Log.d(TAG, "setShiftLocked(" + newShiftLockState + "): " + toString(oldState) + + " > " + this); + } + + public void setAutomaticTemporaryUpperCase() { + final int oldState = mState; + mState = AUTO_SHIFTED; + if (DEBUG) + Log.d(TAG, "setAutomaticTemporaryUpperCase: " + toString(oldState) + " > " + this); + } + + public boolean isShiftedOrShiftLocked() { + return mState != NORMAL; + } + + public boolean isShiftLocked() { + return mState == SHIFT_LOCKED || mState == SHIFT_LOCK_SHIFTED; + } + + public boolean isAutomaticTemporaryUpperCase() { + return mState == AUTO_SHIFTED; + } + + public boolean isManualTemporaryUpperCase() { + return mState == MANUAL_SHIFTED || mState == MANUAL_SHIFTED_FROM_AUTO + || mState == SHIFT_LOCK_SHIFTED; + } + + public boolean isManualTemporaryUpperCaseFromAuto() { + return mState == MANUAL_SHIFTED_FROM_AUTO; + } + + @Override + public String toString() { + return toString(mState); + } + + private static String toString(int state) { + switch (state) { + case NORMAL: return "NORMAL"; + case MANUAL_SHIFTED: return "MANUAL_SHIFTED"; + case MANUAL_SHIFTED_FROM_AUTO: return "MANUAL_SHIFTED_FROM_AUTO"; + case AUTO_SHIFTED: return "AUTO_SHIFTED"; + case SHIFT_LOCKED: return "SHIFT_LOCKED"; + case SHIFT_LOCK_SHIFTED: return "SHIFT_LOCK_SHIFTED"; + default: return "UKNOWN"; + } + } +} diff --git a/java/src/com/android/inputmethod/keyboard/internal/MiniKeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/internal/MiniKeyboardBuilder.java new file mode 100644 index 000000000..7eb3e4623 --- /dev/null +++ b/java/src/com/android/inputmethod/keyboard/internal/MiniKeyboardBuilder.java @@ -0,0 +1,249 @@ +/* + * 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 com.android.inputmethod.keyboard.Keyboard; +import com.android.inputmethod.keyboard.KeyboardView; +import com.android.inputmethod.keyboard.MiniKeyboard; +import com.android.inputmethod.latin.R; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Paint; +import android.graphics.Rect; + +import java.util.List; + +public class MiniKeyboardBuilder { + private final Resources mRes; + private final MiniKeyboard mKeyboard; + private final CharSequence[] mPopupCharacters; + private final MiniKeyboardLayoutParams mParams; + + /* package */ static class MiniKeyboardLayoutParams { + public final int mKeyWidth; + public final int mRowHeight; + /* package */ final int mTopRowAdjustment; + public final int mNumRows; + public final int mNumColumns; + public final int mLeftKeys; + public final int mRightKeys; // includes default key. + + /** + * The object holding mini keyboard layout parameters. + * + * @param numKeys number of keys in this mini keyboard. + * @param maxColumns number of maximum columns of this mini keyboard. + * @param keyWidth mini keyboard key width in pixel, including horizontal gap. + * @param rowHeight mini keyboard row height in pixel, including vertical gap. + * @param coordXInParent coordinate x of the popup key in parent keyboard. + * @param parentKeyboardWidth parent keyboard width in pixel. + */ + public MiniKeyboardLayoutParams(int numKeys, int maxColumns, int keyWidth, int rowHeight, + int coordXInParent, int parentKeyboardWidth) { + if (parentKeyboardWidth / keyWidth < maxColumns) + throw new IllegalArgumentException("Keyboard is too small to hold mini keyboard: " + + parentKeyboardWidth + " " + keyWidth + " " + maxColumns); + mKeyWidth = keyWidth; + mRowHeight = 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; + } + } + + // 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 * mKeyWidth; + } + + public int getX(int n, int row) { + final int x = getColumnPos(n) * mKeyWidth + getDefaultKeyCoordX(); + if (isTopRow(row)) { + return x + mTopRowAdjustment * (mKeyWidth / 2); + } + return x; + } + + public int getY(int row) { + return (mNumRows - 1 - row) * mRowHeight; + } + + public int getRowFlags(int row) { + int rowFlags = 0; + if (row == 0) rowFlags |= Keyboard.EDGE_TOP; + if (isTopRow(row)) rowFlags |= Keyboard.EDGE_BOTTOM; + return rowFlags; + } + + private boolean isTopRow(int rowCount) { + return rowCount == mNumRows - 1; + } + } + + public MiniKeyboardBuilder(KeyboardView view, int layoutTemplateResId, Key parentKey, + Keyboard parentKeyboard) { + final Context context = view.getContext(); + mRes = context.getResources(); + final MiniKeyboard keyboard = new MiniKeyboard( + context, layoutTemplateResId, parentKeyboard); + mKeyboard = keyboard; + mPopupCharacters = parentKey.mPopupCharacters; + + final int keyWidth = getMaxKeyWidth(view, mPopupCharacters, keyboard.getKeyWidth()); + final MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams( + mPopupCharacters.length, parentKey.mMaxPopupColumn, + keyWidth, parentKeyboard.getRowHeight(), + parentKey.mX + (parentKey.mWidth + parentKey.mGap) / 2 - keyWidth / 2, + view.getMeasuredWidth()); + mParams = params; + + keyboard.setRowHeight(params.mRowHeight); + keyboard.setHeight(params.mNumRows * params.mRowHeight); + keyboard.setMinWidth(params.mNumColumns * params.mKeyWidth); + keyboard.setDefaultCoordX(params.getDefaultKeyCoordX() + params.mKeyWidth / 2); + } + + 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.getLabelSizeAndSetPaint(label, 0, 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); + } + + public MiniKeyboard build() { + final MiniKeyboard keyboard = mKeyboard; + final List keys = keyboard.getKeys(); + final MiniKeyboardLayoutParams params = mParams; + for (int n = 0; n < mPopupCharacters.length; n++) { + final CharSequence label = mPopupCharacters[n]; + final int row = n / params.mNumColumns; + final Key key = new Key(mRes, keyboard, label, params.getX(n, row), params.getY(row), + params.mKeyWidth, params.mRowHeight, params.getRowFlags(row)); + keys.add(key); + } + return keyboard; + } +} diff --git a/java/src/com/android/inputmethod/keyboard/internal/ModifierKeyState.java b/java/src/com/android/inputmethod/keyboard/internal/ModifierKeyState.java new file mode 100644 index 000000000..dae73c4e4 --- /dev/null +++ b/java/src/com/android/inputmethod/keyboard/internal/ModifierKeyState.java @@ -0,0 +1,85 @@ +/* + * 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.util.Log; + +import com.android.inputmethod.keyboard.KeyboardSwitcher; + +public class ModifierKeyState { + protected static final String TAG = "ModifierKeyState"; + protected static final boolean DEBUG = KeyboardSwitcher.DEBUG_STATE; + + protected static final int RELEASING = 0; + protected static final int PRESSING = 1; + protected static final int MOMENTARY = 2; + + protected final String mName; + protected int mState = RELEASING; + + public ModifierKeyState(String name) { + mName = name; + } + + public void onPress() { + final int oldState = mState; + mState = PRESSING; + if (DEBUG) + Log.d(TAG, mName + ".onPress: " + toString(oldState) + " > " + this); + } + + public void onRelease() { + final int oldState = mState; + mState = RELEASING; + if (DEBUG) + Log.d(TAG, mName + ".onRelease: " + toString(oldState) + " > " + this); + } + + public void onOtherKeyPressed() { + final int oldState = mState; + if (oldState == PRESSING) + mState = MOMENTARY; + if (DEBUG) + Log.d(TAG, mName + ".onOtherKeyPressed: " + toString(oldState) + " > " + this); + } + + public boolean isPressing() { + return mState == PRESSING; + } + + public boolean isReleasing() { + return mState == RELEASING; + } + + public boolean isMomentary() { + return mState == MOMENTARY; + } + + @Override + public String toString() { + return toString(mState); + } + + protected String toString(int state) { + switch (state) { + case RELEASING: return "RELEASING"; + case PRESSING: return "PRESSING"; + case MOMENTARY: return "MOMENTARY"; + default: return "UNKNOWN"; + } + } +} diff --git a/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerKeyState.java b/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerKeyState.java new file mode 100644 index 000000000..ddadb1338 --- /dev/null +++ b/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerKeyState.java @@ -0,0 +1,101 @@ +/* + * 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 com.android.inputmethod.keyboard.KeyDetector; +import com.android.inputmethod.keyboard.PointerTracker; + +/** + * This class keeps track of a key index and a position where {@link PointerTracker} is. + */ +public class PointerTrackerKeyState { + private final KeyDetector mKeyDetector; + + // The position and time at which first down event occurred. + private long mDownTime; + private long mUpTime; + + // The current key index where this pointer is. + private int mKeyIndex = KeyDetector.NOT_A_KEY; + // The position where mKeyIndex was recognized for the first time. + private int mKeyX; + private int mKeyY; + + // Last pointer position. + private int mLastX; + private int mLastY; + + public PointerTrackerKeyState(KeyDetector keyDetecor) { + mKeyDetector = keyDetecor; + } + + public int getKeyIndex() { + return mKeyIndex; + } + + public int getKeyX() { + return mKeyX; + } + + public int getKeyY() { + return mKeyY; + } + + public long getDownTime() { + return mDownTime; + } + + public long getUpTime() { + return mUpTime; + } + + public int getLastX() { + return mLastX; + } + + public int getLastY() { + return mLastY; + } + + public int onDownKey(int x, int y, long eventTime) { + mDownTime = eventTime; + return onMoveToNewKey(onMoveKeyInternal(x, y), x, y); + } + + private int onMoveKeyInternal(int x, int y) { + mLastX = x; + mLastY = y; + return mKeyDetector.getKeyIndexAndNearbyCodes(x, y, null); + } + + public int onMoveKey(int x, int y) { + return onMoveKeyInternal(x, y); + } + + public int onMoveToNewKey(int keyIndex, int x, int y) { + mKeyIndex = keyIndex; + mKeyX = x; + mKeyY = y; + return keyIndex; + } + + public int onUpKey(int x, int y, long eventTime) { + mUpTime = eventTime; + mKeyIndex = KeyDetector.NOT_A_KEY; + return onMoveKeyInternal(x, y); + } +} diff --git a/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerQueue.java b/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerQueue.java new file mode 100644 index 000000000..f87cd869e --- /dev/null +++ b/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerQueue.java @@ -0,0 +1,85 @@ +/* + * 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 com.android.inputmethod.keyboard.PointerTracker; + +import java.util.LinkedList; + +public class PointerTrackerQueue { + private LinkedList mQueue = new LinkedList(); + + public void add(PointerTracker tracker) { + mQueue.add(tracker); + } + + public void releaseAllPointersOlderThan(PointerTracker tracker, long eventTime) { + if (mQueue.lastIndexOf(tracker) < 0) { + return; + } + final LinkedList queue = mQueue; + int oldestPos = 0; + for (PointerTracker t = queue.get(oldestPos); t != tracker; t = queue.get(oldestPos)) { + if (t.isModifier()) { + oldestPos++; + } else { + t.onPhantomUpEvent(t.getLastX(), t.getLastY(), eventTime, true); + queue.remove(oldestPos); + } + } + } + + public void releaseAllPointers(long eventTime) { + releaseAllPointersExcept(null, eventTime, true); + } + + public void releaseAllPointersExcept(PointerTracker tracker, long eventTime, + boolean updateReleasedKeyGraphics) { + for (PointerTracker t : mQueue) { + if (t == tracker) + continue; + t.onPhantomUpEvent(t.getLastX(), t.getLastY(), eventTime, updateReleasedKeyGraphics); + } + mQueue.clear(); + if (tracker != null) + mQueue.add(tracker); + } + + public void remove(PointerTracker tracker) { + mQueue.remove(tracker); + } + + public boolean isInSlidingKeyInput() { + for (final PointerTracker tracker : mQueue) { + if (tracker.isInSlidingKeyInput()) + return true; + } + return false; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("["); + for (PointerTracker tracker : mQueue) { + if (sb.length() > 1) + sb.append(" "); + sb.append(String.format("%d", tracker.mPointerId)); + } + sb.append("]"); + return sb.toString(); + } +} diff --git a/java/src/com/android/inputmethod/keyboard/internal/PopupCharactersParser.java b/java/src/com/android/inputmethod/keyboard/internal/PopupCharactersParser.java new file mode 100644 index 000000000..3b9a08322 --- /dev/null +++ b/java/src/com/android/inputmethod/keyboard/internal/PopupCharactersParser.java @@ -0,0 +1,177 @@ +/* + * 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 com.android.inputmethod.keyboard.Keyboard; +import com.android.inputmethod.latin.R; + +import android.content.res.Resources; +import android.graphics.drawable.Drawable; +import android.text.TextUtils; + +/** + * String parser of popupCharacters attribute of Key. + * The string is comma separated texts each of which represents one popup key. + * Each popup key text is one of the following: + * - A single letter (Letter) + * - Label optionally followed by keyOutputText or code (keyLabel|keyOutputText). + * - Icon followed by keyOutputText or code (@drawable/icon|@integer/key_code) + * Special character, comma ',' backslash '\', and bar '|' can be escaped by '\' + * character. + * Note that the character '@' and '\' are also parsed by XML parser and CSV parser as well. + */ +public class PopupCharactersParser { + private static final char ESCAPE = '\\'; + private static final String LABEL_END = "|"; + private static final String PREFIX_AT = "@"; + private static final String PREFIX_ICON = PREFIX_AT + "drawable/"; + private static final String PREFIX_CODE = PREFIX_AT + "integer/"; + + private PopupCharactersParser() { + // Intentional empty constructor for utility class. + } + + private static boolean hasIcon(String popupSpec) { + if (popupSpec.startsWith(PREFIX_ICON)) { + final int end = indexOfLabelEnd(popupSpec, 0); + if (end > 0) + return true; + throw new PopupCharactersParserError("outputText or code not specified: " + popupSpec); + } + return false; + } + + private static boolean hasCode(String popupSpec) { + final int end = indexOfLabelEnd(popupSpec, 0); + if (end > 0 && end + 1 < popupSpec.length() + && popupSpec.substring(end + 1).startsWith(PREFIX_CODE)) { + return true; + } + return false; + } + + private static String parseEscape(String text) { + if (text.indexOf(ESCAPE) < 0) + return text; + final int length = text.length(); + final StringBuilder sb = new StringBuilder(); + for (int pos = 0; pos < length; pos++) { + final char c = text.charAt(pos); + if (c == ESCAPE && pos + 1 < length) { + sb.append(text.charAt(++pos)); + } else { + sb.append(c); + } + } + return sb.toString(); + } + + private static int indexOfLabelEnd(String popupSpec, int start) { + if (popupSpec.indexOf(ESCAPE, start) < 0) { + final int end = popupSpec.indexOf(LABEL_END, start); + if (end == 0) + throw new PopupCharactersParserError(LABEL_END + " at " + start + ": " + popupSpec); + return end; + } + final int length = popupSpec.length(); + for (int pos = start; pos < length; pos++) { + final char c = popupSpec.charAt(pos); + if (c == ESCAPE && pos + 1 < length) { + pos++; + } else if (popupSpec.startsWith(LABEL_END, pos)) { + return pos; + } + } + return -1; + } + + public static String getLabel(String popupSpec) { + if (hasIcon(popupSpec)) + return null; + final int end = indexOfLabelEnd(popupSpec, 0); + final String label = (end > 0) ? parseEscape(popupSpec.substring(0, end)) + : parseEscape(popupSpec); + if (TextUtils.isEmpty(label)) + throw new PopupCharactersParserError("Empty label: " + popupSpec); + return label; + } + + public static String getOutputText(String popupSpec) { + if (hasCode(popupSpec)) + return null; + final int end = indexOfLabelEnd(popupSpec, 0); + if (end > 0) { + if (indexOfLabelEnd(popupSpec, end + 1) >= 0) + throw new PopupCharactersParserError("Multiple " + LABEL_END + ": " + + popupSpec); + final String outputText = parseEscape(popupSpec.substring(end + LABEL_END.length())); + if (!TextUtils.isEmpty(outputText)) + return outputText; + throw new PopupCharactersParserError("Empty outputText: " + popupSpec); + } + final String label = getLabel(popupSpec); + if (label == null) + throw new PopupCharactersParserError("Empty label: " + popupSpec); + // Code is automatically generated for one letter label. See {@link getCode()}. + if (label.length() == 1) + return null; + return label; + } + + public static int getCode(Resources res, String popupSpec) { + if (hasCode(popupSpec)) { + final int end = indexOfLabelEnd(popupSpec, 0); + if (indexOfLabelEnd(popupSpec, end + 1) >= 0) + throw new PopupCharactersParserError("Multiple " + LABEL_END + ": " + popupSpec); + final int resId = getResourceId(res, + popupSpec.substring(end + LABEL_END.length() + PREFIX_AT.length())); + final int code = res.getInteger(resId); + return code; + } + if (indexOfLabelEnd(popupSpec, 0) > 0) + return Keyboard.CODE_DUMMY; + final String label = getLabel(popupSpec); + // Code is automatically generated for one letter label. + if (label != null && label.length() == 1) + return label.charAt(0); + return Keyboard.CODE_DUMMY; + } + + public static Drawable getIcon(Resources res, String popupSpec) { + if (hasIcon(popupSpec)) { + int end = popupSpec.indexOf(LABEL_END, PREFIX_ICON.length() + 1); + int resId = getResourceId(res, popupSpec.substring(PREFIX_AT.length(), end)); + return res.getDrawable(resId); + } + return null; + } + + private static int getResourceId(Resources res, String name) { + String packageName = res.getResourcePackageName(R.string.english_ime_name); + int resId = res.getIdentifier(name, null, packageName); + if (resId == 0) + throw new PopupCharactersParserError("Unknown resource: " + name); + return resId; + } + + @SuppressWarnings("serial") + public static class PopupCharactersParserError extends RuntimeException { + public PopupCharactersParserError(String message) { + super(message); + } + } +} diff --git a/java/src/com/android/inputmethod/keyboard/internal/Row.java b/java/src/com/android/inputmethod/keyboard/internal/Row.java new file mode 100644 index 000000000..99d69ea76 --- /dev/null +++ b/java/src/com/android/inputmethod/keyboard/internal/Row.java @@ -0,0 +1,73 @@ +/* + * 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 com.android.inputmethod.keyboard.Keyboard; +import com.android.inputmethod.latin.R; + +import android.content.res.Resources; +import android.content.res.TypedArray; +import android.content.res.XmlResourceParser; +import android.util.Xml; + +/** + * Container for keys in the keyboard. All keys in a row are at the same Y-coordinate. + * Some of the key size defaults can be overridden per row from what the {@link Keyboard} + * defines. + */ +public class Row { + /** Default width of a key in this row. */ + public final int mDefaultWidth; + /** Default height of a key in this row. */ + public final int mDefaultHeight; + /** Default horizontal gap between keys in this row. */ + public final int mDefaultHorizontalGap; + /** Vertical gap following this row. */ + public final int mVerticalGap; + /** + * Edge flags for this row of keys. Possible values that can be assigned are + * {@link Keyboard#EDGE_TOP EDGE_TOP} and {@link Keyboard#EDGE_BOTTOM EDGE_BOTTOM} + */ + public final int mRowEdgeFlags; + + private final Keyboard mKeyboard; + + public Row(Resources res, Keyboard keyboard, XmlResourceParser parser) { + this.mKeyboard = keyboard; + final int keyboardWidth = keyboard.getDisplayWidth(); + final int keyboardHeight = keyboard.getKeyboardHeight(); + TypedArray a = res.obtainAttributes(Xml.asAttributeSet(parser), + R.styleable.Keyboard); + mDefaultWidth = KeyboardParser.getDimensionOrFraction(a, + R.styleable.Keyboard_keyWidth, keyboardWidth, keyboard.getKeyWidth()); + mDefaultHeight = KeyboardParser.getDimensionOrFraction(a, + R.styleable.Keyboard_rowHeight, keyboardHeight, keyboard.getRowHeight()); + mDefaultHorizontalGap = KeyboardParser.getDimensionOrFraction(a, + R.styleable.Keyboard_horizontalGap, keyboardWidth, keyboard.getHorizontalGap()); + mVerticalGap = KeyboardParser.getDimensionOrFraction(a, + R.styleable.Keyboard_verticalGap, keyboardHeight, keyboard.getVerticalGap()); + a.recycle(); + a = res.obtainAttributes(Xml.asAttributeSet(parser), + R.styleable.Keyboard_Row); + mRowEdgeFlags = a.getInt(R.styleable.Keyboard_Row_rowEdgeFlags, 0); + a.recycle(); + } + + public Keyboard getKeyboard() { + return mKeyboard; + } +} diff --git a/java/src/com/android/inputmethod/keyboard/internal/ShiftKeyState.java b/java/src/com/android/inputmethod/keyboard/internal/ShiftKeyState.java new file mode 100644 index 000000000..6617b917f --- /dev/null +++ b/java/src/com/android/inputmethod/keyboard/internal/ShiftKeyState.java @@ -0,0 +1,69 @@ +/* + * 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.util.Log; + +public class ShiftKeyState extends ModifierKeyState { + private static final int PRESSING_ON_SHIFTED = 3; // both temporary shifted & shift locked + private static final int IGNORING = 4; + + public ShiftKeyState(String name) { + super(name); + } + + @Override + public void onOtherKeyPressed() { + int oldState = mState; + if (oldState == PRESSING) { + mState = MOMENTARY; + } else if (oldState == PRESSING_ON_SHIFTED) { + mState = IGNORING; + } + if (DEBUG) + Log.d(TAG, mName + ".onOtherKeyPressed: " + toString(oldState) + " > " + this); + } + + public void onPressOnShifted() { + int oldState = mState; + mState = PRESSING_ON_SHIFTED; + if (DEBUG) + Log.d(TAG, mName + ".onPressOnShifted: " + toString(oldState) + " > " + this); + } + + public boolean isPressingOnShifted() { + return mState == PRESSING_ON_SHIFTED; + } + + public boolean isIgnoring() { + return mState == IGNORING; + } + + @Override + public String toString() { + return toString(mState); + } + + @Override + protected String toString(int state) { + switch (state) { + case PRESSING_ON_SHIFTED: return "PRESSING_ON_SHIFTED"; + case IGNORING: return "IGNORING"; + default: return super.toString(state); + } + } +} diff --git a/java/src/com/android/inputmethod/keyboard/internal/SlidingLocaleDrawable.java b/java/src/com/android/inputmethod/keyboard/internal/SlidingLocaleDrawable.java new file mode 100644 index 000000000..df4b575f1 --- /dev/null +++ b/java/src/com/android/inputmethod/keyboard/internal/SlidingLocaleDrawable.java @@ -0,0 +1,159 @@ +/* + * 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.content.Context; +import android.content.res.TypedArray; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.ColorFilter; +import android.graphics.Paint; +import android.graphics.Paint.Align; +import android.graphics.PixelFormat; +import android.graphics.drawable.Drawable; +import android.text.TextPaint; +import android.view.ViewConfiguration; + +import com.android.inputmethod.keyboard.Keyboard; +import com.android.inputmethod.keyboard.LatinKeyboard; +import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.SubtypeSwitcher; + +/** + * Animation to be displayed on the spacebar preview popup when switching languages by swiping the + * spacebar. It draws the current, previous and next languages and moves them by the delta of touch + * movement on the spacebar. + */ +public class SlidingLocaleDrawable extends Drawable { + private static final int SLIDE_SPEED_MULTIPLIER_RATIO = 150; + private final int mWidth; + private final int mHeight; + private final Drawable mBackground; + private final int mSpacebarTextColor; + private final TextPaint mTextPaint; + private final int mMiddleX; + private final Drawable mLeftDrawable; + private final Drawable mRightDrawable; + private final int mThreshold; + + private int mDiff; + private boolean mHitThreshold; + private String mCurrentLanguage; + private String mNextLanguage; + private String mPrevLanguage; + + public SlidingLocaleDrawable(Context context, Drawable background, int width, int height) { + mBackground = background; + Keyboard.setDefaultBounds(mBackground); + mWidth = width; + mHeight = height; + final TextPaint textPaint = new TextPaint(); + 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 = (mWidth - mBackground.getIntrinsicWidth()) / 2; + + final TypedArray a = context.obtainStyledAttributes( + null, R.styleable.LatinKeyboard, R.attr.latinKeyboardStyle, R.style.LatinKeyboard); + mSpacebarTextColor = a.getColor(R.styleable.LatinKeyboard_spacebarTextColor, 0); + mLeftDrawable = a.getDrawable(R.styleable.LatinKeyboard_spacebarArrowPreviewLeftIcon); + mRightDrawable = a.getDrawable(R.styleable.LatinKeyboard_spacebarArrowPreviewRightIcon); + a.recycle(); + + mThreshold = ViewConfiguration.get(context).getScaledTouchSlop(); + } + + public void setDiff(int diff) { + if (diff == Integer.MAX_VALUE) { + mHitThreshold = false; + mCurrentLanguage = null; + return; + } + mDiff = Math.max(diff, diff * SLIDE_SPEED_MULTIPLIER_RATIO / 100); + if (mDiff > mWidth) mDiff = mWidth; + if (mDiff < -mWidth) mDiff = -mWidth; + if (Math.abs(mDiff) > mThreshold) mHitThreshold = true; + invalidateSelf(); + } + + + @Override + public void draw(Canvas canvas) { + canvas.save(); + if (mHitThreshold) { + Paint paint = mTextPaint; + 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(); + mCurrentLanguage = subtypeSwitcher.getInputLanguageName(); + mNextLanguage = subtypeSwitcher.getNextInputLanguageName(); + mPrevLanguage = subtypeSwitcher.getPreviousInputLanguageName(); + } + // Draw language text with shadow + final float baseline = mHeight * LatinKeyboard.SPACEBAR_LANGUAGE_BASELINE + - paint.descent(); + paint.setColor(mSpacebarTextColor); + 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); + + Keyboard.setDefaultBounds(lArrow); + rArrow.setBounds(width - rArrow.getIntrinsicWidth(), 0, width, + rArrow.getIntrinsicHeight()); + lArrow.draw(canvas); + rArrow.draw(canvas); + } + if (mBackground != null) { + canvas.translate(mMiddleX, 0); + mBackground.draw(canvas); + } + canvas.restore(); + } + + @Override + public int getOpacity() { + return PixelFormat.TRANSLUCENT; + } + + @Override + public void setAlpha(int alpha) { + // Ignore + } + + @Override + public void setColorFilter(ColorFilter cf) { + // Ignore + } + + @Override + public int getIntrinsicWidth() { + return mWidth; + } + + @Override + public int getIntrinsicHeight() { + return mHeight; + } +} diff --git a/java/src/com/android/inputmethod/keyboard/internal/SwipeTracker.java b/java/src/com/android/inputmethod/keyboard/internal/SwipeTracker.java new file mode 100644 index 000000000..8d192c2f0 --- /dev/null +++ b/java/src/com/android/inputmethod/keyboard/internal/SwipeTracker.java @@ -0,0 +1,157 @@ +/* + * 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.view.MotionEvent; + +public class SwipeTracker { + private static final int NUM_PAST = 4; + private static final int LONGEST_PAST_TIME = 200; + + final EventRingBuffer mBuffer = new EventRingBuffer(NUM_PAST); + + private float mYVelocity; + private float mXVelocity; + + public void addMovement(MotionEvent ev) { + if (ev.getAction() == MotionEvent.ACTION_DOWN) { + mBuffer.clear(); + return; + } + long time = ev.getEventTime(); + final int count = ev.getHistorySize(); + for (int i = 0; i < count; i++) { + addPoint(ev.getHistoricalX(i), ev.getHistoricalY(i), ev.getHistoricalEventTime(i)); + } + addPoint(ev.getX(), ev.getY(), time); + } + + private void addPoint(float x, float y, long time) { + final EventRingBuffer buffer = mBuffer; + while (buffer.size() > 0) { + long lastT = buffer.getTime(0); + if (lastT >= time - LONGEST_PAST_TIME) + break; + buffer.dropOldest(); + } + buffer.add(x, y, time); + } + + public void computeCurrentVelocity(int units) { + computeCurrentVelocity(units, Float.MAX_VALUE); + } + + public void computeCurrentVelocity(int units, float maxVelocity) { + final EventRingBuffer buffer = mBuffer; + final float oldestX = buffer.getX(0); + final float oldestY = buffer.getY(0); + final long oldestTime = buffer.getTime(0); + + float accumX = 0; + float accumY = 0; + final int count = buffer.size(); + for (int pos = 1; pos < count; pos++) { + final int dur = (int)(buffer.getTime(pos) - oldestTime); + if (dur == 0) continue; + float dist = buffer.getX(pos) - oldestX; + float vel = (dist / dur) * units; // pixels/frame. + if (accumX == 0) accumX = vel; + else accumX = (accumX + vel) * .5f; + + dist = buffer.getY(pos) - oldestY; + vel = (dist / dur) * units; // pixels/frame. + if (accumY == 0) accumY = vel; + else accumY = (accumY + vel) * .5f; + } + mXVelocity = accumX < 0.0f ? Math.max(accumX, -maxVelocity) + : Math.min(accumX, maxVelocity); + mYVelocity = accumY < 0.0f ? Math.max(accumY, -maxVelocity) + : Math.min(accumY, maxVelocity); + } + + public float getXVelocity() { + return mXVelocity; + } + + public float getYVelocity() { + return mYVelocity; + } + + public static class EventRingBuffer { + private final int bufSize; + private final float xBuf[]; + private final float yBuf[]; + private final long timeBuf[]; + private int top; // points new event + private int end; // points oldest event + private int count; // the number of valid data + + public EventRingBuffer(int max) { + this.bufSize = max; + xBuf = new float[max]; + yBuf = new float[max]; + timeBuf = new long[max]; + clear(); + } + + public void clear() { + top = end = count = 0; + } + + public int size() { + return count; + } + + // Position 0 points oldest event + private int index(int pos) { + return (end + pos) % bufSize; + } + + private int advance(int index) { + return (index + 1) % bufSize; + } + + public void add(float x, float y, long time) { + xBuf[top] = x; + yBuf[top] = y; + timeBuf[top] = time; + top = advance(top); + if (count < bufSize) { + count++; + } else { + end = advance(end); + } + } + + public float getX(int pos) { + return xBuf[index(pos)]; + } + + public float getY(int pos) { + return yBuf[index(pos)]; + } + + public long getTime(int pos) { + return timeBuf[index(pos)]; + } + + public void dropOldest() { + count--; + end = advance(end); + } + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/KeyStylesTests.java b/tests/src/com/android/inputmethod/keyboard/KeyStylesTests.java deleted file mode 100644 index 5dff11471..000000000 --- a/tests/src/com/android/inputmethod/keyboard/KeyStylesTests.java +++ /dev/null @@ -1,90 +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 com.android.inputmethod.keyboard.KeyStyles.EmptyKeyStyle; - -import android.test.AndroidTestCase; -import android.text.TextUtils; - -public class KeyStylesTests extends AndroidTestCase { - private static String format(String message, Object expected, Object actual) { - return message + " expected:<" + expected + "> but was:<" + actual + ">"; - } - - private static void assertTextArray(String message, CharSequence value, - CharSequence ... expected) { - final CharSequence actual[] = EmptyKeyStyle.parseCsvText(value); - if (expected.length == 0) { - assertNull(message, actual); - return; - } - assertSame(message + ": result length", expected.length, actual.length); - for (int i = 0; i < actual.length; i++) { - final boolean equals = TextUtils.equals(expected[i], actual[i]); - assertTrue(format(message + ": result at " + i + ":", expected[i], actual[i]), equals); - } - } - - public void testParseCsvTextZero() { - assertTextArray("Empty string", ""); - } - - public void testParseCsvTextSingle() { - assertTextArray("Single char", "a", "a"); - assertTextArray("Space", " ", " "); - assertTextArray("Single label", "abc", "abc"); - assertTextArray("Spaces", " ", " "); - assertTextArray("Spaces in label", "a b c", "a b c"); - assertTextArray("Spaces at beginning of label", " abc", " abc"); - assertTextArray("Spaces at end of label", "abc ", "abc "); - assertTextArray("label surrounded by spaces", " abc ", " abc "); - } - - public void testParseCsvTextSingleEscaped() { - assertTextArray("Escaped char", "\\a", "a"); - assertTextArray("Escaped comma", "\\,", ","); - assertTextArray("Escaped escape", "\\\\", "\\"); - assertTextArray("Escaped label", "a\\bc", "abc"); - assertTextArray("Escaped label at begininng", "\\abc", "abc"); - assertTextArray("Escaped label with comma", "a\\,c", "a,c"); - assertTextArray("Escaped label with comma at beginning", "\\,bc", ",bc"); - assertTextArray("Escaped label with successive", "\\,\\\\bc", ",\\bc"); - assertTextArray("Escaped label with escape", "a\\\\c", "a\\c"); - } - - public void testParseCsvTextMulti() { - assertTextArray("Multiple chars", "a,b,c", "a", "b", "c"); - assertTextArray("Multiple chars surrounded by spaces", " a , b , c ", " a ", " b ", " c "); - assertTextArray("Multiple labels", "abc,def,ghi", "abc", "def", "ghi"); - assertTextArray("Multiple labels surrounded by spaces", " abc , def , ghi ", - " abc ", " def ", " ghi "); - } - - public void testParseCsvTextMultiEscaped() { - assertTextArray("Multiple chars with comma", "a,\\,,c", "a", ",", "c"); - assertTextArray("Multiple chars with comma surrounded by spaces", " a , \\, , c ", - " a ", " , ", " c "); - assertTextArray("Multiple labels with escape", "\\abc,d\\ef,gh\\i", "abc", "def", "ghi"); - assertTextArray("Multiple labels with escape surrounded by spaces", - " \\abc , d\\ef , gh\\i ", " abc ", " def ", " ghi "); - assertTextArray("Multiple labels with comma and escape", - "ab\\\\,d\\\\\\,,g\\,i", "ab\\", "d\\,", "g,i"); - assertTextArray("Multiple labels with comma and escape surrounded by spaces", - " ab\\\\ , d\\\\\\, , g\\,i ", " ab\\ ", " d\\, ", " g,i "); - } -} diff --git a/tests/src/com/android/inputmethod/keyboard/MiniKeyboardBuilderTests.java b/tests/src/com/android/inputmethod/keyboard/MiniKeyboardBuilderTests.java deleted file mode 100644 index 600342a7c..000000000 --- a/tests/src/com/android/inputmethod/keyboard/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; - -import com.android.inputmethod.keyboard.MiniKeyboardBuilder.MiniKeyboardLayoutParams; - -import android.test.AndroidTestCase; - -public class MiniKeyboardBuilderTests extends AndroidTestCase { - private static final int MAX_COLUMNS = 5; - private static final int WIDTH = 10; - private static final int HEIGHT = 10; - - 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() { - MiniKeyboardLayoutParams params = null; - try { - params = new MiniKeyboardLayoutParams(10, MAX_COLUMNS + 1, WIDTH, HEIGHT, WIDTH * 2, - WIDTH * MAX_COLUMNS); - fail("Should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // Too small keyboard to hold mini keyboard. - } - assertNull("Too small keyboard to hold mini keyboard", params); - } - - // Mini keyboard layout test. - // "[n]" represents n-th key position in mini keyboard. - // "[1]" is the default key. - - // [1] - public void testLayout1KeyM0() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { - MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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/PopupCharactersParserTests.java b/tests/src/com/android/inputmethod/keyboard/PopupCharactersParserTests.java deleted file mode 100644 index ae78866e6..000000000 --- a/tests/src/com/android/inputmethod/keyboard/PopupCharactersParserTests.java +++ /dev/null @@ -1,207 +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 com.android.inputmethod.latin.R; -import android.content.res.Resources; -import android.graphics.drawable.Drawable; -import android.test.AndroidTestCase; - -public class PopupCharactersParserTests extends AndroidTestCase { - private Resources mRes; - - private static final String CODE_SETTINGS = "@integer/key_settings"; - private static final String ICON_SETTINGS = "@drawable/sym_keyboard_settings"; - private static final String CODE_NON_EXISTING = "@integer/non_existing"; - private static final String ICON_NON_EXISTING = "@drawable/non_existing"; - - private int mCodeSettings; - private Drawable mIconSettings; - - @Override - protected void setUp() { - Resources res = getContext().getResources(); - mRes = res; - - final String packageName = res.getResourcePackageName(R.string.english_ime_name); - final int codeId = res.getIdentifier(CODE_SETTINGS.substring(1), null, packageName); - final int iconId = res.getIdentifier(ICON_SETTINGS.substring(1), null, packageName); - mCodeSettings = res.getInteger(codeId); - mIconSettings = res.getDrawable(iconId); - } - - private void assertParser(String message, String popupSpec, String expectedLabel, - String expectedOutputText, Drawable expectedIcon, int expectedCode) { - String actualLabel = PopupCharactersParser.getLabel(popupSpec); - assertEquals(message + ": label:", expectedLabel, actualLabel); - - String actualOutputText = PopupCharactersParser.getOutputText(popupSpec); - assertEquals(message + ": ouptputText:", expectedOutputText, actualOutputText); - - Drawable actualIcon = PopupCharactersParser.getIcon(mRes, popupSpec); - // We can not compare drawables, checking null or non-null instead. - if (expectedIcon == null) { - assertNull(message + ": icon null:", actualIcon); - } else { - assertNotNull(message + ": icon non-null:", actualIcon); - } - - int actualCode = PopupCharactersParser.getCode(mRes, popupSpec); - assertEquals(message + ": codes value:", expectedCode, actualCode); - } - - private void assertParserError(String message, String popupSpec, String expectedLabel, - String expectedOutputText, Drawable expectedIcon, int expectedCode) { - try { - assertParser(message, popupSpec, expectedLabel, expectedOutputText, expectedIcon, - expectedCode); - fail(message); - } catch (PopupCharactersParser.PopupCharactersParserError pcpe) { - // success. - } - } - - public void testSingleLetter() { - assertParser("Single letter", "a", "a", null, null, 'a'); - assertParser("Single escaped bar", "\\|", "|", null, null, '|'); - assertParser("Single escaped escape", "\\\\", "\\", null, null, '\\'); - assertParser("Single comma", ",", ",", null, null, ','); - assertParser("Single escaped comma", "\\,", ",", null, null, ','); - assertParser("Single escaped letter", "\\a", "a", null, null, 'a'); - assertParser("Single at", "@", "@", null, null, '@'); - assertParser("Single escaped at", "\\@", "@", null, null, '@'); - assertParser("Single letter with outputText", "a|abc", "a", "abc", null, - Keyboard.CODE_DUMMY); - assertParser("Single letter with escaped outputText", "a|a\\|c", "a", "a|c", null, - Keyboard.CODE_DUMMY); - assertParser("Single letter with comma outputText", "a|a,b", "a", "a,b", null, - Keyboard.CODE_DUMMY); - assertParser("Single letter with escaped comma outputText", "a|a\\,b", "a", "a,b", null, - Keyboard.CODE_DUMMY); - assertParser("Single letter with outputText starts with at", "a|@bc", "a", "@bc", null, - Keyboard.CODE_DUMMY); - assertParser("Single letter with outputText contains at", "a|a@c", "a", "a@c", null, - Keyboard.CODE_DUMMY); - assertParser("Single letter with escaped at outputText", "a|\\@bc", "a", "@bc", null, - Keyboard.CODE_DUMMY); - assertParser("Single escaped escape with outputText", "\\\\|\\\\", "\\", "\\", null, - Keyboard.CODE_DUMMY); - assertParser("Single escaped bar with outputText", "\\||\\|", "|", "|", null, - Keyboard.CODE_DUMMY); - assertParser("Single letter with code", "a|" + CODE_SETTINGS, "a", null, null, - mCodeSettings); - } - - public void testLabel() { - assertParser("Simple label", "abc", "abc", "abc", null, Keyboard.CODE_DUMMY); - assertParser("Label with escaped bar", "a\\|c", "a|c", "a|c", null, - Keyboard.CODE_DUMMY); - assertParser("Label with escaped escape", "a\\\\c", "a\\c", "a\\c", null, - Keyboard.CODE_DUMMY); - assertParser("Label with comma", "a,c", "a,c", "a,c", null, Keyboard.CODE_DUMMY); - assertParser("Label with escaped comma", "a\\,c", "a,c", "a,c", null, - Keyboard.CODE_DUMMY); - assertParser("Label starts with at", "@bc", "@bc", "@bc", null, Keyboard.CODE_DUMMY); - assertParser("Label contains at", "a@c", "a@c", "a@c", null, Keyboard.CODE_DUMMY); - assertParser("Label with escaped at", "\\@bc", "@bc", "@bc", null, - Keyboard.CODE_DUMMY); - assertParser("Label with escaped letter", "\\abc", "abc", "abc", null, - Keyboard.CODE_DUMMY); - assertParser("Label with outputText", "abc|def", "abc", "def", null, - Keyboard.CODE_DUMMY); - assertParser("Label with comma and outputText", "a,c|def", "a,c", "def", null, - Keyboard.CODE_DUMMY); - assertParser("Escaped comma label with outputText", "a\\,c|def", "a,c", "def", null, - Keyboard.CODE_DUMMY); - assertParser("Escaped label with outputText", "a\\|c|def", "a|c", "def", null, - Keyboard.CODE_DUMMY); - assertParser("Label with escaped bar outputText", "abc|d\\|f", "abc", "d|f", null, - Keyboard.CODE_DUMMY); - assertParser("Escaped escape label with outputText", "a\\\\|def", "a\\", "def", null, - Keyboard.CODE_DUMMY); - assertParser("Label starts with at and outputText", "@bc|def", "@bc", "def", null, - Keyboard.CODE_DUMMY); - assertParser("Label contains at label and outputText", "a@c|def", "a@c", "def", null, - Keyboard.CODE_DUMMY); - assertParser("Escaped at label with outputText", "\\@bc|def", "@bc", "def", null, - Keyboard.CODE_DUMMY); - assertParser("Label with comma outputText", "abc|a,b", "abc", "a,b", null, - Keyboard.CODE_DUMMY); - assertParser("Label with escaped comma outputText", "abc|a\\,b", "abc", "a,b", null, - Keyboard.CODE_DUMMY); - assertParser("Label with outputText starts with at", "abc|@bc", "abc", "@bc", null, - Keyboard.CODE_DUMMY); - assertParser("Label with outputText contains at", "abc|a@c", "abc", "a@c", null, - Keyboard.CODE_DUMMY); - assertParser("Label with escaped at outputText", "abc|\\@bc", "abc", "@bc", null, - Keyboard.CODE_DUMMY); - assertParser("Label with escaped bar outputText", "abc|d\\|f", "abc", "d|f", - null, Keyboard.CODE_DUMMY); - assertParser("Escaped bar label with escaped bar outputText", "a\\|c|d\\|f", "a|c", "d|f", - null, Keyboard.CODE_DUMMY); - assertParser("Label with code", "abc|" + CODE_SETTINGS, "abc", null, null, mCodeSettings); - assertParser("Escaped label with code", "a\\|c|" + CODE_SETTINGS, "a|c", null, null, - mCodeSettings); - } - - public void testIconAndCode() { - assertParser("Icon with outputText", ICON_SETTINGS + "|abc", null, "abc", mIconSettings, - Keyboard.CODE_DUMMY); - assertParser("Icon with outputText starts with at", ICON_SETTINGS + "|@bc", null, "@bc", - mIconSettings, Keyboard.CODE_DUMMY); - assertParser("Icon with outputText contains at", ICON_SETTINGS + "|a@c", null, "a@c", - mIconSettings, Keyboard.CODE_DUMMY); - assertParser("Icon with escaped at outputText", ICON_SETTINGS + "|\\@bc", null, "@bc", - mIconSettings, Keyboard.CODE_DUMMY); - assertParser("Label starts with at and code", "@bc|" + CODE_SETTINGS, "@bc", null, null, - mCodeSettings); - assertParser("Label contains at and code", "a@c|" + CODE_SETTINGS, "a@c", null, null, - mCodeSettings); - assertParser("Escaped at label with code", "\\@bc|" + CODE_SETTINGS, "@bc", null, null, - mCodeSettings); - assertParser("Icon with code", ICON_SETTINGS + "|" + CODE_SETTINGS, null, null, - mIconSettings, mCodeSettings); - } - - public void testFormatError() { - assertParserError("Empty spec", "", null, null, null, Keyboard.CODE_UNSPECIFIED); - assertParserError("Empty label with outputText", "|a", null, "a", null, - Keyboard.CODE_DUMMY); - assertParserError("Empty label with code", "|" + CODE_SETTINGS, null, null, null, - mCodeSettings); - assertParserError("Empty outputText with label", "a|", "a", null, null, - Keyboard.CODE_UNSPECIFIED); - assertParserError("Empty outputText with icon", ICON_SETTINGS + "|", null, null, - mIconSettings, Keyboard.CODE_UNSPECIFIED); - assertParserError("Empty icon and code", "|", null, null, null, Keyboard.CODE_UNSPECIFIED); - assertParserError("Icon without code", ICON_SETTINGS, null, null, mIconSettings, - Keyboard.CODE_DUMMY); - assertParserError("Non existing icon", ICON_NON_EXISTING + "|abc", null, "abc", null, - Keyboard.CODE_DUMMY); - assertParserError("Non existing code", "abc|" + CODE_NON_EXISTING, "abc", null, null, - Keyboard.CODE_UNSPECIFIED); - assertParserError("Third bar at end", "a|b|", "a", null, null, Keyboard.CODE_UNSPECIFIED); - assertParserError("Multiple bar", "a|b|c", "a", null, null, Keyboard.CODE_UNSPECIFIED); - assertParserError("Multiple bar with label and code", "a|" + CODE_SETTINGS + "|c", "a", - null, null, mCodeSettings); - assertParserError("Multiple bar with icon and outputText", ICON_SETTINGS + "|b|c", null, - null, mIconSettings, Keyboard.CODE_UNSPECIFIED); - assertParserError("Multiple bar with icon and code", - ICON_SETTINGS + "|" + CODE_SETTINGS + "|c", null, null, mIconSettings, - mCodeSettings); - } -} diff --git a/tests/src/com/android/inputmethod/keyboard/internal/KeyStylesTests.java b/tests/src/com/android/inputmethod/keyboard/internal/KeyStylesTests.java new file mode 100644 index 000000000..4050a7123 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/internal/KeyStylesTests.java @@ -0,0 +1,90 @@ +/* + * 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 com.android.inputmethod.keyboard.internal.KeyStyles.EmptyKeyStyle; + +import android.test.AndroidTestCase; +import android.text.TextUtils; + +public class KeyStylesTests extends AndroidTestCase { + private static String format(String message, Object expected, Object actual) { + return message + " expected:<" + expected + "> but was:<" + actual + ">"; + } + + private static void assertTextArray(String message, CharSequence value, + CharSequence ... expected) { + final CharSequence actual[] = EmptyKeyStyle.parseCsvText(value); + if (expected.length == 0) { + assertNull(message, actual); + return; + } + assertSame(message + ": result length", expected.length, actual.length); + for (int i = 0; i < actual.length; i++) { + final boolean equals = TextUtils.equals(expected[i], actual[i]); + assertTrue(format(message + ": result at " + i + ":", expected[i], actual[i]), equals); + } + } + + public void testParseCsvTextZero() { + assertTextArray("Empty string", ""); + } + + public void testParseCsvTextSingle() { + assertTextArray("Single char", "a", "a"); + assertTextArray("Space", " ", " "); + assertTextArray("Single label", "abc", "abc"); + assertTextArray("Spaces", " ", " "); + assertTextArray("Spaces in label", "a b c", "a b c"); + assertTextArray("Spaces at beginning of label", " abc", " abc"); + assertTextArray("Spaces at end of label", "abc ", "abc "); + assertTextArray("label surrounded by spaces", " abc ", " abc "); + } + + public void testParseCsvTextSingleEscaped() { + assertTextArray("Escaped char", "\\a", "a"); + assertTextArray("Escaped comma", "\\,", ","); + assertTextArray("Escaped escape", "\\\\", "\\"); + assertTextArray("Escaped label", "a\\bc", "abc"); + assertTextArray("Escaped label at begininng", "\\abc", "abc"); + assertTextArray("Escaped label with comma", "a\\,c", "a,c"); + assertTextArray("Escaped label with comma at beginning", "\\,bc", ",bc"); + assertTextArray("Escaped label with successive", "\\,\\\\bc", ",\\bc"); + assertTextArray("Escaped label with escape", "a\\\\c", "a\\c"); + } + + public void testParseCsvTextMulti() { + assertTextArray("Multiple chars", "a,b,c", "a", "b", "c"); + assertTextArray("Multiple chars surrounded by spaces", " a , b , c ", " a ", " b ", " c "); + assertTextArray("Multiple labels", "abc,def,ghi", "abc", "def", "ghi"); + assertTextArray("Multiple labels surrounded by spaces", " abc , def , ghi ", + " abc ", " def ", " ghi "); + } + + public void testParseCsvTextMultiEscaped() { + assertTextArray("Multiple chars with comma", "a,\\,,c", "a", ",", "c"); + assertTextArray("Multiple chars with comma surrounded by spaces", " a , \\, , c ", + " a ", " , ", " c "); + assertTextArray("Multiple labels with escape", "\\abc,d\\ef,gh\\i", "abc", "def", "ghi"); + assertTextArray("Multiple labels with escape surrounded by spaces", + " \\abc , d\\ef , gh\\i ", " abc ", " def ", " ghi "); + assertTextArray("Multiple labels with comma and escape", + "ab\\\\,d\\\\\\,,g\\,i", "ab\\", "d\\,", "g,i"); + assertTextArray("Multiple labels with comma and escape surrounded by spaces", + " ab\\\\ , d\\\\\\, , g\\,i ", " ab\\ ", " d\\, ", " g,i "); + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/internal/MiniKeyboardBuilderTests.java b/tests/src/com/android/inputmethod/keyboard/internal/MiniKeyboardBuilderTests.java new file mode 100644 index 000000000..0d2802d53 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/internal/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.internal; + +import com.android.inputmethod.keyboard.internal.MiniKeyboardBuilder.MiniKeyboardLayoutParams; + +import android.test.AndroidTestCase; + +public class MiniKeyboardBuilderTests extends AndroidTestCase { + private static final int MAX_COLUMNS = 5; + private static final int WIDTH = 10; + private static final int HEIGHT = 10; + + 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() { + MiniKeyboardLayoutParams params = null; + try { + params = new MiniKeyboardLayoutParams(10, MAX_COLUMNS + 1, WIDTH, HEIGHT, WIDTH * 2, + WIDTH * MAX_COLUMNS); + fail("Should throw IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // Too small keyboard to hold mini keyboard. + } + assertNull("Too small keyboard to hold mini keyboard", params); + } + + // Mini keyboard layout test. + // "[n]" represents n-th key position in mini keyboard. + // "[1]" is the default key. + + // [1] + public void testLayout1KeyM0() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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() { + MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(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/PopupCharactersParserTests.java b/tests/src/com/android/inputmethod/keyboard/internal/PopupCharactersParserTests.java new file mode 100644 index 000000000..be64f89d2 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/internal/PopupCharactersParserTests.java @@ -0,0 +1,209 @@ +/* + * 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 com.android.inputmethod.keyboard.Keyboard; +import com.android.inputmethod.keyboard.internal.PopupCharactersParser.PopupCharactersParserError; +import com.android.inputmethod.latin.R; +import android.content.res.Resources; +import android.graphics.drawable.Drawable; +import android.test.AndroidTestCase; + +public class PopupCharactersParserTests extends AndroidTestCase { + private Resources mRes; + + private static final String CODE_SETTINGS = "@integer/key_settings"; + private static final String ICON_SETTINGS = "@drawable/sym_keyboard_settings"; + private static final String CODE_NON_EXISTING = "@integer/non_existing"; + private static final String ICON_NON_EXISTING = "@drawable/non_existing"; + + private int mCodeSettings; + private Drawable mIconSettings; + + @Override + protected void setUp() { + Resources res = getContext().getResources(); + mRes = res; + + final String packageName = res.getResourcePackageName(R.string.english_ime_name); + final int codeId = res.getIdentifier(CODE_SETTINGS.substring(1), null, packageName); + final int iconId = res.getIdentifier(ICON_SETTINGS.substring(1), null, packageName); + mCodeSettings = res.getInteger(codeId); + mIconSettings = res.getDrawable(iconId); + } + + private void assertParser(String message, String popupSpec, String expectedLabel, + String expectedOutputText, Drawable expectedIcon, int expectedCode) { + String actualLabel = PopupCharactersParser.getLabel(popupSpec); + assertEquals(message + ": label:", expectedLabel, actualLabel); + + String actualOutputText = PopupCharactersParser.getOutputText(popupSpec); + assertEquals(message + ": ouptputText:", expectedOutputText, actualOutputText); + + Drawable actualIcon = PopupCharactersParser.getIcon(mRes, popupSpec); + // We can not compare drawables, checking null or non-null instead. + if (expectedIcon == null) { + assertNull(message + ": icon null:", actualIcon); + } else { + assertNotNull(message + ": icon non-null:", actualIcon); + } + + int actualCode = PopupCharactersParser.getCode(mRes, popupSpec); + assertEquals(message + ": codes value:", expectedCode, actualCode); + } + + private void assertParserError(String message, String popupSpec, String expectedLabel, + String expectedOutputText, Drawable expectedIcon, int expectedCode) { + try { + assertParser(message, popupSpec, expectedLabel, expectedOutputText, expectedIcon, + expectedCode); + fail(message); + } catch (PopupCharactersParser.PopupCharactersParserError pcpe) { + // success. + } + } + + public void testSingleLetter() { + assertParser("Single letter", "a", "a", null, null, 'a'); + assertParser("Single escaped bar", "\\|", "|", null, null, '|'); + assertParser("Single escaped escape", "\\\\", "\\", null, null, '\\'); + assertParser("Single comma", ",", ",", null, null, ','); + assertParser("Single escaped comma", "\\,", ",", null, null, ','); + assertParser("Single escaped letter", "\\a", "a", null, null, 'a'); + assertParser("Single at", "@", "@", null, null, '@'); + assertParser("Single escaped at", "\\@", "@", null, null, '@'); + assertParser("Single letter with outputText", "a|abc", "a", "abc", null, + Keyboard.CODE_DUMMY); + assertParser("Single letter with escaped outputText", "a|a\\|c", "a", "a|c", null, + Keyboard.CODE_DUMMY); + assertParser("Single letter with comma outputText", "a|a,b", "a", "a,b", null, + Keyboard.CODE_DUMMY); + assertParser("Single letter with escaped comma outputText", "a|a\\,b", "a", "a,b", null, + Keyboard.CODE_DUMMY); + assertParser("Single letter with outputText starts with at", "a|@bc", "a", "@bc", null, + Keyboard.CODE_DUMMY); + assertParser("Single letter with outputText contains at", "a|a@c", "a", "a@c", null, + Keyboard.CODE_DUMMY); + assertParser("Single letter with escaped at outputText", "a|\\@bc", "a", "@bc", null, + Keyboard.CODE_DUMMY); + assertParser("Single escaped escape with outputText", "\\\\|\\\\", "\\", "\\", null, + Keyboard.CODE_DUMMY); + assertParser("Single escaped bar with outputText", "\\||\\|", "|", "|", null, + Keyboard.CODE_DUMMY); + assertParser("Single letter with code", "a|" + CODE_SETTINGS, "a", null, null, + mCodeSettings); + } + + public void testLabel() { + assertParser("Simple label", "abc", "abc", "abc", null, Keyboard.CODE_DUMMY); + assertParser("Label with escaped bar", "a\\|c", "a|c", "a|c", null, + Keyboard.CODE_DUMMY); + assertParser("Label with escaped escape", "a\\\\c", "a\\c", "a\\c", null, + Keyboard.CODE_DUMMY); + assertParser("Label with comma", "a,c", "a,c", "a,c", null, Keyboard.CODE_DUMMY); + assertParser("Label with escaped comma", "a\\,c", "a,c", "a,c", null, + Keyboard.CODE_DUMMY); + assertParser("Label starts with at", "@bc", "@bc", "@bc", null, Keyboard.CODE_DUMMY); + assertParser("Label contains at", "a@c", "a@c", "a@c", null, Keyboard.CODE_DUMMY); + assertParser("Label with escaped at", "\\@bc", "@bc", "@bc", null, + Keyboard.CODE_DUMMY); + assertParser("Label with escaped letter", "\\abc", "abc", "abc", null, + Keyboard.CODE_DUMMY); + assertParser("Label with outputText", "abc|def", "abc", "def", null, + Keyboard.CODE_DUMMY); + assertParser("Label with comma and outputText", "a,c|def", "a,c", "def", null, + Keyboard.CODE_DUMMY); + assertParser("Escaped comma label with outputText", "a\\,c|def", "a,c", "def", null, + Keyboard.CODE_DUMMY); + assertParser("Escaped label with outputText", "a\\|c|def", "a|c", "def", null, + Keyboard.CODE_DUMMY); + assertParser("Label with escaped bar outputText", "abc|d\\|f", "abc", "d|f", null, + Keyboard.CODE_DUMMY); + assertParser("Escaped escape label with outputText", "a\\\\|def", "a\\", "def", null, + Keyboard.CODE_DUMMY); + assertParser("Label starts with at and outputText", "@bc|def", "@bc", "def", null, + Keyboard.CODE_DUMMY); + assertParser("Label contains at label and outputText", "a@c|def", "a@c", "def", null, + Keyboard.CODE_DUMMY); + assertParser("Escaped at label with outputText", "\\@bc|def", "@bc", "def", null, + Keyboard.CODE_DUMMY); + assertParser("Label with comma outputText", "abc|a,b", "abc", "a,b", null, + Keyboard.CODE_DUMMY); + assertParser("Label with escaped comma outputText", "abc|a\\,b", "abc", "a,b", null, + Keyboard.CODE_DUMMY); + assertParser("Label with outputText starts with at", "abc|@bc", "abc", "@bc", null, + Keyboard.CODE_DUMMY); + assertParser("Label with outputText contains at", "abc|a@c", "abc", "a@c", null, + Keyboard.CODE_DUMMY); + assertParser("Label with escaped at outputText", "abc|\\@bc", "abc", "@bc", null, + Keyboard.CODE_DUMMY); + assertParser("Label with escaped bar outputText", "abc|d\\|f", "abc", "d|f", + null, Keyboard.CODE_DUMMY); + assertParser("Escaped bar label with escaped bar outputText", "a\\|c|d\\|f", "a|c", "d|f", + null, Keyboard.CODE_DUMMY); + assertParser("Label with code", "abc|" + CODE_SETTINGS, "abc", null, null, mCodeSettings); + assertParser("Escaped label with code", "a\\|c|" + CODE_SETTINGS, "a|c", null, null, + mCodeSettings); + } + + public void testIconAndCode() { + assertParser("Icon with outputText", ICON_SETTINGS + "|abc", null, "abc", mIconSettings, + Keyboard.CODE_DUMMY); + assertParser("Icon with outputText starts with at", ICON_SETTINGS + "|@bc", null, "@bc", + mIconSettings, Keyboard.CODE_DUMMY); + assertParser("Icon with outputText contains at", ICON_SETTINGS + "|a@c", null, "a@c", + mIconSettings, Keyboard.CODE_DUMMY); + assertParser("Icon with escaped at outputText", ICON_SETTINGS + "|\\@bc", null, "@bc", + mIconSettings, Keyboard.CODE_DUMMY); + assertParser("Label starts with at and code", "@bc|" + CODE_SETTINGS, "@bc", null, null, + mCodeSettings); + assertParser("Label contains at and code", "a@c|" + CODE_SETTINGS, "a@c", null, null, + mCodeSettings); + assertParser("Escaped at label with code", "\\@bc|" + CODE_SETTINGS, "@bc", null, null, + mCodeSettings); + assertParser("Icon with code", ICON_SETTINGS + "|" + CODE_SETTINGS, null, null, + mIconSettings, mCodeSettings); + } + + public void testFormatError() { + assertParserError("Empty spec", "", null, null, null, Keyboard.CODE_UNSPECIFIED); + assertParserError("Empty label with outputText", "|a", null, "a", null, + Keyboard.CODE_DUMMY); + assertParserError("Empty label with code", "|" + CODE_SETTINGS, null, null, null, + mCodeSettings); + assertParserError("Empty outputText with label", "a|", "a", null, null, + Keyboard.CODE_UNSPECIFIED); + assertParserError("Empty outputText with icon", ICON_SETTINGS + "|", null, null, + mIconSettings, Keyboard.CODE_UNSPECIFIED); + assertParserError("Empty icon and code", "|", null, null, null, Keyboard.CODE_UNSPECIFIED); + assertParserError("Icon without code", ICON_SETTINGS, null, null, mIconSettings, + Keyboard.CODE_DUMMY); + assertParserError("Non existing icon", ICON_NON_EXISTING + "|abc", null, "abc", null, + Keyboard.CODE_DUMMY); + assertParserError("Non existing code", "abc|" + CODE_NON_EXISTING, "abc", null, null, + Keyboard.CODE_UNSPECIFIED); + assertParserError("Third bar at end", "a|b|", "a", null, null, Keyboard.CODE_UNSPECIFIED); + assertParserError("Multiple bar", "a|b|c", "a", null, null, Keyboard.CODE_UNSPECIFIED); + assertParserError("Multiple bar with label and code", "a|" + CODE_SETTINGS + "|c", "a", + null, null, mCodeSettings); + assertParserError("Multiple bar with icon and outputText", ICON_SETTINGS + "|b|c", null, + null, mIconSettings, Keyboard.CODE_UNSPECIFIED); + assertParserError("Multiple bar with icon and code", + ICON_SETTINGS + "|" + CODE_SETTINGS + "|c", null, null, mIconSettings, + mCodeSettings); + } +} diff --git a/tests/src/com/android/inputmethod/latin/EventRingBufferTests.java b/tests/src/com/android/inputmethod/latin/EventRingBufferTests.java index 869781f3d..a3d2a2b10 100644 --- a/tests/src/com/android/inputmethod/latin/EventRingBufferTests.java +++ b/tests/src/com/android/inputmethod/latin/EventRingBufferTests.java @@ -16,7 +16,7 @@ package com.android.inputmethod.latin; -import com.android.inputmethod.keyboard.SwipeTracker.EventRingBuffer; +import com.android.inputmethod.keyboard.internal.SwipeTracker.EventRingBuffer; import android.test.AndroidTestCase; diff --git a/tests/src/com/android/inputmethod/latin/SuggestHelper.java b/tests/src/com/android/inputmethod/latin/SuggestHelper.java index 87ea011fa..f1224a25a 100644 --- a/tests/src/com/android/inputmethod/latin/SuggestHelper.java +++ b/tests/src/com/android/inputmethod/latin/SuggestHelper.java @@ -16,10 +16,10 @@ package com.android.inputmethod.latin; -import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.KeyDetector; import com.android.inputmethod.keyboard.KeyboardId; import com.android.inputmethod.keyboard.LatinKeyboard; +import com.android.inputmethod.keyboard.internal.Key; import android.content.Context; import android.text.TextUtils; -- cgit v1.2.3-83-g751a