diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinKeyboard.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinKeyboard.java | 536 |
1 files changed, 117 insertions, 419 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboard.java b/java/src/com/android/inputmethod/latin/LatinKeyboard.java index 45a4a9508..cae0b10b3 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboard.java @@ -30,57 +30,36 @@ import android.graphics.PorterDuff; import android.graphics.Rect; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; -import android.inputmethodservice.Keyboard; import android.text.TextPaint; import android.util.Log; import android.view.ViewConfiguration; -import android.view.inputmethod.EditorInfo; +import java.util.HashMap; import java.util.List; import java.util.Locale; +import java.util.Map; -public class LatinKeyboard extends Keyboard { +public class LatinKeyboard extends BaseKeyboard { private static final boolean DEBUG_PREFERRED_LETTER = false; private static final String TAG = "LatinKeyboard"; private static final int OPACITY_FULLY_OPAQUE = 255; private static final int SPACE_LED_LENGTH_PERCENT = 80; - private Drawable mShiftLockIcon; private Drawable mShiftLockPreviewIcon; - private Drawable mOldShiftIcon; + private final HashMap<Key, Drawable> mNormalShiftIcons = new HashMap<Key, Drawable>(); private Drawable mSpaceIcon; private Drawable mSpaceAutoCompletionIndicator; private Drawable mSpacePreviewIcon; - private Drawable mMicIcon; - private Drawable mMicPreviewIcon; - private Drawable m123MicIcon; - private Drawable m123MicPreviewIcon; private final Drawable mButtonArrowLeftIcon; private final Drawable mButtonArrowRightIcon; - private Key mShiftKey; - private Key mEnterKey; - private Key mF1Key; - private final Drawable mHintIcon; + private final int mSpaceBarTextShadowColor; private Key mSpaceKey; - private Key m123Key; - private final int NUMBER_HINT_COUNT = 10; - private Key[] mNumberHintKeys; - private Drawable[] mNumberHintIcons = new Drawable[NUMBER_HINT_COUNT]; private int mSpaceKeyIndex = -1; private int mSpaceDragStartX; private int mSpaceDragLastDiff; - private Locale mLocale; - private LanguageSwitcher mLanguageSwitcher; private final Resources mRes; private final Context mContext; - private int mMode; - // Whether this keyboard has voice icon on it - private boolean mHasVoiceButton; - // Whether voice icon is enabled at all - private boolean mVoiceEnabled; - private final boolean mIsAlphaKeyboard; - private CharSequence m123Label; private boolean mCurrentlyInSpace; private SlidingLocaleDrawable mSlidingLocaleIcon; private int[] mPrefLetterFrequencies; @@ -89,18 +68,7 @@ public class LatinKeyboard extends Keyboard { private int mPrefLetterY; private int mPrefDistance; - // TODO: generalize for any keyboardId - private boolean mIsBlackSym; - - // TODO: remove this attribute when either Keyboard.mDefaultVerticalGap or Key.parent becomes - // non-private. - private final int mVerticalGap; - - private static final int SHIFT_OFF = 0; - private static final int SHIFT_ON = 1; - private static final int SHIFT_LOCKED = 2; - - private int mShiftState = SHIFT_OFF; + private LatinKeyboardShiftState mShiftState = new LatinKeyboardShiftState(); private static final float SPACEBAR_DRAG_THRESHOLD = 0.8f; private static final float OVERLAP_PERCENTAGE_LOW_PROB = 0.70f; @@ -115,354 +83,141 @@ public class LatinKeyboard extends Keyboard { private static int sSpacebarVerticalCorrection; - public LatinKeyboard(Context context, int xmlLayoutResId) { - this(context, xmlLayoutResId, 0); - } - - public LatinKeyboard(Context context, int xmlLayoutResId, int mode) { - super(context, xmlLayoutResId, mode); + public LatinKeyboard(Context context, KeyboardSwitcher.KeyboardId id) { + super(context, id); final Resources res = context.getResources(); mContext = context; - mMode = mode; mRes = res; - mShiftLockIcon = res.getDrawable(R.drawable.sym_keyboard_shift_locked); + if (id.mColorScheme == BaseKeyboardView.COLOR_SCHEME_BLACK) { + mSpaceBarTextShadowColor = res.getColor( + R.color.latinkeyboard_bar_language_shadow_black); + } else { // default color scheme is BaseKeyboardView.COLOR_SCHEME_WHITE + 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); - mMicIcon = res.getDrawable(R.drawable.sym_keyboard_mic); - mMicPreviewIcon = res.getDrawable(R.drawable.sym_keyboard_feedback_mic); - setDefaultBounds(mMicPreviewIcon); mButtonArrowLeftIcon = res.getDrawable(R.drawable.sym_keyboard_language_arrows_left); mButtonArrowRightIcon = res.getDrawable(R.drawable.sym_keyboard_language_arrows_right); - m123MicIcon = res.getDrawable(R.drawable.sym_keyboard_123_mic); - m123MicPreviewIcon = res.getDrawable(R.drawable.sym_keyboard_feedback_123_mic); - mHintIcon = res.getDrawable(R.drawable.hint_popup); - setDefaultBounds(m123MicPreviewIcon); sSpacebarVerticalCorrection = res.getDimensionPixelOffset( R.dimen.spacebar_vertical_correction); - mIsAlphaKeyboard = xmlLayoutResId == R.xml.kbd_qwerty - || xmlLayoutResId == R.xml.kbd_qwerty_black; mSpaceKeyIndex = indexOf(LatinIME.KEYCODE_SPACE); - initializeNumberHintResources(context); - // TODO remove this initialization after cleanup - mVerticalGap = super.getVerticalGap(); - } - - private void initializeNumberHintResources(Context context) { - final Resources res = context.getResources(); - mNumberHintIcons[0] = res.getDrawable(R.drawable.keyboard_hint_0); - mNumberHintIcons[1] = res.getDrawable(R.drawable.keyboard_hint_1); - mNumberHintIcons[2] = res.getDrawable(R.drawable.keyboard_hint_2); - mNumberHintIcons[3] = res.getDrawable(R.drawable.keyboard_hint_3); - mNumberHintIcons[4] = res.getDrawable(R.drawable.keyboard_hint_4); - mNumberHintIcons[5] = res.getDrawable(R.drawable.keyboard_hint_5); - mNumberHintIcons[6] = res.getDrawable(R.drawable.keyboard_hint_6); - mNumberHintIcons[7] = res.getDrawable(R.drawable.keyboard_hint_7); - mNumberHintIcons[8] = res.getDrawable(R.drawable.keyboard_hint_8); - mNumberHintIcons[9] = res.getDrawable(R.drawable.keyboard_hint_9); } @Override protected Key createKeyFromXml(Resources res, Row parent, int x, int y, - XmlResourceParser parser) { - Key key = new LatinKey(res, parent, x, y, parser); + XmlResourceParser parser, KeyStyles keyStyles) { + Key key = new LatinKey(res, parent, x, y, parser, keyStyles); switch (key.codes[0]) { - case LatinIME.KEYCODE_ENTER: - mEnterKey = key; - break; - case LatinKeyboardView.KEYCODE_F1: - mF1Key = key; - break; case LatinIME.KEYCODE_SPACE: mSpaceKey = key; + mSpaceIcon = key.icon; + mSpacePreviewIcon = key.iconPreview; break; - case KEYCODE_MODE_CHANGE: - m123Key = key; - m123Label = key.label; - break; - } - - // For number hints on the upper-right corner of key - if (mNumberHintKeys == null) { - // NOTE: This protected method is being called from the base class constructor before - // mNumberHintKeys gets initialized. - mNumberHintKeys = new Key[NUMBER_HINT_COUNT]; - } - int hintNumber = -1; - if (LatinKeyboardBaseView.isNumberAtLeftmostPopupChar(key)) { - hintNumber = key.popupCharacters.charAt(0) - '0'; - } else if (LatinKeyboardBaseView.isNumberAtRightmostPopupChar(key)) { - hintNumber = key.popupCharacters.charAt(key.popupCharacters.length() - 1) - '0'; - } - if (hintNumber >= 0 && hintNumber <= 9) { - mNumberHintKeys[hintNumber] = key; } return key; } - void setImeOptions(Resources res, int mode, int options) { - mMode = mode; - // TODO should clean up this method - if (mEnterKey != null) { - // Reset some of the rarely used attributes. - mEnterKey.popupCharacters = null; - mEnterKey.popupResId = 0; - mEnterKey.text = null; - switch (options&(EditorInfo.IME_MASK_ACTION|EditorInfo.IME_FLAG_NO_ENTER_ACTION)) { - case EditorInfo.IME_ACTION_GO: - mEnterKey.iconPreview = null; - mEnterKey.icon = null; - mEnterKey.label = res.getText(R.string.label_go_key); - break; - case EditorInfo.IME_ACTION_NEXT: - mEnterKey.iconPreview = null; - mEnterKey.icon = null; - mEnterKey.label = res.getText(R.string.label_next_key); - break; - case EditorInfo.IME_ACTION_DONE: - mEnterKey.iconPreview = null; - mEnterKey.icon = null; - mEnterKey.label = res.getText(R.string.label_done_key); - break; - case EditorInfo.IME_ACTION_SEARCH: - 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.label = null; - break; - case EditorInfo.IME_ACTION_SEND: - mEnterKey.iconPreview = null; - mEnterKey.icon = null; - mEnterKey.label = res.getText(R.string.label_send_key); - break; - default: - if (mode == KeyboardSwitcher.MODE_IM) { - mEnterKey.icon = mHintIcon; - mEnterKey.iconPreview = null; - mEnterKey.label = ":-)"; - mEnterKey.text = ":-) "; - mEnterKey.popupResId = R.xml.popup_smileys; - } else { - mEnterKey.iconPreview = res.getDrawable( - R.drawable.sym_keyboard_feedback_return); - mEnterKey.icon = res.getDrawable(mIsBlackSym ? - R.drawable.sym_bkeyboard_return : R.drawable.sym_keyboard_return); - mEnterKey.label = null; - } - break; - } - // Set the initial size of the preview icon - if (mEnterKey.iconPreview != null) { - setDefaultBounds(mEnterKey.iconPreview); + public void enableShiftLock() { + for (final Key key : getShiftKeys()) { + if (key instanceof LatinKey) { + ((LatinKey)key).enableShiftLock(); } - } - } - - void enableShiftLock() { - int index = getShiftKeyIndex(); - if (index >= 0) { - mShiftKey = getKeys().get(index); - if (mShiftKey instanceof LatinKey) { - ((LatinKey)mShiftKey).enableShiftLock(); - } - mOldShiftIcon = mShiftKey.icon; + mNormalShiftIcons.put(key, key.icon); } } - void setShiftLocked(boolean shiftLocked) { - if (mShiftKey != null) { - if (shiftLocked) { - mShiftKey.on = true; - mShiftKey.icon = mShiftLockIcon; - mShiftState = SHIFT_LOCKED; - } else { - mShiftKey.on = false; - mShiftKey.icon = mShiftLockIcon; - mShiftState = SHIFT_ON; - } + public boolean setShiftLocked(boolean newShiftLockState) { + final Map<Key, Drawable> shiftedIcons = getShiftedIcons(); + for (final Key key : getShiftKeys()) { + key.on = newShiftLockState; + key.icon = newShiftLockState ? shiftedIcons.get(key) : mNormalShiftIcons.get(key); } + mShiftState.setShiftLocked(newShiftLockState); + return true; } - boolean isShiftLocked() { - return mShiftState == SHIFT_LOCKED; + public boolean isShiftLocked() { + return mShiftState.isShiftLocked(); } - + @Override - public boolean setShifted(boolean shiftState) { - boolean shiftChanged = false; - if (mShiftKey != null) { - if (shiftState == false) { - shiftChanged = mShiftState != SHIFT_OFF; - mShiftState = SHIFT_OFF; - mShiftKey.on = false; - mShiftKey.icon = mOldShiftIcon; - } else { - if (mShiftState == SHIFT_OFF) { - shiftChanged = mShiftState == SHIFT_OFF; - mShiftState = SHIFT_ON; - mShiftKey.icon = mShiftLockIcon; - } + public boolean setShifted(boolean newShiftState) { + if (getShiftKeys().size() == 0) + return super.setShifted(newShiftState); + + final Map<Key, Drawable> shiftedIcons = getShiftedIcons(); + for (final Key key : getShiftKeys()) { + if (!newShiftState && !mShiftState.isShiftLocked()) { + key.icon = mNormalShiftIcons.get(key); + } else if (newShiftState && !mShiftState.isShiftedOrShiftLocked()) { + key.icon = shiftedIcons.get(key); } - } else { - return super.setShifted(shiftState); } - return shiftChanged; + return mShiftState.setShifted(newShiftState); } @Override - public boolean isShifted() { - if (mShiftKey != null) { - return mShiftState != SHIFT_OFF; + public boolean isShiftedOrShiftLocked() { + if (getShiftKeys().size() > 0) { + return mShiftState.isShiftedOrShiftLocked(); } else { - return super.isShifted(); - } - } - - /* package */ boolean isAlphaKeyboard() { - return mIsAlphaKeyboard; - } - - public void setColorOfSymbolIcons(boolean isAutoCompletion, boolean isBlack) { - mIsBlackSym = isBlack; - if (isBlack) { - mShiftLockIcon = mRes.getDrawable(R.drawable.sym_bkeyboard_shift_locked); - mSpaceIcon = mRes.getDrawable(R.drawable.sym_bkeyboard_space); - mMicIcon = mRes.getDrawable(R.drawable.sym_bkeyboard_mic); - m123MicIcon = mRes.getDrawable(R.drawable.sym_bkeyboard_123_mic); - } else { - mShiftLockIcon = mRes.getDrawable(R.drawable.sym_keyboard_shift_locked); - mSpaceIcon = mRes.getDrawable(R.drawable.sym_keyboard_space); - mMicIcon = mRes.getDrawable(R.drawable.sym_keyboard_mic); - m123MicIcon = mRes.getDrawable(R.drawable.sym_keyboard_123_mic); - } - updateDynamicKeys(); - if (mSpaceKey != null) { - updateSpaceBarForLocale(isAutoCompletion, isBlack); + return super.isShiftedOrShiftLocked(); } - updateNumberHintKeys(); } - private void setDefaultBounds(Drawable drawable) { - drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); + public void setAutomaticTemporaryUpperCase() { + setShifted(true); + mShiftState.setAutomaticTemporaryUpperCase(); } - public void setVoiceMode(boolean hasVoiceButton, boolean hasVoice) { - mHasVoiceButton = hasVoiceButton; - mVoiceEnabled = hasVoice; - updateDynamicKeys(); + public boolean isAutomaticTemporaryUpperCase() { + return isAlphaKeyboard() && mShiftState.isAutomaticTemporaryUpperCase(); } - private void updateDynamicKeys() { - update123Key(); - updateF1Key(); + public boolean isManualTemporaryUpperCase() { + return isAlphaKeyboard() && mShiftState.isManualTemporaryUpperCase(); } - private void update123Key() { - // Update KEYCODE_MODE_CHANGE key only on alphabet mode, not on symbol mode. - if (m123Key != null && mIsAlphaKeyboard) { - if (mVoiceEnabled && !mHasVoiceButton) { - m123Key.icon = m123MicIcon; - m123Key.iconPreview = m123MicPreviewIcon; - m123Key.label = null; - } else { - m123Key.icon = null; - m123Key.iconPreview = null; - m123Key.label = m123Label; - } - } + /* package */ LatinKeyboardShiftState getKeyboardShiftState() { + return mShiftState; } - private void updateF1Key() { - // Update KEYCODE_F1 key. Please note that some keyboard layouts have no F1 key. - if (mF1Key == null) - return; - - if (mIsAlphaKeyboard) { - if (mMode == KeyboardSwitcher.MODE_URL) { - setNonMicF1Key(mF1Key, "/", R.xml.popup_slash); - } else if (mMode == KeyboardSwitcher.MODE_EMAIL) { - setNonMicF1Key(mF1Key, "@", R.xml.popup_at); - } else { - if (mVoiceEnabled && mHasVoiceButton) { - setMicF1Key(mF1Key); - } else { - setNonMicF1Key(mF1Key, ",", R.xml.popup_comma); - } - } - } else { // Symbols keyboard - if (mVoiceEnabled && mHasVoiceButton) { - setMicF1Key(mF1Key); - } else { - setNonMicF1Key(mF1Key, ",", R.xml.popup_comma); - } - } - } - - private void setMicF1Key(Key key) { - // HACK: draw mMicIcon and mHintIcon at the same time - final Drawable micWithSettingsHintDrawable = new BitmapDrawable(mRes, - drawSynthesizedSettingsHintImage(key.width, key.height, mMicIcon, mHintIcon)); - - key.label = null; - key.codes = new int[] { LatinKeyboardView.KEYCODE_VOICE }; - key.popupResId = R.xml.popup_mic; - key.icon = micWithSettingsHintDrawable; - key.iconPreview = mMicPreviewIcon; - } - - private void setNonMicF1Key(Key key, String label, int popupResId) { - key.label = label; - key.codes = new int[] { label.charAt(0) }; - key.popupResId = popupResId; - key.icon = mHintIcon; - key.iconPreview = null; + public boolean isAlphaKeyboard() { + return mId.getXmlId() == R.xml.kbd_qwerty; } - public boolean isF1Key(Key key) { - return key == mF1Key; + public boolean isPhoneKeyboard() { + return mId.mMode == KeyboardSwitcher.MODE_PHONE; } - public static boolean hasPuncOrSmileysPopup(Key key) { - return key.popupResId == R.xml.popup_punctuation || key.popupResId == R.xml.popup_smileys; + public boolean isNumberKeyboard() { + return mId.mMode == KeyboardSwitcher.MODE_NUMBER; } /** * @return a key which should be invalidated. */ public Key onAutoCompletionStateChanged(boolean isAutoCompletion) { - updateSpaceBarForLocale(isAutoCompletion, mIsBlackSym); + updateSpaceBarForLocale(isAutoCompletion); return mSpaceKey; } - private void updateNumberHintKeys() { - for (int i = 0; i < mNumberHintKeys.length; ++i) { - if (mNumberHintKeys[i] != null) { - mNumberHintKeys[i].icon = mNumberHintIcons[i]; - } - } - } - - public boolean isLanguageSwitchEnabled() { - return mLocale != null; - } - - private void updateSpaceBarForLocale(boolean isAutoCompletion, boolean isBlack) { + private void updateSpaceBarForLocale(boolean isAutoCompletion) { + final Resources res = mRes; // If application locales are explicitly selected. - if (mLocale != null) { - mSpaceKey.icon = new BitmapDrawable(mRes, - drawSpaceBar(OPACITY_FULLY_OPAQUE, isAutoCompletion, isBlack)); + if (SubtypeSwitcher.getInstance().needsToDisplayLanguage()) { + mSpaceKey.icon = new BitmapDrawable(res, + 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(mRes, - drawSpaceBar(OPACITY_FULLY_OPAQUE, isAutoCompletion, isBlack)); + mSpaceKey.icon = new BitmapDrawable(res, + drawSpaceBar(OPACITY_FULLY_OPAQUE, isAutoCompletion)); } else { - mSpaceKey.icon = isBlack ? mRes.getDrawable(R.drawable.sym_bkeyboard_space) - : mRes.getDrawable(R.drawable.sym_keyboard_space); + mSpaceKey.icon = mSpaceIcon; } } } @@ -474,34 +229,6 @@ public class LatinKeyboard extends Keyboard { return bounds.width(); } - // Overlay two images: mainIcon and hintIcon. - private Bitmap drawSynthesizedSettingsHintImage( - int width, int height, Drawable mainIcon, Drawable hintIcon) { - if (mainIcon == null || hintIcon == null) - return null; - Rect hintIconPadding = new Rect(0, 0, 0, 0); - hintIcon.getPadding(hintIconPadding); - final Bitmap buffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); - final Canvas canvas = new Canvas(buffer); - canvas.drawColor(mRes.getColor(R.color.latinkeyboard_transparent), PorterDuff.Mode.CLEAR); - - // Draw main icon at the center of the key visual - // Assuming the hintIcon shares the same padding with the key's background drawable - final int drawableX = (width + hintIconPadding.left - hintIconPadding.right - - mainIcon.getIntrinsicWidth()) / 2; - final int drawableY = (height + hintIconPadding.top - hintIconPadding.bottom - - mainIcon.getIntrinsicHeight()) / 2; - setDefaultBounds(mainIcon); - canvas.translate(drawableX, drawableY); - mainIcon.draw(canvas); - canvas.translate(-drawableX, -drawableY); - - // Draw hint icon fully in the key - hintIcon.setBounds(0, 0, width, height); - hintIcon.draw(canvas); - return buffer; - } - // Layout local language name and left and right arrow on space bar. private static String layoutSpaceBar(Paint paint, Locale locale, Drawable lArrow, Drawable rArrow, int width, int height, float origTextSize, @@ -512,7 +239,7 @@ public class LatinKeyboard extends Keyboard { final Rect bounds = new Rect(); // Estimate appropriate language name text size to fit in maxTextWidth. - String language = LanguageSwitcher.toTitleCase(locale.getDisplayLanguage(locale)); + String language = SubtypeSwitcher.getDisplayLanguage(locale); int textWidth = getTextWidth(paint, language, origTextSize, bounds); // Assuming text width and text size are proportional to each other. float textSize = origTextSize * Math.min(maxTextWidth / textWidth, 1.0f); @@ -528,7 +255,7 @@ public class LatinKeyboard extends Keyboard { textSize = origTextSize; } if (useShortName) { - language = LanguageSwitcher.toTitleCase(locale.getLanguage()); + language = SubtypeSwitcher.getShortDisplayLanguage(locale); textWidth = getTextWidth(paint, language, origTextSize, bounds); textSize = origTextSize * Math.min(maxTextWidth / textWidth, 1.0f); } @@ -545,39 +272,39 @@ public class LatinKeyboard extends Keyboard { 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); final Canvas canvas = new Canvas(buffer); - canvas.drawColor(mRes.getColor(R.color.latinkeyboard_transparent), PorterDuff.Mode.CLEAR); + final Resources res = mRes; + canvas.drawColor(res.getColor(R.color.latinkeyboard_transparent), PorterDuff.Mode.CLEAR); + SubtypeSwitcher subtypeSwitcher = SubtypeSwitcher.getInstance(); // If application locales are explicitly selected. - if (mLocale != null) { + if (subtypeSwitcher.needsToDisplayLanguage()) { final Paint paint = new Paint(); paint.setAlpha(opacity); paint.setAntiAlias(true); paint.setTextAlign(Align.CENTER); final boolean allowVariableTextSize = true; - final String language = layoutSpaceBar(paint, mLanguageSwitcher.getInputLocale(), + final String language = layoutSpaceBar(paint, subtypeSwitcher.getInputLocale(), mButtonArrowLeftIcon, mButtonArrowRightIcon, width, height, getTextSizeFromTheme(android.R.style.TextAppearance_Small, 14), allowVariableTextSize); // Draw language text with shadow - final int shadowColor = mRes.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(mRes.getColor(R.color.latinkeyboard_bar_language_text)); + paint.setColor(res.getColor(R.color.latinkeyboard_bar_language_text)); canvas.drawText(language, width / 2, baseline - descent, paint); // Put arrows that are already layed out on either side of the text - if (mLanguageSwitcher.getLocaleCount() > 1) { + if (SubtypeSwitcher.USE_SPACEBAR_LANGUAGE_SWITCHER + && subtypeSwitcher.getEnabledKeyboardLocaleCount() > 1) { mButtonArrowLeftIcon.draw(canvas); mButtonArrowRightIcon.draw(canvas); } @@ -621,40 +348,23 @@ public class LatinKeyboard extends Keyboard { } public int getLanguageChangeDirection() { - if (mSpaceKey == null || mLanguageSwitcher.getLocaleCount() < 2 - || Math.abs(mSpaceDragLastDiff) < mSpaceKey.width * SPACEBAR_DRAG_THRESHOLD ) { + if (mSpaceKey == null || SubtypeSwitcher.getInstance().getEnabledKeyboardLocaleCount() <= 1 + || Math.abs(mSpaceDragLastDiff) < mSpaceKey.width * SPACEBAR_DRAG_THRESHOLD) { return 0; // No change } return mSpaceDragLastDiff > 0 ? 1 : -1; } - public void setLanguageSwitcher(LanguageSwitcher switcher, boolean isAutoCompletion, - boolean isBlackSym) { - mLanguageSwitcher = switcher; - Locale locale = mLanguageSwitcher.getLocaleCount() > 0 - ? mLanguageSwitcher.getInputLocale() - : null; - // If the language count is 1 and is the same as the system language, don't show it. - if (locale != null - && mLanguageSwitcher.getLocaleCount() == 1 - && mLanguageSwitcher.getSystemLocale().getLanguage() - .equalsIgnoreCase(locale.getLanguage())) { - locale = null; - } - mLocale = locale; - setColorOfSymbolIcons(isAutoCompletion, isBlackSym); - } - boolean isCurrentlyInSpace() { return mCurrentlyInSpace; } - void setPreferredLetters(int[] frequencies) { + public void setPreferredLetters(int[] frequencies) { mPrefLetterFrequencies = frequencies; mPrefLetter = 0; } - void keyReleased() { + public void keyReleased() { mCurrentlyInSpace = false; mSpaceDragLastDiff = 0; mPrefLetter = 0; @@ -670,16 +380,16 @@ public class LatinKeyboard extends Keyboard { * Does the magic of locking the touch gesture into the spacebar when * switching input languages. */ - boolean isInside(LatinKey key, int x, int y) { + public boolean isInside(LatinKey key, int x, int y) { final int code = key.codes[0]; - if (code == KEYCODE_SHIFT || - code == KEYCODE_DELETE) { + if (code == KEYCODE_SHIFT || code == KEYCODE_DELETE) { y -= key.height / 10; if (code == KEYCODE_SHIFT) x += key.width / 6; if (code == KEYCODE_DELETE) x -= key.width / 6; } else if (code == LatinIME.KEYCODE_SPACE) { y += LatinKeyboard.sSpacebarVerticalCorrection; - if (mLanguageSwitcher.getLocaleCount() > 1) { + if (SubtypeSwitcher.USE_SPACEBAR_LANGUAGE_SWITCHER + && SubtypeSwitcher.getInstance().getEnabledKeyboardLocaleCount() > 1) { if (mCurrentlyInSpace) { int diff = x - mSpaceDragStartX; if (Math.abs(diff - mSpaceDragLastDiff) > 0) { @@ -819,8 +529,7 @@ public class LatinKeyboard extends Keyboard { return textSize; } - // TODO LatinKey could be static class - class LatinKey extends Keyboard.Key { + public static class LatinKey extends BaseKeyboard.Key { // functional normal state (with properties) private final int[] KEY_STATE_FUNCTIONAL_NORMAL = { @@ -835,9 +544,9 @@ public class LatinKeyboard extends Keyboard { private boolean mShiftLockEnabled; - public LatinKey(Resources res, Keyboard.Row parent, int x, int y, - XmlResourceParser parser) { - super(res, parent, x, y, parser); + public LatinKey(Resources res, BaseKeyboard.Row parent, int x, int y, + XmlResourceParser parser, KeyStyles keyStyles) { + super(res, parent, x, y, parser, keyStyles); if (popupCharacters != null && popupCharacters.length() == 0) { // If there is a keyboard with no keys specified in popupCharacters popupResId = 0; @@ -868,13 +577,12 @@ public class LatinKeyboard extends Keyboard { */ @Override public boolean isInside(int x, int y) { - // TODO This should be done by parent.isInside(this, x, y) - // if Key.parent were protected. - boolean result = LatinKeyboard.this.isInside(this, x, y); + boolean result = (keyboard instanceof LatinKeyboard) + && ((LatinKeyboard)keyboard).isInside(this, x, y); return result; } - boolean isInsideSuper(int x, int y) { + private boolean isInsideSuper(int x, int y) { return super.isInside(x, y); } @@ -889,15 +597,6 @@ public class LatinKeyboard extends Keyboard { } return super.getCurrentDrawableState(); } - - @Override - public int squaredDistanceFrom(int x, int y) { - // We should count vertical gap between rows to calculate the center of this Key. - final int verticalGap = LatinKeyboard.this.mVerticalGap; - final int xDist = this.x + width / 2 - x; - final int yDist = this.y + (height + verticalGap) / 2 - y; - return xDist * xDist + yDist * yDist; - } } /** @@ -905,7 +604,7 @@ public class LatinKeyboard extends Keyboard { * languages by swiping the spacebar. It draws the current, previous and * next languages and moves them by the delta of touch movement on the spacebar. */ - class SlidingLocaleDrawable extends Drawable { + private class SlidingLocaleDrawable extends Drawable { private final int mWidth; private final int mHeight; @@ -926,17 +625,19 @@ public class LatinKeyboard extends Keyboard { setDefaultBounds(mBackground); mWidth = width; mHeight = height; - mTextPaint = new TextPaint(); - mTextPaint.setTextSize(getTextSizeFromTheme(android.R.style.TextAppearance_Medium, 18)); - mTextPaint.setColor(R.color.latinkeyboard_transparent); - mTextPaint.setTextAlign(Align.CENTER); - mTextPaint.setAlpha(OPACITY_FULLY_OPAQUE); - mTextPaint.setAntiAlias(true); + final TextPaint textPaint = new TextPaint(); + textPaint.setTextSize(getTextSizeFromTheme(android.R.style.TextAppearance_Medium, 18)); + textPaint.setColor(R.color.latinkeyboard_transparent); + textPaint.setTextAlign(Align.CENTER); + textPaint.setAlpha(OPACITY_FULLY_OPAQUE); + textPaint.setAntiAlias(true); + mTextPaint = textPaint; mMiddleX = (mWidth - mBackground.getIntrinsicWidth()) / 2; - mLeftDrawable = - mRes.getDrawable(R.drawable.sym_keyboard_feedback_language_arrows_left); - mRightDrawable = - mRes.getDrawable(R.drawable.sym_keyboard_feedback_language_arrows_right); + 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(); } @@ -953,9 +654,6 @@ public class LatinKeyboard extends Keyboard { invalidateSelf(); } - private String getLanguageName(Locale locale) { - return LanguageSwitcher.toTitleCase(locale.getDisplayLanguage(locale)); - } @Override public void draw(Canvas canvas) { @@ -969,10 +667,10 @@ public class LatinKeyboard extends Keyboard { final Drawable rArrow = mRightDrawable; canvas.clipRect(0, 0, width, height); if (mCurrentLanguage == null) { - final LanguageSwitcher languageSwitcher = mLanguageSwitcher; - mCurrentLanguage = getLanguageName(languageSwitcher.getInputLocale()); - mNextLanguage = getLanguageName(languageSwitcher.getNextInputLocale()); - mPrevLanguage = getLanguageName(languageSwitcher.getPrevInputLocale()); + SubtypeSwitcher subtypeSwitcher = SubtypeSwitcher.getInstance(); + mCurrentLanguage = subtypeSwitcher.getInputLanguageName(); + mNextLanguage = subtypeSwitcher.getNextInputLanguageName(); + mPrevLanguage = subtypeSwitcher.getPreviousInputLanguageName(); } // Draw language text with shadow final float baseline = mHeight * SPACEBAR_LANGUAGE_BASELINE - paint.descent(); |