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

Commit 6ecc810c authored by Selim Cinek's avatar Selim Cinek
Browse files

Fixed a bug with the media notication template

The image could overlap with the buttons due to
the specced way. This is now fixed.

Change-Id: I346467d48b5f8337d09af4b20e5cdfcd41e12b81
parent d61c302b
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -25,8 +25,6 @@ import android.widget.LinearLayout;
import android.widget.RemoteViews;
import android.widget.TextView;

import com.android.internal.R;

import java.util.ArrayList;

/**
@@ -39,6 +37,7 @@ public class NotificationHeaderView extends LinearLayout {
    public static final int NO_COLOR = -1;
    private final int mHeaderMinWidth;
    private final int mExpandTopPadding;
    private final int mContentEndMargin;
    private View mAppName;
    private View mSubTextView;
    private OnClickListener mExpandClickListener;
@@ -51,6 +50,7 @@ public class NotificationHeaderView extends LinearLayout {
    private int mOriginalNotificationColor;
    private boolean mGroupHeader;
    private boolean mExpanded;
    private boolean mShowWorkBadgeAtEnd;

    public NotificationHeaderView(Context context) {
        this(context, null);
@@ -68,6 +68,8 @@ public class NotificationHeaderView extends LinearLayout {
        super(context, attrs, defStyleAttr, defStyleRes);
        mHeaderMinWidth = getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.notification_header_shrink_min_width);
        mContentEndMargin = getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.notification_content_margin_end);
        mExpandTopPadding = (int) (1 * getResources().getDisplayMetrics().density);
    }

@@ -135,6 +137,9 @@ public class NotificationHeaderView extends LinearLayout {
        super.onLayout(changed, l, t, r, b);
        if (mProfileBadge.getVisibility() != View.GONE) {
            int paddingEnd = getPaddingEnd();
            if (mShowWorkBadgeAtEnd) {
                paddingEnd = mContentEndMargin;
            }
            if (getLayoutDirection() == LAYOUT_DIRECTION_RTL) {
                mProfileBadge.layout(paddingEnd,
                        mProfileBadge.getTop(),
@@ -225,6 +230,13 @@ public class NotificationHeaderView extends LinearLayout {
        mExpandButton.setPadding(0, paddingTop, 0, 0);
    }

    public void setShowWorkBadgeAtEnd(boolean showWorkBadgeAtEnd) {
        if (showWorkBadgeAtEnd != mShowWorkBadgeAtEnd) {
            setClipToPadding(!showWorkBadgeAtEnd);
            mShowWorkBadgeAtEnd = showWorkBadgeAtEnd;
        }
    }

    public class HeaderTouchListener implements View.OnTouchListener {

        private final ArrayList<Rect> mTouchRects = new ArrayList<>();
+136 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 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
 */

package com.android.internal.widget;

import android.annotation.Nullable;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.RemoteViews;

/**
 * A TextView that can float around an image on the end.
 *
 * @hide
 */
@RemoteViews.RemoteView
public class MediaNotificationView extends RelativeLayout {

    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;

    public MediaNotificationView(Context context) {
        this(context, null);
    }

    public MediaNotificationView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MediaNotificationView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        this(context, attrs, defStyleAttr, 0);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int mode = MeasureSpec.getMode(widthMeasureSpec);
        boolean hasIcon = mRightIcon.getVisibility() != GONE;
        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();
            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;
            // If the topMargin is high enough we can also remove the header constraint!
            if (layoutParams.topMargin >= mImageMinTopMargin) {
                resetHeaderIndention();
            } else {
                int paddingEnd = mNotificationContentImageMarginEnd;
                ViewGroup.MarginLayoutParams headerParams =
                        (MarginLayoutParams) mHeader.getLayoutParams();
                headerParams.setMarginEnd(size + layoutParams.getMarginEnd());
                if (mHeader.getPaddingEnd() != paddingEnd) {
                    mHeader.setPadding(
                            isLayoutRtl() ? paddingEnd : mHeader.getPaddingLeft(),
                            mHeader.getPaddingTop(),
                            isLayoutRtl() ? mHeader.getPaddingLeft() : paddingEnd,
                            mHeader.getPaddingBottom());
                    mHeader.setLayoutParams(headerParams);
                }
            }
            mRightIcon.setLayoutParams(layoutParams);
        } else if (!hasIcon && mHeader.getPaddingEnd() != mNotificationContentMarginEnd) {
            resetHeaderIndention();
        }
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    private void resetHeaderIndention() {
        if (mHeader.getPaddingEnd() != mNotificationContentMarginEnd) {
            ViewGroup.MarginLayoutParams headerParams =
                    (MarginLayoutParams) mHeader.getLayoutParams();
            headerParams.setMarginEnd(0);
            mHeader.setPadding(
                    isLayoutRtl() ? mNotificationContentMarginEnd : mHeader.getPaddingLeft(),
                    mHeader.getPaddingTop(),
                    isLayoutRtl() ? mHeader.getPaddingLeft() : mNotificationContentMarginEnd,
                    mHeader.getPaddingBottom());
            mHeader.setLayoutParams(headerParams);
        }
    }

    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);
        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);
        mNotificationContentMarginEnd = context.getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.notification_content_margin_end);
        mNotificationContentImageMarginEnd = context.getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.notification_content_image_margin_end);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        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);
    }
}
+9 −8
Original line number Diff line number Diff line
@@ -16,17 +16,17 @@
  -->

<!-- Layout for the expanded media notification -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<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="128dp"
    android:layout_height="126dp"
    android:background="#00000000"
    android:tag="bigMediaNarrow"
    >
    <include layout="@layout/notification_template_header"
        android:layout_width="fill_parent"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:layout_marginEnd="106dp"/>
        android:layout_alignParentStart="true"/>
    <LinearLayout
        android:id="@+id/notification_main_column"
        android:layout_width="match_parent"
@@ -34,7 +34,7 @@
        android:layout_marginTop="@dimen/notification_content_margin_top"
        android:layout_marginStart="@dimen/notification_content_margin_start"
        android:layout_marginBottom="@dimen/notification_content_margin_bottom"
        android:layout_marginEnd="24dp"
        android:layout_marginEnd="@dimen/notification_content_margin_end"
        android:layout_toStartOf="@id/right_icon"
        android:minHeight="@dimen/notification_min_content_height"
        android:orientation="vertical"
@@ -57,12 +57,13 @@
    </LinearLayout>

    <ImageView android:id="@+id/right_icon"
        android:layout_width="96dp"
        android:layout_height="96dp"
        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:scaleType="centerCrop"
        />
</RelativeLayout>
</com.android.internal.widget.MediaNotificationView>
+1 −2
Original line number Diff line number Diff line
@@ -24,8 +24,7 @@
    >
    <include layout="@layout/notification_template_header"
        android:layout_width="fill_parent"
        android:layout_height="48dp"
        android:layout_marginEnd="106dp"/>
        android:layout_height="48dp" />
    <LinearLayout
        android:id="@+id/notification_main_column"
        android:layout_width="match_parent"
+9 −0
Original line number Diff line number Diff line
@@ -169,6 +169,15 @@
    <!-- 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 maximum size of the image in the expanded media notification -->
    <dimen name="media_notification_expanded_image_margin_bottom">16dp</dimen>

    <!-- The margin of the content to an image-->
    <dimen name="notification_content_image_margin_end">8dp</dimen>

    <!-- Preferred width of the search view. -->
    <dimen name="search_view_preferred_width">320dip</dimen>

Loading