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:ca.nehil.rter.streamingapp2.StreamingActivity.java
@Override protected void onResume() { super.onResume(); if (mWakeLock == null) { PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, CLASS_LABEL); mWakeLock.acquire();//from ww w. ja v a 2s .com } 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); // sensors mSensorManager.registerListener(overlay, mAcc, SensorManager.SENSOR_DELAY_NORMAL); mSensorManager.registerListener(overlay, mMag, SensorManager.SENSOR_DELAY_NORMAL); initLayout(); }
From source file:com.ape.camera2raw.Camera2RawFragment.java
@Override public void onViewCreated(final View view, Bundle savedInstanceState) { view.findViewById(R.id.picture).setOnClickListener(this); view.findViewById(R.id.info).setOnClickListener(this); mTextureView = (AutoFitTextureView) view.findViewById(R.id.texture); // Setup a new OrientationEventListener. This is used to handle rotation events like a // 180 degree rotation that do not normally trigger a call to onCreate to do view re-layout // or otherwise cause the preview TextureView's size to change. mOrientationListener = new OrientationEventListener(getActivity(), SensorManager.SENSOR_DELAY_NORMAL) { @Override/*from w w w .j a va 2 s .c o m*/ public void onOrientationChanged(int orientation) { if (mTextureView != null && mTextureView.isAvailable()) { configureTransform(mTextureView.getWidth(), mTextureView.getHeight()); } } }; }
From source file:us.bojie.rawgyroscope.camera.Camera2RawFragment.java
@Override public void onViewCreated(final View view, Bundle savedInstanceState) { view.findViewById(R.id.picture).setOnClickListener(this); mTextureView = (AutoFitTextureView) view.findViewById(R.id.texture); // Setup a new OrientationEventListener. This is used to handle rotation events like a // 180 degree rotation that do not normally trigger a call to onCreate to do view re-layout // or otherwise cause the preview TextureView's size to change. mOrientationListener = new OrientationEventListener(getActivity(), SensorManager.SENSOR_DELAY_NORMAL) { @Override//from w ww. j a v a 2 s. c om public void onOrientationChanged(int orientation) { if (mTextureView != null && mTextureView.isAvailable()) { configureTransform(mTextureView.getWidth(), mTextureView.getHeight()); } } }; }
From source file:net.sourceforge.fidocadj.FidoMain.java
/** Reactivate the events needed by the FidoCadJ app when it is brought on focus. This is in particular useful for the sensors gestures, which need to be deactivated when the app is not on the top. *//*from www . ja v a 2 s . c om*/ @Override protected void onResume() { super.onResume(); // Restore registering accelerometer events. mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL); }
From source file:org.thecongers.mtpms.MainActivity.java
@SuppressLint("HandlerLeak") @Override/* w ww . j av a2s . co m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setTitle(R.string.app_name); layoutFront = (LinearLayout) findViewById(R.id.layoutFront); layoutRear = (LinearLayout) findViewById(R.id.layoutRear); txtFrontPressure = (TextView) findViewById(R.id.txtFrontPressure); txtFrontTemperature = (TextView) findViewById(R.id.txtFrontTemperature); txtFrontVoltage = (TextView) findViewById(R.id.txtFrontVoltage); txtRearPressure = (TextView) findViewById(R.id.txtRearPressure); txtRearTemperature = (TextView) findViewById(R.id.txtRearTemperature); txtRearVoltage = (TextView) findViewById(R.id.txtRearVoltage); txtOutput = (TextView) findViewById(R.id.txtOutput); View myView = findViewById(R.id.appLayout); root = myView.getRootView(); sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); // Keep screen on getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // Watch for Bluetooth Changes IntentFilter filter1 = new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED); IntentFilter filter2 = new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED); IntentFilter filter3 = new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED); this.registerReceiver(btReceiver, filter1); this.registerReceiver(btReceiver, filter2); this.registerReceiver(btReceiver, filter3); sensorDB = new SensorIdDatabase(this); // Backgrounds background = this.getResources().getDrawable(R.drawable.rectangle_bordered); redBackground = this.getResources().getDrawable(R.drawable.rectangle_bordered_red); backgroundDark = this.getResources().getDrawable(R.drawable.rectangle_bordered_dark); redBackgroundDark = this.getResources().getDrawable(R.drawable.rectangle_bordered_red_dark); txtOutBackground = this.getResources().getDrawable(R.drawable.rectangle); txtOutBackgroundDark = this.getResources().getDrawable(R.drawable.rectangle_dark); // Update textViews with select units String pressureFormat = sharedPrefs.getString("prefpressuref", "0"); String pressureUnit = "psi"; if (pressureFormat.contains("1")) { // KPa pressureUnit = "KPa"; } else if (pressureFormat.contains("2")) { // Kg-f pressureUnit = "Kg-f"; } else if (pressureFormat.contains("3")) { // Bar pressureUnit = "Bar"; } String temperatureUnit = "C"; if (sharedPrefs.getString("preftempf", "0").contains("0")) { // F temperatureUnit = "F"; } txtFrontPressure.setText("--- " + pressureUnit); txtFrontTemperature.setText("--- " + temperatureUnit); txtFrontVoltage.setText("--- V"); txtRearPressure.setText("--- " + pressureUnit); txtRearTemperature.setText("--- " + temperatureUnit); txtRearVoltage.setText("--- V"); // Set initial color scheme if (!sharedPrefs.getBoolean("prefNightMode", false)) { root.setBackgroundColor(getResources().getColor(android.R.color.white)); layoutFront.setBackground(background); layoutRear.setBackground(background); txtFrontPressure.setTextColor(getResources().getColor(android.R.color.black)); txtFrontTemperature.setTextColor(getResources().getColor(android.R.color.black)); txtFrontVoltage.setTextColor(getResources().getColor(android.R.color.black)); txtRearPressure.setTextColor(getResources().getColor(android.R.color.black)); txtRearTemperature.setTextColor(getResources().getColor(android.R.color.black)); txtRearVoltage.setTextColor(getResources().getColor(android.R.color.black)); txtOutput.setBackground(txtOutBackground); txtOutput.setTextColor(getResources().getColor(android.R.color.black)); } else { root.setBackgroundColor(getResources().getColor(android.R.color.black)); layoutFront.setBackground(backgroundDark); layoutRear.setBackground(backgroundDark); txtFrontPressure.setTextColor(getResources().getColor(android.R.color.white)); txtFrontTemperature.setTextColor(getResources().getColor(android.R.color.white)); txtFrontVoltage.setTextColor(getResources().getColor(android.R.color.white)); txtRearPressure.setTextColor(getResources().getColor(android.R.color.white)); txtRearTemperature.setTextColor(getResources().getColor(android.R.color.white)); txtRearVoltage.setTextColor(getResources().getColor(android.R.color.white)); txtOutput.setBackground(txtOutBackgroundDark); txtOutput.setTextColor(getResources().getColor(android.R.color.white)); } // Check if there are sensor to wheel mappings if (sharedPrefs.getString("prefFrontID", "").equals("") && sharedPrefs.getString("prefRearID", "").equals("")) { new AlertDialog.Builder(this).setTitle(R.string.alert_setup_title) .setMessage(R.string.alert_setup_message).setNeutralButton(R.string.alert_setup_button, null) .show(); } sensorMessages = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case RECEIVE_MESSAGE: // Message received Log.d(TAG, "Serial Message Received, Length: " + msg.arg1); // Check to see if message is the correct size if (msg.arg1 == 13) { byte[] readBuf = (byte[]) msg.obj; // Validate against checksum int calculatedCheckSum = readBuf[4] + readBuf[5] + readBuf[6] + readBuf[7] + readBuf[8] + readBuf[9] + readBuf[10]; if (calculatedCheckSum == readBuf[11]) { // Convert to hex String[] hexData = new String[13]; StringBuilder sbhex = new StringBuilder(); for (int i = 0; i < msg.arg1; i++) { hexData[i] = String.format("%02X", readBuf[i]); sbhex.append(hexData[i]); } // Get sensor position String position = hexData[3]; // Get sensor ID StringBuilder sensorID = new StringBuilder(); sensorID.append(hexData[4]); sensorID.append(hexData[5]); sensorID.append(hexData[6]); sensorID.append(hexData[7]); // Check if sensor ID is new boolean checkID = sensorDB.sensorIdExists(sensorID.toString()); if (!checkID) { // Add sensor ID to db sensorDB.addID(sensorID.toString()); Toast.makeText(MainActivity.this, getResources().getString(R.string.toast_newSensor) + " " + sensorID.toString(), Toast.LENGTH_LONG).show(); } // Only parse message if there is one or more sensor mappings String prefFrontID = sharedPrefs.getString("prefFrontID", ""); String prefRearID = sharedPrefs.getString("prefRearID", ""); if (!prefFrontID.equals("") || !prefRearID.equals("")) { try { // Get temperature int tempC = Integer.parseInt(hexData[8], 16) - 50; double temp = tempC; String temperatureUnit = "C"; // Get tire pressure int psi = Integer.parseInt(hexData[9], 16); double pressure = psi; String pressureUnit = "psi"; // Get battery voltage double voltage = Integer.parseInt(hexData[10], 16) / 50; // Get pressure thresholds int fLowPressure = Integer .parseInt(sharedPrefs.getString("prefFrontLowPressure", "30")); int fHighPressure = Integer .parseInt(sharedPrefs.getString("prefFrontHighPressure", "46")); int rLowPressure = Integer .parseInt(sharedPrefs.getString("prefRearLowPressure", "30")); int rHighPressure = Integer .parseInt(sharedPrefs.getString("prefRearHighPressure", "46")); if (sharedPrefs.getString("preftempf", "0").contains("0")) { // F temp = (9.0 / 5.0) * tempC + 32.0; temperatureUnit = "F"; } int formattedTemperature = (int) (temp + 0.5d); String pressureFormat = sharedPrefs.getString("prefpressuref", "0"); if (pressureFormat.contains("1")) { // KPa pressure = psi * 6.894757293168361; pressureUnit = "KPa"; } else if (pressureFormat.contains("2")) { // Kg-f pressure = psi * 0.070306957965539; pressureUnit = "Kg-f"; } else if (pressureFormat.contains("3")) { // Bar pressure = psi * 0.0689475729; pressureUnit = "Bar"; } int formattedPressure = (int) (pressure + 0.5d); // Get checksum String checksum = hexData[11]; Log.d(TAG, "Sensor ID: " + sensorID.toString() + ", Sensor Position: " + position + ", Temperature(" + temperatureUnit + "): " + String.valueOf(temp) + ", Pressure(" + pressureUnit + "): " + String.valueOf(pressure) + ", Voltage: " + String.valueOf(voltage) + ", Checksum: " + checksum + ", Data: " + sbhex.toString() + ", Bytes:" + msg.arg1); if (sensorID.toString().equals(prefFrontID)) { Log.d(TAG, "Front ID matched"); // Check for data logging enabled if (sharedPrefs.getBoolean("prefDataLogging", false)) { // Log data if (logger == null) { logger = new LogData(); } logger.write("front", String.valueOf(psi), String.valueOf(tempC), String.valueOf(voltage)); } // Set front tire status if (psi <= fLowPressure) { frontStatus = 1; } else if (psi >= fHighPressure) { frontStatus = 2; } else { frontStatus = 0; } txtFrontPressure .setText(String.valueOf(formattedPressure) + " " + pressureUnit); txtFrontTemperature.setText( String.valueOf(formattedTemperature) + " " + temperatureUnit); txtFrontVoltage.setText(String.format("%.2f", voltage) + " V"); } else if (sensorID.toString().equals(prefRearID)) { Log.d(TAG, "Rear ID matched"); // Check for data logging enabled if (sharedPrefs.getBoolean("prefDataLogging", false)) { // Log data if (logger == null) { logger = new LogData(); } logger.write("rear", String.valueOf(psi), String.valueOf(tempC), String.valueOf(voltage)); } // Set rear tire status if (psi <= rLowPressure) { rearStatus = 1; } else if (psi >= rHighPressure) { rearStatus = 2; } else { rearStatus = 0; } txtRearPressure .setText(String.valueOf(formattedPressure) + " " + pressureUnit); txtRearTemperature.setText( String.valueOf(formattedTemperature) + " " + temperatureUnit); txtRearVoltage.setText(String.format("%.2f", voltage) + " V"); } // Update txtOutput box and send notification if ((frontStatus == 0) && (rearStatus == 0)) { txtOutput.setText(""); if (notificationManager != null) { notificationManager.cancel(0); } } else if ((frontStatus == 1) && (rearStatus == 0)) { txtOutput .setText(getResources().getString(R.string.alert_lowFrontPressure)); Notify(getResources().getString(R.string.alert_lowFrontPressure)); } else if ((frontStatus == 2) && (rearStatus == 0)) { txtOutput.setText( getResources().getString(R.string.alert_highFrontPressure)); Notify(getResources().getString(R.string.alert_highFrontPressure)); } else if ((rearStatus == 1) && (frontStatus == 0)) { txtOutput.setText(getResources().getString(R.string.alert_lowRearPressure)); Notify(getResources().getString(R.string.alert_lowRearPressure)); } else if ((rearStatus == 2) && (frontStatus == 0)) { txtOutput .setText(getResources().getString(R.string.alert_highRearPressure)); Notify(getResources().getString(R.string.alert_highRearPressure)); } else if ((frontStatus == 1) && (rearStatus == 1)) { txtOutput.setText( getResources().getString(R.string.alert_lowFrontLowRearPressure)); Notify(getResources().getString(R.string.alert_lowFrontLowRearPressure)); } else if ((frontStatus == 2) && (rearStatus == 2)) { txtOutput.setText( getResources().getString(R.string.alert_highFrontHighRearPressure)); Notify(getResources().getString(R.string.alert_highFrontHighRearPressure)); } else if ((frontStatus == 1) && (rearStatus == 2)) { txtOutput.setText( getResources().getString(R.string.alert_lowFrontHighRearPressure)); Notify(getResources().getString(R.string.alert_lowFrontHighRearPressure)); } else if ((frontStatus == 2) && (rearStatus == 1)) { txtOutput.setText( getResources().getString(R.string.alert_highFrontLowRearPressure)); Notify(getResources().getString(R.string.alert_highFrontLowRearPressure)); } // Update color scheme if ((!itsDark) && (!sharedPrefs.getBoolean("prefNightMode", false))) { if (frontStatus == 0) { layoutFront.setBackground(background); } else { layoutFront.setBackground(redBackground); } if (rearStatus == 0) { layoutRear.setBackground(background); } else { layoutRear.setBackground(redBackground); } root.setBackgroundColor(getResources().getColor(android.R.color.white)); txtOutput.setBackground(txtOutBackground); txtOutput.setTextColor(getResources().getColor(android.R.color.black)); txtFrontPressure .setTextColor(getResources().getColor(android.R.color.black)); txtFrontTemperature .setTextColor(getResources().getColor(android.R.color.black)); txtFrontVoltage .setTextColor(getResources().getColor(android.R.color.black)); txtRearPressure .setTextColor(getResources().getColor(android.R.color.black)); txtRearTemperature .setTextColor(getResources().getColor(android.R.color.black)); txtRearVoltage.setTextColor(getResources().getColor(android.R.color.black)); } else { if (frontStatus == 0) { layoutFront.setBackground(backgroundDark); } else { layoutFront.setBackground(redBackgroundDark); } if (rearStatus == 0) { layoutRear.setBackground(backgroundDark); } else { layoutRear.setBackground(redBackgroundDark); } root.setBackgroundColor(getResources().getColor(android.R.color.black)); txtOutput.setBackground(txtOutBackgroundDark); txtOutput.setTextColor(getResources().getColor(android.R.color.white)); txtFrontPressure .setTextColor(getResources().getColor(android.R.color.white)); txtFrontTemperature .setTextColor(getResources().getColor(android.R.color.white)); txtFrontVoltage .setTextColor(getResources().getColor(android.R.color.white)); txtRearPressure .setTextColor(getResources().getColor(android.R.color.white)); txtRearTemperature .setTextColor(getResources().getColor(android.R.color.white)); txtRearVoltage.setTextColor(getResources().getColor(android.R.color.white)); } } catch (NumberFormatException e) { Log.d(TAG, "Malformed message, unexpected value"); } } } } else { Log.d(TAG, "Malformed message, message length: " + msg.arg1); } break; } } }; // Light Sensor Stuff SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); Sensor lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); if (lightSensor == null) { Log.d(TAG, "Light sensor not found"); } else { float max = lightSensor.getMaximumRange(); sensorManager.registerListener(lightSensorEventListener, lightSensor, SensorManager.SENSOR_DELAY_NORMAL); hasSensor = true; Log.d(TAG, "Light Sensor Max Value: " + max); } // Try to connect to iTPMSystem btConnect(); }
From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.BusStopDetailsFragment.java
/** * Start the sensors used to measure device magnetic orientation. *//*from ww w. j a v a2 s.c o m*/ private void startOrientationSensors() { // Only use the sensors when both the magnetometer and the accelerometer // are available. if (magnetometer != null && accelerometer != null) { sensMan.registerListener(this, magnetometer, SensorManager.SENSOR_DELAY_NORMAL); sensMan.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL); } }
From source file:com.kircherelectronics.accelerationfilter.activity.AccelerationPlotActivity.java
/** * Set the sensor delay based on user preferences. 0 = slow, 1 = medium, 2 = * fast./*from w w w .ja v a 2 s . com*/ * * @param position * The desired sensor delay. */ private void setSensorDelay(int position) { switch (position) { case 0: sensorManager.unregisterListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)); // Register for sensor updates. sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); break; case 1: sensorManager.unregisterListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)); // Register for sensor updates. sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_GAME); break; case 2: sensorManager.unregisterListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)); // Register for sensor updates. sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_FASTEST); break; } lpf.reset(); meanFilter.reset(); }
From source file:co.taqat.call.CallActivity.java
private void enableProximitySensing(boolean enable) { if (enable) { if (!mProximitySensingEnabled) { mSensorManager.registerListener(this, mProximity, SensorManager.SENSOR_DELAY_NORMAL); mProximitySensingEnabled = true; }//from w w w . j a v a 2s.c o m } else { if (mProximitySensingEnabled) { mSensorManager.unregisterListener(this); mProximitySensingEnabled = false; // Don't forgeting to release wakelock if held if (wakeLock.isHeld()) { wakeLock.release(); } } } }
From source file:com.ichi2.anki2.Reviewer.java
@Override protected void onResume() { mInBackground = false;//w ww . j a va 2s . c o m super.onResume(); // Decks deck = DeckManager.getMainDeck(); // if (deck == null) { // Log.e(AnkiDroidApp.TAG, "Reviewer: Deck already closed, returning to study options"); // closeReviewer(RESULT_DECK_CLOSED, false); // return; // } // check if deck is already opened in big widget. If yes, reload card (to make sure it's not answered yet) // if (DeckManager.deckIsOpenedInBigWidget(deck.getDeckPath()) && mCurrentCard != null && !mInEditor) { // Log.i(AnkiDroidApp.TAG, "Reviewer: onResume: get card from big widget"); // blockControls(); // AnkiDroidWidgetBig.updateWidget(AnkiDroidWidgetBig.UpdateService.VIEW_NOT_SPECIFIED, true); // DeckTask.launchDeckTask(DeckTask.TASK_TYPE_ANSWER_CARD, mAnswerCardHandler, new DeckTask.TaskData(0, deck, // null)); // } else { restartTimer(); // } // if (mShakeEnabled) { mSensorManager.registerListener(mSensorListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); } }
From source file:com.hichinaschool.flashcards.anki.Reviewer.java
@Override protected void onResume() { mInBackground = false;//from ww w. j av a 2 s .c om super.onResume(); // Decks deck = DeckManager.getMainDeck(); // if (deck == null) { // Log.e(AnkiDroidApp.TAG, "Reviewer: Deck already closed, returning to study options"); // closeReviewer(RESULT_DECK_CLOSED, false); // return; // } // check if deck is already opened in big widget. If yes, reload card (to make sure it's not answered yet) // if (DeckManager.deckIsOpenedInBigWidget(deck.getDeckPath()) && mCurrentCard != null && !mInEditor) { // // Log.i(AnkiDroidApp.TAG, "Reviewer: onResume: get card from big widget"); // blockControls(); // AnkiDroidWidgetBig.updateWidget(AnkiDroidWidgetBig.UpdateService.VIEW_NOT_SPECIFIED, true); // DeckTask.launchDeckTask(DeckTask.TASK_TYPE_ANSWER_CARD, mAnswerCardHandler, new DeckTask.TaskData(0, deck, // null)); // } else { restartTimer(); // } // if (mShakeEnabled) { mSensorManager.registerListener(mSensorListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); } }