aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardView.java27
-rw-r--r--java/src/com/android/inputmethod/keyboard/LatinKeyboard.java30
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/SlidingLocaleDrawable.java13
3 files changed, 44 insertions, 26 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index 8ca6ade6c..840e52894 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -118,6 +118,10 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
private final float mBackgroundDimAmount;
private final float mKeyHysteresisDistance;
private final float mVerticalCorrection;
+ private final Drawable mPreviewBackground;
+ private final Drawable mPreviewSpacebarBackground;
+ private final int mPreviewTextColor;
+ private final float mPreviewTextRatio;
private final int mPreviewOffset;
private final int mPreviewHeight;
private final int mPopupLayout;
@@ -138,9 +142,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
// Key preview
private boolean mInForeground;
- private TextView mPreviewText;
- private Drawable mPreviewBackground;
- private float mPreviewTextRatio;
+ private final TextView mPreviewText;
private int mPreviewTextSize;
private boolean mShowKeyPreviewPopup = true;
private final int mDelayBeforePreview;
@@ -342,7 +344,18 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
R.styleable.KeyboardView_keyHysteresisDistance, 0);
mVerticalCorrection = a.getDimensionPixelOffset(
R.styleable.KeyboardView_verticalCorrection, 0);
+ mPreviewTextColor = a.getColor(R.styleable.KeyboardView_keyPreviewTextColor, 0);
final int previewLayout = a.getResourceId(R.styleable.KeyboardView_keyPreviewLayout, 0);
+ if (previewLayout != 0) {
+ mPreviewText = (TextView) LayoutInflater.from(context).inflate(previewLayout, null);
+ mPreviewText.setTextColor(mPreviewTextColor);
+ } else {
+ mPreviewText = null;
+ mShowKeyPreviewPopup = false;
+ }
+ mPreviewBackground = a.getDrawable(R.styleable.KeyboardView_keyPreviewBackground);
+ mPreviewSpacebarBackground = a.getDrawable(
+ R.styleable.KeyboardView_keyPreviewSpacebarBackground);
mPreviewOffset = a.getDimensionPixelOffset(R.styleable.KeyboardView_keyPreviewOffset, 0);
mPreviewHeight = a.getDimensionPixelSize(R.styleable.KeyboardView_keyPreviewHeight, 80);
mKeyLetterRatio = getRatio(a, R.styleable.KeyboardView_keyLetterRatio);
@@ -374,12 +387,6 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
final Resources res = getResources();
- if (previewLayout != 0) {
- mPreviewText = (TextView) LayoutInflater.from(context).inflate(previewLayout, null);
- mPreviewBackground = mPreviewText.getBackground();
- } else {
- mShowKeyPreviewPopup = false;
- }
mDelayBeforePreview = res.getInteger(R.integer.config_delay_before_preview);
mDelayAfterPreview = res.getInteger(R.integer.config_delay_after_preview);
mKeyLabelHorizontalPadding = (int)res.getDimension(
@@ -1010,7 +1017,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
previewText.setText(null);
}
if (key.mCode == Keyboard.CODE_SPACE) {
- previewText.setBackgroundColor(Color.TRANSPARENT);
+ previewText.setBackgroundDrawable(mPreviewSpacebarBackground);
} else {
previewText.setBackgroundDrawable(mPreviewBackground);
}
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
index 00bf348f2..1966d2d65 100644
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
@@ -216,8 +216,12 @@ 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 = lArrow.getIntrinsicWidth();
- final float arrowHeight = lArrow.getIntrinsicHeight();
+ 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();
@@ -251,14 +255,17 @@ public class LatinKeyboard extends Keyboard {
paint.setTextSize(textSize);
// Place left and right arrow just before and after language text.
- final float textHeight = -paint.ascent() + paint.descent();
- final float baseline = (icon != null) ? height * SPACEBAR_LANGUAGE_BASELINE
- : height / 2 + textHeight / 2;
- 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);
+ 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;
}
@@ -323,7 +330,8 @@ public class LatinKeyboard extends Keyboard {
// 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 (mSubtypeSwitcher.useSpacebarLanguageSwitcher()
+ if (mSpacebarArrowLeftIcon != null && mSpacebarArrowRightIcon != null
+ && mSubtypeSwitcher.useSpacebarLanguageSwitcher()
&& mSubtypeSwitcher.getEnabledKeyboardLocaleCount() > 1
&& !(isPhoneKeyboard() || isNumberKeyboard())) {
mSpacebarArrowLeftIcon.setColorFilter(getSpacebarDrawableFilter(textFadeFactor));
diff --git a/java/src/com/android/inputmethod/keyboard/internal/SlidingLocaleDrawable.java b/java/src/com/android/inputmethod/keyboard/internal/SlidingLocaleDrawable.java
index f8c81adfb..78a3a7e9d 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/SlidingLocaleDrawable.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/SlidingLocaleDrawable.java
@@ -70,12 +70,15 @@ public class SlidingLocaleDrawable extends Drawable {
mTextPaint = textPaint;
mMiddleX = (background != null) ? (mWidth - mBackground.getIntrinsicWidth()) / 2 : 0;
- final TypedArray a = context.obtainStyledAttributes(
+ final TypedArray lka = context.obtainStyledAttributes(
null, R.styleable.LatinKeyboard, R.attr.latinKeyboardStyle, R.style.LatinKeyboard);
- mSpacebarTextColor = a.getColor(R.styleable.LatinKeyboard_spacebarTextColor, 0);
- mLeftDrawable = a.getDrawable(R.styleable.LatinKeyboard_spacebarArrowPreviewLeftIcon);
- mRightDrawable = a.getDrawable(R.styleable.LatinKeyboard_spacebarArrowPreviewRightIcon);
- a.recycle();
+ 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);
+ mSpacebarTextColor = kva.getColor(R.styleable.KeyboardView_keyPreviewTextColor, 0);
+ kva.recycle();
mThreshold = ViewConfiguration.get(context).getScaledTouchSlop();
}