1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.util.sensors; 18 19 /** 20 * A wrapper class for sensors that have a boolean state - above/below. 21 */ 22 public interface ThresholdSensor { 23 /** 24 * Optional label to use for logging. 25 * 26 * This should be set to something meaningful by owner of the instance. 27 */ setTag(String tag)28 void setTag(String tag); 29 30 /** 31 * Change the delay used when registering the sensor. 32 * 33 * If the sensor is already registered, this should cause it to re-register with the new 34 * delay. 35 */ setDelay(int delay)36 void setDelay(int delay); 37 38 /** 39 * True if this sensor successfully loads and can be listened to. 40 */ isLoaded()41 boolean isLoaded(); 42 43 /** 44 * Registers with the sensor and calls the supplied callback on value change. 45 * 46 * If this instance is paused, the listener will be recorded, but no registration with 47 * the underlying physical sensor will occur until {@link #resume()} is called. 48 * 49 * @see #unregister(Listener) 50 */ register(Listener listener)51 void register(Listener listener); 52 53 /** 54 * Unregisters from the physical sensor without removing any supplied listeners. 55 * 56 * No events will be sent to listeners as long as this sensor is paused. 57 * 58 * @see #resume() 59 * @see #unregister(Listener) 60 */ pause()61 void pause(); 62 63 /** 64 * Resumes listening to the physical sensor after previously pausing. 65 * 66 * @see #pause() 67 */ resume()68 void resume(); 69 70 /** 71 * Unregister a listener with the sensor. 72 * 73 * @see #register(Listener) 74 */ unregister(Listener listener)75 void unregister(Listener listener); 76 77 /** 78 * Name of the sensor. 79 */ getName()80 String getName(); 81 82 /** 83 * Type of the sensor. 84 */ getType()85 String getType(); 86 87 /** 88 * Interface for listening to events on {@link ThresholdSensor} 89 */ 90 interface Listener { 91 /** 92 * Called whenever the threshold for the registered sensor is crossed. 93 */ onThresholdCrossed(ThresholdSensorEvent event)94 void onThresholdCrossed(ThresholdSensorEvent event); 95 } 96 } 97