MainActivity.java
3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package com.qw7277.game;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.qw7277.game.util.AppUtils;
import com.readystatesoftware.systembartint.SystemBarTintManager;
public class MainActivity extends Activity {
private Context mContext;
private LinearLayout mLlRoot;
private WebView mWebView;
private SystemBarTintManager mTintManager;
private String mUrl = "https://cdn.kky.cn/yxhz/index.html#/home";
private String mParams="";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = this;
mTintManager = new SystemBarTintManager(this);
mTintManager.setStatusBarTintEnabled(false);
mTintManager.setNavigationBarTintEnabled(true);
mTintManager.setStatusBarTintColor(Color.parseColor("#FFFFFF"));
//适配异形屏
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
getWindow().setAttributes(lp);
}
setContentView(R.layout.activity_main);
initView();
initWebView();
initData();
Log.d("ZhenWan", mUrl+"?"+mParams);
mWebView.loadUrl(mUrl+"?"+mParams);
}
private void initView() {
mLlRoot = findViewById(R.id.ll_root);
mLlRoot.setPadding(0, mTintManager.getConfig().getStatusBarHeight(), 0, mTintManager.getConfig().getNavigationBarHeight() + 20);
mWebView = findViewById(R.id.webview);
}
private void initWebView() {
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setDisplayZoomControls(false);
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
webSettings.setAllowFileAccess(true);
}
private void initData() {
Bundle extras = getIntent().getExtras();
if (extras != null && extras.containsKey("AuthParams")) {
mParams = extras.getString("AuthParams");
}
String cid = AppUtils.getLogicChannel(mContext, "sid");
mParams += (TextUtils.isEmpty(mParams) ? "" : "&") + "cid=" + cid;
}
private long mBackPressedTime = 0;
@Override
public void onBackPressed() {
if (mWebView != null && mWebView.canGoBack()) {
mWebView.goBack();
} else {
if (System.currentTimeMillis() - mBackPressedTime > 2000) {
Toast.makeText(this, "再按一次退出应用", Toast.LENGTH_SHORT).show();
mBackPressedTime = System.currentTimeMillis();
} else {
super.onBackPressed();
}
}
}
}