Search in sources :

Example 1 with SwipeToBoundListener

use of de.baumann.browser.View.SwipeToBoundListener 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;
        }
    });
}
Also used : SwipeToBoundListener(de.baumann.browser.View.SwipeToBoundListener) NinjaWebView(de.baumann.browser.View.NinjaWebView) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) NinjaWebView(de.baumann.browser.View.NinjaWebView) AutoCompleteTextView(android.widget.AutoCompleteTextView) DynamicGridView(org.askerov.dynamicgrid.DynamicGridView) View(android.view.View) AdapterView(android.widget.AdapterView) WebView(android.webkit.WebView) TextView(android.widget.TextView) ListView(android.widget.ListView) VideoView(android.widget.VideoView) Paint(android.graphics.Paint) KeyEvent(android.view.KeyEvent) SwipeTouchListener(de.baumann.browser.View.SwipeTouchListener) KeyListener(android.text.method.KeyListener) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) AlbumController(de.baumann.browser.Browser.AlbumController)

Aggregations

Paint (android.graphics.Paint)1 KeyListener (android.text.method.KeyListener)1 KeyEvent (android.view.KeyEvent)1 View (android.view.View)1 WebView (android.webkit.WebView)1 AdapterView (android.widget.AdapterView)1 AutoCompleteTextView (android.widget.AutoCompleteTextView)1 HorizontalScrollView (android.widget.HorizontalScrollView)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 VideoView (android.widget.VideoView)1 AlbumController (de.baumann.browser.Browser.AlbumController)1 NinjaWebView (de.baumann.browser.View.NinjaWebView)1 SwipeToBoundListener (de.baumann.browser.View.SwipeToBoundListener)1 SwipeTouchListener (de.baumann.browser.View.SwipeTouchListener)1 DynamicGridView (org.askerov.dynamicgrid.DynamicGridView)1