diff options
Diffstat (limited to 'java/src')
4 files changed, 50 insertions, 50 deletions
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()); } |