package com.xunao.effectdemo.activity;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import androidx.annotation.Nullable;

import com.xunao.effectdemo.R;

/**
 * author : 程中强
 * e-mail : 740479946@qq.com
 * date : 2022/8/2917:40
 * desc :
 * version: 1.0
 */
public class WebActivity extends Activity {

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


		WebView webview = findViewById(R.id.webview);
		WebSettings webSettings = webview.getSettings();
		webSettings.setDomStorageEnabled(true);
		webSettings.setJavaScriptEnabled(true);
		webSettings.setBlockNetworkImage(false);
		webSettings.setBuiltInZoomControls(true);
		// 覆盖WebView默认使用第三方或系统默认浏览器打开网页的行为，使网页用WebView打开
		webview.setWebViewClient(new WebViewClient() {
			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
//                view.loadUrl(url);
//                return true;

				if (url.startsWith("http:") || url.startsWith("https:") || url.startsWith("ftp")) {
					view.loadUrl(url);
					return true;
				} else if (url.startsWith("scheme://")) {
					// 使用浏览器打开
					Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
					startActivity(intent);
					return true;
				} else {
					return false;
				}

			}
		});

		webview.loadUrl("http://waibao.kidcastle.org/smallgame/tiaoyitiao/zjreplay.html");

	}
}
