Style priority modes items in aggregator
* Different color if active. * Trigger description / "ON" / "Paused" / "Tap to set up" depending on enabled and active status (strings may be revised later). This CL also adds a helper class to create ZenModes, reducing boilerplate in unit tests. Bug: 346575288 Test: atest com.android.settings.notification.modes Flag: android.app.modes_ui Change-Id: Ia0e16b8be5284d13bed4366cbee0f92748bf2f85
This commit is contained in:
@@ -24,6 +24,7 @@ import android.graphics.drawable.LayerDrawable;
|
||||
import android.graphics.drawable.ShapeDrawable;
|
||||
import android.graphics.drawable.shapes.OvalShape;
|
||||
|
||||
import androidx.annotation.AttrRes;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
@@ -32,10 +33,18 @@ import com.android.settingslib.Utils;
|
||||
|
||||
class IconUtil {
|
||||
|
||||
static Drawable applyTint(@NonNull Context context, @NonNull Drawable icon) {
|
||||
static Drawable applyNormalTint(@NonNull Context context, @NonNull Drawable icon) {
|
||||
return applyTint(context, icon, android.R.attr.colorControlNormal);
|
||||
}
|
||||
|
||||
static Drawable applyAccentTint(@NonNull Context context, @NonNull Drawable icon) {
|
||||
return applyTint(context, icon, android.R.attr.colorAccent);
|
||||
}
|
||||
|
||||
private static Drawable applyTint(@NonNull Context context, @NonNull Drawable icon,
|
||||
@AttrRes int colorAttr) {
|
||||
icon = icon.mutate();
|
||||
icon.setTintList(
|
||||
Utils.getColorAttr(context, android.R.attr.colorControlNormal));
|
||||
icon.setTintList(Utils.getColorAttr(context, colorAttr));
|
||||
return icon;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import com.android.settingslib.notification.modes.ZenMode;
|
||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||
import com.android.settingslib.widget.LayoutPreference;
|
||||
|
||||
public class ZenModeButtonPreferenceController extends AbstractZenModePreferenceController {
|
||||
class ZenModeButtonPreferenceController extends AbstractZenModePreferenceController {
|
||||
|
||||
private Button mZenButton;
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ import androidx.preference.TwoStatePreference;
|
||||
import com.android.settingslib.notification.modes.ZenMode;
|
||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||
|
||||
public class ZenModeDisplayEffectPreferenceController extends AbstractZenModePreferenceController
|
||||
class ZenModeDisplayEffectPreferenceController extends AbstractZenModePreferenceController
|
||||
implements Preference.OnPreferenceChangeListener {
|
||||
|
||||
public ZenModeDisplayEffectPreferenceController(Context context, String key,
|
||||
@@ -37,24 +37,20 @@ public class ZenModeDisplayEffectPreferenceController extends AbstractZenModePre
|
||||
@Override
|
||||
public void updateState(Preference preference, @NonNull ZenMode zenMode) {
|
||||
TwoStatePreference pref = (TwoStatePreference) preference;
|
||||
ZenDeviceEffects effects = zenMode.getRule().getDeviceEffects();
|
||||
if (effects == null) {
|
||||
pref.setChecked(false);
|
||||
} else {
|
||||
switch (getPreferenceKey()) {
|
||||
case "effect_greyscale":
|
||||
pref.setChecked(effects.shouldDisplayGrayscale());
|
||||
break;
|
||||
case "effect_aod":
|
||||
pref.setChecked(effects.shouldSuppressAmbientDisplay());
|
||||
break;
|
||||
case "effect_wallpaper":
|
||||
pref.setChecked(effects.shouldDimWallpaper());
|
||||
break;
|
||||
case "effect_dark_theme":
|
||||
pref.setChecked(effects.shouldUseNightMode());
|
||||
break;
|
||||
}
|
||||
ZenDeviceEffects effects = zenMode.getDeviceEffects();
|
||||
switch (getPreferenceKey()) {
|
||||
case "effect_greyscale":
|
||||
pref.setChecked(effects.shouldDisplayGrayscale());
|
||||
break;
|
||||
case "effect_aod":
|
||||
pref.setChecked(effects.shouldSuppressAmbientDisplay());
|
||||
break;
|
||||
case "effect_wallpaper":
|
||||
pref.setChecked(effects.shouldDimWallpaper());
|
||||
break;
|
||||
case "effect_dark_theme":
|
||||
pref.setChecked(effects.shouldUseNightMode());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ class ZenModeHeaderController extends AbstractZenModePreferenceController {
|
||||
|
||||
FutureUtil.whenDone(
|
||||
zenMode.getIcon(mContext, ZenIconLoader.getInstance()),
|
||||
icon -> mHeaderController.setIcon(IconUtil.applyTint(mContext, icon))
|
||||
icon -> mHeaderController.setIcon(IconUtil.applyNormalTint(mContext, icon))
|
||||
.done(/* rebindActions= */ false),
|
||||
mContext.getMainExecutor());
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ class ZenModeIconPickerIconPreferenceController extends AbstractZenModePreferenc
|
||||
|
||||
FutureUtil.whenDone(
|
||||
zenMode.getIcon(mContext, ZenIconLoader.getInstance()),
|
||||
icon -> mHeaderController.setIcon(IconUtil.applyTint(mContext, icon))
|
||||
icon -> mHeaderController.setIcon(IconUtil.applyNormalTint(mContext, icon))
|
||||
.done(/* rebindActions= */ false),
|
||||
mContext.getMainExecutor());
|
||||
}
|
||||
|
||||
@@ -16,18 +16,31 @@
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
import com.android.settingslib.Utils;
|
||||
import com.android.settingslib.notification.modes.ZenIconLoader;
|
||||
import com.android.settingslib.notification.modes.ZenMode;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
/**
|
||||
* Preference representing a single mode item on the modes aggregator page. Clicking on this
|
||||
* preference leads to an individual mode's configuration page.
|
||||
*/
|
||||
class ZenModesListItemPreference extends RestrictedPreference {
|
||||
final Context mContext;
|
||||
ZenMode mZenMode;
|
||||
|
||||
private final Context mContext;
|
||||
private ZenMode mZenMode;
|
||||
|
||||
private TextView mTitleView;
|
||||
private TextView mSummaryView;
|
||||
|
||||
ZenModesListItemPreference(Context context, ZenMode zenMode) {
|
||||
super(context);
|
||||
@@ -36,6 +49,18 @@ class ZenModesListItemPreference extends RestrictedPreference {
|
||||
setKey(zenMode.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
if (holder.findViewById(android.R.id.title) instanceof TextView titleView) {
|
||||
mTitleView = titleView;
|
||||
}
|
||||
if (holder.findViewById(android.R.id.summary) instanceof TextView summaryView) {
|
||||
mSummaryView = summaryView;
|
||||
}
|
||||
updateTextColor(mZenMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick() {
|
||||
ZenSubSettingLauncher.forMode(mContext, mZenMode.getId()).launch();
|
||||
@@ -43,13 +68,47 @@ class ZenModesListItemPreference extends RestrictedPreference {
|
||||
|
||||
public void setZenMode(ZenMode zenMode) {
|
||||
mZenMode = zenMode;
|
||||
setTitle(mZenMode.getRule().getName());
|
||||
setSummary(mZenMode.getRule().getTriggerDescription());
|
||||
setIconSize(ICON_SIZE_SMALL);
|
||||
setTitle(mZenMode.getName());
|
||||
CharSequence statusText = switch (mZenMode.getStatus()) {
|
||||
case ENABLED_AND_ACTIVE ->
|
||||
Strings.isNullOrEmpty(mZenMode.getTriggerDescription())
|
||||
? mContext.getString(R.string.zen_mode_active_text)
|
||||
: mContext.getString(
|
||||
R.string.zen_mode_format_status_and_trigger,
|
||||
mContext.getString(R.string.zen_mode_active_text),
|
||||
mZenMode.getRule().getTriggerDescription());
|
||||
case ENABLED -> mZenMode.getRule().getTriggerDescription();
|
||||
case DISABLED_BY_USER -> mContext.getString(R.string.zen_mode_disabled_by_user);
|
||||
case DISABLED_BY_OTHER -> mContext.getString(R.string.zen_mode_disabled_tap_to_set_up);
|
||||
};
|
||||
setSummary(statusText);
|
||||
|
||||
setIconSize(ICON_SIZE_SMALL);
|
||||
FutureUtil.whenDone(
|
||||
mZenMode.getIcon(mContext, ZenIconLoader.getInstance()),
|
||||
icon -> setIcon(IconUtil.applyTint(mContext, icon)),
|
||||
icon -> setIcon(
|
||||
zenMode.isActive()
|
||||
? IconUtil.applyAccentTint(mContext, icon)
|
||||
: IconUtil.applyNormalTint(mContext, icon)),
|
||||
mContext.getMainExecutor());
|
||||
|
||||
updateTextColor(zenMode);
|
||||
}
|
||||
|
||||
private void updateTextColor(@Nullable ZenMode zenMode) {
|
||||
boolean isActive = zenMode != null && zenMode.isActive();
|
||||
if (mTitleView != null) {
|
||||
mTitleView.setTextColor(Utils.getColorAttr(mContext,
|
||||
isActive ? android.R.attr.colorAccent : android.R.attr.textColorPrimary));
|
||||
}
|
||||
if (mSummaryView != null) {
|
||||
mSummaryView.setTextColor(Utils.getColorAttr(mContext,
|
||||
isActive ? android.R.attr.colorAccent : android.R.attr.textColorSecondary));
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
|
||||
ZenMode getZenMode() {
|
||||
return mZenMode;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user