Separate functional key background from normal one

This CL also moves spacebarBackground attribute from MainKeyboardView
to KeyboardView.

This CL must be checked in together with I48c383ca97.

Bug: 14419121
Change-Id: Id356d0086a8fb21375fb5c66076873258fb3d63e
main
Tadashi G. Takaoka 2014-05-14 15:30:37 +09:00
parent ead058b002
commit c1e6100bde
12 changed files with 81 additions and 102 deletions

View File

@ -15,12 +15,6 @@
--> -->
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Functional keys. -->
<item android:state_single="true" android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_key_dark_pressed_ics" />
<item android:state_single="true"
android:drawable="@drawable/btn_keyboard_key_dark_normal_holo" />
<!-- Action keys. --> <!-- Action keys. -->
<item android:state_active="true" android:state_pressed="true" <item android:state_active="true" android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_key_dark_pressed_ics" /> android:drawable="@drawable/btn_keyboard_key_dark_pressed_ics" />

View File

@ -15,12 +15,6 @@
--> -->
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Functional keys. -->
<item android:state_single="true" android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_key_dark_pressed_klp" />
<item android:state_single="true"
android:drawable="@drawable/btn_keyboard_key_dark_normal_holo" />
<!-- Action keys. --> <!-- Action keys. -->
<item android:state_active="true" android:state_pressed="true" <item android:state_active="true" android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_key_dark_pressed_klp" /> android:drawable="@drawable/btn_keyboard_key_dark_pressed_klp" />

View File

@ -15,12 +15,6 @@
--> -->
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Functional keys. -->
<item android:state_single="true" android:state_pressed="true"
android:drawable="@color/key_background_pressed_lmp" />
<item android:state_single="true"
android:drawable="@color/key_background_lmp" />
<!-- Action keys. --> <!-- Action keys. -->
<item android:state_active="true" android:state_pressed="true" <item android:state_active="true" android:state_pressed="true"
android:drawable="@color/key_background_pressed_lmp" /> android:drawable="@color/key_background_pressed_lmp" />

View File

@ -41,13 +41,16 @@
</declare-styleable> </declare-styleable>
<declare-styleable name="KeyboardView"> <declare-styleable name="KeyboardView">
<!-- Image for the key. This image needs to be a {@link StateListDrawable}, with the <!-- Background image for the key. This image needs to be a {@link StateListDrawable},
following possible states: normal, pressed, checkable, checkable+pressed, with the following possible states: normal, pressed, checkable, checkable+pressed,
checkable+checked, checkable+checked+pressed. --> checkable+checked, checkable+checked+pressed. -->
<attr name="keyBackground" format="reference" /> <attr name="keyBackground" format="reference" />
<!-- Image for the functional key used in Emoji layout. --> <!-- Background image for the functional key. This image needs to be a
<attr name="keyBackgroundEmojiFunctional" format="reference" /> {@link StateListDrawable}, with the following possible states: normal, pressed. -->
<attr name="functionalKeyBackground" format="reference" />
<!-- Background image for the spacebar. This image needs to be a
{@link StateListDrawable}, with the following possible states: normal, pressed. -->
<attr name="spacebarBackground" format="reference" />
<!-- Horizontal padding of left/right aligned key label to the edge of the key. --> <!-- Horizontal padding of left/right aligned key label to the edge of the key. -->
<attr name="keyLabelHorizontalPadding" format="dimension" /> <attr name="keyLabelHorizontalPadding" format="dimension" />
<!-- Right padding of hint letter to the edge of the key.--> <!-- Right padding of hint letter to the edge of the key.-->
@ -76,8 +79,6 @@
<attr name="languageOnSpacebarTextColor" format="color" /> <attr name="languageOnSpacebarTextColor" format="color" />
<attr name="languageOnSpacebarTextShadowRadius" format="float" /> <attr name="languageOnSpacebarTextShadowRadius" format="float" />
<attr name="languageOnSpacebarTextShadowColor" format="color" /> <attr name="languageOnSpacebarTextShadowColor" format="color" />
<!-- Background image for the spacebar. -->
<attr name="spacebarBackground" format="reference" />
<!-- Fadeout animator for spacebar language label. --> <!-- Fadeout animator for spacebar language label. -->
<attr name="languageOnSpacebarFinalAlpha" format="integer" /> <attr name="languageOnSpacebarFinalAlpha" format="integer" />
<attr name="languageOnSpacebarFadeoutAnimator" format="reference" /> <attr name="languageOnSpacebarFadeoutAnimator" format="reference" />

View File

@ -109,12 +109,7 @@
<style name="KeyPreviewTextView" /> <style name="KeyPreviewTextView" />
<!-- Though {@link EmojiPalettesView} doesn't extend {@link KeyboardView}, some views inside it, <!-- Though {@link EmojiPalettesView} doesn't extend {@link KeyboardView}, some views inside it,
for instance delete button, need themed {@link KeyboardView} attributes. --> for instance delete button, need themed {@link KeyboardView} attributes. -->
<style <style name="EmojiPalettesView" />
name="EmojiPalettesView"
parent="KeyboardView"
>
<item name="emojiTabLabelColor">@color/emoji_tab_label_color_holo</item>
</style>
<style name="MoreKeysKeyboard" /> <style name="MoreKeysKeyboard" />
<style <style
name="MoreKeysKeyboardView" name="MoreKeysKeyboardView"

View File

@ -48,6 +48,8 @@
> >
<item name="android:background">@drawable/keyboard_background_holo</item> <item name="android:background">@drawable/keyboard_background_holo</item>
<item name="keyBackground">@drawable/btn_keyboard_key_ics</item> <item name="keyBackground">@drawable/btn_keyboard_key_ics</item>
<item name="functionalKeyBackground">@drawable/btn_keyboard_key_functional_ics</item>
<item name="spacebarBackground">@drawable/btn_keyboard_spacebar_ics</item>
<item name="keyTypeface">bold</item> <item name="keyTypeface">bold</item>
<item name="keyTextColor">@color/key_text_color_holo</item> <item name="keyTextColor">@color/key_text_color_holo</item>
<item name="keyTextInactivatedColor">@color/key_text_inactivated_color_holo</item> <item name="keyTextInactivatedColor">@color/key_text_inactivated_color_holo</item>
@ -73,7 +75,6 @@
<item name="languageOnSpacebarTextColor">@color/spacebar_text_color_holo</item> <item name="languageOnSpacebarTextColor">@color/spacebar_text_color_holo</item>
<item name="languageOnSpacebarTextShadowRadius">1.0</item> <item name="languageOnSpacebarTextShadowRadius">1.0</item>
<item name="languageOnSpacebarTextShadowColor">@color/spacebar_text_shadow_color_holo</item> <item name="languageOnSpacebarTextShadowColor">@color/spacebar_text_shadow_color_holo</item>
<item name="spacebarBackground">@drawable/btn_keyboard_spacebar_ics</item>
</style> </style>
<style <style
name="KeyPreviewTextView.ICS" name="KeyPreviewTextView.ICS"
@ -85,9 +86,8 @@
for instance delete button, need themed {@link KeyboardView} attributes. --> for instance delete button, need themed {@link KeyboardView} attributes. -->
<style <style
name="EmojiPalettesView.ICS" name="EmojiPalettesView.ICS"
parent="KeyboardView.ICS" parent="MainKeyboardView.ICS"
> >
<item name="keyBackgroundEmojiFunctional">@drawable/btn_keyboard_key_functional_ics</item>
<item name="emojiTabLabelColor">@color/emoji_tab_label_color_holo</item> <item name="emojiTabLabelColor">@color/emoji_tab_label_color_holo</item>
</style> </style>
<style <style

View File

@ -48,6 +48,8 @@
> >
<item name="android:background">@drawable/keyboard_background_holo</item> <item name="android:background">@drawable/keyboard_background_holo</item>
<item name="keyBackground">@drawable/btn_keyboard_key_klp</item> <item name="keyBackground">@drawable/btn_keyboard_key_klp</item>
<item name="functionalKeyBackground">@drawable/btn_keyboard_key_functional_klp</item>
<item name="spacebarBackground">@drawable/btn_keyboard_spacebar_klp</item>
<item name="keyTypeface">bold</item> <item name="keyTypeface">bold</item>
<item name="keyTextColor">@color/key_text_color_holo</item> <item name="keyTextColor">@color/key_text_color_holo</item>
<item name="keyTextInactivatedColor">@color/key_text_inactivated_color_holo</item> <item name="keyTextInactivatedColor">@color/key_text_inactivated_color_holo</item>
@ -73,7 +75,6 @@
<item name="languageOnSpacebarTextColor">@color/spacebar_text_color_holo</item> <item name="languageOnSpacebarTextColor">@color/spacebar_text_color_holo</item>
<item name="languageOnSpacebarTextShadowRadius">1.0</item> <item name="languageOnSpacebarTextShadowRadius">1.0</item>
<item name="languageOnSpacebarTextShadowColor">@color/spacebar_text_shadow_color_holo</item> <item name="languageOnSpacebarTextShadowColor">@color/spacebar_text_shadow_color_holo</item>
<item name="spacebarBackground">@drawable/btn_keyboard_spacebar_klp</item>
</style> </style>
<style <style
name="KeyPreviewTextView.KLP" name="KeyPreviewTextView.KLP"
@ -85,9 +86,8 @@
for instance delete button, need themed {@link KeyboardView} attributes. --> for instance delete button, need themed {@link KeyboardView} attributes. -->
<style <style
name="EmojiPalettesView.KLP" name="EmojiPalettesView.KLP"
parent="KeyboardView.KLP" parent="MainKeyboardView.KLP"
> >
<item name="keyBackgroundEmojiFunctional">@drawable/btn_keyboard_key_functional_klp</item>
<item name="emojiTabLabelColor">@color/emoji_tab_label_color_holo</item> <item name="emojiTabLabelColor">@color/emoji_tab_label_color_holo</item>
</style> </style>
<style <style

View File

@ -48,6 +48,8 @@
> >
<item name="android:background">@color/keyboard_background_lmp</item> <item name="android:background">@color/keyboard_background_lmp</item>
<item name="keyBackground">@drawable/btn_keyboard_key_lmp</item> <item name="keyBackground">@drawable/btn_keyboard_key_lmp</item>
<item name="functionalKeyBackground">@drawable/btn_keyboard_key_functional_lmp</item>
<item name="spacebarBackground">@drawable/btn_keyboard_spacebar_lmp</item>
<item name="keyTypeface">bold</item> <item name="keyTypeface">bold</item>
<item name="keyTextColor">@color/key_text_color_holo</item> <item name="keyTextColor">@color/key_text_color_holo</item>
<item name="keyTextInactivatedColor">@color/key_text_inactive_color_lmp</item> <item name="keyTextInactivatedColor">@color/key_text_inactive_color_lmp</item>
@ -73,7 +75,6 @@
<item name="languageOnSpacebarTextColor">@color/key_text_inactive_color_lmp</item> <item name="languageOnSpacebarTextColor">@color/key_text_inactive_color_lmp</item>
<!-- A negative value to disable text shadow layer. --> <!-- A negative value to disable text shadow layer. -->
<item name="languageOnSpacebarTextShadowRadius">-1.0</item> <item name="languageOnSpacebarTextShadowRadius">-1.0</item>
<item name="spacebarBackground">@drawable/btn_keyboard_spacebar_lmp</item>
</style> </style>
<style <style
name="KeyPreviewTextView.LMP" name="KeyPreviewTextView.LMP"
@ -85,9 +86,8 @@
for instance delete button, need themed {@link KeyboardView} attributes. --> for instance delete button, need themed {@link KeyboardView} attributes. -->
<style <style
name="EmojiPalettesView.LMP" name="EmojiPalettesView.LMP"
parent="KeyboardView.LMP" parent="MainKeyboardView.LMP"
> >
<item name="keyBackgroundEmojiFunctional">@drawable/btn_keyboard_key_functional_lmp</item>
<item name="emojiTabLabelColor">@color/emoji_tab_label_color_holo</item> <item name="emojiTabLabelColor">@color/emoji_tab_label_color_holo</item>
</style> </style>
<style <style

View File

@ -23,6 +23,7 @@ import android.content.res.ColorStateList;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Typeface;
import android.os.CountDownTimer; import android.os.CountDownTimer;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
@ -66,8 +67,8 @@ import java.util.concurrent.TimeUnit;
public final class EmojiPalettesView extends LinearLayout implements OnTabChangeListener, public final class EmojiPalettesView extends LinearLayout implements OnTabChangeListener,
ViewPager.OnPageChangeListener, View.OnClickListener, View.OnTouchListener, ViewPager.OnPageChangeListener, View.OnClickListener, View.OnTouchListener,
EmojiPageKeyboardView.OnKeyEventListener { EmojiPageKeyboardView.OnKeyEventListener {
private final int mKeyBackgroundId; private final int mFunctionalKeyBackgroundId;
private final int mEmojiFunctionalKeyBackgroundId; private final int mSpacebarBackgroundId;
private final ColorStateList mTabLabelColor; private final ColorStateList mTabLabelColor;
private final DeleteKeyOnTouchListener mDeleteKeyOnTouchListener; private final DeleteKeyOnTouchListener mDeleteKeyOnTouchListener;
private EmojiPalettesAdapter mEmojiPalettesAdapter; private EmojiPalettesAdapter mEmojiPalettesAdapter;
@ -92,10 +93,12 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
super(context, attrs, defStyle); super(context, attrs, defStyle);
final TypedArray keyboardViewAttr = context.obtainStyledAttributes(attrs, final TypedArray keyboardViewAttr = context.obtainStyledAttributes(attrs,
R.styleable.KeyboardView, defStyle, R.style.KeyboardView); R.styleable.KeyboardView, defStyle, R.style.KeyboardView);
mKeyBackgroundId = keyboardViewAttr.getResourceId( final int keyBackgroundId = keyboardViewAttr.getResourceId(
R.styleable.KeyboardView_keyBackground, 0); R.styleable.KeyboardView_keyBackground, 0);
mEmojiFunctionalKeyBackgroundId = keyboardViewAttr.getResourceId( mFunctionalKeyBackgroundId = keyboardViewAttr.getResourceId(
R.styleable.KeyboardView_keyBackgroundEmojiFunctional, 0); R.styleable.KeyboardView_functionalKeyBackground, keyBackgroundId);
mSpacebarBackgroundId = keyboardViewAttr.getResourceId(
R.styleable.KeyboardView_spacebarBackground, keyBackgroundId);
keyboardViewAttr.recycle(); keyboardViewAttr.recycle();
final TypedArray emojiPalettesViewAttr = context.obtainStyledAttributes(attrs, final TypedArray emojiPalettesViewAttr = context.obtainStyledAttributes(attrs,
R.styleable.EmojiPalettesView, defStyle, R.style.EmojiPalettesView); R.styleable.EmojiPalettesView, defStyle, R.style.EmojiPalettesView);
@ -182,6 +185,7 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
// deleteKey depends only on OnTouchListener. // deleteKey depends only on OnTouchListener.
final ImageView deleteKey = (ImageView)findViewById(R.id.emoji_keyboard_delete); final ImageView deleteKey = (ImageView)findViewById(R.id.emoji_keyboard_delete);
deleteKey.setBackgroundResource(mFunctionalKeyBackgroundId);
deleteKey.setTag(Constants.CODE_DELETE); deleteKey.setTag(Constants.CODE_DELETE);
deleteKey.setOnTouchListener(mDeleteKeyOnTouchListener); deleteKey.setOnTouchListener(mDeleteKeyOnTouchListener);
@ -193,17 +197,17 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
// The text on alphabet keys are set at // The text on alphabet keys are set at
// {@link #startEmojiPalettes(String,int,float,Typeface)}. // {@link #startEmojiPalettes(String,int,float,Typeface)}.
mAlphabetKeyLeft = (TextView)findViewById(R.id.emoji_keyboard_alphabet_left); mAlphabetKeyLeft = (TextView)findViewById(R.id.emoji_keyboard_alphabet_left);
mAlphabetKeyLeft.setBackgroundResource(mEmojiFunctionalKeyBackgroundId); mAlphabetKeyLeft.setBackgroundResource(mFunctionalKeyBackgroundId);
mAlphabetKeyLeft.setTag(Constants.CODE_ALPHA_FROM_EMOJI); mAlphabetKeyLeft.setTag(Constants.CODE_ALPHA_FROM_EMOJI);
mAlphabetKeyLeft.setOnTouchListener(this); mAlphabetKeyLeft.setOnTouchListener(this);
mAlphabetKeyLeft.setOnClickListener(this); mAlphabetKeyLeft.setOnClickListener(this);
mAlphabetKeyRight = (TextView)findViewById(R.id.emoji_keyboard_alphabet_right); mAlphabetKeyRight = (TextView)findViewById(R.id.emoji_keyboard_alphabet_right);
mAlphabetKeyRight.setBackgroundResource(mEmojiFunctionalKeyBackgroundId); mAlphabetKeyRight.setBackgroundResource(mFunctionalKeyBackgroundId);
mAlphabetKeyRight.setTag(Constants.CODE_ALPHA_FROM_EMOJI); mAlphabetKeyRight.setTag(Constants.CODE_ALPHA_FROM_EMOJI);
mAlphabetKeyRight.setOnTouchListener(this); mAlphabetKeyRight.setOnTouchListener(this);
mAlphabetKeyRight.setOnClickListener(this); mAlphabetKeyRight.setOnClickListener(this);
final ImageView spaceKey = (ImageView)findViewById(R.id.emoji_keyboard_space); final ImageView spaceKey = (ImageView)findViewById(R.id.emoji_keyboard_space);
spaceKey.setBackgroundResource(mKeyBackgroundId); spaceKey.setBackgroundResource(mSpacebarBackgroundId);
spaceKey.setTag(Constants.CODE_SPACE); spaceKey.setTag(Constants.CODE_SPACE);
spaceKey.setOnTouchListener(this); spaceKey.setOnTouchListener(this);
spaceKey.setOnClickListener(this); spaceKey.setOnClickListener(this);

View File

@ -218,7 +218,7 @@ public class Key implements Comparable<Key> {
* *
* @param keySpec the key specification. * @param keySpec the key specification.
* @param keyAttr the Key XML attributes array. * @param keyAttr the Key XML attributes array.
* @param keyStyle the {@link KeyStyle} of this key. * @param style the {@link KeyStyle} of this key.
* @param params the keyboard building parameters. * @param params the keyboard building parameters.
* @param row the row that this key belongs to. row's x-coordinate will be the right edge of * @param row the row that this key belongs to. row's x-coordinate will be the right edge of
* this key. * this key.
@ -857,17 +857,6 @@ public class Key implements Comparable<Key> {
android.R.attr.state_empty android.R.attr.state_empty
}; };
// 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
};
// action normal state (with properties) // action normal state (with properties)
private static final int[] KEY_STATE_ACTIVE_NORMAL = { private static final int[] KEY_STATE_ACTIVE_NORMAL = {
android.R.attr.state_active android.R.attr.state_active
@ -880,25 +869,43 @@ public class Key implements Comparable<Key> {
}; };
/** /**
* Returns the drawable state for the key, based on the current state and type of the key. * Returns the background drawable for the key, based on the current state and type of the key.
* @return the drawable state of the key. * @return the background drawable of the key.
* @see android.graphics.drawable.StateListDrawable#setState(int[]) * @see android.graphics.drawable.StateListDrawable#setState(int[])
*/ */
public final int[] getCurrentDrawableState() { public final Drawable selectBackgroundDrawable(final Drawable keyBackground,
switch (mBackgroundType) { final Drawable functionalKeyBackground, final Drawable spacebarBackground) {
case BACKGROUND_TYPE_FUNCTIONAL: final Drawable background;
return mPressed ? KEY_STATE_FUNCTIONAL_PRESSED : KEY_STATE_FUNCTIONAL_NORMAL; if (mBackgroundType == BACKGROUND_TYPE_FUNCTIONAL) {
case BACKGROUND_TYPE_ACTION: background = functionalKeyBackground;
return mPressed ? KEY_STATE_ACTIVE_PRESSED : KEY_STATE_ACTIVE_NORMAL; } else if (getCode() == Constants.CODE_SPACE) {
case BACKGROUND_TYPE_STICKY_OFF: background = spacebarBackground;
return mPressed ? KEY_STATE_PRESSED_HIGHLIGHT_OFF : KEY_STATE_NORMAL_HIGHLIGHT_OFF; } else {
case BACKGROUND_TYPE_STICKY_ON: background = keyBackground;
return mPressed ? KEY_STATE_PRESSED_HIGHLIGHT_ON : KEY_STATE_NORMAL_HIGHLIGHT_ON;
case BACKGROUND_TYPE_EMPTY:
return mPressed ? KEY_STATE_PRESSED : KEY_STATE_EMPTY;
default: /* BACKGROUND_TYPE_NORMAL */
return mPressed ? KEY_STATE_PRESSED : KEY_STATE_NORMAL;
} }
final int[] stateSet;
switch (mBackgroundType) {
case BACKGROUND_TYPE_ACTION:
stateSet = mPressed ? KEY_STATE_ACTIVE_PRESSED : KEY_STATE_ACTIVE_NORMAL;
break;
case BACKGROUND_TYPE_STICKY_OFF:
stateSet = mPressed ? KEY_STATE_PRESSED_HIGHLIGHT_OFF : KEY_STATE_NORMAL_HIGHLIGHT_OFF;
break;
case BACKGROUND_TYPE_STICKY_ON:
stateSet = mPressed ? KEY_STATE_PRESSED_HIGHLIGHT_ON : KEY_STATE_NORMAL_HIGHLIGHT_ON;
break;
case BACKGROUND_TYPE_EMPTY:
stateSet = mPressed ? KEY_STATE_PRESSED : KEY_STATE_EMPTY;
break;
case BACKGROUND_TYPE_FUNCTIONAL:
stateSet = mPressed ? KEY_STATE_PRESSED : KEY_STATE_NORMAL;
break;
default: /* BACKGROUND_TYPE_NORMAL */
stateSet = mPressed ? KEY_STATE_PRESSED : KEY_STATE_NORMAL;
break;
}
background.setState(stateSet);
return background;
} }
public static class Spacer extends Key { public static class Spacer extends Key {

View File

@ -47,6 +47,8 @@ import java.util.HashSet;
* A view that renders a virtual {@link Keyboard}. * A view that renders a virtual {@link Keyboard}.
* *
* @attr ref R.styleable#KeyboardView_keyBackground * @attr ref R.styleable#KeyboardView_keyBackground
* @attr ref R.styleable#KeyboardView_functionalKeyBackground
* @attr ref R.styleable#KeyboardView_spacebarBackground
* @attr ref R.styleable#KeyboardView_keyLabelHorizontalPadding * @attr ref R.styleable#KeyboardView_keyLabelHorizontalPadding
* @attr ref R.styleable#KeyboardView_keyHintLetterPadding * @attr ref R.styleable#KeyboardView_keyHintLetterPadding
* @attr ref R.styleable#KeyboardView_keyPopupHintLetterPadding * @attr ref R.styleable#KeyboardView_keyPopupHintLetterPadding
@ -81,6 +83,8 @@ public class KeyboardView extends View {
private final float mKeyTextShadowRadius; private final float mKeyTextShadowRadius;
private final float mVerticalCorrection; private final float mVerticalCorrection;
private final Drawable mKeyBackground; private final Drawable mKeyBackground;
private final Drawable mFunctionalKeyBackground;
private final Drawable mSpacebarBackground;
private final Rect mKeyBackgroundPadding = new Rect(); private final Rect mKeyBackgroundPadding = new Rect();
private static final float KET_TEXT_SHADOW_RADIUS_DISABLED = -1.0f; private static final float KET_TEXT_SHADOW_RADIUS_DISABLED = -1.0f;
@ -125,6 +129,14 @@ public class KeyboardView extends View {
R.styleable.KeyboardView, defStyle, R.style.KeyboardView); R.styleable.KeyboardView, defStyle, R.style.KeyboardView);
mKeyBackground = keyboardViewAttr.getDrawable(R.styleable.KeyboardView_keyBackground); mKeyBackground = keyboardViewAttr.getDrawable(R.styleable.KeyboardView_keyBackground);
mKeyBackground.getPadding(mKeyBackgroundPadding); mKeyBackground.getPadding(mKeyBackgroundPadding);
final Drawable functionalKeyBackground = keyboardViewAttr.getDrawable(
R.styleable.KeyboardView_functionalKeyBackground);
mFunctionalKeyBackground = (functionalKeyBackground != null) ? functionalKeyBackground
: mKeyBackground;
final Drawable spacebarBackground = keyboardViewAttr.getDrawable(
R.styleable.KeyboardView_spacebarBackground);
mSpacebarBackground = (spacebarBackground != null) ? spacebarBackground
: mKeyBackground;
mKeyLabelHorizontalPadding = keyboardViewAttr.getDimensionPixelOffset( mKeyLabelHorizontalPadding = keyboardViewAttr.getDimensionPixelOffset(
R.styleable.KeyboardView_keyLabelHorizontalPadding, 0); R.styleable.KeyboardView_keyLabelHorizontalPadding, 0);
mKeyHintLetterPadding = keyboardViewAttr.getDimension( mKeyHintLetterPadding = keyboardViewAttr.getDimension(
@ -324,7 +336,9 @@ public class KeyboardView extends View {
params.mAnimAlpha = Constants.Color.ALPHA_OPAQUE; params.mAnimAlpha = Constants.Color.ALPHA_OPAQUE;
if (!key.isSpacer()) { if (!key.isSpacer()) {
onDrawKeyBackground(key, canvas, mKeyBackground); final Drawable background = key.selectBackgroundDrawable(
mKeyBackground, mFunctionalKeyBackground, mSpacebarBackground);
onDrawKeyBackground(key, canvas, background);
} }
onDrawKeyTopVisuals(key, canvas, paint, params); onDrawKeyTopVisuals(key, canvas, paint, params);
@ -339,8 +353,6 @@ public class KeyboardView extends View {
final int bgHeight = key.getHeight() + padding.top + padding.bottom; final int bgHeight = key.getHeight() + padding.top + padding.bottom;
final int bgX = -padding.left; final int bgX = -padding.left;
final int bgY = -padding.top; final int bgY = -padding.top;
final int[] drawableState = key.getCurrentDrawableState();
background.setState(drawableState);
final Rect bounds = background.getBounds(); final Rect bounds = background.getBounds();
if (bgWidth != bounds.right || bgHeight != bounds.bottom) { if (bgWidth != bounds.right || bgHeight != bounds.bottom) {
background.setBounds(0, 0, bgWidth, bgHeight); background.setBounds(0, 0, bgWidth, bgHeight);

View File

@ -76,7 +76,6 @@ import java.util.WeakHashMap;
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextColor * @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextColor
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextShadowRadius * @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextShadowRadius
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextShadowColor * @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextShadowColor
* @attr ref R.styleable#MainKeyboardView_spacebarBackground
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarFinalAlpha * @attr ref R.styleable#MainKeyboardView_languageOnSpacebarFinalAlpha
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarFadeoutAnimator * @attr ref R.styleable#MainKeyboardView_languageOnSpacebarFadeoutAnimator
* @attr ref R.styleable#MainKeyboardView_altCodeKeyWhileTypingFadeoutAnimator * @attr ref R.styleable#MainKeyboardView_altCodeKeyWhileTypingFadeoutAnimator
@ -120,7 +119,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
/* Space key and its icon and background. */ /* Space key and its icon and background. */
private Key mSpaceKey; private Key mSpaceKey;
private Drawable mSpacebarIcon; private Drawable mSpacebarIcon;
private final Drawable mSpacebarBackground;
// Stuff to draw language name on spacebar. // Stuff to draw language name on spacebar.
private final int mLanguageOnSpacebarFinalAlpha; private final int mLanguageOnSpacebarFinalAlpha;
private ObjectAnimator mLanguageOnSpacebarFadeoutAnimator; private ObjectAnimator mLanguageOnSpacebarFadeoutAnimator;
@ -154,7 +152,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
private final SlidingKeyInputDrawingPreview mSlidingKeyInputDrawingPreview; private final SlidingKeyInputDrawingPreview mSlidingKeyInputDrawingPreview;
// Key preview // Key preview
private static final boolean FADE_OUT_KEY_TOP_LETTER_WHEN_KEY_IS_PRESSED = false;
private final KeyPreviewDrawParams mKeyPreviewDrawParams; private final KeyPreviewDrawParams mKeyPreviewDrawParams;
private final KeyPreviewChoreographer mKeyPreviewChoreographer; private final KeyPreviewChoreographer mKeyPreviewChoreographer;
@ -224,8 +221,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
R.styleable.MainKeyboardView_backgroundDimAlpha, 0); R.styleable.MainKeyboardView_backgroundDimAlpha, 0);
mBackgroundDimAlphaPaint.setColor(Color.BLACK); mBackgroundDimAlphaPaint.setColor(Color.BLACK);
mBackgroundDimAlphaPaint.setAlpha(backgroundDimAlpha); mBackgroundDimAlphaPaint.setAlpha(backgroundDimAlpha);
mSpacebarBackground = mainKeyboardViewAttr.getDrawable(
R.styleable.MainKeyboardView_spacebarBackground);
mAutoCorrectionSpacebarLedEnabled = mainKeyboardViewAttr.getBoolean( mAutoCorrectionSpacebarLedEnabled = mainKeyboardViewAttr.getBoolean(
R.styleable.MainKeyboardView_autoCorrectionSpacebarLedEnabled, false); R.styleable.MainKeyboardView_autoCorrectionSpacebarLedEnabled, false);
mAutoCorrectionSpacebarLedIcon = mainKeyboardViewAttr.getDrawable( mAutoCorrectionSpacebarLedIcon = mainKeyboardViewAttr.getDrawable(
@ -557,6 +552,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
} }
// Note that this method is called from a non-UI thread. // Note that this method is called from a non-UI thread.
@SuppressWarnings("static-method")
public void setMainDictionaryAvailability(final boolean mainDictionaryAvailable) { public void setMainDictionaryAvailability(final boolean mainDictionaryAvailable) {
PointerTracker.setMainDictionaryAvailability(mainDictionaryAvailable); PointerTracker.setMainDictionaryAvailability(mainDictionaryAvailable);
} }
@ -864,30 +860,12 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
} }
} }
// Draw key background.
@Override
protected void onDrawKeyBackground(final Key key, final Canvas canvas,
final Drawable background) {
if (key.getCode() == Constants.CODE_SPACE) {
super.onDrawKeyBackground(key, canvas, mSpacebarBackground);
return;
}
super.onDrawKeyBackground(key, canvas, background);
}
@Override @Override
protected void onDrawKeyTopVisuals(final Key key, final Canvas canvas, final Paint paint, protected void onDrawKeyTopVisuals(final Key key, final Canvas canvas, final Paint paint,
final KeyDrawParams params) { final KeyDrawParams params) {
if (key.altCodeWhileTyping() && key.isEnabled()) { if (key.altCodeWhileTyping() && key.isEnabled()) {
params.mAnimAlpha = mAltCodeKeyWhileTypingAnimAlpha; params.mAnimAlpha = mAltCodeKeyWhileTypingAnimAlpha;
} }
// Don't draw key top letter when key preview is showing.
if (FADE_OUT_KEY_TOP_LETTER_WHEN_KEY_IS_PRESSED
&& mKeyPreviewChoreographer.isShowingKeyPreview(key)) {
// TODO: Fade out animation for the key top letter, and fade in animation for the key
// background color when the user presses the key.
return;
}
final int code = key.getCode(); final int code = key.getCode();
if (code == Constants.CODE_SPACE) { if (code == Constants.CODE_SPACE) {
drawSpacebar(key, canvas, paint); drawSpacebar(key, canvas, paint);