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

Commit 24ffe236 authored by Selim Cinek's avatar Selim Cinek Committed by Android (Google) Code Review
Browse files

Merge "Media notifications now properly respect font size changes" into nyc-dev

parents 79fa4069 d2feb63a
Loading
Loading
Loading
Loading
+37 −27
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.RemoteViews;
@@ -31,16 +32,16 @@ import android.widget.RemoteViews;
 * @hide
 */
@RemoteViews.RemoteView
public class MediaNotificationView extends RelativeLayout {
public class MediaNotificationView extends FrameLayout {

    private final int mMaxImageSize;
    private final int mImageMarginBottom;
    private final int mImageMinTopMargin;
    private final int mNotificationContentMarginEnd;
    private final int mNotificationContentImageMarginEnd;
    private ImageView mRightIcon;
    private View mActions;
    private View mHeader;
    private View mMainColumn;

    public MediaNotificationView(Context context) {
        this(context, null);
@@ -61,25 +62,40 @@ public class MediaNotificationView extends RelativeLayout {
        if (hasIcon && mode != MeasureSpec.UNSPECIFIED) {
            measureChild(mActions, widthMeasureSpec, heightMeasureSpec);
            int size = MeasureSpec.getSize(widthMeasureSpec);
            int height = MeasureSpec.getSize(heightMeasureSpec);
            size = size - mActions.getMeasuredWidth();
            ViewGroup.MarginLayoutParams layoutParams =
                    (MarginLayoutParams) mRightIcon.getLayoutParams();
            size -= layoutParams.getMarginEnd();
            int imageEndMargin = layoutParams.getMarginEnd();
            size -= imageEndMargin;
            size = Math.min(size, mMaxImageSize);
            size = Math.max(size, mRightIcon.getMinimumWidth());
            layoutParams.width = size;
            layoutParams.height = size;
            // because we can't allign it to the bottom with a margin, we add a topmargin to it
            layoutParams.topMargin = height - size - mImageMarginBottom;
            mRightIcon.setLayoutParams(layoutParams);

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

        }
        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!
            if (layoutParams.topMargin >= mImageMinTopMargin) {
        if (!hasIcon || topMargin >= mImageMinTopMargin) {
            resetHeaderIndention();
        } else {
            int paddingEnd = mNotificationContentImageMarginEnd;
            ViewGroup.MarginLayoutParams headerParams =
                    (MarginLayoutParams) mHeader.getLayoutParams();
                headerParams.setMarginEnd(size + layoutParams.getMarginEnd());
            headerParams.setMarginEnd(mRightIcon.getMeasuredWidth() + iconParams.getMarginEnd());
            if (mHeader.getPaddingEnd() != paddingEnd) {
                mHeader.setPadding(
                        isLayoutRtl() ? paddingEnd : mHeader.getPaddingLeft(),
@@ -89,11 +105,6 @@ public class MediaNotificationView extends RelativeLayout {
                mHeader.setLayoutParams(headerParams);
            }
        }
            mRightIcon.setLayoutParams(layoutParams);
        } else if (!hasIcon && mHeader.getPaddingEnd() != mNotificationContentMarginEnd) {
            resetHeaderIndention();
        }
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    private void resetHeaderIndention() {
@@ -115,8 +126,6 @@ public class MediaNotificationView extends RelativeLayout {
        super(context, attrs, defStyleAttr, defStyleRes);
        mMaxImageSize = context.getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.media_notification_expanded_image_max_size);
        mImageMarginBottom = context.getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.media_notification_expanded_image_margin_bottom);
        mImageMinTopMargin = (int) (context.getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.notification_content_margin_top)
                + getResources().getDisplayMetrics().density * 2);
@@ -132,5 +141,6 @@ public class MediaNotificationView extends RelativeLayout {
        mRightIcon = (ImageView) findViewById(com.android.internal.R.id.right_icon);
        mActions = findViewById(com.android.internal.R.id.media_actions);
        mHeader = findViewById(com.android.internal.R.id.notification_header);
        mMainColumn = findViewById(com.android.internal.R.id.notification_main_column);
    }
}
+30 −27
Original line number Diff line number Diff line
@@ -19,14 +19,19 @@
<com.android.internal.widget.MediaNotificationView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/status_bar_latest_event_content"
    android:layout_width="match_parent"
    android:layout_height="126dp"
    android:layout_height="wrap_content"
    android:background="#00000000"
    android:tag="bigMediaNarrow"
    >
    <include layout="@layout/notification_template_header"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:layout_alignParentStart="true"/>
        android:layout_gravity="start"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >
        <LinearLayout
            android:id="@+id/notification_main_column"
            android:layout_width="match_parent"
@@ -35,7 +40,6 @@
            android:layout_marginStart="@dimen/notification_content_margin_start"
            android:layout_marginBottom="@dimen/notification_content_margin_bottom"
            android:layout_marginEnd="@dimen/notification_content_margin_end"
        android:layout_toStartOf="@id/right_icon"
            android:minHeight="@dimen/notification_min_content_height"
            android:orientation="vertical"
            >
@@ -46,8 +50,7 @@
            android:id="@+id/media_actions"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true"
            android:layout_marginTop="-15dp"
            android:paddingStart="8dp"
            android:paddingBottom="8dp"
            android:orientation="horizontal"
@@ -55,15 +58,15 @@
            >
            <!-- 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_marginTop="16dp"
        android:layout_alignParentEnd="true"
        android:layout_alignParentTop="true"
        android:layout_marginBottom="16dp"
        android:layout_gravity="bottom|end"
        android:scaleType="centerCrop"
        />
</com.android.internal.widget.MediaNotificationView>