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

Commit 6fe4a104 authored by Selim Cinek's avatar Selim Cinek Committed by Lucas Dupin
Browse files

Fixes an issue with decorated custom view styles

Previously we were only doing the inversion for custom views,
but not for decorated custom views.

Change-Id: I3ef47a2663b386196f58b13c3d6110aa83dc62ee
Test: post notification with white background
Test: post notification with black background
Test: post notification with green background
Fixes: 112767229
parent 027b668b
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -8243,6 +8243,7 @@ public class Notification implements Parcelable

        private void buildIntoRemoteViewContent(RemoteViews remoteViews,
                RemoteViews customContent, TemplateBindResult result) {
            int childIndex = -1;
            if (customContent != null) {
                // Need to clone customContent before adding, because otherwise it can no longer be
                // parceled independently of remoteViews.
@@ -8250,7 +8251,11 @@ public class Notification implements Parcelable
                remoteViews.removeAllViewsExceptId(R.id.notification_main_column, R.id.progress);
                remoteViews.addView(R.id.notification_main_column, customContent, 0 /* index */);
                remoteViews.addFlags(RemoteViews.FLAG_REAPPLY_DISALLOWED);
                childIndex = 0;
            }
            remoteViews.setIntTag(R.id.notification_main_column,
                    com.android.internal.R.id.notification_custom_view_index_tag,
                    childIndex);
            // also update the end margin if there is an image
            Resources resources = mBuilder.mContext.getResources();
            int endMargin = resources.getDimensionPixelSize(
+3 −0
Original line number Diff line number Diff line
@@ -193,4 +193,7 @@

  <!-- A tag used to save the notification action object -->
  <item type="id" name="notification_action_index_tag" />

  <!-- A tag used to save the index where the custom view is stored -->
  <item type="id" name="notification_custom_view_index_tag" />
</resources>
+1 −0
Original line number Diff line number Diff line
@@ -3586,6 +3586,7 @@
  <java-symbol type="bool" name="config_useSmsAppService" />

  <java-symbol type="id" name="transition_overlay_view_tag" />
  <java-symbol type="id" name="notification_custom_view_index_tag" />

  <java-symbol type="dimen" name="rounded_corner_radius" />
  <java-symbol type="dimen" name="rounded_corner_radius_top" />
+13 −39
Original line number Diff line number Diff line
@@ -17,12 +17,7 @@
package com.android.systemui.statusbar.notification.row.wrapper;

import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.os.Build;
import android.view.View;

import com.android.internal.graphics.ColorUtils;
@@ -49,45 +44,24 @@ public class NotificationCustomViewWrapper extends NotificationViewWrapper {
    }

    @Override
    public void onReinflated() {
        super.onReinflated();

        Configuration configuration = mView.getResources().getConfiguration();
        boolean nightMode = (configuration.uiMode & Configuration.UI_MODE_NIGHT_MASK)
                == Configuration.UI_MODE_NIGHT_YES;

        float[] hsl = new float[] {0f, 0f, 0f};
        ColorUtils.colorToHSL(mBackgroundColor, hsl);
        boolean backgroundIsDark = Color.alpha(mBackgroundColor) == 0
                || hsl[1] == 0 && hsl[2] < 0.5;
        boolean backgroundHasColor = hsl[1] > 0;
    public void onContentUpdated(ExpandableNotificationRow row) {
        super.onContentUpdated(row);

        // Let's invert the notification colors when we're in night mode and
        // the notification background isn't colorized.
        if (!backgroundIsDark && !backgroundHasColor && nightMode
                && mRow.getEntry().targetSdk < Build.VERSION_CODES.Q) {
            Paint paint = new Paint();
            ColorMatrix matrix = new ColorMatrix();
            ColorMatrix tmp = new ColorMatrix();
            // Inversion should happen on Y'UV space to conseve the colors and
            // only affect the luminosity.
            matrix.setRGB2YUV();
            tmp.set(new float[]{
                    -1f, 0f, 0f, 0f, 255f,
                    0f, 1f, 0f, 0f, 0f,
                    0f, 0f, 1f, 0f, 0f,
                    0f, 0f, 0f, 1f, 0f
            });
            matrix.postConcat(tmp);
            tmp.setYUV2RGB();
            matrix.postConcat(tmp);
            paint.setColorFilter(new ColorMatrixColorFilter(matrix));
            mView.setLayerType(View.LAYER_TYPE_HARDWARE, paint);
        if (needsInversion(mBackgroundColor, mView)) {
            invertViewLuminosity(mView);

            // Also invert background color if necessary
            // (Otherwise we'd end-up with white on white.)
            float[] hsl = new float[] {0f, 0f, 0f};
            ColorUtils.colorToHSL(mBackgroundColor, hsl);
            if (mBackgroundColor != Color.TRANSPARENT && hsl[2] > 0.5) {
                hsl[2] = 1f - hsl[2];
                mBackgroundColor = ColorUtils.HSLToColor(hsl);
            }
        }
    }

    @Override
    protected boolean shouldClearBackgroundOnReapply() {
+51 −0
Original line number Diff line number Diff line
/*
 * 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.systemui.statusbar.notification.row.wrapper;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;

/**
 * Wraps a notification containing a decorated custom view.
 */
public class NotificationDecoratedCustomViewWrapper extends NotificationTemplateViewWrapper {

    private View mWrappedView = null;

    protected NotificationDecoratedCustomViewWrapper(Context ctx, View view,
            ExpandableNotificationRow row) {
        super(ctx, view, row);
    }

    @Override
    public void onContentUpdated(ExpandableNotificationRow row) {
        ViewGroup container = mView.findViewById(
                com.android.internal.R.id.notification_main_column);
        Integer childIndex = (Integer) container.getTag(
                com.android.internal.R.id.notification_custom_view_index_tag);
        if (childIndex != null && childIndex != -1) {
            mWrappedView = container.getChildAt(childIndex);
        }
        if (needsInversion(resolveBackgroundColor(), mWrappedView)) {
            invertViewLuminosity(mWrappedView);
        }
        super.onContentUpdated(row);
    }
}
Loading