569 lines
20 KiB
Java
569 lines
20 KiB
Java
package com.web.dmcslot;
|
||
|
||
import android.annotation.SuppressLint;
|
||
import android.annotation.TargetApi;
|
||
import android.app.Activity;
|
||
import android.app.DownloadManager;
|
||
import android.content.ActivityNotFoundException;
|
||
import android.content.ComponentName;
|
||
import android.content.Context;
|
||
import android.content.Intent;
|
||
import android.content.pm.PackageManager;
|
||
import android.net.Uri;
|
||
import android.os.Build;
|
||
import android.os.Bundle;
|
||
import android.os.Environment;
|
||
import android.os.Message;
|
||
import android.text.TextUtils;
|
||
import android.util.Log;
|
||
import android.view.KeyEvent;
|
||
import android.view.View;
|
||
import android.view.Window;
|
||
import android.view.WindowManager;
|
||
import android.webkit.DownloadListener;
|
||
import android.webkit.ValueCallback;
|
||
import com.just.agentweb.WebChromeClient;
|
||
import android.webkit.WebResourceError;
|
||
import android.webkit.WebResourceRequest;
|
||
import android.webkit.WebSettings;
|
||
import android.webkit.WebView;
|
||
import com.just.agentweb.WebViewClient;
|
||
import android.widget.FrameLayout;
|
||
import android.widget.ImageView;
|
||
import android.widget.LinearLayout;
|
||
import android.widget.ProgressBar;
|
||
import android.widget.RelativeLayout;
|
||
import android.widget.Toast;
|
||
|
||
import androidx.annotation.Nullable;
|
||
import androidx.annotation.RequiresApi;
|
||
import androidx.appcompat.app.ActionBar;
|
||
import androidx.appcompat.app.AppCompatActivity;
|
||
import androidx.core.app.ActivityCompat;
|
||
|
||
import java.util.HashMap;
|
||
import java.util.Map;
|
||
|
||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||
import io.reactivex.schedulers.Schedulers;
|
||
|
||
import com.just.agentweb.AgentWeb;
|
||
//import com.tencent.smtt.export.external.interfaces.WebResourceRequest;
|
||
//import com.tencent.smtt.sdk.DownloadListener;
|
||
//import com.tencent.smtt.sdk.URLUtil;
|
||
//import com.tencent.smtt.sdk.ValueCallback;
|
||
//import com.tencent.smtt.sdk.WebChromeClient;
|
||
//import com.tencent.smtt.sdk.WebSettings;
|
||
//import com.tencent.smtt.sdk.WebView;
|
||
//import com.tencent.smtt.sdk.WebViewClient;
|
||
|
||
|
||
public class MainActivity3 extends AppCompatActivity {
|
||
LinearLayout webView;
|
||
ImageView show_top_v;
|
||
ImageView menu_iv;
|
||
private ImageView helpIv;
|
||
private LinearLayout showTopLy;
|
||
|
||
String downloadImageUrl = "";
|
||
private int requestCode;
|
||
private String[] permissions;
|
||
private int[] grantResults;
|
||
private View topVvvv;
|
||
private int index = 0;
|
||
private FrameLayout videoContainer;
|
||
|
||
private ImageView backIv;
|
||
private ProgressBar progressBar;
|
||
|
||
AgentWeb mAgentWeb;
|
||
|
||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||
@Override
|
||
protected void onCreate(Bundle savedInstanceState) {
|
||
|
||
getWindow().setNavigationBarColor(getColor(R.color.white));
|
||
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
|
||
|
||
super.onCreate(savedInstanceState);
|
||
View decor = getWindow().getDecorView();
|
||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
|
||
decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||
ActionBar actionBar = getSupportActionBar();
|
||
if (actionBar != null) {
|
||
actionBar.hide();
|
||
}
|
||
setContentView(R.layout.activity_main3);
|
||
initView();
|
||
// setopHeight();
|
||
findViewById(R.id.back_iv).setOnClickListener(view -> onBackPressed());
|
||
}
|
||
|
||
public void hideStatusBar(Activity activity) {
|
||
if (activity == null) return;
|
||
Window window = activity.getWindow();
|
||
if (window == null) return;
|
||
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
|
||
WindowManager.LayoutParams lp = window.getAttributes();
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||
lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
|
||
}
|
||
window.setAttributes(lp);
|
||
}
|
||
|
||
|
||
@Override
|
||
public void onBackPressed() {
|
||
|
||
// if (mAgentWeb.canGoBack()) {//当webview有多级能返回的时候
|
||
// // 在首页 就退出这个页面
|
||
// if (webView.getUrl().equals(url + "index") || webView.getUrl().equals(url + "/index")) {
|
||
//
|
||
// Intent intent = new Intent(this, MainActivity.class);
|
||
// startActivity(intent);
|
||
// super.onBackPressed();
|
||
// } else { //不在首页 回到首页
|
||
// if (webView.getUrl().equals(url + "index") || webView.getUrl().equals(url + "/index")) {
|
||
// isAtGame = false;
|
||
// }
|
||
// topVvvv.setVisibility(View.GONE);
|
||
// progressBar.setVisibility(View.VISIBLE);
|
||
// webView.loadUrl(url);
|
||
// }
|
||
// } else {//不能返回了
|
||
//
|
||
// //返回计算器
|
||
// Intent intent = new Intent(this, MainActivity.class);
|
||
// startActivity(intent);
|
||
//// }
|
||
super.onBackPressed();
|
||
// }
|
||
}
|
||
|
||
/**
|
||
* 修改图标和名称的方法
|
||
*/
|
||
public void changeIcon() {
|
||
PackageManager pm = getApplicationContext().getPackageManager();
|
||
|
||
pm.setComponentEnabledSetting(new ComponentName(
|
||
this,
|
||
"com.web.dmcslot.MainActivity"),
|
||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
||
PackageManager.DONT_KILL_APP);
|
||
Log.d("TAG", "换Test的图标");
|
||
|
||
pm.setComponentEnabledSetting(new ComponentName(
|
||
this,
|
||
"com.web.dmcslot.MainActivityNew"),
|
||
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
|
||
PackageManager.DONT_KILL_APP);
|
||
|
||
}
|
||
|
||
private void setopHeight() {
|
||
RelativeLayout.LayoutParams linearParams = (RelativeLayout.LayoutParams) topVvvv.getLayoutParams(); //取控件textView当前的布局参数
|
||
linearParams.height = getStatusBarHeight();// 控件的宽强制设成30
|
||
|
||
topVvvv.setLayoutParams(linearParams);
|
||
}
|
||
|
||
//https://m.xiannvtu.com/
|
||
public static String url = "http://winway33.com/";
|
||
|
||
// https://telegram.2ltop.com/url.json?rand=111111111
|
||
//先定义
|
||
private static final int REQUEST_EXTERNAL_STORAGE = 1;
|
||
|
||
private static String[] PERMISSIONS_STORAGE = {
|
||
"android.permission.READ_EXTERNAL_STORAGE",
|
||
"android.permission.WRITE_EXTERNAL_STORAGE"};
|
||
|
||
//然后通过一个函数来申请
|
||
public static void verifyStoragePermissions(Activity activity) {
|
||
|
||
// 没有写的权限,去申请写的权限,会弹出对话框
|
||
ActivityCompat.requestPermissions(activity, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE);
|
||
|
||
}
|
||
|
||
|
||
@SuppressLint({"NewApi", "WrongConstant"})
|
||
protected void initView() {
|
||
topVvvv = (View) findViewById(R.id.top_vvvv);
|
||
webView = findViewById(R.id.webview);
|
||
show_top_v = findViewById(R.id.show_top_v);
|
||
showTopLy = findViewById(R.id.show_top_ly);
|
||
videoContainer = (FrameLayout) findViewById(R.id.videoContainer);
|
||
// topVvvvf = (RelativeLayout) findViewById(R.id.top_vvvvf);
|
||
// topVvvv1 = (StatusLayout) findViewById(R.id.top_vvvv1);
|
||
backIv = (ImageView) findViewById(R.id.back_iv);
|
||
progressBar = (ProgressBar) findViewById(R.id.progressbar);
|
||
|
||
// WebSettings settings = webView.getSettings();
|
||
// settings.setDomStorageEnabled(true);
|
||
// settings.setAppCacheEnabled(true);
|
||
// settings.setCacheMode(WebSettings.LOAD_DEFAULT);
|
||
// settings.setJavaScriptEnabled(true);
|
||
// settings.setLoadWithOverviewMode(true);
|
||
// // 设置允许访问文件数据
|
||
// settings.setAllowFileAccess(true);
|
||
// settings.setAllowContentAccess(true);
|
||
// settings.setDatabaseEnabled(true);
|
||
// settings.setSavePassword(false);
|
||
// settings.setSaveFormData(false);
|
||
// settings.setUseWideViewPort(true);
|
||
// settings.setBuiltInZoomControls(true);
|
||
// settings.setPluginState(WebSettings.PluginState.ON);
|
||
// settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
|
||
// webView.setFocusable(true);
|
||
// webView.setFocusableInTouchMode(true);
|
||
// webView.getSettings().setSupportMultipleWindows(true);
|
||
//
|
||
// settings.setSupportZoom(false);
|
||
// webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
|
||
//// webView.setHorizontalScrollbarOverlay(true);
|
||
// webView.setHorizontalScrollBarEnabled(true);
|
||
// webView.requestFocus();
|
||
//// webView.setBackgroundColor(getColor(R.color.black));
|
||
// settings.setJavaScriptCanOpenWindowsAutomatically(true);
|
||
//
|
||
// // 设置在WebView内部是否允许通过file url加载的 Js代码读取其他的本地文件
|
||
// // Android 4.1前默认允许,4.1后默认禁止
|
||
// settings.setAllowFileAccessFromFileURLs(true);
|
||
// // 设置WebView内部是否允许通过 file url 加载的 Javascript 可以访问其他的源(包括http、https等源)
|
||
// // Android 4.1前默认允许,4.1后默认禁止
|
||
// settings.setAllowUniversalAccessFromFileURLs(true);
|
||
//
|
||
//
|
||
// webView.setWebChromeClient(webChromeClient);
|
||
// webView.setWebViewClient(webViewClient);
|
||
// Log.i("XHXDEBUG", "XHXDEBUGURL:::" + url);
|
||
//
|
||
//// new Handler().postDelayed(() -> showTopLy.setVisibility(View.GONE), 3000);
|
||
//// verifyStoragePermissions(this);
|
||
//
|
||
// webView.setDownloadListener(new DownloadListener() {
|
||
// @Override
|
||
// public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimeType, long contentLength) {
|
||
// LogUtils.i("URL是啥onDownloadStart:" + url);
|
||
//
|
||
// try {
|
||
// Intent intent = new Intent();
|
||
// intent.setAction(Intent.ACTION_VIEW);
|
||
// intent.setData(Uri.parse(url));
|
||
// startActivity(intent);
|
||
// } catch (Exception e) {
|
||
// e.printStackTrace();
|
||
// }
|
||
//
|
||
// }
|
||
// });
|
||
getNetUrl();
|
||
}
|
||
public void getNetUrl(){
|
||
// Api.getInstance().geUrl(System.currentTimeMillis())
|
||
// .subscribeOn(Schedulers.io())
|
||
// .observeOn(AndroidSchedulers.mainThread())
|
||
// .subscribe(new BaseObserver<Result>() {
|
||
// @Override
|
||
// public void onSuccess(Result o) {
|
||
// LogUtils.i("URL是啥获取的文件地址:"+o.url);
|
||
// if(!TextUtils.isEmpty(o.url)){
|
||
// MainActivity.saveString(MainActivity3.this,"base_url",o.url);
|
||
// url = MainActivity.getString(MainActivity3.this, "base_url", url);
|
||
// toUrl(url);
|
||
// }
|
||
// }
|
||
//
|
||
// @Override
|
||
// public void onError(int code, String msg) {
|
||
// url = MainActivity.getString(MainActivity3.this, "base_url", url);
|
||
// toUrl(url);
|
||
// }
|
||
// });
|
||
}
|
||
|
||
private void toUrl(String url) {
|
||
mAgentWeb = AgentWeb.with(this)
|
||
.setAgentWebParent( webView, new LinearLayout.LayoutParams(-1, -1))
|
||
.useDefaultIndicator()
|
||
.setWebViewClient(webViewClient)
|
||
.setWebChromeClient(webChromeClient)
|
||
.createAgentWeb()
|
||
|
||
.ready()
|
||
.go(url);
|
||
|
||
}
|
||
|
||
|
||
WebViewClient webViewClient = new WebViewClient() {
|
||
|
||
@Override
|
||
public void onPageFinished(WebView webView, String s) {
|
||
super.onPageFinished(webView, s);
|
||
LogUtils.i("URL是啥加载完成:" + webView.getUrl());
|
||
|
||
int w = View.MeasureSpec.makeMeasureSpec(0,
|
||
View.MeasureSpec.UNSPECIFIED);
|
||
int h = View.MeasureSpec.makeMeasureSpec(0,
|
||
View.MeasureSpec.UNSPECIFIED);
|
||
// 重新测量
|
||
webView.measure(w, h);
|
||
showTopLy.setVisibility(View.GONE);
|
||
|
||
if (webView.getUrl().equals(url + "index") || webView.getUrl().equals(url + "/index")) {
|
||
isAtGame = false;
|
||
topVvvv.setVisibility(View.GONE);
|
||
|
||
} else {
|
||
if (isAtGame) {
|
||
topVvvv.setVisibility(View.VISIBLE);
|
||
} else {
|
||
topVvvv.setVisibility(View.GONE);
|
||
|
||
}
|
||
}
|
||
|
||
}
|
||
// @Override
|
||
// public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
|
||
// super.onReceivedError(view, request, error);
|
||
// if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||
// int errorCode = error.getErrorCode();
|
||
// String errorMessage = error.getDescription().toString();
|
||
// Log.i("CustomWebViewClient", "onReceivedError errorCode : " + errorCode + " errorMessage : " + errorMessage);
|
||
// }
|
||
// progressBar.setVisibility(View.GONE);
|
||
// }
|
||
|
||
@Override
|
||
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
|
||
super.onReceivedError(view, errorCode, description, failingUrl);
|
||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||
Log.i("CustomWebViewClient", "onReceivedError errorCode : " + errorCode + " description : " + description);
|
||
}
|
||
progressBar.setVisibility(View.GONE);
|
||
|
||
}
|
||
|
||
// @Override
|
||
// public boolean shouldOverrideUrlLoading(WebView webView, String s) {
|
||
// LogUtils.i("URL是啥:"+s);
|
||
// return super.shouldOverrideUrlLoading(webView, s);
|
||
// }
|
||
|
||
@Override
|
||
public boolean shouldOverrideUrlLoading(WebView webView, String url1) {
|
||
|
||
LogUtils.i("URL是啥:" + url1);
|
||
if (url1.equals(url + "index") || url1.equals(url + "/index")) {
|
||
isAtGame = false;
|
||
topVvvv.setVisibility(View.GONE);
|
||
}else{
|
||
progressBar.setVisibility(View.VISIBLE);
|
||
}
|
||
|
||
if (!(url1.startsWith("http") || url1.startsWith("https"))) {
|
||
try {
|
||
Intent intent = new Intent();
|
||
intent.setAction(Intent.ACTION_VIEW);
|
||
intent.setData(Uri.parse(url1));
|
||
startActivity(intent);
|
||
return true;
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
} else {
|
||
//其它的该怎么处理就怎么处理
|
||
webView.loadUrl(url1);
|
||
return true;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
};
|
||
|
||
boolean isAtGame = false;
|
||
// String uuid = "", uuid1 = "";
|
||
private static final int REQUEST_CODE_FILE_CHOOSER = 1;
|
||
private ValueCallback<Uri> mUploadCallbackForLowApi;
|
||
private ValueCallback<Uri[]> mUploadCallbackForHighApi;
|
||
WebChromeClient webChromeClient = new WebChromeClient() {
|
||
// @Override
|
||
// public boolean onCreateWindow(WebView webViewdd, boolean b, boolean b1, Message resultMsg) {
|
||
// LogUtils.i("URL是啥onCreateWindow:" + webViewdd.getUrl());
|
||
//
|
||
// WebView newWebView = new WebView(MainActivity3.this);
|
||
// newWebView.setWebViewClient(new WebViewClient() {
|
||
// @Override
|
||
// public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||
// isAtGame = true;
|
||
// mAgentWeb.getUrlLoader().loadUrl(url);
|
||
// return true;
|
||
// }
|
||
// });
|
||
// return true;
|
||
// }
|
||
|
||
|
||
@Override
|
||
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
|
||
return super.onCreateWindow(view, isDialog, isUserGesture, resultMsg);
|
||
}
|
||
|
||
@Override
|
||
public void onProgressChanged(WebView view, int newProgress) {
|
||
super.onProgressChanged(view, newProgress);
|
||
// 更新进度条的进度
|
||
progressBar.setProgress(newProgress);
|
||
// 如果加载完成,隐藏进度条
|
||
if (newProgress == 100) {
|
||
progressBar.setVisibility(View.GONE);
|
||
} else {
|
||
progressBar.setVisibility(View.VISIBLE);
|
||
}
|
||
}
|
||
|
||
|
||
};
|
||
|
||
|
||
@RequiresApi(api = Build.VERSION_CODES.Q)
|
||
@Override
|
||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||
super.onActivityResult(requestCode, resultCode, data);
|
||
switch (requestCode) {
|
||
case REQUEST_CODE_FILE_CHOOSER:
|
||
if (resultCode == RESULT_OK || resultCode == RESULT_CANCELED) {
|
||
afterFileChooseGoing(resultCode, data);
|
||
}
|
||
break;
|
||
|
||
|
||
}
|
||
}
|
||
|
||
/**
|
||
* onActivityResult方法
|
||
*/
|
||
|
||
private void afterFileChooseGoing(int resultCode, Intent data) {
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||
if (mUploadCallbackForHighApi == null) {
|
||
return;
|
||
}
|
||
mUploadCallbackForHighApi.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode, data));
|
||
mUploadCallbackForHighApi = null;
|
||
} else {
|
||
if (mUploadCallbackForLowApi == null) {
|
||
return;
|
||
}
|
||
Uri result = data == null ? null : data.getData();
|
||
mUploadCallbackForLowApi.onReceiveValue(result);
|
||
mUploadCallbackForLowApi = null;
|
||
}
|
||
}
|
||
public class JavaScriptinterface {
|
||
Context context;
|
||
|
||
public JavaScriptinterface(Context c) {
|
||
context = c;
|
||
}
|
||
|
||
}
|
||
|
||
@Override
|
||
public void onRequestPermissionsResult(int requestCode,
|
||
String permissions[], int[] grantResults) {
|
||
switch (requestCode) {
|
||
case REQUEST_EXTERNAL_STORAGE:
|
||
if (grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED) {
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||
}
|
||
|
||
/**
|
||
* 设置网页中图片的点击事件
|
||
*
|
||
* @param view
|
||
*/
|
||
public static void setWebImageClick(WebView view, String method) {
|
||
|
||
|
||
}
|
||
|
||
|
||
// @Override
|
||
// public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||
//
|
||
// if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||
//
|
||
// if (webView.canGoBack()) {
|
||
// webView.goBack();
|
||
// return true;
|
||
// } else {
|
||
// return super.onKeyDown(keyCode, event);
|
||
//
|
||
// }
|
||
//
|
||
// }
|
||
// return super.onKeyDown(keyCode, event);
|
||
// }
|
||
|
||
|
||
@Override
|
||
public void onDestroy() {
|
||
|
||
if (webView != null) {
|
||
//加载null内容
|
||
// webView.loadDataWithBaseURL(null, "", "text/html", "utf-8", null);
|
||
// //清除历史记录
|
||
// webView.clearHistory();
|
||
//移除WebView
|
||
// ((ViewGroup) webView.getParent()).removeView(webView);
|
||
//销毁VebView
|
||
mAgentWeb.destroy();
|
||
}
|
||
super.onDestroy();
|
||
}
|
||
|
||
@Override
|
||
protected void onResume() {
|
||
super.onResume();
|
||
|
||
|
||
}
|
||
|
||
@Override
|
||
protected void onPause() {
|
||
super.onPause();
|
||
|
||
}
|
||
|
||
|
||
/**
|
||
* 获取状态栏高度
|
||
*
|
||
* @return
|
||
*/
|
||
public int getStatusBarHeight() {
|
||
int result = 0;
|
||
//获取状态栏高度的资源id
|
||
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
|
||
if (resourceId > 0) {
|
||
result = getResources().getDimensionPixelSize(resourceId);
|
||
}
|
||
return result;
|
||
}
|
||
//wp-caption alignnone
|
||
|
||
|
||
}
|