Search in sources :

Example 26 with Sensor

use of android.hardware.Sensor in project AndroidSDK-RecipeBook by gabu.

the class ProximityManager method onResume.

public void onResume() {
    // 近接センサーを取得
    List<Sensor> list = mSensorManager.getSensorList(Sensor.TYPE_PROXIMITY);
    // 取得できなければ何もしない
    if (list.size() < 1)
        return;
    // 近接センサーを取得
    Sensor sensor = list.get(0);
    // 近接センサーにリスナーを登録
    // 第3引数で感度を指定できます。
    mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL);
}
Also used : Sensor(android.hardware.Sensor)

Example 27 with Sensor

use of android.hardware.Sensor in project nmid-headline by miao1007.

the class Shake2Share method startSensor.

private void startSensor() {
    mSensorManager = (SensorManager) activity.getSystemService(Context.SENSOR_SERVICE);
    if (mSensorManager == null) {
        throw new UnsupportedOperationException();
    }
    Sensor sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    if (sensor == null) {
        throw new UnsupportedOperationException();
    }
    boolean success = mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME);
    if (!success) {
        throw new UnsupportedOperationException();
    }
}
Also used : Sensor(android.hardware.Sensor)

Example 28 with Sensor

use of android.hardware.Sensor in project libgdx by libgdx.

the class AndroidInput method registerSensorListeners.

void registerSensorListeners() {
    if (config.useAccelerometer) {
        manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
        if (manager.getSensorList(Sensor.TYPE_ACCELEROMETER).size() == 0) {
            accelerometerAvailable = false;
        } else {
            Sensor accelerometer = manager.getSensorList(Sensor.TYPE_ACCELEROMETER).get(0);
            accelerometerListener = new SensorListener(this.nativeOrientation, this.accelerometerValues, this.magneticFieldValues, this.gyroscopeValues);
            accelerometerAvailable = manager.registerListener(accelerometerListener, accelerometer, SensorManager.SENSOR_DELAY_GAME);
        }
    } else
        accelerometerAvailable = false;
    if (config.useGyroscope) {
        manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
        if (manager.getSensorList(Sensor.TYPE_GYROSCOPE).size() == 0) {
            gyroscopeAvailable = false;
        } else {
            Sensor gyroscope = manager.getSensorList(Sensor.TYPE_GYROSCOPE).get(0);
            gyroscopeListener = new SensorListener(this.nativeOrientation, this.gyroscopeValues, this.magneticFieldValues, this.gyroscopeValues);
            gyroscopeAvailable = manager.registerListener(gyroscopeListener, gyroscope, SensorManager.SENSOR_DELAY_GAME);
        }
    } else
        gyroscopeAvailable = false;
    if (config.useCompass) {
        if (manager == null)
            manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
        Sensor sensor = manager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
        if (sensor != null) {
            compassAvailable = accelerometerAvailable;
            if (compassAvailable) {
                compassListener = new SensorListener(this.nativeOrientation, this.accelerometerValues, this.magneticFieldValues, this.gyroscopeValues);
                compassAvailable = manager.registerListener(compassListener, sensor, SensorManager.SENSOR_DELAY_GAME);
            }
        } else {
            compassAvailable = false;
        }
    } else
        compassAvailable = false;
    Gdx.app.log("AndroidInput", "sensor listener setup");
}
Also used : SensorManager(android.hardware.SensorManager) Sensor(android.hardware.Sensor)

Example 29 with Sensor

use of android.hardware.Sensor in project cw-omnibus by commonsguy.

the class MainActivity method getSensorList.

@Override
public List<Sensor> getSensorList() {
    List<Sensor> unfiltered = new ArrayList<Sensor>(mgr.getSensorList(Sensor.TYPE_ALL));
    List<Sensor> result = new ArrayList<Sensor>();
    for (Sensor s : unfiltered) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT || !isTriggerSensor(s)) {
            result.add(s);
        }
    }
    Collections.sort(result, new Comparator<Sensor>() {

        @Override
        public int compare(final Sensor a, final Sensor b) {
            return (a.toString().compareTo(b.toString()));
        }
    });
    return (result);
}
Also used : ArrayList(java.util.ArrayList) Sensor(android.hardware.Sensor)

Example 30 with Sensor

use of android.hardware.Sensor in project jpHolo by teusink.

the class AccelListener method start.

//--------------------------------------------------------------------------
// LOCAL METHODS
//--------------------------------------------------------------------------
//
/**
     * Start listening for acceleration sensor.
     * 
     * @return          status of listener
    */
private int start() {
    // If already starting or running, then just return
    if ((this.status == AccelListener.RUNNING) || (this.status == AccelListener.STARTING)) {
        return this.status;
    }
    this.setStatus(AccelListener.STARTING);
    // Get accelerometer from sensor manager
    List<Sensor> list = this.sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER);
    // If found, then register as listener
    if ((list != null) && (list.size() > 0)) {
        this.mSensor = list.get(0);
        this.sensorManager.registerListener(this, this.mSensor, SensorManager.SENSOR_DELAY_UI);
        this.setStatus(AccelListener.STARTING);
    } else {
        this.setStatus(AccelListener.ERROR_FAILED_TO_START);
        this.fail(AccelListener.ERROR_FAILED_TO_START, "No sensors found to register accelerometer listening to.");
        return this.status;
    }
    // Set a timeout callback on the main thread.
    stopTimeout();
    mainHandler = new Handler(Looper.getMainLooper());
    mainHandler.postDelayed(mainRunnable, 2000);
    return this.status;
}
Also used : Handler(android.os.Handler) Sensor(android.hardware.Sensor)

Aggregations

Sensor (android.hardware.Sensor)36 SensorManager (android.hardware.SensorManager)7 SensorEventListener (android.hardware.SensorEventListener)5 BatteryStats (android.os.BatteryStats)5 SensorEvent (android.hardware.SensorEvent)4 Intent (android.content.Intent)2 Handler (android.os.Handler)2 ArrayList (java.util.ArrayList)2 NotificationChannel (android.app.NotificationChannel)1 NotificationManager (android.app.NotificationManager)1 SharedPreferences (android.content.SharedPreferences)1 Resources (android.content.res.Resources)1 ViewPager (android.support.v4.view.ViewPager)1 View (android.view.View)1 ViewTreeObserver (android.view.ViewTreeObserver)1 Window (android.view.Window)1 AdapterView (android.widget.AdapterView)1 TextView (android.widget.TextView)1 InjectView (butterknife.InjectView)1 BmobUser (cn.bmob.v3.BmobUser)1