aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/android/inputmethod/voice
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/inputmethod/voice')
-rw-r--r--src/com/android/inputmethod/voice/RecognitionView.java30
-rw-r--r--src/com/android/inputmethod/voice/SettingsUtil.java (renamed from src/com/android/inputmethod/voice/GoogleSettingsUtil.java)102
-rw-r--r--src/com/android/inputmethod/voice/VoiceInput.java60
3 files changed, 65 insertions, 127 deletions
diff --git a/src/com/android/inputmethod/voice/RecognitionView.java b/src/com/android/inputmethod/voice/RecognitionView.java
index 97acb1152..fd3d6d0de 100644
--- a/src/com/android/inputmethod/voice/RecognitionView.java
+++ b/src/com/android/inputmethod/voice/RecognitionView.java
@@ -1,12 +1,12 @@
/*
* 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
@@ -36,7 +36,7 @@ import android.widget.ImageView;
import android.widget.TextView;
import com.android.inputmethod.latin.R;
-import com.android.inputmethod.voice.GoogleSettingsUtil;
+import com.android.inputmethod.voice.SettingsUtil;
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
@@ -112,10 +112,10 @@ public class RecognitionView {
mView = inflater.inflate(R.layout.recognition_status, null);
ContentResolver cr = context.getContentResolver();
- mMinMicrophoneLevel = GoogleSettingsUtil.getGservicesFloat(
- cr, GoogleSettingsUtil.LATIN_IME_MIN_MICROPHONE_LEVEL, 15.f);
- mMaxMicrophoneLevel = GoogleSettingsUtil.getGservicesFloat(
- cr, GoogleSettingsUtil.LATIN_IME_MAX_MICROPHONE_LEVEL, 30.f);
+ mMinMicrophoneLevel = SettingsUtil.getSettingsFloat(
+ cr, SettingsUtil.LATIN_IME_MIN_MICROPHONE_LEVEL, 15.f);
+ mMaxMicrophoneLevel = SettingsUtil.getSettingsFloat(
+ cr, SettingsUtil.LATIN_IME_MAX_MICROPHONE_LEVEL, 30.f);
// Pre-load volume level images
Resources r = context.getResources();
@@ -131,7 +131,7 @@ public class RecognitionView {
mInitializing = r.getDrawable(R.drawable.mic_slash);
mError = r.getDrawable(R.drawable.caution);
-
+
mImage = (ImageView) mView.findViewById(R.id.image);
mButton = mView.findViewById(R.id.button);
mButton.setOnClickListener(clickListener);
@@ -207,12 +207,12 @@ public class RecognitionView {
final ShortBuffer buf = ByteBuffer.wrap(waveBuffer.toByteArray())
.order(ByteOrder.nativeOrder()).asShortBuffer();
buf.position(0);
- waveBuffer.reset();
+ waveBuffer.reset();
showWave(buf, speechStartPosition / 2, speechEndPosition / 2);
}
});
}
-
+
/**
* @return an average abs of the specified buffer.
*/
@@ -295,15 +295,15 @@ public class RecognitionView {
MarginLayoutParams mProgressParams = (MarginLayoutParams)mProgress.getLayoutParams();
mProgressParams.topMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
-h / 2 - 18, mContext.getResources().getDisplayMetrics());
-
+
// Tweak the padding manually to fill out the whole view horizontally.
// TODO: Do this in the xml layout instead.
- ((View) mImage.getParent()).setPadding(4, ((View) mImage.getParent()).getPaddingTop(), 3,
+ ((View) mImage.getParent()).setPadding(4, ((View) mImage.getParent()).getPaddingTop(), 3,
((View) mImage.getParent()).getPaddingBottom());
- mProgress.setLayoutParams(mProgressParams);
+ mProgress.setLayoutParams(mProgressParams);
}
-
+
public void finish() {
mState = State.READY;
mUiHandler.post(new Runnable() {
diff --git a/src/com/android/inputmethod/voice/GoogleSettingsUtil.java b/src/com/android/inputmethod/voice/SettingsUtil.java
index d238579ba..abf52047f 100644
--- a/src/com/android/inputmethod/voice/GoogleSettingsUtil.java
+++ b/src/com/android/inputmethod/voice/SettingsUtil.java
@@ -19,20 +19,19 @@ package com.android.inputmethod.voice;
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
+import android.provider.Settings;
import android.util.Log;
/**
- * Utility for getting Google-specific settings from GoogleSettings.Partner or
- * Gservices. Retrieving such settings may fail on a non-Google Experience
- * Device (GED)
+ * Utility for retrieving settings from Settings.Secure.
*/
-public class GoogleSettingsUtil {
+public class SettingsUtil {
/**
* A whitespace-separated list of supported locales for voice input from the keyboard.
*/
public static final String LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES =
"latin_ime_voice_input_supported_locales";
-
+
/**
* A whitespace-separated list of recommended app packages for voice input from the
* keyboard.
@@ -45,7 +44,7 @@ public class GoogleSettingsUtil {
*/
public static final String LATIN_IME_VOICE_INPUT_SWIPE_HINT_MAX_DAYS =
"latin_ime_voice_input_swipe_hint_max_days";
-
+
/**
* The maximum number of times to show the punctuation hint for voice input.
*/
@@ -60,7 +59,7 @@ public class GoogleSettingsUtil {
public static final String LATIN_IME_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS =
"latin_ime_speech_input_complete_silence_length_millis";
public static final String LATIN_IME_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS =
- "latin_ime_speech_input_possibly_complete_silence_length_millis";
+ "latin_ime_speech_input_possibly_complete_silence_length_millis";
/**
* Min and max volume levels that can be displayed on the "speak now" screen.
@@ -76,100 +75,39 @@ public class GoogleSettingsUtil {
public static final String LATIN_IME_MAX_VOICE_RESULTS = "latin_ime_max_voice_results";
/**
- * Uri to use to access gservices settings
- */
- private static final Uri GSERVICES_URI = Uri.parse("content://settings/gservices");
-
- private static final String TAG = GoogleSettingsUtil.class.getSimpleName();
-
- private static final boolean DBG = false;
-
- /**
- * Safely query for a Gservices string setting, which may not be available if this
- * is not a Google Experience Device.
- *
+ * Get a string-valued setting.
+ *
* @param cr The content resolver to use
* @param key The setting to look up
* @param defaultValue The default value to use if none can be found
* @return The value of the setting, or defaultValue if it couldn't be found
*/
- public static String getGservicesString(ContentResolver cr, String key, String defaultValue) {
- return getSettingString(GSERVICES_URI, cr, key, defaultValue);
+ public static String getSettingsString(ContentResolver cr, String key, String defaultValue) {
+ String result = Settings.Secure.getString(cr, key);
+ return (result == null) ? defaultValue : result;
}
-
+
/**
- * Safely query for a Gservices int setting, which may not be available if this
- * is not a Google Experience Device.
- *
+ * Get an int-valued setting.
+ *
* @param cr The content resolver to use
* @param key The setting to look up
* @param defaultValue The default value to use if the setting couldn't be found or parsed
* @return The value of the setting, or defaultValue if it couldn't be found or parsed
*/
- public static int getGservicesInt(ContentResolver cr, String key, int defaultValue) {
- try {
- return Integer.parseInt(getGservicesString(cr, key, String.valueOf(defaultValue)));
- } catch (NumberFormatException e) {
- return defaultValue;
- }
+ public static int getSettingsInt(ContentResolver cr, String key, int defaultValue) {
+ return Settings.Secure.getInt(cr, key, defaultValue);
}
/**
- * Safely query for a Gservices float setting, which may not be available if this
- * is not a Google Experience Device.
- *
+ * Get a float-valued setting.
+ *
* @param cr The content resolver to use
* @param key The setting to look up
* @param defaultValue The default value to use if the setting couldn't be found or parsed
* @return The value of the setting, or defaultValue if it couldn't be found or parsed
*/
- public static float getGservicesFloat(ContentResolver cr, String key, float defaultValue) {
- try {
- return Float.parseFloat(getGservicesString(cr, key, String.valueOf(defaultValue)));
- } catch (NumberFormatException e) {
- return defaultValue;
- }
- }
-
- /**
- * A safe way to query for a setting on both Google Experience and
- * non-Google Experience devices, (code adapted from maps application
- * examples)
- *
- * @param uri The uri to provide to the content resolver
- * @param cr The content resolver to use
- * @param key The setting to look up
- * @param defaultValue The default value to use if none can be found
- * @return The value of the setting, or defaultValue if it couldn't be found
- */
- private static String getSettingString(Uri uri, ContentResolver cr, String key,
- String defaultValue) {
- String value = null;
-
- Cursor cursor = null;
- try {
- cursor = cr.query(uri, new String[] {
- "value"
- }, "name='" + key + "'", null, null);
- if ((cursor != null) && cursor.moveToFirst()) {
- value = cursor.getString(cursor.getColumnIndexOrThrow("value"));
- }
- } catch (Throwable t) {
- // This happens because we're probably running a non Type 1 aka
- // Google Experience device which doesn't have the Google libraries.
- if (DBG) {
- Log.d(TAG, "Error getting setting from " + uri + " for key " + key + ": " + t);
- }
- } finally {
- if (cursor != null) {
- cursor.close();
- }
- }
-
- if (DBG && value == null) {
- Log.i(TAG, "no setting found from " + uri + " for key " + key + ", returning default");
- }
-
- return (value != null) ? value : defaultValue;
+ public static float getSettingsFloat(ContentResolver cr, String key, float defaultValue) {
+ return Settings.Secure.getFloat(cr, key, defaultValue);
}
}
diff --git a/src/com/android/inputmethod/voice/VoiceInput.java b/src/com/android/inputmethod/voice/VoiceInput.java
index c39992aa3..a468b3352 100644
--- a/src/com/android/inputmethod/voice/VoiceInput.java
+++ b/src/com/android/inputmethod/voice/VoiceInput.java
@@ -1,12 +1,12 @@
/*
* 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
@@ -81,13 +81,13 @@ public class VoiceInput implements OnClickListener {
"android.speech.extras.SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS";
private static final String EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS =
"android.speech.extras.SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS";
-
+
// The usual endpointer default value for input complete silence length is 0.5 seconds,
// but that's used for things like voice search. For dictation-like voice input like this,
// we go with a more liberal value of 1 second. This value will only be used if a value
// is not provided from Gservices.
private static final String INPUT_COMPLETE_SILENCE_LENGTH_DEFAULT_VALUE_MILLIS = "1000";
-
+
// Used to record part of that state for logging purposes.
public static final int DEFAULT = 0;
public static final int LISTENING = 1;
@@ -145,11 +145,11 @@ public class VoiceInput implements OnClickListener {
mContext = context;
newView();
- String recommendedPackages = GoogleSettingsUtil.getGservicesString(
+ String recommendedPackages = SettingsUtil.getSettingsString(
context.getContentResolver(),
- GoogleSettingsUtil.LATIN_IME_VOICE_INPUT_RECOMMENDED_PACKAGES,
+ SettingsUtil.LATIN_IME_VOICE_INPUT_RECOMMENDED_PACKAGES,
DEFAULT_RECOMMENDED_PACKAGES);
-
+
mRecommendedList = new Whitelist();
for (String recommendedPackage : recommendedPackages.split("\\s+")) {
mRecommendedList.addApp(recommendedPackage);
@@ -167,10 +167,10 @@ public class VoiceInput implements OnClickListener {
public boolean isBlacklistedField(FieldContext context) {
return mBlacklist.matches(context);
}
-
+
/**
* Used to decide whether to show voice input hints for this field, etc.
- *
+ *
* @return true if field is recommended for voice
*/
public boolean isRecommendedField(FieldContext context) {
@@ -190,7 +190,7 @@ public class VoiceInput implements OnClickListener {
Locale locale = Locale.getDefault();
String localeString = locale.getLanguage() + "-" + locale.getCountry();
-
+
mLogger.start(localeString, swipe);
mState = LISTENING;
@@ -215,9 +215,9 @@ public class VoiceInput implements OnClickListener {
intent.putExtra(EXTRA_RECOGNITION_CONTEXT, context.getBundle());
intent.putExtra(EXTRA_CALLING_PACKAGE, "VoiceIME");
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,
- GoogleSettingsUtil.getGservicesInt(
+ SettingsUtil.getSettingsInt(
mContext.getContentResolver(),
- GoogleSettingsUtil.LATIN_IME_MAX_VOICE_RESULTS,
+ SettingsUtil.LATIN_IME_MAX_VOICE_RESULTS,
1));
// Get endpointer params from Gservices.
@@ -226,27 +226,27 @@ public class VoiceInput implements OnClickListener {
putEndpointerExtra(
cr,
intent,
- GoogleSettingsUtil.LATIN_IME_SPEECH_MINIMUM_LENGTH_MILLIS,
+ SettingsUtil.LATIN_IME_SPEECH_MINIMUM_LENGTH_MILLIS,
EXTRA_SPEECH_MINIMUM_LENGTH_MILLIS,
null /* rely on endpointer default */);
putEndpointerExtra(
cr,
intent,
- GoogleSettingsUtil.LATIN_IME_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS,
+ SettingsUtil.LATIN_IME_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS,
EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS,
INPUT_COMPLETE_SILENCE_LENGTH_DEFAULT_VALUE_MILLIS
/* our default value is different from the endpointer's */);
putEndpointerExtra(
cr,
intent,
- GoogleSettingsUtil.
+ SettingsUtil.
LATIN_IME_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS,
EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS,
null /* rely on endpointer default */);
mRecognitionManager.startListening(intent);
}
-
+
/**
* Gets the value of the provided Gservices key, attempts to parse it into a long,
* and if successful, puts the long value as an extra in the provided intent.
@@ -254,15 +254,15 @@ public class VoiceInput implements OnClickListener {
private void putEndpointerExtra(ContentResolver cr, Intent i,
String gservicesKey, String intentExtraKey, String defaultValue) {
long l = -1;
- String s = GoogleSettingsUtil.getGservicesString(cr, gservicesKey, defaultValue);
+ String s = SettingsUtil.getSettingsString(cr, gservicesKey, defaultValue);
if (s != null) {
try {
l = Long.valueOf(s);
} catch (NumberFormatException e) {
Log.e(TAG, "could not parse value for " + gservicesKey + ": " + s);
- }
+ }
}
-
+
if (l != -1) i.putExtra(intentExtraKey, l);
}
@@ -302,35 +302,35 @@ public class VoiceInput implements OnClickListener {
public void logTextModified() {
mLogger.textModified();
}
-
+
public void logKeyboardWarningDialogShown() {
mLogger.keyboardWarningDialogShown();
}
-
+
public void logKeyboardWarningDialogDismissed() {
mLogger.keyboardWarningDialogDismissed();
}
-
+
public void logKeyboardWarningDialogOk() {
mLogger.keyboardWarningDialogOk();
}
-
+
public void logKeyboardWarningDialogCancel() {
mLogger.keyboardWarningDialogCancel();
}
-
+
public void logSwipeHintDisplayed() {
mLogger.swipeHintDisplayed();
}
-
+
public void logPunctuationHintDisplayed() {
mLogger.punctuationHintDisplayed();
}
-
+
public void logVoiceInputDelivered() {
mLogger.voiceInputDelivered();
}
-
+
public void logNBestChoose(int index) {
mLogger.nBestChoose(index);
}
@@ -338,11 +338,11 @@ public class VoiceInput implements OnClickListener {
public void logInputEnded() {
mLogger.inputEnded();
}
-
+
public void flushLogs() {
mLogger.flush();
}
-
+
private static Intent makeIntent() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);