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.media.dream.dagger; 18 19 import static com.android.systemui.complication.dagger.RegisteredComplicationsModule.DREAM_MEDIA_COMPLICATION_WEIGHT; 20 21 import static java.lang.annotation.RetentionPolicy.RUNTIME; 22 23 import android.content.Context; 24 import android.view.ViewGroup; 25 import android.widget.FrameLayout; 26 27 import com.android.systemui.complication.ComplicationLayoutParams; 28 import com.android.systemui.media.dream.MediaViewHolder; 29 30 import dagger.Module; 31 import dagger.Provides; 32 import dagger.Subcomponent; 33 34 import java.lang.annotation.Documented; 35 import java.lang.annotation.Retention; 36 37 import javax.inject.Named; 38 import javax.inject.Scope; 39 40 /** 41 * {@link MediaComplicationComponent} is responsible for generating dependencies surrounding the 42 * media {@link com.android.systemui.complication.Complication}, such as view controllers 43 * and layout details. 44 */ 45 @Subcomponent(modules = { 46 MediaComplicationComponent.MediaComplicationModule.class, 47 }) 48 @MediaComplicationComponent.MediaComplicationScope 49 public interface MediaComplicationComponent { 50 @Documented 51 @Retention(RUNTIME) 52 @Scope 53 @interface MediaComplicationScope {} 54 55 /** 56 * Generates {@link MediaComplicationComponent}. 57 */ 58 @Subcomponent.Factory 59 interface Factory { create()60 MediaComplicationComponent create(); 61 } 62 63 /** 64 * Creates {@link MediaViewHolder}. 65 */ getViewHolder()66 MediaViewHolder getViewHolder(); 67 68 /** 69 * Scoped values for {@link MediaComplicationComponent}. 70 */ 71 @Module 72 interface MediaComplicationModule { 73 String MEDIA_COMPLICATION_CONTAINER = "media_complication_container"; 74 String MEDIA_COMPLICATION_LAYOUT_PARAMS = "media_complication_layout_params"; 75 76 /** 77 * Provides the complication view. 78 */ 79 @Provides 80 @MediaComplicationScope 81 @Named(MEDIA_COMPLICATION_CONTAINER) provideComplicationContainer(Context context)82 static FrameLayout provideComplicationContainer(Context context) { 83 return new FrameLayout(context); 84 } 85 86 /** 87 * Provides the layout parameters for the complication view. 88 */ 89 @Provides 90 @MediaComplicationScope 91 @Named(MEDIA_COMPLICATION_LAYOUT_PARAMS) provideLayoutParams()92 static ComplicationLayoutParams provideLayoutParams() { 93 return new ComplicationLayoutParams(0, 94 ViewGroup.LayoutParams.WRAP_CONTENT, 95 ComplicationLayoutParams.POSITION_TOP 96 | ComplicationLayoutParams.POSITION_START, 97 ComplicationLayoutParams.DIRECTION_DOWN, 98 DREAM_MEDIA_COMPLICATION_WEIGHT, 99 true); 100 } 101 } 102 } 103