MotoActions: Use stow sensor for both hand wave and pick up gestures
* The behaviors of stow and proximity sensors are pretty similar, so there's no need to use both at the same time. Simply use the stow sensor to handle both hand wave and pick up gestures. * Switch to timestamp associated with the sensor event to determine the operation while at it. Change-Id: I39767cf7b2e48bc2b0baabfac1e47240012f71d6
This commit is contained in:
parent
aa1d43e9fd
commit
276242afab
@ -35,7 +35,6 @@ import org.lineageos.settings.device.actions.LiftToSilence;
|
|||||||
import org.lineageos.settings.device.actions.ProximitySilencer;
|
import org.lineageos.settings.device.actions.ProximitySilencer;
|
||||||
|
|
||||||
import org.lineageos.settings.device.doze.DozePulseAction;
|
import org.lineageos.settings.device.doze.DozePulseAction;
|
||||||
import org.lineageos.settings.device.doze.ProximitySensor;
|
|
||||||
import org.lineageos.settings.device.doze.FlatUpSensor;
|
import org.lineageos.settings.device.doze.FlatUpSensor;
|
||||||
import org.lineageos.settings.device.doze.ScreenReceiver;
|
import org.lineageos.settings.device.doze.ScreenReceiver;
|
||||||
import org.lineageos.settings.device.doze.ScreenStateNotifier;
|
import org.lineageos.settings.device.doze.ScreenStateNotifier;
|
||||||
@ -71,7 +70,6 @@ public class MotoActionsService extends IntentService implements ScreenStateNoti
|
|||||||
mScreenStateNotifiers.add(mDozePulseAction);
|
mScreenStateNotifiers.add(mDozePulseAction);
|
||||||
|
|
||||||
// Actionable sensors get screen on/off notifications
|
// Actionable sensors get screen on/off notifications
|
||||||
mScreenStateNotifiers.add(new ProximitySensor(MotoActionsSettings, mSensorHelper, mDozePulseAction));
|
|
||||||
mScreenStateNotifiers.add(new StowSensor(MotoActionsSettings, mSensorHelper, mDozePulseAction));
|
mScreenStateNotifiers.add(new StowSensor(MotoActionsSettings, mSensorHelper, mDozePulseAction));
|
||||||
mScreenStateNotifiers.add(new FlatUpSensor(MotoActionsSettings, mSensorHelper, mDozePulseAction));
|
mScreenStateNotifiers.add(new FlatUpSensor(MotoActionsSettings, mSensorHelper, mDozePulseAction));
|
||||||
|
|
||||||
|
@ -1,81 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2015 The CyanogenMod Project
|
|
||||||
* Copyright (c) 2017 The LineageOS Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.lineageos.settings.device.doze;
|
|
||||||
|
|
||||||
import android.hardware.Sensor;
|
|
||||||
import android.hardware.SensorEvent;
|
|
||||||
import android.hardware.SensorEventListener;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import org.lineageos.settings.device.MotoActionsSettings;
|
|
||||||
import org.lineageos.settings.device.SensorAction;
|
|
||||||
import org.lineageos.settings.device.SensorHelper;
|
|
||||||
|
|
||||||
public class ProximitySensor implements ScreenStateNotifier, SensorEventListener {
|
|
||||||
private static final String TAG = "MotoActions-ProximitySensor";
|
|
||||||
|
|
||||||
private final MotoActionsSettings mMotoActionsSettings;
|
|
||||||
private final SensorHelper mSensorHelper;
|
|
||||||
private final SensorAction mSensorAction;
|
|
||||||
private final Sensor mSensor;
|
|
||||||
|
|
||||||
private boolean mEnabled;
|
|
||||||
|
|
||||||
private boolean mSawNear = false;
|
|
||||||
|
|
||||||
public ProximitySensor(MotoActionsSettings MotoActionsSettings, SensorHelper sensorHelper,
|
|
||||||
SensorAction action) {
|
|
||||||
mMotoActionsSettings = MotoActionsSettings;
|
|
||||||
mSensorHelper = sensorHelper;
|
|
||||||
mSensorAction = action;
|
|
||||||
|
|
||||||
mSensor = sensorHelper.getProximitySensor();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void screenTurnedOn() {
|
|
||||||
if (mEnabled) {
|
|
||||||
Log.d(TAG, "Disabling");
|
|
||||||
mSensorHelper.unregisterListener(this);
|
|
||||||
mEnabled = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void screenTurnedOff() {
|
|
||||||
if (mMotoActionsSettings.isIrWakeupEnabled() && !mEnabled) {
|
|
||||||
Log.d(TAG, "Enabling");
|
|
||||||
mSensorHelper.registerListener(mSensor, this);
|
|
||||||
mEnabled = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSensorChanged(SensorEvent event) {
|
|
||||||
boolean isNear = event.values[0] < mSensor.getMaximumRange();
|
|
||||||
if (mSawNear && !isNear) {
|
|
||||||
Log.d(TAG, "wave triggered");
|
|
||||||
mSensorAction.action();
|
|
||||||
}
|
|
||||||
mSawNear = isNear;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAccuracyChanged(Sensor mSensor, int accuracy) {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2015 The CyanogenMod Project
|
* Copyright (c) 2015 The CyanogenMod Project
|
||||||
* Copyright (c) 2017 The LineageOS Project
|
* Copyright (c) 2017-2022 The LineageOS Project
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -22,15 +22,18 @@ import android.hardware.SensorEvent;
|
|||||||
import android.hardware.SensorEventListener;
|
import android.hardware.SensorEventListener;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.lang.System;
|
|
||||||
|
|
||||||
import org.lineageos.settings.device.MotoActionsSettings;
|
import org.lineageos.settings.device.MotoActionsSettings;
|
||||||
import org.lineageos.settings.device.SensorAction;
|
import org.lineageos.settings.device.SensorAction;
|
||||||
import org.lineageos.settings.device.SensorHelper;
|
import org.lineageos.settings.device.SensorHelper;
|
||||||
|
|
||||||
public class StowSensor implements ScreenStateNotifier, SensorEventListener {
|
public class StowSensor implements ScreenStateNotifier, SensorEventListener {
|
||||||
private static final String TAG = "MotoActions-StowSensor";
|
private static final String TAG = "MotoActions-StowSensor";
|
||||||
private static final int IN_POCKET_MIN_TIME = 5000;
|
|
||||||
|
// Maximum time for the hand to cover the sensor: 1s
|
||||||
|
private static final long HANDWAVE_MAX_DELTA_NS = 1000L * 1000 * 1000;
|
||||||
|
|
||||||
|
// Minimum time until the device is considered to have been in the pocket: 5s
|
||||||
|
private static final long POCKET_MIN_DELTA_NS = 5000L * 1000 * 1000;
|
||||||
|
|
||||||
private final MotoActionsSettings mMotoActionsSettings;
|
private final MotoActionsSettings mMotoActionsSettings;
|
||||||
private final SensorHelper mSensorHelper;
|
private final SensorHelper mSensorHelper;
|
||||||
@ -39,10 +42,10 @@ public class StowSensor implements ScreenStateNotifier, SensorEventListener {
|
|||||||
|
|
||||||
private boolean mEnabled;
|
private boolean mEnabled;
|
||||||
private boolean mLastStowed;
|
private boolean mLastStowed;
|
||||||
private long isStowedTime;
|
private long mLastStowedTime;
|
||||||
|
|
||||||
public StowSensor(MotoActionsSettings MotoActionsSettings, SensorHelper sensorHelper,
|
public StowSensor(MotoActionsSettings MotoActionsSettings, SensorHelper sensorHelper,
|
||||||
SensorAction action) {
|
SensorAction action) {
|
||||||
mMotoActionsSettings = MotoActionsSettings;
|
mMotoActionsSettings = MotoActionsSettings;
|
||||||
mSensorHelper = sensorHelper;
|
mSensorHelper = sensorHelper;
|
||||||
mSensorAction = action;
|
mSensorAction = action;
|
||||||
@ -61,7 +64,9 @@ public class StowSensor implements ScreenStateNotifier, SensorEventListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void screenTurnedOff() {
|
public void screenTurnedOff() {
|
||||||
if (mMotoActionsSettings.isPocketGestureEnabled() && !mEnabled) {
|
if ((mMotoActionsSettings.isPocketGestureEnabled()
|
||||||
|
|| mMotoActionsSettings.isIrWakeupEnabled())
|
||||||
|
&& !mEnabled) {
|
||||||
Log.d(TAG, "Enabling");
|
Log.d(TAG, "Enabling");
|
||||||
mSensorHelper.registerListener(mSensor, this);
|
mSensorHelper.registerListener(mSensor, this);
|
||||||
mEnabled = true;
|
mEnabled = true;
|
||||||
@ -71,12 +76,10 @@ public class StowSensor implements ScreenStateNotifier, SensorEventListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onSensorChanged(SensorEvent event) {
|
public void onSensorChanged(SensorEvent event) {
|
||||||
boolean thisStowed = (event.values[0] != 0);
|
boolean thisStowed = (event.values[0] != 0);
|
||||||
if(thisStowed){
|
if (thisStowed) {
|
||||||
isStowedTime = System.currentTimeMillis();
|
mLastStowedTime = event.timestamp;
|
||||||
} else if (mLastStowed && !thisStowed) {
|
} else if (mLastStowed) {
|
||||||
long inPocketTime = System.currentTimeMillis() - isStowedTime;
|
if (shouldPulse(event.timestamp)) {
|
||||||
if(inPocketTime >= IN_POCKET_MIN_TIME){
|
|
||||||
Log.d(TAG, "Triggered after " + inPocketTime / 1000 + " seconds");
|
|
||||||
mSensorAction.action();
|
mSensorAction.action();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,6 +87,22 @@ public class StowSensor implements ScreenStateNotifier, SensorEventListener {
|
|||||||
Log.d(TAG, "event: " + thisStowed);
|
Log.d(TAG, "event: " + thisStowed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean shouldPulse(long timestamp) {
|
||||||
|
long delta = timestamp - mLastStowedTime;
|
||||||
|
|
||||||
|
boolean irWakeupEnabled = mMotoActionsSettings.isIrWakeupEnabled();
|
||||||
|
boolean pocketGestureEnabled = mMotoActionsSettings.isPocketGestureEnabled();
|
||||||
|
|
||||||
|
if (irWakeupEnabled && pocketGestureEnabled) {
|
||||||
|
return true;
|
||||||
|
} else if (irWakeupEnabled) {
|
||||||
|
return delta < HANDWAVE_MAX_DELTA_NS;
|
||||||
|
} else if (pocketGestureEnabled) {
|
||||||
|
return delta >= POCKET_MIN_DELTA_NS;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user