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.fragment.dagger;
18 
19 import android.view.View;
20 import android.view.ViewStub;
21 
22 import com.android.systemui.battery.BatteryMeterView;
23 import com.android.systemui.dagger.qualifiers.RootView;
24 import com.android.systemui.res.R;
25 import com.android.systemui.statusbar.HeadsUpStatusBarView;
26 import com.android.systemui.statusbar.phone.PhoneStatusBarTransitions;
27 import com.android.systemui.statusbar.phone.PhoneStatusBarView;
28 import com.android.systemui.statusbar.phone.PhoneStatusBarViewController;
29 import com.android.systemui.statusbar.phone.StatusBarLocation;
30 import com.android.systemui.statusbar.phone.userswitcher.StatusBarUserSwitcherContainer;
31 import com.android.systemui.statusbar.policy.Clock;
32 import com.android.systemui.statusbar.window.StatusBarWindowController;
33 
34 import dagger.Module;
35 import dagger.Provides;
36 
37 import java.util.Optional;
38 
39 import javax.inject.Named;
40 
41 /** Dagger module for {@link StatusBarFragmentComponent}. */
42 @Module
43 public interface StatusBarFragmentModule {
44 
45     String LIGHTS_OUT_NOTIF_VIEW = "lights_out_notif_view";
46     String OPERATOR_NAME_VIEW = "operator_name_view";
47     String OPERATOR_NAME_FRAME_VIEW = "operator_name_frame_view";
48     String START_SIDE_CONTENT = "start_side_content";
49     String END_SIDE_CONTENT = "end_side_content";
50 
51     /** */
52     @Provides
53     @StatusBarFragmentScope
provideBatteryMeterView(@ootView PhoneStatusBarView view)54     static BatteryMeterView provideBatteryMeterView(@RootView PhoneStatusBarView view) {
55         return view.findViewById(R.id.battery);
56     }
57 
58     /** */
59     @Provides
60     @StatusBarFragmentScope
getStatusBarLocation()61     static StatusBarLocation getStatusBarLocation() {
62         return StatusBarLocation.HOME;
63     }
64 
65     /** */
66     @Provides
67     @StatusBarFragmentScope
68     @Named(START_SIDE_CONTENT)
startSideContent(@ootView PhoneStatusBarView view)69     static View startSideContent(@RootView PhoneStatusBarView view) {
70         return view.findViewById(R.id.status_bar_start_side_content);
71     }
72 
73     /** */
74     @Provides
75     @StatusBarFragmentScope
76     @Named(END_SIDE_CONTENT)
endSideContent(@ootView PhoneStatusBarView view)77     static View endSideContent(@RootView PhoneStatusBarView view) {
78         return view.findViewById(R.id.status_bar_end_side_content);
79     }
80 
81     /** */
82     @Provides
83     @StatusBarFragmentScope
84     @Named(LIGHTS_OUT_NOTIF_VIEW)
provideLightsOutNotifView(@ootView PhoneStatusBarView view)85     static View provideLightsOutNotifView(@RootView PhoneStatusBarView view) {
86         return view.findViewById(R.id.notification_lights_out);
87     }
88 
89     /** */
90     @Provides
91     @StatusBarFragmentScope
92     @Named(OPERATOR_NAME_VIEW)
provideOperatorNameView(@ootView PhoneStatusBarView view)93     static View provideOperatorNameView(@RootView PhoneStatusBarView view) {
94         View operatorName = ((ViewStub) view.findViewById(R.id.operator_name_stub)).inflate();
95         operatorName.setVisibility(View.GONE);
96         return operatorName;
97     }
98 
99     /** */
100     @Provides
101     @StatusBarFragmentScope
102     @Named(OPERATOR_NAME_FRAME_VIEW)
provideOperatorFrameNameView(@ootView PhoneStatusBarView view)103     static Optional<View> provideOperatorFrameNameView(@RootView PhoneStatusBarView view) {
104         return Optional.ofNullable(view.findViewById(R.id.operator_name_frame));
105     }
106 
107     /** */
108     @Provides
109     @StatusBarFragmentScope
provideClock(@ootView PhoneStatusBarView view)110     static Clock provideClock(@RootView PhoneStatusBarView view) {
111         return view.findViewById(R.id.clock);
112     }
113 
114     /** */
115     @Provides
116     @StatusBarFragmentScope
provideStatusBarUserSwitcherContainer( @ootView PhoneStatusBarView view)117     static StatusBarUserSwitcherContainer provideStatusBarUserSwitcherContainer(
118             @RootView PhoneStatusBarView view) {
119         return view.findViewById(R.id.user_switcher_container);
120     }
121 
122     /** */
123     @Provides
124     @StatusBarFragmentScope
providePhoneStatusBarViewController( PhoneStatusBarViewController.Factory phoneStatusBarViewControllerFactory, @RootView PhoneStatusBarView phoneStatusBarView)125     static PhoneStatusBarViewController providePhoneStatusBarViewController(
126             PhoneStatusBarViewController.Factory phoneStatusBarViewControllerFactory,
127             @RootView PhoneStatusBarView phoneStatusBarView) {
128         return phoneStatusBarViewControllerFactory.create(
129                 phoneStatusBarView);
130     }
131 
132     /** */
133     @Provides
134     @StatusBarFragmentScope
providePhoneStatusBarTransitions( @ootView PhoneStatusBarView view, StatusBarWindowController statusBarWindowController )135     static PhoneStatusBarTransitions providePhoneStatusBarTransitions(
136             @RootView PhoneStatusBarView view,
137             StatusBarWindowController statusBarWindowController
138     ) {
139         return new PhoneStatusBarTransitions(view, statusBarWindowController.getBackgroundView());
140     }
141 
142     /** */
143     @Provides
144     @StatusBarFragmentScope
providesHeasdUpStatusBarView(@ootView PhoneStatusBarView view)145     static HeadsUpStatusBarView providesHeasdUpStatusBarView(@RootView PhoneStatusBarView view) {
146         return view.findViewById(R.id.heads_up_status_bar_view);
147     }
148 }
149