当前位置: 首页>>代码示例>>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;未经允许,请勿转载。