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

Commit b5839a11 authored by Jeff DeCew's avatar Jeff DeCew
Browse files

Increase the expand button touchable area.

The touchable area used to be a 48x48 square, but we
actually want the entire right-hand side of the
notification to be touchable in the collapsed state.

Bug: 163626038
Test: atest SystemUITests
Test: manual - check touch bounds and validate w/ TalkBack
Change-Id: I9c1b5a0e01d841ed5d448ee5e1030b7f1cbbb2f2
parent 1242ae92
Loading
Loading
Loading
Loading
+2 −13
Original line number Diff line number Diff line
@@ -134,7 +134,6 @@ public class ConversationLayout extends FrameLayout
    private CachingIconView mConversationIconBadgeBg;
    private Icon mLargeIcon;
    private View mExpandButtonContainer;
    private View mExpandButtonInnerContainer;
    private ViewGroup mExpandButtonAndContentContainer;
    private NotificationExpandButton mExpandButton;
    private MessagingLinearLayout mImageMessageContainer;
@@ -266,7 +265,6 @@ public class ConversationLayout extends FrameLayout
        mConversationHeader = findViewById(R.id.conversation_header);
        mContentContainer = findViewById(R.id.notification_action_list_margin_target);
        mExpandButtonAndContentContainer = findViewById(R.id.expand_button_and_content_container);
        mExpandButtonInnerContainer = findViewById(R.id.expand_button_inner_container);
        mExpandButton = findViewById(R.id.expand_button);
        mExpandButtonExpandedTopMargin = getResources().getDimensionPixelSize(
                R.dimen.conversation_expand_button_top_margin_expanded);
@@ -1217,25 +1215,18 @@ public class ConversationLayout extends FrameLayout
    }

    private void updateExpandButton() {
        int drawableId;
        int contentDescriptionId;
        int gravity;
        int topMargin = 0;
        ViewGroup newContainer;
        if (mIsCollapsed) {
            drawableId = R.drawable.ic_expand_notification;
            contentDescriptionId = R.string.expand_button_content_description_collapsed;
            gravity = Gravity.CENTER;
            newContainer = mExpandButtonAndContentContainer;
        } else {
            drawableId = R.drawable.ic_collapse_notification;
            contentDescriptionId = R.string.expand_button_content_description_expanded;
            gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
            topMargin = mExpandButtonExpandedTopMargin;
            newContainer = this;
        }
        mExpandButton.setImageDrawable(getContext().getDrawable(drawableId));
        mExpandButton.setColorFilter(mExpandButton.getOriginalNotificationColor());
        mExpandButton.setExpanded(!mIsCollapsed);

        // We need to make sure that the expand button is in the linearlayout pushing over the
        // content when collapsed, but allows the content to flow under it when expanded.
@@ -1250,8 +1241,6 @@ public class ConversationLayout extends FrameLayout
        layoutParams.gravity = gravity;
        layoutParams.topMargin = topMargin;
        mExpandButton.setLayoutParams(layoutParams);

        mExpandButtonInnerContainer.setContentDescription(mContext.getText(contentDescriptionId));
    }

    private void updateContentEndPaddings() {
@@ -1298,7 +1287,7 @@ public class ConversationLayout extends FrameLayout
        mExpandable = expandable;
        if (expandable) {
            mExpandButtonContainer.setVisibility(VISIBLE);
            mExpandButtonInnerContainer.setOnClickListener(onClickListener);
            mExpandButton.setOnClickListener(onClickListener);
            mConversationIconContainer.setOnClickListener(onClickListener);
        } else {
            mExpandButtonContainer.setVisibility(GONE);
+38 −9
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.RemotableViewMethod;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.Button;
import android.widget.ImageView;
@@ -36,33 +37,58 @@ import com.android.internal.R;
@RemoteViews.RemoteView
public class NotificationExpandButton extends ImageView {

    private final int mMinTouchTargetSize;
    private boolean mExpanded;
    private int mOriginalNotificationColor;

    public NotificationExpandButton(Context context) {
        super(context);
        this(context, null, 0, 0);
    }

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

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

    public NotificationExpandButton(Context context, @Nullable AttributeSet attrs, int defStyleAttr,
            int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        mMinTouchTargetSize = (int) (getResources().getDisplayMetrics().density * 48 + 0.5);
    }

    /**
     * Show the touchable area of the view for a11y.
     * If the parent is the touch container, then that view's bounds are the touchable area.
     */
    @Override
    public void getBoundsOnScreen(Rect outRect, boolean clipToParent) {
        ViewGroup parent = (ViewGroup) getParent();
        if (parent != null && parent.getId() == R.id.expand_button_touch_container) {
            parent.getBoundsOnScreen(outRect, clipToParent);
        } else {
            super.getBoundsOnScreen(outRect, clipToParent);
        }
        extendRectToMinTouchSize(outRect);
    }

    /**
     * Determined if the given point should be touchable.
     * If the parent is the touch container, then any point in that view should be touchable.
     */
    @Override
    public boolean pointInView(float localX, float localY, float slop) {
        ViewGroup parent = (ViewGroup) getParent();
        if (parent != null && parent.getId() == R.id.expand_button_touch_container) {
            // If our parent is checking with us, then the point must be within its bounds.
            return true;
        }
        return super.pointInView(localX, localY, slop);
    }

    @RemotableViewMethod
    public void setOriginalNotificationColor(int color) {
        mOriginalNotificationColor = color;
@@ -81,11 +107,14 @@ public class NotificationExpandButton extends ImageView {
    }

    private void extendRectToMinTouchSize(Rect rect) {
        int touchTargetSize = (int) (getResources().getDisplayMetrics().density * 48);
        rect.left = rect.centerX() - touchTargetSize / 2;
        rect.right = rect.left + touchTargetSize;
        rect.top = rect.centerY() - touchTargetSize / 2;
        rect.bottom = rect.top + touchTargetSize;
        if (rect.width() < mMinTouchTargetSize) {
            rect.left = rect.centerX() - mMinTouchTargetSize / 2;
            rect.right = rect.left + mMinTouchTargetSize;
        }
        if (rect.height() < mMinTouchTargetSize) {
            rect.top = rect.centerY() - mMinTouchTargetSize / 2;
            rect.bottom = rect.top + mMinTouchTargetSize;
        }
    }

    @Override
+17 −11
Original line number Diff line number Diff line
@@ -105,16 +105,22 @@
        android:scaleType="centerCrop"
        />

    <FrameLayout
        android:id="@+id/expand_button_touch_container"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="end">

        <com.android.internal.widget.NotificationExpandButton
            android:id="@+id/expand_button"
            android:layout_width="@dimen/notification_header_expand_icon_size"
            android:layout_height="@dimen/notification_header_expand_icon_size"
            android:layout_gravity="center_vertical|end"
        android:background="@null"
            android:contentDescription="@string/expand_button_content_description_collapsed"
            android:paddingTop="@dimen/notification_expand_button_padding_top"
            android:scaleType="center"
        android:visibility="gone"
            />

    </FrameLayout>

</FrameLayout>
+3 −3
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@
        android:clipToPadding="false"
        android:paddingTop="12dp"
        android:paddingBottom="12dp"
        android:importantForAccessibility="no"
    >

        <FrameLayout
@@ -320,7 +321,7 @@
            collapsed layout while the parent makes sure that we're never laid out bigger
            than the messaging content.-->
        <LinearLayout
            android:id="@+id/expand_button_inner_container"
            android:id="@+id/expand_button_touch_container"
            android:layout_width="wrap_content"
            android:layout_height="@dimen/conversation_expand_button_size"
            android:paddingStart="16dp"
@@ -363,8 +364,7 @@
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:drawable="@drawable/ic_expand_notification"
                android:clickable="false"
                android:importantForAccessibility="no"
                android:contentDescription="@string/expand_button_content_description_collapsed"
                />
        </LinearLayout>
    </FrameLayout>
+1 −1
Original line number Diff line number Diff line
@@ -3944,7 +3944,7 @@
  <java-symbol type="id" name="conversation_icon_badge_ring" />
  <java-symbol type="id" name="conversation_icon_badge_bg" />
  <java-symbol type="id" name="expand_button_container" />
  <java-symbol type="id" name="expand_button_inner_container" />
  <java-symbol type="id" name="expand_button_touch_container" />
  <java-symbol type="id" name="messaging_group_content_container" />
  <java-symbol type="id" name="expand_button_and_content_container" />
  <java-symbol type="id" name="conversation_header" />
Loading