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

Commit 1352a36b authored by Alan Viverette's avatar Alan Viverette
Browse files

Separate TabWidget selection from keyboard focus

Also removes a bunch of weird accessibility hacks that shouldn't have
been there in the first place.

Bug: 19382871
Change-Id: I8cbdfb6e2dab98cc88028dff5bc23376c98a077a
parent cbb6c16f
Loading
Loading
Loading
Loading
+2 −57
Original line number Diff line number Diff line
@@ -117,11 +117,6 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
        a.recycle();

        setChildrenDrawingOrderEnabled(true);

        // Deal with focus, as we don't want the focus to go by default
        // to a tab other than the current tab
        setFocusable(true);
        setOnFocusChangeListener(this);
    }

    @Override
@@ -434,24 +429,6 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
        mSelectedTab = index;
        getChildTabViewAt(mSelectedTab).setSelected(true);
        mStripMoved = true;

        if (isShown()) {
            sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
        }
    }

    /** @hide */
    @Override
    public boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) {
        onPopulateAccessibilityEvent(event);
        // Dispatch only to the selected tab.
        if (mSelectedTab != -1) {
            View tabView = getChildTabViewAt(mSelectedTab);
            if (tabView != null && tabView.getVisibility() == VISIBLE) {
                return tabView.dispatchPopulateAccessibilityEvent(event);
            }
        }
        return false;
    }

    @Override
@@ -467,18 +444,6 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
        event.setCurrentItemIndex(mSelectedTab);
    }


    /** @hide */
    @Override
    public void sendAccessibilityEventUncheckedInternal(AccessibilityEvent event) {
        // this class fires events only when tabs are focused or selected
        if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED && isFocused()) {
            event.recycle();
            return;
        }
        super.sendAccessibilityEventUncheckedInternal(event);
    }

    /**
     * Sets the current tab and focuses the UI on it.
     * This method makes sure that the focused tab matches the selected
@@ -534,7 +499,6 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
        // TODO: detect this via geometry with a tabwidget listener rather
        // than potentially interfere with the view's listener
        child.setOnClickListener(new TabClickListener(getTabCount() - 1));
        child.setOnFocusChangeListener(this);
    }

    @Override
@@ -551,28 +515,9 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
        mSelectionChangedListener = listener;
    }

    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        if (v == this && hasFocus && getTabCount() > 0) {
            getChildTabViewAt(mSelectedTab).requestFocus();
            return;
        }

        if (hasFocus) {
            int i = 0;
            int numTabs = getTabCount();
            while (i < numTabs) {
                if (getChildTabViewAt(i) == v) {
                    setCurrentTab(i);
                    mSelectionChangedListener.onTabSelectionChanged(i, false);
                    if (isShown()) {
                        // a tab is focused so send an event to announce the tab widget state
                        sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
                    }
                    break;
                }
                i++;
            }
        }
        // No-op. Tab selection is separate from keyboard focus.
    }

    // registered with each tab indicator so we can notify tab host