Search in sources :

Example 11 with WebChromeClient

use of android.webkit.WebChromeClient in project UltimateAndroid by cymcsg.

the class WebViewActivity method initWebView.

private void initWebView() {
    mWebView.setWebViewClient(new WebViewClient());
    mWebView.setWebChromeClient(new WebChromeClient());
    WebSettings settings = mWebView.getSettings();
    settings.setSavePassword(true);
    settings.setSaveFormData(true);
    settings.setJavaScriptEnabled(true);
    settings.setSupportZoom(false);
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    settings.setDomStorageEnabled(true);
    settings.setSupportMultipleWindows(false);
    mWebView.loadUrl("http://developer.android.com");
}
Also used : WebSettings(android.webkit.WebSettings) WebChromeClient(android.webkit.WebChromeClient) WebViewClient(android.webkit.WebViewClient)

Example 12 with WebChromeClient

use of android.webkit.WebChromeClient in project weex-example by KalicyZhou.

the class WXWebViewTest method testLoadUrl.

@Test
public void testLoadUrl() throws Exception {
    String url = "http://www.taobao.com";
    view.loadUrl(url);
    WebViewClient client = shadow.getWebViewClient();
    client.onPageStarted(webView, url, null);
    client.onPageFinished(webView, url);
    WebChromeClient chromeClient = shadow.getWebChromeClient();
    chromeClient.onProgressChanged(webView, 10);
    chromeClient.onProgressChanged(webView, 100);
    chromeClient.onReceivedTitle(webView, "test");
}
Also used : WebChromeClient(android.webkit.WebChromeClient) WebViewClient(android.webkit.WebViewClient) Test(org.junit.Test)

Example 13 with WebChromeClient

use of android.webkit.WebChromeClient in project weex-example by KalicyZhou.

the class WXWebView method initWebView.

private void initWebView(WebView wv) {
    WebSettings settings = wv.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setAppCacheEnabled(true);
    settings.setUseWideViewPort(true);
    settings.setDomStorageEnabled(true);
    settings.setSupportZoom(false);
    settings.setBuiltInZoomControls(false);
    wv.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            WXLogUtils.v("tag", "onPageOverride " + url);
            return true;
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            WXLogUtils.v("tag", "onPageStarted " + url);
            if (mOnPageListener != null) {
                mOnPageListener.onPageStart(url);
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            WXLogUtils.v("tag", "onPageFinished " + url);
            if (mOnPageListener != null) {
                mOnPageListener.onPageFinish(url, view.canGoBack(), view.canGoForward());
            }
        }

        @Override
        public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
            super.onReceivedError(view, request, error);
            if (mOnErrorListener != null) {
                //mOnErrorListener.onError("error", "page error code:" + error.getErrorCode() + ", desc:" + error.getDescription() + ", url:" + request.getUrl());
                mOnErrorListener.onError("error", "page error");
            }
        }

        @Override
        public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
            super.onReceivedHttpError(view, request, errorResponse);
            if (mOnErrorListener != null) {
                mOnErrorListener.onError("error", "http error");
            }
        }

        @Override
        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
            super.onReceivedSslError(view, handler, error);
            if (mOnErrorListener != null) {
                mOnErrorListener.onError("error", "ssl error");
            }
        }
    });
    wv.setWebChromeClient(new WebChromeClient() {

        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            showWebView(newProgress == 100);
            showProgressBar(newProgress != 100);
            WXLogUtils.v("tag", "onPageProgressChanged " + newProgress);
        }

        @Override
        public void onReceivedTitle(WebView view, String title) {
            super.onReceivedTitle(view, title);
            if (mOnPageListener != null) {
                mOnPageListener.onReceivedTitle(view.getTitle());
            }
        }
    });
}
Also used : SslErrorHandler(android.webkit.SslErrorHandler) WebResourceRequest(android.webkit.WebResourceRequest) SslError(android.net.http.SslError) Bitmap(android.graphics.Bitmap) WebResourceResponse(android.webkit.WebResourceResponse) WebSettings(android.webkit.WebSettings) WebChromeClient(android.webkit.WebChromeClient) WebResourceError(android.webkit.WebResourceError) WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient)

Example 14 with WebChromeClient

use of android.webkit.WebChromeClient in project Diaspora-Webclient by voidcode.

the class MainActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (isNetworkAvailable()) {
        // load main domain�s rooturl
        SharedPreferences preferences = getSharedPreferences(SETTINGS_FILENAME, MODE_PRIVATE);
        this.main_domain = preferences.getString("currentpod", "");
        // set the home screen
        setContentView(R.layout.main);
        mWeb = (WebView) findViewById(R.id.webView_main);
        //--------------------------------------------------------------------------//
        //start up the webbrowser------------------------------------------------START
        //--------------------------------------------------------------------------//
        WebSettings settings = mWeb.getSettings();
        // set Javascript
        settings.setJavaScriptEnabled(true);
        //settings.setRenderPriority(RenderPriority.HIGH);
        settings.setCacheMode(WebSettings.LOAD_NORMAL);
        // adds JSInterface class to webview
        if (userHasEnableTranslate()) {
            mWeb.addJavascriptInterface(new JSInterface(), "jsinterface");
        }
        //fix to bug 2: cannot reshare
        //see: https://github.com/voidcode/Diaspora-Webclient/issues/2
        mWeb.setWebChromeClient(new WebChromeClient() {

            public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
                return super.onJsAlert(view, url, message, result);
            }
        });
        mWeb.setWebViewClient(new WebViewClient() {

            private String googleapikey;

            private String defaultlanguage;

            private Matcher matcher;

            private Pattern pattern = Pattern.compile("^(https?)://" + main_domain + "[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]");

            // load url
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                //this see if the user is trying to open a internel or externel link
                if (//if internel(on main_domain) eks: joindiaspora.com
                pattern.matcher(url).matches()) {
                    view.loadUrl(url);
                    return true;
                } else // if user try to open a externel link, then open it in the default webbrowser.
                {
                    Intent i = new Intent(Intent.ACTION_VIEW);
                    i.setData(Uri.parse(url));
                    startActivity(i);
                    return true;
                }
            }

            public void onPageFinished(WebView view, String url) {
                // when finish loading page
                if (mProgress.isShowing()) {
                    mProgress.dismiss();
                } else {
                    if (//adds translate link to all post
                    userHasEnableTranslate()) {
                        SharedPreferences preferences = getSharedPreferences(TRANSLATE_FILENAME, MODE_PRIVATE);
                        this.googleapikey = preferences.getString("googleapikey", "microsoft-translator");
                        //default-language=english
                        this.defaultlanguage = preferences.getString("defaultlanguage", "en");
                        //Inject google translate link via javascript into all posts
                        mWeb.loadUrl("javascript:(function() { " + //get variables			        	    			"var i=0; "+
                        "var ltrs=document.getElementsByClassName('ltr'); " + //loop: adds translate buttons to all 'ltr' tags
                        "for(i=0;i<ltrs.length;i++) " + "{" + //makes new div
                        "var btn = document.createElement('div'); " + //retrive select post
                        "var selectpost = encodeURIComponent(ltrs.item(i).innerHTML); " + //"var selectpost = 'google is a search '; "+
                        "btn.setAttribute('onclick','alert(window.jsinterface.Translate( \"" + main_domain + "\",  \"" + this.googleapikey + "\", \"" + this.defaultlanguage + //adds onclick-handler
                        "\", \"'+selectpost+'\" ));'); " + //adds style
                        "btn.setAttribute('style','margin:15px 0px 15px 0px;'); " + //adds id
                        "btn.id='btn_translate_id_'+i; " + //title on link.
                        "btn.innerHTML='Translate this post'; " + //append new button to post '.ltr'
                        "ltrs.item(i).appendChild(btn); " + "} " + "})()");
                    }
                }
            }
        });
        //then open SettingsActivity
        if (this.main_domain.equals("")) {
            startActivity(new Intent(this, PodSettingsActivity.class));
        } else {
            mProgress = ProgressDialog.show(this, "Stream", "Please wait a moment...");
            //goto start or logon pages
            this.mWeb.loadUrl("https://" + main_domain + "/stream");
            // goto users stream
            Toast.makeText(this, "Pod: " + main_domain, Toast.LENGTH_SHORT).show();
        }
    } else {
        // if user don�t have internet
        this.finish();
        startActivity(new Intent(this, SetupInternetActivity.class));
    }
}
Also used : Pattern(java.util.regex.Pattern) SharedPreferences(android.content.SharedPreferences) Matcher(java.util.regex.Matcher) Intent(android.content.Intent) JsResult(android.webkit.JsResult) WebSettings(android.webkit.WebSettings) WebChromeClient(android.webkit.WebChromeClient) WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient)

Example 15 with WebChromeClient

use of android.webkit.WebChromeClient in project wire-android by wireapp.

the class InAppWebViewFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup viewGroup, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_in_app_web_view, viewGroup, false);
    webView = ViewUtils.getView(view, R.id.wv__inapp);
    if (getArguments() == null || !getArguments().containsKey(ARG_URL_TO_BE_OPENED)) {
        throw new RuntimeException("InAppWebViewFragment can only be opened via newInstance(url");
    }
    webView.setWebViewClient(new WebViewClient());
    webView.setWebChromeClient(new WebChromeClient());
    webView.loadUrl(getArguments().getString(ARG_URL_TO_BE_OPENED));
    View closeButton = ViewUtils.getView(view, R.id.gtv__inapp__close);
    if (getArguments().getBoolean(ARG_WITH_CLOSE_BUTTON)) {
        closeButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                getContainer().dismissInAppWebView();
            }
        });
    } else {
        closeButton.setVisibility(View.GONE);
    }
    return view;
}
Also used : WebChromeClient(android.webkit.WebChromeClient) View(android.view.View) WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient)

Aggregations

WebChromeClient (android.webkit.WebChromeClient)45 WebView (android.webkit.WebView)38 WebViewClient (android.webkit.WebViewClient)32 WebSettings (android.webkit.WebSettings)15 View (android.view.View)14 Bitmap (android.graphics.Bitmap)10 WebResourceRequest (android.webkit.WebResourceRequest)8 JsResult (android.webkit.JsResult)7 SuppressLint (android.annotation.SuppressLint)6 Intent (android.content.Intent)6 WebResourceError (android.webkit.WebResourceError)6 LinearLayout (android.widget.LinearLayout)5 Uri (android.net.Uri)4 KeyEvent (android.view.KeyEvent)4 ConsoleMessage (android.webkit.ConsoleMessage)4 JsPromptResult (android.webkit.JsPromptResult)4 WebResourceResponse (android.webkit.WebResourceResponse)4 TextView (android.widget.TextView)3 InjectView (butterknife.InjectView)3 SharedPreferences (android.content.SharedPreferences)2