List of usage examples for android.hardware Sensor TYPE_ACCELEROMETER
int TYPE_ACCELEROMETER
To view the source code for android.hardware Sensor TYPE_ACCELEROMETER.
Click Source Link
From source file:io.authme.sdk.widget.LockPatternView.java
@Override public void onSensorChanged(SensorEvent event) { if (collectSensor) { Sensor sensor = event.sensor;// w w w .j a v a 2 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.example.appf.CS3570.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent();/*from w w w . j ava 2 s . co m*/ Bundle extras = intent.getExtras(); cam = false; // Just in case we are coming from the ServerActivity if (extras != null) { if (extras.containsKey("server_name")) SERVER_IP = extras.getString("server_name"); if (extras.containsKey("server_port")) SERVERPORT = Integer.parseInt(extras.getString("server_port")); } filter = new IMUfilter(.1f, 5); filter.reset(); // Set up reset button Button b = new Button(this); b.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { filter.reset(); } }); b.setText("Reset"); // Set up camera mode. Are we going to use this? Button c = new Button(this); c.setText("Camera Mode"); c.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { filter.reset(); mGLView.mRenderer.mCamera = new Camera(); cam = !cam; } }); LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.VERTICAL); ll.setBackgroundColor(Color.parseColor("#21C9FF")); ll.addView(b); ll.addView(c); // Create a GLSurfaceView instance and set it // as the ContentView for this Activity mGLView = new MyGLSurfaceView(this, this); ll.addView(mGLView); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); gyroscope = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); accelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); magnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); setContentView(ll); new Thread(new SocketThread()).start(); }
From source file:edu.cmu.android.restaurant.MapFragment.java
@Override public void onResume() { super.onResume(); sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); mLocalActivityManager.dispatchResume(); }
From source file:io.github.data4all.service.OrientationListener.java
@Override public void onSensorChanged(SensorEvent event) { // check sensor type if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { // smoothing sensor data mGravity = smoothing.filter(event.values.clone(), mGravity); System.arraycopy(event.values, 0, mGravity, 0, ARRAYLENGTH); } else if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { // smooting sensor data mGeomagnetic = smoothing.filter(event.values.clone(), mGeomagnetic); System.arraycopy(event.values, 0, mGeomagnetic, 0, ARRAYLENGTH); }/* ww w . j a v a 2s .c o m*/ // when the 2 sensors data are available if (mGravity != null && mGeomagnetic != null) { final boolean success = SensorManager.getRotationMatrix(mR, mI, mGravity, mGeomagnetic); if (success) { SensorManager.getOrientation(mR, orientation); if (event.accuracy >= 1) { // saving the new model with the orientation in the // RingBuffer deviceOrientation = new DeviceOrientation(orientation[0], orientation[1], orientation[LAST_INDEX], System.currentTimeMillis()); Optimizer.putDevOrient(deviceOrientation); if (horizonListener != null) { horizonListener.makeHorizon(true); } } } } }
From source file:org.apache.cordova.AccelListener.java
/** * Start listening for acceleration sensor. * //from w ww. j ava 2 s. c o 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. * //from www .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:devbox.com.br.minercompanion.ProfileActivity.java
@Override protected void onResume() { super.onResume(); sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), sensorManager.SENSOR_DELAY_GAME); sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION), sensorManager.SENSOR_DELAY_GAME); sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE), sensorManager.SENSOR_DELAY_NORMAL); sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT), sensorManager.SENSOR_DELAY_NORMAL); }
From source file:com.kircherelectronics.gyroscopeexplorer.activity.GyroscopeActivity.java
public void onResume() { super.onResume(); requestPermissions();/*from w ww. j a v a2 s . c om*/ readPrefs(); reset(); sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_FASTEST); // Register for sensor updates. sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), SensorManager.SENSOR_DELAY_FASTEST); // Register for sensor updates. sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE), SensorManager.SENSOR_DELAY_FASTEST); handler.post(runable); }
From source file:org.apache.cordova.core.AccelListener.java
/** * Start listening for acceleration sensor. * //from w w w .j a v a 2 s .c o 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. stopTimeout(); mainHandler = new Handler(Looper.getMainLooper()); mainHandler.postDelayed(mainRunnable, 2000); return this.status; }
From source file:com.vonglasow.michael.satstat.SensorSectionFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mainActivity = (MainActivity) this.getContext(); View rootView = inflater.inflate(R.layout.fragment_main_sensors, container, false); Sensor mAccSensor = mainActivity.sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); Sensor mGyroSensor = mainActivity.sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); Sensor mMagSensor = mainActivity.sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); Sensor mLightSensor = mainActivity.sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); Sensor mProximitySensor = mainActivity.sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); Sensor mPressureSensor = mainActivity.sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE); Sensor mHumiditySensor = mainActivity.sensorManager.getDefaultSensor(Sensor.TYPE_RELATIVE_HUMIDITY); Sensor mTempSensor = mainActivity.sensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE); mAccSensorRes = getSensorDecimals(mAccSensor, mAccSensorRes); mGyroSensorRes = getSensorDecimals(mGyroSensor, mGyroSensorRes); mMagSensorRes = getSensorDecimals(mMagSensor, mMagSensorRes); mLightSensorRes = getSensorDecimals(mLightSensor, mLightSensorRes); mProximitySensorRes = getSensorDecimals(mProximitySensor, mProximitySensorRes); mPressureSensorRes = getSensorDecimals(mPressureSensor, mPressureSensorRes); mHumiditySensorRes = getSensorDecimals(mHumiditySensor, mHumiditySensorRes); mTempSensorRes = getSensorDecimals(mTempSensor, mTempSensorRes); // Initialize controls accStatus = (TextView) rootView.findViewById(R.id.accStatus); accHeader = (TextView) rootView.findViewById(R.id.accHeader); accX = (TextView) rootView.findViewById(R.id.accX); accY = (TextView) rootView.findViewById(R.id.accY); accZ = (TextView) rootView.findViewById(R.id.accZ); accTotal = (TextView) rootView.findViewById(R.id.accTotal); rotStatus = (TextView) rootView.findViewById(R.id.rotStatus); rotHeader = (TextView) rootView.findViewById(R.id.rotHeader); rotX = (TextView) rootView.findViewById(R.id.rotX); rotY = (TextView) rootView.findViewById(R.id.rotY); rotZ = (TextView) rootView.findViewById(R.id.rotZ); rotTotal = (TextView) rootView.findViewById(R.id.rotTotal); magStatus = (TextView) rootView.findViewById(R.id.magStatus); magHeader = (TextView) rootView.findViewById(R.id.magHeader); magX = (TextView) rootView.findViewById(R.id.magX); magY = (TextView) rootView.findViewById(R.id.magY); magZ = (TextView) rootView.findViewById(R.id.magZ); magTotal = (TextView) rootView.findViewById(R.id.magTotal); orStatus = (TextView) rootView.findViewById(R.id.orStatus); orHeader = (TextView) rootView.findViewById(R.id.orHeader); orAzimuth = (TextView) rootView.findViewById(R.id.orAzimuth); orAziText = (TextView) rootView.findViewById(R.id.orAziText); orPitch = (TextView) rootView.findViewById(R.id.orPitch); orRoll = (TextView) rootView.findViewById(R.id.orRoll); miscHeader = (TextView) rootView.findViewById(R.id.miscHeader); tempStatus = (TextView) rootView.findViewById(R.id.tempStatus); tempHeader = (TextView) rootView.findViewById(R.id.tempHeader); metTemp = (TextView) rootView.findViewById(R.id.metTemp); pressureStatus = (TextView) rootView.findViewById(R.id.pressureStatus); pressureHeader = (TextView) rootView.findViewById(R.id.pressureHeader); metPressure = (TextView) rootView.findViewById(R.id.metPressure); humidStatus = (TextView) rootView.findViewById(R.id.humidStatus); humidHeader = (TextView) rootView.findViewById(R.id.humidHeader); metHumid = (TextView) rootView.findViewById(R.id.metHumid); lightStatus = (TextView) rootView.findViewById(R.id.lightStatus); lightHeader = (TextView) rootView.findViewById(R.id.lightHeader); light = (TextView) rootView.findViewById(R.id.light); proximityStatus = (TextView) rootView.findViewById(R.id.proximityStatus); proximityHeader = (TextView) rootView.findViewById(R.id.proximityHeader); proximity = (TextView) rootView.findViewById(R.id.proximity); mainActivity.sensorSectionFragment = this; return rootView; }