diff --git a/java/res/layout/emoji_keyboard_view.xml b/java/res/layout/emoji_keyboard_view.xml index ccbcfdc6fb4ab3364125fabea7bd034076b48267..5fee419d0bcb6925a5ba0c4e115137fe1e50f2c5 100644 --- a/java/res/layout/emoji_keyboard_view.xml +++ b/java/res/layout/emoji_keyboard_view.xml @@ -76,18 +76,24 @@ android:id="@+id/emoji_action_bar" android:orientation="horizontal" android:layout_width="match_parent" - android:layout_height="@dimen/suggestions_strip_height" + android:layout_height="0dip" + android:layout_weight="1" > <ImageButton android:id="@+id/emoji_keyboard_alphabet" android:layout_width="0dip" - android:layout_weight="0.825" + android:layout_weight="0.15" android:layout_height="match_parent" android:src="@drawable/ic_ime_light" /> + <ImageButton + android:id="@+id/emoji_keyboard_space" + android:layout_width="0dip" + android:layout_weight="0.70" + android:layout_height="match_parent" /> <ImageButton android:id="@+id/emoji_keyboard_send" android:layout_width="0dip" - android:layout_weight="0.125" + android:layout_weight="0.15" android:layout_height="match_parent" android:src="@drawable/sym_keyboard_return_holo" /> </LinearLayout> diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index 2a5334f9532aec53053d4c0264ff0d90b10d74df..09782143f966316447983b62474d31bb2919b74b 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -45,6 +45,8 @@ possible states: normal, pressed, checkable, checkable+pressed, checkable+checked, checkable+checked+pressed. --> <attr name="keyBackground" format="reference" /> + <!-- Image for the functional key used in Emoji layout. --> + <attr name="keyBackgroundEmojiFunctional" format="reference" /> <!-- Horizontal padding of left/right aligned key label to the edge of the key. --> <attr name="keyLabelHorizontalPadding" format="dimension" /> diff --git a/java/res/values/themes-ics.xml b/java/res/values/themes-ics.xml index f3b6b13212cd09346f2fb945a62c8461655b4bb0..19fb4fd272183e8085e066862fd619908f7ee726 100644 --- a/java/res/values/themes-ics.xml +++ b/java/res/values/themes-ics.xml @@ -103,7 +103,7 @@ name="EmojiKeyboardView.ICS" parent="KeyboardView.ICS" > - <item name="keyBackground">@drawable/btn_keyboard_key_functional_ics</item> + <item name="keyBackgroundEmojiFunctional">@drawable/btn_keyboard_key_functional_ics</item> <item name="emojiTabLabelColor">@color/emoji_tab_label_color_ics</item> </style> <style diff --git a/java/src/com/android/inputmethod/keyboard/EmojiKeyboardView.java b/java/src/com/android/inputmethod/keyboard/EmojiKeyboardView.java index 25ff8d0ce70eb58abc1ff63209963a710ede69a2..3f2fdecf74219db7ab386faa2db8caf350bb15ca 100644 --- a/java/src/com/android/inputmethod/keyboard/EmojiKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/EmojiKeyboardView.java @@ -61,6 +61,7 @@ public final class EmojiKeyboardView extends LinearLayout implements OnTabChange ViewPager.OnPageChangeListener, View.OnClickListener, ScrollKeyboardView.OnKeyClickListener { private final int mKeyBackgroundId; + private final int mEmojiFunctionalKeyBackgroundId; private final ColorStateList mTabLabelColor; private final EmojiKeyboardAdapter mEmojiKeyboardAdapter; @@ -116,6 +117,8 @@ public final class EmojiKeyboardView extends LinearLayout implements OnTabChange R.styleable.KeyboardView, defStyle, R.style.KeyboardView); mKeyBackgroundId = keyboardViewAttr.getResourceId( R.styleable.KeyboardView_keyBackground, 0); + mEmojiFunctionalKeyBackgroundId = keyboardViewAttr.getResourceId( + R.styleable.KeyboardView_keyBackgroundEmojiFunctional, 0); keyboardViewAttr.recycle(); final TypedArray emojiKeyboardViewAttr = context.obtainStyledAttributes(attrs, R.styleable.EmojiKeyboardView, defStyle, R.style.EmojiKeyboardView); @@ -126,10 +129,9 @@ public final class EmojiKeyboardView extends LinearLayout implements OnTabChange context, null /* editorInfo */); final Resources res = context.getResources(); builder.setSubtype(SubtypeSwitcher.getInstance().getEmojiSubtype()); - // TODO: Make Keyboard height variable. builder.setKeyboardGeometry(ResourceUtils.getDefaultKeyboardWidth(res), - (int)(ResourceUtils.getDefaultKeyboardHeight(res) - - res.getDimension(R.dimen.suggestions_strip_height))); + (int)ResourceUtils.getDefaultKeyboardHeight(res) + + res.getDimensionPixelSize(R.dimen.suggestions_strip_height)); builder.setOptions(false, false, false /* lanuageSwitchKeyEnabled */); final KeyboardLayoutSet layoutSet = builder.build(); mEmojiKeyboardAdapter = new EmojiKeyboardAdapter(layoutSet, this); @@ -165,7 +167,6 @@ public final class EmojiKeyboardView extends LinearLayout implements OnTabChange R.layout.emoji_keyboard_tab_label, null); textView.setText(sCategoryLabel[category]); textView.setTextColor(mTabLabelColor); - textView.setBackgroundResource(mKeyBackgroundId); tspec.setIndicator(textView); } host.addTab(tspec); @@ -189,27 +190,33 @@ public final class EmojiKeyboardView extends LinearLayout implements OnTabChange mEmojiPager.setAdapter(mEmojiKeyboardAdapter); mEmojiPager.setOnPageChangeListener(this); mEmojiPager.setOffscreenPageLimit(0); - final ViewGroup.LayoutParams lp = mEmojiPager.getLayoutParams(); final Resources res = getResources(); - lp.height = ResourceUtils.getDefaultKeyboardHeight(res) - - res.getDimensionPixelSize(R.dimen.suggestions_strip_height); - mEmojiPager.setLayoutParams(lp); + final EmojiLayoutParams emojiLp = new EmojiLayoutParams(res); + emojiLp.setPagerProps(mEmojiPager); // TODO: Record current category. final int category = CATEGORY_PEOPLE; setCurrentCategory(category, true /* force */); + final LinearLayout actionBar = (LinearLayout)findViewById(R.id.emoji_action_bar); + emojiLp.setActionBarProps(actionBar); + // TODO: Implement auto repeat, using View.OnTouchListener? - final View deleteKey = findViewById(R.id.emoji_keyboard_delete); - deleteKey.setBackgroundResource(mKeyBackgroundId); + final ImageView deleteKey = (ImageView)findViewById(R.id.emoji_keyboard_delete); + deleteKey.setBackgroundResource(mEmojiFunctionalKeyBackgroundId); deleteKey.setTag(Constants.CODE_DELETE); deleteKey.setOnClickListener(this); - final View alphabetKey = findViewById(R.id.emoji_keyboard_alphabet); - alphabetKey.setBackgroundResource(mKeyBackgroundId); + final ImageView alphabetKey = (ImageView)findViewById(R.id.emoji_keyboard_alphabet); + alphabetKey.setBackgroundResource(mEmojiFunctionalKeyBackgroundId); alphabetKey.setTag(Constants.CODE_SWITCH_ALPHA_SYMBOL); alphabetKey.setOnClickListener(this); - final View sendKey = findViewById(R.id.emoji_keyboard_send); - sendKey.setBackgroundResource(mKeyBackgroundId); + final ImageView spaceKey = (ImageView)findViewById(R.id.emoji_keyboard_space); + spaceKey.setBackgroundResource(mKeyBackgroundId); + spaceKey.setTag(Constants.CODE_SPACE); + spaceKey.setOnClickListener(this); + emojiLp.setKeyProps(spaceKey); + final ImageView sendKey = (ImageView)findViewById(R.id.emoji_keyboard_send); + sendKey.setBackgroundResource(mEmojiFunctionalKeyBackgroundId); sendKey.setTag(Constants.CODE_ENTER); sendKey.setOnClickListener(this); } diff --git a/java/src/com/android/inputmethod/keyboard/EmojiLayoutParams.java b/java/src/com/android/inputmethod/keyboard/EmojiLayoutParams.java new file mode 100644 index 0000000000000000000000000000000000000000..6486fc9db47913c794416bbc942239d7e154d5ce --- /dev/null +++ b/java/src/com/android/inputmethod/keyboard/EmojiLayoutParams.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2013 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 com.android.inputmethod.latin.utils.ResourceUtils; + +import android.content.res.Resources; +import android.support.v4.view.ViewPager; +import android.widget.ImageView; +import android.widget.LinearLayout; + +public class EmojiLayoutParams { + private static final int DEFAULT_KEYBOARD_ROWS = 4; + + public final int mEmojiKeyboardHeight; + public final int mEmojiActionBarHeight; + public final int mKeyVerticalGap; + private final int mKeyHorizontalGap; + private final int mBottomPadding; + private final int mTopPadding; + + public EmojiLayoutParams(Resources res) { + final int defaultKeyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res); + final int defaultKeyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res); + mKeyVerticalGap = (int) res.getFraction(R.fraction.key_bottom_gap_ics, + (int) defaultKeyboardHeight, (int) defaultKeyboardHeight); + mBottomPadding = (int) res.getFraction(R.fraction.keyboard_bottom_padding_ics, + (int) defaultKeyboardHeight, (int) defaultKeyboardHeight); + mTopPadding = (int) res.getFraction(R.fraction.keyboard_top_padding_ics, + (int) defaultKeyboardHeight, (int) defaultKeyboardHeight); + mKeyHorizontalGap = (int) (res.getFraction(R.fraction.key_horizontal_gap_ics, + defaultKeyboardWidth, defaultKeyboardWidth)); + final int baseheight = defaultKeyboardHeight - mBottomPadding - mTopPadding + + mKeyVerticalGap; + mEmojiActionBarHeight = ((int) baseheight) / DEFAULT_KEYBOARD_ROWS + - (mKeyVerticalGap - mBottomPadding) / 2; + mEmojiKeyboardHeight = defaultKeyboardHeight - mEmojiActionBarHeight; + } + + public void setPagerProps(ViewPager vp) { + final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) vp.getLayoutParams(); + lp.height = mEmojiKeyboardHeight - mKeyVerticalGap / 2; + lp.bottomMargin = mKeyVerticalGap / 2; + vp.setLayoutParams(lp); + } + + public void setActionBarProps(LinearLayout ll) { + final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) ll.getLayoutParams(); + lp.height = mEmojiActionBarHeight; + lp.topMargin = 0; + lp.bottomMargin = mBottomPadding; + ll.setLayoutParams(lp); + } + + public void setKeyProps(ImageView ib) { + final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) ib.getLayoutParams(); + lp.leftMargin = mKeyHorizontalGap / 2; + lp.rightMargin = mKeyHorizontalGap / 2; + ib.setLayoutParams(lp); + } +}