@Override public boolean onKeyDown(int keyCode, KeyEvent event) { mKeyDelegate.setScrollable(this, null); return mKeyDelegate.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event); }
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { mKeyDelegate.setScrollable(getCurrent(Scrollable.class), mAppBar); mKeyDelegate.setBackInterceptor(getCurrent(KeyDelegate.BackInterceptor.class)); return mKeyDelegate.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event); }
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { mKeyDelegate.setScrollable(getScrollableList(), mAppBar); mKeyDelegate.setBackInterceptor(getBackInterceptor()); return mKeyDelegate.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event); }
@Before public void setUp() { reset(scrollable, appBar); controller = Robolectric.buildActivity(Activity.class); activity = controller.create().get(); PreferenceManager.getDefaultSharedPreferences(activity) .edit() .putBoolean(activity.getString(R.string.pref_volume), true) .apply(); delegate = new KeyDelegate(); delegate.attach(activity); delegate.setScrollable(scrollable, appBar); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Item item = getIntent().getParcelableExtra(EXTRA_ITEM); if (item == null) { finish(); return; } supportRequestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_thread_preview); setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); //noinspection ConstantConditions getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_HOME_AS_UP); RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view); recyclerView.setLayoutManager(new SnappyLinearLayoutManager(this, false)); recyclerView.addItemDecoration(new CommentItemDecoration(this)); recyclerView.setAdapter(new ThreadPreviewRecyclerViewAdapter(mItemManager, item)); mKeyDelegate.setScrollable( new KeyDelegate.RecyclerViewHelper(recyclerView, KeyDelegate.RecyclerViewHelper.SCROLL_ITEM), null); }
@Test public void testVolumeNavigation() { activity.onKeyDown(KeyEvent.KEYCODE_VOLUME_UP, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_VOLUME_UP)); verify(keyDelegate).setScrollable(any(Scrollable.class), any()); verify(keyDelegate).onKeyDown(anyInt(), any(KeyEvent.class)); activity.onKeyUp(KeyEvent.KEYCODE_VOLUME_UP, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_UP)); verify(keyDelegate).onKeyUp(anyInt(), any(KeyEvent.class)); activity.onKeyLongPress(KeyEvent.KEYCODE_VOLUME_UP, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_VOLUME_UP)); verify(keyDelegate).onKeyLongPress(anyInt(), any(KeyEvent.class)); }
@Test public void testVolumeNavigation() { activity.onKeyDown(KeyEvent.KEYCODE_VOLUME_UP, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_VOLUME_UP)); verify(keyDelegate).setScrollable(any(Scrollable.class), any()); verify(keyDelegate).onKeyDown(anyInt(), any(KeyEvent.class)); activity.onKeyUp(KeyEvent.KEYCODE_VOLUME_UP, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_UP)); verify(keyDelegate).onKeyUp(anyInt(), any(KeyEvent.class)); activity.onKeyLongPress(KeyEvent.KEYCODE_VOLUME_UP, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_VOLUME_UP)); verify(keyDelegate).onKeyLongPress(anyInt(), any(KeyEvent.class)); }
@Test public void testVolumeNavigation() { activity.onKeyDown(KeyEvent.KEYCODE_VOLUME_UP, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_VOLUME_UP)); verify(keyDelegate).setScrollable(any(Scrollable.class), any(AppBarLayout.class)); verify(keyDelegate).onKeyDown(anyInt(), any(KeyEvent.class)); activity.onKeyUp(KeyEvent.KEYCODE_VOLUME_UP, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_UP)); verify(keyDelegate).onKeyUp(anyInt(), any(KeyEvent.class)); activity.onKeyLongPress(KeyEvent.KEYCODE_VOLUME_UP, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_VOLUME_UP)); verify(keyDelegate).onKeyLongPress(anyInt(), any(KeyEvent.class)); }
@Test public void testNoBinding() { delegate.setScrollable(null, null); assertTrue(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_UP, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_UP))); assertTrue(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_DOWN, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_DOWN))); assertTrue(delegate.onKeyLongPress(KeyEvent.KEYCODE_VOLUME_UP, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_UP))); assertTrue(delegate.onKeyLongPress(KeyEvent.KEYCODE_VOLUME_DOWN, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_DOWN))); }
@Test public void testVolumeNavigation() { Intent intent = new Intent(); WebItem webItem = new TestWebItem() { @Override public String getUrl() { return "http://example.com"; } @Override public String getId() { return "1"; } }; intent.putExtra(ItemActivity.EXTRA_ITEM, webItem); controller = Robolectric.buildActivity(ItemActivity.class, intent); controller.create().start().resume().visible(); activity = controller.get(); activity.onKeyDown(KeyEvent.KEYCODE_VOLUME_UP, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_VOLUME_UP)); verify(keyDelegate).setScrollable(any(Scrollable.class), any(AppBarLayout.class)); verify(keyDelegate).onKeyDown(anyInt(), any(KeyEvent.class)); activity.onKeyUp(KeyEvent.KEYCODE_VOLUME_UP, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_UP)); verify(keyDelegate).onKeyUp(anyInt(), any(KeyEvent.class)); activity.onKeyLongPress(KeyEvent.KEYCODE_VOLUME_UP, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_VOLUME_UP)); verify(keyDelegate).onKeyLongPress(anyInt(), any(KeyEvent.class)); }