Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chromoting; | 5 package org.chromium.chromoting; |
| 6 | 6 |
| 7 import android.content.Intent; | |
| 7 import android.graphics.PointF; | 8 import android.graphics.PointF; |
| 8 import android.os.Bundle; | 9 import android.os.Bundle; |
| 10 import android.speech.RecognitionListener; | |
| 11 import android.speech.RecognizerIntent; | |
| 12 import android.speech.SpeechRecognizer; | |
| 9 | 13 |
| 10 import com.google.vrtoolkit.cardboard.CardboardActivity; | 14 import com.google.vrtoolkit.cardboard.CardboardActivity; |
| 11 import com.google.vrtoolkit.cardboard.CardboardView; | 15 import com.google.vrtoolkit.cardboard.CardboardView; |
| 12 | 16 |
| 13 import org.chromium.chromoting.jni.JniInterface; | 17 import org.chromium.chromoting.jni.JniInterface; |
| 14 | 18 |
| 15 /** | 19 /** |
| 16 * Virtual desktop activity for Cardboard. | 20 * Virtual desktop activity for Cardboard. |
| 17 */ | 21 */ |
| 18 public class CardboardDesktopActivity extends CardboardActivity { | 22 public class CardboardDesktopActivity extends CardboardActivity { |
| 19 // Flag to indicate whether the current activity is going to switch to norma l | 23 // Flag to indicate whether the current activity is going to switch to norma l |
| 20 // desktop activity. | 24 // desktop activity. |
| 21 private boolean mSwitchToDesktopActivity; | 25 private boolean mSwitchToDesktopActivity; |
| 22 | 26 |
| 23 private CardboardDesktopRenderer mRenderer; | 27 private CardboardDesktopRenderer mRenderer; |
| 28 private SpeechRecognizer mSpeechRecognizer; | |
| 24 | 29 |
| 25 @Override | 30 @Override |
| 26 public void onCreate(Bundle savedInstanceState) { | 31 public void onCreate(Bundle savedInstanceState) { |
| 27 super.onCreate(savedInstanceState); | 32 super.onCreate(savedInstanceState); |
| 28 setContentView(R.layout.cardboard_desktop); | 33 setContentView(R.layout.cardboard_desktop); |
| 29 mSwitchToDesktopActivity = false; | 34 mSwitchToDesktopActivity = false; |
| 30 CardboardView cardboardView = (CardboardView) findViewById(R.id.cardboar d_view); | 35 CardboardView cardboardView = (CardboardView) findViewById(R.id.cardboar d_view); |
| 31 mRenderer = new CardboardDesktopRenderer(this); | 36 mRenderer = new CardboardDesktopRenderer(this); |
| 37 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.
| |
| 38 mSpeechRecognizer.setRecognitionListener(new VoiceInputRecognitionListen er()); | |
| 32 | 39 |
| 33 // Associate a CardboardView.StereoRenderer with cardboardView. | 40 // Associate a CardboardView.StereoRenderer with cardboardView. |
| 34 cardboardView.setRenderer(mRenderer); | 41 cardboardView.setRenderer(mRenderer); |
| 35 | 42 |
| 36 // Associate the cardboardView with this activity. | 43 // Associate the cardboardView with this activity. |
| 37 setCardboardView(cardboardView); | 44 setCardboardView(cardboardView); |
| 38 } | 45 } |
| 39 | 46 |
| 40 @Override | 47 @Override |
| 41 public void onCardboardTrigger() { | 48 public void onCardboardTrigger() { |
| 42 if (mRenderer.isLookingAtDesktop()) { | 49 if (mRenderer.isLookingAtDesktop()) { |
| 43 PointF coordinates = mRenderer.getMouseCoordinates(); | 50 PointF coordinates = mRenderer.getMouseCoordinates(); |
| 44 JniInterface.sendMouseEvent((int) coordinates.x, (int) coordinates.y , | 51 JniInterface.sendMouseEvent((int) coordinates.x, (int) coordinates.y , |
| 45 TouchInputHandler.BUTTON_LEFT, true); | 52 TouchInputHandler.BUTTON_LEFT, true); |
| 46 JniInterface.sendMouseEvent((int) coordinates.x, (int) coordinates.y , | 53 JniInterface.sendMouseEvent((int) coordinates.x, (int) coordinates.y , |
| 47 TouchInputHandler.BUTTON_LEFT, false); | 54 TouchInputHandler.BUTTON_LEFT, false); |
| 48 } else { | 55 } else if (mRenderer.isLookingLeftToDesktop()) { |
| 49 mSwitchToDesktopActivity = true; | 56 mSwitchToDesktopActivity = true; |
| 50 finish(); | 57 finish(); |
| 58 } 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.
| |
| 59 sendVoiceInput(); | |
| 51 } | 60 } |
| 52 } | 61 } |
| 53 | 62 |
| 54 @Override | 63 @Override |
| 55 protected void onStart() { | 64 protected void onStart() { |
| 56 super.onStart(); | 65 super.onStart(); |
| 57 JniInterface.enableVideoChannel(true); | 66 JniInterface.enableVideoChannel(true); |
| 58 mRenderer.attachRedrawCallback(); | 67 mRenderer.attachRedrawCallback(); |
| 59 } | 68 } |
| 60 | 69 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 74 | 83 |
| 75 @Override | 84 @Override |
| 76 protected void onStop() { | 85 protected void onStop() { |
| 77 super.onStop(); | 86 super.onStop(); |
| 78 if (mSwitchToDesktopActivity) { | 87 if (mSwitchToDesktopActivity) { |
| 79 mSwitchToDesktopActivity = false; | 88 mSwitchToDesktopActivity = false; |
| 80 } else { | 89 } else { |
| 81 JniInterface.enableVideoChannel(false); | 90 JniInterface.enableVideoChannel(false); |
| 82 } | 91 } |
| 83 } | 92 } |
| 93 | |
| 94 private void sendVoiceInput() { | |
| 95 Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); | |
| 96 intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, | |
| 97 RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); | |
| 98 | |
| 99 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
| |
| 100 } | |
| 101 | |
| 102 private class VoiceInputRecognitionListener implements RecognitionListener { | |
| 103 public void onReadyForSpeech(Bundle params) { | |
| 104 } | |
| 105 | |
| 106 public void onBeginningOfSpeech() { | |
| 107 } | |
| 108 | |
| 109 public void onRmsChanged(float rmsdB){ | |
| 110 } | |
| 111 | |
| 112 public void onBufferReceived(byte[] buffer) { | |
| 113 } | |
| 114 | |
| 115 public void onEndOfSpeech() { | |
| 116 } | |
| 117 | |
| 118 public void onError(int error) { | |
| 119 } | |
| 120 | |
| 121 public void onResults(Bundle results) { | |
| 122 // TODO(shichengfeng): If necessary, provide a list of choices for u ser to pick. | |
| 123 String text = results.getStringArrayList(SpeechRecognizer.RESULTS_RE COGNITION).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.
| |
| 124 JniInterface.sendTextEvent(text); | |
| 125 } | |
| 126 | |
| 127 public void onPartialResults(Bundle partialResults) { | |
| 128 } | |
| 129 | |
| 130 public void onEvent(int eventType, Bundle params) { | |
| 131 } | |
| 132 } | |
| 84 } | 133 } |
| OLD | NEW |