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

Commit 29603462 authored by Selim Cinek's avatar Selim Cinek
Browse files

Continued implementing the notification templates

The progressbar is now also adapted to always have
at most 2 lines.

Change-Id: I092cf2fdfbbd474288398106309ad2ca85b7054b
parent 5f71bee3
Loading
Loading
Loading
Loading
+61 −112
Original line number Diff line number Diff line
@@ -2969,7 +2969,6 @@ public class Notification implements Parcelable
            Bitmap profileBadge = getProfileBadge();

            contentView.setViewVisibility(R.id.profile_badge_large_template, View.GONE);
            contentView.setViewVisibility(R.id.profile_badge_line2, View.GONE);
            contentView.setViewVisibility(R.id.profile_badge_line3, View.GONE);

            if (profileBadge != null) {
@@ -2986,29 +2985,14 @@ public class Notification implements Parcelable
            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 void unshrinkLine3Text(RemoteViews contentView) {
            float regularTextSize = mContext.getResources().getDimensionPixelSize(
                    com.android.internal.R.dimen.notification_text_size);
            contentView.setTextViewTextSize(R.id.text, TypedValue.COMPLEX_UNIT_PX, regularTextSize);
        }

        private void resetStandardTemplate(RemoteViews contentView) {
            resetHeader(contentView);
            resetContentMargins(contentView);
            contentView.setViewVisibility(R.id.right_icon, View.GONE);
            contentView.setTextViewText(R.id.title, null);
            contentView.setTextViewText(R.id.text, null);
            unshrinkLine3Text(contentView);
            contentView.setTextViewText(R.id.text2, null);
            contentView.setViewVisibility(R.id.text2, View.GONE);
            contentView.setViewVisibility(R.id.info, View.GONE);
            contentView.setViewVisibility(R.id.line3, View.GONE);
            contentView.setViewVisibility(R.id.text_line_1, View.GONE);
            contentView.setViewVisibility(R.id.progress, View.GONE);
        }

@@ -3017,15 +3001,16 @@ public class Notification implements Parcelable
            contentView.setTextViewText(R.id.app_name_text, null);
            contentView.setViewVisibility(R.id.chronometer, View.GONE);
            contentView.setViewVisibility(R.id.expand_button, View.GONE);
            contentView.setViewVisibility(R.id.sub_text_time_divider, View.GONE);
            contentView.setViewVisibility(R.id.header_sub_text, View.GONE);
            contentView.setViewVisibility(R.id.app_title_sub_text_divider, View.GONE);
            contentView.setViewVisibility(R.id.header_content_info, View.GONE);
            contentView.setViewVisibility(R.id.number_of_children, View.GONE);
            contentView.setViewVisibility(R.id.sub_text_divider, View.GONE);
            contentView.setViewVisibility(R.id.content_info_divider, View.GONE);
            contentView.setViewVisibility(R.id.time_divider, View.GONE);
        }

        private void resetContentMargins(RemoteViews contentView) {
            contentView.setViewLayoutMarginEnd(R.id.line1, 0);
            contentView.setViewLayoutMarginEnd(R.id.line2, 0);
            contentView.setViewLayoutMarginEnd(R.id.line3, 0);
        }

@@ -3042,9 +3027,6 @@ public class Notification implements Parcelable
            resetStandardTemplate(contentView);

            boolean showLine3 = false;
            // TODO: look into line3 shrinking
            boolean showLine2 = false;
            boolean contentTextInLine2 = false;
            final Bundle ex = mN.extras;

            bindNotificationHeader(contentView);
@@ -3053,39 +3035,31 @@ public class Notification implements Parcelable
                contentView.setTextViewText(R.id.title,
                        processLegacyText(ex.getCharSequence(EXTRA_TITLE)));
            }
            boolean showProgress = handleProgressBar(hasProgress, contentView, ex);
            if (ex.getCharSequence(EXTRA_TEXT) != null) {
                contentView.setTextViewText(R.id.text,
                contentView.setTextViewText(showProgress ? R.id.text_line_1 : R.id.text,
                        processLegacyText(ex.getCharSequence(EXTRA_TEXT)));
                showLine3 = true;
                if (showProgress) {
                    contentView.setViewVisibility(R.id.text_line_1, View.VISIBLE);
                }
            if (ex.getCharSequence(EXTRA_INFO_TEXT) != null) {
                contentView.setTextViewText(R.id.info,
                        processLegacyText(ex.getCharSequence(EXTRA_INFO_TEXT)));
                contentView.setViewVisibility(R.id.info, View.VISIBLE);
                showLine3 = true;
            } else if (mN.number > 0) {
                final int tooBig = mContext.getResources().getInteger(
                        R.integer.status_bar_notification_info_maxnum);
                if (mN.number > tooBig) {
                    contentView.setTextViewText(R.id.info, processLegacyText(
                            mContext.getResources().getString(
                                    R.string.status_bar_notification_info_overflow)));
                } else {
                    NumberFormat f = NumberFormat.getIntegerInstance();
                    contentView.setTextViewText(R.id.info, processLegacyText(f.format(mN.number)));
                showLine3 = !showProgress;
            }
                contentView.setViewVisibility(R.id.info, View.VISIBLE);
            // We want to add badge to first line of text.
            if (addProfileBadge(contentView, R.id.profile_badge_line3)) {
                showLine3 = true;
            } else {
                contentView.setViewVisibility(R.id.info, View.GONE);
            }
            // Note getStandardView may hide line 3 again.
            contentView.setViewVisibility(R.id.line3, showLine3 ? View.VISIBLE : View.GONE);

            return contentView;
        }

            contentView.setViewVisibility(R.id.text2, View.GONE);
        private boolean handleProgressBar(boolean hasProgress, RemoteViews contentView, Bundle ex) {
            final int max = ex.getInt(EXTRA_PROGRESS_MAX, 0);
            final int progress = ex.getInt(EXTRA_PROGRESS, 0);
            final boolean ind = ex.getBoolean(EXTRA_PROGRESS_INDETERMINATE);
            if (hasProgress && (max != 0 || ind)) {
                contentView.setViewVisibility(R.id.progress, View.VISIBLE);
                contentView.setViewVisibility(com.android.internal.R.id.progress, View.VISIBLE);
                contentView.setProgressBar(
                        R.id.progress, max, progress, ind);
                contentView.setProgressBackgroundTintList(
@@ -3096,27 +3070,11 @@ public class Notification implements Parcelable
                    contentView.setProgressTintList(R.id.progress, colorStateList);
                    contentView.setProgressIndeterminateTintList(R.id.progress, colorStateList);
                }
                showLine2 = true;
                return true;
            } else {
                contentView.setViewVisibility(R.id.progress, View.GONE);
                return false;
            }
            if (showLine2) {

                // need to shrink all the type to make sure everything fits
                shrinkLine3Text(contentView);
            }

            // We want to add badge to first line of text.
            boolean addedBadge = addProfileBadge(contentView,
                    contentTextInLine2 ? R.id.profile_badge_line2 : R.id.profile_badge_line3);
            // If we added the badge to line 3 then we should show line 3.
            if (addedBadge && !contentTextInLine2) {
                showLine3 = true;
            }

            // Note getStandardView may hide line 3 again.
            contentView.setViewVisibility(R.id.line3, showLine3 ? View.VISIBLE : View.GONE);
            return contentView;
        }

        private void bindLargeIcon(RemoteViews contentView) {
@@ -3127,8 +3085,8 @@ public class Notification implements Parcelable
                int endMargin = mContext.getResources().getDimensionPixelSize(
                        R.dimen.notification_content_picture_margin);
                contentView.setViewLayoutMarginEnd(R.id.line1, endMargin);
                contentView.setViewLayoutMarginEnd(R.id.line2, endMargin);
                contentView.setViewLayoutMarginEnd(R.id.line3, endMargin);
                contentView.setViewLayoutMarginEnd(R.id.progress, endMargin);
            }
        }

@@ -3136,10 +3094,37 @@ public class Notification implements Parcelable
            bindSmallIcon(contentView);
            bindHeaderAppName(contentView);
            bindHeaderSubText(contentView);
            bindContentInfo(contentView);
            bindHeaderChronometerAndTime(contentView);
            bindExpandButton(contentView);
        }

        private void bindContentInfo(RemoteViews contentView) {
            boolean visible = false;
            if (mN.extras.getCharSequence(EXTRA_INFO_TEXT) != null) {
                contentView.setTextViewText(R.id.header_content_info,
                        processLegacyText(mN.extras.getCharSequence(EXTRA_INFO_TEXT)));
                contentView.setViewVisibility(R.id.header_content_info, View.VISIBLE);
                visible = true;
            } else if (mN.number > 0) {
                final int tooBig = mContext.getResources().getInteger(
                        R.integer.status_bar_notification_info_maxnum);
                if (mN.number > tooBig) {
                    contentView.setTextViewText(R.id.header_content_info, processLegacyText(
                            mContext.getResources().getString(
                                    R.string.status_bar_notification_info_overflow)));
                } else {
                    contentView.setTextViewText(R.id.header_content_info,
                            processLegacyText(String.valueOf(mN.number)));
                }
                contentView.setViewVisibility(R.id.header_content_info, View.VISIBLE);
                visible = true;
            }
            if (visible) {
                contentView.setViewVisibility(R.id.content_info_divider, View.VISIBLE);
            }
        }

        private void bindExpandButton(RemoteViews contentView) {
            contentView.setDrawableParameters(R.id.expand_button, false, -1, resolveColor(),
                    PorterDuff.Mode.SRC_ATOP, -1);
@@ -3147,7 +3132,7 @@ public class Notification implements Parcelable

        private void bindHeaderChronometerAndTime(RemoteViews contentView) {
            if (showsTimeOrChronometer()) {
                contentView.setViewVisibility(R.id.sub_text_time_divider, View.VISIBLE);
                contentView.setViewVisibility(R.id.time_divider, View.VISIBLE);
                if (mN.extras.getBoolean(EXTRA_SHOW_CHRONOMETER)) {
                    contentView.setViewVisibility(R.id.chronometer, View.VISIBLE);
                    contentView.setLong(R.id.chronometer, "setBase",
@@ -3170,7 +3155,7 @@ public class Notification implements Parcelable
                // TODO: Remove the span entirely to only have the string with propper formating.
                contentView.setTextViewText(R.id.header_sub_text, processLegacyText(subText));
                contentView.setViewVisibility(R.id.header_sub_text, View.VISIBLE);
                contentView.setViewVisibility(R.id.app_title_sub_text_divider, View.VISIBLE);
                contentView.setViewVisibility(R.id.sub_text_divider, View.VISIBLE);
            }
        }

@@ -3204,30 +3189,6 @@ public class Notification implements Parcelable
            return mN.when != 0 && mN.extras.getBoolean(EXTRA_SHOW_WHEN);
        }

        /**
         * Logic to find out whether the notification is going to have three lines in the contracted
         * layout. This is used to adjust the top padding.
         *
         * @return true if the notification is going to have three lines; false if the notification
         *         is going to have one or two lines
         */
        private boolean hasThreeLines() {
            final CharSequence subText = mN.extras.getCharSequence(EXTRA_SUB_TEXT);
            final CharSequence text = mN.extras.getCharSequence(EXTRA_TEXT);
            boolean contentTextInLine2 = subText != null && text != null;
            boolean hasProgress = mStyle == null || mStyle.hasProgress();
            // If we have content text in line 2, badge goes into line 2, or line 3 otherwise
            boolean badgeInLine3 = getProfileBadgeDrawable() != null && !contentTextInLine2;
            boolean hasLine3 = text != null || mN.extras.getCharSequence(EXTRA_INFO_TEXT) != null
                    || mN.number > 0 || badgeInLine3;
            final Bundle ex = mN.extras;
            final int max = ex.getInt(EXTRA_PROGRESS_MAX, 0);
            final boolean ind = ex.getBoolean(EXTRA_PROGRESS_INDETERMINATE);
            boolean hasLine2 = (subText != null && text != null) ||
                    (hasProgress && subText == null && (max != 0 || ind));
            return hasLine2 && hasLine3;
        }

        private void resetStandardTemplateWithActions(RemoteViews big) {
            big.setViewVisibility(R.id.actions, View.GONE);
            big.setViewVisibility(R.id.action_divider, View.GONE);
@@ -3286,9 +3247,14 @@ public class Notification implements Parcelable
                result = applyStandardTemplateWithActions(getBigBaseLayoutResource());
            }
            adaptNotificationHeaderForBigContentView(result);
            hideLine1Text(result);
            return result;
        }

        private void hideLine1Text(RemoteViews result) {
            result.setViewVisibility(R.id.text_line_1, View.GONE);
        }

        private void adaptNotificationHeaderForBigContentView(RemoteViews result) {
            // We have to set the collapse button instead
            result.setImageViewResource(R.id.expand_button, R.drawable.ic_arrow_up_14dp);
@@ -3823,10 +3789,7 @@ public class Notification implements Parcelable

            contentView.setImageViewBitmap(R.id.big_picture, mPicture);

            boolean twoTextLines = mBuilder.getAllExtras().getCharSequence(EXTRA_SUB_TEXT) != null
                    && mBuilder.getAllExtras().getCharSequence(EXTRA_TEXT) != null;
            mBuilder.addProfileBadge(contentView,
                    twoTextLines ? R.id.profile_badge_line2 : R.id.profile_badge_line3);
            mBuilder.addProfileBadge(contentView, R.id.profile_badge_line3);
            return contentView;
        }

@@ -3959,9 +3922,6 @@ public class Notification implements Parcelable
            contentView.setTextViewText(R.id.big_text, mBuilder.processLegacyText(mBigText));
            contentView.setViewVisibility(R.id.big_text, View.VISIBLE);
            contentView.setInt(R.id.big_text, "setMaxLines", calculateMaxLines());
            contentView.setViewVisibility(R.id.text2, View.GONE);

            mBuilder.shrinkLine3Text(contentView);

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

@@ -3979,11 +3939,6 @@ public class Notification implements Parcelable
            if (hasSummary) {
                lineCount -= LINES_CONSUMED_BY_SUMMARY;
            }

            // If we have less top padding at the top, we can fit less lines.
            if (!mBuilder.hasThreeLines()) {
                lineCount--;
            }
            return lineCount;
        }
    }
@@ -4079,8 +4034,6 @@ public class Notification implements Parcelable

            mBuilder.getAllExtras().putCharSequence(EXTRA_TEXT, oldBuilderContentText);

            contentView.setViewVisibility(R.id.text2, View.GONE);

            int[] rowIds = {R.id.inbox_text0, R.id.inbox_text1, R.id.inbox_text2, R.id.inbox_text3,
                    R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6};

@@ -4112,8 +4065,6 @@ public class Notification implements Parcelable
                i++;
            }

            mBuilder.shrinkLine3Text(contentView);

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

            return contentView;
@@ -4305,14 +4256,12 @@ public class Notification implements Parcelable
                }
            }
            handleImage(big);
            big.setViewVisibility(android.R.id.progress, View.GONE);
            return big;
        }

        private void handleImage(RemoteViews contentView) {
            if (mBuilder.mN.mLargeIcon != null) {
                contentView.setViewLayoutMarginEnd(R.id.line1, 0);
                contentView.setViewLayoutMarginEnd(R.id.line2, 0);
                contentView.setViewLayoutMarginEnd(R.id.line3, 0);
            }
        }
+20 −2
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@
        android:singleLine="true"
        />
    <TextView
        android:id="@+id/app_title_sub_text_divider"
        android:id="@+id/sub_text_divider"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="@style/TextAppearance.Material.Notification.Info"
@@ -69,7 +69,25 @@
        android:visibility="gone"
        android:singleLine="true"/>
    <TextView
        android:id="@+id/sub_text_time_divider"
        android:id="@+id/content_info_divider"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="@style/TextAppearance.Material.Notification.Info"
        android:layout_marginEnd="4dp"
        android:text="@string/notification_header_divider_symbol"
        android:singleLine="true"
        android:visibility="gone"/>
    <TextView
        android:id="@+id/header_content_info"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="@style/TextAppearance.Material.Notification.Info"
        android:layout_marginEnd="4dp"
        android:visibility="gone"
        android:maxWidth="60dp"
        android:singleLine="true"/>
    <TextView
        android:id="@+id/time_divider"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="@style/TextAppearance.Material.Notification.Info"
+9 −1
Original line number Diff line number Diff line
@@ -34,8 +34,16 @@
        android:orientation="vertical"
        >
        <include layout="@layout/notification_template_part_line1" />
        <include layout="@layout/notification_template_part_line2" />
        <include layout="@layout/notification_template_part_line3" />
    </LinearLayout>
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:layout_marginStart="@dimen/notification_content_margin_start"
        android:layout_marginBottom="11dp"
        android:layout_marginEnd="@dimen/notification_content_margin_end">
        <include layout="@layout/notification_template_progress" />
    </FrameLayout>
    <include layout="@layout/notification_template_right_icon" />
</FrameLayout>
+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@
        android:orientation="vertical"
        >
        <include layout="@layout/notification_template_part_line1" />
        <include layout="@layout/notification_template_part_line2" />
        <include layout="@layout/notification_template_progress" />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
+0 −1
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@
        android:orientation="vertical"
        >
        <include layout="@layout/notification_template_part_line1" />
        <include layout="@layout/notification_template_part_line2" />
        <include layout="@layout/notification_template_part_line3" />
    </LinearLayout>
    <LinearLayout
Loading