diff options
Diffstat (limited to 'java/src')
6 files changed, 79 insertions, 64 deletions
diff --git a/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java b/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java index 194741087..bcdcef7dc 100644 --- a/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java +++ b/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java @@ -26,16 +26,12 @@ public class EditorInfoCompatUtils { EditorInfo.class, "IME_FLAG_NAVIGATE_NEXT"); private static final Field FIELD_IME_FLAG_NAVIGATE_PREVIOUS = CompatUtils.getField( EditorInfo.class, "IME_FLAG_NAVIGATE_PREVIOUS"); - private static final Field FIELD_IME_FLAG_NO_FULLSCREEN = CompatUtils.getField( - EditorInfo.class, "IME_FLAG_NO_FULLSCREEN"); private static final Field FIELD_IME_ACTION_PREVIOUS = CompatUtils.getField( EditorInfo.class, "IME_ACTION_PREVIOUS"); private static final Integer OBJ_IME_FLAG_NAVIGATE_NEXT = (Integer) CompatUtils .getFieldValue(null, null, FIELD_IME_FLAG_NAVIGATE_NEXT); private static final Integer OBJ_IME_FLAG_NAVIGATE_PREVIOUS = (Integer) CompatUtils .getFieldValue(null, null, FIELD_IME_FLAG_NAVIGATE_PREVIOUS); - private static final Integer OBJ_IME_FLAG_NO_FULLSCREEN = (Integer) CompatUtils - .getFieldValue(null, null, FIELD_IME_FLAG_NO_FULLSCREEN); private static final Integer OBJ_IME_ACTION_PREVIOUS = (Integer) CompatUtils .getFieldValue(null, null, FIELD_IME_ACTION_PREVIOUS); @@ -51,12 +47,6 @@ public class EditorInfoCompatUtils { return (imeOptions & OBJ_IME_FLAG_NAVIGATE_PREVIOUS) != 0; } - public static boolean hasFlagNoFullscreen(int imeOptions) { - if (FIELD_IME_FLAG_NO_FULLSCREEN == null) - return false; - return (imeOptions & OBJ_IME_FLAG_NO_FULLSCREEN) != 0; - } - public static void performEditorActionNext(InputConnection ic) { ic.performEditorAction(EditorInfo.IME_ACTION_NEXT); } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 51716a40c..91a784124 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -160,7 +160,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private View mKeyPreviewBackingView; private View mSuggestionsContainer; - private int mSuggestionsStripHeight; private SuggestionsView mSuggestionsView; private Suggest mSuggest; private CompletionInfo[] mApplicationSpecifiedCompletions; @@ -619,7 +618,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mSuggestionsView = (SuggestionsView) view.findViewById(R.id.suggestions_view); if (mSuggestionsView != null) mSuggestionsView.setListener(this, view); - mSuggestionsStripHeight = (int)mResources.getDimension(R.dimen.suggestions_strip_height); } @Override @@ -688,6 +686,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (mSuggestionsView != null) mSuggestionsView.clear(); + // The EditorInfo might have a flag that affects fullscreen mode. + updateFullscreenMode(); setSuggestionStripShownInternal( isSuggestionsStripVisible(), /* needsInputViewShown */ false); // Delay updating suggestions because keyboard input view may not be shown at this point. @@ -952,14 +952,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar final boolean shouldShowSuggestions = shown && (needsInputViewShown ? mKeyboardSwitcher.isInputViewShown() : true); if (isFullscreenMode()) { - // No need to have extra space to show the key preview. - mKeyPreviewBackingView.setVisibility(View.GONE); mSuggestionsContainer.setVisibility( shouldShowSuggestions ? View.VISIBLE : View.GONE); } else { - // We must control the visibility of the suggestion strip in order to avoid clipped - // key previews, even when we don't show the suggestion strip. - mKeyPreviewBackingView.setVisibility(View.VISIBLE); mSuggestionsContainer.setVisibility( shouldShowSuggestions ? View.VISIBLE : View.INVISIBLE); } @@ -978,12 +973,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar return; final int backingHeight = (mKeyPreviewBackingView.getVisibility() == View.GONE) ? 0 : mKeyPreviewBackingView.getHeight(); - final int extraHeight = mSuggestionsContainer.getHeight() + backingHeight; + final int suggestionsHeight = (mSuggestionsContainer.getVisibility() == View.GONE) ? 0 + : mSuggestionsContainer.getHeight(); + final int extraHeight = backingHeight + suggestionsHeight; int touchY = extraHeight; // Need to set touchable region only if input view is being shown if (mKeyboardSwitcher.isInputViewShown()) { if (mSuggestionsContainer.getVisibility() == View.VISIBLE) { - touchY -= mSuggestionsStripHeight; + touchY -= suggestionsHeight; } final int touchWidth = inputView.getWidth(); final int touchHeight = inputView.getHeight() + extraHeight @@ -1001,16 +998,18 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar @Override public boolean onEvaluateFullscreenMode() { - final EditorInfo ei = getCurrentInputEditorInfo(); - if (ei != null) { - final int imeOptions = ei.imeOptions; - if (EditorInfoCompatUtils.hasFlagNoFullscreen(imeOptions)) - return false; - if ((imeOptions & EditorInfo.IME_FLAG_NO_EXTRACT_UI) != 0) - return false; - } + return super.onEvaluateFullscreenMode() + && mResources.getBoolean(R.bool.config_use_fullscreen_mode); + } + + @Override + public void updateFullscreenMode() { + super.updateFullscreenMode(); - return mResources.getBoolean(R.bool.config_use_fullscreen_mode); + if (mKeyPreviewBackingView == null) return; + // In fullscreen mode, no need to have extra space to show the key preview. + // If not, we should have extra space above the keyboard to show the key preview. + mKeyPreviewBackingView.setVisibility(isFullscreenMode() ? View.GONE : View.VISIBLE); } @Override diff --git a/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java b/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java index 15a0cec2e..5a2eb1632 100644 --- a/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java +++ b/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java @@ -145,13 +145,6 @@ public class MoreSuggestionsView extends KeyboardView implements MoreKeysPanel { // Nothing to do with. } - private final View.OnTouchListener mMotionEventDelegate = new View.OnTouchListener() { - @Override - public boolean onTouch(View view, MotionEvent me) { - return MoreSuggestionsView.this.dispatchTouchEvent(me); - } - }; - @Override public void showMoreKeysPanel(View parentView, Controller controller, int pointX, int pointY, PopupWindow window, KeyboardActionListener listener) { @@ -170,9 +163,7 @@ public class MoreSuggestionsView extends KeyboardView implements MoreKeysPanel { - (container.getMeasuredHeight() - container.getPaddingBottom()) + parentView.getPaddingTop() + mCoordinates[1]; - container.setOnTouchListener(mMotionEventDelegate); window.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED); - window.setFocusable(true); window.setOutsideTouchable(true); window.setContentView(container); window.setWidth(container.getMeasuredWidth()); @@ -193,6 +184,7 @@ public class MoreSuggestionsView extends KeyboardView implements MoreKeysPanel { @Override public boolean dismissMoreKeysPanel() { + if (mController == null) return false; return mController.dismissMoreKeysPanel(); } diff --git a/java/src/com/android/inputmethod/latin/SuggestionsView.java b/java/src/com/android/inputmethod/latin/SuggestionsView.java index 6fc790030..fbb277372 100644 --- a/java/src/com/android/inputmethod/latin/SuggestionsView.java +++ b/java/src/com/android/inputmethod/latin/SuggestionsView.java @@ -549,6 +549,21 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, R.dimen.more_suggestions_modal_tolerance); } + private final View.OnTouchListener mMoreSuggestionsCanceller = new View.OnTouchListener() { + @Override + public boolean onTouch(View view, MotionEvent me) { + if (!mMoreSuggestionsWindow.isShowing()) return false; + + switch (me.getAction()) { + case MotionEvent.ACTION_UP: + case MotionEvent.ACTION_POINTER_UP: + return mMoreSuggestionsView.dismissMoreKeysPanel(); + default: + return true; + } + } + }; + /** * A connection back to the input method. * @param listener @@ -764,6 +779,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, if (mMoreSuggestionsWindow.isShowing()) { mMoreSuggestionsWindow.dismiss(); mKeyboardView.dimEntireKeyboard(false); + mKeyboardView.setOnTouchListener(null); return true; } return false; @@ -795,18 +811,22 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, moreKeysPanel.showMoreKeysPanel( this, mMoreSuggestionsController, pointX, pointY, mMoreSuggestionsWindow, mMoreSuggestionsListener); - mCheckingIfModalOrSlidingMode = true; + mMoreSuggestionsMode = MORE_SUGGESTIONS_CHECKING_MODAL_OR_SLIDING; mOriginX = mLastX; mOriginY = mLastY; view.setPressed(false); mKeyboardView.dimEntireKeyboard(true); + mKeyboardView.setOnTouchListener(mMoreSuggestionsCanceller); return true; } return false; } // Working variables for onLongClick and dispatchTouchEvent. - private boolean mCheckingIfModalOrSlidingMode; + private int mMoreSuggestionsMode = MORE_SUGGESTIONS_IN_MODAL_MODE; + private static final int MORE_SUGGESTIONS_IN_MODAL_MODE = 0; + private static final int MORE_SUGGESTIONS_CHECKING_MODAL_OR_SLIDING = 1; + private static final int MORE_SUGGESTIONS_IN_SLIDING_MODE = 2; private int mLastX; private int mLastY; private int mOriginX; @@ -815,7 +835,8 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, @Override public boolean dispatchTouchEvent(MotionEvent me) { - if (!mMoreSuggestionsWindow.isShowing()) { + if (!mMoreSuggestionsWindow.isShowing() + || mMoreSuggestionsMode == MORE_SUGGESTIONS_IN_MODAL_MODE) { mLastX = (int)me.getX(); mLastY = (int)me.getY(); return super.dispatchTouchEvent(me); @@ -832,22 +853,22 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, final int translatedX = moreKeysPanel.translateX(x); final int translatedY = moreKeysPanel.translateY(y); - if (mCheckingIfModalOrSlidingMode) { + if (mMoreSuggestionsMode == MORE_SUGGESTIONS_CHECKING_MODAL_OR_SLIDING) { if (Math.abs(x - mOriginX) >= mMoreSuggestionsModalTolerance || mOriginY - y >= mMoreSuggestionsModalTolerance) { // Decided to be in the sliding input mode only when the touch point has been moved // upward. - mCheckingIfModalOrSlidingMode = false; + mMoreSuggestionsMode = MORE_SUGGESTIONS_IN_SLIDING_MODE; tracker.onShowMoreKeysPanel( translatedX, translatedY, SystemClock.uptimeMillis(), moreKeysPanel); } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) { // Decided to be in the modal input mode - mCheckingIfModalOrSlidingMode = false; + mMoreSuggestionsMode = MORE_SUGGESTIONS_IN_MODAL_MODE; } return true; } - // Process sliding motion events + // MORE_SUGGESTIONS_IN_SLIDING_MODE tracker.processMotionEvent(action, translatedX, translatedY, eventTime, moreKeysPanel); return true; } diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java index 1e5b87763..915c40572 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java @@ -60,8 +60,11 @@ public class AndroidSpellCheckerService extends SpellCheckerService { private static final int CAPITALIZE_ALL = 2; // All caps private final static String[] EMPTY_STRING_ARRAY = new String[0]; - private final static SuggestionsInfo EMPTY_SUGGESTIONS_INFO = + private final static SuggestionsInfo NOT_IN_DICT_EMPTY_SUGGESTIONS = new SuggestionsInfo(0, EMPTY_STRING_ARRAY); + private final static SuggestionsInfo IN_DICT_EMPTY_SUGGESTIONS = + new SuggestionsInfo(SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY, + EMPTY_STRING_ARRAY); private Map<String, DictionaryPool> mDictionaryPools = Collections.synchronizedMap(new TreeMap<String, DictionaryPool>()); private Map<String, Dictionary> mUserDictionaries = @@ -330,7 +333,12 @@ public class AndroidSpellCheckerService extends SpellCheckerService { try { final String text = textInfo.getText(); - if (shouldFilterOut(text)) return EMPTY_SUGGESTIONS_INFO; + if (shouldFilterOut(text)) { + final DictAndProximity dictInfo = mDictionaryPool.takeOrGetNull(); + if (null == dictInfo) return NOT_IN_DICT_EMPTY_SUGGESTIONS; + return dictInfo.mDictionary.isValidWord(text) ? IN_DICT_EMPTY_SUGGESTIONS + : NOT_IN_DICT_EMPTY_SUGGESTIONS; + } final SuggestionsGatherer suggestionsGatherer = new SuggestionsGatherer(suggestionsLimit); @@ -353,23 +361,19 @@ public class AndroidSpellCheckerService extends SpellCheckerService { final int capitalizeType = getCapitalizationType(text); boolean isInDict = true; - try { - final DictAndProximity dictInfo = mDictionaryPool.take(); - dictInfo.mDictionary.getWords(composer, suggestionsGatherer, - dictInfo.mProximityInfo); - isInDict = dictInfo.mDictionary.isValidWord(text); - if (!isInDict && CAPITALIZE_NONE != capitalizeType) { - // We want to test the word again if it's all caps or first caps only. - // If it's fully down, we already tested it, if it's mixed case, we don't - // want to test a lowercase version of it. - isInDict = dictInfo.mDictionary.isValidWord(text.toLowerCase(mLocale)); - } - if (!mDictionaryPool.offer(dictInfo)) { - Log.e(TAG, "Can't re-insert a dictionary into its pool"); - } - } catch (InterruptedException e) { - // I don't think this can happen. - return EMPTY_SUGGESTIONS_INFO; + final DictAndProximity dictInfo = mDictionaryPool.takeOrGetNull(); + if (null == dictInfo) return NOT_IN_DICT_EMPTY_SUGGESTIONS; + dictInfo.mDictionary.getWords(composer, suggestionsGatherer, + dictInfo.mProximityInfo); + isInDict = dictInfo.mDictionary.isValidWord(text); + if (!isInDict && CAPITALIZE_NONE != capitalizeType) { + // We want to test the word again if it's all caps or first caps only. + // If it's fully down, we already tested it, if it's mixed case, we don't + // want to test a lowercase version of it. + isInDict = dictInfo.mDictionary.isValidWord(text.toLowerCase(mLocale)); + } + if (!mDictionaryPool.offer(dictInfo)) { + Log.e(TAG, "Can't re-insert a dictionary into its pool"); } final SuggestionsGatherer.Result result = suggestionsGatherer.getResults(text, @@ -396,7 +400,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService { throw e; } else { Log.e(TAG, "Exception while spellcheking: " + e); - return EMPTY_SUGGESTIONS_INFO; + return NOT_IN_DICT_EMPTY_SUGGESTIONS; } } } diff --git a/java/src/com/android/inputmethod/latin/spellcheck/DictionaryPool.java b/java/src/com/android/inputmethod/latin/spellcheck/DictionaryPool.java index ee294f6b0..dec18c1d5 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/DictionaryPool.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/DictionaryPool.java @@ -56,6 +56,15 @@ public class DictionaryPool extends LinkedBlockingQueue<DictAndProximity> { } } + // Convenience method + public DictAndProximity takeOrGetNull() { + try { + return take(); + } catch (InterruptedException e) { + return null; + } + } + public void close() { synchronized(this) { mClosed = true; |