Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: remoting/android/java/src/org/chromium/chromoting/cardboard/DesktopActivity.java

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

Powered by Google App Engine
This is Rietveld 408576698