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
parent
30a7315878
commit
2e3aa86cf3
|
@ -109,6 +109,13 @@ public class LanguageSwitcher {
|
||||||
return mSelectedLanguageArray[mCurrentIndex];
|
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
|
* Returns the currently selected input locale, or the display locale if no specific
|
||||||
* locale was selected for input.
|
* locale was selected for input.
|
||||||
|
|
|
@ -1202,7 +1202,10 @@ public class LatinIME extends InputMethodService
|
||||||
setSuggestions(null, false, false, true);
|
setSuggestions(null, false, false, true);
|
||||||
|
|
||||||
FieldContext context = new FieldContext(
|
FieldContext context = new FieldContext(
|
||||||
getCurrentInputConnection(), getCurrentInputEditorInfo());
|
getCurrentInputConnection(),
|
||||||
|
getCurrentInputEditorInfo(),
|
||||||
|
mLanguageSwitcher.getInputLanguage(),
|
||||||
|
mLanguageSwitcher.getEnabledLanguages());
|
||||||
mVoiceInput.startListening(context, swipe);
|
mVoiceInput.startListening(context, swipe);
|
||||||
switchToRecognitionStatusView();
|
switchToRecognitionStatusView();
|
||||||
}
|
}
|
||||||
|
@ -1576,7 +1579,11 @@ public class LatinIME extends InputMethodService
|
||||||
}
|
}
|
||||||
|
|
||||||
private FieldContext makeFieldContext() {
|
private FieldContext makeFieldContext() {
|
||||||
return new FieldContext(getCurrentInputConnection(), getCurrentInputEditorInfo());
|
return new FieldContext(
|
||||||
|
getCurrentInputConnection(),
|
||||||
|
getCurrentInputEditorInfo(),
|
||||||
|
mLanguageSwitcher.getInputLanguage(),
|
||||||
|
mLanguageSwitcher.getEnabledLanguages());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean fieldCanDoVoice(FieldContext fieldContext) {
|
private boolean fieldCanDoVoice(FieldContext fieldContext) {
|
||||||
|
|
|
@ -28,6 +28,8 @@ import android.view.inputmethod.InputConnection;
|
||||||
* to the speech recognizer as context information.
|
* to the speech recognizer as context information.
|
||||||
*/
|
*/
|
||||||
public class FieldContext {
|
public class FieldContext {
|
||||||
|
private static final boolean DBG = false;
|
||||||
|
|
||||||
static final String LABEL = "label";
|
static final String LABEL = "label";
|
||||||
static final String HINT = "hint";
|
static final String HINT = "hint";
|
||||||
static final String PACKAGE_NAME = "packageName";
|
static final String PACKAGE_NAME = "packageName";
|
||||||
|
@ -36,14 +38,18 @@ public class FieldContext {
|
||||||
static final String SINGLE_LINE = "singleLine";
|
static final String SINGLE_LINE = "singleLine";
|
||||||
static final String INPUT_TYPE = "inputType";
|
static final String INPUT_TYPE = "inputType";
|
||||||
static final String IME_OPTIONS = "imeOptions";
|
static final String IME_OPTIONS = "imeOptions";
|
||||||
|
static final String SELECTED_LANGUAGE = "selectedLanguage";
|
||||||
|
static final String ENABLED_LANGUAGES = "enabledLanguages";
|
||||||
|
|
||||||
Bundle mFieldInfo;
|
Bundle mFieldInfo;
|
||||||
|
|
||||||
public FieldContext(InputConnection conn, EditorInfo info) {
|
public FieldContext(InputConnection conn, EditorInfo info,
|
||||||
this.mFieldInfo = new Bundle();
|
String selectedLanguage, String[] enabledLanguages) {
|
||||||
|
mFieldInfo = new Bundle();
|
||||||
addEditorInfoToBundle(info, mFieldInfo);
|
addEditorInfoToBundle(info, mFieldInfo);
|
||||||
addInputConnectionToBundle(conn, 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) {
|
private static String safeToString(Object o) {
|
||||||
|
@ -58,7 +64,6 @@ public class FieldContext {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bundle.putString(LABEL, safeToString(info.label));
|
bundle.putString(LABEL, safeToString(info.label));
|
||||||
bundle.putString(HINT, safeToString(info.hintText));
|
bundle.putString(HINT, safeToString(info.hintText));
|
||||||
bundle.putString(PACKAGE_NAME, safeToString(info.packageName));
|
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);
|
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() {
|
public Bundle getBundle() {
|
||||||
return mFieldInfo;
|
return mFieldInfo;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue