Example usage for android.app Activity setProgress

List of usage examples for android.app Activity setProgress

Introduction

In this page you can find the example usage for android.app Activity setProgress.

Prototype

@Deprecated
public final void setProgress(int progress) 

Source Link

Document

Sets the progress for the progress bars in the title.

Usage

From source file:com.anxpp.blog.fragment.AboutFragment.java

@SuppressLint("SetJavaScriptEnabled")
private void initView() {
    webView = (WebView) getView().findViewById(R.id.webView);
    //      webView.setVisibility(View.GONE);
    webView.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress) {
            Activity activity = getActivity();
            /**/*from w ww . ja  v  a 2s.co  m*/
             * ?Fragment???
             * I am not sure why are you getting this error, 
             * i think it should be something like NullPointerException. 
             * Try next: 
             *     Evert time you calling getActivity() on Fragment instance you should be sure,
             *     that fragment is actually have this Activity. 
             *     Because when your webview is loading you are calling this function:
             * */
            if (activity == null)
                return;
            activity.setTitle("Loading..." + progress + "%");
            activity.setProgress(progress * 100);
            if (progress == 100) {
                activity.setTitle(R.string.app_name);
                webView.setVisibility(View.VISIBLE);
            }
        }
    });
    webView.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Toast("shouldOverrideUrlLoading");
            view.loadUrl(url);
            return true;
        }
    });
    //??
    WebSettings webSettings = webView.getSettings();
    //?
    //webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    //?js
    webSettings.setJavaScriptEnabled(true);
    //? ?
    webSettings.setUseWideViewPort(false); //??
    webSettings.setLoadWithOverviewMode(true); // ??
    webView.loadUrl("http://anxpp.com");
    //
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            //trueWebViewfalse??
            view.loadUrl(url);
            return true; //false?
        }
    });
    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;
        }
    });
}

From source file:com.safecell.LoginActivity.java

void dialogforWebview() {

    AlertDialog.Builder builder;//from  w  ww .  j  a v  a  2s.  c o  m

    Context mContext = LoginActivity.this;

    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.private_policy_layout, (ViewGroup) findViewById(R.id.layout_root));

    final Activity activity = LoginActivity.this;
    wv = (WebView) layout.findViewById(R.id.webview);

    wv.getSettings().setJavaScriptEnabled(true);
    wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);

    wv.setWebViewClient(new HelloWebViewClient());
    wv.setWebChromeClient(new WebChromeClient() {

        public void onProgressChanged(WebView view, int newProgress) {
            activity.setProgress(newProgress * 100);

            if (newProgress == 100) {

            }
        };
    });

    wv.setWebViewClient(new WebViewClient() {
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            // Log.v("errorCode", "errorcode "+errorCode + description);
            alertDialogForTermsConditions.cancel();

        }
    });
    // wv.loadUrl(URLs.REMOTE_URL +
    // "api/1/site_setting/terms_of_service.html");
    wv.loadUrl("file:///android_asset/terms_of_service.html");
    builder = new AlertDialog.Builder(mContext);
    builder.setView(layout);
    builder.setTitle("Policy");

    builder.setPositiveButton("Accept", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            isTermsAcepted = true;
            dialog.cancel();
        }
    }).setNegativeButton("Don't Accept", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            isTermsAcepted = false;
            dialog.cancel();
            quitDialog("License", "Terms and conditions should accept. ");
        }
    });
    alertDialogForTermsConditions = builder.create();
    if (progressDialog != null && progressDialog.isShowing()) {
        progressDialog.dismiss();
    }
    try {
        alertDialogForTermsConditions.show();
    } catch (Exception e) {
        e.printStackTrace();
    }
}