Moved the disabling from alpha to manual color blending
The Transformations don't preserve alpha currently and it's hard to fix without the risk of introducing regressions. We instead blend the color manually now. Change-Id: Ib9c209295529c5e04564a3faed74160914951152 Fixes: 77811784
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
android:singleLine="true"
|
||||
android:ellipsize="end"
|
||||
android:textAlignment="viewStart"
|
||||
android:alpha="0.5"
|
||||
android:alpha="@dimen/notification_action_disabled_alpha"
|
||||
android:enabled="false"
|
||||
android:background="@drawable/notification_material_action_background"
|
||||
/>
|
||||
|
||||
@@ -615,6 +615,8 @@
|
||||
<dimen name="notification_media_image_max_width">280dp</dimen>
|
||||
<!-- The size of the right icon -->
|
||||
<dimen name="notification_right_icon_size">38dp</dimen>
|
||||
<!-- The alpha of a disabled notification button -->
|
||||
<item type="dimen" format="float" name="notification_action_disabled_alpha">0.5</item>
|
||||
|
||||
<!-- The maximum height of any image in a remote view. This is applied to all images in custom remoteviews. -->
|
||||
<dimen name="notification_custom_view_max_image_height_low_ram">208dp</dimen>
|
||||
|
||||
@@ -2877,6 +2877,7 @@
|
||||
|
||||
<java-symbol type="dimen" name="notification_media_image_margin_end" />
|
||||
<java-symbol type="id" name="notification_action_list_margin_target" />
|
||||
<java-symbol type="dimen" name="notification_action_disabled_alpha" />
|
||||
|
||||
<!-- Pinner Service -->
|
||||
<java-symbol type="array" name="config_defaultPinnerServiceFiles" />
|
||||
|
||||
@@ -18,16 +18,20 @@ package com.android.systemui.statusbar.notification;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.service.notification.StatusBarNotification;
|
||||
import android.util.ArraySet;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.internal.util.NotificationColorUtil;
|
||||
import com.android.internal.widget.NotificationActionListLayout;
|
||||
import com.android.systemui.Dependency;
|
||||
import com.android.systemui.UiOffloadThread;
|
||||
@@ -48,7 +52,7 @@ public class NotificationTemplateViewWrapper extends NotificationHeaderViewWrapp
|
||||
private TextView mTitle;
|
||||
private TextView mText;
|
||||
protected View mActionsContainer;
|
||||
private View mReplyAction;
|
||||
private ImageView mReplyAction;
|
||||
private Rect mTmpRect = new Rect();
|
||||
|
||||
private int mContentHeight;
|
||||
@@ -151,25 +155,60 @@ public class NotificationTemplateViewWrapper extends NotificationHeaderViewWrapp
|
||||
if (mActions != null) {
|
||||
int numActions = mActions.getChildCount();
|
||||
for (int i = 0; i < numActions; i++) {
|
||||
View action = mActions.getChildAt(i);
|
||||
Button action = (Button) mActions.getChildAt(i);
|
||||
performOnPendingIntentCancellation(action, () -> {
|
||||
action.setEnabled(false);
|
||||
// The visual appearance doesn't look disabled enough yet, let's add the
|
||||
// alpha as well. Selectors unfortunately don't seem to work here.
|
||||
action.setAlpha(0.5f);
|
||||
if (action.isEnabled()) {
|
||||
action.setEnabled(false);
|
||||
// The visual appearance doesn't look disabled enough yet, let's add the
|
||||
// alpha as well. Since Alpha doesn't play nicely right now with the
|
||||
// transformation, we rather blend it manually with the background color.
|
||||
ColorStateList textColors = action.getTextColors();
|
||||
int[] colors = textColors.getColors();
|
||||
int[] newColors = new int[colors.length];
|
||||
float disabledAlpha = mView.getResources().getFloat(
|
||||
com.android.internal.R.dimen.notification_action_disabled_alpha);
|
||||
for (int j = 0; j < colors.length; j++) {
|
||||
int color = colors[j];
|
||||
color = blendColorWithBackground(color, disabledAlpha);
|
||||
newColors[j] = color;
|
||||
}
|
||||
ColorStateList newColorStateList = new ColorStateList(
|
||||
textColors.getStates(), newColors);
|
||||
action.setTextColor(newColorStateList);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
if (mReplyAction != null) {
|
||||
performOnPendingIntentCancellation(mReplyAction, () -> {
|
||||
mReplyAction.setEnabled(false);
|
||||
// The visual appearance doesn't look disabled enough yet, let's add the
|
||||
// alpha as well. Selectors unfortunately don't seem to work here.
|
||||
mReplyAction.setAlpha(0.5f);
|
||||
if (mReplyAction != null && mReplyAction.isEnabled()) {
|
||||
mReplyAction.setEnabled(false);
|
||||
// The visual appearance doesn't look disabled enough yet, let's add the
|
||||
// alpha as well. Since Alpha doesn't play nicely right now with the
|
||||
// transformation, we rather blend it manually with the background color.
|
||||
Drawable drawable = mReplyAction.getDrawable().mutate();
|
||||
PorterDuffColorFilter colorFilter =
|
||||
(PorterDuffColorFilter) drawable.getColorFilter();
|
||||
float disabledAlpha = mView.getResources().getFloat(
|
||||
com.android.internal.R.dimen.notification_action_disabled_alpha);
|
||||
if (colorFilter != null) {
|
||||
int color = colorFilter.getColor();
|
||||
color = blendColorWithBackground(color, disabledAlpha);
|
||||
drawable.mutate().setColorFilter(color, colorFilter.getMode());
|
||||
} else {
|
||||
mReplyAction.setAlpha(disabledAlpha);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private int blendColorWithBackground(int color, float alpha) {
|
||||
// alpha doesn't go well for color filters, so let's blend it manually
|
||||
return NotificationColorUtil.compositeColors(Color.argb((int) (alpha * 255),
|
||||
Color.red(color), Color.green(color), Color.blue(color)), resolveBackgroundColor());
|
||||
}
|
||||
|
||||
private void performOnPendingIntentCancellation(View view, Runnable cancellationRunnable) {
|
||||
PendingIntent pendingIntent = (PendingIntent) view.getTag(
|
||||
com.android.internal.R.id.pending_intent_tag);
|
||||
|
||||
@@ -175,6 +175,15 @@ public abstract class NotificationViewWrapper implements TransformableView {
|
||||
return mRow.isSummaryWithChildren() ? 0 : mBackgroundColor;
|
||||
}
|
||||
|
||||
protected int resolveBackgroundColor() {
|
||||
int customBackgroundColor = getCustomBackgroundColor();
|
||||
if (customBackgroundColor != 0) {
|
||||
return customBackgroundColor;
|
||||
}
|
||||
return mView.getContext().getColor(
|
||||
com.android.internal.R.color.notification_material_background_color);
|
||||
}
|
||||
|
||||
public void setLegacy(boolean legacy) {
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user