@Test public void testOnKeyDown() { assertTrue(delegate.onKeyDown(KeyEvent.KEYCODE_VOLUME_UP, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_VOLUME_UP))); assertTrue(delegate.onKeyDown(KeyEvent.KEYCODE_VOLUME_DOWN, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_VOLUME_DOWN))); assertFalse(delegate.onKeyDown(KeyEvent.KEYCODE_BACK, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK))); }
public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { return mBackInterceptor != null && mBackInterceptor.onBackPressed(); } if (!mEnabled) { return false; } if (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { event.startTracking(); return true; } return false; }
KeyDelegate { public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { return mBackInterceptor != null && mBackInterceptor.onBackPressed(); } if (!mEnabled) { return false; } if (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { event.startTracking(); return true; } return false; } }
KeyDelegate { public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { return mBackInterceptor != null && mBackInterceptor.onBackPressed(); } if (!mEnabled) { return false; } if (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { event.startTracking(); return true; } return false; } KeyDelegate(); }
KeyDelegate { public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { return mBackInterceptor != null && mBackInterceptor.onBackPressed(); } if (!mEnabled) { return false; } if (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { event.startTracking(); 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 onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { return mBackInterceptor != null && mBackInterceptor.onBackPressed(); } if (!mEnabled) { return false; } if (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { event.startTracking(); 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);  }