use of android.hardware.SensorManager in project BetterBatteryStats by asksven.
the class BatteryStatsProxy method findSensor.
@SuppressLint("NewApi")
Sensor findSensor(Context ctx, int handle) {
String TAG = "BBS.Sensors";
Sensor retVal = null;
// Enumerate all sensors
final SensorManager sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL);
if ((sensors == null) || (sensors.size() == 0))
return null;
for (int i = 0; i < sensors.size(); i++) {
Sensor sensor = sensors.get(i);
Method methodGetHandle;
int hhandle = -1;
try {
methodGetHandle = sensor.getClass().getDeclaredMethod("getHandle");
methodGetHandle.setAccessible(true);
hhandle = ((Integer) methodGetHandle.invoke(sensor)).intValue();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (hhandle == handle) {
retVal = sensor;
return retVal;
}
if (CommonLogSettings.DEBUG) {
if (Build.VERSION.SDK_INT >= 21) {
Log.i(TAG, "name=" + sensor.getName() + ", handle=" + handle + ", wakeup=" + sensor.isWakeUpSensor() + ", type=" + sensor.getStringType());
} else {
Log.i(TAG, "name=" + sensor.getName() + ", handle=" + handle);
}
}
}
return null;
}
use of android.hardware.SensorManager in project android_packages_apps_Settings by omnirom.
the class DoubleTwistPreferenceController method isGestureAvailable.
public static boolean isGestureAvailable(Context context) {
final Resources resources = context.getResources();
final String type = resources.getString(R.string.gesture_double_twist_sensor_type);
final String vendor = resources.getString(R.string.gesture_double_twist_sensor_vendor);
if (!TextUtils.isEmpty(type) && !TextUtils.isEmpty(vendor)) {
final SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
for (Sensor s : sensorManager.getSensorList(Sensor.TYPE_ALL)) {
if (type.equals(s.getStringType()) && vendor.equals(s.getVendor())) {
return true;
}
}
}
return false;
}
use of android.hardware.SensorManager in project AndroidLife by CaMnter.
the class SensorManagerActivity method initData.
/**
* Initialize the Activity data
*/
@Override
protected void initData() {
// 获取传感器管理器
SensorManager sensorManager = (SensorManager) this.getSystemService(Context.SENSOR_SERVICE);
// 获取默认加速度传感器
Sensor linear = sensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION);
/**
* 传感器监听
* SensorEvent.values[0] = x
* SensorEvent.values[1] = y
* SensorEvent.values[2] = z
*/
SensorEventListener listener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
String info = "";
for (int i = 0; i < event.values.length; i++) {
info += "event.values[" + i + "]:" + event.values[i] + "\t";
}
Log.i("SensorManagerActivity", info);
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
};
// 给对应传感器添加监听
sensorManager.registerListener(listener, linear, SensorManager.SENSOR_DELAY_NORMAL);
// 获得全部的传感器列表
List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL);
this.sensorManagerTV.setText(sensors.size() + "");
for (Sensor sensor : sensors) {
TextView title = new TextView(this);
title.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
title.setTextSize(15);
title.setTextColor(this.getResources().getColor(R.color.themeColor));
switch(sensor.getType()) {
case Sensor.TYPE_ACCELEROMETER:
{
title.setText("1.加速度传感器" + "(" + sensor.getName() + ")");
this.addInfoView(sensor, title);
break;
}
case Sensor.TYPE_MAGNETIC_FIELD:
{
title.setText("2.磁力传感器" + "(" + sensor.getName() + ")");
this.addInfoView(sensor, title);
break;
}
case Sensor.TYPE_ORIENTATION:
{
title.setText("3.方向传感器" + "(" + sensor.getName() + ")");
this.addInfoView(sensor, title);
break;
}
case Sensor.TYPE_GYROSCOPE:
{
title.setText("4.陀螺仪传感器" + "(" + sensor.getName() + ")");
this.addInfoView(sensor, title);
break;
}
case Sensor.TYPE_LIGHT:
{
title.setText("5.光线感应传感器" + "(" + sensor.getName() + ")");
this.addInfoView(sensor, title);
break;
}
case Sensor.TYPE_PRESSURE:
{
title.setText("6.压力传感器" + "(" + sensor.getName() + ")");
this.addInfoView(sensor, title);
break;
}
case Sensor.TYPE_TEMPERATURE:
{
title.setText("7.温度传感器" + "(" + sensor.getName() + ")");
this.addInfoView(sensor, title);
break;
}
case Sensor.TYPE_PROXIMITY:
{
title.setText("8.距离传感器" + "(" + sensor.getName() + ")");
this.addInfoView(sensor, title);
break;
}
case Sensor.TYPE_GRAVITY:
{
title.setText("9.重力传感器" + "(" + sensor.getName() + ")");
this.addInfoView(sensor, title);
break;
}
case Sensor.TYPE_LINEAR_ACCELERATION:
{
title.setText("10.线性加速度传感器" + "(" + sensor.getName() + ")");
this.addInfoView(sensor, title);
break;
}
case Sensor.TYPE_ROTATION_VECTOR:
{
title.setText("11.旋转矢量传感器" + "(" + sensor.getName() + ")");
this.addInfoView(sensor, title);
break;
}
}
}
}
use of android.hardware.SensorManager in project PocketMaps by junjunguo.
the class LightSensor method cleanup.
public void cleanup(Activity activity) {
setLight(Brightness.USER);
SensorManager mySensorManager = (SensorManager) activity.getSystemService(android.app.Service.SENSOR_SERVICE);
Sensor lightSensor = mySensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
if (lightSensor != null) {
mySensorManager.unregisterListener(this, lightSensor);
}
affectedWin = null;
}
Aggregations