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

Commit 7b2e888f authored by yingleiw's avatar yingleiw
Browse files

add directional accessibility page actions to StackView

StackView has ITEMS_SLIDE_UP mode and ITEMS_SLIDE_DOWN mode. In
ITEMS_SLIDE_UP mode, scroll forward is slide up and all pages go up
(page down action), scroll backward is slide down and all pages go down
(page up action). In ITEMS_SLIDE_DOWN mode, it is the opposite.
A video in ITEMS_SLIDE_UP MODE is here:
https://drive.google.com/file/d/1m5awAP7ja8tqSaSvNM_oDoVbaUeCa3l6/view?usp=sharing

Test: Tested with twisted talkback that in ITEMS_SLIDE_DOWN mode, page
down action is equivalent to scroll backward, and page up is equivalent
to scroll forward.
Bug: 136277517

Change-Id: I52b2af231781fa04cec5815db2e573a9014e434b
parent e0ad5943
Loading
Loading
Loading
Loading
+47 −11
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@ import android.view.accessibility.AccessibilityNodeInfo;
import android.view.animation.LinearInterpolator;
import android.widget.RemoteViews.RemoteView;

import com.android.internal.R;

import java.lang.ref.WeakReference;

@RemoteView
@@ -1241,12 +1243,38 @@ public class StackView extends AdapterViewAnimator {
        info.setScrollable(getChildCount() > 1);
        if (isEnabled()) {
            if (getDisplayedChild() < getChildCount() - 1) {
                info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
                info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_FORWARD);
                if (mStackMode == ITEMS_SLIDE_UP) {
                    info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_PAGE_DOWN);
                } else {
                    info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_PAGE_UP);
                }
            }
            if (getDisplayedChild() > 0) {
                info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
                info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_BACKWARD);
                if (mStackMode == ITEMS_SLIDE_UP) {
                    info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_PAGE_UP);
                } else {
                    info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_PAGE_DOWN);
                }
            }
        }
    }

    private boolean goForward() {
        if (getDisplayedChild() < getChildCount() - 1) {
            showNext();
            return true;
        }
        return false;
    }

    private boolean goBackward() {
        if (getDisplayedChild() > 0) {
            showPrevious();
            return true;
        }
        return false;
    }

    /** @hide */
@@ -1260,17 +1288,25 @@ public class StackView extends AdapterViewAnimator {
        }
        switch (action) {
            case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD: {
                if (getDisplayedChild() < getChildCount() - 1) {
                    showNext();
                    return true;
                return goForward();
            }
            } return false;
            case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD: {
                if (getDisplayedChild() > 0) {
                    showPrevious();
                    return true;
                return goBackward();
            }
            case R.id.accessibilityActionPageUp: {
                if (mStackMode == ITEMS_SLIDE_UP) {
                    return goBackward();
                } else {
                    return goForward();
                }
            }
            case R.id.accessibilityActionPageDown: {
                if (mStackMode == ITEMS_SLIDE_UP) {
                    return goForward();
                } else {
                    return goBackward();
                }
            }
            } return false;
        }
        return false;
    }