am 486c4894: Keep aspect ratio of Material action key background

* commit '486c4894ce0917fc7b18eaee4bfd031051f2b05b':
  Keep aspect ratio of Material action key background
main
Tadashi G. Takaoka 2014-09-09 06:19:03 +00:00 committed by Android Git Automerger
commit 1b45941588
9 changed files with 90 additions and 26 deletions

View File

@ -338,6 +338,8 @@
<!-- If true, use functionalTextColor instead of ketTextColor to drawing the label on <!-- If true, use functionalTextColor instead of ketTextColor to drawing the label on
the key --> the key -->
<flag name="followFunctionalTextColor" value="0x80000" /> <flag name="followFunctionalTextColor" value="0x80000" />
<!-- Keep aspect ratio of key background. -->
<flag name="keepBackgroundAspectRatio" value="0x100000" />
<!-- If true, disable keyHintLabel. --> <!-- If true, disable keyHintLabel. -->
<flag name="disableKeyHintLabel" value="0x40000000" /> <flag name="disableKeyHintLabel" value="0x40000000" />
<!-- If true, disable additionalMoreKeys. --> <!-- If true, disable additionalMoreKeys. -->

View File

@ -114,6 +114,7 @@
<item name="android:background">@android:color/transparent</item> <item name="android:background">@android:color/transparent</item>
<item name="keyBackground">@drawable/btn_keyboard_key_popup_action_lxx_dark</item> <item name="keyBackground">@drawable/btn_keyboard_key_popup_action_lxx_dark</item>
<item name="divider">@null</item> <item name="divider">@null</item>
<item name="keyLabelFlags">keepBackgroundAspectRatio</item>
</style> </style>
<style <style
name="SuggestionStripView.LXX_Dark" name="SuggestionStripView.LXX_Dark"

View File

@ -114,6 +114,7 @@
<item name="android:background">@android:color/transparent</item> <item name="android:background">@android:color/transparent</item>
<item name="keyBackground">@drawable/btn_keyboard_key_popup_action_lxx_light</item> <item name="keyBackground">@drawable/btn_keyboard_key_popup_action_lxx_light</item>
<item name="divider">@null</item> <item name="divider">@null</item>
<item name="keyLabelFlags">keepBackgroundAspectRatio</item>
</style> </style>
<style <style
name="SuggestionStripView.LXX_Light" name="SuggestionStripView.LXX_Light"

View File

@ -80,6 +80,8 @@
</default> </default>
</switch> </switch>
<!-- Enter key style --> <!-- Enter key style -->
<switch>
<case latin:keyboardTheme="ICS|KLP">
<key-style <key-style
latin:styleName="defaultEnterKeyStyle" latin:styleName="defaultEnterKeyStyle"
latin:keySpec="!icon/enter_key|!code/key_enter" latin:keySpec="!icon/enter_key|!code/key_enter"
@ -87,6 +89,18 @@
latin:keyActionFlags="noKeyPreview" latin:keyActionFlags="noKeyPreview"
latin:backgroundType="action" latin:backgroundType="action"
latin:parentStyle="navigateMoreKeysStyle" /> latin:parentStyle="navigateMoreKeysStyle" />
</case>
<!-- keyboardTheme="LXXLight|LXXDark" -->
<default>
<key-style
latin:styleName="defaultEnterKeyStyle"
latin:keySpec="!icon/enter_key|!code/key_enter"
latin:keyLabelFlags="preserveCase|autoXScale|followKeyLabelRatio|followFunctionalTextColor|keepBackgroundAspectRatio"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="action"
latin:parentStyle="navigateMoreKeysStyle" />
</default>
</switch>
<include latin:keyboardLayout="@xml/key_styles_actions" /> <include latin:keyboardLayout="@xml/key_styles_actions" />
<switch> <switch>
<!-- Shift + Enter in textMultiLine field. --> <!-- Shift + Enter in textMultiLine field. -->

View File

@ -80,11 +80,24 @@
latin:keyActionFlags="isRepeatable|noKeyPreview" latin:keyActionFlags="isRepeatable|noKeyPreview"
latin:backgroundType="functional" /> latin:backgroundType="functional" />
<!-- emojiKeyStyle must be defined before including @xml/key_syles_enter. --> <!-- emojiKeyStyle must be defined before including @xml/key_syles_enter. -->
<switch>
<case latin:keyboardTheme="ICS|KLP">
<key-style <key-style
latin:styleName="emojiKeyStyle" latin:styleName="emojiKeyStyle"
latin:keySpec="!icon/emoji_action_key|!code/key_emoji" latin:keySpec="!icon/emoji_action_key|!code/key_emoji"
latin:keyActionFlags="noKeyPreview" latin:keyActionFlags="noKeyPreview"
latin:backgroundType="action" /> latin:backgroundType="action" />
</case>
<!-- keyboardTheme="LXXLight|LXXDark" -->
<default>
<key-style
latin:styleName="emojiKeyStyle"
latin:keySpec="!icon/emoji_action_key|!code/key_emoji"
latin:keyLabelFlags="keepBackgroundAspectRatio"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="action" />
</default>
</switch>
<include <include
latin:keyboardLayout="@xml/key_styles_enter" /> latin:keyboardLayout="@xml/key_styles_enter" />
<!-- TODO: Currently there is no way to specify icon alignment per theme. --> <!-- TODO: Currently there is no way to specify icon alignment per theme. -->

View File

@ -212,6 +212,8 @@
</default> </default>
</switch> </switch>
<!-- Enter key style --> <!-- Enter key style -->
<switch>
<case latin:keyboardTheme="ICS|KLP">
<key-style <key-style
latin:styleName="defaultEnterKeyStyle" latin:styleName="defaultEnterKeyStyle"
latin:keySpec="!icon/enter_key|!code/key_enter" latin:keySpec="!icon/enter_key|!code/key_enter"
@ -219,6 +221,18 @@
latin:keyActionFlags="noKeyPreview" latin:keyActionFlags="noKeyPreview"
latin:backgroundType="action" latin:backgroundType="action"
latin:parentStyle="navigateMoreKeysStyle" /> latin:parentStyle="navigateMoreKeysStyle" />
</case>
<!-- keyboardTheme="LXXLight|LXXDark" -->
<default>
<key-style
latin:styleName="defaultEnterKeyStyle"
latin:keySpec="!icon/enter_key|!code/key_enter"
latin:keyLabelFlags="preserveCase|autoXScale|followKeyLabelRatio|followFunctionalTextColor|keepBackgroundAspectRatio"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="action"
latin:parentStyle="navigateMoreKeysStyle" />
</default>
</switch>
<include latin:keyboardLayout="@xml/key_styles_actions" /> <include latin:keyboardLayout="@xml/key_styles_actions" />
<switch> <switch>
<!-- Shift + Enter in textMultiLine field. --> <!-- Shift + Enter in textMultiLine field. -->

View File

@ -87,6 +87,7 @@ public class Key implements Comparable<Key> {
private static final int LABEL_FLAGS_SHIFTED_LETTER_ACTIVATED = 0x20000; private static final int LABEL_FLAGS_SHIFTED_LETTER_ACTIVATED = 0x20000;
private static final int LABEL_FLAGS_FROM_CUSTOM_ACTION_LABEL = 0x40000; private static final int LABEL_FLAGS_FROM_CUSTOM_ACTION_LABEL = 0x40000;
private static final int LABEL_FLAGS_FOLLOW_FUNCTIONAL_TEXT_COLOR = 0x80000; private static final int LABEL_FLAGS_FOLLOW_FUNCTIONAL_TEXT_COLOR = 0x80000;
private static final int LABEL_FLAGS_KEEP_BACKGROUND_ASPECT_RATIO = 0x100000;
private static final int LABEL_FLAGS_DISABLE_HINT_LABEL = 0x40000000; private static final int LABEL_FLAGS_DISABLE_HINT_LABEL = 0x40000000;
private static final int LABEL_FLAGS_DISABLE_ADDITIONAL_MORE_KEYS = 0x80000000; private static final int LABEL_FLAGS_DISABLE_ADDITIONAL_MORE_KEYS = 0x80000000;
@ -697,6 +698,10 @@ public class Key implements Comparable<Key> {
return (mLabelFlags & LABEL_FLAGS_AUTO_SCALE) == LABEL_FLAGS_AUTO_SCALE; return (mLabelFlags & LABEL_FLAGS_AUTO_SCALE) == LABEL_FLAGS_AUTO_SCALE;
} }
public final boolean needsToKeepBackgroundAspectRatio(final int defaultFlags) {
return ((mLabelFlags | defaultFlags) & LABEL_FLAGS_KEEP_BACKGROUND_ASPECT_RATIO) != 0;
}
private final boolean isShiftedLetterActivated() { private final boolean isShiftedLetterActivated() {
return (mLabelFlags & LABEL_FLAGS_SHIFTED_LETTER_ACTIVATED) != 0 return (mLabelFlags & LABEL_FLAGS_SHIFTED_LETTER_ACTIVATED) != 0
&& !TextUtils.isEmpty(mHintLabel); && !TextUtils.isEmpty(mHintLabel);

View File

@ -340,11 +340,25 @@ public class KeyboardView extends View {
// Draw key background. // 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 Drawable background) {
final int keyWidth = key.getDrawWidth();
final int keyHeight = key.getHeight();
final int bgWidth, bgHeight, bgX, bgY;
if (key.needsToKeepBackgroundAspectRatio(mDefaultKeyLabelFlags)) {
final int intrinsicWidth = background.getIntrinsicWidth();
final int intrinsicHeight = background.getIntrinsicHeight();
final float minScale = Math.min(
keyWidth / (float)intrinsicWidth, keyHeight / (float)intrinsicHeight);
bgWidth = (int)(intrinsicWidth * minScale);
bgHeight = (int)(intrinsicHeight * minScale);
bgX = (keyWidth - bgWidth) / 2;
bgY = (keyHeight - bgHeight) / 2;
} else {
final Rect padding = mKeyBackgroundPadding; final Rect padding = mKeyBackgroundPadding;
final int bgWidth = key.getDrawWidth() + padding.left + padding.right; bgWidth = keyWidth + padding.left + padding.right;
final int bgHeight = key.getHeight() + padding.top + padding.bottom; bgHeight = keyHeight + padding.top + padding.bottom;
final int bgX = -padding.left; bgX = -padding.left;
final int bgY = -padding.top; bgY = -padding.top;
}
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

@ -308,8 +308,8 @@ public final class MoreKeysKeyboard extends Keyboard {
dividerWidth = 0; dividerWidth = 0;
} }
final MoreKeySpec[] moreKeys = key.getMoreKeys(); final MoreKeySpec[] moreKeys = key.getMoreKeys();
mParams.setParameters(moreKeys.length, key.getMoreKeysColumnNumber(), keyWidth, rowHeight, mParams.setParameters(moreKeys.length, key.getMoreKeysColumnNumber(), keyWidth,
key.getX() + key.getWidth() / 2, keyboard.mId.mWidth, rowHeight, key.getX() + key.getWidth() / 2, keyboard.mId.mWidth,
key.isMoreKeysFixedColumn(), key.isMoreKeysFixedOrder(), dividerWidth); key.isMoreKeysFixedColumn(), key.isMoreKeysFixedOrder(), dividerWidth);
} }