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:org.skt.runtime.html5apis.Accelerometer.java
/** * Called when the accuracy of the sensor has changed. * // w ww.ja v a2 s.co m * @param sensor * @param accuracy */ public void onAccuracyChanged(Sensor sensor, int accuracy) { // Only look at accelerometer events if (sensor.getType() != Sensor.TYPE_ACCELEROMETER) { return; } // If not running, then just return if (this.status == Accelerometer.STOPPED) { return; } this.accuracy = accuracy; }
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 a va2 s . c om }
From source file:org.apache.cordova.AccelListener.java
/** * Called when the accuracy of the sensor has changed. * * @param sensor/* w ww . j av a 2 s . c o m*/ * @param accuracy */ public void onAccuracyChanged(Sensor sensor, int accuracy) { // Only look at accelerometer events if (sensor.getType() != Sensor.TYPE_ACCELEROMETER) { return; } // If not running, then just return if (this.status == AccelListener.STOPPED) { return; } this.accuracy = accuracy; }
From source file:com.phonegap.AccelListener.java
/** * Start listening for acceleration sensor. * //www. j av a 2 s . c om * @return status of listener */ public int start() { // If already starting or running, then just return if ((this.status == AccelListener.RUNNING) || (this.status == AccelListener.STARTING)) { return this.status; } // 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_FASTEST); this.setStatus(AccelListener.STARTING); this.lastAccessTime = System.currentTimeMillis(); } // If error, then set status to error else { this.setStatus(AccelListener.ERROR_FAILED_TO_START); } return this.status; }
From source file:edu.cens.loci.sensors.AccelerometerHandler.java
public void stop() { if (!mIsOn)// w ww . j av a 2 s.c om return; mIsOn = false; if (mDuration > 0) { mOnTimer.cancel(); mOffTimer.cancel(); if (mSensorOn) { mSensorOn = false; mSensorService.unregisterListener(this, mSensorService.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)); } if (mCpuLock.isHeld()) mCpuLock.release(); } else { if (mSensorOn) { mSensorOn = false; mSensorService.unregisterListener(this, mSensorService.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)); } mReportTimer.cancel(); if (mCpuLock.isHeld()) mCpuLock.release(); } stopChkTimer(); }
From source file:com.javadog.cgeowear.WearService.java
/** * Starts service & watch app./*from w w w . ja va 2s . com*/ */ private void handleInit() { SharedPreferences userPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); //Register listener for INTENT_STOP events IntentFilter filter = new IntentFilter(INTENT_STOP); registerReceiver(intentReceiver, filter); //Register listener for when watch app closes IntentFilter localFilter = new IntentFilter(ListenerService.PATH_KILL_APP); LocalBroadcastManager.getInstance(this).registerReceiver(localReceiver, localFilter); //Show a persistent notification Intent stopServiceIntent = new Intent(INTENT_STOP); PendingIntent nIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, stopServiceIntent, 0); Notification notification = new NotificationCompat.Builder(getApplicationContext()).setOngoing(true) .setContentIntent(nIntent).setSmallIcon(R.drawable.ic_launcher) .setContentTitle(getText(R.string.app_name)).setContentText(getText(R.string.notification_text)) .build(); //Specify how quickly we want to receive location updates locationRequest = LocationRequest.create().setInterval(LOCATION_UPDATE_INTERVAL) .setFastestInterval(LOCATION_UPDATE_MAX_INTERVAL) .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); //Start reading compass sensors if using phone compass useWatchCompass = userPrefs.getBoolean("pref_use_watch_compass", false); if (!useWatchCompass) { sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); magnetometer = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL); sensorManager.registerListener(this, magnetometer, SensorManager.SENSOR_DELAY_NORMAL); } //Start service in foreground startForeground(R.string.app_name, notification); }
From source file:io.github.data4all.service.OrientationListener.java
@Override public void onAccuracyChanged(Sensor sensor, int accuracy) { if (sensor.getType() == Sensor.TYPE_ACCELEROMETER) { if (accuracy < SensorManager.SENSOR_STATUS_ACCURACY_HIGH) { Log.d(TAG, "The sensor: " + sensor.getName() + " has now the accuracy of " + accuracy + " it needs recalibration!"); accOk = accuracy;// w ww . j ava 2 s . com } else { Log.d(TAG, "The sensor: " + sensor.getName() + " has now the accuracy of " + accuracy + " App ready to use!"); accOk = accuracy; } } if (sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { if (accuracy < SensorManager.SENSOR_STATUS_ACCURACY_HIGH) { Log.d(TAG, "The sensor: " + sensor.getName() + " has now the accuracy of " + accuracy + " it needs recalibration!"); magOk = accuracy; } else { Log.d(TAG, "The sensor: " + sensor.getName() + " has now the accuracy of " + accuracy + " App ready to use!"); magOk = accuracy; } } this.checkAccuracy(); /* * Creates a new Intent containing a Uri object BROADCAST_ACTION is a * custom Intent action */ final Intent localIntent = new Intent(BROADCAST_CAMERA) // Puts the status into the Intent .putExtra(INTENT_CAMERA_UPDATE, true); // Broadcasts the Intent to receivers in this app. LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent); }
From source file:com.shimi.camera.must.stand.straight.MainActivity.java
@Override protected void onResume() { super.onResume(); if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) { mCameraView.start();/*ww w .j a va2 s.c om*/ mCameraView.setAspectRatio(AspectRatio.parse("16:9")); mCameraView.setFacing(CameraView.FACING_FRONT); } else if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) { ConfirmationDialogFragment .newInstance(R.string.camera_permission_confirmation, new String[] { Manifest.permission.CAMERA }, REQUEST_CAMERA_PERMISSION, R.string.camera_permission_not_granted) .show(getSupportFragmentManager(), FRAGMENT_DIALOG); } else { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA }, REQUEST_CAMERA_PERMISSION); } // register this class as a listener for the orientation and // accelerometer sensors mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); }
From source file:github.popeen.dsub.activity.SubsonicActivity.java
@Override protected void onCreate(Bundle bundle) { sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE); if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) { // tv = true; }//w w w . ja v a 2s. c o m PackageManager pm = getPackageManager(); if (!pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN)) { touchscreen = false; } setUncaughtExceptionHandler(); applyTheme(); applyFullscreen(); super.onCreate(bundle); startService(new Intent(this, DownloadService.class)); setVolumeControlStream(AudioManager.STREAM_MUSIC); if (getIntent().hasExtra(Constants.FRAGMENT_POSITION)) { lastSelectedPosition = getIntent().getIntExtra(Constants.FRAGMENT_POSITION, 0); } if (preferencesListener == null) { preferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() { @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { // When changing drawer settings change visibility switch (key) { case Constants.PREFERENCES_KEY_PODCASTS_ENABLED: setDrawerItemVisible(R.id.drawer_podcasts, false); break; case Constants.PREFERENCES_KEY_BOOKMARKS_ENABLED: setDrawerItemVisible(R.id.drawer_bookmarks, false); break; case Constants.PREFERENCES_KEY_INTERNET_RADIO_ENABLED: setDrawerItemVisible(R.id.drawer_internet_radio_stations, false); break; case Constants.PREFERENCES_KEY_SHARED_ENABLED: setDrawerItemVisible(R.id.drawer_shares, false); break; case Constants.PREFERENCES_KEY_CHAT_ENABLED: setDrawerItemVisible(R.id.drawer_chat, false); break; case Constants.PREFERENCES_KEY_ADMIN_ENABLED: setDrawerItemVisible(R.id.drawer_admin, false); break; } } }; Util.getPreferences(this).registerOnSharedPreferenceChangeListener(preferencesListener); } if (ContextCompat.checkSelfPermission(this, permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[] { permission.WRITE_EXTERNAL_STORAGE }, PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE); } }
From source file:org.skt.runtime.html5apis.Accelerometer.java
/** * Sensor listener event./*w ww. j av a 2s .co m*/ * * @param SensorEvent event */ public void onSensorChanged(SensorEvent event) { // Only look at accelerometer events if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER) { return; } // If not running, then just return if (this.status == Accelerometer.STOPPED) { return; } this.setStatus(Accelerometer.RUNNING); if (this.accuracy >= SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM) { // Save time that event was received this.timestamp = System.nanoTime(); this.x = event.values[0]; this.y = event.values[1]; this.z = event.values[2]; this.win(); } }