• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.plugins.statusbar;
18 
19 import com.android.systemui.plugins.annotations.DependsOn;
20 import com.android.systemui.plugins.annotations.ProvidesInterface;
21 import com.android.systemui.plugins.statusbar.StatusBarStateController.StateListener;
22 
23 
24 /**
25  * Sends updates to {@link StateListener}s about changes to the status bar state and dozing state
26  */
27 @ProvidesInterface(version = StatusBarStateController.VERSION)
28 @DependsOn(target = StatusBarStateController.StateListener.class)
29 public interface StatusBarStateController {
30     int VERSION = 1;
31 
32     /**
33      * Current status bar state
34      */
getState()35     int getState();
36 
37     /**
38      * Is device dozing
39      */
isDozing()40     boolean isDozing();
41 
42     /**
43      * Adds a state listener
44      */
addCallback(StateListener listener)45     void addCallback(StateListener listener);
46 
47     /**
48      * Removes callback from listeners
49      */
removeCallback(StateListener listener)50     void removeCallback(StateListener listener);
51 
52     /**
53      * Get amount of doze
54      */
getDozeAmount()55     float getDozeAmount();
56 
57     /**
58      * Listener for StatusBarState updates
59      */
60     @ProvidesInterface(version = StateListener.VERSION)
61     public interface StateListener {
62         int VERSION = 1;
63 
64         /**
65          * Callback before the new state is applied, for those who need to preempt the change.
66          */
onStatePreChange(int oldState, int newState)67         default void onStatePreChange(int oldState, int newState) {
68         }
69 
70         /**
71          * Callback after all listeners have had a chance to update based on the state change
72          */
onStatePostChange()73         default void onStatePostChange() {
74         }
75 
76         /**
77          * Required callback. Get the new state and do what you will with it. Keep in mind that
78          * other listeners are typically unordered and don't rely on your work being done before
79          * other peers.
80          *
81          * Only called if the state is actually different.
82          */
onStateChanged(int newState)83         default void onStateChanged(int newState) {
84         }
85 
86         /**
87          * Callback to be notified when Dozing changes. Dozing is stored separately from state.
88          */
onDozingChanged(boolean isDozing)89         default void onDozingChanged(boolean isDozing) {}
90 
91         /**
92          * Callback to be notified when the doze amount changes. Useful for animations.
93          * Note: this will be called for each animation frame. Please be careful to avoid
94          * performance regressions.
95          */
onDozeAmountChanged(float linear, float eased)96         default void onDozeAmountChanged(float linear, float eased) {}
97     }
98 }
99