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

* commit '486c4894ce0917fc7b18eaee4bfd031051f2b05b':
  Keep aspect ratio of Material action key background
This commit is contained in:
Tadashi G. Takaoka 2014-09-09 06:19:02 +00:00 committed by Android Git Automerger
commit 12814352dd
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
the key -->
<flag name="followFunctionalTextColor" value="0x80000" />
<!-- Keep aspect ratio of key background. -->
<flag name="keepBackgroundAspectRatio" value="0x100000" />
<!-- If true, disable keyHintLabel. -->
<flag name="disableKeyHintLabel" value="0x40000000" />
<!-- If true, disable additionalMoreKeys. -->

View file

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

View file

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

View file

@ -80,6 +80,8 @@
</default>
</switch>
<!-- Enter key style -->
<switch>
<case latin:keyboardTheme="ICS|KLP">
<key-style
latin:styleName="defaultEnterKeyStyle"
latin:keySpec="!icon/enter_key|!code/key_enter"
@ -87,6 +89,18 @@
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="action"
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" />
<switch>
<!-- Shift + Enter in textMultiLine field. -->

View file

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

View file

@ -212,6 +212,8 @@
</default>
</switch>
<!-- Enter key style -->
<switch>
<case latin:keyboardTheme="ICS|KLP">
<key-style
latin:styleName="defaultEnterKeyStyle"
latin:keySpec="!icon/enter_key|!code/key_enter"
@ -219,6 +221,18 @@
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="action"
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" />
<switch>
<!-- 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_FROM_CUSTOM_ACTION_LABEL = 0x40000;
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_ADDITIONAL_MORE_KEYS = 0x80000000;
@ -697,6 +698,10 @@ public class Key implements Comparable<Key> {
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() {
return (mLabelFlags & LABEL_FLAGS_SHIFTED_LETTER_ACTIVATED) != 0
&& !TextUtils.isEmpty(mHintLabel);

View file

@ -340,11 +340,25 @@ public class KeyboardView extends View {
// Draw key background.
protected void onDrawKeyBackground(final Key key, final Canvas canvas,
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 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;
bgWidth = keyWidth + padding.left + padding.right;
bgHeight = keyHeight + padding.top + padding.bottom;
bgX = -padding.left;
bgY = -padding.top;
}
final Rect bounds = background.getBounds();
if (bgWidth != bounds.right || bgHeight != bounds.bottom) {
background.setBounds(0, 0, bgWidth, bgHeight);

View file

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