Commit f8355c48 by jeffrey

解析任务调整,明天加入多线程解析

parent 1317c475
......@@ -5,9 +5,11 @@ import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Environment;
import android.provider.Settings;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.LocalBroadcastManager;
......@@ -23,12 +25,17 @@ import com.yuqirong.listenwechatnotification.askhttp.UpdateApk;
import com.yuqirong.listenwechatnotification.bean.ImageBean;
import com.yuqirong.listenwechatnotification.broadcastReceiver.MyCashReceiver;
import com.yuqirong.listenwechatnotification.function.BuildUrlsFunction;
import com.yuqirong.listenwechatnotification.function.QRCodeFunction;
import com.yuqirong.listenwechatnotification.service.WeChatNotificationListenerService;
import com.yuqirong.listenwechatnotification.uitl.Save2SharedPreferences;
import com.yuqirong.listenwechatnotification.uitl.Utils;
import org.greenrobot.eventbus.EventBus;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import static com.yuqirong.listenwechatnotification.function.QRCodeFunction.listAllZfbFileNames;
......@@ -127,12 +134,29 @@ public class MainActivity extends ParentActivity {
// timingRequest();
// ArrayList<String> result = ActivePullCashList.generateMoneys();
StringBuilder sb = new StringBuilder();
for (String one : result){
sb.append(one);
sb.append(",");
}
Log.d(TAG,"done =" + sb.toString());
// 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();
// for (String one : result){
// sb.append(one);
// sb.append(",");
// }
// Log.d(TAG,"done =" + sb.toString());
}
......@@ -239,6 +263,18 @@ private void checkNotificationPermission() {
am.setRepeating(AlarmManager.RTC_WAKEUP,System.currentTimeMillis(),10000,pi);
}
public static void writeString2File(String str) throws IOException {
File moneyFile = new File(Environment.getExternalStorageDirectory().getPath(), "money.txt");
if (!moneyFile.exists()){
moneyFile.createNewFile();
}
BufferedWriter bfw = new BufferedWriter(new FileWriter(moneyFile, false));
bfw.write(str);
bfw.flush();
bfw.close();
}
@Override
protected void onResume() {
super.onResume();
......
......@@ -32,7 +32,9 @@ public class JobAwaken {
Toast.makeText(context,"未安装微信",Toast.LENGTH_LONG).show();
}else {
intent.setComponent(cn);
if (context.getPackageManager().resolveActivity(intent,0) != null){
context.startActivity(intent);
}
}
}
}
......@@ -23,6 +23,7 @@ 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.MainActivity;
import com.yuqirong.listenwechatnotification.MyApplication;
import com.yuqirong.listenwechatnotification.askhttp.ActivePullCashList;
import com.yuqirong.listenwechatnotification.askhttp.ActivePushCashList;
......@@ -38,8 +39,11 @@ import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static android.graphics.BitmapFactory.decodeFile;
......@@ -50,22 +54,26 @@ import static android.graphics.BitmapFactory.decodeFile;
*/
public class QRCodeFunction extends Thread{
ArrayList<ImageBean> beans;
private static String TAG = "QRCodeFunction";
private BuildUrlsFunction functionUrls;
// private BuildUrlsFunction functionUrls;
private String filePath;
public QRCodeFunction(String name,String filePath) {
super(name);
this.filePath = filePath;
this.beans = new ArrayList<>();
}
@Override
public void run() {
super.run();
functionUrls = new BuildUrlsFunction();
ArrayList<ImageBean> imageInfos = functionFoundImageFile(this.filePath);
OneBatchResult result = new OneBatchResult(imageInfos);
List<File> imageFiles = functionFoundImageFile(this.filePath);
List<ImageBean> imageBeanList = functionQRCode((File[]) imageFiles.toArray());
OneBatchResult result = new OneBatchResult(new ArrayList<ImageBean>(imageBeanList));
String stringResult = new Gson().toJson(result);
SharedPreferences sp = MyApplication.get().getSharedPreferences("result", Context.MODE_PRIVATE);
......@@ -75,6 +83,14 @@ public class QRCodeFunction extends Thread{
Log.d(TAG,stringResult);
Log.d(TAG,"fei result end-----------------------------");
String strResult = MyApplication.get().getSharedPreferences("result",Context.MODE_PRIVATE).getString("result","");
Log.d(TAG,"done =" + strResult);
try {
MainActivity.writeString2File(strResult);
} catch (IOException e) {
e.printStackTrace();
}
// //数据发送成功的话,这边修改下次请求参数类型
// //还需要删除当前类型文件夹下所有图片
// if (PayTypeSingleTon.newInstance().getPayType().equals(Utils.payTypeZFB)){
......@@ -90,7 +106,7 @@ public class QRCodeFunction extends Thread{
/**
* 支付宝保存的图片只存在于 DCIM/CAMERA 华为手机
*/
private ArrayList<ImageBean> functionFoundImageFile(String filePath){
private List<File> functionFoundImageFile(String filePath){
//有sd卡
if (Environment.MEDIA_MOUNTED.equals(Environment
.getExternalStorageState())) {
......@@ -103,7 +119,7 @@ public class QRCodeFunction extends Thread{
Log.d(TAG, "文件夹存在");
File[] files = path1.listFiles();
if (files.length>0) {
return functionQRCode(files);
return Arrays.asList(files);
}else{
Log.d(TAG, "没有图片文件");
}
......@@ -134,12 +150,15 @@ public class QRCodeFunction extends Thread{
}
public ArrayList<ImageBean> functionQRCode(File[] files){
ArrayList<ImageBean> list = new ArrayList<>();
for (File f:files) {
parseCode(f);
ImageBean imageBean = parseCode(f);
if (imageBean != null){
list.add(imageBean);
}
}
interrupt();
return functionUrls.getBeans();
return list;
// ActivePushCashList activePushCashList = new ActivePushCashList();
//
......@@ -147,7 +166,7 @@ public class QRCodeFunction extends Thread{
// activePushCashList.pushCashList(this.functionUrls.getBeans());
}
public void parseCode(File file) {
public ImageBean parseCode(File file) {
Bitmap obmp = decodeFile(file.getPath());
int width = obmp.getWidth();
int height = obmp.getHeight();
......@@ -162,10 +181,10 @@ public class QRCodeFunction extends Thread{
ImageBean bean = new ImageBean();
bean.setUrl(re.getText());
bean.setDescription(file.getName());
Log.d(TAG, "parseCode: "+bean.getUrl());
this.functionUrls.getBeans().add(bean);
return bean;
Log.d(TAG, "parseCode: "+bean.getUrl());
} catch (NotFoundException e) {
e.printStackTrace();
Log.d(TAG, "fei error: " + e.getMessage() + " file name " + file.getName());
......@@ -178,6 +197,7 @@ public class QRCodeFunction extends Thread{
Log.d(TAG, "fei error: " + e.getMessage() + " file name " + file.getName());
}
return null;
}
......
......@@ -83,12 +83,24 @@ 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();
}else{
new Runnable() {
@Override
public void run() {
QRCodeFunction qrThread = new QRCodeFunction("QRCodeFunction---WEIXIN", Utils.WeiXinImgPath);
qrThread.run();
}
}.run();
}
moneylist.clear();
return;
......
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