Example usage for android.webkit WebView canGoBack

List of usage examples for android.webkit WebView canGoBack

Introduction

In this page you can find the example usage for android.webkit WebView canGoBack.

Prototype

public boolean canGoBack() 

Source Link

Document

Gets whether this WebView has a back history item.

Usage

From source file:de.baumann.browser.helper.helper_webView.java

private static void webView_Touch(final Activity from, final WebView webView) {

    webView.setOnTouchListener(new class_OnSwipeTouchListener_webview(from) {
        public void onSwipeRight() {
            if (webView.canGoBack()) {
                webView.goBack();// w w w.j av  a 2  s.c o m
            } else {
                Snackbar.make(webView, R.string.toast_back, Snackbar.LENGTH_SHORT).show();
            }
        }

        public void onSwipeLeft() {
            if (webView.canGoForward()) {
                webView.goForward();
            } else {
                Snackbar.make(webView, R.string.toast_forward, Snackbar.LENGTH_SHORT).show();
            }
        }
    });
}

From source file:com.macleod2486.utnow.MainActivity.java

public void back(View view) {
    WebView utdirect = (WebView) findViewById(R.id.webView);
    if (utdirect.canGoBack())
        utdirect.goBack();/*from   w  w w  . j a va 2 s .c om*/
}

From source file:com.wordpress.jftreading.BaseFragmentWebView.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    fragmentView = inflater.inflate(R.layout.webview_fragment, container, false);
    browser = (WebView) fragmentView.findViewById(R.id.webkit);
    browser.getSettings().setJavaScriptEnabled(true);
    browser.setWebViewClient(new WebViewClient() {
        @Override//w w  w .j a v  a  2s  .c o  m
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (!networkIsUp() && !offlinePage) {
                view.loadUrl(getErrorPage());
                return true;
            }
            if (url.startsWith("http:") || url.startsWith("https:") || url.startsWith("file:")) {
                return false;
            }
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            startActivity(intent);
            return true;
        }
    });
    browser.setWebChromeClient(new WebChromeClient() {
        @Override
        public boolean onJsConfirm(WebView view, String url, String message, JsResult result) {
            return super.onJsConfirm(view, url, message, result);
        }
    });
    browser.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                WebView webView = (WebView) v;

                switch (keyCode) {
                case KeyEvent.KEYCODE_BACK:
                    if (webView.canGoBack()) {
                        webView.goBack();
                        return true;
                    }
                    break;
                }
            }
            return false;
        }
    });
    browser.setDownloadListener(new DownloadListener() {

        @Override
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype,
                long contentLength) {
            Uri uri = Uri.parse(url);
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(intent);
        }
    });
    browser.addJavascriptInterface(new MyJavascriptInterface(), "Android");
    browser.loadUrl(linkSelector());
    return fragmentView;
}

From source file:com.inha.stickyonpage.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (getSupportFragmentManager().findFragmentByTag("BrowsingWebView") != null) {
            if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT) || mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
                mDrawerLayout.closeDrawer(Gravity.RIGHT);
                mDrawerLayout.closeDrawer(Gravity.LEFT);
                return false;
            } else {
                WebView mWebView = (WebView) findViewById(R.id.webView1);
                if (mWebView.canGoBack()) {
                    mWebView.goBack();//from w  w w .j av a2s. co  m
                } else {
                    ActionBar mActionBar = getActionBar();
                    mActionBar.setCustomView(null);
                    mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME);
                    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
                    RecentStickyView stickyFragment = new RecentStickyView();
                    ft.replace(R.id.drawer_main, stickyFragment, "RecentStickyView");
                    ft.commit();
                }
                return false;
            }
        } else if (getSupportFragmentManager().getBackStackEntryCount() == 0) {
            if (!mFlag) {
                Toast.makeText(this, "''?  ?  ?.",
                        Toast.LENGTH_SHORT).show();
                mFlag = true;
                mHandler.sendEmptyMessageDelayed(0, 2000);
                return false;
            } else {
                finish();
            }
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.tfc.webviewer.presenter.WebViewPresenterImpl.java

@Override
public void onBackPressed(PopupWindow menu, WebView webView) {
    if (menu.isShowing()) {
        mView.closeMenu();/*from   w  ww. j av  a2  s.  com*/
    } else if (webView.canGoBack()) {
        mView.goBack();
    } else {
        mView.close();
    }
}

From source file:com.tomeokin.lspush.biz.home.CollectionWebViewActivity.java

@Override
protected void onPrepareWebView(WebView webView) {
    super.onPrepareWebView(webView);
    webView.setWebViewClient(new WebViewClient() {
        @Override/*w  w w.  j a v  a2s . co m*/
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            return false; // let the web view handle the url
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            boolean canGoBack = view.canGoBack();
            mBottomBar.backButton.setEnabled(canGoBack);
            mBottomBar.backButton
                    .setImageResource(canGoBack ? R.drawable.ic_action_back_deep : R.drawable.ic_action_back);

            boolean canGoForward = view.canGoForward();
            mBottomBar.forwardButton.setEnabled(canGoForward);
            mBottomBar.forwardButton.setImageResource(
                    canGoForward ? R.drawable.ic_action_forward_deep : R.drawable.ic_action_forward);
        }
    });
}

From source file:com.cliff.comichelper.MainActivity.java

@Override
public void onBackPressed() {
    WebView webView = currentFragment.getWebView();
    if (webView.canGoBack())
        webView.goBack();//from w  w w. j  av a  2s  . c  o  m
    else
        super.onBackPressed();
}

From source file:org.apache.cordova.AndroidWebViewClient.java

/**
 * Report an error to the host application. These errors are unrecoverable (i.e. the main resource is unavailable).
 * The errorCode parameter corresponds to one of the ERROR_* constants.
 *
 * @param view          The WebView that is initiating the callback.
 * @param errorCode     The error code corresponding to an ERROR_* value.
 * @param description   A String describing the error.
 * @param failingUrl    The url that failed to load.
 *///ww w.j av  a  2 s .co  m
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
    // Ignore error due to stopLoading().
    if (!isCurrentlyLoading) {
        return;
    }
    LOG.d(TAG, "CordovaWebViewClient.onReceivedError: Error code=%s Description=%s URL=%s", errorCode,
            description, failingUrl);

    // Clear timeout flag
    appView.loadUrlTimeout++;

    // If this is a "Protocol Not Supported" error, then revert to the previous
    // page. If there was no previous page, then punt. The application's config
    // is likely incorrect (start page set to sms: or something like that)
    if (errorCode == WebViewClient.ERROR_UNSUPPORTED_SCHEME) {
        if (view.canGoBack()) {
            view.goBack();
            return;
        } else {
            super.onReceivedError(view, errorCode, description, failingUrl);
        }
    }

    // Handle other errors by passing them to the webview in JS
    JSONObject data = new JSONObject();
    try {
        data.put("errorCode", errorCode);
        data.put("description", description);
        data.put("url", failingUrl);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    this.appView.getPluginManager().postMessage("onReceivedError", data);
}

From source file:org.apache.cordova.CordovaWebViewClient.java

/**
 * Report an error to the host application. These errors are unrecoverable (i.e. the main resource is unavailable).
 * The errorCode parameter corresponds to one of the ERROR_* constants.
 *
 * @param view          The WebView that is initiating the callback.
 * @param errorCode     The error code corresponding to an ERROR_* value.
 * @param description   A String describing the error.
 * @param failingUrl    The url that failed to load.
 *//*from  w w w.  j  av a 2 s  .  co m*/
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
    // Ignore error due to stopLoading().
    if (!isCurrentlyLoading) {
        return;
    }
    LOG.d(TAG, "CordovaWebViewClient.onReceivedError: Error code=%s Description=%s URL=%s", errorCode,
            description, failingUrl);

    // Clear timeout flag
    this.appView.loadUrlTimeout++;

    // If this is a "Protocol Not Supported" error, then revert to the previous
    // page. If there was no previous page, then punt. The application's config
    // is likely incorrect (start page set to sms: or something like that)
    if (errorCode == WebViewClient.ERROR_UNSUPPORTED_SCHEME) {
        if (view.canGoBack()) {
            view.goBack();
            return;
        } else {
            super.onReceivedError(view, errorCode, description, failingUrl);
        }
    }

    // Handle other errors by passing them to the webview in JS
    JSONObject data = new JSONObject();
    try {
        data.put("errorCode", errorCode);
        data.put("description", description);
        data.put("url", failingUrl);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    this.appView.postMessage("onReceivedError", data);
}

From source file:com.stoutner.privacybrowser.MainWebViewActivity.java

@Override
public void onBackPressed() {
    final WebView mainWebView = (WebView) findViewById(R.id.mainWebView);

    // Close the navigation drawer if it is available.  GravityCompat.START is the drawer on the left on Left-to-Right layout text.
    if (drawerLayout.isDrawerVisible(GravityCompat.START)) {
        drawerLayout.closeDrawer(GravityCompat.START);
    } else {/*  ww w . ja v a2  s  .c o  m*/
        // Load the previous URL if available.
        assert mainWebView != null; //This assert removes the incorrect warning on the following line that mainWebView might be null.
        if (mainWebView.canGoBack()) {
            mainWebView.goBack();
        } else {
            // Pass onBackPressed to the system.
            super.onBackPressed();
        }
    }
}