am 7081a36e: Merge "Add spacebar background drawable"

* commit '7081a36e2f67c6c98abb5fca844af22f30809f5d':
  Add spacebar background drawable
main
Tadashi G. Takaoka 2013-12-03 19:51:09 -08:00 committed by Android Git Automerger
commit f7c3b5dcfa
9 changed files with 96 additions and 13 deletions

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_key_light_pressed" />
<item android:drawable="@drawable/btn_keyboard_key_light_normal" />
</selector>

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_key_light_pressed_ics" />
<item android:drawable="@drawable/btn_keyboard_key_light_normal_holo" />
</selector>

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_key_light_pressed_klp" />
<item android:drawable="@drawable/btn_keyboard_key_light_normal_holo" />
</selector>

View File

@ -41,9 +41,9 @@
</declare-styleable>
<declare-styleable name="KeyboardView">
<!-- Image for the key. This image needs to be a StateListDrawable, with the following
possible states: normal, pressed, checkable, checkable+pressed, checkable+checked,
checkable+checked+pressed. -->
<!-- Image for the key. This image needs to be a {@link StateListDrawable}, with the
following 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" />
@ -75,6 +75,8 @@
<attr name="languageOnSpacebarTextRatio" format="fraction" />
<attr name="languageOnSpacebarTextColor" format="color" />
<attr name="languageOnSpacebarTextShadowColor" format="color" />
<!-- Background image for the spacebar. -->
<attr name="spacebarBackground" format="reference" />
<!-- Fadeout animator for spacebar language label. -->
<attr name="languageOnSpacebarFinalAlpha" format="integer" />
<attr name="languageOnSpacebarFadeoutAnimator" format="reference" />

View File

@ -93,6 +93,7 @@
<item name="autoCorrectionSpacebarLedIcon">@drawable/sym_keyboard_space_led_gb</item>
<item name="languageOnSpacebarTextColor">@color/spacebar_text_color_gb</item>
<item name="languageOnSpacebarTextShadowColor">@color/spacebar_text_shadow_color_gb</item>
<item name="spacebarBackground">@drawable/btn_keyboard_spacebar_gb</item>
</style>
<style
name="KeyPreviewTextView.GB"

View File

@ -72,6 +72,7 @@
<item name="autoCorrectionSpacebarLedIcon">@drawable/sym_keyboard_space_led_holo</item>
<item name="languageOnSpacebarTextColor">@color/spacebar_text_color_holo</item>
<item name="languageOnSpacebarTextShadowColor">@color/spacebar_text_shadow_color_holo</item>
<item name="spacebarBackground">@drawable/btn_keyboard_spacebar_ics</item>
</style>
<style
name="KeyPreviewTextView.ICS"

View File

@ -72,6 +72,7 @@
<item name="autoCorrectionSpacebarLedIcon">@drawable/sym_keyboard_space_led_holo</item>
<item name="languageOnSpacebarTextColor">@color/spacebar_text_color_holo</item>
<item name="languageOnSpacebarTextShadowColor">@color/spacebar_text_shadow_color_holo</item>
<item name="spacebarBackground">@drawable/btn_keyboard_spacebar_klp</item>
</style>
<style
name="KeyPreviewTextView.KLP"

View File

@ -319,7 +319,7 @@ public class KeyboardView extends View {
params.mAnimAlpha = Constants.Color.ALPHA_OPAQUE;
if (!key.isSpacer()) {
onDrawKeyBackground(key, canvas);
onDrawKeyBackground(key, canvas, mKeyBackground);
}
onDrawKeyTopVisuals(key, canvas, paint, params);
@ -327,14 +327,14 @@ public class KeyboardView extends View {
}
// Draw key background.
protected void onDrawKeyBackground(final Key key, final Canvas canvas) {
protected void onDrawKeyBackground(final Key key, final Canvas canvas,
final Drawable background) {
final Rect padding = mKeyBackgroundPadding;
final int bgWidth = key.getDrawWidth() + padding.left + padding.right;
final int bgHeight = key.getHeight() + padding.top + padding.bottom;
final int bgX = -padding.left;
final int bgY = -padding.top;
final int[] drawableState = key.getCurrentDrawableState();
final Drawable background = mKeyBackground;
background.setState(drawableState);
final Rect bounds = background.getBounds();
if (bgWidth != bounds.right || bgHeight != bounds.bottom) {

View File

@ -84,6 +84,7 @@ import java.util.WeakHashMap;
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextRatio
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextColor
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextShadowColor
* @attr ref R.styleable#MainKeyboardView_spacebarBackground
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarFinalAlpha
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarFadeoutAnimator
* @attr ref R.styleable#MainKeyboardView_altCodeKeyWhileTypingFadeoutAnimator
@ -124,9 +125,10 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
/** Listener for {@link KeyboardActionListener}. */
private KeyboardActionListener mKeyboardActionListener;
/* Space key and its icons */
/* Space key and its icon and background. */
private Key mSpaceKey;
private Drawable mSpaceIcon;
private Drawable mSpacebarIcon;
private final Drawable mSpacebarBackground;
// Stuff to draw language name on spacebar.
private final int mLanguageOnSpacebarFinalAlpha;
private ObjectAnimator mLanguageOnSpacebarFadeoutAnimator;
@ -244,6 +246,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
R.styleable.MainKeyboardView_backgroundDimAlpha, 0);
mBackgroundDimAlphaPaint.setColor(Color.BLACK);
mBackgroundDimAlphaPaint.setAlpha(backgroundDimAlpha);
mSpacebarBackground = mainKeyboardViewAttr.getDrawable(
R.styleable.MainKeyboardView_spacebarBackground);
mAutoCorrectionSpacebarLedEnabled = mainKeyboardViewAttr.getBoolean(
R.styleable.MainKeyboardView_autoCorrectionSpacebarLedEnabled, false);
mAutoCorrectionSpacebarLedIcon = mainKeyboardViewAttr.getDrawable(
@ -431,7 +435,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
mMoreKeysKeyboardCache.clear();
mSpaceKey = keyboard.getKey(Constants.CODE_SPACE);
mSpaceIcon = (mSpaceKey != null)
mSpacebarIcon = (mSpaceKey != null)
? mSpaceKey.getIcon(keyboard.mIconsSet, Constants.Color.ALPHA_OPAQUE) : null;
final int keyHeight = keyboard.mMostCommonKeyHeight - keyboard.mVerticalGap;
mLanguageOnSpacebarTextSize = keyHeight * mLanguageOnSpacebarTextRatio;
@ -1103,6 +1107,17 @@ 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
protected void onDrawKeyTopVisuals(final Key key, final Canvas canvas, final Paint paint,
final KeyDrawParams params) {
@ -1201,12 +1216,12 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
int x = (width - iconWidth) / 2;
int y = height - iconHeight;
drawIcon(canvas, mAutoCorrectionSpacebarLedIcon, x, y, iconWidth, iconHeight);
} else if (mSpaceIcon != null) {
final int iconWidth = mSpaceIcon.getIntrinsicWidth();
final int iconHeight = mSpaceIcon.getIntrinsicHeight();
} else if (mSpacebarIcon != null) {
final int iconWidth = mSpacebarIcon.getIntrinsicWidth();
final int iconHeight = mSpacebarIcon.getIntrinsicHeight();
int x = (width - iconWidth) / 2;
int y = height - iconHeight;
drawIcon(canvas, mSpaceIcon, x, y, iconWidth, iconHeight);
drawIcon(canvas, mSpacebarIcon, x, y, iconWidth, iconHeight);
}
}