diff options
Diffstat (limited to 'java/src')
16 files changed, 82 insertions, 378 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java index 7f4631b2d..9a3ac674e 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java @@ -27,7 +27,6 @@ import com.android.inputmethod.latin.common.Constants; import com.android.inputmethod.latin.common.FileUtils; import com.android.inputmethod.latin.common.InputPointers; import com.android.inputmethod.latin.common.StringUtils; -import com.android.inputmethod.latin.define.DecoderSpecificConstants; import com.android.inputmethod.latin.makedict.DictionaryHeader; import com.android.inputmethod.latin.makedict.FormatSpec; import com.android.inputmethod.latin.makedict.FormatSpec.DictionaryOptions; @@ -330,7 +329,9 @@ public final class BinaryDictionary extends Dictionary { if (len > 0) { suggestions.add(new SuggestedWordInfo( new String(session.mOutputCodePoints, start, len), - (int)(session.mOutputScores[j] * weightForLocale), session.mOutputTypes[j], + "" /* prevWordsContext */, + (int)(session.mOutputScores[j] * weightForLocale), + session.mOutputTypes[j], this /* sourceDict */, session.mSpaceIndices[j] /* indexOfTouchPointOfSecondWord */, session.mOutputAutoCommitFirstWordConfidence[0])); diff --git a/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java b/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java index 5f981a009..6b49f9aa6 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java +++ b/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java @@ -89,6 +89,24 @@ public interface DictionaryFacilitator { void onUpdateMainDictionaryAvailability(boolean isMainDictionaryAvailable); } + /** + * Called every time {@link LatinIME} starts on a new text field. + * Dot not affect {@link AndroidSpellCheckerService}. + * + * WARNING: The service methods that call start/finish are very spammy. + */ + void onStartInput(); + + /** + * Called every time the {@link LatinIME} finishes with the current text field. + * May be followed by {@link #onStartInput} again in another text field, + * or it may be done for a while. + * Dot not affect {@link AndroidSpellCheckerService}. + * + * WARNING: The service methods that call start/finish are very spammy. + */ + void onFinishInput(); + boolean isActive(); Locale getLocale(); diff --git a/java/src/com/android/inputmethod/latin/DictionaryFacilitatorImpl.java b/java/src/com/android/inputmethod/latin/DictionaryFacilitatorImpl.java index a59253aad..e5d770aee 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryFacilitatorImpl.java +++ b/java/src/com/android/inputmethod/latin/DictionaryFacilitatorImpl.java @@ -202,6 +202,15 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator { public DictionaryFacilitatorImpl() { } + @Override + public void onStartInput() { + } + + @Override + public void onFinishInput() { + } + + @Override public boolean isActive() { return mDictionaryGroup.mLocale != null; } diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java index fa8fb2028..80daedd50 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java @@ -121,8 +121,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { private static boolean needsToMigrateDictionary(final int formatVersion) { // When we bump up the dictionary format version, the old version should be added to here // for supporting migration. Note that native code has to support reading such formats. - return formatVersion == FormatSpec.VERSION4_ONLY_FOR_TESTING - || formatVersion == FormatSpec.VERSION402; + return formatVersion == FormatSpec.VERSION402; } public boolean isValidDictionaryLocked() { diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index a8aeb8795..330be377b 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -792,6 +792,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen @SuppressWarnings("deprecation") void onStartInputViewInternal(final EditorInfo editorInfo, final boolean restarting) { super.onStartInputView(editorInfo, restarting); + + mDictionaryFacilitator.onStartInput(); // Switch to the null consumer to handle cases leading to early exit below, for which we // also wouldn't be consuming gesture data. mGestureConsumer = GestureConsumer.NULL_GESTURE_CONSUMER; @@ -970,6 +972,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen void onFinishInputInternal() { super.onFinishInput(); + mDictionaryFacilitator.onFinishInput(); final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView(); if (mainKeyboardView != null) { mainKeyboardView.closing(); @@ -1383,7 +1386,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen @Override public void onUpdateBatchInput(final InputPointers batchPointers) { - mInputLogic.onUpdateBatchInput(mSettings.getCurrent(), batchPointers, mKeyboardSwitcher); + mInputLogic.onUpdateBatchInput(batchPointers); } @Override @@ -1407,7 +1410,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen */ public void onTailBatchInputResultShown(final SuggestedWords suggestedWords) { mGestureConsumer.onImeSuggestionsProcessed(suggestedWords, - mInputLogic.getComposingStart(), mInputLogic.getComposingLength()); + mInputLogic.getComposingStart(), mInputLogic.getComposingLength(), + mDictionaryFacilitator); } // This method must run on the UI Thread. @@ -1537,7 +1541,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen setSuggestedWords(neutralSuggestions); } - // TODO: Make this private // Outside LatinIME, only used by the {@link InputTestsBase} test suite. @UsedForTesting void loadKeyboard() { @@ -1768,7 +1771,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen dialog.show(); } - // TODO: can this be removed somehow without breaking the tests? @UsedForTesting SuggestedWords getSuggestedWordsForTest() { // You may not use this method for anything else than debug diff --git a/java/src/com/android/inputmethod/latin/PunctuationSuggestions.java b/java/src/com/android/inputmethod/latin/PunctuationSuggestions.java index c9b6d6b70..e2c562174 100644 --- a/java/src/com/android/inputmethod/latin/PunctuationSuggestions.java +++ b/java/src/com/android/inputmethod/latin/PunctuationSuggestions.java @@ -114,7 +114,8 @@ public final class PunctuationSuggestions extends SuggestedWords { } private static SuggestedWordInfo newHardCodedWordInfo(final String keySpec) { - return new SuggestedWordInfo(keySpec, SuggestedWordInfo.MAX_SCORE, + return new SuggestedWordInfo(keySpec, "" /* prevWordsContext */, + SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_HARDCODED, Dictionary.DICTIONARY_HARDCODED, SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */, diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 8562acd83..7ccefd2dd 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -36,7 +36,6 @@ import java.util.HashMap; import java.util.Locale; import javax.annotation.Nonnull; -import javax.annotation.Nullable; /** * This class loads a dictionary and provides a list of suggestions for a given sequence of @@ -249,7 +248,8 @@ public final class Suggest { } final SuggestedWordInfo typedWordInfo = new SuggestedWordInfo(typedWordString, - SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_TYPED, + "" /* prevWordsContext */, SuggestedWordInfo.MAX_SCORE, + SuggestedWordInfo.KIND_TYPED, null == sourceDictionaryOfRemovedWord ? Dictionary.DICTIONARY_USER_TYPED : sourceDictionaryOfRemovedWord, SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */, @@ -426,7 +426,8 @@ public final class Suggest { for (int i = quotesToAppend - 1; i >= 0; --i) { sb.appendCodePoint(Constants.CODE_SINGLE_QUOTE); } - return new SuggestedWordInfo(sb.toString(), wordInfo.mScore, wordInfo.mKindAndFlags, + return new SuggestedWordInfo(sb.toString(), wordInfo.mPrevWordsContext, + wordInfo.mScore, wordInfo.mKindAndFlags, wordInfo.mSourceDict, wordInfo.mIndexOfTouchPointOfSecondWord, wordInfo.mAutoCommitFirstWordConfidence); } diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index 87fe29159..bcd4d5f69 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -17,11 +17,9 @@ package com.android.inputmethod.latin; import android.text.TextUtils; -import android.util.Log; import android.view.inputmethod.CompletionInfo; import com.android.inputmethod.annotations.UsedForTesting; -import com.android.inputmethod.latin.common.Constants; import com.android.inputmethod.latin.common.StringUtils; import com.android.inputmethod.latin.define.DebugFlags; @@ -264,6 +262,7 @@ public class SuggestedWords { public static final int KIND_FLAG_APPROPRIATE_FOR_AUTO_CORRECTION = 0x10000000; public final String mWord; + public final String mPrevWordsContext; // The completion info from the application. Null for suggestions that don't come from // the application (including keyboard-computed ones, so this is almost always null) public final CompletionInfo mApplicationSpecifiedCompletionInfo; @@ -284,6 +283,7 @@ public class SuggestedWords { /** * Create a new suggested word info. * @param word The string to suggest. + * @param prevWordsContext previous words context. * @param score A measure of how likely this suggestion is. * @param kindAndFlags The kind of suggestion, as one of the above KIND_* constants with * flags. @@ -291,10 +291,12 @@ public class SuggestedWords { * @param indexOfTouchPointOfSecondWord See mIndexOfTouchPointOfSecondWord. * @param autoCommitFirstWordConfidence See mAutoCommitFirstWordConfidence. */ - public SuggestedWordInfo(final String word, final int score, final int kindAndFlags, + public SuggestedWordInfo(final String word, final String prevWordsContext, + final int score, final int kindAndFlags, final Dictionary sourceDict, final int indexOfTouchPointOfSecondWord, final int autoCommitFirstWordConfidence) { mWord = word; + mPrevWordsContext = prevWordsContext; mApplicationSpecifiedCompletionInfo = null; mScore = score; mKindAndFlags = kindAndFlags; @@ -311,6 +313,7 @@ public class SuggestedWords { */ public SuggestedWordInfo(final CompletionInfo applicationSpecifiedCompletion) { mWord = applicationSpecifiedCompletion.getText().toString(); + mPrevWordsContext = ""; mApplicationSpecifiedCompletionInfo = applicationSpecifiedCompletion; mScore = SuggestedWordInfo.MAX_SCORE; mKindAndFlags = SuggestedWordInfo.KIND_APP_DEFINED; @@ -429,27 +432,6 @@ public class SuggestedWords { return isPrediction(mInputStyle); } - // Creates a new SuggestedWordInfo from the currently suggested words that removes all but the - // last word of all suggestions, separated by a space. This is necessary because when we commit - // a multiple-word suggestion, the IME only retains the last word as the composing word, and - // we should only suggest replacements for this last word. - // TODO: make this work with languages without spaces. - public SuggestedWords getSuggestedWordsForLastWordOfPhraseGesture() { - final ArrayList<SuggestedWordInfo> newSuggestions = new ArrayList<>(); - for (int i = 0; i < mSuggestedWordInfoList.size(); ++i) { - final SuggestedWordInfo info = mSuggestedWordInfoList.get(i); - final int indexOfLastSpace = info.mWord.lastIndexOf(Constants.CODE_SPACE) + 1; - final String lastWord = info.mWord.substring(indexOfLastSpace); - newSuggestions.add(new SuggestedWordInfo(lastWord, info.mScore, info.mKindAndFlags, - info.mSourceDict, SuggestedWordInfo.NOT_AN_INDEX, - SuggestedWordInfo.NOT_A_CONFIDENCE)); - } - return new SuggestedWords(newSuggestions, null /* rawSuggestions */, - newSuggestions.isEmpty() ? null : newSuggestions.get(0) /* typedWordInfo */, - mTypedWordValid, mWillAutoCorrect, mIsObsoleteSuggestions, INPUT_STYLE_TAIL_BATCH, - NOT_A_SEQUENCE_NUMBER); - } - /** * @return the {@link SuggestedWordInfo} which corresponds to the word that is originally * typed by the user. Otherwise returns {@code null}. Note that gesture input is not diff --git a/java/src/com/android/inputmethod/latin/debug/ExternalDictionaryGetterForDebug.java b/java/src/com/android/inputmethod/latin/debug/ExternalDictionaryGetterForDebug.java deleted file mode 100644 index 8cc3552ed..000000000 --- a/java/src/com/android/inputmethod/latin/debug/ExternalDictionaryGetterForDebug.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright (C) 2013 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.debug; - -import android.app.AlertDialog; -import android.content.Context; -import android.content.DialogInterface; -import android.content.DialogInterface.OnCancelListener; -import android.content.DialogInterface.OnClickListener; -import android.os.Environment; - -import com.android.inputmethod.latin.BinaryDictionaryFileDumper; -import com.android.inputmethod.latin.BinaryDictionaryGetter; -import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.common.LocaleUtils; -import com.android.inputmethod.latin.makedict.DictionaryHeader; -import com.android.inputmethod.latin.utils.DialogUtils; -import com.android.inputmethod.latin.utils.DictionaryInfoUtils; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Locale; - -/** - * A class to read a local file as a dictionary for debugging purposes. - */ -public class ExternalDictionaryGetterForDebug { - static final String SOURCE_FOLDER = Environment.getExternalStorageDirectory().getPath() - + "/Download"; - - private static String[] findDictionariesInTheDownloadedFolder() { - final File[] files = new File(SOURCE_FOLDER).listFiles(); - final ArrayList<String> eligibleList = new ArrayList<>(); - for (File f : files) { - final DictionaryHeader header = DictionaryInfoUtils.getDictionaryFileHeaderOrNull(f); - if (null == header) continue; - eligibleList.add(f.getName()); - } - return eligibleList.toArray(new String[0]); - } - - public static void chooseAndInstallDictionary(final Context context) { - final String[] fileNames = findDictionariesInTheDownloadedFolder(); - if (0 == fileNames.length) { - showNoFileDialog(context); - } else if (1 == fileNames.length) { - askInstallFile(context, SOURCE_FOLDER, fileNames[0], null /* completeRunnable */); - } else { - showChooseFileDialog(context, fileNames); - } - } - - private static void showNoFileDialog(final Context context) { - new AlertDialog.Builder(DialogUtils.getPlatformDialogThemeContext(context)) - .setMessage(R.string.read_external_dictionary_no_files_message) - .setPositiveButton(android.R.string.ok, new OnClickListener() { - @Override - public void onClick(final DialogInterface dialog, final int which) { - dialog.dismiss(); - } - }).create().show(); - } - - private static void showChooseFileDialog(final Context context, final String[] fileNames) { - new AlertDialog.Builder(DialogUtils.getPlatformDialogThemeContext(context)) - .setTitle(R.string.read_external_dictionary_multiple_files_title) - .setItems(fileNames, new OnClickListener() { - @Override - public void onClick(final DialogInterface dialog, final int which) { - askInstallFile(context, SOURCE_FOLDER, fileNames[which], - null /* completeRunnable */); - } - }) - .create().show(); - } - - /** - * Shows a dialog which offers the user to install the external dictionary. - */ - public static void askInstallFile(final Context context, final String dirPath, - final String fileName, final Runnable completeRunnable) { - final File file = new File(dirPath, fileName.toString()); - final DictionaryHeader header = DictionaryInfoUtils.getDictionaryFileHeaderOrNull(file); - final StringBuilder message = new StringBuilder(); - final String localeString = header.mLocaleString; - for (final String key : header.mDictionaryOptions.mAttributes.keySet()) { - message.append(key + " = " + header.mDictionaryOptions.mAttributes.get(key)); - message.append("\n"); - } - final String languageName = LocaleUtils.constructLocaleFromString(localeString) - .getDisplayName(Locale.getDefault()); - final String title = String.format( - context.getString(R.string.read_external_dictionary_confirm_install_message), - languageName); - new AlertDialog.Builder(DialogUtils.getPlatformDialogThemeContext(context)) - .setTitle(title) - .setMessage(message) - .setNegativeButton(android.R.string.cancel, new OnClickListener() { - @Override - public void onClick(final DialogInterface dialog, final int which) { - dialog.dismiss(); - if (completeRunnable != null) { - completeRunnable.run(); - } - } - }).setPositiveButton(android.R.string.ok, new OnClickListener() { - @Override - public void onClick(final DialogInterface dialog, final int which) { - installFile(context, file, header); - dialog.dismiss(); - if (completeRunnable != null) { - completeRunnable.run(); - } - } - }).setOnCancelListener(new OnCancelListener() { - @Override - public void onCancel(DialogInterface dialog) { - // Canceled by the user by hitting the back key - if (completeRunnable != null) { - completeRunnable.run(); - } - } - }).create().show(); - } - - static void installFile(final Context context, final File file, final DictionaryHeader header) { - BufferedOutputStream outputStream = null; - File tempFile = null; - try { - final String localeString = header.mLocaleString; - // Create the id for a main dictionary for this locale - final String id = BinaryDictionaryGetter.MAIN_DICTIONARY_CATEGORY - + BinaryDictionaryGetter.ID_CATEGORY_SEPARATOR + localeString; - final String finalFileName = DictionaryInfoUtils.getCacheFileName( - id, localeString, context); - final String tempFileName = BinaryDictionaryGetter.getTempFileName(id, context); - tempFile = new File(tempFileName); - tempFile.delete(); - outputStream = new BufferedOutputStream(new FileOutputStream(tempFile)); - final BufferedInputStream bufferedStream = new BufferedInputStream( - new FileInputStream(file)); - BinaryDictionaryFileDumper.checkMagicAndCopyFileTo(bufferedStream, outputStream); - outputStream.flush(); - final File finalFile = new File(finalFileName); - finalFile.delete(); - if (!tempFile.renameTo(finalFile)) { - throw new IOException("Can't move the file to its final name"); - } - } catch (IOException e) { - // There was an error: show a dialog - new AlertDialog.Builder(DialogUtils.getPlatformDialogThemeContext(context)) - .setTitle(R.string.read_external_dictionary_error) - .setMessage(e.toString()) - .setPositiveButton(android.R.string.ok, new OnClickListener() { - @Override - public void onClick(final DialogInterface dialog, final int which) { - dialog.dismiss(); - } - }).create().show(); - return; - } finally { - try { - if (null != outputStream) outputStream.close(); - if (null != tempFile) tempFile.delete(); - } catch (IOException e) { - // Don't do anything - } - } - } -} diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index 00175f024..5b3b28d75 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -225,9 +225,7 @@ public final class InputLogic { * @return the complete transaction object */ public InputTransaction onTextInput(final SettingsValues settingsValues, final Event event, - final int keyboardShiftMode, - // TODO: remove this argument - final LatinIME.UIHandler handler) { + final int keyboardShiftMode, final LatinIME.UIHandler handler) { final String rawText = event.getTextToCommit().toString(); final InputTransaction inputTransaction = new InputTransaction(settingsValues, event, SystemClock.uptimeMillis(), mSpaceState, @@ -266,12 +264,14 @@ public final class InputLogic { // interface public InputTransaction onPickSuggestionManually(final SettingsValues settingsValues, final SuggestedWordInfo suggestionInfo, final int keyboardShiftState, - // TODO: remove these arguments final int currentKeyboardScriptId, final LatinIME.UIHandler handler) { final SuggestedWords suggestedWords = mSuggestedWords; final String suggestion = suggestionInfo.mWord; // If this is a punctuation picked from the suggestion strip, pass it to onCodeInput if (suggestion.length() == 1 && suggestedWords.isPunctuationSuggestions()) { + // We still want to log a suggestion click. + StatsUtils.onPickSuggestionManually( + mSuggestedWords, suggestionInfo, mDictionaryFacilitator); // Word separators are suggested before the user inputs something. // Rely on onCodeInput to do the complicated swapping/stripping logic consistently. final Event event = Event.createPunctuationSuggestionPickedEvent(suggestionInfo); @@ -419,7 +419,6 @@ public final class InputLogic { */ public InputTransaction onCodeInput(final SettingsValues settingsValues, @Nonnull final Event event, final int keyboardShiftMode, - // TODO: remove these arguments final int currentKeyboardScriptId, final LatinIME.UIHandler handler) { final Event processedEvent = mWordComposer.processEvent(event); final InputTransaction inputTransaction = new InputTransaction(settingsValues, @@ -466,7 +465,6 @@ public final class InputLogic { } public void onStartBatchInput(final SettingsValues settingsValues, - // TODO: remove these arguments final KeyboardSwitcher keyboardSwitcher, final LatinIME.UIHandler handler) { mInputLogicHandler.onStartBatchInput(); handler.showGesturePreviewAndSuggestionStrip( @@ -530,10 +528,7 @@ public final class InputLogic { * earlier sequence number. */ private int mAutoCommitSequenceNumber = 1; - public void onUpdateBatchInput(final SettingsValues settingsValues, - final InputPointers batchPointers, - // TODO: remove these arguments - final KeyboardSwitcher keyboardSwitcher) { + public void onUpdateBatchInput(final InputPointers batchPointers) { mInputLogicHandler.onUpdateBatchInput(batchPointers, mAutoCommitSequenceNumber); } @@ -542,7 +537,6 @@ public final class InputLogic { ++mAutoCommitSequenceNumber; } - // TODO: remove this argument public void onCancelBatchInput(final LatinIME.UIHandler handler) { mInputLogicHandler.onCancelBatchInput(); handler.showGesturePreviewAndSuggestionStrip( @@ -618,7 +612,6 @@ public final class InputLogic { * @param inputTransaction The transaction in progress. */ private void handleFunctionalEvent(final Event event, final InputTransaction inputTransaction, - // TODO: remove these arguments final int currentKeyboardScriptId, final LatinIME.UIHandler handler) { switch (event.mKeyCode) { case Constants.CODE_DELETE: @@ -670,7 +663,6 @@ public final class InputLogic { // handled in {@link KeyboardState#onEvent(Event,int)}. break; case Constants.CODE_SHIFT_ENTER: - // TODO: remove this object final Event tmpEvent = Event.createSoftwareKeypressEvent(Constants.CODE_ENTER, event.mKeyCode, event.mX, event.mY, event.isKeyRepeat()); handleNonSpecialCharacterEvent(tmpEvent, inputTransaction, handler); @@ -694,7 +686,6 @@ public final class InputLogic { */ private void handleNonFunctionalEvent(final Event event, final InputTransaction inputTransaction, - // TODO: remove this argument final LatinIME.UIHandler handler) { inputTransaction.setDidAffectContents(); switch (event.mCodePoint) { @@ -740,7 +731,6 @@ public final class InputLogic { */ private void handleNonSpecialCharacterEvent(final Event event, final InputTransaction inputTransaction, - // TODO: remove this argument final LatinIME.UIHandler handler) { final int codePoint = event.mCodePoint; mSpaceState = SpaceState.NONE; @@ -846,7 +836,6 @@ public final class InputLogic { * @param inputTransaction The transaction in progress. */ private void handleSeparatorEvent(final Event event, final InputTransaction inputTransaction, - // TODO: remove this argument final LatinIME.UIHandler handler) { final int codePoint = event.mCodePoint; final SettingsValues settingsValues = inputTransaction.mSettingsValues; @@ -954,7 +943,6 @@ public final class InputLogic { * @param inputTransaction The transaction in progress. */ private void handleBackspaceEvent(final Event event, final InputTransaction inputTransaction, - // TODO: remove this argument, put it into settingsValues final int currentKeyboardScriptId) { mSpaceState = SpaceState.NONE; mDeleteCount++; @@ -1158,7 +1146,6 @@ public final class InputLogic { settingsValues.mSpacingAndPunctuations, currentKeyboardScriptId); if (range == null) { - // TODO(zivkovic): Check for bad connection before getting this far. // Happens if we don't have an input connection at all. return false; } @@ -1408,7 +1395,8 @@ public final class InputLogic { public void onGetSuggestedWords(final SuggestedWords suggestedWords) { final String typedWordString = mWordComposer.getTypedWord(); final SuggestedWordInfo typedWordInfo = new SuggestedWordInfo( - typedWordString, SuggestedWordInfo.MAX_SCORE, + typedWordString, "" /* prevWordsContext */, + SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_TYPED, Dictionary.DICTIONARY_USER_TYPED, SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */, SuggestedWordInfo.NOT_A_CONFIDENCE); @@ -1441,7 +1429,6 @@ public final class InputLogic { * to a cursor move, for example). In ICS, there is a platform bug that we need to work * around only when we come here at input start time. */ - // TODO: make this private. public void restartSuggestionsOnWordTouchedByCursor(final SettingsValues settingsValues, final boolean forStartInput, // TODO: remove this argument, put it into settingsValues @@ -1492,7 +1479,7 @@ public final class InputLogic { final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<>(); final String typedWordString = range.mWord.toString(); final SuggestedWordInfo typedWordInfo = new SuggestedWordInfo(typedWordString, - SuggestedWords.MAX_SUGGESTIONS + 1, + "" /* prevWordsContext */, SuggestedWords.MAX_SUGGESTIONS + 1, SuggestedWordInfo.KIND_TYPED, Dictionary.DICTIONARY_USER_TYPED, SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */, SuggestedWordInfo.NOT_A_CONFIDENCE /* autoCommitFirstWordConfidence */); @@ -1507,7 +1494,7 @@ public final class InputLogic { ++i; if (!TextUtils.equals(s, typedWordString)) { suggestions.add(new SuggestedWordInfo(s, - SuggestedWords.MAX_SUGGESTIONS - i, + "" /* prevWordsContext */, SuggestedWords.MAX_SUGGESTIONS - i, SuggestedWordInfo.KIND_RESUMED, Dictionary.DICTIONARY_RESUMED, SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */, SuggestedWordInfo.NOT_A_CONFIDENCE @@ -1721,7 +1708,6 @@ public final class InputLogic { * @param nthPreviousWord reverse index of the word to get (1-indexed) * @return the information of previous words */ - // TODO: Make this private public NgramContext getNgramContextFromNthPreviousWordForSuggestion( final SpacingAndPunctuations spacingAndPunctuations, final int nthPreviousWord) { if (spacingAndPunctuations.mCurrentLanguageHasSpaces) { @@ -1951,9 +1937,7 @@ public final class InputLogic { * @param suggestedWords suggestedWords to use. */ public void onUpdateTailBatchInputCompleted(final SettingsValues settingsValues, - final SuggestedWords suggestedWords, - // TODO: remove this argument - final KeyboardSwitcher keyboardSwitcher) { + final SuggestedWords suggestedWords, final KeyboardSwitcher keyboardSwitcher) { final String batchInputText = suggestedWords.isEmpty() ? null : suggestedWords.getWord(0); if (TextUtils.isEmpty(batchInputText)) { return; @@ -1986,7 +1970,6 @@ public final class InputLogic { * @param settingsValues the current values of the settings. * @param separatorString the separator that's causing the commit, or NOT_A_SEPARATOR if none. */ - // TODO: Make this private public void commitTyped(final SettingsValues settingsValues, final String separatorString) { if (!mWordComposer.isComposingWord()) return; final String typedWord = mWordComposer.getTypedWord(); @@ -2015,9 +1998,7 @@ public final class InputLogic { * @param separator the separator that's causing the commit to happen. */ private void commitCurrentAutoCorrection(final SettingsValues settingsValues, - final String separator, - // TODO: Remove this argument. - final LatinIME.UIHandler handler) { + final String separator, final LatinIME.UIHandler handler) { // Complete any pending suggestions query first if (handler.hasPendingUpdateSuggestions()) { handler.cancelUpdateSuggestionStrip(); @@ -2053,8 +2034,11 @@ public final class InputLogic { mConnection.commitCorrection(new CorrectionInfo( mConnection.getExpectedSelectionEnd() - stringToCommit.length(), typedWord, stringToCommit)); + String prevWordsContext = (autoCorrectionOrNull != null) + ? autoCorrectionOrNull.mPrevWordsContext + : ""; StatsUtils.onAutoCorrection(typedWord, stringToCommit, isBatchMode, - mDictionaryFacilitator); + mDictionaryFacilitator, prevWordsContext); StatsUtils.onWordCommitAutoCorrect(stringToCommit, isBatchMode); } else { StatsUtils.onWordCommitUserTyped(stringToCommit, isBatchMode); @@ -2103,11 +2087,8 @@ public final class InputLogic { * @param remainingTries How many times we may try again before giving up. * @return whether true if the caches were successfully reset, false otherwise. */ - // TODO: make this private public boolean retryResetCachesAndReturnSuccess(final boolean tryResumeSuggestions, - final int remainingTries, - // TODO: remove these arguments - final LatinIME.UIHandler handler) { + final int remainingTries, final LatinIME.UIHandler handler) { final boolean shouldFinishComposition = mConnection.hasSelection() || !mConnection.isCursorPositionKnown(); if (!mConnection.resetCachesUponCursorMoveAndReturnSuccess( diff --git a/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java b/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java index 288261bf0..e422c4cd2 100644 --- a/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java +++ b/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java @@ -174,9 +174,6 @@ public final class FormatSpec { public static final int VERSION202 = 202; // format version for Fava Dictionaries. public static final int VERSION_DELIGHT3 = 86736212; - public static final int MINIMUM_SUPPORTED_VERSION_OF_CODE_POINT_TABLE = VERSION201; - // Dictionary version used for testing. - public static final int VERSION4_ONLY_FOR_TESTING = 399; public static final int VERSION402 = 402; public static final int VERSION403 = 403; public static final int VERSION4 = VERSION403; diff --git a/java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java index 48361bf8c..39dcddb95 100644 --- a/java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java +++ b/java/src/com/android/inputmethod/latin/settings/AccountsSettingsFragment.java @@ -132,7 +132,7 @@ public final class AccountsSettingsFragment extends SubScreenFragment { @Override protected Void doInBackground(Void... params) { - if (ManagedProfileUtils.getInstance().hasManagedWorkProfile(mFragment.getActivity())) { + if (ManagedProfileUtils.getInstance().hasWorkProfile(mFragment.getActivity())) { mFragment.removeSyncPreferences(); } else { mFragment.enableSyncPreferences(); diff --git a/java/src/com/android/inputmethod/latin/settings/CorrectionSettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/CorrectionSettingsFragment.java index f7c5f6760..62834cd2a 100644 --- a/java/src/com/android/inputmethod/latin/settings/CorrectionSettingsFragment.java +++ b/java/src/com/android/inputmethod/latin/settings/CorrectionSettingsFragment.java @@ -49,7 +49,7 @@ import java.util.TreeSet; */ public final class CorrectionSettingsFragment extends SubScreenFragment { private static final boolean DBG_USE_INTERNAL_PERSONAL_DICTIONARY_SETTINGS = false; - private static final boolean USE_INTERNAL_PERSONAL_DICTIONARY_SETTIGS = + private static final boolean USE_INTERNAL_PERSONAL_DICTIONARY_SETTINGS = DBG_USE_INTERNAL_PERSONAL_DICTIONARY_SETTINGS || Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR2; @@ -61,8 +61,6 @@ public final class CorrectionSettingsFragment extends SubScreenFragment { final Context context = getActivity(); final PackageManager pm = context.getPackageManager(); - ensureConsistencyOfAutoCorrectionSettings(); - final Preference dictionaryLink = findPreference(Settings.PREF_CONFIGURE_DICTIONARIES_KEY); final Intent intent = dictionaryLink.getIntent(); intent.setClassName(context.getPackageName(), DictionarySettingsActivity.class.getName()); @@ -74,7 +72,7 @@ public final class CorrectionSettingsFragment extends SubScreenFragment { final Preference editPersonalDictionary = findPreference(Settings.PREF_EDIT_PERSONAL_DICTIONARY); final Intent editPersonalDictionaryIntent = editPersonalDictionary.getIntent(); - final ResolveInfo ri = USE_INTERNAL_PERSONAL_DICTIONARY_SETTIGS ? null + final ResolveInfo ri = USE_INTERNAL_PERSONAL_DICTIONARY_SETTINGS ? null : pm.resolveActivity( editPersonalDictionaryIntent, PackageManager.MATCH_DEFAULT_ONLY); if (ri == null) { @@ -82,19 +80,6 @@ public final class CorrectionSettingsFragment extends SubScreenFragment { } } - @Override - public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) { - ensureConsistencyOfAutoCorrectionSettings(); - } - - private void ensureConsistencyOfAutoCorrectionSettings() { - final TwoStatePreference autoCorrectionPref = (TwoStatePreference) - findPreference(Settings.PREF_AUTO_CORRECTION); - if (!autoCorrectionPref.isChecked()) { - setPreferenceEnabled(Settings.PREF_BIGRAM_PREDICTIONS, false); - } - } - private void overwriteUserDictionaryPreference(final Preference userDictionaryPreference) { final Activity activity = getActivity(); final TreeSet<String> localeList = UserDictionaryList.getUserDictionaryLocalesSet(activity); diff --git a/java/src/com/android/inputmethod/latin/settings/DebugSettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/DebugSettingsFragment.java index a56de1f69..37855377d 100644 --- a/java/src/com/android/inputmethod/latin/settings/DebugSettingsFragment.java +++ b/java/src/com/android/inputmethod/latin/settings/DebugSettingsFragment.java @@ -30,7 +30,6 @@ import android.preference.TwoStatePreference; import com.android.inputmethod.latin.DictionaryDumpBroadcastReceiver; import com.android.inputmethod.latin.DictionaryFacilitatorImpl; import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.debug.ExternalDictionaryGetterForDebug; import com.android.inputmethod.latin.utils.ApplicationUtils; import com.android.inputmethod.latin.utils.ResourceUtils; @@ -43,12 +42,10 @@ import java.util.Locale; */ public final class DebugSettingsFragment extends SubScreenFragment implements OnPreferenceClickListener { - private static final String PREF_READ_EXTERNAL_DICTIONARY = "read_external_dictionary"; private static final String PREF_KEY_DUMP_DICTS = "pref_key_dump_dictionaries"; private static final String PREF_KEY_DUMP_DICT_PREFIX = "pref_key_dump_dictionaries"; private boolean mServiceNeedsRestart = false; - private Preference mReadExternalDictionaryPref; private TwoStatePreference mDebugMode; @Override @@ -60,11 +57,6 @@ public final class DebugSettingsFragment extends SubScreenFragment removePreference(DebugSettings.PREF_SHOULD_SHOW_LXX_SUGGESTION_UI); } - mReadExternalDictionaryPref = findPreference(PREF_READ_EXTERNAL_DICTIONARY); - if (mReadExternalDictionaryPref != null) { - mReadExternalDictionaryPref.setOnPreferenceClickListener(this); - } - final PreferenceGroup dictDumpPreferenceGroup = (PreferenceGroup)findPreference(PREF_KEY_DUMP_DICTS); for (final String dictName : DictionaryFacilitatorImpl.DICT_TYPE_TO_CLASS.keySet()) { @@ -111,11 +103,6 @@ public final class DebugSettingsFragment extends SubScreenFragment @Override public boolean onPreferenceClick(final Preference pref) { final Context context = getActivity(); - if (pref == mReadExternalDictionaryPref) { - ExternalDictionaryGetterForDebug.chooseAndInstallDictionary(context); - mServiceNeedsRestart = true; - return true; - } if (pref instanceof DictDumpPreference) { final DictDumpPreference dictDumpPref = (DictDumpPreference)pref; final String dictName = dictDumpPref.mDictName; diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java index b98c53af4..f5455e3db 100644 --- a/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java +++ b/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java @@ -16,10 +16,12 @@ package com.android.inputmethod.latin.settings; +import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.preference.Preference; import android.preference.PreferenceScreen; +import android.provider.Settings.Secure; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -68,13 +70,23 @@ public final class SettingsFragment extends InputMethodSettingsFragment { @Override public boolean onOptionsItemSelected(final MenuItem item) { + final Activity activity = getActivity(); + final int setupStatus = Secure.getInt( + activity.getContentResolver(), + "user_setup_complete", + 0 /* default */); + if (setupStatus == 0) { + // If setup is not complete, it's not safe to launch Help or other activities + // because they might go to the Play Store. See b/19866981. + return true; + } final int itemId = item.getItemId(); if (itemId == MENU_HELP_AND_FEEDBACK) { - FeedbackUtils.showHelpAndFeedbackForm(getActivity()); + FeedbackUtils.showHelpAndFeedbackForm(activity); return true; } if (itemId == MENU_ABOUT) { - final Intent aboutIntent = FeedbackUtils.getAboutKeyboardIntent(getActivity()); + final Intent aboutIntent = FeedbackUtils.getAboutKeyboardIntent(activity); if (aboutIntent != null) { startActivity(aboutIntent); return true; diff --git a/java/src/com/android/inputmethod/latin/utils/ManagedProfileUtils.java b/java/src/com/android/inputmethod/latin/utils/ManagedProfileUtils.java deleted file mode 100644 index 1bd8f314c..000000000 --- a/java/src/com/android/inputmethod/latin/utils/ManagedProfileUtils.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2014 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.utils; - -import android.annotation.TargetApi; -import android.content.Context; -import android.os.Build; -import android.os.UserHandle; -import android.os.UserManager; -import android.util.Log; - -import com.android.inputmethod.annotations.UsedForTesting; - -import java.util.List; - -/** - * Utility for determining if the device has managed profiles. - */ -public class ManagedProfileUtils { - private static final boolean DEBUG = false; - private static final String TAG = ManagedProfileUtils.class.getSimpleName(); - - private static ManagedProfileUtils INSTANCE = new ManagedProfileUtils(); - private static ManagedProfileUtils sTestInstance; - - private ManagedProfileUtils() { - // This utility class is not publicly instantiable. - } - - @UsedForTesting - public static void setTestInstance(final ManagedProfileUtils testInstance) { - sTestInstance = testInstance; - } - - public static ManagedProfileUtils getInstance() { - return sTestInstance == null ? INSTANCE : sTestInstance; - } - - /** - * Note that {@link UserManager#getUserProfiles} has been introduced - * in API level 21 (Build.VERSION_CODES.LOLLIPOP). - */ - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public boolean hasManagedWorkProfile(final Context context) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - return false; - } - - final UserManager userManagerService = - (UserManager) context.getSystemService(Context.USER_SERVICE); - if (userManagerService != null) { - if (DEBUG) { - Log.d(TAG, "Detecting managed profile..."); - } - final List<UserHandle> userProfiles = userManagerService.getUserProfiles(); - if (userProfiles.size() > 1) { - if (DEBUG) { - Log.d(TAG, "More than one user profile => Managed profile exists."); - } - return true; - } - } - if (DEBUG) { - Log.d(TAG, "Managed profile not detected."); - } - return false; - } -} |