Redesign channel listing and channel page
Test: atest Bug: 127796543 Fixes: 129452112 Fixes: 129453207 Change-Id: I1d520c9e35860303235b7ffbb18a76cbc4f4b8bc
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user