Example usage for android.webkit WebChromeClient WebChromeClient

List of usage examples for android.webkit WebChromeClient WebChromeClient

Introduction

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

Prototype

WebChromeClient

Source Link

Usage

From source file:Main.java

/**
 * <p>Configures basic settings of the webView (Javascript enabled, DOM storage enabled,
 * database enabled).</p>//from  w  ww .j  a va 2s .  c o  m
 *
 * @param webView The shared webView.
 */
@SuppressLint("SetJavaScriptEnabled")
private static void configureWebViewDefaults(WebView webView) {
    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setDomStorageEnabled(true);
    settings.setDatabaseEnabled(true);

    webView.setWebChromeClient(new WebChromeClient());
}

From source file:jupiter.broadcasting.live.holo.ShowNotesView.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    Bundle b = getArguments();//from  w  w w . j ava 2 s  . c o  m
    link = b.getString("Notes");
    v = inflater.inflate(R.layout.shownotes_fragment, null);
    wv = (WebView) v.findViewById(R.id.notesview);
    loadingProgressBar = (ProgressBar) v.findViewById(R.id.progressbar_Horizontal);
    wv.getSettings().setJavaScriptEnabled(true);
    wv.setVisibility(View.INVISIBLE);
    wv.setWebChromeClient(new WebChromeClient() {

        // this will be called on page loading progress
        @Override
        public void onProgressChanged(WebView view, int newProgress) {

            super.onProgressChanged(view, newProgress);

            loadingProgressBar.setProgress(newProgress);

            // hide the progress bar if the loading is complete
            if (newProgress == 100) {
                loadingProgressBar.setVisibility(View.GONE);
            } else {
                loadingProgressBar.setVisibility(View.VISIBLE);
            }
        }

    });

    wv.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            wv.loadUrl("javascript:(function() {var mon = document.getElementsByTagName('div');"
                    + "for (var i = 0; i < mon.length; i++) {"
                    + "if (mon[i].id == 'footer'){mon[i].style.display = 'none';}"
                    + "if (mon[i].id == 'header'){mon[i].style.display = 'none';}"
                    + "if (mon[i].id == 'thevideo'){mon[i].style.display = 'none';}"
                    + "if (mon[i].id == 'sidebar'){mon[i].style.display = 'none';}"
                    + "if (mon[i].id == 'menubar'){mon[i].style.display = 'none';}"
                    + "if (mon[i].id == 'videodets'){mon[i].style.display = 'none';}"
                    + "if (mon[i].id == 'postcomments'){mon[i].style.display = 'none';}" + "}})()");
            wv.loadUrl("javascript: window.CallToAnAndroidFunction.setVisible()");
        }
    });
    wv.addJavascriptInterface(new myJavaScriptInterface(), "CallToAnAndroidFunction");
    wv.loadUrl(link);

    return v;
}

From source file:org.h4des.alertrmobilemanager.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    this.webView = (WebView) findViewById(R.id.webView);

    // clear cache
    this.webView.clearCache(true);

    // enable JavaScript
    this.webView.getSettings().setJavaScriptEnabled(true);

    this.webView.setWebChromeClient(new WebChromeClient());

    // create own WebViewClient
    this.webView.setWebViewClient(new WebViewClient() {

        // for debugging in the emulator only
        // install your own certificate on the android device via copying your cert.cer
        // on the sd card and add it in the security options
        //@Override
        //public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {            
        //    handler.proceed();
        //}/*from   w  w  w  .  j a va 2  s .  c o m*/

        // when using basic http authentication
        // enter your own credentials
        @Override
        public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host,
                String realm) {

            // get username and password from the settings
            SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
            String username = preferences.getString("username", "None");
            String password = preferences.getString("password", "None");

            // use credentials from the settings
            handler.proceed(username, password);
        }
    });

    // get URL from the settings
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
    String url = preferences.getString("url", "None");

    this.webView.loadUrl(url);

    // focus webView
    this.webView.requestFocus(View.FOCUS_DOWN);
}

From source file:com.jio.mhood.services.api.settings.LicensesFragment.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override/* w  w w .  j  a va2  s  . co m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup view = (ViewGroup) inflater.inflate(R.layout.fragment_licenses, container, false);

    if (mWebView == null) {
        mWebView = new WebView(view.getContext());
        mWebView.setLayoutParams(
                new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        mWebView.setWebChromeClient(new WebChromeClient());
        mWebView.setBackgroundColor(0);

        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setDomStorageEnabled(true);
        webSettings.setPluginState(PluginState.ON_DEMAND);
        webSettings.setPluginState(PluginState.ON);
        webSettings.setBuiltInZoomControls(true);
        webSettings.setUseWideViewPort(true);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            webSettings.setDisplayZoomControls(false);
        }

        mWebView.loadUrl(URL);
    } else {
        mParent.removeView(mWebView);
    }
    mParent = view;
    mParent.addView(mWebView);

    return mParent;
}

From source file:com.prey.activities.PanelWebActivity.java

@Override
public void onResume() {
    super.onResume();
    WebSettings settings = myWebView.getSettings();
    settings.setUseWideViewPort(true);/*from ww w. ja v  a 2 s.  com*/
    settings.setLoadWithOverviewMode(true);
    settings.setJavaScriptEnabled(true);
    myWebView.setVerticalScrollBarEnabled(false);
    myWebView.setHorizontalScrollBarEnabled(false);
    myWebView.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress) {
            activity.setTitle("Loading...");
            activity.setProgress(progress * 100);

            if (progress == 100)
                activity.setTitle(R.string.app_name);
        }

    });
    myWebView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageFinished(WebView view, String url) {
            PreyLogger.d("Finished:" + url);
            super.onPageFinished(view, url);
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            PreyLogger.d("Started:" + url);
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            PreyLogger.d("OverrideUrl:" + url);
            return super.shouldOverrideUrlLoading(view, url);
        }
    });

    String url = PreyConfig.getPreyConfig(getApplicationContext()).getPreyPanelJwt();

    String postData = "token=" + PreyConfig.getPreyConfig(getApplicationContext()).getTokenJwt();
    ;

    byte[] postByte = EncodingUtils.getBytes(postData, "BASE64");
    myWebView.postUrl(url, postByte);
}

From source file:com.iangclifton.auid.appendixc.sections.LoadingIndicatorFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mWebView = new WebView(inflater.getContext());
    mWebView.setWebChromeClient(new WebChromeClient() {
        @Override/*ww w. ja va  2  s.c o m*/
        public void onProgressChanged(WebView view, int progress) {
            getActivity().setProgress(progress * 100);
        }
    });
    return mWebView;
}

From source file:com.sinelead.car.club.XinchepingFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    View v = inflater.inflate(R.layout.activity_content_xincheping, null);
    WebView webView = (WebView) v.findViewById(R.id.webView_xincheping);
    webView.setWebChromeClient(new WebChromeClient());

    webView.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);/*  www  . java 2  s . c om*/
            return true;
        }
    });

    webView.getSettings().setJavaScriptEnabled(true);

    webView.loadUrl("http://m.xincheping.com");
    return v;
}

From source file:me.jvdv.bancwear.BaseActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mWebView = (WebView) findViewById(R.id.webview);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setDomStorageEnabled(true);
    WebView.setWebContentsDebuggingEnabled(true);

    mWebView.setWebChromeClient(new WebChromeClient());
    mWebView.setWebViewClient(new WebViewClient());

    mRegistrationBroadcastReceiver = new BroadcastReceiver() {
        @Override//from   w  w w. j a v  a2 s  .c  o m
        public void onReceive(Context context, Intent intent) {
            SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
            boolean sentToken = sharedPreferences.getBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false);
            if (sentToken) {
                blaat(getString(R.string.gcm_send_message));
            } else {
                blaat(getString(R.string.token_error_message));
            }
        }
    };

    // Registering BroadcastReceiver
    registerReceiver();

    if (checkPlayServices()) {
        // Start IntentService to register this application with GCM.
        Intent intent = new Intent(this, RegistrationIntentService.class);
        startService(intent);
    }
}

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

@SuppressLint("SetJavaScriptEnabled")
@Override/*from   w ww.  ja  va 2  s  . c o m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View v = inflater.inflate(R.layout.webview, container, false);

    final ProgressBar viewContentProgress = (ProgressBar) v.findViewById(R.id.progress);
    viewContentWebView = (WebView) v.findViewById(R.id.webview);
    viewContentWebView.getSettings().setJavaScriptEnabled(true);
    viewContentWebView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return super.shouldOverrideUrlLoading(view, url);
        }
    });
    viewContentWebView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            viewContentProgress.setProgress(newProgress);
            viewContentProgress.setVisibility(newProgress == 100 ? View.GONE : View.VISIBLE);

            if (newProgress == 100 && resetHistory) {
                viewContentWebView.clearHistory();
                resetHistory = false;
            }
        }
    });
    return v;
}

From source file:com.autoparts.buyers.action_content.fragment.WebViewFragment.java

@SuppressLint("SetJavaScriptEnabled")
@Override//from   w  w w  . ja  va2  s  .  c  o  m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View v = inflater.inflate(R.layout.webview_fragment, container, false);

    final ProgressBar viewContentProgress = (ProgressBar) v.findViewById(R.id.progress);
    viewContentWebView = (WebView) v.findViewById(R.id.webview);
    viewContentWebView.getSettings().setJavaScriptEnabled(true);
    viewContentWebView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return super.shouldOverrideUrlLoading(view, url);
        }
    });
    viewContentWebView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            viewContentProgress.setProgress(newProgress);
            viewContentProgress.setVisibility(newProgress == 100 ? View.GONE : View.VISIBLE);

            if (newProgress == 100 && resetHistory) {
                viewContentWebView.clearHistory();
                resetHistory = false;
            }
        }
    });
    return v;
}