|
@@ -1,26 +1,56 @@
|
|
|
package com.cooleshow.teacher.ui.web;
|
|
|
|
|
|
+import android.content.pm.ActivityInfo;
|
|
|
+import android.content.res.Configuration;
|
|
|
+import android.graphics.Color;
|
|
|
+import android.net.Uri;
|
|
|
import android.os.Build;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.view.View;
|
|
|
+import android.webkit.GeolocationPermissions;
|
|
|
+import android.webkit.ValueCallback;
|
|
|
+import android.webkit.WebChromeClient;
|
|
|
import android.webkit.WebSettings;
|
|
|
import android.webkit.WebView;
|
|
|
import android.widget.FrameLayout;
|
|
|
|
|
|
+import com.alibaba.android.arouter.facade.annotation.Route;
|
|
|
import com.cooleshow.base.BuildConfig;
|
|
|
import com.cooleshow.base.databinding.ActivityHtmlBinding;
|
|
|
+import com.cooleshow.base.router.RouterPath;
|
|
|
import com.cooleshow.base.ui.activity.BaseActivity;
|
|
|
-import com.cooleshow.base.utils.helper.JsInterfaceHelper;
|
|
|
+import com.cooleshow.base.utils.LogUtils;
|
|
|
+import com.cooleshow.base.utils.Utils;
|
|
|
+import com.cooleshow.base.utils.helper.QMUIStatusBarHelper;
|
|
|
+import com.cooleshow.base.widgets.WebClient;
|
|
|
+import com.cooleshow.teacher.widgets.helper.JsInterfaceHelper;
|
|
|
import com.cooleshow.base.widgets.LollipopFixedWebView;
|
|
|
import com.cooleshow.usercenter.helper.UserHelper;
|
|
|
|
|
|
+import org.json.JSONObject;
|
|
|
+
|
|
|
import androidx.annotation.NonNull;
|
|
|
+import androidx.annotation.Nullable;
|
|
|
+
|
|
|
+import static com.cooleshow.base.common.WebConstants.WEB_URL;
|
|
|
|
|
|
/**
|
|
|
* Author by pq, Date on 2022/4/24.
|
|
|
*/
|
|
|
-public class WebActivity extends BaseActivity<ActivityHtmlBinding> {
|
|
|
+@Route(path = RouterPath.WebCenter.ACTIVITY_HTML)
|
|
|
+public class WebActivity extends BaseActivity<ActivityHtmlBinding> implements JsInterfaceHelper.OnJsMethodCallListener {
|
|
|
|
|
|
private WebView webView;
|
|
|
private String url;
|
|
|
+ private JsInterfaceHelper mInterfaceUtils;
|
|
|
+ private WebClient mWebClient;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ QMUIStatusBarHelper.setStatusBarLightMode(this);
|
|
|
+ }
|
|
|
|
|
|
@NonNull
|
|
|
@Override
|
|
@@ -30,6 +60,7 @@ public class WebActivity extends BaseActivity<ActivityHtmlBinding> {
|
|
|
|
|
|
@Override
|
|
|
protected void initView() {
|
|
|
+ Utils.setHeadView(viewBinding.statusBarView, this, 0);
|
|
|
try {
|
|
|
if (Build.VERSION.SDK_INT >= 21 && Build.VERSION.SDK_INT < 23) {
|
|
|
webView = new LollipopFixedWebView(this);
|
|
@@ -40,23 +71,30 @@ public class WebActivity extends BaseActivity<ActivityHtmlBinding> {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
if (null == webView) {
|
|
|
+ finish();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ url = getIntent().getStringExtra(WEB_URL);
|
|
|
+ if (TextUtils.isEmpty(url)) {
|
|
|
+ finish();
|
|
|
return;
|
|
|
}
|
|
|
viewBinding.viewParent.addView(webView, new FrameLayout.LayoutParams(
|
|
|
FrameLayout.LayoutParams.MATCH_PARENT,
|
|
|
FrameLayout.LayoutParams.MATCH_PARENT));
|
|
|
initWebView();
|
|
|
- JsInterfaceHelper jsInterfaceUtils = new JsInterfaceHelper(WebActivity.this);
|
|
|
-// jsInterfaceUtils.setOnItemClickListener(this);
|
|
|
-
|
|
|
- webView.addJavascriptInterface(jsInterfaceUtils, "DAYA");
|
|
|
-// webView.setWebViewClient(new WebClient());
|
|
|
-// webView.setWebChromeClient(new MyWebChromeClient());
|
|
|
+ mInterfaceUtils = new JsInterfaceHelper(WebActivity.this);
|
|
|
+ mInterfaceUtils.setOnJsCallListener(this);
|
|
|
+ webView.addJavascriptInterface(mInterfaceUtils, "COLEXIUAPPA");
|
|
|
+ mWebClient = new WebClient();
|
|
|
+ webView.setWebViewClient(mWebClient);
|
|
|
+ webView.setWebChromeClient(new MyWebChromeClient());
|
|
|
loadUrl();
|
|
|
}
|
|
|
|
|
|
private void loadUrl() {
|
|
|
String userToken = UserHelper.getUserToken();
|
|
|
+ mWebClient.setAuthorization(userToken);
|
|
|
boolean status = url.contains("?");
|
|
|
if (status) {
|
|
|
url = (url + "&Authorization=" + userToken);
|
|
@@ -123,4 +161,132 @@ public class WebActivity extends BaseActivity<ActivityHtmlBinding> {
|
|
|
// downloadFile(url);
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 状态栏控制
|
|
|
+ *
|
|
|
+ * @param message
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void setBarStatus(JSONObject message) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 返回按钮
|
|
|
+ *
|
|
|
+ * @param message
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void backIconChange(JSONObject message) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取状态栏高度
|
|
|
+ *
|
|
|
+ * @param message
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void getNavHeight(JSONObject message) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onDestroy() {
|
|
|
+ super.onDestroy();
|
|
|
+ if (mInterfaceUtils != null) {
|
|
|
+ mInterfaceUtils.release();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private class MyWebChromeClient extends WebChromeClient {
|
|
|
+ public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
|
|
|
+ callback.invoke(origin, true, false);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onProgressChanged(WebView view, int newProgress) {
|
|
|
+ LogUtils.e(newProgress + "");
|
|
|
+ if (newProgress == 100 && null != viewBinding.progressBar) {
|
|
|
+ viewBinding.progressBar.setVisibility(View.GONE);//加载完网页进度条消失
|
|
|
+ } else {
|
|
|
+ if (null != viewBinding.progressBar) {
|
|
|
+ viewBinding.progressBar.setVisibility(View.VISIBLE);//开始加载网页时显示进度条
|
|
|
+ viewBinding.progressBar.setProgress(newProgress);//设置进度值
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onReceivedTitle(WebView view, String title) {
|
|
|
+ super.onReceivedTitle(view, title);
|
|
|
+ if (!TextUtils.isEmpty(title)) {
|
|
|
+ viewBinding.tvTitle.setText(title);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // Android > 5.0.1
|
|
|
+ public boolean onShowFileChooser(
|
|
|
+ WebView webView, ValueCallback<Uri[]> filePathCallback,
|
|
|
+ FileChooserParams fileChooserParams) {
|
|
|
+// setUploadMsg(filePathCallback);
|
|
|
+// addPermissions(PORTRAIT_REQUEST_CODE);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private CustomViewCallback mCustomViewCallback;
|
|
|
+ // 横屏时,显示视频的view
|
|
|
+ private View mCustomView;
|
|
|
+
|
|
|
+ // 点击全屏按钮时,调用的方法
|
|
|
+ @Override
|
|
|
+ public void onShowCustomView(View view, CustomViewCallback callback) {
|
|
|
+ super.onShowCustomView(view, callback);
|
|
|
+
|
|
|
+ //如果view 已经存在,则隐藏
|
|
|
+ if (mCustomView != null) {
|
|
|
+ callback.onCustomViewHidden();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ mCustomView = view;
|
|
|
+ mCustomView.setVisibility(View.VISIBLE);
|
|
|
+ mCustomViewCallback = callback;
|
|
|
+ viewBinding.flVideo.addView(mCustomView);
|
|
|
+ viewBinding.flVideo.setVisibility(View.VISIBLE);
|
|
|
+// mLayout.bringToFront();
|
|
|
+ viewBinding.headerBarView.setVisibility(View.GONE);
|
|
|
+ //设置横屏
|
|
|
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 取消全屏调用的方法
|
|
|
+ @Override
|
|
|
+ public void onHideCustomView() {
|
|
|
+ super.onHideCustomView();
|
|
|
+ if (mCustomView == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ mCustomView.setVisibility(View.GONE);
|
|
|
+ viewBinding.flVideo.removeView(mCustomView);
|
|
|
+ mCustomView = null;
|
|
|
+ viewBinding.flVideo.setVisibility(View.GONE);
|
|
|
+ try {
|
|
|
+ mCustomViewCallback.onCustomViewHidden();
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ viewBinding.headerBarView.setVisibility(View.VISIBLE);
|
|
|
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//竖屏
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onConfigurationChanged(@NonNull Configuration newConfig) {
|
|
|
+ super.onConfigurationChanged(newConfig);
|
|
|
+ }
|
|
|
}
|