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:org.skt.runtime.original.CompassListener.java
/** * Start listening for compass sensor.// w ww .j a va 2s. co m * * @return status of listener */ public int start() { // If already starting or running, then just return if ((this.status == CompassListener.RUNNING) || (this.status == CompassListener.STARTING)) { return this.status; } // Get compass sensor from sensor manager List<Sensor> list = this.sensorManager.getSensorList(Sensor.TYPE_ORIENTATION); // 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_NORMAL); this.lastAccessTime = System.currentTimeMillis(); this.setStatus(CompassListener.STARTING); } // If error, then set status to error else { this.setStatus(CompassListener.ERROR_FAILED_TO_START); } return this.status; }
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();/*from www.j a va2 s . co m*/ 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:com.javadog.cgeowear.WearService.java
/** * Starts service & watch app./* w w w . ja v a 2s .co m*/ */ 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: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; }/*from w ww . j a va 2s. co 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:ca.nehil.rter.streamingapp.StreamingActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_streaming); poilist = new ArrayList<POI>(); /* Retrieve server URL from stored app values */ storedValues = getSharedPreferences(getString(R.string.sharedPreferences_filename), MODE_PRIVATE); server_url = storedValues.getString("server_url", "not-set"); /* Orientation listenever implementation to orient video */ myOrientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) { @Override/*from www .j a va 2 s . c o m*/ public void onOrientationChanged(int orientation) { int rotation = getWindowManager().getDefaultDisplay().getRotation(); if (rotation == Surface.ROTATION_270) { flipVideo = true; } else { flipVideo = false; } } }; myOrientationEventListener.enable(); /* Retrieve user auth data from cookie */ cookies = getSharedPreferences("RterUserCreds", MODE_PRIVATE); cookieEditor = 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); URL serverURL = null; try { serverURL = new URL(server_url); CookieStore myCookieStore = new BasicCookieStore(); client.setCookieStore(myCookieStore); String[] credentials = setRterCredentials.split("=", 2); BasicClientCookie newCookie = new BasicClientCookie(credentials[0], credentials[1]); newCookie.setDomain(serverURL.getHost()); newCookie.setPath("/"); myCookieStore.addCookie(newCookie); mSensorSource = SensorSource.getInstance(this, GET_LOCATION_FROM_SERVER, serverURL, setRterCredentials, setUsername); POIs = new POIList(this, serverURL, setRterCredentials, mSensorSource); } catch (MalformedURLException e) { e.printStackTrace(); } overlay = new OverlayController(this, POIs, mSensorSource); // OpenGL overlay /* Get location */ Location location = mSensorSource.getLocation(); if (location != null) { lati = (float) (location.getLatitude()); longi = (float) (location.getLongitude()); } else { Toast toast = Toast.makeText(this, "Location not available", Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP, 0, 0); toast.show(); lati = (float) (45.505958f); // Hard coded location for testing purposes. longi = (float) (-73.576254f); } 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.setDesiredOrientation(0.0f); }
From source file:com.example.jony.myapp.reader_APP.ui.DailyDetailsActivity.java
@Override protected void onResume() { super.onResume(); mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); isShakeMode = Settings.getInstance().getBoolean(Settings.SHAKE_TO_RETURN, true); }
From source file:de.tlabs.ssr.g1.client.SourcesView.java
private void init() { // make this view focusable setFocusable(true);/* w w w. j a va 2s . co m*/ // init fields viewportTransformation = new Matrix(); newViewportTransformation = new Matrix(); inverseViewportTransformation = new Matrix(); selectionOffset = new float[2]; touchPoint = new float[2]; buffer = ByteBuffer.allocate(1024); scalingInterpolator = new TimedInterpolator(); scalingInterpolator.setDuration(800); translationXInterpolator = new TimedInterpolator(); translationXInterpolator.setDuration(800); translationYInterpolator = new TimedInterpolator(); translationYInterpolator.setDuration(800); rotationInterpolator = new TimedInterpolator(); rotationInterpolator.setDuration(800); centerRotationInterpolator = new TimedInterpolator(); centerRotationInterpolator.setDuration(800); currentOrientation = getContext().getResources().getConfiguration().orientation; setOrientationFlag(true); if (SourcesView.paint == null) { SourcesView.paint = new Paint(); SourcesView.paint.setAntiAlias(false); SourcesView.paint.setStrokeWidth(0); SourcesView.paint.setTextAlign(Paint.Align.CENTER); SourcesView.paint.setTextSize(9.0f); } // set up orientation event listener orientationEventListener = new OrientationEventListener(getContext(), SensorManager.SENSOR_DELAY_NORMAL) { @Override public void onOrientationChanged(int orientation) { if ((orientation >= 80 && orientation <= 100) || (orientation >= 260 && orientation <= 280)) { // landscape setOrientation(Configuration.ORIENTATION_LANDSCAPE); } else if ((orientation >= 350 || orientation <= 10) || (orientation >= 170 && orientation <= 190)) { // portrait setOrientation(Configuration.ORIENTATION_PORTRAIT); } } }; if (!GlobalData.orientationTrackingEnabled) // orientation tracking and screen rotation tracking don't go together orientationEventListener.enable(); // set up gesture detector gestureDetector = new GestureDetector(getContext(), this); gestureDetector.setIsLongpressEnabled(false); gestureDetector.setOnDoubleTapListener(this); // init viewport transformation matrix recalculateViewportTransformation(); }
From source file:com.wordpress.tonytam.avatar.AvatarWearActivity.java
@Override protected void onResume() { super.onResume(); if (mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL)) { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Successfully registered for the sensor updates"); }//from w ww .j a va2 s. c o m } // TODO: if (false) { if (mSensorManager.registerListener(this, mSensorAccelerometer, SensorManager.SENSOR_DELAY_NORMAL)) { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Successfully registered for the sensor updates"); } } } }
From source file:edu.uwp.alga.calculator.CalculatorFragment.java
public void getLux() { sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); if (lightSensor == null) { lux = 12000f;//from ww w .j a v a 2 s . co m Log.e("Light", String.valueOf(lux)); } else { sensorManager.registerListener(this, lightSensor, SensorManager.SENSOR_DELAY_NORMAL); } }