Search in sources :

Example 61 with WebSettings

use of android.webkit.WebSettings in project Tools-For-Android-Development by hatanvir.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    webView = findViewById(R.id.WebViewIdXml);
    webView.loadUrl("http://www.primeasia.edu.bd/");
    // javascript enable
    WebSettings webSettings = webView.getSettings();
    webSettings.getJavaScriptEnabled();
    // for visiting more page
    webView.setWebViewClient(new WebViewClient());
}
Also used : WebSettings(android.webkit.WebSettings) WebViewClient(android.webkit.WebViewClient)

Example 62 with WebSettings

use of android.webkit.WebSettings in project WanAndroid by dangxy.

the class DetailActivity method initView.

protected void initView() {
    url = getIntent().getStringExtra("url");
    WebSettings webSettings = wvUrl.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setAppCacheEnabled(true);
    webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    webSettings.setBuiltInZoomControls(false);
    webSettings.setJavaScriptEnabled(true);
    wvUrl.loadUrl(url);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolBar);
    toolbar.setTitle("");
    setSupportActionBar(toolbar);
    WebChromeClient webChromeClient = new WebChromeClient() {

        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            progressBar.setProgress(newProgress);
            if (newProgress == 100) {
                progressBar.setVisibility(View.INVISIBLE);
            } else {
                progressBar.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void onReceivedTitle(WebView view, String title) {
            super.onReceivedTitle(view, title);
            if (title.equals("")) {
                tvTitle.setText("详情");
            } else {
                tvTitle.setText(title);
            }
        }
    };
    wvUrl.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            wvUrl.loadUrl(url);
            return true;
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
        }
    });
    wvUrl.setWebChromeClient(webChromeClient);
}
Also used : Bitmap(android.graphics.Bitmap) WebSettings(android.webkit.WebSettings) WebChromeClient(android.webkit.WebChromeClient) WebView(android.webkit.WebView) Toolbar(android.support.v7.widget.Toolbar) WebViewClient(android.webkit.WebViewClient)

Example 63 with WebSettings

use of android.webkit.WebSettings in project AndroidLife by CaMnter.

the class JsResponseWebView method initWebView.

@SuppressLint("SetJavaScriptEnabled")
private void initWebView() {
    WebSettings settings = this.getSettings();
    settings.setJavaScriptEnabled(true);
    this.setWebViewClient(new JsResponseViewClient());
    this.javascript = "javascript:(function(){" + "   // 图片   " + "   var images = document.getElementsByTagName('img');" + "   for(var i=0;i<images.length;i++){" + "       images[i].onclick=function(){" + "           window." + INTERFACE_NAME + "." + ON_CLICK_PICTURE + "(images[i].src);" + "       }" + "   }" + "   // 标签   " + "   var tags = document.getElementsByClassName('video');" + "   for(var i=0;i<tags.length;i++){" + "       tags[i].onclick=function(){" + "           window." + INTERFACE_NAME + "." + ON_CLICK_TAG + "(tags[i].id,i);" + "       }" + "   }" + "})()";
}
Also used : WebSettings(android.webkit.WebSettings) SuppressLint(android.annotation.SuppressLint)

Example 64 with WebSettings

use of android.webkit.WebSettings in project Osmand by osmandapp.

the class AbstractCard method openUrl.

@SuppressLint("SetJavaScriptEnabled")
@SuppressWarnings("deprecation")
protected static void openUrl(@NonNull Context ctx, @NonNull OsmandApplication app, @Nullable String title, @NonNull String url, boolean externalLink, boolean hasImageUrl) {
    if (externalLink) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(url));
        ctx.startActivity(intent);
        return;
    }
    final Dialog dialog = new Dialog(ctx, app.getSettings().isLightContent() ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme);
    LinearLayout ll = new LinearLayout(ctx);
    ll.setOrientation(LinearLayout.VERTICAL);
    final Toolbar topBar = new Toolbar(ctx);
    topBar.setClickable(true);
    Drawable back = app.getIconsCache().getIcon(R.drawable.ic_action_remove_dark);
    topBar.setNavigationIcon(back);
    topBar.setNavigationContentDescription(R.string.shared_string_close);
    topBar.setTitle(title);
    topBar.setBackgroundColor(ContextCompat.getColor(ctx, getResIdFromAttribute(ctx, R.attr.pstsTabBackground)));
    topBar.setTitleTextColor(ContextCompat.getColor(ctx, getResIdFromAttribute(ctx, R.attr.pstsTextColor)));
    topBar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View v) {
            dialog.dismiss();
        }
    });
    final WebView wv = new WebView(ctx);
    wv.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return false;
        }
    });
    WebSettings settings = wv.getSettings();
    if (hasImageUrl) {
        settings.setDefaultTextEncodingName("utf-8");
        settings.setBuiltInZoomControls(true);
        settings.setDisplayZoomControls(false);
        settings.setSupportZoom(true);
    }
    /*
		//Scale web view font size with system font size
		float scale = ctx.getResources().getConfiguration().fontScale;
		if (android.os.Build.VERSION.SDK_INT >= 14) {
			settings.setTextZoom((int) (scale * 100f));
		} else {
			if (scale <= 0.7f) {
				settings.setTextSize(WebSettings.TextSize.SMALLEST);
			} else if (scale <= 0.85f) {
				settings.setTextSize(WebSettings.TextSize.SMALLER);
			} else if (scale <= 1.0f) {
				settings.setTextSize(WebSettings.TextSize.NORMAL);
			} else if (scale <= 1.15f) {
				settings.setTextSize(WebSettings.TextSize.LARGER);
			} else {
				settings.setTextSize(WebSettings.TextSize.LARGEST);
			}
		}
*/
    wv.setBackgroundColor(Color.argb(1, 0, 0, 0));
    // wv.setScrollContainer(false);
    wv.getSettings().setJavaScriptEnabled(true);
    if (hasImageUrl) {
        wv.loadData("<html><body style='margin:0;padding:0'><img style='max-width:100%;max-height:100%;' src='" + url + "'/></body></html>", "text/html", "UTF-8");
    } else {
        wv.loadUrl(url);
    }
    ll.addView(topBar);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0);
    lp.weight = 1;
    ll.addView(wv, lp);
    dialog.setContentView(ll);
    /*
		wv.setFocusable(true);
		wv.setFocusableInTouchMode(true);
		wv.requestFocus(View.FOCUS_DOWN);
		wv.setOnTouchListener(new View.OnTouchListener() {
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				switch (event.getAction()) {
					case MotionEvent.ACTION_DOWN:
					case MotionEvent.ACTION_UP:
						if (!v.hasFocus()) {
							v.requestFocus();
						}
						break;
				}
				return false;
			}
		});
		*/
    dialog.setCancelable(true);
    dialog.show();
}
Also used : Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) View(android.view.View) WebView(android.webkit.WebView) Dialog(android.app.Dialog) WebSettings(android.webkit.WebSettings) WebView(android.webkit.WebView) LinearLayout(android.widget.LinearLayout) Toolbar(android.support.v7.widget.Toolbar) WebViewClient(android.webkit.WebViewClient) SuppressLint(android.annotation.SuppressLint)

Example 65 with WebSettings

use of android.webkit.WebSettings in project ttdj by soonphe.

the class BCWXWapPaymentActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // 根布局参数
    LinearLayout.LayoutParams layoutParamsRoot = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
    // 根布局
    LinearLayout layoutRoot = new LinearLayout(this);
    layoutRoot.setLayoutParams(layoutParamsRoot);
    layoutRoot.setOrientation(LinearLayout.VERTICAL);
    layoutRoot.setBackgroundColor(0xFFF5F5F5);
    webView = new WebView(this);
    LinearLayout.LayoutParams webViewLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
    layoutRoot.addView(webView, webViewLayoutParams);
    setContentView(layoutRoot);
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    // 设置可以支持缩放
    webSettings.setSupportZoom(true);
    webSettings.setUseWideViewPort(true);
    // 设置默认加载的可视范围是大视野范围
    webSettings.setLoadWithOverviewMode(true);
    // 设置出现缩放工具
    webSettings.setBuiltInZoomControls(true);
    webView.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // 如下方案可在非微信内部WebView的H5页面中调出微信支付
            if (url.startsWith("weixin://wap/pay?")) {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(url));
                startActivity(intent);
                return true;
            }
            return super.shouldOverrideUrlLoading(view, url);
        }
    });
    url = getIntent().getStringExtra("url");
    webView.loadUrl(url);
}
Also used : WebSettings(android.webkit.WebSettings) Intent(android.content.Intent) WebView(android.webkit.WebView) LinearLayout(android.widget.LinearLayout) WebViewClient(android.webkit.WebViewClient)

Aggregations

WebSettings (android.webkit.WebSettings)213 WebView (android.webkit.WebView)110 WebViewClient (android.webkit.WebViewClient)77 SuppressLint (android.annotation.SuppressLint)52 WebChromeClient (android.webkit.WebChromeClient)49 View (android.view.View)38 Intent (android.content.Intent)32 Bitmap (android.graphics.Bitmap)23 WebResourceRequest (android.webkit.WebResourceRequest)15 KeyEvent (android.view.KeyEvent)11 JsResult (android.webkit.JsResult)11 LinearLayout (android.widget.LinearLayout)11 WebResourceError (android.webkit.WebResourceError)10 CookieManager (android.webkit.CookieManager)9 TextView (android.widget.TextView)9 SslError (android.net.http.SslError)8 SslErrorHandler (android.webkit.SslErrorHandler)8 WebResourceResponse (android.webkit.WebResourceResponse)8 ProgressDialog (android.app.ProgressDialog)7 Toolbar (android.support.v7.widget.Toolbar)7