aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/voice
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/voice')
-rw-r--r--java/src/com/android/inputmethod/voice/RecognitionView.java27
-rw-r--r--java/src/com/android/inputmethod/voice/VoiceIMEConnector.java13
-rw-r--r--java/src/com/android/inputmethod/voice/VoiceInput.java49
3 files changed, 65 insertions, 24 deletions
diff --git a/java/src/com/android/inputmethod/voice/RecognitionView.java b/java/src/com/android/inputmethod/voice/RecognitionView.java
index 98db9365f..95a79f463 100644
--- a/java/src/com/android/inputmethod/voice/RecognitionView.java
+++ b/java/src/com/android/inputmethod/voice/RecognitionView.java
@@ -16,6 +16,9 @@
package com.android.inputmethod.voice;
+import com.android.inputmethod.latin.R;
+import com.android.inputmethod.latin.SubtypeSwitcher;
+
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
@@ -35,13 +38,11 @@ import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
-import com.android.inputmethod.latin.R;
-
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ShortBuffer;
-import java.util.List;
+import java.util.Locale;
/**
* The user interface for the "Speak now" and "working" states.
@@ -60,6 +61,7 @@ public class RecognitionView {
private ImageView mImage;
private View mProgress;
private SoundIndicator mSoundIndicator;
+ private TextView mLanguage;
private Button mButton;
private Drawable mInitializing;
@@ -105,6 +107,7 @@ public class RecognitionView {
mButton = (Button) mView.findViewById(R.id.button);
mButton.setOnClickListener(clickListener);
mText = (TextView) mView.findViewById(R.id.text);
+ mLanguage = (TextView) mView.findViewById(R.id.language);
mContext = context;
}
@@ -184,9 +187,14 @@ public class RecognitionView {
private void prepareDialog(CharSequence text, Drawable image,
CharSequence btnTxt) {
+
+ /*
+ * The mic of INIT and of LISTENING has to be displayed in the same position. To accomplish
+ * that, some text visibility are not set as GONE but as INVISIBLE.
+ */
switch (mState) {
case INIT:
- mText.setVisibility(View.GONE);
+ mText.setVisibility(View.INVISIBLE);
mProgress.setVisibility(View.GONE);
@@ -196,6 +204,8 @@ public class RecognitionView {
mSoundIndicator.setVisibility(View.GONE);
mSoundIndicator.stop();
+ mLanguage.setVisibility(View.INVISIBLE);
+
mPopupLayout.setBackgroundDrawable(mListeningBorder);
break;
case LISTENING:
@@ -209,6 +219,11 @@ public class RecognitionView {
mSoundIndicator.setVisibility(View.VISIBLE);
mSoundIndicator.start();
+ Locale locale = SubtypeSwitcher.getInstance().getInputLocale();
+
+ mLanguage.setVisibility(View.VISIBLE);
+ mLanguage.setText(SubtypeSwitcher.getFullDisplayName(locale, true));
+
mPopupLayout.setBackgroundDrawable(mListeningBorder);
break;
case WORKING:
@@ -223,6 +238,8 @@ public class RecognitionView {
mSoundIndicator.setVisibility(View.GONE);
mSoundIndicator.stop();
+ mLanguage.setVisibility(View.GONE);
+
mPopupLayout.setBackgroundDrawable(mWorkingBorder);
break;
case READY:
@@ -237,6 +254,8 @@ public class RecognitionView {
mSoundIndicator.setVisibility(View.GONE);
mSoundIndicator.stop();
+ mLanguage.setVisibility(View.GONE);
+
mPopupLayout.setBackgroundDrawable(mErrorBorder);
break;
default:
diff --git a/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java b/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java
index 6c9b7d527..a3a3ea88e 100644
--- a/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java
+++ b/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java
@@ -78,6 +78,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
// given text field. For instance this is specified by the search dialog when the
// dialog is already showing a voice search button.
private static final String IME_OPTION_NO_MICROPHONE = "nm";
+ private static final int RECOGNITIONVIEW_HEIGHT_THRESHOLD_RATIO = 6;
@SuppressWarnings("unused")
private static final String TAG = "VoiceIMEConnector";
@@ -543,10 +544,14 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
// As we add mm, we don't know how the rounding is going to work
// thus we may end up with few pixels extra (or less).
if (keyboardView != null) {
- int h = keyboardView.getHeight();
- if (h > 0) {
- View popupLayout = v.findViewById(R.id.popup_layout);
- popupLayout.getLayoutParams().height = h;
+ View popupLayout = v.findViewById(R.id.popup_layout);
+ final int displayHeight =
+ mService.getResources().getDisplayMetrics().heightPixels;
+ final int currentHeight = popupLayout.getLayoutParams().height;
+ final int keyboardHeight = keyboardView.getHeight();
+ if (keyboardHeight > currentHeight || keyboardHeight
+ > (displayHeight / RECOGNITIONVIEW_HEIGHT_THRESHOLD_RATIO)) {
+ popupLayout.getLayoutParams().height = keyboardHeight;
}
}
mService.setInputView(v);
diff --git a/java/src/com/android/inputmethod/voice/VoiceInput.java b/java/src/com/android/inputmethod/voice/VoiceInput.java
index ffa349fde..2df9e8588 100644
--- a/java/src/com/android/inputmethod/voice/VoiceInput.java
+++ b/java/src/com/android/inputmethod/voice/VoiceInput.java
@@ -17,6 +17,7 @@
package com.android.inputmethod.voice;
import com.android.inputmethod.latin.EditingUtils;
+import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R;
import android.content.ContentResolver;
@@ -58,6 +59,7 @@ public class VoiceInput implements OnClickListener {
private static final String EXTRA_CALLING_PACKAGE = "calling_package";
private static final String EXTRA_ALTERNATES = "android.speech.extra.ALTERNATES";
private static final int MAX_ALT_LIST_LENGTH = 6;
+ private static boolean DBG = LatinImeLogger.sDBG;
private static final String DEFAULT_RECOMMENDED_PACKAGES =
"com.android.mms " +
@@ -128,19 +130,14 @@ public class VoiceInput implements OnClickListener {
private int mState = DEFAULT;
- private final static int MSG_CLOSE_ERROR_DIALOG = 1;
-
- private final static int MSG_RESET = 2;
+ private final static int MSG_RESET = 1;
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
- if (msg.what == MSG_RESET || msg.what == MSG_CLOSE_ERROR_DIALOG) {
+ if (msg.what == MSG_RESET) {
mState = DEFAULT;
mRecognitionView.finish();
- }
-
- if (msg.what == MSG_CLOSE_ERROR_DIALOG) {
mUiListener.onCancelVoice();
}
}
@@ -313,8 +310,18 @@ public class VoiceInput implements OnClickListener {
* @param swipe whether this voice input was started by swipe, for logging purposes
*/
public void startListening(FieldContext context, boolean swipe) {
- mState = DEFAULT;
-
+ if (DBG) {
+ Log.d(TAG, "startListening: " + context);
+ }
+
+ if (mState != DEFAULT) {
+ Log.w(TAG, "startListening in the wrong status " + mState);
+ }
+
+ // If everything works ok, the voice input should be already in the correct state. As this
+ // class can be called by third-party, we call reset just to be on the safe side.
+ reset();
+
Locale locale = Locale.getDefault();
String localeString = locale.getLanguage() + "-" + locale.getCountry();
@@ -499,6 +506,21 @@ public class VoiceInput implements OnClickListener {
}
/**
+ * Reset the current voice recognition.
+ */
+ public void reset() {
+ if (mState != DEFAULT) {
+ mState = DEFAULT;
+
+ // Remove all pending tasks (e.g., timers to cancel voice input)
+ mHandler.removeMessages(MSG_RESET);
+
+ mSpeechRecognizer.cancel();
+ mRecognitionView.finish();
+ }
+ }
+
+ /**
* Cancel in-progress speech recognition.
*/
public void cancel() {
@@ -513,14 +535,9 @@ public class VoiceInput implements OnClickListener {
mLogger.cancelDuringError();
break;
}
- mState = DEFAULT;
-
- // Remove all pending tasks (e.g., timers to cancel voice input)
- mHandler.removeMessages(MSG_RESET);
- mSpeechRecognizer.cancel();
+ reset();
mUiListener.onCancelVoice();
- mRecognitionView.finish();
}
private int getErrorStringId(int errorType, boolean endpointed) {
@@ -555,7 +572,7 @@ public class VoiceInput implements OnClickListener {
mState = ERROR;
mRecognitionView.showError(error);
// Wait a couple seconds and then automatically dismiss message.
- mHandler.sendMessageDelayed(Message.obtain(mHandler, MSG_CLOSE_ERROR_DIALOG), 2000);
+ mHandler.sendMessageDelayed(Message.obtain(mHandler, MSG_RESET), 2000);
}
private class ImeRecognitionListener implements RecognitionListener {