Example usage for android.hardware SensorManager SENSOR_DELAY_GAME

List of usage examples for android.hardware SensorManager SENSOR_DELAY_GAME

Introduction

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

Prototype

int SENSOR_DELAY_GAME

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

Click Source Link

Document

rate suitable for games

Usage

From source file:com.example.nate.cloudcar.MainActivity.java

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

From source file:com.pseudosurface.levels.template.SimulatorActivity.java

@Override
protected void onResume() {
    super.onResume();
    // 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();//  w w w. ja v a 2  s  .  c o  m
    sensorManager.registerListener(this, gravitySensor, SensorManager.SENSOR_DELAY_GAME);
}

From source file:com.metinkale.prayerapp.compass.Main.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (mRefresh == item) {
        mOnlyNew = true;//from   w ww . ja v  a2s  .c o  m
        if (PermissionUtils.get(this).pLocation) {
            LocationManager locMan = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

            locMan.removeUpdates(this);
            List<String> providers = locMan.getProviders(true);
            for (String provider : providers) {
                locMan.requestLocationUpdates(provider, 0, 0, this);
            }
        }
    } else if (mSwitch == item) {
        if (mMode == Mode.Map) {
            mSensorManager.registerListener(mMagAccel,
                    mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
                    SensorManager.SENSOR_DELAY_GAME);
            mSensorManager.registerListener(mMagAccel,
                    mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
                    SensorManager.SENSOR_DELAY_GAME);

            updateFrag(Mode.TwoDim);

            mSwitch.setIcon(MaterialDrawableBuilder.with(this).setIcon(MaterialDrawableBuilder.IconValue.MAP)
                    .setColor(Color.WHITE).setToActionbarSize().build());
        } else if (PermissionUtils.get(this).pLocation) {
            mSensorManager.unregisterListener(mMagAccel);
            updateFrag(Mode.Map);
            mSwitch.setIcon(MaterialDrawableBuilder.with(this)
                    .setIcon(MaterialDrawableBuilder.IconValue.COMPASS_OUTLINE).setColor(Color.WHITE)
                    .setToActionbarSize().build());
        } else {
            Toast.makeText(this, R.string.permissionNotGranted, Toast.LENGTH_LONG).show();
        }
    }

    return super.onOptionsItemSelected(item);
}

From source file:se.toxbee.sleepfighter.challenge.shake.ShakeChallenge.java

@Override
public void onResume() {
    this.sensorManager.registerListener(this.sensorEventListener, accelerometer,
            SensorManager.SENSOR_DELAY_GAME);
}

From source file:com.cubic9.android.droidglove.Main.java

@Override
public void onResume() {
    super.onResume();

    // show IP address
    mTextViewIp.setText("IP: " + getIPAddress());

    // prevent sleep
    mWakeLock.acquire();/*  ww  w.ja v a2s .com*/

    // get values of sensors
    mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
            SensorManager.SENSOR_DELAY_GAME);
    mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
            SensorManager.SENSOR_DELAY_GAME);

    // get network information
    InetAddress mRemoteIP = null;
    try {
        mRemoteIP = InetAddress.getByName(ip);
    } catch (UnknownHostException e) {
        new AlertDialog.Builder(Main.this).setIcon(android.R.drawable.ic_dialog_alert)
                .setTitle(getString(R.string.dialog_error_title))
                .setMessage(getString(R.string.dialog_error_get_ip))
                .setPositiveButton(R.string.dialog_error_ok, null).create().show();
        e.printStackTrace();
    }

    // Bring the IP Address and port together to form our OSC Sender
    try {
        mSender = new OSCPortOut(mRemoteIP, OSCPort.defaultSCOSCPort());
    } catch (SocketException e) {
        new AlertDialog.Builder(Main.this).setIcon(android.R.drawable.ic_dialog_alert)
                .setTitle(getString(R.string.dialog_error_title))
                .setMessage(getString(R.string.dialog_error_sender))
                .setPositiveButton(R.string.dialog_error_ok, null).create().show();
        e.printStackTrace();
    }

    try {
        mReceiver = new OSCPortIn(OSCPort.defaultSCOSCPort());
    } catch (SocketException e) {
        new AlertDialog.Builder(Main.this).setIcon(android.R.drawable.ic_dialog_alert)
                .setTitle(getString(R.string.dialog_error_title))
                .setMessage(getString(R.string.dialog_error_receiver))
                .setPositiveButton(R.string.dialog_error_ok, null).create().show();
        e.printStackTrace();
    }
    OSCListener listener = new OSCListener() {
        public void acceptMessage(java.util.Date time, OSCMessage message) {
            Object[] args = message.getArguments();
            int vibrationTime = (Integer) args[0];
            if (vibrationTime == 0) {
                mVibrator.vibrate(userVibrationTime);
            } else {
                mVibrator.vibrate(vibrationTime);
            }
        }
    };
    mReceiver.addListener(OSC_ADDRESS_TO_PHONE, listener);
    mReceiver.startListening();
}

From source file:com.metinkale.prayerapp.compass.Main.java

@Override
protected void onResume() {
    super.onResume();
    mSensorManager.unregisterListener(mMagAccel);

    mSensorManager.registerListener(mMagAccel, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
            SensorManager.SENSOR_DELAY_GAME);
    mSensorManager.registerListener(mMagAccel, mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
            SensorManager.SENSOR_DELAY_GAME);

    if (mSelCity == null) {
        mSelCity = (TextView) findViewById(R.id.selcity);
        mSelCity.setOnClickListener(new OnClickListener() {
            @Override//from w w w. ja  v a2  s  .  co m
            public void onClick(View arg0) {
                if (App.isOnline()) {
                    startActivity(new Intent(Main.this, LocationPicker.class));
                } else {
                    Toast.makeText(Main.this, R.string.noConnection, Toast.LENGTH_LONG).show();
                }
            }
        });
    }

    if (PermissionUtils.get(this).pLocation) {
        LocationManager locMan = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

        List<String> providers = locMan.getProviders(true);
        for (String provider : providers) {
            locMan.requestLocationUpdates(provider, 0, 0, this);
            Location lastKnownLocation = locMan.getLastKnownLocation(provider);
            if (lastKnownLocation != null) {
                calcQiblaAngel(lastKnownLocation);
            }
        }
    }

    if (Prefs.getCompassLat() != 0) {
        Location loc = new Location("custom");
        loc.setLatitude(Prefs.getCompassLat());
        loc.setLongitude(Prefs.getCompassLng());
        calcQiblaAngel(loc);
    }
}

From source file:com.mhennessy.mapfly.MainActivity.java

@Override
protected void onResume() {
    super.onResume();
    mSensorManager.registerListener(this, mOrientationSensor, SensorManager.SENSOR_DELAY_NORMAL);
    mSensorManager.registerListener(this, mAccelerationSensor, SensorManager.SENSOR_DELAY_GAME);
}

From source file:com.inloc.dr.StepService.java

private void registerDetector() {
    mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER /*| 
                                                                        Sensor.TYPE_MAGNETIC_FIELD | 
                                                                        Sensor.TYPE_ORIENTATION*/);
    mSensorManager.registerListener(mStepDetector, mSensor, SensorManager.SENSOR_DELAY_FASTEST);
    mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
    mSensorManager.registerListener(mTurnDetector, mSensor, SensorManager.SENSOR_DELAY_GAME);
}

From source file:com.shadowmaps.example.GpsTestActivity.java

@Override
protected void onResume() {
    super.onResume();

    SharedPreferences settings = Application.getPrefs();
    if (GpsTestUtil.isRotationVectorSensorSupported(this)) {
        // Use the modern rotation vector sensors
        Sensor vectorSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
        mSensorManager.registerListener(this, vectorSensor, 16000); // ~60hz
    } else {/*  ww w .  j a v  a  2  s  .com*/
        // Use the legacy orientation sensors
        Sensor sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
        if (sensor != null) {
            mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME);
        }
    }

    if (!mService.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        promptEnableGps();
    }

    /**
     * Check preferences to see how they should be initialized
     */
    checkKeepScreenOn(settings);

    checkTimeAndDistance(settings);

    checkTrueNorth(settings);
}

From source file:com.sinelead.car.club.map.AMapEx.java

public void setRotateWithSensor(boolean enabled) {
    if (mOrientationSensor == null)
        return;/*  w  w  w .j  ava 2  s.  co  m*/
    if (enabled) {
        mSensorManager.registerListener(mSensorEventListener, mOrientationSensor,
                SensorManager.SENSOR_DELAY_GAME);
    } else {
        mSensorManager.unregisterListener(mSensorEventListener);
    }
}