diff options
Diffstat (limited to 'java/src')
8 files changed, 79 insertions, 51 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index 1010adbe0..fc47713b8 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -87,8 +87,8 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { private final KeyDrawParams mKeyDrawParams; // Key preview + private final int mKeyPreviewLayoutId; private final KeyPreviewDrawParams mKeyPreviewDrawParams; - private final TextView mPreviewText; private boolean mShowKeyPreviewPopup = true; private final int mDelayBeforePreview; private int mDelayAfterPreview; @@ -139,9 +139,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { keyboardView.showKey(msg.arg1, tracker); break; case MSG_DISMISS_KEY_PREVIEW: - if (keyboardView.mPreviewText != null) { - keyboardView.mPreviewText.setVisibility(View.INVISIBLE); - } + tracker.getKeyPreviewText().setVisibility(View.INVISIBLE); break; } } @@ -150,7 +148,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { removeMessages(MSG_SHOW_KEY_PREVIEW); final KeyboardView keyboardView = getOuterInstance(); if (keyboardView == null) return; - if (keyboardView.mPreviewText.getVisibility() == VISIBLE || delay == 0) { + if (tracker.getKeyPreviewText().getVisibility() == VISIBLE || delay == 0) { // Show right away, if it's already visible and finger is moving around keyboardView.showKey(keyIndex, tracker); } else { @@ -171,6 +169,10 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { sendMessageDelayed(obtainMessage(MSG_DISMISS_KEY_PREVIEW, tracker), delay); } + public void cancelDismissKeyPreview(PointerTracker tracker) { + removeMessages(MSG_DISMISS_KEY_PREVIEW, tracker); + } + public void cancelAllDismissKeyPreviews() { removeMessages(MSG_DISMISS_KEY_PREVIEW); } @@ -317,11 +319,8 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { mKeyDrawParams = new KeyDrawParams(a); mKeyPreviewDrawParams = new KeyPreviewDrawParams(a, mKeyDrawParams); - final int previewLayout = a.getResourceId(R.styleable.KeyboardView_keyPreviewLayout, 0); - if (previewLayout != 0) { - mPreviewText = (TextView) LayoutInflater.from(context).inflate(previewLayout, null); - } else { - mPreviewText = null; + mKeyPreviewLayoutId = a.getResourceId(R.styleable.KeyboardView_keyPreviewLayout, 0); + if (mKeyPreviewLayoutId == 0) { mShowKeyPreviewPopup = false; } mBackgroundDimAmount = a.getFloat(R.styleable.KeyboardView_backgroundDimAmount, 0.5f); @@ -730,6 +729,17 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { mDrawingHandler.cancelAllMessages(); } + // Called by {@link PointerTracker} constructor to create a TextView. + @Override + public TextView inflateKeyPreviewText() { + final Context context = getContext(); + if (mKeyPreviewLayoutId != 0) { + return (TextView)LayoutInflater.from(context).inflate(mKeyPreviewLayoutId, null); + } else { + return new TextView(context); + } + } + @Override public void showKeyPreview(int keyIndex, PointerTracker tracker) { if (mShowKeyPreviewPopup) { @@ -760,15 +770,15 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { } // TODO: Introduce minimum duration for displaying key previews - // TODO: Display up to two key previews when the user presses two keys at the same time private void showKey(final int keyIndex, PointerTracker tracker) { - final TextView previewText = mPreviewText; + final TextView previewText = tracker.getKeyPreviewText(); // If the key preview has no parent view yet, add it to the ViewGroup which can place // key preview absolutely in SoftInputWindow. if (previewText.getParent() == null) { addKeyPreview(previewText); } + mDrawingHandler.cancelDismissKeyPreview(tracker); final Key key = tracker.getKey(keyIndex); // If keyIndex is invalid or IME is already closed, we must not show key preview. // Trying to show key preview while root window is closed causes @@ -776,7 +786,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { if (key == null) return; - mDrawingHandler.cancelAllDismissKeyPreviews(); final KeyPreviewDrawParams params = mKeyPreviewDrawParams; final int keyDrawX = key.mX + key.mVisualInsetsLeft; final int keyDrawWidth = key.mWidth - key.mVisualInsetsLeft - key.mVisualInsetsRight; @@ -858,13 +867,18 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { } public void closing() { - mPreviewText.setVisibility(View.GONE); + PointerTracker.dismissAllKeyPreviews(); cancelAllMessages(); mDirtyRect.union(0, 0, getWidth(), getHeight()); requestLayout(); } + @Override + public boolean dismissPopupPanel() { + return false; + } + public void purgeKeyboardAndClosing() { mKeyboard = null; closing(); diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java index ea2dacfa0..cb1a2b782 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java @@ -400,11 +400,10 @@ public class LatinKeyboardBaseView extends KeyboardView implements PointerTracke mPopupPanel = popupPanel; mPopupPanelPointerTrackerId = tracker.mPointerId; - tracker.onLongPressed(); - popupPanel.showPanel(this, parentKey, tracker, mPopupWindow); + popupPanel.showPopupPanel(this, parentKey, tracker, mPopupWindow); final int translatedX = popupPanel.translateX(tracker.getLastX()); final int translatedY = popupPanel.translateY(tracker.getLastY()); - tracker.onDownEvent(translatedX, translatedY, SystemClock.uptimeMillis(), popupPanel); + tracker.onShowPopupPanel(translatedX, translatedY, SystemClock.uptimeMillis(), popupPanel); invalidateAllKeys(); return true; @@ -546,11 +545,12 @@ public class LatinKeyboardBaseView extends KeyboardView implements PointerTracke @Override public void closing() { super.closing(); - dismissMiniKeyboard(); + dismissPopupPanel(); mPopupPanelCache.clear(); } - public boolean dismissMiniKeyboard() { + @Override + public boolean dismissPopupPanel() { if (mPopupWindow != null && mPopupWindow.isShowing()) { mPopupWindow.dismiss(); mPopupPanel = null; @@ -562,7 +562,7 @@ public class LatinKeyboardBaseView extends KeyboardView implements PointerTracke } public boolean handleBack() { - return dismissMiniKeyboard(); + return dismissPopupPanel(); } @Override diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index e66ea7b79..f64835726 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -19,6 +19,7 @@ package com.android.inputmethod.keyboard; import android.content.Context; import android.content.res.Resources; import android.util.Log; +import android.widget.TextView; import com.android.inputmethod.keyboard.internal.PointerTrackerQueue; import com.android.inputmethod.latin.LatinImeLogger; @@ -64,9 +65,11 @@ public class PointerTracker { public interface DrawingProxy { public void invalidateKey(Key key); + public TextView inflateKeyPreviewText(); public void showKeyPreview(int keyIndex, PointerTracker tracker); public void cancelShowKeyPreview(PointerTracker tracker); public void dismissKeyPreview(PointerTracker tracker); + public boolean dismissPopupPanel(); } public interface TimerProxy { @@ -99,6 +102,7 @@ public class PointerTracker { private Keyboard mKeyboard; private List<Key> mKeys; private int mKeyQuarterWidthSquared; + private final TextView mKeyPreviewText; // The position and time at which first down event occurred. private long mDownTime; @@ -117,9 +121,12 @@ public class PointerTracker { // true if keyboard layout has been changed. private boolean mKeyboardLayoutHasBeenChanged; - // true if event is already translated to a key action (long press or mini-keyboard) + // true if event is already translated to a key action. private boolean mKeyAlreadyProcessed; + // true if this pointer has been long-pressed and is showing a popup panel. + private boolean mIsShowingPopupPanel; + // true if this pointer is repeatable key private boolean mIsRepeatableKey; @@ -211,6 +218,11 @@ public class PointerTracker { mListener = handler.getKeyboardActionListener(); mDrawingProxy = handler.getDrawingProxy(); mTimerProxy = handler.getTimerProxy(); + mKeyPreviewText = mDrawingProxy.inflateKeyPreviewText(); + } + + public TextView getKeyPreviewText() { + return mKeyPreviewText; } // Returns true if keyboard has been changed by this callback. @@ -579,6 +591,10 @@ public class PointerTracker { } final int keyIndex = onUpKey(keyX, keyY, eventTime); setReleasedKeyGraphics(keyIndex); + if (mIsShowingPopupPanel) { + mDrawingProxy.dismissPopupPanel(); + mIsShowingPopupPanel = false; + } if (mKeyAlreadyProcessed) return; if (!mIsRepeatableKey) { @@ -586,6 +602,12 @@ public class PointerTracker { } } + public void onShowPopupPanel(int x, int y, long eventTime, KeyEventHandler handler) { + onLongPressed(); + onDownEvent(x, y, eventTime, handler); + mIsShowingPopupPanel = true; + } + public void onLongPressed() { mKeyAlreadyProcessed = true; setReleasedKeyGraphics(mKeyIndex); @@ -612,6 +634,10 @@ public class PointerTracker { mDrawingProxy.cancelShowKeyPreview(this); setReleasedKeyGraphics(mKeyIndex); mIsInSlidingKeyInput = false; + if (mIsShowingPopupPanel) { + mDrawingProxy.dismissPopupPanel(); + mIsShowingPopupPanel = false; + } } private void startRepeatKey(int keyIndex) { diff --git a/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java b/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java index a90f57c62..2741ee80b 100644 --- a/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java @@ -59,19 +59,16 @@ public class PopupMiniKeyboardView extends KeyboardView implements PopupPanel { public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) { mParentKeyboardView.getKeyboardActionListener() .onCodeInput(primaryCode, keyCodes, x, y); - mParentKeyboardView.dismissMiniKeyboard(); } @Override public void onTextInput(CharSequence text) { mParentKeyboardView.getKeyboardActionListener().onTextInput(text); - mParentKeyboardView.dismissMiniKeyboard(); } @Override public void onCancelInput() { mParentKeyboardView.getKeyboardActionListener().onCancelInput(); - mParentKeyboardView.dismissMiniKeyboard(); } @Override @@ -159,7 +156,7 @@ public class PopupMiniKeyboardView extends KeyboardView implements PopupPanel { } @Override - public void showPanel(LatinKeyboardBaseView parentKeyboardView, Key parentKey, + public void showPopupPanel(LatinKeyboardBaseView parentKeyboardView, Key parentKey, PointerTracker tracker, PopupWindow window) { mParentKeyboardView = parentKeyboardView; final View container = (View)getParent(); @@ -192,6 +189,11 @@ public class PopupMiniKeyboardView extends KeyboardView implements PopupPanel { } @Override + public boolean dismissPopupPanel() { + return mParentKeyboardView.dismissPopupPanel(); + } + + @Override public int translateX(int x) { return x - mOriginX; } diff --git a/java/src/com/android/inputmethod/keyboard/PopupPanel.java b/java/src/com/android/inputmethod/keyboard/PopupPanel.java index f94d1c562..dc526e74f 100644 --- a/java/src/com/android/inputmethod/keyboard/PopupPanel.java +++ b/java/src/com/android/inputmethod/keyboard/PopupPanel.java @@ -26,7 +26,7 @@ public interface PopupPanel extends PointerTracker.KeyEventHandler { * @param tracker the pointer tracker that pressesd the parent key * @param window PopupWindow to be used to show this popup panel */ - public void showPanel(LatinKeyboardBaseView parentKeyboardView, Key parentKey, + public void showPopupPanel(LatinKeyboardBaseView parentKeyboardView, Key parentKey, PointerTracker tracker, PopupWindow window); /** diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java index 00d80f566..41b577cf3 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java @@ -107,6 +107,7 @@ public class BinaryDictionaryFileDumper { if (null == afd) return null; final String fileName = copyFileTo(afd.createInputStream(), getCacheFileNameForLocale(locale, context)); + afd.close(); return Arrays.asList(AssetFileAddress.makeFromFileName(fileName)); } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index a8118e549..d9d421411 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1442,8 +1442,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // not to auto correct, but accept the typed word. For instance, // in Italian dov' should not be expanded to dove' because the elision // requires the last vowel to be removed. - final boolean shouldAutoCorrect = - (mSettingsValues.mAutoCorrectEnabled || mSettingsValues.mQuickFixes) + final boolean shouldAutoCorrect = mSettingsValues.mAutoCorrectEnabled && !mInputTypeNoAutoCorrect && mHasDictionary; if (shouldAutoCorrect && primaryCode != Keyboard.CODE_SINGLE_QUOTE) { pickedDefault = pickDefaultSuggestion(primaryCode); @@ -2085,8 +2084,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private void updateCorrectionMode() { // TODO: cleanup messy flags mHasDictionary = mSuggest != null ? mSuggest.hasMainDictionary() : false; - final boolean shouldAutoCorrect = (mSettingsValues.mAutoCorrectEnabled - || mSettingsValues.mQuickFixes) && !mInputTypeNoAutoCorrect && mHasDictionary; + final boolean shouldAutoCorrect = mSettingsValues.mAutoCorrectEnabled + && !mInputTypeNoAutoCorrect && mHasDictionary; mCorrectionMode = (shouldAutoCorrect && mSettingsValues.mAutoCorrectEnabled) ? Suggest.CORRECTION_FULL : (shouldAutoCorrect ? Suggest.CORRECTION_BASIC : Suggest.CORRECTION_NONE); @@ -2100,7 +2099,13 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private void updateAutoTextEnabled() { if (mSuggest == null) return; - mSuggest.setQuickFixesEnabled(mSettingsValues.mQuickFixes + // We want to use autotext if the settings are asking for auto corrections, and if + // the input language is the same as the system language (because autotext will only + // work in the system language so if we are entering text in a different language we + // do not want it on). + // We used to look at the "quick fixes" option instead of mAutoCorrectEnabled, but + // this option was redundant and confusing and therefore removed. + mSuggest.setQuickFixesEnabled(mSettingsValues.mAutoCorrectEnabled && SubtypeSwitcher.getInstance().isSystemLanguageSameAsInputLanguage()); } diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index 6a4837163..dbab227db 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -69,7 +69,6 @@ public class Settings extends InputMethodSettingsActivity public static final String PREF_CONFIGURE_DICTIONARIES_KEY = "configure_dictionaries_key"; public static final String PREF_CORRECTION_SETTINGS_KEY = "correction_settings"; - public static final String PREF_QUICK_FIXES = "quick_fixes"; public static final String PREF_SHOW_SUGGESTIONS_SETTING = "show_suggestions_setting"; public static final String PREF_AUTO_CORRECTION_THRESHOLD = "auto_correction_threshold"; public static final String PREF_DEBUG_SETTINGS = "debug_settings"; @@ -111,7 +110,6 @@ public class Settings extends InputMethodSettingsActivity public final boolean mKeyPreviewPopupOn; public final int mKeyPreviewPopupDismissDelay; public final boolean mAutoCap; - public final boolean mQuickFixes; public final boolean mAutoCorrectEnabled; public final double mAutoCorrectionThreshold; // Suggestion: use bigrams to adjust scores of suggestions obtained from unigram dictionary @@ -171,7 +169,6 @@ public class Settings extends InputMethodSettingsActivity mKeyPreviewPopupOn = isKeyPreviewPopupEnabled(prefs, res); mKeyPreviewPopupDismissDelay = getKeyPreviewPopupDismissDelay(prefs, res); mAutoCap = prefs.getBoolean(Settings.PREF_AUTO_CAP, true); - mQuickFixes = isQuickFixesEnabled(prefs, res); mAutoCorrectEnabled = isAutoCorrectEnabled(prefs, res); mBigramSuggestionEnabled = mAutoCorrectEnabled @@ -208,17 +205,6 @@ public class Settings extends InputMethodSettingsActivity return mMagicSpaceSwappers.contains(String.valueOf((char)code)); } - // Helper methods - private static boolean isQuickFixesEnabled(SharedPreferences sp, Resources resources) { - final boolean showQuickFixesOption = resources.getBoolean( - R.bool.config_enable_quick_fixes_option); - if (!showQuickFixesOption) { - return isAutoCorrectEnabled(sp, resources); - } - return sp.getBoolean(Settings.PREF_QUICK_FIXES, resources.getBoolean( - R.bool.config_default_quick_fixes)); - } - private static boolean isAutoCorrectEnabled(SharedPreferences sp, Resources resources) { final String currentAutoCorrectionSetting = sp.getString( Settings.PREF_AUTO_CORRECTION_THRESHOLD, @@ -419,12 +405,6 @@ public class Settings extends InputMethodSettingsActivity generalSettings.removePreference(findPreference(PREF_RECORRECTION_ENABLED)); } - final boolean showQuickFixesOption = res.getBoolean( - R.bool.config_enable_quick_fixes_option); - if (!showQuickFixesOption) { - textCorrectionGroup.removePreference(findPreference(PREF_QUICK_FIXES)); - } - final boolean showBigramSuggestionsOption = res.getBoolean( R.bool.config_enable_bigram_suggestions_option); if (!showBigramSuggestionsOption) { |