From e276d8ddaaff91d5940a71cefb5ecd94fd48ba98 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Fri, 14 Jan 2011 16:12:36 +0900 Subject: Add SubtypeLocale class Change-Id: Ic4c73c313f976ad6df1b4ddf48b914d05a08d283 --- .../android/inputmethod/latin/SubtypeLocale.java | 46 ++++++++++++++++++++++ .../android/inputmethod/latin/SubtypeSwitcher.java | 5 ++- 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 java/src/com/android/inputmethod/latin/SubtypeLocale.java (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/latin/SubtypeLocale.java b/java/src/com/android/inputmethod/latin/SubtypeLocale.java new file mode 100644 index 000000000..917521c40 --- /dev/null +++ b/java/src/com/android/inputmethod/latin/SubtypeLocale.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.inputmethod.latin; + +import android.content.Context; +import android.content.res.Resources; + +import java.util.Locale; + +public class SubtypeLocale { + private static String[] sExceptionKeys; + private static String[] sExceptionValues; + + private SubtypeLocale() { + // Intentional empty constructor for utility class. + } + + public static void init(Context context) { + final Resources res = context.getResources(); + sExceptionKeys = res.getStringArray(R.array.subtype_locale_exception_keys); + sExceptionValues = res.getStringArray(R.array.subtype_locale_exception_values); + } + + public static String getFullDisplayName(Locale locale) { + String localeCode = locale.toString(); + for (int index = 0; index < sExceptionKeys.length; index++) { + if (sExceptionKeys[index].equals(localeCode)) + return sExceptionValues[index]; + } + return locale.getDisplayName(locale); + } +} diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index d696834e9..f75e2953e 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -16,7 +16,6 @@ package com.android.inputmethod.latin; -import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.voice.SettingsUtil; import com.android.inputmethod.voice.VoiceIMEConnector; @@ -90,6 +89,8 @@ public class SubtypeSwitcher { } sInstance.updateAllParameters(); + + SubtypeLocale.init(service); } private SubtypeSwitcher() { @@ -445,7 +446,7 @@ public class SubtypeSwitcher { public static String getFullDisplayName(Locale locale, boolean returnsNameInThisLocale) { if (returnsNameInThisLocale) { - return toTitleCase(locale.getDisplayName(locale)); + return toTitleCase(SubtypeLocale.getFullDisplayName(locale)); } else { return toTitleCase(locale.getDisplayName()); } -- cgit v1.2.3-83-g751a From de0c8874a4eb1250e8439d9e4e1badca88316670 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 12 Jan 2011 20:33:54 +0900 Subject: Notify keyboard language on space bar when it has changed This change also introduces the following. * space bar language switcher is enabled for phone device. * get rid of spcae key icon from number keyboard of tablet. * slightly lower the position of language name on space bar of tablet. Bug: 3290290 Change-Id: I432be8f757bcc84c257770112ff1f6fa7970c584 --- java/res/values-xlarge/config.xml | 3 + java/res/values/config.xml | 4 ++ java/res/xml-xlarge/kbd_key_styles.xml | 3 - java/res/xml-xlarge/kbd_numkey_styles.xml | 2 - .../inputmethod/keyboard/KeyboardSwitcher.java | 21 +++++-- .../android/inputmethod/keyboard/KeyboardView.java | 3 +- .../inputmethod/keyboard/LatinKeyboard.java | 55 +++++++++++------- .../inputmethod/keyboard/LatinKeyboardView.java | 8 +++ .../com/android/inputmethod/latin/LatinIME.java | 56 ++++++++++++++----- .../android/inputmethod/latin/SubtypeSwitcher.java | 65 +++++++++------------- 10 files changed, 135 insertions(+), 85 deletions(-) (limited to 'java/src') diff --git a/java/res/values-xlarge/config.xml b/java/res/values-xlarge/config.xml index 56b9a166f..410b5e19e 100644 --- a/java/res/values-xlarge/config.xml +++ b/java/res/values-xlarge/config.xml @@ -28,6 +28,9 @@ false false + false + + 1200 5 medium diff --git a/java/res/values/config.xml b/java/res/values/config.xml index 63af9a9ba..adfec4c25 100644 --- a/java/res/values/config.xml +++ b/java/res/values/config.xml @@ -31,6 +31,10 @@ true true + true + + -1 + 50 0 10 0 diff --git a/java/res/xml-xlarge/kbd_key_styles.xml b/java/res/xml-xlarge/kbd_key_styles.xml index c6b785896..efbad5bab 100644 --- a/java/res/xml-xlarge/kbd_key_styles.xml +++ b/java/res/xml-xlarge/kbd_key_styles.xml @@ -57,7 +57,6 @@ diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 331c8db6a..25ef847cd 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -157,7 +157,14 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha boolean voiceButtonOnPrimary) { mAutoModeSwitchState = AUTO_MODE_SWITCH_STATE_ALPHA; try { + if (mInputView == null) return; + final Keyboard oldKeyboard = mInputView.getKeyboard(); loadKeyboardInternal(mode, imeOptions, voiceKeyEnabled, voiceButtonOnPrimary, false); + final Keyboard newKeyboard = mInputView.getKeyboard(); + if (newKeyboard.isAlphaKeyboard() && (oldKeyboard == null + || !newKeyboard.mId.mLocale.equals(oldKeyboard.mId.mLocale))) { + mInputMethodService.mHandler.startDisplayLanguageOnSpacebar(); + } } catch (RuntimeException e) { Log.w(TAG, e); LatinImeLogger.logOnException(mode + "," + imeOptions, e); @@ -167,6 +174,11 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha private void loadKeyboardInternal(int mode, int imeOptions, boolean voiceButtonEnabled, boolean voiceButtonOnPrimary, boolean isSymbols) { if (mInputView == null) return; + final Keyboard oldKeyboard = mInputView.getKeyboard(); + final KeyboardId id = getKeyboardId(mode, imeOptions, isSymbols); + if (oldKeyboard != null && oldKeyboard.mId.equals(id)) + return; + mInputView.setPreviewEnabled(mInputMethodService.getPopupOn()); mMode = mode; @@ -178,11 +190,8 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha mHasSettingsKey = getSettingsKeyMode(mPrefs, mInputMethodService); makeSymbolsKeyboardIds(); - KeyboardId id = getKeyboardId(mode, imeOptions, isSymbols); - LatinKeyboard keyboard = getKeyboard(id); - mCurrentId = id; - mInputView.setKeyboard(keyboard); + mInputView.setKeyboard(getKeyboard(id)); } private LatinKeyboard getKeyboard(KeyboardId id) { @@ -210,6 +219,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha keyboard.onAutoCorrectionStateChanged(mIsAutoCorrectionActive); keyboard.setShifted(false); + // If the cached keyboard had been switched to another keyboard while the language was + // displayed on its spacebar, it might have had arbitrary text fade factor. In such case, + // we should reset the text fade factor. + keyboard.setSpacebarTextFadeFactor(0.0f, null); return keyboard; } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index e7dd716fb..a952acf8b 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -912,9 +912,8 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { // We should re-draw popup preview when 1) we need to hide the preview, 2) we will show // the space key preview and 3) pointer moves off the space key to other letter key, we // should hide the preview of the previous key. - @SuppressWarnings("unused") final boolean hidePreviewOrShowSpaceKeyPreview = (tracker == null) - || (SubtypeSwitcher.USE_SPACEBAR_LANGUAGE_SWITCHER + || (SubtypeSwitcher.getInstance().useSpacebarLanguageSwitcher() && SubtypeSwitcher.getInstance().needsToDisplayLanguage() && (tracker.isSpaceKey(keyIndex) || tracker.isSpaceKey(oldKeyIndex))); // If key changed and preview is on or the key is space (language switch is enabled) diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java index 77dde8d1b..db8934049 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java @@ -24,6 +24,7 @@ import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Canvas; +import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Align; import android.graphics.PorterDuff; @@ -47,7 +48,9 @@ public class LatinKeyboard extends Keyboard { private final Drawable mSpaceAutoCorrectionIndicator; private final Drawable mButtonArrowLeftIcon; private final Drawable mButtonArrowRightIcon; - private final int mSpaceBarTextShadowColor; + private final int mSpacebarTextColor; + private final int mSpacebarTextShadowColor; + private float mSpacebarTextFadeFactor = 0.0f; private final int[] mSpaceKeyIndexArray; private int mSpaceDragStartX; private int mSpaceDragLastDiff; @@ -67,6 +70,7 @@ public class LatinKeyboard extends Keyboard { private static final float SPACEBAR_POPUP_MIN_RATIO = 0.4f; // Height in space key the language name will be drawn. (proportional to space key height) public static final float SPACEBAR_LANGUAGE_BASELINE = 0.6f; + private static final float SPACEBAR_LANGUAGE_BASELINE_WITHOUT_ICON = 0.65f; // If the full language name needs to be smaller than this value to be drawn on space key, // its short language name will be used instead. private static final float MINIMUM_SCALE_OF_LANGUAGE_NAME = 0.8f; @@ -80,11 +84,12 @@ public class LatinKeyboard extends Keyboard { super(context, id.getXmlId(), id); final Resources res = context.getResources(); mContext = context; + mSpacebarTextColor = res.getColor(R.color.latinkeyboard_bar_language_text); if (id.mColorScheme == KeyboardView.COLOR_SCHEME_BLACK) { - mSpaceBarTextShadowColor = res.getColor( + mSpacebarTextShadowColor = res.getColor( R.color.latinkeyboard_bar_language_shadow_black); } else { // default color scheme is KeyboardView.COLOR_SCHEME_WHITE - mSpaceBarTextShadowColor = res.getColor( + mSpacebarTextShadowColor = res.getColor( R.color.latinkeyboard_bar_language_shadow_white); } mSpaceAutoCorrectionIndicator = res.getDrawable(R.drawable.sym_keyboard_space_led); @@ -96,25 +101,38 @@ public class LatinKeyboard extends Keyboard { mSpaceKeyIndexArray = new int[] { indexOf(CODE_SPACE) }; } + public void setSpacebarTextFadeFactor(float fadeFactor, LatinKeyboardView view) { + mSpacebarTextFadeFactor = fadeFactor; + updateSpacebarForLocale(false); + if (view != null) + view.invalidateKey(mSpaceKey); + } + + private static int getSpacebarTextColor(int color, float fadeFactor) { + final int newColor = Color.argb((int)(Color.alpha(color) * fadeFactor), + Color.red(color), Color.green(color), Color.blue(color)); + return newColor; + } + /** * @return a key which should be invalidated. */ public Key onAutoCorrectionStateChanged(boolean isAutoCorrection) { - updateSpaceBarForLocale(isAutoCorrection); + updateSpacebarForLocale(isAutoCorrection); return mSpaceKey; } - private void updateSpaceBarForLocale(boolean isAutoCorrection) { + private void updateSpacebarForLocale(boolean isAutoCorrection) { final Resources res = mContext.getResources(); // If application locales are explicitly selected. if (SubtypeSwitcher.getInstance().needsToDisplayLanguage()) { mSpaceKey.setIcon(new BitmapDrawable(res, - drawSpaceBar(OPACITY_FULLY_OPAQUE, isAutoCorrection))); + drawSpacebar(OPACITY_FULLY_OPAQUE, isAutoCorrection))); } else { // sym_keyboard_space_led can be shared with Black and White symbol themes. if (isAutoCorrection) { mSpaceKey.setIcon(new BitmapDrawable(res, - drawSpaceBar(OPACITY_FULLY_OPAQUE, isAutoCorrection))); + drawSpacebar(OPACITY_FULLY_OPAQUE, isAutoCorrection))); } else { mSpaceKey.setIcon(mSpaceIcon); } @@ -128,8 +146,8 @@ public class LatinKeyboard extends Keyboard { return bounds.width(); } - // Layout local language name and left and right arrow on space bar. - private static String layoutSpaceBar(Paint paint, Locale locale, Drawable lArrow, + // Layout local language name and left and right arrow on spacebar. + private static String layoutSpacebar(Paint paint, Locale locale, Drawable lArrow, Drawable rArrow, int width, int height, float origTextSize, boolean allowVariableTextSize) { final float arrowWidth = lArrow.getIntrinsicWidth(); @@ -138,7 +156,7 @@ public class LatinKeyboard extends Keyboard { final Rect bounds = new Rect(); // Estimate appropriate language name text size to fit in maxTextWidth. - String language = SubtypeSwitcher.getDisplayLanguage(locale); + String language = SubtypeSwitcher.getFullDisplayName(locale, true); 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); @@ -171,8 +189,7 @@ public class LatinKeyboard extends Keyboard { return language; } - @SuppressWarnings("unused") - private Bitmap drawSpaceBar(int opacity, boolean isAutoCorrection) { + private Bitmap drawSpacebar(int opacity, boolean isAutoCorrection) { final int width = mSpaceKey.mWidth; final int height = mSpaceIcon != null ? mSpaceIcon.getIntrinsicHeight() : mSpaceKey.mHeight; final Bitmap buffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); @@ -202,21 +219,22 @@ public class LatinKeyboard extends Keyboard { } final boolean allowVariableTextSize = true; - final String language = layoutSpaceBar(paint, subtypeSwitcher.getInputLocale(), + final String language = layoutSpacebar(paint, subtypeSwitcher.getInputLocale(), mButtonArrowLeftIcon, mButtonArrowRightIcon, width, height, getTextSizeFromTheme(textStyle, defaultTextSize), allowVariableTextSize); // Draw language text with shadow - final float baseline = height * SPACEBAR_LANGUAGE_BASELINE; + final float baseline = height * (mSpaceIcon != null ? SPACEBAR_LANGUAGE_BASELINE + : SPACEBAR_LANGUAGE_BASELINE_WITHOUT_ICON); final float descent = paint.descent(); - paint.setColor(mSpaceBarTextShadowColor); + paint.setColor(getSpacebarTextColor(mSpacebarTextShadowColor, mSpacebarTextFadeFactor)); canvas.drawText(language, width / 2, baseline - descent - 1, paint); - paint.setColor(res.getColor(R.color.latinkeyboard_bar_language_text)); + paint.setColor(getSpacebarTextColor(mSpacebarTextColor, mSpacebarTextFadeFactor)); canvas.drawText(language, width / 2, baseline - descent, paint); // Put arrows that are already layed out on either side of the text - if (SubtypeSwitcher.USE_SPACEBAR_LANGUAGE_SWITCHER + if (SubtypeSwitcher.getInstance().useSpacebarLanguageSwitcher() && subtypeSwitcher.getEnabledKeyboardLocaleCount() > 1) { mButtonArrowLeftIcon.draw(canvas); mButtonArrowRightIcon.draw(canvas); @@ -291,7 +309,6 @@ public class LatinKeyboard extends Keyboard { * switching input languages. */ @Override - @SuppressWarnings("unused") // SubtypeSwitcher.USE_SPACEBAR_LANGUAGE_SWITCHER is constant public boolean isInside(Key key, int pointX, int pointY) { int x = pointX; int y = pointY; @@ -302,7 +319,7 @@ public class LatinKeyboard extends Keyboard { if (code == CODE_DELETE) x -= key.mWidth / 6; } else if (code == CODE_SPACE) { y += LatinKeyboard.sSpacebarVerticalCorrection; - if (SubtypeSwitcher.USE_SPACEBAR_LANGUAGE_SWITCHER + if (SubtypeSwitcher.getInstance().useSpacebarLanguageSwitcher() && SubtypeSwitcher.getInstance().getEnabledKeyboardLocaleCount() > 1) { if (mCurrentlyInSpace) { int diff = x - mSpaceDragStartX; diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index 51bfbf1f9..ef41cb6e4 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -85,6 +85,14 @@ public class LatinKeyboardView extends KeyboardView { } } + public void setSpacebarTextFadeFactor(float fadeFactor, LatinKeyboard oldKeyboard) { + final LatinKeyboard currentKeyboard = getLatinKeyboard(); + // We should not set text fade factor to the keyboard which does not display the language on + // its spacebar. + if (currentKeyboard != null && currentKeyboard == oldKeyboard) + currentKeyboard.setSpacebarTextFadeFactor(fadeFactor, this); + } + @Override protected boolean onLongPress(Key key) { int primaryCode = key.mCode; diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 5e701c1f0..b93b07ffb 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -21,6 +21,7 @@ import com.android.inputmethod.keyboard.KeyboardActionListener; import com.android.inputmethod.keyboard.KeyboardId; import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.keyboard.KeyboardView; +import com.android.inputmethod.keyboard.LatinKeyboard; import com.android.inputmethod.keyboard.LatinKeyboardView; import com.android.inputmethod.latin.Utils.RingCharBuffer; import com.android.inputmethod.voice.VoiceIMEConnector; @@ -151,6 +152,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private boolean mAutoCap; private boolean mQuickFixes; private boolean mConfigSwipeDownDismissKeyboardEnabled; + private int mConfigDelayBeforeFadeoutLanguageOnSpacebar; + private int mConfigDurationOfFadeoutLanguageOnSpacebar; private int mCorrectionMode; private int mCommittedLength; @@ -241,9 +244,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private static final int MSG_UPDATE_OLD_SUGGESTIONS = 1; private static final int MSG_UPDATE_SHIFT_STATE = 2; private static final int MSG_VOICE_RESULTS = 3; + private static final int MSG_FADEOUT_LANGUAGE_ON_SPACEBAR = 4; + private static final int MSG_DISMISS_LANGUAGE_ON_SPACEBAR = 5; @Override public void handleMessage(Message msg) { + final KeyboardSwitcher switcher = mKeyboardSwitcher; + final LatinKeyboardView inputView = switcher.getInputView(); switch (msg.what) { case MSG_UPDATE_SUGGESTIONS: updateSuggestions(); @@ -252,12 +259,21 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen setOldSuggestions(); break; case MSG_UPDATE_SHIFT_STATE: - mKeyboardSwitcher.updateShiftState(); + switcher.updateShiftState(); break; case MSG_VOICE_RESULTS: mVoiceConnector.handleVoiceResults(preferCapitalization() - || (mKeyboardSwitcher.isAlphabetMode() - && mKeyboardSwitcher.isShiftedOrShiftLocked())); + || (switcher.isAlphabetMode() && switcher.isShiftedOrShiftLocked())); + break; + case MSG_FADEOUT_LANGUAGE_ON_SPACEBAR: + if (inputView != null) + inputView.setSpacebarTextFadeFactor(0.5f, (LatinKeyboard)msg.obj); + sendMessageDelayed(obtainMessage(MSG_DISMISS_LANGUAGE_ON_SPACEBAR, msg.obj), + mConfigDurationOfFadeoutLanguageOnSpacebar); + break; + case MSG_DISMISS_LANGUAGE_ON_SPACEBAR: + if (inputView != null) + inputView.setSpacebarTextFadeFactor(0.0f, (LatinKeyboard)msg.obj); break; } } @@ -297,6 +313,23 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen public void updateVoiceResults() { sendMessage(obtainMessage(MSG_VOICE_RESULTS)); } + + public void startDisplayLanguageOnSpacebar() { + removeMessages(MSG_FADEOUT_LANGUAGE_ON_SPACEBAR); + removeMessages(MSG_DISMISS_LANGUAGE_ON_SPACEBAR); + final LatinKeyboardView inputView = mKeyboardSwitcher.getInputView(); + if (inputView != null) { + final LatinKeyboard keyboard = inputView.getLatinKeyboard(); + // The language is never displayed when the delay is zero. + if (mConfigDelayBeforeFadeoutLanguageOnSpacebar != 0) + inputView.setSpacebarTextFadeFactor(1.0f, keyboard); + // The language is always displayed when the delay is negative. + if (mConfigDelayBeforeFadeoutLanguageOnSpacebar > 0) { + sendMessageDelayed(obtainMessage(MSG_FADEOUT_LANGUAGE_ON_SPACEBAR, keyboard), + mConfigDelayBeforeFadeoutLanguageOnSpacebar); + } + } + } } @Override @@ -319,6 +352,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen res.getBoolean(R.bool.default_recorrection_enabled)); mConfigSwipeDownDismissKeyboardEnabled = res.getBoolean( R.bool.config_swipe_down_dismiss_keyboard_enabled); + mConfigDelayBeforeFadeoutLanguageOnSpacebar = res.getInteger( + R.integer.config_delay_before_fadeout_language_on_spacebar); + mConfigDurationOfFadeoutLanguageOnSpacebar = res.getInteger( + R.integer.config_duration_of_fadeout_language_on_spacebar); Utils.GCUtils.getInstance().reset(); boolean tryGC = true; @@ -401,23 +438,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen @Override public void onConfigurationChanged(Configuration conf) { - mSubtypeSwitcher.onConfigurationChanged(conf); - if (mSubtypeSwitcher.isKeyboardMode()) - onKeyboardLanguageChanged(); - updateAutoTextEnabled(); - // If orientation changed while predicting, commit the change if (conf.orientation != mOrientation) { InputConnection ic = getCurrentInputConnection(); commitTyped(ic); if (ic != null) ic.finishComposingText(); // For voice input mOrientation = conf.orientation; - final int mode = mKeyboardSwitcher.getKeyboardMode(); - final EditorInfo attribute = getCurrentInputEditorInfo(); - final int imeOptions = (attribute != null) ? attribute.imeOptions : 0; - mKeyboardSwitcher.loadKeyboard(mode, imeOptions, - mVoiceConnector.isVoiceButtonEnabled(), - mVoiceConnector.isVoiceButtonOnPrimary()); } mConfigurationChanging = true; @@ -1817,7 +1843,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // "reset" and "next" are used only for USE_SPACEBAR_LANGUAGE_SWITCHER. private void toggleLanguage(boolean reset, boolean next) { - if (SubtypeSwitcher.USE_SPACEBAR_LANGUAGE_SWITCHER) { + if (mSubtypeSwitcher.useSpacebarLanguageSwitcher()) { mSubtypeSwitcher.toggleLanguage(reset, next); } // Reload keyboard because the current language has been changed. diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index e1852b2ad..91044685e 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -41,10 +41,6 @@ import java.util.Locale; import java.util.Map; public class SubtypeSwitcher { - // TODO: This should be configurable by resource - // This flag indicates if we support language switching by swipe on space bar. - // We may or may not draw the current language on space bar regardless of this flag. - public static final boolean USE_SPACEBAR_LANGUAGE_SWITCHER = false; private static final boolean DBG = false; private static final String TAG = "SubtypeSwitcher"; @@ -63,6 +59,8 @@ public class SubtypeSwitcher { new ArrayList(); private final ArrayList mEnabledLanguagesOfCurrentInputMethod = new ArrayList(); + private boolean mConfigUseSpacebarLanguageSwitcher; + /*-----------------------------------------------------------*/ // Variants which should be changed only by reload functions. private boolean mNeedsToDisplayLanguage; @@ -84,10 +82,6 @@ public class SubtypeSwitcher { public static void init(LatinIME service, SharedPreferences prefs) { sInstance.mPrefs = prefs; sInstance.resetParams(service); - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { - sInstance.initLanguageSwitcher(service); - } - sInstance.updateAllParameters(); } @@ -109,6 +103,10 @@ public class SubtypeSwitcher { mAllEnabledSubtypesOfCurrentInputMethod = null; // TODO: Voice input should be created here mVoiceInput = null; + mConfigUseSpacebarLanguageSwitcher = mResources.getBoolean( + R.bool.config_use_spacebar_language_switcher); + if (mConfigUseSpacebarLanguageSwitcher) + initLanguageSwitcher(service); } // Update all parameters stored in SubtypeSwitcher. @@ -122,8 +120,8 @@ public class SubtypeSwitcher { // Update parameters which are changed outside LatinIME. This parameters affect UI so they // should be updated every time onStartInputview. public void updateParametersOnStartInputView() { - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { - updateForSpaceBarLanguageSwitch(); + if (mConfigUseSpacebarLanguageSwitcher) { + updateForSpacebarLanguageSwitch(); } else { updateEnabledSubtypes(); } @@ -307,19 +305,23 @@ public class SubtypeSwitcher { ////////////////////////////////// public int getEnabledKeyboardLocaleCount() { - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + if (mConfigUseSpacebarLanguageSwitcher) { return mLanguageSwitcher.getLocaleCount(); } else { return mEnabledKeyboardSubtypesOfCurrentInputMethod.size(); } } + public boolean useSpacebarLanguageSwitcher() { + return mConfigUseSpacebarLanguageSwitcher; + } + public boolean needsToDisplayLanguage() { return mNeedsToDisplayLanguage; } public Locale getInputLocale() { - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + if (mConfigUseSpacebarLanguageSwitcher) { return mLanguageSwitcher.getInputLocale(); } else { return mInputLocale; @@ -327,7 +329,7 @@ public class SubtypeSwitcher { } public String getInputLocaleStr() { - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + if (mConfigUseSpacebarLanguageSwitcher) { String inputLanguage = null; inputLanguage = mLanguageSwitcher.getInputLanguage(); // Should return system locale if there is no Language available. @@ -341,7 +343,7 @@ public class SubtypeSwitcher { } public String[] getEnabledLanguages() { - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + if (mConfigUseSpacebarLanguageSwitcher) { return mLanguageSwitcher.getEnabledLanguages(); } else { return mEnabledLanguagesOfCurrentInputMethod.toArray( @@ -350,7 +352,7 @@ public class SubtypeSwitcher { } public Locale getSystemLocale() { - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + if (mConfigUseSpacebarLanguageSwitcher) { return mLanguageSwitcher.getSystemLocale(); } else { return mSystemLocale; @@ -358,7 +360,7 @@ public class SubtypeSwitcher { } public boolean isSystemLanguageSameAsInputLanguage() { - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + if (mConfigUseSpacebarLanguageSwitcher) { return getSystemLocale().getLanguage().equalsIgnoreCase( getInputLocaleStr().substring(0, 2)); } else { @@ -366,25 +368,8 @@ public class SubtypeSwitcher { } } - public void onConfigurationChanged(Configuration conf) { - final Locale systemLocale = conf.locale; - // If system configuration was changed, update all parameters. - if (!TextUtils.equals(systemLocale.toString(), mSystemLocale.toString())) { - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { - // If the system locale changes and is different from the saved - // locale (mSystemLocale), then reload the input locale list from the - // latin ime settings (shared prefs) and reset the input locale - // to the first one. - mLanguageSwitcher.loadLocales(mPrefs); - mLanguageSwitcher.setSystemLocale(systemLocale); - } else { - updateAllParameters(); - } - } - } - public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + if (mConfigUseSpacebarLanguageSwitcher) { if (Settings.PREF_SELECTED_LANGUAGES.equals(key)) { mLanguageSwitcher.loadLocales(sharedPreferences); } @@ -438,7 +423,7 @@ public class SubtypeSwitcher { } ////////////////////////////////////// - // SpaceBar Language Switch support // + // Spacebar Language Switch support // ////////////////////////////////////// private LanguageSwitcher mLanguageSwitcher; @@ -466,7 +451,7 @@ public class SubtypeSwitcher { return Character.toUpperCase(s.charAt(0)) + s.substring(1); } - private void updateForSpaceBarLanguageSwitch() { + private void updateForSpacebarLanguageSwitch() { // We need to update mNeedsToDisplayLanguage in onStartInputView because // getEnabledKeyboardLocaleCount could have been changed. mNeedsToDisplayLanguage = !(getEnabledKeyboardLocaleCount() <= 1 @@ -479,7 +464,7 @@ public class SubtypeSwitcher { } public String getNextInputLanguageName() { - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + if (mConfigUseSpacebarLanguageSwitcher) { return getDisplayLanguage(mLanguageSwitcher.getNextInputLocale()); } else { return ""; @@ -487,7 +472,7 @@ public class SubtypeSwitcher { } public String getPreviousInputLanguageName() { - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + if (mConfigUseSpacebarLanguageSwitcher) { return getDisplayLanguage(mLanguageSwitcher.getPrevInputLocale()); } else { return ""; @@ -524,13 +509,13 @@ public class SubtypeSwitcher { } public void loadSettings() { - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + if (mConfigUseSpacebarLanguageSwitcher) { mLanguageSwitcher.loadLocales(mPrefs); } } public void toggleLanguage(boolean reset, boolean next) { - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + if (mConfigUseSpacebarLanguageSwitcher) { if (reset) { mLanguageSwitcher.reset(); } else { -- cgit v1.2.3-83-g751a From 34cee317d8c475b5200789143723f86ccd7f47da Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Fri, 14 Jan 2011 22:24:10 +0900 Subject: Fix froyo-ub-LatinImeGoogle compatibility Change-Id: I46fca4735d08552dfb414b2b302b4ed97ae96ab0 --- java/src/com/android/inputmethod/keyboard/MiniKeyboardBuilder.java | 2 +- java/src/com/android/inputmethod/latin/Settings.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/keyboard/MiniKeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/MiniKeyboardBuilder.java index 458a9eed4..c150baadb 100644 --- a/java/src/com/android/inputmethod/keyboard/MiniKeyboardBuilder.java +++ b/java/src/com/android/inputmethod/keyboard/MiniKeyboardBuilder.java @@ -71,7 +71,7 @@ public class MiniKeyboardBuilder { for (CharSequence popupSpec : popupCharacters) { final CharSequence label = PopupCharactersParser.getLabel(popupSpec.toString()); // If the label is single letter, minKeyWidth is enough to hold the label. - if (label.length() > 1) { + if (label != null && label.length() > 1) { if (paint == null) { paint = new Paint(); paint.setAntiAlias(true); diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index 8efeeda35..064a80fe1 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -182,7 +182,7 @@ public class Settings extends PreferenceActivity if (pref == mInputLanguageSelection) { final String action; if (android.os.Build.VERSION.SDK_INT - >= /* android.os.Build.VERSION_CODES.HONEYCOMB */ 10) { + >= /* android.os.Build.VERSION_CODES.HONEYCOMB */ 11) { action = "android.settings.INPUT_METHOD_AND_SUBTYPE_ENABLER"; } else { action = "com.android.inputmethod.latin.INPUT_LANGUAGE_SELECTION"; -- cgit v1.2.3-83-g751a From 67e08bb0fb922532d21e9a03c4e1627f62703935 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Sat, 15 Jan 2011 02:26:00 +0900 Subject: Invoke voice recognition certainly onStartInputView Bug: 3352347 Change-Id: I80763c0a48ebf1ecd23549d78269421ebb40d206 --- java/src/com/android/inputmethod/voice/VoiceIMEConnector.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java b/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java index d9528eb40..1ac4391f1 100644 --- a/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java +++ b/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java @@ -630,9 +630,15 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { public void onStartInputView(IBinder token) { // If IME is in voice mode, but still needs to show the voice warning dialog, // keep showing the warning. - if (mSubtypeSwitcher.isVoiceMode() && needsToShowWarningDialog() && token != null) { - showVoiceWarningDialog(false, token, false); + if (mSubtypeSwitcher.isVoiceMode() && token != null) { + if (needsToShowWarningDialog()) { + showVoiceWarningDialog(false, token, false); + } else { + startListening(false, token, false); + } } + // If we have no token, onAttachedToWindow will take care of showing dialog and start + // listening. } public void onAttachedToWindow() { -- cgit v1.2.3-83-g751a From f250c56a3830a8ed848d2f41cf7cc38ff9cacb58 Mon Sep 17 00:00:00 2001 From: satok Date: Mon, 17 Jan 2011 14:46:25 +0900 Subject: Allow implicitly enabled subtypes in subtype switcher. Change-Id: I30cd9df85fd1927ee9c3bfbe0574167d4953a765 --- java/src/com/android/inputmethod/latin/SubtypeSwitcher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index f04f3efe7..968495b8e 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -134,7 +134,7 @@ public class SubtypeSwitcher { private void updateEnabledSubtypes() { boolean foundCurrentSubtypeBecameDisabled = true; mAllEnabledSubtypesOfCurrentInputMethod = mImm.getEnabledInputMethodSubtypeList( - null, false); + null, true); mEnabledLanguagesOfCurrentInputMethod.clear(); mEnabledKeyboardSubtypesOfCurrentInputMethod.clear(); for (InputMethodSubtype ims: mAllEnabledSubtypesOfCurrentInputMethod) { -- cgit v1.2.3-83-g751a From da50e1e98dadc3733c615dfb8d87fe8b4688c782 Mon Sep 17 00:00:00 2001 From: Ken Wakasa Date: Mon, 17 Jan 2011 15:13:45 +0900 Subject: Fixes in close() in BinaryDictionary. Avoid using 'synchronized' in finalizer as well. bug: 3340837 Change-Id: I9b28f54e4490ecb844ba33a379f71b625e4246a2 --- .../inputmethod/latin/BinaryDictionary.java | 34 +++++++++++++++++----- .../inputmethod/latin/InputLanguageSelection.java | 2 +- .../src/com/android/inputmethod/latin/Suggest.java | 8 ++--- ..._android_inputmethod_latin_BinaryDictionary.cpp | 2 +- 4 files changed, 33 insertions(+), 13 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java index f7e67673a..813f7d32f 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java @@ -42,6 +42,7 @@ public class BinaryDictionary extends Dictionary { private static final int TYPED_LETTER_MULTIPLIER = 2; + private static final BinaryDictionary sInstance = new BinaryDictionary(); private int mDicTypeId; private int mNativeDict; private long mDictLength; @@ -59,16 +60,24 @@ public class BinaryDictionary extends Dictionary { } } + private BinaryDictionary() { + } + /** - * Create a dictionary from a raw resource file + * Initialize a dictionary from a raw resource file * @param context application context for reading resources * @param resId the resource containing the raw binary dictionary + * @return initialized instance of BinaryDictionary */ - public BinaryDictionary(Context context, int resId, int dicTypeId) { - if (resId != 0) { - loadDictionary(context, resId); + public static BinaryDictionary initDictionary(Context context, int resId, int dicTypeId) { + synchronized (sInstance) { + sInstance.closeInternal(); + if (resId != 0) { + sInstance.loadDictionary(context, resId); + sInstance.mDicTypeId = dicTypeId; + } } - mDicTypeId = dicTypeId; + return sInstance; } private native int openNative(String sourceDir, long dictOffset, long dictSize, @@ -104,6 +113,8 @@ public class BinaryDictionary extends Dictionary { @Override public void getBigrams(final WordComposer codes, final CharSequence previousWord, final WordCallback callback, int[] nextLettersFrequencies) { + if (mNativeDict == 0) return; + char[] chars = previousWord.toString().toCharArray(); Arrays.fill(mOutputChars_bigrams, (char) 0); Arrays.fill(mFrequencies_bigrams, 0); @@ -135,6 +146,8 @@ public class BinaryDictionary extends Dictionary { @Override public void getWords(final WordComposer codes, final WordCallback callback, int[] nextLettersFrequencies) { + if (mNativeDict == 0) return; + final int codesSize = codes.size(); // Won't deal with really long words. if (codesSize > MAX_WORD_LENGTH - 1) return; @@ -179,6 +192,10 @@ public class BinaryDictionary extends Dictionary { @Override public synchronized void close() { + closeInternal(); + } + + private void closeInternal() { if (mNativeDict != 0) { closeNative(mNativeDict); mNativeDict = 0; @@ -188,7 +205,10 @@ public class BinaryDictionary extends Dictionary { @Override protected void finalize() throws Throwable { - close(); - super.finalize(); + try { + closeInternal(); + } finally { + super.finalize(); + } } } diff --git a/java/src/com/android/inputmethod/latin/InputLanguageSelection.java b/java/src/com/android/inputmethod/latin/InputLanguageSelection.java index faee38eda..a9f2c2c22 100644 --- a/java/src/com/android/inputmethod/latin/InputLanguageSelection.java +++ b/java/src/com/android/inputmethod/latin/InputLanguageSelection.java @@ -107,7 +107,7 @@ public class InputLanguageSelection extends PreferenceActivity { res.updateConfiguration(conf, res.getDisplayMetrics()); int mainDicResId = LatinIME.getMainDictionaryResourceId(res); - BinaryDictionary bd = new BinaryDictionary(this, mainDicResId, Suggest.DIC_MAIN); + BinaryDictionary bd = BinaryDictionary.initDictionary(this, mainDicResId, Suggest.DIC_MAIN); // Is the dictionary larger than a placeholder? Arbitrarily chose a lower limit of // 4000-5000 words, whereas the LARGE_DICTIONARY is about 20000+ words. diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 9ea9c2f3e..a8454b23e 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -103,7 +103,7 @@ public class Suggest implements Dictionary.WordCallback { private int mCorrectionMode = CORRECTION_BASIC; public Suggest(Context context, int dictionaryResId) { - mMainDict = new BinaryDictionary(context, dictionaryResId, DIC_MAIN); + mMainDict = BinaryDictionary.initDictionary(context, dictionaryResId, DIC_MAIN); initPool(); } @@ -127,7 +127,7 @@ public class Suggest implements Dictionary.WordCallback { } public boolean hasMainDictionary() { - return mMainDict.getSize() > LARGE_DICTIONARY_THRESHOLD; + return mMainDict != null && mMainDict.getSize() > LARGE_DICTIONARY_THRESHOLD; } public int getApproxMaxWordLength() { @@ -276,7 +276,7 @@ public class Suggest implements Dictionary.WordCallback { mHaveCorrection = true; } } - mMainDict.getWords(wordComposer, this, mNextLettersFrequencies); + if (mMainDict != null) mMainDict.getWords(wordComposer, this, mNextLettersFrequencies); if ((mCorrectionMode == CORRECTION_FULL || mCorrectionMode == CORRECTION_FULL_BIGRAM) && mSuggestions.size() > 0 && mPriorities.length > 0) { // TODO: when the normalized score of the first suggestion is nearly equals to @@ -496,7 +496,7 @@ public class Suggest implements Dictionary.WordCallback { } public boolean isValidWord(final CharSequence word) { - if (word == null || word.length() == 0) { + if (word == null || word.length() == 0 || mMainDict == null) { return false; } return mMainDict.isValidWord(word) diff --git a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp index 6e4e97138..25580f4b1 100644 --- a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp +++ b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp @@ -89,7 +89,7 @@ static jint latinime_BinaryDictionary_open(JNIEnv *env, jobject object, return 0; } dictBuf = malloc(sizeof(char) * dictSize); - if (dictBuf == NULL) { + if (!dictBuf) { LOGE("DICT: Can't allocate memory region for dictionary. errno=%d", errno); return 0; } -- cgit v1.2.3-83-g751a From 66432cfc9b7680a653bcf19d0d4250db21155ece Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 17 Jan 2011 13:43:51 +0900 Subject: Place language name at center of spacebar if no space icon This change also leaves the language name as light grayed after fading out. Bug: 3290290 Change-Id: I71adf80c9a3b77d2fd34bca458845d85d55cbee7 --- java/res/values/config.xml | 1 + java/src/com/android/inputmethod/keyboard/LatinKeyboard.java | 8 +++++--- java/src/com/android/inputmethod/latin/LatinIME.java | 10 ++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) (limited to 'java/src') diff --git a/java/res/values/config.xml b/java/res/values/config.xml index adfec4c25..11b92e7c3 100644 --- a/java/res/values/config.xml +++ b/java/res/values/config.xml @@ -35,6 +35,7 @@ -1 50 + 15 0 10 0 diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java index db8934049..888375b93 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java @@ -70,7 +70,6 @@ public class LatinKeyboard extends Keyboard { private static final float SPACEBAR_POPUP_MIN_RATIO = 0.4f; // Height in space key the language name will be drawn. (proportional to space key height) public static final float SPACEBAR_LANGUAGE_BASELINE = 0.6f; - private static final float SPACEBAR_LANGUAGE_BASELINE_WITHOUT_ICON = 0.65f; // If the full language name needs to be smaller than this value to be drawn on space key, // its short language name will be used instead. private static final float MINIMUM_SCALE_OF_LANGUAGE_NAME = 0.8f; @@ -225,9 +224,12 @@ public class LatinKeyboard extends Keyboard { allowVariableTextSize); // Draw language text with shadow - final float baseline = height * (mSpaceIcon != null ? SPACEBAR_LANGUAGE_BASELINE - : SPACEBAR_LANGUAGE_BASELINE_WITHOUT_ICON); + // In case there is no space icon, we will place the language text at the center of + // spacebar. final float descent = paint.descent(); + final float textHeight = -paint.ascent() + descent; + final float baseline = (mSpaceIcon != null) ? height * SPACEBAR_LANGUAGE_BASELINE + : height / 2 + textHeight / 2; paint.setColor(getSpacebarTextColor(mSpacebarTextShadowColor, mSpacebarTextFadeFactor)); canvas.drawText(language, width / 2, baseline - descent - 1, paint); paint.setColor(getSpacebarTextColor(mSpacebarTextColor, mSpacebarTextFadeFactor)); diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index b93b07ffb..bea44eef2 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -154,6 +154,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private boolean mConfigSwipeDownDismissKeyboardEnabled; private int mConfigDelayBeforeFadeoutLanguageOnSpacebar; private int mConfigDurationOfFadeoutLanguageOnSpacebar; + private float mConfigFinalFadeoutFactorOfLanugageOnSpacebar; private int mCorrectionMode; private int mCommittedLength; @@ -267,13 +268,16 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen break; case MSG_FADEOUT_LANGUAGE_ON_SPACEBAR: if (inputView != null) - inputView.setSpacebarTextFadeFactor(0.5f, (LatinKeyboard)msg.obj); + inputView.setSpacebarTextFadeFactor( + (1.0f + mConfigFinalFadeoutFactorOfLanugageOnSpacebar) / 2, + (LatinKeyboard)msg.obj); sendMessageDelayed(obtainMessage(MSG_DISMISS_LANGUAGE_ON_SPACEBAR, msg.obj), mConfigDurationOfFadeoutLanguageOnSpacebar); break; case MSG_DISMISS_LANGUAGE_ON_SPACEBAR: if (inputView != null) - inputView.setSpacebarTextFadeFactor(0.0f, (LatinKeyboard)msg.obj); + inputView.setSpacebarTextFadeFactor( + mConfigFinalFadeoutFactorOfLanugageOnSpacebar, (LatinKeyboard)msg.obj); break; } } @@ -356,6 +360,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen R.integer.config_delay_before_fadeout_language_on_spacebar); mConfigDurationOfFadeoutLanguageOnSpacebar = res.getInteger( R.integer.config_duration_of_fadeout_language_on_spacebar); + mConfigFinalFadeoutFactorOfLanugageOnSpacebar = res.getInteger( + R.integer.config_final_fadeout_percentage_of_language_on_spacebar) / 100.0f; Utils.GCUtils.getInstance().reset(); boolean tryGC = true; -- cgit v1.2.3-83-g751a From dc64b138b5e3fb3706c0818d0a308fe6e36985b0 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 17 Jan 2011 17:52:15 +0900 Subject: Revert I432be8f7 partially This change reverts removing SubtypeSwitcher.onConfigurationChanged by careless in I432be8f7. Bug: 3290290 Change-Id: I796ea01877d61eb750dabdeb3fdbf87666646c56 --- java/src/com/android/inputmethod/latin/LatinIME.java | 1 + .../com/android/inputmethod/latin/SubtypeSwitcher.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index bea44eef2..4a78c2e7a 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -444,6 +444,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen @Override public void onConfigurationChanged(Configuration conf) { + mSubtypeSwitcher.onConfigurationChanged(conf); // If orientation changed while predicting, commit the change if (conf.orientation != mOrientation) { InputConnection ic = getCurrentInputConnection(); diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index 968495b8e..21c99fe09 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -370,6 +370,23 @@ public class SubtypeSwitcher { } } + public void onConfigurationChanged(Configuration conf) { + final Locale systemLocale = conf.locale; + // If system configuration was changed, update all parameters. + if (!TextUtils.equals(systemLocale.toString(), mSystemLocale.toString())) { + if (mConfigUseSpacebarLanguageSwitcher) { + // If the system locale changes and is different from the saved + // locale (mSystemLocale), then reload the input locale list from the + // latin ime settings (shared prefs) and reset the input locale + // to the first one. + mLanguageSwitcher.loadLocales(mPrefs); + mLanguageSwitcher.setSystemLocale(systemLocale); + } else { + updateAllParameters(); + } + } + } + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (mConfigUseSpacebarLanguageSwitcher) { if (Settings.PREF_SELECTED_LANGUAGES.equals(key)) { -- cgit v1.2.3-83-g751a From 8bec4aa912c193135bebacfc75dc15f06c5dce6e Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 17 Jan 2011 19:27:39 +0900 Subject: Fix voice key enable status has not been reflected to keyboard id Bug: 3355428 Change-Id: Id4e572357a7b5603e9a609b7e80b81d8e2c500f6 --- .../com/android/inputmethod/keyboard/KeyboardSwitcher.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 25ef847cd..42af8a8d6 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -174,12 +174,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha private void loadKeyboardInternal(int mode, int imeOptions, boolean voiceButtonEnabled, boolean voiceButtonOnPrimary, boolean isSymbols) { if (mInputView == null) return; - final Keyboard oldKeyboard = mInputView.getKeyboard(); - final KeyboardId id = getKeyboardId(mode, imeOptions, isSymbols); - if (oldKeyboard != null && oldKeyboard.mId.equals(id)) - return; - - mInputView.setPreviewEnabled(mInputMethodService.getPopupOn()); mMode = mode; mImeOptions = imeOptions; @@ -188,9 +182,15 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha mIsSymbols = isSymbols; // Update the settings key state because number of enabled IMEs could have been changed mHasSettingsKey = getSettingsKeyMode(mPrefs, mInputMethodService); - makeSymbolsKeyboardIds(); + final KeyboardId id = getKeyboardId(mode, imeOptions, isSymbols); + final Keyboard oldKeyboard = mInputView.getKeyboard(); + if (oldKeyboard != null && oldKeyboard.mId.equals(id)) + return; + + makeSymbolsKeyboardIds(); mCurrentId = id; + mInputView.setPreviewEnabled(mInputMethodService.getPopupOn()); mInputView.setKeyboard(getKeyboard(id)); } -- cgit v1.2.3-83-g751a From 504e8d5171edae36ec464a5e0c72cee22bb9ac4d Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 13 Jan 2011 17:14:27 +0900 Subject: Preserve punctuation character after canceling auto correction Bug: 3230708 Change-Id: I939ca19c9c08d9b79658261b1e654a66af5cc493 --- .../com/android/inputmethod/latin/LatinIME.java | 30 +++++++++++++++------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index b93b07ffb..f839a806c 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1132,14 +1132,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private void handleBackspace() { if (mVoiceConnector.logAndRevertVoiceInput()) return; - boolean deleteChar = false; - InputConnection ic = getCurrentInputConnection(); - if (ic == null) return; + final InputConnection ic = getCurrentInputConnection(); + if (ic == null) return; ic.beginBatchEdit(); mVoiceConnector.handleBackspace(); + boolean deleteChar = false; if (mHasValidSuggestions) { final int length = mComposing.length(); if (length > 0) { @@ -1157,12 +1157,15 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen deleteChar = true; } mHandler.postUpdateShiftKeyState(); + TextEntryState.backspace(); if (TextEntryState.getState() == TextEntryState.State.UNDO_COMMIT) { revertLastWord(deleteChar); ic.endBatchEdit(); return; - } else if (mEnteredText != null && sameAsTextBeforeCursor(ic, mEnteredText)) { + } + + if (mEnteredText != null && sameAsTextBeforeCursor(ic, mEnteredText)) { ic.deleteSurroundingText(mEnteredText.length(), 0); } else if (deleteChar) { if (mCandidateView != null && mCandidateView.dismissAddToDictionaryHint()) { @@ -1796,16 +1799,25 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final InputConnection ic = getCurrentInputConnection(); mHasValidSuggestions = true; mJustReverted = true; + final CharSequence punctuation = ic.getTextBeforeCursor(1, 0); if (deleteChar) ic.deleteSurroundingText(1, 0); int toDelete = mCommittedLength; - CharSequence toTheLeft = ic.getTextBeforeCursor(mCommittedLength, 0); - if (toTheLeft != null && toTheLeft.length() > 0 - && isWordSeparator(toTheLeft.charAt(0))) { + final CharSequence toTheLeft = ic.getTextBeforeCursor(mCommittedLength, 0); + if (!TextUtils.isEmpty(toTheLeft) && isWordSeparator(toTheLeft.charAt(0))) { toDelete--; } ic.deleteSurroundingText(toDelete, 0); - ic.setComposingText(mComposing, 1); - TextEntryState.backspace(); + if (deleteChar) { + ic.commitText(mComposing, 1); + TextEntryState.acceptedTyped(mComposing); + if (!TextUtils.isEmpty(punctuation) && isWordSeparator(punctuation.charAt(0))) { + ic.commitText(punctuation, 1); + TextEntryState.typedCharacter(punctuation.charAt(0), true); + } + } else { + ic.setComposingText(mComposing, 1); + TextEntryState.backspace(); + } mHandler.postUpdateSuggestions(); } else { sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL); -- cgit v1.2.3-83-g751a From 04f815eca4088ece879b1d9fb482bb7a342bfe4f Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Sat, 15 Jan 2011 08:44:25 +0900 Subject: Make sure that keyboard is not displayed when voice mode Bug: 3352347 Change-Id: I43cf5159f8bdcf2bc2c9a48662ea44a43ad4e25d --- .../android/inputmethod/keyboard/KeyboardView.java | 10 +-- .../com/android/inputmethod/latin/LatinIME.java | 2 +- .../android/inputmethod/voice/RecognitionView.java | 4 +- .../inputmethod/voice/VoiceIMEConnector.java | 97 +++++++++++----------- 4 files changed, 53 insertions(+), 60 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index a952acf8b..b1815a146 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -298,8 +298,6 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.KeyboardView, defStyle, R.style.KeyboardView); - LayoutInflater inflate = - (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); int previewLayout = 0; int keyTextSize = 0; @@ -365,7 +363,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { mPreviewPopup = new PopupWindow(context); if (previewLayout != 0) { - mPreviewText = (TextView) inflate.inflate(previewLayout, null); + mPreviewText = (TextView) LayoutInflater.from(context).inflate(previewLayout, null); mPreviewTextSizeLarge = (int) res.getDimension(R.dimen.key_preview_text_size_large); mPreviewPopup.setContentView(mPreviewText); mPreviewPopup.setBackgroundDrawable(null); @@ -1080,9 +1078,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { private View inflateMiniKeyboardContainer(Key popupKey) { int popupKeyboardResId = mKeyboard.getPopupKeyboardResId(); - LayoutInflater inflater = (LayoutInflater)getContext().getSystemService( - Context.LAYOUT_INFLATER_SERVICE); - View container = inflater.inflate(mPopupLayout, null); + View container = LayoutInflater.from(getContext()).inflate(mPopupLayout, null); if (container == null) throw new NullPointerException(); @@ -1408,7 +1404,9 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { dismissPopupKeyboard(); mBuffer = null; mCanvas = null; + mKeyboard = null; mMiniKeyboardCache.clear(); + requestLayout(); } @Override diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 4a78c2e7a..e3b4072c4 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -615,7 +615,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen checkReCorrectionOnStart(); inputView.setForeground(true); - mVoiceConnector.onStartInputView(mKeyboardSwitcher.getInputView().getWindowToken()); + mVoiceConnector.onStartInputView(inputView.getWindowToken()); if (TRACE) Debug.startMethodTracing("/data/trace/latinime"); } diff --git a/java/src/com/android/inputmethod/voice/RecognitionView.java b/java/src/com/android/inputmethod/voice/RecognitionView.java index 12d0de852..d6d0721e2 100644 --- a/java/src/com/android/inputmethod/voice/RecognitionView.java +++ b/java/src/com/android/inputmethod/voice/RecognitionView.java @@ -103,9 +103,7 @@ public class RecognitionView { public RecognitionView(Context context, OnClickListener clickListener) { mUiHandler = new Handler(); - LayoutInflater inflater = (LayoutInflater) context.getSystemService( - Context.LAYOUT_INFLATER_SERVICE); - mView = inflater.inflate(R.layout.recognition_status, null); + mView = LayoutInflater.from(context).inflate(R.layout.recognition_status, null); ContentResolver cr = context.getContentResolver(); mMinMicrophoneLevel = SettingsUtil.getSettingsFloat( cr, SettingsUtil.LATIN_IME_MIN_MICROPHONE_LEVEL, 15.f); diff --git a/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java b/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java index 1ac4391f1..715486147 100644 --- a/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java +++ b/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java @@ -16,6 +16,7 @@ package com.android.inputmethod.voice; +import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.latin.EditingUtils; import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinIME.UIHandler; @@ -91,7 +92,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { private boolean mVoiceInputHighlighted; private InputMethodManager mImm; - private LatinIME mContext; + private LatinIME mService; private AlertDialog mVoiceWarningDialog; private VoiceInput mVoiceInput; private final VoiceResults mVoiceResults = new VoiceResults(); @@ -111,21 +112,19 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { return sInstance; } - private void initInternal(LatinIME context, SharedPreferences prefs, UIHandler h) { - mContext = context; + private void initInternal(LatinIME service, SharedPreferences prefs, UIHandler h) { + mService = service; mHandler = h; - mImm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); + mImm = (InputMethodManager) service.getSystemService(Context.INPUT_METHOD_SERVICE); mSubtypeSwitcher = SubtypeSwitcher.getInstance(); if (VOICE_INSTALLED) { - mVoiceInput = new VoiceInput(context, this); - mHints = new Hints(context, prefs, new Hints.Display() { + mVoiceInput = new VoiceInput(service, this); + mHints = new Hints(service, prefs, new Hints.Display() { @Override public void showHint(int viewResource) { - LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( - Context.LAYOUT_INFLATER_SERVICE); - View view = inflater.inflate(viewResource, null); - mContext.setCandidatesView(view); - mContext.setCandidatesViewShown(true); + View view = LayoutInflater.from(mService).inflate(viewResource, null); + mService.setCandidatesView(view); + mService.setCandidatesViewShown(true); mIsShowingHint = true; } }); @@ -161,7 +160,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { mVoiceInput.flushAllTextModificationCounters(); // send this intent AFTER logging any prior aggregated edits. mVoiceInput.logTextModifiedByChooseSuggestion(suggestion.toString(), index, - wordSeparators, mContext.getCurrentInputConnection()); + wordSeparators, mService.getCurrentInputConnection()); } } @@ -170,7 +169,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { if (mVoiceWarningDialog != null && mVoiceWarningDialog.isShowing()) { return; } - AlertDialog.Builder builder = new AlertDialog.Builder(mContext); + AlertDialog.Builder builder = new AlertDialog.Builder(mService); builder.setCancelable(true); builder.setIcon(R.drawable.ic_mic_dialog); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @@ -199,13 +198,13 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { final CharSequence message; if (mLocaleSupportedForVoiceInput) { message = TextUtils.concat( - mContext.getText(R.string.voice_warning_may_not_understand), "\n\n", - mContext.getText(R.string.voice_warning_how_to_turn_off)); + mService.getText(R.string.voice_warning_may_not_understand), "\n\n", + mService.getText(R.string.voice_warning_how_to_turn_off)); } else { message = TextUtils.concat( - mContext.getText(R.string.voice_warning_locale_not_supported), "\n\n", - mContext.getText(R.string.voice_warning_may_not_understand), "\n\n", - mContext.getText(R.string.voice_warning_how_to_turn_off)); + mService.getText(R.string.voice_warning_locale_not_supported), "\n\n", + mService.getText(R.string.voice_warning_may_not_understand), "\n\n", + mService.getText(R.string.voice_warning_how_to_turn_off)); } builder.setMessage(message); @@ -296,7 +295,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { } public void showPunctuationHintIfNecessary() { - InputConnection ic = mContext.getCurrentInputConnection(); + InputConnection ic = mService.getCurrentInputConnection(); if (!mImmediatelyAfterVoiceInput && mAfterVoiceInput && ic != null) { if (mHints.showPunctuationHintIfNecessary(ic)) { mVoiceInput.logPunctuationHintDisplayed(); @@ -364,17 +363,17 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { } private void revertVoiceInput() { - InputConnection ic = mContext.getCurrentInputConnection(); + InputConnection ic = mService.getCurrentInputConnection(); if (ic != null) ic.commitText("", 1); - mContext.updateSuggestions(); + mService.updateSuggestions(); mVoiceInputHighlighted = false; } public void commitVoiceInput() { if (VOICE_INSTALLED && mVoiceInputHighlighted) { - InputConnection ic = mContext.getCurrentInputConnection(); + InputConnection ic = mService.getCurrentInputConnection(); if (ic != null) ic.finishComposingText(); - mContext.updateSuggestions(); + mService.updateSuggestions(); mVoiceInputHighlighted = false; } } @@ -394,7 +393,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { if (mShowingVoiceSuggestions) { // Retain the replaced word in the alternatives array. String wordToBeReplaced = EditingUtils.getWordAtCursor( - mContext.getCurrentInputConnection(), wordSeparators); + mService.getCurrentInputConnection(), wordSeparators); if (!mWordToSuggestions.containsKey(wordToBeReplaced)) { wordToBeReplaced = wordToBeReplaced.toLowerCase(); } @@ -438,8 +437,8 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { builder.addWords(suggestions); } builder.setTypedWordValid(true).setHasMinimalSuggestion(true); - mContext.setSuggestions(builder.build()); - mContext.setCandidatesViewShown(true); + mService.setSuggestions(builder.build()); + mService.setCandidatesViewShown(true); return true; } return false; @@ -486,15 +485,15 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { mAfterVoiceInput = true; mImmediatelyAfterVoiceInput = true; - InputConnection ic = mContext.getCurrentInputConnection(); - if (!mContext.isFullscreenMode()) { + InputConnection ic = mService.getCurrentInputConnection(); + if (!mService.isFullscreenMode()) { // Start listening for updates to the text from typing, etc. if (ic != null) { ExtractedTextRequest req = new ExtractedTextRequest(); ic.getExtractedText(req, InputConnection.GET_EXTRACTED_TEXT_MONITOR); } } - mContext.vibrate(); + mService.vibrate(); final List nBest = new ArrayList(); for (String c : mVoiceResults.candidates) { @@ -511,7 +510,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { mHints.registerVoiceResult(bestResult); if (ic != null) ic.beginBatchEdit(); // To avoid extra updates on committing older text - mContext.commitTyped(ic); + mService.commitTyped(ic); EditingUtils.appendText(ic, bestResult); if (ic != null) ic.endBatchEdit(); @@ -525,15 +524,15 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { mHandler.post(new Runnable() { @Override public void run() { - mContext.setCandidatesViewShown(false); + mService.setCandidatesViewShown(false); mRecognizing = true; View v = mVoiceInput.getView(); ViewParent p = v.getParent(); if (p != null && p instanceof ViewGroup) { ((ViewGroup)p).removeView(v); } - mContext.setInputView(v); - mContext.updateInputViewShown(); + mService.setInputView(v); + mService.updateInputViewShown(); if (configChanged) { mVoiceInput.onConfigurationChanged(); } @@ -541,7 +540,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { } private void switchToLastInputMethod() { - IBinder token = mContext.getWindow().getWindow().getAttributes().token; + IBinder token = mService.getWindow().getWindow().getAttributes().token; mImm.switchToLastInputMethod(token); } @@ -553,7 +552,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { // The user has started a voice input, so remember that in the // future (so we don't show the warning dialog after the first run). SharedPreferences.Editor editor = - PreferenceManager.getDefaultSharedPreferences(mContext).edit(); + PreferenceManager.getDefaultSharedPreferences(mService).edit(); editor.putBoolean(PREF_HAS_USED_VOICE_INPUT, true); SharedPreferencesCompat.apply(editor); mHasUsedVoiceInput = true; @@ -563,14 +562,14 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { // The user has started a voice input from an unsupported locale, so remember that // in the future (so we don't show the warning dialog the next time they do this). SharedPreferences.Editor editor = - PreferenceManager.getDefaultSharedPreferences(mContext).edit(); + PreferenceManager.getDefaultSharedPreferences(mService).edit(); editor.putBoolean(PREF_HAS_USED_VOICE_INPUT_UNSUPPORTED_LOCALE, true); SharedPreferencesCompat.apply(editor); mHasUsedVoiceInputUnsupportedLocale = true; } // Clear N-best suggestions - mContext.clearSuggestions(); + mService.clearSuggestions(); FieldContext context = makeFieldContext(); mVoiceInput.startListening(context, swipe); @@ -579,7 +578,6 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { public void startListening(final boolean swipe, IBinder token, final boolean configurationChanging) { - // TODO: remove swipe which is no longer used. if (VOICE_INSTALLED) { if (needsToShowWarningDialog()) { // Calls reallyStartListening if user clicks OK, does nothing if user clicks Cancel. @@ -601,7 +599,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { return ENABLE_VOICE_BUTTON && fieldCanDoVoice(fieldContext) && !(attribute != null && IME_OPTION_NO_MICROPHONE.equals(attribute.privateImeOptions)) - && SpeechRecognizer.isRecognitionAvailable(mContext); + && SpeechRecognizer.isRecognitionAvailable(mService); } public void loadSettings(EditorInfo attribute, SharedPreferences sp) { @@ -614,10 +612,10 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { if (VOICE_INSTALLED) { final String voiceMode = sp.getString(PREF_VOICE_MODE, - mContext.getString(R.string.voice_mode_main)); - mVoiceButtonEnabled = !voiceMode.equals(mContext.getString(R.string.voice_mode_off)) + mService.getString(R.string.voice_mode_main)); + mVoiceButtonEnabled = !voiceMode.equals(mService.getString(R.string.voice_mode_off)) && shouldShowVoiceButton(makeFieldContext(), attribute); - mVoiceButtonOnPrimary = voiceMode.equals(mContext.getString(R.string.voice_mode_main)); + mVoiceButtonOnPrimary = voiceMode.equals(mService.getString(R.string.voice_mode_main)); } } @@ -631,11 +629,10 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { // If IME is in voice mode, but still needs to show the voice warning dialog, // keep showing the warning. if (mSubtypeSwitcher.isVoiceMode() && token != null) { - if (needsToShowWarningDialog()) { - showVoiceWarningDialog(false, token, false); - } else { - startListening(false, token, false); - } + // Close keyboard view if it is been shown. + if (KeyboardSwitcher.getInstance().isInputViewShown()) + KeyboardSwitcher.getInstance().getInputView().closing(); + startListening(false, token, false); } // If we have no token, onAttachedToWindow will take care of showing dialog and start // listening. @@ -668,7 +665,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { // onCurrentInputMethodSubtypeChanged() will be called first. LatinIME will know // that it's in keyboard mode and SubtypeSwitcher will call onCancelVoice(). mRecognizing = false; - mContext.switchToKeyboardView(); + mService.switchToKeyboardView(); } } } @@ -686,8 +683,8 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { public FieldContext makeFieldContext() { SubtypeSwitcher switcher = SubtypeSwitcher.getInstance(); - return new FieldContext(mContext.getCurrentInputConnection(), - mContext.getCurrentInputEditorInfo(), switcher.getInputLocaleStr(), + return new FieldContext(mService.getCurrentInputConnection(), + mService.getCurrentInputEditorInfo(), switcher.getInputLocaleStr(), switcher.getEnabledLanguages()); } -- cgit v1.2.3-83-g751a From d5a6b910e83de6dea3c5813cbf5e219abaccdf8a Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 17 Jan 2011 23:47:52 +0900 Subject: Purge keyboard only when voice input will be invoked This change also draws the language name in light gray on spacebar without fading out even when the keyboard locale has not been changed. Bug: 3362369 Bug: 3361915 Change-Id: I66538b03ce2e48c3441091319d0377176f8118ec --- .../android/inputmethod/keyboard/KeyboardSwitcher.java | 7 ++++--- .../com/android/inputmethod/keyboard/KeyboardView.java | 6 +++++- java/src/com/android/inputmethod/latin/LatinIME.java | 15 ++++++++------- .../com/android/inputmethod/voice/VoiceIMEConnector.java | 2 +- 4 files changed, 18 insertions(+), 12 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 42af8a8d6..68d3ccd84 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -161,9 +161,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha final Keyboard oldKeyboard = mInputView.getKeyboard(); loadKeyboardInternal(mode, imeOptions, voiceKeyEnabled, voiceButtonOnPrimary, false); final Keyboard newKeyboard = mInputView.getKeyboard(); - if (newKeyboard.isAlphaKeyboard() && (oldKeyboard == null - || !newKeyboard.mId.mLocale.equals(oldKeyboard.mId.mLocale))) { - mInputMethodService.mHandler.startDisplayLanguageOnSpacebar(); + if (newKeyboard.isAlphaKeyboard()) { + final boolean localeChanged = (oldKeyboard == null) + || !newKeyboard.mId.mLocale.equals(oldKeyboard.mId.mLocale); + mInputMethodService.mHandler.startDisplayLanguageOnSpacebar(localeChanged); } } catch (RuntimeException e) { Log.w(TAG, e); diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index b1815a146..766fdf0e6 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -1404,11 +1404,15 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { dismissPopupKeyboard(); mBuffer = null; mCanvas = null; - mKeyboard = null; mMiniKeyboardCache.clear(); requestLayout(); } + public void purgeKeyboardAndClosing() { + mKeyboard = null; + closing(); + } + @Override public void onDetachedFromWindow() { super.onDetachedFromWindow(); diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 5766f6b38..cd4143e78 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -154,7 +154,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private boolean mConfigSwipeDownDismissKeyboardEnabled; private int mConfigDelayBeforeFadeoutLanguageOnSpacebar; private int mConfigDurationOfFadeoutLanguageOnSpacebar; - private float mConfigFinalFadeoutFactorOfLanugageOnSpacebar; + private float mConfigFinalFadeoutFactorOfLanguageOnSpacebar; private int mCorrectionMode; private int mCommittedLength; @@ -269,7 +269,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen case MSG_FADEOUT_LANGUAGE_ON_SPACEBAR: if (inputView != null) inputView.setSpacebarTextFadeFactor( - (1.0f + mConfigFinalFadeoutFactorOfLanugageOnSpacebar) / 2, + (1.0f + mConfigFinalFadeoutFactorOfLanguageOnSpacebar) / 2, (LatinKeyboard)msg.obj); sendMessageDelayed(obtainMessage(MSG_DISMISS_LANGUAGE_ON_SPACEBAR, msg.obj), mConfigDurationOfFadeoutLanguageOnSpacebar); @@ -277,7 +277,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen case MSG_DISMISS_LANGUAGE_ON_SPACEBAR: if (inputView != null) inputView.setSpacebarTextFadeFactor( - mConfigFinalFadeoutFactorOfLanugageOnSpacebar, (LatinKeyboard)msg.obj); + mConfigFinalFadeoutFactorOfLanguageOnSpacebar, (LatinKeyboard)msg.obj); break; } } @@ -318,7 +318,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen sendMessage(obtainMessage(MSG_VOICE_RESULTS)); } - public void startDisplayLanguageOnSpacebar() { + public void startDisplayLanguageOnSpacebar(boolean localeChanged) { removeMessages(MSG_FADEOUT_LANGUAGE_ON_SPACEBAR); removeMessages(MSG_DISMISS_LANGUAGE_ON_SPACEBAR); final LatinKeyboardView inputView = mKeyboardSwitcher.getInputView(); @@ -326,9 +326,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final LatinKeyboard keyboard = inputView.getLatinKeyboard(); // The language is never displayed when the delay is zero. if (mConfigDelayBeforeFadeoutLanguageOnSpacebar != 0) - inputView.setSpacebarTextFadeFactor(1.0f, keyboard); + inputView.setSpacebarTextFadeFactor(localeChanged ? 1.0f + : mConfigFinalFadeoutFactorOfLanguageOnSpacebar, keyboard); // The language is always displayed when the delay is negative. - if (mConfigDelayBeforeFadeoutLanguageOnSpacebar > 0) { + if (localeChanged && mConfigDelayBeforeFadeoutLanguageOnSpacebar > 0) { sendMessageDelayed(obtainMessage(MSG_FADEOUT_LANGUAGE_ON_SPACEBAR, keyboard), mConfigDelayBeforeFadeoutLanguageOnSpacebar); } @@ -360,7 +361,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen R.integer.config_delay_before_fadeout_language_on_spacebar); mConfigDurationOfFadeoutLanguageOnSpacebar = res.getInteger( R.integer.config_duration_of_fadeout_language_on_spacebar); - mConfigFinalFadeoutFactorOfLanugageOnSpacebar = res.getInteger( + mConfigFinalFadeoutFactorOfLanguageOnSpacebar = res.getInteger( R.integer.config_final_fadeout_percentage_of_language_on_spacebar) / 100.0f; Utils.GCUtils.getInstance().reset(); diff --git a/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java b/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java index 715486147..9a6c3a83a 100644 --- a/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java +++ b/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java @@ -631,7 +631,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { if (mSubtypeSwitcher.isVoiceMode() && token != null) { // Close keyboard view if it is been shown. if (KeyboardSwitcher.getInstance().isInputViewShown()) - KeyboardSwitcher.getInstance().getInputView().closing(); + KeyboardSwitcher.getInstance().getInputView().purgeKeyboardAndClosing(); startListening(false, token, false); } // If we have no token, onAttachedToWindow will take care of showing dialog and start -- cgit v1.2.3-83-g751a From 7766340cac9b79408c307e05460e30d7aca899e0 Mon Sep 17 00:00:00 2001 From: satok Date: Mon, 17 Jan 2011 23:26:18 +0900 Subject: Add debug log for subtypes. Change-Id: I7941adeab3357db1ceb7bc0c9c01a01d6ac9cf98 --- java/src/com/android/inputmethod/latin/SubtypeSwitcher.java | 1 + 1 file changed, 1 insertion(+) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index 21c99fe09..b765fad3f 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -155,6 +155,7 @@ public class SubtypeSwitcher { && mIsSystemLanguageSameAsInputLanguage); if (foundCurrentSubtypeBecameDisabled) { if (DBG) { + Log.w(TAG, "Current subtype: " + mInputLocaleStr + ", " + mMode); Log.w(TAG, "Last subtype was disabled. Update to the current one."); } updateSubtype(mImm.getCurrentInputMethodSubtype()); -- cgit v1.2.3-83-g751a From 6c381b38cc19cc8174a7620e5726314a79ed7e43 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 18 Jan 2011 15:20:35 +0900 Subject: Remove the keyboard popup option by default. Add an option to mask the sound on keypress preference, and make it false on xlarge terminals by default. bug: 3282448 Change-Id: I747272d9edf854dc229aa620836cfa35a437d13f --- java/res/values-xlarge/config.xml | 1 + java/res/values/config.xml | 1 + java/src/com/android/inputmethod/latin/Settings.java | 6 ++++++ 3 files changed, 8 insertions(+) (limited to 'java/src') diff --git a/java/res/values-xlarge/config.xml b/java/res/values-xlarge/config.xml index 410b5e19e..912971793 100644 --- a/java/res/values-xlarge/config.xml +++ b/java/res/values-xlarge/config.xml @@ -22,6 +22,7 @@ false false false + false false false false diff --git a/java/res/values/config.xml b/java/res/values/config.xml index 11b92e7c3..e5821075e 100644 --- a/java/res/values/config.xml +++ b/java/res/values/config.xml @@ -25,6 +25,7 @@ true true true + true true true true diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index 064a80fe1..5db63b719 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -134,6 +134,12 @@ public class Settings extends PreferenceActivity if (!showSubtypeSettings) { getPreferenceScreen().removePreference(findPreference(PREF_SUBTYPES)); } + + final boolean showPopupOption = getResources().getBoolean( + R.bool.config_enable_show_popup_on_keypress_option); + if (!showPopupOption) { + getPreferenceScreen().removePreference(findPreference(PREF_POPUP_ON)); + } } @Override -- cgit v1.2.3-83-g751a From fd7d814c81132bdd59146a39dd668532f9514cd1 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 18 Jan 2011 17:45:22 +0900 Subject: Simplify latin IME settings page. Do not show the recorrection option on xlarge terminals, and make it true by default. Also, bring the Auto-capitalization at the top of the settings page. Issue: 3282448 Change-Id: I51a9ae6c7e496be2970107277f0a4ac65b12821e --- java/res/values-xlarge/config.xml | 1 + java/res/values/config.xml | 1 + java/res/xml/prefs.xml | 14 +++++++------- java/src/com/android/inputmethod/latin/LatinIME.java | 12 ++++++++++-- java/src/com/android/inputmethod/latin/Settings.java | 6 ++++++ 5 files changed, 25 insertions(+), 9 deletions(-) (limited to 'java/src') diff --git a/java/res/values-xlarge/config.xml b/java/res/values-xlarge/config.xml index 912971793..d6864608d 100644 --- a/java/res/values-xlarge/config.xml +++ b/java/res/values-xlarge/config.xml @@ -23,6 +23,7 @@ false false false + false false false false diff --git a/java/res/values/config.xml b/java/res/values/config.xml index e5821075e..a523635ca 100644 --- a/java/res/values/config.xml +++ b/java/res/values/config.xml @@ -26,6 +26,7 @@ true true true + true true true true diff --git a/java/res/xml/prefs.xml b/java/res/xml/prefs.xml index 9c780cb2d..4bcb1d7d8 100644 --- a/java/res/xml/prefs.xml +++ b/java/res/xml/prefs.xml @@ -18,6 +18,13 @@ android:title="@string/english_ime_settings" android:key="english_ime_settings"> + + - - Date: Tue, 18 Jan 2011 15:48:29 +0900 Subject: Clear composing text when the auto-corrected word is reverted Bug: 3363133 Change-Id: Ib7582ad354ba16eb8ebc9f0b4f51c8ec3790f578 --- java/src/com/android/inputmethod/latin/LatinIME.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index cd4143e78..93d5ef616 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1805,7 +1805,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final int length = mComposing.length(); if (!mHasValidSuggestions && length > 0) { final InputConnection ic = getCurrentInputConnection(); - mHasValidSuggestions = true; mJustReverted = true; final CharSequence punctuation = ic.getTextBeforeCursor(1, 0); if (deleteChar) ic.deleteSurroundingText(1, 0); @@ -1815,14 +1814,19 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen toDelete--; } ic.deleteSurroundingText(toDelete, 0); - if (deleteChar) { + // Re-insert punctuation only when the deleted character was word separator and the + // composing text wasn't equal to the auto-corrected text. + if (deleteChar + && !TextUtils.isEmpty(punctuation) && isWordSeparator(punctuation.charAt(0)) + && !TextUtils.equals(mComposing, toTheLeft)) { ic.commitText(mComposing, 1); TextEntryState.acceptedTyped(mComposing); - if (!TextUtils.isEmpty(punctuation) && isWordSeparator(punctuation.charAt(0))) { - ic.commitText(punctuation, 1); - TextEntryState.typedCharacter(punctuation.charAt(0), true); - } + ic.commitText(punctuation, 1); + TextEntryState.typedCharacter(punctuation.charAt(0), true); + // Clear composing text + mComposing.setLength(0); } else { + mHasValidSuggestions = true; ic.setComposingText(mComposing, 1); TextEntryState.backspace(); } -- cgit v1.2.3-83-g751a From c1c4ee6b3a8c3ec42edefe42fd183f3cbf67b0bf Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 18 Jan 2011 15:28:21 +0900 Subject: Load keyboard correctly when subtype has been changed to keyboard Bug: 3299191 Change-Id: I5d75898aca5de25d9955efac52979097e529990b --- .../com/android/inputmethod/latin/LatinIME.java | 123 +++++++++++---------- .../android/inputmethod/latin/SubtypeSwitcher.java | 6 +- 2 files changed, 68 insertions(+), 61 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index cd4143e78..02ad5bcef 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -133,14 +133,17 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private Resources mResources; private SharedPreferences mPrefs; + // These variables are initialized according to the {@link EditorInfo#inputType}. + private boolean mAutoSpace; + private boolean mInputTypeNoAutoCorrect; + private boolean mIsSettingsSuggestionStripOn; + private boolean mApplicationSpecifiedCompletionOn; + private final StringBuilder mComposing = new StringBuilder(); private WordComposer mWord = new WordComposer(); private CharSequence mBestWord; private boolean mHasValidSuggestions; - private boolean mIsSettingsSuggestionStripOn; - private boolean mApplicationSpecifiedCompletionOn; private boolean mHasDictionary; - private boolean mAutoSpace; private boolean mJustAddedAutoSpace; private boolean mAutoCorrectEnabled; private boolean mReCorrectionEnabled; @@ -164,9 +167,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private int mLastSelectionEnd; private SuggestedWords mSuggestPuncList; - // Input type is such that we should not auto-correct - private boolean mInputTypeNoAutoCorrect; - // Indicates whether the suggestion strip is to be on in landscape private boolean mJustAccepted; private boolean mJustReverted; @@ -507,24 +507,62 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (mRefreshKeyboardRequired) { mRefreshKeyboardRequired = false; - onKeyboardLanguageChanged(); + onRefreshKeyboard(); } TextEntryState.newSession(this); - // Most such things we decide below in the switch statement, but we need to know - // now whether this is a password text field, because we need to know now (before - // the switch statement) whether we want to enable the voice button. - int variation = attribute.inputType & InputType.TYPE_MASK_VARIATION; - mVoiceConnector.resetVoiceStates(isPasswordVariation(variation)); + // Most such things we decide below in initializeInputAttributesAndGetMode, but we need to + // know now whether this is a password text field, because we need to know now whether we + // want to enable the voice button. + mVoiceConnector.resetVoiceStates(isPasswordVariation( + attribute.inputType & InputType.TYPE_MASK_VARIATION)); + + final int mode = initializeInputAttributesAndGetMode(attribute.inputType); + + inputView.closing(); + mEnteredText = null; + mComposing.setLength(0); + mHasValidSuggestions = false; + mDeleteCount = 0; + mJustAddedAutoSpace = false; + + loadSettings(attribute); + if (mSubtypeSwitcher.isKeyboardMode()) { + switcher.loadKeyboard(mode, attribute.imeOptions, + mVoiceConnector.isVoiceButtonEnabled(), + mVoiceConnector.isVoiceButtonOnPrimary()); + switcher.updateShiftState(); + } + + setCandidatesViewShownInternal(isCandidateStripVisible(), + false /* needsInputViewShown */ ); + // Delay updating suggestions because keyboard input view may not be shown at this point. + mHandler.postUpdateSuggestions(); + + updateCorrectionMode(); + + inputView.setPreviewEnabled(mPopupOn); + inputView.setProximityCorrectionEnabled(true); + // If we just entered a text field, maybe it has some old text that requires correction + checkReCorrectionOnStart(); + inputView.setForeground(true); + + mVoiceConnector.onStartInputView(inputView.getWindowToken()); + + if (TRACE) Debug.startMethodTracing("/data/trace/latinime"); + } + + private int initializeInputAttributesAndGetMode(int inputType) { + final int variation = inputType & InputType.TYPE_MASK_VARIATION; + mAutoSpace = false; mInputTypeNoAutoCorrect = false; mIsSettingsSuggestionStripOn = false; mApplicationSpecifiedCompletionOn = false; mApplicationSpecifiedCompletions = null; - mEnteredText = null; final int mode; - switch (attribute.inputType & InputType.TYPE_MASK_CLASS) { + switch (inputType & InputType.TYPE_MASK_CLASS) { case InputType.TYPE_CLASS_NUMBER: case InputType.TYPE_CLASS_DATETIME: mode = KeyboardId.MODE_NUMBER; @@ -559,7 +597,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mode = KeyboardId.MODE_WEB; // If it's a browser edit field and auto correct is not ON explicitly, then // disable auto correction, but keep suggestions on. - if ((attribute.inputType & InputType.TYPE_TEXT_FLAG_AUTO_CORRECT) == 0) { + if ((inputType & InputType.TYPE_TEXT_FLAG_AUTO_CORRECT) == 0) { mInputTypeNoAutoCorrect = true; } } else { @@ -567,16 +605,16 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } // If NO_SUGGESTIONS is set, don't do prediction. - if ((attribute.inputType & InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS) != 0) { + if ((inputType & InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS) != 0) { mIsSettingsSuggestionStripOn = false; mInputTypeNoAutoCorrect = true; } // If it's not multiline and the autoCorrect flag is not set, then don't correct - if ((attribute.inputType & InputType.TYPE_TEXT_FLAG_AUTO_CORRECT) == 0 && - (attribute.inputType & InputType.TYPE_TEXT_FLAG_MULTI_LINE) == 0) { + if ((inputType & InputType.TYPE_TEXT_FLAG_AUTO_CORRECT) == 0 && + (inputType & InputType.TYPE_TEXT_FLAG_MULTI_LINE) == 0) { mInputTypeNoAutoCorrect = true; } - if ((attribute.inputType & InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE) != 0) { + if ((inputType & InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE) != 0) { mIsSettingsSuggestionStripOn = false; mApplicationSpecifiedCompletionOn = isFullscreenMode(); } @@ -585,40 +623,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mode = KeyboardId.MODE_TEXT; break; } - inputView.closing(); - mComposing.setLength(0); - mHasValidSuggestions = false; - mDeleteCount = 0; - mJustAddedAutoSpace = false; - - loadSettings(attribute); - if (mSubtypeSwitcher.isKeyboardMode()) { - switcher.loadKeyboard(mode, attribute.imeOptions, - mVoiceConnector.isVoiceButtonEnabled(), - mVoiceConnector.isVoiceButtonOnPrimary()); - switcher.updateShiftState(); - } - - setCandidatesViewShownInternal(isCandidateStripVisible(), - false /* needsInputViewShown */ ); - // Delay updating suggestions because keyboard input view may not be shown at this point. - mHandler.postUpdateSuggestions(); - - // If the dictionary is not big enough, don't auto correct - mHasDictionary = mSuggest.hasMainDictionary(); - - updateCorrectionMode(); - - inputView.setPreviewEnabled(mPopupOn); - inputView.setProximityCorrectionEnabled(true); - mIsSettingsSuggestionStripOn &= (mCorrectionMode > 0 || isShowingSuggestionsStrip()); - // If we just entered a text field, maybe it has some old text that requires correction - checkReCorrectionOnStart(); - inputView.setForeground(true); - - mVoiceConnector.onStartInputView(inputView.getWindowToken()); - - if (TRACE) Debug.startMethodTracing("/data/trace/latinime"); + return mode; } private void checkReCorrectionOnStart() { @@ -1387,7 +1392,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } private boolean isSuggestionsRequested() { - return mIsSettingsSuggestionStripOn; + return mIsSettingsSuggestionStripOn + && (mCorrectionMode > 0 || isShowingSuggestionsStrip()); } private boolean isShowingPunctuationList() { @@ -1855,9 +1861,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen return mWord.isFirstCharCapitalized(); } - // Notify that Language has been changed and toggleLanguage will update KeyboaredID according - // to new Language. - public void onKeyboardLanguageChanged() { + // Notify that language or mode have been changed and toggleLanguage will update KeyboaredID + // according to new language or mode. + public void onRefreshKeyboard() { toggleLanguage(true, true); } @@ -1868,8 +1874,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } // Reload keyboard because the current language has been changed. KeyboardSwitcher switcher = mKeyboardSwitcher; - final int mode = switcher.getKeyboardMode(); final EditorInfo attribute = getCurrentInputEditorInfo(); + final int mode = initializeInputAttributesAndGetMode((attribute != null) + ? attribute.inputType : 0); final int imeOptions = (attribute != null) ? attribute.imeOptions : 0; switcher.loadKeyboard(mode, imeOptions, mVoiceConnector.isVoiceButtonEnabled(), mVoiceConnector.isVoiceButtonOnPrimary()); diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index 21c99fe09..2c82a800a 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -186,7 +186,7 @@ public class SubtypeSwitcher { // fallback to the default locale and mode. Log.w(TAG, "Couldn't get the current subtype."); newLocale = "en_US"; - newMode =KEYBOARD_MODE; + newMode = KEYBOARD_MODE; } else { newLocale = newSubtype.getLocale(); newMode = newSubtype.getMode(); @@ -216,8 +216,8 @@ public class SubtypeSwitcher { mVoiceInput.cancel(); } } - if (languageChanged) { - mService.onKeyboardLanguageChanged(); + if (modeChanged || languageChanged) { + mService.onRefreshKeyboard(); } } else if (isVoiceMode()) { // If needsToShowWarningDialog is true, voice input need to show warning before -- cgit v1.2.3-83-g751a From cff6d095956106bac8c9af43a314c4923df11e2d Mon Sep 17 00:00:00 2001 From: satok Date: Tue, 18 Jan 2011 22:07:58 +0900 Subject: Disable auto-correct when previous suggestion candidates are shown Change-Id: I16717f0c67950297a077a15b2b6492180c0bc54b --- java/src/com/android/inputmethod/latin/SuggestedWords.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index 5398b77b2..0fbbcdd91 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -124,7 +124,7 @@ public class SuggestedWords { addWord(previousSuggestions.getWord(pos)); mIsCompletions = false; mTypedWordValid = false; - mHasMinimalSuggestion = (previousSize > 1); + mHasMinimalSuggestion = false; return this; } -- cgit v1.2.3-83-g751a From bbd651a00898dabf6b2ae0e715d99953ea81063f Mon Sep 17 00:00:00 2001 From: Luca Zanolin Date: Tue, 18 Jan 2011 15:49:17 +0000 Subject: Change the UI of Voice IME to be more like Voice Search. There has been a bit of refactoring in RecognitionView in particular to fix the portrait layout. The main issues found were: - the size of the keyboard is specified in inches, and (cm)(inches + inches) != ((cm) inches) + ((cm) inches)) - the height of keyboard background is high as the landscape keyboard, but it higher than the portrait keyboard. This is not an issue on LatinKeyboard, as it overwrite the onMeasure method. However, if I use the same image background in RelativeLayout the Relative layout height is set to the height of the background, thus higher than the keyboard - the change configuration was not propageted correctly Change-Id: Id5dca425826997c573ccae7a085d5ddc9719733b --- java/res/drawable-xlarge/btn_center_default.9.png | Bin 0 -> 182 bytes java/res/drawable-xlarge/btn_center_pressed.9.png | Bin 0 -> 200 bytes java/res/drawable-xlarge/btn_center_selected.9.png | Bin 0 -> 200 bytes java/res/drawable-xlarge/caution.png | Bin 0 -> 1100 bytes java/res/drawable-xlarge/mic_base.png | Bin 0 -> 2957 bytes java/res/drawable-xlarge/mic_full.png | Bin 0 -> 2935 bytes java/res/drawable-xlarge/mic_slash.png | Bin 0 -> 3766 bytes java/res/drawable-xlarge/vs_dialog_blue.9.png | Bin 0 -> 8275 bytes java/res/drawable-xlarge/vs_dialog_red.9.png | Bin 0 -> 8607 bytes java/res/drawable-xlarge/vs_dialog_yellow.9.png | Bin 0 -> 8151 bytes java/res/drawable-xlarge/vs_popup_mic_edge.png | Bin 0 -> 3685 bytes java/res/drawable/background_voice.xml | 25 +++ java/res/drawable/btn_center.xml | 40 ++++ java/res/drawable/btn_center_default.9.png | Bin 0 -> 182 bytes java/res/drawable/btn_center_pressed.9.png | Bin 0 -> 200 bytes java/res/drawable/btn_center_selected.9.png | Bin 0 -> 200 bytes java/res/drawable/caution.png | Bin 0 -> 1100 bytes java/res/drawable/mic_base.png | Bin 0 -> 2957 bytes java/res/drawable/mic_full.png | Bin 0 -> 2935 bytes java/res/drawable/mic_slash.png | Bin 0 -> 3766 bytes java/res/drawable/vs_dialog_blue.9.png | Bin 0 -> 8275 bytes java/res/drawable/vs_dialog_red.9.png | Bin 0 -> 8607 bytes java/res/drawable/vs_dialog_yellow.9.png | Bin 0 -> 8151 bytes java/res/drawable/vs_popup_mic_edge.png | Bin 0 -> 3685 bytes java/res/layout/recognition_status.xml | 141 ++++++------- .../com/android/inputmethod/latin/LatinIME.java | 2 +- .../android/inputmethod/latin/SubtypeSwitcher.java | 2 +- .../android/inputmethod/voice/RecognitionView.java | 221 +++++++++++---------- .../android/inputmethod/voice/SoundIndicator.java | 155 +++++++++++++++ .../inputmethod/voice/VoiceIMEConnector.java | 54 +++-- .../com/android/inputmethod/voice/VoiceInput.java | 13 +- 31 files changed, 446 insertions(+), 207 deletions(-) create mode 100755 java/res/drawable-xlarge/btn_center_default.9.png create mode 100755 java/res/drawable-xlarge/btn_center_pressed.9.png create mode 100644 java/res/drawable-xlarge/btn_center_selected.9.png create mode 100755 java/res/drawable-xlarge/caution.png create mode 100644 java/res/drawable-xlarge/mic_base.png create mode 100644 java/res/drawable-xlarge/mic_full.png create mode 100644 java/res/drawable-xlarge/mic_slash.png create mode 100644 java/res/drawable-xlarge/vs_dialog_blue.9.png create mode 100644 java/res/drawable-xlarge/vs_dialog_red.9.png create mode 100644 java/res/drawable-xlarge/vs_dialog_yellow.9.png create mode 100644 java/res/drawable-xlarge/vs_popup_mic_edge.png create mode 100644 java/res/drawable/background_voice.xml create mode 100644 java/res/drawable/btn_center.xml create mode 100755 java/res/drawable/btn_center_default.9.png create mode 100755 java/res/drawable/btn_center_pressed.9.png create mode 100644 java/res/drawable/btn_center_selected.9.png create mode 100755 java/res/drawable/caution.png create mode 100644 java/res/drawable/mic_base.png create mode 100644 java/res/drawable/mic_full.png create mode 100644 java/res/drawable/mic_slash.png create mode 100644 java/res/drawable/vs_dialog_blue.9.png create mode 100644 java/res/drawable/vs_dialog_red.9.png create mode 100644 java/res/drawable/vs_dialog_yellow.9.png create mode 100644 java/res/drawable/vs_popup_mic_edge.png create mode 100644 java/src/com/android/inputmethod/voice/SoundIndicator.java (limited to 'java/src') diff --git a/java/res/drawable-xlarge/btn_center_default.9.png b/java/res/drawable-xlarge/btn_center_default.9.png new file mode 100755 index 000000000..d5ec36ba4 Binary files /dev/null and b/java/res/drawable-xlarge/btn_center_default.9.png differ diff --git a/java/res/drawable-xlarge/btn_center_pressed.9.png b/java/res/drawable-xlarge/btn_center_pressed.9.png new file mode 100755 index 000000000..593a679d0 Binary files /dev/null and b/java/res/drawable-xlarge/btn_center_pressed.9.png differ diff --git a/java/res/drawable-xlarge/btn_center_selected.9.png b/java/res/drawable-xlarge/btn_center_selected.9.png new file mode 100644 index 000000000..f1914a886 Binary files /dev/null and b/java/res/drawable-xlarge/btn_center_selected.9.png differ diff --git a/java/res/drawable-xlarge/caution.png b/java/res/drawable-xlarge/caution.png new file mode 100755 index 000000000..eaef53425 Binary files /dev/null and b/java/res/drawable-xlarge/caution.png differ diff --git a/java/res/drawable-xlarge/mic_base.png b/java/res/drawable-xlarge/mic_base.png new file mode 100644 index 000000000..53e29ff4b Binary files /dev/null and b/java/res/drawable-xlarge/mic_base.png differ diff --git a/java/res/drawable-xlarge/mic_full.png b/java/res/drawable-xlarge/mic_full.png new file mode 100644 index 000000000..e3e3dfac3 Binary files /dev/null and b/java/res/drawable-xlarge/mic_full.png differ diff --git a/java/res/drawable-xlarge/mic_slash.png b/java/res/drawable-xlarge/mic_slash.png new file mode 100644 index 000000000..1dd05c5b4 Binary files /dev/null and b/java/res/drawable-xlarge/mic_slash.png differ diff --git a/java/res/drawable-xlarge/vs_dialog_blue.9.png b/java/res/drawable-xlarge/vs_dialog_blue.9.png new file mode 100644 index 000000000..cf27e8f43 Binary files /dev/null and b/java/res/drawable-xlarge/vs_dialog_blue.9.png differ diff --git a/java/res/drawable-xlarge/vs_dialog_red.9.png b/java/res/drawable-xlarge/vs_dialog_red.9.png new file mode 100644 index 000000000..6c08d5a30 Binary files /dev/null and b/java/res/drawable-xlarge/vs_dialog_red.9.png differ diff --git a/java/res/drawable-xlarge/vs_dialog_yellow.9.png b/java/res/drawable-xlarge/vs_dialog_yellow.9.png new file mode 100644 index 000000000..2fb06c263 Binary files /dev/null and b/java/res/drawable-xlarge/vs_dialog_yellow.9.png differ diff --git a/java/res/drawable-xlarge/vs_popup_mic_edge.png b/java/res/drawable-xlarge/vs_popup_mic_edge.png new file mode 100644 index 000000000..4ff6337a2 Binary files /dev/null and b/java/res/drawable-xlarge/vs_popup_mic_edge.png differ diff --git a/java/res/drawable/background_voice.xml b/java/res/drawable/background_voice.xml new file mode 100644 index 000000000..3b6137df3 --- /dev/null +++ b/java/res/drawable/background_voice.xml @@ -0,0 +1,25 @@ + + + + + \ No newline at end of file diff --git a/java/res/drawable/btn_center.xml b/java/res/drawable/btn_center.xml new file mode 100644 index 000000000..9998b56e2 --- /dev/null +++ b/java/res/drawable/btn_center.xml @@ -0,0 +1,40 @@ + + + + + + + + + + \ No newline at end of file diff --git a/java/res/drawable/btn_center_default.9.png b/java/res/drawable/btn_center_default.9.png new file mode 100755 index 000000000..d5ec36ba4 Binary files /dev/null and b/java/res/drawable/btn_center_default.9.png differ diff --git a/java/res/drawable/btn_center_pressed.9.png b/java/res/drawable/btn_center_pressed.9.png new file mode 100755 index 000000000..593a679d0 Binary files /dev/null and b/java/res/drawable/btn_center_pressed.9.png differ diff --git a/java/res/drawable/btn_center_selected.9.png b/java/res/drawable/btn_center_selected.9.png new file mode 100644 index 000000000..f1914a886 Binary files /dev/null and b/java/res/drawable/btn_center_selected.9.png differ diff --git a/java/res/drawable/caution.png b/java/res/drawable/caution.png new file mode 100755 index 000000000..eaef53425 Binary files /dev/null and b/java/res/drawable/caution.png differ diff --git a/java/res/drawable/mic_base.png b/java/res/drawable/mic_base.png new file mode 100644 index 000000000..53e29ff4b Binary files /dev/null and b/java/res/drawable/mic_base.png differ diff --git a/java/res/drawable/mic_full.png b/java/res/drawable/mic_full.png new file mode 100644 index 000000000..e3e3dfac3 Binary files /dev/null and b/java/res/drawable/mic_full.png differ diff --git a/java/res/drawable/mic_slash.png b/java/res/drawable/mic_slash.png new file mode 100644 index 000000000..1dd05c5b4 Binary files /dev/null and b/java/res/drawable/mic_slash.png differ diff --git a/java/res/drawable/vs_dialog_blue.9.png b/java/res/drawable/vs_dialog_blue.9.png new file mode 100644 index 000000000..cf27e8f43 Binary files /dev/null and b/java/res/drawable/vs_dialog_blue.9.png differ diff --git a/java/res/drawable/vs_dialog_red.9.png b/java/res/drawable/vs_dialog_red.9.png new file mode 100644 index 000000000..6c08d5a30 Binary files /dev/null and b/java/res/drawable/vs_dialog_red.9.png differ diff --git a/java/res/drawable/vs_dialog_yellow.9.png b/java/res/drawable/vs_dialog_yellow.9.png new file mode 100644 index 000000000..2fb06c263 Binary files /dev/null and b/java/res/drawable/vs_dialog_yellow.9.png differ diff --git a/java/res/drawable/vs_popup_mic_edge.png b/java/res/drawable/vs_popup_mic_edge.png new file mode 100644 index 000000000..4ff6337a2 Binary files /dev/null and b/java/res/drawable/vs_popup_mic_edge.png differ diff --git a/java/res/layout/recognition_status.xml b/java/res/layout/recognition_status.xml index ea2d9eefe..b2c9f4a51 100644 --- a/java/res/layout/recognition_status.xml +++ b/java/res/layout/recognition_status.xml @@ -16,83 +16,70 @@ ** See the License for the specific language governing permissions and ** limitations under the License. */ ---> - - - - - - - + - - - - - - - - - - - - + android:background="@drawable/background_voice"> + + + + + + + +