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

Commit c0ac4af1 authored by Selim Cinek's avatar Selim Cinek
Browse files

Improved expand accessibility experience

The expand action is now on the notification itself
instead of the expand button, this way a user immediately
know if it is expanded.
It also improves the click feedback of the expand button

Test: add notifications, observe accessibility feedback
Change-Id: I9c397d839df52d5354d7ae16725ce3e595da19c7
Fixes: 32322410
Fixes: 35064589
parent fc0f9377
Loading
Loading
Loading
Loading
+7 −33
Original line number Diff line number Diff line
@@ -23,9 +23,7 @@ import android.graphics.Canvas;
import android.graphics.Outline;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.ImageView;
import android.widget.RemoteViews;

@@ -67,33 +65,6 @@ public class NotificationHeaderView extends ViewGroup {
            }
        }
    };
    final AccessibilityDelegate mExpandDelegate = new AccessibilityDelegate() {

        @Override
        public boolean performAccessibilityAction(View host, int action, Bundle args) {
            if (super.performAccessibilityAction(host, action, args)) {
                return true;
            }
            if (action == AccessibilityNodeInfo.ACTION_COLLAPSE
                    || action == AccessibilityNodeInfo.ACTION_EXPAND) {
                mExpandClickListener.onClick(mExpandButton);
                return true;
            }
            return false;
        }

        @Override
        public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
            super.onInitializeAccessibilityNodeInfo(host, info);
            // Avoid that the button description is also spoken
            info.setClassName(getClass().getName());
            if (mExpanded) {
                info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_COLLAPSE);
            } else {
                info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_EXPAND);
            }
        }
    };
    private boolean mAcceptAllTouches;

    public NotificationHeaderView(Context context) {
@@ -124,9 +95,6 @@ public class NotificationHeaderView extends ViewGroup {
        mAppName = findViewById(com.android.internal.R.id.app_name_text);
        mHeaderText = findViewById(com.android.internal.R.id.header_text);
        mExpandButton = (ImageView) findViewById(com.android.internal.R.id.expand_button);
        if (mExpandButton != null) {
            mExpandButton.setAccessibilityDelegate(mExpandDelegate);
        }
        mIcon = (CachingIconView) findViewById(com.android.internal.R.id.icon);
        mProfileBadge = findViewById(com.android.internal.R.id.profile_badge);
    }
@@ -295,13 +263,19 @@ public class NotificationHeaderView extends ViewGroup {

    private void updateExpandButton() {
        int drawableId;
        int contentDescriptionId;
        if (mExpanded) {
            drawableId = com.android.internal.R.drawable.ic_collapse_notification;
            contentDescriptionId
                    = com.android.internal.R.string.expand_button_content_description_expanded;
        } else {
            drawableId = com.android.internal.R.drawable.ic_expand_notification;
            contentDescriptionId
                    = com.android.internal.R.string.expand_button_content_description_collapsed;
        }
        mExpandButton.setImageDrawable(getContext().getDrawable(drawableId));
        mExpandButton.setColorFilter(mOriginalNotificationColor);
        mExpandButton.setContentDescription(mContext.getText(contentDescriptionId));
    }

    public void setShowWorkBadgeAtEnd(boolean showWorkBadgeAtEnd) {
@@ -391,7 +365,7 @@ public class NotificationHeaderView extends ViewGroup {
                    break;
                case MotionEvent.ACTION_UP:
                    if (mTrackGesture) {
                        mExpandClickListener.onClick(NotificationHeaderView.this);
                        mExpandButton.performClick();
                    }
                    break;
            }
+8 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import android.annotation.Nullable;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RemoteViews;

@@ -59,4 +61,10 @@ public class NotificationExpandButton extends ImageView {
        rect.top = rect.centerY() - touchTargetSize / 2;
        rect.bottom = rect.top + touchTargetSize;
    }

    @Override
    public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
        super.onInitializeAccessibilityNodeInfo(info);
        info.setClassName(Button.class.getName());
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -97,7 +97,7 @@
        android:layout_height="wrap_content"
        android:paddingTop="1dp"
        android:visibility="gone"
        android:contentDescription="@string/expand_button_content_description"
        android:contentDescription="@string/expand_button_content_description_collapsed"
        />
    <ImageView android:id="@+id/profile_badge"
        android:layout_width="@dimen/notification_badge_size"
+5 −2
Original line number Diff line number Diff line
@@ -4335,8 +4335,11 @@
    <!-- Content description of the work profile icon in the notification. -->
    <string name="notification_work_profile_content_description">Work profile</string>

    <!-- Content description of the expand button icon in the notification.-->
    <string name="expand_button_content_description">Expand button</string>
    <!-- Content description of the expand button icon in the notification when collaped.-->
    <string name="expand_button_content_description_collapsed">Expand</string>

    <!-- Content description of the expand button icon in the notification when expanded.-->
    <string name="expand_button_content_description_expanded">Collapse</string>

    <!-- Accessibility action description on the expand button. -->
    <string name="expand_action_accessibility">toggle expansion</string>
+3 −0
Original line number Diff line number Diff line
@@ -2877,6 +2877,9 @@
  <java-symbol type="string" name="alert_windows_notification_turn_off_action" />
  <java-symbol type="drawable" name="alert_window_layer" />

  <java-symbol type="string" name="expand_button_content_description_collapsed" />
  <java-symbol type="string" name="expand_button_content_description_expanded" />

  <!-- Colon separated list of package names that should be granted Notification Listener access -->
  <java-symbol type="string" name="config_defaultListenerAccessPackages" />
</resources>
Loading