• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.dreams.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.R;
26 import com.android.systemui.dagger.qualifiers.Main;
27 import com.android.systemui.dreams.dagger.DreamOverlayComponent;
28 
29 import javax.inject.Named;
30 
31 import dagger.Module;
32 import dagger.Provides;
33 
34 /**
35  * Module for providing a scoped host view.
36  */
37 @Module
38 public abstract class ComplicationHostViewModule {
39     public static final String SCOPED_COMPLICATIONS_LAYOUT = "scoped_complications_layout";
40     public static final String COMPLICATION_MARGIN_DEFAULT = "complication_margin_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 
46     /**
47      * Generates a {@link ConstraintLayout}, which can host
48      * {@link com.android.systemui.dreams.complication.Complication} instances.
49      */
50     @Provides
51     @Named(SCOPED_COMPLICATIONS_LAYOUT)
52     @DreamOverlayComponent.DreamOverlayScope
providesComplicationHostView( LayoutInflater layoutInflater)53     static ConstraintLayout providesComplicationHostView(
54             LayoutInflater layoutInflater) {
55         return Preconditions.checkNotNull((ConstraintLayout)
56                         layoutInflater.inflate(R.layout.dream_overlay_complications_layer,
57                                 null),
58                 "R.layout.dream_overlay_complications_layer did not properly inflated");
59     }
60 
61     @Provides
62     @Named(COMPLICATION_MARGIN_DEFAULT)
63     @DreamOverlayComponent.DreamOverlayScope
providesComplicationPadding(@ain Resources resources)64     static int providesComplicationPadding(@Main Resources resources) {
65         return resources.getDimensionPixelSize(R.dimen.dream_overlay_complication_margin);
66     }
67 
68     /**
69      * Provides the fade out duration for complications.
70      */
71     @Provides
72     @Named(COMPLICATIONS_FADE_OUT_DURATION)
73     @DreamOverlayComponent.DreamOverlayScope
providesComplicationsFadeOutDuration(@ain Resources resources)74     static int providesComplicationsFadeOutDuration(@Main Resources resources) {
75         return resources.getInteger(R.integer.complicationFadeOutMs);
76     }
77 
78     /**
79      * Provides the delay to wait for before fading out complications.
80      */
81     @Provides
82     @Named(COMPLICATIONS_FADE_OUT_DELAY)
83     @DreamOverlayComponent.DreamOverlayScope
providesComplicationsFadeOutDelay(@ain Resources resources)84     static int providesComplicationsFadeOutDelay(@Main Resources resources) {
85         return resources.getInteger(R.integer.complicationFadeOutDelayMs);
86     }
87 
88     /**
89      * Provides the fade in duration for complications.
90      */
91     @Provides
92     @Named(COMPLICATIONS_FADE_IN_DURATION)
93     @DreamOverlayComponent.DreamOverlayScope
providesComplicationsFadeInDuration(@ain Resources resources)94     static int providesComplicationsFadeInDuration(@Main Resources resources) {
95         return resources.getInteger(R.integer.complicationFadeInMs);
96     }
97 
98     /**
99      * Provides the timeout for restoring complication visibility.
100      */
101     @Provides
102     @Named(COMPLICATIONS_RESTORE_TIMEOUT)
103     @DreamOverlayComponent.DreamOverlayScope
providesComplicationsRestoreTimeout(@ain Resources resources)104     static int providesComplicationsRestoreTimeout(@Main Resources resources) {
105         return resources.getInteger(R.integer.complicationRestoreMs);
106     }
107 }
108