下面列出了android.hardware.Sensor#isWakeUpSensor ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public DeviceSensor(Sensor sensor) {
name = sensor.getName();
vendor = sensor.getVendor();
version = sensor.getVersion();
type = sensor.getType();
resolution = sensor.getResolution();
power = sensor.getPower();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
stringType = sensor.getStringType();
} else {
stringType = "SENSOR_TYPE_" + type;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
reportingMode = sensor.getReportingMode();
isWakeUpSensor = sensor.isWakeUpSensor();
} else {
reportingMode = 0;
isWakeUpSensor = sensor.getName().toLowerCase().contains("wake_up");
}
}
private static SensorDetails extractSensorDetails(Sensor sensor) {
SensorDetails details = null;
if ((details = sensorsMap.get(sensor.getName())) == null) {
details = new SensorDetails();
sensorsMap.put(sensor.getName(), details);
}
details.codeType = sensor.getType();
details.fifoMaxEventCount = sensor.getFifoMaxEventCount();
details.fifoReservedEventCount = sensor.getFifoReservedEventCount();
getAttributesNewVersion(sensor, details);
details.isWakeUpSensor = sensor.isWakeUpSensor();
details.maxDelay = sensor.getMaxDelay();
details.maximumRange = sensor.getMaximumRange();
details.minDelay = sensor.getMinDelay();
details.name = sensor.getName();
details.power = sensor.getPower();
details.reportingMode = sensor.getReportingMode();
details.resolution = sensor.getResolution();
details.stringType = sensor.getStringType();
details.vendor = sensor.getVendor();
details.version = sensor.getVersion();
return details;
}
/**
* Creates a new WindowOrientationListener.
*
* @param context for the WindowOrientationListener.
* @param handler Provides the Looper for receiving sensor updates.
* @param rate at which sensor events are processed (see also
* {@link android.hardware.SensorManager SensorManager}). Use the default
* value of {@link android.hardware.SensorManager#SENSOR_DELAY_NORMAL
* SENSOR_DELAY_NORMAL} for simple screen orientation change detection.
*
* This constructor is private since no one uses it.
*/
private WindowOrientationListener(Context context, Handler handler, int rate) {
mHandler = handler;
mSensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
mRate = rate;
List<Sensor> l = mSensorManager.getSensorList(Sensor.TYPE_DEVICE_ORIENTATION);
Sensor wakeUpDeviceOrientationSensor = null;
Sensor nonWakeUpDeviceOrientationSensor = null;
/**
* Prefer the wakeup form of the sensor if implemented.
* It's OK to look for just two types of this sensor and use
* the last found. Typical devices will only have one sensor of
* this type.
*/
for (Sensor s : l) {
if (s.isWakeUpSensor()) {
wakeUpDeviceOrientationSensor = s;
} else {
nonWakeUpDeviceOrientationSensor = s;
}
}
if (wakeUpDeviceOrientationSensor != null) {
mSensor = wakeUpDeviceOrientationSensor;
} else {
mSensor = nonWakeUpDeviceOrientationSensor;
}
if (mSensor != null) {
mOrientationJudge = new OrientationSensorJudge();
}
if (mOrientationJudge == null) {
mSensor = mSensorManager.getDefaultSensor(USE_GRAVITY_SENSOR
? Sensor.TYPE_GRAVITY : Sensor.TYPE_ACCELEROMETER);
if (mSensor != null) {
// Create listener only if sensors do exist
mOrientationJudge = new AccelSensorJudge(context);
}
}
}
static boolean isWakeupSensor(Sensor sensor) {
return Build.VERSION.SDK_INT >= 21 && sensor.isWakeUpSensor();
}