• 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.View;
22 import android.view.ViewGroup;
23 
24 import androidx.lifecycle.Lifecycle;
25 import androidx.lifecycle.LifecycleOwner;
26 
27 import com.android.internal.util.Preconditions;
28 import com.android.systemui.ambient.statusbar.dagger.AmbientStatusBarComponent;
29 import com.android.systemui.ambient.statusbar.ui.AmbientStatusBarView;
30 import com.android.systemui.ambient.statusbar.ui.AmbientStatusBarViewController;
31 import com.android.systemui.dagger.qualifiers.Main;
32 import com.android.systemui.dreams.DreamOverlayContainerView;
33 import com.android.systemui.res.R;
34 import com.android.systemui.touch.TouchInsetManager;
35 
36 import dagger.Module;
37 import dagger.Provides;
38 
39 import javax.inject.Named;
40 
41 /** Dagger module for {@link DreamOverlayComponent}. */
42 @Module
43 public abstract class DreamOverlayModule {
44     public static final String DREAM_OVERLAY_CONTENT_VIEW = "dream_overlay_content_view";
45     public static final String HUB_GESTURE_INDICATOR_VIEW = "hub_gesture_indicator_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      * Gesture indicator bar on the right edge of the screen to indicate to users that they can
80      * swipe to see their widgets on lock screen.
81      */
82     @Provides
83     @DreamOverlayComponent.DreamOverlayScope
84     @Named(HUB_GESTURE_INDICATOR_VIEW)
providesHubGestureIndicatorView(DreamOverlayContainerView view)85     public static View providesHubGestureIndicatorView(DreamOverlayContainerView view) {
86         return Preconditions.checkNotNull(view.findViewById(R.id.glanceable_hub_handle),
87                 "R.id.glanceable_hub_handle must not be null");
88     }
89 
90     /** */
91     @Provides
providesTouchInsetSession( TouchInsetManager manager)92     public static TouchInsetManager.TouchInsetSession providesTouchInsetSession(
93             TouchInsetManager manager) {
94         return manager.createSession();
95     }
96 
97     /** */
98     @Provides
99     @DreamOverlayComponent.DreamOverlayScope
providesDreamOverlayStatusBarView( DreamOverlayContainerView view)100     public static AmbientStatusBarView providesDreamOverlayStatusBarView(
101             DreamOverlayContainerView view) {
102         return Preconditions.checkNotNull(view.findViewById(R.id.dream_overlay_status_bar),
103                 "R.id.status_bar must not be null");
104     }
105 
106     /**
107      * Provides the view controller for the {@link AmbientStatusBarView}
108      */
109     @Provides
110     @DreamOverlayComponent.DreamOverlayScope
providesStatusBarViewController( AmbientStatusBarView view, AmbientStatusBarComponent.Factory factory)111     public static AmbientStatusBarViewController providesStatusBarViewController(
112             AmbientStatusBarView view, AmbientStatusBarComponent.Factory factory) {
113         return factory.create(view).getController();
114     }
115 
116     /**  */
117     @Provides
118     @DreamOverlayComponent.DreamOverlayScope
119     @Named(MAX_BURN_IN_OFFSET)
providesMaxBurnInOffset(@ain Resources resources)120     static int providesMaxBurnInOffset(@Main Resources resources) {
121         return resources.getDimensionPixelSize(R.dimen.default_burn_in_prevention_offset);
122     }
123 
124     /** */
125     @Provides
126     @Named(BURN_IN_PROTECTION_UPDATE_INTERVAL)
providesBurnInProtectionUpdateInterval(@ain Resources resources)127     static long providesBurnInProtectionUpdateInterval(@Main Resources resources) {
128         return resources.getInteger(
129                 R.integer.config_dreamOverlayBurnInProtectionUpdateIntervalMillis);
130     }
131 
132     /** */
133     @Provides
134     @Named(MILLIS_UNTIL_FULL_JITTER)
providesMillisUntilFullJitter(@ain Resources resources)135     static long providesMillisUntilFullJitter(@Main Resources resources) {
136         return resources.getInteger(R.integer.config_dreamOverlayMillisUntilFullJitter);
137     }
138 
139     /**
140      * The blur radius applied to the dream overlay at dream entry and exit.
141      */
142     @Provides
143     @Named(DREAM_BLUR_RADIUS)
providesDreamBlurRadius(@ain Resources resources)144     static int providesDreamBlurRadius(@Main Resources resources) {
145         return resources.getDimensionPixelSize(R.dimen.dream_overlay_anim_blur_radius);
146     }
147 
148     /**
149      * Duration in milliseconds of the dream in un-blur animation.
150      */
151     @Provides
152     @Named(DREAM_IN_BLUR_ANIMATION_DURATION)
providesDreamInBlurAnimationDuration(@ain Resources resources)153     static long providesDreamInBlurAnimationDuration(@Main Resources resources) {
154         return (long) resources.getInteger(R.integer.config_dreamOverlayInBlurDurationMs);
155     }
156 
157     /**
158      * Duration in milliseconds of the dream in complications fade-in animation.
159      */
160     @Provides
161     @Named(DREAM_IN_COMPLICATIONS_ANIMATION_DURATION)
providesDreamInComplicationsAnimationDuration(@ain Resources resources)162     static long providesDreamInComplicationsAnimationDuration(@Main Resources resources) {
163         return (long) resources.getInteger(R.integer.config_dreamOverlayInComplicationsDurationMs);
164     }
165 
166     /**
167      * Provides the number of pixels to translate complications when entering a dream.
168      */
169     @Provides
170     @Named(DREAM_IN_TRANSLATION_Y_DISTANCE)
171     @DreamOverlayComponent.DreamOverlayScope
providesDreamInComplicationsTranslationY(@ain Resources resources)172     static int providesDreamInComplicationsTranslationY(@Main Resources resources) {
173         return resources.getDimensionPixelSize(R.dimen.dream_overlay_entry_y_offset);
174     }
175 
176     /**
177      * Provides the duration in ms of the y-translation when dream enters.
178      */
179     @Provides
180     @Named(DREAM_IN_TRANSLATION_Y_DURATION)
181     @DreamOverlayComponent.DreamOverlayScope
providesDreamInComplicationsTranslationYDuration(@ain Resources resources)182     static long providesDreamInComplicationsTranslationYDuration(@Main Resources resources) {
183         return (long) resources.getInteger(R.integer.config_dreamOverlayInTranslationYDurationMs);
184     }
185 
186     @Provides
187     @DreamOverlayComponent.DreamOverlayScope
providesLifecycle(LifecycleOwner lifecycleOwner)188     static Lifecycle providesLifecycle(LifecycleOwner lifecycleOwner) {
189         return lifecycleOwner.getLifecycle();
190     }
191 }
192