From 2affaf91a04d63e0994102299816014a8bbe11e1 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 8 Feb 2012 16:12:11 +0900 Subject: Rename mini keyboard to more keys keyboard Change-Id: Ie4c85e8ca5a1f41a420aae5c1cd9c1cb07e237e5 --- java/proguard.flags | 2 +- java/res/anim/mini_keyboard_fadein.xml | 29 --- java/res/anim/mini_keyboard_fadeout.xml | 29 --- java/res/anim/more_keys_keyboard_fadein.xml | 29 +++ java/res/anim/more_keys_keyboard_fadeout.xml | 29 +++ java/res/layout/mini_keyboard.xml | 34 --- java/res/layout/more_keys_keyboard.xml | 34 +++ java/res/layout/more_suggestions.xml | 2 +- java/res/values-ar/donottranslate-more-keys.xml | 2 +- java/res/values-land/dimens.xml | 4 +- java/res/values-sw600dp/config.xml | 5 +- java/res/values-sw600dp/dimens.xml | 6 +- java/res/values-sw768dp/config.xml | 5 +- java/res/values-sw768dp/dimens.xml | 6 +- java/res/values/attrs.xml | 19 +- java/res/values/config.xml | 18 +- java/res/values/dimens.xml | 10 +- java/res/values/donottranslate-more-keys.xml | 2 +- java/res/values/styles.xml | 54 ++--- java/res/values/themes-basic-highcontrast.xml | 6 +- java/res/values/themes-basic.xml | 6 +- java/res/values/themes-gingerbread.xml | 6 +- java/res/values/themes-ics.xml | 6 +- java/res/values/themes-stone-bold.xml | 6 +- java/res/values/themes-stone.xml | 6 +- .../kbd_mini_keyboard_template.xml | 26 -- .../kbd_more_keys_keyboard_template.xml | 26 ++ .../res/xml-sw600dp/kbd_mini_keyboard_template.xml | 26 -- .../kbd_more_keys_keyboard_template.xml | 26 ++ .../kbd_mini_keyboard_template.xml | 26 -- .../kbd_more_keys_keyboard_template.xml | 26 ++ .../res/xml-sw768dp/kbd_mini_keyboard_template.xml | 26 -- .../kbd_more_keys_keyboard_template.xml | 26 ++ java/res/xml/kbd_mini_keyboard_template.xml | 26 -- java/res/xml/kbd_more_keys_keyboard_template.xml | 26 ++ java/res/xml/key_styles_common.xml | 2 +- java/src/com/android/inputmethod/keyboard/Key.java | 2 +- .../com/android/inputmethod/keyboard/Keyboard.java | 10 +- .../inputmethod/keyboard/LatinKeyboardView.java | 28 +-- .../android/inputmethod/keyboard/MiniKeyboard.java | 268 -------------------- .../inputmethod/keyboard/MiniKeyboardView.java | 189 --------------- .../inputmethod/keyboard/MoreKeysKeyboard.java | 269 +++++++++++++++++++++ .../inputmethod/keyboard/MoreKeysKeyboardView.java | 189 +++++++++++++++ .../inputmethod/keyboard/ProximityInfo.java | 2 +- 44 files changed, 792 insertions(+), 782 deletions(-) delete mode 100644 java/res/anim/mini_keyboard_fadein.xml delete mode 100644 java/res/anim/mini_keyboard_fadeout.xml create mode 100644 java/res/anim/more_keys_keyboard_fadein.xml create mode 100644 java/res/anim/more_keys_keyboard_fadeout.xml delete mode 100644 java/res/layout/mini_keyboard.xml create mode 100644 java/res/layout/more_keys_keyboard.xml delete mode 100644 java/res/xml-sw600dp-land/kbd_mini_keyboard_template.xml create mode 100644 java/res/xml-sw600dp-land/kbd_more_keys_keyboard_template.xml delete mode 100644 java/res/xml-sw600dp/kbd_mini_keyboard_template.xml create mode 100644 java/res/xml-sw600dp/kbd_more_keys_keyboard_template.xml delete mode 100644 java/res/xml-sw768dp-land/kbd_mini_keyboard_template.xml create mode 100644 java/res/xml-sw768dp-land/kbd_more_keys_keyboard_template.xml delete mode 100644 java/res/xml-sw768dp/kbd_mini_keyboard_template.xml create mode 100644 java/res/xml-sw768dp/kbd_more_keys_keyboard_template.xml delete mode 100644 java/res/xml/kbd_mini_keyboard_template.xml create mode 100644 java/res/xml/kbd_more_keys_keyboard_template.xml delete mode 100644 java/src/com/android/inputmethod/keyboard/MiniKeyboard.java delete mode 100644 java/src/com/android/inputmethod/keyboard/MiniKeyboardView.java create mode 100644 java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java create mode 100644 java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java (limited to 'java') diff --git a/java/proguard.flags b/java/proguard.flags index caf1ea183..5ce0c273c 100644 --- a/java/proguard.flags +++ b/java/proguard.flags @@ -35,6 +35,6 @@ *; } --keep class com.android.inputmethod.keyboard.MiniKeyboard$Builder$MiniKeyboardParams { +-keep class com.android.inputmethod.keyboard.MoreKeysKeyboard$Builder$MoreKeysKeyboardParams { (...); } diff --git a/java/res/anim/mini_keyboard_fadein.xml b/java/res/anim/mini_keyboard_fadein.xml deleted file mode 100644 index f80e8b8de..000000000 --- a/java/res/anim/mini_keyboard_fadein.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - diff --git a/java/res/anim/mini_keyboard_fadeout.xml b/java/res/anim/mini_keyboard_fadeout.xml deleted file mode 100644 index 535b100ae..000000000 --- a/java/res/anim/mini_keyboard_fadeout.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - diff --git a/java/res/anim/more_keys_keyboard_fadein.xml b/java/res/anim/more_keys_keyboard_fadein.xml new file mode 100644 index 000000000..c781f36ad --- /dev/null +++ b/java/res/anim/more_keys_keyboard_fadein.xml @@ -0,0 +1,29 @@ + + + + + + diff --git a/java/res/anim/more_keys_keyboard_fadeout.xml b/java/res/anim/more_keys_keyboard_fadeout.xml new file mode 100644 index 000000000..32fae6bd8 --- /dev/null +++ b/java/res/anim/more_keys_keyboard_fadeout.xml @@ -0,0 +1,29 @@ + + + + + + diff --git a/java/res/layout/mini_keyboard.xml b/java/res/layout/mini_keyboard.xml deleted file mode 100644 index 6964ec5d6..000000000 --- a/java/res/layout/mini_keyboard.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - diff --git a/java/res/layout/more_keys_keyboard.xml b/java/res/layout/more_keys_keyboard.xml new file mode 100644 index 000000000..89161c6b4 --- /dev/null +++ b/java/res/layout/more_keys_keyboard.xml @@ -0,0 +1,34 @@ + + + + + diff --git a/java/res/layout/more_suggestions.xml b/java/res/layout/more_suggestions.xml index 1e59b8931..34f54f974 100644 --- a/java/res/layout/more_suggestions.xml +++ b/java/res/layout/more_suggestions.xml @@ -22,7 +22,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" - style="?attr/miniKeyboardPanelStyle" + style="?attr/moreKeysKeyboardPanelStyle" > "\u060c,\u061b,\u061f,!,:,-,/,\',\",\u0640\u0640\u0640|\u0640,\u064e,\u0650,\u064b,\u064d,\u0670,\u0656,\u0655,\u0654,\u0653,\u0652,\u0651,\u064c,\u064f" - 9 + 9 \u064b "١" "٢" diff --git a/java/res/values-land/dimens.xml b/java/res/values-land/dimens.xml index dcbfe463e..f9cce839a 100644 --- a/java/res/values-land/dimens.xml +++ b/java/res/values-land/dimens.xml @@ -66,7 +66,7 @@ 72dip - 0.336in + 0.336in - -0.280in + -0.280in diff --git a/java/res/values-sw600dp/config.xml b/java/res/values-sw600dp/config.xml index 40c674190..ecc5b7136 100644 --- a/java/res/values-sw600dp/config.xml +++ b/java/res/values-sw600dp/config.xml @@ -39,6 +39,7 @@ Configuration for LatinKeyboardView --> false - - true + + true diff --git a/java/res/values-sw600dp/dimens.xml b/java/res/values-sw600dp/dimens.xml index e393be579..e04609f2a 100644 --- a/java/res/values-sw600dp/dimens.xml +++ b/java/res/values-sw600dp/dimens.xml @@ -40,12 +40,12 @@ 0.0%p - 6dip + 6dip - 15.6mm + 15.6mm - -13.0mm + -13.0mm 6dip diff --git a/java/res/values-sw768dp/config.xml b/java/res/values-sw768dp/config.xml index 98d722aba..c1f9179ee 100644 --- a/java/res/values-sw768dp/config.xml +++ b/java/res/values-sw768dp/config.xml @@ -37,8 +37,9 @@ Configuration for LatinKeyboardView --> false - - true + + true - 15.6mm + 15.6mm - -13.0mm + -13.0mm 6dip diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index 410a94208..86e3fe3cb 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -25,11 +25,11 @@ - - - - - + + + + + @@ -152,8 +152,8 @@ - - + + @@ -232,7 +232,10 @@ been replaced, those remaining entries are appended at the end of moreKeys. --> - + + + + diff --git a/java/res/values/config.xml b/java/res/values/config.xml index c3f8edf8a..cb13ba30b 100644 --- a/java/res/values/config.xml +++ b/java/res/values/config.xml @@ -44,8 +44,8 @@ 100 50 50 - 0 - 100 + 0 + 100 32 16 1100 @@ -69,10 +69,12 @@ 1200 - @integer/config_long_press_key_timeout + + @integer/config_long_press_key_timeout 700 - - false + + false @@ -88,9 +90,11 @@ will be subject to auto-correction. --> 0 - + 0.11 - + 0.03 - 0.396in + 0.396in - -0.330in + -0.330in 0.0in diff --git a/java/res/values/donottranslate-more-keys.xml b/java/res/values/donottranslate-more-keys.xml index d78e41fb1..57a6d6bda 100644 --- a/java/res/values/donottranslate-more-keys.xml +++ b/java/res/values/donottranslate-more-keys.xml @@ -56,7 +56,7 @@ ¢,$,€,£,¥,₱ ":-)|:-) ,:-(|:-( ,;-)|;-) ,:-P|:-P ,=-O|=-O ,:-*|:-* ,:O|:O ,B-)|B-) ,:-$|:-$ ,:-!|:-! ,:-[|:-[ ,O:-)|O:-) ,:-\\\\|:-\\\\ ,:\'(|:\'( ,:-D|:-D " "\\,,\?,!,:,-,\',\",(,),/,;,+,&,\@" - 7 + 7 ".com" diff --git a/java/res/values/styles.xml b/java/res/values/styles.xml index f69078288..b9e8b26a3 100644 --- a/java/res/values/styles.xml +++ b/java/res/values/styles.xml @@ -23,7 +23,7 @@ @dimen/keyboardHeight @fraction/maxKeyboardHeight @fraction/minKeyboardHeight - @xml/kbd_mini_keyboard_template + @xml/kbd_more_keys_keyboard_template @fraction/keyboard_top_padding @fraction/keyboard_bottom_padding @fraction/keyboard_horizontal_edges_padding @@ -60,7 +60,7 @@ @dimen/key_preview_height @fraction/key_preview_text_ratio @integer/config_key_preview_linger_timeout - @layout/mini_keyboard + @layout/more_keys_keyboard @dimen/keyboard_vertical_correction #BB000000 2.75 @@ -76,7 +76,7 @@ @integer/config_long_press_shift_key_timeout @integer/config_long_press_space_key_timeout @integer/config_ignore_special_key_timeout - @bool/config_show_mini_keyboard_at_touched_point + @bool/config_show_more_keys_keyboard_at_touched_point - @@ -322,7 +322,7 @@ #80000000 - - diff --git a/java/res/values/themes-basic-highcontrast.xml b/java/res/values/themes-basic-highcontrast.xml index 0062b2837..19df42ce1 100644 --- a/java/res/values/themes-basic-highcontrast.xml +++ b/java/res/values/themes-basic-highcontrast.xml @@ -19,9 +19,9 @@ @style/Keyboard.HighContrast @style/KeyboardView.HighContrast @style/LatinKeyboardView.HighContrast - @style/MiniKeyboard - @style/MiniKeyboardView - @style/MiniKeyboardPanelStyle + @style/MoreKeysKeyboard + @style/MoreKeysKeyboardView + @style/MoreKeysKeyboardPanelStyle @style/SuggestionsStripBackgroundStyle @style/SuggestionsViewStyle @style/MoreSuggestionsViewStyle diff --git a/java/res/values/themes-basic.xml b/java/res/values/themes-basic.xml index 0786e08fc..5d477206d 100644 --- a/java/res/values/themes-basic.xml +++ b/java/res/values/themes-basic.xml @@ -19,9 +19,9 @@ @style/Keyboard @style/KeyboardView @style/LatinKeyboardView - @style/MiniKeyboard - @style/MiniKeyboardView - @style/MiniKeyboardPanelStyle + @style/MoreKeysKeyboard + @style/MoreKeysKeyboardView + @style/MoreKeysKeyboardPanelStyle @style/SuggestionsStripBackgroundStyle @style/SuggestionsViewStyle @style/MoreSuggestionsViewStyle diff --git a/java/res/values/themes-gingerbread.xml b/java/res/values/themes-gingerbread.xml index 44338d821..a13979818 100644 --- a/java/res/values/themes-gingerbread.xml +++ b/java/res/values/themes-gingerbread.xml @@ -19,9 +19,9 @@ @style/Keyboard.Gingerbread @style/KeyboardView.Gingerbread @style/LatinKeyboardView.Gingerbread - @style/MiniKeyboard.Gingerbread - @style/MiniKeyboardView.Gingerbread - @style/MiniKeyboardPanelStyle + @style/MoreKeysKeyboard.Gingerbread + @style/MoreKeysKeyboardView.Gingerbread + @style/MoreKeysKeyboardPanelStyle @style/SuggestionsStripBackgroundStyle @style/SuggestionsViewStyle @style/MoreSuggestionsViewStyle diff --git a/java/res/values/themes-ics.xml b/java/res/values/themes-ics.xml index dbc8f32e3..e6fd4f451 100644 --- a/java/res/values/themes-ics.xml +++ b/java/res/values/themes-ics.xml @@ -19,9 +19,9 @@ @style/Keyboard.IceCreamSandwich @style/KeyboardView.IceCreamSandwich @style/LatinKeyboardView.IceCreamSandwich - @style/MiniKeyboard.IceCreamSandwich - @style/MiniKeyboardView.IceCreamSandwich - @style/MiniKeyboardPanelStyle.IceCreamSandwich + @style/MoreKeysKeyboard.IceCreamSandwich + @style/MoreKeysKeyboardView.IceCreamSandwich + @style/MoreKeysKeyboardPanelStyle.IceCreamSandwich @style/SuggestionsStripBackgroundStyle.IceCreamSandwich @style/SuggestionsViewStyle.IceCreamSandwich @style/MoreSuggestionsViewStyle.IceCreamSandwich diff --git a/java/res/values/themes-stone-bold.xml b/java/res/values/themes-stone-bold.xml index 60f130d59..47de99e47 100644 --- a/java/res/values/themes-stone-bold.xml +++ b/java/res/values/themes-stone-bold.xml @@ -19,9 +19,9 @@ @style/Keyboard.Stone.Bold @style/KeyboardView.Stone.Bold @style/LatinKeyboardView.Stone.Bold - @style/MiniKeyboard.Stone - @style/MiniKeyboardView.Stone - @style/MiniKeyboardPanelStyle + @style/MoreKeysKeyboard.Stone + @style/MoreKeysKeyboardView.Stone + @style/MoreKeysKeyboardPanelStyle @style/SuggestionsStripBackgroundStyle @style/SuggestionsViewStyle @style/MoreSuggestionsViewStyle diff --git a/java/res/values/themes-stone.xml b/java/res/values/themes-stone.xml index 9aaca3a6c..a0b39e3e6 100644 --- a/java/res/values/themes-stone.xml +++ b/java/res/values/themes-stone.xml @@ -19,9 +19,9 @@ @style/Keyboard.Stone @style/KeyboardView.Stone @style/LatinKeyboardView.Stone - @style/MiniKeyboard.Stone - @style/MiniKeyboardView.Stone - @style/MiniKeyboardPanelStyle + @style/MoreKeysKeyboard.Stone + @style/MoreKeysKeyboardView.Stone + @style/MoreKeysKeyboardPanelStyle @style/SuggestionsStripBackgroundStyle @style/SuggestionsViewStyle @style/MoreSuggestionsViewStyle diff --git a/java/res/xml-sw600dp-land/kbd_mini_keyboard_template.xml b/java/res/xml-sw600dp-land/kbd_mini_keyboard_template.xml deleted file mode 100644 index 8272e02f0..000000000 --- a/java/res/xml-sw600dp-land/kbd_mini_keyboard_template.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - diff --git a/java/res/xml-sw600dp-land/kbd_more_keys_keyboard_template.xml b/java/res/xml-sw600dp-land/kbd_more_keys_keyboard_template.xml new file mode 100644 index 000000000..4d8b446a2 --- /dev/null +++ b/java/res/xml-sw600dp-land/kbd_more_keys_keyboard_template.xml @@ -0,0 +1,26 @@ + + + + + diff --git a/java/res/xml-sw600dp/kbd_mini_keyboard_template.xml b/java/res/xml-sw600dp/kbd_mini_keyboard_template.xml deleted file mode 100644 index 0d5795f6a..000000000 --- a/java/res/xml-sw600dp/kbd_mini_keyboard_template.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - diff --git a/java/res/xml-sw600dp/kbd_more_keys_keyboard_template.xml b/java/res/xml-sw600dp/kbd_more_keys_keyboard_template.xml new file mode 100644 index 000000000..d90a5884e --- /dev/null +++ b/java/res/xml-sw600dp/kbd_more_keys_keyboard_template.xml @@ -0,0 +1,26 @@ + + + + + diff --git a/java/res/xml-sw768dp-land/kbd_mini_keyboard_template.xml b/java/res/xml-sw768dp-land/kbd_mini_keyboard_template.xml deleted file mode 100644 index 85e864a6c..000000000 --- a/java/res/xml-sw768dp-land/kbd_mini_keyboard_template.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - diff --git a/java/res/xml-sw768dp-land/kbd_more_keys_keyboard_template.xml b/java/res/xml-sw768dp-land/kbd_more_keys_keyboard_template.xml new file mode 100644 index 000000000..f593fa944 --- /dev/null +++ b/java/res/xml-sw768dp-land/kbd_more_keys_keyboard_template.xml @@ -0,0 +1,26 @@ + + + + + diff --git a/java/res/xml-sw768dp/kbd_mini_keyboard_template.xml b/java/res/xml-sw768dp/kbd_mini_keyboard_template.xml deleted file mode 100644 index 409c60556..000000000 --- a/java/res/xml-sw768dp/kbd_mini_keyboard_template.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - diff --git a/java/res/xml-sw768dp/kbd_more_keys_keyboard_template.xml b/java/res/xml-sw768dp/kbd_more_keys_keyboard_template.xml new file mode 100644 index 000000000..f89a0a673 --- /dev/null +++ b/java/res/xml-sw768dp/kbd_more_keys_keyboard_template.xml @@ -0,0 +1,26 @@ + + + + + diff --git a/java/res/xml/kbd_mini_keyboard_template.xml b/java/res/xml/kbd_mini_keyboard_template.xml deleted file mode 100644 index ad6cf51fe..000000000 --- a/java/res/xml/kbd_mini_keyboard_template.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - diff --git a/java/res/xml/kbd_more_keys_keyboard_template.xml b/java/res/xml/kbd_more_keys_keyboard_template.xml new file mode 100644 index 000000000..8e977c5ad --- /dev/null +++ b/java/res/xml/kbd_more_keys_keyboard_template.xml @@ -0,0 +1,26 @@ + + + + + diff --git a/java/res/xml/key_styles_common.xml b/java/res/xml/key_styles_common.xml index ab9bc4672..177a62c58 100644 --- a/java/res/xml/key_styles_common.xml +++ b/java/res/xml/key_styles_common.xml @@ -278,6 +278,6 @@ latin:keyHintLabel="@string/keyhintlabel_for_punctuation" latin:keyLabelFlags="hasPopupHint|preserveCase" latin:moreKeys="@string/more_keys_for_punctuation" - latin:maxMoreKeysColumn="@integer/mini_keyboard_column_for_punctuation" + latin:maxMoreKeysColumn="@integer/more_keys_keyboard_column_for_punctuation" latin:backgroundType="functional" /> diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index 6eaa606db..5656c38b4 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -245,7 +245,7 @@ public class Key { mActionFlags = actionFlags; mMoreKeys = moreKeys; mMaxMoreKeysColumn = style.getInt(keyAttr, - R.styleable.Keyboard_Key_maxMoreKeysColumn, params.mMaxMiniKeyboardColumn); + R.styleable.Keyboard_Key_maxMoreKeysColumn, params.mMaxMoreKeysKeyboardColumn); mLabel = adjustCaseOfStringForKeyboardId(style.getString(keyAttr, R.styleable.Keyboard_Key_keyLabel), preserveCase, params.mId); diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index 10e0a5b01..cb6a54569 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -121,8 +121,8 @@ public class Keyboard { /** More keys keyboard template */ public final int mMoreKeysTemplate; - /** Maximum column for mini keyboard */ - public final int mMaxMiniKeyboardColumn; + /** Maximum column for more keys keyboard */ + public final int mMaxMoreKeysKeyboardColumn; /** List of keys and icons in this keyboard */ public final Set mKeys; @@ -143,7 +143,7 @@ public class Keyboard { mMostCommonKeyHeight = params.mMostCommonKeyHeight; mMostCommonKeyWidth = params.mMostCommonKeyWidth; mMoreKeysTemplate = params.mMoreKeysTemplate; - mMaxMiniKeyboardColumn = params.mMaxMiniKeyboardColumn; + mMaxMoreKeysKeyboardColumn = params.mMaxMoreKeysKeyboardColumn; mTopPadding = params.mTopPadding; mVerticalGap = params.mVerticalGap; @@ -226,7 +226,7 @@ public class Keyboard { public int mVerticalGap; public int mMoreKeysTemplate; - public int mMaxMiniKeyboardColumn; + public int mMaxMoreKeysKeyboardColumn; public int GRID_WIDTH; public int GRID_HEIGHT; @@ -770,7 +770,7 @@ public class Keyboard { params.mMoreKeysTemplate = keyboardAttr.getResourceId( R.styleable.Keyboard_moreKeysTemplate, 0); - params.mMaxMiniKeyboardColumn = keyAttr.getInt( + params.mMaxMoreKeysKeyboardColumn = keyAttr.getInt( R.styleable.Keyboard_Key_maxMoreKeysColumn, 5); params.mIconsSet.loadIcons(keyboardAttr); diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index 870c7cb25..88a41579d 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -92,13 +92,13 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke private final Drawable mAutoCorrectionSpacebarLedIcon; private static final int SPACE_LED_LENGTH_PERCENT = 80; - // Mini keyboard + // More keys keyboard private PopupWindow mMoreKeysWindow; private MoreKeysPanel mMoreKeysPanel; private int mMoreKeysPanelPointerTrackerId; private final WeakHashMap mMoreKeysPanelCache = new WeakHashMap(); - private final boolean mConfigShowMiniKeyboardAtTouchedPoint; + private final boolean mConfigShowMoreKeysKeyboardAtTouchedPoint; private final PointerTrackerParams mPointerTrackerParams; private final boolean mIsSpacebarTriggeringPopupByLongPress; @@ -137,7 +137,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke break; case MSG_LONGPRESS_KEY: if (tracker != null) { - keyboardView.openMiniKeyboardIfRequired(tracker.getKey(), tracker); + keyboardView.openMoreKeysKeyboardIfRequired(tracker.getKey(), tracker); } else { KeyboardSwitcher.getInstance().onLongPressTimeout(msg.arg1); } @@ -338,8 +338,8 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke R.styleable.LatinKeyboardView_keyHysteresisDistance, 0); mKeyDetector = new KeyDetector(keyHysteresisDistance); mKeyTimerHandler = new KeyTimerHandler(this, keyTimerParams); - mConfigShowMiniKeyboardAtTouchedPoint = a.getBoolean( - R.styleable.LatinKeyboardView_showMiniKeyboardAtTouchedPoint, false); + mConfigShowMoreKeysKeyboardAtTouchedPoint = a.getBoolean( + R.styleable.LatinKeyboardView_showMoreKeysKeyboardAtTouchedPoint, false); a.recycle(); PointerTracker.setParameters(mPointerTrackerParams); @@ -435,7 +435,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke super.cancelAllMessages(); } - private boolean openMiniKeyboardIfRequired(Key parentKey, PointerTracker tracker) { + private boolean openMoreKeysKeyboardIfRequired(Key parentKey, PointerTracker tracker) { // Check if we have a popup layout specified first. if (mMoreKeysLayout == 0) { return false; @@ -458,19 +458,19 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke if (container == null) throw new NullPointerException(); - final MiniKeyboardView miniKeyboardView = - (MiniKeyboardView)container.findViewById(R.id.mini_keyboard_view); + final MoreKeysKeyboardView moreKeysKeyboardView = + (MoreKeysKeyboardView)container.findViewById(R.id.more_keys_keyboard_view); final Keyboard parentKeyboard = getKeyboard(); - final Keyboard miniKeyboard = new MiniKeyboard.Builder( + final Keyboard moreKeysKeyboard = new MoreKeysKeyboard.Builder( this, parentKeyboard.mMoreKeysTemplate, parentKey, parentKeyboard).build(); - miniKeyboardView.setKeyboard(miniKeyboard); + moreKeysKeyboardView.setKeyboard(moreKeysKeyboard); container.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); - return miniKeyboardView; + return moreKeysKeyboardView; } /** - * Called when a key is long pressed. By default this will open mini keyboard associated + * Called when a key is long pressed. By default this will open more keys keyboard associated * with this key. * @param parentKey the key that was long pressed * @param tracker the pointer tracker which pressed the parent key @@ -524,13 +524,13 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke if (mMoreKeysWindow == null) { mMoreKeysWindow = new PopupWindow(getContext()); mMoreKeysWindow.setBackgroundDrawable(null); - mMoreKeysWindow.setAnimationStyle(R.style.MiniKeyboardAnimation); + mMoreKeysWindow.setAnimationStyle(R.style.MoreKeysKeyboardAnimation); } mMoreKeysPanel = moreKeysPanel; mMoreKeysPanelPointerTrackerId = tracker.mPointerId; final Keyboard keyboard = getKeyboard(); - final int pointX = (mConfigShowMiniKeyboardAtTouchedPoint) ? tracker.getLastX() + final int pointX = (mConfigShowMoreKeysKeyboardAtTouchedPoint) ? tracker.getLastX() : parentKey.mX + parentKey.mWidth / 2; final int pointY = parentKey.mY - keyboard.mVerticalGap; moreKeysPanel.showMoreKeysPanel( diff --git a/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java b/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java deleted file mode 100644 index 4648da1c1..000000000 --- a/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java +++ /dev/null @@ -1,268 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package com.android.inputmethod.keyboard; - -import android.graphics.Paint; - -import com.android.inputmethod.keyboard.internal.KeySpecParser; -import com.android.inputmethod.latin.R; - -public class MiniKeyboard extends Keyboard { - private final int mDefaultKeyCoordX; - - private MiniKeyboard(Builder.MiniKeyboardParams params) { - super(params); - mDefaultKeyCoordX = params.getDefaultKeyCoordX() + params.mDefaultKeyWidth / 2; - } - - public int getDefaultCoordX() { - return mDefaultKeyCoordX; - } - - public static class Builder extends Keyboard.Builder { - private final String[] mMoreKeys; - - public static class MiniKeyboardParams extends Keyboard.Params { - /* package */int mTopRowAdjustment; - public int mNumRows; - public int mNumColumns; - public int mLeftKeys; - public int mRightKeys; // includes default key. - - public MiniKeyboardParams() { - super(); - } - - /* package for test */MiniKeyboardParams(int numKeys, int maxColumns, int keyWidth, - int rowHeight, int coordXInParent, int parentKeyboardWidth) { - super(); - setParameters(numKeys, maxColumns, keyWidth, rowHeight, coordXInParent, - parentKeyboardWidth); - } - - /** - * Set keyboard parameters of mini keyboard. - * - * @param numKeys number of keys in this mini keyboard. - * @param maxColumns number of maximum columns of this mini keyboard. - * @param keyWidth mini keyboard key width in pixel, including horizontal gap. - * @param rowHeight mini keyboard row height in pixel, including vertical gap. - * @param coordXInParent coordinate x of the popup key in parent keyboard. - * @param parentKeyboardWidth parent keyboard width in pixel. - */ - public void setParameters(int numKeys, int maxColumns, int keyWidth, int rowHeight, - int coordXInParent, int parentKeyboardWidth) { - if (parentKeyboardWidth / keyWidth < maxColumns) { - throw new IllegalArgumentException( - "Keyboard is too small to hold mini keyboard: " + parentKeyboardWidth - + " " + keyWidth + " " + maxColumns); - } - mDefaultKeyWidth = keyWidth; - mDefaultRowHeight = rowHeight; - - final int numRows = (numKeys + maxColumns - 1) / maxColumns; - mNumRows = numRows; - final int numColumns = getOptimizedColumns(numKeys, maxColumns); - mNumColumns = numColumns; - - final int numLeftKeys = (numColumns - 1) / 2; - final int numRightKeys = numColumns - numLeftKeys; // including default key. - final int maxLeftKeys = coordXInParent / keyWidth; - final int maxRightKeys = Math.max(1, (parentKeyboardWidth - coordXInParent) - / keyWidth); - int leftKeys, rightKeys; - if (numLeftKeys > maxLeftKeys) { - leftKeys = maxLeftKeys; - rightKeys = numColumns - maxLeftKeys; - } else if (numRightKeys > maxRightKeys) { - leftKeys = numColumns - maxRightKeys; - rightKeys = maxRightKeys; - } else { - leftKeys = numLeftKeys; - rightKeys = numRightKeys; - } - // Shift right if the left edge of mini keyboard is on the edge of parent keyboard - // unless the parent key is on the left edge. - if (leftKeys * keyWidth >= coordXInParent && leftKeys > 0) { - leftKeys--; - rightKeys++; - } - // Shift left if the right edge of mini keyboard is on the edge of parent keyboard - // unless the parent key is on the right edge. - if (rightKeys * keyWidth + coordXInParent >= parentKeyboardWidth && rightKeys > 1) { - leftKeys++; - rightKeys--; - } - mLeftKeys = leftKeys; - mRightKeys = rightKeys; - - // Centering of the top row. - final boolean onEdge = (leftKeys == 0 || rightKeys == 1); - if (numRows < 2 || onEdge || getTopRowEmptySlots(numKeys, numColumns) % 2 == 0) { - mTopRowAdjustment = 0; - } else if (mLeftKeys < mRightKeys - 1) { - mTopRowAdjustment = 1; - } else { - mTopRowAdjustment = -1; - } - - mBaseWidth = mOccupiedWidth = mNumColumns * mDefaultKeyWidth; - // Need to subtract the bottom row's gutter only. - mBaseHeight = mOccupiedHeight = mNumRows * mDefaultRowHeight - mVerticalGap - + mTopPadding + mBottomPadding; - } - - // Return key position according to column count (0 is default). - /* package */int getColumnPos(int n) { - final int col = n % mNumColumns; - if (col == 0) { - // default position. - return 0; - } - int pos = 0; - int right = 1; // include default position key. - int left = 0; - int i = 0; - while (true) { - // Assign right key if available. - if (right < mRightKeys) { - pos = right; - right++; - i++; - } - if (i >= col) - break; - // Assign left key if available. - if (left < mLeftKeys) { - left++; - pos = -left; - i++; - } - if (i >= col) - break; - } - return pos; - } - - private static int getTopRowEmptySlots(int numKeys, int numColumns) { - final int remainingKeys = numKeys % numColumns; - if (remainingKeys == 0) { - return 0; - } else { - return numColumns - remainingKeys; - } - } - - private int getOptimizedColumns(int numKeys, int maxColumns) { - int numColumns = Math.min(numKeys, maxColumns); - while (getTopRowEmptySlots(numKeys, numColumns) >= mNumRows) { - numColumns--; - } - return numColumns; - } - - public int getDefaultKeyCoordX() { - return mLeftKeys * mDefaultKeyWidth; - } - - public int getX(int n, int row) { - final int x = getColumnPos(n) * mDefaultKeyWidth + getDefaultKeyCoordX(); - if (isTopRow(row)) { - return x + mTopRowAdjustment * (mDefaultKeyWidth / 2); - } - return x; - } - - public int getY(int row) { - return (mNumRows - 1 - row) * mDefaultRowHeight + mTopPadding; - } - - public void markAsEdgeKey(Key key, int row) { - if (row == 0) - key.markAsTopEdge(this); - if (isTopRow(row)) - key.markAsBottomEdge(this); - } - - private boolean isTopRow(int rowCount) { - return rowCount == mNumRows - 1; - } - } - - public Builder(KeyboardView view, int xmlId, Key parentKey, Keyboard parentKeyboard) { - super(view.getContext(), new MiniKeyboardParams()); - load(xmlId, parentKeyboard.mId); - - // TODO: Mini keyboard's vertical gap is currently calculated heuristically. - // Should revise the algorithm. - mParams.mVerticalGap = parentKeyboard.mVerticalGap / 2; - mMoreKeys = parentKey.mMoreKeys; - - final int previewWidth = view.mKeyPreviewDrawParams.mPreviewBackgroundWidth; - final int previewHeight = view.mKeyPreviewDrawParams.mPreviewBackgroundHeight; - final int width, height; - // Use pre-computed width and height if these values are available and mini keyboard - // has only one key to mitigate visual flicker between key preview and mini keyboard. - if (view.isKeyPreviewPopupEnabled() && mMoreKeys.length == 1 && previewWidth > 0 - && previewHeight > 0) { - width = previewWidth; - height = previewHeight + mParams.mVerticalGap; - } else { - width = getMaxKeyWidth(view, parentKey.mMoreKeys, mParams.mDefaultKeyWidth); - height = parentKeyboard.mMostCommonKeyHeight; - } - mParams.setParameters(mMoreKeys.length, parentKey.mMaxMoreKeysColumn, width, height, - parentKey.mX + (mParams.mDefaultKeyWidth - width) / 2, view.getMeasuredWidth()); - } - - private static int getMaxKeyWidth(KeyboardView view, String[] moreKeys, int minKeyWidth) { - final int padding = (int) view.getContext().getResources() - .getDimension(R.dimen.mini_keyboard_key_horizontal_padding); - Paint paint = null; - int maxWidth = minKeyWidth; - for (String moreKeySpec : moreKeys) { - final String label = KeySpecParser.getLabel(moreKeySpec); - // 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 width = (int)view.getDefaultLabelWidth(label, paint) + padding; - if (maxWidth < width) { - maxWidth = width; - } - } - } - return maxWidth; - } - - @Override - public MiniKeyboard build() { - final MiniKeyboardParams params = mParams; - for (int n = 0; n < mMoreKeys.length; n++) { - final String moreKeySpec = mMoreKeys[n]; - final int row = n / params.mNumColumns; - final Key key = new Key(mResources, params, moreKeySpec, params.getX(n, row), - params.getY(row), params.mDefaultKeyWidth, params.mDefaultRowHeight); - params.markAsEdgeKey(key, row); - params.onAddKey(key); - } - return new MiniKeyboard(params); - } - } -} diff --git a/java/src/com/android/inputmethod/keyboard/MiniKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MiniKeyboardView.java deleted file mode 100644 index 72d5b6889..000000000 --- a/java/src/com/android/inputmethod/keyboard/MiniKeyboardView.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.inputmethod.keyboard; - -import android.content.Context; -import android.content.res.Resources; -import android.util.AttributeSet; -import android.view.Gravity; -import android.view.View; -import android.widget.PopupWindow; - -import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy; -import com.android.inputmethod.keyboard.PointerTracker.TimerProxy; -import com.android.inputmethod.latin.R; - -/** - * A view that renders a virtual {@link MiniKeyboard}. It handles rendering of keys and detecting - * key presses and touch movements. - */ -public class MiniKeyboardView extends KeyboardView implements MoreKeysPanel { - private final int[] mCoordinates = new int[2]; - - private final KeyDetector mKeyDetector; - - private Controller mController; - private KeyboardActionListener mListener; - private int mOriginX; - private int mOriginY; - - private static final TimerProxy EMPTY_TIMER_PROXY = new TimerProxy.Adapter(); - - private final KeyboardActionListener mMiniKeyboardListener = - new KeyboardActionListener.Adapter() { - @Override - public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) { - mListener.onCodeInput(primaryCode, keyCodes, x, y); - } - - @Override - public void onTextInput(CharSequence text) { - mListener.onTextInput(text); - } - - @Override - public void onCancelInput() { - mListener.onCancelInput(); - } - - @Override - public void onPressKey(int primaryCode) { - mListener.onPressKey(primaryCode); - } - - @Override - public void onReleaseKey(int primaryCode, boolean withSliding) { - mListener.onReleaseKey(primaryCode, withSliding); - } - }; - - public MiniKeyboardView(Context context, AttributeSet attrs) { - this(context, attrs, R.attr.miniKeyboardViewStyle); - } - - public MiniKeyboardView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - - final Resources res = context.getResources(); - mKeyDetector = new MoreKeysDetector( - res.getDimension(R.dimen.mini_keyboard_slide_allowance)); - setKeyPreviewPopupEnabled(false, 0); - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - final Keyboard keyboard = getKeyboard(); - if (keyboard != null) { - final int width = keyboard.mOccupiedWidth + getPaddingLeft() + getPaddingRight(); - final int height = keyboard.mOccupiedHeight + getPaddingTop() + getPaddingBottom(); - setMeasuredDimension(width, height); - } else { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - } - } - - @Override - public void setKeyboard(Keyboard keyboard) { - super.setKeyboard(keyboard); - mKeyDetector.setKeyboard(keyboard, -getPaddingLeft(), - -getPaddingTop() + mVerticalCorrection); - } - - @Override - public KeyDetector getKeyDetector() { - return mKeyDetector; - } - - @Override - public KeyboardActionListener getKeyboardActionListener() { - return mMiniKeyboardListener; - } - - @Override - public DrawingProxy getDrawingProxy() { - return this; - } - - @Override - public TimerProxy getTimerProxy() { - return EMPTY_TIMER_PROXY; - } - - @Override - public void setKeyPreviewPopupEnabled(boolean previewEnabled, int delay) { - // Mini keyboard needs no pop-up key preview displayed, so we pass always false with a - // delay of 0. The delay does not matter actually since the popup is not shown anyway. - super.setKeyPreviewPopupEnabled(false, 0); - } - - @Override - public void showMoreKeysPanel(View parentView, Controller controller, int pointX, int pointY, - PopupWindow window, KeyboardActionListener listener) { - mController = controller; - mListener = listener; - final View container = (View)getParent(); - final MiniKeyboard miniKeyboard = (MiniKeyboard)getKeyboard(); - - parentView.getLocationInWindow(mCoordinates); - final int miniKeyboardLeft = pointX - miniKeyboard.getDefaultCoordX() - + parentView.getPaddingLeft(); - final int x = wrapUp(Math.max(0, Math.min(miniKeyboardLeft, - parentView.getWidth() - miniKeyboard.mOccupiedWidth)) - - container.getPaddingLeft() + mCoordinates[0], - container.getMeasuredWidth(), 0, parentView.getWidth()); - final int y = pointY - - (container.getMeasuredHeight() - container.getPaddingBottom()) - + parentView.getPaddingTop() + mCoordinates[1]; - - window.setContentView(container); - window.setWidth(container.getMeasuredWidth()); - window.setHeight(container.getMeasuredHeight()); - window.showAtLocation(parentView, Gravity.NO_GRAVITY, x, y); - - mOriginX = x + container.getPaddingLeft() - mCoordinates[0]; - mOriginY = y + container.getPaddingTop() - mCoordinates[1]; - } - - private static int wrapUp(int x, int width, int left, int right) { - if (x < left) - return left; - if (x + width > right) - return right - width; - return x; - } - - private boolean mIsDismissing; - - @Override - public boolean dismissMoreKeysPanel() { - if (mIsDismissing) return false; - mIsDismissing = true; - final boolean dismissed = mController.dismissMoreKeysPanel(); - mIsDismissing = false; - return dismissed; - } - - @Override - public int translateX(int x) { - return x - mOriginX; - } - - @Override - public int translateY(int y) { - return y - mOriginY; - } -} diff --git a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java new file mode 100644 index 000000000..83155f719 --- /dev/null +++ b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java @@ -0,0 +1,269 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.android.inputmethod.keyboard; + +import android.graphics.Paint; + +import com.android.inputmethod.keyboard.internal.KeySpecParser; +import com.android.inputmethod.latin.R; + +public class MoreKeysKeyboard extends Keyboard { + private final int mDefaultKeyCoordX; + + private MoreKeysKeyboard(Builder.MoreKeysKeyboardParams params) { + super(params); + mDefaultKeyCoordX = params.getDefaultKeyCoordX() + params.mDefaultKeyWidth / 2; + } + + public int getDefaultCoordX() { + return mDefaultKeyCoordX; + } + + public static class Builder extends Keyboard.Builder { + private final String[] mMoreKeys; + + public static class MoreKeysKeyboardParams extends Keyboard.Params { + /* package */int mTopRowAdjustment; + public int mNumRows; + public int mNumColumns; + public int mLeftKeys; + public int mRightKeys; // includes default key. + + public MoreKeysKeyboardParams() { + super(); + } + + /* package for test */MoreKeysKeyboardParams(int numKeys, int maxColumns, int keyWidth, + int rowHeight, int coordXInParent, int parentKeyboardWidth) { + super(); + setParameters(numKeys, maxColumns, keyWidth, rowHeight, coordXInParent, + parentKeyboardWidth); + } + + /** + * Set keyboard parameters of more keys keyboard. + * + * @param numKeys number of keys in this more keys keyboard. + * @param maxColumns number of maximum columns of this more keys keyboard. + * @param keyWidth more keys keyboard key width in pixel, including horizontal gap. + * @param rowHeight more keys keyboard row height in pixel, including vertical gap. + * @param coordXInParent coordinate x of the key preview in parent keyboard. + * @param parentKeyboardWidth parent keyboard width in pixel. + */ + public void setParameters(int numKeys, int maxColumns, int keyWidth, int rowHeight, + int coordXInParent, int parentKeyboardWidth) { + if (parentKeyboardWidth / keyWidth < maxColumns) { + throw new IllegalArgumentException( + "Keyboard is too small to hold more keys keyboard: " + + parentKeyboardWidth + " " + keyWidth + " " + maxColumns); + } + mDefaultKeyWidth = keyWidth; + mDefaultRowHeight = rowHeight; + + final int numRows = (numKeys + maxColumns - 1) / maxColumns; + mNumRows = numRows; + final int numColumns = getOptimizedColumns(numKeys, maxColumns); + mNumColumns = numColumns; + + final int numLeftKeys = (numColumns - 1) / 2; + final int numRightKeys = numColumns - numLeftKeys; // including default key. + final int maxLeftKeys = coordXInParent / keyWidth; + final int maxRightKeys = Math.max(1, (parentKeyboardWidth - coordXInParent) + / keyWidth); + int leftKeys, rightKeys; + if (numLeftKeys > maxLeftKeys) { + leftKeys = maxLeftKeys; + rightKeys = numColumns - maxLeftKeys; + } else if (numRightKeys > maxRightKeys) { + leftKeys = numColumns - maxRightKeys; + rightKeys = maxRightKeys; + } else { + leftKeys = numLeftKeys; + rightKeys = numRightKeys; + } + // Shift right if the left edge of more keys 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 more keys 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; + } + + mBaseWidth = mOccupiedWidth = mNumColumns * mDefaultKeyWidth; + // Need to subtract the bottom row's gutter only. + mBaseHeight = mOccupiedHeight = mNumRows * mDefaultRowHeight - mVerticalGap + + mTopPadding + mBottomPadding; + } + + // Return key position according to column count (0 is default). + /* package */int getColumnPos(int n) { + final int col = n % mNumColumns; + if (col == 0) { + // default position. + return 0; + } + int pos = 0; + int right = 1; // include default position key. + int left = 0; + int i = 0; + while (true) { + // Assign right key if available. + if (right < mRightKeys) { + pos = right; + right++; + i++; + } + if (i >= col) + break; + // Assign left key if available. + if (left < mLeftKeys) { + left++; + pos = -left; + i++; + } + if (i >= col) + break; + } + return pos; + } + + private static int getTopRowEmptySlots(int numKeys, int numColumns) { + final int remainingKeys = numKeys % numColumns; + if (remainingKeys == 0) { + return 0; + } else { + return numColumns - remainingKeys; + } + } + + private int getOptimizedColumns(int numKeys, int maxColumns) { + int numColumns = Math.min(numKeys, maxColumns); + while (getTopRowEmptySlots(numKeys, numColumns) >= mNumRows) { + numColumns--; + } + return numColumns; + } + + public int getDefaultKeyCoordX() { + return mLeftKeys * mDefaultKeyWidth; + } + + public int getX(int n, int row) { + final int x = getColumnPos(n) * mDefaultKeyWidth + getDefaultKeyCoordX(); + if (isTopRow(row)) { + return x + mTopRowAdjustment * (mDefaultKeyWidth / 2); + } + return x; + } + + public int getY(int row) { + return (mNumRows - 1 - row) * mDefaultRowHeight + mTopPadding; + } + + public void markAsEdgeKey(Key key, int row) { + if (row == 0) + key.markAsTopEdge(this); + if (isTopRow(row)) + key.markAsBottomEdge(this); + } + + private boolean isTopRow(int rowCount) { + return rowCount == mNumRows - 1; + } + } + + public Builder(KeyboardView view, int xmlId, Key parentKey, Keyboard parentKeyboard) { + super(view.getContext(), new MoreKeysKeyboardParams()); + load(xmlId, parentKeyboard.mId); + + // TODO: More keys keyboard's vertical gap is currently calculated heuristically. + // Should revise the algorithm. + mParams.mVerticalGap = parentKeyboard.mVerticalGap / 2; + mMoreKeys = parentKey.mMoreKeys; + + final int previewWidth = view.mKeyPreviewDrawParams.mPreviewBackgroundWidth; + final int previewHeight = view.mKeyPreviewDrawParams.mPreviewBackgroundHeight; + final int width, height; + // Use pre-computed width and height if these values are available and more keys + // keyboard has only one key to mitigate visual flicker between key preview and more + // keys keyboard. + if (view.isKeyPreviewPopupEnabled() && mMoreKeys.length == 1 && previewWidth > 0 + && previewHeight > 0) { + width = previewWidth; + height = previewHeight + mParams.mVerticalGap; + } else { + width = getMaxKeyWidth(view, parentKey.mMoreKeys, mParams.mDefaultKeyWidth); + height = parentKeyboard.mMostCommonKeyHeight; + } + mParams.setParameters(mMoreKeys.length, parentKey.mMaxMoreKeysColumn, width, height, + parentKey.mX + (mParams.mDefaultKeyWidth - width) / 2, view.getMeasuredWidth()); + } + + private static int getMaxKeyWidth(KeyboardView view, String[] moreKeys, int minKeyWidth) { + final int padding = (int) view.getContext().getResources() + .getDimension(R.dimen.more_keys_keyboard_key_horizontal_padding); + Paint paint = null; + int maxWidth = minKeyWidth; + for (String moreKeySpec : moreKeys) { + final String label = KeySpecParser.getLabel(moreKeySpec); + // 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 width = (int)view.getDefaultLabelWidth(label, paint) + padding; + if (maxWidth < width) { + maxWidth = width; + } + } + } + return maxWidth; + } + + @Override + public MoreKeysKeyboard build() { + final MoreKeysKeyboardParams params = mParams; + for (int n = 0; n < mMoreKeys.length; n++) { + final String moreKeySpec = mMoreKeys[n]; + final int row = n / params.mNumColumns; + final Key key = new Key(mResources, params, moreKeySpec, params.getX(n, row), + params.getY(row), params.mDefaultKeyWidth, params.mDefaultRowHeight); + params.markAsEdgeKey(key, row); + params.onAddKey(key); + } + return new MoreKeysKeyboard(params); + } + } +} diff --git a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java new file mode 100644 index 000000000..b030dd95a --- /dev/null +++ b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java @@ -0,0 +1,189 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.inputmethod.keyboard; + +import android.content.Context; +import android.content.res.Resources; +import android.util.AttributeSet; +import android.view.Gravity; +import android.view.View; +import android.widget.PopupWindow; + +import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy; +import com.android.inputmethod.keyboard.PointerTracker.TimerProxy; +import com.android.inputmethod.latin.R; + +/** + * A view that renders a virtual {@link MoreKeysKeyboard}. It handles rendering of keys and + * detecting key presses and touch movements. + */ +public class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel { + private final int[] mCoordinates = new int[2]; + + private final KeyDetector mKeyDetector; + + private Controller mController; + private KeyboardActionListener mListener; + private int mOriginX; + private int mOriginY; + + private static final TimerProxy EMPTY_TIMER_PROXY = new TimerProxy.Adapter(); + + private final KeyboardActionListener mMoreKeysKeyboardListener = + new KeyboardActionListener.Adapter() { + @Override + public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) { + mListener.onCodeInput(primaryCode, keyCodes, x, y); + } + + @Override + public void onTextInput(CharSequence text) { + mListener.onTextInput(text); + } + + @Override + public void onCancelInput() { + mListener.onCancelInput(); + } + + @Override + public void onPressKey(int primaryCode) { + mListener.onPressKey(primaryCode); + } + + @Override + public void onReleaseKey(int primaryCode, boolean withSliding) { + mListener.onReleaseKey(primaryCode, withSliding); + } + }; + + public MoreKeysKeyboardView(Context context, AttributeSet attrs) { + this(context, attrs, R.attr.moreKeysKeyboardViewStyle); + } + + public MoreKeysKeyboardView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + + final Resources res = context.getResources(); + mKeyDetector = new MoreKeysDetector( + res.getDimension(R.dimen.more_keys_keyboard_slide_allowance)); + setKeyPreviewPopupEnabled(false, 0); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + final Keyboard keyboard = getKeyboard(); + if (keyboard != null) { + final int width = keyboard.mOccupiedWidth + getPaddingLeft() + getPaddingRight(); + final int height = keyboard.mOccupiedHeight + getPaddingTop() + getPaddingBottom(); + setMeasuredDimension(width, height); + } else { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + } + } + + @Override + public void setKeyboard(Keyboard keyboard) { + super.setKeyboard(keyboard); + mKeyDetector.setKeyboard(keyboard, -getPaddingLeft(), + -getPaddingTop() + mVerticalCorrection); + } + + @Override + public KeyDetector getKeyDetector() { + return mKeyDetector; + } + + @Override + public KeyboardActionListener getKeyboardActionListener() { + return mMoreKeysKeyboardListener; + } + + @Override + public DrawingProxy getDrawingProxy() { + return this; + } + + @Override + public TimerProxy getTimerProxy() { + return EMPTY_TIMER_PROXY; + } + + @Override + public void setKeyPreviewPopupEnabled(boolean previewEnabled, int delay) { + // More keys keyboard needs no pop-up key preview displayed, so we pass always false with a + // delay of 0. The delay does not matter actually since the popup is not shown anyway. + super.setKeyPreviewPopupEnabled(false, 0); + } + + @Override + public void showMoreKeysPanel(View parentView, Controller controller, int pointX, int pointY, + PopupWindow window, KeyboardActionListener listener) { + mController = controller; + mListener = listener; + final View container = (View)getParent(); + final MoreKeysKeyboard moreKeysKeyboard = (MoreKeysKeyboard)getKeyboard(); + + parentView.getLocationInWindow(mCoordinates); + final int moreKeysKeyboardLeft = pointX - moreKeysKeyboard.getDefaultCoordX() + + parentView.getPaddingLeft(); + final int x = wrapUp(Math.max(0, Math.min(moreKeysKeyboardLeft, + parentView.getWidth() - moreKeysKeyboard.mOccupiedWidth)) + - container.getPaddingLeft() + mCoordinates[0], + container.getMeasuredWidth(), 0, parentView.getWidth()); + final int y = pointY + - (container.getMeasuredHeight() - container.getPaddingBottom()) + + parentView.getPaddingTop() + mCoordinates[1]; + + window.setContentView(container); + window.setWidth(container.getMeasuredWidth()); + window.setHeight(container.getMeasuredHeight()); + window.showAtLocation(parentView, Gravity.NO_GRAVITY, x, y); + + mOriginX = x + container.getPaddingLeft() - mCoordinates[0]; + mOriginY = y + container.getPaddingTop() - mCoordinates[1]; + } + + private static int wrapUp(int x, int width, int left, int right) { + if (x < left) + return left; + if (x + width > right) + return right - width; + return x; + } + + private boolean mIsDismissing; + + @Override + public boolean dismissMoreKeysPanel() { + if (mIsDismissing) return false; + mIsDismissing = true; + final boolean dismissed = mController.dismissMoreKeysPanel(); + mIsDismissing = false; + return dismissed; + } + + @Override + public int translateX(int x) { + return x - mOriginX; + } + + @Override + public int translateY(int y) { + return y - mOriginY; + } +} diff --git a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java index 2d1a0083d..41e7ef435 100644 --- a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java +++ b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java @@ -59,7 +59,7 @@ public class ProximityInfo { mKeyHeight = keyHeight; mGridNeighbors = new Key[mGridSize][]; if (minWidth == 0 || height == 0) { - // No proximity required. Keyboard might be mini keyboard. + // No proximity required. Keyboard might be more keys keyboard. return; } computeNearestNeighbors(keyWidth, keys, touchPositionCorrection, additionalProximityChars); -- cgit v1.2.3-83-g751a