@@ -33,7 +33,6 @@ public class ServiceLanguageChooser {
33
33
private final String mAppId ;
34
34
private final int mKeyCurrentCombo ;
35
35
private int mIndex ;
36
- private SpeechRecognizer mSpeechRecognizer ;
37
36
private Intent mIntent ;
38
37
private String mLanguage = null ;
39
38
private ComponentName mRecognizerComponentName = null ;
@@ -87,9 +86,16 @@ public ServiceLanguageChooser(Context context, SharedPreferences prefs, int keys
87
86
update ();
88
87
}
89
88
90
-
89
+ /**
90
+ * If the stored recognizer component name does not refer to an existing service on the device then we use
91
+ * the default service. This can happen if services get removed or renamed.
92
+ * TODO: improve
93
+ */
91
94
public SpeechRecognizer getSpeechRecognizer () {
92
- return mSpeechRecognizer ;
95
+ if (mRecognizerComponentName == null || !IntentUtils .isRecognitionAvailable (mContext , mRecognizerComponentName )) {
96
+ return SpeechRecognizer .createSpeechRecognizer (mContext );
97
+ }
98
+ return SpeechRecognizer .createSpeechRecognizer (mContext , mRecognizerComponentName );
93
99
}
94
100
95
101
public int size () {
@@ -139,10 +145,12 @@ public String getCombo() {
139
145
return mCombosAsList .get (mIndex );
140
146
}
141
147
148
+ // TODO: can return null, but some callers expect non-null
142
149
public String getLanguage () {
143
150
return mLanguage ;
144
151
}
145
152
153
+ // TODO: can return null, but some callers expect non-null
146
154
public ComponentName getService () {
147
155
return mRecognizerComponentName ;
148
156
}
@@ -156,14 +164,6 @@ private void update() {
156
164
language = splits [1 ];
157
165
}
158
166
159
- // If the stored combo name does not refer to an existing service on the device then we use
160
- // the default service. This can happen if services get removed or renamed.
161
- if (mRecognizerComponentName == null || !IntentUtils .isRecognitionAvailable (mContext , mRecognizerComponentName )) {
162
- mSpeechRecognizer = SpeechRecognizer .createSpeechRecognizer (mContext );
163
- } else {
164
- mSpeechRecognizer = SpeechRecognizer .createSpeechRecognizer (mContext , mRecognizerComponentName );
165
- }
166
-
167
167
// TODO: support other actions
168
168
mIntent = Utils .getRecognizerIntent (RecognizerIntent .ACTION_RECOGNIZE_SPEECH , mCallerInfo , language );
169
169
mLanguage = language ;
0 commit comments