OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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.content.browser; | 5 package org.chromium.content.browser; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.hardware.Sensor; | 8 import android.hardware.Sensor; |
9 import android.hardware.SensorEvent; | 9 import android.hardware.SensorEvent; |
10 import android.hardware.SensorEventListener; | 10 import android.hardware.SensorEventListener; |
11 import android.hardware.SensorManager; | 11 import android.hardware.SensorManager; |
12 import android.os.Handler; | 12 import android.os.Handler; |
13 import android.os.Looper; | 13 import android.os.Looper; |
14 | 14 |
15 import com.google.common.collect.ImmutableMap; | |
16 import com.google.common.collect.ImmutableSet; | |
17 import com.google.common.collect.Sets; | |
18 | |
15 import org.chromium.base.CalledByNative; | 19 import org.chromium.base.CalledByNative; |
16 import org.chromium.base.JNINamespace; | 20 import org.chromium.base.JNINamespace; |
17 import org.chromium.base.WeakContext; | 21 import org.chromium.base.WeakContext; |
18 | 22 |
19 import java.util.List; | 23 import java.util.List; |
24 import java.util.Map; | |
25 import java.util.Set; | |
20 | 26 |
21 /** | 27 /** |
22 * Android implementation of the DeviceOrientation API. | 28 * Android implementation of the device motion and orientation API. |
Peter Beverloo
2013/03/12 17:11:22
nit: s/API/APIs/.
timvolodine
2013/03/13 12:32:24
Done.
| |
23 */ | 29 */ |
24 @JNINamespace("content") | 30 @JNINamespace("content") |
25 class DeviceOrientation implements SensorEventListener { | 31 class DeviceMotionAndOrientation implements SensorEventListener { |
26 | 32 |
27 // These fields are lazily initialized by getHandler(). | 33 // These fields are lazily initialized by getHandler(). |
28 private Thread mThread; | 34 private Thread mThread; |
29 private Handler mHandler; | 35 private Handler mHandler; |
30 | 36 |
31 // The lock to access the mHandler. | 37 // The lock to access the mHandler. |
32 private Object mHandlerLock = new Object(); | 38 private Object mHandlerLock = new Object(); |
33 | 39 |
34 // Non-zero if and only if we're listening for events. | 40 // Non-zero if and only if we're listening for events. |
35 // To avoid race conditions on the C++ side, access must be synchronized. | 41 // To avoid race conditions on the C++ side, access must be synchronized. |
36 private int mNativePtr; | 42 private int mNativePtr; |
37 | 43 |
38 // The lock to access the mNativePtr. | 44 // The lock to access the mNativePtr. |
39 private Object mNativePtrLock = new Object(); | 45 private Object mNativePtrLock = new Object(); |
40 | 46 |
41 // The gravity vector expressed in the body frame. | 47 // The gravity vector expressed in the body frame. |
42 private float[] mGravityVector; | 48 private float[] mGravityVector; |
43 | 49 |
44 // The geomagnetic vector expressed in the body frame. | 50 // The geomagnetic vector expressed in the body frame. |
45 private float[] mMagneticFieldVector; | 51 private float[] mMagneticFieldVector; |
46 | 52 |
53 // The linear acceleration vector expressed in the body frame. | |
54 private float[] mAccelerationVector; | |
55 | |
56 // Gyroscope | |
Peter Beverloo
2013/03/12 17:11:22
"The angular speed at which the device is rotating
timvolodine
2013/03/13 12:32:24
Done.
| |
57 private float[] mGyroVector; | |
Peter Beverloo
2013/03/12 17:11:22
Let's spell out the full name: mGyroscopeVector.
timvolodine
2013/03/13 12:32:24
Done.
| |
58 | |
47 // Lazily initialized when registering for notifications. | 59 // Lazily initialized when registering for notifications. |
48 private SensorManager mSensorManager; | 60 private SensorManager mSensorManager; |
49 | 61 |
50 // The only instance of that class and its associated lock. | 62 // The only instance of that class and its associated lock. |
51 private static DeviceOrientation sSingleton; | 63 private static DeviceMotionAndOrientation sSingleton; |
52 private static Object sSingletonLock = new Object(); | 64 private static Object sSingletonLock = new Object(); |
53 | 65 |
54 private DeviceOrientation() { | 66 /** |
67 * constants for using in JNI calls, also see | |
68 * content/browser/device_orientation/data_fetcher_impl_android.cc | |
69 * @see #start | |
70 * @see #stop | |
71 */ | |
72 private static enum EventType { | |
Miguel Garcia
2013/03/12 17:00:26
what happened to my comment about not using an enu
Peter Beverloo
2013/03/12 17:11:22
Please use int constants instead of enums (enums i
timvolodine
2013/03/13 12:32:24
sorry seem to have missed that while uploading new
timvolodine
2013/03/13 12:32:24
Done.
| |
73 DEVICE_ORIENTATION(0), | |
74 DEVICE_MOTION(1); | |
Miguel Garcia
2013/03/12 17:00:26
test?
timvolodine
2013/03/13 12:32:24
hmm not sure, is this N/A anymore (?)
| |
75 | |
76 public int value; | |
77 private EventType(int value) { | |
78 this.value = value; | |
79 } | |
80 } | |
81 | |
82 private static ImmutableSet<Integer> DEVICE_ORIENTATION_SENSORS = | |
83 ImmutableSet.of(Sensor.TYPE_ACCELEROMETER, | |
84 Sensor.TYPE_MAGNETIC_FIELD); | |
85 | |
86 private static ImmutableSet<Integer> DEVICE_MOTION_SENSORS = | |
87 ImmutableSet.of(Sensor.TYPE_ACCELEROMETER, | |
88 Sensor.TYPE_LINEAR_ACCELERATION, | |
89 Sensor.TYPE_GYROSCOPE); | |
90 | |
91 private Set<Integer> mActiveSensors = Sets.newHashSet(); | |
92 | |
93 private static Map<Integer, ImmutableSet<Integer>> SENSORS_FOR_EVENT = Immut ableMap.of( | |
94 EventType.DEVICE_ORIENTATION.value, DEVICE_ORIENTATION_SENSORS, | |
95 EventType.DEVICE_MOTION.value, DEVICE_MOTION_SENSORS); | |
Peter Beverloo
2013/03/12 17:11:22
For line 82 to 95: I think this is much too verbos
timvolodine
2013/03/13 12:32:24
Done.
| |
96 | |
97 // keep an array of active event types for speed because it is used in @see # | |
Miguel Garcia
2013/03/12 17:00:26
@see # ?
where is it used?
Peter Beverloo
2013/03/12 17:11:22
nit: Grammar. You seem to be missing a reference h
timvolodine
2013/03/13 12:32:24
Done.
timvolodine
2013/03/13 12:32:24
Done.
| |
98 private boolean[] mIsSpecEventActive = new boolean[EventType.values().length ]; | |
Peter Beverloo
2013/03/12 17:11:22
As I mentioned in the native code review, please d
timvolodine
2013/03/13 12:32:24
Done.
| |
99 | |
100 private DeviceMotionAndOrientation() { | |
101 mIsSpecEventActive[EventType.DEVICE_ORIENTATION.value] = false; | |
102 mIsSpecEventActive[EventType.DEVICE_MOTION.value] = false; | |
55 } | 103 } |
Miguel Garcia
2013/03/12 17:00:26
can you do this in a for loop so we don't forget t
Peter Beverloo
2013/03/12 17:11:22
I think we should just have two separate members.
timvolodine
2013/03/13 12:32:24
Done.
timvolodine
2013/03/13 12:32:24
Done.
| |
56 | 104 |
57 /** | 105 /** |
58 * Start listening for sensor events. If this object is already listening | 106 * Start listening for sensor events. If this object is already listening |
59 * for events, the old callback is unregistered first. | 107 * for events, the old callback is unregistered first. |
60 * | 108 * |
61 * @param nativePtr Value to pass to nativeGotOrientation() for each event. | 109 * @param nativePtr Value to pass to nativeGotOrientation() for each event. |
62 * @param rateInMilliseconds Requested callback rate in milliseconds. The | 110 * @param rateInMilliseconds Requested callback rate in milliseconds. The |
63 * actual rate may be higher. Unwanted events should be ignored. | 111 * actual rate may be higher. Unwanted events should be ignored. |
112 * @param specEventType type of event to listen to, can either 0 for device | |
Peter Beverloo
2013/03/12 17:11:22
nit: grammar (capital). s/can either/can be either
timvolodine
2013/03/13 12:32:24
Done.
| |
113 * orientation, or 1 for device motion. | |
64 * @return True on success. | 114 * @return True on success. |
65 */ | 115 */ |
66 @CalledByNative | 116 @CalledByNative |
67 public boolean start(int nativePtr, int rateInMilliseconds) { | 117 public boolean start(int nativePtr, int eventType, int rateInMilliseconds) { |
118 Set<Integer> sensorsForEvent = SENSORS_FOR_EVENT.get(eventType); | |
119 if (sensorsForEvent == null) | |
120 return false; | |
121 | |
68 synchronized (mNativePtrLock) { | 122 synchronized (mNativePtrLock) { |
69 stop(); | 123 Set<Integer> sensorsToActivate = Sets.newHashSet(sensorsForEvent); |
70 if (registerForSensors(rateInMilliseconds)) { | 124 sensorsToActivate.removeAll(mActiveSensors); |
125 boolean success = registerForSensors(sensorsToActivate, rateInMillis econds); | |
126 if (success) { | |
71 mNativePtr = nativePtr; | 127 mNativePtr = nativePtr; |
72 return true; | 128 mIsSpecEventActive[eventType] = true; |
73 } | 129 } |
74 return false; | 130 return success; |
75 } | 131 } |
76 } | 132 } |
77 | 133 |
78 /** | 134 /** |
79 * Stop listening for sensor events. Always succeeds. | 135 * Stop listening for particular sensor events. Always succeeds. |
80 * | 136 * |
137 * @param specEventType type of event to listen to, can either 0 for device | |
Peter Beverloo
2013/03/12 17:11:22
nit: dito to line 112.
timvolodine
2013/03/13 12:32:24
Done.
| |
138 * orientation, or 1 for device motion. | |
81 * We strictly guarantee that nativeGotOrientation() will not be called | 139 * We strictly guarantee that nativeGotOrientation() will not be called |
82 * after this method returns. | 140 * after this method returns. |
83 */ | 141 */ |
84 @CalledByNative | 142 @CalledByNative |
85 public void stop() { | 143 public void stop(int eventType) { |
144 if (SENSORS_FOR_EVENT.get(eventType) == null) | |
145 return; | |
146 Set<Integer> sensorsToRemainActive = Sets.newHashSet(); | |
147 | |
86 synchronized (mNativePtrLock) { | 148 synchronized (mNativePtrLock) { |
87 if (mNativePtr != 0) { | 149 for (EventType event : EventType.values()) { |
88 mNativePtr = 0; | 150 if (event.value != eventType && mIsSpecEventActive[event.value]) { |
89 unregisterForSensors(); | 151 sensorsToRemainActive.addAll(SENSORS_FOR_EVENT.get(event.val ue)); |
152 } | |
90 } | 153 } |
154 Set<Integer> sensorsToDeactivate = Sets.newHashSet(mActiveSensors); | |
155 sensorsToDeactivate.removeAll(sensorsToRemainActive); | |
156 unregisterForSensors(sensorsToDeactivate); | |
157 mNativePtr = 0; | |
158 mIsSpecEventActive[eventType] = false; | |
91 } | 159 } |
92 } | 160 } |
93 | 161 |
94 @Override | 162 @Override |
95 public void onAccuracyChanged(Sensor sensor, int accuracy) { | 163 public void onAccuracyChanged(Sensor sensor, int accuracy) { |
96 // Nothing | 164 // Nothing |
97 } | 165 } |
98 | 166 |
99 @Override | 167 @Override |
100 public void onSensorChanged(SensorEvent event) { | 168 public void onSensorChanged(SensorEvent event) { |
169 boolean dispatchDeviceOrientation = | |
Miguel Garcia
2013/03/12 17:00:26
I would change this a bit so that the switch just
timvolodine
2013/03/13 12:32:24
Done.
| |
170 mIsSpecEventActive[EventType.DEVICE_ORIENTATION.value]; | |
171 boolean dispatchDeviceMotion = | |
172 mIsSpecEventActive[EventType.DEVICE_MOTION.value]; | |
Peter Beverloo
2013/03/12 17:11:22
When we have two separate booleans for the events,
timvolodine
2013/03/13 12:32:24
Done.
| |
173 | |
101 switch (event.sensor.getType()) { | 174 switch (event.sensor.getType()) { |
102 case Sensor.TYPE_ACCELEROMETER: | 175 case Sensor.TYPE_ACCELEROMETER: |
103 if (mGravityVector == null) { | 176 if (mGravityVector == null) { |
104 mGravityVector = new float[3]; | 177 mGravityVector = new float[3]; |
105 } | 178 } |
106 System.arraycopy(event.values, 0, mGravityVector, 0, mGravityVec tor.length); | 179 System.arraycopy(event.values, 0, mGravityVector, 0, mGravityVec tor.length); |
180 if (dispatchDeviceMotion) | |
Peter Beverloo
2013/03/12 17:11:22
nit: Please include brackets for readability. The
timvolodine
2013/03/13 12:32:24
Done.
| |
181 gotAccelerationIncludingGravity(mGravityVector[0], mGravityV ector[1], | |
182 mGravityVector[2]); | |
183 break; | |
184 case Sensor.TYPE_LINEAR_ACCELERATION: | |
185 if (mAccelerationVector == null) { | |
Peter Beverloo
2013/03/12 17:11:22
We're not using mAccelerationVector anywhere outsi
timvolodine
2013/03/13 12:32:24
Done.
| |
186 mAccelerationVector = new float[3]; | |
187 } | |
188 System.arraycopy(event.values, 0, mAccelerationVector, 0, | |
189 mAccelerationVector.length); | |
190 if (dispatchDeviceMotion) | |
Peter Beverloo
2013/03/12 17:11:22
Why do we have this if statement here? We'll only
timvolodine
2013/03/13 12:32:24
Done.
| |
191 gotAcceleration(mAccelerationVector[0], mAccelerationVector[ 1], | |
192 mAccelerationVector[2]); | |
193 break; | |
Miguel Garcia
2013/03/12 17:00:26
extra blank line
timvolodine
2013/03/13 12:32:24
Done.
| |
194 | |
195 case Sensor.TYPE_GYROSCOPE: | |
Peter Beverloo
2013/03/12 17:11:22
This whole block: dito to the comments on line 185
timvolodine
2013/03/13 12:32:24
Done.
| |
196 if (mGyroVector == null) { | |
197 mGyroVector = new float[3]; | |
198 } | |
199 System.arraycopy(event.values, 0, mGyroVector, 0, mGyroVector.le ngth); | |
200 if (dispatchDeviceMotion) | |
201 gotRotationRate(mGyroVector[0], mGyroVector[1], mGyroVector[ 2]); | |
107 break; | 202 break; |
108 | 203 |
109 case Sensor.TYPE_MAGNETIC_FIELD: | 204 case Sensor.TYPE_MAGNETIC_FIELD: |
110 if (mMagneticFieldVector == null) { | 205 if (mMagneticFieldVector == null) { |
111 mMagneticFieldVector = new float[3]; | 206 mMagneticFieldVector = new float[3]; |
112 } | 207 } |
113 System.arraycopy(event.values, 0, mMagneticFieldVector, 0, | 208 System.arraycopy(event.values, 0, mMagneticFieldVector, 0, |
114 mMagneticFieldVector.length); | 209 mMagneticFieldVector.length); |
115 break; | 210 break; |
116 | 211 |
117 default: | 212 default: |
118 // Unexpected | 213 // Unexpected |
Miguel Garcia
2013/03/12 17:00:26
can you log/assert something here?
timvolodine
2013/03/13 12:32:24
It feels a bit scary if something goes wrong and w
Peter Beverloo
2013/03/13 14:02:47
Maybe. We know that something is wrong when we li
| |
119 return; | 214 return; |
120 } | 215 } |
121 | 216 |
122 getOrientationUsingGetRotationMatrix(); | 217 if (dispatchDeviceOrientation) |
Miguel Garcia
2013/03/12 17:00:26
I think the style guide says to use brackets on al
Peter Beverloo
2013/03/12 17:11:22
nit: dito to the comment on line 180.
timvolodine
2013/03/13 12:32:24
Done.
timvolodine
2013/03/13 12:32:24
Done.
| |
218 getOrientationUsingGetRotationMatrix(); | |
123 } | 219 } |
124 | 220 |
125 void getOrientationUsingGetRotationMatrix() { | 221 void getOrientationUsingGetRotationMatrix() { |
126 if (mGravityVector == null || mMagneticFieldVector == null) { | 222 if (mGravityVector == null || mMagneticFieldVector == null) { |
127 return; | 223 return; |
128 } | 224 } |
129 | 225 |
130 // Get the rotation matrix. | 226 // Get the rotation matrix. |
131 // The rotation matrix that transforms from the body frame to the earth | 227 // The rotation matrix that transforms from the body frame to the earth |
132 // frame. | 228 // frame. |
(...skipping 23 matching lines...) Expand all Loading... | |
156 } | 252 } |
157 | 253 |
158 double gamma = Math.toDegrees(rotationAngles[2]); | 254 double gamma = Math.toDegrees(rotationAngles[2]); |
159 while (gamma < -90.0) { | 255 while (gamma < -90.0) { |
160 gamma += 360.0; // [-90, 90) | 256 gamma += 360.0; // [-90, 90) |
161 } | 257 } |
162 | 258 |
163 gotOrientation(alpha, beta, gamma); | 259 gotOrientation(alpha, beta, gamma); |
164 } | 260 } |
165 | 261 |
166 boolean registerForSensors(int rateInMilliseconds) { | |
167 if (registerForSensorType(Sensor.TYPE_ACCELEROMETER, rateInMilliseconds) | |
168 && registerForSensorType(Sensor.TYPE_MAGNETIC_FIELD, rateInMilli seconds)) { | |
169 return true; | |
170 } | |
171 unregisterForSensors(); | |
172 return false; | |
173 } | |
174 | |
175 private SensorManager getSensorManager() { | 262 private SensorManager getSensorManager() { |
176 if (mSensorManager != null) { | 263 if (mSensorManager != null) { |
177 return mSensorManager; | 264 return mSensorManager; |
178 } | 265 } |
179 mSensorManager = (SensorManager)WeakContext.getSystemService(Context.SEN SOR_SERVICE); | 266 mSensorManager = (SensorManager)WeakContext.getSystemService(Context.SEN SOR_SERVICE); |
180 return mSensorManager; | 267 return mSensorManager; |
181 } | 268 } |
182 | 269 |
183 void unregisterForSensors() { | 270 private boolean registerForSensors(Iterable<Integer> sensorTypes, int rateIn Milliseconds) { |
184 SensorManager sensorManager = getSensorManager(); | 271 for (Integer sensorType : sensorTypes) { |
185 if (sensorManager == null) { | 272 if (!mActiveSensors.contains(sensorType)) { |
186 return; | 273 if (!registerForSensorType(sensorType, rateInMilliseconds)) { |
274 // restore the previous state upon failure | |
275 unregisterForSensors(sensorTypes); | |
Peter Beverloo
2013/03/12 17:11:22
Won't this fail if device orientation registered f
timvolodine
2013/03/13 12:32:24
this method is always called from start() with a l
| |
276 return false; | |
277 } | |
278 } | |
279 mActiveSensors.add(sensorType); | |
187 } | 280 } |
188 sensorManager.unregisterListener(this); | 281 return true; |
282 } | |
283 | |
284 private void unregisterForSensors(Iterable<Integer> sensorTypes) { | |
285 for (Integer sensorType : sensorTypes) { | |
286 if (mActiveSensors.contains(sensorType)) { | |
287 getSensorManager().unregisterListener(this, | |
288 getSensorManager().getDefaultSensor(sensorType)); | |
289 mActiveSensors.remove(sensorType); | |
290 } | |
291 } | |
189 } | 292 } |
190 | 293 |
191 boolean registerForSensorType(int type, int rateInMilliseconds) { | 294 boolean registerForSensorType(int type, int rateInMilliseconds) { |
192 SensorManager sensorManager = getSensorManager(); | 295 SensorManager sensorManager = getSensorManager(); |
193 if (sensorManager == null) { | 296 if (sensorManager == null) { |
194 return false; | 297 return false; |
195 } | 298 } |
196 List<Sensor> sensors = sensorManager.getSensorList(type); | 299 Sensor defaultSensor = sensorManager.getDefaultSensor(type); |
Peter Beverloo
2013/03/12 17:11:22
I looked into doing this change myself, but I'm a
timvolodine
2013/03/13 12:32:24
ok, so should I revert to the previous solution wi
Peter Beverloo
2013/03/13 14:02:47
I do think we should revert until we properly unde
Peter Beverloo
2013/03/13 14:02:47
Can you file an issue to track looking in to switc
timvolodine
2013/03/13 15:29:49
Done.
timvolodine
2013/03/13 15:29:49
will do
| |
197 if (sensors.isEmpty()) { | 300 if (defaultSensor == null) { |
198 return false; | 301 return false; |
199 } | 302 } |
200 | 303 |
201 final int rateInMicroseconds = 1000 * rateInMilliseconds; | 304 final int rateInMicroseconds = 1000 * rateInMilliseconds; |
202 // We want to err on the side of getting more events than we need. | 305 return sensorManager.registerListener(this, defaultSensor, rateInMicrose conds, |
203 final int requestedRate = rateInMicroseconds / 2; | 306 getHandler()); |
204 | |
205 // TODO(steveblock): Consider handling multiple sensors. | |
206 return sensorManager.registerListener(this, sensors.get(0), requestedRat e, getHandler()); | |
207 } | 307 } |
208 | 308 |
209 void gotOrientation(double alpha, double beta, double gamma) { | 309 void gotOrientation(double alpha, double beta, double gamma) { |
210 synchronized (mNativePtrLock) { | 310 synchronized (mNativePtrLock) { |
211 if (mNativePtr != 0) { | 311 if (mNativePtr != 0) { |
212 nativeGotOrientation(mNativePtr, alpha, beta, gamma); | 312 nativeGotOrientation(mNativePtr, alpha, beta, gamma); |
213 } | 313 } |
214 } | 314 } |
215 } | 315 } |
216 | 316 |
317 void gotAcceleration(double x, double y, double z) { | |
Miguel Garcia
2013/03/12 17:00:26
I wonder if we could not simplify this by having o
Miguel Garcia
2013/03/12 17:00:26
can these methods be private or public if meant to
Peter Beverloo
2013/03/12 17:11:22
We cannot be sure in regards to which sensors we c
Peter Beverloo
2013/03/12 17:11:22
They should be private.
timvolodine
2013/03/13 12:32:24
Done.
timvolodine
2013/03/13 12:32:24
Done.
timvolodine
2013/03/13 12:32:24
Done.
timvolodine
2013/03/13 12:32:24
Done.
| |
318 synchronized (mNativePtrLock) { | |
319 if (mNativePtr != 0) { | |
320 nativeGotAcceleration(mNativePtr, x, y, z); | |
321 } | |
322 } | |
323 } | |
324 | |
325 void gotAccelerationIncludingGravity(double x, double y, double z) { | |
326 synchronized (mNativePtrLock) { | |
327 if (mNativePtr != 0) { | |
328 nativeGotAccelerationIncludingGravity(mNativePtr, x, y, z); | |
329 } | |
330 } | |
331 } | |
332 | |
333 void gotRotationRate(double alpha, double beta, double gamma) { | |
334 synchronized (mNativePtrLock) { | |
335 if (mNativePtr != 0) { | |
336 nativeGotRotationRate(mNativePtr, alpha, beta, gamma); | |
337 } | |
338 } | |
339 } | |
340 | |
217 private Handler getHandler() { | 341 private Handler getHandler() { |
218 synchronized (mHandlerLock) { | 342 synchronized (mHandlerLock) { |
219 // If we don't have a background thread, start it now. | 343 // If we don't have a background thread, start it now. |
220 if (mThread == null) { | 344 if (mThread == null) { |
221 mThread = new Thread(new Runnable() { | 345 mThread = new Thread(new Runnable() { |
222 @Override | 346 @Override |
223 public void run() { | 347 public void run() { |
224 Looper.prepare(); | 348 Looper.prepare(); |
225 // Our Handler doesn't actually have to do anything, bec ause | 349 // Our Handler doesn't actually have to do anything, bec ause |
226 // SensorManager posts directly to the underlying Looper . | 350 // SensorManager posts directly to the underlying Looper . |
(...skipping 17 matching lines...) Expand all Loading... | |
244 } | 368 } |
245 | 369 |
246 private void setHandler(Handler handler) { | 370 private void setHandler(Handler handler) { |
247 synchronized (mHandlerLock) { | 371 synchronized (mHandlerLock) { |
248 mHandler = handler; | 372 mHandler = handler; |
249 mHandlerLock.notify(); | 373 mHandlerLock.notify(); |
250 } | 374 } |
251 } | 375 } |
252 | 376 |
253 @CalledByNative | 377 @CalledByNative |
254 private static DeviceOrientation getInstance() { | 378 private static DeviceMotionAndOrientation getInstance() { |
255 synchronized (sSingletonLock) { | 379 synchronized (sSingletonLock) { |
256 if (sSingleton == null) { | 380 if (sSingleton == null) { |
257 sSingleton = new DeviceOrientation(); | 381 sSingleton = new DeviceMotionAndOrientation(); |
258 } | 382 } |
259 return sSingleton; | 383 return sSingleton; |
260 } | 384 } |
261 } | 385 } |
262 | 386 |
263 /** | 387 /** |
264 * See chrome/browser/device_orientation/data_fetcher_impl_android.cc | 388 * Native JNI calls, |
389 * see content/browser/device_orientation/data_fetcher_impl_android.cc | |
265 */ | 390 */ |
266 private native void nativeGotOrientation( | 391 private native void nativeGotOrientation( |
267 int nativeDataFetcherImplAndroid, | 392 int nativeDataFetcherImplAndroid, |
268 double alpha, double beta, double gamma); | 393 double alpha, double beta, double gamma); |
269 } | 394 |
395 /** | |
396 * linear acceleration w/o gravity | |
Peter Beverloo
2013/03/12 17:11:22
nit: Please use proper grammar and spell out "with
timvolodine
2013/03/13 12:32:24
Done.
| |
397 */ | |
398 private native void nativeGotAcceleration( | |
399 int nativeDataFetcherImplAndroid, | |
400 double x, double y, double z); | |
401 | |
402 /** | |
403 * acceleration including gravity | |
Peter Beverloo
2013/03/12 17:11:22
nit: dito.
timvolodine
2013/03/13 12:32:24
Done.
| |
404 */ | |
405 private native void nativeGotAccelerationIncludingGravity( | |
406 int nativeDataFetcherImplAndroid, | |
407 double x, double y, double z); | |
408 | |
409 /** | |
410 * gyroscope | |
Peter Beverloo
2013/03/12 17:11:22
nit: dito.
timvolodine
2013/03/13 12:32:24
Done.
| |
411 */ | |
412 private native void nativeGotRotationRate( | |
413 int nativeDataFetcherImplAndroid, | |
414 double alpha, double beta, double gamma); | |
415 | |
416 } | |
OLD | NEW |