diff options
Diffstat (limited to 'java')
-rw-r--r-- | java/res/values/attrs.xml | 14 | ||||
-rw-r--r-- | java/res/values/styles.xml | 23 | ||||
-rw-r--r-- | java/res/values/themes.xml | 6 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/LatinKeyboard.java | 54 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/SlidingLocaleDrawable.java | 39 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/latin/CandidateView.java | 5 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinIME.java | 2 |
7 files changed, 89 insertions, 54 deletions
diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index 2aff88983..3bed8806a 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -18,6 +18,8 @@ <declare-styleable name="KeyboardTheme"> <!-- Keyboard style --> <attr name="keyboardStyle" format="reference" /> + <!-- LatinKeyboard style --> + <attr name="latinKeyboardStyle" format="reference" /> <!-- KeyboardView style --> <attr name="keyboardViewStyle" format="reference" /> <attr name="keyPreviewStyle" format="reference" /> @@ -94,7 +96,6 @@ <flag name="autoCorrectBold" value="0x01" /> <flag name="autoCorrectUnderline" value="0x02" /> <flag name="autoCorrectInvert" value="0x04" /> - <flag name="autoCorrectSpacebarLed" value="0x08" /> </attr> <attr name="colorTypedWord" format="color" /> <attr name="colorAutoCorrect" format="color" /> @@ -243,4 +244,15 @@ <attr name="styleName" format="string" /> <attr name="parentStyle" format="string" /> </declare-styleable> + + <declare-styleable name="LatinKeyboard"> + <attr name="autoCorrectionSpacebarLedIcon" format="reference" /> + <attr name="disabledShortcutIcon" format="reference" /> + <attr name="spacebarTextColor" 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> </resources> diff --git a/java/res/values/styles.xml b/java/res/values/styles.xml index 06e02c7f4..37f1fe3c6 100644 --- a/java/res/values/styles.xml +++ b/java/res/values/styles.xml @@ -16,9 +16,19 @@ <resources> <!-- Theme "Basic" --> - <style name="Keyboard" > + <style name="Keyboard"> <item name="popupHintIcon">@drawable/hint_popup</item> </style> + <style name="LatinKeyboard"> + <item name="autoCorrectionSpacebarLedIcon">@drawable/sym_keyboard_space_led</item> + <item name="disabledShortcutIcon">@drawable/sym_keyboard_voice_off_holo</item> + <item name="spacebarTextColor">@color/latinkeyboard_bar_language_text</item> + <item name="spacebarTextShadowColor">@color/latinkeyboard_bar_language_shadow_white</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 name="KeyboardView"> <item name="android:background">@drawable/keyboard_background</item> <item name="keyBackground">@drawable/btn_keyboard_key</item> @@ -61,8 +71,6 @@ <item name="android:background">@drawable/candidate_feedback_background</item> </style> <style name="CandidateViewStyle" parent="SuggestionsStripBackgroundStyle"> - <!-- TODO: autoCorrectSpacebarLed should be in style for LatinKeyboard. --> - <item name="autoCorrectHighlight">autoCorrectBold|autoCorrectSpacebarLed</item> <item name="colorTypedWord">#FFFFFFFF</item> <item name="colorAutoCorrect">#FFFCAE00</item> <item name="colorSuggested">#FFFCAE00</item> @@ -75,6 +83,11 @@ <item name="keyBackground">@drawable/btn_keyboard_key3</item> </style> <!-- Theme "Stone" --> + <style name="LatinKeyboard.Stone" patent="LatinKeyboard"> + <item name="spacebarTextColor">#FF444444</item> + <item name="spacebarTextShadowColor">@color/latinkeyboard_bar_language_shadow_black</item> + <item name="disabledShortcutIcon">@drawable/sym_bkeyboard_voice_off</item> + </style> <style name="KeyboardView.Stone" parent="KeyboardView"> <item name="keyBackground">@drawable/btn_keyboard_key_stone</item> <item name="keyTextColor">@color/latinkeyboard_key_color_black</item> @@ -104,6 +117,10 @@ <style name="Keyboard.Honeycomb" parent="Keyboard" > <item name="popupHintIcon">@drawable/hint_popup_holo</item> </style> + <style name="LatinKeyboard.Honeycomb" parent="LatinKeyboard"> + <item name="autoCorrectionSpacebarLedIcon">@null</item> + <item name="disabledShortcutIcon">@drawable/sym_keyboard_voice_off_holo</item> + </style> <style name="KeyboardView.Honeycomb" parent="KeyboardView"> <item name="android:background">@drawable/keyboard_background_holo</item> <item name="keyBackground">@drawable/btn_keyboard_key_honeycomb</item> diff --git a/java/res/values/themes.xml b/java/res/values/themes.xml index dbea58036..728ce5a02 100644 --- a/java/res/values/themes.xml +++ b/java/res/values/themes.xml @@ -17,6 +17,7 @@ <resources> <style name="KeyboardTheme" parent="android:Theme"> <item name="keyboardStyle">@style/Keyboard</item> + <item name="latinKeyboardStyle">@style/LatinKeyboard</item> <item name="keyboardViewStyle">@style/KeyboardView</item> <item name="keyPreviewStyle">@style/KeyPreviewStyle</item> <item name="popupMiniKeyboardViewStyle">@style/PopupMiniKeyboardView</item> @@ -28,6 +29,7 @@ </style> <style name="KeyboardTheme.HighContrast" parent="android:Theme"> <item name="keyboardStyle">@style/Keyboard</item> + <item name="latinKeyboardStyle">@style/LatinKeyboard</item> <item name="keyboardViewStyle">@style/KeyboardView.HighContrast</item> <item name="keyPreviewStyle">@style/KeyPreviewStyle</item> <item name="popupMiniKeyboardViewStyle">@style/PopupMiniKeyboardView</item> @@ -38,6 +40,7 @@ </style> <style name="KeyboardTheme.Stone" parent="android:Theme.Light"> <item name="keyboardStyle">@style/Keyboard</item> + <item name="latinKeyboardStyle">@style/LatinKeyboard.Stone</item> <item name="keyboardViewStyle">@style/KeyboardView.Stone</item> <item name="keyPreviewStyle">@style/KeyPreviewStyle</item> <item name="popupMiniKeyboardViewStyle">@style/PopupMiniKeyboardView.Stone</item> @@ -48,6 +51,7 @@ </style> <style name="KeyboardTheme.Stone.Bold" parent="android:Theme.Light"> <item name="keyboardStyle">@style/Keyboard</item> + <item name="latinKeyboardStyle">@style/LatinKeyboard.Stone</item> <item name="keyboardViewStyle">@style/KeyboardView.Stone.Bold</item> <item name="keyPreviewStyle">@style/KeyPreviewStyle</item> <item name="popupMiniKeyboardViewStyle">@style/PopupMiniKeyboardView.Stone</item> @@ -58,6 +62,7 @@ </style> <style name="KeyboardTheme.Gingerbread" parent="android:Theme.Black"> <item name="keyboardStyle">@style/Keyboard</item> + <item name="latinKeyboardStyle">@style/LatinKeyboard</item> <item name="keyboardViewStyle">@style/KeyboardView.Gingerbread</item> <item name="keyPreviewStyle">@style/KeyPreviewStyle</item> <item name="popupMiniKeyboardViewStyle">@style/PopupMiniKeyboardView.Gingerbread</item> @@ -68,6 +73,7 @@ </style> <style name="KeyboardTheme.Honeycomb" parent="android:Theme.Holo"> <item name="keyboardStyle">@style/Keyboard.Honeycomb</item> + <item name="latinKeyboardStyle">@style/LatinKeyboard.Honeycomb</item> <item name="keyboardViewStyle">@style/KeyboardView.Honeycomb</item> <item name="keyPreviewStyle">@style/KeyPreviewStyle.Honeycomb</item> <item name="popupMiniKeyboardViewStyle">@style/PopupMiniKeyboardView.Honeycomb</item> 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/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 e5ac22554..2a29e1f8f 100644 --- a/java/src/com/android/inputmethod/latin/CandidateView.java +++ b/java/src/com/android/inputmethod/latin/CandidateView.java @@ -81,7 +81,6 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo 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 static final int AUTO_CORRECT_SPACEBAR_LED = 0x08; private final int mColorTypedWord; private final int mColorAutoCorrect; private final int mColorSuggestedCandidate; @@ -420,10 +419,6 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo mShowingAutoCorrectionInverted = true; } - public boolean needsAutoCorrectionSpacebarLed() { - return (mAutoCorrectHighlight & AUTO_CORRECT_SPACEBAR_LED) != 0; - } - public boolean isShowingAddToDictionaryHint() { return mShowingAddToDictionary; } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index db8e52aa1..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.needsAutoCorrectionSpacebarLed()) { + if (mKeyboardSwitcher.getLatinKeyboard().needsAutoCorrectionSpacebarLed()) { mKeyboardSwitcher.onAutoCorrectionStateChanged( words.hasWordAboveAutoCorrectionScoreThreshold()); } |