當前位置: 首頁>>代碼示例>>Java>>正文


Java Sensor類代碼示例

本文整理匯總了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;
}
 
開發者ID:BANKEX,項目名稱:smart-asset-iot-android-demo,代碼行數:23,代碼來源:ShakeDetector.java

示例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);
   
    
}
 
開發者ID:StringMon,項目名稱:homescreenarcade,代碼行數:24,代碼來源:GameActivity.java

示例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");
  }
}
 
開發者ID:Piasy,項目名稱:AppRTC-Android,代碼行數:9,代碼來源:AppRTCProximitySensor.java

示例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);
    }
}
 
開發者ID:googlecodelabs,項目名稱:androidthings-weatherstation,代碼行數:11,代碼來源:WeatherStationActivity.java

示例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);
    }
}
 
開發者ID:WrBug,項目名稱:GravityBox,代碼行數:19,代碼來源:ModLedControl.java

示例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();
}
 
開發者ID:feup-infolab,項目名稱:labtablet,代碼行數:16,代碼來源:FieldModeActivity.java

示例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) {}
    };
}
 
開發者ID:ubikgs,項目名稱:AndroidSensors,代碼行數:13,代碼來源:IMUSensorGatherer.java

示例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;
}
 
開發者ID:tringuyen1121,項目名稱:Khonsu,代碼行數:21,代碼來源:SensorService.java

示例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;
    }
}
 
開發者ID:mattdelsordo,項目名稱:420Game,代碼行數:16,代碼來源:HostLobbyActivity.java

示例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);
    }
}
 
開發者ID:peter10110,項目名稱:Android-SteamVR-controller,代碼行數:20,代碼來源:AccelerometerCompassProvider.java

示例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);
}
 
開發者ID:ANFR-France,項目名稱:proto-collecte,代碼行數:10,代碼來源:CameraActivity.java

示例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;
    }
}
 
開發者ID:mattdelsordo,項目名稱:420Game,代碼行數:15,代碼來源:JoinLobbyActivity.java

示例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;

	}
}
 
開發者ID:ljlgithup,項目名稱:MapDemo,代碼行數:22,代碼來源:MyOrientationListener.java

示例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();
    }
 
開發者ID:PacktPublishing,項目名稱:Android-Wear-Projects,代碼行數:10,代碼來源:WearStepService.java

示例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);
}
 
開發者ID:HyfUestc,項目名稱:PDR,代碼行數:14,代碼來源:StepDetector.java


注:本文中的android.hardware.Sensor類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。