Fix overlapping importance icons

We can't re-use the same background because not
all of the buttons are the same size

Test: manual
Bug: 161297551
Change-Id: I8583cb2fbbcb971ab5819eefd84dde3f7c3b4bdf
This commit is contained in:
Julia Reynolds
2020-07-15 16:45:54 -04:00
parent 0d34f6c80b
commit f04c167475
3 changed files with 49 additions and 147 deletions

View File

@@ -50,8 +50,6 @@ public class ConversationPriorityPreference extends Preference {
private View mAlertButton;
private View mPriorityButton;
private Context mContext;
Drawable selectedBackground;
Drawable unselectedBackground;
private static final int BUTTON_ANIM_TIME_MS = 100;
public ConversationPriorityPreference(Context context, AttributeSet attrs,
@@ -77,8 +75,6 @@ public class ConversationPriorityPreference 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_priority_conversation_preference);
}
@@ -148,86 +144,43 @@ public class ConversationPriorityPreference extends Preference {
TransitionManager.beginDelayedTransition(parent, transition);
}
ColorStateList colorAccent = getAccentTint();
ColorStateList colorNormal = getRegularTint();
ImageView silenceIcon = parent.findViewById(R.id.silence_icon);
TextView silenceLabel = parent.findViewById(R.id.silence_label);
TextView silenceSummary = parent.findViewById(R.id.silence_summary);
ImageView alertIcon = parent.findViewById(R.id.alert_icon);
TextView alertLabel = parent.findViewById(R.id.alert_label);
TextView alertSummary = parent.findViewById(R.id.alert_summary);
ImageView priorityIcon = parent.findViewById(R.id.priority_icon);
TextView priorityLabel = parent.findViewById(R.id.priority_label);
TextView prioritySummary = parent.findViewById(R.id.priority_summary);
if (importance <= IMPORTANCE_LOW && importance > IMPORTANCE_UNSPECIFIED) {
alertSummary.setVisibility(GONE);
alertIcon.setImageTintList(colorNormal);
alertLabel.setTextColor(colorNormal);
prioritySummary.setVisibility(GONE);
priorityIcon.setImageTintList(colorNormal);
priorityLabel.setTextColor(colorNormal);
silenceIcon.setImageTintList(colorAccent);
silenceLabel.setTextColor(colorAccent);
silenceSummary.setVisibility(VISIBLE);
mAlertButton.setBackground(unselectedBackground);
mPriorityButton.setBackground(unselectedBackground);
mSilenceButton.setBackground(selectedBackground);
// a11y service won't always read the newly appearing text in the right order if the
// selection happens too soon (readback happens on a different thread as layout). post
// the selection to make that conflict less likely
parent.post(() -> {
mSilenceButton.setSelected(true);
mAlertButton.setSelected(false);
mPriorityButton.setSelected(false);
});
setSelected(mPriorityButton, false);
setSelected(mAlertButton, false);
setSelected(mSilenceButton, true);
} else {
if (isPriority) {
alertSummary.setVisibility(GONE);
alertIcon.setImageTintList(colorNormal);
alertLabel.setTextColor(colorNormal);
prioritySummary.setVisibility(VISIBLE);
priorityIcon.setImageTintList(colorAccent);
priorityLabel.setTextColor(colorAccent);
silenceIcon.setImageTintList(colorNormal);
silenceLabel.setTextColor(colorNormal);
silenceSummary.setVisibility(GONE);
mAlertButton.setBackground(unselectedBackground);
mPriorityButton.setBackground(selectedBackground);
mSilenceButton.setBackground(unselectedBackground);
parent.post(() -> {
mSilenceButton.setSelected(false);
mAlertButton.setSelected(false);
mPriorityButton.setSelected(true);
});
setSelected(mPriorityButton, true);
setSelected(mAlertButton, false);
setSelected(mSilenceButton, false);
} else {
alertSummary.setVisibility(VISIBLE);
alertIcon.setImageTintList(colorAccent);
alertLabel.setTextColor(colorAccent);
prioritySummary.setVisibility(GONE);
priorityIcon.setImageTintList(colorNormal);
priorityLabel.setTextColor(colorNormal);
silenceIcon.setImageTintList(colorNormal);
silenceLabel.setTextColor(colorNormal);
silenceSummary.setVisibility(GONE);
mAlertButton.setBackground(selectedBackground);
mPriorityButton.setBackground(unselectedBackground);
mSilenceButton.setBackground(unselectedBackground);
parent.post(() -> {
mSilenceButton.setSelected(false);
mAlertButton.setSelected(true);
mPriorityButton.setSelected(false);
});
setSelected(mPriorityButton, false);
setSelected(mAlertButton, true);
setSelected(mSilenceButton, false);
}
}
}
void setSelected(View view, boolean selected) {
ColorStateList colorAccent = getAccentTint();
ColorStateList colorNormal = getRegularTint();
ImageView icon = view.findViewById(R.id.icon);
TextView label = view.findViewById(R.id.label);
TextView summary = view.findViewById(R.id.summary);
icon.setImageTintList(selected ? colorAccent : colorNormal);
label.setTextColor(selected ? colorAccent : colorNormal);
summary.setVisibility(selected ? VISIBLE : GONE);
view.setBackground(mContext.getDrawable(selected
? R.drawable.button_border_selected
: R.drawable.button_border_unselected));
// a11y service won't always read the newly appearing text in the right order if the
// selection happens too soon (readback happens on a different thread as layout). post
// the selection to make that conflict less likely
view.post(() -> {
view.setSelected(selected);
});
}
}