commit
7d3ead6af2
@ -720,52 +720,70 @@ 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) {
|
||||||
switch (event.getKeyCode()) {
|
if (event.isCtrlPressed()) {
|
||||||
case KeyEvent.KEYCODE_T:
|
switch (event.getKeyCode()) {
|
||||||
// Open new tab
|
case KeyEvent.KEYCODE_F:
|
||||||
newTab(null, true);
|
// Search in page
|
||||||
return true;
|
findInPage();
|
||||||
case KeyEvent.KEYCODE_W:
|
return true;
|
||||||
// Close current tab
|
case KeyEvent.KEYCODE_T:
|
||||||
mPresenter.deleteTab(mTabsManager.indexOfCurrentTab());
|
// Open new tab
|
||||||
return true;
|
newTab(null, true);
|
||||||
case KeyEvent.KEYCODE_Q:
|
return true;
|
||||||
// Close browser
|
case KeyEvent.KEYCODE_W:
|
||||||
closeBrowser();
|
// Close current tab
|
||||||
return true;
|
mPresenter.deleteTab(mTabsManager.indexOfCurrentTab());
|
||||||
case KeyEvent.KEYCODE_R:
|
return true;
|
||||||
// Refresh current tab
|
case KeyEvent.KEYCODE_Q:
|
||||||
LightningView currentTab = mTabsManager.getCurrentTab();
|
// Close browser
|
||||||
if (currentTab != null) {
|
closeBrowser();
|
||||||
currentTab.reload();
|
return true;
|
||||||
}
|
case KeyEvent.KEYCODE_R:
|
||||||
return true;
|
// Refresh current tab
|
||||||
case KeyEvent.KEYCODE_TAB:
|
LightningView currentTab = mTabsManager.getCurrentTab();
|
||||||
int nextIndex = 0;
|
if (currentTab != null) {
|
||||||
if (event.isShiftPressed()) {
|
currentTab.reload();
|
||||||
// Go back one tab
|
|
||||||
if (mTabsManager.indexOfCurrentTab() > 0) {
|
|
||||||
nextIndex = mTabsManager.indexOfCurrentTab() - 1;
|
|
||||||
} else {
|
|
||||||
nextIndex = mTabsManager.last();
|
|
||||||
}
|
}
|
||||||
|
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.getKeyCode() == KeyEvent.KEYCODE_SEARCH) {
|
||||||
|
// Highlight search field
|
||||||
|
mSearch.requestFocus();
|
||||||
|
mSearch.selectAll();
|
||||||
|
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 {
|
} else {
|
||||||
// Go forward one tab
|
nextIndex = event.getKeyCode() - KeyEvent.KEYCODE_1;
|
||||||
if (mTabsManager.indexOfCurrentTab() < mTabsManager.last()) {
|
|
||||||
nextIndex = mTabsManager.indexOfCurrentTab() + 1;
|
|
||||||
} else {
|
|
||||||
nextIndex = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
mPresenter.tabChanged(nextIndex);
|
mPresenter.tabChanged(nextIndex);
|
||||||
return true;
|
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);
|
return super.dispatchKeyEvent(event);
|
||||||
}
|
}
|
||||||
|
@ -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…
x
Reference in New Issue
Block a user