Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 396cacaa authored by Selim Cinek's avatar Selim Cinek
Browse files

Changed the appearance of phone call notifications

The old design didn't work at all because of various
paddings. The new design adds more paddings and a
new button style

Fixes: 72814598
Test: runtest systemui
Change-Id: I4b4ac0790afe45db97f912740446c6da09620be3
parent b172d5b4
Loading
Loading
Loading
Loading
+49 −40
Original line number Original line Diff line number Diff line
@@ -3115,7 +3115,6 @@ public class Notification implements Parcelable
        private int mTextColorsAreForBackground = COLOR_INVALID;
        private int mTextColorsAreForBackground = COLOR_INVALID;
        private int mPrimaryTextColor = COLOR_INVALID;
        private int mPrimaryTextColor = COLOR_INVALID;
        private int mSecondaryTextColor = COLOR_INVALID;
        private int mSecondaryTextColor = COLOR_INVALID;
        private int mActionBarColor = COLOR_INVALID;
        private int mBackgroundColor = COLOR_INVALID;
        private int mBackgroundColor = COLOR_INVALID;
        private int mForegroundColor = COLOR_INVALID;
        private int mForegroundColor = COLOR_INVALID;
        /**
        /**
@@ -4359,16 +4358,6 @@ public class Notification implements Parcelable
            return mSecondaryTextColor;
            return mSecondaryTextColor;
        }
        }


        private int getActionBarColor() {
            ensureColors();
            return mActionBarColor;
        }

        private int getActionBarColorDeEmphasized() {
            int backgroundColor = getBackgroundColor();
            return NotificationColorUtil.getShiftedColor(backgroundColor, 12);
        }

        private void setTextViewColorSecondary(RemoteViews contentView, int id) {
        private void setTextViewColorSecondary(RemoteViews contentView, int id) {
            ensureColors();
            ensureColors();
            contentView.setTextColor(id, mSecondaryTextColor);
            contentView.setTextColor(id, mSecondaryTextColor);
@@ -4378,7 +4367,6 @@ public class Notification implements Parcelable
            int backgroundColor = getBackgroundColor();
            int backgroundColor = getBackgroundColor();
            if (mPrimaryTextColor == COLOR_INVALID
            if (mPrimaryTextColor == COLOR_INVALID
                    || mSecondaryTextColor == COLOR_INVALID
                    || mSecondaryTextColor == COLOR_INVALID
                    || mActionBarColor == COLOR_INVALID
                    || mTextColorsAreForBackground != backgroundColor) {
                    || mTextColorsAreForBackground != backgroundColor) {
                mTextColorsAreForBackground = backgroundColor;
                mTextColorsAreForBackground = backgroundColor;
                if (!hasForegroundColor() || !isColorized()) {
                if (!hasForegroundColor() || !isColorized()) {
@@ -4451,8 +4439,6 @@ public class Notification implements Parcelable
                        }
                        }
                    }
                    }
                }
                }
                mActionBarColor = NotificationColorUtil.resolveActionBarColor(mContext,
                        backgroundColor);
            }
            }
        }
        }


@@ -4761,8 +4747,8 @@ public class Notification implements Parcelable
                    validRemoteInput |= actionHasValidInput;
                    validRemoteInput |= actionHasValidInput;


                    final RemoteViews button = generateActionButton(action, emphazisedMode,
                    final RemoteViews button = generateActionButton(action, emphazisedMode,
                            i % 2 != 0, p.ambient);
                            p.ambient);
                    if (actionHasValidInput) {
                    if (actionHasValidInput && !emphazisedMode) {
                        // Clear the drawable
                        // Clear the drawable
                        button.setInt(R.id.action0, "setBackgroundResource", 0);
                        button.setInt(R.id.action0, "setBackgroundResource", 0);
                    }
                    }
@@ -5069,7 +5055,7 @@ public class Notification implements Parcelable
        }
        }


        private RemoteViews generateActionButton(Action action, boolean emphazisedMode,
        private RemoteViews generateActionButton(Action action, boolean emphazisedMode,
                boolean oddAction, boolean ambient) {
                boolean ambient) {
            final boolean tombstone = (action.actionIntent == null);
            final boolean tombstone = (action.actionIntent == null);
            RemoteViews button = new BuilderRemoteViews(mContext.getApplicationInfo(),
            RemoteViews button = new BuilderRemoteViews(mContext.getApplicationInfo(),
                    emphazisedMode ? getEmphasizedActionLayoutResource()
                    emphazisedMode ? getEmphasizedActionLayoutResource()
@@ -5082,35 +5068,42 @@ public class Notification implements Parcelable
            if (action.mRemoteInputs != null) {
            if (action.mRemoteInputs != null) {
                button.setRemoteInputs(R.id.action0, action.mRemoteInputs);
                button.setRemoteInputs(R.id.action0, action.mRemoteInputs);
            }
            }
            // TODO: handle emphasized mode / actions right
            if (emphazisedMode) {
            if (emphazisedMode) {
                // change the background bgColor
                // change the background bgColor
                int bgColor;
                if (isColorized()) {
                    bgColor = oddAction ? getActionBarColor() : getActionBarColorDeEmphasized();
                } else {
                    bgColor = mContext.getColor(oddAction ? R.color.notification_action_list
                            : R.color.notification_action_list_dark);
                }
                button.setDrawableTint(R.id.button_holder, true,
                        bgColor, PorterDuff.Mode.SRC_ATOP);
                CharSequence title = action.title;
                CharSequence title = action.title;
                ColorStateList[] outResultColor = null;
                ColorStateList[] outResultColor = null;
                int background = resolveBackgroundColor();
                if (isLegacy()) {
                if (isLegacy()) {
                    title = NotificationColorUtil.clearColorSpans(title);
                    title = NotificationColorUtil.clearColorSpans(title);
                } else {
                } else {
                    outResultColor = new ColorStateList[1];
                    outResultColor = new ColorStateList[1];
                    title = ensureColorSpanContrast(title, bgColor, outResultColor);
                    title = ensureColorSpanContrast(title, background, outResultColor);
                }
                }
                button.setTextViewText(R.id.action0, processTextSpans(title));
                button.setTextViewText(R.id.action0, processTextSpans(title));
                setTextViewColorPrimary(button, R.id.action0);
                setTextViewColorPrimary(button, R.id.action0);
                if (outResultColor != null && outResultColor[0] != null) {
                int rippleColor;
                    // We need to set the text color as well since changing a text to uppercase
                boolean hasColorOverride = outResultColor != null && outResultColor[0] != null;
                    // clears its spans.
                if (hasColorOverride) {
                    button.setTextColor(R.id.action0, outResultColor[0]);
                    // There's a span spanning the full text, let's take it and use it as the
                    // background color
                    background = outResultColor[0].getDefaultColor();
                    int textColor = NotificationColorUtil.resolvePrimaryColor(mContext,
                            background);
                    button.setTextColor(R.id.action0, textColor);
                    rippleColor = textColor;
                } else if (mN.color != COLOR_DEFAULT && !isColorized() && mTintActionButtons) {
                } else if (mN.color != COLOR_DEFAULT && !isColorized() && mTintActionButtons) {
                    button.setTextColor(R.id.action0,resolveContrastColor());
                    rippleColor = resolveContrastColor();
                }
                    button.setTextColor(R.id.action0, rippleColor);
                } else {
                    rippleColor = getPrimaryTextColor();
                }
                // We only want about 20% alpha for the ripple
                rippleColor = (rippleColor & 0x00ffffff) | 0x33000000;
                button.setColorStateList(R.id.action0, "setRippleColor",
                        ColorStateList.valueOf(rippleColor));
                button.setColorStateList(R.id.action0, "setButtonBackground",
                        ColorStateList.valueOf(background));
                button.setBoolean(R.id.action0, "setHasStroke", !hasColorOverride);
            } else {
            } else {
                button.setTextViewText(R.id.action0, processTextSpans(
                button.setTextViewText(R.id.action0, processTextSpans(
                        processLegacyText(action.title)));
                        processLegacyText(action.title)));
@@ -5160,32 +5153,36 @@ public class Notification implements Parcelable
                            }
                            }
                            textColor = new ColorStateList(textColor.getStates().clone(),
                            textColor = new ColorStateList(textColor.getStates().clone(),
                                    newColors);
                                    newColors);
                            if (fullLength) {
                                outResultColor[0] = textColor;
                                // Let's drop the color from the span
                                textColor = null;
                            }
                            resultSpan = new TextAppearanceSpan(
                            resultSpan = new TextAppearanceSpan(
                                    originalSpan.getFamily(),
                                    originalSpan.getFamily(),
                                    originalSpan.getTextStyle(),
                                    originalSpan.getTextStyle(),
                                    originalSpan.getTextSize(),
                                    originalSpan.getTextSize(),
                                    textColor,
                                    textColor,
                                    originalSpan.getLinkTextColor());
                                    originalSpan.getLinkTextColor());
                            if (fullLength) {
                                outResultColor[0] = new ColorStateList(
                                        textColor.getStates().clone(), newColors);
                            }
                        }
                        }
                    } else if (resultSpan instanceof ForegroundColorSpan) {
                    } else if (resultSpan instanceof ForegroundColorSpan) {
                        ForegroundColorSpan originalSpan = (ForegroundColorSpan) resultSpan;
                        ForegroundColorSpan originalSpan = (ForegroundColorSpan) resultSpan;
                        int foregroundColor = originalSpan.getForegroundColor();
                        int foregroundColor = originalSpan.getForegroundColor();
                        foregroundColor = NotificationColorUtil.ensureLargeTextContrast(
                        foregroundColor = NotificationColorUtil.ensureLargeTextContrast(
                                foregroundColor, background, mInNightMode);
                                foregroundColor, background, mInNightMode);
                        resultSpan = new ForegroundColorSpan(foregroundColor);
                        if (fullLength) {
                        if (fullLength) {
                            outResultColor[0] = ColorStateList.valueOf(foregroundColor);
                            outResultColor[0] = ColorStateList.valueOf(foregroundColor);
                            resultSpan = null;
                        } else {
                            resultSpan = new ForegroundColorSpan(foregroundColor);
                        }
                        }
                    } else {
                    } else {
                        resultSpan = span;
                        resultSpan = span;
                    }
                    }

                    if (resultSpan != null) {
                        builder.setSpan(resultSpan, spanStart, spanEnd, ss.getSpanFlags(span));
                        builder.setSpan(resultSpan, spanStart, spanEnd, ss.getSpanFlags(span));
                    }
                    }
                }
                return builder;
                return builder;
            }
            }
            return charSequence;
            return charSequence;
@@ -5515,6 +5512,18 @@ public class Notification implements Parcelable
            }
            }
        }
        }


        /**
         * Same as getBackgroundColor but also resolved the default color to the background.
         */
        private int resolveBackgroundColor() {
            int backgroundColor = getBackgroundColor();
            if (backgroundColor == COLOR_DEFAULT) {
                backgroundColor = mContext.getColor(
                        com.android.internal.R.color.notification_material_background_color);
            }
            return backgroundColor;
        }

        private boolean isColorized() {
        private boolean isColorized() {
            return mN.isColorized();
            return mN.isColorized();
        }
        }
+15 −0
Original line number Original line Diff line number Diff line
@@ -2999,6 +2999,21 @@ public class RemoteViews implements Parcelable, Filter {
        addAction(new ReflectionAction(viewId, methodName, ReflectionAction.INT, value));
        addAction(new ReflectionAction(viewId, methodName, ReflectionAction.INT, value));
    }
    }


    /**
     * Call a method taking one ColorStateList on a view in the layout for this RemoteViews.
     *
     * @param viewId The id of the view on which to call the method.
     * @param methodName The name of the method to call.
     * @param value The value to pass to the method.
     *
     * @hide
     */
    public void setColorStateList(int viewId, String methodName, ColorStateList value) {
        addAction(new ReflectionAction(viewId, methodName, ReflectionAction.COLOR_STATE_LIST,
                value));
    }


    /**
    /**
     * Call a method taking one long on a view in the layout for this RemoteViews.
     * Call a method taking one long on a view in the layout for this RemoteViews.
     *
     *
+0 −7
Original line number Original line Diff line number Diff line
@@ -558,13 +558,6 @@ public class NotificationColorUtil {
        }
        }
    }
    }


    public static int resolveActionBarColor(Context context, int backgroundColor) {
        if (backgroundColor == Notification.COLOR_DEFAULT) {
            return context.getColor(com.android.internal.R.color.notification_action_list);
        }
        return getShiftedColor(backgroundColor, 7);
    }

    /**
    /**
     * Get a color that stays in the same tint, but darkens or lightens it by a certain
     * Get a color that stays in the same tint, but darkens or lightens it by a certain
     * amount.
     * amount.
+83 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2018 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.internal.widget;

import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.drawable.DrawableWrapper;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.InsetDrawable;
import android.graphics.drawable.RippleDrawable;
import android.util.AttributeSet;
import android.view.RemotableViewMethod;
import android.widget.Button;
import android.widget.RemoteViews;

/**
 * A button implementation for the emphasized notification style.
 *
 * @hide
 */
@RemoteViews.RemoteView
public class EmphasizedNotificationButton extends Button {
    private final RippleDrawable mRipple;
    private final int mStrokeWidth;
    private final int mStrokeColor;

    public EmphasizedNotificationButton(Context context) {
        this(context, null);
    }

    public EmphasizedNotificationButton(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public EmphasizedNotificationButton(Context context, AttributeSet attrs, int defStyleAttr) {
        this(context, attrs, defStyleAttr, 0);
    }

    public EmphasizedNotificationButton(Context context, AttributeSet attrs, int defStyleAttr,
            int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        DrawableWrapper background = (DrawableWrapper) getBackground().mutate();
        mRipple = (RippleDrawable) background.getDrawable();
        mStrokeWidth = getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.emphasized_button_stroke_width);
        mStrokeColor = getContext().getColor(com.android.internal.R.color.material_grey_300);
        mRipple.mutate();
    }

    @RemotableViewMethod
    public void setRippleColor(ColorStateList color) {
        mRipple.setColor(color);
        invalidate();
    }

    @RemotableViewMethod
    public void setButtonBackground(ColorStateList color) {
        GradientDrawable inner = (GradientDrawable) mRipple.getDrawable(0);
        inner.setColor(color);
        invalidate();
    }

    @RemotableViewMethod
    public void setHasStroke(boolean hasStroke) {
        GradientDrawable inner = (GradientDrawable) mRipple.getDrawable(0);
        inner.setStroke(hasStroke ? mStrokeWidth : 0, mStrokeColor);
        invalidate();
    }
}
+55 −15
Original line number Original line Diff line number Diff line
@@ -16,17 +16,15 @@


package com.android.internal.widget;
package com.android.internal.widget;


import android.annotation.Nullable;
import android.content.Context;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.RippleDrawable;
import android.graphics.drawable.RippleDrawable;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.util.Pair;
import android.util.Pair;
import android.view.Gravity;
import android.view.Gravity;
import android.view.RemotableViewMethod;
import android.view.RemotableViewMethod;
import android.view.View;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.LinearLayout;
import android.widget.RemoteViews;
import android.widget.RemoteViews;
import android.widget.TextView;
import android.widget.TextView;
@@ -45,9 +43,11 @@ public class NotificationActionListLayout extends LinearLayout {
    private int mTotalWidth = 0;
    private int mTotalWidth = 0;
    private ArrayList<Pair<Integer, TextView>> mMeasureOrderTextViews = new ArrayList<>();
    private ArrayList<Pair<Integer, TextView>> mMeasureOrderTextViews = new ArrayList<>();
    private ArrayList<View> mMeasureOrderOther = new ArrayList<>();
    private ArrayList<View> mMeasureOrderOther = new ArrayList<>();
    private boolean mMeasureLinearly;
    private boolean mEmphasizedMode;
    private int mDefaultPaddingEnd;
    private int mDefaultPaddingBottom;
    private Drawable mDefaultBackground;
    private int mDefaultPaddingTop;
    private int mEmphasizedHeight;
    private int mRegularHeight;


    public NotificationActionListLayout(Context context, AttributeSet attrs) {
    public NotificationActionListLayout(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
        this(context, attrs, 0);
@@ -68,7 +68,7 @@ public class NotificationActionListLayout extends LinearLayout {


    @Override
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        if (mMeasureLinearly) {
        if (mEmphasizedMode) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            return;
            return;
        }
        }
@@ -219,7 +219,7 @@ public class NotificationActionListLayout extends LinearLayout {


    @Override
    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        if (mMeasureLinearly) {
        if (mEmphasizedMode) {
            super.onLayout(changed, left, top, right, bottom);
            super.onLayout(changed, left, top, right, bottom);
            return;
            return;
        }
        }
@@ -280,8 +280,21 @@ public class NotificationActionListLayout extends LinearLayout {
    @Override
    @Override
    protected void onFinishInflate() {
    protected void onFinishInflate() {
        super.onFinishInflate();
        super.onFinishInflate();
        mDefaultPaddingEnd = getPaddingEnd();
        mDefaultPaddingBottom = getPaddingBottom();
        mDefaultBackground = getBackground();
        mDefaultPaddingTop = getPaddingTop();
        updateHeights();
    }

    private void updateHeights() {
        int paddingTop = getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.notification_content_margin);
        // same padding on bottom and at end
        int paddingBottom = getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.notification_content_margin_end);
        mEmphasizedHeight = paddingBottom + paddingTop + getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.notification_action_emphasized_height);
        mRegularHeight = getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.notification_action_list_height);
    }
    }


    /**
    /**
@@ -291,11 +304,38 @@ public class NotificationActionListLayout extends LinearLayout {
     */
     */
    @RemotableViewMethod
    @RemotableViewMethod
    public void setEmphasizedMode(boolean emphasizedMode) {
    public void setEmphasizedMode(boolean emphasizedMode) {
        mMeasureLinearly = emphasizedMode;
        mEmphasizedMode = emphasizedMode;
        setPaddingRelative(getPaddingStart(), getPaddingTop(),
        int height;
                emphasizedMode ? 0 : mDefaultPaddingEnd, getPaddingBottom());
        if (emphasizedMode) {
        setBackground(emphasizedMode ? null : mDefaultBackground);
            int paddingTop = getResources().getDimensionPixelSize(
        requestLayout();
                    com.android.internal.R.dimen.notification_content_margin);
            // same padding on bottom and at end
            int paddingBottom = getResources().getDimensionPixelSize(
                    com.android.internal.R.dimen.notification_content_margin_end);
            height = mEmphasizedHeight;
            int buttonPaddingInternal = getResources().getDimensionPixelSize(
                    com.android.internal.R.dimen.button_inset_vertical_material);
            setPaddingRelative(getPaddingStart(),
                    paddingTop - buttonPaddingInternal,
                    getPaddingEnd(),
                    paddingBottom - buttonPaddingInternal);
        } else {
            setPaddingRelative(getPaddingStart(),
                    mDefaultPaddingTop,
                    getPaddingEnd(),
                    mDefaultPaddingBottom);
            height = mRegularHeight;
        }
        ViewGroup.LayoutParams layoutParams = getLayoutParams();
        layoutParams.height = height;
        setLayoutParams(layoutParams);
    }

    public int getExtraMeasureHeight() {
        if (mEmphasizedMode) {
            return mEmphasizedHeight - mRegularHeight;
        }
        return 0;
    }
    }


    public static final Comparator<Pair<Integer, TextView>> MEASURE_ORDER_COMPARATOR
    public static final Comparator<Pair<Integer, TextView>> MEASURE_ORDER_COMPARATOR
Loading