Pq 3 лет назад
Родитель
Сommit
92534d520e

+ 2 - 0
BaseLibrary/build.gradle

@@ -53,6 +53,8 @@ kapt {
 
 dependencies {
 
+    implementation project(path: ':Provider')
+    implementation project(path: ':usercenter')
     testImplementation 'junit:junit:4.13.2'
     androidTestImplementation 'androidx.test.ext:junit:1.1.3'
     androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

+ 126 - 0
BaseLibrary/src/main/java/com/cooleshow/base/ui/activity/web/WebActivity.java

@@ -0,0 +1,126 @@
+package com.cooleshow.base.ui.activity.web;
+
+import android.os.Build;
+import android.webkit.WebSettings;
+import android.webkit.WebView;
+import android.widget.FrameLayout;
+
+import com.cooleshow.base.BuildConfig;
+import com.cooleshow.base.databinding.ActivityHtmlBinding;
+import com.cooleshow.base.ui.activity.BaseActivity;
+import com.cooleshow.base.utils.helper.JsInterfaceHelper;
+import com.cooleshow.base.widgets.LollipopFixedWebView;
+import com.cooleshow.usercenter.helper.UserHelper;
+
+import androidx.annotation.NonNull;
+
+/**
+ * Author by pq, Date on 2022/4/24.
+ */
+public class WebActivity extends BaseActivity<ActivityHtmlBinding> {
+
+    private WebView webView;
+    private String url;
+
+    @NonNull
+    @Override
+    protected ActivityHtmlBinding getLayoutView() {
+        return ActivityHtmlBinding.inflate(getLayoutInflater());
+    }
+
+    @Override
+    protected void initView() {
+        try {
+            if (Build.VERSION.SDK_INT >= 21 && Build.VERSION.SDK_INT < 23) {
+                webView = new LollipopFixedWebView(this);
+            } else {
+                webView = new WebView(this);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        if (null == webView) {
+            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());
+        loadUrl();
+    }
+
+    private void loadUrl() {
+        String userToken = UserHelper.getUserToken();
+        boolean status = url.contains("?");
+        if (status) {
+            url = (url + "&Authorization=" + userToken);
+        } else {
+            url = (url + "?Authorization=" + userToken);
+        }
+        webView.loadUrl(url);
+    }
+
+    @Override
+    public void initData() {
+        super.initData();
+    }
+
+    private void initWebView() {
+        //声明WebSettings子类
+        WebSettings webSettings = webView.getSettings();
+        webSettings.setUserAgentString(webSettings.getUserAgentString() + ";DAYAAPPA");
+        webSettings.setGeolocationDatabasePath(getApplicationContext().getFilesDir().getPath());
+        webSettings.setGeolocationEnabled(true);
+        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
+        //如果访问的页面中要与Javascript交互,则webview必须设置支持Javascript
+        webSettings.setJavaScriptEnabled(true);
+        webSettings.setMediaPlaybackRequiresUserGesture(false);//false允许自动播放音视频
+        //是否启用缓存
+        webSettings.setAppCacheEnabled(true);
+
+        // 开启DOM缓存,默认状态下是不支持LocalStorage的
+        webSettings.setDomStorageEnabled(true);
+        // 开启数据库缓存
+        webSettings.setDatabaseEnabled(true);
+        // 地址跨域导致视频预览图片加载不出来 无法播放:
+        webSettings.setAllowUniversalAccessFromFileURLs(false);
+        webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
+
+        //设置自适应屏幕,两者合用
+        webSettings.setUseWideViewPort(true); //将图片调整到适合webview的大小
+        webSettings.setLoadWithOverviewMode(true); // 缩放至屏幕的大小
+        //缩放操作
+        webSettings.setSupportZoom(false); //支持缩放,默认为true。是下面那个的前提。
+        // 设置允许JS弹窗
+        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
+        //其他细节操作
+        webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); //关闭webview中缓存
+        webSettings.setAllowFileAccess(true); //设置可以访问文件
+        webSettings.setJavaScriptCanOpenWindowsAutomatically(true); //支持通过JS打开新窗口
+        webSettings.setLoadsImagesAutomatically(true); //支持自动加载图片
+        webSettings.setDefaultTextEncodingName("UTF-8");//设置编码格式
+
+        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);  //富文本适配
+        webSettings.setAppCacheMaxSize(Long.MAX_VALUE);
+        webSettings.setAppCachePath(this.getDir("appcache", 0).getPath());
+        webSettings.setDatabasePath(this.getDir("databases", 0).getPath());
+        webSettings.setGeolocationDatabasePath(this.getDir("geolocation", 0)
+                .getPath());
+        webSettings.setPluginState(WebSettings.PluginState.ON_DEMAND);
+        if (BuildConfig.DEBUG) {
+            webView.setWebContentsDebuggingEnabled(true);
+        }
+        webSettings.setTextZoom(100);//设置字体默认的缩放比例,以避免手机系统的字体修改对页面字体及布局造成影响。
+        webView.setHorizontalScrollBarEnabled(false);
+        webView.setVerticalScrollBarEnabled(false);
+        webView.setDownloadListener((url, userAgent, contentDisposition, mimetype, contentLength) -> {
+//            downloadFile(url);
+        });
+    }
+}

+ 35 - 0
BaseLibrary/src/main/java/com/cooleshow/base/utils/helper/JsInterfaceHelper.java

@@ -0,0 +1,35 @@
+package com.cooleshow.base.utils.helper;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.net.Uri;
+import android.text.TextUtils;
+import android.view.Window;
+import android.view.WindowManager;
+import android.webkit.JavascriptInterface;
+
+import com.alibaba.android.arouter.launcher.ARouter;
+
+import org.json.JSONObject;
+
+
+/**
+ * Description:
+ * Copyright  : Copyright (c) 2016
+ * Company    : 大雅
+ * Author     : 刘瑞
+ * Date       : 2018/11/12 15:23
+ */
+public class JsInterfaceHelper extends Object {
+    public static final String ENTERLIVEROOM = "enterLiveRoom";
+
+    private Activity activity;
+    JSONObject resultJson;
+
+
+    public JsInterfaceHelper(Activity activity) {
+        this.activity = activity;
+
+    }
+
+}

+ 33 - 0
BaseLibrary/src/main/java/com/cooleshow/base/widgets/LollipopFixedWebView.java

@@ -0,0 +1,33 @@
+package com.cooleshow.base.widgets;
+
+import android.annotation.TargetApi;
+import android.content.Context;
+import android.content.res.Configuration;
+import android.os.Build;
+import android.util.AttributeSet;
+import android.webkit.WebView;
+
+public class LollipopFixedWebView extends WebView {
+    public LollipopFixedWebView(Context context) {
+        super(getFixedContext(context));
+    }
+
+    public LollipopFixedWebView(Context context, AttributeSet attrs) {
+        super(getFixedContext(context), attrs);
+    }
+
+    public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr) {
+        super(getFixedContext(context), attrs, defStyleAttr);
+    }
+
+    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+    public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+        super(getFixedContext(context), attrs, defStyleAttr, defStyleRes);
+    }
+
+    public static Context getFixedContext(Context context) {
+        if (Build.VERSION.SDK_INT >= 21 && Build.VERSION.SDK_INT < 23) // Android Lollipop 5.0 & 5.1
+            return context.createConfigurationContext(new Configuration());
+        return context;
+    }
+}

BIN
BaseLibrary/src/main/res/drawable-xxhdpi/ic_back.png


BIN
BaseLibrary/src/main/res/drawable-xxhdpi/ic_delete.png


BIN
BaseLibrary/src/main/res/drawable-xxhdpi/ic_html_close_stu.png


+ 26 - 0
BaseLibrary/src/main/res/drawable/pg.xml

@@ -0,0 +1,26 @@
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <item android:id="@android:id/background">
+        <shape>
+            <corners android:radius="2dp" />
+            <gradient
+                android:angle="270"
+                android:centerColor="#E3E3E3"
+                android:endColor="#E6E6E6"
+                android:startColor="#C8C8C8" />
+        </shape>
+    </item>
+    <item android:id="@android:id/progress">
+        <clip>
+            <shape>
+                <corners android:radius="2dp" />
+                <gradient
+                    android:centerColor="@color/colorPrimary"
+                    android:endColor="@color/colorPrimary"
+                    android:startColor="@color/colorPrimary" />
+
+            </shape>
+        </clip>
+    </item>
+
+</layer-list>

+ 26 - 0
BaseLibrary/src/main/res/drawable/pg_stu.xml

@@ -0,0 +1,26 @@
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <item android:id="@android:id/background">
+        <shape>
+            <corners android:radius="2dp" />
+            <gradient
+                android:angle="270"
+                android:centerColor="#E3E3E3"
+                android:endColor="#E6E6E6"
+                android:startColor="#C8C8C8" />
+        </shape>
+    </item>
+    <item android:id="@android:id/progress">
+        <clip>
+            <shape>
+                <corners android:radius="2dp" />
+                <gradient
+                    android:centerColor="@color/colorPrimaryStudent"
+                    android:endColor="@color/colorPrimaryStudent"
+                    android:startColor="@color/colorPrimaryStudent" />
+
+            </shape>
+        </clip>
+    </item>
+
+</layer-list>

+ 129 - 0
BaseLibrary/src/main/res/layout/activity_html.xml

@@ -0,0 +1,129 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:id="@+id/rl_activity_html"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:background="@color/white"
+    android:orientation="vertical">
+
+    <FrameLayout
+        android:id="@+id/fl_video"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:layout_below="@+id/ll_activity_html"
+        android:visibility="gone" />
+
+    <FrameLayout
+        android:id="@+id/view_parent"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:layout_below="@+id/ll_activity_html"
+        android:scrollbars="none" />
+
+    <LinearLayout
+        android:id="@+id/ll_activity_html"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="vertical">
+
+        <View
+            android:id="@+id/view_statusbar"
+            android:layout_width="match_parent"
+            android:layout_height="0dp"
+            android:background="@color/white"
+            android:visibility="gone" />
+
+        <ProgressBar
+            android:id="@+id/progressBar"
+            style="?android:attr/progressBarStyleHorizontal"
+            android:layout_width="match_parent"
+            android:layout_height="2dip"
+            android:progressDrawable="@drawable/pg_stu" />
+
+        <androidx.constraintlayout.widget.ConstraintLayout
+            android:id="@+id/header_bar_view"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:orientation="vertical">
+
+            <View
+                android:id="@+id/view"
+                android:layout_width="match_parent"
+                android:layout_height="0dp"
+                app:layout_constraintEnd_toEndOf="parent"
+                app:layout_constraintStart_toStartOf="parent"
+                app:layout_constraintTop_toTopOf="parent" />
+
+            <ImageView
+                android:id="@+id/btn_back"
+                android:layout_width="wrap_content"
+                android:layout_height="@dimen/dp_44"
+                android:paddingStart="@dimen/dp_12"
+                android:paddingEnd="@dimen/dp_12"
+                android:scaleType="center"
+                android:src="@drawable/ic_back"
+                app:layout_constraintStart_toStartOf="parent"
+                app:layout_constraintTop_toBottomOf="@id/view" />
+
+            <ImageView
+                android:id="@+id/btn_close"
+                android:layout_width="wrap_content"
+                android:layout_height="@dimen/dp_44"
+                android:paddingStart="@dimen/dp_12"
+                android:paddingEnd="@dimen/dp_12"
+                android:scaleType="center"
+                android:src="@drawable/ic_html_close_stu"
+                app:layout_constraintStart_toEndOf="@id/btn_back"
+                app:layout_constraintTop_toBottomOf="@id/view" />
+
+            <TextView
+                android:id="@+id/tv_title"
+                android:layout_width="0dp"
+                android:layout_height="@dimen/dp_40"
+                android:layout_marginStart="@dimen/dp_90"
+                android:layout_marginEnd="@dimen/dp_90"
+                android:ellipsize="marquee"
+                android:focusable="true"
+                android:focusableInTouchMode="true"
+                android:gravity="center"
+                android:paddingStart="@dimen/dp_15"
+                android:paddingEnd="@dimen/dp_15"
+                android:singleLine="true"
+                android:textColor="@color/black"
+                android:textSize="@dimen/dp_18"
+                app:layout_constraintEnd_toEndOf="parent"
+                app:layout_constraintStart_toStartOf="parent"
+                app:layout_constraintTop_toBottomOf="@id/view" />
+
+            <TextView
+                android:id="@+id/tv_action"
+                android:layout_width="wrap_content"
+                android:layout_height="@dimen/dp_40"
+                android:gravity="center"
+                android:paddingEnd="@dimen/dp_15"
+                android:text=""
+                android:textColor="@color/black"
+                android:textSize="@dimen/dp_16"
+                android:visibility="invisible"
+                app:layout_constraintEnd_toEndOf="parent"
+                app:layout_constraintTop_toBottomOf="@id/view" />
+
+            <ImageView
+                android:id="@+id/iv_action"
+                android:layout_width="@dimen/dp_44"
+                android:layout_height="@dimen/dp_44"
+                android:layout_marginEnd="@dimen/dp_10"
+                android:padding="@dimen/dp_5"
+                android:scaleType="center"
+                android:src="@drawable/ic_delete"
+                android:visibility="gone"
+                app:layout_constraintBottom_toBottomOf="parent"
+                app:layout_constraintEnd_toEndOf="parent"
+                app:layout_constraintTop_toBottomOf="@id/view" />
+        </androidx.constraintlayout.widget.ConstraintLayout>
+
+    </LinearLayout>
+
+
+</RelativeLayout>

+ 7 - 0
Provider/src/main/java/com/cooleshow/provider/router/RouterPath.kt

@@ -23,6 +23,13 @@ object RouterPath{
         }
     }
 
+    //用户模块
+    class WebCenter{
+        companion object {
+            const val ACTIVITY_HTML = "ui/activity/web/HtmlActivity"
+        }
+    }
+
 
 
     //订单模块