Example usage for android.hardware Sensor TYPE_GRAVITY

List of usage examples for android.hardware Sensor TYPE_GRAVITY

Introduction

In this page you can find the example usage for android.hardware Sensor TYPE_GRAVITY.

Prototype

int TYPE_GRAVITY

To view the source code for android.hardware Sensor TYPE_GRAVITY.

Click Source Link

Document

A constant describing a gravity sensor type.

Usage

From source file:io.authme.sdk.widget.LockPatternView.java

@Override
public void onSensorChanged(SensorEvent event) {
    if (collectSensor) {
        Sensor sensor = event.sensor;/*from   ww w .  j a  v a2  s.co m*/
        if (sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
            mGravity = event.values;
            Accelerometer sensordata = new Accelerometer(mGravity[0], mGravity[1], mGravity[2],
                    event.timestamp);
            accelList.add(sensordata);
        }

        if (sensor.getType() == Sensor.TYPE_GRAVITY) {
            mGravity = event.values;
            Accelerometer sensordata = new Accelerometer(mGravity[0], mGravity[1], mGravity[2],
                    event.timestamp);
            accelList.add(sensordata);
        }

        if (sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
            mGeomagnetic = event.values;
            Magnetic magnetic = new Magnetic(mGeomagnetic[0], mGeomagnetic[1], mGeomagnetic[2],
                    event.timestamp);
            magnetics.add(magnetic);
        }

        if (sensor.getType() == Sensor.TYPE_GYROSCOPE) {
            float x = event.values[0];
            float y = event.values[1];
            float z = event.values[2];
            Gyroscope gyro = new Gyroscope(x, y, z, event.timestamp);
            gyrolist.add(gyro);
        }

        if (mGravity != null && mGeomagnetic != null) {
            float R[] = new float[9];
            float I[] = new float[9];

            boolean success = SensorManager.getRotationMatrix(R, I, mGravity, mGeomagnetic);
            if (success) {
                float orientation[] = new float[3];
                SensorManager.getOrientation(R, orientation);
                Orientation orientationObj = new Orientation(orientation[0], orientation[1], orientation[2],
                        event.timestamp);
                orientationArrayList.add(orientationObj);
            }
        }

    }

}

From source file:com.kircherelectronics.fusedgyroscopeexplorer.sensor.GravitySensor.java

/**
 * Register for Sensor.TYPE_GRAVITY measurements.
 * //from   w w w .  j  ava  2  s  .c o  m
 * @param observer
 *            The observer to be registered.
 */
public void registerGravityObserver(GravitySensorObserver observer) {
    // If there are currently no observers, but one has just requested to be
    // registered, register to listen for sensor events from the device.
    if (observersAcceleration.size() == 0) {
        sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY),
                SensorManager.SENSOR_DELAY_FASTEST);
    }

    // Only register the observer if it is not already registered.
    int i = observersAcceleration.indexOf(observer);
    if (i == -1) {
        observersAcceleration.add(observer);
    }
}

From source file:it.unime.mobility4ckan.MySensor.java

public void registerSensor(Sensor mSensor) {
    LocationListener locationListener = new LocationListener() {
        @Override/*from w  w w.ja  v  a 2 s . c o m*/
        public void onLocationChanged(Location location) {
            //latitude = location.getLatitude();
            //longitude = location.getLongitude();
            currentSpeed = location.getSpeed();
            //locationText.setText(String.valueOf(latitude)+ "  " +String.valueOf(longitude)+ "  " +String.valueOf(speed));
            //isGPSReady = true;
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
            //
        }

        @Override
        public void onProviderEnabled(String provider) {
            //
        }

        @Override
        public void onProviderDisabled(String provider) {
            //
        }
    };

    SensorEventListener sensorListener = new SensorEventListener() {
        @Override
        public void onSensorChanged(SensorEvent event) {

            switch (event.sensor.getType()) {
            case Sensor.TYPE_AMBIENT_TEMPERATURE: // Gradi Celsius (C)
                currentTemp = event.values[0];
                break;

            case Sensor.TYPE_PRESSURE:
                currentPressure = event.values[0]; // hPa o mbar
                break;

            case Sensor.TYPE_LIGHT: // lx
                currentLight = event.values[0];
                break;

            case Sensor.TYPE_ACCELEROMETER: // m/s2
                currentAcceleration[0] = event.values[0];
                currentAcceleration[1] = event.values[1];
                currentAcceleration[2] = event.values[2];
                break;

            case Sensor.TYPE_GYROSCOPE: // rad/s
                currentGyroscope[0] = event.values[0];
                currentGyroscope[1] = event.values[1];
                currentGyroscope[2] = event.values[2];
                break;

            case Sensor.TYPE_MAGNETIC_FIELD: // T
                currentMagnetic[0] = event.values[0];
                currentMagnetic[1] = event.values[1];
                currentMagnetic[2] = event.values[2];
                break;

            case Sensor.TYPE_PROXIMITY: // cm
                currentProximity = event.values[0];
                break;

            case Sensor.TYPE_ROTATION_VECTOR: // unita di misura sconosciuta
                currentRotation[0] = event.values[0];
                currentRotation[1] = event.values[1];
                currentRotation[2] = event.values[2];
                break;

            case Sensor.TYPE_GRAVITY: // m/s2
                currentGravity[0] = event.values[0];
                currentGravity[1] = event.values[1];
                currentGravity[2] = event.values[2];
                break;

            case Sensor.TYPE_LINEAR_ACCELERATION: // m/s2
                currentLinearAcceleration[0] = event.values[0];
                currentLinearAcceleration[1] = event.values[1];
                currentLinearAcceleration[2] = event.values[2];
                break;

            case Sensor.TYPE_RELATIVE_HUMIDITY: // %
                currentHumidity = event.values[0];
                break;

            default:
                break;
            }

        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {

        }
    };

    //sensorManager.registerListener(locationListener, mSensor, LocationManager.GPS_PROVIDER);
    /*        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
    // TODO: Consider calling
    //    ActivityCompat#requestPermissions
    // here to request the missing permissions, and then overriding
    //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
    //                                          int[] grantResults)
    // to handle the case where the user grants the permission. See the documentation
    // for ActivityCompat#requestPermissions for more details.
    return;
            }*/
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
    sensorManager.registerListener(sensorListener, mSensor, SensorManager.SENSOR_DELAY_FASTEST);
}

From source file:nl.atcomputing.spacetravelagency.activities.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);//from  w w w  . j a v a 2  s  .  co m

    setupDatastructures();

    if (savedInstanceState != null) {
        this.planetInfo = savedInstanceState.getString(BUNDLE_KEY_PLANETINFO);
    }

    this.layoutTag = (String) findViewById(R.id.main_layout).getTag();
    if (this.layoutTag == null) {
        this.layoutTag = "";
    }
    setupFragments();

    addTabs();
    if (savedInstanceState != null) {
        this.selectedTabName = savedInstanceState.getString(BUNDLE_KEY_SELECTEDTAB);
        selectTab(this.selectedTabName);
    }

    DepartureInfoService.cancelDepartureInfoServiceAlarm(this);
    DepartureInfoService.setupDepartureInfoServiceAlarm(this);

    Button b = (Button) findViewById(R.id.button);
    b.setOnClickListener(this);

    this.sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    this.sensor = this.sensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);

    if (this.layoutTag.contentEquals(TAG_PORTRAIT)) {
        /**
         * In portrait mode we show planet info if state is showing planet info
         * or checkout if state is checking out.
         * We assume that user rotated device to read the information fullscreen
         */
        if (StateSingleton.getInstance().isShowingPlanetInfo()) {
            showPlanetInfo();
        } else if (StateSingleton.getInstance().isCheckingOut()) {
            showCheckout();
        }
    } else {
        //In landscape mode we always show destinations list
        //in onResume we determine what to show next to the destinations list
        showDestinations();
    }
}

From source file:com.wordpress.tonytam.avatar.AvatarWearActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.jj_layout);/* www  . ja va2s. c o m*/
    setupViews();
    mHandler = new Handler();
    mJumpCounter = Utils.getCounterFromPreference(this);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    renewTimer();
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);
    mSensorAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);

    mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this).addApi(Wearable.API).build();
}

From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.InternalSensorService.java

@Override
public void onCreate() {
    // The service is being created
    Log.e(TAG, "onCreate");

    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    pref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

    if (pref.getBoolean(getResources().getString(R.string.in_acc), false)) {
        Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
        mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }/*from  w w w  .  j a  va 2  s.  c  om*/
    if (pref.getBoolean(getResources().getString(R.string.in_lig), false)) {
        Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
        mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }
    if (pref.getBoolean(getResources().getString(R.string.in_pres), false)) {
        Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE);
        mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }
    if (pref.getBoolean(getResources().getString(R.string.in_prox), false)) {
        Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
        mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }
    if (pref.getBoolean(getResources().getString(R.string.in_mag), false)) {
        Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
        mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }
    if (pref.getBoolean(getResources().getString(R.string.in_gyrs), false)) {
        Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
        mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }
    if (pref.getBoolean(getResources().getString(R.string.in_grav), false)) {
        Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);
        mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }
    if (pref.getBoolean(getResources().getString(R.string.in_hum), false)) {
        Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_RELATIVE_HUMIDITY);
        mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }
    if (pref.getBoolean(getResources().getString(R.string.in_lin_acc), false)) {
        Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION);
        mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }
    if (pref.getBoolean(getResources().getString(R.string.in_tem), false)) {
        Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE);
        mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }

}

From source file:com.kircherelectronics.fusedgyroscopeexplorer.sensor.GravitySensor.java

@Override
public void onSensorChanged(SensorEvent event) {
    if (event.sensor.getType() == Sensor.TYPE_GRAVITY) {
        System.arraycopy(event.values, 0, gravity, 0, event.values.length);

        timeStamp = event.timestamp;/* w w w  .j  ava  2  s  .c om*/

        if (vehicleMode) {
            gravity = quaternionToDeviceVehicleMode(gravity);
        }

        notifyGravityObserver();
    }
}

From source file:foam.starwisp.StarwispActivity.java

protected void DeclareSensors() {
    String str = "";
    str += "(define sensor-accelerometer " + Sensor.TYPE_ACCELEROMETER + ")";
    str += "(define sensor-ambient-temperature " + Sensor.TYPE_AMBIENT_TEMPERATURE + ")";
    str += "(define sensor-game-rotation-vector " + Sensor.TYPE_GAME_ROTATION_VECTOR + ")";
    str += "(define sensor-geomagnetic-rotation-vector " + Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR + ")";
    str += "(define sensor-gravity " + Sensor.TYPE_GRAVITY + ")";
    str += "(define sensor-gyroscope " + Sensor.TYPE_GYROSCOPE + ")";
    str += "(define sensor-gyroscope-uncalibrated " + Sensor.TYPE_GYROSCOPE_UNCALIBRATED + ")";
    str += "(define sensor-heart-rate " + Sensor.TYPE_HEART_RATE + ")";
    str += "(define sensor-light " + Sensor.TYPE_LIGHT + ")";
    str += "(define sensor-linear-acceleration " + Sensor.TYPE_LINEAR_ACCELERATION + ")";
    str += "(define sensor-magnetic-field " + Sensor.TYPE_MAGNETIC_FIELD + ")";
    str += "(define sensor-magnetic-field-uncalibrated " + Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED + ")";
    str += "(define sensor-orientation " + Sensor.TYPE_ORIENTATION + ")";
    str += "(define sensor-pressure " + Sensor.TYPE_PRESSURE + ")";
    str += "(define sensor-proximity " + Sensor.TYPE_PROXIMITY + ")";
    str += "(define sensor-relative-humidity " + Sensor.TYPE_RELATIVE_HUMIDITY + ")";
    str += "(define sensor-rotation-vector " + Sensor.TYPE_ROTATION_VECTOR + ")";
    str += "(define sensor-significant-motion " + Sensor.TYPE_SIGNIFICANT_MOTION + ")";
    str += "(define sensor-step-counter " + Sensor.TYPE_STEP_COUNTER + ")";
    str += "(define sensor-step-detector " + Sensor.TYPE_STEP_DETECTOR + ")";
    m_Scheme.eval(str);//from   w  w  w  . j ava2 s  . co  m
}

From source file:com.example.android.camera2video.CameraActivity.java

@Override
public void onSensorChanged(SensorEvent event) {
    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        logText("ACCELEROMETER," + event.values[0] + "," + event.values[1] + "," + event.values[2]);
        mAccVal = event.values;/*from  w  ww .  j  a v  a 2s  . c o  m*/
    } else if (event.sensor.getType() == Sensor.TYPE_GRAVITY) {
        logText("GRAVITY," + event.values[0] + "," + event.values[1] + "," + event.values[2]);
    } else if (event.sensor.getType() == Sensor.TYPE_LINEAR_ACCELERATION) {
        logText("LINEAR_ACCELERATION," + event.values[0] + "," + event.values[1] + "," + event.values[2]);
    } else if (event.sensor.getType() == Sensor.TYPE_GYROSCOPE) {
        logText("GYROSCOPE," + event.values[0] + "," + event.values[1] + "," + event.values[2]);
    } else if (event.sensor.getType() == Sensor.TYPE_GYROSCOPE_UNCALIBRATED) {
        logText("GYROSCOPE_UNCALIBRATED," + event.values[0] + "," + event.values[1] + "," + event.values[2]
                + "," + event.values[3] + "," + event.values[4] + "," + event.values[5]);
    } else if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
        logText("MAGNETIC_FIELD," + event.values[0] + "," + event.values[1] + "," + event.values[2]);
        mMagVal = event.values;
        if (mAccVal != null) {
            float R[] = new float[9];
            float I[] = new float[9];
            boolean success = SensorManager.getRotationMatrix(R, I, mAccVal, mMagVal);
            if (success) {
                float orientation[] = new float[3];
                SensorManager.getOrientation(R, orientation);
                logText("ORIENTATION," + orientation[0] + "," + orientation[1] + "," + orientation[2]); //azimuth, pitch and roll
            }
        }
    }
}

From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.fragments.GraphPlotFragment.java

private void updateTitleAndType() {

    ArrayList<String> grpTitle = new ArrayList<String>();
    ArrayList<Integer> grpType = new ArrayList<Integer>();
    ArrayList<Boolean> grpBarType = new ArrayList<Boolean>();

    SharedPreferences pref = PreferenceManager
            .getDefaultSharedPreferences(getActivity().getApplicationContext());

    if (pref.getBoolean(getResources().getString(R.string.in_hum), false)) {
        grpTitle.add("Humidity");
        grpType.add(Sensor.TYPE_RELATIVE_HUMIDITY);
        grpBarType.add(false);//from www  .  j  av  a2  s.com

    }
    if (pref.getBoolean(getResources().getString(R.string.in_lig), false)) {
        grpTitle.add("Light in lux/min");
        grpType.add(Sensor.TYPE_LIGHT);
        grpBarType.add(false);

    }
    if (pref.getBoolean(getResources().getString(R.string.in_pres), false)) {
        grpTitle.add("Pressure in min");
        grpType.add(Sensor.TYPE_PRESSURE);
        grpBarType.add(false);

    }
    if (pref.getBoolean(getResources().getString(R.string.in_prox), false)) {
        grpTitle.add("Proximity in min");
        grpType.add(Sensor.TYPE_PROXIMITY);
        grpBarType.add(false);

    }
    if (pref.getBoolean(getResources().getString(R.string.in_tem), false)) {
        grpTitle.add("Ambient Temperature in C");
        grpType.add(Sensor.TYPE_AMBIENT_TEMPERATURE);
        grpBarType.add(false);

    }
    if (pref.getBoolean(getResources().getString(R.string.pulse), false)) {
        grpTitle.add("Heart Rate bpm");
        grpType.add(999);
        grpBarType.add(false);

    }
    if (pref.getBoolean(getResources().getString(R.string.in_acc), false)) {
        grpTitle.add("Motion Strength/min");
        grpType.add(Sensor.TYPE_ACCELEROMETER);
        grpBarType.add(true);

    }
    if (pref.getBoolean(getResources().getString(R.string.in_mag), false)) {
        grpTitle.add("Magnetic Field Strength/min");
        grpType.add(Sensor.TYPE_MAGNETIC_FIELD);
        grpBarType.add(true);

    }
    if (pref.getBoolean(getResources().getString(R.string.in_grav), false)) {
        grpTitle.add("Gravity Strength/min");
        grpType.add(Sensor.TYPE_GRAVITY);
        grpBarType.add(true);

    }

    if (pref.getBoolean(getResources().getString(R.string.in_gyrs), false)) {
        grpTitle.add("Gyroscope Strength/min");
        grpType.add(Sensor.TYPE_GYROSCOPE);
        grpBarType.add(true);

    }
    if (pref.getBoolean(getResources().getString(R.string.in_lin_acc), false)) {
        grpTitle.add("Linear Accelerometer Strength/min");
        grpType.add(Sensor.TYPE_LINEAR_ACCELERATION);
        grpBarType.add(true);

    }
    if (grpTitle.size() == 2 && grpType.size() == 2) {
        firstGrpTitle = grpTitle.get(0);
        firstGrpType = grpType.get(0);
        isFirstBar = grpBarType.get(0);

        secondGrpTitle = grpTitle.get(1);
        secondGrpType = grpType.get(1);
        isSecondBar = grpBarType.get(1);
    } else if (grpTitle.size() == 1 && grpType.size() == 1) {
        firstGrpTitle = grpTitle.get(0);
        firstGrpType = grpType.get(0);
        isFirstBar = grpBarType.get(0);

        secondGrpTitle = "";
        secondGrpType = -1;
    }
}