diff options
Diffstat (limited to 'java/src')
12 files changed, 99 insertions, 67 deletions
diff --git a/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java b/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java index 1e93e7e7a..4b89d20bb 100644 --- a/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java +++ b/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java @@ -304,7 +304,7 @@ public final class DictionarySettingsFragment extends PreferenceFragment // the description. final String key = matchLevelString + "." + description + "." + wordlistId; final WordListPreference existingPref = prefMap.get(key); - if (null == existingPref || hasPriority(status, existingPref.mStatus)) { + if (null == existingPref || existingPref.hasPriorityOver(status)) { final WordListPreference oldPreference = mCurrentPreferenceMap.get(key); final WordListPreference pref; if (null != oldPreference @@ -315,7 +315,7 @@ public final class DictionarySettingsFragment extends PreferenceFragment // need to be the same, others have been tested through the key of the // map. Also, status may differ so we don't want to use #equals() here. pref = oldPreference; - pref.mStatus = status; + pref.setStatus(status); } else { // Otherwise, discard it and create a new one instead. pref = new WordListPreference(activity, mDictionaryListInterfaceState, @@ -331,18 +331,6 @@ public final class DictionarySettingsFragment extends PreferenceFragment } } - /** - * Finds out if a given status has priority over another for display order. - * - * @param newStatus - * @param oldStatus - * @return whether newStatus has priority over oldStatus. - */ - private static boolean hasPriority(final int newStatus, final int oldStatus) { - // Both of these should be one of MetadataDbHelper.STATUS_* - return newStatus > oldStatus; - } - @Override public boolean onOptionsItemSelected(final MenuItem item) { switch (item.getItemId()) { diff --git a/java/src/com/android/inputmethod/dictionarypack/WordListPreference.java b/java/src/com/android/inputmethod/dictionarypack/WordListPreference.java index a1031c2ca..7ec7e9c13 100644 --- a/java/src/com/android/inputmethod/dictionarypack/WordListPreference.java +++ b/java/src/com/android/inputmethod/dictionarypack/WordListPreference.java @@ -61,7 +61,7 @@ public final class WordListPreference extends Preference { public final Locale mLocale; public final String mDescription; // The status - public int mStatus; + private int mStatus; // The size of the dictionary file private final int mFilesize; @@ -92,7 +92,7 @@ public final class WordListPreference extends Preference { setKey(wordlistId); } - private void setStatus(final int status) { + public void setStatus(final int status) { if (status == mStatus) return; mStatus = status; setSummary(getSummary(status)); @@ -106,6 +106,11 @@ public final class WordListPreference extends Preference { return mInterfaceState.addToCacheAndReturnView(newView); } + public boolean hasPriorityOver(final int otherPrefStatus) { + // Both of these should be one of MetadataDbHelper.STATUS_* + return mStatus > otherPrefStatus; + } + private String getSummary(final int status) { switch (status) { // If we are deleting the word list, for the user it's like it's already deleted. diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 83f109014..7295efab1 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -274,30 +274,30 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { // Implements {@link KeyboardState.SwitchActions}. @Override - public void startDoubleTapTimer() { + public void startDoubleTapShiftKeyTimer() { final MainKeyboardView keyboardView = getMainKeyboardView(); if (keyboardView != null) { final TimerProxy timer = keyboardView.getTimerProxy(); - timer.startDoubleTapTimer(); + timer.startDoubleTapShiftKeyTimer(); } } // Implements {@link KeyboardState.SwitchActions}. @Override - public void cancelDoubleTapTimer() { + public void cancelDoubleTapShiftKeyTimer() { final MainKeyboardView keyboardView = getMainKeyboardView(); if (keyboardView != null) { final TimerProxy timer = keyboardView.getTimerProxy(); - timer.cancelDoubleTapTimer(); + timer.cancelDoubleTapShiftKeyTimer(); } } // Implements {@link KeyboardState.SwitchActions}. @Override - public boolean isInDoubleTapTimeout() { + public boolean isInDoubleTapShiftKeyTimeout() { final MainKeyboardView keyboardView = getMainKeyboardView(); return (keyboardView != null) - ? keyboardView.getTimerProxy().isInDoubleTapTimeout() : false; + ? keyboardView.getTimerProxy().isInDoubleTapShiftKeyTimeout() : false; } // Implements {@link KeyboardState.SwitchActions}. diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java index 7493df874..435adb6f5 100644 --- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java @@ -202,7 +202,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack private static final int MSG_TYPING_STATE_EXPIRED = 0; private static final int MSG_REPEAT_KEY = 1; private static final int MSG_LONGPRESS_KEY = 2; - private static final int MSG_DOUBLE_TAP = 3; + private static final int MSG_DOUBLE_TAP_SHIFT_KEY = 3; private static final int MSG_UPDATE_BATCH_INPUT = 4; private final int mKeyRepeatStartTimeout; @@ -392,19 +392,19 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack } @Override - public void startDoubleTapTimer() { - sendMessageDelayed(obtainMessage(MSG_DOUBLE_TAP), + public void startDoubleTapShiftKeyTimer() { + sendMessageDelayed(obtainMessage(MSG_DOUBLE_TAP_SHIFT_KEY), ViewConfiguration.getDoubleTapTimeout()); } @Override - public void cancelDoubleTapTimer() { - removeMessages(MSG_DOUBLE_TAP); + public void cancelDoubleTapShiftKeyTimer() { + removeMessages(MSG_DOUBLE_TAP_SHIFT_KEY); } @Override - public boolean isInDoubleTapTimeout() { - return hasMessages(MSG_DOUBLE_TAP); + public boolean isInDoubleTapShiftKeyTimeout() { + return hasMessages(MSG_DOUBLE_TAP_SHIFT_KEY); } @Override diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 5df7011cb..a28bd1a1e 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -94,9 +94,9 @@ public final class PointerTracker implements PointerTrackerQueue.Element { public void startLongPressTimer(PointerTracker tracker); public void startLongPressTimer(int code); public void cancelLongPressTimer(); - public void startDoubleTapTimer(); - public void cancelDoubleTapTimer(); - public boolean isInDoubleTapTimeout(); + public void startDoubleTapShiftKeyTimer(); + public void cancelDoubleTapShiftKeyTimer(); + public boolean isInDoubleTapShiftKeyTimeout(); public void cancelKeyTimers(); public void startUpdateBatchInputTimer(PointerTracker tracker); public void cancelUpdateBatchInputTimer(PointerTracker tracker); @@ -116,11 +116,11 @@ public final class PointerTracker implements PointerTrackerQueue.Element { @Override public void cancelLongPressTimer() {} @Override - public void startDoubleTapTimer() {} + public void startDoubleTapShiftKeyTimer() {} @Override - public void cancelDoubleTapTimer() {} + public void cancelDoubleTapShiftKeyTimer() {} @Override - public boolean isInDoubleTapTimeout() { return false; } + public boolean isInDoubleTapShiftKeyTimeout() { return false; } @Override public void cancelKeyTimers() {} @Override diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java index 9f6374bf7..bb6dec69e 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java @@ -53,9 +53,9 @@ public final class KeyboardState { */ public void requestUpdatingShiftState(); - public void startDoubleTapTimer(); - public boolean isInDoubleTapTimeout(); - public void cancelDoubleTapTimer(); + public void startDoubleTapShiftKeyTimer(); + public boolean isInDoubleTapShiftKeyTimeout(); + public void cancelDoubleTapShiftKeyTimer(); public void startLongPressTimer(int code); public void cancelLongPressTimer(); } @@ -325,7 +325,7 @@ public final class KeyboardState { } else if (code == Constants.CODE_SWITCH_ALPHA_SYMBOL) { onPressSymbol(); } else { - mSwitchActions.cancelDoubleTapTimer(); + mSwitchActions.cancelDoubleTapShiftKeyTimer(); mSwitchActions.cancelLongPressTimer(); mLongPressShiftLockFired = false; mShiftKeyState.onOtherKeyPressed(); @@ -450,10 +450,10 @@ public final class KeyboardState { // importantly the double tap timer. if (RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE != mRecapitalizeMode) return; if (mIsAlphabetMode) { - mIsInDoubleTapShiftKey = mSwitchActions.isInDoubleTapTimeout(); + mIsInDoubleTapShiftKey = mSwitchActions.isInDoubleTapShiftKeyTimeout(); if (!mIsInDoubleTapShiftKey) { // This is first tap. - mSwitchActions.startDoubleTapTimer(); + mSwitchActions.startDoubleTapShiftKeyTimer(); } if (mIsInDoubleTapShiftKey) { if (mAlphabetShiftState.isManualShifted() || mIsInAlphabetUnshiftedFromShifted) { diff --git a/java/src/com/android/inputmethod/latin/AssetFileAddress.java b/java/src/com/android/inputmethod/latin/AssetFileAddress.java index 47c750f54..875192554 100644 --- a/java/src/com/android/inputmethod/latin/AssetFileAddress.java +++ b/java/src/com/android/inputmethod/latin/AssetFileAddress.java @@ -24,7 +24,7 @@ import java.io.File; * the package file. Open it correctly thus requires the name of the package it is in, but * also the offset in the file and the length of this data. This class encapsulates these three. */ -final class AssetFileAddress { +public final class AssetFileAddress { public final String mFilename; public final long mOffset; public final long mLength; diff --git a/java/src/com/android/inputmethod/latin/DictionaryFactory.java b/java/src/com/android/inputmethod/latin/DictionaryFactory.java index 40e51672a..4514ec2ec 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryFactory.java +++ b/java/src/com/android/inputmethod/latin/DictionaryFactory.java @@ -21,6 +21,8 @@ import android.content.res.AssetFileDescriptor; import android.content.res.Resources; import android.util.Log; +import com.android.inputmethod.annotations.UsedForTesting; + import java.io.File; import java.util.ArrayList; import java.util.LinkedList; @@ -126,21 +128,22 @@ public final class DictionaryFactory { /** * Create a dictionary from passed data. This is intended for unit tests only. - * @param dictionary the file to read - * @param startOffset the offset in the file where the data starts - * @param length the length of the data + * @param dictionaryList the list of files to read, with their offsets and lengths * @param useFullEditDistance whether to use the full edit distance in suggestions * @return the created dictionary, or null. */ - public static Dictionary createDictionaryForTest(File dictionary, long startOffset, long length, + @UsedForTesting + public static Dictionary createDictionaryForTest(final AssetFileAddress[] dictionaryList, final boolean useFullEditDistance, Locale locale) { - if (dictionary.isFile()) { - return new BinaryDictionary(dictionary.getAbsolutePath(), startOffset, length, - useFullEditDistance, locale, Dictionary.TYPE_MAIN); - } else { - Log.e(TAG, "Could not find the file. path=" + dictionary.getAbsolutePath()); - return null; + final DictionaryCollection dictionaryCollection = + new DictionaryCollection(Dictionary.TYPE_MAIN); + for (final AssetFileAddress address : dictionaryList) { + final BinaryDictionary binaryDictionary = new BinaryDictionary(address.mFilename, + address.mOffset, address.mLength, useFullEditDistance, locale, + Dictionary.TYPE_MAIN); + dictionaryCollection.addDictionary(binaryDictionary); } + return dictionaryCollection; } /** diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index c9a42a3a4..98008ac1c 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1637,8 +1637,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen public void onStartBatchInput(final LatinIME latinIme) { synchronized (mLock) { mHandler.removeMessages(MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP); - mLatinIme = latinIme; mInBatchInput = true; + mLatinIme = latinIme; + mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip( + SuggestedWords.EMPTY, false /* dismissGestureFloatingPreviewText */); } } @@ -1797,8 +1799,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { final String word = mWordComposer.getTypedWord(); ResearchLogger.latinIME_handleBackspace_batch(word, 1); - ResearchLogger.getInstance().uncommitCurrentLogUnit( - word, false /* dumpCurrentLogUnit */); } final String rejectedSuggestion = mWordComposer.getTypedWord(); mWordComposer.reset(); @@ -1825,6 +1825,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // like the smiley key or the .com key. final int length = mEnteredText.length(); mConnection.deleteSurroundingText(length, 0); + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { + ResearchLogger.latinIME_handleBackspace_cancelTextInput(mEnteredText); + } mEnteredText = null; // If we have mEnteredText, then we know that mHasUncommittedTypedChars == false. // In addition we know that spaceState is false, and that we should not be @@ -1858,7 +1861,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mLastSelectionEnd = mLastSelectionStart; mConnection.deleteSurroundingText(numCharsDeleted, 0); if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { - ResearchLogger.latinIME_handleBackspace(numCharsDeleted); + ResearchLogger.latinIME_handleBackspace(numCharsDeleted, + false /* shouldUncommitLogUnit */); } } else { // There is no selection, just delete one character. @@ -1876,12 +1880,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mConnection.deleteSurroundingText(1, 0); } if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { - ResearchLogger.latinIME_handleBackspace(1); + ResearchLogger.latinIME_handleBackspace(1, true /* shouldUncommitLogUnit */); } if (mDeleteCount > DELETE_ACCELERATE_AT) { mConnection.deleteSurroundingText(1, 0); if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { - ResearchLogger.latinIME_handleBackspace(1); + ResearchLogger.latinIME_handleBackspace(1, + true /* shouldUncommitLogUnit */); } } } diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 5d580f29b..e783e6d51 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -23,7 +23,6 @@ import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.keyboard.ProximityInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; -import java.io.File; import java.util.ArrayList; import java.util.Comparator; import java.util.HashSet; @@ -77,9 +76,9 @@ public final class Suggest { } @UsedForTesting - Suggest(final File dictionary, final long startOffset, final long length, final Locale locale) { - final Dictionary mainDict = DictionaryFactory.createDictionaryForTest(dictionary, - startOffset, length /* useFullEditDistance */, false, locale); + Suggest(final AssetFileAddress[] dictionaryList, final Locale locale) { + final Dictionary mainDict = DictionaryFactory.createDictionaryForTest(dictionaryList, + false /* useFullEditDistance */, locale); mLocale = locale; mMainDictionary = mainDict; addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_MAIN, mainDict); diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java index 2f2ec3560..e4c5a06a2 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java @@ -208,6 +208,9 @@ final class SuggestionStripLayoutHelper { private CharSequence getStyledSuggestedWord(final SuggestedWords suggestedWords, final int indexInSuggestedWords) { + if (indexInSuggestedWords >= suggestedWords.size()) { + return null; + } final String word = suggestedWords.getWord(indexInSuggestedWords); final boolean isAutoCorrect = indexInSuggestedWords == 1 && suggestedWords.willAutoCorrect(); diff --git a/java/src/com/android/inputmethod/research/ResearchLogger.java b/java/src/com/android/inputmethod/research/ResearchLogger.java index 2da6d0178..57b740b95 100644 --- a/java/src/com/android/inputmethod/research/ResearchLogger.java +++ b/java/src/com/android/inputmethod/research/ResearchLogger.java @@ -865,7 +865,10 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang // Check that expected word matches. if (oldLogUnit != null) { final String oldLogUnitWords = oldLogUnit.getWordsAsString(); - if (oldLogUnitWords != null && !oldLogUnitWords.equals(expectedWord)) { + // Because the word is stored in the LogUnit with digits scrubbed, the comparison must + // be made on a scrubbed version of the expectedWord as well. + if (oldLogUnitWords != null && !oldLogUnitWords.equals( + scrubDigitsFromString(expectedWord))) { return; } } @@ -1276,6 +1279,16 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang } /** + * Log a revert of onTextInput() (known in the IME as "EnteredText"). + * + * SystemResponse: Remove the LogUnit recording the textInput + */ + public static void latinIME_handleBackspace_cancelTextInput(final String text) { + final ResearchLogger researchLogger = getInstance(); + researchLogger.uncommitCurrentLogUnit(text, true /* dumpCurrentLogUnit */); + } + + /** * Log a call to LatinIME.pickSuggestionManually(). * * UserAction: The user has chosen a specific word from the suggestion strip. @@ -1595,7 +1608,12 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang private static final LogStatement LOGSTATEMENT_RICHINPUTCONNECTION_REVERTDOUBLESPACEPERIOD = new LogStatement("RichInputConnectionRevertDoubleSpacePeriod", false, false); public static void richInputConnection_revertDoubleSpacePeriod() { - getInstance().enqueueEvent(LOGSTATEMENT_RICHINPUTCONNECTION_REVERTDOUBLESPACEPERIOD); + final ResearchLogger researchLogger = getInstance(); + // An extra LogUnit is added for the period; this is removed here because of the revert. + researchLogger.uncommitCurrentLogUnit(null, true /* dumpCurrentLogUnit */); + // TODO: This will probably be lost as the user backspaces further. Figure out how to put + // it into the right logUnit. + researchLogger.enqueueEvent(LOGSTATEMENT_RICHINPUTCONNECTION_REVERTDOUBLESPACEPERIOD); } /** @@ -1826,17 +1844,26 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang SystemClock.uptimeMillis()); } + private static final LogStatement LOGSTATEMENT_LATINIME_HANDLEBACKSPACE = + new LogStatement("LatinIMEHandleBackspace", true, false, "numCharacters"); /** * Log a call to LatinIME.handleBackspace() that is not a batch delete. * * UserInput: The user is deleting one or more characters by hitting the backspace key once. * The covers single character deletes as well as deleting selections. + * + * @param numCharacters how many characters the backspace operation deleted + * @param shouldUncommitLogUnit whether to uncommit the last {@code LogUnit} in the + * {@code LogBuffer} */ - private static final LogStatement LOGSTATEMENT_LATINIME_HANDLEBACKSPACE = - new LogStatement("LatinIMEHandleBackspace", true, false, "numCharacters"); - public static void latinIME_handleBackspace(final int numCharacters) { + public static void latinIME_handleBackspace(final int numCharacters, + final boolean shouldUncommitLogUnit) { final ResearchLogger researchLogger = getInstance(); researchLogger.enqueueEvent(LOGSTATEMENT_LATINIME_HANDLEBACKSPACE, numCharacters); + if (shouldUncommitLogUnit) { + ResearchLogger.getInstance().uncommitCurrentLogUnit( + null, true /* dumpCurrentLogUnit */); + } } /** @@ -1854,6 +1881,8 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang numCharacters); researchLogger.mStatistics.recordGestureDelete(deletedText.length(), SystemClock.uptimeMillis()); + researchLogger.uncommitCurrentLogUnit(deletedText.toString(), + false /* dumpCurrentLogUnit */); } /** |