Render sliding spacebar language switch arrows by text

Change-Id: Ief1a4f12a3d4840c36aa7a082f44b5b1ff894dd1
main
Tadashi G. Takaoka 2011-06-28 02:08:40 +09:00
parent f41e9f79eb
commit 87089985b1
18 changed files with 33 additions and 98 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

View File

@ -309,9 +309,5 @@
<attr name="disabledShortcutIcon" format="reference" /> <attr name="disabledShortcutIcon" format="reference" />
<attr name="spacebarTextColor" format="color" /> <attr name="spacebarTextColor" format="color" />
<attr name="spacebarTextShadowColor" format="color" /> <attr name="spacebarTextShadowColor" format="color" />
<attr name="spacebarArrowLeftIcon" format="reference" />
<attr name="spacebarArrowRightIcon" format="reference" />
<attr name="spacebarArrowPreviewLeftIcon" format="reference" />
<attr name="spacebarArrowPreviewRightIcon" format="reference" />
</declare-styleable> </declare-styleable>
</resources> </resources>

View File

@ -38,9 +38,5 @@
<!-- LatinKeyboard icons --> <!-- LatinKeyboard icons -->
<item name="autoCorrectionSpacebarLedIcon">@drawable/sym_keyboard_space_led</item> <item name="autoCorrectionSpacebarLedIcon">@drawable/sym_keyboard_space_led</item>
<item name="disabledShortcutIcon">@drawable/sym_bkeyboard_voice_off</item> <item name="disabledShortcutIcon">@drawable/sym_bkeyboard_voice_off</item>
<item name="spacebarArrowLeftIcon">@null</item>
<item name="spacebarArrowRightIcon">@null</item>
<item name="spacebarArrowPreviewLeftIcon">@drawable/sym_keyboard_feedback_language_arrows_left</item>
<item name="spacebarArrowPreviewRightIcon">@drawable/sym_keyboard_feedback_language_arrows_right</item>
</style> </style>
</resources> </resources>

View File

@ -52,9 +52,5 @@
<!-- LatinKeyboard icons --> <!-- LatinKeyboard icons -->
<item name="autoCorrectionSpacebarLedIcon">@drawable/sym_keyboard_space_led</item> <item name="autoCorrectionSpacebarLedIcon">@drawable/sym_keyboard_space_led</item>
<item name="disabledShortcutIcon">@drawable/sym_keyboard_voice_off_holo</item> <item name="disabledShortcutIcon">@drawable/sym_keyboard_voice_off_holo</item>
<item name="spacebarArrowLeftIcon">@drawable/sym_keyboard_language_arrows_left</item>
<item name="spacebarArrowRightIcon">@drawable/sym_keyboard_language_arrows_right</item>
<item name="spacebarArrowPreviewLeftIcon">@null</item>
<item name="spacebarArrowPreviewRightIcon">@null</item>
</style> </style>
</resources> </resources>

View File

@ -34,9 +34,5 @@
<!-- LatinKeyboard icons --> <!-- LatinKeyboard icons -->
<item name="autoCorrectionSpacebarLedIcon">@drawable/sym_keyboard_space_led</item> <item name="autoCorrectionSpacebarLedIcon">@drawable/sym_keyboard_space_led</item>
<item name="disabledShortcutIcon">@drawable/sym_keyboard_voice_off_holo</item> <item name="disabledShortcutIcon">@drawable/sym_keyboard_voice_off_holo</item>
<item name="spacebarArrowLeftIcon">@drawable/sym_keyboard_language_arrows_left</item>
<item name="spacebarArrowRightIcon">@drawable/sym_keyboard_language_arrows_right</item>
<item name="spacebarArrowPreviewLeftIcon">@drawable/sym_keyboard_feedback_language_arrows_left</item>
<item name="spacebarArrowPreviewRightIcon">@drawable/sym_keyboard_feedback_language_arrows_right</item>
</style> </style>
</resources> </resources>

View File

@ -23,9 +23,6 @@ import android.content.res.TypedArray;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Paint.Align; import android.graphics.Paint.Align;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
@ -61,8 +58,6 @@ public class LatinKeyboard extends Keyboard {
private final int mSpaceKeyIndex; private final int mSpaceKeyIndex;
private final boolean mAutoCorrectionSpacebarLedEnabled; private final boolean mAutoCorrectionSpacebarLedEnabled;
private final Drawable mAutoCorrectionSpacebarLedIcon; private final Drawable mAutoCorrectionSpacebarLedIcon;
private final Drawable mSpacebarArrowLeftIcon;
private final Drawable mSpacebarArrowRightIcon;
private final int mSpacebarTextColor; private final int mSpacebarTextColor;
private final int mSpacebarTextShadowColor; private final int mSpacebarTextShadowColor;
private float mSpacebarTextFadeFactor = 0.0f; private float mSpacebarTextFadeFactor = 0.0f;
@ -77,6 +72,11 @@ public class LatinKeyboard extends Keyboard {
private final Drawable mEnabledShortcutIcon; private final Drawable mEnabledShortcutIcon;
private final Drawable mDisabledShortcutIcon; private final Drawable mDisabledShortcutIcon;
// BLACK LEFT-POINTING TRIANGLE and two spaces.
public static final String ARROW_LEFT = "\u25C0 ";
// Two spaces and BLACK RIGHT-POINTING TRIANGLE.
public static final String ARROW_RIGHT = " \u25B6";
// Minimum width of spacebar dragging to trigger the language switch (represented by the number // Minimum width of spacebar dragging to trigger the language switch (represented by the number
// of the most common key width of this keyboard). // of the most common key width of this keyboard).
private static final int SPACEBAR_DRAG_WIDTH = 3; private static final int SPACEBAR_DRAG_WIDTH = 3;
@ -131,10 +131,6 @@ public class LatinKeyboard extends Keyboard {
mSpacebarTextColor = a.getColor(R.styleable.LatinKeyboard_spacebarTextColor, 0); mSpacebarTextColor = a.getColor(R.styleable.LatinKeyboard_spacebarTextColor, 0);
mSpacebarTextShadowColor = a.getColor( mSpacebarTextShadowColor = a.getColor(
R.styleable.LatinKeyboard_spacebarTextShadowColor, 0); R.styleable.LatinKeyboard_spacebarTextShadowColor, 0);
mSpacebarArrowLeftIcon = a.getDrawable(
R.styleable.LatinKeyboard_spacebarArrowLeftIcon);
mSpacebarArrowRightIcon = a.getDrawable(
R.styleable.LatinKeyboard_spacebarArrowRightIcon);
a.recycle(); a.recycle();
// The threshold is "key width" x 1.25 // The threshold is "key width" x 1.25
@ -165,12 +161,6 @@ public class LatinKeyboard extends Keyboard {
return newColor; return newColor;
} }
private static ColorFilter getSpacebarDrawableFilter(float fadeFactor) {
final ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.setScale(1, 1, 1, fadeFactor);
return new ColorMatrixColorFilter(colorMatrix);
}
public void updateShortcutKey(boolean available, LatinKeyboardView view) { public void updateShortcutKey(boolean available, LatinKeyboardView view) {
if (mShortcutKey == null) if (mShortcutKey == null)
return; return;
@ -214,59 +204,40 @@ public class LatinKeyboard extends Keyboard {
} }
// Layout local language name and left and right arrow on spacebar. // Layout local language name and left and right arrow on spacebar.
private static String layoutSpacebar(Paint paint, Locale locale, Drawable icon, Drawable lArrow, private static String layoutSpacebar(Paint paint, Locale locale, int width,
Drawable rArrow, int width, int height, float origTextSize) { float origTextSize) {
final float arrowWidth;
if (lArrow != null && rArrow != null) {
arrowWidth = lArrow.getIntrinsicWidth();
} else {
arrowWidth = 0;
}
final float maxTextWidth = width - (arrowWidth + arrowWidth);
final Rect bounds = new Rect(); final Rect bounds = new Rect();
// Estimate appropriate language name text size to fit in maxTextWidth. // Estimate appropriate language name text size to fit in maxTextWidth.
String language = SubtypeSwitcher.getFullDisplayName(locale, true); String language = ARROW_LEFT + SubtypeSwitcher.getFullDisplayName(locale, true)
+ ARROW_RIGHT;
int textWidth = getTextWidth(paint, language, origTextSize, bounds); int textWidth = getTextWidth(paint, language, origTextSize, bounds);
// Assuming text width and text size are proportional to each other. // Assuming text width and text size are proportional to each other.
float textSize = origTextSize * Math.min(maxTextWidth / textWidth, 1.0f); float textSize = origTextSize * Math.min(width / textWidth, 1.0f);
// allow variable text size // allow variable text size
textWidth = getTextWidth(paint, language, textSize, bounds); textWidth = getTextWidth(paint, language, textSize, bounds);
// If text size goes too small or text does not fit, use middle or short name // If text size goes too small or text does not fit, use middle or short name
final boolean useMiddleName = (textSize / origTextSize < MINIMUM_SCALE_OF_LANGUAGE_NAME) final boolean useMiddleName = (textSize / origTextSize < MINIMUM_SCALE_OF_LANGUAGE_NAME)
|| (textWidth > maxTextWidth); || (textWidth > width);
final boolean useShortName; final boolean useShortName;
if (useMiddleName) { if (useMiddleName) {
language = SubtypeSwitcher.getMiddleDisplayLanguage(locale); language = ARROW_LEFT + SubtypeSwitcher.getMiddleDisplayLanguage(locale) + ARROW_RIGHT;
textWidth = getTextWidth(paint, language, origTextSize, bounds); textWidth = getTextWidth(paint, language, origTextSize, bounds);
textSize = origTextSize * Math.min(maxTextWidth / textWidth, 1.0f); textSize = origTextSize * Math.min(width / textWidth, 1.0f);
useShortName = (textSize / origTextSize < MINIMUM_SCALE_OF_LANGUAGE_NAME) useShortName = (textSize / origTextSize < MINIMUM_SCALE_OF_LANGUAGE_NAME)
|| (textWidth > maxTextWidth); || (textWidth > width);
} else { } else {
useShortName = false; useShortName = false;
} }
if (useShortName) { if (useShortName) {
language = SubtypeSwitcher.getShortDisplayLanguage(locale); language = ARROW_LEFT + SubtypeSwitcher.getShortDisplayLanguage(locale) + ARROW_RIGHT;
textWidth = getTextWidth(paint, language, origTextSize, bounds); textWidth = getTextWidth(paint, language, origTextSize, bounds);
textSize = origTextSize * Math.min(maxTextWidth / textWidth, 1.0f); textSize = origTextSize * Math.min(width / textWidth, 1.0f);
} }
paint.setTextSize(textSize); paint.setTextSize(textSize);
// Place left and right arrow just before and after language text.
if (lArrow != null && rArrow != null) {
final float textHeight = -paint.ascent() + paint.descent();
final float baseline = (icon != null) ? height * SPACEBAR_LANGUAGE_BASELINE
: height / 2 + textHeight / 2;
final int arrowHeight = lArrow.getIntrinsicHeight();
final int top = (int)(baseline - arrowHeight);
final float remains = (width - textWidth) / 2;
lArrow.setBounds((int)(remains - arrowWidth), top, (int)remains, (int)baseline);
rArrow.setBounds((int)(remains + textWidth), top,
(int)(remains + textWidth + arrowWidth), (int)baseline);
}
return language; return language;
} }
@ -311,9 +282,8 @@ public class LatinKeyboard extends Keyboard {
defaultTextSize = 14; defaultTextSize = 14;
} }
final String language = layoutSpacebar(paint, inputLocale, mSpaceIcon, final String language = layoutSpacebar(paint, inputLocale, width, getTextSizeFromTheme(
mSpacebarArrowLeftIcon, mSpacebarArrowRightIcon, width, height, mTheme, textStyle, defaultTextSize));
getTextSizeFromTheme(mTheme, textStyle, defaultTextSize));
// Draw language text with shadow // Draw language text with shadow
// In case there is no space icon, we will place the language text at the center of // In case there is no space icon, we will place the language text at the center of
@ -326,19 +296,6 @@ public class LatinKeyboard extends Keyboard {
canvas.drawText(language, width / 2, baseline - descent - 1, paint); canvas.drawText(language, width / 2, baseline - descent - 1, paint);
paint.setColor(getSpacebarTextColor(mSpacebarTextColor, textFadeFactor)); paint.setColor(getSpacebarTextColor(mSpacebarTextColor, textFadeFactor));
canvas.drawText(language, width / 2, baseline - descent, paint); canvas.drawText(language, width / 2, baseline - descent, paint);
// Put arrows that are already laid out on either side of the text
// Because language switch is disabled on phone and number layouts, hide arrows.
// TODO: Sort out how to enable language switch on these layouts.
if (mSpacebarArrowLeftIcon != null && mSpacebarArrowRightIcon != null
&& mSubtypeSwitcher.useSpacebarLanguageSwitcher()
&& mSubtypeSwitcher.getEnabledKeyboardLocaleCount() > 1
&& !(isPhoneKeyboard() || isNumberKeyboard())) {
mSpacebarArrowLeftIcon.setColorFilter(getSpacebarDrawableFilter(textFadeFactor));
mSpacebarArrowRightIcon.setColorFilter(getSpacebarDrawableFilter(textFadeFactor));
mSpacebarArrowLeftIcon.draw(canvas);
mSpacebarArrowRightIcon.draw(canvas);
}
} }
// Draw the spacebar icon at the bottom // Draw the spacebar icon at the bottom

View File

@ -46,8 +46,7 @@ public class SlidingLocaleDrawable extends Drawable {
private final int mSpacebarTextColor; private final int mSpacebarTextColor;
private final TextPaint mTextPaint; private final TextPaint mTextPaint;
private final int mMiddleX; private final int mMiddleX;
private final Drawable mLeftDrawable; private final boolean mDrawArrows;
private final Drawable mRightDrawable;
private final int mThreshold; private final int mThreshold;
private int mDiff; private int mDiff;
@ -65,20 +64,18 @@ public class SlidingLocaleDrawable extends Drawable {
textPaint.setTextSize(LatinKeyboard.getTextSizeFromTheme( textPaint.setTextSize(LatinKeyboard.getTextSizeFromTheme(
context.getTheme(), android.R.style.TextAppearance_Medium, 18)); context.getTheme(), android.R.style.TextAppearance_Medium, 18));
textPaint.setColor(Color.TRANSPARENT); textPaint.setColor(Color.TRANSPARENT);
textPaint.setTextAlign(Align.CENTER);
textPaint.setAntiAlias(true); textPaint.setAntiAlias(true);
mTextPaint = textPaint; mTextPaint = textPaint;
mMiddleX = (background != null) ? (mWidth - mBackground.getIntrinsicWidth()) / 2 : 0; mMiddleX = (background != null) ? (mWidth - mBackground.getIntrinsicWidth()) / 2 : 0;
final TypedArray lka = context.obtainStyledAttributes( final TypedArray a = context.obtainStyledAttributes(
null, R.styleable.LatinKeyboard, R.attr.latinKeyboardStyle, R.style.LatinKeyboard);
mLeftDrawable = lka.getDrawable(R.styleable.LatinKeyboard_spacebarArrowPreviewLeftIcon);
mRightDrawable = lka.getDrawable(R.styleable.LatinKeyboard_spacebarArrowPreviewRightIcon);
lka.recycle();
final TypedArray kva = context.obtainStyledAttributes(
null, R.styleable.KeyboardView, R.attr.keyboardViewStyle, R.style.KeyboardView); null, R.styleable.KeyboardView, R.attr.keyboardViewStyle, R.style.KeyboardView);
mSpacebarTextColor = kva.getColor(R.styleable.KeyboardView_keyPreviewTextColor, 0); mSpacebarTextColor = a.getColor(R.styleable.KeyboardView_keyPreviewTextColor, 0);
kva.recycle(); final int spacebarPreviewBackrgound = a.getResourceId(
R.styleable.KeyboardView_keyPreviewSpacebarBackground, 0);
// If spacebar preview background is transparent, we need not draw arrows.
mDrawArrows = (spacebarPreviewBackrgound != R.drawable.transparent);
a.recycle();
mThreshold = ViewConfiguration.get(context).getScaledTouchSlop(); mThreshold = ViewConfiguration.get(context).getScaledTouchSlop();
} }
@ -105,8 +102,6 @@ public class SlidingLocaleDrawable extends Drawable {
final int width = mWidth; final int width = mWidth;
final int height = mHeight; final int height = mHeight;
final int diff = mDiff; final int diff = mDiff;
final Drawable lArrow = mLeftDrawable;
final Drawable rArrow = mRightDrawable;
canvas.clipRect(0, 0, width, height); canvas.clipRect(0, 0, width, height);
if (mCurrentLanguage == null) { if (mCurrentLanguage == null) {
SubtypeSwitcher subtypeSwitcher = SubtypeSwitcher.getInstance(); SubtypeSwitcher subtypeSwitcher = SubtypeSwitcher.getInstance();
@ -114,20 +109,19 @@ public class SlidingLocaleDrawable extends Drawable {
mNextLanguage = subtypeSwitcher.getNextInputLanguageName(); mNextLanguage = subtypeSwitcher.getNextInputLanguageName();
mPrevLanguage = subtypeSwitcher.getPreviousInputLanguageName(); mPrevLanguage = subtypeSwitcher.getPreviousInputLanguageName();
} }
// Draw language text with shadow // Draw language text.
final float baseline = mHeight * LatinKeyboard.SPACEBAR_LANGUAGE_BASELINE final float baseline = mHeight * LatinKeyboard.SPACEBAR_LANGUAGE_BASELINE
- paint.descent(); - paint.descent();
paint.setColor(mSpacebarTextColor); paint.setColor(mSpacebarTextColor);
paint.setTextAlign(Align.CENTER);
canvas.drawText(mCurrentLanguage, width / 2 + diff, baseline, paint); canvas.drawText(mCurrentLanguage, width / 2 + diff, baseline, paint);
canvas.drawText(mNextLanguage, diff - width / 2, baseline, paint); canvas.drawText(mNextLanguage, diff - width / 2, baseline, paint);
canvas.drawText(mPrevLanguage, diff + width + width / 2, baseline, paint); canvas.drawText(mPrevLanguage, diff + width + width / 2, baseline, paint);
if (mDrawArrows) {
if (lArrow != null && rArrow != null) { paint.setTextAlign(Align.LEFT);
Keyboard.setDefaultBounds(lArrow); canvas.drawText(LatinKeyboard.ARROW_LEFT, 0, baseline, paint);
rArrow.setBounds(width - rArrow.getIntrinsicWidth(), 0, width, paint.setTextAlign(Align.RIGHT);
rArrow.getIntrinsicHeight()); canvas.drawText(LatinKeyboard.ARROW_RIGHT, width, baseline, paint);
lArrow.draw(canvas);
rArrow.draw(canvas);
} }
} }
if (mBackground != null) { if (mBackground != null) {