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