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.R;
23 import com.android.systemui.complication.ComplicationLayoutParams;
24 import com.android.systemui.dagger.SystemUIBinder;
25 import com.android.systemui.dagger.qualifiers.Main;
26 import com.android.systemui.flags.FeatureFlags;
27 import com.android.systemui.flags.Flags;
28 
29 import dagger.Module;
30 import dagger.Provides;
31 
32 import javax.inject.Named;
33 
34 /**
35  * Module for all components with corresponding dream layer complications registered in
36  * {@link SystemUIBinder}.
37  */
38 @Module(
39         subcomponents = {
40                 DreamClockTimeComplicationComponent.class,
41                 DreamHomeControlsComplicationComponent.class,
42                 DreamMediaEntryComplicationComponent.class
43         })
44 public interface RegisteredComplicationsModule {
45     String DREAM_CLOCK_TIME_COMPLICATION_LAYOUT_PARAMS = "time_complication_layout_params";
46     String DREAM_SMARTSPACE_LAYOUT_PARAMS = "smartspace_layout_params";
47     String DREAM_HOME_CONTROLS_CHIP_LAYOUT_PARAMS = "home_controls_chip_layout_params";
48     String DREAM_MEDIA_ENTRY_LAYOUT_PARAMS = "media_entry_layout_params";
49 
50     int DREAM_CLOCK_TIME_COMPLICATION_WEIGHT = 1;
51     int DREAM_CLOCK_TIME_COMPLICATION_WEIGHT_NO_SMARTSPACE = 2;
52     int DREAM_SMARTSPACE_COMPLICATION_WEIGHT = 2;
53     int DREAM_MEDIA_COMPLICATION_WEIGHT = 0;
54     int DREAM_HOME_CONTROLS_CHIP_COMPLICATION_WEIGHT = 4;
55     int DREAM_MEDIA_ENTRY_COMPLICATION_WEIGHT = 3;
56     int DREAM_WEATHER_COMPLICATION_WEIGHT = 0;
57 
58     /**
59      * Provides layout parameters for the clock time complication.
60      */
61     @Provides
62     @Named(DREAM_CLOCK_TIME_COMPLICATION_LAYOUT_PARAMS)
provideClockTimeLayoutParams(FeatureFlags featureFlags)63     static ComplicationLayoutParams provideClockTimeLayoutParams(FeatureFlags featureFlags) {
64         if (featureFlags.isEnabled(Flags.HIDE_SMARTSPACE_ON_DREAM_OVERLAY)) {
65             return new ComplicationLayoutParams(0,
66                     ViewGroup.LayoutParams.WRAP_CONTENT,
67                     ComplicationLayoutParams.POSITION_BOTTOM
68                             | ComplicationLayoutParams.POSITION_START,
69                     ComplicationLayoutParams.DIRECTION_END,
70                     DREAM_CLOCK_TIME_COMPLICATION_WEIGHT_NO_SMARTSPACE);
71         }
72         return new ComplicationLayoutParams(0,
73                 ViewGroup.LayoutParams.WRAP_CONTENT,
74                 ComplicationLayoutParams.POSITION_BOTTOM
75                         | ComplicationLayoutParams.POSITION_START,
76                 ComplicationLayoutParams.DIRECTION_UP,
77                 DREAM_CLOCK_TIME_COMPLICATION_WEIGHT,
78                 0 /*margin*/);
79     }
80 
81     /**
82      * Provides layout parameters for the home controls complication.
83      */
84     @Provides
85     @Named(DREAM_HOME_CONTROLS_CHIP_LAYOUT_PARAMS)
provideHomeControlsChipLayoutParams()86     static ComplicationLayoutParams provideHomeControlsChipLayoutParams() {
87         return new ComplicationLayoutParams(
88                 ViewGroup.LayoutParams.WRAP_CONTENT,
89                 ViewGroup.LayoutParams.WRAP_CONTENT,
90                 ComplicationLayoutParams.POSITION_BOTTOM
91                         | ComplicationLayoutParams.POSITION_START,
92                 ComplicationLayoutParams.DIRECTION_END,
93                 DREAM_HOME_CONTROLS_CHIP_COMPLICATION_WEIGHT);
94     }
95 
96     /**
97      * Provides layout parameters for the media entry complication.
98      */
99     @Provides
100     @Named(DREAM_MEDIA_ENTRY_LAYOUT_PARAMS)
provideMediaEntryLayoutParams(@ain Resources res)101     static ComplicationLayoutParams provideMediaEntryLayoutParams(@Main Resources res) {
102         return new ComplicationLayoutParams(
103                 ViewGroup.LayoutParams.WRAP_CONTENT,
104                 ViewGroup.LayoutParams.WRAP_CONTENT,
105                 ComplicationLayoutParams.POSITION_BOTTOM
106                         | ComplicationLayoutParams.POSITION_START,
107                 ComplicationLayoutParams.DIRECTION_END,
108                 DREAM_MEDIA_ENTRY_COMPLICATION_WEIGHT);
109     }
110 
111     /**
112      * Provides layout parameters for the smartspace complication.
113      */
114     @Provides
115     @Named(DREAM_SMARTSPACE_LAYOUT_PARAMS)
provideSmartspaceLayoutParams(@ain Resources res)116     static ComplicationLayoutParams provideSmartspaceLayoutParams(@Main Resources res) {
117         return new ComplicationLayoutParams(
118                 ViewGroup.LayoutParams.WRAP_CONTENT,
119                 ViewGroup.LayoutParams.WRAP_CONTENT,
120                 ComplicationLayoutParams.POSITION_BOTTOM
121                         | ComplicationLayoutParams.POSITION_START,
122                 ComplicationLayoutParams.DIRECTION_END,
123                 DREAM_SMARTSPACE_COMPLICATION_WEIGHT,
124                 res.getDimensionPixelSize(R.dimen.dream_overlay_complication_smartspace_padding),
125                 res.getDimensionPixelSize(R.dimen.dream_overlay_complication_smartspace_max_width));
126     }
127 }
128