Browse Source

Enhanced keyboard shortcuts. Added Ctrl+f to find in page, Alt+<number> to switch to a specific tab, and Ctrl+Shift+p to open a new private window. Ctrl+p was left reserved for printing.

master
Zoraver Kang 8 years ago
parent
commit
0919c25969
  1. 22
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  2. 18
      app/src/main/java/acr/browser/lightning/activity/MainActivity.java

22
app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java

@ -750,8 +750,13 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
@Override @Override
public boolean dispatchKeyEvent(KeyEvent event) { public boolean dispatchKeyEvent(KeyEvent event) {
// Keyboard shortcuts // Keyboard shortcuts
if (event.isCtrlPressed() && event.getAction() == KeyEvent.ACTION_DOWN) { if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (event.isCtrlPressed()) {
switch (event.getKeyCode()) { switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_F:
// Search in page
findInPage();
return true;
case KeyEvent.KEYCODE_T: case KeyEvent.KEYCODE_T:
// Open new tab // Open new tab
newTab(null, true); newTab(null, true);
@ -791,11 +796,24 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
mPresenter.tabChanged(nextIndex); mPresenter.tabChanged(nextIndex);
return true; return true;
} }
} else if (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_SEARCH) { } else if (event.getKeyCode() == KeyEvent.KEYCODE_SEARCH) {
// Highlight search field // Highlight search field
mSearch.requestFocus(); mSearch.requestFocus();
mSearch.selectAll(); mSearch.selectAll();
return true; return true;
} else if (event.isAltPressed()) {
// Alt + tab number
if (KeyEvent.KEYCODE_0 <= event.getKeyCode() && event.getKeyCode() <= KeyEvent.KEYCODE_9) {
int nextIndex;
if (event.getKeyCode() > mTabsManager.last() + KeyEvent.KEYCODE_1 || event.getKeyCode() == KeyEvent.KEYCODE_0) {
nextIndex = mTabsManager.last();
} else {
nextIndex = event.getKeyCode() - KeyEvent.KEYCODE_1;
}
mPresenter.tabChanged(nextIndex);
return true;
}
}
} }
return super.dispatchKeyEvent(event); return super.dispatchKeyEvent(event);
} }

18
app/src/main/java/acr/browser/lightning/activity/MainActivity.java

@ -4,6 +4,7 @@ import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.view.KeyEvent;
import android.view.Menu; import android.view.Menu;
import android.webkit.CookieManager; import android.webkit.CookieManager;
import android.webkit.CookieSyncManager; import android.webkit.CookieSyncManager;
@ -76,5 +77,22 @@ public class MainActivity extends BrowserActivity {
}); });
} }
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN && event.isCtrlPressed()) {
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_P:
// Open a new private window
if(event.isShiftPressed()) {
startActivity(new Intent(this, IncognitoActivity.class));
overridePendingTransition(R.anim.slide_up_in, R.anim.fade_out_scale);
return true;
}
break;
}
}
return super.dispatchKeyEvent(event);
}
} }

Loading…
Cancel
Save