Merge "Add shadow to dream overlay home controls button." into udc-dev

This commit is contained in:
Bryce Lee
2023-05-15 20:20:41 +00:00
committed by Android (Google) Code Review
7 changed files with 96 additions and 10 deletions

View File

@@ -18,9 +18,7 @@
-->
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
android:shape="rectangle">
<solid android:color="?androidprv:attr/colorSurface"/>
<size
android:width="@dimen/dream_overlay_bottom_affordance_height"
android:height="@dimen/dream_overlay_bottom_affordance_width"/>

View File

@@ -21,8 +21,6 @@
android:layout_width="@dimen/dream_overlay_bottom_affordance_width"
android:layout_gravity="bottom|start"
android:padding="@dimen/dream_overlay_bottom_affordance_padding"
android:background="@drawable/dream_overlay_bottom_affordance_bg"
android:scaleType="fitCenter"
android:tint="?android:attr/textColorPrimary"
android:src="@drawable/controls_icon"
android:contentDescription="@string/quick_controls_title" />

View File

@@ -1643,6 +1643,19 @@
<dimen name="dream_overlay_bottom_affordance_height">64dp</dimen>
<dimen name="dream_overlay_bottom_affordance_width">64dp</dimen>
<dimen name="dream_overlay_bottom_affordance_radius">32dp</dimen>
<dimen name="dream_overlay_bottom_affordance_key_text_shadow_dx">0.5dp</dimen>
<dimen name="dream_overlay_bottom_affordance_key_text_shadow_dy">0.5dp</dimen>
<dimen name="dream_overlay_bottom_affordance_key_text_shadow_radius">1dp</dimen>
<item name="dream_overlay_bottom_affordance_key_shadow_alpha" format="float" type="dimen">
0.35
</item>
<dimen name="dream_overlay_bottom_affordance_ambient_text_shadow_dx">0.5dp</dimen>
<dimen name="dream_overlay_bottom_affordance_ambient_text_shadow_dy">0.5dp</dimen>
<dimen name="dream_overlay_bottom_affordance_ambient_text_shadow_radius">2dp</dimen>
<item name="dream_overlay_bottom_affordance_ambient_shadow_alpha" format="float" type="dimen">
0.4
</item>
<dimen name="dream_overlay_bottom_affordance_inset">1dp</dimen>
<dimen name="dream_overlay_bottom_affordance_padding">14dp</dimen>
<dimen name="dream_overlay_complication_clock_time_text_size">86dp</dimen>
<dimen name="dream_overlay_complication_clock_subtitle_text_size">24sp</dimen>

View File

@@ -15,6 +15,7 @@
*/
package com.android.systemui.shared.shadow
import android.content.res.ColorStateList
import android.graphics.BlendMode
import android.graphics.Canvas
import android.graphics.Color
@@ -106,6 +107,14 @@ class DoubleShadowIconDrawable(
mIconDrawable.draw(canvas)
}
override fun getIntrinsicHeight(): Int {
return mCanvasSize
}
override fun getIntrinsicWidth(): Int {
return mCanvasSize
}
override fun getOpacity(): Int {
return PixelFormat.TRANSPARENT
}
@@ -121,4 +130,8 @@ class DoubleShadowIconDrawable(
override fun setTint(color: Int) {
mIconDrawable.setTint(color)
}
override fun setTintList(tint: ColorStateList?) {
mIconDrawable.setTintList(tint)
}
}

View File

@@ -24,6 +24,7 @@ import static com.android.systemui.controls.dagger.ControlsComponent.Visibility.
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
@@ -39,6 +40,7 @@ import com.android.systemui.controls.dagger.ControlsComponent;
import com.android.systemui.controls.management.ControlsListingController;
import com.android.systemui.controls.ui.ControlsActivity;
import com.android.systemui.controls.ui.ControlsUiController;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dagger.qualifiers.SystemUser;
import com.android.systemui.dreams.DreamOverlayStateController;
import com.android.systemui.plugins.ActivityStarter;
@@ -56,17 +58,20 @@ import javax.inject.Named;
* devices at home like lights and thermostats).
*/
public class DreamHomeControlsComplication implements Complication {
private final Resources mResources;
private final DreamHomeControlsComplicationComponent.Factory mComponentFactory;
@Inject
public DreamHomeControlsComplication(
@Main Resources resources,
DreamHomeControlsComplicationComponent.Factory componentFactory) {
mResources = resources;
mComponentFactory = componentFactory;
}
@Override
public ViewHolder createView(ComplicationViewModel model) {
return mComponentFactory.create().getViewHolder();
return mComponentFactory.create(mResources).getViewHolder();
}
@Override

View File

@@ -18,12 +18,19 @@ package com.android.systemui.complication.dagger;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.widget.ImageView;
import com.android.settingslib.Utils;
import com.android.systemui.R;
import com.android.systemui.complication.DreamHomeControlsComplication;
import com.android.systemui.shared.shadow.DoubleShadowIconDrawable;
import com.android.systemui.shared.shadow.DoubleShadowTextHelper;
import dagger.BindsInstance;
import dagger.Module;
import dagger.Provides;
import dagger.Subcomponent;
@@ -59,7 +66,7 @@ public interface DreamHomeControlsComplicationComponent {
*/
@Subcomponent.Factory
interface Factory {
DreamHomeControlsComplicationComponent create();
DreamHomeControlsComplicationComponent create(@BindsInstance Resources resources);
}
/**
@@ -68,6 +75,7 @@ public interface DreamHomeControlsComplicationComponent {
@Module
interface DreamHomeControlsModule {
String DREAM_HOME_CONTROLS_CHIP_VIEW = "dream_home_controls_chip_view";
String DREAM_HOME_CONTROLS_BACKGROUND_DRAWABLE = "dream_home_controls_background_drawable";
/**
* Provides the dream home controls chip view.
@@ -75,9 +83,56 @@ public interface DreamHomeControlsComplicationComponent {
@Provides
@DreamHomeControlsComplicationScope
@Named(DREAM_HOME_CONTROLS_CHIP_VIEW)
static ImageView provideHomeControlsChipView(LayoutInflater layoutInflater) {
return (ImageView) layoutInflater.inflate(R.layout.dream_overlay_home_controls_chip,
null, false);
static ImageView provideHomeControlsChipView(
LayoutInflater layoutInflater,
@Named(DREAM_HOME_CONTROLS_BACKGROUND_DRAWABLE) Drawable backgroundDrawable) {
final ImageView chip =
(ImageView) layoutInflater.inflate(R.layout.dream_overlay_home_controls_chip,
null, false);
chip.setBackground(backgroundDrawable);
return chip;
}
@Provides
@DreamHomeControlsComplicationScope
@Named(DREAM_HOME_CONTROLS_BACKGROUND_DRAWABLE)
static Drawable providesHomeControlsBackground(Context context, Resources resources) {
final Drawable background = new DoubleShadowIconDrawable(createShadowInfo(
resources,
R.dimen.dream_overlay_bottom_affordance_key_text_shadow_radius,
R.dimen.dream_overlay_bottom_affordance_key_text_shadow_dx,
R.dimen.dream_overlay_bottom_affordance_key_text_shadow_dy,
R.dimen.dream_overlay_bottom_affordance_key_shadow_alpha
),
createShadowInfo(
resources,
R.dimen.dream_overlay_bottom_affordance_ambient_text_shadow_radius,
R.dimen.dream_overlay_bottom_affordance_ambient_text_shadow_dx,
R.dimen.dream_overlay_bottom_affordance_ambient_text_shadow_dy,
R.dimen.dream_overlay_bottom_affordance_ambient_shadow_alpha
),
resources.getDrawable(R.drawable.dream_overlay_bottom_affordance_bg),
resources.getDimensionPixelOffset(
R.dimen.dream_overlay_bottom_affordance_width),
resources.getDimensionPixelSize(R.dimen.dream_overlay_bottom_affordance_inset)
);
background.setTintList(
Utils.getColorAttr(context, com.android.internal.R.attr.colorSurface));
return background;
}
private static DoubleShadowTextHelper.ShadowInfo createShadowInfo(Resources resources,
int blurId, int offsetXId, int offsetYId, int alphaId) {
return new DoubleShadowTextHelper.ShadowInfo(
resources.getDimension(blurId),
resources.getDimension(offsetXId),
resources.getDimension(offsetYId),
resources.getFloat(alphaId)
);
}
}
}

View File

@@ -29,6 +29,7 @@ import static org.mockito.Mockito.when;
import android.content.ComponentName;
import android.content.Context;
import android.content.res.Resources;
import android.testing.AndroidTestingRunner;
import android.view.View;
@@ -72,6 +73,9 @@ public class DreamHomeControlsComplicationTest extends SysuiTestCase {
@Mock
private Context mContext;
@Mock
private Resources mResources;
@Mock
private ControlsComponent mControlsComponent;
@@ -118,7 +122,7 @@ public class DreamHomeControlsComplicationTest extends SysuiTestCase {
@Test
public void complicationType() {
final DreamHomeControlsComplication complication =
new DreamHomeControlsComplication(mComponentFactory);
new DreamHomeControlsComplication(mResources, mComponentFactory);
assertThat(complication.getRequiredTypeAvailability()).isEqualTo(
COMPLICATION_TYPE_HOME_CONTROLS);
}