Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 45f1e819 authored by Matías Hernández's avatar Matías Hernández
Browse files

Icon picker: Styling improvements

Instead of a the plain appearance of a EntityHeaderController, make the top icon bigger and use the same circled style as the choices in the list. Also highlight the current icon in the list as selected, even if it is the default for the mode type.

Also cleaned up controllers that don't need a ZenModesBackend to not receive it.

(Both of these changes also line up with the "new mode" fragment that is incoming).

Bug: 333901673
Bug: 326442408
Test: atest com.android.settings.notification.modes
Flag: android.app.modes_ui
Change-Id: I0c9f3e34019a1a6c48658933dde545ad8d7399ae
parent 2639c194
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -24,8 +24,8 @@

    <ImageView
        android:id="@+id/icon_image_view"
        android:layout_width="@dimen/zen_mode_icon_list_circle_diameter"
        android:layout_height="@dimen/zen_mode_icon_list_circle_diameter"
        android:layout_width="@dimen/zen_mode_icon_list_item_circle_diameter"
        android:layout_height="@dimen/zen_mode_icon_list_item_circle_diameter"
        android:importantForAccessibility="no"
        android:layout_gravity="center" />
</FrameLayout>
+4 −2
Original line number Diff line number Diff line
@@ -502,7 +502,9 @@
    <dimen name="audio_streams_qrcode_preview_radius">30dp</dimen>

    <!-- Zen Modes -->
    <dimen name="zen_mode_icon_list_header_circle_diameter">90dp</dimen>
    <dimen name="zen_mode_icon_list_header_icon_size">48dp</dimen>
    <dimen name="zen_mode_icon_list_item_size">96dp</dimen>
    <dimen name="zen_mode_icon_list_circle_diameter">56dp</dimen>
    <dimen name="zen_mode_icon_list_icon_size">32dp</dimen>
    <dimen name="zen_mode_icon_list_item_circle_diameter">56dp</dimen>
    <dimen name="zen_mode_icon_list_item_icon_size">32dp</dimen>
</resources>
+23 −10
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.settings.notification.modes;

import static com.google.common.base.Preconditions.checkState;

import android.app.Flags;
import android.content.Context;
import android.service.notification.ZenPolicy;
@@ -30,8 +32,6 @@ import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.notification.modes.ZenMode;
import com.android.settingslib.notification.modes.ZenModesBackend;

import com.google.common.base.Preconditions;

import java.util.function.Function;

/**
@@ -41,8 +41,8 @@ abstract class AbstractZenModePreferenceController extends AbstractPreferenceCon

    private static final String TAG = "AbstractZenModePreferenceController";

    @Nullable
    protected ZenModesBackend mBackend;
    @Nullable protected final ZenModesBackend mBackend;


    @Nullable  // only until setZenMode() is called
    private ZenMode mZenMode;
@@ -50,14 +50,27 @@ abstract class AbstractZenModePreferenceController extends AbstractPreferenceCon
    @NonNull
    private final String mKey;

    // ZenModesBackend should only be passed in if the preference controller may set the user's
    // policy for this zen mode. Otherwise, if the preference controller is essentially read-only
    // and leads to a further Settings screen, backend should be null.
    /**
     * Constructor suitable for "read-only" controllers (e.g. link to a different sub-screen.
     * Controllers that call this constructor to initialize themselves <em>cannot</em> call
     * {@link #saveMode} or {@link #savePolicy} later.
     */
    AbstractZenModePreferenceController(@NonNull Context context, @NonNull String key) {
        super(context);
        mKey = key;
        mBackend = null;
    }

    /**
     * Constructor suitable for controllers that will update the associated {@link ZenMode}.
     * Controllers that call this constructor to initialize themselves may call {@link #saveMode} or
     * {@link #savePolicy} later.
     */
    AbstractZenModePreferenceController(@NonNull Context context, @NonNull String key,
            @Nullable ZenModesBackend backend) {
            @NonNull ZenModesBackend backend) {
        super(context);
        mBackend = backend;
        mKey = key;
        mBackend = backend;
    }

    @Override
@@ -135,7 +148,7 @@ abstract class AbstractZenModePreferenceController extends AbstractPreferenceCon
     *                instance is ok.
     */
    protected final boolean saveMode(Function<ZenMode, ZenMode> updater) {
        Preconditions.checkState(mBackend != null);
        checkState(mBackend != null);
        ZenMode mode = mZenMode;
        if (mode == null) {
            Log.wtf(TAG, "Cannot save mode, it hasn't been loaded (" + getClass() + ")");
+44 −21
Original line number Diff line number Diff line
@@ -19,14 +19,17 @@ package com.android.settings.notification.modes;
import static com.google.common.base.Preconditions.checkNotNull;

import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.view.Gravity;

import androidx.annotation.AttrRes;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Px;

import com.android.settings.R;
import com.android.settingslib.Utils;
@@ -49,32 +52,52 @@ class IconUtil {
    }

    /**
     * Returns a variant of the supplied {@code icon} to be used in the icon picker. The inner icon
     * is 36x36dp and it's contained into a circle of diameter 54dp. It's also set up so that
     * selection and pressed states are represented in the color.
     * Returns a variant of the supplied {@code icon} to be used as the header in the icon picker.
     * The inner icon is 48x48dp and it's contained into a circle of diameter 90dp.
     */
    static Drawable makeIconCircle(@NonNull Context context, @NonNull Drawable icon) {
    static Drawable makeBigIconCircle(@NonNull Context context, Drawable icon) {
        return composeIconCircle(
                Utils.getColorAttr(context,
                        com.android.internal.R.attr.materialColorSecondaryContainer),
                context.getResources().getDimensionPixelSize(
                        R.dimen.zen_mode_icon_list_header_circle_diameter),
                icon,
                Utils.getColorAttr(context,
                        com.android.internal.R.attr.materialColorOnSecondaryContainer),
                context.getResources().getDimensionPixelSize(
                        R.dimen.zen_mode_icon_list_header_icon_size));
    }

    /**
     * Returns a variant of the supplied {@code icon} to be used as an option in the icon picker.
     * The inner icon is 36x36dp and it's contained into a circle of diameter 54dp. It's also set up
     * so that selection and pressed states are represented in the color.
     */
    static Drawable makeSmallIconCircle(@NonNull Context context, @DrawableRes int iconResId) {
        return composeIconCircle(
                context.getColorStateList(R.color.modes_icon_picker_item_background),
                context.getResources().getDimensionPixelSize(
                        R.dimen.zen_mode_icon_list_item_circle_diameter),
                checkNotNull(context.getDrawable(iconResId)),
                context.getColorStateList(R.color.modes_icon_picker_item_icon),
                context.getResources().getDimensionPixelSize(
                        R.dimen.zen_mode_icon_list_item_icon_size));
    }

    private static Drawable composeIconCircle(ColorStateList circleColor, @Px int circleDiameterPx,
            Drawable icon, ColorStateList iconColor, @Px int iconSizePx) {
        ShapeDrawable background = new ShapeDrawable(new OvalShape());
        background.setTintList(
                context.getColorStateList(R.color.modes_icon_picker_item_background));
        icon = icon.mutate();
        icon.setTintList(
                context.getColorStateList(R.color.modes_icon_picker_item_icon));
        background.setTintList(circleColor);
        Drawable foreground = checkNotNull(icon.getConstantState()).newDrawable().mutate();
        foreground.setTintList(iconColor);

        LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { background, icon });
        LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { background, foreground });

        int circleDiameter = context.getResources().getDimensionPixelSize(
                R.dimen.zen_mode_icon_list_circle_diameter);
        int iconSize = context.getResources().getDimensionPixelSize(
                R.dimen.zen_mode_icon_list_icon_size);
        int iconPadding = (circleDiameter - iconSize) / 2;
        layerDrawable.setBounds(0, 0, circleDiameter, circleDiameter);
        layerDrawable.setLayerInset(1, iconPadding, iconPadding, iconPadding, iconPadding);
        layerDrawable.setBounds(0, 0, circleDiameterPx, circleDiameterPx);
        layerDrawable.setLayerSize(0, circleDiameterPx, circleDiameterPx);
        layerDrawable.setLayerGravity(1, Gravity.CENTER);
        layerDrawable.setLayerSize(1, iconSizePx, iconSizePx);

        return layerDrawable;
    }

    static Drawable makeIconCircle(@NonNull Context context, @DrawableRes int iconResId) {
        return makeIconCircle(context, checkNotNull(context.getDrawable(iconResId)));
    }
}
+2 −5
Original line number Diff line number Diff line
@@ -22,20 +22,17 @@ import android.content.Context;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.Preference;

import com.android.settings.R;
import com.android.settings.core.SubSettingLauncher;
import com.android.settingslib.notification.modes.ZenMode;
import com.android.settingslib.notification.modes.ZenModesBackend;
import com.android.settingslib.widget.ActionButtonsPreference;

class ZenModeActionsPreferenceController extends AbstractZenModePreferenceController {

    ZenModeActionsPreferenceController(@NonNull Context context, @NonNull String key,
            @Nullable ZenModesBackend backend) {
        super(context, key, backend);
    ZenModeActionsPreferenceController(@NonNull Context context, @NonNull String key) {
        super(context, key);
    }

    @Override
Loading