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.LayoutInflater;
21 
22 import androidx.constraintlayout.widget.ConstraintLayout;
23 
24 import com.android.internal.util.Preconditions;
25 import com.android.systemui.dagger.qualifiers.Main;
26 import com.android.systemui.res.R;
27 
28 import dagger.Module;
29 import dagger.Provides;
30 
31 import javax.inject.Named;
32 
33 /**
34  * Module for providing a scoped host view.
35  */
36 @Module
37 public abstract class ComplicationHostViewModule {
38     public static final String SCOPED_COMPLICATIONS_LAYOUT = "scoped_complications_layout";
39     public static final String COMPLICATION_DIRECTIONAL_SPACING_DEFAULT =
40             "complication_directional_spacing_default";
41     public static final String COMPLICATIONS_FADE_OUT_DURATION = "complications_fade_out_duration";
42     public static final String COMPLICATIONS_FADE_IN_DURATION = "complications_fade_in_duration";
43     public static final String COMPLICATIONS_RESTORE_TIMEOUT = "complication_restore_timeout";
44     public static final String COMPLICATIONS_FADE_OUT_DELAY = "complication_fade_out_delay";
45     public static final String COMPLICATION_MARGIN_POSITION_START =
46             "complication_margin_position_start";
47     public static final String COMPLICATION_MARGIN_POSITION_TOP =
48             "complication_margin_position_top";
49     public static final String COMPLICATION_MARGIN_POSITION_END =
50             "complication_margin_position_end";
51     public static final String COMPLICATION_MARGIN_POSITION_BOTTOM =
52             "complication_margin_position_bottom";
53 
54     /**
55      * Generates a {@link ConstraintLayout}, which can host
56      * {@link com.android.systemui.complication.Complication} instances.
57      */
58     @Provides
59     @Named(SCOPED_COMPLICATIONS_LAYOUT)
60     @ComplicationModule.ComplicationScope
providesComplicationHostView( LayoutInflater layoutInflater)61     static ConstraintLayout providesComplicationHostView(
62             LayoutInflater layoutInflater) {
63         return Preconditions.checkNotNull((ConstraintLayout)
64                         layoutInflater.inflate(R.layout.dream_overlay_complications_layer,
65                                 null),
66                 "R.layout.dream_overlay_complications_layer did not properly inflated");
67     }
68 
69     @Provides
70     @Named(COMPLICATION_DIRECTIONAL_SPACING_DEFAULT)
providesComplicationPadding(@ain Resources resources)71     static int providesComplicationPadding(@Main Resources resources) {
72         return resources.getDimensionPixelSize(R.dimen.dream_overlay_complication_margin);
73     }
74 
75     @Provides
76     @Named(COMPLICATION_MARGIN_POSITION_START)
providesComplicationMarginPositionStart(@ain Resources resources)77     static int providesComplicationMarginPositionStart(@Main Resources resources) {
78         return resources.getDimensionPixelSize(R.dimen.dream_overlay_container_padding_start);
79     }
80 
81     @Provides
82     @Named(COMPLICATION_MARGIN_POSITION_TOP)
providesComplicationMarginPositionTop(@ain Resources resources)83     static int providesComplicationMarginPositionTop(@Main Resources resources) {
84         return resources.getDimensionPixelSize(R.dimen.dream_overlay_container_padding_top);
85     }
86 
87     @Provides
88     @Named(COMPLICATION_MARGIN_POSITION_END)
providesComplicationMarginPositionEnd(@ain Resources resources)89     static int providesComplicationMarginPositionEnd(@Main Resources resources) {
90         return resources.getDimensionPixelSize(R.dimen.dream_overlay_container_padding_end);
91     }
92 
93     @Provides
94     @Named(COMPLICATION_MARGIN_POSITION_BOTTOM)
providesComplicationMarginPositionBottom(@ain Resources resources)95     static int providesComplicationMarginPositionBottom(@Main Resources resources) {
96         return resources.getDimensionPixelSize(R.dimen.dream_overlay_container_padding_bottom);
97     }
98 
99     /**
100      * Provides the fade out duration for complications.
101      */
102     @Provides
103     @Named(COMPLICATIONS_FADE_OUT_DURATION)
providesComplicationsFadeOutDuration(@ain Resources resources)104     static int providesComplicationsFadeOutDuration(@Main Resources resources) {
105         return resources.getInteger(R.integer.complicationFadeOutMs);
106     }
107 
108     /**
109      * Provides the delay to wait for before fading out complications.
110      */
111     @Provides
112     @Named(COMPLICATIONS_FADE_OUT_DELAY)
providesComplicationsFadeOutDelay(@ain Resources resources)113     static int providesComplicationsFadeOutDelay(@Main Resources resources) {
114         return resources.getInteger(R.integer.complicationFadeOutDelayMs);
115     }
116 
117     /**
118      * Provides the fade in duration for complications.
119      */
120     @Provides
121     @Named(COMPLICATIONS_FADE_IN_DURATION)
providesComplicationsFadeInDuration(@ain Resources resources)122     static int providesComplicationsFadeInDuration(@Main Resources resources) {
123         return resources.getInteger(R.integer.complicationFadeInMs);
124     }
125 
126     /**
127      * Provides the timeout for restoring complication visibility.
128      */
129     @Provides
130     @Named(COMPLICATIONS_RESTORE_TIMEOUT)
providesComplicationsRestoreTimeout(@ain Resources resources)131     static int providesComplicationsRestoreTimeout(@Main Resources resources) {
132         return resources.getInteger(R.integer.complicationRestoreMs);
133     }
134 }
135