本文整理汇总了Java中android.hardware.Sensor类的典型用法代码示例。如果您正苦于以下问题:Java Sensor类的具体用法?Java Sensor怎么用?Java Sensor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Sensor类属于android.hardware包,在下文中一共展示了Sensor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import android.hardware.Sensor; //导入依赖的package包/类
/**
* Starts listening for shakes on devices with appropriate hardware.
*
* @return true if the device supports shake detection.
*/
public boolean start(SensorManager sensorManager) {
// Already started?
if (accelerometer != null) {
return true;
}
accelerometer = sensorManager.getDefaultSensor(
Sensor.TYPE_ACCELEROMETER);
// If this phone has an accelerometer, listen to it.
if (accelerometer != null) {
this.sensorManager = sensorManager;
sensorManager.registerListener(this, accelerometer,
SensorManager.SENSOR_DELAY_FASTEST);
}
return accelerometer != null;
}
示例2: onCreate
import android.hardware.Sensor; //导入依赖的package包/类
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mySensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
myAccelerometer = mySensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
mySensorManager.registerListener(this, myAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);
int level = getIntent().getIntExtra("level", 1);
soundEngine = new com.homescreenarcade.mazeman.SoundEngine(this);
gameEngine = new com.homescreenarcade.mazeman.GameEngine(this, soundEngine, level);
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
gameView = new com.homescreenarcade.mazeman.GameSurfaceView(this, gameEngine, width, height);
setContentView(gameView);
}
示例3: onAccuracyChanged
import android.hardware.Sensor; //导入依赖的package包/类
@Override
public final void onAccuracyChanged(Sensor sensor, int accuracy) {
threadChecker.checkIsOnValidThread();
AppRTCUtils.assertIsTrue(sensor.getType() == Sensor.TYPE_PROXIMITY);
if (accuracy == SensorManager.SENSOR_STATUS_UNRELIABLE) {
Log.e(TAG, "The values returned by this sensor cannot be trusted");
}
}
示例4: onSensorChanged
import android.hardware.Sensor; //导入依赖的package包/类
@Override
public void onSensorChanged(SensorEvent event) {
final float value = event.values[0];
if (event.sensor.getType() == Sensor.TYPE_AMBIENT_TEMPERATURE) {
updateTemperatureDisplay(value);
} else if (event.sensor.getType() == Sensor.TYPE_PRESSURE) {
updateBarometerDisplay(value);
}
}
示例5: toggleActiveScreenFeature
import android.hardware.Sensor; //导入依赖的package包/类
private static void toggleActiveScreenFeature(boolean enable) {
try {
if (enable && mContext != null) {
mPm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
mKm = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
mSm = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
mProxSensor = mSm.getDefaultSensor(Sensor.TYPE_PROXIMITY);
} else {
mProxSensor = null;
mSm = null;
mPm = null;
mKm = null;
}
if (DEBUG) log("Active screen feature: " + enable);
} catch (Throwable t) {
XposedBridge.log(t);
}
}
示例6: onResume
import android.hardware.Sensor; //导入依赖的package包/类
@Override
protected void onResume() {
super.onResume();
Log.e("fieldMode", "resume");
sensorManager.registerListener(this,
sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT),
SensorManager.SENSOR_DELAY_NORMAL);
sensorManager.registerListener(this,
sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
SensorManager.SENSOR_DELAY_NORMAL);
registerBatInforReceiver();
}
示例7: initializeSensorEventListenerFor
import android.hardware.Sensor; //导入依赖的package包/类
private SensorEventListener initializeSensorEventListenerFor(final FlowableEmitter<SensorRecord> subscriber) {
return new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
subscriber.onNext(createSensorRecordFrom(event));
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
};
}
示例8: onStartCommand
import android.hardware.Sensor; //导入依赖的package包/类
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
ssManager = (SensorManager)getSystemService(SENSOR_SERVICE);
rotationSensor = ssManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
gravitySensor = ssManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
stepDetectSensor = ssManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR);
magnetSensor = ssManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
// Check if sensors are available, if not close application
if (rotationSensor == null) { hasRotationSensor = false; }
if (gravitySensor == null || stepDetectSensor == null || magnetSensor == null) {
sensorAvailable = false;
}
initListener();
return START_NOT_STICKY;
}
示例9: onSensorChanged
import android.hardware.Sensor; //导入依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.CUPCAKE)
@Override
public void onSensorChanged(SensorEvent event) {
// when pressure value is changed, this method will be called.
float pressure_value = 0.0f;
// if you use this listener as listener of only one sensor (ex, Pressure), then you don't need to check sensor type.
if( Sensor.TYPE_PRESSURE == event.sensor.getType() ) {
pressure_value = event.values[0];
//mAddressLabel = (TextView)findViewById(R.id.hostlobby_address);
// mAddressLabel.setText(String.valueOf(pressure_value));
mCurrentPressure = pressure_value;
}
}
示例10: onSensorChanged
import android.hardware.Sensor; //导入依赖的package包/类
@Override
public void onSensorChanged(SensorEvent event) {
// we received a sensor event. it is a good practice to check
// that we received the proper event
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
System.arraycopy(event.values, 0, magnitudeValues, 0, magnitudeValues.length);
} else if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
System.arraycopy(event.values, 0, accelerometerValues, 0, accelerometerValues.length);
}
if (magnitudeValues != null && accelerometerValues != null) {
// Fuse accelerometer with compass
SensorManager.getRotationMatrix(currentOrientationRotationMatrix.matrix, inclinationValues, accelerometerValues,
magnitudeValues);
// Transform rotation matrix to quaternion
currentOrientationQuaternion.setRowMajor(currentOrientationRotationMatrix.matrix);
}
}
示例11: onCreate
import android.hardware.Sensor; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
accelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
magnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
txt = (TextView) findViewById(R.id.label_hello);
}
示例12: onSensorChanged
import android.hardware.Sensor; //导入依赖的package包/类
@Override
public void onSensorChanged(SensorEvent event) {
// when pressure value is changed, this method will be called.
float pressure_value = 0.0f;
// if you use this listener as listener of only one sensor (ex, Pressure), then you don't need to check sensor type.
if( Sensor.TYPE_PRESSURE == event.sensor.getType() ) {
pressure_value = event.values[0];
//mAddressLabel = (TextView)findViewById(R.id.hostlobby_address);
// mAddressLabel.setText(String.valueOf(pressure_value));
mCurrentPressure = pressure_value;
}
}
示例13: onSensorChanged
import android.hardware.Sensor; //导入依赖的package包/类
@SuppressWarnings(
{ "deprecation" })
@Override
public void onSensorChanged(SensorEvent event)
{
if (event.sensor.getType() == Sensor.TYPE_ORIENTATION)
{
float x = event.values[SensorManager.DATA_X];
if (Math.abs(x - lastX) > 1.0)
{
if (mOnOrientationListener != null)
{
mOnOrientationListener.onOrientationChanged(x);
}
}
lastX = x;
}
}
示例14: onSensorChanged
import android.hardware.Sensor; //导入依赖的package包/类
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_STEP_COUNTER)
StepsTaken.updateSteps(event.values.length);
Log.d(TAG, "onSensorChanged: steps count is" + event.values.length);
// sendToPhone();
sendData();
updateNotification();
}
示例15: onResume
import android.hardware.Sensor; //导入依赖的package包/类
public void onResume() {
sensorManager.registerListener(this,
sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SensorManager.SENSOR_DELAY_FASTEST);
sensorManager.registerListener(this,
sensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION),
SensorManager.SENSOR_DELAY_FASTEST);
sensorManager.registerListener(this,
sensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY),
SensorManager.SENSOR_DELAY_FASTEST);
}