1 /* 2 * Copyright (C) 2024 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.systemui.complication.OpenHubComplication; 28 import com.android.systemui.res.R; 29 import com.android.systemui.shared.shadow.DoubleShadowIconDrawable; 30 import com.android.systemui.shared.shadow.DoubleShadowTextHelper; 31 32 import dagger.BindsInstance; 33 import dagger.Module; 34 import dagger.Provides; 35 import dagger.Subcomponent; 36 37 import java.lang.annotation.Documented; 38 import java.lang.annotation.Retention; 39 40 import javax.inject.Named; 41 import javax.inject.Scope; 42 43 /** 44 * Responsible for generating dependencies for the {@link OpenHubComplication}. 45 */ 46 @Subcomponent(modules = OpenHubComplicationComponent.OpenHubModule.class) 47 @OpenHubComplicationComponent.OpenHubComplicationScope 48 public interface OpenHubComplicationComponent { 49 /** 50 * Creates a view holder for the open hub complication. 51 */ getViewHolder()52 OpenHubComplication.OpenHubChipViewHolder getViewHolder(); 53 54 /** 55 * Scope of the open hub complication. 56 */ 57 @Documented 58 @Retention(RUNTIME) 59 @Scope 60 @interface OpenHubComplicationScope { 61 } 62 63 /** 64 * Factory that generates a {@link OpenHubComplicationComponent}. 65 */ 66 @Subcomponent.Factory 67 interface Factory { 68 /** 69 * Creates an instance of {@link OpenHubComplicationComponent}. 70 */ create(@indsInstance Resources resources)71 OpenHubComplicationComponent create(@BindsInstance Resources resources); 72 } 73 74 /** 75 * Scoped injected values for the {@link OpenHubComplicationComponent}. 76 */ 77 @Module 78 interface OpenHubModule { 79 String OPEN_HUB_CHIP_VIEW = "open_hub_chip_view"; 80 String OPEN_HUB_BACKGROUND_DRAWABLE = "open_hub_background_drawable"; 81 82 /** 83 * Provides the dream open hub chip view. 84 */ 85 @Provides 86 @OpenHubComplicationScope 87 @Named(OPEN_HUB_CHIP_VIEW) provideOpenHubChipView( LayoutInflater layoutInflater, @Named(OPEN_HUB_BACKGROUND_DRAWABLE) Drawable backgroundDrawable)88 static ImageView provideOpenHubChipView( 89 LayoutInflater layoutInflater, 90 @Named(OPEN_HUB_BACKGROUND_DRAWABLE) Drawable backgroundDrawable) { 91 final ImageView chip = 92 (ImageView) layoutInflater.inflate(R.layout.dream_overlay_open_hub_chip, 93 null, false); 94 chip.setBackground(backgroundDrawable); 95 96 return chip; 97 } 98 99 /** 100 * Provides the background drawable for the open hub chip. 101 */ 102 @Provides 103 @OpenHubComplicationScope 104 @Named(OPEN_HUB_BACKGROUND_DRAWABLE) providesOpenHubBackground(Context context, Resources resources)105 static Drawable providesOpenHubBackground(Context context, Resources resources) { 106 return new DoubleShadowIconDrawable(createShadowInfo( 107 resources, 108 R.dimen.dream_overlay_bottom_affordance_key_text_shadow_radius, 109 R.dimen.dream_overlay_bottom_affordance_key_text_shadow_dx, 110 R.dimen.dream_overlay_bottom_affordance_key_text_shadow_dy, 111 R.dimen.dream_overlay_bottom_affordance_key_shadow_alpha 112 ), 113 createShadowInfo( 114 resources, 115 R.dimen.dream_overlay_bottom_affordance_ambient_text_shadow_radius, 116 R.dimen.dream_overlay_bottom_affordance_ambient_text_shadow_dx, 117 R.dimen.dream_overlay_bottom_affordance_ambient_text_shadow_dy, 118 R.dimen.dream_overlay_bottom_affordance_ambient_shadow_alpha 119 ), 120 resources.getDrawable(R.drawable.dream_overlay_bottom_affordance_bg), 121 resources.getDimensionPixelOffset( 122 R.dimen.dream_overlay_bottom_affordance_width), 123 resources.getDimensionPixelSize(R.dimen.dream_overlay_bottom_affordance_inset) 124 ); 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