Search in sources :

Example 1 with MyWebViewClient

use of net.iGap.libs.MyWebViewClient in project iGap-Android by KianIranian-STDG.

the class FragmentChat method openWebViewForSpecialUrlChat.

private void openWebViewForSpecialUrlChat(String mUrl) {
    try {
        setDownBtnGone();
    } catch (NullPointerException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (botInit != null)
        botInit.close();
    /*   StructWebView urlWebView = getUrlWebView(mUrl);
        if (urlWebView == null) {
            return;
        } else {

            urlWebViewForSpecialUrlChat = urlWebView.getUrl();
        }
        */
    urlWebViewForSpecialUrlChat = mUrl;
    if (rootWebView == null)
        rootWebView = rootView.findViewById(R.id.rootWebView);
    if (progressWebView == null)
        progressWebView = rootView.findViewById(R.id.progressWebView);
    if (webViewChatPage == null) {
        try {
            webViewChatPage = new WebView(getContext());
            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
            params.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
            params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
            params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
            rootWebView.addView(webViewChatPage, params);
        // webViewChatPage = rootView.findViewById(R.id.webViewChatPage);
        } catch (Exception e) {
            return;
        }
    }
    recyclerView.setVisibility(View.GONE);
    viewAttachFile.setVisibility(View.GONE);
    rootWebView.setVisibility(View.VISIBLE);
    webViewChatPage.getSettings().setLoadsImagesAutomatically(true);
    webViewChatPage.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    webViewChatPage.clearCache(true);
    webViewChatPage.clearHistory();
    webViewChatPage.clearView();
    webViewChatPage.clearFormData();
    webViewChatPage.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    webViewChatPage.getSettings().setJavaScriptEnabled(true);
    webViewChatPage.getSettings().setDomStorageEnabled(true);
    progressWebView.setVisibility(View.VISIBLE);
    webViewChatPage.setWebChromeClient(new WebChromeClient() {

        @Override
        public void onProgressChanged(WebView view, int progress) {
            if (progress == 100) {
                progressWebView.setVisibility(View.GONE);
            } else {
                progressWebView.setVisibility(View.VISIBLE);
            }
        }
    });
    webViewChatPage.setWebViewClient(new MyWebViewClient() {

        @Override
        protected void onReceivedError(WebView webView, String url, int errorCode, String description) {
        }

        @Override
        protected boolean handleUri(WebView webView, Uri uri) {
            final String host = uri.getHost();
            final String scheme = uri.getScheme();
            // startActivity(intent);
            return false;
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            if (url.toLowerCase().equals("igap://close")) {
                makeWebViewGone();
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
        }
    });
    webViewChatPage.loadUrl(urlWebViewForSpecialUrlChat);
}
Also used : RealmString(net.iGap.realm.RealmString) HelperString(net.iGap.helper.HelperString) AttachFile.getFilePathFromUri(net.iGap.module.AttachFile.getFilePathFromUri) Uri(android.net.Uri) IOException(java.io.IOException) JsonSyntaxException(com.google.gson.JsonSyntaxException) SuppressLint(android.annotation.SuppressLint) ParamWithInitBitmap(net.iGap.helper.avatar.ParamWithInitBitmap) Bitmap(android.graphics.Bitmap) MyWebViewClient(net.iGap.libs.MyWebViewClient) WebChromeClient(android.webkit.WebChromeClient) RelativeLayout(android.widget.RelativeLayout) StructWebView(net.iGap.module.structs.StructWebView) WebView(android.webkit.WebView)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 Bitmap (android.graphics.Bitmap)1 Uri (android.net.Uri)1 WebChromeClient (android.webkit.WebChromeClient)1 WebView (android.webkit.WebView)1 RelativeLayout (android.widget.RelativeLayout)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 IOException (java.io.IOException)1 HelperString (net.iGap.helper.HelperString)1 ParamWithInitBitmap (net.iGap.helper.avatar.ParamWithInitBitmap)1 MyWebViewClient (net.iGap.libs.MyWebViewClient)1 AttachFile.getFilePathFromUri (net.iGap.module.AttachFile.getFilePathFromUri)1 StructWebView (net.iGap.module.structs.StructWebView)1 RealmString (net.iGap.realm.RealmString)1