use of android.hardware.SensorEventListener in project android_frameworks_base by ResurrectionRemix.
the class PowerManagerService method runPostProximityCheck.
private void runPostProximityCheck(final Runnable r) {
if (mSensorManager == null) {
r.run();
return;
}
synchronized (mProximityWakeLock) {
mProximityWakeLock.acquire();
mProximityListener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
cleanupProximityLocked();
if (!mHandler.hasMessages(MSG_WAKE_UP)) {
Slog.w(TAG, "Proximity sensor took too long, wake event already triggered!");
return;
}
mHandler.removeMessages(MSG_WAKE_UP);
final float distance = event.values[0];
if (distance >= PROXIMITY_NEAR_THRESHOLD || distance >= mProximitySensor.getMaximumRange()) {
r.run();
} else {
Slog.w(TAG, "Not waking up. Proximity sensor is blocked.");
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// Do nothing
}
};
mSensorManager.registerListener(mProximityListener, mProximitySensor, SensorManager.SENSOR_DELAY_FASTEST);
}
}
use of android.hardware.SensorEventListener in project android_frameworks_base by crdroidandroid.
the class PowerManagerService method runPostProximityCheck.
private void runPostProximityCheck(final Runnable r) {
if (mSensorManager == null) {
r.run();
return;
}
synchronized (mProximityWakeLock) {
mProximityWakeLock.acquire();
mProximityListener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
cleanupProximityLocked();
if (!mHandler.hasMessages(MSG_WAKE_UP)) {
Slog.w(TAG, "Proximity sensor took too long, wake event already triggered!");
return;
}
mHandler.removeMessages(MSG_WAKE_UP);
final float distance = event.values[0];
if (distance >= PROXIMITY_NEAR_THRESHOLD || distance >= mProximitySensor.getMaximumRange()) {
r.run();
} else {
Slog.w(TAG, "Not waking up. Proximity sensor is blocked.");
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// Do nothing
}
};
mSensorManager.registerListener(mProximityListener, mProximitySensor, SensorManager.SENSOR_DELAY_FASTEST);
}
}
use of android.hardware.SensorEventListener in project HAR-Android by linw7.
the class StepActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_step);
total_step = (TextView) findViewById(R.id.total_step);
current_step = (TextView) findViewById(R.id.current_step);
energy_step = (TextView) findViewById(R.id.energy_step);
distance_step = (TextView) findViewById(R.id.distance_step);
circular_button = (CircularProgressButton) findViewById(R.id.circular_button);
final SensorEventListener step_listener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
if (sensorEvent.sensor.getType() == Sensor.TYPE_STEP_COUNTER) {
if (new_start == false) {
new_start = true;
cur_step = (int) (sensorEvent.values[0]);
}
mCount = sensorEvent.values[0];
}
if (sensorEvent.sensor.getType() == Sensor.TYPE_STEP_DETECTOR) {
if (sensorEvent.values[0] == 1.0) {
mDetector = mDetector + 1;
}
}
}
@Override
public // 传感器精度改变时调用
void onAccuracyChanged(Sensor sensor, int i) {
}
};
mCount = 0;
mDetector = 0;
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mStepCount = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
mStepDetector = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR);
mSensorManager.registerListener(step_listener, mStepCount, SensorManager.SENSOR_DELAY_FASTEST);
mSensorManager.registerListener(step_listener, mStepDetector, SensorManager.SENSOR_DELAY_FASTEST);
circular_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!runable) {
runable = true;
circular_button.setIndeterminateProgressMode(true);
for (int i = 1; i < 100; i++) circular_button.setProgress(i);
timer.schedule(display_task, 0, 100);
circular_button.setProgress(100);
} else {
new AlertDialog.Builder(StepActivity.this).setTitle("请确认").setMessage("您正在处于步数监测状态,是否退出?").setPositiveButton(R.string.AlertDialog_yes, null).setNegativeButton(R.string.AlertDialog_no, null).show();
}
}
});
}
use of android.hardware.SensorEventListener in project HAR-Android by linw7.
the class StepMainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_step_main);
total_step = (TextView) findViewById(R.id.total_step);
current_step = (TextView) findViewById(R.id.current_step);
energy_step = (TextView) findViewById(R.id.energy_step);
distance_step = (TextView) findViewById(R.id.distance_step);
circular_button = (CircularProgressButton) findViewById(R.id.circular_button);
progress_step = (ProgressBar) findViewById(R.id.progress_step);
progress_energy = (ProgressBar) findViewById(R.id.progress_energy);
progress_step_text = (TextView) findViewById(R.id.progress_step_text);
progress_energy_text = (TextView) findViewById(R.id.progress_energy_text);
progressView = (CircularProgressView) findViewById(R.id.progress_view);
target_step = (TextView) findViewById(R.id.target_step);
target_energy = (TextView) findViewById(R.id.target_energy);
text_step = (TextView) findViewById(R.id.text_step);
text_energy = (TextView) findViewById(R.id.text_energy);
runable = false;
circular_button.setIndeterminateProgressMode(true);
// 设置目标
target_step.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog dialog = new AlertDialog.Builder(StepMainActivity.this).setTitle("请设置步数目标").setIcon(R.drawable.logo_activity).setSingleChoiceItems(STEP, -1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(StepMainActivity.this, STEP[which], Toast.LENGTH_SHORT).show();
if (which == 0)
set_step = 2000;
else if (which == 1)
set_step = 4000;
else if (which == 2)
set_step = 6000;
else if (which == 3)
set_step = 8000;
else if (which == 4)
set_step = 10000;
set_step = 100;
Log.i("step", "设置步数:" + set_step);
dialog.dismiss();
}
}).create();
dialog.show();
}
});
// 设置能量目标
target_energy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog dialog = new AlertDialog.Builder(StepMainActivity.this).setTitle("请设置卡路里目标").setIcon(R.drawable.logo_activity).setSingleChoiceItems(ENERGY, -1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(StepMainActivity.this, ENERGY[which], Toast.LENGTH_SHORT).show();
if (which == 0)
set_energy = 300;
else if (which == 1)
set_energy = 600;
else if (which == 2)
set_energy = 900;
else if (which == 3)
set_energy = 1200;
else if (which == 4)
set_energy = 1500;
set_energy = 6;
dialog.dismiss();
}
}).create();
dialog.show();
}
});
// 传感器
final SensorEventListener step_listener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
if (sensorEvent.sensor.getType() == Sensor.TYPE_STEP_COUNTER) {
if (new_start == false) {
new_start = true;
cur_step = (int) (sensorEvent.values[0]);
}
mCount = sensorEvent.values[0];
}
if (sensorEvent.sensor.getType() == Sensor.TYPE_STEP_DETECTOR) {
if (sensorEvent.values[0] == 1.0) {
mDetector = mDetector + 1;
}
}
}
@Override
public // 传感器精度改变时调用
void onAccuracyChanged(Sensor sensor, int i) {
}
};
mCount = 0;
mDetector = 0;
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mStepCount = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
mStepDetector = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR);
mSensorManager.registerListener(step_listener, mStepCount, SensorManager.SENSOR_DELAY_FASTEST);
mSensorManager.registerListener(step_listener, mStepDetector, SensorManager.SENSOR_DELAY_FASTEST);
timer.schedule(display_task, 0, 100);
circular_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!runable) {
run();
} else {
reset();
}
}
});
}
use of android.hardware.SensorEventListener in project xDrip by NightscoutFoundation.
the class Reminders method onPause.
@Override
protected void onPause() {
super.onPause();
Log.d(TAG, "onPause");
final SensorEventListener activity = this;
JoH.runOnUiThreadDelayed(new Runnable() {
@Override
public void run() {
Log.d(TAG, "Unregistering proximity sensor listener");
try {
mSensorManager.unregisterListener(activity);
} catch (Exception e) {
Log.d(TAG, "Error unregistering proximity listener: " + e);
}
}
}, 10000);
}
Aggregations