@Test public void testOnKeyUp() { KeyEvent keyEvent = mock(KeyEvent.class); when(keyEvent.getFlags()).thenReturn(KeyEvent.FLAG_CANCELED_LONG_PRESS); assertFalse(delegate.onKeyUp(KeyEvent.KEYCODE_BACK, keyEvent)); assertFalse(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_UP, keyEvent)); assertFalse(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_DOWN, keyEvent)); KeyEvent keyEventVolUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_UP), keyEventVolDown = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_DOWN); assertTrue(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_UP, keyEventVolUp)); verify(scrollable).scrollToPrevious(); verify(appBar).setExpanded(eq(true), anyBoolean()); reset(scrollable, appBar); when(scrollable.scrollToPrevious()).thenReturn(true); assertTrue(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_UP, keyEventVolUp)); verify(scrollable).scrollToPrevious(); verify(appBar, never()).setExpanded(eq(true), anyBoolean()); reset(scrollable, appBar); when(appBar.getHeight()).thenReturn(10); when(appBar.getBottom()).thenReturn(10); assertTrue(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_DOWN, keyEventVolDown)); verify(scrollable, never()).scrollToNext(); verify(appBar).setExpanded(eq(false), anyBoolean()); reset(scrollable, appBar); when(appBar.getHeight()).thenReturn(10); when(appBar.getBottom()).thenReturn(0); assertTrue(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_DOWN, keyEventVolDown)); verify(scrollable).scrollToNext(); verify(appBar, never()).setExpanded(eq(false), anyBoolean()); }
public boolean onKeyUp(int keyCode, KeyEvent event) { if (!mEnabled) { return false; } boolean notLongPress = (event.getFlags() & KeyEvent.FLAG_CANCELED_LONG_PRESS) == 0; if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && notLongPress) { shortPress(DIRECTION_UP); return true; } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN && notLongPress) { shortPress(DIRECTION_DOWN); return true; } return false; }
KeyDelegate { public boolean onKeyUp(int keyCode, KeyEvent event) { if (!mEnabled) { return false; } boolean notLongPress = (event.getFlags() & KeyEvent.FLAG_CANCELED_LONG_PRESS) == 0; if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && notLongPress) { shortPress(DIRECTION_UP); return true; } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN && notLongPress) { shortPress(DIRECTION_DOWN); return true; } return false; } }
KeyDelegate { public boolean onKeyUp(int keyCode, KeyEvent event) { if (!mEnabled) { return false; } boolean notLongPress = (event.getFlags() & KeyEvent.FLAG_CANCELED_LONG_PRESS) == 0; if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && notLongPress) { shortPress(DIRECTION_UP); return true; } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN && notLongPress) { shortPress(DIRECTION_DOWN); return true; } return false; } KeyDelegate(); }
KeyDelegate { public boolean onKeyUp(int keyCode, KeyEvent event) { if (!mEnabled) { return false; } boolean notLongPress = (event.getFlags() & KeyEvent.FLAG_CANCELED_LONG_PRESS) == 0; if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && notLongPress) { shortPress(DIRECTION_UP); return true; } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN && notLongPress) { shortPress(DIRECTION_DOWN); return true; } return false; } KeyDelegate(); void attach(Activity activity); void detach(Activity activity); void setScrollable(Scrollable scrollable, AppBarLayout appBarLayout); boolean onKeyDown(int keyCode, KeyEvent event); boolean onKeyUp(int keyCode, KeyEvent event); @SuppressWarnings("UnusedParameters") boolean onKeyLongPress(int keyCode, KeyEvent event); }
KeyDelegate { public boolean onKeyUp(int keyCode, KeyEvent event) { if (!mEnabled) { return false; } boolean notLongPress = (event.getFlags() & KeyEvent.FLAG_CANCELED_LONG_PRESS) == 0; if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && notLongPress) { shortPress(DIRECTION_UP); return true; } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN && notLongPress) { shortPress(DIRECTION_DOWN); return true; } return false; } KeyDelegate(); void attach(Activity activity); void detach(Activity activity); void setScrollable(Scrollable scrollable, AppBarLayout appBarLayout); boolean onKeyDown(int keyCode, KeyEvent event); boolean onKeyUp(int keyCode, KeyEvent event); @SuppressWarnings("UnusedParameters") boolean onKeyLongPress(int keyCode, KeyEvent event);  }