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

Side by Side Diff: webrtc/examples/androidapp/src/org/appspot/apprtc/AppRTCProximitySensor.java

Issue 2377003002: Format all Java in WebRTC. (Closed)
Patch Set: Rebase. Created 4 years, 2 months 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 /* 1 /*
2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2014 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 27 matching lines...) Expand all
38 // (e.g. the main thread). We use |nonThreadSafe| to ensure that this is 38 // (e.g. the main thread). We use |nonThreadSafe| to ensure that this is
39 // the case. Only active when |DEBUG| is set to true. 39 // the case. Only active when |DEBUG| is set to true.
40 private final ThreadUtils.ThreadChecker threadChecker = new ThreadUtils.Thread Checker(); 40 private final ThreadUtils.ThreadChecker threadChecker = new ThreadUtils.Thread Checker();
41 41
42 private final Runnable onSensorStateListener; 42 private final Runnable onSensorStateListener;
43 private final SensorManager sensorManager; 43 private final SensorManager sensorManager;
44 private Sensor proximitySensor = null; 44 private Sensor proximitySensor = null;
45 private boolean lastStateReportIsNear = false; 45 private boolean lastStateReportIsNear = false;
46 46
47 /** Construction */ 47 /** Construction */
48 static AppRTCProximitySensor create(Context context, 48 static AppRTCProximitySensor create(Context context, Runnable sensorStateListe ner) {
49 Runnable sensorStateListener) {
50 return new AppRTCProximitySensor(context, sensorStateListener); 49 return new AppRTCProximitySensor(context, sensorStateListener);
51 } 50 }
52 51
53 private AppRTCProximitySensor(Context context, Runnable sensorStateListener) { 52 private AppRTCProximitySensor(Context context, Runnable sensorStateListener) {
54 Log.d(TAG, "AppRTCProximitySensor" + AppRTCUtils.getThreadInfo()); 53 Log.d(TAG, "AppRTCProximitySensor" + AppRTCUtils.getThreadInfo());
55 onSensorStateListener = sensorStateListener; 54 onSensorStateListener = sensorStateListener;
56 sensorManager = ((SensorManager) context.getSystemService( 55 sensorManager = ((SensorManager) context.getSystemService(Context.SENSOR_SER VICE));
57 Context.SENSOR_SERVICE));
58 } 56 }
59 57
60 /** 58 /**
61 * Activate the proximity sensor. Also do initialization if called for the 59 * Activate the proximity sensor. Also do initialization if called for the
62 * first time. 60 * first time.
63 */ 61 */
64 public boolean start() { 62 public boolean start() {
65 threadChecker.checkIsOnValidThread(); 63 threadChecker.checkIsOnValidThread();
66 Log.d(TAG, "start" + AppRTCUtils.getThreadInfo()); 64 Log.d(TAG, "start" + AppRTCUtils.getThreadInfo());
67 if (!initDefaultSensor()) { 65 if (!initDefaultSensor()) {
68 // Proximity sensor is not supported on this device. 66 // Proximity sensor is not supported on this device.
69 return false; 67 return false;
70 } 68 }
71 sensorManager.registerListener( 69 sensorManager.registerListener(this, proximitySensor, SensorManager.SENSOR_D ELAY_NORMAL);
72 this, proximitySensor, SensorManager.SENSOR_DELAY_NORMAL);
73 return true; 70 return true;
74 } 71 }
75 72
76 /** Deactivate the proximity sensor. */ 73 /** Deactivate the proximity sensor. */
77 public void stop() { 74 public void stop() {
78 threadChecker.checkIsOnValidThread(); 75 threadChecker.checkIsOnValidThread();
79 Log.d(TAG, "stop" + AppRTCUtils.getThreadInfo()); 76 Log.d(TAG, "stop" + AppRTCUtils.getThreadInfo());
80 if (proximitySensor == null) { 77 if (proximitySensor == null) {
81 return; 78 return;
82 } 79 }
(...skipping 30 matching lines...) Expand all
113 lastStateReportIsNear = false; 110 lastStateReportIsNear = false;
114 } 111 }
115 112
116 // Report about new state to listening client. Client can then call 113 // Report about new state to listening client. Client can then call
117 // sensorReportsNearState() to query the current state (NEAR or FAR). 114 // sensorReportsNearState() to query the current state (NEAR or FAR).
118 if (onSensorStateListener != null) { 115 if (onSensorStateListener != null) {
119 onSensorStateListener.run(); 116 onSensorStateListener.run();
120 } 117 }
121 118
122 Log.d(TAG, "onSensorChanged" + AppRTCUtils.getThreadInfo() + ": " 119 Log.d(TAG, "onSensorChanged" + AppRTCUtils.getThreadInfo() + ": "
123 + "accuracy=" + event.accuracy 120 + "accuracy=" + event.accuracy + ", timestamp=" + event.timestamp + ", distance="
124 + ", timestamp=" + event.timestamp + ", distance=" + event.values[0]); 121 + event.values[0]);
125 } 122 }
126 123
127 /** 124 /**
128 * Get default proximity sensor if it exists. Tablet devices (e.g. Nexus 7) 125 * Get default proximity sensor if it exists. Tablet devices (e.g. Nexus 7)
129 * does not support this type of sensor and false will be returned in such 126 * does not support this type of sensor and false will be returned in such
130 * cases. 127 * cases.
131 */ 128 */
132 private boolean initDefaultSensor() { 129 private boolean initDefaultSensor() {
133 if (proximitySensor != null) { 130 if (proximitySensor != null) {
134 return true; 131 return true;
(...skipping 26 matching lines...) Expand all
161 info.append(", type: ").append(proximitySensor.getStringType()); 158 info.append(", type: ").append(proximitySensor.getStringType());
162 } 159 }
163 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 160 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
164 // Added in API level 21. 161 // Added in API level 21.
165 info.append(", max delay: ").append(proximitySensor.getMaxDelay()); 162 info.append(", max delay: ").append(proximitySensor.getMaxDelay());
166 info.append(", reporting mode: ").append(proximitySensor.getReportingMode( )); 163 info.append(", reporting mode: ").append(proximitySensor.getReportingMode( ));
167 info.append(", isWakeUpSensor: ").append(proximitySensor.isWakeUpSensor()) ; 164 info.append(", isWakeUpSensor: ").append(proximitySensor.isWakeUpSensor()) ;
168 } 165 }
169 Log.d(TAG, info.toString()); 166 Log.d(TAG, info.toString());
170 } 167 }
171
172 } 168 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698