Animate the color transition (active<->inactive) in the mode header icon
Also, don't apply the layout params, etc on each call to updateState - once per displayPreference is enough. Fixes: 356399449 Bug: 357861830 Test: manual Flag: android.app.modes_ui Change-Id: I6967ea1745377d0f514ca0f68101043f017a8fd7
This commit is contained in:
@@ -30,7 +30,9 @@ import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.graphics.drawable.ShapeDrawable;
|
||||
import android.graphics.drawable.StateListDrawable;
|
||||
import android.graphics.drawable.shapes.OvalShape;
|
||||
import android.util.StateSet;
|
||||
import android.view.Gravity;
|
||||
|
||||
import androidx.annotation.AttrRes;
|
||||
@@ -65,20 +67,42 @@ class IconUtil {
|
||||
|
||||
/**
|
||||
* Returns a variant of the supplied mode icon to be used as the header in the mode page. The
|
||||
* inner icon is 64x64 dp and it's contained in a 12-sided-cookie of 136dp diameter. It's
|
||||
* tinted with the "material secondary" color combination and the "selected" color variant
|
||||
* should be used for modes currently active.
|
||||
* mode icon is contained in a 12-sided-cookie. The color combination is "material secondary"
|
||||
* when unselected and "material primary" when selected; the switch between these two color sets
|
||||
* is animated with a cross-fade. The selected colors should be used when the mode is currently
|
||||
* active.
|
||||
*/
|
||||
static Drawable makeModeHeader(@NonNull Context context, Drawable modeIcon) {
|
||||
return composeIcons(
|
||||
checkNotNull(context.getDrawable(R.drawable.ic_zen_mode_icon_cookie)),
|
||||
context.getColorStateList(R.color.modes_icon_selectable_background),
|
||||
context.getResources().getDimensionPixelSize(
|
||||
R.dimen.zen_mode_header_size),
|
||||
Resources res = context.getResources();
|
||||
Drawable background = checkNotNull(context.getDrawable(R.drawable.ic_zen_mode_icon_cookie));
|
||||
@Px int outerSizePx = res.getDimensionPixelSize(R.dimen.zen_mode_header_size);
|
||||
@Px int innerSizePx = res.getDimensionPixelSize(R.dimen.zen_mode_header_inner_icon_size);
|
||||
|
||||
Drawable base = composeIcons(
|
||||
background,
|
||||
Utils.getColorAttr(context,
|
||||
com.android.internal.R.attr.materialColorSecondaryContainer),
|
||||
outerSizePx,
|
||||
modeIcon,
|
||||
context.getColorStateList(R.color.modes_icon_selectable_icon),
|
||||
context.getResources().getDimensionPixelSize(
|
||||
R.dimen.zen_mode_header_inner_icon_size));
|
||||
Utils.getColorAttr(context,
|
||||
com.android.internal.R.attr.materialColorOnSecondaryContainer),
|
||||
innerSizePx);
|
||||
|
||||
Drawable selected = composeIcons(
|
||||
background,
|
||||
Utils.getColorAttr(context, com.android.internal.R.attr.materialColorPrimary),
|
||||
outerSizePx,
|
||||
modeIcon,
|
||||
Utils.getColorAttr(context, com.android.internal.R.attr.materialColorOnPrimary),
|
||||
innerSizePx);
|
||||
|
||||
StateListDrawable result = new StateListDrawable();
|
||||
result.setEnterFadeDuration(res.getInteger(android.R.integer.config_mediumAnimTime));
|
||||
result.setExitFadeDuration(res.getInteger(android.R.integer.config_mediumAnimTime));
|
||||
result.addState(new int[] { android.R.attr.state_selected }, selected);
|
||||
result.addState(StateSet.WILD_CARD, base);
|
||||
result.setBounds(0, 0, outerSizePx, outerSizePx);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user