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:pl.mrwojtek.sensrec.app.SamplingPeriodDialog.java

public static int getSamplingPosition(long delay) {
    if (delay == SensorManager.SENSOR_DELAY_NORMAL) {
        return POSITION_NORMAL;
    } else if (delay == SensorManager.SENSOR_DELAY_UI) {
        return POSITION_UI;
    } else if (delay == SensorManager.SENSOR_DELAY_GAME) {
        return POSITION_GAME;
    } else if (delay == SensorManager.SENSOR_DELAY_FASTEST) {
        return POSITION_FASTEST;
    } else {//from  w ww  . j  a  v  a2s .  co  m
        return POSITION_CUSTOM;
    }
}

From source file:org.jitsi.android.gui.call.ProximitySensorFragment.java

/**
 * {@inheritDoc}//  w  ww .  j av a 2s .  c o  m
 */
@Override
public void onResume() {
    super.onResume();

    SensorManager manager = JitsiApplication.getSensorManager();

    // Skips if the sensor has been already attached
    if (proximitySensor != null) {
        // Re-registers the listener as it might have been
        // unregistered in onPause()
        manager.registerListener(this, proximitySensor, SensorManager.SENSOR_DELAY_UI);
        return;
    }

    List<Sensor> sensors = manager.getSensorList(Sensor.TYPE_ALL);
    logger.trace("Device has " + sensors.size() + " sensors");
    for (Sensor s : sensors) {
        logger.trace("Sensor " + s.getName() + " type: " + s.getType());
    }

    this.proximitySensor = manager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
    if (proximitySensor == null) {
        return;
    }

    logger.info("Using proximity sensor: " + proximitySensor.getName());
    sensorDisabled = false;
    manager.registerListener(this, proximitySensor, SensorManager.SENSOR_DELAY_UI);
}

From source file:MyActivity.java

@Override
protected void onResume() {
    super.onResume();
    sensorManager.registerListener(sensorListener, magFieldSensor, SensorManager.SENSOR_DELAY_UI);
    sensorManager.registerListener(sensorListener, accelerometer, SensorManager.SENSOR_DELAY_UI);

    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
}

From source file:org.jitsi.android.gui.fragment.ProximitySensorFragment.java

/**
 * {@inheritDoc}/*from  w  w  w. j  a  v a  2 s  .c  o  m*/
 */
@Override
public void onResume() {
    super.onResume();

    // Skips if the sensor has been already attached
    if (proximitySensor != null)
        return;

    SensorManager manager = JitsiApplication.getSensorManager();

    List<Sensor> sensors = manager.getSensorList(Sensor.TYPE_ALL);
    logger.trace("Device has " + sensors.size() + " sensors");
    for (Sensor s : sensors) {
        logger.trace("Sensor " + s.getName() + " type: " + s.getType());
    }

    this.proximitySensor = manager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
    if (proximitySensor == null) {
        return;
    }

    logger.info("Using proximity sensor: " + proximitySensor.getName());
    sensorDisabled = false;
    manager.registerListener(this, proximitySensor, SensorManager.SENSOR_DELAY_UI);
}

From source file:com.nikhilnayak.games.octoshootar.beta.SensorDelayDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("Sensor Delay");

    final ArrayList<String> sensorDelayString = new ArrayList<String>();
    sensorDelayString.add("Delay Fastest");
    sensorDelayString.add("Delay Game");
    sensorDelayString.add("Delay Ui");
    sensorDelayString.add("Delay Normal");

    final ArrayList<Integer> sensorDelayInteger = new ArrayList<Integer>();
    sensorDelayInteger.add(SensorManager.SENSOR_DELAY_FASTEST);
    sensorDelayInteger.add(SensorManager.SENSOR_DELAY_GAME);
    sensorDelayInteger.add(SensorManager.SENSOR_DELAY_UI);
    sensorDelayInteger.add(SensorManager.SENSOR_DELAY_NORMAL);

    final SharedPreferences sharedPreferences = getActivity()
            .getSharedPreferences(BetaUtils.KEY_SHARED_PREFERENCES, Context.MODE_PRIVATE);
    final SharedPreferences.Editor sharedPreferencesEditor = sharedPreferences.edit();

    int currentSensorDelayIndex = sensorDelayInteger
            .indexOf(sharedPreferences.getInt(BetaUtils.KEY_SENSOR_DELAY, SensorManager.SENSOR_DELAY_GAME));

    builder.setSingleChoiceItems(sensorDelayString.toArray(new String[] {}), currentSensorDelayIndex,
            new DialogInterface.OnClickListener() {
                @Override//from ww  w  .j  ava2  s.  c  o m
                public void onClick(DialogInterface dialog, int which) {
                    sharedPreferencesEditor.putInt(BetaUtils.KEY_SENSOR_DELAY, sensorDelayInteger.get(which));
                }
            });

    builder.setPositiveButton(R.string.craft_dialog_fragment_ok_response,
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    sharedPreferencesEditor.commit();
                }
            });

    return builder.create();
}

From source file:com.polyvi.xface.extension.XAccelerometerExt.java

/**
 * ?accelerometer sensor//from  w  w  w .j a  va 2  s.  c  om
 */
private void start() {
    if ((mStatus == RUNNING) || (mStatus == STARTING)) {
        return;
    }

    mStatus = STARTING;
    if (null == mSensorManager) {
        mSensorManager = (SensorManager) getContext().getSystemService(Context.SENSOR_SERVICE);
    }

    List<Sensor> list = mSensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER);

    if ((list != null) && (list.size() > 0)) {
        mSensor = list.get(0);
        mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_UI);
    } else {
        mStatus = ERROR_FAILED_TO_START;
        mCallbackCtx.error("No sensors found to register accelerometer listening to.");
    }

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

From source file:com.sorin.cloudcog.phone.batterymeter.BatteryInfoActivity.java

@Override
public void onResume() {
    super.onResume();
    // Add the following line to register the Session Manager Listener
    // onResume/*from w ww  . j  ava  2s .com*/
    mSensorManager.registerListener(mShakeDetector, mAccelerometer, SensorManager.SENSOR_DELAY_UI);
}

From source file:com.example.android.networkconnect.BureauFragment.java

@Override
public void onResume() {
    super.onResume();
    mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_UI);
    mSensorManager.registerListener(this, mMagneticField, SensorManager.SENSOR_DELAY_UI);
}

From source file:edu.Groove9.TunesMaster.songplayer.SongPlayerFragment.java

@Override
public void onResume() {
    super.onResume();
    // Add the following line to register the Session Manager Listener onResume
    mSensorManager.registerListener(mShakeDetector, mAccelerometer, SensorManager.SENSOR_DELAY_UI);

    mPresenter.start();/*from w w w.j  av  a 2s  . c o  m*/
    mPresenter.updatePlayPauseIcon(audioPlayer);
}

From source file:de.uni_weimar.benike.misex3.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // register for accelerometer events:
    mSensorManager = (SensorManager) getApplicationContext().getSystemService(Context.SENSOR_SERVICE);
    for (Sensor sensor : mSensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER)) {
        if (sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
            mAccelerometerSensor = sensor;
        }//from  ww  w.  java  2  s  .  c o m
    }

    // if we can't access the accelerometer sensor then exit:
    if (mAccelerometerSensor == null) {
        Log.e(TAG, "Failed to attach to Accelerator Sensor.");
        Toast.makeText(this, "Error! Failed to create accelerometer sensor!", Toast.LENGTH_LONG).show();
        cleanup();
    }

    mSensorManager.registerListener(this, mAccelerometerSensor, SensorManager.SENSOR_DELAY_UI);

    // setup the Accelerometer History plot:
    mAccelerometerPlot = (XYPlot) findViewById(R.id.accelerometerPlot);
    mFftPlot = (XYPlot) findViewById(R.id.fftPlot);

    mAccelerometerPlot.setRangeBoundaries(-25, 25, BoundaryMode.FIXED);
    mAccelerometerPlot.setDomainBoundaries(0, mWindowSize - 1, BoundaryMode.FIXED);

    mFftPlot.setRangeBoundaries(0, 250, BoundaryMode.FIXED);
    mFftPlot.setDomainBoundaries(0, mWindowSize / 2, BoundaryMode.AUTO);
    mFftPlot.setDomainStep(XYStepMode.SUBDIVIDE, 10);
    //mFftPlot.setRangeStep(XYStepMode.INCREMENT_BY_VAL, 50);

    mAccelerometerXSeries = new SimpleXYSeries("X");
    mAccelerometerXSeries.useImplicitXVals();
    mAccelerometerYSeries = new SimpleXYSeries("Y");
    mAccelerometerYSeries.useImplicitXVals();
    mAccelerometerZSeries = new SimpleXYSeries("Z");
    mAccelerometerZSeries.useImplicitXVals();
    mAccelerometerMSeries = new SimpleXYSeries("magnitude");
    mAccelerometerMSeries.useImplicitXVals();

    mFftSeries = new SimpleXYSeries("FFT");
    mFftSeries.useImplicitXVals();

    mFftPlot.addSeries(mFftSeries, new LineAndPointFormatter(Color.rgb(0, 0, 0), null, null, null));

    mAccelerometerPlot.addSeries(mAccelerometerXSeries,
            new LineAndPointFormatter(Color.rgb(100, 100, 200), null, null, null));
    mAccelerometerPlot.addSeries(mAccelerometerYSeries,
            new LineAndPointFormatter(Color.rgb(100, 200, 100), null, null, null));
    mAccelerometerPlot.addSeries(mAccelerometerZSeries,
            new LineAndPointFormatter(Color.rgb(200, 100, 100), null, null, null));
    mAccelerometerPlot.addSeries(mAccelerometerMSeries,
            new LineAndPointFormatter(Color.rgb(0, 0, 0), null, null, null));
    mAccelerometerPlot.setDomainStepValue(5);
    mAccelerometerPlot.setTicksPerRangeLabel(3);
    mAccelerometerPlot.setDomainLabel("Sample Index");
    mAccelerometerPlot.getDomainLabelWidget().pack();
    mAccelerometerPlot.setRangeLabel("m/s^2");
    mAccelerometerPlot.getRangeLabelWidget().pack();

    final PlotStatistics histStats = new PlotStatistics(1000, false);
    mAccelerometerPlot.addListener(histStats);

    // perform hardware accelerated rendering of the plots
    mAccelerometerPlot.setLayerType(View.LAYER_TYPE_NONE, null);
    mFftPlot.setLayerType(View.LAYER_TYPE_NONE, null);

    mFftPlot.setTicksPerRangeLabel(5);
    mFftPlot.setTicksPerDomainLabel(1);

    mSampleRateSeekBar = (SeekBar) findViewById(R.id.sampleRateSeekBar);
    mSampleRateSeekBar.setMax((SAMPLE_MAX_VALUE - SAMPLE_MIN_VALUE) / SAMPLE_STEP);
    mSampleRateSeekBar.setOnSeekBarChangeListener(this);

    mFftWindowSeekBar = (SeekBar) findViewById(R.id.fftWindowSeekBar);
    mFftWindowSeekBar.setMax((WINDOW_MAX_VALUE - WINDOW_MIN_VALUE) / WINDOW_STEP);
    mFftWindowSeekBar.setOnSeekBarChangeListener(this);

    mWindowSizeTextView = (TextView) findViewById(R.id.windowSizeTextView);

    // Perform FFT calculations in background thread
    mFft = new FFT(mWindowSize);
    Runnable r = new PerformFft();
    mFftThread = new Thread(r);
    mFftThread.start();

    mNotificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_help_outline_black_24dp).setContentTitle("MIS Ex3 Activity Recognizer")
            .setContentText("Trying to guess your activity").setOngoing(true);

    Intent resultIntent = new Intent(this, MainActivity.class);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mNotificationBuilder.setContentIntent(resultPendingIntent);

    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(mNotificationId, mNotificationBuilder.build());

    Runnable detectActivity = new DetectActivity();
    mDetectActivityThread = new Thread(detectActivity);
    mDetectActivityThread.start();
}