(Refactor 1) Moved voice related codes to deprecated/voice
Change-Id: I008ac7099c815fb74a9ab374419617b336453f97
This commit is contained in:
parent
071f47140c
commit
9807ab27ea
15 changed files with 142 additions and 72 deletions
|
@ -45,7 +45,7 @@
|
||||||
android:layout_height="0dip"
|
android:layout_height="0dip"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_weight="1.0">
|
android:layout_weight="1.0">
|
||||||
<com.android.inputmethod.voice.SoundIndicator
|
<com.android.inputmethod.deprecated.voice.SoundIndicator
|
||||||
android:id="@+id/sound_indicator"
|
android:id="@+id/sound_indicator"
|
||||||
android:src="@drawable/mic_full"
|
android:src="@drawable/mic_full"
|
||||||
android:background="@drawable/mic_base"
|
android:background="@drawable/mic_base"
|
||||||
|
|
|
@ -14,8 +14,13 @@
|
||||||
* the License.
|
* the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.inputmethod.voice;
|
package com.android.inputmethod.deprecated;
|
||||||
|
|
||||||
|
import com.android.inputmethod.deprecated.voice.FieldContext;
|
||||||
|
import com.android.inputmethod.deprecated.voice.Hints;
|
||||||
|
import com.android.inputmethod.deprecated.voice.SettingsUtil;
|
||||||
|
import com.android.inputmethod.deprecated.voice.VoiceInput;
|
||||||
|
import com.android.inputmethod.deprecated.voice.VoiceInputLogger;
|
||||||
import com.android.inputmethod.keyboard.KeyboardSwitcher;
|
import com.android.inputmethod.keyboard.KeyboardSwitcher;
|
||||||
import com.android.inputmethod.latin.EditingUtils;
|
import com.android.inputmethod.latin.EditingUtils;
|
||||||
import com.android.inputmethod.latin.LatinIME;
|
import com.android.inputmethod.latin.LatinIME;
|
||||||
|
@ -28,6 +33,7 @@ import com.android.inputmethod.latin.SuggestedWords;
|
||||||
import com.android.inputmethod.latin.Utils;
|
import com.android.inputmethod.latin.Utils;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -62,8 +68,8 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class VoiceIMEConnector implements VoiceInput.UiListener {
|
public class VoiceConnector implements VoiceInput.UiListener {
|
||||||
private static final VoiceIMEConnector sInstance = new VoiceIMEConnector();
|
private static final VoiceConnector sInstance = new VoiceConnector();
|
||||||
|
|
||||||
public static final boolean VOICE_INSTALLED = true;
|
public static final boolean VOICE_INSTALLED = true;
|
||||||
private static final boolean ENABLE_VOICE_BUTTON = true;
|
private static final boolean ENABLE_VOICE_BUTTON = true;
|
||||||
|
@ -77,7 +83,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
|
||||||
"has_used_voice_input_unsupported_locale";
|
"has_used_voice_input_unsupported_locale";
|
||||||
private static final int RECOGNITIONVIEW_HEIGHT_THRESHOLD_RATIO = 6;
|
private static final int RECOGNITIONVIEW_HEIGHT_THRESHOLD_RATIO = 6;
|
||||||
|
|
||||||
private static final String TAG = VoiceIMEConnector.class.getSimpleName();
|
private static final String TAG = VoiceConnector.class.getSimpleName();
|
||||||
private static final boolean DEBUG = LatinImeLogger.sDBG;
|
private static final boolean DEBUG = LatinImeLogger.sDBG;
|
||||||
|
|
||||||
private boolean mAfterVoiceInput;
|
private boolean mAfterVoiceInput;
|
||||||
|
@ -105,12 +111,12 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
|
||||||
private final Map<String, List<CharSequence>> mWordToSuggestions =
|
private final Map<String, List<CharSequence>> mWordToSuggestions =
|
||||||
new HashMap<String, List<CharSequence>>();
|
new HashMap<String, List<CharSequence>>();
|
||||||
|
|
||||||
public static VoiceIMEConnector init(LatinIME context, SharedPreferences prefs, UIHandler h) {
|
public static VoiceConnector init(LatinIME context, SharedPreferences prefs, UIHandler h) {
|
||||||
sInstance.initInternal(context, prefs, h);
|
sInstance.initInternal(context, prefs, h);
|
||||||
return sInstance;
|
return sInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static VoiceIMEConnector getInstance() {
|
public static VoiceConnector getInstance() {
|
||||||
return sInstance;
|
return sInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +139,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private VoiceIMEConnector() {
|
private VoiceConnector() {
|
||||||
// Intentional empty constructor for singleton.
|
// Intentional empty constructor for singleton.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -674,7 +680,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
|
||||||
public void onAttachedToWindow() {
|
public void onAttachedToWindow() {
|
||||||
// After onAttachedToWindow, we can show the voice warning dialog. See startListening()
|
// After onAttachedToWindow, we can show the voice warning dialog. See startListening()
|
||||||
// above.
|
// above.
|
||||||
mSubtypeSwitcher.setVoiceInput(mVoiceInput);
|
VoiceInputConnector.getInstance().setVoiceInput(mVoiceInput, mSubtypeSwitcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onConfigurationChanged(Configuration configuration) {
|
public void onConfigurationChanged(Configuration configuration) {
|
||||||
|
@ -725,4 +731,91 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
|
||||||
List<String> candidates;
|
List<String> candidates;
|
||||||
Map<String, List<CharSequence>> alternatives;
|
Map<String, List<CharSequence>> alternatives;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class VoiceLoggerConnector {
|
||||||
|
private static final VoiceLoggerConnector sInstance = new VoiceLoggerConnector();
|
||||||
|
private VoiceInputLogger mLogger;
|
||||||
|
|
||||||
|
public static VoiceLoggerConnector getInstance(Context context) {
|
||||||
|
if (sInstance.mLogger == null) {
|
||||||
|
// Not thread safe, but it's ok.
|
||||||
|
sInstance.mLogger = VoiceInputLogger.getLogger(context);
|
||||||
|
}
|
||||||
|
return sInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
// private for the singleton
|
||||||
|
private VoiceLoggerConnector() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void settingsWarningDialogCancel() {
|
||||||
|
mLogger.settingsWarningDialogCancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void settingsWarningDialogOk() {
|
||||||
|
mLogger.settingsWarningDialogOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void settingsWarningDialogShown() {
|
||||||
|
mLogger.settingsWarningDialogShown();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void settingsWarningDialogDismissed() {
|
||||||
|
mLogger.settingsWarningDialogDismissed();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void voiceInputSettingEnabled(boolean enabled) {
|
||||||
|
if (enabled) {
|
||||||
|
mLogger.voiceInputSettingEnabled();
|
||||||
|
} else {
|
||||||
|
mLogger.voiceInputSettingDisabled();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class VoiceInputConnector {
|
||||||
|
private static final VoiceInputConnector sInstance = new VoiceInputConnector();
|
||||||
|
private VoiceInput mVoiceInput;
|
||||||
|
public static VoiceInputConnector getInstance() {
|
||||||
|
return sInstance;
|
||||||
|
}
|
||||||
|
public void setVoiceInput(VoiceInput voiceInput, SubtypeSwitcher switcher) {
|
||||||
|
if (mVoiceInput == null && voiceInput != null) {
|
||||||
|
mVoiceInput = voiceInput;
|
||||||
|
switcher.setVoiceInputConnector(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private VoiceInputConnector() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cancel() {
|
||||||
|
if (mVoiceInput != null) mVoiceInput.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reset() {
|
||||||
|
if (mVoiceInput != null) mVoiceInput.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A list of locales which are supported by default for voice input, unless we get a
|
||||||
|
// different list from Gservices.
|
||||||
|
private static final String DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES =
|
||||||
|
"en " +
|
||||||
|
"en_US " +
|
||||||
|
"en_GB " +
|
||||||
|
"en_AU " +
|
||||||
|
"en_CA " +
|
||||||
|
"en_IE " +
|
||||||
|
"en_IN " +
|
||||||
|
"en_NZ " +
|
||||||
|
"en_SG " +
|
||||||
|
"en_ZA ";
|
||||||
|
|
||||||
|
public static String getSupportedLocalesString (ContentResolver resolver) {
|
||||||
|
return SettingsUtil.getSettingsString(
|
||||||
|
resolver,
|
||||||
|
SettingsUtil.LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES,
|
||||||
|
DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -14,7 +14,7 @@
|
||||||
* the License.
|
* the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.inputmethod.voice;
|
package com.android.inputmethod.deprecated.voice;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
|
@ -14,7 +14,7 @@
|
||||||
* the License.
|
* the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.inputmethod.voice;
|
package com.android.inputmethod.deprecated.voice;
|
||||||
|
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
import com.android.inputmethod.latin.SharedPreferencesCompat;
|
import com.android.inputmethod.latin.SharedPreferencesCompat;
|
|
@ -14,7 +14,7 @@
|
||||||
* the License.
|
* the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.inputmethod.voice;
|
package com.android.inputmethod.deprecated.voice;
|
||||||
|
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
import com.android.inputmethod.latin.SubtypeSwitcher;
|
import com.android.inputmethod.latin.SubtypeSwitcher;
|
|
@ -14,7 +14,7 @@
|
||||||
* the License.
|
* the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.inputmethod.voice;
|
package com.android.inputmethod.deprecated.voice;
|
||||||
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
|
@ -14,7 +14,7 @@
|
||||||
* the License.
|
* the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.inputmethod.voice;
|
package com.android.inputmethod.deprecated.voice;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
|
@ -14,7 +14,7 @@
|
||||||
* the License.
|
* the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.inputmethod.voice;
|
package com.android.inputmethod.deprecated.voice;
|
||||||
|
|
||||||
import com.android.inputmethod.latin.EditingUtils;
|
import com.android.inputmethod.latin.EditingUtils;
|
||||||
import com.android.inputmethod.latin.LatinImeLogger;
|
import com.android.inputmethod.latin.LatinImeLogger;
|
|
@ -14,7 +14,7 @@
|
||||||
* the License.
|
* the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.inputmethod.voice;
|
package com.android.inputmethod.deprecated.voice;
|
||||||
|
|
||||||
import com.android.common.speech.LoggingEvents;
|
import com.android.common.speech.LoggingEvents;
|
||||||
import com.android.common.userhappiness.UserHappinessSignals;
|
import com.android.common.userhappiness.UserHappinessSignals;
|
|
@ -14,7 +14,7 @@
|
||||||
* the License.
|
* the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.inputmethod.voice;
|
package com.android.inputmethod.deprecated.voice;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
|
@ -14,7 +14,7 @@
|
||||||
* the License.
|
* the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.inputmethod.voice;
|
package com.android.inputmethod.deprecated.voice;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
|
|
||||||
package com.android.inputmethod.keyboard;
|
package com.android.inputmethod.keyboard;
|
||||||
|
|
||||||
|
import com.android.inputmethod.deprecated.VoiceConnector;
|
||||||
import com.android.inputmethod.latin.LatinImeLogger;
|
import com.android.inputmethod.latin.LatinImeLogger;
|
||||||
import com.android.inputmethod.latin.Utils;
|
import com.android.inputmethod.latin.Utils;
|
||||||
import com.android.inputmethod.voice.VoiceIMEConnector;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
|
@ -264,6 +264,6 @@ public class LatinKeyboardView extends KeyboardView {
|
||||||
@Override
|
@Override
|
||||||
protected void onAttachedToWindow() {
|
protected void onAttachedToWindow() {
|
||||||
// Token is available from here.
|
// Token is available from here.
|
||||||
VoiceIMEConnector.getInstance().onAttachedToWindow();
|
VoiceConnector.getInstance().onAttachedToWindow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package com.android.inputmethod.latin;
|
package com.android.inputmethod.latin;
|
||||||
|
|
||||||
|
import com.android.inputmethod.deprecated.VoiceConnector;
|
||||||
import com.android.inputmethod.keyboard.Keyboard;
|
import com.android.inputmethod.keyboard.Keyboard;
|
||||||
import com.android.inputmethod.keyboard.KeyboardActionListener;
|
import com.android.inputmethod.keyboard.KeyboardActionListener;
|
||||||
import com.android.inputmethod.keyboard.KeyboardSwitcher;
|
import com.android.inputmethod.keyboard.KeyboardSwitcher;
|
||||||
|
@ -23,7 +24,6 @@ import com.android.inputmethod.keyboard.KeyboardView;
|
||||||
import com.android.inputmethod.keyboard.LatinKeyboard;
|
import com.android.inputmethod.keyboard.LatinKeyboard;
|
||||||
import com.android.inputmethod.keyboard.LatinKeyboardView;
|
import com.android.inputmethod.keyboard.LatinKeyboardView;
|
||||||
import com.android.inputmethod.latin.Utils.RingCharBuffer;
|
import com.android.inputmethod.latin.Utils.RingCharBuffer;
|
||||||
import com.android.inputmethod.voice.VoiceIMEConnector;
|
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
|
@ -146,7 +146,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
private String mInputMethodId;
|
private String mInputMethodId;
|
||||||
private KeyboardSwitcher mKeyboardSwitcher;
|
private KeyboardSwitcher mKeyboardSwitcher;
|
||||||
private SubtypeSwitcher mSubtypeSwitcher;
|
private SubtypeSwitcher mSubtypeSwitcher;
|
||||||
private VoiceIMEConnector mVoiceConnector;
|
private VoiceConnector mVoiceConnector;
|
||||||
|
|
||||||
private UserDictionary mUserDictionary;
|
private UserDictionary mUserDictionary;
|
||||||
private UserBigramDictionary mUserBigramDictionary;
|
private UserBigramDictionary mUserBigramDictionary;
|
||||||
|
@ -419,7 +419,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
|
filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
|
||||||
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
||||||
registerReceiver(mReceiver, filter);
|
registerReceiver(mReceiver, filter);
|
||||||
mVoiceConnector = VoiceIMEConnector.init(this, prefs, mHandler);
|
mVoiceConnector = VoiceConnector.init(this, prefs, mHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initSuggest() {
|
private void initSuggest() {
|
||||||
|
@ -531,7 +531,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
// Most such things we decide below in initializeInputAttributesAndGetMode, but we need to
|
// Most such things we decide below in initializeInputAttributesAndGetMode, but we need to
|
||||||
// know now whether this is a password text field, because we need to know now whether we
|
// know now whether this is a password text field, because we need to know now whether we
|
||||||
// want to enable the voice button.
|
// want to enable the voice button.
|
||||||
final VoiceIMEConnector voiceIme = mVoiceConnector;
|
final VoiceConnector voiceIme = mVoiceConnector;
|
||||||
voiceIme.resetVoiceStates(Utils.isPasswordInputType(attribute.inputType)
|
voiceIme.resetVoiceStates(Utils.isPasswordInputType(attribute.inputType)
|
||||||
|| Utils.isVisiblePasswordInputType(attribute.inputType));
|
|| Utils.isVisiblePasswordInputType(attribute.inputType));
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,7 @@
|
||||||
|
|
||||||
package com.android.inputmethod.latin;
|
package com.android.inputmethod.latin;
|
||||||
|
|
||||||
import com.android.inputmethod.voice.VoiceIMEConnector;
|
import com.android.inputmethod.deprecated.VoiceConnector;
|
||||||
import com.android.inputmethod.voice.VoiceInputLogger;
|
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
|
@ -82,7 +81,7 @@ public class Settings extends PreferenceActivity
|
||||||
|
|
||||||
private AlertDialog mDialog;
|
private AlertDialog mDialog;
|
||||||
|
|
||||||
private VoiceInputLogger mLogger;
|
private VoiceConnector.VoiceLoggerConnector mVoiceLogger;
|
||||||
|
|
||||||
private boolean mOkClicked = false;
|
private boolean mOkClicked = false;
|
||||||
private String mVoiceModeOff;
|
private String mVoiceModeOff;
|
||||||
|
@ -111,7 +110,7 @@ public class Settings extends PreferenceActivity
|
||||||
mVoiceModeOff = getString(R.string.voice_mode_off);
|
mVoiceModeOff = getString(R.string.voice_mode_off);
|
||||||
mVoiceOn = !(prefs.getString(PREF_VOICE_SETTINGS_KEY, mVoiceModeOff)
|
mVoiceOn = !(prefs.getString(PREF_VOICE_SETTINGS_KEY, mVoiceModeOff)
|
||||||
.equals(mVoiceModeOff));
|
.equals(mVoiceModeOff));
|
||||||
mLogger = VoiceInputLogger.getLogger(this);
|
mVoiceLogger = VoiceConnector.VoiceLoggerConnector.getInstance(this);
|
||||||
|
|
||||||
mAutoCorrectionThreshold = (ListPreference) findPreference(PREF_AUTO_CORRECTION_THRESHOLD);
|
mAutoCorrectionThreshold = (ListPreference) findPreference(PREF_AUTO_CORRECTION_THRESHOLD);
|
||||||
mBigramSuggestion = (CheckBoxPreference) findPreference(PREF_BIGRAM_SUGGESTIONS);
|
mBigramSuggestion = (CheckBoxPreference) findPreference(PREF_BIGRAM_SUGGESTIONS);
|
||||||
|
@ -184,7 +183,7 @@ public class Settings extends PreferenceActivity
|
||||||
((PreferenceGroup) findPreference(PREF_PREDICTION_SETTINGS_KEY))
|
((PreferenceGroup) findPreference(PREF_PREDICTION_SETTINGS_KEY))
|
||||||
.removePreference(mQuickFixes);
|
.removePreference(mQuickFixes);
|
||||||
}
|
}
|
||||||
if (!VoiceIMEConnector.VOICE_INSTALLED
|
if (!VoiceConnector.VOICE_INSTALLED
|
||||||
|| !SpeechRecognizer.isRecognitionAvailable(this)) {
|
|| !SpeechRecognizer.isRecognitionAvailable(this)) {
|
||||||
getPreferenceScreen().removePreference(mVoicePreference);
|
getPreferenceScreen().removePreference(mVoicePreference);
|
||||||
} else {
|
} else {
|
||||||
|
@ -277,10 +276,10 @@ public class Settings extends PreferenceActivity
|
||||||
public void onClick(DialogInterface dialog, int whichButton) {
|
public void onClick(DialogInterface dialog, int whichButton) {
|
||||||
if (whichButton == DialogInterface.BUTTON_NEGATIVE) {
|
if (whichButton == DialogInterface.BUTTON_NEGATIVE) {
|
||||||
mVoicePreference.setValue(mVoiceModeOff);
|
mVoicePreference.setValue(mVoiceModeOff);
|
||||||
mLogger.settingsWarningDialogCancel();
|
mVoiceLogger.settingsWarningDialogCancel();
|
||||||
} else if (whichButton == DialogInterface.BUTTON_POSITIVE) {
|
} else if (whichButton == DialogInterface.BUTTON_POSITIVE) {
|
||||||
mOkClicked = true;
|
mOkClicked = true;
|
||||||
mLogger.settingsWarningDialogOk();
|
mVoiceLogger.settingsWarningDialogOk();
|
||||||
}
|
}
|
||||||
updateVoicePreference();
|
updateVoicePreference();
|
||||||
}
|
}
|
||||||
|
@ -311,7 +310,7 @@ public class Settings extends PreferenceActivity
|
||||||
AlertDialog dialog = builder.create();
|
AlertDialog dialog = builder.create();
|
||||||
mDialog = dialog;
|
mDialog = dialog;
|
||||||
dialog.setOnDismissListener(this);
|
dialog.setOnDismissListener(this);
|
||||||
mLogger.settingsWarningDialogShown();
|
mVoiceLogger.settingsWarningDialogShown();
|
||||||
return dialog;
|
return dialog;
|
||||||
default:
|
default:
|
||||||
Log.e(TAG, "unknown dialog " + id);
|
Log.e(TAG, "unknown dialog " + id);
|
||||||
|
@ -321,7 +320,7 @@ public class Settings extends PreferenceActivity
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDismiss(DialogInterface dialog) {
|
public void onDismiss(DialogInterface dialog) {
|
||||||
mLogger.settingsWarningDialogDismissed();
|
mVoiceLogger.settingsWarningDialogDismissed();
|
||||||
if (!mOkClicked) {
|
if (!mOkClicked) {
|
||||||
// This assumes that onPreferenceClick gets called first, and this if the user
|
// This assumes that onPreferenceClick gets called first, and this if the user
|
||||||
// agreed after the warning, we set the mOkClicked value to true.
|
// agreed after the warning, we set the mOkClicked value to true.
|
||||||
|
@ -331,10 +330,6 @@ public class Settings extends PreferenceActivity
|
||||||
|
|
||||||
private void updateVoicePreference() {
|
private void updateVoicePreference() {
|
||||||
boolean isChecked = !mVoicePreference.getValue().equals(mVoiceModeOff);
|
boolean isChecked = !mVoicePreference.getValue().equals(mVoiceModeOff);
|
||||||
if (isChecked) {
|
mVoiceLogger.voiceInputSettingEnabled(isChecked);
|
||||||
mLogger.voiceInputSettingEnabled();
|
|
||||||
} else {
|
|
||||||
mLogger.voiceInputSettingDisabled();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,9 @@
|
||||||
|
|
||||||
package com.android.inputmethod.latin;
|
package com.android.inputmethod.latin;
|
||||||
|
|
||||||
|
import com.android.inputmethod.deprecated.VoiceConnector;
|
||||||
import com.android.inputmethod.keyboard.KeyboardSwitcher;
|
import com.android.inputmethod.keyboard.KeyboardSwitcher;
|
||||||
import com.android.inputmethod.keyboard.LatinKeyboard;
|
import com.android.inputmethod.keyboard.LatinKeyboard;
|
||||||
import com.android.inputmethod.voice.SettingsUtil;
|
|
||||||
import com.android.inputmethod.voice.VoiceIMEConnector;
|
|
||||||
import com.android.inputmethod.voice.VoiceInput;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -78,7 +76,7 @@ public class SubtypeSwitcher {
|
||||||
private Locale mSystemLocale;
|
private Locale mSystemLocale;
|
||||||
private Locale mInputLocale;
|
private Locale mInputLocale;
|
||||||
private String mInputLocaleStr;
|
private String mInputLocaleStr;
|
||||||
private VoiceInput mVoiceInput;
|
private VoiceConnector.VoiceInputConnector mVoiceInputConnector;
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
private boolean mIsNetworkConnected;
|
private boolean mIsNetworkConnected;
|
||||||
|
@ -113,7 +111,7 @@ public class SubtypeSwitcher {
|
||||||
mCurrentSubtype = null;
|
mCurrentSubtype = null;
|
||||||
mAllEnabledSubtypesOfCurrentInputMethod = null;
|
mAllEnabledSubtypesOfCurrentInputMethod = null;
|
||||||
// TODO: Voice input should be created here
|
// TODO: Voice input should be created here
|
||||||
mVoiceInput = null;
|
mVoiceInputConnector = null;
|
||||||
mConfigUseSpacebarLanguageSwitcher = mResources.getBoolean(
|
mConfigUseSpacebarLanguageSwitcher = mResources.getBoolean(
|
||||||
R.bool.config_use_spacebar_language_switcher);
|
R.bool.config_use_spacebar_language_switcher);
|
||||||
if (mConfigUseSpacebarLanguageSwitcher)
|
if (mConfigUseSpacebarLanguageSwitcher)
|
||||||
|
@ -243,30 +241,30 @@ public class SubtypeSwitcher {
|
||||||
// We cancel its status when we change mode, while we reset otherwise.
|
// We cancel its status when we change mode, while we reset otherwise.
|
||||||
if (isKeyboardMode()) {
|
if (isKeyboardMode()) {
|
||||||
if (modeChanged) {
|
if (modeChanged) {
|
||||||
if (VOICE_MODE.equals(oldMode) && mVoiceInput != null) {
|
if (VOICE_MODE.equals(oldMode) && mVoiceInputConnector != null) {
|
||||||
mVoiceInput.cancel();
|
mVoiceInputConnector.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (modeChanged || languageChanged) {
|
if (modeChanged || languageChanged) {
|
||||||
updateShortcutIME();
|
updateShortcutIME();
|
||||||
mService.onRefreshKeyboard();
|
mService.onRefreshKeyboard();
|
||||||
}
|
}
|
||||||
} else if (isVoiceMode() && mVoiceInput != null) {
|
} else if (isVoiceMode() && mVoiceInputConnector != null) {
|
||||||
if (VOICE_MODE.equals(oldMode)) {
|
if (VOICE_MODE.equals(oldMode)) {
|
||||||
mVoiceInput.reset();
|
mVoiceInputConnector.reset();
|
||||||
}
|
}
|
||||||
// If needsToShowWarningDialog is true, voice input need to show warning before
|
// If needsToShowWarningDialog is true, voice input need to show warning before
|
||||||
// show recognition view.
|
// show recognition view.
|
||||||
if (languageChanged || modeChanged
|
if (languageChanged || modeChanged
|
||||||
|| VoiceIMEConnector.getInstance().needsToShowWarningDialog()) {
|
|| VoiceConnector.getInstance().needsToShowWarningDialog()) {
|
||||||
triggerVoiceIME();
|
triggerVoiceIME();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.w(TAG, "Unknown subtype mode: " + newMode);
|
Log.w(TAG, "Unknown subtype mode: " + newMode);
|
||||||
if (VOICE_MODE.equals(oldMode) && mVoiceInput != null) {
|
if (VOICE_MODE.equals(oldMode) && mVoiceInputConnector != null) {
|
||||||
// We need to reset the voice input to release the resources and to reset its status
|
// We need to reset the voice input to release the resources and to reset its status
|
||||||
// as it is not the current input mode.
|
// as it is not the current input mode.
|
||||||
mVoiceInput.reset();
|
mVoiceInputConnector.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -507,9 +505,9 @@ public class SubtypeSwitcher {
|
||||||
// Voice Input functions //
|
// Voice Input functions //
|
||||||
///////////////////////////
|
///////////////////////////
|
||||||
|
|
||||||
public boolean setVoiceInput(VoiceInput vi) {
|
public boolean setVoiceInputConnector(VoiceConnector.VoiceInputConnector vi) {
|
||||||
if (mVoiceInput == null && vi != null) {
|
if (mVoiceInputConnector == null && vi != null) {
|
||||||
mVoiceInput = vi;
|
mVoiceInputConnector = vi;
|
||||||
if (isVoiceMode()) {
|
if (isVoiceMode()) {
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
Log.d(TAG, "Set and call voice input.: " + getInputLocaleStr());
|
Log.d(TAG, "Set and call voice input.: " + getInputLocaleStr());
|
||||||
|
@ -527,7 +525,7 @@ public class SubtypeSwitcher {
|
||||||
|
|
||||||
private void triggerVoiceIME() {
|
private void triggerVoiceIME() {
|
||||||
if (!mService.isInputViewShown()) return;
|
if (!mService.isInputViewShown()) return;
|
||||||
VoiceIMEConnector.getInstance().startListening(false,
|
VoiceConnector.getInstance().startListening(false,
|
||||||
KeyboardSwitcher.getInstance().getInputView().getWindowToken());
|
KeyboardSwitcher.getInstance().getInputView().getWindowToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -612,30 +610,14 @@ public class SubtypeSwitcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// A list of locales which are supported by default for voice input, unless we get a
|
|
||||||
// different list from Gservices.
|
|
||||||
private static final String DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES =
|
|
||||||
"en " +
|
|
||||||
"en_US " +
|
|
||||||
"en_GB " +
|
|
||||||
"en_AU " +
|
|
||||||
"en_CA " +
|
|
||||||
"en_IE " +
|
|
||||||
"en_IN " +
|
|
||||||
"en_NZ " +
|
|
||||||
"en_SG " +
|
|
||||||
"en_ZA ";
|
|
||||||
|
|
||||||
public boolean isVoiceSupported(String locale) {
|
public boolean isVoiceSupported(String locale) {
|
||||||
// Get the current list of supported locales and check the current locale against that
|
// Get the current list of supported locales and check the current locale against that
|
||||||
// list. We cache this value so as not to check it every time the user starts a voice
|
// list. We cache this value so as not to check it every time the user starts a voice
|
||||||
// input. Because this method is called by onStartInputView, this should mean that as
|
// input. Because this method is called by onStartInputView, this should mean that as
|
||||||
// long as the locale doesn't change while the user is keeping the IME open, the
|
// long as the locale doesn't change while the user is keeping the IME open, the
|
||||||
// value should never be stale.
|
// value should never be stale.
|
||||||
String supportedLocalesString = SettingsUtil.getSettingsString(
|
String supportedLocalesString = VoiceConnector.getSupportedLocalesString(
|
||||||
mService.getContentResolver(),
|
mService.getContentResolver());
|
||||||
SettingsUtil.LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES,
|
|
||||||
DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES);
|
|
||||||
List<String> voiceInputSupportedLocales = Arrays.asList(
|
List<String> voiceInputSupportedLocales = Arrays.asList(
|
||||||
supportedLocalesString.split("\\s+"));
|
supportedLocalesString.split("\\s+"));
|
||||||
return voiceInputSupportedLocales.contains(locale);
|
return voiceInputSupportedLocales.contains(locale);
|
||||||
|
|
Loading…
Reference in a new issue