本文整理匯總了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);
}