From 5ef4fccbb90491e1f6c2e87b47ebf9f3659949fb Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 29 Feb 2012 22:21:57 +0900 Subject: [PATCH] Support dividers in MoreKeysKeyboard Bug: 6080806 Change-Id: Iacd78c6aab6abf948717d34da7489a79c41316d2 --- java/res/drawable-hdpi/more_keys_divider.png | Bin 0 -> 1034 bytes java/res/drawable-mdpi/more_keys_divider.png | Bin 0 -> 2940 bytes java/res/drawable-xhdpi/more_keys_divider.png | Bin 0 -> 1053 bytes java/res/xml/key_styles_enter.xml | 2 +- .../com/android/inputmethod/keyboard/Key.java | 9 +++ .../keyboard/MoreKeysKeyboard.java | 64 +++++++++++++++--- .../latin/suggestions/MoreSuggestions.java | 4 +- ...oreKeysKeyboardBuilderFixedOrderTests.java | 2 +- .../MoreKeysKeyboardBuilderTests.java | 2 +- 9 files changed, 69 insertions(+), 14 deletions(-) create mode 100644 java/res/drawable-hdpi/more_keys_divider.png create mode 100644 java/res/drawable-mdpi/more_keys_divider.png create mode 100644 java/res/drawable-xhdpi/more_keys_divider.png diff --git a/java/res/drawable-hdpi/more_keys_divider.png b/java/res/drawable-hdpi/more_keys_divider.png new file mode 100644 index 0000000000000000000000000000000000000000..a5912f95cdb712d78efd974fe53e3981984690a6 GIT binary patch literal 1034 zcmbVLPixdb6i+QksTT35c$lUr7To;pZjzy~Z2q+irY_qB7f)uBX*YC}36p6z?WN#F z{0O3W@#3i;Ko5QZr5{7^BzP(wTqoO2^-y~-kj%Wv@BM!7y?O6tdvkqZ{`Ne_aSN>t zr^D7O?A7M3vhTf_*N`nUd1u|?j!*7<%wSbHuK{NnGGE8$= znEZqnvVD0h@?Zj?yC&Z(1wqem0~-?r>Vi}YrG^9=vLLG~nx;JfiX=;-q=>RolQpO+ zP?Es(;h7qVwqeKdrdrH0`2nRF6vfeKB#cx6lO0hu45Q>wlo~_S@`IEHMJ>&jDh3DT zA&D~@;}n#PK_Bl?lV_2hrI2L4e@>j{(?YS5iA9i!vLJ~`Qsy;5=d^?VgmED{?;d1G z?4TU)kq|NXQsvBQcezjrWYNIKBxaWq3>_TqB`BpW$K=@`A&Mi|Fm&BjbWgGrt)a_u z)AJl%m8H62xSFfk6~{%smS^d8-LRXM%pS+HT*Ym=s_r<7>e;SW`L@!W25E>Y-I(c4 zeXUDEEi)ECAV={M|^ zrei6d`memte53!VnaF|>%jWp2S*jz}f#vqR^_g)#JSb%oL)d8idVB2y8>>a?_UIPg zrlWu$Zk+_#AP#Mu?ju4G0ry)eMZ@LMi=Vd`_-@N-c8fRt)A4w1c1~@doF0As@@o9< h`cwJ+O~0Jd@pzW|eB)?2T5SI)?UuXg99z$x{{~vWK!E@N literal 0 HcmV?d00001 diff --git a/java/res/drawable-mdpi/more_keys_divider.png b/java/res/drawable-mdpi/more_keys_divider.png new file mode 100644 index 0000000000000000000000000000000000000000..a46284f218c2dd3ffd3000f6c7d619eac71cb68e GIT binary patch literal 2940 zcmV-?3xo8DP)9)Gc>Uwq5=^` zLdiiLn+!5)wxpu}JlQBip_vQ~8E<-M1e-ydgvYoERMJ!kKI*17T^B0GzjoyKE}SbXLTb{bpEJtE$kCFF=0@fUGX7MGJP;#(rtOckbaMf_GAo5o>g z0)Qfk?E(%fNyMfiCh@~U+(f(-030dtD~|t)1)Lm#_)>1^8M%CJVv>Na%hIEp+1fJb z-kj`IjzC}(#AKx~`E0sddRhjPmkYq+oj*%PTwA)R$kt}I*49Sm#%5m?>c4LOO^JKE zNUwrF_Y9)-eX;$OUwSIQ_o0dBB}pL2 zuro2q&dxUGa#+UVg8rfZ>F_u7)%T3W>Ha7W-JO%b6s8L3;<~ZYQ`3cfdS(Wb#i1Mh zd5HgU;9sA^Focu9;d6MRh;Y%Aae0ZNcJtU=0XLmT=koqj6aQh@pR_pFB2gMX0cxx< zkQ$%@4-!K8&?cw^Du=3}I;aWy9y$eGfUZJ=&^>4rnu30Z-opq?f~l}F ztPPvM4A=$sgTvsJa3Z`K&Vvi#?Qj)b47|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~EPhDeN>$q-xy}i$> zuk9zRpW6DZ``ZU>20Cxp-sl=!I(T--Y3RaD_nVh*`P{mGd)e*5JIn9f9gZ0uxy!yg zc`x0kG~(0%d4Z_dB<%|yAY*8C zZfk61ZXh!FfcGUFhw~q zFfcGTH8U_UFfcGhK{hZjFfcGPK{+@uFfcGNH#SD2_KkZ0001F$MObuGZ)S9NVRB^v zM{;3sXlY|ZZ*F#Fa&%>KASg+0bY*NQcZd2J0000ZNkl5LZ7>*RB)btdT{!3aXO47Oeff{xb&7QzrzIiV5=H38H_PLvlEMY##N6&U))vUTH(qX%%BRO?PR&867UCVJx-$s%VKM7!| z8&Tb{uX(PoZei#Xgxd)9%L-`r5J6cFrNCOR0?!Ykq_B(UIk~M3akK+N7o!-A@~cN@ z>DR15z4_K?XjC%rf@VUKCg;*@2iq3~n|O0{gcHkAKcmu-dTe?R>v`JRB}fOv}@gUp~Kk zI(=j9AXL*&Oy_9$T;6<}Ka)SqUZ4B1puf0Z^!ac&!92WpR1x2=U8N?|a8~U@^TDIv Dqen@v literal 0 HcmV?d00001 diff --git a/java/res/xml/key_styles_enter.xml b/java/res/xml/key_styles_enter.xml index 61efb89b6..03bcb8620 100644 --- a/java/res/xml/key_styles_enter.xml +++ b/java/res/xml/key_styles_enter.xml @@ -49,7 +49,7 @@ + latin:moreKeys="!fixedColumnOrder!2,!needsDividers!,@string/action_previous_as_more_key,@string/action_next_as_more_key" /> { private final Key mParentKey; + private final Drawable mDivider; private static final float LABEL_PADDING_RATIO = 0.2f; + private static final float DIVIDER_RATIO = 0.2f; public static class MoreKeysKeyboardParams extends Keyboard.Params { public boolean mIsFixedOrder; @@ -47,6 +51,8 @@ public class MoreKeysKeyboard extends Keyboard { public int mTopKeys; public int mLeftKeys; public int mRightKeys; // includes default key. + public int mDividerWidth; + public int mColumnWidth; public MoreKeysKeyboardParams() { super(); @@ -62,9 +68,11 @@ public class MoreKeysKeyboard extends Keyboard { * @param coordXInParent coordinate x of the key preview in parent keyboard. * @param parentKeyboardWidth parent keyboard width in pixel. * @param isFixedColumnOrder if true, more keys should be laid out in fixed order. + * @param dividerWidth width of divider, zero for no dividers. */ public void setParameters(int numKeys, int maxColumns, int keyWidth, int rowHeight, - int coordXInParent, int parentKeyboardWidth, boolean isFixedColumnOrder) { + int coordXInParent, int parentKeyboardWidth, boolean isFixedColumnOrder, + int dividerWidth) { mIsFixedOrder = isFixedColumnOrder; if (parentKeyboardWidth / keyWidth < maxColumns) { throw new IllegalArgumentException( @@ -116,7 +124,9 @@ public class MoreKeysKeyboard extends Keyboard { // Adjustment of the top row. mTopRowAdjustment = mIsFixedOrder ? getFixedOrderTopRowAdjustment() : getAutoOrderTopRowAdjustment(); - mBaseWidth = mOccupiedWidth = mNumColumns * mDefaultKeyWidth; + mDividerWidth = dividerWidth; + mColumnWidth = mDefaultKeyWidth + mDividerWidth; + mBaseWidth = mOccupiedWidth = mNumColumns * mColumnWidth - mDividerWidth; // Need to subtract the bottom row's gutter only. mBaseHeight = mOccupiedHeight = mNumRows * mDefaultRowHeight - mVerticalGap + mTopPadding + mBottomPadding; @@ -214,13 +224,13 @@ public class MoreKeysKeyboard extends Keyboard { } public int getDefaultKeyCoordX() { - return mLeftKeys * mDefaultKeyWidth; + return mLeftKeys * mColumnWidth; } public int getX(int n, int row) { - final int x = getColumnPos(n) * mDefaultKeyWidth + getDefaultKeyCoordX(); + final int x = getColumnPos(n) * mColumnWidth + getDefaultKeyCoordX(); if (isTopRow(row)) { - return x + mTopRowAdjustment * (mDefaultKeyWidth / 2); + return x + mTopRowAdjustment * (mColumnWidth / 2); } return x; } @@ -267,9 +277,19 @@ public class MoreKeysKeyboard extends Keyboard { width = getMaxKeyWidth(view, parentKey, mParams.mDefaultKeyWidth); height = parentKeyboard.mMostCommonKeyHeight; } + final int dividerWidth; + if (parentKey.needsDividersInMoreKeys()) { + mDivider = mResources.getDrawable(R.drawable.more_keys_divider); + // TODO: Drawable itself should have an alpha value. + mDivider.setAlpha(128); + dividerWidth = (int)(width * DIVIDER_RATIO); + } else { + mDivider = null; + dividerWidth = 0; + } mParams.setParameters(parentKey.mMoreKeys.length, parentKey.getMoreKeysColumn(), width, height, parentKey.mX + parentKey.mWidth / 2, view.getMeasuredWidth(), - parentKey.isFixedColumnOrderMoreKeys()); + parentKey.isFixedColumnOrderMoreKeys(), dividerWidth); } private static int getMaxKeyWidth(KeyboardView view, Key parentKey, int minKeyWidth) { @@ -295,6 +315,21 @@ public class MoreKeysKeyboard extends Keyboard { return maxWidth; } + private static class MoreKeyDivider extends Key.Spacer { + private final Drawable mIcon; + + public MoreKeyDivider(MoreKeysKeyboardParams params, Drawable icon, int x, int y) { + super(params, x, y, params.mDividerWidth, params.mDefaultRowHeight); + mIcon = icon; + } + + @Override + public Drawable getIcon(KeyboardIconsSet iconSet) { + // KeyboardIconsSet is unused. Use the icon that has been passed to the constructor. + return mIcon; + } + } + @Override public MoreKeysKeyboard build() { final MoreKeysKeyboardParams params = mParams; @@ -306,11 +341,22 @@ public class MoreKeysKeyboard extends Keyboard { for (int n = 0; n < moreKeys.length; n++) { final String moreKeySpec = moreKeys[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, - moreKeyFlags); + final int x = params.getX(n, row); + final int y = params.getY(row); + final Key key = new Key(mResources, params, moreKeySpec, x, y, + params.mDefaultKeyWidth, params.mDefaultRowHeight, moreKeyFlags); params.markAsEdgeKey(key, row); params.onAddKey(key); + + final int pos = params.getColumnPos(n); + // The "pos" value represents the offset from the default position. Negative means + // left of the default position. + if (params.mDividerWidth > 0 && pos != 0) { + final int dividerX = (pos > 0) ? x - params.mDividerWidth + : x + params.mDefaultKeyWidth; + final Key divider = new MoreKeyDivider(params, mDivider, dividerX, y); + params.onAddKey(divider); + } } return new MoreKeysKeyboard(params); } diff --git a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java index 0bd6abe09..cb1b49c67 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java +++ b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java @@ -34,7 +34,7 @@ import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; public class MoreSuggestions extends Keyboard { public static final int SUGGESTION_CODE_BASE = 1024; - private MoreSuggestions(Builder.MoreSuggestionsParam params) { + MoreSuggestions(Builder.MoreSuggestionsParam params) { super(params); } @@ -63,7 +63,7 @@ public class MoreSuggestions extends Keyboard { paint.setAntiAlias(true); final Resources res = view.getContext().getResources(); mDivider = res.getDrawable(R.drawable.more_suggestions_divider); - // TODO: Drawable itself should has an alpha value. + // TODO: Drawable itself should have an alpha value. mDivider.setAlpha(128); mDividerWidth = mDivider.getIntrinsicWidth(); final int padding = (int) res.getDimension( diff --git a/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderFixedOrderTests.java b/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderFixedOrderTests.java index afd3df40b..5c6c83432 100644 --- a/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderFixedOrderTests.java +++ b/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderFixedOrderTests.java @@ -45,7 +45,7 @@ public class MoreKeysKeyboardBuilderFixedOrderTests extends AndroidTestCase { int coordXInParnet) { final MoreKeysKeyboardParams params = new MoreKeysKeyboardParams(); params.setParameters(numKeys, columnNum, WIDTH, HEIGHT, coordXInParnet, KEYBOARD_WIDTH, - /* isFixedOrderColumn */true); + /* isFixedOrderColumn */true, /* dividerWidth */0); return params; } diff --git a/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderTests.java b/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderTests.java index 456247bae..31f0e0fef 100644 --- a/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderTests.java +++ b/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderTests.java @@ -45,7 +45,7 @@ public class MoreKeysKeyboardBuilderTests extends AndroidTestCase { int coordXInParnet) { final MoreKeysKeyboardParams params = new MoreKeysKeyboardParams(); params.setParameters(numKeys, maxColumns, WIDTH, HEIGHT, coordXInParnet, KEYBOARD_WIDTH, - /* isFixedOrderColumn */false); + /* isFixedOrderColumn */false, /* dividerWidth */0); return params; }