use of de.baumann.browser.View.SwipeTouchListener in project browser by scoute-dich.
the class BrowserActivity method initOmnibox.
private void initOmnibox() {
omnibox = findViewById(R.id.main_omnibox);
inputBox = findViewById(R.id.main_omnibox_input);
omniboxRefresh = findViewById(R.id.omnibox_refresh);
omniboxOverflow = findViewById(R.id.omnibox_overflow);
omniboxTitle = findViewById(R.id.omnibox_title);
progressBar = findViewById(R.id.main_progress_bar);
int fab_position = Integer.parseInt(sp.getString("nav_position", "0"));
switch(fab_position) {
case 0:
fab_imageButtonNav = findViewById(R.id.fab_imageButtonNav_right);
break;
case 1:
fab_imageButtonNav = findViewById(R.id.fab_imageButtonNav_left);
break;
case 2:
fab_imageButtonNav = findViewById(R.id.fab_imageButtonNav_center);
break;
default:
fab_imageButtonNav = findViewById(R.id.fab_imageButtonNav_right);
break;
}
fab_imageButtonNav.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (currentAlbumController instanceof NinjaWebView) {
showSwitcher();
}
return false;
}
});
fab_imageButtonNav.setOnClickListener(this);
fab_imageButtonNav.setOnTouchListener(new SwipeTouchListener(BrowserActivity.this) {
public void onSwipeTop() {
ninjaWebView = (NinjaWebView) currentAlbumController;
ninjaWebView.pageUp(true);
}
public void onSwipeBottom() {
ninjaWebView = (NinjaWebView) currentAlbumController;
ninjaWebView.pageDown(true);
}
public void onSwipeRight() {
ninjaWebView = (NinjaWebView) currentAlbumController;
if (ninjaWebView.canGoForward()) {
ninjaWebView.goForward();
} else {
NinjaToast.show(BrowserActivity.this, R.string.toast_webview_forward);
}
}
public void onSwipeLeft() {
if (ninjaWebView.canGoBack()) {
ninjaWebView.goBack();
} else {
removeAlbum(currentAlbumController);
}
}
});
inputBox.setOnTouchListener(new SwipeToBoundListener(omnibox, new SwipeToBoundListener.BoundCallback() {
private final KeyListener keyListener = inputBox.getKeyListener();
@Override
public boolean canSwipe() {
boolean ob = sp.getBoolean(getString(R.string.sp_omnibox_control), true);
return switcherPanel.isKeyBoardShowing() && ob;
}
@Override
public void onSwipe() {
inputBox.setKeyListener(null);
inputBox.setFocusable(false);
inputBox.setFocusableInTouchMode(false);
inputBox.clearFocus();
}
@Override
public void onBound(boolean canSwitch, boolean left) {
inputBox.setKeyListener(keyListener);
inputBox.setFocusable(true);
inputBox.setFocusableInTouchMode(true);
inputBox.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
inputBox.clearFocus();
if (canSwitch) {
AlbumController controller = nextAlbumController(left);
showAlbum(controller, false);
}
}
}));
inputBox.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (currentAlbumController == null) {
// || !(actionId == EditorInfo.IME_ACTION_DONE)
return false;
}
String query = inputBox.getText().toString().trim();
if (query.isEmpty()) {
NinjaToast.show(BrowserActivity.this, getString(R.string.toast_input_empty));
return true;
}
updateAlbum(query);
hideSoftInput(inputBox);
return false;
}
});
updateBookmarks();
updateAutoComplete();
omniboxRefresh.setOnClickListener(this);
omniboxOverflow.setOnClickListener(this);
omniboxOverflow.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (currentAlbumController != null && currentAlbumController instanceof NinjaWebView) {
showSwitcher();
}
return false;
}
});
}
Aggregations