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

Commit 0847acd4 authored by Selim Cinek's avatar Selim Cinek
Browse files

Implementing gradual image fade for the media template

Test: play music
Merged-In: I525513ce1da1237c4edad32c0ed31e79d5eacd32
Change-Id: I525513ce1da1237c4edad32c0ed31e79d5eacd32
Fixes: 36561228
parent 5fb73f86
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -4959,6 +4959,22 @@ public class Notification implements Parcelable
        return false;
    }


    /**
     * @return true if this is a media notification
     *
     * @hide
     */
    public boolean isMediaNotification() {
        Class<? extends Style> style = getNotificationStyle();
        if (MediaStyle.class.equals(style)) {
            return true;
        } else if (DecoratedMediaCustomViewStyle.class.equals(style)) {
            return true;
        }
        return false;
    }

    private boolean hasLargeIcon() {
        return mLargeIcon != null || largeIcon != null;
    }
+35 −46
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.RemoteViews;

/**
@@ -34,8 +33,7 @@ import android.widget.RemoteViews;
@RemoteViews.RemoteView
public class MediaNotificationView extends FrameLayout {

    private final int mMaxImageSize;
    private final int mImageMinTopMargin;
    private final int mSmallImageSize;
    private final int mNotificationContentMarginEnd;
    private final int mNotificationContentImageMarginEnd;
    private ImageView mRightIcon;
@@ -57,72 +55,68 @@ public class MediaNotificationView extends FrameLayout {

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int mode = MeasureSpec.getMode(widthMeasureSpec);
        boolean hasIcon = mRightIcon.getVisibility() != GONE;
        if (!hasIcon) {
            resetHeaderIndention();
        }
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int mode = MeasureSpec.getMode(widthMeasureSpec);
        boolean reMeasure = false;
        if (hasIcon && mode != MeasureSpec.UNSPECIFIED) {
            measureChild(mActions, widthMeasureSpec, heightMeasureSpec);
            int size = MeasureSpec.getSize(widthMeasureSpec);
            size = size - mActions.getMeasuredWidth();
            ViewGroup.MarginLayoutParams layoutParams =
                    (MarginLayoutParams) mRightIcon.getLayoutParams();
            int imageEndMargin = layoutParams.getMarginEnd();
            size -= imageEndMargin;
            size = Math.min(size, mMaxImageSize);
            size = Math.max(size, mRightIcon.getMinimumWidth());
            int fullHeight = getMeasuredHeight();
            if (size < fullHeight) {
                size = mSmallImageSize;
            } else {
                size = fullHeight;
            }
            if (layoutParams.width != size || layoutParams.height != size) {
                layoutParams.width = size;
                layoutParams.height = size;
                mRightIcon.setLayoutParams(layoutParams);
                reMeasure = true;
            }

            // lets ensure that the main column doesn't run into the image
            ViewGroup.MarginLayoutParams mainParams
            ViewGroup.MarginLayoutParams params
                    = (MarginLayoutParams) mMainColumn.getLayoutParams();
            int marginEnd = size + imageEndMargin + mNotificationContentMarginEnd;
            if (marginEnd != mainParams.getMarginEnd()) {
                mainParams.setMarginEnd(marginEnd);
                mMainColumn.setLayoutParams(mainParams);
            }

            if (marginEnd != params.getMarginEnd()) {
                params.setMarginEnd(marginEnd);
                mMainColumn.setLayoutParams(params);
                reMeasure = true;
            }
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        ViewGroup.MarginLayoutParams iconParams =
                (MarginLayoutParams) mRightIcon.getLayoutParams();
        int topMargin = getMeasuredHeight() - mRightIcon.getMeasuredHeight()
                - iconParams.bottomMargin;
        // If the topMargin is high enough we can also remove the header constraint!
        boolean reMeasure = false;
        if (!hasIcon || topMargin >= mImageMinTopMargin) {
            reMeasure = resetHeaderIndention();
        } else {
            int paddingEnd = mNotificationContentImageMarginEnd;
            ViewGroup.MarginLayoutParams headerParams =
                    (MarginLayoutParams) mHeader.getLayoutParams();
            int newMarginEnd = mRightIcon.getMeasuredWidth() + iconParams.getMarginEnd();
            if (headerParams.getMarginEnd() != newMarginEnd) {
                headerParams.setMarginEnd(newMarginEnd);
                mHeader.setLayoutParams(headerParams);
            int headerMarginEnd = size + imageEndMargin;
            params = (MarginLayoutParams) mHeader.getLayoutParams();
            if (params.getMarginEnd() != headerMarginEnd) {
                params.setMarginEnd(headerMarginEnd);
                mHeader.setLayoutParams(params);
                reMeasure = true;
            }
            if (mHeader.getPaddingEnd() != paddingEnd) {
            if (mHeader.getPaddingEnd() != mNotificationContentImageMarginEnd) {
                mHeader.setPaddingRelative(mHeader.getPaddingStart(),
                        mHeader.getPaddingTop(),
                        paddingEnd,
                        mNotificationContentImageMarginEnd,
                        mHeader.getPaddingBottom());
                reMeasure = true;
            }
        }
        if (reMeasure) {
            measureChildWithMargins(mHeader, widthMeasureSpec, 0, heightMeasureSpec, 0);
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    }

    private boolean resetHeaderIndention() {
        boolean remeasure = false;
    private void resetHeaderIndention() {
        if (mHeader.getPaddingEnd() != mNotificationContentMarginEnd) {
            mHeader.setPaddingRelative(mHeader.getPaddingStart(),
                    mHeader.getPaddingTop(),
                    mNotificationContentMarginEnd,
                    mHeader.getPaddingBottom());
            remeasure = true;
        }
        ViewGroup.MarginLayoutParams headerParams =
                (MarginLayoutParams) mHeader.getLayoutParams();
@@ -130,19 +124,14 @@ public class MediaNotificationView extends FrameLayout {
        if (headerParams.getMarginEnd() != 0) {
            headerParams.setMarginEnd(0);
            mHeader.setLayoutParams(headerParams);
            remeasure = true;
        }
        return remeasure;
    }

    public MediaNotificationView(Context context, AttributeSet attrs, int defStyleAttr,
            int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        mMaxImageSize = context.getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.media_notification_expanded_image_max_size);
        mImageMinTopMargin = (int) (context.getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.notification_content_margin_top)
                + getResources().getDisplayMetrics().density * 2);
        mSmallImageSize = context.getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.media_notification_expanded_image_small_size);
        mNotificationContentMarginEnd = context.getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.notification_content_margin_end);
        mNotificationContentImageMarginEnd = context.getResources().getDimensionPixelSize(
+7 −10
Original line number Diff line number Diff line
@@ -23,6 +23,13 @@
    android:background="#00000000"
    android:tag="bigMediaNarrow"
    >
    <!-- The size will actually be determined at runtime -->
    <ImageView android:id="@+id/right_icon"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_gravity="top|end"
        android:scaleType="centerCrop"
    />
    <include layout="@layout/notification_template_header"
        android:layout_width="match_parent"
        android:layout_height="53dp"
@@ -60,14 +67,4 @@
            <!-- media buttons will be added here -->
        </LinearLayout>
    </LinearLayout>

    <ImageView android:id="@+id/right_icon"
        android:layout_width="@dimen/media_notification_expanded_image_max_size"
        android:layout_height="@dimen/media_notification_expanded_image_max_size"
        android:minWidth="40dp"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="20dp"
        android:layout_gravity="bottom|end"
        android:scaleType="centerCrop"
        />
</com.android.internal.widget.MediaNotificationView>
+7 −1
Original line number Diff line number Diff line
@@ -23,6 +23,13 @@
    android:background="#00000000"
    android:tag="media"
    >
    <ImageView android:id="@+id/right_icon"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:layout_gravity="top|end"
        android:scaleType="centerCrop"
    />
    <include layout="@layout/notification_template_header"
        android:layout_width="fill_parent"
        android:layout_height="53dp" />
@@ -61,5 +68,4 @@
            <!-- media buttons will be added here -->
        </LinearLayout>
    </LinearLayout>
    <include layout="@layout/notification_template_right_icon" />
</FrameLayout>
+2 −2
Original line number Diff line number Diff line
@@ -208,8 +208,8 @@
    <!-- The minimum height of the content if there are at least two lines or a picture-->
    <dimen name="notification_min_content_height">41dp</dimen>

    <!-- The maximum size of the image in the expanded media notification -->
    <dimen name="media_notification_expanded_image_max_size">94dp</dimen>
    <!-- The small size of the image if the height drawing doesn't work anymore -->
    <dimen name="media_notification_expanded_image_small_size">72dp</dimen>

    <!-- The maximum size of the image in the expanded media notification -->
    <dimen name="media_notification_expanded_image_margin_bottom">20dp</dimen>
Loading