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.cardboard; | 5 package org.chromium.chromoting.cardboard; |
6 | 6 |
7 import android.content.Intent; | 7 import android.content.Intent; |
8 import android.graphics.PointF; | 8 import android.graphics.PointF; |
9 import android.os.Bundle; | 9 import android.os.Bundle; |
10 import android.speech.RecognitionListener; | 10 import android.speech.RecognitionListener; |
11 import android.speech.RecognizerIntent; | 11 import android.speech.RecognizerIntent; |
12 import android.speech.SpeechRecognizer; | 12 import android.speech.SpeechRecognizer; |
13 | 13 |
14 import com.google.vrtoolkit.cardboard.CardboardActivity; | 14 import com.google.vrtoolkit.cardboard.CardboardActivity; |
15 import com.google.vrtoolkit.cardboard.CardboardView; | 15 import com.google.vrtoolkit.cardboard.CardboardView; |
16 | 16 |
17 import org.chromium.chromoting.R; | 17 import org.chromium.chromoting.R; |
18 import org.chromium.chromoting.TouchInputHandler; | 18 import org.chromium.chromoting.TouchInputHandler; |
19 import org.chromium.chromoting.jni.Client; | 19 import org.chromium.chromoting.jni.JniInterface; |
20 | 20 |
21 import java.util.ArrayList; | 21 import java.util.ArrayList; |
22 | 22 |
23 /** | 23 /** |
24 * Virtual desktop activity for Cardboard. | 24 * Virtual desktop activity for Cardboard. |
25 */ | 25 */ |
26 public class DesktopActivity extends CardboardActivity { | 26 public class DesktopActivity extends CardboardActivity { |
27 // Flag to indicate whether the current activity is going to switch to norma
l | 27 // Flag to indicate whether the current activity is going to switch to norma
l |
28 // desktop activity. | 28 // desktop activity. |
29 private boolean mSwitchToDesktopActivity; | 29 private boolean mSwitchToDesktopActivity; |
30 | 30 |
31 private Client mClient; | |
32 private CardboardRenderer mRenderer; | 31 private CardboardRenderer mRenderer; |
33 private SpeechRecognizer mSpeechRecognizer; | 32 private SpeechRecognizer mSpeechRecognizer; |
34 | 33 |
35 // Flag to indicate whether the speech recognizer is listening or not. | 34 // Flag to indicate whether the speech recognizer is listening or not. |
36 private boolean mIsListening; | 35 private boolean mIsListening; |
37 | 36 |
38 @Override | 37 @Override |
39 public void onCreate(Bundle savedInstanceState) { | 38 public void onCreate(Bundle savedInstanceState) { |
40 super.onCreate(savedInstanceState); | 39 super.onCreate(savedInstanceState); |
41 setContentView(R.layout.cardboard_desktop); | 40 setContentView(R.layout.cardboard_desktop); |
42 | |
43 mClient = Client.getInstance(); | |
44 | |
45 mSwitchToDesktopActivity = false; | 41 mSwitchToDesktopActivity = false; |
46 CardboardView cardboardView = (CardboardView) findViewById(R.id.cardboar
d_view); | 42 CardboardView cardboardView = (CardboardView) findViewById(R.id.cardboar
d_view); |
47 mRenderer = new CardboardRenderer(this, mClient); | 43 mRenderer = new CardboardRenderer(this); |
48 mIsListening = false; | 44 mIsListening = false; |
49 | 45 |
50 // Associate a CardboardView.StereoRenderer with cardboard view. | 46 // Associate a CardboardView.StereoRenderer with cardboard view. |
51 cardboardView.setRenderer(mRenderer); | 47 cardboardView.setRenderer(mRenderer); |
52 | 48 |
53 // Associate the cardboard view with this activity. | 49 // Associate the cardboard view with this activity. |
54 setCardboardView(cardboardView); | 50 setCardboardView(cardboardView); |
55 } | 51 } |
56 | 52 |
57 @Override | 53 @Override |
(...skipping 14 matching lines...) Expand all Loading... |
72 case ZOOM_OUT: | 68 case ZOOM_OUT: |
73 mRenderer.moveAwayFromDesktop(); | 69 mRenderer.moveAwayFromDesktop(); |
74 break; | 70 break; |
75 } | 71 } |
76 } else { | 72 } else { |
77 mRenderer.setMenuBarVisible(false); | 73 mRenderer.setMenuBarVisible(false); |
78 } | 74 } |
79 } else { | 75 } else { |
80 if (mRenderer.isLookingAtDesktop()) { | 76 if (mRenderer.isLookingAtDesktop()) { |
81 PointF coordinates = mRenderer.getMouseCoordinates(); | 77 PointF coordinates = mRenderer.getMouseCoordinates(); |
82 mClient.sendMouseEvent((int) coordinates.x, (int) coordinates.y, | 78 JniInterface.sendMouseEvent((int) coordinates.x, (int) coordinat
es.y, |
83 TouchInputHandler.BUTTON_LEFT, true); | 79 TouchInputHandler.BUTTON_LEFT, true); |
84 mClient.sendMouseEvent((int) coordinates.x, (int) coordinates.y, | 80 JniInterface.sendMouseEvent((int) coordinates.x, (int) coordinat
es.y, |
85 TouchInputHandler.BUTTON_LEFT, false); | 81 TouchInputHandler.BUTTON_LEFT, false); |
86 } else { | 82 } else { |
87 if (mRenderer.isLookingFarawayFromDesktop()) { | 83 if (mRenderer.isLookingFarawayFromDesktop()) { |
88 getCardboardView().resetHeadTracker(); | 84 getCardboardView().resetHeadTracker(); |
89 } else { | 85 } else { |
90 mRenderer.setMenuBarVisible(true); | 86 mRenderer.setMenuBarVisible(true); |
91 } | 87 } |
92 } | 88 } |
93 } | 89 } |
94 } | 90 } |
95 | 91 |
96 @Override | 92 @Override |
97 protected void onStart() { | 93 protected void onStart() { |
98 super.onStart(); | 94 super.onStart(); |
99 mClient.enableVideoChannel(true); | 95 JniInterface.enableVideoChannel(true); |
100 } | 96 } |
101 | 97 |
102 @Override | 98 @Override |
103 protected void onPause() { | 99 protected void onPause() { |
104 super.onPause(); | 100 super.onPause(); |
105 if (!mSwitchToDesktopActivity) { | 101 if (!mSwitchToDesktopActivity) { |
106 mClient.enableVideoChannel(false); | 102 JniInterface.enableVideoChannel(false); |
107 } | 103 } |
108 if (mSpeechRecognizer != null) { | 104 if (mSpeechRecognizer != null) { |
109 mSpeechRecognizer.stopListening(); | 105 mSpeechRecognizer.stopListening(); |
110 } | 106 } |
111 } | 107 } |
112 | 108 |
113 @Override | 109 @Override |
114 protected void onResume() { | 110 protected void onResume() { |
115 super.onResume(); | 111 super.onResume(); |
116 mClient.enableVideoChannel(true); | 112 JniInterface.enableVideoChannel(true); |
117 } | 113 } |
118 | 114 |
119 @Override | 115 @Override |
120 protected void onStop() { | 116 protected void onStop() { |
121 super.onStop(); | 117 super.onStop(); |
122 if (mSwitchToDesktopActivity) { | 118 if (mSwitchToDesktopActivity) { |
123 mSwitchToDesktopActivity = false; | 119 mSwitchToDesktopActivity = false; |
124 } else { | 120 } else { |
125 mClient.enableVideoChannel(false); | 121 JniInterface.enableVideoChannel(false); |
126 } | 122 } |
127 if (mSpeechRecognizer != null) { | 123 if (mSpeechRecognizer != null) { |
128 mSpeechRecognizer.stopListening(); | 124 mSpeechRecognizer.stopListening(); |
129 } | 125 } |
130 } | 126 } |
131 | 127 |
132 @Override | 128 @Override |
133 protected void onDestroy() { | 129 protected void onDestroy() { |
134 super.onDestroy(); | 130 super.onDestroy(); |
135 if (mSpeechRecognizer != null) { | 131 if (mSpeechRecognizer != null) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 | 179 |
184 public void onError(int error) { | 180 public void onError(int error) { |
185 mIsListening = false; | 181 mIsListening = false; |
186 } | 182 } |
187 | 183 |
188 public void onResults(Bundle results) { | 184 public void onResults(Bundle results) { |
189 // TODO(shichengfeng): If necessary, provide a list of choices for u
ser to pick. | 185 // TODO(shichengfeng): If necessary, provide a list of choices for u
ser to pick. |
190 ArrayList<String> data = | 186 ArrayList<String> data = |
191 results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNIT
ION); | 187 results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNIT
ION); |
192 if (!data.isEmpty()) { | 188 if (!data.isEmpty()) { |
193 mClient.sendTextEvent(data.get(0)); | 189 JniInterface.sendTextEvent(data.get(0)); |
194 } | 190 } |
195 } | 191 } |
196 | 192 |
197 public void onPartialResults(Bundle partialResults) { | 193 public void onPartialResults(Bundle partialResults) { |
198 } | 194 } |
199 | 195 |
200 public void onEvent(int eventType, Bundle params) { | 196 public void onEvent(int eventType, Bundle params) { |
201 } | 197 } |
202 } | 198 } |
203 } | 199 } |
OLD | NEW |