diff options
Diffstat (limited to 'java/src/com')
4 files changed, 82 insertions, 109 deletions
diff --git a/java/src/com/android/inputmethod/latin/BaseKeyboardParser.java b/java/src/com/android/inputmethod/latin/BaseKeyboardParser.java index ea209c515..3a2764968 100644 --- a/java/src/com/android/inputmethod/latin/BaseKeyboardParser.java +++ b/java/src/com/android/inputmethod/latin/BaseKeyboardParser.java @@ -394,18 +394,22 @@ public class BaseKeyboardParser { final TypedArray a = mResources.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.BaseKeyboard_Case); + final TypedArray viewAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser), + R.styleable.BaseKeyboardView); try { - final boolean modeMatched = matchInteger( - a, R.styleable.BaseKeyboard_Case_mode, id.mMode); - final boolean settingsKeyMatched = matchBoolean( - a, R.styleable.BaseKeyboard_Case_hasSettingsKey, id.mHasSettingsKey); - final boolean voiceEnabledMatched = matchBoolean( - a, R.styleable.BaseKeyboard_Case_voiceKeyEnabled, id.mVoiceKeyEnabled); - final boolean voiceKeyMatched = matchBoolean( - a, R.styleable.BaseKeyboard_Case_hasVoiceKey, id.mHasVoiceKey); + final boolean modeMatched = matchInteger(a, + R.styleable.BaseKeyboard_Case_mode, id.mMode); + final boolean settingsKeyMatched = matchBoolean(a, + R.styleable.BaseKeyboard_Case_hasSettingsKey, id.mHasSettingsKey); + final boolean voiceEnabledMatched = matchBoolean(a, + R.styleable.BaseKeyboard_Case_voiceKeyEnabled, id.mVoiceKeyEnabled); + final boolean voiceKeyMatched = matchBoolean(a, + R.styleable.BaseKeyboard_Case_hasVoiceKey, id.mHasVoiceKey); + final boolean colorSchemeMatched = matchInteger(viewAttr, + R.styleable.BaseKeyboardView_colorScheme, id.mColorScheme); final boolean selected = modeMatched && settingsKeyMatched - && voiceEnabledMatched && voiceKeyMatched; + && voiceEnabledMatched && voiceKeyMatched && colorSchemeMatched; if (DEBUG_TAG) { Log.d(TAG, "parseCaseCondition: " + Boolean.toString(selected).toUpperCase() @@ -417,12 +421,15 @@ public class BaseKeyboardParser { R.styleable.BaseKeyboard_Case_voiceKeyEnabled, "voiceKeyEnabled") + debugBoolean(a, R.styleable.BaseKeyboard_Case_hasVoiceKey, "hasVoiceKey") + + debugInteger(viewAttr, + R.styleable.BaseKeyboardView_colorScheme, "colorScheme") ); } return selected; } finally { a.recycle(); + viewAttr.recycle(); } } diff --git a/java/src/com/android/inputmethod/latin/BaseKeyboardView.java b/java/src/com/android/inputmethod/latin/BaseKeyboardView.java index d98cd04b2..129ff81a1 100644 --- a/java/src/com/android/inputmethod/latin/BaseKeyboardView.java +++ b/java/src/com/android/inputmethod/latin/BaseKeyboardView.java @@ -73,6 +73,9 @@ public class BaseKeyboardView extends View implements PointerTracker.UIProxy { private static final boolean DEBUG = false; private static final boolean DEBUG_KEYBOARD_GRID = false; + public static final int COLOR_SCHEME_WHITE = 0; + public static final int COLOR_SCHEME_BLACK = 1; + public static final int NOT_A_TOUCH_COORDINATE = -1; public interface OnKeyboardActionListener { @@ -170,7 +173,7 @@ public class BaseKeyboardView extends View implements PointerTracker.UIProxy { private int mKeyTextColor; private Typeface mKeyTextStyle = Typeface.DEFAULT; private int mLabelTextSize; - private int mSymbolColorScheme = 0; + private int mColorScheme = COLOR_SCHEME_WHITE; private int mShadowColor; private float mShadowRadius; private Drawable mKeyBackground; @@ -490,8 +493,8 @@ public class BaseKeyboardView extends View implements PointerTracker.UIProxy { break; } break; - case R.styleable.BaseKeyboardView_symbolColorScheme: - mSymbolColorScheme = a.getInt(attr, 0); + case R.styleable.BaseKeyboardView_colorScheme: + mColorScheme = a.getInt(attr, COLOR_SCHEME_WHITE); break; } } @@ -659,8 +662,8 @@ public class BaseKeyboardView extends View implements PointerTracker.UIProxy { return mShowPreview; } - public int getSymbolColorScheme() { - return mSymbolColorScheme; + public int getColorScheme() { + return mColorScheme; } public void setPopupParent(View v) { diff --git a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java index 790f86138..b90ea2471 100644 --- a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java @@ -52,27 +52,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha R.layout.input_honeycomb, // DEFAULT_LAYOUT_ID }; - // Ids for each characters' color in the keyboard - private static final int CHAR_THEME_COLOR_WHITE = 0; - private static final int CHAR_THEME_COLOR_BLACK = 1; - - // Tables which contains resource ids for each character theme color - private static final int[] KBD_PHONE = new int[] { - R.xml.kbd_phone, R.xml.kbd_phone_black - }; - private static final int[] KBD_PHONE_SYMBOLS = new int[] { - R.xml.kbd_phone_symbols, R.xml.kbd_phone_symbols_black - }; - private static final int[] KBD_SYMBOLS = new int[] { - R.xml.kbd_symbols, R.xml.kbd_symbols_black - }; - private static final int[] KBD_SYMBOLS_SHIFT = new int[] { - R.xml.kbd_symbols_shift, R.xml.kbd_symbols_shift_black - }; - private static final int[] KBD_QWERTY = new int[] { - R.xml.kbd_qwerty, R.xml.kbd_qwerty_black - }; - private static final int SYMBOLS_MODE_STATE_NONE = 0; private static final int SYMBOLS_MODE_STATE_BEGIN = 1; private static final int SYMBOLS_MODE_STATE_SYMBOL = 2; @@ -137,7 +116,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha final Locale locale = mSubtypeSwitcher.getInputLocale(); final int orientation = mInputMethodService.getResources().getConfiguration().orientation; final int mode = mMode; - final int colorScheme = getCharColorId(); + final int colorScheme = getColorScheme(); final boolean hasSettingsKey = mHasSettingsKey; final boolean voiceKeyEnabled = mVoiceKeyEnabled; final boolean hasVoiceKey = voiceKeyEnabled && !mVoiceButtonOnPrimary; @@ -150,10 +129,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha // mSymbolsId and mSymbolsShiftedId to "phone keyboard" and "phone symbols keyboard" // respectively here for xlarge device's layout switching. mSymbolsId = new KeyboardId(locale, orientation, mode, - mode == MODE_PHONE ? KBD_PHONE : KBD_SYMBOLS, + mode == MODE_PHONE ? R.xml.kbd_phone : R.xml.kbd_symbols, colorScheme, hasSettingsKey, voiceKeyEnabled, hasVoiceKey, imeOptions, true); mSymbolsShiftedId = new KeyboardId(locale, orientation, mode, - mode == MODE_PHONE ? KBD_PHONE_SYMBOLS : KBD_SYMBOLS_SHIFT, + mode == MODE_PHONE ? R.xml.kbd_phone_symbols : R.xml.kbd_symbols_shift, colorScheme, hasSettingsKey, voiceKeyEnabled, hasVoiceKey, imeOptions, true); } @@ -165,7 +144,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha public final Locale mLocale; public final int mOrientation; public final int mMode; - public final int[] mXmlArray; + public final int mXmlId; public final int mColorScheme; public final boolean mHasSettingsKey; public final boolean mVoiceKeyEnabled; @@ -176,12 +155,12 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha private final int mHashCode; public KeyboardId(Locale locale, int orientation, int mode, - int[] xmlArray, int colorScheme, boolean hasSettingsKey, boolean voiceKeyEnabled, + int xmlId, int colorScheme, boolean hasSettingsKey, boolean voiceKeyEnabled, boolean hasVoiceKey, int imeOptions, boolean enableShiftLock) { this.mLocale = locale; this.mOrientation = orientation; this.mMode = mode; - this.mXmlArray = xmlArray; + this.mXmlId = xmlId; this.mColorScheme = colorScheme; this.mHasSettingsKey = hasSettingsKey; this.mVoiceKeyEnabled = voiceKeyEnabled; @@ -193,7 +172,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha locale, orientation, mode, - xmlArray, + xmlId, colorScheme, hasSettingsKey, voiceKeyEnabled, @@ -204,11 +183,11 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } public int getXmlId() { - return mXmlArray[mColorScheme]; + return mXmlId; } public boolean isAlphabetMode() { - return mXmlArray == KBD_QWERTY; + return mXmlId == R.xml.kbd_qwerty; } @Override @@ -220,7 +199,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha return other.mLocale.equals(this.mLocale) && other.mOrientation == this.mOrientation && other.mMode == this.mMode - && other.mXmlArray == this.mXmlArray + && other.mXmlId == this.mXmlId && other.mColorScheme == this.mColorScheme && other.mHasSettingsKey == this.mHasSettingsKey && other.mVoiceKeyEnabled == this.mVoiceKeyEnabled @@ -241,8 +220,8 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha (mOrientation == 1 ? "port" : "land"), modeName(mMode), mImeOptions, - mXmlArray[0], - (mColorScheme == CHAR_THEME_COLOR_WHITE ? "white" : "black"), + mXmlId, + colorSchemeName(mColorScheme), (mHasSettingsKey ? " hasSettingsKey" : ""), (mVoiceKeyEnabled ? " voiceKeyEnabled" : ""), (mHasVoiceKey ? " hasVoiceKey" : ""), @@ -260,6 +239,14 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } return null; } + + private static String colorSchemeName(int colorScheme) { + switch (colorScheme) { + case BaseKeyboardView.COLOR_SCHEME_WHITE: return "white"; + case BaseKeyboardView.COLOR_SCHEME_BLACK: return "black"; + } + return null; + } } private boolean hasVoiceKey(boolean isSymbols) { @@ -315,7 +302,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha keyboard = new LatinKeyboard(mInputMethodService, id); keyboard.setImeOptions(res, id.mMode, id.mImeOptions); - keyboard.setColorOfSymbolIcons(isBlackSym(id.mColorScheme)); if (id.mEnableShiftLock) { keyboard.enableShiftLock(); @@ -338,20 +324,20 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha private KeyboardId getKeyboardId(int mode, int imeOptions, boolean isSymbols) { final boolean hasVoiceKey = hasVoiceKey(isSymbols); - final int charColorId = getCharColorId(); - final int[] xmlArray; + final int charColorId = getColorScheme(); + final int xmlId; final boolean enableShiftLock; if (isSymbols) { - xmlArray = mode == MODE_PHONE ? KBD_PHONE_SYMBOLS : KBD_SYMBOLS; + xmlId = mode == MODE_PHONE ? R.xml.kbd_phone_symbols : R.xml.kbd_symbols; enableShiftLock = false; } else { // QWERTY - xmlArray = mode == MODE_PHONE ? KBD_PHONE : KBD_QWERTY; + xmlId = mode == MODE_PHONE ? R.xml.kbd_phone : R.xml.kbd_qwerty; enableShiftLock = mode == MODE_PHONE ? false : true; } final int orientation = mInputMethodService.getResources().getConfiguration().orientation; final Locale locale = mSubtypeSwitcher.getInputLocale(); - return new KeyboardId(locale, orientation, mode, xmlArray, charColorId, + return new KeyboardId(locale, orientation, mode, xmlId, charColorId, mHasSettingsKey, mVoiceKeyEnabled, hasVoiceKey, imeOptions, enableShiftLock); } @@ -719,23 +705,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } } - public boolean isBlackSym() { - if (mInputView != null && mInputView.getSymbolColorScheme() == 1) { - return true; - } - return false; - } - - private boolean isBlackSym(int colorScheme) { - return colorScheme == CHAR_THEME_COLOR_BLACK; - } - - private int getCharColorId() { - if (isBlackSym()) { - return CHAR_THEME_COLOR_BLACK; - } else { - return CHAR_THEME_COLOR_WHITE; - } + private int getColorScheme() { + return (mInputView != null) + ? mInputView.getColorScheme() : BaseKeyboardView.COLOR_SCHEME_WHITE; } public void onAutoCompletionStateChanged(boolean isAutoCompletion) { diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboard.java b/java/src/com/android/inputmethod/latin/LatinKeyboard.java index fc62053fe..be00659b8 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboard.java @@ -46,7 +46,7 @@ public class LatinKeyboard extends BaseKeyboard { private static final int OPACITY_FULLY_OPAQUE = 255; private static final int SPACE_LED_LENGTH_PERCENT = 80; - private Drawable mShiftedIcon; + private final Drawable mShiftedIcon; private Drawable mShiftLockPreviewIcon; private final HashMap<Key, Drawable> mNormalShiftIcons = new HashMap<Key, Drawable>(); private Drawable mSpaceIcon; @@ -54,6 +54,8 @@ public class LatinKeyboard extends BaseKeyboard { private Drawable mSpacePreviewIcon; private final Drawable mButtonArrowLeftIcon; private final Drawable mButtonArrowRightIcon; + private final Drawable mSearchIcon; + private final int mSpaceBarTextShadowColor; private Key mEnterKey; private Key mSpaceKey; private int mSpaceKeyIndex = -1; @@ -61,7 +63,6 @@ public class LatinKeyboard extends BaseKeyboard { private int mSpaceDragLastDiff; private final Resources mRes; private final Context mContext; - private final boolean mIsAlphaKeyboard; private boolean mCurrentlyInSpace; private SlidingLocaleDrawable mSlidingLocaleIcon; private int[] mPrefLetterFrequencies; @@ -76,9 +77,6 @@ public class LatinKeyboard extends BaseKeyboard { private final CharSequence mDefaultEnterLabel; private final CharSequence mDefaultEnterText; - // TODO: generalize for any keyboardId - private boolean mIsBlackSym; - private LatinKeyboardShiftState mShiftState = new LatinKeyboardShiftState(); private static final float SPACEBAR_DRAG_THRESHOLD = 0.8f; @@ -99,19 +97,26 @@ public class LatinKeyboard extends BaseKeyboard { final Resources res = context.getResources(); mContext = context; mRes = res; - mShiftedIcon = res.getDrawable(R.drawable.sym_keyboard_shift_locked); + if (id.mColorScheme == BaseKeyboardView.COLOR_SCHEME_BLACK) { + // TODO: use <case imeOptions> and <case colorScheme> in XML to load search icon + mSearchIcon = res.getDrawable(R.drawable.sym_bkeyboard_search); + mShiftedIcon = res.getDrawable(R.drawable.sym_bkeyboard_shift_locked); + mSpaceBarTextShadowColor = res.getColor( + R.color.latinkeyboard_bar_language_shadow_black); + } else { // default color scheme is BaseKeyboardView.COLOR_SCHEME_WHITE + // TODO: use <case imeOptions> and <case colorScheme> in XML to load search icon + mSearchIcon = res.getDrawable(R.drawable.sym_keyboard_search); + mShiftedIcon = res.getDrawable(R.drawable.sym_keyboard_shift_locked); + mSpaceBarTextShadowColor = res.getColor( + R.color.latinkeyboard_bar_language_shadow_white); + } mShiftLockPreviewIcon = res.getDrawable(R.drawable.sym_keyboard_feedback_shift_locked); setDefaultBounds(mShiftLockPreviewIcon); - mSpaceIcon = res.getDrawable(R.drawable.sym_keyboard_space); mSpaceAutoCompletionIndicator = res.getDrawable(R.drawable.sym_keyboard_space_led); - mSpacePreviewIcon = res.getDrawable(R.drawable.sym_keyboard_feedback_space); mButtonArrowLeftIcon = res.getDrawable(R.drawable.sym_keyboard_language_arrows_left); mButtonArrowRightIcon = res.getDrawable(R.drawable.sym_keyboard_language_arrows_right); sSpacebarVerticalCorrection = res.getDimensionPixelOffset( R.dimen.spacebar_vertical_correction); - final int xmlLayoutResId = id.getXmlId(); - mIsAlphaKeyboard = xmlLayoutResId == R.xml.kbd_qwerty - || xmlLayoutResId == R.xml.kbd_qwerty_black; mSpaceKeyIndex = indexOf(LatinIME.KEYCODE_SPACE); if (mEnterKey != null) { @@ -135,6 +140,8 @@ public class LatinKeyboard extends BaseKeyboard { break; case LatinIME.KEYCODE_SPACE: mSpaceKey = key; + mSpaceIcon = key.icon; + mSpacePreviewIcon = key.iconPreview; break; } @@ -151,6 +158,7 @@ public class LatinKeyboard extends BaseKeyboard { key.label = label; } + // TODO: remove this method and use <case imeOptions> in XML public void setImeOptions(Resources res, int mode, int options) { if (mEnterKey == null) return; @@ -170,8 +178,7 @@ public class LatinKeyboard extends BaseKeyboard { case EditorInfo.IME_ACTION_SEARCH: resetKeyAttributes(mEnterKey, null); mEnterKey.iconPreview = res.getDrawable(R.drawable.sym_keyboard_feedback_search); - mEnterKey.icon = res.getDrawable(mIsBlackSym ? R.drawable.sym_bkeyboard_search - : R.drawable.sym_keyboard_search); + mEnterKey.icon = mSearchIcon; break; case EditorInfo.IME_ACTION_SEND: resetKeyAttributes(mEnterKey, res.getText(R.string.label_send_key)); @@ -240,11 +247,11 @@ public class LatinKeyboard extends BaseKeyboard { } public boolean isAutomaticTemporaryUpperCase() { - return mIsAlphaKeyboard && mShiftState.isAutomaticTemporaryUpperCase(); + return isAlphaKeyboard() && mShiftState.isAutomaticTemporaryUpperCase(); } public boolean isManualTemporaryUpperCase() { - return mIsAlphaKeyboard && mShiftState.isManualTemporaryUpperCase(); + return isAlphaKeyboard() && mShiftState.isManualTemporaryUpperCase(); } /* package */ LatinKeyboardShiftState getKeyboardShiftState() { @@ -252,43 +259,30 @@ public class LatinKeyboard extends BaseKeyboard { } public boolean isAlphaKeyboard() { - return mIsAlphaKeyboard; - } - - public void setColorOfSymbolIcons(boolean isBlack) { - mIsBlackSym = isBlack; - final Resources res = mRes; - if (isBlack) { - mShiftedIcon = res.getDrawable(R.drawable.sym_bkeyboard_shift_locked); - mSpaceIcon = res.getDrawable(R.drawable.sym_bkeyboard_space); - } else { - mShiftedIcon = res.getDrawable(R.drawable.sym_keyboard_shift_locked); - mSpaceIcon = res.getDrawable(R.drawable.sym_keyboard_space); - } + return mId.getXmlId() == R.xml.kbd_qwerty; } /** * @return a key which should be invalidated. */ public Key onAutoCompletionStateChanged(boolean isAutoCompletion) { - updateSpaceBarForLocale(isAutoCompletion, mIsBlackSym); + updateSpaceBarForLocale(isAutoCompletion); return mSpaceKey; } - private void updateSpaceBarForLocale(boolean isAutoCompletion, boolean isBlack) { + private void updateSpaceBarForLocale(boolean isAutoCompletion) { final Resources res = mRes; // If application locales are explicitly selected. if (SubtypeSwitcher.getInstance().needsToDisplayLanguage()) { mSpaceKey.icon = new BitmapDrawable(res, - drawSpaceBar(OPACITY_FULLY_OPAQUE, isAutoCompletion, isBlack)); + drawSpaceBar(OPACITY_FULLY_OPAQUE, isAutoCompletion)); } else { // sym_keyboard_space_led can be shared with Black and White symbol themes. if (isAutoCompletion) { mSpaceKey.icon = new BitmapDrawable(res, - drawSpaceBar(OPACITY_FULLY_OPAQUE, isAutoCompletion, isBlack)); + drawSpaceBar(OPACITY_FULLY_OPAQUE, isAutoCompletion)); } else { - mSpaceKey.icon = isBlack ? res.getDrawable(R.drawable.sym_bkeyboard_space) - : res.getDrawable(R.drawable.sym_keyboard_space); + mSpaceKey.icon = mSpaceIcon; } } } @@ -343,7 +337,7 @@ public class LatinKeyboard extends BaseKeyboard { return language; } - private Bitmap drawSpaceBar(int opacity, boolean isAutoCompletion, boolean isBlack) { + private Bitmap drawSpaceBar(int opacity, boolean isAutoCompletion) { final int width = mSpaceKey.width; final int height = mSpaceIcon.getIntrinsicHeight(); final Bitmap buffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); @@ -366,12 +360,9 @@ public class LatinKeyboard extends BaseKeyboard { allowVariableTextSize); // Draw language text with shadow - final int shadowColor = res.getColor(isBlack - ? R.color.latinkeyboard_bar_language_shadow_black - : R.color.latinkeyboard_bar_language_shadow_white); final float baseline = height * SPACEBAR_LANGUAGE_BASELINE; final float descent = paint.descent(); - paint.setColor(shadowColor); + paint.setColor(mSpaceBarTextShadowColor); canvas.drawText(language, width / 2, baseline - descent - 1, paint); paint.setColor(res.getColor(R.color.latinkeyboard_bar_language_text)); canvas.drawText(language, width / 2, baseline - descent, paint); |