@Test public void testBackPressed() { Intent intent = new Intent(); WebItem webItem = new TestWebItem() { @Override public String getUrl() { return "http: } @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_BACK, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK)); verify(keyDelegate).setBackInterceptor(any()); verify(keyDelegate).onKeyDown(anyInt(), any(KeyEvent.class)); }
@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); }
ItemActivity extends InjectableActivity implements ItemFragment.ItemChangedListener { @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); } }
ItemActivity extends InjectableActivity implements ItemFragment.ItemChangedListener { @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); }  }
ItemActivity extends InjectableActivity implements ItemFragment.ItemChangedListener { @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 boolean onCreateOptionsMenu(Menu menu); @Override boolean onPrepareOptionsMenu(Menu menu); @Override boolean onOptionsItemSelected(MenuItem item); @Override void onBackPressed(); @Override boolean onKeyDown(int keyCode, KeyEvent event); @Override boolean onKeyUp(int keyCode, KeyEvent event); @Override boolean onKeyLongPress(int keyCode, KeyEvent event); @Override void onWindowFocusChanged(boolean hasFocus); @Override void onItemChanged(@NonNull Item item); }
ItemActivity extends InjectableActivity implements ItemFragment.ItemChangedListener { @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 boolean onCreateOptionsMenu(Menu menu); @Override boolean onPrepareOptionsMenu(Menu menu); @Override boolean onOptionsItemSelected(MenuItem item); @Override void onBackPressed(); @Override boolean onKeyDown(int keyCode, KeyEvent event); @Override boolean onKeyUp(int keyCode, KeyEvent event); @Override boolean onKeyLongPress(int keyCode, KeyEvent event); @Override void onWindowFocusChanged(boolean hasFocus); @Override void onItemChanged(@NonNull Item item); static final String EXTRA_ITEM; static final String EXTRA_CACHE_MODE; static final String EXTRA_OPEN_COMMENTS; }