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 static java.lang.annotation.RetentionPolicy.RUNTIME; 20 21 import android.content.Context; 22 import android.content.res.Resources; 23 import android.graphics.drawable.Drawable; 24 import android.view.LayoutInflater; 25 import android.widget.ImageView; 26 27 import com.android.settingslib.Utils; 28 import com.android.systemui.R; 29 import com.android.systemui.complication.DreamHomeControlsComplication; 30 import com.android.systemui.shared.shadow.DoubleShadowIconDrawable; 31 import com.android.systemui.shared.shadow.DoubleShadowTextHelper; 32 33 import dagger.BindsInstance; 34 import dagger.Module; 35 import dagger.Provides; 36 import dagger.Subcomponent; 37 38 39 import java.lang.annotation.Documented; 40 import java.lang.annotation.Retention; 41 42 import javax.inject.Named; 43 import javax.inject.Scope; 44 45 /** 46 * Responsible for generating dependencies for the {@link DreamHomeControlsComplication}. 47 */ 48 @Subcomponent(modules = DreamHomeControlsComplicationComponent.DreamHomeControlsModule.class) 49 @DreamHomeControlsComplicationComponent.DreamHomeControlsComplicationScope 50 public interface DreamHomeControlsComplicationComponent { 51 /** 52 * Creates a view holder for the home controls complication. 53 */ getViewHolder()54 DreamHomeControlsComplication.DreamHomeControlsChipViewHolder getViewHolder(); 55 56 /** 57 * Scope of the home controls complication. 58 */ 59 @Documented 60 @Retention(RUNTIME) 61 @Scope 62 @interface DreamHomeControlsComplicationScope {} 63 64 /** 65 * Factory that generates a {@link DreamHomeControlsComplicationComponent}. 66 */ 67 @Subcomponent.Factory 68 interface Factory { create(@indsInstance Resources resources)69 DreamHomeControlsComplicationComponent create(@BindsInstance Resources resources); 70 } 71 72 /** 73 * Scoped injected values for the {@link DreamHomeControlsComplicationComponent}. 74 */ 75 @Module 76 interface DreamHomeControlsModule { 77 String DREAM_HOME_CONTROLS_CHIP_VIEW = "dream_home_controls_chip_view"; 78 String DREAM_HOME_CONTROLS_BACKGROUND_DRAWABLE = "dream_home_controls_background_drawable"; 79 80 /** 81 * Provides the dream home controls chip view. 82 */ 83 @Provides 84 @DreamHomeControlsComplicationScope 85 @Named(DREAM_HOME_CONTROLS_CHIP_VIEW) provideHomeControlsChipView( LayoutInflater layoutInflater, @Named(DREAM_HOME_CONTROLS_BACKGROUND_DRAWABLE) Drawable backgroundDrawable)86 static ImageView provideHomeControlsChipView( 87 LayoutInflater layoutInflater, 88 @Named(DREAM_HOME_CONTROLS_BACKGROUND_DRAWABLE) Drawable backgroundDrawable) { 89 final ImageView chip = 90 (ImageView) layoutInflater.inflate(R.layout.dream_overlay_home_controls_chip, 91 null, false); 92 chip.setBackground(backgroundDrawable); 93 94 return chip; 95 } 96 97 @Provides 98 @DreamHomeControlsComplicationScope 99 @Named(DREAM_HOME_CONTROLS_BACKGROUND_DRAWABLE) providesHomeControlsBackground(Context context, Resources resources)100 static Drawable providesHomeControlsBackground(Context context, Resources resources) { 101 final Drawable background = new DoubleShadowIconDrawable(createShadowInfo( 102 resources, 103 R.dimen.dream_overlay_bottom_affordance_key_text_shadow_radius, 104 R.dimen.dream_overlay_bottom_affordance_key_text_shadow_dx, 105 R.dimen.dream_overlay_bottom_affordance_key_text_shadow_dy, 106 R.dimen.dream_overlay_bottom_affordance_key_shadow_alpha 107 ), 108 createShadowInfo( 109 resources, 110 R.dimen.dream_overlay_bottom_affordance_ambient_text_shadow_radius, 111 R.dimen.dream_overlay_bottom_affordance_ambient_text_shadow_dx, 112 R.dimen.dream_overlay_bottom_affordance_ambient_text_shadow_dy, 113 R.dimen.dream_overlay_bottom_affordance_ambient_shadow_alpha 114 ), 115 resources.getDrawable(R.drawable.dream_overlay_bottom_affordance_bg), 116 resources.getDimensionPixelOffset( 117 R.dimen.dream_overlay_bottom_affordance_width), 118 resources.getDimensionPixelSize(R.dimen.dream_overlay_bottom_affordance_inset) 119 ); 120 121 background.setTintList( 122 Utils.getColorAttr(context, com.android.internal.R.attr.colorSurface)); 123 124 return background; 125 } 126 createShadowInfo(Resources resources, int blurId, int offsetXId, int offsetYId, int alphaId)127 private static DoubleShadowTextHelper.ShadowInfo createShadowInfo(Resources resources, 128 int blurId, int offsetXId, int offsetYId, int alphaId) { 129 130 return new DoubleShadowTextHelper.ShadowInfo( 131 resources.getDimension(blurId), 132 resources.getDimension(offsetXId), 133 resources.getDimension(offsetYId), 134 resources.getFloat(alphaId) 135 ); 136 } 137 } 138 } 139