• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 package com.android.systemui.car.systembar;
17 
18 import androidx.annotation.CallSuper;
19 
20 import com.android.systemui.car.systembar.element.CarSystemBarElementController;
21 import com.android.systemui.car.systembar.element.CarSystemBarElementStateController;
22 import com.android.systemui.car.systembar.element.CarSystemBarElementStatusBarDisableController;
23 import com.android.systemui.car.wm.scalableui.EventDispatcher;
24 import com.android.systemui.settings.UserTracker;
25 
26 import dagger.assisted.Assisted;
27 import dagger.assisted.AssistedFactory;
28 import dagger.assisted.AssistedInject;
29 
30 /**
31  * A generic CarSystemBarElementController for handling CarSystemBarButton button interactions.
32  */
33 public class CarSystemBarButtonController
34         extends CarSystemBarElementController<CarSystemBarButton> {
35 
36     private final UserTracker mUserTracker;
37     private final EventDispatcher mEventDispatcher;
38     private final ButtonSelectionStateController mButtonSelectionStateController;
39 
40     @AssistedInject
CarSystemBarButtonController(@ssisted CarSystemBarButton barButton, CarSystemBarElementStatusBarDisableController disableController, CarSystemBarElementStateController stateController, UserTracker userTracker, EventDispatcher eventDispatcher, ButtonSelectionStateController buttonSelectionStateController)41     public CarSystemBarButtonController(@Assisted CarSystemBarButton barButton,
42             CarSystemBarElementStatusBarDisableController disableController,
43             CarSystemBarElementStateController stateController,
44             UserTracker userTracker, EventDispatcher eventDispatcher,
45             ButtonSelectionStateController buttonSelectionStateController) {
46         super(barButton, disableController, stateController);
47 
48         mUserTracker = userTracker;
49         mEventDispatcher = eventDispatcher;
50         mButtonSelectionStateController = buttonSelectionStateController;
51     }
52 
53     @Override
54     @CallSuper
onInit()55     protected void onInit() {
56         mView.setUserTracker(mUserTracker);
57         mView.setEventDispatcher(mEventDispatcher);
58     }
59 
60     @Override
onViewAttached()61     protected void onViewAttached() {
62         super.onViewAttached();
63         mButtonSelectionStateController.addAllButtonsWithSelectionState(mView);
64     }
65 
66     @Override
onViewDetached()67     protected void onViewDetached() {
68         super.onViewDetached();
69         mButtonSelectionStateController.removeButton(mView);
70     }
71 
72     @AssistedFactory
73     public interface Factory extends
74             CarSystemBarElementController.Factory<CarSystemBarButton,
75                     CarSystemBarButtonController> {
76     }
77 }
78