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/DictionaryCollection.java5
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java16
-rw-r--r--java/src/com/android/inputmethod/latin/Settings.java62
-rw-r--r--java/src/com/android/inputmethod/latin/UserDictionary.java22
4 files changed, 67 insertions, 38 deletions
diff --git a/java/src/com/android/inputmethod/latin/DictionaryCollection.java b/java/src/com/android/inputmethod/latin/DictionaryCollection.java
index e987d9f0c..107840331 100644
--- a/java/src/com/android/inputmethod/latin/DictionaryCollection.java
+++ b/java/src/com/android/inputmethod/latin/DictionaryCollection.java
@@ -17,6 +17,7 @@
package com.android.inputmethod.latin;
import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -36,11 +37,13 @@ public class DictionaryCollection extends Dictionary {
mDictionaries = new CopyOnWriteArrayList<Dictionary>();
} else {
mDictionaries = new CopyOnWriteArrayList<Dictionary>(dictionaries);
+ mDictionaries.removeAll(Collections.singleton(null));
}
}
public DictionaryCollection(Collection<Dictionary> dictionaries) {
mDictionaries = new CopyOnWriteArrayList<Dictionary>(dictionaries);
+ mDictionaries.removeAll(Collections.singleton(null));
}
@Override
@@ -70,6 +73,6 @@ public class DictionaryCollection extends Dictionary {
}
public void addDictionary(Dictionary newDict) {
- mDictionaries.add(newDict);
+ if (null != newDict) mDictionaries.add(newDict);
}
}
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index c5f7dd2c7..3457ac984 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -151,6 +151,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
private UserDictionary mUserDictionary;
private UserBigramDictionary mUserBigramDictionary;
private UserUnigramDictionary mUserUnigramDictionary;
+ private boolean mIsUserDictionaryAvaliable;
// TODO: Create an inner class to group options and pseudo-options to improve readability.
// These variables are initialized according to the {@link EditorInfo#inputType}.
@@ -504,6 +505,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mUserDictionary = new UserDictionary(this, localeStr);
mSuggest.setUserDictionary(mUserDictionary);
+ mIsUserDictionaryAvaliable = mUserDictionary.isEnabled();
resetContactsDictionary();
@@ -645,9 +647,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
LanguageSwitcherProxy.loadSettings();
if (mSubtypeSwitcher.isKeyboardMode()) {
- switcher.loadKeyboard(attribute,
- mSubtypeSwitcher.isShortcutImeEnabled() && voiceIme.isVoiceButtonEnabled(),
- voiceIme.isVoiceButtonOnPrimary());
+ switcher.loadKeyboard(attribute, mSettingsValues);
switcher.updateShiftState();
}
@@ -1763,7 +1763,11 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// take a noticeable delay to update them which may feel uneasy.
}
if (showingAddToDictionaryHint) {
- mCandidateView.showAddToDictionaryHint(suggestion);
+ if (mIsUserDictionaryAvaliable) {
+ mCandidateView.showAddToDictionaryHint(suggestion);
+ } else {
+ mHandler.postUpdateSuggestions();
+ }
}
if (ic != null) {
ic.endBatchEdit();
@@ -1966,9 +1970,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
setInputView(mKeyboardSwitcher.onCreateInputView());
}
// Reload keyboard because the current language has been changed.
- mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(),
- mSubtypeSwitcher.isShortcutImeEnabled() && mVoiceProxy.isVoiceButtonEnabled(),
- mVoiceProxy.isVoiceButtonOnPrimary());
+ mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(), mSettingsValues);
initSuggest();
loadSettings();
mKeyboardSwitcher.updateShiftState();
diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java
index 54f0a1b4d..b6171d276 100644
--- a/java/src/com/android/inputmethod/latin/Settings.java
+++ b/java/src/com/android/inputmethod/latin/Settings.java
@@ -16,13 +16,6 @@
package com.android.inputmethod.latin;
-import com.android.inputmethod.compat.CompatUtils;
-import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
-import com.android.inputmethod.compat.InputMethodServiceCompatWrapper;
-import com.android.inputmethod.deprecated.VoiceProxy;
-import com.android.inputmethod.compat.VibratorCompatWrapper;
-import com.android.inputmethodcommon.InputMethodSettingsActivity;
-
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
@@ -40,12 +33,20 @@ import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
-import android.speech.SpeechRecognizer;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.util.Log;
+import android.view.inputmethod.EditorInfo;
import android.widget.TextView;
+import com.android.inputmethod.compat.CompatUtils;
+import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
+import com.android.inputmethod.compat.InputMethodServiceCompatWrapper;
+import com.android.inputmethod.compat.InputTypeCompatUtils;
+import com.android.inputmethod.compat.VibratorCompatWrapper;
+import com.android.inputmethod.deprecated.VoiceProxy;
+import com.android.inputmethodcommon.InputMethodSettingsActivity;
+
import java.util.Arrays;
import java.util.Locale;
@@ -119,6 +120,9 @@ public class Settings extends InputMethodSettingsActivity
public final boolean mBigramPredictionEnabled;
public final boolean mUseContactsDict;
+ private final boolean mVoiceButtonEnabled;
+ private final boolean mVoiceButtonOnPrimary;
+
public Values(final SharedPreferences prefs, final Context context,
final String localeStr) {
final Resources res = context.getResources();
@@ -179,6 +183,12 @@ public class Settings extends InputMethodSettingsActivity
mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true);
+ final String voiceMode = prefs.getString(PREF_VOICE_SETTINGS_KEY, null);
+ mVoiceButtonEnabled = voiceMode != null && !voiceMode.equals(
+ res.getString(R.string.voice_mode_off));
+ mVoiceButtonOnPrimary = voiceMode != null && voiceMode.equals(
+ res.getString(R.string.voice_mode_main));
+
Utils.setSystemLocale(res, savedLocale);
}
@@ -287,6 +297,17 @@ public class Settings extends InputMethodSettingsActivity
}
return builder.setIsPunctuationSuggestions().build();
}
+
+ public boolean isVoiceButtonEnabled(EditorInfo attribute) {
+ final boolean shortcutImeEnabled = SubtypeSwitcher.getInstance().isShortcutImeEnabled();
+ final int inputType = (attribute != null) ? attribute.inputType : 0;
+ return shortcutImeEnabled && mVoiceButtonEnabled
+ && !InputTypeCompatUtils.isPasswordInputType(inputType);
+ }
+
+ public boolean isVoiceButtonOnPrimary() {
+ return mVoiceButtonOnPrimary;
+ }
}
private PreferenceScreen mInputLanguageSelection;
@@ -304,8 +325,6 @@ public class Settings extends InputMethodSettingsActivity
private AlertDialog mDialog;
- private VoiceProxy.VoiceLoggerWrapper mVoiceLogger;
-
private boolean mOkClicked = false;
private String mVoiceModeOff;
@@ -349,7 +368,6 @@ public class Settings extends InputMethodSettingsActivity
mVoiceModeOff = getString(R.string.voice_mode_off);
mVoiceOn = !(prefs.getString(PREF_VOICE_SETTINGS_KEY, mVoiceModeOff)
.equals(mVoiceModeOff));
- mVoiceLogger = VoiceProxy.VoiceLoggerWrapper.getInstance(context);
mAutoCorrectionThreshold = (ListPreference) findPreference(PREF_AUTO_CORRECTION_THRESHOLD);
mBigramSuggestion = (CheckBoxPreference) findPreference(PREF_BIGRAM_SUGGESTIONS);
@@ -447,14 +465,17 @@ public class Settings extends InputMethodSettingsActivity
}
}
+ @SuppressWarnings("unused")
@Override
public void onResume() {
super.onResume();
- if (!VoiceProxy.VOICE_INSTALLED
- || !SpeechRecognizer.isRecognitionAvailable(getActivityInternal())) {
- getPreferenceScreen().removePreference(mVoicePreference);
- } else {
+ final boolean isShortcutImeEnabled = SubtypeSwitcher.getInstance().isShortcutImeEnabled();
+ if (isShortcutImeEnabled
+ || (VoiceProxy.VOICE_INSTALLED
+ && VoiceProxy.isRecognitionAvailable(getActivityInternal()))) {
updateVoiceModeSummary();
+ } else {
+ getPreferenceScreen().removePreference(mVoicePreference);
}
updateSettingsKeySummary();
updateShowCorrectionSuggestionsSummary();
@@ -541,6 +562,7 @@ public class Settings extends InputMethodSettingsActivity
[mVoicePreference.findIndexOfValue(mVoicePreference.getValue())]);
}
+ @Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case VOICE_INPUT_CONFIRM_DIALOG:
@@ -549,12 +571,9 @@ public class Settings extends InputMethodSettingsActivity
public void onClick(DialogInterface dialog, int whichButton) {
if (whichButton == DialogInterface.BUTTON_NEGATIVE) {
mVoicePreference.setValue(mVoiceModeOff);
- mVoiceLogger.settingsWarningDialogCancel();
} else if (whichButton == DialogInterface.BUTTON_POSITIVE) {
mOkClicked = true;
- mVoiceLogger.settingsWarningDialogOk();
}
- updateVoicePreference();
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(getActivityInternal())
@@ -583,7 +602,6 @@ public class Settings extends InputMethodSettingsActivity
AlertDialog dialog = builder.create();
mDialog = dialog;
dialog.setOnDismissListener(this);
- mVoiceLogger.settingsWarningDialogShown();
return dialog;
default:
Log.e(TAG, "unknown dialog " + id);
@@ -593,16 +611,10 @@ public class Settings extends InputMethodSettingsActivity
@Override
public void onDismiss(DialogInterface dialog) {
- mVoiceLogger.settingsWarningDialogDismissed();
if (!mOkClicked) {
// This assumes that onPreferenceClick gets called first, and this if the user
// agreed after the warning, we set the mOkClicked value to true.
mVoicePreference.setValue(mVoiceModeOff);
}
}
-
- private void updateVoicePreference() {
- boolean isChecked = !mVoicePreference.getValue().equals(mVoiceModeOff);
- mVoiceLogger.voiceInputSettingEnabled(isChecked);
- }
}
diff --git a/java/src/com/android/inputmethod/latin/UserDictionary.java b/java/src/com/android/inputmethod/latin/UserDictionary.java
index 2aaa26c8d..f93d24fe6 100644
--- a/java/src/com/android/inputmethod/latin/UserDictionary.java
+++ b/java/src/com/android/inputmethod/latin/UserDictionary.java
@@ -38,23 +38,24 @@ public class UserDictionary extends ExpandableDictionary {
Words.FREQUENCY,
Words.LOCALE,
};
-
+
private ContentObserver mObserver;
private String mLocale;
public UserDictionary(Context context, String locale) {
super(context, Suggest.DIC_USER);
mLocale = locale;
- // Perform a managed query. The Activity will handle closing and requerying the cursor
+ // Perform a managed query. The Activity will handle closing and re-querying the cursor
// when needed.
ContentResolver cres = context.getContentResolver();
-
- cres.registerContentObserver(Words.CONTENT_URI, true, mObserver = new ContentObserver(null) {
+
+ mObserver = new ContentObserver(null) {
@Override
public void onChange(boolean self) {
setRequiresReload(true);
}
- });
+ };
+ cres.registerContentObserver(Words.CONTENT_URI, true, mObserver);
loadDictionary();
}
@@ -76,6 +77,17 @@ public class UserDictionary extends ExpandableDictionary {
addWords(cursor);
}
+ public boolean isEnabled() {
+ final ContentResolver cr = getContext().getContentResolver();
+ final ContentProviderClient client = cr.acquireContentProviderClient(Words.CONTENT_URI);
+ if (client != null) {
+ client.release();
+ return true;
+ } else {
+ return false;
+ }
+ }
+
/**
* Adds a word to the dictionary and makes it persistent.
* @param word the word to add. If the word is capitalized, then the dictionary will