Browse Source

延时进行下一步动作,防止动作不生效;
不再直接复制监听到的图片,而是把非png的图片转换为png格式

zengjiebin 7 years ago
parent
commit
3dc942f1c9

+ 1 - 1
app/build.gradle

@@ -171,7 +171,7 @@ dependencies {
 
 
     //不要修改这里,相信我
     //不要修改这里,相信我
     releaseCompile 'com.android.support:multidex:1.0.3'
     releaseCompile 'com.android.support:multidex:1.0.3'
-    compile(name: 'com.kfzs.safe', ext: 'aar')
+    compile(name: 'com.kfzs.safe-201809211354', ext: 'aar')
 
 
     //butterknife
     //butterknife
     compile 'com.jakewharton:butterknife:8.8.1'
     compile 'com.jakewharton:butterknife:8.8.1'

BIN
app/libs/com.kfzs.safe-201809211354.aar


BIN
app/libs/com.kfzs.safe.aar


+ 17 - 2
app/src/main/java/com/sheep/gamegroup/absBase/BaseActivity.java

@@ -7,8 +7,14 @@ import android.support.v7.app.AppCompatActivity;
 import com.sheep.gamegroup.util.DataUtil;
 import com.sheep.gamegroup.util.DataUtil;
 import com.sheep.gamegroup.view.dialog.DialogLoading;
 import com.sheep.gamegroup.view.dialog.DialogLoading;
 
 
+import java.util.concurrent.TimeUnit;
+
 import butterknife.ButterKnife;
 import butterknife.ButterKnife;
 import butterknife.Unbinder;
 import butterknife.Unbinder;
+import rx.Observable;
+import rx.android.schedulers.AndroidSchedulers;
+import rx.functions.Action1;
+import rx.schedulers.Schedulers;
 
 
 /**
 /**
  * Created by kemllor on 2017/12/15.
  * Created by kemllor on 2017/12/15.
@@ -67,9 +73,18 @@ public abstract class BaseActivity extends AppCompatActivity {
     @Override
     @Override
     protected void onResume() {
     protected void onResume() {
         super.onResume();
         super.onResume();
-        Object action = DataUtil.getInstance().getAction(getClass().getSimpleName());
+        final Object action = DataUtil.getInstance().getAction(getClass().getSimpleName());
         if (action != null) {
         if (action != null) {
-            doNextAction(action);
+            //延时一会儿,不然有可能操作会无效
+            Observable.just(1).delay(50L, TimeUnit.MILLISECONDS)
+                    .subscribeOn(Schedulers.io())
+                    .observeOn(AndroidSchedulers.mainThread())
+                    .subscribe(new Action1<Integer>() {
+                        @Override
+                        public void call(Integer integer) {
+                            doNextAction(action);
+                        }
+                    });
         }
         }
     }
     }
 
 

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

@@ -286,7 +286,7 @@ public class DataUtil {
         return null;
         return null;
     }
     }
     //是否使用小绵羊截图方案
     //是否使用小绵羊截图方案
-    public static boolean IS_USE_SCREEN_SHOT = true;
+    public static boolean IS_USE_SCREEN_SHOT = false;//默认开启小剪刀截图,有很多问题,调整到单独的后台进程再测试
     //是否监听媒体库图片变化
     //是否监听媒体库图片变化
     public static boolean IS_LISTEN_SCREEN_SHOT = true;
     public static boolean IS_LISTEN_SCREEN_SHOT = true;
     //初始化是否启用小绵羊两种截图方案
     //初始化是否启用小绵羊两种截图方案
@@ -299,7 +299,7 @@ public class DataUtil {
                             public void onNext(BaseMessage baseMessage) {
                             public void onNext(BaseMessage baseMessage) {
                                 ScreenShotConfig config = baseMessage.getData(ScreenShotConfig.class);
                                 ScreenShotConfig config = baseMessage.getData(ScreenShotConfig.class);
                                 if(config != null) {
                                 if(config != null) {
-                                    IS_USE_SCREEN_SHOT = config.isNeed();
+                                    IS_USE_SCREEN_SHOT &= config.isNeed();//默认开启才可配置为false
                                     IS_LISTEN_SCREEN_SHOT = config.isNeed();
                                     IS_LISTEN_SCREEN_SHOT = config.isNeed();
                                 }
                                 }
                             }
                             }

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

@@ -758,7 +758,7 @@ public class Jump2View {
     }
     }
 
 
     /**
     /**
-     * 跳转到 一分钟快速了解小绵羊 界面
+     * 新手任务列表
      */
      */
     public void goNewbieTaskList(Context context, Object o) {
     public void goNewbieTaskList(Context context, Object o) {
         UMConfigUtils.onEvent(UMConfigUtils.Event.SHEEP_NEWBIE_TASK_LIST);
         UMConfigUtils.onEvent(UMConfigUtils.Event.SHEEP_NEWBIE_TASK_LIST);

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

@@ -8,6 +8,7 @@ import android.app.usage.UsageStats;
 import android.app.usage.UsageStatsManager;
 import android.app.usage.UsageStatsManager;
 import android.content.Context;
 import android.content.Context;
 import android.content.Intent;
 import android.content.Intent;
+import android.graphics.Bitmap;
 import android.os.Build;
 import android.os.Build;
 import android.os.IBinder;
 import android.os.IBinder;
 import android.support.annotation.Nullable;
 import android.support.annotation.Nullable;
@@ -23,11 +24,12 @@ import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.utils.FileUtil;
 import com.sheep.jiuyan.samllsheep.utils.FileUtil;
 
 
 import java.io.File;
 import java.io.File;
-import java.io.IOException;
 import java.util.List;
 import java.util.List;
+import java.util.Locale;
 import java.util.TreeMap;
 import java.util.TreeMap;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeUnit;
 
 
+import go.kfzssafe.Kfzssafe;
 import rx.Observable;
 import rx.Observable;
 import rx.android.schedulers.AndroidSchedulers;
 import rx.android.schedulers.AndroidSchedulers;
 import rx.functions.Action1;
 import rx.functions.Action1;
@@ -44,7 +46,9 @@ public class ListenerShotService extends Service {
     @Override
     @Override
     public void onCreate() {
     public void onCreate() {
         super.onCreate();
         super.onCreate();
+        //初始化获取当前应用的工具类
         runningTaskUtil = new RunningTaskUtil(getApplicationContext());
         runningTaskUtil = new RunningTaskUtil(getApplicationContext());
+        //开启监听
         manager = ScreenShotListenManager.newInstance(getApplicationContext());
         manager = ScreenShotListenManager.newInstance(getApplicationContext());
         manager.setListener(
         manager.setListener(
                 new ScreenShotListenManager.OnScreenShotListener() {
                 new ScreenShotListenManager.OnScreenShotListener() {
@@ -54,23 +58,23 @@ public class ListenerShotService extends Service {
                 }
                 }
         );
         );
         manager.startListen();
         manager.startListen();
-
+        //发送一个通知栏,保证存活
         Notification notification = new Notification();
         Notification notification = new Notification();
         //通知栏没有展开时的显示内容
         //通知栏没有展开时的显示内容
         notification.icon = R.mipmap.icon;
         notification.icon = R.mipmap.icon;
         notification.tickerText = "回到小绵羊";
         notification.tickerText = "回到小绵羊";
 
 
         //下拉通知栏的显示内容
         //下拉通知栏的显示内容
-        notification.contentView = new RemoteViews(getPackageName() , R.layout.notification_sheep_shot_screen);
+        notification.contentView = new RemoteViews(getPackageName(), R.layout.notification_sheep_shot_screen);
 
 
         //点击通知栏跳转到相应的应用里面
         //点击通知栏跳转到相应的应用里面
-        Intent intent = new Intent(this , ActMain.class);
+        Intent intent = new Intent(this, ActMain.class);
         //这一句加不加没什么影响
         //这一句加不加没什么影响
 // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        notification.contentIntent = PendingIntent.getActivity(this , 1 , intent , 0);
+        notification.contentIntent = PendingIntent.getActivity(this, 1, intent, 0);
 
 
         //这里的id不能是0
         //这里的id不能是0
-        startForeground(1 , notification);
+        startForeground(113922, notification);
     }
     }
 
 
     @Nullable
     @Nullable
@@ -78,7 +82,9 @@ public class ListenerShotService extends Service {
     public IBinder onBind(Intent intent) {
     public IBinder onBind(Intent intent) {
         return null;
         return null;
     }
     }
+
     private ScreenShotListenManager manager;
     private ScreenShotListenManager manager;
+
     @Override
     @Override
     public void onDestroy() {
     public void onDestroy() {
         super.onDestroy();
         super.onDestroy();
@@ -89,19 +95,21 @@ public class ListenerShotService extends Service {
 
 
     /**
     /**
      * 获取前台运行的程序的包名
      * 获取前台运行的程序的包名
+     *
      * @return
      * @return
      */
      */
     @SuppressLint("NewApi")
     @SuppressLint("NewApi")
     public String getPackageNameInForeground1(Context context) {
     public String getPackageNameInForeground1(Context context) {
         String topPackageName = runningTaskUtil.getTopRunningTasks();
         String topPackageName = runningTaskUtil.getTopRunningTasks();
-        if(TextUtils.isEmpty(topPackageName)){
+        if (TextUtils.isEmpty(topPackageName)) {
             return getAppProcessInfoInForeground(context);
             return getAppProcessInfoInForeground(context);
         }
         }
-        return  topPackageName;
+        return topPackageName;
     }
     }
 
 
     /**
     /**
      * 获取前台运行的程序的包名
      * 获取前台运行的程序的包名
+     *
      * @return
      * @return
      */
      */
     @SuppressLint("NewApi")
     @SuppressLint("NewApi")
@@ -110,7 +118,7 @@ public class ListenerShotService extends Service {
             UsageStatsManager mUsageStatsManager = (UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE);//usagestats
             UsageStatsManager mUsageStatsManager = (UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE);//usagestats
             long time = System.currentTimeMillis();
             long time = System.currentTimeMillis();
             if (mUsageStatsManager != null) {
             if (mUsageStatsManager != null) {
-                List<UsageStats> usageStatsList = mUsageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_BEST, time-5000L, time);
+                List<UsageStats> usageStatsList = mUsageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_BEST, time - 5000L, time);
 
 
                 if (!ListUtil.isEmpty(usageStatsList)) {
                 if (!ListUtil.isEmpty(usageStatsList)) {
                     TreeMap<Long, UsageStats> mySortedMap = new TreeMap<>();
                     TreeMap<Long, UsageStats> mySortedMap = new TreeMap<>();
@@ -142,11 +150,10 @@ public class ListenerShotService extends Service {
 
 
     public void addPng(final String imagePath) {
     public void addPng(final String imagePath) {
         final String packageName = getPackageNameInForeground1(getApplicationContext());
         final String packageName = getPackageNameInForeground1(getApplicationContext());
-        if(TextUtils.isEmpty(packageName)){
+        if (TextUtils.isEmpty(packageName)) {
             LogUtil.println("ScreenShotListenManager", "无法获取到当前运行的应用的包名");
             LogUtil.println("ScreenShotListenManager", "无法获取到当前运行的应用的包名");
             return;
             return;
         }
         }
-//        File shotFile = getScreenShotsFile(packageName);
         LogUtil.println("ScreenShotListenManager", packageName);
         LogUtil.println("ScreenShotListenManager", packageName);
         Observable.just(1).delay(1, TimeUnit.SECONDS)
         Observable.just(1).delay(1, TimeUnit.SECONDS)
                 .subscribeOn(Schedulers.io())
                 .subscribeOn(Schedulers.io())
@@ -155,15 +162,21 @@ public class ListenerShotService extends Service {
                     @Override
                     @Override
                     public void call(Integer integer) {
                     public void call(Integer integer) {
                         try {
                         try {
-                            FileUtil.copyFileToDir(new File(imagePath), getScreenShotsDir(getApplicationContext(), packageName));
-                        } catch (IOException e) {
-                            e.printStackTrace();
-                            LogUtil.println("ScreenShotListenManager", "复制截屏图片失败");
+                            File toDir = getScreenShotsDir(getApplicationContext(), packageName);
+                            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());
+                                FileUtil.convertImage(imagePath, toFilePath, Bitmap.CompressFormat.PNG);
+                            }
+                        } catch (Exception e) {
+                            LogUtil.println("ScreenShotListenManager", "复制截屏图片失败", e.getMessage());
                         }
                         }
                     }
                     }
                 });
                 });
 
 
     }
     }
+
     /**
     /**
      * 截图目录
      * 截图目录
      *
      *
@@ -172,6 +185,7 @@ public class ListenerShotService extends Service {
     public static File getScreenShotsDir(Context context) {
     public static File getScreenShotsDir(Context context) {
         return context.getDir("ScreenShots", Context.MODE_PRIVATE);
         return context.getDir("ScreenShots", Context.MODE_PRIVATE);
     }
     }
+
     /**
     /**
      * 指定程序的截图目录
      * 指定程序的截图目录
      *
      *
@@ -179,7 +193,7 @@ public class ListenerShotService extends Service {
      */
      */
     public static File getScreenShotsDir(Context context, String packageName) {
     public static File getScreenShotsDir(Context context, String packageName) {
         File dir = new File(getScreenShotsDir(context), packageName);
         File dir = new File(getScreenShotsDir(context), packageName);
-        if(!dir.exists())
+        if (!dir.exists())
             dir.mkdirs();
             dir.mkdirs();
         return dir;
         return dir;
     }
     }

+ 25 - 10
app/src/main/java/com/sheep/jiuyan/samllsheep/utils/FileUtil.java

@@ -1,12 +1,16 @@
 package com.sheep.jiuyan.samllsheep.utils;
 package com.sheep.jiuyan.samllsheep.utils;
 
 
 
 
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
 import android.support.annotation.NonNull;
 import android.support.annotation.NonNull;
 
 
 import com.sheep.gamegroup.util.LogUtil;
 import com.sheep.gamegroup.util.LogUtil;
 
 
+import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.IOException;
 import java.nio.channels.FileChannel;
 import java.nio.channels.FileChannel;
@@ -21,18 +25,19 @@ public class FileUtil {
     public static void deleteFile(File file) {
     public static void deleteFile(File file) {
         deleteFile(file, true);
         deleteFile(file, true);
     }
     }
+
     public static void deleteFile(File file, boolean isDeleteDir) {
     public static void deleteFile(File file, boolean isDeleteDir) {
         if (file != null && file.exists()) { // 判断文件是否存在
         if (file != null && file.exists()) { // 判断文件是否存在
             if (file.isFile()) { // 判断是否是文件
             if (file.isFile()) { // 判断是否是文件
                 file.delete(); // delete()方法 你应该知道 是删除的意思;
                 file.delete(); // delete()方法 你应该知道 是删除的意思;
             } else if (file.isDirectory()) { // 否则如果它是一个目录
             } else if (file.isDirectory()) { // 否则如果它是一个目录
                 File[] files = file.listFiles(); // 声明目录下所有的文件 files[];
                 File[] files = file.listFiles(); // 声明目录下所有的文件 files[];
-                if(files != null) {
+                if (files != null) {
                     for (int i = 0; i < files.length; i++) { // 遍历目录下所有的文件
                     for (int i = 0; i < files.length; i++) { // 遍历目录下所有的文件
                         deleteFile(files[i]); // 把每个文件 用这个方法进行迭代
                         deleteFile(files[i]); // 把每个文件 用这个方法进行迭代
                     }
                     }
                 }
                 }
-                if(isDeleteDir)
+                if (isDeleteDir)
                     file.delete();
                     file.delete();
             }
             }
         }
         }
@@ -40,18 +45,18 @@ public class FileUtil {
 
 
     public static void copyFileToDir(@NonNull File fileFrom, @NonNull File dirTo) throws IOException {
     public static void copyFileToDir(@NonNull File fileFrom, @NonNull File dirTo) throws IOException {
         LogUtil.println("copyFile", fileFrom.getAbsolutePath(), dirTo.getAbsolutePath());
         LogUtil.println("copyFile", fileFrom.getAbsolutePath(), dirTo.getAbsolutePath());
-        if(!dirTo.isDirectory()){
+        if (!dirTo.isDirectory()) {
             return;
             return;
         }
         }
-        if(!dirTo.exists())
+        if (!dirTo.exists())
             dirTo.mkdirs();
             dirTo.mkdirs();
-        File dest= new File(dirTo, fileFrom.getName());
+        File dest = new File(dirTo, fileFrom.getName());
         if (dest.exists()) {
         if (dest.exists()) {
-            if(dest.delete()){
+            if (dest.delete()) {
                 LogUtil.println("copyFile", "删除文件失败");
                 LogUtil.println("copyFile", "删除文件失败");
             }
             }
         }
         }
-        if(!dest.createNewFile()){
+        if (!dest.createNewFile()) {
             LogUtil.println("copyFile", "创建文件失败");
             LogUtil.println("copyFile", "创建文件失败");
         }
         }
         FileChannel outputChannel = null;
         FileChannel outputChannel = null;
@@ -66,16 +71,17 @@ public class FileUtil {
             if (outputChannel != null) outputChannel.close();
             if (outputChannel != null) outputChannel.close();
         }
         }
     }
     }
+
     public static void copyFile(@NonNull File fileFrom, @NonNull File fileTo) throws IOException {
     public static void copyFile(@NonNull File fileFrom, @NonNull File fileTo) throws IOException {
         LogUtil.println("copyFile", fileFrom.getAbsolutePath(), fileTo.getAbsolutePath());
         LogUtil.println("copyFile", fileFrom.getAbsolutePath(), fileTo.getAbsolutePath());
-        if(!fileTo.getParentFile().exists())
+        if (!fileTo.getParentFile().exists())
             fileTo.getParentFile().mkdirs();
             fileTo.getParentFile().mkdirs();
         if (fileTo.exists()) {
         if (fileTo.exists()) {
-            if(fileTo.delete()){
+            if (fileTo.delete()) {
                 LogUtil.println("copyFile", "删除文件失败");
                 LogUtil.println("copyFile", "删除文件失败");
             }
             }
         }
         }
-        if(!fileTo.createNewFile()){
+        if (!fileTo.createNewFile()) {
             LogUtil.println("copyFile", "创建文件失败");
             LogUtil.println("copyFile", "创建文件失败");
         }
         }
         FileChannel outputChannel = null;
         FileChannel outputChannel = null;
@@ -90,4 +96,13 @@ public class FileUtil {
             if (outputChannel != null) outputChannel.close();
             if (outputChannel != null) outputChannel.close();
         }
         }
     }
     }
+
+    public static void convertImage(String fromFilePath, String toFilePath, Bitmap.CompressFormat format) throws IOException {
+        LogUtil.println("ScreenShotListenManager", "convertImage", fromFilePath, toFilePath);
+        Bitmap bitmap = BitmapFactory.decodeFile(fromFilePath);
+        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(toFilePath));
+        if (bitmap != null && bitmap.compress(format, 100, bos)) {
+            bos.flush();
+        }
+    }
 }
 }