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

Commit 190d58d6 authored by Dan Sandler's avatar Dan Sandler
Browse files

Badge largeIcons with the notification icon.

The old right-hand small icon is no more; instead the
notification's small icon is overlaid atop the largeIcon
bitmap.

If the small icon would have had a colored circle background
applied to it in the large left-hand slot, it gets a similar
treatment when used as a badge.

Change-Id: I8b262afbdd4faab2beffd294d662f4759f35f3b3
parent 574ed553
Loading
Loading
Loading
Loading
+30 −19
Original line number Diff line number Diff line
@@ -1889,27 +1889,21 @@ public class Notification implements Parcelable
            RemoteViews contentView = new RemoteViews(mContext.getPackageName(), resId);
            boolean showLine3 = false;
            boolean showLine2 = false;
            int smallIconImageViewId = R.id.icon;

            if (mPriority < PRIORITY_LOW) {
                // TODO: Low priority presentation
            }
            if (mLargeIcon != null) {
                contentView.setImageViewBitmap(R.id.icon, mLargeIcon);
                processLargeIcon(mLargeIcon, contentView);
                smallIconImageViewId = R.id.right_icon;
            }
            if (mSmallIcon != 0) {
                contentView.setImageViewResource(smallIconImageViewId, mSmallIcon);
                contentView.setViewVisibility(smallIconImageViewId, View.VISIBLE);
                if (mLargeIcon != null) {
                    processSmallRightIcon(mSmallIcon, smallIconImageViewId, contentView);
                } else {
                contentView.setImageViewResource(R.id.right_icon, mSmallIcon);
                contentView.setViewVisibility(R.id.right_icon, View.VISIBLE);
                processSmallRightIcon(mSmallIcon, contentView);
            } else { // small icon at left
                contentView.setImageViewResource(R.id.icon, mSmallIcon);
                contentView.setViewVisibility(R.id.icon, View.VISIBLE);
                processSmallIconAsLarge(mSmallIcon, contentView);
            }

            } else {
                contentView.setViewVisibility(smallIconImageViewId, View.GONE);
            }
            if (mContentTitle != null) {
                contentView.setTextViewText(R.id.title, processLegacyText(mContentTitle));
            }
@@ -2103,6 +2097,8 @@ public class Notification implements Parcelable
        private void processLargeIcon(Bitmap largeIcon, RemoteViews contentView) {
            if (!isLegacy() || mColorUtil.isGrayscale(largeIcon)) {
                applyLargeIconBackground(contentView);
            } else {
                removeLargeIconBackground(contentView);
            }
        }

@@ -2122,16 +2118,31 @@ public class Notification implements Parcelable
                    -1);
        }

        private void removeLargeIconBackground(RemoteViews contentView) {
            contentView.setInt(R.id.icon, "setBackgroundResource", 0);
        }

        /**
         * Recolor small icons when used in the R.id.right_icon slot.
         */
        private void processSmallRightIcon(int smallIconDrawableId, int smallIconImageViewId,
        private void processSmallRightIcon(int smallIconDrawableId,
                RemoteViews contentView) {
            if (!isLegacy() || mColorUtil.isGrayscale(mContext, smallIconDrawableId)) {
                contentView.setDrawableParameters(smallIconImageViewId, false, -1,
                        mContext.getResources().getColor(
                                R.color.notification_action_legacy_color_filter),
                        PorterDuff.Mode.MULTIPLY, -1);
                contentView.setDrawableParameters(R.id.right_icon, false, -1,
                        0xFFFFFFFF,
                        PorterDuff.Mode.SRC_ATOP, -1);

                contentView.setInt(R.id.right_icon,
                        "setBackgroundResource",
                        R.drawable.notification_icon_legacy_bg);

                contentView.setDrawableParameters(
                        R.id.right_icon,
                        true,
                        -1,
                        mColor,
                        PorterDuff.Mode.SRC_ATOP,
                        -1);
            }
        }

+42 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2014 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
  -->

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:internal="http://schemas.android.com/apk/prv/res/android"
    android:layout_width="@dimen/notification_large_icon_width"
    android:layout_height="@dimen/notification_large_icon_height"
    android:id="@+id/icon_group"
    >
    <ImageView android:id="@+id/icon"
        android:layout_width="@dimen/notification_large_icon_width"
        android:layout_height="@dimen/notification_large_icon_height"
        android:padding="8dp"
        android:scaleType="centerInside"
        />
    <ImageView android:id="@+id/right_icon"
        android:layout_width="24dp"
        android:layout_height="24dp"
        android:padding="4dp"
        android:layout_gravity="end|bottom"
        android:scaleType="centerInside"
        android:visibility="gone"
        android:layout_marginEnd="3dp"
        android:layout_marginBottom="3dp"
        />
</FrameLayout>
+1 −12
Original line number Diff line number Diff line
@@ -23,10 +23,9 @@
    internal:layout_minHeight="64dp"
    internal:layout_maxHeight="64dp"
    >
    <ImageView android:id="@+id/icon"
    <include layout="@layout/notification_template_icon_group"
        android:layout_width="@dimen/notification_large_icon_width"
        android:layout_height="@dimen/notification_large_icon_height"
        android:scaleType="center"
        />
    <LinearLayout
        android:layout_width="match_parent"
@@ -121,16 +120,6 @@
                android:gravity="center"
                android:paddingStart="8dp"
                />
            <ImageView android:id="@+id/right_icon"
                android:layout_width="16dp"
                android:layout_height="16dp"
                android:layout_gravity="center"
                android:layout_weight="0"
                android:layout_marginStart="8dp"
                android:scaleType="centerInside"
                android:visibility="gone"
                android:drawableAlpha="153"
                />
        </LinearLayout>
    </LinearLayout>
</FrameLayout>
+1 −12
Original line number Diff line number Diff line
@@ -23,10 +23,9 @@
    internal:layout_minHeight="65dp"
    internal:layout_maxHeight="unbounded"
    >
    <ImageView android:id="@+id/icon"
    <include layout="@layout/notification_template_icon_group"
        android:layout_width="@dimen/notification_large_icon_width"
        android:layout_height="@dimen/notification_large_icon_height"
        android:scaleType="center"
        />
    <LinearLayout
        android:layout_width="match_parent"
@@ -128,16 +127,6 @@
                    android:gravity="center"
                    android:paddingStart="8dp"
                    />
                <ImageView android:id="@+id/right_icon"
                    android:layout_width="16dp"
                    android:layout_height="16dp"
                    android:layout_gravity="center"
                    android:layout_weight="0"
                    android:layout_marginStart="8dp"
                    android:scaleType="centerInside"
                    android:visibility="gone"
                    android:drawableAlpha="153"
                    />
            </LinearLayout>
            <ProgressBar
                android:id="@android:id/progress"
+1 −12
Original line number Diff line number Diff line
@@ -22,10 +22,9 @@
    internal:layout_minHeight="65dp"
    internal:layout_maxHeight="unbounded"
    >
    <ImageView android:id="@+id/icon"
    <include layout="@layout/notification_template_icon_group"
        android:layout_width="@dimen/notification_large_icon_width"
        android:layout_height="@dimen/notification_large_icon_height"
        android:scaleType="center"
        />
    <LinearLayout
        android:layout_width="match_parent"
@@ -166,16 +165,6 @@
                android:gravity="center"
                android:paddingStart="8dp"
                />
            <ImageView android:id="@+id/right_icon"
                android:layout_width="16dp"
                android:layout_height="16dp"
                android:layout_gravity="center"
                android:layout_weight="0"
                android:layout_marginStart="8dp"
                android:scaleType="centerInside"
                android:visibility="gone"
                android:drawableAlpha="153"
                />
        </LinearLayout>
    </LinearLayout>
</FrameLayout>
Loading