List of usage examples for android.webkit WebView goBack
public void goBack()
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(); } else { Snackbar.make(webView, R.string.toast_back, Snackbar.LENGTH_SHORT).show(); }/*from w w w .java 2 s .co m*/ } 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 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(); } 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();/*w ww.j a v a2 s . c om*/ } 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.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/*www .j a v a 2 s .c om*/ 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.cliff.comichelper.MainActivity.java
@Override public void onBackPressed() { WebView webView = currentFragment.getWebView(); if (webView.canGoBack()) webView.goBack(); else/*from ww w. j ava 2s .c o m*/ super.onBackPressed(); }
From source file:com.facebook.react.views.webview.ReactWebViewManager.java
@Override public void receiveCommand(WebView root, int commandId, @Nullable ReadableArray args) { switch (commandId) { case COMMAND_GO_BACK: root.goBack(); break;//ww w . j a va 2 s.c o m case COMMAND_GO_FORWARD: root.goForward(); break; case COMMAND_RELOAD: root.reload(); break; case COMMAND_STOP_LOADING: root.stopLoading(); break; case COMMAND_POST_MESSAGE: try { JSONObject eventInitDict = new JSONObject(); eventInitDict.put("data", args.getString(0)); root.loadUrl("javascript:(function () {" + "var event;" + "var data = " + eventInitDict.toString() + ";" + "try {" + "event = new MessageEvent('message', data);" + "} catch (e) {" + "event = document.createEvent('MessageEvent');" + "event.initMessageEvent('message', true, true, data.data, data.origin, data.lastEventId, data.source);" + "}" + "document.dispatchEvent(event);" + "})();"); } catch (JSONException e) { throw new RuntimeException(e); } break; case COMMAND_INJECT_JAVASCRIPT: root.loadUrl("javascript:" + args.getString(0)); break; } }
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. *//* www. j av a 2s . 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 ww . j a va 2 s .c om*/ @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 {//from ww w . java 2s . c om // 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(); } } }
From source file:com.jiandanbaoxian.fragment.DialogFragmentCreater.java
/** * Dialog ???/*from w ww . j a v a 2 s. c o m*/ * @param mContext * @return */ private Dialog showLicenseChoiceDialog(final Context mContext) { View convertView = LayoutInflater.from(mContext).inflate(R.layout.dialog_license_choice, null); final Dialog dialog = new Dialog(mContext, R.style.mystyle); View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View v) { switch (v.getId()) { case R.id.layout_rule: if (isAgree) { isAgree = false; ImageView imageView = (ImageView) v.findViewById(R.id.iv_choose); // TextView textView = (TextView)v.findViewById(R.id.tv_rule); imageView.setImageResource(R.drawable.icon_choose); // textView.setBackgroundColor(getResources().getColor(R.color.bg_gray_color_level_0)); // textView.setTextColor(getResources().getColor(R.color.tv_gray_color_level_3)); } else { isAgree = true; ImageView imageView = (ImageView) v.findViewById(R.id.iv_choose); // TextView textView = (TextView)v.findViewById(R.id.tv_rule); imageView.setImageResource(R.drawable.icon_choose_selected); // textView.setBackgroundResource(R.drawable.btn_select_base_shape_0); // textView.setTextColor(getResources().getColor(R.color.white_color)); } break; } if (onLicenseDialogClickListener != null) { onLicenseDialogClickListener.onClick(v, isAgree); } } }; TitleBar titleBar; SwipeRefreshLayout swipeLayout; final WebView webView; ProgressBar progressBar; LinearLayout layoutRule; LinearLayout layoutConfirm; titleBar = (TitleBar) convertView.findViewById(R.id.title_bar); swipeLayout = (SwipeRefreshLayout) convertView.findViewById(R.id.swipe_layout); webView = (WebView) convertView.findViewById(R.id.webView); progressBar = (ProgressBar) convertView.findViewById(R.id.progress_bar); layoutRule = (LinearLayout) convertView.findViewById(R.id.layout_rule); layoutConfirm = (LinearLayout) convertView.findViewById(R.id.layout_confirm); WebChromeClient client = new AppChromeWebClient(titleBar, progressBar, swipeLayout); webView.setWebChromeClient(client); webView.setWebViewClient(new AppWebClient()); webView.getSettings().setJavaScriptEnabled(true); webView.loadUrl(webViewURL); webView.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) { webView.goBack(); //? return true; //? } } return false; } }); titleBar.initTitleBarInfo("", R.drawable.arrow_left, -1, "", ""); titleBar.setOnTitleBarClickListener(new TitleBar.OnTitleBarClickListener() { @Override public void onLeftButtonClick(View v) { if (webView.canGoBack()) { webView.goBack(); //? return; //? } if (onLicenseDialogClickListener != null) { onLicenseDialogClickListener.onClick(v, isAgree); dismiss(); } } @Override public void onRightButtonClick(View v) { } }); UIUtils.initSwipeRefreshLayout(swipeLayout); swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { webView.reload(); } }); layoutConfirm.setOnClickListener(listener); layoutRule.setOnClickListener(listener); dialog.setContentView(convertView); dialog.getWindow().setWindowAnimations(R.style.dialog_right_control_style); return dialog; }