List of usage examples for android.hardware SensorManager SENSOR_DELAY_NORMAL
int SENSOR_DELAY_NORMAL
To view the source code for android.hardware SensorManager SENSOR_DELAY_NORMAL.
Click Source Link
From source file:com.example.lijingjiang.mobile_sensor_display.SimplePedometerActivity.java
public void startCollection_Sleeping(View view) { /**//from w ww . ja v a 2 s . c om * Get current time stamp to calculate the elapsed time */ date = new Date(); startButtonSleeping.setEnabled(false); stopButtonSleeping.setEnabled(true); startButtonRunning.setEnabled(false); stopButtonRunning.setEnabled(false); startButtonExercising.setEnabled(false); startButtonExercising.setEnabled(false); /** * Reset all data */ hr = 0; numSteps = 0; accumulatedLocationCalculatedFromGoogle = 0; startRecording = true; distanceResultView.setText(R.string.zero + " Meters"); hrResultView.setText(TEXT_HR + hr); stepsResultView.setText(TEXT_NUM_STEPS + numSteps); /** * When click the start button, register the sensor and start google * location service */ sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL); /** * The following code blocks is required by google api */ if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Add function logic when user don't give the permission return; } previousLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); currentLatitude = previousLocation.getLatitude(); currentLongitude = previousLocation.getLongitude(); /** * The following toast will indicate that the user has provided the permission, * and the app can get the location information now */ //Toast // .makeText(this, currentLatitude + " WORKS " + currentLongitude + "", // Toast.LENGTH_LONG) // .show(); LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this); }
From source file:com.mummyding.app.leisure.ui.MainActivity.java
@Override protected void onResume() { super.onResume(); mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); if (Settings.needRecreate) { Settings.needRecreate = false;/*from ww w . ja v a 2 s . co m*/ this.recreate(); } }
From source file:hr.abunicic.angular.CameraActivity.java
@Override protected void onResume() { super.onResume(); //Registering the sensor when the activity is resumed mSensorManager.registerListener(this, mGyroSensor, SensorManager.SENSOR_DELAY_NORMAL); //Reinitializing the camera preview.removeAllViews();// w w w . ja va 2 s .c o m initCamera(); startPreview = false; //Starting detection if no shape is paused if (cardBottom.getVisibility() == View.INVISIBLE) startDetection(); }
From source file:org.deviceconnect.android.deviceplugin.host.HostDeviceService.java
/** * Promity Profile<br>/*ww w. j a v a 2 s . c o m*/ * ?. * * @param response ? * @param deviceId ?ID * @param sessionKey */ public void registerPromityEvent(final Intent response, final String deviceId, final String sessionKey) { mDeviceId = deviceId; mSensorManagerProximity = (SensorManager) getSystemService(SENSOR_SERVICE); List<Sensor> sensors = mSensorManagerProximity.getSensorList(Sensor.TYPE_PROXIMITY); if (sensors.size() > 0) { Sensor sensor = sensors.get(0); mSensorManagerProximity.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL); } response.putExtra(DConnectMessage.EXTRA_RESULT, DConnectMessage.RESULT_OK); response.putExtra(DConnectMessage.EXTRA_VALUE, "Register onuserproximity event"); sendBroadcast(response); }
From source file:com.thalmic.android.sample.helloworld.HelloWorldActivity.java
protected void onResume() { super.onResume(); // Register a listener for the sensor. sensorManager.registerListener(this, vector, SensorManager.SENSOR_DELAY_NORMAL); sensorManager.registerListener(this, acc, SensorManager.SENSOR_DELAY_NORMAL); sensorManager.registerListener(this, mag, SensorManager.SENSOR_DELAY_GAME); }
From source file:ca.nehil.rter.streamingapp2.StreamingActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Orientation listenever implementation myOrientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) { @Override/*from ww w . j a v a2 s.co m*/ public void onOrientationChanged(int orientation) { int rotation = getWindowManager().getDefaultDisplay().getRotation(); if (rotation == Surface.ROTATION_270) { flipVideo = true; } else { flipVideo = false; } } }; myOrientationEventListener.enable(); // stopService(new Intent(StreamingActivity.this, // BackgroundService.class)); Log.e(TAG, "onCreate"); AndroidId = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID); frameInfo = new FrameInfo(); // openGL overlay overlay = new OverlayController(this); // orientation mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); mAcc = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mMag = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); setContentView(R.layout.activity_streaming); // Find the total number of cameras available numberOfCameras = Camera.getNumberOfCameras(); cookies = getSharedPreferences("RterUserCreds", MODE_PRIVATE); prefEditor = cookies.edit(); setUsername = cookies.getString("Username", "not-set"); setRterCredentials = cookies.getString("RterCreds", "not-set"); if (setRterCredentials.equalsIgnoreCase("not-set") || setRterCredentials == null) { Log.e("PREFS", "Login Not successful, please restart"); } Log.d("PREFS", "Prefs ==> rter_Creds:" + setRterCredentials); // Get the location manager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // Define the criteria how to select the location provider -> use // default if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { Log.e(TAG, "GPS not available"); } Criteria criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, true); Log.d(TAG, "Requesting location"); locationManager.requestLocationUpdates(provider, 0, 1, this); // register the overlay control for location updates as well, so we get // the geomagnetic field locationManager.requestLocationUpdates(provider, 0, 1000, overlay); if (provider != null) { Location location = locationManager.getLastKnownLocation(provider); // Initialize the location fields if (location != null) { System.out.println("Provider " + provider + " has been selected. and location " + location); onLocationChanged(location); } else { Toast toast = Toast.makeText(this, "Location not available", Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP, 0, 0); toast.show(); lati = (float) (45.505958f); longi = (float) (-73.576254f); Log.d(TAG, "Location not available"); } } // power manager PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, CLASS_LABEL); mWakeLock.acquire(); // test, set desired orienation to north overlay.letFreeRoam(false); overlay.setDesiredOrientation(0.0f); // CharSequence text = "Tap to start.."; // int duration = Toast.LENGTH_SHORT; // // Toast toast = Toast.makeText(this, text, duration); // toast.setGravity(Gravity.TOP|Gravity.RIGHT, 0, 0); // toast.show(); }
From source file:com.gelakinetic.selfr.CameraActivity.java
/** * When the activity resumes, request permissions, or if the app has them initialize: * - audio capturer (to detect button presses) * - camera (to take pictures)//from w w w. ja va 2 s. c o m * - headset state receiver (to detect the selfie stick) * - accelerometer (to properly set picture rotation) */ @Override protected void onResume() { super.onResume(); /* Check to see what permissions we're granted */ ArrayList<String> requestedPermissions = new ArrayList<>(3); if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { requestedPermissions.add(Manifest.permission.CAMERA); } if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { requestedPermissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE); } if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) { requestedPermissions.add(Manifest.permission.RECORD_AUDIO); } /* If we don't have all of the permissions */ if (requestedPermissions.size() > 0) { String permissionStrings[] = new String[requestedPermissions.size()]; requestedPermissions.toArray(permissionStrings); /* Request the permissions */ ActivityCompat.requestPermissions(this, permissionStrings, PERMISSION_REQUEST_CODE); } else { /* Otherwise, fire everything up */ /* Set things based on preferences */ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); if (prefs.getBoolean(getString(R.string.display_value_key), false)) { mDebugTextView.setVisibility(View.VISIBLE); } else { mDebugTextView.setVisibility(View.GONE); } mButtonThreshold = Float.parseFloat( prefs.getString(getString(R.string.threshold_key), getString(R.string.default_threshold))); /* Set up the audio capture */ mAudioCapturer = AudioCapturer.getInstance(this); /* Set up the camera */ mCamera = getCameraInstance(mCameraType); if (mCamera != null) { mCameraPreview = new CameraPreview(this, mCamera); mContentView.addView(mCameraPreview); } /* Register the headset state receiver */ mHeadsetStateReceiver = new HeadsetStateReceiver(this); registerReceiver(mHeadsetStateReceiver, new IntentFilter(Intent.ACTION_HEADSET_PLUG)); /* Set up the accelerometer */ mOrientationEventListener = new OrientationEventListener(CameraActivity.this, SensorManager.SENSOR_DELAY_NORMAL) { /** * Called when the orientation of the device has changed. orientation parameter is * in degrees, ranging from 0 to 359. orientation is 0 degrees when the device is * oriented in its natural position, 90 degrees when its left side is at the top, * 180 degrees when it is upside down, and 270 degrees when its right side is to the * top. ORIENTATION_UNKNOWN is returned when the device is close to flat and the * orientation cannot be determined. * * @param orientation The orientation of the device. (0->359, ORIENTATION_UNKNOWN) */ @Override public void onOrientationChanged(int orientation) { /* If the orientation is unknown, don't bother */ if (orientation == ORIENTATION_UNKNOWN) { return; } /* Clamp rotation to nearest 90 degree wedge, depending on camera */ if (mCameraType == Camera.CameraInfo.CAMERA_FACING_FRONT) { if (315 <= orientation || orientation < 45) { mDeviceRotation = 270; } else if (45 <= orientation && orientation < 135) { mDeviceRotation = 180; } else if (135 <= orientation && orientation < 225) { mDeviceRotation = 90; } else if (225 <= orientation && orientation < 315) { mDeviceRotation = 0; } } else { if (315 <= orientation || orientation < 45) { mDeviceRotation = 90; } else if (45 <= orientation && orientation < 135) { mDeviceRotation = 180; } else if (135 <= orientation && orientation < 225) { mDeviceRotation = 270; } else if (225 <= orientation && orientation < 315) { mDeviceRotation = 0; } } } }; if (mOrientationEventListener.canDetectOrientation()) { mOrientationEventListener.enable(); } /* Trigger the initial hide() shortly after the activity has been * created, to briefly hint to the user that UI controls * are available. */ delayedHide(2000); } }
From source file:com.waz.zclient.pages.main.drawing.DrawingFragment.java
@Override public void onStart() { super.onStart(); colorLayout.setOnWidthChangedListener(this); shakeEventListener = new ShakeEventListener(); shakeEventListener.setOnShakeListener(new ShakeEventListener.OnShakeListener() { @Override// www . j ava 2s . c o m public void onShake() { if (includeBackgroundImage) { drawingCanvasView.removeBackgroundBitmap(); includeBackgroundImage = false; } else { drawingCanvasView.drawBackgroundBitmap(); includeBackgroundImage = true; } } }); sensorManager.registerListener(shakeEventListener, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); getControllerFactory().getGlobalLayoutController().addKeyboardVisibilityObserver(this); getControllerFactory().getAccentColorController().addAccentColorObserver(this); getControllerFactory().getRequestPermissionsController().addObserver(this); }
From source file:org.zywx.wbpalmstar.plugin.uexaudio.EUExAudio.java
public void setProximityState(String[] params) { if (params == null || params.length < 1) return;// w ww.j a v a2 s.c o m boolean state = "1".equals(params[0]); SensorManager mSensorManager = (SensorManager) mContext.getApplicationContext() .getSystemService(Context.SENSOR_SERVICE); if (!state) { if (sensorEventListener != null) mSensorManager.unregisterListener(sensorEventListener); return; } Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); if (sensorEventListener == null) { if (m_pfMusicPlayer != null) { sensorEventListener = m_pfMusicPlayer.getSensorEventListener(); } else { errorCallback(0, EUExCallback.F_E_AUDIO_MUSIC_STOP_NO_OPEN_ERROR_CODE, /* "" */finder.getString(mContext, "plugin_audio_no_open_error")); return; } } mSensorManager.registerListener(sensorEventListener, mSensor, SensorManager.SENSOR_DELAY_NORMAL); }
From source file:com.first.akashshrivastava.showernow.ShowerActivity.java
void setupStepcount() { /*mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); //from w w w .j a va 2 s . com // have a default sensor configured //int sensorType = Sensor.TYPE_LIGHT; int sensorType = Sensor.TYPE_STEP_COUNTER; // we need the light sensor Sensor sensor = mSensorManager.getDefaultSensor(sensorType); // TODO we could have the sensor reading delay configurable also though that won't do much // in this use case since we work with the alarm manager mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL); */ mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); sensorType = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER); if (mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER) != null) { mSensorManager.registerListener(this, sensorType, SensorManager.SENSOR_DELAY_NORMAL); } else { Toast.makeText(getApplicationContext(), "Pedometer doesn't exist", Toast.LENGTH_SHORT).show(); } }