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:com.jiandanbaoxian.fragment.DialogFragmentCreater.java

/**
 * Dialog ???/*ww w. ja  v  a 2s .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;
}

From source file:com.purchasingpower.inappbrowser.WebViewActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //setContentView(R.layout.activity_main);
    setContentView(getResources().getIdentifier("nativebrowserplugin", "layout", getPackageName()));
    if (!checkPermission()) {
        requestPermission();//  w  w w . j  av  a2s.  com
    }
    Intent intent = getIntent();
    String url = intent.getExtras().getString("url");
    final WebView myWebView = (WebView) findViewById(
            getResources().getIdentifier("webview", "id", getPackageName()));
    myWebView.setWebViewClient(new MyWebViewClient());

    webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setAllowFileAccess(true);
    myWebView.setWebChromeClient(new PQChromeClient());
    //if SDK version is greater of 19 then activate hardware acceleration otherwise activate software acceleration
    if (Build.VERSION.SDK_INT >= 19) {
        myWebView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    } else if (Build.VERSION.SDK_INT >= 11 && Build.VERSION.SDK_INT < 19) {
        myWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }

    myWebView.loadUrl(url);

    back = (ImageView) findViewById(getResources().getIdentifier("back", "id", getPackageName()));
    back.setImageResource(getResources().getIdentifier("back_gray", "drawable", getPackageName()));
    forward = (ImageView) findViewById(getResources().getIdentifier("forward", "id", getPackageName()));
    forward.setImageResource(getResources().getIdentifier("forward_gray", "drawable", getPackageName()));
    done = (TextView) findViewById(getResources().getIdentifier("done", "id", getPackageName()));
    pbar = (ProgressBar) findViewById(getResources().getIdentifier("pbar", "id", getPackageName()));
    pbar.setVisibility(View.VISIBLE);
    back.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (myWebView.canGoBack()) {
                myWebView.goBack();
            }
        }
    });
    forward.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (myWebView.canGoForward()) {
                myWebView.goForward();
            }
        }
    });
    done.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.v("Done", "Clicked");
            finish();
        }
    });
}