List of usage examples for android.hardware Sensor TYPE_PROXIMITY
int TYPE_PROXIMITY
To view the source code for android.hardware Sensor TYPE_PROXIMITY.
Click Source Link
From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.fragments.GraphPlotFragment.java
private void updateTitleAndType() { ArrayList<String> grpTitle = new ArrayList<String>(); ArrayList<Integer> grpType = new ArrayList<Integer>(); ArrayList<Boolean> grpBarType = new ArrayList<Boolean>(); SharedPreferences pref = PreferenceManager .getDefaultSharedPreferences(getActivity().getApplicationContext()); if (pref.getBoolean(getResources().getString(R.string.in_hum), false)) { grpTitle.add("Humidity"); grpType.add(Sensor.TYPE_RELATIVE_HUMIDITY); grpBarType.add(false);/*from w w w . j a v a 2s . co m*/ } if (pref.getBoolean(getResources().getString(R.string.in_lig), false)) { grpTitle.add("Light in lux/min"); grpType.add(Sensor.TYPE_LIGHT); grpBarType.add(false); } if (pref.getBoolean(getResources().getString(R.string.in_pres), false)) { grpTitle.add("Pressure in min"); grpType.add(Sensor.TYPE_PRESSURE); grpBarType.add(false); } if (pref.getBoolean(getResources().getString(R.string.in_prox), false)) { grpTitle.add("Proximity in min"); grpType.add(Sensor.TYPE_PROXIMITY); grpBarType.add(false); } if (pref.getBoolean(getResources().getString(R.string.in_tem), false)) { grpTitle.add("Ambient Temperature in C"); grpType.add(Sensor.TYPE_AMBIENT_TEMPERATURE); grpBarType.add(false); } if (pref.getBoolean(getResources().getString(R.string.pulse), false)) { grpTitle.add("Heart Rate bpm"); grpType.add(999); grpBarType.add(false); } if (pref.getBoolean(getResources().getString(R.string.in_acc), false)) { grpTitle.add("Motion Strength/min"); grpType.add(Sensor.TYPE_ACCELEROMETER); grpBarType.add(true); } if (pref.getBoolean(getResources().getString(R.string.in_mag), false)) { grpTitle.add("Magnetic Field Strength/min"); grpType.add(Sensor.TYPE_MAGNETIC_FIELD); grpBarType.add(true); } if (pref.getBoolean(getResources().getString(R.string.in_grav), false)) { grpTitle.add("Gravity Strength/min"); grpType.add(Sensor.TYPE_GRAVITY); grpBarType.add(true); } if (pref.getBoolean(getResources().getString(R.string.in_gyrs), false)) { grpTitle.add("Gyroscope Strength/min"); grpType.add(Sensor.TYPE_GYROSCOPE); grpBarType.add(true); } if (pref.getBoolean(getResources().getString(R.string.in_lin_acc), false)) { grpTitle.add("Linear Accelerometer Strength/min"); grpType.add(Sensor.TYPE_LINEAR_ACCELERATION); grpBarType.add(true); } if (grpTitle.size() == 2 && grpType.size() == 2) { firstGrpTitle = grpTitle.get(0); firstGrpType = grpType.get(0); isFirstBar = grpBarType.get(0); secondGrpTitle = grpTitle.get(1); secondGrpType = grpType.get(1); isSecondBar = grpBarType.get(1); } else if (grpTitle.size() == 1 && grpType.size() == 1) { firstGrpTitle = grpTitle.get(0); firstGrpType = grpType.get(0); isFirstBar = grpBarType.get(0); secondGrpTitle = ""; secondGrpType = -1; } }
From source file:co.taqat.call.CallActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); instance = this; if (getResources().getBoolean(R.bool.orientation_portrait_only)) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); }/* w w w . j a v a2 s.c o m*/ getWindow().addFlags( WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); setContentView(R.layout.call); isTransferAllowed = getApplicationContext().getResources().getBoolean(R.bool.allow_transfers); if (!BluetoothManager.getInstance().isBluetoothHeadsetAvailable()) { BluetoothManager.getInstance().initBluetooth(); } cameraNumber = AndroidCameraConfiguration.retrieveCameras().length; try { // Yeah, this is hidden field. field = PowerManager.class.getClass().getField("PROXIMITY_SCREEN_OFF_WAKE_LOCK").getInt(null); } catch (Throwable ignored) { } powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = powerManager.newWakeLock(field, getLocalClassName()); mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mProximity = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); mListener = new LinphoneCoreListenerBase() { @Override public void messageReceived(LinphoneCore lc, LinphoneChatRoom cr, LinphoneChatMessage message) { displayMissedChats(); } @Override public void callState(LinphoneCore lc, final LinphoneCall call, LinphoneCall.State state, String message) { if (LinphoneManager.getLc().getCallsNb() == 0) { finish(); return; } if (state == State.IncomingReceived) { startIncomingCallActivity(); return; } else if (state == State.Paused || state == State.PausedByRemote || state == State.Pausing) { if (LinphoneManager.getLc().getCurrentCall() != null) { enabledVideoButton(false); } if (isVideoEnabled(call)) { showAudioView(); } } else if (state == State.Resuming) { if (LinphonePreferences.instance().isVideoEnabled()) { status.refreshStatusItems(call, isVideoEnabled(call)); if (call.getCurrentParamsCopy().getVideoEnabled()) { showVideoView(); } } if (LinphoneManager.getLc().getCurrentCall() != null) { enabledVideoButton(true); } } else if (state == State.StreamsRunning) { switchVideo(isVideoEnabled(call)); enableAndRefreshInCallActions(); if (status != null) { videoProgress.setVisibility(View.GONE); status.refreshStatusItems(call, isVideoEnabled(call)); } } else if (state == State.CallUpdatedByRemote) { // If the correspondent proposes video while audio call boolean videoEnabled = LinphonePreferences.instance().isVideoEnabled(); if (!videoEnabled) { acceptCallUpdate(false); } boolean remoteVideo = call.getRemoteParams().getVideoEnabled(); boolean localVideo = call.getCurrentParamsCopy().getVideoEnabled(); boolean autoAcceptCameraPolicy = true;//LinphonePreferences.instance().shouldAutomaticallyAcceptVideoRequests(); if (remoteVideo && !localVideo && !autoAcceptCameraPolicy && !LinphoneManager.getLc().isInConference()) { showAcceptCallUpdateDialog(); timer = new CountDownTimer(SECONDS_BEFORE_DENYING_CALL_UPDATE, 1000) { public void onTick(long millisUntilFinished) { } public void onFinish() { //TODO dismiss dialog acceptCallUpdate(false); } }.start(); /*showAcceptCallUpdateDialog(); timer = new CountDownTimer(SECONDS_BEFORE_DENYING_CALL_UPDATE, 1000) { public void onTick(long millisUntilFinished) { } public void onFinish() { //TODO dismiss dialog } }.start();*/ } // else if (remoteVideo && !LinphoneManager.getLc().isInConference() && autoAcceptCameraPolicy) { // mHandler.post(new Runnable() { // @Override // public void run() { // acceptCallUpdate(true); // } // }); // } } refreshIncallUi(); transfer.setEnabled(LinphoneManager.getLc().getCurrentCall() != null); } @Override public void callEncryptionChanged(LinphoneCore lc, final LinphoneCall call, boolean encrypted, String authenticationToken) { if (status != null) { if (call.getCurrentParamsCopy().getMediaEncryption().equals(LinphoneCore.MediaEncryption.ZRTP) && !call.isAuthenticationTokenVerified()) { status.showZRTPDialog(call); } status.refreshStatusItems(call, call.getCurrentParamsCopy().getVideoEnabled()); } } }; if (findViewById(R.id.fragmentContainer) != null) { initUI(); if (LinphoneManager.getLc().getCallsNb() > 0) { LinphoneCall call = LinphoneManager.getLc().getCalls()[0]; if (LinphoneUtils.isCallEstablished(call)) { enableAndRefreshInCallActions(); } } if (savedInstanceState != null) { // Fragment already created, no need to create it again (else it will generate a memory leak with duplicated fragments) isSpeakerEnabled = savedInstanceState.getBoolean("Speaker"); isMicMuted = savedInstanceState.getBoolean("Mic"); isVideoCallPaused = savedInstanceState.getBoolean("VideoCallPaused"); refreshInCallActions(); return; } else { isSpeakerEnabled = LinphoneManager.getLc().isSpeakerEnabled(); isMicMuted = LinphoneManager.getLc().isMicMuted(); } Fragment callFragment; if (isVideoEnabled(LinphoneManager.getLc().getCurrentCall())) { callFragment = new CallVideoFragment(); videoCallFragment = (CallVideoFragment) callFragment; displayVideoCall(false); LinphoneManager.getInstance().routeAudioToSpeaker(); isSpeakerEnabled = true; } else { callFragment = new CallAudioFragment(); audioCallFragment = (CallAudioFragment) callFragment; } if (BluetoothManager.getInstance().isBluetoothHeadsetAvailable()) { BluetoothManager.getInstance().routeAudioToBluetooth(); } callFragment.setArguments(getIntent().getExtras()); getFragmentManager().beginTransaction().add(R.id.fragmentContainer, callFragment) .commitAllowingStateLoss(); } }
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);/*w w w.j a v a 2 s. co m*/ }
From source file:ch.bfh.sensordataprocessor.sensor.SensorDisplayFragment.java
/** * @see android.hardware.SensorEventListener#onSensorChanged(android.hardware.SensorEvent) *///from w w w. j a v a2 s .c o m @Override public void onSensorChanged(SensorEvent event) { onAccuracyChanged(event.sensor, event.accuracy); timestampLabel.setVisibility(View.VISIBLE); timestamp.setVisibility(View.VISIBLE); timestamp.setText(String.valueOf(event.timestamp)); timestampUnits.setVisibility(View.VISIBLE); switch (event.sensor.getType()) { case Sensor.TYPE_ACCELEROMETER: showEventData("Acceleration - gravity on axis", ACCELERATION_UNITS, event.values[0], event.values[1], event.values[2]); break; case Sensor.TYPE_MAGNETIC_FIELD: showEventData("Abient Magnetic Field", "uT", event.values[0], event.values[1], event.values[2]); break; case Sensor.TYPE_GYROSCOPE: showEventData("Angular speed around axis", "radians/sec", event.values[0], event.values[1], event.values[2]); break; case Sensor.TYPE_LIGHT: showEventData("Ambient light", "lux", event.values[0]); break; case Sensor.TYPE_PRESSURE: showEventData("Atmospheric pressure", "hPa", event.values[0]); break; case Sensor.TYPE_PROXIMITY: showEventData("Distance", "cm", event.values[0]); break; case Sensor.TYPE_GRAVITY: showEventData("Gravity", ACCELERATION_UNITS, event.values[0], event.values[1], event.values[2]); break; case Sensor.TYPE_LINEAR_ACCELERATION: showEventData("Acceleration (not including gravity)", ACCELERATION_UNITS, event.values[0], event.values[1], event.values[2]); break; case Sensor.TYPE_ROTATION_VECTOR: showEventData("Rotation Vector", null, event.values[0], event.values[1], event.values[2]); xAxisLabel.setText("x*sin(" + THETA + "/2)"); yAxisLabel.setText("y*sin(" + THETA + "/2)"); zAxisLabel.setText("z*sin(" + THETA + "/2)"); if (event.values.length == 4) { cosLabel.setVisibility(View.VISIBLE); cos.setVisibility(View.VISIBLE); cos.setText(String.valueOf(event.values[3])); } break; case Sensor.TYPE_ORIENTATION: showEventData("Angle", "Degrees", event.values[0], event.values[1], event.values[2]); xAxisLabel.setText(R.string.azimuthLabel); yAxisLabel.setText(R.string.pitchLabel); zAxisLabel.setText(R.string.rollLabel); break; case Sensor.TYPE_RELATIVE_HUMIDITY: showEventData("Relatice ambient air humidity", "%", event.values[0]); break; case Sensor.TYPE_AMBIENT_TEMPERATURE: showEventData("Ambien temperature", "degree Celcius", event.values[0]); break; } }
From source file:com.achep.acdisplay.services.activemode.sensors.ProximitySensor.java
@Override public int getType() { return Sensor.TYPE_PROXIMITY; }
From source file:it.unime.mobility4ckan.MainActivity.java
private void createListView() { overviewList.clear();//www . j a va 2 s . c o m Overview overviewTitle = new Overview(getApplicationContext()); overviewTitle.setSensorName("Nome Sensore"); overviewTitle.setCurrentValue("Valore Corrente"); overviewTitle.setValueSend("Valore Inviato"); overviewList.add(overviewTitle); Overview overview0 = new Overview(getApplicationContext()); overview0.setSensorName("Speed"); overview0.setCurrentValue("" + mySensor.getCurrentSpeed()); overview0.setValueSend(lastSpeedValue); overviewList.add(overview0); for (int k = 0; k < sensorList.size(); k++) { Overview overview = new Overview(getApplicationContext()); switch (sensorList.get(k).getType()) { case Sensor.TYPE_AMBIENT_TEMPERATURE: // Gradi Celsius (C) overview.setSensorName("Temperature"); overview.setCurrentValue("" + mySensor.getCurrentTemp()); overview.setValueSend(lastTempValue); overviewList.add(overview); break; case Sensor.TYPE_PRESSURE: overview.setSensorName("Pressure"); overview.setCurrentValue("" + mySensor.getCurrentPressure()); overview.setValueSend(lastPressureValue); overviewList.add(overview); break; case Sensor.TYPE_LIGHT: // lx overview.setSensorName("Light"); overview.setCurrentValue("" + mySensor.getCurrentLight()); overview.setValueSend(lastLightValue); overviewList.add(overview); break; case Sensor.TYPE_ACCELEROMETER: // m/s2 overview.setSensorName("Accelerometer"); overview.setCurrentValue("" + mySensor.getCurrentAcceleration()); overview.setValueSend(lastAccelerationValue); overviewList.add(overview); break; case Sensor.TYPE_GYROSCOPE: // rad/s overview.setSensorName("Gyroscope"); overview.setCurrentValue("" + mySensor.getCurrentGyroscope()); overview.setValueSend(lastGyroscopeValue); overviewList.add(overview); break; case Sensor.TYPE_MAGNETIC_FIELD: // T overview.setSensorName("Magnetic Field"); overview.setCurrentValue("" + mySensor.getCurrentMagnetic()); overview.setValueSend(lastMagneticValue); overviewList.add(overview); break; case Sensor.TYPE_PROXIMITY: // cm overview.setSensorName("Proximity"); overview.setCurrentValue("" + mySensor.getCurrentProximity()); overview.setValueSend(lastProximityValue); overviewList.add(overview); break; case Sensor.TYPE_ROTATION_VECTOR: // unita di misura sconosciuta overview.setSensorName("Rotation Vector"); overview.setCurrentValue("" + mySensor.getCurrentRotation()); overview.setValueSend(lastRotationValue); overviewList.add(overview); break; case Sensor.TYPE_GRAVITY: // m/s2 overview.setSensorName("Gravity"); overview.setCurrentValue("" + mySensor.getCurrentGravity()); overview.setValueSend(lastGravityValue); overviewList.add(overview); break; case Sensor.TYPE_LINEAR_ACCELERATION: // m/s2 overview.setSensorName("Linear Acceleration"); overview.setCurrentValue("" + mySensor.getCurrentLinearAcceleration()); overview.setValueSend(lastLinearAccelerationValue); overviewList.add(overview); break; case Sensor.TYPE_RELATIVE_HUMIDITY: // % overview.setSensorName("Relative Humidity"); overview.setCurrentValue("" + mySensor.getCurrentHumidity()); overview.setValueSend(lastRelativeHumidity); overviewList.add(overview); break; default: break; } } listView.setAdapter(new OverviewAdapter(getApplicationContext(), overviewList)); }
From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.InternalSensorService.java
@Override public void onSensorChanged(SensorEvent event) { if (pref == null) pref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); int mSensorType = event.sensor.getType(); if (mSensorType == Sensor.TYPE_ACCELEROMETER) { int x = Math.round(event.values[0]); int y = Math.round(event.values[1]); int z = Math.round(event.values[2]); // using ACCELEROMETER_KNEE only as a demonstration, // in practice new event can be created AccDeviceSensorEvent accEvt = new AccDeviceSensorEvent("eventID", getTimestamp(), "producerID", SensorReadingEvent.ACCELEROMETER_ON_DEVICE, getTimestamp(), x, y, z, x, y, z); sendToChannel(accEvt, AbstractChannel.RECEIVER); // for external // apps//from ww w .j ava 2s . com // subscription gotAccEvent(getTimestamp(), Sensor.TYPE_ACCELEROMETER, x, y, z); // for // on device // graphViews // using } else if (mSensorType == Sensor.TYPE_LIGHT) { float x = event.values[0]; // using ambientLightEvent only as a demonstration, // in practice new event can be created AmbientLightEvent lightEvnt = new AmbientLightEvent("eventID", getTimestamp(), "producerID", SensorReadingEvent.AMBIENT_LIGHT, getTimestamp(), "location", "object", x, AmbientLightEvent.UNIT_LUX); sendToChannel(lightEvnt, AbstractChannel.RECEIVER); gotLightEvent(getTimestamp(), Sensor.TYPE_LIGHT, x); } else if (mSensorType == Sensor.TYPE_PRESSURE) { float x = event.values[0]; AmbientPressureEvent temEvnt = new AmbientPressureEvent("eventID", getTimestamp(), "producerID", SensorReadingEvent.AMBIENT_PRESSURE, getTimestamp(), "location", "object", x, AmbientPressureEvent.UNIT_HPA); sendToChannel(temEvnt, AbstractChannel.RECEIVER); gotLightEvent(getTimestamp(), Sensor.TYPE_PRESSURE, x); } else if (mSensorType == Sensor.TYPE_PROXIMITY) { float x = event.values[0]; ProximityEvent evnt = new ProximityEvent("eventID", getTimestamp(), "producerID", SensorReadingEvent.PROXIMITY, getTimestamp(), "location", "object", x, ""); sendToChannel(evnt, AbstractChannel.RECEIVER); gotLightEvent(getTimestamp(), Sensor.TYPE_PROXIMITY, x); } else if (mSensorType == Sensor.TYPE_AMBIENT_TEMPERATURE) { float x = event.values[0]; TemperatureEvent evnt = new TemperatureEvent("eventID", getTimestamp(), "producerID", SensorReadingEvent.ROOM_TEMPERATURE, getTimestamp(), "location", "object", x, TemperatureEvent.UNIT_CELSIUS); sendToChannel(evnt, AbstractChannel.RECEIVER); gotLightEvent(getTimestamp(), Sensor.TYPE_AMBIENT_TEMPERATURE, x); } else if (mSensorType == Sensor.TYPE_RELATIVE_HUMIDITY) { float x = event.values[0]; HumidityEvent evnt = new HumidityEvent("eventID", getTimestamp(), "producerID", SensorReadingEvent.HUMIDITY, getTimestamp(), "location", "object", x); sendToChannel(evnt, AbstractChannel.RECEIVER); gotLightEvent(getTimestamp(), Sensor.TYPE_RELATIVE_HUMIDITY, x); } else if (mSensorType == Sensor.TYPE_GYROSCOPE) { int x = Math.round(event.values[0]); int y = Math.round(event.values[1]); int z = Math.round(event.values[2]); GyroscopeSensorEvent gSEvnt = new GyroscopeSensorEvent("eventID", getTimestamp(), "producerID", SensorReadingEvent.GYROSCOPE, getTimestamp(), x, y, z, x, y, z); sendToChannel(gSEvnt, AbstractChannel.RECEIVER); gotAccEvent(getTimestamp(), Sensor.TYPE_GYROSCOPE, x, y, z); } else if (mSensorType == Sensor.TYPE_MAGNETIC_FIELD) { int x = Math.round(event.values[0]); int y = Math.round(event.values[1]); int z = Math.round(event.values[2]); MagneticSensorEvent gSEvnt = new MagneticSensorEvent("eventID", getTimestamp(), "producerID", SensorReadingEvent.MAGNETIC_FIELD, getTimestamp(), x, y, z, x, y, z); sendToChannel(gSEvnt, AbstractChannel.RECEIVER); gotAccEvent(getTimestamp(), Sensor.TYPE_MAGNETIC_FIELD, x, y, z); } else if (mSensorType == Sensor.TYPE_LINEAR_ACCELERATION) { int x = Math.round(event.values[0]); int y = Math.round(event.values[1]); int z = Math.round(event.values[2]); // using ACCELEROMETER_KNEE only as a demonstration, // in practice new event can be created AccDeviceSensorEvent accEvt = new AccDeviceSensorEvent("eventID", getTimestamp(), "producerID", SensorReadingEvent.ACCELEROMETER_ON_DEVICE, getTimestamp(), x, y, z, x, y, z); sendToChannel(accEvt, AbstractChannel.RECEIVER); gotAccEvent(getTimestamp(), Sensor.TYPE_LINEAR_ACCELERATION, x, y, z); } }
From source file:com.vonglasow.michael.satstat.SensorSectionFragment.java
/** * Called by {@link MainActivity} when a sensor's reading changes. Updates sensor display. */// w ww . ja v a 2 s . c o m public void onSensorChanged(SensorEvent event) { switch (event.sensor.getType()) { case Sensor.TYPE_ACCELEROMETER: accX.setText(String.format("%." + mAccSensorRes + "f", event.values[0])); accY.setText(String.format("%." + mAccSensorRes + "f", event.values[1])); accZ.setText(String.format("%." + mAccSensorRes + "f", event.values[2])); accTotal.setText(String.format("%." + mAccSensorRes + "f", Math.sqrt( Math.pow(event.values[0], 2) + Math.pow(event.values[1], 2) + Math.pow(event.values[2], 2)))); accStatus.setTextColor(getResources().getColor(accuracyToColor(event.accuracy))); break; case Sensor.TYPE_ORIENTATION: orAzimuth.setText(String.format("%.0f%s", event.values[0], getString(R.string.unit_degree))); orAziText.setText(MainActivity.formatOrientation(this.getContext(), event.values[0])); orPitch.setText(String.format("%.0f%s", event.values[1], getString(R.string.unit_degree))); orRoll.setText(String.format("%.0f%s", event.values[2], getString(R.string.unit_degree))); orStatus.setTextColor(getResources().getColor(accuracyToColor(event.accuracy))); break; case Sensor.TYPE_GYROSCOPE: rotX.setText(String.format("%." + mGyroSensorRes + "f", event.values[0])); rotY.setText(String.format("%." + mGyroSensorRes + "f", event.values[1])); rotZ.setText(String.format("%." + mGyroSensorRes + "f", event.values[2])); rotTotal.setText(String.format("%." + mGyroSensorRes + "f", Math.sqrt( Math.pow(event.values[0], 2) + Math.pow(event.values[1], 2) + Math.pow(event.values[2], 2)))); rotStatus.setTextColor(getResources().getColor(accuracyToColor(event.accuracy))); break; case Sensor.TYPE_MAGNETIC_FIELD: magX.setText(String.format("%." + mMagSensorRes + "f", event.values[0])); magY.setText(String.format("%." + mMagSensorRes + "f", event.values[1])); magZ.setText(String.format("%." + mMagSensorRes + "f", event.values[2])); magTotal.setText(String.format("%." + mMagSensorRes + "f", Math.sqrt( Math.pow(event.values[0], 2) + Math.pow(event.values[1], 2) + Math.pow(event.values[2], 2)))); magStatus.setTextColor(getResources().getColor(accuracyToColor(event.accuracy))); break; case Sensor.TYPE_LIGHT: light.setText(String.format("%." + mLightSensorRes + "f", event.values[0])); lightStatus.setTextColor(getResources().getColor(accuracyToColor(event.accuracy))); break; case Sensor.TYPE_PROXIMITY: proximity.setText(String.format("%." + mProximitySensorRes + "f", event.values[0])); proximityStatus.setTextColor(getResources().getColor(accuracyToColor(event.accuracy))); break; case Sensor.TYPE_PRESSURE: metPressure.setText(String.format("%." + mPressureSensorRes + "f", event.values[0])); pressureStatus.setTextColor(getResources().getColor(accuracyToColor(event.accuracy))); break; case Sensor.TYPE_RELATIVE_HUMIDITY: metHumid.setText(String.format("%." + mHumiditySensorRes + "f", event.values[0])); humidStatus.setTextColor(getResources().getColor(accuracyToColor(event.accuracy))); break; case Sensor.TYPE_AMBIENT_TEMPERATURE: metTemp.setText(String.format("%." + mTempSensorRes + "f", event.values[0])); tempStatus.setTextColor(getResources().getColor(accuracyToColor(event.accuracy))); break; } }
From source file:org.deviceconnect.android.deviceplugin.host.HostDeviceService.java
/** * Promity Profile<br>//from w w w . j ava 2s . 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.ferdi2005.secondgram.voip.VoIPService.java
@Override public void onDestroy() { FileLog.d("=============== VoIPService STOPPING ==============="); stopForeground(true);// w ww. j a v a2s .c o m stopRinging(); NotificationCenter.getInstance().removeObserver(this, NotificationCenter.appDidLogout); SensorManager sm = (SensorManager) getSystemService(SENSOR_SERVICE); Sensor proximity = sm.getDefaultSensor(Sensor.TYPE_PROXIMITY); if (proximity != null) { sm.unregisterListener(this); } if (proximityWakelock != null && proximityWakelock.isHeld()) { proximityWakelock.release(); } unregisterReceiver(receiver); if (timeoutRunnable != null) { AndroidUtilities.cancelRunOnUIThread(timeoutRunnable); timeoutRunnable = null; } super.onDestroy(); sharedInstance = null; AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { NotificationCenter.getInstance().postNotificationName(NotificationCenter.didEndedCall); } }); if (controller != null && controllerStarted) { lastKnownDuration = controller.getCallDuration(); updateStats(); StatsController.getInstance().incrementTotalCallsTime(getStatsNetworkType(), (int) (lastKnownDuration / 1000) % 5); if (needSendDebugLog) { String debugLog = controller.getDebugLog(); TLRPC.TL_phone_saveCallDebug req = new TLRPC.TL_phone_saveCallDebug(); req.debug = new TLRPC.TL_dataJSON(); req.debug.data = debugLog; req.peer = new TLRPC.TL_inputPhoneCall(); req.peer.access_hash = call.access_hash; req.peer.id = call.id; ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { @Override public void run(TLObject response, TLRPC.TL_error error) { FileLog.d("Sent debug logs, response=" + response); } }); } controller.release(); controller = null; } cpuWakelock.release(); AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE); if (isBtHeadsetConnected && !playingSound) am.stopBluetoothSco(); am.setMode(AudioManager.MODE_NORMAL); am.unregisterMediaButtonEventReceiver(new ComponentName(this, VoIPMediaButtonReceiver.class)); if (haveAudioFocus) am.abandonAudioFocus(this); if (!playingSound) soundPool.release(); ConnectionsManager.getInstance().setAppPaused(true, false); }