aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin')
-rw-r--r--java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java16
-rw-r--r--java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java54
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java8
-rw-r--r--java/src/com/android/inputmethod/latin/SynchronouslyLoadedUserBinaryDictionary.java4
-rw-r--r--java/src/com/android/inputmethod/latin/UserBinaryDictionary.java15
-rw-r--r--java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java54
-rw-r--r--java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java18
-rw-r--r--java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionary.java12
-rw-r--r--java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java12
-rw-r--r--java/src/com/android/inputmethod/latin/settings/SettingsValues.java82
-rw-r--r--java/src/com/android/inputmethod/latin/settings/SpacingAndPunctuations.java25
-rw-r--r--java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java80
-rw-r--r--java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java8
13 files changed, 247 insertions, 141 deletions
diff --git a/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java
index a787ef153..d626ff926 100644
--- a/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java
@@ -29,7 +29,6 @@ import android.provider.ContactsContract.Contacts;
import android.text.TextUtils;
import android.util.Log;
-import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.personalization.AccountUtils;
import com.android.inputmethod.latin.utils.StringUtils;
@@ -73,8 +72,13 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary {
private final boolean mUseFirstLastBigrams;
public ContactsBinaryDictionary(final Context context, final Locale locale) {
- super(context, getDictNameWithLocale(NAME, locale), locale,
- Dictionary.TYPE_CONTACTS, false /* isUpdatable */);
+ this(context, locale, null /* dictFile */);
+ }
+
+ public ContactsBinaryDictionary(final Context context, final Locale locale,
+ final File dictFile) {
+ super(context, getDictName(NAME, locale, dictFile), locale, Dictionary.TYPE_CONTACTS,
+ false /* isUpdatable */, dictFile);
mLocale = locale;
mUseFirstLastBigrams = useFirstLastBigramsForLocale(locale);
registerObserver(context);
@@ -84,12 +88,6 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary {
loadDictionary();
}
- // Dummy constructor for tests.
- @UsedForTesting
- public ContactsBinaryDictionary(final Context context, final Locale locale, final File file) {
- this(context, locale);
- }
-
private synchronized void registerObserver(final Context context) {
// Perform a managed query. The Activity will handle closing and requerying the cursor
// when needed.
diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
index c2451ce8d..3b9be4395 100644
--- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
@@ -122,7 +122,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
new DictionaryUpdateController();
/* A extension for a binary dictionary file. */
- public static final String DICT_FILE_EXTENSION = ".dict";
+ protected static final String DICT_FILE_EXTENSION = ".dict";
private final AtomicReference<Runnable> mUnfinishedFlushingTask =
new AtomicReference<Runnable>();
@@ -148,10 +148,6 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
return mBinaryDictionary.isValidDictionary();
}
- private File getDictFile() {
- return mDictFile;
- }
-
/**
* Gets the dictionary update controller for the given dictionary name.
*/
@@ -213,15 +209,10 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
* @param dictType the dictionary type, as a human-readable string
* @param isUpdatable whether to support dynamically updating the dictionary. Please note that
* dynamic dictionary has negative effects on memory space and computation time.
+ * @param dictFile dictionary file path. if null, use default dictionary path based on
+ * dictionary type.
*/
public ExpandableBinaryDictionary(final Context context, final String dictName,
- final Locale locale, final String dictType, final boolean isUpdatable) {
- this(context, dictName, locale, dictType, isUpdatable,
- new File(context.getFilesDir(), dictName + DICT_FILE_EXTENSION));
- }
-
- // Creates an instance that uses a given dictionary file.
- public ExpandableBinaryDictionary(final Context context, final String dictName,
final Locale locale, final String dictType, final boolean isUpdatable,
final File dictFile) {
super(dictType);
@@ -229,15 +220,22 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
mContext = context;
mLocale = locale;
mIsUpdatable = isUpdatable;
- mDictFile = dictFile;
+ mDictFile = getDictFile(context, dictName, dictFile);
mBinaryDictionary = null;
mDictNameDictionaryUpdateController = getDictionaryUpdateController(dictName);
// Currently, only dynamic personalization dictionary is updatable.
mDictionaryWriter = getDictionaryWriter(isUpdatable);
}
- protected static String getDictNameWithLocale(final String name, final Locale locale) {
- return name + "." + locale.toString();
+ public static File getDictFile(final Context context, final String dictName,
+ final File dictFile) {
+ return (dictFile != null) ? dictFile
+ : new File(context.getFilesDir(), dictName + DICT_FILE_EXTENSION);
+ }
+
+ public static String getDictName(final String name, final Locale locale,
+ final File dictFile) {
+ return dictFile != null ? dictFile.getName() : name + "." + locale.toString();
}
/**
@@ -279,6 +277,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
}
protected void clear() {
+ final File dictFile = mDictFile;
getExecutor(mDictName).execute(new Runnable() {
@Override
public void run() {
@@ -286,14 +285,13 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
if (mBinaryDictionary != null) {
mBinaryDictionary.close();
}
- final File file = getDictFile();
- if (file.exists() && !FileUtils.deleteRecursively(file)) {
- Log.e(TAG, "Can't remove a file: " + file.getName());
+ if (dictFile.exists() && !FileUtils.deleteRecursively(dictFile)) {
+ Log.e(TAG, "Can't remove a file: " + dictFile.getName());
}
- BinaryDictionary.createEmptyDictFile(file.getAbsolutePath(),
+ BinaryDictionary.createEmptyDictFile(dictFile.getAbsolutePath(),
DICTIONARY_FORMAT_VERSION, mLocale, getHeaderAttributeMap());
mBinaryDictionary = new BinaryDictionary(
- file.getAbsolutePath(), 0 /* offset */, file.length(),
+ dictFile.getAbsolutePath(), 0 /* offset */, dictFile.length(),
true /* useFullEditDistance */, mLocale, mDictType, mIsUpdatable);
} else {
mDictionaryWriter.clear();
@@ -544,9 +542,8 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
}
}
- final File file = getDictFile();
- final String filename = file.getAbsolutePath();
- final long length = file.length();
+ final String filename = mDictFile.getAbsolutePath();
+ final long length = mDictFile.length();
// Build the new binary dictionary
final BinaryDictionary newBinaryDictionary = new BinaryDictionary(filename, 0 /* offset */,
@@ -585,17 +582,16 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
if (needsToReloadBeforeWriting()) {
mDictionaryWriter.clear();
loadDictionaryAsync();
- mDictionaryWriter.write(getDictFile(), getHeaderAttributeMap());
+ mDictionaryWriter.write(mDictFile, getHeaderAttributeMap());
} else {
if (mBinaryDictionary == null || !isValidDictionary()
// TODO: remove the check below
|| !matchesExpectedBinaryDictFormatVersionForThisType(
mBinaryDictionary.getFormatVersion())) {
- final File file = getDictFile();
- if (file.exists() && !FileUtils.deleteRecursively(file)) {
- Log.e(TAG, "Can't remove a file: " + file.getName());
+ if (mDictFile.exists() && !FileUtils.deleteRecursively(mDictFile)) {
+ Log.e(TAG, "Can't remove a file: " + mDictFile.getName());
}
- BinaryDictionary.createEmptyDictFile(file.getAbsolutePath(),
+ BinaryDictionary.createEmptyDictFile(mDictFile.getAbsolutePath(),
DICTIONARY_FORMAT_VERSION, mLocale, getHeaderAttributeMap());
} else {
if (mBinaryDictionary.needsToRunGC(false /* mindsBlockByGC */)) {
@@ -719,7 +715,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
// TODO: cache the file's existence so that we avoid doing a disk access each time.
private boolean dictionaryFileExists() {
- return getDictFile().exists();
+ return mDictFile.exists();
}
/**
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 30bb505cb..7b72e8044 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1734,13 +1734,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final int keyboardMode = keyboard != null ? keyboard.mId.mMode : -1;
p.println(" Keyboard mode = " + keyboardMode);
final SettingsValues settingsValues = mSettings.getCurrent();
- p.println(" mIsSuggestionsRequested = " + settingsValues.isSuggestionsRequested());
- p.println(" mCorrectionEnabled=" + settingsValues.mCorrectionEnabled);
- p.println(" isComposingWord=" + mInputLogic.mWordComposer.isComposingWord());
- p.println(" mSoundOn=" + settingsValues.mSoundOn);
- p.println(" mVibrateOn=" + settingsValues.mVibrateOn);
- p.println(" mKeyPreviewPopupOn=" + settingsValues.mKeyPreviewPopupOn);
- p.println(" inputAttributes=" + settingsValues.mInputAttributes);
+ p.println(settingsValues.dump());
// TODO: Dump all settings values
}
}
diff --git a/java/src/com/android/inputmethod/latin/SynchronouslyLoadedUserBinaryDictionary.java b/java/src/com/android/inputmethod/latin/SynchronouslyLoadedUserBinaryDictionary.java
index 9ccd9e4e8..801fb5b89 100644
--- a/java/src/com/android/inputmethod/latin/SynchronouslyLoadedUserBinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/SynchronouslyLoadedUserBinaryDictionary.java
@@ -28,12 +28,12 @@ public final class SynchronouslyLoadedUserBinaryDictionary extends UserBinaryDic
private final Object mLock = new Object();
public SynchronouslyLoadedUserBinaryDictionary(final Context context, final Locale locale) {
- this(context, locale, false);
+ this(context, locale, false /* alsoUseMoreRestrictiveLocales */);
}
public SynchronouslyLoadedUserBinaryDictionary(final Context context, final Locale locale,
final boolean alsoUseMoreRestrictiveLocales) {
- super(context, locale, alsoUseMoreRestrictiveLocales);
+ super(context, locale, alsoUseMoreRestrictiveLocales, null /* dictFile */);
}
@Override
diff --git a/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java b/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java
index 8011247c6..2a195f58b 100644
--- a/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java
@@ -28,7 +28,6 @@ import android.provider.UserDictionary.Words;
import android.text.TextUtils;
import android.util.Log;
-import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.compat.UserDictionaryCompatUtils;
import com.android.inputmethod.latin.utils.LocaleUtils;
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
@@ -78,19 +77,17 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
final public boolean mEnabled;
public UserBinaryDictionary(final Context context, final Locale locale) {
- this(context, locale, false);
+ this(context, locale, false /* alsoUseMoreRestrictiveLocales */, null /* dictFile */);
}
- // Dummy constructor for tests.
- @UsedForTesting
- public UserBinaryDictionary(final Context context, final Locale locale, final File file) {
- this(context, locale);
+ public UserBinaryDictionary(final Context context, final Locale locale, final File dictFile) {
+ this(context, locale, false /* alsoUseMoreRestrictiveLocales */, dictFile);
}
public UserBinaryDictionary(final Context context, final Locale locale,
- final boolean alsoUseMoreRestrictiveLocales) {
- super(context, getDictNameWithLocale(NAME, locale), locale, Dictionary.TYPE_USER,
- false /* isUpdatable */);
+ final boolean alsoUseMoreRestrictiveLocales, final File dictFile) {
+ super(context, getDictName(NAME, locale, dictFile), locale, Dictionary.TYPE_USER,
+ false /* isUpdatable */, dictFile);
if (null == locale) throw new NullPointerException(); // Catch the error earlier
final String localeStr = locale.toString();
if (SubtypeLocaleUtils.NO_LANGUAGE.equals(localeStr)) {
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index 6e9050593..bd114ebca 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -973,7 +973,13 @@ public final class InputLogic {
} else {
final int codePointBeforeCursor = mConnection.getCodePointBeforeCursor();
if (codePointBeforeCursor == Constants.NOT_A_CODE) {
- // Nothing to delete before the cursor.
+ // HACK for backward compatibility with broken apps that haven't realized
+ // yet that hardware keyboards are not the only way of inputting text.
+ // Nothing to delete before the cursor. We should not do anything, but many
+ // broken apps expect something to happen in this case so that they can
+ // catch it and have their broken interface react. If you need the keyboard
+ // to do this, you're doing it wrong -- please fix your app.
+ mConnection.deleteSurroundingText(1, 0);
return;
}
final int lengthToDelete =
@@ -1355,6 +1361,7 @@ public final class InputLogic {
final String previousWord = mLastComposedWord.mPrevWord;
final CharSequence originallyTypedWord = mLastComposedWord.mTypedWord;
final CharSequence committedWord = mLastComposedWord.mCommittedWord;
+ final String committedWordString = committedWord.toString();
final int cancelLength = committedWord.length();
// We want java chars, not codepoints for the following.
final int separatorLength = mLastComposedWord.mSeparatorString.length();
@@ -1376,33 +1383,44 @@ public final class InputLogic {
if (!TextUtils.isEmpty(previousWord) && !TextUtils.isEmpty(committedWord)) {
if (mSuggest != null) {
mSuggest.mDictionaryFacilitator.cancelAddingUserHistory(
- previousWord, committedWord.toString());
+ previousWord, committedWordString);
}
}
final String stringToCommit = originallyTypedWord + mLastComposedWord.mSeparatorString;
final SpannableString textToCommit = new SpannableString(stringToCommit);
if (committedWord instanceof SpannableString) {
- final int lastCharIndex = textToCommit.length() - 1;
- // Add the auto-correction to the list of suggestions.
- textToCommit.setSpan(new SuggestionSpan(settingsValues.mLocale,
- new String[] { committedWord.toString() }, 0 /* flags */),
- 0 /* start */, lastCharIndex /* end */, 0 /* flags */);
final SpannableString committedWordWithSuggestionSpans = (SpannableString)committedWord;
final Object[] spans = committedWordWithSuggestionSpans.getSpans(0,
committedWord.length(), Object.class);
+ final int lastCharIndex = textToCommit.length() - 1;
+ // We will collect all suggestions in the following array.
+ final ArrayList<String> suggestions = CollectionUtils.newArrayList();
+ // First, add the committed word to the list of suggestions.
+ suggestions.add(committedWordString);
for (final Object span : spans) {
- // Put all the spans in the original text on this new text. We could remove the
- // typed word from the suggestions, but we'd have to make more dynamic instanceof
- // checks, to copy the span, copy all suggestions and attributes... And there is
- // the risk to drop the originally typed string if there is a subtle bug. There is
- // still the committed auto-correction that we reverted from, which is not included
- // in the suggestions, that's why we added it with another call to setSpan a few
- // lines above.
- // The code that re-reads these spans already knows to do the right thing whether
- // the typed word is included or not. That should be enough.
- textToCommit.setSpan(span, 0 /* start */, lastCharIndex /* end */,
- committedWordWithSuggestionSpans.getSpanFlags(span));
+ // If this is a suggestion span, we check that the locale is the right one, and
+ // that the word is not the committed word. That should mostly be the case.
+ // Given this, we add it to the list of suggestions, otherwise we discard it.
+ if (span instanceof SuggestionSpan) {
+ final SuggestionSpan suggestionSpan = (SuggestionSpan)span;
+ if (!suggestionSpan.getLocale().equals(settingsValues.mLocale.toString())) {
+ continue;
+ }
+ for (final String suggestion : suggestionSpan.getSuggestions()) {
+ if (!suggestion.equals(committedWordString)) {
+ suggestions.add(suggestion);
+ }
+ }
+ } else {
+ // If this is not a suggestion span, we just add it as is.
+ textToCommit.setSpan(span, 0 /* start */, lastCharIndex /* end */,
+ committedWordWithSuggestionSpans.getSpanFlags(span));
+ }
}
+ // Add the suggestion list to the list of suggestions.
+ textToCommit.setSpan(new SuggestionSpan(settingsValues.mLocale,
+ suggestions.toArray(new String[suggestions.size()]), 0 /* flags */),
+ 0 /* start */, lastCharIndex /* end */, 0 /* flags */);
}
if (settingsValues.mSpacingAndPunctuations.mCurrentLanguageHasSpaces) {
// For languages with spaces, we revert to the typed string, but the cursor is still
diff --git a/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java b/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java
index 6a7a3368e..8f7378c58 100644
--- a/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java
+++ b/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java
@@ -51,22 +51,10 @@ public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableB
private final String mDictName;
- /* package */ DecayingExpandableBinaryDictionaryBase(final Context context,
- final Locale locale, final String dictionaryType, final String dictName) {
- super(context, dictName, locale, dictionaryType, true);
- mLocale = locale;
- mDictName = dictName;
- if (mLocale != null && mLocale.toString().length() > 1) {
- reloadDictionaryIfRequired();
- }
- }
-
- // Creates an instance that uses a given dictionary file for testing.
- @UsedForTesting
- /* package */ DecayingExpandableBinaryDictionaryBase(final Context context,
- final Locale locale, final String dictionaryType, final String dictName,
+ protected DecayingExpandableBinaryDictionaryBase(final Context context,
+ final String dictName, final Locale locale, final String dictionaryType,
final File dictFile) {
- super(context, dictName, locale, dictionaryType, true, dictFile);
+ super(context, dictName, locale, dictionaryType, true /* isUpdatable */, dictFile);
mLocale = locale;
mDictName = dictName;
if (mLocale != null && mLocale.toString().length() > 1) {
diff --git a/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionary.java b/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionary.java
index 652614876..4afd5b4c9 100644
--- a/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionary.java
+++ b/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionary.java
@@ -16,27 +16,23 @@
package com.android.inputmethod.latin.personalization;
-import com.android.inputmethod.annotations.UsedForTesting;
+import android.content.Context;
+
import com.android.inputmethod.latin.Dictionary;
import java.io.File;
import java.util.Locale;
-import android.content.Context;
-
public class PersonalizationDictionary extends DecayingExpandableBinaryDictionaryBase {
/* package */ static final String NAME = PersonalizationDictionary.class.getSimpleName();
/* package */ PersonalizationDictionary(final Context context, final Locale locale) {
- super(context, locale, Dictionary.TYPE_PERSONALIZATION,
- getDictNameWithLocale(NAME, locale));
+ this(context, locale, null /* dictFile */);
}
- // Creates an instance that uses a given dictionary file for testing.
- @UsedForTesting
public PersonalizationDictionary(final Context context, final Locale locale,
final File dictFile) {
- super(context, locale, Dictionary.TYPE_PERSONALIZATION, getDictNameWithLocale(NAME, locale),
+ super(context, getDictName(NAME, locale, dictFile), locale, Dictionary.TYPE_PERSONALIZATION,
dictFile);
}
diff --git a/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java b/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java
index 6778c2334..504e9b2f3 100644
--- a/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java
@@ -16,29 +16,27 @@
package com.android.inputmethod.latin.personalization;
-import com.android.inputmethod.annotations.UsedForTesting;
+import android.content.Context;
+
import com.android.inputmethod.latin.Dictionary;
import java.io.File;
import java.util.Locale;
-import android.content.Context;
-
/**
* Locally gathers stats about the words user types and various other signals like auto-correction
* cancellation or manual picks. This allows the keyboard to adapt to the typist over time.
*/
public class UserHistoryDictionary extends DecayingExpandableBinaryDictionaryBase {
/* package */ static final String NAME = UserHistoryDictionary.class.getSimpleName();
+
/* package */ UserHistoryDictionary(final Context context, final Locale locale) {
- super(context, locale, Dictionary.TYPE_USER_HISTORY, getDictNameWithLocale(NAME, locale));
+ this(context, locale, null /* dictFile */);
}
- // Creates an instance that uses a given dictionary file for testing.
- @UsedForTesting
public UserHistoryDictionary(final Context context, final Locale locale,
final File dictFile) {
- super(context, locale, Dictionary.TYPE_USER_HISTORY, getDictNameWithLocale(NAME, locale),
+ super(context, getDictName(NAME, locale, dictFile), locale, Dictionary.TYPE_USER_HISTORY,
dictFile);
}
diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
index 90d3519a4..77968f79a 100644
--- a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
@@ -329,4 +329,86 @@ public final class SettingsValues {
}
return prefs.getBoolean(Settings.PREF_VOICE_INPUT_KEY, true);
}
+
+ public String dump() {
+ final StringBuilder sb = new StringBuilder("Current settings :");
+ sb.append("\n mSpacingAndPunctuations = ");
+ sb.append("" + mSpacingAndPunctuations.dump());
+ sb.append("\n mDelayUpdateOldSuggestions = ");
+ sb.append("" + mDelayUpdateOldSuggestions);
+ sb.append("\n mAutoCap = ");
+ sb.append("" + mAutoCap);
+ sb.append("\n mVibrateOn = ");
+ sb.append("" + mVibrateOn);
+ sb.append("\n mSoundOn = ");
+ sb.append("" + mSoundOn);
+ sb.append("\n mKeyPreviewPopupOn = ");
+ sb.append("" + mKeyPreviewPopupOn);
+ sb.append("\n mShowsVoiceInputKey = ");
+ sb.append("" + mShowsVoiceInputKey);
+ sb.append("\n mIncludesOtherImesInLanguageSwitchList = ");
+ sb.append("" + mIncludesOtherImesInLanguageSwitchList);
+ sb.append("\n mShowsLanguageSwitchKey = ");
+ sb.append("" + mShowsLanguageSwitchKey);
+ sb.append("\n mUseContactsDict = ");
+ sb.append("" + mUseContactsDict);
+ sb.append("\n mUsePersonalizedDicts = ");
+ sb.append("" + mUsePersonalizedDicts);
+ sb.append("\n mUseDoubleSpacePeriod = ");
+ sb.append("" + mUseDoubleSpacePeriod);
+ sb.append("\n mBlockPotentiallyOffensive = ");
+ sb.append("" + mBlockPotentiallyOffensive);
+ sb.append("\n mBigramPredictionEnabled = ");
+ sb.append("" + mBigramPredictionEnabled);
+ sb.append("\n mGestureInputEnabled = ");
+ sb.append("" + mGestureInputEnabled);
+ sb.append("\n mGestureTrailEnabled = ");
+ sb.append("" + mGestureTrailEnabled);
+ sb.append("\n mGestureFloatingPreviewTextEnabled = ");
+ sb.append("" + mGestureFloatingPreviewTextEnabled);
+ sb.append("\n mSlidingKeyInputPreviewEnabled = ");
+ sb.append("" + mSlidingKeyInputPreviewEnabled);
+ sb.append("\n mPhraseGestureEnabled = ");
+ sb.append("" + mPhraseGestureEnabled);
+ sb.append("\n mKeyLongpressTimeout = ");
+ sb.append("" + mKeyLongpressTimeout);
+ sb.append("\n mLocale = ");
+ sb.append("" + mLocale);
+ sb.append("\n mInputAttributes = ");
+ sb.append("" + mInputAttributes);
+ sb.append("\n mKeypressVibrationDuration = ");
+ sb.append("" + mKeypressVibrationDuration);
+ sb.append("\n mKeypressSoundVolume = ");
+ sb.append("" + mKeypressSoundVolume);
+ sb.append("\n mKeyPreviewPopupDismissDelay = ");
+ sb.append("" + mKeyPreviewPopupDismissDelay);
+ sb.append("\n mAutoCorrectEnabled = ");
+ sb.append("" + mAutoCorrectEnabled);
+ sb.append("\n mAutoCorrectionThreshold = ");
+ sb.append("" + mAutoCorrectionThreshold);
+ sb.append("\n mCorrectionEnabled = ");
+ sb.append("" + mCorrectionEnabled);
+ sb.append("\n mSuggestionVisibility = ");
+ sb.append("" + mSuggestionVisibility);
+ sb.append("\n mUseOnlyPersonalizationDictionaryForDebug = ");
+ sb.append("" + mUseOnlyPersonalizationDictionaryForDebug);
+ sb.append("\n mDisplayOrientation = ");
+ sb.append("" + mDisplayOrientation);
+ sb.append("\n mAppWorkarounds = ");
+ final AppWorkaroundsUtils awu = mAppWorkarounds.get(null, 0);
+ sb.append("" + (null == awu ? "null" : awu.toString()));
+ sb.append("\n mAdditionalFeaturesSettingValues = ");
+ sb.append("" + Arrays.toString(mAdditionalFeaturesSettingValues));
+ sb.append("\n mIsInternal = ");
+ sb.append("" + mIsInternal);
+ sb.append("\n mKeyPreviewShowUpDuration = ");
+ sb.append("" + mKeyPreviewShowUpDuration);
+ sb.append("\n mKeyPreviewDismissDuration = ");
+ sb.append("" + mKeyPreviewDismissDuration);
+ sb.append("\n mKeyPreviewShowUpStartScale = ");
+ sb.append("" + mKeyPreviewShowUpStartScale);
+ sb.append("\n mKeyPreviewDismissEndScale = ");
+ sb.append("" + mKeyPreviewDismissEndScale);
+ return sb.toString();
+ }
}
diff --git a/java/src/com/android/inputmethod/latin/settings/SpacingAndPunctuations.java b/java/src/com/android/inputmethod/latin/settings/SpacingAndPunctuations.java
index 60ca5baab..03883a48b 100644
--- a/java/src/com/android/inputmethod/latin/settings/SpacingAndPunctuations.java
+++ b/java/src/com/android/inputmethod/latin/settings/SpacingAndPunctuations.java
@@ -115,4 +115,29 @@ public final class SpacingAndPunctuations {
public boolean isSentenceSeparator(final int code) {
return code == mSentenceSeparator;
}
+
+ public String dump() {
+ final StringBuilder sb = new StringBuilder();
+ sb.append("mSortedSymbolsPrecededBySpace = ");
+ sb.append("" + Arrays.toString(mSortedSymbolsPrecededBySpace));
+ sb.append("\n mSortedSymbolsFollowedBySpace = ");
+ sb.append("" + Arrays.toString(mSortedSymbolsFollowedBySpace));
+ sb.append("\n mSortedWordConnectors = ");
+ sb.append("" + Arrays.toString(mSortedWordConnectors));
+ sb.append("\n mSortedWordSeparators = ");
+ sb.append("" + Arrays.toString(mSortedWordSeparators));
+ sb.append("\n mSuggestPuncList = ");
+ sb.append("" + mSuggestPuncList);
+ sb.append("\n mSentenceSeparator = ");
+ sb.append("" + mSentenceSeparator);
+ sb.append("\n mSentenceSeparatorAndSpace = ");
+ sb.append("" + mSentenceSeparatorAndSpace);
+ sb.append("\n mCurrentLanguageHasSpaces = ");
+ sb.append("" + mCurrentLanguageHasSpaces);
+ sb.append("\n mUsesAmericanTypography = ");
+ sb.append("" + mUsesAmericanTypography);
+ sb.append("\n mUsesGermanRules = ");
+ sb.append("" + mUsesGermanRules);
+ return sb.toString();
+ }
}
diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java
index 4063edccc..5f05b48d4 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java
@@ -65,7 +65,7 @@ final class SuggestionStripLayoutHelper {
public final int mPadding;
public final int mDividerWidth;
public final int mSuggestionsStripHeight;
- public final int mSuggestionsCountInStrip;
+ private final int mSuggestionsCountInStrip;
public final int mMoreSuggestionsRowHeight;
private int mMaxMoreSuggestionsRow;
public final float mMinMoreSuggestionsWidth;
@@ -288,54 +288,65 @@ final class SuggestionStripLayoutHelper {
params.gravity = Gravity.CENTER;
}
- public void layout(final SuggestedWords suggestedWords, final ViewGroup stripView,
- final ViewGroup placerView) {
+ /**
+ * Layout suggestions to the suggestions strip. And returns the number of suggestions displayed
+ * in the suggestions strip.
+ *
+ * @param suggestedWords suggestions to be shown in the suggestions strip.
+ * @param stripView the suggestions strip view.
+ * @param placerView the view where the debug info will be placed.
+ * @return the number of suggestions displayed in the suggestions strip
+ */
+ public int layoutAndReturnSuggestionCountInStrip(final SuggestedWords suggestedWords,
+ final ViewGroup stripView, final ViewGroup placerView) {
if (suggestedWords.mIsPunctuationSuggestions) {
- layoutPunctuationSuggestions(suggestedWords, stripView);
- return;
+ return layoutPunctuationSuggestionsAndReturnSuggestionCountInStrip(
+ suggestedWords, stripView);
}
- final int countInStrip = mSuggestionsCountInStrip;
- setupWordViewsTextAndColor(suggestedWords, countInStrip);
+ setupWordViewsTextAndColor(suggestedWords, mSuggestionsCountInStrip);
final TextView centerWordView = mWordViews.get(mCenterPositionInStrip);
final int availableStripWidth = placerView.getWidth()
- placerView.getPaddingRight() - placerView.getPaddingLeft();
final int centerWidth = getSuggestionWidth(mCenterPositionInStrip, availableStripWidth);
- if (getTextScaleX(centerWordView.getText(), centerWidth, centerWordView.getPaint())
- < MIN_TEXT_XSCALE) {
+ final int countInStrip;
+ if (suggestedWords.size() == 1 || getTextScaleX(centerWordView.getText(), centerWidth,
+ centerWordView.getPaint()) < MIN_TEXT_XSCALE) {
// Layout only the most relevant suggested word at the center of the suggestion strip
// by consolidating all slots in the strip.
- mMoreSuggestionsAvailable = (suggestedWords.size() > 1);
+ countInStrip = 1;
+ mMoreSuggestionsAvailable = (suggestedWords.size() > countInStrip);
layoutWord(mCenterPositionInStrip, availableStripWidth - mPadding);
stripView.addView(centerWordView);
setLayoutWeight(centerWordView, 1.0f, ViewGroup.LayoutParams.MATCH_PARENT);
if (SuggestionStripView.DBG) {
layoutDebugInfo(mCenterPositionInStrip, placerView, availableStripWidth);
}
- return;
- }
-
- mMoreSuggestionsAvailable = (suggestedWords.size() > countInStrip);
- int x = 0;
- for (int positionInStrip = 0; positionInStrip < countInStrip; positionInStrip++) {
- if (positionInStrip != 0) {
- final View divider = mDividerViews.get(positionInStrip);
- // Add divider if this isn't the left most suggestion in suggestions strip.
- addDivider(stripView, divider);
- x += divider.getMeasuredWidth();
- }
-
- final int width = getSuggestionWidth(positionInStrip, availableStripWidth);
- final TextView wordView = layoutWord(positionInStrip, width);
- stripView.addView(wordView);
- setLayoutWeight(wordView, getSuggestionWeight(positionInStrip),
- ViewGroup.LayoutParams.MATCH_PARENT);
- x += wordView.getMeasuredWidth();
-
- if (SuggestionStripView.DBG) {
- layoutDebugInfo(positionInStrip, placerView, x);
+ } else {
+ countInStrip = mSuggestionsCountInStrip;
+ mMoreSuggestionsAvailable = (suggestedWords.size() > countInStrip);
+ int x = 0;
+ for (int positionInStrip = 0; positionInStrip < countInStrip; positionInStrip++) {
+ if (positionInStrip != 0) {
+ final View divider = mDividerViews.get(positionInStrip);
+ // Add divider if this isn't the left most suggestion in suggestions strip.
+ addDivider(stripView, divider);
+ x += divider.getMeasuredWidth();
+ }
+
+ final int width = getSuggestionWidth(positionInStrip, availableStripWidth);
+ final TextView wordView = layoutWord(positionInStrip, width);
+ stripView.addView(wordView);
+ setLayoutWeight(wordView, getSuggestionWeight(positionInStrip),
+ ViewGroup.LayoutParams.MATCH_PARENT);
+ x += wordView.getMeasuredWidth();
+
+ if (SuggestionStripView.DBG) {
+ layoutDebugInfo(positionInStrip, placerView, x);
+ }
}
}
+ return countInStrip;
}
/**
@@ -435,8 +446,8 @@ final class SuggestionStripLayoutHelper {
}
}
- private void layoutPunctuationSuggestions(final SuggestedWords suggestedWords,
- final ViewGroup stripView) {
+ private int layoutPunctuationSuggestionsAndReturnSuggestionCountInStrip(
+ final SuggestedWords suggestedWords, final ViewGroup stripView) {
final int countInStrip = Math.min(suggestedWords.size(), PUNCTUATIONS_IN_STRIP);
for (int positionInStrip = 0; positionInStrip < countInStrip; positionInStrip++) {
if (positionInStrip != 0) {
@@ -457,6 +468,7 @@ final class SuggestionStripLayoutHelper {
setLayoutWeight(wordView, 1.0f, mSuggestionsStripHeight);
}
mMoreSuggestionsAvailable = (suggestedWords.size() > countInStrip);
+ return countInStrip;
}
public void layoutAddToDictionaryHint(final String word, final ViewGroup addToDictionaryStrip,
diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java
index 29c0613e4..cf0a7a2aa 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java
@@ -77,6 +77,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
Listener mListener;
private SuggestedWords mSuggestedWords = SuggestedWords.EMPTY;
+ private int mSuggestionsCountInStrip;
private final SuggestionStripLayoutHelper mLayoutHelper;
private final StripVisibilityGroup mStripVisibilityGroup;
@@ -189,7 +190,8 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
clear();
mStripVisibilityGroup.setLayoutDirection(isRtlLanguage);
mSuggestedWords = suggestedWords;
- mLayoutHelper.layout(mSuggestedWords, mSuggestionsStrip, this);
+ mSuggestionsCountInStrip = mLayoutHelper.layoutAndReturnSuggestionCountInStrip(
+ mSuggestedWords, mSuggestionsStrip, this);
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
ResearchLogger.suggestionStripView_setSuggestions(mSuggestedWords);
}
@@ -312,7 +314,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
final View container = mMoreSuggestionsContainer;
final int maxWidth = stripWidth - container.getPaddingLeft() - container.getPaddingRight();
final MoreSuggestions.Builder builder = mMoreSuggestionsBuilder;
- builder.layout(mSuggestedWords, layoutHelper.mSuggestionsCountInStrip, maxWidth,
+ builder.layout(mSuggestedWords, mSuggestionsCountInStrip, maxWidth,
(int)(maxWidth * layoutHelper.mMinMoreSuggestionsWidth),
layoutHelper.getMaxMoreSuggestionsRow(), parentKeyboard);
mMoreSuggestionsView.setKeyboard(builder.build());
@@ -326,7 +328,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
mMoreSuggestionsMode = MORE_SUGGESTIONS_CHECKING_MODAL_OR_SLIDING;
mOriginX = mLastX;
mOriginY = mLastY;
- for (int i = 0; i < layoutHelper.mSuggestionsCountInStrip; i++) {
+ for (int i = 0; i < mSuggestionsCountInStrip; i++) {
mWordViews.get(i).setPressed(false);
}
return true;