Add additional language information to FieldContext used for voice input.

This will allow us to choose the right voice input language for the user
on the VoiceSearch side.
main
Mike LeBeau 2010-02-04 18:31:40 -08:00
parent 30a7315878
commit 2e3aa86cf3
3 changed files with 31 additions and 6 deletions

View File

@ -109,6 +109,13 @@ public class LanguageSwitcher {
return mSelectedLanguageArray[mCurrentIndex];
}
/**
* Returns the list of enabled language codes.
*/
public String[] getEnabledLanguages() {
return mSelectedLanguageArray;
}
/**
* Returns the currently selected input locale, or the display locale if no specific
* locale was selected for input.

View File

@ -1202,7 +1202,10 @@ public class LatinIME extends InputMethodService
setSuggestions(null, false, false, true);
FieldContext context = new FieldContext(
getCurrentInputConnection(), getCurrentInputEditorInfo());
getCurrentInputConnection(),
getCurrentInputEditorInfo(),
mLanguageSwitcher.getInputLanguage(),
mLanguageSwitcher.getEnabledLanguages());
mVoiceInput.startListening(context, swipe);
switchToRecognitionStatusView();
}
@ -1576,7 +1579,11 @@ public class LatinIME extends InputMethodService
}
private FieldContext makeFieldContext() {
return new FieldContext(getCurrentInputConnection(), getCurrentInputEditorInfo());
return new FieldContext(
getCurrentInputConnection(),
getCurrentInputEditorInfo(),
mLanguageSwitcher.getInputLanguage(),
mLanguageSwitcher.getEnabledLanguages());
}
private boolean fieldCanDoVoice(FieldContext fieldContext) {

View File

@ -28,6 +28,8 @@ import android.view.inputmethod.InputConnection;
* to the speech recognizer as context information.
*/
public class FieldContext {
private static final boolean DBG = false;
static final String LABEL = "label";
static final String HINT = "hint";
static final String PACKAGE_NAME = "packageName";
@ -36,14 +38,18 @@ public class FieldContext {
static final String SINGLE_LINE = "singleLine";
static final String INPUT_TYPE = "inputType";
static final String IME_OPTIONS = "imeOptions";
static final String SELECTED_LANGUAGE = "selectedLanguage";
static final String ENABLED_LANGUAGES = "enabledLanguages";
Bundle mFieldInfo;
public FieldContext(InputConnection conn, EditorInfo info) {
this.mFieldInfo = new Bundle();
public FieldContext(InputConnection conn, EditorInfo info,
String selectedLanguage, String[] enabledLanguages) {
mFieldInfo = new Bundle();
addEditorInfoToBundle(info, mFieldInfo);
addInputConnectionToBundle(conn, mFieldInfo);
Log.i("FieldContext", "Bundle = " + mFieldInfo.toString());
addLanguageInfoToBundle(selectedLanguage, enabledLanguages, mFieldInfo);
if (DBG) Log.i("FieldContext", "Bundle = " + mFieldInfo.toString());
}
private static String safeToString(Object o) {
@ -58,7 +64,6 @@ public class FieldContext {
return;
}
bundle.putString(LABEL, safeToString(info.label));
bundle.putString(HINT, safeToString(info.hintText));
bundle.putString(PACKAGE_NAME, safeToString(info.packageName));
@ -81,6 +86,12 @@ public class FieldContext {
bundle.putBoolean(SINGLE_LINE, (et.flags & et.FLAG_SINGLE_LINE) > 0);
}
private static void addLanguageInfoToBundle(
String selectedLanguage, String[] enabledLanguages, Bundle bundle) {
bundle.putString(SELECTED_LANGUAGE, selectedLanguage);
bundle.putStringArray(ENABLED_LANGUAGES, enabledLanguages);
}
public Bundle getBundle() {
return mFieldInfo;
}