1 /*
2  * Copyright (C) 2021 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.statusbar.phone;
18 
19 import static com.android.systemui.classifier.FalsingModule.DOUBLE_TAP_TIMEOUT_MS;
20 
21 import com.android.internal.annotations.VisibleForTesting;
22 import com.android.systemui.dagger.SysUISingleton;
23 import com.android.systemui.dagger.qualifiers.Main;
24 import com.android.systemui.statusbar.policy.ConfigurationController;
25 import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;
26 import com.android.systemui.util.ViewController;
27 import com.android.systemui.util.concurrency.DelayableExecutor;
28 
29 import javax.inject.Inject;
30 import javax.inject.Named;
31 
32 /**
33  * Controller for {@link TapAgainView}.
34  */
35 @SysUISingleton
36 public class TapAgainViewController extends ViewController<TapAgainView> {
37     private final DelayableExecutor mDelayableExecutor;
38     private final ConfigurationController mConfigurationController;
39     private final long mDoubleTapTimeMs;
40 
41     private Runnable mHideCanceler;
42 
43     @VisibleForTesting
44     final ConfigurationListener mConfigurationListener = new ConfigurationListener() {
45         @Override
46         public void onUiModeChanged() {
47             mView.updateColor();
48         }
49 
50         @Override
51         public void onThemeChanged() {
52             mView.updateColor();
53         }
54     };
55 
56     @Inject
TapAgainViewController(TapAgainView view, @Main DelayableExecutor delayableExecutor, ConfigurationController configurationController, @Named(DOUBLE_TAP_TIMEOUT_MS) long doubleTapTimeMs)57     protected TapAgainViewController(TapAgainView view,
58             @Main DelayableExecutor delayableExecutor,
59             ConfigurationController configurationController,
60             @Named(DOUBLE_TAP_TIMEOUT_MS) long doubleTapTimeMs) {
61         super(view);
62         mDelayableExecutor = delayableExecutor;
63         mConfigurationController = configurationController;
64         mDoubleTapTimeMs = doubleTapTimeMs;
65     }
66 
67     @Override
onViewAttached()68     protected void onViewAttached() {
69         mConfigurationController.addCallback(mConfigurationListener);
70     }
71 
72     @Override
onViewDetached()73     protected void onViewDetached() {
74         mConfigurationController.removeCallback(mConfigurationListener);
75     }
76 
77     /** Shows the associated view, possibly animating it. */
show()78     public void show() {
79         if (mHideCanceler != null) {
80             mHideCanceler.run();
81         }
82         mView.animateIn();
83         mHideCanceler = mDelayableExecutor.executeDelayed(this::hide, mDoubleTapTimeMs);
84     }
85 
86     /** Hides the associated view, possibly animating it. */
hide()87     private void hide() {
88         mHideCanceler = null;
89         mView.animateOut();
90     }
91 }
92