@Test public void testOnKeyUpDisabled() { PreferenceManager.getDefaultSharedPreferences(activity) .edit() .putBoolean(activity.getString(R.string.pref_volume), false) .apply(); assertFalse(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_UP, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_UP))); }
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);  }