android.hardware.Sensor#getType ( )源码实例Demo

下面列出了android.hardware.Sensor#getType ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: VirtualSensor   文件: SensorChange.java
public float[] handleListener(Sensor s, VirtualSensorListener listener, float[] values, int accuracy, long timestamp, float accResolution, float magResolution) {
    if (s.getType() == Sensor.TYPE_ACCELEROMETER) {
        if (Util.checkSensorResolution(this.accelerometerValues, values, accResolution)) {
            this.accelerometerValues = values;
        }
        if (listener.getSensor() != null || listener.isDummyGyroListener) {
            return this.getSensorValues(listener, timestamp);
        }

    } else if (s.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
        if (Util.checkSensorResolution(this.magneticValues, values, magResolution)) {
            this.magneticValues = values;
        }
    }

    return null;
}
 
源代码2 项目: 30-android-libraries-in-30-days   文件: Engine.java
@Override
public void onAccuracyChanged(final Sensor pSensor, final int pAccuracy) {
	if(this.mRunning) {
		switch(pSensor.getType()) {
			case Sensor.TYPE_ACCELEROMETER:
				if(this.mAccelerationData != null) {
					this.mAccelerationData.setAccuracy(pAccuracy);
					this.mAccelerationListener.onAccelerationAccuracyChanged(this.mAccelerationData);
				} else if(this.mOrientationData != null) {
					this.mOrientationData.setAccelerationAccuracy(pAccuracy);
					this.mOrientationListener.onOrientationAccuracyChanged(this.mOrientationData);
				}
				break;
			case Sensor.TYPE_MAGNETIC_FIELD:
				this.mOrientationData.setMagneticFieldAccuracy(pAccuracy);
				this.mOrientationListener.onOrientationAccuracyChanged(this.mOrientationData);
				break;
		}
	}
}
 
源代码3 项目: trekarta   文件: GaugePanel.java
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
    if (sensor.getType() == Sensor.TYPE_PRESSURE) {
        if (accuracy == SensorManager.SENSOR_STATUS_NO_CONTACT || accuracy == SensorManager.SENSOR_STATUS_UNRELIABLE)
            setValue(Gauge.TYPE_ELEVATION, Float.NaN);
    }
}
 
源代码4 项目: SEAL-Demo   文件: RunService.java
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
    Sensor sensor = sensorEvent.sensor;
    if (sensor.getType() == TYPE_ACCELEROMETER) {
        mAccelerometerMatrix = sensorEvent.values;
    } else if (sensor.getType() == TYPE_GYROSCOPE) {
        mGyroscopeMatrix = sensorEvent.values;
    }
}
 
源代码5 项目: android-motion-detector   文件: SensorsActivity.java
/**
 * {@inheritDoc}
 */
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
    if (sensor == null) throw new NullPointerException();

    if (sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD && accuracy == SensorManager.SENSOR_STATUS_UNRELIABLE) {
        Log.e(TAG, "Compass data unreliable");
    }
}
 
源代码6 项目: react-native-google-fit   文件: StepSensor.java
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
    Sensor mySensor = sensorEvent.sensor;

    Log.i(TAG, "onSensorChanged");



    if (mySensor.getType() == Sensor.TYPE_STEP_COUNTER) {
        WritableMap map = Arguments.createMap();

        long curTime = System.currentTimeMillis();
        //i++;
        if ((curTime - lastUpdate) > delay) {
            final Object o = sensorEvent.values[0];
            Log.i("History", "Data point:" + sensorEvent.values[0]);

            map.putDouble("steps", sensorEvent.values[0]);
            sendEvent(this.mReactContext, "StepSensorChangedEvent", map);

            activity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(mReactContext.getApplicationContext(), "" + o, Toast.LENGTH_SHORT).show();
                }
            });
            lastUpdate = curTime;
        }
    }
}
 
源代码7 项目: PTVGlass   文件: OrientationManager.java
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
    if (sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
        mHasInterference = (accuracy < SensorManager.SENSOR_STATUS_ACCURACY_HIGH);
        notifyAccuracyChanged();
    }
}
 
/**
 * Called when the accuracy of the sensor has changed.
 *
 * @param sensor
 * @param accuracy
 */
public void onAccuracyChanged(Sensor sensor, int accuracy) {
    // Only look at accelerometer events
    if (sensor.getType() != Sensor.TYPE_ACCELEROMETER) {
        return;
    }

    // If not running, then just return
    if (this.status == AccelListener.STOPPED) {
        return;
    }
    this.accuracy = accuracy;
}
 
源代码9 项目: androidthings-drivers   文件: LuxActivity.java
@Override
public void onDynamicSensorConnected(Sensor sensor) {
    if (sensor.getType() == Sensor.TYPE_LIGHT) {
        Log.i(TAG, "Light sensor connected");
        mSensorManager.registerListener(LuxActivity.this,
                sensor, SensorManager.SENSOR_DELAY_NORMAL);
    }
}
 
源代码10 项目: Myna   文件: MynaService.java
private void checkAndRegisterSensor(int sensorType){
    List<Sensor> sensors = mSensorManager.getSensorList(Sensor.TYPE_ALL);
    Sensor sensor;
    for (int index = 0; index < sensors.size(); ++index) {
        sensor = sensors.get(index);
        if (sensor.getType() == sensorType) {
            mSensorManager.registerListener(this, sensor,
                    SensorManager.SENSOR_DELAY_FASTEST);
        }
    }
}
 
源代码11 项目: JkStepSensor   文件: StepDcretor.java
public void onSensorChanged(SensorEvent event) {
    Sensor sensor = event.sensor;
    synchronized (this) {
        if (sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
            calc_step(event);
        }
    }
}
 
源代码12 项目: tilt-game-android   文件: Engine.java
@Override
public void onSensorChanged(final SensorEvent pEvent) {
	if (this.mRunning) {
		final Sensor sensor = pEvent.sensor;
		final int sensorType = sensor.getType();
		switch (sensorType) {
			case Sensor.TYPE_ACCELEROMETER:
				if (this.mAccelerationData != null) {
					this.mAccelerationData.setDisplayRotation(this.getDisplayOrientation());
					this.mAccelerationData.setValues(pEvent.values);
					this.mAccelerationListener.onAccelerationChanged(this.mAccelerationData);
				} else if (this.mOrientationData != null) {
					this.mOrientationData.setDisplayRotation(this.getDisplayOrientation());
					this.mOrientationData.setAccelerationValues(pEvent.values);
					this.mOrientationListener.onOrientationChanged(this.mOrientationData);
				}
				break;
			case Sensor.TYPE_MAGNETIC_FIELD:
				this.mOrientationData.setDisplayRotation(this.getDisplayOrientation());
				this.mOrientationData.setMagneticFieldValues(pEvent.values);
				this.mOrientationListener.onOrientationChanged(this.mOrientationData);
				break;
			default:
				throw new IllegalArgumentException("Unexpected " + Sensor.class.getSimpleName() + " of Type: '" + sensorType + "'.");
		}
	}
}
 
源代码13 项目: Sensor-Disabler   文件: SensorUtil.java
public static String generateUniqueSensorKey(Sensor sensor) {
    //TODO Maybe use Sensor.toString?
    return sensor.getName()
            + SENSOR_SEPARATOR
            + sensor.getVendor()
            + SENSOR_SEPARATOR
            + sensor.getVersion()
            + SENSOR_SEPARATOR
            + sensor.getType();
}
 
源代码14 项目: geopaparazzi   文件: OrientationSensor.java
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
    int SensorType = sensor.getType();
    switch (SensorType) {
        case Sensor.TYPE_GRAVITY:
            m_GravityAccuracy = accuracy;
            break;
        case Sensor.TYPE_MAGNETIC_FIELD:
            m_MagneticFieldAccuracy = accuracy;
            break;
    }
    if (m_parent != null) m_parent.onAccuracyChanged(sensor, accuracy);
}
 
源代码15 项目: Sensor-Disabler   文件: SensorUtil.java
public static float getMinimumValueForSensor(Sensor sensor) {
    float minimumValue;
    switch (sensor.getType()) {
        case Sensor.TYPE_HEART_RATE:
        case Sensor.TYPE_LIGHT:
        case Sensor.TYPE_PROXIMITY:
        case Sensor.TYPE_STEP_COUNTER:
        case Sensor.TYPE_PRESSURE:
            minimumValue = 0;
            break;
        default:
            minimumValue = -sensor.getMaximumRange();
    }
    return minimumValue;
}
 
源代码16 项目: PressureNet-SDK   文件: CbService.java
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
	if (sensor.getType() == sensorId) {

	}
}
 
源代码17 项目: Battery-Metrics   文件: SensorMetricsCollector.java
@Override
public synchronized boolean getSnapshot(SensorMetrics snapshot) {
  Utilities.checkNotNull(snapshot, "Null value passed to getSnapshot!");

  if (!mEnabled) {
    return false;
  }

  long currentTimeMs = SystemClock.elapsedRealtime();
  snapshot.set(mCumulativeMetrics);

  for (int i = 0, l = mActiveSensors.size(); i < l; i++) {
    Sensor sensor = mActiveSensors.keyAt(i);
    SensorData data = mActiveSensors.valueAt(i);

    if (data.activeCount <= 0) {
      continue;
    }

    long sensorActiveTimeMs = currentTimeMs - data.startTimeMs;
    double sensorPowerMah = energyConsumedMah(sensor, sensorActiveTimeMs);
    snapshot.total.activeTimeMs += sensorActiveTimeMs;
    snapshot.total.powerMah += sensorPowerMah;

    boolean isWakeupSensor = Util.isWakeupSensor(sensor);
    if (isWakeupSensor) {
      snapshot.total.wakeUpTimeMs += sensorActiveTimeMs;
    }

    if (snapshot.isAttributionEnabled) {
      int type = sensor.getType();
      SensorMetrics.Consumption consumption = snapshot.sensorConsumption.get(type);
      if (consumption == null) {
        consumption = new SensorMetrics.Consumption();
        snapshot.sensorConsumption.put(type, consumption);
      }

      consumption.activeTimeMs += sensorActiveTimeMs;
      consumption.powerMah += sensorPowerMah;

      if (isWakeupSensor) {
        consumption.wakeUpTimeMs += sensorActiveTimeMs;
      }
    }
  }

  return true;
}
 
源代码18 项目: science-journal   文件: AllNativeSensorProvider.java
private List<AdvertisedSensor> buildSensors() {
  List<AdvertisedSensor> sensors = new ArrayList<>();
  final List<Sensor> deviceSensors = getSensorManager().getSensorList(Sensor.TYPE_ALL);
  for (final Sensor sensor : deviceSensors) {
    final SensorAppearanceResources appearance = new SensorAppearanceResources();
    String name = sensor.getName();

    final SensorBehavior behavior = new SensorBehavior();
    behavior.loggingId = name;
    behavior.settingsIntent =
        DeviceSettingsPopupActivity.getPendingIntent(AllNativeSensorProvider.this, sensor);

    final int sensorType = sensor.getType();
    if (sensorType == Sensor.TYPE_ACCELEROMETER) {
      appearance.iconId = android.R.drawable.ic_media_ff;
      appearance.units = "ms/2";
      appearance.shortDescription = "Not really a 3-axis accelerometer";
      behavior.shouldShowSettingsOnConnect = true;
    }

    if (isTemperature(sensorType)) {
      appearance.iconId = android.R.drawable.star_on;
      String unitString =
          TemperatureSettingsPopupActivity.getUnitString(AllNativeSensorProvider.this);
      appearance.units = unitString;
      appearance.shortDescription = "Ambient temperature (settings to change units!)";
      behavior.settingsIntent =
          TemperatureSettingsPopupActivity.getPendingIntent(AllNativeSensorProvider.this, sensor);
    }

    String sensorAddress = "" + sensorType;
    sensors.add(
        new AdvertisedSensor(sensorAddress, name) {
          private SensorEventListener mSensorEventListener;

          @Override
          protected SensorAppearanceResources getAppearance() {
            return appearance;
          }

          @Override
          protected SensorBehavior getBehavior() {
            return behavior;
          }

          @Override
          protected boolean connect() throws Exception {
            unregister();
            return true;
          }

          @Override
          protected void streamData(final DataConsumer c) {
            final int index =
                DeviceSettingsPopupActivity.getIndexForSensorType(
                    sensorType, AllNativeSensorProvider.this);
            mSensorEventListener = new HardwareEventListener(sensorType, index, c);
            getSensorManager()
                .registerListener(mSensorEventListener, sensor, SensorManager.SENSOR_DELAY_UI);
          }

          @Override
          protected void disconnect() {
            unregister();
          }

          private void unregister() {
            if (mSensorEventListener != null) {
              getSensorManager().unregisterListener(mSensorEventListener);
              mSensorEventListener = null;
            }
          }
        });
  }

  return sensors;
}
 
源代码19 项目: CameraV   文件: EnvironmentalSucker.java
@SuppressWarnings({ "unchecked", "deprecation" })
public EnvironmentalSucker(Context context) {
	super(context);
	setSucker(this);
	
	sm = (SensorManager)context.getApplicationContext().getSystemService(Context.SENSOR_SERVICE);
	availableSensors = sm.getSensorList(Sensor.TYPE_ALL);
	
	for(Sensor s : availableSensors) {
		switch(s.getType()) {
		case Sensor.TYPE_AMBIENT_TEMPERATURE:
			sm.registerListener(this, s, SensorManager.SENSOR_DELAY_NORMAL);
			break;
		case Sensor.TYPE_RELATIVE_HUMIDITY:
			sm.registerListener(this, s, SensorManager.SENSOR_DELAY_NORMAL);
			break;
		case Sensor.TYPE_PRESSURE:
			sm.registerListener(this, s, SensorManager.SENSOR_DELAY_NORMAL);
			break;
		case Sensor.TYPE_LIGHT:
			sm.registerListener(this, s, SensorManager.SENSOR_DELAY_NORMAL);
			break;				
		case Sensor.TYPE_TEMPERATURE:
			sm.registerListener(this, s, SensorManager.SENSOR_DELAY_NORMAL);
			break;
		}
			
	}
	
	setTask(new TimerTask() {
		
		@Override
		public void run() {
				if(currentAmbientTemp != null)
					sendToBuffer(currentAmbientTemp);
				if(currentDeviceTemp != null)
					sendToBuffer(currentDeviceTemp);
				if(currentHumidity != null)
					sendToBuffer(currentHumidity);
				if(currentPressure != null)
					sendToBuffer(currentPressure);
				if(currentLight != null)
					sendToBuffer(currentLight);
		}
	});
	
	getTimer().schedule(getTask(), 0, Environment.LOG_RATE);
}
 
源代码20 项目: Sensor-Disabler   文件: SensorUtil.java
public static String getDescription(Sensor sensor) {
    switch (sensor.getType()) {
        case Sensor.TYPE_ACCELEROMETER:
            return "Measures the acceleration force in m/s² that is applied to a device on all three physical axes (x, y, and z), including the force of gravity.";

        case Sensor.TYPE_AMBIENT_TEMPERATURE:
            return "Measures the ambient room temperature in degrees Celsius (°C).";

        case Sensor.TYPE_GRAVITY:
            return "Measures the force of gravity in m/s² that is applied to a device on all three physical axes (x, y, z).";

        case Sensor.TYPE_GYROSCOPE:
            return "Measures a device's rate of rotation in rad/s around each of the three physical axes (x, y, and z).";

        case Sensor.TYPE_HEART_RATE:
            return "Measures heart rate.";

        case Sensor.TYPE_LIGHT:
            return "Measures the ambient light level (illumination) in lx.";

        case Sensor.TYPE_LINEAR_ACCELERATION:
            return "Measures the acceleration force in m/s² that is applied to a device on all three physical axes (x, y, and z), excluding the force of gravity.";

        case Sensor.TYPE_MAGNETIC_FIELD:
            return "Measures the ambient geomagnetic field for all three physical axes (x, y, z) in μT.";

        case Sensor.TYPE_PRESSURE:
            return "Measures the ambient air pressure in hPa or mbar.";

        case Sensor.TYPE_PROXIMITY:
            return "Measures the proximity of an object in cm relative to the view screen of a device. This sensor is typically used to determine whether a handset is being held up to a person's ear.";

        case Sensor.TYPE_RELATIVE_HUMIDITY:
            return "Measures the relative ambient humidity in percent (%).";

        case Sensor.TYPE_ROTATION_VECTOR:
            return "Measures the orientation of a device by providing the three elements of the device's rotation vector.";

        case Sensor.TYPE_ORIENTATION:
            return "Measures degrees of rotation that a device makes around all three physical axes (x, y, z). ";

        case Sensor.TYPE_TEMPERATURE:
            return "Measures the temperature of the device in degrees Celsius (°C). ";

        default:
            return "Information about this sensor is unavailable.";
    }
}