sanders: MotoActions: Re-add/fix Glance Sensor

This commit is contained in:
therootlord
2018-02-08 01:16:19 -02:00
parent 44cfb60227
commit 8cbf0fd3bb
3 changed files with 83 additions and 14 deletions

View File

@@ -0,0 +1,76 @@
/*
* 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 GlanceSensor implements ScreenStateNotifier {
private static final String TAG = "MotoActions-GlanceSensor";
private final MotoActionsSettings mMotoActionsSettings;
private final SensorHelper mSensorHelper;
private final SensorAction mSensorAction;
private final Sensor mSensor;
private boolean mEnabled;
public GlanceSensor(MotoActionsSettings motoActionsSettings, SensorHelper sensorHelper,
SensorAction action) {
mMotoActionsSettings = motoActionsSettings;
mSensorHelper = sensorHelper;
mSensorAction = action;
mSensor = sensorHelper.getGlanceSensor();
}
@Override
public void screenTurnedOn() {
if (mEnabled) {
Log.d(TAG, "Disabling");
mSensorHelper.unregisterListener(mGlanceListener);
mEnabled = false;
}
}
@Override
public void screenTurnedOff() {
if (mMotoActionsSettings.isPickUpEnabled() && !mEnabled) {
Log.d(TAG, "Enabling");
mSensorHelper.registerListener(mSensor, mGlanceListener);
mEnabled = true;
}
}
private SensorEventListener mGlanceListener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
Log.d(TAG, "triggered");
mSensorAction.action();
}
@Override
public void onAccuracyChanged(Sensor mSensor, int accuracy) {
}
};
}