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

Commit bf9b181e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes Ie8bf816b,I8045cb47

* changes:
  Allow tapping notification icon to expand/contract.
  Prioritize ContentTitle over the SubText
parents 40d11f38 ee451e58
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -43,12 +43,13 @@ import java.util.ArrayList;
 */
@RemoteViews.RemoteView
public class NotificationHeaderView extends FrameLayout {
    private final int mContentEndMargin;
    private final int mHeadingEndMargin;
    private final int mTouchableHeight;
    private OnClickListener mExpandClickListener;
    private HeaderTouchListener mTouchListener = new HeaderTouchListener();
    private NotificationTopLineView mTopLineView;
    private NotificationExpandButton mExpandButton;
    private View mAltExpandTarget;
    private CachingIconView mIcon;
    private Drawable mBackground;
    private boolean mEntireHeaderClickable;
@@ -82,8 +83,8 @@ public class NotificationHeaderView extends FrameLayout {
            int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        Resources res = getResources();
        mContentEndMargin = res.getDimensionPixelSize(R.dimen.notification_content_margin_end);
        mHeadingEndMargin = res.getDimensionPixelSize(R.dimen.notification_heading_margin_end);
        mTouchableHeight = res.getDimensionPixelSize(R.dimen.notification_header_touchable_height);
        mEntireHeaderClickable = res.getBoolean(R.bool.config_notificationHeaderClickableForExpand);
    }

@@ -93,6 +94,7 @@ public class NotificationHeaderView extends FrameLayout {
        mIcon = findViewById(R.id.icon);
        mTopLineView = findViewById(R.id.notification_top_line);
        mExpandButton = findViewById(R.id.expand_button);
        mAltExpandTarget = findViewById(R.id.alternate_expand_target);
        setClipToPadding(false);
    }

@@ -146,6 +148,7 @@ public class NotificationHeaderView extends FrameLayout {
    public void setOnClickListener(@Nullable OnClickListener l) {
        mExpandClickListener = l;
        mExpandButton.setOnClickListener(mExpandClickListener);
        mAltExpandTarget.setOnClickListener(mExpandClickListener);
        updateTouchListener();
    }

@@ -187,6 +190,7 @@ public class NotificationHeaderView extends FrameLayout {

        private final ArrayList<Rect> mTouchRects = new ArrayList<>();
        private Rect mExpandButtonRect;
        private Rect mAltExpandTargetRect;
        private int mTouchSlop;
        private boolean mTrackGesture;
        private float mDownX;
@@ -199,6 +203,7 @@ public class NotificationHeaderView extends FrameLayout {
            mTouchRects.clear();
            addRectAroundView(mIcon);
            mExpandButtonRect = addRectAroundView(mExpandButton);
            mAltExpandTargetRect = addRectAroundView(mAltExpandTarget);
            addWidthRect();
            mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
        }
@@ -206,7 +211,7 @@ public class NotificationHeaderView extends FrameLayout {
        private void addWidthRect() {
            Rect r = new Rect();
            r.top = 0;
            r.bottom = (int) (32 * getResources().getDisplayMetrics().density);
            r.bottom = mTouchableHeight;
            r.left = 0;
            r.right = getWidth();
            mTouchRects.add(r);
@@ -277,7 +282,8 @@ public class NotificationHeaderView extends FrameLayout {
                return true;
            }
            if (mExpandOnlyOnButton) {
                return mExpandButtonRect.contains((int) x, (int) y);
                return mExpandButtonRect.contains((int) x, (int) y)
                        || mAltExpandTargetRect.contains((int) x, (int) y);
            }
            for (int i = 0; i < mTouchRects.size(); i++) {
                Rect r = mTouchRects.get(i);
+25 −27
Original line number Diff line number Diff line
@@ -97,10 +97,8 @@ public class NotificationTopLineView extends ViewGroup {
        final int givenWidth = MeasureSpec.getSize(widthMeasureSpec);
        final int givenHeight = MeasureSpec.getSize(heightMeasureSpec);
        final boolean wrapHeight = MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST;
        int wrapContentWidthSpec = MeasureSpec.makeMeasureSpec(givenWidth,
                MeasureSpec.AT_MOST);
        int wrapContentHeightSpec = MeasureSpec.makeMeasureSpec(givenHeight,
                MeasureSpec.AT_MOST);
        int wrapContentWidthSpec = MeasureSpec.makeMeasureSpec(givenWidth, MeasureSpec.AT_MOST);
        int heightSpec = MeasureSpec.makeMeasureSpec(givenHeight, MeasureSpec.AT_MOST);
        int totalWidth = getPaddingStart();
        int maxChildHeight = -1;
        mMaxAscent = -1;
@@ -114,7 +112,7 @@ public class NotificationTopLineView extends ViewGroup {
            final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams();
            int childWidthSpec = getChildMeasureSpec(wrapContentWidthSpec,
                    lp.leftMargin + lp.rightMargin, lp.width);
            int childHeightSpec = getChildMeasureSpec(wrapContentHeightSpec,
            int childHeightSpec = getChildMeasureSpec(heightSpec,
                    lp.topMargin + lp.bottomMargin, lp.height);
            child.measure(childWidthSpec, childHeightSpec);
            totalWidth += lp.leftMargin + lp.rightMargin + child.getMeasuredWidth();
@@ -131,30 +129,29 @@ public class NotificationTopLineView extends ViewGroup {
        int endMargin = Math.max(mHeaderTextMarginEnd, getPaddingEnd());
        if (totalWidth > givenWidth - endMargin) {
            int overFlow = totalWidth - givenWidth + endMargin;
            if (mAppName != null) {
                // We are overflowing, lets shrink the app name first
                overFlow = shrinkViewForOverflow(wrapContentHeightSpec, overFlow, mAppName,
                        mChildMinWidth);
            }

            if (mTitle != null) {
                // still overflowing, we shrink the title text
                overFlow = shrinkViewForOverflow(wrapContentHeightSpec, overFlow, mTitle,
                        mChildMinWidth);
            }
            // First shrink the app name, down to a minimum size
            overFlow = shrinkViewForOverflow(heightSpec, overFlow, mAppName, mChildMinWidth);

            // Next, shrink the header text (this usually has subText)
            //   This shrinks the subtext first, but not all the way (yet!)
            overFlow = shrinkViewForOverflow(heightSpec, overFlow, mHeaderText, mChildMinWidth);

            // still overflowing, we shrink the header text
            overFlow = shrinkViewForOverflow(wrapContentHeightSpec, overFlow, mHeaderText, 0);
            // Next, shrink the secondary header text  (this rarely has conversationTitle)
            overFlow = shrinkViewForOverflow(heightSpec, overFlow, mSecondaryHeaderText, 0);

            // still overflowing, finally we shrink the secondary header text
            shrinkViewForOverflow(wrapContentHeightSpec, overFlow, mSecondaryHeaderText,
                    0);
            // Next, shrink the title text (this has contentTitle; only in headerless views)
            overFlow = shrinkViewForOverflow(heightSpec, overFlow, mTitle, mChildMinWidth);

            // Finally, if there is still overflow, shrink the header down to 0 if still necessary.
            shrinkViewForOverflow(heightSpec, overFlow, mHeaderText, 0);
        }
        setMeasuredDimension(givenWidth, wrapHeight ? maxChildHeight : givenHeight);
    }

    private int shrinkViewForOverflow(int heightSpec, int overFlow, View targetView,
            int minimumWidth) {
        if (targetView != null) {
            final int oldWidth = targetView.getMeasuredWidth();
            if (overFlow > 0 && targetView.getVisibility() != GONE && oldWidth > minimumWidth) {
                // we're still too big
@@ -163,6 +160,7 @@ public class NotificationTopLineView extends ViewGroup {
                targetView.measure(childWidthSpec, heightSpec);
                overFlow -= oldWidth - newSize;
            }
        }
        return overFlow;
    }

+8 −0
Original line number Diff line number Diff line
@@ -54,6 +54,14 @@

    </NotificationTopLineView>

    <FrameLayout
        android:id="@+id/alternate_expand_target"
        android:layout_width="@dimen/notification_content_margin_start"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:importantForAccessibility="no"
        />

    <com.android.internal.widget.NotificationExpandButton
        android:id="@+id/expand_button"
        android:layout_width="@dimen/notification_header_expand_icon_size"
+8 −0
Original line number Diff line number Diff line
@@ -143,6 +143,14 @@
        android:scaleType="centerCrop"
        />

    <FrameLayout
        android:id="@+id/alternate_expand_target"
        android:layout_width="@dimen/notification_content_margin_start"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:importantForAccessibility="no"
        />

    <FrameLayout
        android:id="@+id/expand_button_touch_container"
        android:layout_width="wrap_content"
+3 −0
Original line number Diff line number Diff line
@@ -259,6 +259,9 @@
    <!-- The height of the background for a notification header on a group -->
    <dimen name="notification_header_background_height">49.5dp</dimen>

    <!-- The height of the full-width touch rectangle for the notification header -->
    <dimen name="notification_header_touchable_height">36dp</dimen>

    <!-- The top padding for the notification header -->
    <dimen name="notification_header_padding_top">16dp</dimen>

Loading