Commit 7e491c77 by jeffrey

加入多线程解析

parent 3b4892fc
......@@ -130,25 +130,14 @@ public class MainActivity extends ParentActivity {
my = new MyCashReceiver();
registerReceiver(my,filter);
ArrayList<String> result = ActivePullCashList.moneyWithFilter();
QRCodeFunction qrThread = new QRCodeFunction("QRCodeFunction---ZFB", Utils.ZFBImgPath);
qrThread.start();
// ArrayList<String> result = ActivePullCashList.moneyWithFilter();
// timingRequest();
// ArrayList<String> result = ActivePullCashList.generateMoneys();
// new Runnable() {
// @Override
// public void run() {
// QRCodeFunction qrThread = new QRCodeFunction("QRCodeFunction---ZFB", Utils.ZFBImgPath);
// qrThread.run();
// }
// }.run();
// String strResult = MyApplication.get().getSharedPreferences("result", Context.MODE_PRIVATE).getString("result","");
// try {
// writeString2File(strResult);
// } catch (IOException e) {
// e.printStackTrace();
// }
// StringBuilder sb = new StringBuilder();
......@@ -296,4 +285,7 @@ private void checkNotificationPermission() {
super.onDestroy();
am.cancel(pi);
}
}
package com.yuqirong.listenwechatnotification.function;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.os.Environment;
import android.util.Log;
import com.google.gson.Gson;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.ChecksumException;
import com.google.zxing.FormatException;
import com.google.zxing.NotFoundException;
import com.google.zxing.RGBLuminanceSource;
import com.google.zxing.Result;
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.qrcode.QRCodeReader;
import com.yuqirong.listenwechatnotification.MyApplication;
import com.yuqirong.listenwechatnotification.bean.ImageBean;
import com.yuqirong.listenwechatnotification.bean.OneBatchResult;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import static android.graphics.BitmapFactory.decodeFile;
/**
* 创建日期:2018/3/8 on 15:48
* 描述:
* 作者:Li
*/
public class ParseImageFunc {
private final String TAG = ParseImageFunc.class.getSimpleName();
private List<ImageBean> imageBeanList = new ArrayList<>() ;
private ConcurrentLinkedQueue<File> queue = new ConcurrentLinkedQueue<File>();
public void start(String filePath){
final List<File> imageFiles = foundImageFile(filePath);
if (imageFiles == null || imageFiles.size() == 0){
return;
}
for (File file : imageFiles){
queue.add(file);
}
ExecutorService service = Executors.newFixedThreadPool(3);
for (int i = 0 ; i < 3 ;i ++){
service.submit(new Runnable() {
@Override
public void run() {
while (!queue.isEmpty()){
File file = queue.poll();
ImageBean result = parseCode(file);
if (result != null){
imageBeanList.add(result);
}
}
Collections.sort(imageBeanList,new Comparator<ImageBean>() {
@Override
public int compare(ImageBean o1, ImageBean o2) {
float left = Float.parseFloat(o1.getDescription());
float right = Float.parseFloat(o2.getDescription());
return left < right ? -1 : 1;
}
});
OneBatchResult result = new OneBatchResult(new ArrayList<ImageBean>(imageBeanList));
String stringResult = new Gson().toJson(result);
SharedPreferences sp = MyApplication.get().getSharedPreferences("result", Context.MODE_PRIVATE);
sp.edit().putString("result",stringResult).apply();
Log.d("fei","parse done");
}
});
}
}
/**
* 支付宝保存的图片只存在于 DCIM/CAMERA 华为手机
*/
private List<File> foundImageFile(String filePath){
//有sd卡
if (Environment.MEDIA_MOUNTED.equals(Environment
.getExternalStorageState())) {
// 创建一个文件夹对象,赋值为外部存储器的目录
File sdcardDir = Environment.getExternalStorageDirectory();
// 得到一个路径,内容是sdcard的文件夹路径和名字
String path = sdcardDir.getPath() + filePath;
File path1 = new File(path);
if (path1.exists()){
Log.d(TAG, "文件夹存在");
File[] files = path1.listFiles();
if (files.length>0) {
return Arrays.asList(files);
}else{
Log.d(TAG, "没有图片文件");
}
}else{
Log.d(TAG, "文件不存在");
}
} else{
}
return null;
}
public ImageBean parseCode(File file) {
Bitmap obmp = decodeFile(file.getPath());
int width = obmp.getWidth();
int height = obmp.getHeight();
int[] data = new int[width * height];
obmp.getPixels(data, 0, width, 0, 0, width, height);
RGBLuminanceSource source = new RGBLuminanceSource(width, height, data);
BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
QRCodeReader reader = new QRCodeReader();
Result re = null;
try {
re = reader.decode(bitmap1);
ImageBean bean = new ImageBean();
bean.setUrl(re.getText());
bean.setDescription(file.getName());
Log.d(TAG, "parseCode: "+bean.getUrl());
return bean;
} catch (NotFoundException e) {
e.printStackTrace();
Log.d(TAG, "fei error: " + e.getMessage() + " file name " + file.getName());
} catch (ChecksumException e) {
e.printStackTrace();
Log.d(TAG, "fei error: " + e.getMessage() + " file name " + file.getName());
} catch (FormatException e) {
e.printStackTrace();
Log.d(TAG, "fei error: " + e.getMessage() + " file name " + file.getName());
}
return null;
}
}
......@@ -71,6 +71,9 @@ public class QRCodeFunction extends Thread{
public void run() {
super.run();
List<File> imageFiles = functionFoundImageFile(this.filePath);
if (imageFiles == null || imageFiles.size() == 0){
return;
}
List<ImageBean> imageBeanList = functionQRCode((File[]) imageFiles.toArray());
OneBatchResult result = new OneBatchResult(new ArrayList<ImageBean>(imageBeanList));
......
......@@ -88,22 +88,12 @@ public class MyAccessibilityService extends AccessibilityService {
Log.d(TAG, "这次任务已经完成!");
if (PayTypeSingleTon.newInstance().getPayType().equals(Utils.payTypeZFB)){
new Runnable() {
@Override
public void run() {
QRCodeFunction qrThread = new QRCodeFunction("QRCodeFunction---ZFB", Utils.ZFBImgPath);
qrThread.run();
}
}.run();
qrThread.start();
}else{
new Runnable() {
@Override
public void run() {
QRCodeFunction qrThread = new QRCodeFunction("QRCodeFunction---WEIXIN", Utils.WeiXinImgPath);
qrThread.run();
}
}.run();
qrThread.start();
}
moneylist.clear();
......@@ -209,7 +199,6 @@ public class MyAccessibilityService extends AccessibilityService {
}
if (info.getChildCount() == 0) {
Log.i("fei ", "child widget----------------------------" + info.getClassName());
Log.i("fei ", "showDialog:" + info.canOpenPopup());
Log.i("fei ", "Text:" + info.getText());
Log.i("fei ", "windowId:" + info.getWindowId());
// if (!TextUtils.isEmpty(info.getText()) && searchText.equals(info.getText())){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment