From 19166f8dfbe20cacb5a92130fc736ae0894175e5 Mon Sep 17 00:00:00 2001 From: Zoraver Kang Date: Sun, 18 Dec 2016 23:59:09 -0500 Subject: [PATCH] Added basic keyboard shortcut support. --- .../lightning/activity/BrowserActivity.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java index b848b0a..d3db8e4 100644 --- a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java @@ -712,6 +712,50 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements return super.onKeyUp(keyCode, event); } + @Override + public boolean dispatchKeyEvent(KeyEvent event) { + // Keyboard shortcuts + if (event.isCtrlPressed() && event.getAction() == KeyEvent.ACTION_DOWN) { + switch(event.getKeyCode()) { + case KeyEvent.KEYCODE_T: + // Open new tab + newTab(null, true); + return true; + case KeyEvent.KEYCODE_W: + // Close current tab + mPresenter.deleteTab(mTabsManager.indexOfCurrentTab()); + return true; + case KeyEvent.KEYCODE_Q: + // Close browser + closeBrowser(); + return true; + case KeyEvent.KEYCODE_R: + // Refresh current tab + mTabsManager.getCurrentTab().reload(); + return true; + case KeyEvent.KEYCODE_TAB: + int nextIndex = 0; + if(event.isShiftPressed()) { + // Go back one tab + if(mTabsManager.indexOfCurrentTab() > 0) nextIndex = mTabsManager.indexOfCurrentTab() - 1; + else nextIndex = mTabsManager.last(); + } else { + // Go forward one tab + if(mTabsManager.indexOfCurrentTab() < mTabsManager.last()) nextIndex = mTabsManager.indexOfCurrentTab() + 1; + else nextIndex = 0; + } + mPresenter.tabChanged(nextIndex); + return true; + } + } else if(event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_SEARCH) { + // Highlight search field + mSearch.requestFocus(); + mSearch.selectAll(); + return true; + } + return super.dispatchKeyEvent(event); + } + @Override public boolean onOptionsItemSelected(MenuItem item) { final LightningView currentView = mTabsManager.getCurrentTab();