diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinIME.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinIME.java | 208 |
1 files changed, 105 insertions, 103 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index d1125afcc..75ba24d75 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -171,10 +171,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen public void onCreate() { final Resources res = getOwnerInstance().getResources(); - mDelayUpdateSuggestions = - res.getInteger(R.integer.config_delay_update_suggestions); - mDelayUpdateShiftState = - res.getInteger(R.integer.config_delay_update_shift_state); + mDelayUpdateSuggestions = res.getInteger(R.integer.config_delay_update_suggestions); + mDelayUpdateShiftState = res.getInteger(R.integer.config_delay_update_shift_state); mDoubleSpacePeriodTimeout = res.getInteger(R.integer.config_double_space_period_timeout); } @@ -339,12 +337,15 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private void executePendingImsCallback(final LatinIME latinIme, final EditorInfo editorInfo, boolean restarting) { - if (mHasPendingFinishInputView) + if (mHasPendingFinishInputView) { latinIme.onFinishInputViewInternal(mHasPendingFinishInput); - if (mHasPendingFinishInput) + } + if (mHasPendingFinishInput) { latinIme.onFinishInputInternal(); - if (mHasPendingStartInput) + } + if (mHasPendingStartInput) { latinIme.onStartInputInternal(editorInfo, restarting); + } resetPendingImsCallback(); } @@ -579,9 +580,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen (mInputLogic.mSuggest == null) ? null : mInputLogic.mSuggest.mDictionaryFacilitator; // Creates new dictionary facilitator for the new locale. final DictionaryFacilitatorForSuggest dictionaryFacilitator = - new DictionaryFacilitatorForSuggest(this /* context */, locale, - settingsValues, this /* DictionaryInitializationListener */, - oldDictionaryFacilitator); + new DictionaryFacilitatorForSuggest(this /* context */, locale, settingsValues, + this /* DictionaryInitializationListener */, oldDictionaryFacilitator); final Suggest newSuggest = new Suggest(locale, dictionaryFacilitator); if (settingsValues.mCorrectionEnabled) { newSuggest.setAutoCorrectionThreshold(settingsValues.mAutoCorrectionThreshold); @@ -658,7 +658,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen .findViewById(android.R.id.extractArea); mKeyPreviewBackingView = view.findViewById(R.id.key_preview_backing); mSuggestionStripView = (SuggestionStripView)view.findViewById(R.id.suggestion_strip_view); - if (mSuggestionStripView != null) { + if (hasSuggestionStripView()) { mSuggestionStripView.setListener(this, view); } if (LatinImeLogger.sVISUALDEBUG) { @@ -738,13 +738,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen ResearchLogger.latinIME_onStartInputViewInternal(editorInfo, prefs); } if (InputAttributes.inPrivateImeOptions(null, NO_MICROPHONE_COMPAT, editorInfo)) { - Log.w(TAG, "Deprecated private IME option specified: " - + editorInfo.privateImeOptions); + Log.w(TAG, "Deprecated private IME option specified: " + editorInfo.privateImeOptions); Log.w(TAG, "Use " + getPackageName() + "." + NO_MICROPHONE + " instead"); } if (InputAttributes.inPrivateImeOptions(getPackageName(), FORCE_ASCII, editorInfo)) { - Log.w(TAG, "Deprecated private IME option specified: " - + editorInfo.privateImeOptions); + Log.w(TAG, "Deprecated private IME option specified: " + editorInfo.privateImeOptions); Log.w(TAG, "Use EditorInfo.IME_FLAG_FORCE_ASCII flag instead"); } @@ -781,11 +779,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (null != suggest && null != currentLocale && !currentLocale.equals(suggest.mLocale)) { initSuggest(); } - if (mSuggestionStripView != null) { - // This will set the punctuation suggestions if next word suggestion is off; - // otherwise it will clear the suggestion strip. - setNeutralSuggestionStrip(); - } // Sometimes, while rotating, for some reason the framework tells the app we are not // connected to it and that means we can't refresh the cache. In this case, schedule a @@ -834,8 +827,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // Space state must be updated before calling updateShiftState switcher.updateShiftState(); } - setSuggestionStripShownInternal( - isSuggestionsStripVisible(), /* needsInputViewShown */ false); + // This will set the punctuation suggestions if next word suggestion is off; + // otherwise it will clear the suggestion strip. + setNeutralSuggestionStripInternal(false /* needsInputViewShown */); mHandler.cancelUpdateSuggestionStrip(); mHandler.cancelDoubleSpacePeriodTimer(); @@ -894,12 +888,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd, composingSpanStart, composingSpanEnd); if (DEBUG) { - Log.i(TAG, "onUpdateSelection: oss=" + oldSelStart - + ", ose=" + oldSelEnd - + ", nss=" + newSelStart - + ", nse=" + newSelEnd - + ", cs=" + composingSpanStart - + ", ce=" + composingSpanEnd); + Log.i(TAG, "onUpdateSelection: oss=" + oldSelStart + ", ose=" + oldSelEnd + + ", nss=" + newSelStart + ", nse=" + newSelEnd + + ", cs=" + composingSpanStart + ", ce=" + composingSpanEnd); } if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.latinIME_onUpdateSelection(oldSelStart, oldSelEnd, @@ -983,7 +974,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } } } - if (!mSettings.getCurrent().isApplicationSpecifiedCompletionsOn()) return; + if (!mSettings.getCurrent().isApplicationSpecifiedCompletionsOn()) { + return; + } if (applicationSpecifiedCompletions == null) { setNeutralSuggestionStrip(); if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { @@ -997,27 +990,25 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final ArrayList<SuggestedWords.SuggestedWordInfo> applicationSuggestedWords = SuggestedWords.getFromApplicationSpecifiedCompletions( applicationSpecifiedCompletions); - final SuggestedWords suggestedWords = new SuggestedWords( - applicationSuggestedWords, null /* rawSuggestions */, - false /* typedWordValid */, - false /* willAutoCorrect */, - false /* isObsoleteSuggestions */, - false /* isPrediction */); - // When in fullscreen mode, show completions generated by the application - setSuggestedWords(suggestedWords, true /* shouldShow */); + final SuggestedWords suggestedWords = new SuggestedWords(applicationSuggestedWords, + null /* rawSuggestions */, false /* typedWordValid */, false /* willAutoCorrect */, + false /* isObsoleteSuggestions */, false /* isPrediction */); + // When in fullscreen mode, show completions generated by the application forcibly + setSuggestedWords(suggestedWords, true /* isSuggestionStripVisible */, + true /* needsInputViewShown */); if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.latinIME_onDisplayCompletions(applicationSpecifiedCompletions); } } - private void setSuggestionStripShownInternal(final boolean shown, + private void setSuggestionStripShownInternal(final boolean isSuggestionStripVisible, final boolean needsInputViewShown) { // TODO: Modify this if we support suggestions with hard keyboard - if (!onEvaluateInputViewShown() || null == mSuggestionStripView) { + if (!onEvaluateInputViewShown() || !hasSuggestionStripView()) { return; } final boolean inputViewShown = mKeyboardSwitcher.isShowingMainKeyboardOrEmojiPalettes(); - final boolean shouldShowSuggestions = shown + final boolean shouldShowSuggestions = isSuggestionStripVisible && (needsInputViewShown ? inputViewShown : true); if (shouldShowSuggestions) { mSuggestionStripView.setVisibility(View.VISIBLE); @@ -1057,7 +1048,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen public void onComputeInsets(final InputMethodService.Insets outInsets) { super.onComputeInsets(outInsets); final View visibleKeyboardView = mKeyboardSwitcher.getVisibleKeyboardView(); - if (visibleKeyboardView == null || mSuggestionStripView == null) { + if (visibleKeyboardView == null || !hasSuggestionStripView()) { return; } final int adjustedBackingHeight = getAdjustedBackingViewHeight(); @@ -1177,18 +1168,28 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen public void onClick(final DialogInterface di, final int position) { di.dismiss(); ImportantNoticeUtils.updateLastImportantNoticeVersion(context); - setNeutralSuggestionStrip(); + if (position == DialogInterface.BUTTON_POSITIVE) { + setNeutralSuggestionStrip(); + return; + } + if (position == DialogInterface.BUTTON_NEGATIVE) { + launchSettings(); + return; + } } }; final AlertDialog.Builder builder = new AlertDialog.Builder(context, AlertDialog.THEME_HOLO_DARK); builder.setMessage(R.string.important_notice_contents) - .setPositiveButton(android.R.string.ok, listener); + .setPositiveButton(android.R.string.ok, listener) + .setNegativeButton(R.string.go_to_settings, listener); showOptionDialog(builder.create(), true /* cancelable */); } public void displaySettingsDialog() { - if (isShowingOptionDialog()) return; + if (isShowingOptionDialog()) { + return; + } showSubtypeSelectorAndSettings(); } @@ -1248,8 +1249,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mSubtypeSwitcher.switchToShortcutIME(this); // Still call the *#onCodeInput methods for readability. } - mInputLogic.onCodeInput(codeToSend, keyX, keyY, mSettings.getCurrent(), - mHandler, mKeyboardSwitcher); + mInputLogic.onCodeInput(codeToSend, keyX, keyY, mSettings.getCurrent(), mHandler, + mKeyboardSwitcher); mKeyboardSwitcher.onCodeInput(codePoint); } @@ -1306,27 +1307,28 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // Nothing to do so far. } - // TODO: remove this, read this directly from mInputLogic or something in the tests - @UsedForTesting - public boolean isShowingPunctuationList() { - return mInputLogic.isShowingPunctuationList(mSettings.getCurrent()); - } - // TODO[IL]: Define a clear interface for this - public boolean isSuggestionsStripVisible() { - final SettingsValues currentSettings = mSettings.getCurrent(); - if (mSuggestionStripView == null) + public boolean isSuggestionStripVisible() { + if (!hasSuggestionStripView()) { return false; - if (mSuggestionStripView.isShowingAddToDictionaryHint()) - return true; - if (ImportantNoticeUtils.hasNewImportantNoticeAndNotInSetupWizard(this)) + } + if (mSuggestionStripView.isShowingAddToDictionaryHint()) { return true; - if (null == currentSettings) + } + final SettingsValues currentSettings = mSettings.getCurrent(); + if (null == currentSettings) { return false; - if (!currentSettings.isSuggestionStripVisible()) + } + if (ImportantNoticeUtils.shouldShowImportantNotice(this, + currentSettings.mInputAttributes)) { + return true; + } + if (!currentSettings.isSuggestionStripVisible()) { return false; - if (currentSettings.isApplicationSpecifiedCompletionsOn()) + } + if (currentSettings.isApplicationSpecifiedCompletionsOn()) { return true; + } return currentSettings.isSuggestionsRequested(); } @@ -1342,30 +1344,35 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen @Override public void dismissAddToDictionaryHint() { - if (null != mSuggestionStripView) { - mSuggestionStripView.dismissAddToDictionaryHint(); + if (!hasSuggestionStripView()) { + return; } + mSuggestionStripView.dismissAddToDictionaryHint(); } // TODO[IL]: Define a clear interface for this - public void setSuggestedWords(final SuggestedWords suggestedWords, final boolean shouldShow) { + public void setSuggestedWords(final SuggestedWords suggestedWords, + final boolean isSuggestionStripVisible, final boolean needsInputViewShown) { mInputLogic.setSuggestedWords(suggestedWords); - if (mSuggestionStripView != null) { - final boolean showSuggestions; - if (SuggestedWords.EMPTY == suggestedWords - || suggestedWords.isPunctuationSuggestions() - || !mSettings.getCurrent().isSuggestionsRequested()) { - showSuggestions = !mSuggestionStripView.maybeShowImportantNoticeTitle(); - } else { - showSuggestions = true; - } - if (showSuggestions) { - mSuggestionStripView.setSuggestions(suggestedWords, - SubtypeLocaleUtils.isRtlLanguage(mSubtypeSwitcher.getCurrentSubtype())); - } - mKeyboardSwitcher.onAutoCorrectionStateChanged(suggestedWords.mWillAutoCorrect); - setSuggestionStripShownInternal(shouldShow, true /* needsInputViewShown */); + if (!hasSuggestionStripView()) { + return; + } + final SettingsValues currentSettings = mSettings.getCurrent(); + final boolean showSuggestions; + if (SuggestedWords.EMPTY == suggestedWords + || suggestedWords.isPunctuationSuggestions() + || !currentSettings.isSuggestionsRequested()) { + showSuggestions = !mSuggestionStripView.maybeShowImportantNoticeTitle( + currentSettings.mInputAttributes); + } else { + showSuggestions = true; + } + if (showSuggestions) { + mSuggestionStripView.setSuggestions(suggestedWords, + SubtypeLocaleUtils.isRtlLanguage(mSubtypeSwitcher.getCurrentSubtype())); } + mKeyboardSwitcher.onAutoCorrectionStateChanged(suggestedWords.mWillAutoCorrect); + setSuggestionStripShownInternal(isSuggestionStripVisible, needsInputViewShown); } // TODO[IL]: Move this out of LatinIME. @@ -1404,9 +1411,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } suggest.getSuggestedWords(mInputLogic.mWordComposer, mInputLogic.mWordComposer.getPreviousWordForSuggestion(), - keyboard.getProximityInfo(), - currentSettings.mBlockPotentiallyOffensive, currentSettings.mCorrectionEnabled, - additionalFeaturesOptions, sessionId, sequenceNumber, callback); + keyboard.getProximityInfo(), currentSettings.mBlockPotentiallyOffensive, + currentSettings.mCorrectionEnabled, additionalFeaturesOptions, sessionId, + sequenceNumber, callback); } // TODO[IL]: Move this to InputLogic @@ -1420,7 +1427,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // the "add to dictionary" hint, we need to revert to suggestions - although it is unclear // how we can come here if it's displayed. if (suggestedWords.size() > 1 || typedWord.length() <= 1 - || null == mSuggestionStripView || isShowingAddToDictionaryHint()) { + || !hasSuggestionStripView() || isShowingAddToDictionaryHint()) { return suggestedWords; } else { final SuggestedWords punctuationList = @@ -1430,10 +1437,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions = SuggestedWords.getTypedWordAndPreviousSuggestions(typedWord, oldSuggestedWords); return new SuggestedWords(typedWordAndPreviousSuggestions, null /* rawSuggestions */, - false /* typedWordValid */, - false /* hasAutoCorrectionCandidate */, - true /* isObsoleteSuggestions */, - false /* isPrediction */); + false /* typedWordValid */, false /* hasAutoCorrectionCandidate */, + true /* isObsoleteSuggestions */, false /* isPrediction */); } } @@ -1453,7 +1458,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen setNeutralSuggestionStrip(); } else { mInputLogic.mWordComposer.setAutoCorrection(autoCorrection); - setSuggestedWords(suggestedWords, isSuggestionsStripVisible()); + setSuggestedWords( + suggestedWords, isSuggestionStripVisible(), true /* needsInputViewShown */); } // Cache the auto-correction in accessibility code so we can speak it if the user // touches a key that will insert it. @@ -1471,7 +1477,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen @Override public void showAddToDictionaryHint(final String word) { - if (null == mSuggestionStripView) return; + if (!hasSuggestionStripView()) { + return; + } mSuggestionStripView.showAddToDictionaryHint(word); } @@ -1480,13 +1488,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // punctuation suggestions (if it's disabled). @Override public void setNeutralSuggestionStrip() { + setNeutralSuggestionStripInternal(true /* needsInputViewShown */); + } + + private void setNeutralSuggestionStripInternal(final boolean needsInputViewShown) { final SettingsValues currentSettings = mSettings.getCurrent(); - if (currentSettings.mBigramPredictionEnabled) { - setSuggestedWords(SuggestedWords.EMPTY, isSuggestionsStripVisible()); - } else { - setSuggestedWords(currentSettings.mSpacingAndPunctuations.mSuggestPuncList, - isSuggestionsStripVisible()); - } + final SuggestedWords neutralSuggestions = currentSettings.mBigramPredictionEnabled + ? SuggestedWords.EMPTY : currentSettings.mSpacingAndPunctuations.mSuggestPuncList; + setSuggestedWords(neutralSuggestions, isSuggestionStripVisible(), needsInputViewShown); } // TODO: Make this private @@ -1612,13 +1621,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen launchSubActivity(SettingsActivity.class); } - public void launchKeyboardedDialogActivity(final Class<? extends Activity> activityClass) { - // Put the text in the attached EditText into a safe, saved state before switching to a - // new activity that will also use the soft keyboard. - mInputLogic.commitTyped(mSettings.getCurrent(), LastComposedWord.NOT_A_SEPARATOR); - launchSubActivity(activityClass); - } - private void launchSubActivity(final Class<? extends Activity> activityClass) { Intent intent = new Intent(); intent.setClass(LatinIME.this, activityClass); @@ -1682,7 +1684,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // TODO: can this be removed somehow without breaking the tests? @UsedForTesting - /* package for test */ SuggestedWords getSuggestedWords() { + /* package for test */ SuggestedWords getSuggestedWordsForTest() { // You may not use this method for anything else than debug return DEBUG ? mInputLogic.mSuggestedWords : null; } |