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

Commit ff44e803 authored by Jorim Jaggi's avatar Jorim Jaggi Committed by Android Git Automerger
Browse files

am 8219f7cc: am 2157b125: am 99a9436c: Merge "Fix various problems with...

am 8219f7cc: am 2157b125: am 99a9436c: Merge "Fix various problems with notification layouts" into lmp-dev

* commit '8219f7cc7e2fd3e623d8e14260ab720197952c3b':
  Fix various problems with notification layouts
parents bea2e6d9 2c71e557
Loading
Loading
Loading
Loading
+42 −13
Original line number Original line Diff line number Diff line
@@ -1867,6 +1867,15 @@ public class Notification implements Parcelable
         */
         */
        private Notification mRebuildNotification = null;
        private Notification mRebuildNotification = null;


        /**
         * Whether the build notification has three lines. This is used to make the top padding for
         * both the contracted and expanded layout consistent.
         *
         * <p>
         * This field is only valid during the build phase.
         */
        private boolean mHasThreeLines;

        /**
        /**
         * Constructs a new Builder with the defaults:
         * Constructs a new Builder with the defaults:
         *
         *
@@ -2564,19 +2573,23 @@ public class Notification implements Parcelable
            return this;
            return this;
        }
        }


        private Bitmap getProfileBadge() {
        private Drawable getProfileBadgeDrawable() {
            // Note: This assumes that the current user can read the profile badge of the
            // Note: This assumes that the current user can read the profile badge of the
            // originating user.
            // originating user.
            UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
            UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
            Drawable badge = userManager.getBadgeForUser(new UserHandle(mOriginatingUserId), 0);
            return userManager.getBadgeForUser(new UserHandle(mOriginatingUserId), 0);
        }

        private Bitmap getProfileBadge() {
            Drawable badge = getProfileBadgeDrawable();
            if (badge == null) {
            if (badge == null) {
                return null;
                return null;
            }
            }
            final int width = badge.getIntrinsicWidth();
            final int size = mContext.getResources().getDimensionPixelSize(
            final int height = badge.getIntrinsicHeight();
                    R.dimen.notification_badge_size);
            Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(bitmap);
            Canvas canvas = new Canvas(bitmap);
            badge.setBounds(0, 0, width, height);
            badge.setBounds(0, 0, size, size);
            badge.draw(canvas);
            badge.draw(canvas);
            return bitmap;
            return bitmap;
        }
        }
@@ -2602,6 +2615,12 @@ public class Notification implements Parcelable
            return false;
            return false;
        }
        }


        private void shrinkLine3Text(RemoteViews contentView) {
            float subTextSize = mContext.getResources().getDimensionPixelSize(
                    R.dimen.notification_subtext_size);
            contentView.setTextViewTextSize(R.id.text, TypedValue.COMPLEX_UNIT_PX, subTextSize);
        }

        private RemoteViews applyStandardTemplate(int resId) {
        private RemoteViews applyStandardTemplate(int resId) {
            RemoteViews contentView = new BuilderRemoteViews(mContext.getPackageName(),
            RemoteViews contentView = new BuilderRemoteViews(mContext.getPackageName(),
                    mOriginatingUserId, resId);
                    mOriginatingUserId, resId);
@@ -2674,10 +2693,7 @@ public class Notification implements Parcelable
            if (showLine2) {
            if (showLine2) {


                // need to shrink all the type to make sure everything fits
                // need to shrink all the type to make sure everything fits
                final Resources res = mContext.getResources();
                shrinkLine3Text(contentView);
                final float subTextSize = res.getDimensionPixelSize(
                        R.dimen.notification_subtext_size);
                contentView.setTextViewTextSize(R.id.text, TypedValue.COMPLEX_UNIT_PX, subTextSize);
            }
            }


            if (mWhen != 0 && mShowWhen) {
            if (mWhen != 0 && mShowWhen) {
@@ -2696,7 +2712,7 @@ public class Notification implements Parcelable


            // Adjust padding depending on line count and font size.
            // Adjust padding depending on line count and font size.
            contentView.setViewPadding(R.id.line1, 0, calculateTopPadding(mContext,
            contentView.setViewPadding(R.id.line1, 0, calculateTopPadding(mContext,
                    hasThreeLines(), mContext.getResources().getConfiguration().fontScale),
                    mHasThreeLines, mContext.getResources().getConfiguration().fontScale),
                    0, 0);
                    0, 0);


            // We want to add badge to first line of text.
            // We want to add badge to first line of text.
@@ -2721,7 +2737,12 @@ public class Notification implements Parcelable
         *         is going to have one or two lines
         *         is going to have one or two lines
         */
         */
        private boolean hasThreeLines() {
        private boolean hasThreeLines() {
            boolean hasLine3 = mContentText != null || mContentInfo != null || mNumber > 0;
            boolean contentTextInLine2 = mSubText != null && mContentText != null;

            // If we have content text in line 2, badge goes into line 2, or line 3 otherwise
            boolean badgeInLine3 = getProfileBadgeDrawable() != null && !contentTextInLine2;
            boolean hasLine3 = mContentText != null || mContentInfo != null || mNumber > 0
                    || badgeInLine3;
            boolean hasLine2 = (mSubText != null && mContentText != null) ||
            boolean hasLine2 = (mSubText != null && mContentText != null) ||
                    (mSubText == null && (mProgressMax != 0 || mProgressIndeterminate));
                    (mSubText == null && (mProgressMax != 0 || mProgressIndeterminate));
            return hasLine2 && hasLine3;
            return hasLine2 && hasLine3;
@@ -3092,6 +3113,7 @@ public class Notification implements Parcelable
            if (mRebuildNotification == null) {
            if (mRebuildNotification == null) {
                throw new IllegalStateException("rebuild() only valid when in 'rebuild' mode.");
                throw new IllegalStateException("rebuild() only valid when in 'rebuild' mode.");
            }
            }
            mHasThreeLines = hasThreeLines();


            Bundle extras = mRebuildNotification.extras;
            Bundle extras = mRebuildNotification.extras;


@@ -3124,6 +3146,7 @@ public class Notification implements Parcelable
            }
            }
            extras.remove(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW);
            extras.remove(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW);


            mHasThreeLines = false;
            return mRebuildNotification;
            return mRebuildNotification;
        }
        }


@@ -3238,6 +3261,7 @@ public class Notification implements Parcelable
         */
         */
        public Notification build() {
        public Notification build() {
            mOriginatingUserId = mContext.getUserId();
            mOriginatingUserId = mContext.getUserId();
            mHasThreeLines = hasThreeLines();


            Notification n = buildUnstyled();
            Notification n = buildUnstyled();


@@ -3259,6 +3283,7 @@ public class Notification implements Parcelable
                mStyle.addExtras(n.extras);
                mStyle.addExtras(n.extras);
            }
            }


            mHasThreeLines = false;
            return n;
            return n;
        }
        }


@@ -3388,7 +3413,7 @@ public class Notification implements Parcelable
         */
         */
        protected void applyTopPadding(RemoteViews contentView) {
        protected void applyTopPadding(RemoteViews contentView) {
            int topPadding = Builder.calculateTopPadding(mBuilder.mContext,
            int topPadding = Builder.calculateTopPadding(mBuilder.mContext,
                    mBuilder.hasThreeLines(),
                    mBuilder.mHasThreeLines,
                    mBuilder.mContext.getResources().getConfiguration().fontScale);
                    mBuilder.mContext.getResources().getConfiguration().fontScale);
            contentView.setViewPadding(R.id.line1, 0, topPadding, 0, 0);
            contentView.setViewPadding(R.id.line1, 0, topPadding, 0, 0);
        }
        }
@@ -3661,6 +3686,8 @@ public class Notification implements Parcelable


            applyTopPadding(contentView);
            applyTopPadding(contentView);


            mBuilder.shrinkLine3Text(contentView);

            mBuilder.addProfileBadge(contentView, R.id.profile_badge_large_template);
            mBuilder.addProfileBadge(contentView, R.id.profile_badge_large_template);


            return contentView;
            return contentView;
@@ -3800,6 +3827,8 @@ public class Notification implements Parcelable


            applyTopPadding(contentView);
            applyTopPadding(contentView);


            mBuilder.shrinkLine3Text(contentView);

            mBuilder.addProfileBadge(contentView, R.id.profile_badge_large_template);
            mBuilder.addProfileBadge(contentView, R.id.profile_badge_large_template);


            return contentView;
            return contentView;
+2 −2
Original line number Original line Diff line number Diff line
@@ -53,8 +53,8 @@
                android:visibility="gone"
                android:visibility="gone"
                />
                />
            <ImageView android:id="@+id/profile_badge_large_template"
            <ImageView android:id="@+id/profile_badge_large_template"
                android:layout_width="20dp"
                android:layout_width="@dimen/notification_badge_size"
                android:layout_height="20dp"
                android:layout_height="@dimen/notification_badge_size"
                android:layout_weight="0"
                android:layout_weight="0"
                android:layout_marginStart="4dp"
                android:layout_marginStart="4dp"
                android:scaleType="fitCenter"
                android:scaleType="fitCenter"
+4 −3
Original line number Original line Diff line number Diff line
@@ -39,11 +39,12 @@
        <include layout="@layout/notification_template_part_line2" />
        <include layout="@layout/notification_template_part_line2" />
        <LinearLayout
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_height="0dp"
            android:layout_marginEnd="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginBottom="10dp"
            android:layout_marginBottom="10dp"
            android:orientation="horizontal"
            android:orientation="horizontal"
            android:gravity="top"
            android:gravity="top"
            android:layout_weight="1"
            >
            >
            <TextView android:id="@+id/big_text"
            <TextView android:id="@+id/big_text"
                android:textAppearance="@style/TextAppearance.Material.Notification"
                android:textAppearance="@style/TextAppearance.Material.Notification"
@@ -54,8 +55,8 @@
                android:visibility="gone"
                android:visibility="gone"
                />
                />
            <ImageView android:id="@+id/profile_badge_large_template"
            <ImageView android:id="@+id/profile_badge_large_template"
                android:layout_width="20dp"
                android:layout_width="@dimen/notification_badge_size"
                android:layout_height="20dp"
                android:layout_height="@dimen/notification_badge_size"
                android:layout_weight="0"
                android:layout_weight="0"
                android:layout_marginStart="4dp"
                android:layout_marginStart="4dp"
                android:scaleType="fitCenter"
                android:scaleType="fitCenter"
+85 −82
Original line number Original line Diff line number Diff line
@@ -37,31 +37,39 @@
        >
        >
        <include layout="@layout/notification_template_part_line1" />
        <include layout="@layout/notification_template_part_line1" />
        <include layout="@layout/notification_template_part_line2" />
        <include layout="@layout/notification_template_part_line2" />

        <!-- We can't have another vertical linear layout here with weight != 0 so this forces us to
             put the badge on the first line. -->
        <LinearLayout
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:gravity="top"
            >
            <LinearLayout
                android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_weight="1"
                android:layout_height="wrap_content"
            android:layout_height="0dp"
                android:orientation="vertical"
            android:orientation="horizontal"
            >
            >
            <TextView android:id="@+id/inbox_text0"
            <TextView android:id="@+id/inbox_text0"
                android:textAppearance="@style/TextAppearance.Material.Notification"
                android:textAppearance="@style/TextAppearance.Material.Notification"
                    android:layout_width="match_parent"
                android:layout_width="0dp"
                    android:layout_height="0dp"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:singleLine="true"
                android:ellipsize="end"
                android:ellipsize="end"
                android:visibility="gone"
                android:visibility="gone"
                android:layout_weight="1"
                android:layout_weight="1"
                />
                />
            <ImageView android:id="@+id/profile_badge_large_template"
                android:layout_width="@dimen/notification_badge_size"
                android:layout_height="@dimen/notification_badge_size"
                android:layout_weight="0"
                android:layout_marginStart="4dp"
                android:layout_marginEnd="8dp"
                android:scaleType="fitCenter"
                android:visibility="gone"
                />
        </LinearLayout>
        <TextView android:id="@+id/inbox_text1"
        <TextView android:id="@+id/inbox_text1"
            android:textAppearance="@style/TextAppearance.Material.Notification"
            android:textAppearance="@style/TextAppearance.Material.Notification"
            android:layout_width="match_parent"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_height="0dp"
            android:layout_marginEnd="8dp"
            android:singleLine="true"
            android:singleLine="true"
            android:ellipsize="end"
            android:ellipsize="end"
            android:visibility="gone"
            android:visibility="gone"
@@ -71,6 +79,7 @@
            android:textAppearance="@style/TextAppearance.Material.Notification"
            android:textAppearance="@style/TextAppearance.Material.Notification"
            android:layout_width="match_parent"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_height="0dp"
            android:layout_marginEnd="8dp"
            android:singleLine="true"
            android:singleLine="true"
            android:ellipsize="end"
            android:ellipsize="end"
            android:visibility="gone"
            android:visibility="gone"
@@ -80,6 +89,7 @@
            android:textAppearance="@style/TextAppearance.Material.Notification"
            android:textAppearance="@style/TextAppearance.Material.Notification"
            android:layout_width="match_parent"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_height="0dp"
            android:layout_marginEnd="8dp"
            android:singleLine="true"
            android:singleLine="true"
            android:ellipsize="end"
            android:ellipsize="end"
            android:visibility="gone"
            android:visibility="gone"
@@ -89,6 +99,7 @@
            android:textAppearance="@style/TextAppearance.Material.Notification"
            android:textAppearance="@style/TextAppearance.Material.Notification"
            android:layout_width="match_parent"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_height="0dp"
            android:layout_marginEnd="8dp"
            android:singleLine="true"
            android:singleLine="true"
            android:ellipsize="end"
            android:ellipsize="end"
            android:visibility="gone"
            android:visibility="gone"
@@ -98,6 +109,7 @@
            android:textAppearance="@style/TextAppearance.Material.Notification"
            android:textAppearance="@style/TextAppearance.Material.Notification"
            android:layout_width="match_parent"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_height="0dp"
            android:layout_marginEnd="8dp"
            android:singleLine="true"
            android:singleLine="true"
            android:ellipsize="end"
            android:ellipsize="end"
            android:visibility="gone"
            android:visibility="gone"
@@ -107,6 +119,7 @@
            android:textAppearance="@style/TextAppearance.Material.Notification"
            android:textAppearance="@style/TextAppearance.Material.Notification"
            android:layout_width="match_parent"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_height="0dp"
            android:layout_marginEnd="8dp"
            android:singleLine="true"
            android:singleLine="true"
            android:ellipsize="end"
            android:ellipsize="end"
            android:visibility="gone"
            android:visibility="gone"
@@ -116,23 +129,13 @@
            android:textAppearance="@style/TextAppearance.Material.Notification"
            android:textAppearance="@style/TextAppearance.Material.Notification"
            android:layout_width="match_parent"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_height="0dp"
            android:layout_marginEnd="8dp"
            android:singleLine="true"
            android:singleLine="true"
            android:ellipsize="end"
            android:ellipsize="end"
            android:visibility="gone"
            android:visibility="gone"
            android:layout_weight="1"
            android:layout_weight="1"
            android:text="@android:string/ellipsis"
            android:text="@android:string/ellipsis"
            />
            />
            </LinearLayout>
            <ImageView android:id="@+id/profile_badge_large_template"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_weight="0"
                android:layout_marginStart="4dp"
                android:layout_marginEnd="8dp"
                android:scaleType="fitCenter"
                android:visibility="gone"
                />
        </LinearLayout>
        <FrameLayout
        <FrameLayout
            android:id="@+id/inbox_end_pad"
            android:id="@+id/inbox_end_pad"
            android:layout_width="match_parent"
            android:layout_width="match_parent"
+2 −4
Original line number Original line Diff line number Diff line
@@ -20,8 +20,6 @@
        android:layout_width="match_parent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginEnd="8dp"
        android:visibility="gone"
        android:layout_weight="0"
        android:orientation="horizontal"
        android:orientation="horizontal"
        android:gravity="center_vertical"
        android:gravity="center_vertical"
        >
        >
@@ -39,8 +37,8 @@
            android:layout_weight="1"
            android:layout_weight="1"
        />
        />
        <ImageView android:id="@+id/profile_badge_line2"
        <ImageView android:id="@+id/profile_badge_line2"
            android:layout_width="20dp"
            android:layout_width="@dimen/notification_badge_size"
            android:layout_height="20dp"
            android:layout_height="@dimen/notification_badge_size"
            android:layout_weight="0"
            android:layout_weight="0"
            android:layout_marginStart="4dp"
            android:layout_marginStart="4dp"
            android:scaleType="fitCenter"
            android:scaleType="fitCenter"
Loading