• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.dreams.dagger;
18 
19 import android.content.res.Resources;
20 import android.view.LayoutInflater;
21 import android.view.ViewGroup;
22 
23 import androidx.lifecycle.Lifecycle;
24 import androidx.lifecycle.LifecycleOwner;
25 import androidx.lifecycle.LifecycleRegistry;
26 
27 import com.android.internal.util.Preconditions;
28 import com.android.systemui.R;
29 import com.android.systemui.dagger.qualifiers.Main;
30 import com.android.systemui.dreams.DreamOverlayContainerView;
31 import com.android.systemui.dreams.DreamOverlayStatusBarView;
32 import com.android.systemui.touch.TouchInsetManager;
33 
34 import java.util.concurrent.Executor;
35 
36 import javax.inject.Named;
37 
38 import dagger.Lazy;
39 import dagger.Module;
40 import dagger.Provides;
41 
42 /** Dagger module for {@link DreamOverlayComponent}. */
43 @Module
44 public abstract class DreamOverlayModule {
45     public static final String DREAM_OVERLAY_CONTENT_VIEW = "dream_overlay_content_view";
46     public static final String MAX_BURN_IN_OFFSET = "max_burn_in_offset";
47     public static final String BURN_IN_PROTECTION_UPDATE_INTERVAL =
48             "burn_in_protection_update_interval";
49     public static final String MILLIS_UNTIL_FULL_JITTER = "millis_until_full_jitter";
50     public static final String DREAM_BLUR_RADIUS = "DREAM_BLUR_RADIUS";
51     public static final String DREAM_IN_BLUR_ANIMATION_DURATION = "dream_in_blur_anim_duration";
52     public static final String DREAM_IN_COMPLICATIONS_ANIMATION_DURATION =
53             "dream_in_complications_anim_duration";
54     public static final String DREAM_IN_TRANSLATION_Y_DISTANCE =
55             "dream_in_complications_translation_y";
56     public static final String DREAM_IN_TRANSLATION_Y_DURATION =
57             "dream_in_complications_translation_y_duration";
58 
59     /** */
60     @Provides
61     @DreamOverlayComponent.DreamOverlayScope
providesDreamOverlayContainerView( LayoutInflater layoutInflater)62     public static DreamOverlayContainerView providesDreamOverlayContainerView(
63             LayoutInflater layoutInflater) {
64         return Preconditions.checkNotNull((DreamOverlayContainerView)
65                 layoutInflater.inflate(R.layout.dream_overlay_container, null),
66                 "R.layout.dream_layout_container could not be properly inflated");
67     }
68 
69     /** */
70     @Provides
71     @DreamOverlayComponent.DreamOverlayScope
72     @Named(DREAM_OVERLAY_CONTENT_VIEW)
providesDreamOverlayContentView(DreamOverlayContainerView view)73     public static ViewGroup providesDreamOverlayContentView(DreamOverlayContainerView view) {
74         return Preconditions.checkNotNull(view.findViewById(R.id.dream_overlay_content),
75                 "R.id.dream_overlay_content must not be null");
76     }
77 
78     /** */
79     @Provides
providesTouchInsetSession( TouchInsetManager manager)80     public static TouchInsetManager.TouchInsetSession providesTouchInsetSession(
81             TouchInsetManager manager) {
82         return manager.createSession();
83     }
84 
85     /** */
86     @Provides
87     @DreamOverlayComponent.DreamOverlayScope
providesTouchInsetManager(@ain Executor executor, DreamOverlayContainerView view)88     public static TouchInsetManager providesTouchInsetManager(@Main Executor executor,
89             DreamOverlayContainerView view) {
90         return new TouchInsetManager(executor, view);
91     }
92 
93     /** */
94     @Provides
95     @DreamOverlayComponent.DreamOverlayScope
providesDreamOverlayStatusBarView( DreamOverlayContainerView view)96     public static DreamOverlayStatusBarView providesDreamOverlayStatusBarView(
97             DreamOverlayContainerView view) {
98         return Preconditions.checkNotNull(view.findViewById(R.id.dream_overlay_status_bar),
99                 "R.id.status_bar must not be null");
100     }
101 
102     /** */
103     @Provides
104     @DreamOverlayComponent.DreamOverlayScope
105     @Named(MAX_BURN_IN_OFFSET)
providesMaxBurnInOffset(@ain Resources resources)106     static int providesMaxBurnInOffset(@Main Resources resources) {
107         return resources.getDimensionPixelSize(R.dimen.default_burn_in_prevention_offset);
108     }
109 
110     /** */
111     @Provides
112     @Named(BURN_IN_PROTECTION_UPDATE_INTERVAL)
providesBurnInProtectionUpdateInterval(@ain Resources resources)113     static long providesBurnInProtectionUpdateInterval(@Main Resources resources) {
114         return resources.getInteger(
115                 R.integer.config_dreamOverlayBurnInProtectionUpdateIntervalMillis);
116     }
117 
118     /** */
119     @Provides
120     @Named(MILLIS_UNTIL_FULL_JITTER)
providesMillisUntilFullJitter(@ain Resources resources)121     static long providesMillisUntilFullJitter(@Main Resources resources) {
122         return resources.getInteger(R.integer.config_dreamOverlayMillisUntilFullJitter);
123     }
124 
125     /**
126      * The blur radius applied to the dream overlay at dream entry and exit.
127      */
128     @Provides
129     @Named(DREAM_BLUR_RADIUS)
providesDreamBlurRadius(@ain Resources resources)130     static int providesDreamBlurRadius(@Main Resources resources) {
131         return resources.getDimensionPixelSize(R.dimen.dream_overlay_anim_blur_radius);
132     }
133 
134     /**
135      * Duration in milliseconds of the dream in un-blur animation.
136      */
137     @Provides
138     @Named(DREAM_IN_BLUR_ANIMATION_DURATION)
providesDreamInBlurAnimationDuration(@ain Resources resources)139     static long providesDreamInBlurAnimationDuration(@Main Resources resources) {
140         return (long) resources.getInteger(R.integer.config_dreamOverlayInBlurDurationMs);
141     }
142 
143     /**
144      * Duration in milliseconds of the dream in complications fade-in animation.
145      */
146     @Provides
147     @Named(DREAM_IN_COMPLICATIONS_ANIMATION_DURATION)
providesDreamInComplicationsAnimationDuration(@ain Resources resources)148     static long providesDreamInComplicationsAnimationDuration(@Main Resources resources) {
149         return (long) resources.getInteger(R.integer.config_dreamOverlayInComplicationsDurationMs);
150     }
151 
152     /**
153      * Provides the number of pixels to translate complications when entering a dream.
154      */
155     @Provides
156     @Named(DREAM_IN_TRANSLATION_Y_DISTANCE)
157     @DreamOverlayComponent.DreamOverlayScope
providesDreamInComplicationsTranslationY(@ain Resources resources)158     static int providesDreamInComplicationsTranslationY(@Main Resources resources) {
159         return resources.getDimensionPixelSize(R.dimen.dream_overlay_entry_y_offset);
160     }
161 
162     /**
163      * Provides the duration in ms of the y-translation when dream enters.
164      */
165     @Provides
166     @Named(DREAM_IN_TRANSLATION_Y_DURATION)
167     @DreamOverlayComponent.DreamOverlayScope
providesDreamInComplicationsTranslationYDuration(@ain Resources resources)168     static long providesDreamInComplicationsTranslationYDuration(@Main Resources resources) {
169         return (long) resources.getInteger(R.integer.config_dreamOverlayInTranslationYDurationMs);
170     }
171 
172     @Provides
173     @DreamOverlayComponent.DreamOverlayScope
providesLifecycleOwner(Lazy<LifecycleRegistry> lifecycleRegistryLazy)174     static LifecycleOwner providesLifecycleOwner(Lazy<LifecycleRegistry> lifecycleRegistryLazy) {
175         return () -> lifecycleRegistryLazy.get();
176     }
177 
178     @Provides
179     @DreamOverlayComponent.DreamOverlayScope
providesLifecycleRegistry(LifecycleOwner lifecycleOwner)180     static LifecycleRegistry providesLifecycleRegistry(LifecycleOwner lifecycleOwner) {
181         return new LifecycleRegistry(lifecycleOwner);
182     }
183 
184     @Provides
185     @DreamOverlayComponent.DreamOverlayScope
providesLifecycle(LifecycleOwner lifecycleOwner)186     static Lifecycle providesLifecycle(LifecycleOwner lifecycleOwner) {
187         return lifecycleOwner.getLifecycle();
188     }
189 }
190