Chromium Code Reviews| Index: remoting/android/java/src/org/chromium/chromoting/CardboardDesktopActivity.java |
| diff --git a/remoting/android/java/src/org/chromium/chromoting/CardboardDesktopActivity.java b/remoting/android/java/src/org/chromium/chromoting/CardboardDesktopActivity.java |
| index 8289d0eba6b04e6b4fb0ac92ce0eb1f2adb5965e..31756e6f134f8d6a1dd289819e4bf4b5673ef525 100644 |
| --- a/remoting/android/java/src/org/chromium/chromoting/CardboardDesktopActivity.java |
| +++ b/remoting/android/java/src/org/chromium/chromoting/CardboardDesktopActivity.java |
| @@ -4,8 +4,12 @@ |
| package org.chromium.chromoting; |
| +import android.content.Intent; |
| import android.graphics.PointF; |
| import android.os.Bundle; |
| +import android.speech.RecognitionListener; |
| +import android.speech.RecognizerIntent; |
| +import android.speech.SpeechRecognizer; |
| import com.google.vrtoolkit.cardboard.CardboardActivity; |
| import com.google.vrtoolkit.cardboard.CardboardView; |
| @@ -21,6 +25,7 @@ public class CardboardDesktopActivity extends CardboardActivity { |
| private boolean mSwitchToDesktopActivity; |
| private CardboardDesktopRenderer mRenderer; |
| + private SpeechRecognizer mSpeechRecognizer; |
| @Override |
| public void onCreate(Bundle savedInstanceState) { |
| @@ -29,6 +34,8 @@ public class CardboardDesktopActivity extends CardboardActivity { |
| mSwitchToDesktopActivity = false; |
| CardboardView cardboardView = (CardboardView) findViewById(R.id.cardboard_view); |
| mRenderer = new CardboardDesktopRenderer(this); |
| + mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(this); |
|
Sergey Ulanov
2015/08/05 17:53:47
It might be good idea to create this lazily the fi
shichengfeng
2015/08/05 23:06:31
Done.
|
| + mSpeechRecognizer.setRecognitionListener(new VoiceInputRecognitionListener()); |
| // Associate a CardboardView.StereoRenderer with cardboardView. |
| cardboardView.setRenderer(mRenderer); |
| @@ -45,9 +52,11 @@ public class CardboardDesktopActivity extends CardboardActivity { |
| TouchInputHandler.BUTTON_LEFT, true); |
| JniInterface.sendMouseEvent((int) coordinates.x, (int) coordinates.y, |
| TouchInputHandler.BUTTON_LEFT, false); |
| - } else { |
| + } else if (mRenderer.isLookingLeftToDesktop()) { |
| mSwitchToDesktopActivity = true; |
| finish(); |
| + } else if (mRenderer.isLookingRightToDesktop()) { |
|
Lambros
2015/08/05 00:25:52
This is OK for now, but add a TODO for a more poli
shichengfeng
2015/08/05 23:06:31
Done.
|
| + sendVoiceInput(); |
| } |
| } |
| @@ -81,4 +90,44 @@ public class CardboardDesktopActivity extends CardboardActivity { |
| JniInterface.enableVideoChannel(false); |
| } |
| } |
| + |
| + private void sendVoiceInput() { |
| + Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); |
| + intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, |
| + RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); |
| + |
| + mSpeechRecognizer.startListening(intent); |
|
Sergey Ulanov
2015/08/05 17:53:47
Do we need to verify that the recognizer is not al
Sergey Ulanov
2015/08/05 17:53:47
I think one problem when I tried using the feature
shichengfeng
2015/08/05 23:06:31
Sure, I will put all UI polish in another CL. Put
shichengfeng
2015/08/05 23:06:31
Yes, we have to. I added a flag to prevent calling
|
| + } |
| + |
| + private class VoiceInputRecognitionListener implements RecognitionListener { |
| + public void onReadyForSpeech(Bundle params) { |
| + } |
| + |
| + public void onBeginningOfSpeech() { |
| + } |
| + |
| + public void onRmsChanged(float rmsdB){ |
| + } |
| + |
| + public void onBufferReceived(byte[] buffer) { |
| + } |
| + |
| + public void onEndOfSpeech() { |
| + } |
| + |
| + public void onError(int error) { |
| + } |
| + |
| + public void onResults(Bundle results) { |
| + // TODO(shichengfeng): If necessary, provide a list of choices for user to pick. |
| + String text = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION).get(0); |
|
Lambros
2015/08/05 00:25:52
I don't know if the result array is guaranteed to
shichengfeng
2015/08/05 23:06:31
Done.
|
| + JniInterface.sendTextEvent(text); |
| + } |
| + |
| + public void onPartialResults(Bundle partialResults) { |
| + } |
| + |
| + public void onEvent(int eventType, Bundle params) { |
| + } |
| + } |
| } |