diff options
Diffstat (limited to 'java/src/com/android/inputmethod')
14 files changed, 136 insertions, 132 deletions
diff --git a/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java b/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java index 2789bcb39..bcdcef7dc 100644 --- a/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java +++ b/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java @@ -27,7 +27,7 @@ public class EditorInfoCompatUtils { private static final Field FIELD_IME_FLAG_NAVIGATE_PREVIOUS = CompatUtils.getField( EditorInfo.class, "IME_FLAG_NAVIGATE_PREVIOUS"); private static final Field FIELD_IME_ACTION_PREVIOUS = CompatUtils.getField( - EditorInfo.class, "IME_FLAG_ACTION_PREVIOUS"); + EditorInfo.class, "IME_ACTION_PREVIOUS"); private static final Integer OBJ_IME_FLAG_NAVIGATE_NEXT = (Integer) CompatUtils .getFieldValue(null, null, FIELD_IME_FLAG_NAVIGATE_NEXT); private static final Integer OBJ_IME_FLAG_NAVIGATE_PREVIOUS = (Integer) CompatUtils diff --git a/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java b/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java index 828aea41f..7d8c745c3 100644 --- a/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java +++ b/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java @@ -16,12 +16,12 @@ package com.android.inputmethod.compat; -import com.android.inputmethod.deprecated.LanguageSwitcherProxy; -import com.android.inputmethod.latin.SubtypeSwitcher; - import android.inputmethodservice.InputMethodService; import android.view.inputmethod.InputMethodSubtype; +import com.android.inputmethod.deprecated.LanguageSwitcherProxy; +import com.android.inputmethod.latin.SubtypeSwitcher; + public class InputMethodServiceCompatWrapper extends InputMethodService { // CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED needs to be false if the API level is 10 // or previous. Note that InputMethodSubtype was added in the API level 11. diff --git a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java index 5d89669b7..4929dd948 100644 --- a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java +++ b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java @@ -30,12 +30,14 @@ import java.util.ArrayList; import java.util.Locale; public class SuggestionSpanUtils { + // TODO: Use reflection to get field values public static final String ACTION_SUGGESTION_PICKED = "android.text.style.SUGGESTION_PICKED"; public static final String SUGGESTION_SPAN_PICKED_AFTER = "after"; public static final String SUGGESTION_SPAN_PICKED_BEFORE = "before"; public static final String SUGGESTION_SPAN_PICKED_HASHCODE = "hashcode"; public static final int SUGGESTION_MAX_SIZE = 5; + public static final boolean SUGGESTION_SPAN_IS_SUPPORTED; private static final Class<?> CLASS_SuggestionSpan = CompatUtils .getClass("android.text.style.SuggestionSpan"); @@ -43,24 +45,23 @@ public class SuggestionSpanUtils { Context.class, Locale.class, String[].class, int.class, Class.class }; private static final Constructor<?> CONSTRUCTOR_SuggestionSpan = CompatUtils .getConstructor(CLASS_SuggestionSpan, INPUT_TYPE_SuggestionSpan); - public static final boolean SUGGESTION_SPAN_IS_SUPPORTED; static { SUGGESTION_SPAN_IS_SUPPORTED = CLASS_SuggestionSpan != null && CONSTRUCTOR_SuggestionSpan != null; } public static CharSequence getTextWithSuggestionSpan(Context context, - CharSequence suggestion, SuggestedWords suggestedWords) { - if (TextUtils.isEmpty(suggestion) || CONSTRUCTOR_SuggestionSpan == null + CharSequence pickedWord, SuggestedWords suggestedWords) { + if (TextUtils.isEmpty(pickedWord) || CONSTRUCTOR_SuggestionSpan == null || suggestedWords == null || suggestedWords.size() == 0) { - return suggestion; + return pickedWord; } final Spannable spannable; - if (suggestion instanceof Spannable) { - spannable = (Spannable) suggestion; + if (pickedWord instanceof Spannable) { + spannable = (Spannable) pickedWord; } else { - spannable = new SpannableString(suggestion); + spannable = new SpannableString(pickedWord); } final ArrayList<String> suggestionsList = new ArrayList<String>(); for (int i = 0; i < suggestedWords.size(); ++i) { @@ -68,7 +69,7 @@ public class SuggestionSpanUtils { break; } final CharSequence word = suggestedWords.getWord(i); - if (!TextUtils.equals(suggestion, word)) { + if (!TextUtils.equals(pickedWord, word)) { suggestionsList.add(word.toString()); } } @@ -78,9 +79,9 @@ public class SuggestionSpanUtils { (Class<?>) SuggestionSpanPickedNotificationReceiver.class }; final Object ss = CompatUtils.newInstance(CONSTRUCTOR_SuggestionSpan, args); if (ss == null) { - return suggestion; + return pickedWord; } - spannable.setSpan(ss, 0, suggestion.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + spannable.setSpan(ss, 0, pickedWord.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannable; } } diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index 3db214ec9..58629ba51 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -18,7 +18,6 @@ package com.android.inputmethod.keyboard; import android.content.Context; import android.content.res.Resources; -import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.util.Log; @@ -173,11 +172,6 @@ public class Keyboard { mDefaultHeight = mDefaultWidth; mId = id; 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); } @@ -440,7 +434,7 @@ public class Keyboard { private void loadKeyboard(Context context, int xmlLayoutResId) { try { - KeyboardParser parser = new KeyboardParser(this, context.getResources()); + KeyboardParser parser = new KeyboardParser(this, context); parser.parseKeyboard(xmlLayoutResId); // mMinWidth is the width of this keyboard which is maximum width of row. mMinWidth = parser.getMaxRowWidth(); diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardId.java b/java/src/com/android/inputmethod/keyboard/KeyboardId.java index 7c03ec71e..d97bb6730 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardId.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardId.java @@ -16,12 +16,12 @@ package com.android.inputmethod.keyboard; +import android.view.inputmethod.EditorInfo; + import com.android.inputmethod.compat.EditorInfoCompatUtils; import com.android.inputmethod.compat.InputTypeCompatUtils; import com.android.inputmethod.latin.R; -import android.view.inputmethod.EditorInfo; - import java.util.Arrays; import java.util.Locale; @@ -43,7 +43,7 @@ public class KeyboardId { public final int mMode; public final int mXmlId; public final int mColorScheme; - public final boolean mWebInput; + public final boolean mNavigateAction; public final boolean mPasswordInput; public final boolean mHasSettingsKey; public final boolean mVoiceKeyEnabled; @@ -67,7 +67,10 @@ public class KeyboardId { this.mMode = mode; this.mXmlId = xmlId; this.mColorScheme = colorScheme; - this.mWebInput = InputTypeCompatUtils.isWebInputType(inputType); + // Note: Turn off checking navigation flag to show TAB key for now. + this.mNavigateAction = InputTypeCompatUtils.isWebInputType(inputType); +// || EditorInfoCompatUtils.hasFlagNavigateNext(imeOptions) +// || EditorInfoCompatUtils.hasFlagNavigatePrevious(imeOptions); this.mPasswordInput = InputTypeCompatUtils.isPasswordInputType(inputType) || InputTypeCompatUtils.isVisiblePasswordInputType(inputType); this.mHasSettingsKey = hasSettingsKey; @@ -89,7 +92,7 @@ public class KeyboardId { mode, xmlId, colorScheme, - mWebInput, + mNavigateAction, mPasswordInput, hasSettingsKey, voiceKeyEnabled, @@ -143,7 +146,7 @@ public class KeyboardId { && other.mMode == this.mMode && other.mXmlId == this.mXmlId && other.mColorScheme == this.mColorScheme - && other.mWebInput == this.mWebInput + && other.mNavigateAction == this.mNavigateAction && other.mPasswordInput == this.mPasswordInput && other.mHasSettingsKey == this.mHasSettingsKey && other.mVoiceKeyEnabled == this.mVoiceKeyEnabled @@ -166,7 +169,7 @@ public class KeyboardId { modeName(mMode), EditorInfoCompatUtils.imeOptionsName(mImeAction), colorSchemeName(mColorScheme), - (mWebInput ? " webInput" : ""), + (mNavigateAction ? " navigateAction" : ""), (mPasswordInput ? " passwordInput" : ""), (mHasSettingsKey ? " hasSettingsKey" : ""), (mVoiceKeyEnabled ? " voiceKeyEnabled" : ""), diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java b/java/src/com/android/inputmethod/keyboard/KeyboardParser.java index 07166b1db..20af12bc5 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardParser.java @@ -121,6 +121,7 @@ public class KeyboardParser { public static final String TAG_KEY_STYLE = "key-style"; private final Keyboard mKeyboard; + private final Context mContext; private final Resources mResources; private int mHorizontalEdgesPadding; @@ -131,8 +132,10 @@ public class KeyboardParser { private Row mCurrentRow = null; private final KeyStyles mKeyStyles = new KeyStyles(); - public KeyboardParser(Keyboard keyboard, Resources res) { + public KeyboardParser(Keyboard keyboard, Context context) { mKeyboard = keyboard; + mContext = context; + final Resources res = context.getResources(); mResources = res; mHorizontalEdgesPadding = (int)res.getDimension(R.dimen.keyboard_horizontal_edges_padding); } @@ -187,8 +190,9 @@ public class KeyboardParser { private void parseKeyboardAttributes(XmlResourceParser parser) { final Keyboard keyboard = mKeyboard; - final TypedArray keyboardAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser), - R.styleable.Keyboard); + final TypedArray keyboardAttr = mContext.obtainStyledAttributes( + Xml.asAttributeSet(parser), R.styleable.Keyboard, R.attr.keyboardStyle, + R.style.Keyboard); final TypedArray keyAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.Keyboard_Key); try { @@ -469,8 +473,8 @@ public class KeyboardParser { try { final boolean modeMatched = matchTypedValue(a, R.styleable.Keyboard_Case_mode, id.mMode, KeyboardId.modeName(id.mMode)); - final boolean webInputMatched = matchBoolean(a, - R.styleable.Keyboard_Case_webInput, id.mWebInput); + final boolean navigateActionMatched = matchBoolean(a, + R.styleable.Keyboard_Case_navigateAction, id.mNavigateAction); final boolean passwordInputMatched = matchBoolean(a, R.styleable.Keyboard_Case_passwordInput, id.mPasswordInput); final boolean settingsKeyMatched = matchBoolean(a, @@ -493,7 +497,7 @@ public class KeyboardParser { R.styleable.Keyboard_Case_languageCode, id.mLocale.getLanguage()); final boolean countryCodeMatched = matchString(a, R.styleable.Keyboard_Case_countryCode, id.mLocale.getCountry()); - final boolean selected = modeMatched && webInputMatched && passwordInputMatched + final boolean selected = modeMatched && navigateActionMatched && passwordInputMatched && settingsKeyMatched && voiceEnabledMatched && voiceKeyMatched && colorSchemeMatched && imeActionMatched && localeCodeMatched && languageCodeMatched && countryCodeMatched; @@ -503,7 +507,7 @@ public class KeyboardParser { textAttr(KeyboardId.colorSchemeName( viewAttr.getInt( R.styleable.KeyboardView_colorScheme, -1)), "colorScheme"), - booleanAttr(a, R.styleable.Keyboard_Case_webInput, "webInput"), + booleanAttr(a, R.styleable.Keyboard_Case_navigateAction, "navigateAction"), booleanAttr(a, R.styleable.Keyboard_Case_passwordInput, "passwordInput"), booleanAttr(a, R.styleable.Keyboard_Case_hasSettingsKey, "hasSettingsKey"), booleanAttr(a, R.styleable.Keyboard_Case_voiceKeyEnabled, "voiceKeyEnabled"), diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 50c61ffae..8657768ee 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -43,7 +43,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha private static final boolean DEBUG_CACHE = LatinImeLogger.sDBG; public static final boolean DEBUG_STATE = false; - private static String sConfigDefaultKeyboardThemeId; public static final String PREF_KEYBOARD_LAYOUT = "pref_keyboard_layout_20100902"; private static final int[] KEYBOARD_THEMES = { R.style.KeyboardTheme, @@ -102,7 +101,8 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha // Default is SETTINGS_KEY_MODE_AUTO. private static final int DEFAULT_SETTINGS_KEY_MODE = SETTINGS_KEY_MODE_AUTO; - private int mThemeIndex; + private int mThemeIndex = -1; + private Context mThemeContext; private int mKeyboardWidth; private static final KeyboardSwitcher sInstance = new KeyboardSwitcher(); @@ -119,17 +119,30 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha sInstance.mInputMethodService = ims; sInstance.mPrefs = prefs; sInstance.mSubtypeSwitcher = SubtypeSwitcher.getInstance(); + sInstance.setContextThemeWrapper(ims, getKeyboardThemeIndex(ims, prefs)); + prefs.registerOnSharedPreferenceChangeListener(sInstance); + } + private static int getKeyboardThemeIndex(Context context, SharedPreferences prefs) { + final String defaultThemeId = context.getString(R.string.config_default_keyboard_theme_id); + final String themeId = prefs.getString(PREF_KEYBOARD_LAYOUT, defaultThemeId); try { - sConfigDefaultKeyboardThemeId = ims.getString( - R.string.config_default_keyboard_theme_id); - sInstance.mThemeIndex = Integer.valueOf( - prefs.getString(PREF_KEYBOARD_LAYOUT, sConfigDefaultKeyboardThemeId)); + final int themeIndex = Integer.valueOf(themeId); + if (themeIndex >= 0 && themeIndex < KEYBOARD_THEMES.length) + return themeIndex; } catch (NumberFormatException e) { - sConfigDefaultKeyboardThemeId = "0"; - sInstance.mThemeIndex = 0; + // Format error, keyboard theme is default to 0. + } + Log.w(TAG, "Illegal keyboard theme in preference: " + themeId + ", default to 0"); + return 0; + } + + private void setContextThemeWrapper(Context context, int themeIndex) { + if (mThemeIndex != themeIndex) { + mThemeIndex = themeIndex; + mThemeContext = new ContextThemeWrapper(context, KEYBOARD_THEMES[themeIndex]); + mKeyboardCache.clear(); } - prefs.registerOnSharedPreferenceChangeListener(sInstance); } public void loadKeyboard(EditorInfo attribute, boolean voiceKeyEnabled, @@ -202,9 +215,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha final Locale savedLocale = Utils.setSystemLocale(res, mSubtypeSwitcher.getInputLocale()); - final Context themeContext = new ContextThemeWrapper(mInputMethodService, - KEYBOARD_THEMES[mThemeIndex]); - keyboard = new LatinKeyboard(themeContext, id, id.mWidth); + keyboard = new LatinKeyboard(mThemeContext, id, id.mWidth); if (id.mEnableShiftLock) { keyboard.enableShiftLock(); @@ -724,30 +735,29 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha if (mKeyboardView != null) { mKeyboardView.closing(); } - final int themeIndex = (newThemeIndex < KEYBOARD_THEMES.length) ? newThemeIndex - : Integer.valueOf(sConfigDefaultKeyboardThemeId); + final int oldThemeIndex = mThemeIndex; Utils.GCUtils.getInstance().reset(); boolean tryGC = true; for (int i = 0; i < Utils.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) { try { - final Context themeContext = new ContextThemeWrapper(mInputMethodService, - KEYBOARD_THEMES[themeIndex]); - mCurrentInputView = LayoutInflater.from(themeContext).inflate( + setContextThemeWrapper(mInputMethodService, newThemeIndex); + mCurrentInputView = LayoutInflater.from(mThemeContext).inflate( R.layout.input_view, null); tryGC = false; } catch (OutOfMemoryError e) { Log.w(TAG, "load keyboard failed: " + e); - tryGC = Utils.GCUtils.getInstance().tryGCOrWait(mThemeIndex + "," + themeIndex, e); + tryGC = Utils.GCUtils.getInstance().tryGCOrWait( + oldThemeIndex + "," + newThemeIndex, e); } catch (InflateException e) { Log.w(TAG, "load keyboard failed: " + e); - tryGC = Utils.GCUtils.getInstance().tryGCOrWait(mThemeIndex + "," + themeIndex, e); + tryGC = Utils.GCUtils.getInstance().tryGCOrWait( + oldThemeIndex + "," + newThemeIndex, e); } } mKeyboardView = (LatinKeyboardView) mCurrentInputView.findViewById(R.id.keyboard_view); mKeyboardView.setOnKeyboardActionListener(mInputMethodService); - mThemeIndex = themeIndex; return mCurrentInputView; } @@ -766,8 +776,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (PREF_KEYBOARD_LAYOUT.equals(key)) { - final int layoutId = Integer.valueOf( - sharedPreferences.getString(key, sConfigDefaultKeyboardThemeId)); + final int layoutId = getKeyboardThemeIndex(mInputMethodService, sharedPreferences); postSetInputView(createInputView(layoutId, false)); } else if (Settings.PREF_SETTINGS_KEY.equals(key)) { mSettingsKeyEnabledInSettings = getSettingsKeyMode(sharedPreferences, @@ -782,11 +791,15 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } public void onAutoCorrectionStateChanged(boolean isAutoCorrection) { - if (isAutoCorrection != mIsAutoCorrectionActive) { - LatinKeyboardView keyboardView = getKeyboardView(); + if (mIsAutoCorrectionActive != isAutoCorrection) { mIsAutoCorrectionActive = isAutoCorrection; - keyboardView.invalidateKey(((LatinKeyboard) keyboardView.getKeyboard()) - .onAutoCorrectionStateChanged(isAutoCorrection)); + final LatinKeyboard keyboard = getLatinKeyboard(); + if (keyboard != null && keyboard.needsAutoCorrectionSpacebarLed()) { + final Key invalidatedKey = keyboard.onAutoCorrectionStateChanged(isAutoCorrection); + final LatinKeyboardView keyboardView = getKeyboardView(); + if (keyboardView != null) + keyboardView.invalidateKey(invalidatedKey); + } } } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index 44f2ff3ff..f73cdc083 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -626,8 +626,14 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { mDirtyRect.union(0, 0, width, height); } if (mBuffer == null || mBuffer.getWidth() != width || mBuffer.getHeight() != height) { + if (mBuffer != null) + mBuffer.recycle(); mBuffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); - mCanvas = new Canvas(mBuffer); + if (mCanvas != null) { + mCanvas.setBitmap(mBuffer); + } else { + mCanvas = new Canvas(mBuffer); + } } final Canvas canvas = mCanvas; canvas.clipRect(mDirtyRect, Op.REPLACE); diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java index a6ac76751..473006deb 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java @@ -16,9 +16,6 @@ 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.Resources.Theme; @@ -36,6 +33,9 @@ import android.graphics.Rect; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; +import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.SubtypeSwitcher; + import java.lang.ref.SoftReference; import java.util.Arrays; import java.util.HashMap; @@ -49,7 +49,8 @@ public class LatinKeyboard extends Keyboard { public static final int CODE_NEXT_LANGUAGE = -100; public static final int CODE_PREV_LANGUAGE = -101; - private final Context mContext; + private final Resources mRes; + private final Theme mTheme; private final SubtypeSwitcher mSubtypeSwitcher = SubtypeSwitcher.getInstance(); /* Space key and its icons, drawables and colors. */ @@ -65,7 +66,7 @@ public class LatinKeyboard extends Keyboard { private float mSpacebarTextFadeFactor = 0.0f; private final int mSpacebarLanguageSwitchThreshold; private int mSpacebarSlidingLanguageSwitchDiff; - private SlidingLocaleDrawable mSlidingLocaleIcon; + private final SlidingLocaleDrawable mSlidingLocaleIcon; private final HashMap<Integer, SoftReference<BitmapDrawable>> mSpaceDrawableCache = new HashMap<Integer, SoftReference<BitmapDrawable>>(); @@ -90,7 +91,8 @@ public class LatinKeyboard extends Keyboard { public LatinKeyboard(Context context, KeyboardId id, int width) { super(context, id.getXmlId(), id, width); - mContext = context; + mRes = context.getResources(); + mTheme = context.getTheme(); final List<Key> keys = getKeys(); int spaceKeyIndex = -1; @@ -133,6 +135,13 @@ public class LatinKeyboard extends Keyboard { // The threshold is "key width" x 1.25 mSpacebarLanguageSwitchThreshold = (getMostCommonKeyWidth() * 5) / 4; + + final int spaceKeyWidth = Math.max(mSpaceKey.mWidth, + (int)(getMinWidth() * SPACEBAR_POPUP_MIN_RATIO)); + final int spaceKeyheight = mSpacePreviewIcon.getIntrinsicHeight(); + mSlidingLocaleIcon = new SlidingLocaleDrawable( + context, mSpacePreviewIcon, spaceKeyWidth, spaceKeyheight); + mSlidingLocaleIcon.setBounds(0, 0, spaceKeyWidth, spaceKeyheight); } public void setSpacebarTextFadeFactor(float fadeFactor, LatinKeyboardView view) { @@ -250,7 +259,7 @@ public class LatinKeyboard extends Keyboard { final SoftReference<BitmapDrawable> ref = mSpaceDrawableCache.get(hashCode); BitmapDrawable drawable = (ref == null) ? null : ref.get(); if (drawable == null) { - drawable = new BitmapDrawable(mContext.getResources(), drawSpacebar( + drawable = new BitmapDrawable(mRes, drawSpacebar( locale, isAutoCorrection, mSpacebarTextFadeFactor)); mSpaceDrawableCache.put(hashCode, new SoftReference<BitmapDrawable>(drawable)); } @@ -263,7 +272,7 @@ public class LatinKeyboard extends Keyboard { final int height = mSpaceIcon != null ? mSpaceIcon.getIntrinsicHeight() : mSpaceKey.mHeight; final Bitmap buffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(buffer); - final Resources res = mContext.getResources(); + final Resources res = mRes; canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); // If application locales are explicitly selected. @@ -287,7 +296,7 @@ public class LatinKeyboard extends Keyboard { final String language = layoutSpacebar(paint, inputLocale, mSpacebarArrowLeftIcon, mSpacebarArrowRightIcon, width, height, - getTextSizeFromTheme(mContext.getTheme(), textStyle, defaultTextSize)); + getTextSizeFromTheme(mTheme, textStyle, defaultTextSize)); // Draw language text with shadow // In case there is no space icon, we will place the language text at the center of @@ -341,14 +350,6 @@ public class LatinKeyboard extends Keyboard { if (mSpacebarSlidingLanguageSwitchDiff == diff) return; mSpacebarSlidingLanguageSwitchDiff = diff; - if (mSlidingLocaleIcon == null) { - final int width = Math.max(mSpaceKey.mWidth, - (int)(getMinWidth() * SPACEBAR_POPUP_MIN_RATIO)); - final int height = mSpacePreviewIcon.getIntrinsicHeight(); - mSlidingLocaleIcon = - new SlidingLocaleDrawable(mContext, mSpacePreviewIcon, width, height); - mSlidingLocaleIcon.setBounds(0, 0, width, height); - } mSlidingLocaleIcon.setDiff(diff); if (Math.abs(diff) == Integer.MAX_VALUE) { mSpaceKey.setPreviewIcon(mSpacePreviewIcon); @@ -403,7 +404,7 @@ public class LatinKeyboard extends Keyboard { Math.max(0, Math.min(y, getHeight() - 1))); } - private static int getTextSizeFromTheme(Theme theme, int style, int defValue) { + public static int getTextSizeFromTheme(Theme theme, int style, int defValue) { TypedArray array = theme.obtainStyledAttributes( style, new int[] { android.R.attr.textSize }); int textSize = array.getDimensionPixelSize(array.getResourceId(0, 0), defValue); diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 397ac7eec..0a727ad42 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -615,7 +615,7 @@ public class PointerTracker { // The modifier key, such as shift key, should not show its key preview. private boolean isKeyPreviewNotRequired(int keyIndex) { final Key key = getKey(keyIndex); - if (!key.mEnabled) + if (key == null || !key.mEnabled) return true; // Such as spacebar sliding language switch. if (mKeyboard.needSpacebarPreview(keyIndex)) diff --git a/java/src/com/android/inputmethod/keyboard/SlidingLocaleDrawable.java b/java/src/com/android/inputmethod/keyboard/SlidingLocaleDrawable.java index a20bf1cd3..dd271de64 100644 --- a/java/src/com/android/inputmethod/keyboard/SlidingLocaleDrawable.java +++ b/java/src/com/android/inputmethod/keyboard/SlidingLocaleDrawable.java @@ -60,8 +60,8 @@ public class SlidingLocaleDrawable extends Drawable { mWidth = width; mHeight = height; final TextPaint textPaint = new TextPaint(); - textPaint.setTextSize(getTextSizeFromTheme( - context, android.R.style.TextAppearance_Medium, 18)); + textPaint.setTextSize(LatinKeyboard.getTextSizeFromTheme( + context.getTheme(), android.R.style.TextAppearance_Medium, 18)); textPaint.setColor(Color.TRANSPARENT); textPaint.setTextAlign(Align.CENTER); textPaint.setAntiAlias(true); @@ -78,13 +78,6 @@ public class SlidingLocaleDrawable extends Drawable { mThreshold = ViewConfiguration.get(context).getScaledTouchSlop(); } - 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; - } - void setDiff(int diff) { if (diff == Integer.MAX_VALUE) { mHitThreshold = false; diff --git a/java/src/com/android/inputmethod/latin/CandidateView.java b/java/src/com/android/inputmethod/latin/CandidateView.java index 2a29e1f8f..92d26a01c 100644 --- a/java/src/com/android/inputmethod/latin/CandidateView.java +++ b/java/src/com/android/inputmethod/latin/CandidateView.java @@ -349,9 +349,9 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo dv.setTextColor(0xff808080); dv.setText(info.getDebugString()); // TODO: debug view for candidate strip needed. - mCandidatesPane.addView(dv); - LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)dv.getLayoutParams(); - lp.gravity = Gravity.BOTTOM; +// mCandidatesPane.addView(dv); +// LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)dv.getLayoutParams(); +// lp.gravity = Gravity.BOTTOM; } } if (x != 0) { diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 87912eb00..fd4a47c39 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -518,8 +518,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar LatinKeyboardView inputView = switcher.getKeyboardView(); if (DEBUG) { - Log.d(TAG, "onStartInputView: inputType=" + ((attribute == null) ? "none" - : String.format("0x%08x", attribute.inputType))); + Log.d(TAG, "onStartInputView: attribute:" + ((attribute == null) ? "none" + : String.format("inputType=0x%08x imeOptions=0x%08x", + attribute.inputType, attribute.imeOptions))); } // In landscape mode, this method gets called without the input view being created. if (inputView == null) { @@ -1458,16 +1459,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } public void setSuggestions(SuggestedWords words) { -// if (mVoiceProxy.getAndResetIsShowingHint()) { -// setCandidatesView(mCandidateViewContainer); -// } - if (mCandidateView != null) { mCandidateView.setSuggestions(words); - if (mKeyboardSwitcher.getLatinKeyboard().needsAutoCorrectionSpacebarLed()) { - mKeyboardSwitcher.onAutoCorrectionStateChanged( - words.hasWordAboveAutoCorrectionScoreThreshold()); - } + mKeyboardSwitcher.onAutoCorrectionStateChanged( + words.hasWordAboveAutoCorrectionScoreThreshold()); } } @@ -1876,7 +1871,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } // The following is necessary because on API levels < 10, we don't get notified when // subtype changes. - onRefreshKeyboard(); + if (!CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED) + onRefreshKeyboard(); } @Override diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 62788fb9e..d01e3e9c2 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -117,30 +117,31 @@ public class Suggest implements Dictionary.WordCallback { } private void init(Context context, Dictionary mainDict) { - if (mainDict != null) { - mMainDict = mainDict; - mUnigramDictionaries.put(DICT_KEY_MAIN, mainDict); - mBigramDictionaries.put(DICT_KEY_MAIN, mainDict); - } + mMainDict = mainDict; + addOrReplaceDictionary(mUnigramDictionaries, DICT_KEY_MAIN, mainDict); + addOrReplaceDictionary(mBigramDictionaries, DICT_KEY_MAIN, mainDict); mWhiteListDictionary = WhitelistDictionary.init(context); - if (mWhiteListDictionary != null) { - mUnigramDictionaries.put(DICT_KEY_WHITELIST, mWhiteListDictionary); - } + addOrReplaceDictionary(mUnigramDictionaries, DICT_KEY_WHITELIST, mWhiteListDictionary); mAutoCorrection = new AutoCorrection(); initPool(); } + private void addOrReplaceDictionary(Map<String, Dictionary> dictionaries, String key, + Dictionary dict) { + final Dictionary oldDict = (dict == null) + ? dictionaries.remove(key) + : dictionaries.put(key, dict); + if (oldDict != null && dict != oldDict) { + oldDict.close(); + } + } + public void resetMainDict(Context context, int dictionaryResId, Locale locale) { final Dictionary newMainDict = DictionaryFactory.createDictionaryFromManager( context, locale, dictionaryResId); mMainDict = newMainDict; - if (null == newMainDict) { - mUnigramDictionaries.remove(DICT_KEY_MAIN); - mBigramDictionaries.remove(DICT_KEY_MAIN); - } else { - mUnigramDictionaries.put(DICT_KEY_MAIN, newMainDict); - mBigramDictionaries.put(DICT_KEY_MAIN, newMainDict); - } + addOrReplaceDictionary(mUnigramDictionaries, DICT_KEY_MAIN, newMainDict); + addOrReplaceDictionary(mBigramDictionaries, DICT_KEY_MAIN, newMainDict); } private void initPool() { @@ -179,8 +180,7 @@ public class Suggest implements Dictionary.WordCallback { * before the main dictionary, if set. */ public void setUserDictionary(Dictionary userDictionary) { - if (userDictionary != null) - mUnigramDictionaries.put(DICT_KEY_USER, userDictionary); + addOrReplaceDictionary(mUnigramDictionaries, DICT_KEY_USER, userDictionary); } /** @@ -189,23 +189,16 @@ public class Suggest implements Dictionary.WordCallback { * won't be used. */ public void setContactsDictionary(Dictionary contactsDictionary) { - if (contactsDictionary != null) { - mUnigramDictionaries.put(DICT_KEY_CONTACTS, contactsDictionary); - mBigramDictionaries.put(DICT_KEY_CONTACTS, contactsDictionary); - } else { - mUnigramDictionaries.remove(DICT_KEY_CONTACTS); - mBigramDictionaries.remove(DICT_KEY_CONTACTS); - } + addOrReplaceDictionary(mUnigramDictionaries, DICT_KEY_CONTACTS, contactsDictionary); + addOrReplaceDictionary(mBigramDictionaries, DICT_KEY_CONTACTS, contactsDictionary); } public void setAutoDictionary(Dictionary autoDictionary) { - if (autoDictionary != null) - mUnigramDictionaries.put(DICT_KEY_AUTO, autoDictionary); + addOrReplaceDictionary(mUnigramDictionaries, DICT_KEY_AUTO, autoDictionary); } public void setUserBigramDictionary(Dictionary userBigramDictionary) { - if (userBigramDictionary != null) - mBigramDictionaries.put(DICT_KEY_USER_BIGRAM, userBigramDictionary); + addOrReplaceDictionary(mBigramDictionaries, DICT_KEY_USER_BIGRAM, userBigramDictionary); } public void setAutoCorrectionThreshold(double threshold) { |