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/LatinIME.java34
-rw-r--r--java/src/com/android/inputmethod/latin/RichInputConnection.java31
-rw-r--r--java/src/com/android/inputmethod/latin/Settings.java7
-rw-r--r--java/src/com/android/inputmethod/latin/SettingsValues.java13
-rw-r--r--java/src/com/android/inputmethod/latin/Utils.java10
-rw-r--r--java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java2
-rw-r--r--java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java3
7 files changed, 56 insertions, 44 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 5236591f6..77a0ccf70 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -872,7 +872,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (ProductionFlag.IS_EXPERIMENTAL) {
ResearchLogger.latinIME_onDisplayCompletions(applicationSpecifiedCompletions);
}
- if (mInputAttributes.mApplicationSpecifiedCompletionOn) {
+ if (null != mInputAttributes && mInputAttributes.mApplicationSpecifiedCompletionOn) {
mApplicationSpecifiedCompletions = applicationSpecifiedCompletions;
if (applicationSpecifiedCompletions == null) {
clearSuggestions();
@@ -1627,8 +1627,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
public boolean isSuggestionsRequested() {
- // TODO: move this method to mSettingsValues
- return mInputAttributes.mIsSettingsSuggestionStripOn
+ // TODO: move this method to mCurrentSettings
+ return (null != mInputAttributes && mInputAttributes.mIsSettingsSuggestionStripOn)
&& (mCurrentSettings.isCorrectionOn() || isShowingSuggestionsStrip());
}
@@ -1648,7 +1648,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
return true;
if (!isShowingSuggestionsStrip())
return false;
- if (mInputAttributes.mApplicationSpecifiedCompletionOn)
+ if (null != mInputAttributes && mInputAttributes.mApplicationSpecifiedCompletionOn)
return true;
return isSuggestionsRequested();
}
@@ -1804,14 +1804,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@Override
public void pickSuggestionManually(final int index, final CharSequence suggestion,
- int x, int y) {
- mConnection.beginBatchEdit(getCurrentInputConnection());
- pickSuggestionManuallyWhileInBatchEdit(index, suggestion, x, y);
- mConnection.endBatchEdit();
- }
-
- public void pickSuggestionManuallyWhileInBatchEdit(final int index,
- final CharSequence suggestion, final int x, final int y) {
+ final int x, final int y) {
final SuggestedWords suggestedWords = mSuggestionsView.getSuggestions();
// If this is a punctuation picked from the suggestion strip, pass it to onCodeInput
if (suggestion.length() == 1 && isShowingPunctuationList()) {
@@ -1837,7 +1830,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
}
- if (mInputAttributes.mApplicationSpecifiedCompletionOn
+ if ((null != mInputAttributes && mInputAttributes.mApplicationSpecifiedCompletionOn)
&& mApplicationSpecifiedCompletions != null
&& index >= 0 && index < mApplicationSpecifiedCompletions.length) {
if (mSuggestionsView != null) {
@@ -1846,7 +1839,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mKeyboardSwitcher.updateShiftState();
resetComposingState(true /* alsoResetLastComposedWord */);
final CompletionInfo completionInfo = mApplicationSpecifiedCompletions[index];
+ mConnection.beginBatchEdit(getCurrentInputConnection());
mConnection.commitCompletion(completionInfo);
+ mConnection.endBatchEdit();
if (ProductionFlag.IS_EXPERIMENTAL) {
ResearchLogger.latinIME_pickApplicationSpecifiedCompletion(index,
completionInfo.getText(), x, y);
@@ -1958,12 +1953,16 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// showSuggestions will retrieve the word near the cursor, we don't want that here)
showSuggestions(suggestedWords, "");
} else {
- if (!isShowingPunctuationList()) setPunctuationSuggestions();
+ clearSuggestions();
}
}
public void setPunctuationSuggestions() {
- setSuggestions(mCurrentSettings.mSuggestPuncList, false);
+ if (mCurrentSettings.mBigramPredictionEnabled) {
+ clearSuggestions();
+ } else {
+ setSuggestions(mCurrentSettings.mSuggestPuncList, false);
+ }
setAutoCorrectionIndicator(false);
setSuggestionStripShown(isSuggestionsStripVisible());
}
@@ -1986,10 +1985,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} else {
secondWord = suggestion.toString();
}
- // We demote unrecognized word and words with 0-frequency (assuming they would be
- // profanity etc.) by specifying them as "invalid".
+ // We demote unrecognized words (frequency < 0, below) by specifying them as "invalid".
+ // We don't add words with 0-frequency (assuming they would be profanity etc.).
final int maxFreq = AutoCorrection.getMaxFrequency(
mSuggest.getUnigramDictionaries(), suggestion);
+ if (maxFreq == 0) return null;
mUserHistoryDictionary.addToUserHistory(null == prevWord ? null : prevWord.toString(),
secondWord, maxFreq > 0);
return prevWord;
diff --git a/java/src/com/android/inputmethod/latin/RichInputConnection.java b/java/src/com/android/inputmethod/latin/RichInputConnection.java
index 227990acc..0c19bed05 100644
--- a/java/src/com/android/inputmethod/latin/RichInputConnection.java
+++ b/java/src/com/android/inputmethod/latin/RichInputConnection.java
@@ -65,66 +65,70 @@ public class RichInputConnection {
if (--mNestLevel == 0 && null != mIC) mIC.endBatchEdit();
}
+ private void checkBatchEdit() {
+ if (mNestLevel != 1) {
+ // TODO: exception instead
+ Log.e(TAG, "Batch edit level incorrect : " + mNestLevel);
+ Log.e(TAG, Utils.getStackTrace(4));
+ }
+ }
+
public void finishComposingText() {
- if (mNestLevel <= 0) Log.e(TAG, "Batch edit not in progress!"); // TODO: exception instead
+ checkBatchEdit();
if (null != mIC) mIC.finishComposingText();
}
public void commitText(final CharSequence text, final int i) {
- if (mNestLevel <= 0) Log.e(TAG, "Batch edit not in progress!"); // TODO: exception instead
+ checkBatchEdit();
if (null != mIC) mIC.commitText(text, i);
}
public int getCursorCapsMode(final int inputType) {
- if (mNestLevel <= 0) Log.e(TAG, "Batch edit not in progress!"); // TODO: exception instead
if (null == mIC) return Constants.TextUtils.CAP_MODE_OFF;
return mIC.getCursorCapsMode(inputType);
}
public CharSequence getTextBeforeCursor(final int i, final int j) {
- if (mNestLevel <= 0) Log.e(TAG, "Batch edit not in progress!"); // TODO: exception instead
if (null != mIC) return mIC.getTextBeforeCursor(i, j);
return null;
}
public CharSequence getTextAfterCursor(final int i, final int j) {
- if (mNestLevel <= 0) Log.e(TAG, "Batch edit not in progress!"); // TODO: exception instead
if (null != mIC) return mIC.getTextAfterCursor(i, j);
return null;
}
public void deleteSurroundingText(final int i, final int j) {
- if (mNestLevel <= 0) Log.e(TAG, "Batch edit not in progress!"); // TODO: exception instead
+ checkBatchEdit();
if (null != mIC) mIC.deleteSurroundingText(i, j);
}
public void performEditorAction(final int actionId) {
- if (mNestLevel <= 0) Log.e(TAG, "Batch edit not in progress!"); // TODO: exception instead
if (null != mIC) mIC.performEditorAction(actionId);
}
public void sendKeyEvent(final KeyEvent keyEvent) {
- if (mNestLevel <= 0) Log.e(TAG, "Batch edit not in progress!"); // TODO: exception instead
+ checkBatchEdit();
if (null != mIC) mIC.sendKeyEvent(keyEvent);
}
public void setComposingText(final CharSequence text, final int i) {
- if (mNestLevel <= 0) Log.e(TAG, "Batch edit not in progress!"); // TODO: exception instead
+ checkBatchEdit();
if (null != mIC) mIC.setComposingText(text, i);
}
public void setSelection(final int from, final int to) {
- if (mNestLevel <= 0) Log.e(TAG, "Batch edit not in progress!"); // TODO: exception instead
+ checkBatchEdit();
if (null != mIC) mIC.setSelection(from, to);
}
public void commitCorrection(final CorrectionInfo correctionInfo) {
- if (mNestLevel <= 0) Log.e(TAG, "Batch edit not in progress!"); // TODO: exception instead
+ checkBatchEdit();
if (null != mIC) mIC.commitCorrection(correctionInfo);
}
public void commitCompletion(final CompletionInfo completionInfo) {
- if (mNestLevel <= 0) Log.e(TAG, "Batch edit not in progress!"); // TODO: exception instead
+ checkBatchEdit();
if (null != mIC) mIC.commitCompletion(completionInfo);
}
@@ -316,6 +320,7 @@ public class RichInputConnection {
}
public void removeTrailingSpace() {
+ checkBatchEdit();
final CharSequence lastOne = getTextBeforeCursor(1, 0);
if (lastOne != null && lastOne.length() == 1
&& lastOne.charAt(0) == Keyboard.CODE_SPACE) {
@@ -372,6 +377,7 @@ public class RichInputConnection {
}
public boolean revertDoubleSpace() {
+ checkBatchEdit();
// Here we test whether we indeed have a period and a space before us. This should not
// be needed, but it's there just in case something went wrong.
final CharSequence textBeforeCursor = getTextBeforeCursor(2, 0);
@@ -395,6 +401,7 @@ public class RichInputConnection {
}
public boolean revertSwapPunctuation() {
+ checkBatchEdit();
// Here we test whether we indeed have a space and something else before us. This should not
// be needed, but it's there just in case something went wrong.
final CharSequence textBeforeCursor = getTextBeforeCursor(2, 0);
diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java
index c9ff0a5a8..152d66851 100644
--- a/java/src/com/android/inputmethod/latin/Settings.java
+++ b/java/src/com/android/inputmethod/latin/Settings.java
@@ -149,10 +149,13 @@ public class Settings extends InputMethodSettingsFragment
generalSettings.removePreference(mVoicePreference);
}
+ final PreferenceGroup advancedSettings =
+ (PreferenceGroup) findPreference(PREF_ADVANCED_SETTINGS);
+ // Remove those meaningless options for now. TODO: delete them for good
+ advancedSettings.removePreference(findPreference(PREF_BIGRAM_SUGGESTION));
+ advancedSettings.removePreference(findPreference(PREF_KEY_ENABLE_SPAN_INSERT));
if (!VibratorUtils.getInstance(context).hasVibrator()) {
generalSettings.removePreference(findPreference(PREF_VIBRATE_ON));
- final PreferenceGroup advancedSettings =
- (PreferenceGroup) findPreference(PREF_ADVANCED_SETTINGS);
if (null != advancedSettings) { // Theoretically advancedSettings cannot be null
advancedSettings.removePreference(findPreference(PREF_VIBRATION_DURATION_SETTINGS));
}
diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java
index 6a79aa611..f8a0a4df6 100644
--- a/java/src/com/android/inputmethod/latin/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/SettingsValues.java
@@ -151,8 +151,8 @@ public class SettingsValues {
&& isBigramSuggestionEnabled(prefs, res, mAutoCorrectEnabled);
mBigramPredictionEnabled = mBigramSuggestionEnabled
&& isBigramPredictionEnabled(prefs, res);
- mEnableSuggestionSpanInsertion =
- prefs.getBoolean(Settings.PREF_KEY_ENABLE_SPAN_INSERT, true);
+ // TODO: remove mEnableSuggestionSpanInsertion. It's always true.
+ mEnableSuggestionSpanInsertion = true;
mVibrationDurationSettingsRawValue =
prefs.getInt(Settings.PREF_VIBRATION_DURATION_SETTINGS, -1);
mKeypressSoundVolumeRawValue = prefs.getFloat(Settings.PREF_KEYPRESS_SOUND_VOLUME, -1.0f);
@@ -288,13 +288,8 @@ public class SettingsValues {
private static boolean isBigramSuggestionEnabled(final SharedPreferences sp,
final Resources resources, final boolean autoCorrectEnabled) {
- final boolean showBigramSuggestionsOption = resources.getBoolean(
- R.bool.config_enable_next_word_suggestions_option);
- if (!showBigramSuggestionsOption) {
- return autoCorrectEnabled;
- }
- return sp.getBoolean(Settings.PREF_BIGRAM_SUGGESTION, resources.getBoolean(
- R.bool.config_default_next_word_suggestions));
+ // TODO: remove this method. Bigram suggestion is always true.
+ return true;
}
private static boolean isBigramPredictionEnabled(final SharedPreferences sp,
diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java
index 903b5a357..f2d21ab9b 100644
--- a/java/src/com/android/inputmethod/latin/Utils.java
+++ b/java/src/com/android/inputmethod/latin/Utils.java
@@ -204,18 +204,24 @@ public class Utils {
}
// Get the current stack trace
- public static String getStackTrace() {
+ public static String getStackTrace(final int limit) {
StringBuilder sb = new StringBuilder();
try {
throw new RuntimeException();
} catch (RuntimeException e) {
StackTraceElement[] frames = e.getStackTrace();
// Start at 1 because the first frame is here and we don't care about it
- for (int j = 1; j < frames.length; ++j) sb.append(frames[j].toString() + "\n");
+ for (int j = 1; j < frames.length && j < limit + 1; ++j) {
+ sb.append(frames[j].toString() + "\n");
+ }
}
return sb.toString();
}
+ public static String getStackTrace() {
+ return getStackTrace(Integer.MAX_VALUE);
+ }
+
public static class UsabilityStudyLogUtils {
// TODO: remove code duplication with ResearchLog class
private static final String USABILITY_TAG = UsabilityStudyLogUtils.class.getSimpleName();
diff --git a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java
index 8a29dcc13..19287e3f3 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java
@@ -167,7 +167,7 @@ public class MoreSuggestionsView extends KeyboardView implements MoreKeysPanel {
@Override
public boolean dismissMoreKeysPanel() {
- if (mIsDismissing) return false;
+ if (mIsDismissing || mController == null) return false;
mIsDismissing = true;
final boolean dismissed = mController.dismissMoreKeysPanel();
mIsDismissing = false;
diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java
index 3d593aaa7..e86390b11 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java
@@ -670,7 +670,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
}
public void setSuggestions(SuggestedWords suggestedWords) {
- if (suggestedWords == null || suggestedWords.size() == 0)
+ if (suggestedWords == null)
return;
clear();
@@ -884,5 +884,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
super.onDetachedFromWindow();
mHandler.cancelAllMessages();
hidePreview();
+ dismissMoreSuggestions();
}
}