import org.lineageos.settings.device.actions.ProximitySilencer;
import org.lineageos.settings.device.doze.DozePulseAction;
-import org.lineageos.settings.device.doze.GlanceSensor;
import org.lineageos.settings.device.doze.ProximitySensor;
import org.lineageos.settings.device.doze.FlatUpSensor;
import org.lineageos.settings.device.doze.ScreenReceiver;
mScreenStateNotifiers.add(mDozePulseAction);
// Actionable sensors get screen on/off notifications
- mScreenStateNotifiers.add(new GlanceSensor(MotoActionsSettings, mSensorHelper, mDozePulseAction));
mScreenStateNotifiers.add(new ProximitySensor(MotoActionsSettings, mSensorHelper, mDozePulseAction));
mScreenStateNotifiers.add(new StowSensor(MotoActionsSettings, mSensorHelper, mDozePulseAction));
mScreenStateNotifiers.add(new FlatUpSensor(MotoActionsSettings, mSensorHelper, mDozePulseAction));
private static final int SENSOR_TYPE_MMI_FLAT_UP = 65537;
private static final int SENSOR_TYPE_MMI_FLAT_DOWN = 65538;
private static final int SENSOR_TYPE_MMI_STOW = 65539;
- private static final int SENSOR_TYPE_MMI_GLANCE = 65548;
- private static final int SENSOR_TYPE_MMI_GLANCE_APPROACH = 65555;
private static final int BATCH_LATENCY_IN_MS = 100;
return mSensorManager.getDefaultSensor(SENSOR_TYPE_MMI_FLAT_DOWN, true);
}
- public Sensor getGlanceSensor() {
- return mSensorManager.getDefaultSensor(SENSOR_TYPE_MMI_GLANCE, true);
- }
-
- public Sensor getApproachGlanceSensor() {
- return mSensorManager.getDefaultSensor(SENSOR_TYPE_MMI_GLANCE_APPROACH, true);
- }
-
public Sensor getProximitySensor() {
return mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY, true);
}
+++ /dev/null
-/*
- * 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 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 final Sensor mApproachSensor;
-
- private boolean mEnabled;
-
- public GlanceSensor(MotoActionsSettings MotoActionsSettings, SensorHelper sensorHelper,
- SensorAction action) {
- mMotoActionsSettings = MotoActionsSettings;
- mSensorHelper = sensorHelper;
- mSensorAction = action;
-
- mSensor = sensorHelper.getGlanceSensor();
- mApproachSensor = sensorHelper.getApproachGlanceSensor();
- }
-
- @Override
- public void screenTurnedOn() {
- if (mEnabled) {
- Log.d(TAG, "Disabling");
- mSensorHelper.unregisterListener(mGlanceListener);
- mSensorHelper.unregisterListener(mApproachGlanceListener);
- mEnabled = false;
- }
- }
-
- @Override
- public void screenTurnedOff() {
- if (mMotoActionsSettings.isPickUpEnabled() && !mEnabled) {
- Log.d(TAG, "Enabling");
- mSensorHelper.registerListener(mSensor, mGlanceListener);
- mSensorHelper.registerListener(mApproachSensor, mApproachGlanceListener);
- mEnabled = true;
- }
- }
-
- private SensorEventListener mGlanceListener = new SensorEventListener() {
- @Override
- public synchronized void onSensorChanged(SensorEvent event) {
- Log.d(TAG, "Changed");
- mSensorAction.action();
- }
-
- @Override
- public void onAccuracyChanged(Sensor mSensor, int accuracy) {
- }
- };
-
- private SensorEventListener mApproachGlanceListener = new SensorEventListener() {
- @Override
- public synchronized void onSensorChanged(SensorEvent event) {
- Log.d(TAG, "Approach: Changed");
- mSensorAction.action();
- }
-
- @Override
- public void onAccuracyChanged(Sensor mSensor, int accuracy) {
- }
- };
-}