Merge "Support 9-patch drawable for spacebar icon"
This commit is contained in:
commit
812d7d935a
13 changed files with 50 additions and 45 deletions
BIN
java/res/drawable-hdpi/sym_keyboard_spacebar_lxx_dark.9.png
Normal file
BIN
java/res/drawable-hdpi/sym_keyboard_spacebar_lxx_dark.9.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 199 B |
BIN
java/res/drawable-mdpi/sym_keyboard_spacebar_lxx_dark.9.png
Normal file
BIN
java/res/drawable-mdpi/sym_keyboard_spacebar_lxx_dark.9.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 185 B |
BIN
java/res/drawable-xhdpi/sym_keyboard_spacebar_lxx_dark.9.png
Normal file
BIN
java/res/drawable-xhdpi/sym_keyboard_spacebar_lxx_dark.9.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 246 B |
BIN
java/res/drawable-xxhdpi/sym_keyboard_spacebar_lxx_dark.9.png
Normal file
BIN
java/res/drawable-xxhdpi/sym_keyboard_spacebar_lxx_dark.9.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 180 B |
|
@ -51,6 +51,7 @@
|
|||
<!-- 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" />
|
||||
<attr name="spacebarIconWidthRatio" format="float" />
|
||||
<!-- Horizontal padding of left/right aligned key label to the edge of the key. -->
|
||||
<attr name="keyLabelHorizontalPadding" format="dimension" />
|
||||
<!-- Right padding of hint letter to the edge of the key.-->
|
||||
|
@ -284,6 +285,7 @@
|
|||
<!-- This should be aligned with Key.LABEL_FLAGS__* -->
|
||||
<flag name="alignLeft" value="0x01" />
|
||||
<flag name="alignRight" value="0x02" />
|
||||
<flag name="alignButtom" value="0x04" />
|
||||
<flag name="alignLeftOfCenter" value="0x08" />
|
||||
<flag name="fontNormal" value="0x10" />
|
||||
<flag name="fontMonoSpace" value="0x20" />
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
<item name="iconShiftKey">@drawable/sym_keyboard_shift_holo_dark</item>
|
||||
<item name="iconDeleteKey">@drawable/sym_keyboard_delete_lxx_dark</item>
|
||||
<item name="iconSettingsKey">@drawable/sym_keyboard_settings_lxx_dark</item>
|
||||
<item name="iconSpaceKey">@drawable/sym_keyboard_space_holo_dark</item>
|
||||
<item name="iconSpaceKey">@drawable/sym_keyboard_spacebar_lxx_dark</item>
|
||||
<item name="iconEnterKey">@drawable/sym_keyboard_return_holo_dark</item>
|
||||
<item name="iconGoKey">@drawable/sym_keyboard_go_lxx_dark</item>
|
||||
<item name="iconSearchKey">@drawable/sym_keyboard_search_lxx_dark</item>
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
<item name="keyBackground">@drawable/btn_keyboard_key_lxx</item>
|
||||
<item name="functionalKeyBackground">@drawable/btn_keyboard_key_functional_lxx</item>
|
||||
<item name="spacebarBackground">@drawable/btn_keyboard_spacebar_lxx</item>
|
||||
<item name="spacebarIconWidthRatio">0.9</item>
|
||||
<item name="keyTypeface">bold</item>
|
||||
<item name="keyTextColor">@color/key_text_color_holo</item>
|
||||
<item name="keyTextInactivatedColor">@color/key_text_inactive_color_lxx</item>
|
||||
|
|
|
@ -79,6 +79,7 @@
|
|||
<key-style
|
||||
latin:styleName="spaceKeyStyle"
|
||||
latin:keySpec="!icon/space_key|!code/key_space"
|
||||
latin:keyLabelFlags="alignButtom"
|
||||
latin:keyActionFlags="noKeyPreview|enableLongPress" />
|
||||
<!-- U+200C: ZERO WIDTH NON-JOINER
|
||||
U+200D: ZERO WIDTH JOINER -->
|
||||
|
|
|
@ -88,6 +88,7 @@
|
|||
<key-style
|
||||
latin:styleName="spaceKeyStyle"
|
||||
latin:keySpec="!icon/space_key|!code/key_space"
|
||||
latin:keyLabelFlags="alignButtom"
|
||||
latin:keyActionFlags="noKeyPreview|enableLongPress" />
|
||||
<!-- U+200C: ZERO WIDTH NON-JOINER
|
||||
U+200D: ZERO WIDTH JOINER -->
|
||||
|
|
|
@ -120,6 +120,7 @@
|
|||
<key-style
|
||||
latin:styleName="numSpaceKeyStyle"
|
||||
latin:keySpec="!icon/space_key_for_number_layout|!code/key_space"
|
||||
latin:keyLabelFlags="alignButtom"
|
||||
latin:keyActionFlags="enableLongPress"
|
||||
latin:parentStyle="numKeyBaseStyle" />
|
||||
<!-- Override defaultEnterKeyStyle in key_styles_enter.xml -->
|
||||
|
|
|
@ -60,6 +60,7 @@ public class Key implements Comparable<Key> {
|
|||
private final int mLabelFlags;
|
||||
private static final int LABEL_FLAGS_ALIGN_LEFT = 0x01;
|
||||
private static final int LABEL_FLAGS_ALIGN_RIGHT = 0x02;
|
||||
private static final int LABEL_FLAGS_ALIGN_BUTTOM = 0x04;
|
||||
private static final int LABEL_FLAGS_ALIGN_LEFT_OF_CENTER = 0x08;
|
||||
private static final int LABEL_FLAGS_FONT_NORMAL = 0x10;
|
||||
private static final int LABEL_FLAGS_FONT_MONO_SPACE = 0x20;
|
||||
|
@ -646,6 +647,10 @@ public class Key implements Comparable<Key> {
|
|||
return (mLabelFlags & LABEL_FLAGS_ALIGN_RIGHT) != 0;
|
||||
}
|
||||
|
||||
public final boolean isAlignButtom() {
|
||||
return (mLabelFlags & LABEL_FLAGS_ALIGN_BUTTOM) != 0;
|
||||
}
|
||||
|
||||
public final boolean isAlignLeftOfCenter() {
|
||||
return (mLabelFlags & LABEL_FLAGS_ALIGN_LEFT_OF_CENTER) != 0;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import android.graphics.Rect;
|
|||
import android.graphics.Region;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.NinePatchDrawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
|
@ -49,6 +50,7 @@ import java.util.HashSet;
|
|||
* @attr ref R.styleable#KeyboardView_keyBackground
|
||||
* @attr ref R.styleable#KeyboardView_functionalKeyBackground
|
||||
* @attr ref R.styleable#KeyboardView_spacebarBackground
|
||||
* @attr ref R.styleable#KeyboardView_spacebarIconWidthRatio
|
||||
* @attr ref R.styleable#KeyboardView_keyLabelHorizontalPadding
|
||||
* @attr ref R.styleable#KeyboardView_keyHintLetterPadding
|
||||
* @attr ref R.styleable#KeyboardView_keyPopupHintLetterPadding
|
||||
|
@ -85,6 +87,7 @@ public class KeyboardView extends View {
|
|||
private final Drawable mKeyBackground;
|
||||
private final Drawable mFunctionalKeyBackground;
|
||||
private final Drawable mSpacebarBackground;
|
||||
private final float mSpacebarIconWidthRatio;
|
||||
private final Rect mKeyBackgroundPadding = new Rect();
|
||||
private static final float KET_TEXT_SHADOW_RADIUS_DISABLED = -1.0f;
|
||||
|
||||
|
@ -135,8 +138,9 @@ public class KeyboardView extends View {
|
|||
: mKeyBackground;
|
||||
final Drawable spacebarBackground = keyboardViewAttr.getDrawable(
|
||||
R.styleable.KeyboardView_spacebarBackground);
|
||||
mSpacebarBackground = (spacebarBackground != null) ? spacebarBackground
|
||||
: mKeyBackground;
|
||||
mSpacebarBackground = (spacebarBackground != null) ? spacebarBackground : mKeyBackground;
|
||||
mSpacebarIconWidthRatio = keyboardViewAttr.getFloat(
|
||||
R.styleable.KeyboardView_spacebarIconWidthRatio, 1.0f);
|
||||
mKeyLabelHorizontalPadding = keyboardViewAttr.getDimensionPixelOffset(
|
||||
R.styleable.KeyboardView_keyLabelHorizontalPadding, 0);
|
||||
mKeyHintLetterPadding = keyboardViewAttr.getDimension(
|
||||
|
@ -513,10 +517,16 @@ public class KeyboardView extends View {
|
|||
|
||||
// Draw key icon.
|
||||
if (label == null && icon != null) {
|
||||
final int iconWidth = Math.min(icon.getIntrinsicWidth(), keyWidth);
|
||||
final int iconWidth;
|
||||
if (key.getCode() == Constants.CODE_SPACE && icon instanceof NinePatchDrawable) {
|
||||
iconWidth = (int)(keyWidth * mSpacebarIconWidthRatio);
|
||||
} else {
|
||||
iconWidth = Math.min(icon.getIntrinsicWidth(), keyWidth);
|
||||
}
|
||||
final int iconHeight = icon.getIntrinsicHeight();
|
||||
final int iconX, alignX;
|
||||
final int iconY = (keyHeight - iconHeight) / 2;
|
||||
final int iconY = key.isAlignButtom() ? keyHeight - iconHeight
|
||||
: (keyHeight - iconHeight) / 2;
|
||||
if (key.isAlignLeft()) {
|
||||
iconX = mKeyLabelHorizontalPadding;
|
||||
alignX = iconX;
|
||||
|
|
|
@ -27,7 +27,6 @@ import android.graphics.Color;
|
|||
import android.graphics.Paint;
|
||||
import android.graphics.Paint.Align;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
|
@ -116,7 +115,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
|||
|
||||
/* Space key and its icon and background. */
|
||||
private Key mSpaceKey;
|
||||
private Drawable mSpacebarIcon;
|
||||
// Stuff to draw language name on spacebar.
|
||||
private final int mLanguageOnSpacebarFinalAlpha;
|
||||
private ObjectAnimator mLanguageOnSpacebarFadeoutAnimator;
|
||||
|
@ -389,8 +387,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
|||
mMoreKeysKeyboardCache.clear();
|
||||
|
||||
mSpaceKey = keyboard.getKey(Constants.CODE_SPACE);
|
||||
mSpacebarIcon = (mSpaceKey != null)
|
||||
? mSpaceKey.getIcon(keyboard.mIconsSet, Constants.Color.ALPHA_OPAQUE) : null;
|
||||
final int keyHeight = keyboard.mMostCommonKeyHeight - keyboard.mVerticalGap;
|
||||
mLanguageOnSpacebarTextSize = keyHeight * mLanguageOnSpacebarTextRatio;
|
||||
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
||||
|
@ -847,18 +843,19 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
|||
if (key.altCodeWhileTyping() && key.isEnabled()) {
|
||||
params.mAnimAlpha = mAltCodeKeyWhileTypingAnimAlpha;
|
||||
}
|
||||
super.onDrawKeyTopVisuals(key, canvas, paint, params);
|
||||
final int code = key.getCode();
|
||||
if (code == Constants.CODE_SPACE) {
|
||||
drawSpacebar(key, canvas, paint);
|
||||
// If input language are explicitly selected.
|
||||
if (mLanguageOnSpacebarFormatType != LanguageOnSpacebarHelper.FORMAT_TYPE_NONE) {
|
||||
drawLanguageOnSpacebar(key, canvas, paint);
|
||||
}
|
||||
// Whether space key needs to show the "..." popup hint for special purposes
|
||||
if (key.isLongPressEnabled() && mHasMultipleEnabledIMEsOrSubtypes) {
|
||||
drawKeyPopupHint(key, canvas, paint, params);
|
||||
}
|
||||
} else if (code == Constants.CODE_LANGUAGE_SWITCH) {
|
||||
super.onDrawKeyTopVisuals(key, canvas, paint, params);
|
||||
drawKeyPopupHint(key, canvas, paint, params);
|
||||
} else {
|
||||
super.onDrawKeyTopVisuals(key, canvas, paint, params);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -898,42 +895,29 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
|||
return "";
|
||||
}
|
||||
|
||||
private void drawSpacebar(final Key key, final Canvas canvas, final Paint paint) {
|
||||
private void drawLanguageOnSpacebar(final Key key, final Canvas canvas, final Paint paint) {
|
||||
final int width = key.getWidth();
|
||||
final int height = key.getHeight();
|
||||
|
||||
// If input language are explicitly selected.
|
||||
if (mLanguageOnSpacebarFormatType != LanguageOnSpacebarHelper.FORMAT_TYPE_NONE) {
|
||||
paint.setTextAlign(Align.CENTER);
|
||||
paint.setTypeface(Typeface.DEFAULT);
|
||||
paint.setTextSize(mLanguageOnSpacebarTextSize);
|
||||
final InputMethodSubtype subtype = getKeyboard().mId.mSubtype;
|
||||
final String language = layoutLanguageOnSpacebar(paint, subtype, width);
|
||||
// Draw language text with shadow
|
||||
final float descent = paint.descent();
|
||||
final float textHeight = -paint.ascent() + descent;
|
||||
final float baseline = height / 2 + textHeight / 2;
|
||||
if (mLanguageOnSpacebarTextShadowRadius > 0.0f) {
|
||||
paint.setShadowLayer(mLanguageOnSpacebarTextShadowRadius, 0, 0,
|
||||
mLanguageOnSpacebarTextShadowColor);
|
||||
} else {
|
||||
paint.clearShadowLayer();
|
||||
}
|
||||
paint.setColor(mLanguageOnSpacebarTextColor);
|
||||
paint.setAlpha(mLanguageOnSpacebarAnimAlpha);
|
||||
canvas.drawText(language, width / 2, baseline - descent, paint);
|
||||
paint.setTextAlign(Align.CENTER);
|
||||
paint.setTypeface(Typeface.DEFAULT);
|
||||
paint.setTextSize(mLanguageOnSpacebarTextSize);
|
||||
final InputMethodSubtype subtype = getKeyboard().mId.mSubtype;
|
||||
final String language = layoutLanguageOnSpacebar(paint, subtype, width);
|
||||
// Draw language text with shadow
|
||||
final float descent = paint.descent();
|
||||
final float textHeight = -paint.ascent() + descent;
|
||||
final float baseline = height / 2 + textHeight / 2;
|
||||
if (mLanguageOnSpacebarTextShadowRadius > 0.0f) {
|
||||
paint.setShadowLayer(mLanguageOnSpacebarTextShadowRadius, 0, 0,
|
||||
mLanguageOnSpacebarTextShadowColor);
|
||||
} else {
|
||||
paint.clearShadowLayer();
|
||||
paint.setTextScaleX(1.0f);
|
||||
}
|
||||
|
||||
// Draw the spacebar icon at the bottom
|
||||
if (mSpacebarIcon != null) {
|
||||
final int iconWidth = mSpacebarIcon.getIntrinsicWidth();
|
||||
final int iconHeight = mSpacebarIcon.getIntrinsicHeight();
|
||||
int x = (width - iconWidth) / 2;
|
||||
int y = height - iconHeight;
|
||||
drawIcon(canvas, mSpacebarIcon, x, y, iconWidth, iconHeight);
|
||||
}
|
||||
paint.setColor(mLanguageOnSpacebarTextColor);
|
||||
paint.setAlpha(mLanguageOnSpacebarAnimAlpha);
|
||||
canvas.drawText(language, width / 2, baseline - descent, paint);
|
||||
paint.clearShadowLayer();
|
||||
paint.setTextScaleX(1.0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue