update 推送图片
This commit is contained in:
@@ -3,6 +3,7 @@ package org.yameida.worktool.observer;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
@@ -12,8 +13,8 @@ import android.util.Log;
|
||||
public class MultiFileObserver extends FileObserver {
|
||||
|
||||
public HashMap<String, Long> map = new HashMap<>();
|
||||
public static String lastPicPath = "";
|
||||
public static Long lastPicCreateTime = 0L;
|
||||
public static HashSet<String> createSet = new HashSet<>();
|
||||
public static HashSet<String> finishSet = new HashSet<>();
|
||||
|
||||
/** Only modification events */
|
||||
public static int CHANGES_ONLY = CREATE | MODIFY | DELETE | CLOSE_WRITE
|
||||
@@ -77,28 +78,35 @@ public class MultiFileObserver extends FileObserver {
|
||||
mObservers = null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onEvent(int event, String path) {
|
||||
switch (event) {
|
||||
case FileObserver.ACCESS:
|
||||
case FileObserver.CLOSE_WRITE:
|
||||
case FileObserver.CLOSE_NOWRITE:
|
||||
if (path.endsWith(".0") && !map.containsKey(path)) {
|
||||
Log.i("RecursiveFileObserver", "发现新图片: " + path);
|
||||
if (path.endsWith(".0") && !map.containsKey(path) && createSet.contains(path)) {
|
||||
map.put(path, System.currentTimeMillis());
|
||||
lastPicPath = path;
|
||||
Log.i("RecursiveFileObserver", "发现新图片: " + path);
|
||||
finishSet.add(path);
|
||||
// try {
|
||||
// ImageInfo imageInfo = new ImageInfo();
|
||||
// imageInfo.setDetermineImageNumber(true);
|
||||
// ImageInfo.run(path, new FileInputStream(path), imageInfo, true);
|
||||
// } catch (Exception e) { e.printStackTrace(); }
|
||||
}
|
||||
break;
|
||||
case FileObserver.CREATE:
|
||||
Log.i("RecursiveFileObserver", "CREATE: " + path);
|
||||
lastPicCreateTime = System.currentTimeMillis();
|
||||
if (path.endsWith(".0")) {
|
||||
createSet.add(path);
|
||||
}
|
||||
break;
|
||||
case FileObserver.ATTRIB:
|
||||
// Log.i("RecursiveFileObserver", "ATTRIB: " + path);
|
||||
break;
|
||||
case FileObserver.CLOSE_WRITE:
|
||||
// case FileObserver.CLOSE_WRITE:
|
||||
// Log.i("RecursiveFileObserver", "CLOSE_WRITE: " + path);
|
||||
break;
|
||||
// break;
|
||||
case FileObserver.DELETE:
|
||||
// Log.i("RecursiveFileObserver", "DELETE: " + path);
|
||||
break;
|
||||
|
||||
@@ -545,33 +545,37 @@ object WeworkLoopImpl {
|
||||
message = WeworkMessageBean.SubMessageBean(0, textType, itemMessageList, nameList)
|
||||
//图片类型特殊处理
|
||||
if (doubleCheck && Constant.pushImage && textType == 2) {
|
||||
val lastPicCreateTime = MultiFileObserver.lastPicCreateTime
|
||||
val lastPicPath = MultiFileObserver.lastPicPath
|
||||
LogUtils.d("发现图片类型应该点击")
|
||||
MultiFileObserver.createSet.clear()
|
||||
MultiFileObserver.finishSet.clear()
|
||||
LogUtils.v("点击图片类型")
|
||||
AccessibilityUtil.performClickWithSon(relativeLayoutContent)
|
||||
AccessibilityExtraUtil.loadingPage("ShowImageController", Constant.CHANGE_PAGE_INTERVAL)
|
||||
LogUtils.d("发现图片类型 查看图片检查有无新图片产生")
|
||||
if (MultiFileObserver.lastPicCreateTime > lastPicCreateTime) {
|
||||
LogUtils.v("发现图片类型 查看图片检查有无新图片产生")
|
||||
if (MultiFileObserver.createSet.isNotEmpty()) {
|
||||
LogUtils.d("正在下载图片...")
|
||||
var downloading = true
|
||||
val startTime = System.currentTimeMillis()
|
||||
var currentTime = startTime
|
||||
while (currentTime - startTime < Constant.LONG_INTERVAL) {
|
||||
if (!lastPicPath.equals(MultiFileObserver.lastPicPath)) {
|
||||
LogUtils.d("下载图片完成")
|
||||
if (MultiFileObserver.createSet.size == MultiFileObserver.finishSet.size) {
|
||||
LogUtils.d("下载图片完成: ${MultiFileObserver.createSet.size}")
|
||||
downloading = false
|
||||
try {
|
||||
for (path in MultiFileObserver.finishSet) {
|
||||
val df = SimpleDateFormat("MMdd_HHmmss")
|
||||
val targetPath = "${
|
||||
Utils.getApp().getExternalFilesDir("copy")
|
||||
}/${df.format(Date())}/${File(MultiFileObserver.lastPicPath).name}.png"
|
||||
if (FileUtils.copy(MultiFileObserver.lastPicPath, targetPath)) {
|
||||
LogUtils.d("复制图片完成: $targetPath")
|
||||
}/${df.format(Date())}/${File(path).name}.png"
|
||||
if (FileUtils.copy(path, targetPath)) {
|
||||
LogUtils.d("复制图片完成: $targetPath " + ImageDepthSizeUtil.checkRawImage(targetPath))
|
||||
log("复制图片完成: $targetPath")
|
||||
} else {
|
||||
LogUtils.e("复制图片失败 请检查权限: $targetPath")
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
LogUtils.e("接收图片出错", e)
|
||||
error("接收图片出错: ${e.message}")
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
@@ -74,12 +74,15 @@ class WeworkService : AccessibilityService() {
|
||||
mFileObserver =
|
||||
MultiFileObserver("/storage/emulated/0/Android/data/com.tencent.wework/files/imagecache/imagemsg2");
|
||||
mFileObserver?.startWatching()
|
||||
log("startWatching...")
|
||||
} else {
|
||||
mFileObserver?.stopWatching()
|
||||
mFileObserver?.startWatching()
|
||||
log("restartWatching...")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
LogUtils.e(e)
|
||||
error("initObserver startWatching error!: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
1232
app/src/main/java/org/yameida/worktool/utils/ImageInfo.java
Normal file
1232
app/src/main/java/org/yameida/worktool/utils/ImageInfo.java
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user