aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java14
-rw-r--r--java/src/com/android/inputmethod/latin/AutoCorrection.java14
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java14
-rw-r--r--java/src/com/android/inputmethod/latin/Suggest.java6
4 files changed, 16 insertions, 32 deletions
diff --git a/java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java b/java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java
index 1cbdbd650..9c5ccc76b 100644
--- a/java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java
+++ b/java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java
@@ -16,9 +16,7 @@
package com.android.inputmethod.latin;
-import android.content.BroadcastReceiver;
import android.content.Context;
-import android.content.Intent;
import android.media.AudioManager;
import android.view.HapticFeedbackConstants;
import android.view.View;
@@ -32,7 +30,7 @@ import com.android.inputmethod.keyboard.Keyboard;
* It offers a consistent and simple interface that allows LatinIME to forget about the
* complexity of settings and the like.
*/
-public class AudioAndHapticFeedbackManager extends BroadcastReceiver {
+public class AudioAndHapticFeedbackManager {
final private SettingsValues mSettingsValues;
final private AudioManager mAudioManager;
final private VibratorCompatWrapper mVibrator;
@@ -100,13 +98,7 @@ public class AudioAndHapticFeedbackManager extends BroadcastReceiver {
}
}
- @Override
- public void onReceive(Context context, Intent intent) {
- final String action = intent.getAction();
- // The following test is supposedly useless since we only listen for the ringer event.
- // Still, it's a good safety measure.
- if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
- mSoundOn = reevaluateIfSoundIsOn();
- }
+ public void onRingerModeChanged() {
+ mSoundOn = reevaluateIfSoundIsOn();
}
}
diff --git a/java/src/com/android/inputmethod/latin/AutoCorrection.java b/java/src/com/android/inputmethod/latin/AutoCorrection.java
index 425b5c3f3..c4c944635 100644
--- a/java/src/com/android/inputmethod/latin/AutoCorrection.java
+++ b/java/src/com/android/inputmethod/latin/AutoCorrection.java
@@ -26,21 +26,15 @@ public class AutoCorrection {
private static final boolean DBG = LatinImeLogger.sDBG;
private static final String TAG = AutoCorrection.class.getSimpleName();
private CharSequence mAutoCorrectionWord;
- private double mNormalizedScore;
public void init() {
mAutoCorrectionWord = null;
- mNormalizedScore = Integer.MIN_VALUE;
}
public boolean hasAutoCorrection() {
return null != mAutoCorrectionWord;
}
- public double getNormalizedScore() {
- return mNormalizedScore;
- }
-
public CharSequence updateAutoCorrectionStatus(Map<String, Dictionary> dictionaries,
WordComposer wordComposer, ArrayList<CharSequence> suggestions, int[] sortedScores,
CharSequence typedWord, double autoCorrectionThreshold, int correctionMode,
@@ -108,7 +102,7 @@ public class AutoCorrection {
|| correctionMode == Suggest.CORRECTION_FULL_BIGRAM);
}
- private boolean hasAutoCorrectionForBinaryDictionary(WordComposer wordComposer,
+ private static boolean hasAutoCorrectionForBinaryDictionary(WordComposer wordComposer,
ArrayList<CharSequence> suggestions, int correctionMode, int[] sortedScores,
CharSequence typedWord, double autoCorrectionThreshold) {
if (wordComposer.size() > 1 && (correctionMode == Suggest.CORRECTION_FULL
@@ -118,15 +112,15 @@ public class AutoCorrection {
final int autoCorrectionSuggestionScore = sortedScores[0];
// TODO: when the normalized score of the first suggestion is nearly equals to
// the normalized score of the second suggestion, behave less aggressive.
- mNormalizedScore = BinaryDictionary.calcNormalizedScore(
+ final double normalizedScore = BinaryDictionary.calcNormalizedScore(
typedWord.toString(), autoCorrectionSuggestion.toString(),
autoCorrectionSuggestionScore);
if (DBG) {
Log.d(TAG, "Normalized " + typedWord + "," + autoCorrectionSuggestion + ","
- + autoCorrectionSuggestionScore + ", " + mNormalizedScore
+ + autoCorrectionSuggestionScore + ", " + normalizedScore
+ "(" + autoCorrectionThreshold + ")");
}
- if (mNormalizedScore >= autoCorrectionThreshold) {
+ if (normalizedScore >= autoCorrectionThreshold) {
if (DBG) {
Log.d(TAG, "Auto corrected by S-threshold.");
}
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index ca38cdeec..73a96895f 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -532,6 +532,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// Also receive installation and removal of a dictionary pack.
final IntentFilter filter = new IntentFilter();
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
+ filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
registerReceiver(mReceiver, filter);
mVoiceProxy = VoiceProxy.init(this, prefs, mHandler);
@@ -547,19 +548,11 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
registerReceiver(mDictionaryPackInstallReceiver, newDictFilter);
}
- private void renewFeedbackReceiver() {
- if (null != mFeedbackManager) unregisterReceiver(mFeedbackManager);
- mFeedbackManager = new AudioAndHapticFeedbackManager(this, mSettingsValues);
- final IntentFilter ringerModeFilter = new IntentFilter();
- ringerModeFilter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
- registerReceiver(mFeedbackManager, ringerModeFilter);
- }
-
// Has to be package-visible for unit tests
/* package */ void loadSettings() {
if (null == mPrefs) mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
mSettingsValues = new SettingsValues(mPrefs, this, mSubtypeSwitcher.getInputLocaleStr());
- renewFeedbackReceiver();
+ mFeedbackManager = new AudioAndHapticFeedbackManager(this, mSettingsValues);
resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary());
}
@@ -648,7 +641,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mSuggest = null;
}
unregisterReceiver(mReceiver);
- unregisterReceiver(mFeedbackManager);
unregisterReceiver(mDictionaryPackInstallReceiver);
mVoiceProxy.destroy();
LatinImeLogger.commit();
@@ -2356,6 +2348,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
final String action = intent.getAction();
if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
mSubtypeSwitcher.onNetworkStateChanged(intent);
+ } else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
+ mFeedbackManager.onRingerModeChanged();
}
}
};
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index 4c0f67270..19655f27d 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -374,7 +374,11 @@ public class Suggest implements Dictionary.WordCallback {
StringUtils.removeDupes(mSuggestions);
if (DBG) {
- double normalizedScore = mAutoCorrection.getNormalizedScore();
+ final CharSequence autoCorrectionSuggestion = mSuggestions.get(0);
+ final int autoCorrectionSuggestionScore = mScores[0];
+ double normalizedScore = BinaryDictionary.calcNormalizedScore(
+ typedWord.toString(), autoCorrectionSuggestion.toString(),
+ autoCorrectionSuggestionScore);
ArrayList<SuggestedWords.SuggestedWordInfo> scoreInfoList =
new ArrayList<SuggestedWords.SuggestedWordInfo>();
scoreInfoList.add(new SuggestedWords.SuggestedWordInfo("+", false));