Procházet zdrojové kódy

通过TextView来显示h5,但是不支持视频播放;
添加签到刮奖

zengjiebin před 7 roky
rodič
revize
b562f18899

+ 0 - 18
app/src/main/java/com/lqr/emoji/HtmlTvUtil.java

@@ -1,18 +0,0 @@
-package com.lqr.emoji;
-
-import android.text.Html;
-import android.widget.TextView;
-
-import com.sheep.gamegroup.util.ResImageGetter;
-
-import java.util.Locale;
-
-/**
- * Created by realicing on 2018/11/8.
- * realicing@sina.com
- */
-public class HtmlTvUtil {
-    public static void setHtmlToTv(TextView textView,  String content){
-        textView.setText(Html.fromHtml(content, new ResImageGetter(textView), null));
-    }
-}

+ 5 - 0
app/src/main/java/com/sheep/gamegroup/model/api/ApiService.java

@@ -1324,6 +1324,11 @@ public interface ApiService {
     @GET("app/user_sign/signs")
     Observable<BaseMessage> getUserSignSigns();
     /**
+     * 获取最后一次刮奖结果
+     */
+    @GET("app/user_sign/last_scratch")
+    Observable<BaseMessage> getUserSignLastScratch();
+    /**
      * 每日签到
      */
     @POST("app/user_sign/sign_in")

+ 12 - 0
app/src/main/java/com/sheep/gamegroup/model/entity/NoviceGuidance.java

@@ -45,6 +45,8 @@ public class NoviceGuidance implements IContentTypeContainer<Integer, String> {
 
     private String video_url;
 
+    private String image_url;
+
     public void setContent(String content){
         this.content = content;
         contentType = StringUtils.initContentType(content);
@@ -96,12 +98,22 @@ public class NoviceGuidance implements IContentTypeContainer<Integer, String> {
         return this.video_url;
     }
 
+    public String getImage_url() {
+        return image_url;
+    }
+
+    public void setImage_url(String image_url) {
+        this.image_url = image_url;
+    }
+
 //    //默认类型,服务器数据无此类型,只作为客户端自己直接添加使用,只包含内容
 //    public static final int TYPE_MSG = 0;
 //    //标题与文本
 //    public static final int TYPE_CONTENT = 1;
 //    //标题与文本与视频
 //    public static final int TYPE_VIDEO = 2;
+//    //标题与文本与图片
+//    public static final int TYPE_VIDEO = 3;
 
     //content的类型
     private int contentType;

+ 20 - 0
app/src/main/java/com/sheep/gamegroup/model/entity/RechargeLogEntity.java

@@ -1,5 +1,10 @@
 package com.sheep.gamegroup.model.entity;//
 
+import android.text.TextUtils;
+
+import com.sheep.gamegroup.util.TimeUtil;
+
+import java.util.Calendar;
 import java.util.Locale;
 
 /**
@@ -177,4 +182,19 @@ public class RechargeLogEntity implements ILog {
     public boolean getSelect() {
         return isSelect();
     }
+
+
+
+
+
+    //今日的数据
+    public boolean isToday() {
+        String format = "yyyyMMdd";
+        return TextUtils.equals(TimeUtil.TimeStamp2Date(create_time * 1000, format), TimeUtil.TimeStamp2Date(System.currentTimeMillis(), format));
+    }
+
+    //空数据
+    public boolean isNull() {
+        return id == 0;
+    }
 }

+ 46 - 5
app/src/main/java/com/sheep/gamegroup/util/ResImageGetter.java

@@ -1,14 +1,22 @@
 package com.sheep.gamegroup.util;
 
 import android.content.res.Resources;
+import android.graphics.BitmapFactory;
 import android.graphics.drawable.Drawable;
 import android.text.Html;
 import android.widget.TextView;
 
+import com.sheep.gamegroup.util.viewHelper.CacheImageUtil;
 import com.sheep.jiuyan.samllsheep.BuildConfig;
+import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.utils.G;
 
+import java.io.File;
+import java.util.Locale;
+
+import rx.functions.Action1;
+
 /**
  * Created by realicing on 2018/11/7.
  * realicing@sina.com
@@ -16,16 +24,49 @@ import com.sheep.jiuyan.samllsheep.utils.G;
 public class ResImageGetter implements Html.ImageGetter {
 
     private int textSize;
-
-    public ResImageGetter(TextView textView) {
+    private int maxWidth;
+    private TextView textView;
+    private String content;
+    public ResImageGetter(TextView textView, String content, int maxWidth) {
+        this.textView = textView;
+        this.content = content;
+        this.maxWidth = maxWidth;
         textSize = G.getRealPix(60);
     }
 
     @Override
     public Drawable getDrawable(final String source) {
         Resources resources = SheepApp.getInstance().getResources();
-        Drawable drawable = resources.getDrawable(resources.getIdentifier(source, "mipmap", BuildConfig.APPLICATION_ID));
-        drawable.setBounds(0, 0, textSize, textSize);
-        return drawable;
+        int id = resources.getIdentifier(source, "mipmap", BuildConfig.APPLICATION_ID);
+        if(id > 0) {
+            Drawable drawable = resources.getDrawable(id);
+            drawable.setBounds(0, 0, textSize, textSize);
+            return drawable;
+        } else {
+            String path = CacheImageUtil.getCacheImg(source);
+            if(path != null){
+                Drawable drawable = Drawable.createFromPath(path);
+                if(drawable != null){
+                    int imgWidth = G.getRealPix(drawable.getMinimumWidth());
+                    int imgHeight = G.getRealPix(drawable.getMinimumHeight());
+                    if(imgWidth > maxWidth && maxWidth > 0){
+                        imgHeight = (int) (maxWidth * imgHeight * 1.0f / imgWidth);
+                        imgWidth = maxWidth;
+                    }
+                    drawable.setBounds(0, 0, imgWidth, imgHeight);
+                    return drawable;
+                }
+            }
+            Drawable drawable = resources.getDrawable(R.drawable.loading_01);
+            drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
+            CacheImageUtil.cacheImg(source, new Action1<File>() {
+                @Override
+                public void call(File file) {
+                    if(file != null)
+                        ViewUtil.setH5ImgText(textView, content, maxWidth);
+                }
+            });
+            return drawable;
+        }
     }
 }

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

@@ -320,7 +320,7 @@ public class StringUtils {
         boolean hasExp = EmotionLayout.hasExp(content);
         if(hasExp){
             return CONTENT_TYPE_EXP;
-        } else if(content.contains("<p>")){
+        } else if(content.contains("<p>") || content.contains("<br>")){
             return CONTENT_TYPE_H5;
         } else {
             return CONTENT_TYPE_FONT;

+ 2 - 1
app/src/main/java/com/sheep/gamegroup/util/TextViewUtil.java

@@ -6,6 +6,7 @@ import android.view.View;
 import android.widget.TextView;
 
 import com.sheep.gamegroup.model.entity.ShowAll;
+import com.sheep.jiuyan.samllsheep.utils.G;
 
 import rx.functions.Action1;
 
@@ -50,7 +51,7 @@ public class TextViewUtil {
         boolean isFirst = showAll.isFirst();
 
         if(showAll.isHasExp())
-            ViewUtil.setH5ImgText(intro_content, showAll.getContent());
+            ViewUtil.setH5ImgText(intro_content, showAll.getContent(), G.WIDTH - G.getRealPix(50));
         else
             ViewUtil.setText(intro_content, showAll.getContent());
         if (isFirst) {

+ 6 - 5
app/src/main/java/com/sheep/gamegroup/util/ViewUtil.java

@@ -926,13 +926,13 @@ public class ViewUtil {
         }
     }
 
-    public static void setH5ImgText(TextView textView, String content) {
+    public static void setH5ImgText(TextView textView, String content, int maxWidth) {
         if (textView != null) {
             if (TextUtils.isEmpty(content)) {
                 textView.setText("");
                 return;
             }
-            textView.setText(Html.fromHtml(content, new ResImageGetter(textView), null));
+            textView.setText(Html.fromHtml(content, new ResImageGetter(textView, content, maxWidth), null));
         }
     }
 
@@ -1517,16 +1517,17 @@ public class ViewUtil {
         }
     }
 
-    public static void setText(TextView textView, IContentTypeContainer<Integer, String> contentTypeContainer) {
+    public static void setText(TextView textView, IContentTypeContainer<Integer, String> contentTypeContainer, int maxWidth) {
         switch (contentTypeContainer.getContentType()) {
             case StringUtils.CONTENT_TYPE_FONT:
                 setText(textView, contentTypeContainer.getContentResult());
                 break;
             case StringUtils.CONTENT_TYPE_H5:
-                setH5Text(textView, contentTypeContainer.getContentResult());
+//                setH5Text(textView, contentTypeContainer.getContentResult());
+                setH5ImgText(textView, contentTypeContainer.getContentResult(), maxWidth);
                 break;
             case StringUtils.CONTENT_TYPE_EXP:
-                setH5ImgText(textView, contentTypeContainer.getContentResult());
+                setH5ImgText(textView, contentTypeContainer.getContentResult(), maxWidth);
                 break;
         }
     }

+ 74 - 0
app/src/main/java/com/sheep/gamegroup/util/viewHelper/CacheImageUtil.java

@@ -0,0 +1,74 @@
+package com.sheep.gamegroup.util.viewHelper;
+
+import android.content.Context;
+
+import com.sheep.gamegroup.util.DataUtil;
+import com.sheep.jiuyan.samllsheep.SheepApp;
+import com.zhy.http.okhttp.OkHttpUtils;
+import com.zhy.http.okhttp.callback.FileCallBack;
+
+import java.io.File;
+
+import okhttp3.Call;
+import rx.functions.Action1;
+
+/**
+ * Created by realicing on 2018/11/13.
+ * realicing@sina.com
+ * 缓存图片工具类
+ */
+public class CacheImageUtil {
+
+    //已经缓存图片
+    public static String getCacheImg(String link) {
+        String name = String.valueOf(link.hashCode());
+        String fileName = name + ".png";
+        File file = new File(getImgCacheDirPath(), fileName);
+        if(file.exists() && DataUtil.getAsInt("sheep_png_" + name, STATE_NOE) == STATE_SUCCESS){
+            return file.getAbsolutePath();
+        }
+        return null;
+    }
+
+    public static final int STATE_NOE = 0;//无状态
+    public static final int STATE_DOWNLOAD = 1;//下载中
+    public static final int STATE_ERROR = 2;//下载失败
+    public static final int STATE_SUCCESS = 3;//下载成功
+
+    //缓存图片
+    public static void cacheImg(String link, final Action1<File> action1) {
+        final String name = String.valueOf(link.hashCode());
+        String fileName = name + ".png";
+        if (DataUtil.getAsInt("sheep_png_" + name, STATE_NOE) == STATE_DOWNLOAD) {//这里不好处理
+            return;
+        }
+        DataUtil.putAsInt("sheep_png_" + name, STATE_DOWNLOAD);
+        OkHttpUtils.get().url(link).build().execute(new FileCallBack(getImgCacheDirPath(), fileName) {
+            @Override
+            public void onError(Call call, Exception e, int id) {
+                DataUtil.putAsInt("sheep_png_" + name, STATE_ERROR);
+                if (action1 != null) {
+                    action1.call(null);
+                }
+            }
+
+            @Override
+            public void onResponse(File response, int id) {
+                if (response.exists()) {
+                    DataUtil.putAsInt("sheep_png_" + name, STATE_SUCCESS);
+                    if (action1 != null) {
+                        action1.call(response);
+                    }
+                }
+            }
+        });
+    }
+
+    public static File getImgCacheDir() {
+        return SheepApp.getInstance().getDir("img", Context.MODE_PRIVATE);
+    }
+
+    public static String getImgCacheDirPath() {
+        return SheepApp.getInstance().getDir("img", Context.MODE_PRIVATE).getPath();
+    }
+}

+ 235 - 0
app/src/main/java/com/sheep/gamegroup/util/viewHelper/WebViewVideoHelper.java

@@ -0,0 +1,235 @@
+package com.sheep.gamegroup.util.viewHelper;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.pm.ActivityInfo;
+import android.graphics.PixelFormat;
+import android.os.Build;
+import android.util.Log;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.WindowManager;
+import android.webkit.WebChromeClient;
+import android.webkit.WebSettings;
+import android.webkit.WebView;
+import android.webkit.WebViewClient;
+import android.widget.FrameLayout;
+
+import com.sheep.gamegroup.util.ActivityManager;
+import com.sheep.gamegroup.util.CommonUtil;
+import com.sheep.gamegroup.util.LogUtil;
+import com.sheep.jiuyan.samllsheep.SheepApp;
+
+/**
+ * Created by realicing on 2018/11/13.
+ * realicing@sina.com
+ */
+public class WebViewVideoHelper {
+    private WebView webView;
+    private Activity activity;
+
+
+    /**
+     * 视频全屏参数
+     */
+    protected final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
+    private View customView;
+    private FrameLayout fullscreenContainer;
+    private WebChromeClient.CustomViewCallback customViewCallback;
+
+    public void init(Activity activity, WebView webView) {
+        this.activity = activity;
+        this.webView = webView;
+        initWebView();
+        CommonUtil.getInstance().setDownloadListener(ActivityManager.getInstance().currentActivity(), webView);
+    }
+
+    public void initWebView() {
+        WebSettings webSetting = webView.getSettings();
+        webSetting.setJavaScriptEnabled(true);
+        webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
+        webSetting.setAllowFileAccess(true);
+        webSetting.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
+//        webSetting.setSupportZoom(true);
+//        webSetting.setBuiltInZoomControls(true);
+//        webSetting.setUseWideViewPort(true);
+        //下面这行会影响setDownloadListener,暂时注释掉,等有空研究一下
+//        webSetting.setSupportMultipleWindows(true);
+        webSetting.setAppCacheEnabled(true);
+        webSetting.setDatabaseEnabled(true);
+        webSetting.setDomStorageEnabled(true);
+        webSetting.setGeolocationEnabled(true);
+        webSetting.setAppCacheMaxSize(Long.MAX_VALUE);
+        webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND);
+        webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH);
+        webSetting.setCacheMode(android.webkit.WebSettings.LOAD_NO_CACHE);
+
+
+        webSetting.setCacheMode(android.webkit.WebSettings.LOAD_DEFAULT);
+        webSetting.setLoadWithOverviewMode(true);
+        activity.getWindow().setFormat(PixelFormat.TRANSLUCENT);
+        webView.setWebChromeClient(new WebChromeClient() {
+
+            /**视频播放相关的方法*
+             *
+             */
+
+
+            @Override
+            public View getVideoLoadingProgressView() {
+                FrameLayout frameLayout = new FrameLayout(SheepApp.getInstance());
+                frameLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+                return frameLayout;
+            }
+
+            @Override
+            public void onShowCustomView(View view, CustomViewCallback callback) {
+                super.onShowCustomView(view, callback);
+                showCustomView(view, callback);
+                activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//设置横屏
+            }
+
+            @Override
+            public void onHideCustomView() {
+                hideCustomView();
+                activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//设置竖屏
+                super.onHideCustomView();
+            }
+        });
+        webView.setWebViewClient(new WebViewClient() {
+            @Override
+            public boolean shouldOverrideUrlLoading(WebView view, String url) {
+                LogUtil.println(getClass().getSimpleName(), "shouldOverrideUrlLoading", url);
+                //Android8.0以下的需要返回true 并且需要loadUrl;8.0之后效果相反
+                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+                    return false;
+                }
+                webView.loadUrl(url);
+                return true;
+            }
+        });
+    }
+
+    /**
+     * 视频播放全屏
+     */
+
+    private void showCustomView(View view, WebChromeClient.CustomViewCallback callback) {
+        // if a view already exists then immediately terminate the new one
+        if (customView != null) {
+            callback.onCustomViewHidden();
+            return;
+        }
+
+        activity.getWindow().getDecorView();
+
+        FrameLayout decor = (FrameLayout) activity.getWindow().getDecorView();
+        fullscreenContainer = new FullscreenHolder(activity);
+        fullscreenContainer.addView(view, COVER_SCREEN_PARAMS);
+        decor.addView(fullscreenContainer, COVER_SCREEN_PARAMS);
+        customView = view;
+        setStatusBarVisibility(false);
+        customViewCallback = callback;
+    }
+
+
+    private void setStatusBarVisibility(boolean visible) {
+        int flag = visible ? 0 : WindowManager.LayoutParams.FLAG_FULLSCREEN;
+        activity.getWindow().setFlags(flag, WindowManager.LayoutParams.FLAG_FULLSCREEN);
+        Log.i("bar------", visible + "");
+    }
+
+    /**
+     * 隐藏视频全屏
+     */
+    private void hideCustomView() {
+        if (customView == null) {
+            return;
+        }
+
+        setStatusBarVisibility(true);
+        FrameLayout decor = (FrameLayout) activity.getWindow().getDecorView();
+        decor.removeView(fullscreenContainer);
+        fullscreenContainer = null;
+        customView = null;
+        customViewCallback.onCustomViewHidden();
+        webView.setVisibility(View.VISIBLE);
+    }
+
+    public void onBackUp() {
+/**回退键 事件处理 优先级:
+ 视频播放全屏 - 网页回退 - 关闭页面*/
+        if (customView != null) {
+            hideCustomView();
+        } else if (webView != null && webView.canGoBack()) {
+            webView.goBack();
+        } else {
+            activity.finish();
+        }
+    }
+
+    public boolean onBackPressed() {
+        if (webView != null && webView.canGoBack()) {
+            webView.goBack();
+            return true;
+        }
+        return false;
+    }
+    public void onResume(){
+        try {
+            if (webView != null) {
+//                webView.resumeTimers();
+                webView.onResume();
+                webView.getClass().getMethod("onResume").invoke(webView, (Object[]) null);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+
+    public void onPause() {
+        if (webView != null) {
+            webView.onPause();
+            //            webView.pauseTimers();
+            try {
+                webView.getClass().getMethod("onPause").invoke(webView, (Object[]) null);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+    }
+    public void onDestroy() {
+        if (webView != null) {
+//            webView.onPause();
+//            webView.freeMemory();
+//            webView.removeAllViews();
+            webView.destroy();
+//            webView = null;
+        }
+    }
+
+    /**
+     * 全屏容器界面
+     */
+
+
+    class FullscreenHolder extends FrameLayout {
+
+        public FullscreenHolder(Context ctx) {
+            super(ctx);
+            setBackgroundColor(ctx.getResources().getColor(android.R.color.black));
+        }
+
+        @Override
+        public boolean onTouchEvent(MotionEvent evt) {
+            switch (evt.getAction()) {
+                case MotionEvent.ACTION_POINTER_UP:
+                    break;
+            }
+            return true;
+        }
+    }
+
+}

+ 31 - 222
app/src/main/java/com/sheep/gamegroup/view/activity/ActArticle.java

@@ -1,29 +1,19 @@
 package com.sheep.gamegroup.view.activity;
 
 import android.app.Activity;
-import android.content.Context;
 import android.content.Intent;
-import android.content.pm.ActivityInfo;
 import android.content.res.Configuration;
-import android.graphics.PixelFormat;
-import android.os.Build;
 import android.support.v4.widget.SwipeRefreshLayout;
 import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
 import android.text.TextUtils;
-import android.util.Log;
 import android.view.KeyEvent;
 import android.view.LayoutInflater;
-import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.WindowManager;
-import android.webkit.WebChromeClient;
-import android.webkit.WebSettings;
 import android.webkit.WebView;
-import android.webkit.WebViewClient;
 import android.widget.EditText;
-import android.widget.FrameLayout;
 import android.widget.ImageView;
 import android.widget.RelativeLayout;
 import android.widget.TextView;
@@ -32,9 +22,9 @@ import com.sheep.gamegroup.absBase.BaseActivity;
 import com.sheep.gamegroup.event.BigEvent;
 import com.sheep.gamegroup.greendao.download.DownLoadInfo;
 import com.sheep.gamegroup.helper.TaskHelper;
-import com.sheep.gamegroup.model.entity.BaseMessage;
 import com.sheep.gamegroup.model.entity.Applications;
 import com.sheep.gamegroup.model.entity.Article;
+import com.sheep.gamegroup.model.entity.BaseMessage;
 import com.sheep.gamegroup.model.util.SheepSubscriber;
 import com.sheep.gamegroup.util.CommonUtil;
 import com.sheep.gamegroup.util.DataUtil;
@@ -47,6 +37,7 @@ import com.sheep.gamegroup.util.SysAppUtil;
 import com.sheep.gamegroup.util.TimeUtil;
 import com.sheep.gamegroup.util.ViewHolder;
 import com.sheep.gamegroup.util.ViewUtil;
+import com.sheep.gamegroup.util.viewHelper.WebViewVideoHelper;
 import com.sheep.gamegroup.view.adapter.AdbCommonRecycler;
 import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.SheepApp;
@@ -84,16 +75,6 @@ public class ActArticle extends BaseActivity implements Action1<Integer> {
 
     private int id;
 
-    /**
-     * 视频全屏参数
-     */
-
-
-    protected final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
-    private View customView;
-    private FrameLayout fullscreenContainer;
-    private WebChromeClient.CustomViewCallback customViewCallback;
-
 
     @BindView(R.id.refresh)
     SwipeRefreshLayout refresh;
@@ -107,8 +88,7 @@ public class ActArticle extends BaseActivity implements Action1<Integer> {
     RelativeLayout bottom;
     //输入框
     private EditText input_comment_input;
-    WebView webView;
-
+    private WebViewVideoHelper webViewVideoHelper = new WebViewVideoHelper();
     @Override
     public void initView() {
         id = getIntent().getIntExtra("id", 0);
@@ -191,162 +171,6 @@ public class ActArticle extends BaseActivity implements Action1<Integer> {
     }
 
 
-    public void initWebView() {
-        WebSettings webSetting = webView.getSettings();
-        webSetting.setJavaScriptEnabled(true);
-        webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
-        webSetting.setAllowFileAccess(true);
-        webSetting.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
-//        webSetting.setSupportZoom(true);
-//        webSetting.setBuiltInZoomControls(true);
-//        webSetting.setUseWideViewPort(true);
-        //下面这行会影响setDownloadListener,暂时注释掉,等有空研究一下
-//        webSetting.setSupportMultipleWindows(true);
-        webSetting.setAppCacheEnabled(true);
-        webSetting.setDatabaseEnabled(true);
-        webSetting.setDomStorageEnabled(true);
-        webSetting.setGeolocationEnabled(true);
-        webSetting.setAppCacheMaxSize(Long.MAX_VALUE);
-        webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND);
-        webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH);
-        webSetting.setCacheMode(android.webkit.WebSettings.LOAD_NO_CACHE);
-
-
-        webSetting.setCacheMode(android.webkit.WebSettings.LOAD_DEFAULT);
-        webSetting.setLoadWithOverviewMode(true);
-        getWindow().setFormat(PixelFormat.TRANSLUCENT);
-        webView.setWebChromeClient(new WebChromeClient() {
-
-            /**视频播放相关的方法*
-             *
-             */
-
-
-            @Override
-            public View getVideoLoadingProgressView() {
-                FrameLayout frameLayout = new FrameLayout(ActArticle.this);
-                frameLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
-                return frameLayout;
-            }
-
-            @Override
-            public void onShowCustomView(View view, CustomViewCallback callback) {
-                super.onShowCustomView(view, callback);
-                showCustomView(view, callback);
-                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//设置横屏
-            }
-
-            @Override
-            public void onHideCustomView() {
-                hideCustomView();
-                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//设置竖屏
-                super.onHideCustomView();
-            }
-        });
-        webView.setWebViewClient(new WebViewClient() {
-            @Override
-            public boolean shouldOverrideUrlLoading(WebView view, String url) {
-                LogUtil.println(getClass().getSimpleName(), "shouldOverrideUrlLoading", url);
-                //Android8.0以下的需要返回true 并且需要loadUrl;8.0之后效果相反
-                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
-                    return false;
-                }
-                webView.loadUrl(url);
-                return true;
-            }
-        });
-    }
-
-    /**
-     * 视频播放全屏
-     */
-
-    private void showCustomView(View view, WebChromeClient.CustomViewCallback callback) {
-        // if a view already exists then immediately terminate the new one
-        if (customView != null) {
-            callback.onCustomViewHidden();
-            return;
-        }
-
-        ActArticle.this.getWindow().getDecorView();
-
-        FrameLayout decor = (FrameLayout) getWindow().getDecorView();
-        fullscreenContainer = new FullscreenHolder(ActArticle.this);
-        fullscreenContainer.addView(view, COVER_SCREEN_PARAMS);
-        decor.addView(fullscreenContainer, COVER_SCREEN_PARAMS);
-        customView = view;
-        setStatusBarVisibility(false);
-        customViewCallback = callback;
-    }
-
-    /**
-     * 隐藏视频全屏
-     */
-
-
-    private void hideCustomView() {
-        if (customView == null) {
-            return;
-        }
-
-        setStatusBarVisibility(true);
-        FrameLayout decor = (FrameLayout) getWindow().getDecorView();
-        decor.removeView(fullscreenContainer);
-        fullscreenContainer = null;
-        customView = null;
-        customViewCallback.onCustomViewHidden();
-        webView.setVisibility(View.VISIBLE);
-    }
-
-    /**
-     * 全屏容器界面
-     */
-
-
-    class FullscreenHolder extends FrameLayout {
-
-        public FullscreenHolder(Context ctx) {
-            super(ctx);
-            setBackgroundColor(ctx.getResources().getColor(android.R.color.black));
-        }
-
-        @Override
-        public boolean onTouchEvent(MotionEvent evt) {
-            switch (evt.getAction()) {
-                case MotionEvent.ACTION_POINTER_UP:
-                    break;
-            }
-            return true;
-        }
-    }
-
-    private void setStatusBarVisibility(boolean visible) {
-        int flag = visible ? 0 : WindowManager.LayoutParams.FLAG_FULLSCREEN;
-        getWindow().setFlags(flag, WindowManager.LayoutParams.FLAG_FULLSCREEN);
-        Log.i("bar------", visible + "");
-    }
-
-    @Override
-    public boolean onKeyUp(int keyCode, KeyEvent event) {
-        switch (keyCode) {
-            case KeyEvent.KEYCODE_BACK:
-/**回退键 事件处理 优先级:
- 视频播放全屏 - 网页回退 - 关闭页面*/
-
-                if (customView != null) {
-                    hideCustomView();
-                } else if (webView != null && webView.canGoBack()) {
-                    webView.goBack();
-                } else {
-                    finish();
-                }
-                return true;
-            default:
-                return super.onKeyUp(keyCode, event);
-        }
-    }
-
-
     private void loadTop(View itemView) {
         TextView find_information_name = (TextView) itemView.findViewById(R.id.find_information_name);
         TextView find_information_time = (TextView) itemView.findViewById(R.id.find_information_time);
@@ -355,9 +179,8 @@ public class ActArticle extends BaseActivity implements Action1<Integer> {
         ViewUtil.setText(find_information_time, String.format(Locale.CHINA, "发布时间:%s", TimeUtil.TimeStamp2Date(article.getCreated_at(), "yyyy-MM-dd HH:mm")));
         ViewUtil.setText(find_information_look, article.getClicks());
 
-        webView = itemView.findViewById(R.id.find_information_content_wb);
-        initWebView();
-        CommonUtil.getInstance().setDownloadListener(ActArticle.this, webView);
+        WebView webView = itemView.findViewById(R.id.find_information_content_wb);
+        webViewVideoHelper.init(this, webView);
         ViewUtil.loadDataWithBaseURL(webView, article.getContent());
 
 
@@ -674,31 +497,40 @@ public class ActArticle extends BaseActivity implements Action1<Integer> {
     protected void onResume() {
         super.onResume();
         taskHelper.onResume();
-        try {
-            if (webView != null) {
-//                webView.resumeTimers();
-                webView.onResume();
-                webView.getClass().getMethod("onResume").invoke(webView, (Object[]) null);
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
+        webViewVideoHelper.onResume();
     }
 
+
+
+    @Override
+    public boolean onKeyUp(int keyCode, KeyEvent event) {
+        switch (keyCode) {
+            case KeyEvent.KEYCODE_BACK:
+                webViewVideoHelper.onBackUp();
+                return true;
+            default:
+                return super.onKeyUp(keyCode, event);
+        }
+    }
+    @Override
+    public void onBackPressed() {
+        if(webViewVideoHelper.onBackPressed()){
+            return;
+        }
+        super.onBackPressed();
+    }
+    @Override
+    protected void onPause() {
+        super.onPause();
+        webViewVideoHelper.onPause();
+    }
     @Override
     protected void onDestroy() {
         LogUtil.logI("释放资源");
         EventBus.getDefault().unregister(this);
         taskHelper.destroy();
-        if (webView != null) {
-//            webView.onPause();
-//            webView.freeMemory();
-//            webView.removeAllViews();
-            webView.destroy();
-//            webView = null;
-        }
+        webViewVideoHelper.onDestroy();
         super.onDestroy();
-        ActArticle.this.finish();
     }
 
     @Override
@@ -710,29 +542,6 @@ public class ActArticle extends BaseActivity implements Action1<Integer> {
         }
     }
 
-    @Override
-    protected void onPause() {
-        super.onPause();
-        if (webView != null) {
-            webView.onPause();
-//            webView.pauseTimers();
-            try {
-                webView.getClass().getMethod("onPause").invoke(webView, (Object[]) null);
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-        }
-    }
-
-    @Override
-    public void onBackPressed() {
-        if (webView != null && webView.canGoBack()) {
-            webView.goBack();
-            return;
-        }
-        super.onBackPressed();
-    }
-
 
     @Override
     public void onConfigurationChanged(Configuration config) {

+ 19 - 18
app/src/main/java/com/sheep/gamegroup/view/activity/ActMain.java

@@ -438,24 +438,25 @@ public class ActMain extends BaseActYmPermissionCheck  {
     public void onEventMainThread(Intent intent) {
         if (intent != null && intent.getAction() != null && intent.getDataString() != null && intent.getDataString().contains("package:")) {
             String packageName = intent.getDataString().replace("package:", "");
-
-            TextView tvProgress = progressView.findViewWithTag(PUBLIC_TAG_PREFIX_TEXTVIEW_LIST + url);
-            if (tvProgress != null && downloadHelper != null && TextUtils.equals(packageName, this.packageName)) {
-                switch (intent.getAction()) {
-                    case ACTION_PACKAGE_ADDED:
-                        tvProgress.setText(CommonUtil.GAME_OPEN);
-                        downloadHelper.updateState(DownloadUtil.STATUS_INSTALLED);
-                        break;
-                    case ACTION_PACKAGE_REMOVED:
-                        String path = PackageUtil.isExistsFile(packageName, url);
-                        if (TextUtils.isEmpty(path)) {
-                            downloadHelper.updateState(DownloadUtil.STATUS_INIT);
-                            tvProgress.setText(CommonUtil.START_DOWNLOAD);
-                        } else {
-                            downloadHelper.updateState(DownloadUtil.STATUS_FINISH);
-                            tvProgress.setText(CommonUtil.START_INSTALL);
-                        }
-                        break;
+            if(progressView != null) {
+                TextView tvProgress = progressView.findViewWithTag(PUBLIC_TAG_PREFIX_TEXTVIEW_LIST + url);
+                if (tvProgress != null && downloadHelper != null && TextUtils.equals(packageName, this.packageName)) {
+                    switch (intent.getAction()) {
+                        case ACTION_PACKAGE_ADDED:
+                            tvProgress.setText(CommonUtil.GAME_OPEN);
+                            downloadHelper.updateState(DownloadUtil.STATUS_INSTALLED);
+                            break;
+                        case ACTION_PACKAGE_REMOVED:
+                            String path = PackageUtil.isExistsFile(packageName, url);
+                            if (TextUtils.isEmpty(path)) {
+                                downloadHelper.updateState(DownloadUtil.STATUS_INIT);
+                                tvProgress.setText(CommonUtil.START_DOWNLOAD);
+                            } else {
+                                downloadHelper.updateState(DownloadUtil.STATUS_FINISH);
+                                tvProgress.setText(CommonUtil.START_INSTALL);
+                            }
+                            break;
+                    }
                 }
             }
         }

+ 3 - 1
app/src/main/java/com/sheep/gamegroup/view/activity/ActTestExpression.java

@@ -14,6 +14,7 @@ import com.sheep.gamegroup.absBase.BaseActivity;
 import com.sheep.gamegroup.util.ResImageGetter;
 import com.sheep.gamegroup.util.ViewUtil;
 import com.sheep.jiuyan.samllsheep.R;
+import com.sheep.jiuyan.samllsheep.utils.G;
 import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
 
 import java.util.Locale;
@@ -82,7 +83,8 @@ public class ActTestExpression extends BaseActivity {
 
     //提交数据
     private void commitComment(String content) {
-        test_content.setText(Html.fromHtml(String.format(Locale.CHINA, "%s<img src=\"%s\" />", content, "exp_666"), new ResImageGetter(test_content), null));
+        String msg = String.format(Locale.CHINA, "%s<img src=\"%s\" />", content, "exp_666");
+        test_content.setText(Html.fromHtml(msg, new ResImageGetter(test_content, msg, G.WIDTH), null));
     }
 
     //点击x来清空输入内容

+ 5 - 1
app/src/main/java/com/sheep/gamegroup/view/adapter/AdpNoviceGuidance.java

@@ -14,6 +14,7 @@ import com.sheep.gamegroup.util.Jump2View;
 import com.sheep.gamegroup.util.ListUtil;
 import com.sheep.gamegroup.util.ViewUtil;
 import com.sheep.jiuyan.samllsheep.R;
+import com.sheep.jiuyan.samllsheep.utils.G;
 
 import java.util.List;
 
@@ -30,6 +31,7 @@ public class AdpNoviceGuidance extends RecyclerViewAdapter<NoviceGuidance> {
     public void convert(ViewHolder viewHolder, final NoviceGuidance item, int position) {
         TextView item_novice_guidance_title = viewHolder.itemView.findViewById(R.id.item_novice_guidance_title);
 //        VideoView item_novice_guidance_video = viewHolder.itemView.findViewById(R.id.item_novice_guidance_video);
+        final ImageView item_novice_guidance_image = viewHolder.itemView.findViewById(R.id.item_novice_guidance_image);
         final ImageView item_novice_guidance_video_image = viewHolder.itemView.findViewById(R.id.item_novice_guidance_video_image);
         final ImageView item_novice_guidance_video_control = viewHolder.itemView.findViewById(R.id.item_novice_guidance_video_control);
         final ImageView item_novice_guidance_video_full = viewHolder.itemView.findViewById(R.id.item_novice_guidance_video_full);
@@ -37,6 +39,7 @@ public class AdpNoviceGuidance extends RecyclerViewAdapter<NoviceGuidance> {
 
         ViewUtil.setVisibility(item_novice_guidance_title, !TextUtils.isEmpty(item.getTitle()));
         ViewUtil.setVisibility(item_novice_guidance_content, !TextUtils.isEmpty(item.getContent()));
+        ViewUtil.setVisibility(item_novice_guidance_image, !TextUtils.isEmpty(item.getImage_url()));
 //        ViewUtil.setVisibility(item_novice_guidance_video, !TextUtils.isEmpty(item.getVideo_url()));
         ViewUtil.setVisibility(item_novice_guidance_video_control, !TextUtils.isEmpty(item.getVideo_url()));
         ViewUtil.setVisibility(item_novice_guidance_video_image, !TextUtils.isEmpty(item.getVideo_url()));
@@ -44,8 +47,9 @@ public class AdpNoviceGuidance extends RecyclerViewAdapter<NoviceGuidance> {
 
         ViewUtil.setImage(item_novice_guidance_video_full, ViewUtil.getNetImgByName("fangda"));
         ViewUtil.setImage(item_novice_guidance_video_image, item.getVideo_url());
+        ViewUtil.setImage(item_novice_guidance_image, item.getImage_url());
         ViewUtil.setText(item_novice_guidance_title, item.getTitle());
-        ViewUtil.setText(item_novice_guidance_content, item);
+        ViewUtil.setText(item_novice_guidance_content, item, G.WIDTH - G.getRealPix(32));
 //        ViewUtil.setVideoAndFull(item_novice_guidance_video, item_novice_guidance_video_image, item_novice_guidance_video_control, item.getVideo_url());
         item_novice_guidance_video_control.setOnClickListener(new View.OnClickListener() {
             @Override

+ 35 - 3
app/src/main/java/com/sheep/jiuyan/samllsheep/ui/activity/SignActivity.java

@@ -14,6 +14,7 @@ import com.kfzs.duanduan.utils.NumberFormatUtils;
 import com.sheep.gamegroup.model.entity.BaseMessage;
 import com.sheep.gamegroup.model.entity.Lp;
 import com.sheep.gamegroup.model.entity.PunchAndSign;
+import com.sheep.gamegroup.model.entity.RechargeLogEntity;
 import com.sheep.gamegroup.model.entity.RobTask;
 import com.sheep.gamegroup.model.entity.SheepSignResult;
 import com.sheep.gamegroup.model.entity.UserSign;
@@ -24,7 +25,6 @@ import com.sheep.gamegroup.util.DataUtil;
 import com.sheep.gamegroup.util.Jump2View;
 import com.sheep.gamegroup.util.ListUtil;
 import com.sheep.gamegroup.util.LogUtil;
-import com.sheep.gamegroup.util.TestUtil;
 import com.sheep.gamegroup.util.TimeUtil;
 import com.sheep.gamegroup.util.ViewUtil;
 import com.sheep.gamegroup.util.viewHelper.LayoutParamsUtil;
@@ -156,8 +156,31 @@ public class SignActivity extends BaseActivity implements UMShareListener {
     @Override
     protected void onData() {
         initSigns();
+        initUserSignLastScratch();
         initSignCardData();
     }
+    //是否完成最后一次刮奖数据的获取
+    private boolean isFinishInitLastScratch = false;
+    //最后一次刮奖数据
+    private RechargeLogEntity rechargeLogEntity;
+    private void initUserSignLastScratch() {
+        SheepApp.getInstance().getNetComponent().getApiService().getUserSignLastScratch()
+                        .subscribeOn(Schedulers.io())
+                        .observeOn(AndroidSchedulers.mainThread())
+                        .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
+                            @Override
+                            public void onNext(BaseMessage baseMessage) {
+                                rechargeLogEntity = baseMessage.getData(RechargeLogEntity.class);
+                                isFinishInitLastScratch = true;
+                                updateGignGuajiang();
+
+                            }
+
+                            @Override
+                            public void onError(BaseMessage baseMessage) {
+                            }
+                        });
+    }
 
     private void initSignCardData() {
         SheepApp.getInstance().getNetComponent().getApiService().getPunchAndSignCount()
@@ -217,6 +240,7 @@ public class SignActivity extends BaseActivity implements UMShareListener {
                                 ViewUtil.setText(signNowBut, isSignToday ? "已签到" : "签到");
 //                                        ViewUtil.setEnabled(signNowBut, !isSignToday);
                             }
+                            updateGignGuajiang();
                         } else {
                             G.showToast(R.string.service_data_error);
                         }
@@ -282,6 +306,14 @@ public class SignActivity extends BaseActivity implements UMShareListener {
 //                });
     }
 
+    //更新刮奖显示状态
+    private void updateGignGuajiang() {
+        if(isFinishInitLastScratch && ListUtil.size(userSignList) == SIGN_PERIOD && (rechargeLogEntity == null || !rechargeLogEntity.isToday())){
+            //一个周期完成且今日没有刮奖时,可以进行刮奖
+            ViewUtil.setVisibility(signGuajiang, true);
+        }
+    }
+
     //签到周期
     public static final int SIGN_PERIOD = 6;
 
@@ -522,9 +554,9 @@ public class SignActivity extends BaseActivity implements UMShareListener {
                 .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
                     @Override
                     public void onNext(BaseMessage baseMessage) {
-                        Float aFloat = baseMessage.getData(Float.class, DEFAULT_FLOAT);
+                        SheepSignResult sheepSignResult = baseMessage.getData(SheepSignResult.class);
                         signGuajiang.setVisibility(View.GONE);
-                        tryShowSignResultAndTask("刮奖成功", aFloat);
+                        tryShowSignResultAndTask("刮奖成功", sheepSignResult.getAmount());
                     }
 
                     @Override

+ 13 - 1
app/src/main/res/layout/item_novice_guidance.xml

@@ -32,13 +32,25 @@
     <!--app:layout_constraintTop_toBottomOf="@id/item_novice_guidance_title" />-->
 
     <ImageView
+        android:id="@+id/item_novice_guidance_image"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginStart="16dp"
+        android:layout_marginTop="16dp"
+        android:layout_marginEnd="16dp"
+        android:adjustViewBounds="true"
+        android:scaleType="fitCenter"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toBottomOf="@id/item_novice_guidance_title" />
+    <ImageView
         android:id="@+id/item_novice_guidance_video_image"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginStart="16dp"
         android:layout_marginTop="16dp"
         android:layout_marginEnd="16dp"
-        android:minHeight="140dp"
+        android:minHeight="190dp"
         android:adjustViewBounds="true"
         android:scaleType="fitCenter"
         app:layout_constraintEnd_toEndOf="parent"