1 /*
2  * Copyright (C) 2022 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.complication.dagger;
18 
19 import android.content.res.Resources;
20 import android.view.ViewGroup;
21 
22 import com.android.systemui.complication.ComplicationLayoutParams;
23 import com.android.systemui.dagger.SystemUIBinder;
24 import com.android.systemui.dagger.qualifiers.Main;
25 import com.android.systemui.flags.FeatureFlags;
26 import com.android.systemui.flags.Flags;
27 import com.android.systemui.res.R;
28 import com.android.systemui.util.settings.SystemSettings;
29 
30 import dagger.Module;
31 import dagger.Provides;
32 
33 import javax.inject.Named;
34 
35 /**
36  * Module for all components with corresponding dream layer complications registered in
37  * {@link SystemUIBinder}.
38  */
39 @Module(
40         subcomponents = {
41                 DreamClockTimeComplicationComponent.class,
42                 DreamHomeControlsComplicationComponent.class,
43                 OpenHubComplicationComponent.class,
44                 DreamMediaEntryComplicationComponent.class
45         })
46 public interface RegisteredComplicationsModule {
47     String DREAM_CLOCK_TIME_COMPLICATION_LAYOUT_PARAMS = "time_complication_layout_params";
48     String DREAM_SMARTSPACE_LAYOUT_PARAMS = "smartspace_layout_params";
49     String DREAM_HOME_CONTROLS_CHIP_LAYOUT_PARAMS = "home_controls_chip_layout_params";
50     String DREAM_MEDIA_ENTRY_LAYOUT_PARAMS = "media_entry_layout_params";
51     String OPEN_HUB_CHIP_LAYOUT_PARAMS = "open_hub_chip_layout_params";
52     String OPEN_HUB_CHIP_REPLACE_HOME_CONTROLS = "open_hub_chip_replace_home_controls";
53 
54     int DREAM_CLOCK_TIME_COMPLICATION_WEIGHT = 1;
55     int DREAM_CLOCK_TIME_COMPLICATION_WEIGHT_NO_SMARTSPACE = 2;
56     int DREAM_SMARTSPACE_COMPLICATION_WEIGHT = 2;
57     int DREAM_MEDIA_COMPLICATION_WEIGHT = 0;
58     int DREAM_HOME_CONTROLS_CHIP_COMPLICATION_WEIGHT = 4;
59     int DREAM_MEDIA_ENTRY_COMPLICATION_WEIGHT = 3;
60     int DREAM_WEATHER_COMPLICATION_WEIGHT = 0;
61 
62     /**
63      * Provides layout parameters for the clock time complication.
64      */
65     @Provides
66     @Named(DREAM_CLOCK_TIME_COMPLICATION_LAYOUT_PARAMS)
provideClockTimeLayoutParams(FeatureFlags featureFlags)67     static ComplicationLayoutParams provideClockTimeLayoutParams(FeatureFlags featureFlags) {
68         if (featureFlags.isEnabled(Flags.HIDE_SMARTSPACE_ON_DREAM_OVERLAY)) {
69             return new ComplicationLayoutParams(0,
70                     ViewGroup.LayoutParams.WRAP_CONTENT,
71                     ComplicationLayoutParams.POSITION_BOTTOM
72                             | ComplicationLayoutParams.POSITION_START,
73                     ComplicationLayoutParams.DIRECTION_END,
74                     DREAM_CLOCK_TIME_COMPLICATION_WEIGHT_NO_SMARTSPACE);
75         }
76         return new ComplicationLayoutParams(0,
77                 ViewGroup.LayoutParams.WRAP_CONTENT,
78                 ComplicationLayoutParams.POSITION_BOTTOM
79                         | ComplicationLayoutParams.POSITION_START,
80                 ComplicationLayoutParams.DIRECTION_UP,
81                 DREAM_CLOCK_TIME_COMPLICATION_WEIGHT,
82                 0 /*margin*/);
83     }
84 
85     /**
86      * Provides layout parameters for the home controls complication.
87      */
88     @Provides
89     @Named(DREAM_HOME_CONTROLS_CHIP_LAYOUT_PARAMS)
provideHomeControlsChipLayoutParams()90     static ComplicationLayoutParams provideHomeControlsChipLayoutParams() {
91         return new ComplicationLayoutParams(
92                 ViewGroup.LayoutParams.WRAP_CONTENT,
93                 ViewGroup.LayoutParams.WRAP_CONTENT,
94                 ComplicationLayoutParams.POSITION_BOTTOM
95                         | ComplicationLayoutParams.POSITION_START,
96                 ComplicationLayoutParams.DIRECTION_END,
97                 DREAM_HOME_CONTROLS_CHIP_COMPLICATION_WEIGHT);
98     }
99 
100     /**
101      * Provides layout parameters for the media entry complication.
102      */
103     @Provides
104     @Named(DREAM_MEDIA_ENTRY_LAYOUT_PARAMS)
provideMediaEntryLayoutParams(@ain Resources res)105     static ComplicationLayoutParams provideMediaEntryLayoutParams(@Main Resources res) {
106         return new ComplicationLayoutParams(
107                 ViewGroup.LayoutParams.WRAP_CONTENT,
108                 ViewGroup.LayoutParams.WRAP_CONTENT,
109                 ComplicationLayoutParams.POSITION_BOTTOM
110                         | ComplicationLayoutParams.POSITION_START,
111                 ComplicationLayoutParams.DIRECTION_END,
112                 DREAM_MEDIA_ENTRY_COMPLICATION_WEIGHT);
113     }
114 
115     /**
116      * Provides layout parameters for the open hub complication.
117      */
118     @Provides
119     @Named(OPEN_HUB_CHIP_LAYOUT_PARAMS)
provideOpenHubLayoutParams( @amedOPEN_HUB_CHIP_REPLACE_HOME_CONTROLS) boolean replaceHomeControls)120     static ComplicationLayoutParams provideOpenHubLayoutParams(
121             @Named(OPEN_HUB_CHIP_REPLACE_HOME_CONTROLS) boolean replaceHomeControls) {
122         int position = ComplicationLayoutParams.POSITION_BOTTOM | (replaceHomeControls
123                 ? ComplicationLayoutParams.POSITION_START
124                 : ComplicationLayoutParams.POSITION_END);
125         int direction = replaceHomeControls ? ComplicationLayoutParams.DIRECTION_END
126                 : ComplicationLayoutParams.DIRECTION_START;
127         return new ComplicationLayoutParams(
128                 ViewGroup.LayoutParams.WRAP_CONTENT,
129                 ViewGroup.LayoutParams.WRAP_CONTENT,
130                 position,
131                 direction,
132                 DREAM_HOME_CONTROLS_CHIP_COMPLICATION_WEIGHT);
133     }
134 
135     /**
136      * Provides layout parameters for the smartspace complication.
137      */
138     @Provides
139     @Named(DREAM_SMARTSPACE_LAYOUT_PARAMS)
provideSmartspaceLayoutParams(@ain Resources res)140     static ComplicationLayoutParams provideSmartspaceLayoutParams(@Main Resources res) {
141         return new ComplicationLayoutParams(
142                 ViewGroup.LayoutParams.WRAP_CONTENT,
143                 ViewGroup.LayoutParams.WRAP_CONTENT,
144                 ComplicationLayoutParams.POSITION_BOTTOM
145                         | ComplicationLayoutParams.POSITION_START,
146                 ComplicationLayoutParams.DIRECTION_END,
147                 DREAM_SMARTSPACE_COMPLICATION_WEIGHT,
148                 res.getDimensionPixelSize(R.dimen.dream_overlay_complication_smartspace_padding),
149                 res.getDimensionPixelSize(R.dimen.dream_overlay_complication_smartspace_max_width));
150     }
151 
152     /**
153      * If true, the home controls chip should not be shown and the open hub chip should be shown in
154      * its place.
155      */
156     @Provides
157     @Named(OPEN_HUB_CHIP_REPLACE_HOME_CONTROLS)
providesOpenHubChipReplaceHomeControls(SystemSettings systemSettings)158     static boolean providesOpenHubChipReplaceHomeControls(SystemSettings systemSettings) {
159         return systemSettings.getBool(OPEN_HUB_CHIP_REPLACE_HOME_CONTROLS, false);
160     }
161 }
162