diff options
Diffstat (limited to 'java/src')
12 files changed, 232 insertions, 155 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index cb529461a..e5ee272a2 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -37,25 +37,24 @@ public class Key { * The key code (unicode or custom code) that this key generates. */ public final int mCode; - /** The unicode that this key generates in manual temporary upper case mode. */ - public final int mManualTemporaryUpperCaseCode; /** Label to display */ public final CharSequence mLabel; + /** Hint letter to display on the key in conjunction with the label */ + public final CharSequence mHintLetter; /** Option of the label */ public final int mLabelOption; + public static final int LABEL_OPTION_ALIGN_LEFT = 0x01; + public static final int LABEL_OPTION_ALIGN_RIGHT = 0x02; + public static final int LABEL_OPTION_ALIGN_BOTTOM = 0x08; + public static final int LABEL_OPTION_FONT_NORMAL = 0x10; + private static final int LABEL_OPTION_POPUP_HINT = 0x20; + private static final int LABEL_OPTION_HAS_UPPERCASE_LETTER = 0x40; /** Icon to display instead of a label. Icon takes precedence over a label */ private Drawable mIcon; /** Preview version of the icon, for the preview popup */ private Drawable mPreviewIcon; - /** Hint icon to display on the key in conjunction with the label */ - public final Drawable mHintIcon; - /** - * The hint icon to display on the key when keyboard is in manual temporary upper case - * mode. - */ - public final Drawable mManualTemporaryUpperCaseHintIcon; /** Width of the key, not including the gap */ public final int mWidth; @@ -154,9 +153,7 @@ public class Key { mVisualInsetsLeft = mVisualInsetsRight = 0; mWidth = width - mGap; mEdgeFlags = edgeFlags; - mHintIcon = null; - mManualTemporaryUpperCaseHintIcon = null; - mManualTemporaryUpperCaseCode = Keyboard.CODE_DUMMY; + mHintLetter = null; mLabelOption = 0; mFunctional = false; mSticky = false; @@ -273,16 +270,10 @@ public class Key { Keyboard.setDefaultBounds(mPreviewIcon); mIcon = style.getDrawable(keyAttr, R.styleable.Keyboard_Key_keyIcon); Keyboard.setDefaultBounds(mIcon); - mHintIcon = style.getDrawable(keyAttr, R.styleable.Keyboard_Key_keyHintIcon); - Keyboard.setDefaultBounds(mHintIcon); - mManualTemporaryUpperCaseHintIcon = style.getDrawable(keyAttr, - R.styleable.Keyboard_Key_manualTemporaryUpperCaseHintIcon); - Keyboard.setDefaultBounds(mManualTemporaryUpperCaseHintIcon); + mHintLetter = style.getText(keyAttr, R.styleable.Keyboard_Key_keyHintLetter); mLabel = style.getText(keyAttr, R.styleable.Keyboard_Key_keyLabel); mLabelOption = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyLabelOption, 0); - mManualTemporaryUpperCaseCode = style.getInt(keyAttr, - R.styleable.Keyboard_Key_manualTemporaryUpperCaseCode, Keyboard.CODE_DUMMY); mOutputText = style.getText(keyAttr, R.styleable.Keyboard_Key_keyOutputText); // Choose the first letter of the label as primary code if not // specified. @@ -305,6 +296,14 @@ public class Key { } } + public boolean hasPopupHint() { + return (mLabelOption & LABEL_OPTION_POPUP_HINT) != 0; + } + + public boolean hasUppercaseLetter() { + return (mLabelOption & LABEL_OPTION_HAS_UPPERCASE_LETTER) != 0; + } + private static boolean isDigitPopupCharacter(CharSequence label) { return label != null && label.length() == 1 && Character.isDigit(label.charAt(0)); } diff --git a/java/src/com/android/inputmethod/keyboard/KeyStyles.java b/java/src/com/android/inputmethod/keyboard/KeyStyles.java index d53df788f..ce5ee5495 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyStyles.java +++ b/java/src/com/android/inputmethod/keyboard/KeyStyles.java @@ -183,7 +183,7 @@ public class KeyStyles { readText(keyAttr, R.styleable.Keyboard_Key_keyOutputText); readDrawable(keyAttr, R.styleable.Keyboard_Key_keyIcon); readDrawable(keyAttr, R.styleable.Keyboard_Key_iconPreview); - readDrawable(keyAttr, R.styleable.Keyboard_Key_keyHintIcon); + readText(keyAttr, R.styleable.Keyboard_Key_keyHintLetter); readDrawable(keyAttr, R.styleable.Keyboard_Key_shiftedIcon); readBoolean(keyAttr, R.styleable.Keyboard_Key_isFunctional); readBoolean(keyAttr, R.styleable.Keyboard_Key_isSticky); diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index 267abccb3..3db214ec9 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -16,15 +16,16 @@ package com.android.inputmethod.keyboard; -import com.android.inputmethod.latin.R; - -import org.xmlpull.v1.XmlPullParserException; - import android.content.Context; import android.content.res.Resources; +import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.util.Log; +import com.android.inputmethod.latin.R; + +import org.xmlpull.v1.XmlPullParserException; + import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; @@ -171,8 +172,13 @@ public class Keyboard { mDefaultVerticalGap = 0; mDefaultHeight = mDefaultWidth; mId = id; - loadKeyboard(context, xmlLayoutResId); mProximityInfo = new ProximityInfo(GRID_WIDTH, GRID_HEIGHT); + + final TypedArray attrs = context.obtainStyledAttributes( + null, R.styleable.Keyboard, R.attr.keyboardStyle, R.style.Keyboard); + attrs.recycle(); + + loadKeyboard(context, xmlLayoutResId); } public int getProximityInfo() { diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java b/java/src/com/android/inputmethod/keyboard/KeyboardParser.java index c2db62a1c..07166b1db 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardParser.java @@ -16,12 +16,6 @@ package com.android.inputmethod.keyboard; -import com.android.inputmethod.compat.EditorInfoCompatUtils; -import com.android.inputmethod.latin.R; - -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; - import android.content.Context; import android.content.res.Resources; import android.content.res.TypedArray; @@ -31,6 +25,12 @@ import android.util.TypedValue; import android.util.Xml; import android.view.InflateException; +import com.android.inputmethod.compat.EditorInfoCompatUtils; +import com.android.inputmethod.latin.R; + +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; + import java.io.IOException; import java.util.Arrays; import java.util.List; diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 8e9c7ef7e..50c61ffae 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -202,7 +202,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha final Locale savedLocale = Utils.setSystemLocale(res, mSubtypeSwitcher.getInputLocale()); - keyboard = new LatinKeyboard(mInputMethodService, id, id.mWidth); + final Context themeContext = new ContextThemeWrapper(mInputMethodService, + KEYBOARD_THEMES[mThemeIndex]); + keyboard = new LatinKeyboard(themeContext, id, id.mWidth); if (id.mEnableShiftLock) { keyboard.enableShiftLock(); diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index f8bce40b1..44f2ff3ff 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -16,9 +16,6 @@ package com.android.inputmethod.keyboard; -import com.android.inputmethod.latin.LatinImeLogger; -import com.android.inputmethod.latin.R; - import android.content.Context; import android.content.pm.PackageManager; import android.content.res.Resources; @@ -50,6 +47,9 @@ import android.widget.LinearLayout; import android.widget.PopupWindow; import android.widget.TextView; +import com.android.inputmethod.latin.LatinImeLogger; +import com.android.inputmethod.latin.R; + import java.util.ArrayList; import java.util.HashMap; import java.util.WeakHashMap; @@ -63,13 +63,18 @@ import java.util.WeakHashMap; * @attr ref R.styleable#KeyboardView_keyBackground * @attr ref R.styleable#KeyboardView_keyHysteresisDistance * @attr ref R.styleable#KeyboardView_keyLetterRatio - * @attr ref R.styleable#KeyboardView_keyLetterStyle + * @attr ref R.styleable#KeyboardView_keyLabelRatio + * @attr ref R.styleable#KeyboardView_keyHintLetterRatio + * @attr ref R.styleable#KeyboardView_keyUppercaseLetterRatio + * @attr ref R.styleable#KeyboardView_keyTextStyle * @attr ref R.styleable#KeyboardView_keyPreviewLayout * @attr ref R.styleable#KeyboardView_keyPreviewOffset * @attr ref R.styleable#KeyboardView_keyPreviewHeight * @attr ref R.styleable#KeyboardView_keyTextColor * @attr ref R.styleable#KeyboardView_keyTextColorDisabled - * @attr ref R.styleable#KeyboardView_labelTextRatio + * @attr ref R.styleable#KeyboardView_keyHintLetterColor + * @attr ref R.styleable#KeyboardView_keyUppercaseLetterInactivatedColor + * @attr ref R.styleable#KeyboardView_keyUppercaseLetterActivatedColor * @attr ref R.styleable#KeyboardView_verticalCorrection * @attr ref R.styleable#KeyboardView_popupLayout * @attr ref R.styleable#KeyboardView_shadowColor @@ -96,9 +101,11 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { // XML attribute private final float mKeyLetterRatio; private final int mKeyTextColor; - private final int mKeyTextColorDisabled; - private final Typeface mKeyLetterStyle; - private final float mLabelTextRatio; + private final int mKeyTextInactivatedColor; + private final Typeface mKeyTextStyle; + private final float mKeyLabelRatio; + private final float mKeyHintLetterRatio; + private final float mKeyUppercaseLetterRatio; private final int mColorScheme; private final int mShadowColor; private final float mShadowRadius; @@ -109,11 +116,17 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { private final int mPreviewOffset; private final int mPreviewHeight; private final int mPopupLayout; + private final Drawable mKeyPopupHintIcon; + private final int mKeyHintLetterColor; + private final int mKeyUppercaseLetterInactivatedColor; + private final int mKeyUppercaseLetterActivatedColor; // Main keyboard private Keyboard mKeyboard; private int mKeyLetterSize; - private int mLabelTextSize; + private int mKeyLabelSize; + private int mKeyHintLetterSize; + private int mKeyUppercaseLetterSize; // Key preview private boolean mInForeground; @@ -168,18 +181,17 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { private Bitmap mBuffer; /** The canvas for the above mutable keyboard bitmap */ private Canvas mCanvas; - private final Paint mPaint; - private final Rect mPadding; + private final Paint mPaint = new Paint(); + private final Rect mPadding = new Rect(); + private final Rect mTextBounds = new Rect(); // This map caches key label text height in pixel as value and key label text size as map key. private final HashMap<Integer, Integer> mTextHeightCache = new HashMap<Integer, Integer>(); + // This map caches key label text width in pixel as value and key label text size as map key. + private final HashMap<Integer, Integer> mTextWidthCache = new HashMap<Integer, Integer>(); // Distance from horizontal center of the key, proportional to key label text height and width. - private final float KEY_LABEL_VERTICAL_ADJUSTMENT_FACTOR_CENTER = 0.45f; - private final float KEY_LABEL_VERTICAL_PADDING_FACTOR = 1.60f; - private final String KEY_LABEL_REFERENCE_CHAR = "H"; - private final int KEY_LABEL_OPTION_ALIGN_LEFT = 1; - private final int KEY_LABEL_OPTION_ALIGN_RIGHT = 2; - private final int KEY_LABEL_OPTION_ALIGN_BOTTOM = 8; - private final int KEY_LABEL_OPTION_FONT_NORMAL = 16; + private static final float KEY_LABEL_VERTICAL_ADJUSTMENT_FACTOR_CENTER = 0.45f; + private static final float KEY_LABEL_VERTICAL_PADDING_FACTOR = 1.60f; + private static final String KEY_LABEL_REFERENCE_CHAR = "M"; private final int mKeyLabelHorizontalPadding; private final UIHandler mHandler = new UIHandler(); @@ -321,18 +333,28 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { mPreviewOffset = a.getDimensionPixelOffset(R.styleable.KeyboardView_keyPreviewOffset, 0); mPreviewHeight = a.getDimensionPixelSize(R.styleable.KeyboardView_keyPreviewHeight, 80); mKeyLetterRatio = getRatio(a, R.styleable.KeyboardView_keyLetterRatio); + mKeyLabelRatio = getRatio(a, R.styleable.KeyboardView_keyLabelRatio); + mKeyHintLetterRatio = getRatio(a, R.styleable.KeyboardView_keyHintLetterRatio); + mKeyUppercaseLetterRatio = getRatio(a, + R.styleable.KeyboardView_keyUppercaseLetterRatio); mKeyTextColor = a.getColor(R.styleable.KeyboardView_keyTextColor, 0xFF000000); - mKeyTextColorDisabled = a.getColor( - R.styleable.KeyboardView_keyTextColorDisabled, 0xFF000000); - mLabelTextRatio = getRatio(a, R.styleable.KeyboardView_labelTextRatio); + mKeyTextInactivatedColor = a.getColor( + R.styleable.KeyboardView_keyTextInactivatedColor, 0xFF000000); + mKeyPopupHintIcon = a.getDrawable(R.styleable.KeyboardView_keyPopupHintIcon); + mKeyHintLetterColor = a.getColor(R.styleable.KeyboardView_keyHintLetterColor, 0); + mKeyUppercaseLetterInactivatedColor = a.getColor( + R.styleable.KeyboardView_keyUppercaseLetterInactivatedColor, 0); + mKeyUppercaseLetterActivatedColor = a.getColor( + R.styleable.KeyboardView_keyUppercaseLetterActivatedColor, 0); + mKeyTextStyle = Typeface.defaultFromStyle( + a.getInt(R.styleable.KeyboardView_keyTextStyle, Typeface.NORMAL)); mPopupLayout = a.getResourceId(R.styleable.KeyboardView_popupLayout, 0); mShadowColor = a.getColor(R.styleable.KeyboardView_shadowColor, 0); mShadowRadius = a.getFloat(R.styleable.KeyboardView_shadowRadius, 0f); // TODO: Use Theme (android.R.styleable.Theme_backgroundDimAmount) mBackgroundDimAmount = a.getFloat(R.styleable.KeyboardView_backgroundDimAmount, 0.5f); - mKeyLetterStyle = Typeface.defaultFromStyle( - a.getInt(R.styleable.KeyboardView_keyLetterStyle, Typeface.NORMAL)); mColorScheme = a.getInt(R.styleable.KeyboardView_colorScheme, COLOR_SCHEME_WHITE); + a.recycle(); final Resources res = getResources(); @@ -347,12 +369,10 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { mKeyLabelHorizontalPadding = (int)res.getDimension( R.dimen.key_label_horizontal_alignment_padding); - mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setTextAlign(Align.CENTER); mPaint.setAlpha(255); - mPadding = new Rect(0, 0, 0, 0); mKeyBackground.getPadding(mPadding); mSwipeThreshold = (int) (500 * res.getDisplayMetrics().density); @@ -496,7 +516,10 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { mPopupPanelCache.clear(); final int keyHeight = keyboard.getRowHeight() - keyboard.getVerticalGap(); mKeyLetterSize = (int)(keyHeight * mKeyLetterRatio); - mLabelTextSize = (int)(keyHeight * mLabelTextRatio); + mKeyLabelSize = (int)(keyHeight * mKeyLabelRatio); + mKeyHintLetterSize = (int)(keyHeight * mKeyHintLetterRatio); + mKeyUppercaseLetterSize = (int)( + keyHeight * mKeyUppercaseLetterRatio); mPreviewTextSize = (int)(keyHeight * mPreviewTextRatio); } @@ -683,7 +706,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { // Vertical label text alignment. final float baseline; - if ((key.mLabelOption & KEY_LABEL_OPTION_ALIGN_BOTTOM) != 0) { + if ((key.mLabelOption & Key.LABEL_OPTION_ALIGN_BOTTOM) != 0) { baseline = key.mHeight - labelCharHeight * KEY_LABEL_VERTICAL_PADDING_FACTOR; if (DEBUG_SHOW_ALIGN) drawHorizontalLine(canvas, (int)baseline, keyDrawWidth, 0xc0008000, @@ -697,12 +720,12 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { } // Horizontal label text alignment final int positionX; - if ((key.mLabelOption & KEY_LABEL_OPTION_ALIGN_LEFT) != 0) { + if ((key.mLabelOption & Key.LABEL_OPTION_ALIGN_LEFT) != 0) { positionX = mKeyLabelHorizontalPadding + padding.left; paint.setTextAlign(Align.LEFT); if (DEBUG_SHOW_ALIGN) drawVerticalLine(canvas, positionX, rowHeight, 0xc0800080, new Paint()); - } else if ((key.mLabelOption & KEY_LABEL_OPTION_ALIGN_RIGHT) != 0) { + } else if ((key.mLabelOption & Key.LABEL_OPTION_ALIGN_RIGHT) != 0) { positionX = keyDrawWidth - mKeyLabelHorizontalPadding - padding.right; paint.setTextAlign(Align.RIGHT); if (DEBUG_SHOW_ALIGN) @@ -715,8 +738,8 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { drawVerticalLine(canvas, positionX, rowHeight, 0xc0008080, new Paint()); } } - if (key.mManualTemporaryUpperCaseHintIcon != null && isManualTemporaryUpperCase) { - paint.setColor(mKeyTextColorDisabled); + if (key.hasUppercaseLetter() && isManualTemporaryUpperCase) { + paint.setColor(mKeyTextInactivatedColor); } else { paint.setColor(mKeyTextColor); } @@ -732,6 +755,27 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { paint.setShadowLayer(0, 0, 0, 0); } + // Draw hint letter. + if (key.mHintLetter != null) { + final String label = key.mHintLetter.toString(); + final int textColor; + final int textSize; + if (key.hasUppercaseLetter()) { + textColor = isManualTemporaryUpperCase ? mKeyUppercaseLetterActivatedColor + : mKeyUppercaseLetterInactivatedColor; + textSize = mKeyUppercaseLetterSize; + } else { + textColor = mKeyHintLetterColor; + textSize = mKeyHintLetterSize; + } + paint.setColor(textColor); + paint.setTextSize(textSize); + // Note: padding.right for drawX? + final float drawX = keyDrawWidth - getLabelCharWidth(textSize, paint); + final float drawY = -paint.ascent() + padding.top; + canvas.drawText(label, drawX, drawY, paint); + } + // Draw key icon. final Drawable icon = key.getIcon(); if (key.mLabel == null && icon != null) { @@ -739,11 +783,11 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { final int drawableHeight = icon.getIntrinsicHeight(); final int drawableX; final int drawableY = (key.mHeight + padding.top - padding.bottom - drawableHeight) / 2; - if ((key.mLabelOption & KEY_LABEL_OPTION_ALIGN_LEFT) != 0) { + if ((key.mLabelOption & Key.LABEL_OPTION_ALIGN_LEFT) != 0) { drawableX = padding.left + mKeyLabelHorizontalPadding; if (DEBUG_SHOW_ALIGN) drawVerticalLine(canvas, drawableX, rowHeight, 0xc0800080, new Paint()); - } else if ((key.mLabelOption & KEY_LABEL_OPTION_ALIGN_RIGHT) != 0) { + } else if ((key.mLabelOption & Key.LABEL_OPTION_ALIGN_RIGHT) != 0) { drawableX = keyDrawWidth - padding.right - mKeyLabelHorizontalPadding - drawableWidth; if (DEBUG_SHOW_ALIGN) @@ -761,15 +805,14 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { 0x80c00000, new Paint()); } - // Draw hint icon. - if (key.mHintIcon != null) { + // Draw popup hint icon "...". + // TODO: Draw "..." by text. + if (key.hasPopupHint()) { final int drawableWidth = keyDrawWidth; final int drawableHeight = key.mHeight; final int drawableX = 0; final int drawableY = HINT_ICON_VERTICAL_ADJUSTMENT_PIXEL; - Drawable hintIcon = (isManualTemporaryUpperCase - && key.mManualTemporaryUpperCaseHintIcon != null) - ? key.mManualTemporaryUpperCaseHintIcon : key.mHintIcon; + final Drawable hintIcon = mKeyPopupHintIcon; drawIcon(canvas, hintIcon, drawableX, drawableY, drawableWidth, drawableHeight); if (DEBUG_SHOW_ALIGN) drawRectangle(canvas, drawableX, drawableY, drawableWidth, drawableHeight, @@ -784,15 +827,15 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { final int labelSize; final Typeface labelStyle; if (label.length() > 1) { - labelSize = mLabelTextSize; - if ((keyLabelOption & KEY_LABEL_OPTION_FONT_NORMAL) != 0) { + labelSize = mKeyLabelSize; + if ((keyLabelOption & Key.LABEL_OPTION_FONT_NORMAL) != 0) { labelStyle = Typeface.DEFAULT; } else { labelStyle = Typeface.DEFAULT_BOLD; } } else { labelSize = mKeyLetterSize; - labelStyle = mKeyLetterStyle; + labelStyle = mKeyTextStyle; } paint.setTextSize(labelSize); paint.setTypeface(labelStyle); @@ -805,14 +848,26 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { if (labelHeightValue != null) { labelCharHeight = labelHeightValue; } else { - Rect textBounds = new Rect(); - paint.getTextBounds(KEY_LABEL_REFERENCE_CHAR, 0, 1, textBounds); - labelCharHeight = textBounds.height(); + paint.getTextBounds(KEY_LABEL_REFERENCE_CHAR, 0, 1, mTextBounds); + labelCharHeight = mTextBounds.height(); mTextHeightCache.put(labelSize, labelCharHeight); } return labelCharHeight; } + private int getLabelCharWidth(int labelSize, Paint paint) { + Integer labelWidthValue = mTextWidthCache.get(labelSize); + final int labelCharWidth; + if (labelWidthValue != null) { + labelCharWidth = labelWidthValue; + } else { + paint.getTextBounds(KEY_LABEL_REFERENCE_CHAR, 0, 1, mTextBounds); + labelCharWidth = mTextBounds.width(); + mTextWidthCache.put(labelSize, labelCharWidth); + } + return labelCharWidth; + } + private static void drawIcon(Canvas canvas, Drawable icon, int x, int y, int width, int height) { canvas.translate(x, y); @@ -935,7 +990,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { previewText.setTypeface(Typeface.DEFAULT_BOLD); } else { previewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mPreviewTextSize); - previewText.setTypeface(mKeyLetterStyle); + previewText.setTypeface(mKeyTextStyle); } } else { final Drawable previewIcon = key.getPreviewIcon(); diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java index fe27ab412..a6ac76751 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java @@ -57,9 +57,9 @@ public class LatinKeyboard extends Keyboard { private final Drawable mSpaceIcon; private final Drawable mSpacePreviewIcon; private final int mSpaceKeyIndex; - private final Drawable mSpaceAutoCorrectionIndicator; - private final Drawable mButtonArrowLeftIcon; - private final Drawable mButtonArrowRightIcon; + 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; @@ -90,7 +90,6 @@ public class LatinKeyboard extends Keyboard { public LatinKeyboard(Context context, KeyboardId id, int width) { super(context, id.getXmlId(), id, width); - final Resources res = context.getResources(); mContext = context; final List<Key> keys = getKeys(); @@ -118,19 +117,20 @@ public class LatinKeyboard extends Keyboard { mShortcutKey = (shortcutKeyIndex >= 0) ? keys.get(shortcutKeyIndex) : null; mEnabledShortcutIcon = (mShortcutKey != null) ? mShortcutKey.getIcon() : null; - mSpacebarTextColor = res.getColor(R.color.latinkeyboard_bar_language_text); - if (id.mColorScheme == KeyboardView.COLOR_SCHEME_BLACK) { - mSpacebarTextShadowColor = res.getColor( - R.color.latinkeyboard_bar_language_shadow_black); - mDisabledShortcutIcon = res.getDrawable(R.drawable.sym_bkeyboard_voice_off); - } else { // default color scheme is KeyboardView.COLOR_SCHEME_WHITE - mSpacebarTextShadowColor = res.getColor( - R.color.latinkeyboard_bar_language_shadow_white); - mDisabledShortcutIcon = res.getDrawable(R.drawable.sym_keyboard_voice_off_holo); - } - mSpaceAutoCorrectionIndicator = res.getDrawable(R.drawable.sym_keyboard_space_led); - mButtonArrowLeftIcon = res.getDrawable(R.drawable.sym_keyboard_language_arrows_left); - mButtonArrowRightIcon = res.getDrawable(R.drawable.sym_keyboard_language_arrows_right); + final TypedArray a = context.obtainStyledAttributes( + null, R.styleable.LatinKeyboard, R.attr.latinKeyboardStyle, R.style.LatinKeyboard); + mAutoCorrectionSpacebarLedIcon = a.getDrawable( + R.styleable.LatinKeyboard_autoCorrectionSpacebarLedIcon); + mDisabledShortcutIcon = a.getDrawable(R.styleable.LatinKeyboard_disabledShortcutIcon); + 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 mSpacebarLanguageSwitchThreshold = (getMostCommonKeyWidth() * 5) / 4; } @@ -163,6 +163,10 @@ public class LatinKeyboard extends Keyboard { view.invalidateKey(mShortcutKey); } + public boolean needsAutoCorrectionSpacebarLed() { + return mAutoCorrectionSpacebarLedIcon != null; + } + /** * @return a key which should be invalidated. */ @@ -282,7 +286,7 @@ public class LatinKeyboard extends Keyboard { } final String language = layoutSpacebar(paint, inputLocale, - mButtonArrowLeftIcon, mButtonArrowRightIcon, width, height, + mSpacebarArrowLeftIcon, mSpacebarArrowRightIcon, width, height, getTextSizeFromTheme(mContext.getTheme(), textStyle, defaultTextSize)); // Draw language text with shadow @@ -303,21 +307,21 @@ public class LatinKeyboard extends Keyboard { if (mSubtypeSwitcher.useSpacebarLanguageSwitcher() && mSubtypeSwitcher.getEnabledKeyboardLocaleCount() > 1 && !(isPhoneKeyboard() || isNumberKeyboard())) { - mButtonArrowLeftIcon.setColorFilter(getSpacebarDrawableFilter(textFadeFactor)); - mButtonArrowRightIcon.setColorFilter(getSpacebarDrawableFilter(textFadeFactor)); - mButtonArrowLeftIcon.draw(canvas); - mButtonArrowRightIcon.draw(canvas); + mSpacebarArrowLeftIcon.setColorFilter(getSpacebarDrawableFilter(textFadeFactor)); + mSpacebarArrowRightIcon.setColorFilter(getSpacebarDrawableFilter(textFadeFactor)); + mSpacebarArrowLeftIcon.draw(canvas); + mSpacebarArrowRightIcon.draw(canvas); } } // Draw the spacebar icon at the bottom if (isAutoCorrection) { final int iconWidth = width * SPACE_LED_LENGTH_PERCENT / 100; - final int iconHeight = mSpaceAutoCorrectionIndicator.getIntrinsicHeight(); + final int iconHeight = mAutoCorrectionSpacebarLedIcon.getIntrinsicHeight(); int x = (width - iconWidth) / 2; int y = height - iconHeight; - mSpaceAutoCorrectionIndicator.setBounds(x, y, x + iconWidth, y + iconHeight); - mSpaceAutoCorrectionIndicator.draw(canvas); + mAutoCorrectionSpacebarLedIcon.setBounds(x, y, x + iconWidth, y + iconHeight); + mAutoCorrectionSpacebarLedIcon.draw(canvas); } else if (mSpaceIcon != null) { final int iconWidth = mSpaceIcon.getIntrinsicWidth(); final int iconHeight = mSpaceIcon.getIntrinsicHeight(); diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index cf8458978..397ac7eec 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -639,8 +639,7 @@ public class PointerTracker { Key key = getKey(keyIndex); if (key.mCode == Keyboard.CODE_SHIFT) { mHandler.startLongPressShiftTimer(mLongPressShiftKeyTimeout, keyIndex, this); - } else if (key.mManualTemporaryUpperCaseCode != Keyboard.CODE_DUMMY - && mKeyboard.isManualTemporaryUpperCase()) { + } else if (key.hasUppercaseLetter() && mKeyboard.isManualTemporaryUpperCase()) { // We need not start long press timer on the key which has manual temporary upper case // code defined and the keyboard is in manual temporary upper case mode. return; @@ -667,10 +666,9 @@ public class PointerTracker { mKeyDetector.getKeyIndexAndNearbyCodes(x, y, codes); // If keyboard is in manual temporary upper case state and key has manual temporary - // shift code, alternate character code should be sent. - if (mKeyboard.isManualTemporaryUpperCase() - && key.mManualTemporaryUpperCaseCode != Keyboard.CODE_DUMMY) { - code = key.mManualTemporaryUpperCaseCode; + // uppercase letter as key hint letter, alternate character code should be sent. + if (mKeyboard.isManualTemporaryUpperCase() && key.hasUppercaseLetter()) { + code = key.mHintLetter.charAt(0); codes[0] = code; } diff --git a/java/src/com/android/inputmethod/keyboard/SlidingLocaleDrawable.java b/java/src/com/android/inputmethod/keyboard/SlidingLocaleDrawable.java index 5cf31cb14..a20bf1cd3 100644 --- a/java/src/com/android/inputmethod/keyboard/SlidingLocaleDrawable.java +++ b/java/src/com/android/inputmethod/keyboard/SlidingLocaleDrawable.java @@ -16,22 +16,21 @@ package com.android.inputmethod.keyboard; -import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.SubtypeSwitcher; - import android.content.Context; -import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.ColorFilter; import android.graphics.Paint; -import android.graphics.PixelFormat; import android.graphics.Paint.Align; +import android.graphics.PixelFormat; import android.graphics.drawable.Drawable; import android.text.TextPaint; import android.view.ViewConfiguration; +import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.SubtypeSwitcher; + /** * Animation to be displayed on the spacebar preview popup when switching languages by swiping the * spacebar. It draws the current, previous and next languages and moves them by the delta of touch @@ -39,16 +38,16 @@ import android.view.ViewConfiguration; */ public class SlidingLocaleDrawable extends Drawable { private static final int SLIDE_SPEED_MULTIPLIER_RATIO = 150; - private final Context mContext; - private final Resources mRes; private final int mWidth; private final int mHeight; private final Drawable mBackground; + private final int mSpacebarTextColor; private final TextPaint mTextPaint; private final int mMiddleX; private final Drawable mLeftDrawable; private final Drawable mRightDrawable; private final int mThreshold; + private int mDiff; private boolean mHitThreshold; private String mCurrentLanguage; @@ -56,29 +55,31 @@ public class SlidingLocaleDrawable extends Drawable { private String mPrevLanguage; public SlidingLocaleDrawable(Context context, Drawable background, int width, int height) { - mContext = context; - mRes = context.getResources(); mBackground = background; Keyboard.setDefaultBounds(mBackground); mWidth = width; mHeight = height; final TextPaint textPaint = new TextPaint(); - textPaint.setTextSize(getTextSizeFromTheme(android.R.style.TextAppearance_Medium, 18)); + textPaint.setTextSize(getTextSizeFromTheme( + context, android.R.style.TextAppearance_Medium, 18)); textPaint.setColor(Color.TRANSPARENT); textPaint.setTextAlign(Align.CENTER); textPaint.setAntiAlias(true); mTextPaint = textPaint; mMiddleX = (mWidth - mBackground.getIntrinsicWidth()) / 2; - final Resources res = mRes; - mLeftDrawable = res.getDrawable( - R.drawable.sym_keyboard_feedback_language_arrows_left); - mRightDrawable = res.getDrawable( - R.drawable.sym_keyboard_feedback_language_arrows_right); - mThreshold = ViewConfiguration.get(mContext).getScaledTouchSlop(); + + final TypedArray a = 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(); + + mThreshold = ViewConfiguration.get(context).getScaledTouchSlop(); } - private int getTextSizeFromTheme(int style, int defValue) { - TypedArray array = mContext.getTheme().obtainStyledAttributes( + private static int getTextSizeFromTheme(Context context, int style, int defValue) { + TypedArray array = context.getTheme().obtainStyledAttributes( style, new int[] { android.R.attr.textSize }); int textSize = array.getDimensionPixelSize(array.getResourceId(0, 0), defValue); return textSize; @@ -118,7 +119,7 @@ public class SlidingLocaleDrawable extends Drawable { // Draw language text with shadow final float baseline = mHeight * LatinKeyboard.SPACEBAR_LANGUAGE_BASELINE - paint.descent(); - paint.setColor(mRes.getColor(R.color.latinkeyboard_feedback_language_text)); + paint.setColor(mSpacebarTextColor); 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); diff --git a/java/src/com/android/inputmethod/latin/CandidateView.java b/java/src/com/android/inputmethod/latin/CandidateView.java index 481092c92..2a29e1f8f 100644 --- a/java/src/com/android/inputmethod/latin/CandidateView.java +++ b/java/src/com/android/inputmethod/latin/CandidateView.java @@ -18,6 +18,7 @@ package com.android.inputmethod.latin; import android.content.Context; import android.content.res.Resources; +import android.content.res.TypedArray; import android.graphics.Color; import android.graphics.Typeface; import android.os.Handler; @@ -38,6 +39,7 @@ import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnLongClickListener; import android.view.ViewGroup; +import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.PopupWindow; import android.widget.TextView; @@ -64,8 +66,8 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo private static final boolean DBG = LatinImeLogger.sDBG; private static final int NUM_CANDIDATES_IN_STRIP = 3; - private final View mExpandCandidatesPane; - private final View mCloseCandidatesPane; + private final ImageView mExpandCandidatesPane; + private final ImageView mCloseCandidatesPane; private ViewGroup mCandidatesPane; private ViewGroup mCandidatesPaneContainer; private View mKeyboardView; @@ -73,9 +75,12 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo private final ArrayList<View> mDividers = new ArrayList<View>(); private final int mCandidatePadding; private final int mCandidateStripHeight; - private final boolean mConfigCandidateHighlightFontColorEnabled; private final CharacterStyle mInvertedForegroundColorSpan; private final CharacterStyle mInvertedBackgroundColorSpan; + private final int mAutoCorrectHighlight; + private static final int AUTO_CORRECT_BOLD = 0x01; + private static final int AUTO_CORRECT_UNDERLINE = 0x02; + private static final int AUTO_CORRECT_INVERT = 0x04; private final int mColorTypedWord; private final int mColorAutoCorrect; private final int mColorSuggestedCandidate; @@ -139,7 +144,11 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo * @param attrs */ public CandidateView(Context context, AttributeSet attrs) { - super(context, attrs); + this(context, attrs, R.attr.candidateViewStyle); + } + + public CandidateView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); Resources res = context.getResources(); LayoutInflater inflater = LayoutInflater.from(context); @@ -151,13 +160,6 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo ViewGroup.LayoutParams.WRAP_CONTENT); mPreviewPopup.setContentView(mPreviewText); mPreviewPopup.setBackgroundDrawable(null); - mConfigCandidateHighlightFontColorEnabled = - res.getBoolean(R.bool.config_candidate_highlight_font_color_enabled); - mColorTypedWord = res.getColor(R.color.candidate_typed_word); - mColorAutoCorrect = res.getColor(R.color.candidate_auto_correct); - mColorSuggestedCandidate = res.getColor(R.color.candidate_suggested); - mInvertedForegroundColorSpan = new ForegroundColorSpan(mColorTypedWord ^ 0x00ffffff); - mInvertedBackgroundColorSpan = new BackgroundColorSpan(mColorTypedWord); mCandidatePadding = res.getDimensionPixelOffset(R.dimen.candidate_padding); mCandidateStripHeight = res.getDimensionPixelOffset(R.dimen.candidate_strip_height); @@ -192,20 +194,35 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo } } - mExpandCandidatesPane = findViewById(R.id.expand_candidates_pane); + final TypedArray a = context.obtainStyledAttributes( + attrs, R.styleable.CandidateView, defStyle, R.style.CandidateViewStyle); + mAutoCorrectHighlight = a.getInt(R.styleable.CandidateView_autoCorrectHighlight, 0); + mColorTypedWord = a.getColor(R.styleable.CandidateView_colorTypedWord, 0); + mColorAutoCorrect = a.getColor(R.styleable.CandidateView_colorAutoCorrect, 0); + mColorSuggestedCandidate = a.getColor(R.styleable.CandidateView_colorSuggested, 0); + mInvertedForegroundColorSpan = new ForegroundColorSpan(mColorTypedWord ^ 0x00ffffff); + mInvertedBackgroundColorSpan = new BackgroundColorSpan(mColorTypedWord); + + mExpandCandidatesPane = (ImageView)findViewById(R.id.expand_candidates_pane); + mExpandCandidatesPane.setImageDrawable( + a.getDrawable(R.styleable.CandidateView_iconExpandPane)); mExpandCandidatesPane.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { expandCandidatesPane(); } }); - mCloseCandidatesPane = findViewById(R.id.close_candidates_pane); + mCloseCandidatesPane = (ImageView)findViewById(R.id.close_candidates_pane); + mCloseCandidatesPane.setImageDrawable( + a.getDrawable(R.styleable.CandidateView_iconClosePane)); mCloseCandidatesPane.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { closeCandidatesPane(); } }); + + a.recycle(); } /** @@ -244,19 +261,20 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo private CharSequence getStyledCandidateWord(CharSequence word, boolean isAutoCorrect) { if (!isAutoCorrect) return word; - final CharacterStyle style = mConfigCandidateHighlightFontColorEnabled ? BOLD_SPAN - : UNDERLINE_SPAN; final Spannable spannedWord = new SpannableString(word); - spannedWord.setSpan(style, 0, word.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); + if ((mAutoCorrectHighlight & AUTO_CORRECT_BOLD) != 0) + spannedWord.setSpan(BOLD_SPAN, 0, word.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); + if ((mAutoCorrectHighlight & AUTO_CORRECT_UNDERLINE) != 0) + spannedWord.setSpan(UNDERLINE_SPAN, 0, word.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); return spannedWord; } private int getCandidateTextColor(boolean isAutoCorrect, boolean isSuggestedCandidate, SuggestedWordInfo info) { final int color; - if (isAutoCorrect && mConfigCandidateHighlightFontColorEnabled) { + if (isAutoCorrect) { color = mColorAutoCorrect; - } else if (isSuggestedCandidate && mConfigCandidateHighlightFontColorEnabled) { + } else if (isSuggestedCandidate) { color = mColorSuggestedCandidate; } else { color = mColorTypedWord; @@ -388,9 +406,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo } public void onAutoCorrectionInverted(CharSequence autoCorrectedWord) { - // Displaying auto corrected word as inverted is enabled only when highlighting candidate - // with color is disabled. - if (mConfigCandidateHighlightFontColorEnabled) + if ((mAutoCorrectHighlight & AUTO_CORRECT_INVERT) == 0) return; final TextView tv = mWords.get(1); final Spannable word = new SpannableString(autoCorrectedWord); @@ -403,10 +419,6 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo mShowingAutoCorrectionInverted = true; } - public boolean isConfigCandidateHighlightFontColorEnabled() { - return mConfigCandidateHighlightFontColorEnabled; - } - public boolean isShowingAddToDictionaryHint() { return mShowingAddToDictionary; } diff --git a/java/src/com/android/inputmethod/latin/DictionaryCollection.java b/java/src/com/android/inputmethod/latin/DictionaryCollection.java index 3fcb6ed55..5e7de3e6b 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryCollection.java +++ b/java/src/com/android/inputmethod/latin/DictionaryCollection.java @@ -54,8 +54,8 @@ public class DictionaryCollection extends Dictionary { @Override public boolean isValidWord(CharSequence word) { - for (final Dictionary dict : mDictionaries) - if (dict.isValidWord(word)) return true; + for (int i = mDictionaries.size() - 1; i >= 0; --i) + if (mDictionaries.get(i).isValidWord(word)) return true; return false; } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 75bca9937..87912eb00 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1464,7 +1464,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (mCandidateView != null) { mCandidateView.setSuggestions(words); - if (mCandidateView.isConfigCandidateHighlightFontColorEnabled()) { + if (mKeyboardSwitcher.getLatinKeyboard().needsAutoCorrectionSpacebarLed()) { mKeyboardSwitcher.onAutoCorrectionStateChanged( words.hasWordAboveAutoCorrectionScoreThreshold()); } |