Selaa lähdekoodia

Merge remote-tracking branch 'origin/sheep_develop' into sheep_develop

liujiangyao 7 vuotta sitten
vanhempi
commit
4c27aca957

+ 23 - 4
app/src/main/java/com/sheep/gamegroup/absBase/AbsChooseImageActivity.java

@@ -5,14 +5,13 @@ import android.net.Uri;
 import android.text.TextUtils;
 
 import com.alibaba.fastjson.JSON;
-import com.sheep.gamegroup.util.LogUtil;
-import com.sheep.gamegroup.util.TestUtil;
-import com.sheep.gamegroup.util.upfile.UpFileListener;
-import com.sheep.gamegroup.util.upfile.UpFileUtils;
 import com.sheep.gamegroup.model.api.BaseMessageConverter;
 import com.sheep.gamegroup.model.api.ICallBack;
 import com.sheep.gamegroup.model.entity.UploadResult;
 import com.sheep.gamegroup.util.ListUtil;
+import com.sheep.gamegroup.util.LogUtil;
+import com.sheep.gamegroup.util.upfile.UpFileListener;
+import com.sheep.gamegroup.util.upfile.UpFileUtils;
 import com.sheep.gamegroup.view.dialog.DialogProgress;
 import com.sheep.jiuyan.samllsheep.utils.G;
 import com.yalantis.ucrop.UCrop;
@@ -86,6 +85,26 @@ public abstract class AbsChooseImageActivity extends BaseActivity implements UpF
             G.showToast("暂无截图(若您已经截图,请查看是否开启查看应用使用情况等权限!)");
         }
     }
+    public void showChooseListDialog(boolean isCrop, boolean isUpload, int photoCount, ArrayList<String> imageUriList) {
+        if(!ListUtil.isEmpty(imageUriList)) {
+            photoCount = Math.max(1, photoCount);
+            this.isUpload = isUpload;
+            this.isCrop = isCrop && photoCount == 1;
+            this.photoCount = photoCount;
+            this.photos = null;
+            this.path = null;
+            this.urls.clear();
+            PhotoPicker.builder()
+                    .setPhotoCount(photoCount)
+                    .setShowCamera(showCamera)
+                    .setShowGif(false)
+                    .setPreviewEnabled(true)
+                    .setPicker(imageUriList)
+                    .start(this, PhotoPicker.REQUEST_CODE);
+        } else {
+            G.showToast("暂无截图(若您已经截图,请查看是否开启查看应用使用情况等权限!)");
+        }
+    }
     public void showChooseDialog(boolean isCrop, boolean isUpload, int photoCount, ArrayList<String> imageUriList) {
         photoCount = Math.max(1,photoCount);
         this.isUpload = isUpload;

+ 31 - 0
app/src/main/java/com/sheep/gamegroup/greendao/DDProviderHelper.java

@@ -10,6 +10,8 @@ import com.sheep.gamegroup.greendao.download.DownLoadInfo;
 import com.sheep.gamegroup.greendao.download.DownLoadInfoDao;
 import com.sheep.gamegroup.greendao.download.ProcessRecord;
 import com.sheep.gamegroup.greendao.download.ProcessRecordDao;
+import com.sheep.gamegroup.greendao.download.ScreenShotRecord;
+import com.sheep.gamegroup.greendao.download.ScreenShotRecordDao;
 import com.sheep.jiuyan.samllsheep.service.AutoCheckService;
 
 import java.util.List;
@@ -365,4 +367,33 @@ public class DDProviderHelper {
             acceptTaskRecordDao.deleteAll();
         }
     }
+    /**
+     * 添加截图记录
+     * 添加成功返回true
+     * @param context
+     * @param newInfo
+     */
+    public boolean addScreenShotRecord(Context context, ScreenShotRecord newInfo) {
+        try{
+            ScreenShotRecordDao infoDao = getDaossion(context).getScreenShotRecordDao();
+            infoDao.insert(newInfo);
+        }catch (Exception e){
+            e.printStackTrace();
+            return false;
+        }
+        return true;
+    }
+    /**
+     * 获取对应包名下的截图列表
+     *
+     * @param ctx
+     */
+    public List<ScreenShotRecord> getScreenShotRecordList(Context ctx, String packageName) {
+        return getDaossion(ctx)
+                .getScreenShotRecordDao()
+                .queryBuilder()
+                .where(ScreenShotRecordDao.Properties.PackageName.eq(packageName))
+                .build()
+                .list();
+    }
 }

+ 3 - 0
app/src/main/java/com/sheep/gamegroup/greendao/download/DaoMaster.java

@@ -25,6 +25,7 @@ public class DaoMaster extends AbstractDaoMaster {
         DownLoadInfoDao.createTable(db, ifNotExists);
         ProcessRecordDao.createTable(db, ifNotExists);
         AcceptTaskRecordDao.createTable(db, ifNotExists);
+        ScreenShotRecordDao.createTable(db, ifNotExists);
     }
 
     /** Drops underlying database table using DAOs. */
@@ -33,6 +34,7 @@ public class DaoMaster extends AbstractDaoMaster {
         DownLoadInfoDao.dropTable(db, ifExists);
         ProcessRecordDao.dropTable(db, ifExists);
         AcceptTaskRecordDao.dropTable(db, ifExists);
+        ScreenShotRecordDao.dropTable(db, ifExists);
     }
 
     /**
@@ -55,6 +57,7 @@ public class DaoMaster extends AbstractDaoMaster {
         registerDaoClass(DownLoadInfoDao.class);
         registerDaoClass(ProcessRecordDao.class);
         registerDaoClass(AcceptTaskRecordDao.class);
+        registerDaoClass(ScreenShotRecordDao.class);
     }
 
     public DaoSession newSession() {

+ 14 - 0
app/src/main/java/com/sheep/gamegroup/greendao/download/DaoSession.java

@@ -12,11 +12,13 @@ import com.sheep.gamegroup.greendao.download.AppdownloadBean;
 import com.sheep.gamegroup.greendao.download.DownLoadInfo;
 import com.sheep.gamegroup.greendao.download.ProcessRecord;
 import com.sheep.gamegroup.greendao.download.AcceptTaskRecord;
+import com.sheep.gamegroup.greendao.download.ScreenShotRecord;
 
 import com.sheep.gamegroup.greendao.download.AppdownloadBeanDao;
 import com.sheep.gamegroup.greendao.download.DownLoadInfoDao;
 import com.sheep.gamegroup.greendao.download.ProcessRecordDao;
 import com.sheep.gamegroup.greendao.download.AcceptTaskRecordDao;
+import com.sheep.gamegroup.greendao.download.ScreenShotRecordDao;
 
 // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
 
@@ -31,11 +33,13 @@ public class DaoSession extends AbstractDaoSession {
     private final DaoConfig downLoadInfoDaoConfig;
     private final DaoConfig processRecordDaoConfig;
     private final DaoConfig acceptTaskRecordDaoConfig;
+    private final DaoConfig screenShotRecordDaoConfig;
 
     private final AppdownloadBeanDao appdownloadBeanDao;
     private final DownLoadInfoDao downLoadInfoDao;
     private final ProcessRecordDao processRecordDao;
     private final AcceptTaskRecordDao acceptTaskRecordDao;
+    private final ScreenShotRecordDao screenShotRecordDao;
 
     public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends AbstractDao<?, ?>>, DaoConfig>
             daoConfigMap) {
@@ -53,15 +57,20 @@ public class DaoSession extends AbstractDaoSession {
         acceptTaskRecordDaoConfig = daoConfigMap.get(AcceptTaskRecordDao.class).clone();
         acceptTaskRecordDaoConfig.initIdentityScope(type);
 
+        screenShotRecordDaoConfig = daoConfigMap.get(ScreenShotRecordDao.class).clone();
+        screenShotRecordDaoConfig.initIdentityScope(type);
+
         appdownloadBeanDao = new AppdownloadBeanDao(appdownloadBeanDaoConfig, this);
         downLoadInfoDao = new DownLoadInfoDao(downLoadInfoDaoConfig, this);
         processRecordDao = new ProcessRecordDao(processRecordDaoConfig, this);
         acceptTaskRecordDao = new AcceptTaskRecordDao(acceptTaskRecordDaoConfig, this);
+        screenShotRecordDao = new ScreenShotRecordDao(screenShotRecordDaoConfig, this);
 
         registerDao(AppdownloadBean.class, appdownloadBeanDao);
         registerDao(DownLoadInfo.class, downLoadInfoDao);
         registerDao(ProcessRecord.class, processRecordDao);
         registerDao(AcceptTaskRecord.class, acceptTaskRecordDao);
+        registerDao(ScreenShotRecord.class, screenShotRecordDao);
     }
     
     public void clear() {
@@ -69,6 +78,7 @@ public class DaoSession extends AbstractDaoSession {
         downLoadInfoDaoConfig.clearIdentityScope();
         processRecordDaoConfig.clearIdentityScope();
         acceptTaskRecordDaoConfig.clearIdentityScope();
+        screenShotRecordDaoConfig.clearIdentityScope();
     }
 
     public AppdownloadBeanDao getAppdownloadBeanDao() {
@@ -87,4 +97,8 @@ public class DaoSession extends AbstractDaoSession {
         return acceptTaskRecordDao;
     }
 
+    public ScreenShotRecordDao getScreenShotRecordDao() {
+        return screenShotRecordDao;
+    }
+
 }

+ 82 - 0
app/src/main/java/com/sheep/gamegroup/greendao/download/ScreenShotRecord.java

@@ -0,0 +1,82 @@
+package com.sheep.gamegroup.greendao.download;
+
+import org.greenrobot.greendao.annotation.Entity;
+import org.greenrobot.greendao.annotation.Id;
+import org.greenrobot.greendao.annotation.Property;
+import org.greenrobot.greendao.annotation.Generated;
+
+/**
+ * Created by realicing on 2018/9/26.
+ * realicing@sina.com
+ * 记录截图目录
+ */
+@Entity
+public class ScreenShotRecord {
+    /**
+     * id,
+     */
+    @Id(autoincrement = true)
+    private Long id;
+    /**
+     * 用户id
+     */
+    @Property(nameInDb = "user_id")
+    private String userId;
+    /**
+     * 包名
+     */
+    @Property(nameInDb = "package_name")
+    private String packageName;
+    /**
+     * 截图路径
+     */
+    @Property(nameInDb = "path")
+    private String path;
+    /**
+     * 截图生成的时间
+     */
+    @Property(nameInDb = "create_time")
+    private long createTime;
+    public long getCreateTime() {
+        return this.createTime;
+    }
+    public void setCreateTime(long createTime) {
+        this.createTime = createTime;
+    }
+    public String getPath() {
+        return this.path;
+    }
+    public void setPath(String path) {
+        this.path = path;
+    }
+    public String getPackageName() {
+        return this.packageName;
+    }
+    public void setPackageName(String packageName) {
+        this.packageName = packageName;
+    }
+    public String getUserId() {
+        return this.userId;
+    }
+    public void setUserId(String userId) {
+        this.userId = userId;
+    }
+    public Long getId() {
+        return this.id;
+    }
+    public void setId(Long id) {
+        this.id = id;
+    }
+    @Generated(hash = 2053561572)
+    public ScreenShotRecord(Long id, String userId, String packageName,
+            String path, long createTime) {
+        this.id = id;
+        this.userId = userId;
+        this.packageName = packageName;
+        this.path = path;
+        this.createTime = createTime;
+    }
+    @Generated(hash = 926491684)
+    public ScreenShotRecord() {
+    }
+}

+ 161 - 0
app/src/main/java/com/sheep/gamegroup/greendao/download/ScreenShotRecordDao.java

@@ -0,0 +1,161 @@
+package com.sheep.gamegroup.greendao.download;
+
+import android.database.Cursor;
+import android.database.sqlite.SQLiteStatement;
+
+import org.greenrobot.greendao.AbstractDao;
+import org.greenrobot.greendao.Property;
+import org.greenrobot.greendao.internal.DaoConfig;
+import org.greenrobot.greendao.database.Database;
+import org.greenrobot.greendao.database.DatabaseStatement;
+
+// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
+/** 
+ * DAO for table "SCREEN_SHOT_RECORD".
+*/
+public class ScreenShotRecordDao extends AbstractDao<ScreenShotRecord, Long> {
+
+    public static final String TABLENAME = "SCREEN_SHOT_RECORD";
+
+    /**
+     * Properties of entity ScreenShotRecord.<br/>
+     * Can be used for QueryBuilder and for referencing column names.
+     */
+    public static class Properties {
+        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
+        public final static Property UserId = new Property(1, String.class, "userId", false, "user_id");
+        public final static Property PackageName = new Property(2, String.class, "packageName", false, "package_name");
+        public final static Property Path = new Property(3, String.class, "path", false, "path");
+        public final static Property CreateTime = new Property(4, long.class, "createTime", false, "create_time");
+    }
+
+
+    public ScreenShotRecordDao(DaoConfig config) {
+        super(config);
+    }
+    
+    public ScreenShotRecordDao(DaoConfig config, DaoSession daoSession) {
+        super(config, daoSession);
+    }
+
+    /** Creates the underlying database table. */
+    public static void createTable(Database db, boolean ifNotExists) {
+        String constraint = ifNotExists? "IF NOT EXISTS ": "";
+        db.execSQL("CREATE TABLE " + constraint + "\"SCREEN_SHOT_RECORD\" (" + //
+                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
+                "\"user_id\" TEXT," + // 1: userId
+                "\"package_name\" TEXT," + // 2: packageName
+                "\"path\" TEXT," + // 3: path
+                "\"create_time\" INTEGER NOT NULL );"); // 4: createTime
+    }
+
+    /** Drops the underlying database table. */
+    public static void dropTable(Database db, boolean ifExists) {
+        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"SCREEN_SHOT_RECORD\"";
+        db.execSQL(sql);
+    }
+
+    @Override
+    protected final void bindValues(DatabaseStatement stmt, ScreenShotRecord entity) {
+        stmt.clearBindings();
+ 
+        Long id = entity.getId();
+        if (id != null) {
+            stmt.bindLong(1, id);
+        }
+ 
+        String userId = entity.getUserId();
+        if (userId != null) {
+            stmt.bindString(2, userId);
+        }
+ 
+        String packageName = entity.getPackageName();
+        if (packageName != null) {
+            stmt.bindString(3, packageName);
+        }
+ 
+        String path = entity.getPath();
+        if (path != null) {
+            stmt.bindString(4, path);
+        }
+        stmt.bindLong(5, entity.getCreateTime());
+    }
+
+    @Override
+    protected final void bindValues(SQLiteStatement stmt, ScreenShotRecord entity) {
+        stmt.clearBindings();
+ 
+        Long id = entity.getId();
+        if (id != null) {
+            stmt.bindLong(1, id);
+        }
+ 
+        String userId = entity.getUserId();
+        if (userId != null) {
+            stmt.bindString(2, userId);
+        }
+ 
+        String packageName = entity.getPackageName();
+        if (packageName != null) {
+            stmt.bindString(3, packageName);
+        }
+ 
+        String path = entity.getPath();
+        if (path != null) {
+            stmt.bindString(4, path);
+        }
+        stmt.bindLong(5, entity.getCreateTime());
+    }
+
+    @Override
+    public Long readKey(Cursor cursor, int offset) {
+        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
+    }    
+
+    @Override
+    public ScreenShotRecord readEntity(Cursor cursor, int offset) {
+        ScreenShotRecord entity = new ScreenShotRecord( //
+            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
+            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // userId
+            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // packageName
+            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // path
+            cursor.getLong(offset + 4) // createTime
+        );
+        return entity;
+    }
+     
+    @Override
+    public void readEntity(Cursor cursor, ScreenShotRecord entity, int offset) {
+        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
+        entity.setUserId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
+        entity.setPackageName(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
+        entity.setPath(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
+        entity.setCreateTime(cursor.getLong(offset + 4));
+     }
+    
+    @Override
+    protected final Long updateKeyAfterInsert(ScreenShotRecord entity, long rowId) {
+        entity.setId(rowId);
+        return rowId;
+    }
+    
+    @Override
+    public Long getKey(ScreenShotRecord entity) {
+        if(entity != null) {
+            return entity.getId();
+        } else {
+            return null;
+        }
+    }
+
+    @Override
+    public boolean hasKey(ScreenShotRecord entity) {
+        return entity.getId() != null;
+    }
+
+    @Override
+    protected final boolean isEntityUpdateable() {
+        return true;
+    }
+    
+}

+ 2 - 2
app/src/main/java/com/sheep/gamegroup/usage/AppUsageManager.java

@@ -176,7 +176,7 @@ public class AppUsageManager {
     //未开启查看应用使用情况的权限
     public static final long NOT_OPEN_USAGE_STATS = -1L;
     /**
-     * 获取应用从2018-01-01 0:0:0到现在,在前台运行的时长
+     * 获取应用从指定时间到现在,在前台运行的时长
      * @param packageName
      * @return
      */
@@ -185,7 +185,7 @@ public class AppUsageManager {
             UsageStatsManager mUsageStatsManager = (UsageStatsManager) SheepApp.getInstance().getSystemService(USAGE_STATS_SERVICE);
             long time = System.currentTimeMillis();
             if(mUsageStatsManager != null) {
-                List<UsageStats> usageStatsList = mUsageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_BEST, 1_514_736_000_000L, time);//1_514_736_000_000L 对应 2018-01-01 0:0:0
+                List<UsageStats> usageStatsList = mUsageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_BEST, 1_537_964_279_000L, time);//1_537_964_279_000L 对应 2018-09-26 20:17:59
 
                 if (usageStatsList != null && !usageStatsList.isEmpty()) {
                     for (UsageStats usageStats : usageStatsList) {

+ 15 - 21
app/src/main/java/com/sheep/gamegroup/util/CommonUtil.java

@@ -149,7 +149,7 @@ public class CommonUtil {
     public static String GAME_OPEN = "开始试玩";
     public static String GAME_RESERVATION = "预约游戏";
     public static String TASK_OFFLINE = "任务已下线";
-    public static String TASK_AUDIT = "audit";
+    public static final String TASK_AUDIT = "audit";
     private static CommonUtil commonUtil;
 
     public static CommonUtil getInstance() {
@@ -2529,26 +2529,20 @@ public class CommonUtil {
      * 给任务设置标签
      */
     public void setTaskTag(Context context, View itemView, TaskReleaseEty taskReleaseEty, String show_type ){
-        int from = 0;
-        if(show_type.equals(TASK_AUDIT)){
-            from = 2;
-        }else
-        if(!TextUtils.isEmpty(show_type))
-            from = 1;
-        switch (from) {
-            case 1://来自主页
-                TaskHelper.setTaskTypeText((TextView) itemView.findViewById(R.id.item_num_tv), taskReleaseEty);
-                TaskHelper.setTaskTagText((TextView) itemView.findViewById(R.id.item_num_tv1), taskReleaseEty);
-                TaskHelper.setNumText((TextView) itemView.findViewById(R.id.item_num_tv2), taskReleaseEty);
-                break;
-            case 2:
-                TaskHelper.setTaskTagText((TextView) itemView.findViewById(R.id.item_num_tv), taskReleaseEty);
-                break;
-            default:
-                TaskHelper.setTaskTagText((TextView) itemView.findViewById(R.id.item_num_tv), taskReleaseEty);
-                TaskHelper.setNumText((TextView) itemView.findViewById(R.id.item_num_tv1), taskReleaseEty);
-                break;
+        if(!TextUtils.isEmpty(show_type)){
+            switch (show_type){
+                case TASK_AUDIT:
+                    TaskHelper.setTaskTagText((TextView) itemView.findViewById(R.id.item_num_tv), taskReleaseEty);
+                    break;
+                default:
+                    TaskHelper.setTaskTypeText((TextView) itemView.findViewById(R.id.item_num_tv), taskReleaseEty);
+                    TaskHelper.setTaskTagText((TextView) itemView.findViewById(R.id.item_num_tv1), taskReleaseEty);
+                    TaskHelper.setNumText((TextView) itemView.findViewById(R.id.item_num_tv2), taskReleaseEty);
+                    break;
+            }
+        } else {
+            TaskHelper.setTaskTagText((TextView) itemView.findViewById(R.id.item_num_tv), taskReleaseEty);
+            TaskHelper.setNumText((TextView) itemView.findViewById(R.id.item_num_tv1), taskReleaseEty);
         }
-
     }
 }

+ 19 - 2
app/src/main/java/com/sheep/gamegroup/util/ListUtil.java

@@ -140,6 +140,14 @@ public class ListUtil {
         Collections.addAll(list, items);
         return list;
     }
+    public static <T> ArrayList<T> asList(List<T> itemList) {
+        if(itemList instanceof ArrayList){
+            return (ArrayList<T>) itemList;
+        }
+        ArrayList<T> list = emptyList();
+        addAllItem(list, itemList);
+        return list;
+    }
 
     @SafeVarargs
     public static <T, R> ArrayList<R> asList(CallBack<T, R> callBack, T... items) {
@@ -150,12 +158,21 @@ public class ListUtil {
         }
         return list;
     }
+    public static <T, R> ArrayList<R> asList(CallBack<T, R> callBack, List<T> itemList, CallBack<T, Boolean> filterCallBack) {
+        ArrayList<R> list = emptyList();
+        for (T t : itemList) {
+            R r = callBack.call(t);
+            if(filterCallBack == null || filterCallBack.call(t))
+                list.add(r);
+        }
+        return list;
+    }
 
-    public static <T> List<T> removeItem(List<T> list, CallBack<T, Boolean> callBack) {
+    public static <T> ArrayList<T> removeItem(List<T> list, CallBack<T, Boolean> callBack) {
         if (isEmpty(list)) {
             return null;
         }
-        List<T> removeList = emptyList();
+        ArrayList<T> removeList = emptyList();
         for (T t : list) {
             if (callBack.call(t))
                 removeList.add(t);

+ 21 - 0
app/src/main/java/com/sheep/gamegroup/util/upfile/UpFileUtils.java

@@ -7,12 +7,16 @@ import com.nanchen.compresshelper.CompressHelper;
 import com.sheep.gamegroup.model.api.ICallBack;
 import com.sheep.gamegroup.model.util.ExceptionHandle;
 import com.sheep.jiuyan.samllsheep.SheepApp;
+import com.sheep.jiuyan.samllsheep.service.ListenerShotService;
+import com.sheep.jiuyan.samllsheep.utils.FileUtil;
 import com.zhy.http.okhttp.OkHttpUtils;
 import com.zhy.http.okhttp.callback.Callback;
 
 import java.io.File;
 import java.util.ArrayList;
+import java.util.Locale;
 
+import go.kfzssafe.Kfzssafe;
 import okhttp3.Call;
 import okhttp3.Response;
 import okhttp3.ResponseBody;
@@ -66,6 +70,17 @@ public class UpFileUtils {
             File file;
             if ((file = new File(photos.get(index))).exists()) {
                 File newFile = null;
+                if(ListenerShotService.IS_RECORD_PATH) {
+                    try {
+                        if (!Kfzssafe.isPng(file.getAbsolutePath())) {
+                            String toFilePath = String.format(Locale.CHINA, "%s%s_%d.png", file.getParent(), File.separator, System.currentTimeMillis());
+                            FileUtil.convertImage(file.getAbsolutePath(), toFilePath, Bitmap.CompressFormat.PNG);
+                            file = new File(toFilePath);
+                        }
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                }
                 try {
                     newFile = new CompressHelper.Builder(SheepApp.getInstance())
                             .setMaxWidth(1080)  // 默认最大宽度为720
@@ -78,6 +93,12 @@ public class UpFileUtils {
                 }
                 if(newFile == null || !newFile.exists()){
                     newFile = file;
+                } else {
+                    if(ListenerShotService.IS_RECORD_PATH) {
+                        if(file.delete()){
+                            file = null;
+                        }
+                    }
                 }
                 try {
                     if(action1 != null)

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

@@ -29,6 +29,7 @@ import com.sheep.gamegroup.greendao.DDProviderHelper;
 import com.sheep.gamegroup.greendao.download.AcceptTaskRecord;
 import com.sheep.gamegroup.greendao.download.DownLoadInfo;
 import com.sheep.gamegroup.greendao.download.ProcessRecord;
+import com.sheep.gamegroup.greendao.download.ScreenShotRecord;
 import com.sheep.gamegroup.helper.TaskHelper;
 import com.sheep.gamegroup.model.api.ICallBack;
 import com.sheep.gamegroup.model.api.IDownload;
@@ -67,6 +68,7 @@ import com.sheep.jiuyan.samllsheep.BuildConfig;
 import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.service.AutoCheckService;
+import com.sheep.jiuyan.samllsheep.service.ListenerShotService;
 import com.sheep.jiuyan.samllsheep.utils.G;
 import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
 import com.sheep.jiuyan.samllsheep.utils.SpUtils;
@@ -937,8 +939,23 @@ public class TaskDetailAct extends AbsChooseImageActivity implements TaskDetailC
         }
         if (commitScreenShotTaskId > 0) {
             if ((DataUtil.IS_USE_SCREEN_SHOT || DataUtil.IS_LISTEN_SCREEN_SHOT) && taskEty.needShotScreen()) {//小绵羊截图方案与监听方案
-                File dir = DataUtil.getScreenShotsDir(taskEty.getPackage_names());
-                showChooseDialog(false, true, DEFAULT_MAX_COUNT, dir);
+                if(ListenerShotService.IS_RECORD_PATH){//使用记录的方式来获取用户的截图
+                    List<ScreenShotRecord> list = DDProviderHelper.getInstance().getScreenShotRecordList(activity, taskEty.getPackage_names());
+                    showChooseListDialog(false, true, DEFAULT_MAX_COUNT, ListUtil.asList(new ListUtil.CallBack<ScreenShotRecord, String>() {
+                        @Override
+                        public String call(ScreenShotRecord screenShotRecord) {
+                            return screenShotRecord.getPath();
+                        }
+                    }, list, new ListUtil.CallBack<ScreenShotRecord, Boolean>() {
+                        @Override
+                        public Boolean call(ScreenShotRecord screenShotRecord) {
+                            return new File(screenShotRecord.getPath()).exists();
+                        }
+                    }));
+                } else {
+                    File dir = DataUtil.getScreenShotsDir(taskEty.getPackage_names());
+                    showChooseDialog(false, true, DEFAULT_MAX_COUNT, dir);
+                }
             } else {//用户手动截图方案
                 ArrayList<String> imageUriList = DataUtil.getAllScreenShotList();
 

+ 16 - 4
app/src/main/java/com/sheep/jiuyan/samllsheep/service/ListenerShotService.java

@@ -15,6 +15,8 @@ import android.support.annotation.Nullable;
 import android.text.TextUtils;
 import android.widget.RemoteViews;
 
+import com.sheep.gamegroup.greendao.DDProviderHelper;
+import com.sheep.gamegroup.greendao.download.ScreenShotRecord;
 import com.sheep.gamegroup.util.ListUtil;
 import com.sheep.gamegroup.util.LogUtil;
 import com.sheep.gamegroup.util.RunningTaskUtil;
@@ -79,7 +81,6 @@ public class ListenerShotService extends Service {
         //这里的id不能是0
         startForeground(113922, notification);
     }
-
     @Nullable
     @Override
     public IBinder onBind(Intent intent) {
@@ -158,6 +159,18 @@ public class ListenerShotService extends Service {
             return;
         }
         LogUtil.println("ScreenShotListenManager", packageName);
+        if (IS_RECORD_PATH) {//使用记录的方式来获取用户的截图
+            ScreenShotRecord screenShotRecord = new ScreenShotRecord();
+            screenShotRecord.setCreateTime(System.currentTimeMillis());
+            screenShotRecord.setPackageName(packageName);
+            screenShotRecord.setPath(imagePath);
+            DDProviderHelper.getInstance().addScreenShotRecord(getApplicationContext(), screenShotRecord);
+        } else {
+            delayCopyImage(imagePath, packageName);
+        }
+    }
+    public static final boolean IS_RECORD_PATH = true;//是否直接记录截图文件路径,而不是复制截图到私有目录
+    private void delayCopyImage(final String imagePath, final String packageName) {
         Observable.just(1).delay(1, TimeUnit.SECONDS)
                 .subscribeOn(Schedulers.io())
                 .observeOn(AndroidSchedulers.mainThread())
@@ -166,7 +179,7 @@ public class ListenerShotService extends Service {
                     public void call(Integer integer) {
                         try {
                             File toDir = getScreenShotsDir(getApplicationContext(), packageName);
-                            if(Kfzssafe.isPng(imagePath)){
+                            if (Kfzssafe.isPng(imagePath)) {
                                 FileUtil.copyFileToDir(new File(imagePath), toDir);
                             } else {
                                 String toFilePath = String.format(Locale.CHINA, "%s%s%s_%d.png", toDir.getAbsolutePath(), File.separator, packageName, System.currentTimeMillis());
@@ -175,9 +188,8 @@ public class ListenerShotService extends Service {
                         } catch (Exception e) {
                             LogUtil.println("ScreenShotListenManager", "复制截屏图片失败", e.getMessage());
                         }
-                    }
+                        }
                 });
-
     }
 
     /**

+ 15 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/utils/FileUtil.java

@@ -121,4 +121,19 @@ public class FileUtil {
         BitmapFactory.decodeFile(file.getAbsolutePath(), options); // 此时返回的bitmap为null
         return options;
     }
+    /**
+     * 图片是否已损毁或不完整
+     * @param file
+     * @return
+     */
+    public static boolean isNotImage(File file) {
+        BitmapFactory.Options options = new BitmapFactory.Options();
+        /**
+         * 最关键在此,把options.inJustDecodeBounds = true;
+         * 这里再decodeFile(),返回的bitmap为空,但此时调用options.outHeight时,已经包含了图片的高了
+         */
+        options.inJustDecodeBounds = true;
+        BitmapFactory.decodeFile(file.getAbsolutePath(), options); // 此时返回的bitmap为null
+        return options.mCancel || options.outWidth == -1 || options.outHeight == -1;
+    }
 }