aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2011-06-28 02:08:40 +0900
committerTadashi G. Takaoka <takaoka@google.com>2011-06-28 15:58:45 +0900
commit87089985b1ca396557d1350e9433c958a39adf11 (patch)
tree955f42cded3de1679ad3db97d5d0e93690b6624e /java/src
parentf41e9f79eb19fc881b1f8fd76a767d6edf375f19 (diff)
downloadlatinime-87089985b1ca396557d1350e9433c958a39adf11.tar.gz
latinime-87089985b1ca396557d1350e9433c958a39adf11.tar.xz
latinime-87089985b1ca396557d1350e9433c958a39adf11.zip
Render sliding spacebar language switch arrows by text
Change-Id: Ief1a4f12a3d4840c36aa7a082f44b5b1ff894dd1
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/LatinKeyboard.java79
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/SlidingLocaleDrawable.java36
2 files changed, 33 insertions, 82 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
index 1966d2d65..9d58f69ff 100644
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
@@ -23,9 +23,6 @@ import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
-import android.graphics.ColorFilter;
-import android.graphics.ColorMatrix;
-import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.PorterDuff;
@@ -61,8 +58,6 @@ public class LatinKeyboard extends Keyboard {
private final int mSpaceKeyIndex;
private final boolean mAutoCorrectionSpacebarLedEnabled;
private final Drawable mAutoCorrectionSpacebarLedIcon;
- private final Drawable mSpacebarArrowLeftIcon;
- private final Drawable mSpacebarArrowRightIcon;
private final int mSpacebarTextColor;
private final int mSpacebarTextShadowColor;
private float mSpacebarTextFadeFactor = 0.0f;
@@ -77,6 +72,11 @@ public class LatinKeyboard extends Keyboard {
private final Drawable mEnabledShortcutIcon;
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
// of the most common key width of this keyboard).
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);
mSpacebarTextShadowColor = a.getColor(
R.styleable.LatinKeyboard_spacebarTextShadowColor, 0);
- mSpacebarArrowLeftIcon = a.getDrawable(
- R.styleable.LatinKeyboard_spacebarArrowLeftIcon);
- mSpacebarArrowRightIcon = a.getDrawable(
- R.styleable.LatinKeyboard_spacebarArrowRightIcon);
a.recycle();
// The threshold is "key width" x 1.25
@@ -165,12 +161,6 @@ public class LatinKeyboard extends Keyboard {
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) {
if (mShortcutKey == null)
return;
@@ -214,59 +204,40 @@ public class LatinKeyboard extends Keyboard {
}
// Layout local language name and left and right arrow on spacebar.
- private static String layoutSpacebar(Paint paint, Locale locale, Drawable icon, Drawable lArrow,
- Drawable rArrow, int width, int height, float origTextSize) {
- final float arrowWidth;
- if (lArrow != null && rArrow != null) {
- arrowWidth = lArrow.getIntrinsicWidth();
- } else {
- arrowWidth = 0;
- }
- final float maxTextWidth = width - (arrowWidth + arrowWidth);
+ private static String layoutSpacebar(Paint paint, Locale locale, int width,
+ float origTextSize) {
final Rect bounds = new Rect();
// 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);
// 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
textWidth = getTextWidth(paint, language, textSize, bounds);
// 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)
- || (textWidth > maxTextWidth);
+ || (textWidth > width);
final boolean useShortName;
if (useMiddleName) {
- language = SubtypeSwitcher.getMiddleDisplayLanguage(locale);
+ language = ARROW_LEFT + SubtypeSwitcher.getMiddleDisplayLanguage(locale) + ARROW_RIGHT;
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)
- || (textWidth > maxTextWidth);
+ || (textWidth > width);
} else {
useShortName = false;
}
if (useShortName) {
- language = SubtypeSwitcher.getShortDisplayLanguage(locale);
+ language = ARROW_LEFT + SubtypeSwitcher.getShortDisplayLanguage(locale) + ARROW_RIGHT;
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);
- // 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;
}
@@ -311,9 +282,8 @@ public class LatinKeyboard extends Keyboard {
defaultTextSize = 14;
}
- final String language = layoutSpacebar(paint, inputLocale, mSpaceIcon,
- mSpacebarArrowLeftIcon, mSpacebarArrowRightIcon, width, height,
- getTextSizeFromTheme(mTheme, textStyle, defaultTextSize));
+ final String language = layoutSpacebar(paint, inputLocale, width, getTextSizeFromTheme(
+ mTheme, textStyle, defaultTextSize));
// Draw language text with shadow
// 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);
paint.setColor(getSpacebarTextColor(mSpacebarTextColor, textFadeFactor));
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
diff --git a/java/src/com/android/inputmethod/keyboard/internal/SlidingLocaleDrawable.java b/java/src/com/android/inputmethod/keyboard/internal/SlidingLocaleDrawable.java
index 78a3a7e9d..ef3ea4c12 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/SlidingLocaleDrawable.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/SlidingLocaleDrawable.java
@@ -46,8 +46,7 @@ public class SlidingLocaleDrawable extends Drawable {
private final int mSpacebarTextColor;
private final TextPaint mTextPaint;
private final int mMiddleX;
- private final Drawable mLeftDrawable;
- private final Drawable mRightDrawable;
+ private final boolean mDrawArrows;
private final int mThreshold;
private int mDiff;
@@ -65,20 +64,18 @@ public class SlidingLocaleDrawable extends Drawable {
textPaint.setTextSize(LatinKeyboard.getTextSizeFromTheme(
context.getTheme(), android.R.style.TextAppearance_Medium, 18));
textPaint.setColor(Color.TRANSPARENT);
- textPaint.setTextAlign(Align.CENTER);
textPaint.setAntiAlias(true);
mTextPaint = textPaint;
mMiddleX = (background != null) ? (mWidth - mBackground.getIntrinsicWidth()) / 2 : 0;
- final TypedArray lka = 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(
+ final TypedArray a = context.obtainStyledAttributes(
null, R.styleable.KeyboardView, R.attr.keyboardViewStyle, R.style.KeyboardView);
- mSpacebarTextColor = kva.getColor(R.styleable.KeyboardView_keyPreviewTextColor, 0);
- kva.recycle();
+ mSpacebarTextColor = a.getColor(R.styleable.KeyboardView_keyPreviewTextColor, 0);
+ 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();
}
@@ -105,8 +102,6 @@ public class SlidingLocaleDrawable extends Drawable {
final int width = mWidth;
final int height = mHeight;
final int diff = mDiff;
- final Drawable lArrow = mLeftDrawable;
- final Drawable rArrow = mRightDrawable;
canvas.clipRect(0, 0, width, height);
if (mCurrentLanguage == null) {
SubtypeSwitcher subtypeSwitcher = SubtypeSwitcher.getInstance();
@@ -114,20 +109,19 @@ public class SlidingLocaleDrawable extends Drawable {
mNextLanguage = subtypeSwitcher.getNextInputLanguageName();
mPrevLanguage = subtypeSwitcher.getPreviousInputLanguageName();
}
- // Draw language text with shadow
+ // Draw language text.
final float baseline = mHeight * LatinKeyboard.SPACEBAR_LANGUAGE_BASELINE
- paint.descent();
paint.setColor(mSpacebarTextColor);
+ paint.setTextAlign(Align.CENTER);
canvas.drawText(mCurrentLanguage, width / 2 + diff, baseline, paint);
canvas.drawText(mNextLanguage, diff - width / 2, baseline, paint);
canvas.drawText(mPrevLanguage, diff + width + width / 2, baseline, paint);
-
- if (lArrow != null && rArrow != null) {
- Keyboard.setDefaultBounds(lArrow);
- rArrow.setBounds(width - rArrow.getIntrinsicWidth(), 0, width,
- rArrow.getIntrinsicHeight());
- lArrow.draw(canvas);
- rArrow.draw(canvas);
+ if (mDrawArrows) {
+ paint.setTextAlign(Align.LEFT);
+ canvas.drawText(LatinKeyboard.ARROW_LEFT, 0, baseline, paint);
+ paint.setTextAlign(Align.RIGHT);
+ canvas.drawText(LatinKeyboard.ARROW_RIGHT, width, baseline, paint);
}
}
if (mBackground != null) {