aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/android/inputmethod/voice/FieldContext.java
diff options
context:
space:
mode:
authorMike LeBeau <mlebeau@android.com>2010-01-16 12:21:23 -0800
committerMike LeBeau <mlebeau@android.com>2010-01-17 02:42:58 -0500
commit466741d8a78965b8509bf527344f289e50873092 (patch)
treea391762c52cee87df8e0482cbd3bdc5aed87d988 /src/com/android/inputmethod/voice/FieldContext.java
parent388ce92ab8a635c5ad44620dad59baf05dfea510 (diff)
downloadlatinime-466741d8a78965b8509bf527344f289e50873092.tar.gz
latinime-466741d8a78965b8509bf527344f289e50873092.tar.xz
latinime-466741d8a78965b8509bf527344f289e50873092.zip
Migrate voice features into the open-source LatinIME. This includes
the change to logging to remove any private dependencies and use broadcast intents to VoiceSearch instead. I have audited this code and it appears good to go for open-source, but would appreciate a second pair of eyes. Still to do after submitting this CL: * Reintroduce Amith's memory leak fix (37557) which was the only CL added to LatinIME since the last merge over to the private copy. * Make some changes to allow LatinIME to work without voice search installed. Currently I believe it will show the mic but fail if you press it. We need to base the visibility on the mic on the availability of the service. * Fix this code to use the new Gservices framework, it's still trying to use the old one.
Diffstat (limited to 'src/com/android/inputmethod/voice/FieldContext.java')
-rw-r--r--src/com/android/inputmethod/voice/FieldContext.java91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/com/android/inputmethod/voice/FieldContext.java b/src/com/android/inputmethod/voice/FieldContext.java
new file mode 100644
index 000000000..0578af732
--- /dev/null
+++ b/src/com/android/inputmethod/voice/FieldContext.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.android.inputmethod.voice;
+
+import android.os.Bundle;
+import android.util.Log;
+import android.view.inputmethod.EditorInfo;
+import android.view.inputmethod.ExtractedText;
+import android.view.inputmethod.ExtractedTextRequest;
+import android.view.inputmethod.InputConnection;
+
+/**
+ * Represents information about a given text field, which can be passed
+ * to the speech recognizer as context information.
+ */
+public class FieldContext {
+ static final String LABEL = "label";
+ static final String HINT = "hint";
+ static final String PACKAGE_NAME = "packageName";
+ static final String FIELD_ID = "fieldId";
+ static final String FIELD_NAME = "fieldName";
+ static final String SINGLE_LINE = "singleLine";
+ static final String INPUT_TYPE = "inputType";
+ static final String IME_OPTIONS = "imeOptions";
+
+ Bundle mFieldInfo;
+
+ public FieldContext(InputConnection conn, EditorInfo info) {
+ this.mFieldInfo = new Bundle();
+ addEditorInfoToBundle(info, mFieldInfo);
+ addInputConnectionToBundle(conn, mFieldInfo);
+ Log.i("FieldContext", "Bundle = " + mFieldInfo.toString());
+ }
+
+ private static String safeToString(Object o) {
+ if (o == null) {
+ return "";
+ }
+ return o.toString();
+ }
+
+ private static void addEditorInfoToBundle(EditorInfo info, Bundle bundle) {
+ if (info == null) {
+ return;
+ }
+
+
+ bundle.putString(LABEL, safeToString(info.label));
+ bundle.putString(HINT, safeToString(info.hintText));
+ bundle.putString(PACKAGE_NAME, safeToString(info.packageName));
+ bundle.putInt(FIELD_ID, info.fieldId);
+ bundle.putString(FIELD_NAME, safeToString(info.fieldName));
+ bundle.putInt(INPUT_TYPE, info.inputType);
+ bundle.putInt(IME_OPTIONS, info.imeOptions);
+ }
+
+ private static void addInputConnectionToBundle(
+ InputConnection conn, Bundle bundle) {
+ if (conn == null) {
+ return;
+ }
+
+ ExtractedText et = conn.getExtractedText(new ExtractedTextRequest(), 0);
+ if (et == null) {
+ return;
+ }
+ bundle.putBoolean(SINGLE_LINE, (et.flags & et.FLAG_SINGLE_LINE) > 0);
+ }
+
+ public Bundle getBundle() {
+ return mFieldInfo;
+ }
+
+ public String toString() {
+ return mFieldInfo.toString();
+ }
+}