当前位置: 首页>>代码示例>>Java>>正文


Java Sensor.TYPE_SIGNIFICANT_MOTION属性代码示例

本文整理汇总了Java中android.hardware.Sensor.TYPE_SIGNIFICANT_MOTION属性的典型用法代码示例。如果您正苦于以下问题:Java Sensor.TYPE_SIGNIFICANT_MOTION属性的具体用法?Java Sensor.TYPE_SIGNIFICANT_MOTION怎么用?Java Sensor.TYPE_SIGNIFICANT_MOTION使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.hardware.Sensor的用法示例。


在下文中一共展示了Sensor.TYPE_SIGNIFICANT_MOTION属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onCreate

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);

    //assim como em LocationManager a gente pega um tipo de provider (GPS_PROVIDER)
    //com sensores, não há APIs dedicadas para sensores, usamos o SensorManager
    //os sensores são identificados por nomes (TYPE_LINEAR_ACCELERATION)

    //existem sensores e tipos de sensores
    //abaixo, estamos pedindo todos os sensores, de todos os tipos
    List<Sensor> allSensors = new ArrayList<>(sensorManager.getSensorList(Sensor.TYPE_ALL));
    List<Sensor> sensors = new ArrayList<>();

    //removendo trigger sensors, que entregam apenas uma única leitura
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        for (Sensor s : allSensors) {
            boolean triggerSensor = s.getType() == Sensor.TYPE_SIGNIFICANT_MOTION ||
                    s.getType() == Sensor.TYPE_STEP_COUNTER ||
                    s.getType() == Sensor.TYPE_STEP_DETECTOR;

            if (!triggerSensor) {
                sensors.add(s);
            }
        }
    }
    else {
        sensors = allSensors;
    }

    adapter=new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, sensors);
    setListAdapter(adapter);
}
 
开发者ID:if710,项目名称:2017.2-codigo,代码行数:34,代码来源:SensorListActivity.java

示例2: onTrigger

@Override
public void onTrigger(TriggerEvent event) {
    Log.i("BumpMonitor", "Sensor triggered");
    //value[0] = 1.0 when the sensor triggers. 1.0 is the only allowed value.
    long curTime = System.currentTimeMillis();
    // only allow one update every 100ms.
    if (event.sensor.getType() == Sensor.TYPE_SIGNIFICANT_MOTION) {
        if ((curTime - lastUpdate) > CHECK_INTERVAL) {
            lastUpdate = curTime;

            /*
             * Send Alert
             */
            Message message = new Message();
            message.what = EventTrigger.BUMP;

            try {
                if (serviceMessenger != null) {
                    serviceMessenger.send(message);
                }
            } catch (RemoteException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    //re-register the listener (it finishes after each event)
    boolean registered = sensorMgr.requestTriggerSensor(sensorListener, bumpSensor);
    Log.i("BumpMonitor", "Significant motion sensor re-registered: "+registered);

}
 
开发者ID:guardianproject,项目名称:haven,代码行数:31,代码来源:BumpMonitor.java

示例3: isRestricted

@SuppressWarnings("deprecation")
private boolean isRestricted(XParam param, int type) throws Throwable {
	if (type == Sensor.TYPE_ALL)
		return false;
	else if (type == Sensor.TYPE_ACCELEROMETER || type == Sensor.TYPE_LINEAR_ACCELERATION) {
		if (isRestricted(param, "acceleration"))
			return true;
	} else if (type == Sensor.TYPE_GRAVITY) {
		if (isRestricted(param, "gravity"))
			return true;
	} else if (type == Sensor.TYPE_RELATIVE_HUMIDITY) {
		if (isRestricted(param, "humidity"))
			return true;
	} else if (type == Sensor.TYPE_LIGHT) {
		if (isRestricted(param, "light"))
			return true;
	} else if (type == Sensor.TYPE_MAGNETIC_FIELD || type == Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED) {
		if (isRestricted(param, "magnetic"))
			return true;
	} else if (type == Sensor.TYPE_SIGNIFICANT_MOTION) {
		if (isRestricted(param, "motion"))
			return true;
	} else if (type == Sensor.TYPE_ORIENTATION || type == Sensor.TYPE_GYROSCOPE
			|| type == Sensor.TYPE_GYROSCOPE_UNCALIBRATED) {
		if (isRestricted(param, "orientation"))
			return true;
	} else if (type == Sensor.TYPE_PRESSURE) {
		if (isRestricted(param, "pressure"))
			return true;
	} else if (type == Sensor.TYPE_PROXIMITY) {
		if (isRestricted(param, "proximity"))
			return true;
	} else if (type == Sensor.TYPE_GAME_ROTATION_VECTOR || type == Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR
			|| type == Sensor.TYPE_ROTATION_VECTOR) {
		if (isRestricted(param, "rotation"))
			return true;
	} else if (type == Sensor.TYPE_TEMPERATURE || type == Sensor.TYPE_AMBIENT_TEMPERATURE) {
		if (isRestricted(param, "temperature"))
			return true;
	} else if (type == Sensor.TYPE_STEP_COUNTER || type == Sensor.TYPE_STEP_DETECTOR) {
		if (isRestricted(param, "step"))
			return true;
	} else if (type == Sensor.TYPE_HEART_RATE) {
		if (isRestricted(param, "heartrate"))
			return true;
	} else if (type == 22) {
		// 22 = TYPE_TILT_DETECTOR
		// Do nothing
	} else if (type == 23 || type == 24 || type == 25) {
		// 23 = TYPE_WAKE_GESTURE
		// 24 = TYPE_GLANCE_GESTURE
		// 25 = TYPE_PICK_UP_GESTURE
		// 23/24 This sensor is expected to only be used by the system ui
		// 25 Expected to be used internally for always on display
	} else
		Util.log(this, Log.WARN, "Unknown sensor type=" + type);
	return false;
}
 
开发者ID:ukanth,项目名称:XPrivacy,代码行数:58,代码来源:XSensorManager.java


注:本文中的android.hardware.Sensor.TYPE_SIGNIFICANT_MOTION属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。