|
42 | 42 | import android.os.Parcelable; |
43 | 43 | import androidx.appcompat.content.res.AppCompatResources; |
44 | 44 | import android.util.AttributeSet; |
45 | | -import android.view.KeyEvent; |
46 | 45 | import android.view.View; |
47 | 46 | import android.view.ViewGroup; |
48 | 47 | import android.view.ViewOutlineProvider; |
@@ -1445,7 +1444,6 @@ public Behavior(Context context, AttributeSet attrs) { |
1445 | 1444 | // TODO(b/76413401): remove this base class and generic type after the widget migration is done |
1446 | 1445 | protected static class BaseBehavior<T extends AppBarLayout> extends HeaderBehavior<T> { |
1447 | 1446 | private static final int MAX_OFFSET_ANIMATION_DURATION = 600; // ms |
1448 | | - private static final double EXPAND_BY_KEY_EVENT_THRESHOLD_PERCENTAGE = 0.1; |
1449 | 1447 |
|
1450 | 1448 | /** Callback to allow control over any {@link AppBarLayout} dragging. */ |
1451 | 1449 | // TODO(b/76413401): remove this base class and generic type after the widget migration |
@@ -1827,56 +1825,9 @@ public boolean onLayoutChild( |
1827 | 1825 | abl.onOffsetChanged(getTopAndBottomOffset()); |
1828 | 1826 |
|
1829 | 1827 | updateAccessibilityActions(parent, abl); |
1830 | | - // TODO(b/243555083): Until CoordinatorLayout fixes triggering scroll events with physical |
1831 | | - // keyboard scrolling, we have this hack in place. |
1832 | | - View v = findFirstScrollingChild(parent); |
1833 | | - if (v != null) { |
1834 | | - if (VERSION.SDK_INT >= VERSION_CODES.P) { |
1835 | | - v.addOnUnhandledKeyEventListener( |
1836 | | - (v1, event) -> { |
1837 | | - controlExpansionOnKeyPress(event, v, abl); |
1838 | | - return false; |
1839 | | - }); |
1840 | | - } else { |
1841 | | - // Unfortunately if not using >= API 28, we don't have access to the unhandled key event |
1842 | | - // handler. Using setOnKeyListener is less ideal since it will replace any listener |
1843 | | - // already on the scrollable child. Furthermore, the 'scrolling' may be occurring due to |
1844 | | - // switching focus between children of the scrollable child, which will not trigger this |
1845 | | - // listener. |
1846 | | - v.setOnKeyListener( |
1847 | | - (v1, keyCode, event) -> { |
1848 | | - controlExpansionOnKeyPress(event, v, abl); |
1849 | | - return false; |
1850 | | - }); |
1851 | | - } |
1852 | | - } |
1853 | 1828 | return handled; |
1854 | 1829 | } |
1855 | 1830 |
|
1856 | | - // TODO(b/243555083): Until CoordinatorLayout fixes triggering scroll events with physical |
1857 | | - // keyboard scrolling, we have this hack in place. |
1858 | | - private void controlExpansionOnKeyPress( |
1859 | | - KeyEvent event, View scrollableChild, AppBarLayout abl) { |
1860 | | - if (event.getAction() == KeyEvent.ACTION_DOWN || event.getAction() == KeyEvent.ACTION_UP) { |
1861 | | - int keyCode = event.getKeyCode(); |
1862 | | - if (keyCode == KeyEvent.KEYCODE_DPAD_UP |
1863 | | - || keyCode == KeyEvent.KEYCODE_SYSTEM_NAVIGATION_UP |
1864 | | - || keyCode == KeyEvent.KEYCODE_PAGE_UP) { |
1865 | | - // If within height threshold, we expand. |
1866 | | - if (scrollableChild.getScrollY() |
1867 | | - < scrollableChild.getMeasuredHeight() * EXPAND_BY_KEY_EVENT_THRESHOLD_PERCENTAGE) { |
1868 | | - abl.setExpanded(true); |
1869 | | - } |
1870 | | - } else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN |
1871 | | - || keyCode == KeyEvent.KEYCODE_SYSTEM_NAVIGATION_DOWN |
1872 | | - || keyCode == KeyEvent.KEYCODE_PAGE_DOWN) { |
1873 | | - if (scrollableChild.getScrollY() > 0) { |
1874 | | - abl.setExpanded(false); |
1875 | | - } |
1876 | | - } |
1877 | | - } |
1878 | | - } |
1879 | | - |
1880 | 1831 | private void updateAccessibilityActions( |
1881 | 1832 | CoordinatorLayout coordinatorLayout, @NonNull T appBarLayout) { |
1882 | 1833 | ViewCompat.removeAccessibilityAction(coordinatorLayout, ACTION_SCROLL_FORWARD.getId()); |
|
0 commit comments