Просмотр исходного кода

内部h5加载优化(添加进度与加载中gif图片)

zengjiebin лет назад: 7
Родитель
Сommit
92c687fd56

+ 0 - 24
app/src/main/assets/loadImg.html

@@ -1,24 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
-    <meta charset="UTF-8">
-    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
-    <meta http-equiv="X-UA-Compatible" content="ie=edge">
-    <title></title>
-</head>
-<style>
-    * {
-        margin:0;
-        padding:0;
-    }
-</style>
-<body>
-    <img id="img" style="width:100vw" alt="">
-</body>
-<script>
-    function imgsrc(path){
-		var img = document.getElementById("img");
-			img.src = path;
-	}
-</script>
-</html>

+ 28 - 3
app/src/main/java/com/sheep/gamegroup/model/entity/WebParams.java

@@ -2,6 +2,8 @@ package com.sheep.gamegroup.model.entity;
 
 import android.text.TextUtils;
 
+import com.sheep.jiuyan.samllsheep.SheepApp;
+
 import java.io.Serializable;
 
 /**
@@ -12,7 +14,7 @@ public class WebParams implements Serializable {
     private String url;//要加载的网页地址
     private String jsUrl;//要注入的js的网页地址
     private String title = "加载中";//页面默认标题
-    private boolean needJsInteract = false;
+    private boolean needJsInteract = true;
     private boolean showTitle = true;
     private String tokenKey = "authorization";
 
@@ -22,7 +24,7 @@ public class WebParams implements Serializable {
 
     public WebParams(String url, String title) {
         this.url = url;
-        if(!TextUtils.isEmpty(title))
+        if (!TextUtils.isEmpty(title))
             this.title = title;
     }
 
@@ -45,6 +47,7 @@ public class WebParams implements Serializable {
         this.tokenKey = tokenKey;
         return this;
     }
+
     public WebParams tokenFirstUpperCase() {
         String start = tokenKey.substring(0, 1).toUpperCase();
         String end = tokenKey.substring(1);
@@ -53,7 +56,7 @@ public class WebParams implements Serializable {
     }
 
     public WebParams setTitle(String title) {
-        if(!TextUtils.isEmpty(title))
+        if (!TextUtils.isEmpty(title))
             this.title = title;
         return this;
     }
@@ -86,4 +89,26 @@ public class WebParams implements Serializable {
     public String getTokenKey() {
         return tokenKey;
     }
+
+
+    //有些内部h5界面不显示标题,是通过js方法来设置的,会导致屏幕闪一下,所以暂时加一下筛选
+    public WebParams checkShowTitle() {
+        if (title != null) {
+            if (TextUtils.equals(SheepApp.getInstance().getConnectAddress().getName(), "sheep")) {
+                switch (title) {
+                    case "幸运大转盘":
+                        showTitle = false;
+                        break;
+                }
+            } else {
+                switch (title) {
+                    case "3.4.5大转盘":
+                    case "娱乐抽奖":
+                        showTitle = false;
+                        break;
+                }
+            }
+        }
+        return this;
+    }
 }

+ 11 - 11
app/src/main/java/com/sheep/gamegroup/util/GlideImageLoader.java

@@ -36,72 +36,72 @@ import rx.functions.Action1;
 
 public class GlideImageLoader {
 
-    public static void setBlur(ImageView imageView, String url) {
+    public static void setBlur(ImageView imageView, Object url) {
         Glide.with(SheepApp.getInstance())
                 .load(url)
                 .apply(new RequestOptions().transform(new BlurTransformation()))
                 .into(imageView);
     }
-    public static void setImage(ImageView imageView, String url) {
+    public static void setImage(ImageView imageView, Object url) {
         Glide.with(SheepApp.getInstance())
                 .load(url)
                 .into(imageView);
     }
-    public static void setImage(ImageView imageView, String url, int id) {
+    public static void setImage(ImageView imageView, Object url, int id) {
         Glide.with(SheepApp.getInstance())
                 .load(url)
                 .apply(new RequestOptions().placeholder(id))
                 .into(imageView);
     }
-    public static void setImageDisHardConfig(ImageView imageView, String url) {
+    public static void setImageDisHardConfig(ImageView imageView, Object url) {
         Glide.with(SheepApp.getInstance())
                 .load(url)
                 .apply(new RequestOptions().disallowHardwareConfig())
                 .into(imageView);
     }
 
-    public static void centerImage(ImageView imageView, String url, int id) {
+    public static void centerImage(ImageView imageView, Object url, int id) {
         Glide.with(SheepApp.getInstance())
                 .load(url)
                 .apply(new RequestOptions().centerCrop().placeholder(id))
                 .into(imageView);
     }
 
-    public static void centerImage(ImageView imageView, String path) {
+    public static void centerImage(ImageView imageView, Object path) {
         Glide.with(SheepApp.getInstance())
                 .load(path)
                 .apply(new RequestOptions().centerCrop().placeholder(R.drawable.loading_01))
                 .into(imageView);
     }
 
-    public static void circleImage(ImageView imageView, String url, int id) {
+    public static void circleImage(ImageView imageView, Object url, int id) {
         Glide.with(SheepApp.getInstance())
                 .load(url)
                 .apply(new RequestOptions().circleCrop().placeholder(id))
                 .into(imageView);
     }
 
-    public static void circleImage(ImageView imageView, String url) {
+    public static void circleImage(ImageView imageView, Object url) {
         Glide.with(SheepApp.getInstance())
                 .load(url)
                 .apply(new RequestOptions().circleCrop().placeholder(R.drawable.loading_01))
                 .into(imageView);
     }
 
-    public static void roundedCornersImage(ImageView imageView, String url, int radius, int id) {
+    public static void roundedCornersImage(ImageView imageView, Object url, int radius, int id) {
         Glide.with(SheepApp.getInstance())
                 .load(url)
                 .apply(new RequestOptions().transform(new RoundedCornersTransformation(radius, 0)).placeholder(id))
                 .into(imageView);
     }
 
-    public static void roundedCornersImage(ImageView imageView, String url, int radius) {
+    public static void roundedCornersImage(ImageView imageView, Object url, int radius) {
         Glide.with(SheepApp.getInstance())
                 .load(url)
                 .apply(new RequestOptions().transform(new RoundedCornersTransformation(radius, 0)).placeholder(R.drawable.loading_01))
                 .into(imageView);
     }
-    public static void roundedCornersImage1(ImageView imageView, String url, int radius) {
+    public static void roundedCornersImage1(ImageView imageView, Object url, int radius) {
         Glide.with(SheepApp.getInstance())
                 .load(url)
                 .apply(new RequestOptions().centerCrop().transform(new RoundedCorners(radius)))

+ 10 - 1
app/src/main/java/com/sheep/gamegroup/util/Jump2View.java

@@ -967,7 +967,7 @@ public class Jump2View {
      * @param webParams
      */
     public void goWeb(Context context, WebParams webParams) {
-        String url = webParams.getUrl();
+        String url = webParams.checkShowTitle().getUrl();
         if (TextUtils.isEmpty(url)) {
             G.showToast(R.string.service_data_error);
             return;
@@ -2481,6 +2481,15 @@ public class Jump2View {
      * 小绵羊3.4.7新增 -- 跳转VIP介绍界面
      * @param activity
      */
+    public void gotoVip(Activity activity) {
+        String url = SheepApp.getInstance().getConnectAddress().getVipUrl();
+        WebParams webParams = new WebParams(url).setShowTitle(false);
+        goWeb(activity, webParams);
+    }
+    /**
+     * 小绵羊3.4.7新增 -- 跳转VIP介绍界面
+     * @param activity
+     */
     public void goActVip(Activity activity) {
         Intent intent = new Intent(activity, ActVip.class);
         activity.startActivity(intent);

+ 3 - 4
app/src/main/java/com/sheep/gamegroup/util/js/BaseActWeb.java

@@ -3,7 +3,6 @@ package com.sheep.gamegroup.util.js;
 import android.view.View;
 import android.webkit.WebView;
 
-import com.sheep.gamegroup.absBase.BaseActivity;
 import com.sheep.gamegroup.absBase.BaseUMActivity;
 import com.sheep.gamegroup.model.entity.UserEntity;
 import com.sheep.gamegroup.util.CommonUtil;
@@ -42,10 +41,10 @@ public abstract class BaseActWeb extends BaseUMActivity {
 
 
     public static String addUrlToken(String url) {
-        return addUrl(url, "authorization", SpUtils.getToken(SheepApp.getInstance()));
+        return addUrlQuery(url, "authorization", SpUtils.getToken(SheepApp.getInstance()));
     }
 
-    public static String addUrl(String url, String key, String value) {
+    public static String addUrlQuery(String url, String key, String value) {
         return url + ((url.contains("?") || url.contains("#") && url.contains("=")) ? "&" : "?") + key + "=" + value;
     }
     public void setH5Type(String h5Type) {
@@ -65,7 +64,7 @@ public abstract class BaseActWeb extends BaseUMActivity {
                                         }
 //                                是否是联通卡分享 1:是 0:不是
 //                                分享链接需要加个 is_unicom  参数
-                                        String url = addUrl(userEntity.getShareLink(), "is_unicom", "1");
+                                        String url = addUrlQuery(userEntity.getShareLink(), "is_unicom", "1");
                                         new ShareLinkConfig().setLink(url).setTitle("下载小绵羊,免费领取联通大/小天神卡").toShare(BaseActWeb.this);
                                     }
                                 });

+ 1 - 2
app/src/main/java/com/sheep/gamegroup/view/activity/ActMyMoney.java

@@ -33,7 +33,6 @@ import com.sheep.gamegroup.util.Jump2View;
 import com.sheep.gamegroup.util.RefreshUtil;
 import com.sheep.gamegroup.util.ViewUtil;
 import com.sheep.gamegroup.view.adapter.TitleFragmentListAdapter;
-import com.sheep.gamegroup.view.fragment.BaseListFragment3;
 import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.utils.G;
@@ -280,7 +279,7 @@ public class ActMyMoney extends BaseActivity {
 
     //点击VIP
     public void onClickVip(View view) {
-        Jump2View.getInstance().goActVip(this);
+        Jump2View.getInstance().gotoVip(this);
     }
 
     //点击游戏直充

+ 40 - 38
app/src/main/java/com/sheep/gamegroup/view/activity/ActWebX5.java

@@ -14,12 +14,16 @@ import android.support.v7.app.ActionBar;
 import android.support.v7.app.AlertDialog;
 import android.text.TextUtils;
 import android.view.View;
+import android.view.animation.Animation;
+import android.view.animation.AnimationUtils;
+import android.widget.ImageView;
+import android.widget.ProgressBar;
 
-import com.sheep.gamegroup.absBase.IJumpWeb;
 import com.sheep.gamegroup.model.entity.WebParams;
 import com.sheep.gamegroup.module.webview.util.WebResourceRequestAdapter;
 import com.sheep.gamegroup.module.webview.util.WebResourceResponseAdapter;
 import com.sheep.gamegroup.util.CommonUtil;
+import com.sheep.gamegroup.util.GlideImageLoader;
 import com.sheep.gamegroup.util.Jump2View;
 import com.sheep.gamegroup.util.LogUtil;
 import com.sheep.gamegroup.util.NetUtil;
@@ -64,6 +68,10 @@ public class ActWebX5 extends BaseActWeb {
 
     @BindView(R.id.webview)
     WebView mWebView;
+    @BindView(R.id.act_web_loading_pb)
+    ProgressBar act_web_loading_pb;
+    @BindView(R.id.act_web_loading_iv)
+    ImageView act_web_loading_iv;
     private WebParams webParams;
     private WebSettings webViewSettings;
 
@@ -75,6 +83,8 @@ public class ActWebX5 extends BaseActWeb {
     @RequiresApi(api = Build.VERSION_CODES.KITKAT)
     @Override
     public void initView() {
+        GlideImageLoader.setImage(act_web_loading_iv, R.drawable.gif_sheep_loading);
+
         Intent intent = getIntent();
         webParams = (WebParams) intent.getSerializableExtra(WebParams.class.getSimpleName());
         String url = webParams.getUrl();
@@ -253,10 +263,29 @@ public class ActWebX5 extends BaseActWeb {
 
             @Override
             public void onProgressChanged(WebView view, int newProgress) {
-                if (newProgress == 100) {
-                    String action = "javascript:imgsrc('" + url + "')";
-                    runWebviewUrl(action);
+                LogUtil.println("ActWeb", "onProgressChanged", newProgress);
+                if (newProgress == 100 && ViewUtil.isVisible(act_web_loading_iv)) {
+                    Animation animation = AnimationUtils.loadAnimation(SheepApp.getInstance(), R.anim.anim_alpha_1_0);
+                    animation.setAnimationListener(new Animation.AnimationListener() {
+                        @Override
+                        public void onAnimationStart(Animation animation) {
+
+                        }
+
+                        @Override
+                        public void onAnimationEnd(Animation animation) {
+                            ViewUtil.setVisibility(act_web_loading_iv, false);
+                        }
+
+                        @Override
+                        public void onAnimationRepeat(Animation animation) {
+
+                        }
+                    });
+                    act_web_loading_iv.startAnimation(animation);
                 }
+                ViewUtil.setVisibility(act_web_loading_pb, newProgress != 100);
+                act_web_loading_pb.setProgress(newProgress);
                 super.onProgressChanged(view, newProgress);
             }
         });
@@ -330,26 +359,21 @@ public class ActWebX5 extends BaseActWeb {
             public void onPageFinished(WebView view, String url) {
                 LogUtil.println("ActWeb", "onPageFinished", url);
                 super.onPageFinished(view, url);
-                imgReset();
                 loadJs();
             }
         });
         webViewSettings.setJavaScriptEnabled(true);
+
         if (webParams.isNeedJsInteract()) {
             mWebView.addJavascriptInterface(new KFZSJs(this), "kfzsjs");
-            String loadUrl = addUrl(url, webParams.getTokenKey(), SpUtils.getToken(SheepApp.getInstance()));
-            LogUtil.println("ActWeb loadUrl = " + loadUrl);
-            if (CommonUtil.getInstance().judgeUrlPicture(url)) {
-                runWebviewUrl("file:///android_asset/loadImg.html");
-            } else {
-                webViewLoadUrl(mWebView, loadUrl);
+            String loadUrl = url;
+            if(webParams.getTokenKey() != null){
+                loadUrl = addUrlQuery(url, webParams.getTokenKey(), SpUtils.getToken(SheepApp.getInstance()));
             }
+            LogUtil.println("ActWeb loadUrl = " + loadUrl);
+            webViewLoadUrl(mWebView, loadUrl);
         } else {
-            if (CommonUtil.getInstance().judgeUrlPicture(url)) {
-                runWebviewUrl("file:///android_asset/loadImg.html");
-            } else {
-                webViewLoadUrl(mWebView, url);
-            }
+            webViewLoadUrl(mWebView, url);
         }
     }
 
@@ -439,28 +463,6 @@ public class ActWebX5 extends BaseActWeb {
         }
     }
 
-    private void imgReset() {
-        ViewUtil.loadJs(mWebView, "(function(){" +
-                "var objs = document.getElementsByTagName('img'); " +
-                "for(var i=0;i<objs.length;i++)  " +
-                "{"
-                + "var img = objs[i];   " +
-                " img.style.maxWidth = '100%';" +
-                "}" +
-                "})()");
-    }
-
-    private void runWebviewUrl(final String url) {
-        runOnUiThread(new Runnable() {
-            @Override
-            public void run() {
-                if (mWebView != null && !TextUtils.isEmpty(url)) {
-                    webViewLoadUrl(mWebView, url);
-                }
-            }
-        });
-    }
-
     // 注入js函数监听
     public void loadJs() {
         if (TextUtils.isEmpty(js))

+ 2 - 3
app/src/main/java/com/sheep/gamegroup/view/activity/TaskDetailAct.java

@@ -40,7 +40,6 @@ import com.sheep.gamegroup.model.entity.TaskChild;
 import com.sheep.gamegroup.model.entity.TaskDescEntity;
 import com.sheep.gamegroup.model.entity.TaskEty;
 import com.sheep.gamegroup.model.entity.Release_task;
-import com.sheep.gamegroup.model.entity.UserEntity;
 import com.sheep.gamegroup.model.util.EntityUtils;
 import com.sheep.gamegroup.model.util.SheepSubscriber;
 import com.sheep.gamegroup.presenter.TaskDetailContract;
@@ -885,10 +884,10 @@ public class TaskDetailAct extends AbsChooseImageActivity implements TaskDetailC
                         });
                     break;
                 case R.id.task_detail_vip_cl:
-                    Jump2View.getInstance().goActVip(this);
+                    Jump2View.getInstance().gotoVip(this);
                     break;
                 case R.id.task_detail_pay_vip_tv:
-                    Jump2View.getInstance().goActVip(this);
+                    Jump2View.getInstance().gotoVip(this);
                     break;
             }
         } catch (Exception e) {

+ 1 - 1
app/src/main/java/com/sheep/gamegroup/view/fragment/FgtPersonalCenter.java

@@ -435,7 +435,7 @@ public class FgtPersonalCenter extends BaseFragment {
                 Jump2View.getInstance().goPersionInfo(activity, null);
                 break;
             case R.id.fgt_pc_item_vip_ll://VIP
-                Jump2View.getInstance().goActVip(activity);
+                Jump2View.getInstance().gotoVip(activity);
                 break;
             case R.id.personalcenter_price_layout://我的资产
                 Jump2View.getInstance().goMyMoney(activity, null);

+ 10 - 0
app/src/main/res/anim/anim_alpha_1_0.xml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<set xmlns:android="http://schemas.android.com/apk/res/android"
+    android:fillAfter="true"
+    android:interpolator="@android:interpolator/accelerate_decelerate">
+
+    <alpha
+        android:duration="500"
+        android:fromAlpha="1"
+        android:toAlpha="0" />
+</set>

BIN
app/src/main/res/drawable-xxhdpi/gif_sheep_loading.gif


+ 24 - 9
app/src/main/res/layout/act_web_x5.xml

@@ -1,16 +1,31 @@
 <?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:orientation="vertical"
-    android:fitsSystemWindows="true"
-    android:background="@color/white_F9F9F9">
+    android:background="@color/white_F9F9F9"
+    android:fitsSystemWindows="true">
 
     <com.tencent.smtt.sdk.WebView
         android:id="@+id/webview"
         android:layout_width="match_parent"
-        android:layout_height="0dp"
-        android:layout_weight="1"
-        android:scrollbars="none"
-        android:background="@drawable/x_shap_shadow_bg_rectgangle_white"/>
-</LinearLayout>
+        android:layout_height="match_parent"
+        android:background="@drawable/x_shap_shadow_bg_rectgangle_white"
+        android:scrollbars="none" />
+
+    <ProgressBar
+        android:id="@+id/act_web_loading_pb"
+        style="?android:attr/progressBarStyleHorizontal"
+        android:layout_width="match_parent"
+        android:layout_height="2dp"
+        android:layout_alignParentTop="true"
+        android:max="100"
+        android:progress="0"
+        android:progressDrawable="@drawable/lay_list_progress_yellow" />
+
+    <ImageView
+        android:id="@+id/act_web_loading_iv"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_centerInParent="true" />
+
+</RelativeLayout>