| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 | 51 |
| 52 // Lazily initialized when registering for notifications. | 52 // Lazily initialized when registering for notifications. |
| 53 private SensorManagerProxy mSensorManagerProxy; | 53 private SensorManagerProxy mSensorManagerProxy; |
| 54 | 54 |
| 55 // The only instance of that class and its associated lock. | 55 // The only instance of that class and its associated lock. |
| 56 private static DeviceMotionAndOrientation sSingleton; | 56 private static DeviceMotionAndOrientation sSingleton; |
| 57 private static Object sSingletonLock = new Object(); | 57 private static Object sSingletonLock = new Object(); |
| 58 | 58 |
| 59 /** | 59 /** |
| 60 * constants for using in JNI calls, also see | 60 * constants for using in JNI calls, also see |
| 61 * content/browser/device_orientation/data_fetcher_impl_android.cc | 61 * content/browser/device_orientation/sensor_manager_android.cc |
| 62 */ | 62 */ |
| 63 static final int DEVICE_ORIENTATION = 0; | 63 static final int DEVICE_ORIENTATION = 0; |
| 64 static final int DEVICE_MOTION = 1; | 64 static final int DEVICE_MOTION = 1; |
| 65 | 65 |
| 66 static final Set<Integer> DEVICE_ORIENTATION_SENSORS = CollectionUtil.newHas
hSet( | 66 static final Set<Integer> DEVICE_ORIENTATION_SENSORS = CollectionUtil.newHas
hSet( |
| 67 Sensor.TYPE_ROTATION_VECTOR); | 67 Sensor.TYPE_ROTATION_VECTOR); |
| 68 | 68 |
| 69 static final Set<Integer> DEVICE_MOTION_SENSORS = CollectionUtil.newHashSet( | 69 static final Set<Integer> DEVICE_MOTION_SENSORS = CollectionUtil.newHashSet( |
| 70 Sensor.TYPE_ACCELEROMETER, | 70 Sensor.TYPE_ACCELEROMETER, |
| 71 Sensor.TYPE_LINEAR_ACCELERATION, | 71 Sensor.TYPE_LINEAR_ACCELERATION, |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 synchronized (sSingletonLock) { | 432 synchronized (sSingletonLock) { |
| 433 if (sSingleton == null) { | 433 if (sSingleton == null) { |
| 434 sSingleton = new DeviceMotionAndOrientation(); | 434 sSingleton = new DeviceMotionAndOrientation(); |
| 435 } | 435 } |
| 436 return sSingleton; | 436 return sSingleton; |
| 437 } | 437 } |
| 438 } | 438 } |
| 439 | 439 |
| 440 /** | 440 /** |
| 441 * Native JNI calls, | 441 * Native JNI calls, |
| 442 * see content/browser/device_orientation/data_fetcher_impl_android.cc | 442 * see content/browser/device_orientation/sensor_manager_android.cc |
| 443 */ | 443 */ |
| 444 | 444 |
| 445 /** | 445 /** |
| 446 * Orientation of the device with respect to its reference frame. | 446 * Orientation of the device with respect to its reference frame. |
| 447 */ | 447 */ |
| 448 private native void nativeGotOrientation( | 448 private native void nativeGotOrientation( |
| 449 long nativeDataFetcherImplAndroid, | 449 long nativeSensorManagerAndroid, |
| 450 double alpha, double beta, double gamma); | 450 double alpha, double beta, double gamma); |
| 451 | 451 |
| 452 /** | 452 /** |
| 453 * Linear acceleration without gravity of the device with respect to its bod
y frame. | 453 * Linear acceleration without gravity of the device with respect to its bod
y frame. |
| 454 */ | 454 */ |
| 455 private native void nativeGotAcceleration( | 455 private native void nativeGotAcceleration( |
| 456 long nativeDataFetcherImplAndroid, | 456 long nativeSensorManagerAndroid, |
| 457 double x, double y, double z); | 457 double x, double y, double z); |
| 458 | 458 |
| 459 /** | 459 /** |
| 460 * Acceleration including gravity of the device with respect to its body fra
me. | 460 * Acceleration including gravity of the device with respect to its body fra
me. |
| 461 */ | 461 */ |
| 462 private native void nativeGotAccelerationIncludingGravity( | 462 private native void nativeGotAccelerationIncludingGravity( |
| 463 long nativeDataFetcherImplAndroid, | 463 long nativeSensorManagerAndroid, |
| 464 double x, double y, double z); | 464 double x, double y, double z); |
| 465 | 465 |
| 466 /** | 466 /** |
| 467 * Rotation rate of the device with respect to its body frame. | 467 * Rotation rate of the device with respect to its body frame. |
| 468 */ | 468 */ |
| 469 private native void nativeGotRotationRate( | 469 private native void nativeGotRotationRate( |
| 470 long nativeDataFetcherImplAndroid, | 470 long nativeSensorManagerAndroid, |
| 471 double alpha, double beta, double gamma); | 471 double alpha, double beta, double gamma); |
| 472 | 472 |
| 473 /** | 473 /** |
| 474 * Need the an interface for SensorManager for testing. | 474 * Need the an interface for SensorManager for testing. |
| 475 */ | 475 */ |
| 476 interface SensorManagerProxy { | 476 interface SensorManagerProxy { |
| 477 public boolean registerListener(SensorEventListener listener, int sensor
Type, int rate, | 477 public boolean registerListener(SensorEventListener listener, int sensor
Type, int rate, |
| 478 Handler handler); | 478 Handler handler); |
| 479 public void unregisterListener(SensorEventListener listener, int sensorT
ype); | 479 public void unregisterListener(SensorEventListener listener, int sensorT
ype); |
| 480 } | 480 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 499 @Override | 499 @Override |
| 500 public void unregisterListener(SensorEventListener listener, int sensorT
ype) { | 500 public void unregisterListener(SensorEventListener listener, int sensorT
ype) { |
| 501 List<Sensor> sensors = mSensorManager.getSensorList(sensorType); | 501 List<Sensor> sensors = mSensorManager.getSensorList(sensorType); |
| 502 if (!sensors.isEmpty()) { | 502 if (!sensors.isEmpty()) { |
| 503 mSensorManager.unregisterListener(listener, sensors.get(0)); | 503 mSensorManager.unregisterListener(listener, sensors.get(0)); |
| 504 } | 504 } |
| 505 } | 505 } |
| 506 } | 506 } |
| 507 | 507 |
| 508 } | 508 } |
| OLD | NEW |