Example usage for android.hardware SensorManager SENSOR_DELAY_UI

List of usage examples for android.hardware SensorManager SENSOR_DELAY_UI

Introduction

In this page you can find the example usage for android.hardware SensorManager SENSOR_DELAY_UI.

Prototype

int SENSOR_DELAY_UI

To view the source code for android.hardware SensorManager SENSOR_DELAY_UI.

Click Source Link

Document

rate suitable for the user interface

Usage

From source file:com.javierarias.magnadroid.Magnadroid.java

@Override
protected void onResume() {
    super.onResume();
    mSensorManager.registerListener(this, mMagnetic, SensorManager.SENSOR_DELAY_UI);
}

From source file:pl.mrwojtek.sensrec.app.SamplingPeriodDialog.java

@Override
public void onClick(DialogInterface dialog, int which) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    int position = samplingSpinner.getSelectedItemPosition();
    if (position == POSITION_CUSTOM) {
        try {//from w  w w.  j  a va 2s  .co  m
            long delay = Long.valueOf(millisecondsEdit.getText().toString());
            prefs.edit().putLong(SensorsRecorder.PREF_SAMPLING_PERIOD, delay).apply();
        } catch (NumberFormatException ex) {
            Log.i(TAG, "Unable to save sampling delay: " + ex.getMessage());
        }
    } else if (position == POSITION_NORMAL) {
        prefs.edit().putLong(SensorsRecorder.PREF_SAMPLING_PERIOD, SensorManager.SENSOR_DELAY_NORMAL).apply();
    } else if (position == POSITION_UI) {
        prefs.edit().putLong(SensorsRecorder.PREF_SAMPLING_PERIOD, SensorManager.SENSOR_DELAY_UI).apply();
    } else if (position == POSITION_GAME) {
        prefs.edit().putLong(SensorsRecorder.PREF_SAMPLING_PERIOD, SensorManager.SENSOR_DELAY_GAME).apply();
    } else if (position == POSITION_FASTEST) {
        prefs.edit().putLong(SensorsRecorder.PREF_SAMPLING_PERIOD, SensorManager.SENSOR_DELAY_FASTEST).apply();
    }
}

From source file:com.android.plugins.MagnetometerListener.java

/**
 * Start listening for speed sensor./* ww w .j a  va  2  s.  co  m*/
 *
 * @return          status of listener
*/
private int start() {
    // If already starting or running, then just return
    if ((this.status == MagnetometerListener.RUNNING) || (this.status == MagnetometerListener.STARTING)) {
        return this.status;
    }

    this.setStatus(MagnetometerListener.STARTING);

    // Get magnetometer from sensor manager
    List<Sensor> list = this.sensorManager.getSensorList(Sensor.TYPE_MAGNETIC_FIELD);

    // 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(MagnetometerListener.STARTING);
    } else {
        this.setStatus(MagnetometerListener.ERROR_FAILED_TO_START);
        this.fail(MagnetometerListener.ERROR_FAILED_TO_START,
                "No sensors found to register magnetometer 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;
}

From source file:org.dartlang.phonegap.barometer.BarometerListener.java

/**
 * Start listening for pressure sensor./*from   w w w  . ja va 2s .c om*/
 * 
 * @return          status of listener
*/
private int start() {
    // If already starting or running, then just return
    if ((this.status == BarometerListener.RUNNING) || (this.status == BarometerListener.STARTING)) {
        return this.status;
    }

    this.setStatus(BarometerListener.STARTING);

    // Get barometer from sensor manager
    List<Sensor> list = this.sensorManager.getSensorList(Sensor.TYPE_PRESSURE);

    // 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(BarometerListener.STARTING);
    } else {
        this.setStatus(BarometerListener.ERROR_FAILED_TO_START);
        this.fail(BarometerListener.ERROR_FAILED_TO_START,
                "No sensors found to register barometer 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;
}

From source file:com.android.plugins.GyroscopeListener.java

/**
 * Start listening for speed sensor.// w  ww  . ja va2  s .  c  o  m
 *
 * @return          status of listener
*/
private int start() {
    // If already starting or running, then just return
    if ((this.status == GyroscopeListener.RUNNING) || (this.status == GyroscopeListener.STARTING)) {
        return this.status;
    }

    this.setStatus(GyroscopeListener.STARTING);

    // Get gyroscope from sensor manager
    List<Sensor> list = this.sensorManager.getSensorList(Sensor.TYPE_GYROSCOPE);

    // 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(GyroscopeListener.STARTING);
    } else {
        this.setStatus(GyroscopeListener.ERROR_FAILED_TO_START);
        this.fail(GyroscopeListener.ERROR_FAILED_TO_START,
                "No sensors found to register gyroscope 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;
}

From source file:org.dartlang.phonegap.thermometer.ThermometerListener.java

/**
 * Start listening for temperature sensor.
 * //from ww  w.j  a v  a2  s.  c o m
 * @return          status of listener
*/
private int start() {
    // If already starting or running, then just return
    if ((this.status == ThermometerListener.RUNNING) || (this.status == ThermometerListener.STARTING)) {
        return this.status;
    }

    this.setStatus(ThermometerListener.STARTING);

    // Get thermometer from sensor manager
    List<Sensor> list = this.sensorManager.getSensorList(Sensor.TYPE_AMBIENT_TEMPERATURE);

    // 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(ThermometerListener.STARTING);
    } else {
        this.setStatus(ThermometerListener.ERROR_FAILED_TO_START);
        this.fail(ThermometerListener.ERROR_FAILED_TO_START,
                "No sensors found to register thermometer 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;
}

From source file:org.apache.cordova.pedometer.PedoListener.java

/**
 * Start listening for pedometers sensor.
 *///from   ww w  .  j  a v  a2 s. c o  m
private void start() {
    // If already starting or running, then return
    if ((this.status == PedoListener.RUNNING) || (this.status == PedoListener.STARTING)) {
        return;
    }

    starttimestamp = System.currentTimeMillis();
    this.startsteps = 0;
    this.setStatus(PedoListener.STARTING);

    // Get pedometer from sensor manager
    List<Sensor> list = this.sensorManager.getSensorList(Sensor.TYPE_STEP_COUNTER);

    // If found, then register as listener
    if ((list != null) && (list.size() > 0)) {
        this.mSensor = list.get(0);
        if (this.sensorManager.registerListener(this, this.mSensor, SensorManager.SENSOR_DELAY_UI)) {
            this.setStatus(PedoListener.STARTING);
        } else {
            this.setStatus(PedoListener.ERROR_FAILED_TO_START);
            this.fail(PedoListener.ERROR_FAILED_TO_START, "Device sensor returned an error.");
            return;
        }
        ;
    } else {
        this.setStatus(PedoListener.ERROR_FAILED_TO_START);
        this.fail(PedoListener.ERROR_FAILED_TO_START,
                "No sensors found to register step counter listening to.");
        return;
    }
}

From source file:org.apache.cordova.AccelListener.java

/**
 * Start listening for acceleration sensor.
 * //w  ww.  j a  v a 2  s  .co m
 * @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.
    Handler handler = new Handler(Looper.getMainLooper());
    handler.postDelayed(new Runnable() {
        public void run() {
            AccelListener.this.timeout();
        }
    }, 2000);

    return this.status;
}

From source file:org.skt.runtime.html5apis.Accelerometer.java

/**
 * Start listening for acceleration sensor.
 * // w w w  . j  a v  a 2  s.  c om
 * @return          status of listener
 */
private int start() {
    // If already starting or running, then just return
    if ((this.status == Accelerometer.RUNNING) || (this.status == Accelerometer.STARTING)) {
        return this.status;
    }

    this.setStatus(Accelerometer.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(Accelerometer.STARTING);
    } else {
        this.setStatus(Accelerometer.ERROR_FAILED_TO_START);
        this.fail(Accelerometer.ERROR_FAILED_TO_START,
                "No sensors found to register accelerometer listening to.");
        return this.status;
    }

    // Wait until running
    long timeout = 2000;
    while ((this.status == STARTING) && (timeout > 0)) {
        timeout = timeout - 100;
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    if (timeout == 0) {
        this.setStatus(Accelerometer.ERROR_FAILED_TO_START);
        this.fail(Accelerometer.ERROR_FAILED_TO_START, "Accelerometer could not be started.");
    }
    return this.status;
}

From source file:com.example.appf.CS3570.java

@Override
protected void onResume() {
    super.onResume();
    mSensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_UI);
    mSensorManager.registerListener(this, magnetometer, SensorManager.SENSOR_DELAY_UI);
    mSensorManager.registerListener(this, gyroscope, SensorManager.SENSOR_DELAY_UI);
    // The following call resumes a paused rendering thread.
    // If you de-allocated graphic objects for onPause()
    // this is a good place to re-allocate them.
    mGLView.onResume();/*from w ww  .j ava2 s .  c  o m*/
}