sanders: LineageActions -> MotoActions
This commit is contained in:
66
MotoActions/src/com/moto/actions/doze/DozePulseAction.java
Normal file
66
MotoActions/src/com/moto/actions/doze/DozePulseAction.java
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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 com.moto.actions.doze;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
import com.moto.actions.SensorAction;
|
||||
|
||||
public class DozePulseAction implements SensorAction, ScreenStateNotifier {
|
||||
private static final String TAG = "MotoActions";
|
||||
|
||||
private static final int DELAY_BETWEEN_DOZES_IN_MS = 1500;
|
||||
|
||||
private final Context mContext;
|
||||
|
||||
private long mLastDoze;
|
||||
|
||||
public DozePulseAction(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void screenTurnedOn() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void screenTurnedOff() {
|
||||
mLastDoze = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void action() {
|
||||
if (mayDoze()) {
|
||||
Log.d(TAG, "Sending doze.pulse intent");
|
||||
mContext.sendBroadcast(new Intent("com.android.systemui.doze.pulse"));
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized boolean mayDoze() {
|
||||
long now = System.currentTimeMillis();
|
||||
if (now - mLastDoze > DELAY_BETWEEN_DOZES_IN_MS) {
|
||||
Log.d(TAG, "Allowing doze");
|
||||
mLastDoze = now;
|
||||
return true;
|
||||
} else {
|
||||
Log.d(TAG, "Denying doze");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
81
MotoActions/src/com/moto/actions/doze/ProximitySensor.java
Normal file
81
MotoActions/src/com/moto/actions/doze/ProximitySensor.java
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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 com.moto.actions.doze;
|
||||
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.util.Log;
|
||||
|
||||
import com.moto.actions.MotoActionsSettings;
|
||||
import com.moto.actions.SensorAction;
|
||||
import com.moto.actions.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) {
|
||||
}
|
||||
}
|
||||
48
MotoActions/src/com/moto/actions/doze/ScreenReceiver.java
Normal file
48
MotoActions/src/com/moto/actions/doze/ScreenReceiver.java
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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 com.moto.actions.doze;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
|
||||
import com.moto.actions.actions.Constants;
|
||||
|
||||
public class ScreenReceiver extends BroadcastReceiver {
|
||||
private final ScreenStateNotifier mNotifier;
|
||||
|
||||
public ScreenReceiver(Context context, ScreenStateNotifier notifier) {
|
||||
mNotifier = notifier;
|
||||
|
||||
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
|
||||
filter.addAction(Intent.ACTION_SCREEN_OFF);
|
||||
context.registerReceiver(this, filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
|
||||
mNotifier.screenTurnedOff();
|
||||
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
|
||||
mNotifier.screenTurnedOn();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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 com.moto.actions.doze;
|
||||
|
||||
public interface ScreenStateNotifier {
|
||||
public void screenTurnedOn();
|
||||
public void screenTurnedOff();
|
||||
}
|
||||
91
MotoActions/src/com/moto/actions/doze/StowSensor.java
Normal file
91
MotoActions/src/com/moto/actions/doze/StowSensor.java
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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 com.moto.actions.doze;
|
||||
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.util.Log;
|
||||
|
||||
import java.lang.System;
|
||||
|
||||
import com.moto.actions.MotoActionsSettings;
|
||||
import com.moto.actions.SensorAction;
|
||||
import com.moto.actions.SensorHelper;
|
||||
|
||||
public class StowSensor implements ScreenStateNotifier, SensorEventListener {
|
||||
private static final String TAG = "MotoActions-StowSensor";
|
||||
private static final int IN_POCKET_MIN_TIME = 5000;
|
||||
|
||||
private final MotoActionsSettings mMotoActionsSettings;
|
||||
private final SensorHelper mSensorHelper;
|
||||
private final SensorAction mSensorAction;
|
||||
private final Sensor mSensor;
|
||||
|
||||
private boolean mEnabled;
|
||||
private boolean mLastStowed;
|
||||
private long isStowedTime;
|
||||
|
||||
public StowSensor(MotoActionsSettings motoActionsSettings, SensorHelper sensorHelper,
|
||||
SensorAction action) {
|
||||
mMotoActionsSettings = motoActionsSettings;
|
||||
mSensorHelper = sensorHelper;
|
||||
mSensorAction = action;
|
||||
|
||||
mSensor = sensorHelper.getStowSensor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void screenTurnedOn() {
|
||||
if (mEnabled) {
|
||||
Log.d(TAG, "Disabling");
|
||||
mSensorHelper.unregisterListener(this);
|
||||
mEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void screenTurnedOff() {
|
||||
if (!mMotoActionsSettings.isIrWakeupEnabled() &&
|
||||
mMotoActionsSettings.isPickUpEnabled() && !mEnabled) {
|
||||
Log.d(TAG, "Enabling");
|
||||
mSensorHelper.registerListener(mSensor, this);
|
||||
mEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
boolean thisStowed = (event.values[0] != 0);
|
||||
if(thisStowed){
|
||||
isStowedTime = System.currentTimeMillis();
|
||||
} else if (mLastStowed && !thisStowed) {
|
||||
long inPocketTime = System.currentTimeMillis() - isStowedTime;
|
||||
if(inPocketTime >= IN_POCKET_MIN_TIME){
|
||||
Log.d(TAG, "Triggered after " + inPocketTime / 1000 + " seconds");
|
||||
mSensorAction.action();
|
||||
}
|
||||
}
|
||||
mLastStowed = thisStowed;
|
||||
Log.d(TAG, "event: " + thisStowed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user