List of usage examples for android.hardware SensorManager SENSOR_DELAY_FASTEST
int SENSOR_DELAY_FASTEST
To view the source code for android.hardware SensorManager SENSOR_DELAY_FASTEST.
Click Source Link
From source file:com.android.camera2.its.ItsService.java
@Override public void onCreate() { try {// w w w . j a v a 2 s .c o m mThreadExitFlag = false; // Get handle to camera manager. mCameraManager = (CameraManager) this.getSystemService(Context.CAMERA_SERVICE); if (mCameraManager == null) { throw new ItsException("Failed to connect to camera manager"); } mBlockingCameraManager = new BlockingCameraManager(mCameraManager); mCameraListener = new BlockingStateCallback(); // Register for motion events. mEvents = new LinkedList<MySensorEvent>(); mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mAccelSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mMagSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); mGyroSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); mSensorManager.registerListener(this, mAccelSensor, SensorManager.SENSOR_DELAY_FASTEST); mSensorManager.registerListener(this, mMagSensor, SensorManager.SENSOR_DELAY_FASTEST); mSensorManager.registerListener(this, mGyroSensor, SensorManager.SENSOR_DELAY_FASTEST); // Get a handle to the system vibrator. mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // Create threads to receive images and save them. for (int i = 0; i < MAX_NUM_OUTPUT_SURFACES; i++) { mSaveThreads[i] = new HandlerThread("SaveThread" + i); mSaveThreads[i].start(); mSaveHandlers[i] = new Handler(mSaveThreads[i].getLooper()); } // Create a thread to handle object serialization. (new Thread(new SerializerRunnable())).start(); ; // Create a thread to receive capture results and process them. mResultThread = new HandlerThread("ResultThread"); mResultThread.start(); mResultHandler = new Handler(mResultThread.getLooper()); // Create a thread for the camera device. mCameraThread = new HandlerThread("ItsCameraThread"); mCameraThread.start(); mCameraHandler = new Handler(mCameraThread.getLooper()); // Create a thread to process commands, listening on a TCP socket. mSocketRunnableObj = new SocketRunnable(); (new Thread(mSocketRunnableObj)).start(); } catch (ItsException e) { Logt.e(TAG, "Service failed to start: ", e); } }
From source file:radu.pidroid.Controller.java
@Override protected void onResume() { super.onResume(); mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_FASTEST); mSensorManager.registerListener(this, mGeomagnetic, SensorManager.SENSOR_DELAY_FASTEST); ////from ww w .j a v a2 s.co m if (Main.detailsCheckBox.isChecked()) loadPreferences(); else clearPreferences(); //setupVideoFeed(); }
From source file:au.gov.ga.worldwind.androidremote.client.Remote.java
@Override protected void onResume() { super.onResume(); // Performing this check in onResume() covers the case in which BT was // not enabled during onStart(), so we were paused to enable it... // onResume() will be called when ACTION_REQUEST_ENABLE activity returns. if (communicator != null && communicator.getState() == AndroidCommunicator.State.NONE) { communicator.start();//from w w w.j a va 2 s. c o m remoteViewCommunicator.start(); } updateActionBarIcon(communicator.getState()); sensorManager.registerListener(sensorListener, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_FASTEST); }
From source file:com.davidmascharka.lips.MainActivity.java
@Override public void onResume() { super.onResume(); // Set building textview to the building the user has selected TextView buildingText = (TextView) findViewById(R.id.text_building); buildingText.setText("Building: " + building); // Set room size textview to the room size the user has selected TextView roomSizeText = (TextView) findViewById(R.id.text_room_size); roomSizeText.setText("Room size: " + roomWidth + " x " + roomLength); // Set grid options GridView grid = (GridView) findViewById(R.id.gridView); grid.setGridSize(roomWidth, roomLength); grid.setDisplayMap(displayMap);/*from ww w. j ava 2s. co m*/ // Register to get sensor updates from all the available sensors sensorList = sensorManager.getSensorList(Sensor.TYPE_ALL); for (Sensor sensor : sensorList) { sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_FASTEST); } // Enable wifi if it is not if (!wifiManager.isWifiEnabled()) { Toast.makeText(this, "WiFi not enabled. Enabling...", Toast.LENGTH_SHORT).show(); wifiManager.setWifiEnabled(true); } // Request location updates from gps and the network //@author Mahesh Gaya added permission if-statment if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_WIFI_STATE) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this, android.Manifest.permission.CHANGE_WIFI_STATE) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { Log.i(TAG, "Permissions have NOT been granted. Requesting permissions."); requestMyPermissions(); } else { Log.i(TAG, "Permissions have already been granted. Getting location from GPS and Network"); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); } registerReceiver(receiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)); }
From source file:edu.drake.research.android.lipswithmaps.activity.MapsActivity.java
/** * Registers the listeners for the different sensors *///w w w . ja v a 2s . c o m @Override protected void onStart() { super.onStart(); mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_FASTEST); mSensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_DELAY_FASTEST); mSensorManager.registerListener(this, mRotationMeter, SensorManager.SENSOR_DELAY_FASTEST); mAuth.addAuthStateListener(mAuthListener); }
From source file:cl.ipp.katbag.fragment.Player.java
public void setSensing(String[] line, int lineNumber) { switch (Integer.parseInt(line[3])) { case 0:/*w w w . jav a2 s . co m*/ boolean ex = false; for (int z = 0; z < touchEventId.size(); z++) { if (line[0].contentEquals(String.valueOf(touchEventId.get(z)))) { ex = true; break; } } if (!ex) { int last = -1; for (int i = lineNumber + 1; i < develop.size(); i++) { String[] it = develop.get(i).split("&&"); last = i; if (Integer.parseInt(line[8]) >= Integer.parseInt(it[8])) { last--; break; } } if ((lineNumber + 1) <= last) { touchEventId.add(Integer.valueOf(line[0])); touchEventDrawing.add(Integer.valueOf(line[4])); // drawing touchEventBgn.add(lineNumber + 1); // begin in touchEventLst.add(last); // ends final KatbagDrawing drawing = (KatbagDrawing) v.findViewById(Integer.valueOf(line[4])); if (drawing != null) { drawing.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: for (int i = 0; i < touchEventDrawing.size(); i++) { if (touchEventDrawing.get(i) == drawing.getId()) { setBranchTreeCondition(touchEventId.get(i), 1); if (checkTreeCondition(touchEventId.get(i))) { Log.d("ply", "touchEventDrawing - ini:" + touchEventBgn.get(i) + ", last:" + touchEventLst.get(i)); play(touchEventBgn.get(i), touchEventLst.get(i) + 1); break; } } } break; case MotionEvent.ACTION_UP: for (int i = 0; i < touchEventDrawing.size(); i++) { if (touchEventDrawing.get(i) == drawing.getId()) { setBranchTreeCondition(touchEventId.get(i), 0); break; } } break; } return true; } }); Log.d("ply", "setSensing - touchEvent add! count:" + touchEventId.size() + ", drawing:" + touchEventDrawing.get(touchEventDrawing.size() - 1) + " ini:" + touchEventBgn.get(touchEventBgn.size() - 1) + " last:" + touchEventLst.get(touchEventLst.size() - 1)); } } if (last > -1) if ((last + 1) < develop.size()) play((last + 1), develop.size()); } break; case 1: boolean ex1 = false; for (int z = 0; z < shakeId.size(); z++) { if (line[0].contentEquals(String.valueOf(shakeId.get(z)))) { ex1 = true; break; } } if (!ex1) { int last1 = -1; for (int i = lineNumber + 1; i < develop.size(); i++) { String[] it = develop.get(i).split("&&"); last1 = i; if (Integer.parseInt(line[8]) >= Integer.parseInt(it[8])) { last1--; break; } } if ((lineNumber + 1) <= last1) { shakeId.add(Integer.valueOf(line[0])); shakeBgn.add(lineNumber + 1); // begin in shakeLst.add(last1); // ends sensorManager = (SensorManager) mainActivity.context.getSystemService(Context.SENSOR_SERVICE); accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_FASTEST); useAccelerometer = true; Log.d("ply", "setSensing - shake add! count:" + shakeId.size() + ", ini:" + shakeBgn.get(shakeBgn.size() - 1) + " last:" + shakeLst.get(shakeLst.size() - 1)); } if (last1 > -1) if ((last1 + 1) < develop.size()) play((last1 + 1), develop.size()); } break; } }
From source file:tv.piratemedia.flightcontroller.BluetoothComputerFragment.java
public void setupAccel() { SensorManager mSensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION); mSensorManager.registerListener(new SensorEventListener() { @Override// w ww. ja v a 2 s.c om public void onSensorChanged(SensorEvent event) { if (!Moving && currentTrottle > 20) { float[] filtered = new float[3]; lowPass(event.values, filtered); float x = getAverageX(filtered[0]); float y = getAverageY(filtered[1]); currentXOffset += x * multiValue; currentYOffset += y * multiValue; if (currentXOffset > maxOffset) { currentXOffset = maxOffset; } else if (currentXOffset < -maxOffset) { currentXOffset = -maxOffset; } if (currentYOffset > maxOffset) { currentYOffset = maxOffset; } else if (currentYOffset < -maxOffset) { currentYOffset = -maxOffset; } if (PitchCorrection != (int) currentYOffset && RollCorrection != (int) currentXOffset) { PitchCorrection = (int) currentYOffset; RollCorrection = -(int) currentXOffset; JSONObject msg = new JSONObject(); try { msg.put("action", "correction_update"); msg.put("pitch", PitchCorrection); msg.put("roll", RollCorrection); } catch (JSONException e) { e.printStackTrace(); } sendTextMessage(msg.toString()); updateThrottle(currentTrottle); } } else if (!Moving && currentTrottle <= 20) { PitchCorrection = 0; RollCorrection = 0; JSONObject msg = new JSONObject(); try { msg.put("action", "correction_update"); msg.put("pitch", PitchCorrection); msg.put("roll", RollCorrection); } catch (JSONException e) { e.printStackTrace(); } sendTextMessage(msg.toString()); updateThrottle(currentTrottle); } } @Override public void onAccuracyChanged(Sensor sensor, int accuracy) { } }, mSensor, SensorManager.SENSOR_DELAY_FASTEST); }
From source file:com.thousandthoughts.tutorials.SensorFusionActivity.java
public void initListeners() { mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_FASTEST); mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE), SensorManager.SENSOR_DELAY_FASTEST); mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), SensorManager.SENSOR_DELAY_FASTEST); }
From source file:com.saulcintero.moveon.services.MoveOnService.java
private void registerDetector() { mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mSensorManager.registerListener(mStepDetector, mSensor, SensorManager.SENSOR_DELAY_FASTEST); stepDetectorSensitivity();/*from ww w. jav a2 s.c o m*/ }
From source file:tv.piratemedia.flightcontroller.BluetoothComputerFragment.java
public void setupGyro() { final Handler TimeoutHandler = new Handler(); SensorManager mSensorManager;//from w w w.ja va 2s .c om Sensor mSensor; mSensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY); SensorEventListener sensorListener = new SensorEventListener() { @Override public void onSensorChanged(SensorEvent event) { int X = (int) (event.values[0] / 2.0f); int Y = (int) (event.values[1] / 2.0f); int Z = (int) (event.values[2] / 2.0f); Y = -Y; //Log.d("gyro", "X: " + X + " Y: " + Y + " Z: " + Z); if (currentPitch != Y || currentRoll != X || currentYaw != Z) { if (!Moving && currentTrottle > 10) { if ((PitchCorrection < MaxCorrectionValue || Y < 0) && (PitchCorrection > -MaxCorrectionValue || Y > 0)) { PitchCorrection += Y; if (PitchCorrection > MaxCorrectionValue) { PitchCorrection = MaxCorrectionValue; } else if (PitchCorrection < -MaxCorrectionValue) { PitchCorrection = -MaxCorrectionValue; } } if ((RollCorrection < MaxCorrectionValue || X < 0) && (RollCorrection > -MaxCorrectionValue || X > 0)) { RollCorrection += X; if (RollCorrection > MaxCorrectionValue) { RollCorrection = MaxCorrectionValue; } else if (RollCorrection < -MaxCorrectionValue) { RollCorrection = -MaxCorrectionValue; } } updateThrottle(currentTrottle); } else if (currentTrottle <= 10) { PitchCorrection = 0; RollCorrection = 0; } currentPitch = Y; currentRoll = X; currentYaw = Z; JSONObject msg = new JSONObject(); try { msg.put("action", "gyro_update"); msg.put("x", currentRoll); msg.put("y", currentPitch); msg.put("z", currentYaw); } catch (JSONException e) { e.printStackTrace(); } sendTextMessage(msg.toString()); } } @Override public void onAccuracyChanged(Sensor sensor, int accuracy) { } }; if (mSensor != null) { mSensorManager.registerListener(sensorListener, mSensor, SensorManager.SENSOR_DELAY_FASTEST); } else { Toast.makeText(getActivity().getApplicationContext(), "No Gravity Sensor on device", Toast.LENGTH_LONG) .show(); } }