Redesign channel listing and channel page

Test: atest
Bug: 127796543
Fixes: 129452112
Fixes: 129453207
Change-Id: I1d520c9e35860303235b7ffbb18a76cbc4f4b8bc
This commit is contained in:
Julia Reynolds
2019-04-12 16:52:40 -04:00
parent 670bf45b50
commit 5c097c6d3c
21 changed files with 405 additions and 579 deletions

View File

@@ -33,6 +33,7 @@ import androidx.preference.SwitchPreference;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.R;
import com.android.settings.widget.MasterSwitchPreference;
import com.android.settingslib.RestrictedSwitchPreference;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -255,7 +256,7 @@ public class AppNotificationSettings extends NotificationSettingsBase {
int childCount = groupGroup.getPreferenceCount();
for (int i = 0; i < childCount; i++) {
Preference pref = groupGroup.getPreference(i);
if (pref instanceof ChannelSummaryPreference) {
if (pref instanceof MasterSwitchPreference) {
toRemove.add(pref);
}
}

View File

@@ -94,6 +94,7 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
mControllers = new ArrayList<>();
mControllers.add(new HeaderPreferenceController(context, this));
mControllers.add(new BlockPreferenceController(context, mImportanceListener, mBackend));
mControllers.add(new ImportancePreferenceController(
context, mImportanceListener, mBackend));
mControllers.add(new MinImportancePreferenceController(

View File

@@ -1,115 +0,0 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.notification;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.CheckBox;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
import com.android.settingslib.TwoTargetPreference;
/**
* A custom preference that provides inline checkbox and tappable target.
*/
public class ChannelSummaryPreference extends TwoTargetPreference {
private Context mContext;
private Intent mIntent;
private CheckBox mCheckBox;
private boolean mChecked;
private boolean mEnableCheckBox = true;
public ChannelSummaryPreference(Context context) {
super(context);
setLayoutResource(R.layout.preference_checkable_two_target);
mContext = context;
setWidgetLayoutResource(R.layout.zen_rule_widget);
}
@Override
public void onBindViewHolder(PreferenceViewHolder view) {
super.onBindViewHolder(view);
View settingsWidget = view.findViewById(android.R.id.widget_frame);
View divider = view.findViewById(R.id.two_target_divider);
if (mIntent != null) {
divider.setVisibility(View.VISIBLE);
settingsWidget.setVisibility(View.VISIBLE);
settingsWidget.setOnClickListener(v -> mContext.startActivity(mIntent));
} else {
divider.setVisibility(View.GONE);
settingsWidget.setVisibility(View.GONE);
settingsWidget.setOnClickListener(null);
}
View checkboxContainer = view.findViewById(R.id.checkbox_container);
if (checkboxContainer != null) {
checkboxContainer.setOnClickListener(mOnCheckBoxClickListener);
}
mCheckBox = (CheckBox) view.findViewById(com.android.internal.R.id.checkbox);
if (mCheckBox != null) {
mCheckBox.setChecked(mChecked);
mCheckBox.setEnabled(mEnableCheckBox);
}
}
public boolean isChecked() {
return mChecked;
}
@Override
public void setIntent(Intent intent) {
mIntent = intent;
}
@Override
public void onClick() {
mOnCheckBoxClickListener.onClick(null);
}
public void setChecked(boolean checked) {
mChecked = checked;
if (mCheckBox != null) {
mCheckBox.setChecked(checked);
}
}
public void setCheckBoxEnabled(boolean enabled) {
mEnableCheckBox = enabled;
if (mCheckBox != null) {
mCheckBox.setEnabled(enabled);
}
}
private View.OnClickListener mOnCheckBoxClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mCheckBox != null && !mCheckBox.isEnabled()) {
return;
}
setChecked(!mChecked);
if (!callChangeListener(mChecked)) {
setChecked(!mChecked);
} else {
persistBoolean(mChecked);
}
}
};
}

View File

@@ -20,17 +20,12 @@ import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static android.app.NotificationManager.IMPORTANCE_LOW;
import static android.app.NotificationManager.IMPORTANCE_MIN;
import static android.app.NotificationManager.IMPORTANCE_NONE;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.LayerDrawable;
import android.util.ArrayMap;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Button;
import android.widget.TextView;
import com.android.settingslib.R;
@@ -39,14 +34,15 @@ import androidx.preference.PreferenceViewHolder;
public class ImportancePreference extends Preference {
boolean mIsBlockable = true;
boolean mIsConfigurable = true;
int mImportance;
ImageButton blockButton;
ImageButton silenceButton;
ImageButton alertButton;
ArrayMap<ImageButton, Integer> mImageButtons = new ArrayMap<>();
Context mContext;
private boolean mIsConfigurable = true;
private int mImportance;
private boolean mDisplayInStatusBar;
private boolean mDisplayOnLockscreen;
private Button mSilenceButton;
private Button mAlertButton;
private Context mContext;
Drawable selectedBackground;
Drawable unselectedBackground;
public ImportancePreference(Context context, AttributeSet attrs,
int defStyleAttr, int defStyleRes) {
@@ -71,6 +67,8 @@ public class ImportancePreference extends Preference {
private void init(Context context) {
mContext = context;
selectedBackground = mContext.getDrawable(R.drawable.button_border_selected);
unselectedBackground = mContext.getDrawable(R.drawable.button_border_unselected);
setLayoutResource(R.layout.notif_importance_preference);
}
@@ -78,94 +76,81 @@ public class ImportancePreference extends Preference {
mImportance = importance;
}
public void setBlockable(boolean blockable) {
mIsBlockable = blockable;
}
public void setConfigurable(boolean configurable) {
mIsConfigurable = configurable;
}
public void setDisplayInStatusBar(boolean display) {
mDisplayInStatusBar = display;
}
public void setDisplayOnLockscreen(boolean display) {
mDisplayOnLockscreen = display;
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
View blockView = holder.itemView.findViewById(R.id.block);
View alertView = holder.itemView.findViewById(R.id.alert);
View silenceView = holder.itemView.findViewById(R.id.silence);
if (!mIsBlockable) {
blockView.setVisibility(View.GONE);
if (mImportance == IMPORTANCE_NONE) {
mImportance = IMPORTANCE_LOW;
callChangeListener(IMPORTANCE_LOW);
}
TextView textView = (TextView) holder.findViewById(R.id.description);
mSilenceButton = (Button) holder.findViewById(R.id.silence);
mAlertButton = (Button) holder.findViewById(R.id.alert);
if (!mIsConfigurable) {
mSilenceButton.setEnabled(false);
mAlertButton.setEnabled(false);
}
blockButton = blockView.findViewById(R.id.block_icon);
silenceButton = silenceView.findViewById(R.id.silence_icon);
alertButton = alertView.findViewById(R.id.alert_icon);
mImageButtons.put(blockButton, mContext.getColor(R.color.notification_block_color));
mImageButtons.put(silenceButton, mContext.getColor(R.color.notification_silence_color));
mImageButtons.put(alertButton, mContext.getColor(R.color.notification_alert_color));
switch (mImportance) {
case IMPORTANCE_NONE:
colorizeImageButton(blockButton.getId());
if (!mIsConfigurable) {
alertView.setVisibility(View.GONE);
silenceView.setVisibility(View.GONE);
}
break;
case IMPORTANCE_MIN:
case IMPORTANCE_LOW:
colorizeImageButton(silenceButton.getId());
if (!mIsConfigurable) {
alertView.setVisibility(View.GONE);
blockView.setVisibility(View.GONE);
}
mAlertButton.setBackground(unselectedBackground);
mSilenceButton.setBackground(selectedBackground);
break;
case IMPORTANCE_HIGH:
default:
colorizeImageButton(alertButton.getId());
if (!mIsConfigurable) {
blockView.setVisibility(View.GONE);
silenceView.setVisibility(View.GONE);
}
mSilenceButton.setBackground(unselectedBackground);
mAlertButton.setBackground(selectedBackground);
break;
}
setImportanceSummary(textView, mImportance);
blockButton.setOnClickListener(v -> {
callChangeListener(IMPORTANCE_NONE);
colorizeImageButton(blockButton.getId());
});
silenceButton.setOnClickListener(v -> {
mSilenceButton.setOnClickListener(v -> {
callChangeListener(IMPORTANCE_LOW);
colorizeImageButton(silenceButton.getId());
mAlertButton.setBackground(unselectedBackground);
mSilenceButton.setBackground(selectedBackground);
mSilenceButton.setTextAppearance(
R.style.TextAppearance_NotificationImportanceButton_Selected);
mAlertButton.setTextAppearance(
R.style.TextAppearance_NotificationImportanceButton_Unselected);
setImportanceSummary(textView, IMPORTANCE_LOW);
});
alertButton.setOnClickListener(v -> {
mAlertButton.setOnClickListener(v -> {
callChangeListener(IMPORTANCE_DEFAULT);
colorizeImageButton(alertButton.getId());
mSilenceButton.setBackground(unselectedBackground);
mAlertButton.setBackground(selectedBackground);
mAlertButton.setTextAppearance(
R.style.TextAppearance_NotificationImportanceButton_Selected);
mSilenceButton.setTextAppearance(
R.style.TextAppearance_NotificationImportanceButton_Unselected);
setImportanceSummary(textView, IMPORTANCE_DEFAULT);
});
}
private void colorizeImageButton(int buttonId) {
if (mImageButtons != null) {
for (int i = 0; i < mImageButtons.size(); i++) {
final ImageButton imageButton = mImageButtons.keyAt(i);
final int color = mImageButtons.valueAt(i);
if (imageButton != null) {
LayerDrawable drawable = (LayerDrawable) imageButton.getDrawable();
Drawable foreground = drawable.findDrawableByLayerId(R.id.fore);
GradientDrawable background =
(GradientDrawable) drawable.findDrawableByLayerId(R.id.back);
if (buttonId == imageButton.getId()) {
foreground.setTint(Color.WHITE);
background.setColor(color);
} else {
foreground.setTint(color);
background.setColor(Color.TRANSPARENT);
}
}
void setImportanceSummary(TextView view, int importance) {
if (importance >= IMPORTANCE_DEFAULT) {
view.setText(R.string.notification_channel_summary_default);
} else {
if (mDisplayInStatusBar) {
if (mDisplayOnLockscreen) {
view.setText(R.string.notification_channel_summary_low_status_lock);
} else {
view.setText(R.string.notification_channel_summary_low_status);
}
} else if (mDisplayOnLockscreen) {
view.setText(R.string.notification_channel_summary_low_lock);
} else {
view.setText(R.string.notification_channel_summary_low);
}
}
}

View File

@@ -47,22 +47,13 @@ public class ImportancePreferenceController extends NotificationPreferenceContro
@Override
public boolean isAvailable() {
if (mAppRow == null) {
return false;
}
if (mAppRow.banned) {
if (!super.isAvailable()) {
return false;
}
if (mChannel == null) {
return false;
}
if (isDefaultChannel()) {
return false;
}
if (mChannelGroup != null && mChannelGroup.isBlocked()) {
return false;
}
return true;
return !isDefaultChannel();
}
@Override
@@ -70,9 +61,10 @@ public class ImportancePreferenceController extends NotificationPreferenceContro
if (mAppRow!= null && mChannel != null) {
preference.setEnabled(mAdmin == null && isChannelConfigurable());
ImportancePreference pref = (ImportancePreference) preference;
pref.setBlockable(isChannelBlockable());
pref.setConfigurable(isChannelConfigurable());
pref.setImportance(mChannel.getImportance());
pref.setDisplayInStatusBar(mBackend.showSilentInStatusBar(mContext.getPackageName()));
// TODO: b/128445911 pass along lock screen setting
}
}

View File

@@ -360,6 +360,15 @@ public class NotificationBackend {
return new ArrayList<>();
}
public boolean showSilentInStatusBar(String pkg) {
try {
return !sINM.shouldHideSilentStatusIcons(pkg);
} catch (Exception e) {
Log.w(TAG, "Error calling NoMan", e);
}
return false;
}
protected void recordAggregatedUsageEvents(Context context, AppRow appRow) {
long now = System.currentTimeMillis();
long startTime = now - (DateUtils.DAY_IN_MILLIS * DAYS_TO_CHECK);

View File

@@ -34,6 +34,12 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.graphics.BlendMode;
import android.graphics.BlendModeColorFilter;
import android.graphics.ColorFilter;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Bundle;
import android.os.UserHandle;
import android.provider.Settings;
@@ -50,6 +56,7 @@ import com.android.settings.SettingsActivity;
import com.android.settings.applications.AppInfoBase;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.widget.MasterSwitchPreference;
import com.android.settingslib.RestrictedLockUtilsInternal;
import java.util.ArrayList;
@@ -272,11 +279,14 @@ abstract public class NotificationSettingsBase extends DashboardFragment {
protected Preference populateSingleChannelPrefs(PreferenceGroup parent,
final NotificationChannel channel, final boolean groupBlocked) {
ChannelSummaryPreference channelPref = new ChannelSummaryPreference(getPrefContext());
channelPref.setCheckBoxEnabled(mSuspendedAppsAdmin == null
MasterSwitchPreference channelPref = new MasterSwitchPreference(getPrefContext());
channelPref.setSwitchEnabled(mSuspendedAppsAdmin == null
&& isChannelBlockable(channel)
&& isChannelConfigurable(channel)
&& !groupBlocked);
channelPref.setIcon(channel.getImportance() > IMPORTANCE_LOW
? R.drawable.ic_notification_alert : R.drawable.ic_notification_silence);
channelPref.setIconSize(MasterSwitchPreference.ICON_SIZE_SMALL);
channelPref.setKey(channel.getId());
channelPref.setTitle(channel.getName());
channelPref.setSummary(NotificationBackend.getSentSummary(
@@ -295,19 +305,21 @@ abstract public class NotificationSettingsBase extends DashboardFragment {
.toIntent());
channelPref.setOnPreferenceChangeListener(
new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference,
Object o) {
boolean value = (Boolean) o;
int importance = value ? IMPORTANCE_LOW : IMPORTANCE_NONE;
channel.setImportance(importance);
channel.lockFields(
NotificationChannel.USER_LOCKED_IMPORTANCE);
mBackend.updateChannel(mPkg, mUid, channel);
(preference, o) -> {
boolean value = (Boolean) o;
int importance = value ? IMPORTANCE_LOW : IMPORTANCE_NONE;
channel.setImportance(importance);
channel.lockFields(
NotificationChannel.USER_LOCKED_IMPORTANCE);
MasterSwitchPreference channelPref1 = (MasterSwitchPreference) preference;
channelPref1.setIcon(channel.getImportance() > IMPORTANCE_LOW
? R.drawable.ic_notification_alert
: R.drawable.ic_notification_silence);
toggleBehaviorIconState(channelPref1.getIcon(),
importance != IMPORTANCE_NONE);
mBackend.updateChannel(mPkg, mUid, channel);
return true;
}
return true;
});
if (parent.findPreference(channelPref.getKey()) == null) {
parent.addPreference(channelPref);
@@ -315,6 +327,19 @@ abstract public class NotificationSettingsBase extends DashboardFragment {
return channelPref;
}
private void toggleBehaviorIconState(Drawable icon, boolean enabled) {
LayerDrawable layerDrawable = (LayerDrawable) icon;
GradientDrawable background =
(GradientDrawable) layerDrawable.findDrawableByLayerId(R.id.back);
if (enabled) {
background.clearColorFilter();
} else {
background.setColorFilter(new BlendModeColorFilter(
mContext.getColor(R.color.material_grey_300),
BlendMode.SRC_IN));
}
}
protected boolean isChannelConfigurable(NotificationChannel channel) {
if (channel != null && mAppRow != null) {
return !channel.getId().equals(mAppRow.lockedChannelId);