|
@@ -29,33 +29,34 @@ import static com.usai.util.Network.URL_UPLOAD;
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
public class RAUploadManager {
|
|
public class RAUploadManager {
|
|
|
- public int maxThread=3;
|
|
|
|
|
|
|
+ public int maxThread = 3;
|
|
|
public int activeThread;
|
|
public int activeThread;
|
|
|
- public int maxRetry=5;
|
|
|
|
|
- public int retryWaiting=300;
|
|
|
|
|
|
|
+ public int maxRetry = 5;
|
|
|
|
|
+ public int retryWaiting = 300;
|
|
|
|
|
|
|
|
|
|
|
|
|
- public Boolean wifiOnly=false;
|
|
|
|
|
-// public Boolean autoStart=true;
|
|
|
|
|
|
|
+ public Boolean wifiOnly = false;
|
|
|
|
|
+ // public Boolean autoStart=true;
|
|
|
// public Boolean removeFinish=true;
|
|
// public Boolean removeFinish=true;
|
|
|
// public Boolean removeError=false;
|
|
// public Boolean removeError=false;
|
|
|
public QueueStatus queue_status;
|
|
public QueueStatus queue_status;
|
|
|
|
|
|
|
|
|
|
|
|
|
- public static final int RESULT_BARCODE_ERROR=-50;
|
|
|
|
|
|
|
+ public static final int RESULT_BARCODE_ERROR = -50;
|
|
|
|
|
|
|
|
- public TaskStatus newtaskStatus= TaskStatus.TaskStatusWait;
|
|
|
|
|
|
|
+ public TaskStatus newtaskStatus = TaskStatus.TaskStatusWait;
|
|
|
private ArrayList<Bundle> arr_queue;
|
|
private ArrayList<Bundle> arr_queue;
|
|
|
|
|
|
|
|
- public ArrayList<Bundle> get_arr_queue()
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ public ArrayList<Bundle> get_arr_queue() {
|
|
|
return arr_queue;
|
|
return arr_queue;
|
|
|
}
|
|
}
|
|
|
-// private List<Bundle> operation_queue;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // private List<Bundle> operation_queue;
|
|
|
// private ExecutorService es = Executors.newFixedThreadPool(3);//
|
|
// private ExecutorService es = Executors.newFixedThreadPool(3);//
|
|
|
// .newFixedThreadPool();
|
|
// .newFixedThreadPool();
|
|
|
// private CountDownLatch latch = new CountDownLatch(maxThread);
|
|
// private CountDownLatch latch = new CountDownLatch(maxThread);
|
|
|
private RAOperationQueue operation_queue;
|
|
private RAOperationQueue operation_queue;
|
|
|
|
|
+
|
|
|
public enum QueueStatus {
|
|
public enum QueueStatus {
|
|
|
QueueStatusDefault,
|
|
QueueStatusDefault,
|
|
|
QueueStatusAdd,
|
|
QueueStatusAdd,
|
|
@@ -76,7 +77,7 @@ public class RAUploadManager {
|
|
|
public UIUpdateListener uiUpdateListener;
|
|
public UIUpdateListener uiUpdateListener;
|
|
|
|
|
|
|
|
public interface UIUpdateListener {
|
|
public interface UIUpdateListener {
|
|
|
-// void onProgress(long index, double percentage);
|
|
|
|
|
|
|
+ // void onProgress(long index, double percentage);
|
|
|
void updateCell(long index, Bundle taskinfo);
|
|
void updateCell(long index, Bundle taskinfo);
|
|
|
// void updateList();
|
|
// void updateList();
|
|
|
|
|
|
|
@@ -98,26 +99,23 @@ public class RAUploadManager {
|
|
|
// }
|
|
// }
|
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
- public RAUploadManager()
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ public RAUploadManager() {
|
|
|
queue_status = QueueStatus.QueueStatusDefault;
|
|
queue_status = QueueStatus.QueueStatusDefault;
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
SharedPreferences UMSetting = RedAntApplication.getInstance()
|
|
SharedPreferences UMSetting = RedAntApplication.getInstance()
|
|
|
.getSharedPreferences("UploadManager", 0);
|
|
.getSharedPreferences("UploadManager", 0);
|
|
|
|
|
|
|
|
- if(UMSetting!=null)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ if (UMSetting != null) {
|
|
|
// autoStart = UMSetting.getBoolean("auto_upload",false);
|
|
// autoStart = UMSetting.getBoolean("auto_upload",false);
|
|
|
// removeFinish = UMSetting.getBoolean("auto_rm_finish",false);
|
|
// removeFinish = UMSetting.getBoolean("auto_rm_finish",false);
|
|
|
// removeError = UMSetting.getBoolean("auto_rm_error",false);
|
|
// removeError = UMSetting.getBoolean("auto_rm_error",false);
|
|
|
- maxRetry = UMSetting.getInt("retry_count",5);
|
|
|
|
|
- newtaskStatus = TaskStatus.values()[UMSetting.getInt("newtask_status",TaskStatus.TaskStatusWait.ordinal())];
|
|
|
|
|
|
|
+ maxRetry = UMSetting.getInt("retry_count", 5);
|
|
|
|
|
+ newtaskStatus = TaskStatus.values()[UMSetting.getInt("newtask_status", TaskStatus.TaskStatusWait.ordinal())];
|
|
|
|
|
|
|
|
- maxThread = UMSetting.getInt("max_thread",3);
|
|
|
|
|
|
|
+ maxThread = UMSetting.getInt("max_thread", 3);
|
|
|
|
|
|
|
|
- wifiOnly = UMSetting.getBoolean("wifi_only",false);
|
|
|
|
|
|
|
+ wifiOnly = UMSetting.getBoolean("wifi_only", false);
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
operation_queue = new RAOperationQueue();
|
|
operation_queue = new RAOperationQueue();
|
|
@@ -192,30 +190,30 @@ public class RAUploadManager {
|
|
|
// 9/* earthnet */)
|
|
// 9/* earthnet */)
|
|
|
//
|
|
//
|
|
|
|
|
|
|
|
- boolean ret=false;
|
|
|
|
|
- String path=taskinfo.getString("path");
|
|
|
|
|
- taskinfo.putInt("status",TaskStatus.TaskStatusStart.ordinal());
|
|
|
|
|
- String url=taskinfo.getString("url")+""+URL_UPLOAD;
|
|
|
|
|
|
|
+ boolean ret = false;
|
|
|
|
|
+ String path = taskinfo.getString("path");
|
|
|
|
|
+ taskinfo.putInt("status", TaskStatus.TaskStatusStart.ordinal());
|
|
|
|
|
+ String url = taskinfo.getString("url") + "" + URL_UPLOAD;
|
|
|
|
|
|
|
|
- int waiting=taskinfo.getInt("retry_waiting",0);
|
|
|
|
|
|
|
+ int waiting = taskinfo.getInt("retry_waiting", 0);
|
|
|
|
|
|
|
|
int newwaiting = waiting;
|
|
int newwaiting = waiting;
|
|
|
- if(newwaiting/60.0<20)
|
|
|
|
|
- newwaiting+=retryWaiting;
|
|
|
|
|
- if(newwaiting>1200)
|
|
|
|
|
|
|
+ if (newwaiting / 60.0 < 20)
|
|
|
|
|
+ newwaiting += retryWaiting;
|
|
|
|
|
+ if (newwaiting > 1200)
|
|
|
newwaiting = 1200;
|
|
newwaiting = 1200;
|
|
|
- taskinfo.putInt("retry_waiting",newwaiting);
|
|
|
|
|
|
|
+ taskinfo.putInt("retry_waiting", newwaiting);
|
|
|
|
|
|
|
|
// try{
|
|
// try{
|
|
|
try {
|
|
try {
|
|
|
- Thread.currentThread().sleep(waiting*1000);
|
|
|
|
|
|
|
+ Thread.currentThread().sleep(waiting * 1000);
|
|
|
} catch (InterruptedException e) {
|
|
} catch (InterruptedException e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
// }catch(InterruptedException ie){
|
|
// }catch(InterruptedException ie){
|
|
|
// ie.printStackTrace();
|
|
// ie.printStackTrace();
|
|
|
// }
|
|
// }
|
|
|
- JSONObject result=Network.UploadImage(path, taskinfo.getBundle("params"), url, new Network.FileUploadListener() {
|
|
|
|
|
|
|
+ JSONObject result = Network.UploadImage(path, taskinfo.getBundle("params"), url, new Network.FileUploadListener() {
|
|
|
@Override
|
|
@Override
|
|
|
public double percent_step() {
|
|
public double percent_step() {
|
|
|
//进度刷新步进 3%
|
|
//进度刷新步进 3%
|
|
@@ -226,22 +224,22 @@ public class RAUploadManager {
|
|
|
public boolean interupt() {
|
|
public boolean interupt() {
|
|
|
// if(taskinfo.getBoolean("iscancel",false))
|
|
// if(taskinfo.getBoolean("iscancel",false))
|
|
|
// return false;
|
|
// return false;
|
|
|
- return taskinfo.getBoolean("iscancel",false);
|
|
|
|
|
|
|
+ return taskinfo.getBoolean("iscancel", false);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void onProgress(long pro, double percentage) {
|
|
public void onProgress(long pro, double percentage) {
|
|
|
|
|
|
|
|
|
|
|
|
|
- synchronized(this){
|
|
|
|
|
|
|
+ synchronized (this) {
|
|
|
Log.d("_synchronized", "UploadImage onProgress: " + percentage);
|
|
Log.d("_synchronized", "UploadImage onProgress: " + percentage);
|
|
|
long timeStart = System.currentTimeMillis();
|
|
long timeStart = System.currentTimeMillis();
|
|
|
- taskinfo.putDouble("progress",percentage);
|
|
|
|
|
- if (uiUpdateListener!=null) {
|
|
|
|
|
|
|
+ taskinfo.putDouble("progress", percentage);
|
|
|
|
|
+ if (uiUpdateListener != null) {
|
|
|
int index = arr_queue.indexOf(taskinfo);
|
|
int index = arr_queue.indexOf(taskinfo);
|
|
|
// uiUpdateListener.onProgress(index,percentage);
|
|
// uiUpdateListener.onProgress(index,percentage);
|
|
|
|
|
|
|
|
- uiUpdateListener.updateCell(index,taskinfo);
|
|
|
|
|
|
|
+ uiUpdateListener.updateCell(index, taskinfo);
|
|
|
}
|
|
}
|
|
|
Log.d("_synchronized", "UploadImage onProgress: end" + (System.currentTimeMillis() - timeStart));
|
|
Log.d("_synchronized", "UploadImage onProgress: end" + (System.currentTimeMillis() - timeStart));
|
|
|
}
|
|
}
|
|
@@ -260,58 +258,46 @@ public class RAUploadManager {
|
|
|
r = result.getInt("result");
|
|
r = result.getInt("result");
|
|
|
|
|
|
|
|
|
|
|
|
|
- if(r==2|| r==RESULT_BARCODE_ERROR)
|
|
|
|
|
- {
|
|
|
|
|
- taskinfo.putInt("status",TaskStatus.TaskStatusFinish.ordinal());
|
|
|
|
|
- if(r==2)
|
|
|
|
|
- taskinfo.putString("msg","upload successful");
|
|
|
|
|
|
|
+ if (r == 2 || r == RESULT_BARCODE_ERROR) {
|
|
|
|
|
+ taskinfo.putInt("status", TaskStatus.TaskStatusFinish.ordinal());
|
|
|
|
|
+ if (r == 2)
|
|
|
|
|
+ taskinfo.putString("msg", "upload successful");
|
|
|
else {
|
|
else {
|
|
|
- String rmsg=result.getString("msg");
|
|
|
|
|
|
|
+ String rmsg = result.getString("msg");
|
|
|
taskinfo.putString("msg", "warning: " + rmsg);
|
|
taskinfo.putString("msg", "warning: " + rmsg);
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- if(taskinfo.getInt("retry",0)>=maxRetry)
|
|
|
|
|
- {
|
|
|
|
|
- taskinfo.putInt("status",TaskStatus.TaskStatusError.ordinal());
|
|
|
|
|
- taskinfo.putDouble("progress",0.0);
|
|
|
|
|
- String rmsg=result.getString("msg");
|
|
|
|
|
- taskinfo.putString("msg",rmsg);
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- taskinfo.putInt("retry",taskinfo.getInt("retry",0)+1);
|
|
|
|
|
- taskinfo.putInt("status",TaskStatus.TaskStatusWait.ordinal());
|
|
|
|
|
- taskinfo.putDouble("progress",0.0);
|
|
|
|
|
- taskinfo.putString("msg","connection lost, retry...");
|
|
|
|
|
- ret=true;
|
|
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (taskinfo.getInt("retry", 0) >= maxRetry) {
|
|
|
|
|
+ taskinfo.putInt("status", TaskStatus.TaskStatusError.ordinal());
|
|
|
|
|
+ taskinfo.putDouble("progress", 0.0);
|
|
|
|
|
+ String rmsg = result.getString("msg");
|
|
|
|
|
+ taskinfo.putString("msg", rmsg);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ taskinfo.putInt("retry", taskinfo.getInt("retry", 0) + 1);
|
|
|
|
|
+ taskinfo.putInt("status", TaskStatus.TaskStatusWait.ordinal());
|
|
|
|
|
+ taskinfo.putDouble("progress", 0.0);
|
|
|
|
|
+ taskinfo.putString("msg", "connection lost, retry...");
|
|
|
|
|
+ ret = true;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
} catch (JSONException e) {
|
|
} catch (JSONException e) {
|
|
|
// String rmsg=result.getString("msg");
|
|
// String rmsg=result.getString("msg");
|
|
|
- taskinfo.putInt("status",TaskStatus.TaskStatusError.ordinal());
|
|
|
|
|
- taskinfo.putDouble("progress",0.0);
|
|
|
|
|
- taskinfo.putString("msg","can not upload, please contact administrator.");
|
|
|
|
|
|
|
+ taskinfo.putInt("status", TaskStatus.TaskStatusError.ordinal());
|
|
|
|
|
+ taskinfo.putDouble("progress", 0.0);
|
|
|
|
|
+ taskinfo.putString("msg", "can not upload, please contact administrator.");
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
- }
|
|
|
|
|
- finally {
|
|
|
|
|
- synchronized (this)
|
|
|
|
|
- {
|
|
|
|
|
- Log.d("_synchronized", "UploadImage finally " );
|
|
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ synchronized (this) {
|
|
|
|
|
+ Log.d("_synchronized", "UploadImage finally ");
|
|
|
|
|
|
|
|
long timeStart = System.currentTimeMillis();
|
|
long timeStart = System.currentTimeMillis();
|
|
|
- if (uiUpdateListener!=null) {
|
|
|
|
|
|
|
+ if (uiUpdateListener != null) {
|
|
|
int index = arr_queue.indexOf(taskinfo);
|
|
int index = arr_queue.indexOf(taskinfo);
|
|
|
|
|
|
|
|
- uiUpdateListener.updateCell(index,taskinfo);
|
|
|
|
|
|
|
+ uiUpdateListener.updateCell(index, taskinfo);
|
|
|
}
|
|
}
|
|
|
Log.d("_synchronized", "UploadImage finally finish" + (System.currentTimeMillis() - timeStart));
|
|
Log.d("_synchronized", "UploadImage finally finish" + (System.currentTimeMillis() - timeStart));
|
|
|
|
|
|
|
@@ -336,7 +322,7 @@ public class RAUploadManager {
|
|
|
@Override
|
|
@Override
|
|
|
public void operateFinish(Bundle taskinfo) {
|
|
public void operateFinish(Bundle taskinfo) {
|
|
|
|
|
|
|
|
- TaskStatus status= TaskStatus.values()[taskinfo.getInt("status",0)];
|
|
|
|
|
|
|
+ TaskStatus status = TaskStatus.values()[taskinfo.getInt("status", 0)];
|
|
|
|
|
|
|
|
//新增逻辑,对于成功上传的图片,从书记删除
|
|
//新增逻辑,对于成功上传的图片,从书记删除
|
|
|
//taskinfo.getString("msg").indexOf("warning:")<0 没有匹配错误
|
|
//taskinfo.getString("msg").indexOf("warning:")<0 没有匹配错误
|
|
@@ -344,27 +330,24 @@ public class RAUploadManager {
|
|
|
File file = new File(path);
|
|
File file = new File(path);
|
|
|
//只有finish的task 可以删除图片
|
|
//只有finish的task 可以删除图片
|
|
|
|
|
|
|
|
- if(file.exists()&&taskinfo.getInt("status")== TaskStatus.TaskStatusFinish.ordinal()&&taskinfo.getString("msg").indexOf("warning:")<0)
|
|
|
|
|
- {
|
|
|
|
|
- String filepath=file.getAbsolutePath();
|
|
|
|
|
|
|
+ if (file.exists() && taskinfo.getInt("status") == TaskStatus.TaskStatusFinish.ordinal() && taskinfo.getString("msg").indexOf("warning:") < 0) {
|
|
|
|
|
+ String filepath = file.getAbsolutePath();
|
|
|
file.delete();
|
|
file.delete();
|
|
|
RAUtil.updateGallery(filepath);
|
|
RAUtil.updateGallery(filepath);
|
|
|
}
|
|
}
|
|
|
///////////////////////////////////////////////
|
|
///////////////////////////////////////////////
|
|
|
|
|
|
|
|
- boolean removefromlist=false;
|
|
|
|
|
|
|
+ boolean removefromlist = false;
|
|
|
// if (status==TaskStatus.TaskStatusFinish&&removeFinish)
|
|
// if (status==TaskStatus.TaskStatusFinish&&removeFinish)
|
|
|
// removefromlist=true;
|
|
// removefromlist=true;
|
|
|
// else if (status==TaskStatus.TaskStatusError&&removeError)
|
|
// else if (status==TaskStatus.TaskStatusError&&removeError)
|
|
|
// removefromlist=true;
|
|
// removefromlist=true;
|
|
|
|
|
|
|
|
- synchronized (this)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ synchronized (this) {
|
|
|
|
|
|
|
|
- Log.d("_synchronized", "OperationCallback operateFinish: " );
|
|
|
|
|
|
|
+ Log.d("_synchronized", "OperationCallback operateFinish: ");
|
|
|
long timeStart = System.currentTimeMillis();
|
|
long timeStart = System.currentTimeMillis();
|
|
|
- if(removefromlist)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ if (removefromlist) {
|
|
|
|
|
|
|
|
removeTask(taskinfo);
|
|
removeTask(taskinfo);
|
|
|
// arr_queue.remove(taskinfo);
|
|
// arr_queue.remove(taskinfo);
|
|
@@ -372,16 +355,13 @@ public class RAUploadManager {
|
|
|
// uiUpdateListener.updateList();
|
|
// uiUpdateListener.updateList();
|
|
|
|
|
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ } else {
|
|
|
saveTasks();
|
|
saveTasks();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Log.d("_synchronized", "OperationCallback operateFinish: end" + (System.currentTimeMillis() - timeStart));
|
|
Log.d("_synchronized", "OperationCallback operateFinish: end" + (System.currentTimeMillis() - timeStart));
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
// saveTasks();
|
|
// saveTasks();
|
|
|
|
|
|
|
|
|
|
|
|
@@ -397,19 +377,17 @@ public class RAUploadManager {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void loadTask()
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ private void loadTask() {
|
|
|
stopAllTasks();
|
|
stopAllTasks();
|
|
|
arr_queue = new ArrayList<Bundle>();
|
|
arr_queue = new ArrayList<Bundle>();
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
Log.d("_RAIMAGE", "saveTasks: RAUploadManager");
|
|
Log.d("_RAIMAGE", "saveTasks: RAUploadManager");
|
|
|
|
|
|
|
|
SharedPreferences pref = RedAntApplication.getInstance()
|
|
SharedPreferences pref = RedAntApplication.getInstance()
|
|
|
.getSharedPreferences("RA Image", 0);
|
|
.getSharedPreferences("RA Image", 0);
|
|
|
try {
|
|
try {
|
|
|
- String tasksBase64 = pref.getString("task_list", "");
|
|
|
|
|
|
|
+ String tasksBase64 = pref.getString("task_list", "");
|
|
|
|
|
|
|
|
|
|
|
|
|
// ArrayList<String> wrap_arr = new ArrayList<String>();
|
|
// ArrayList<String> wrap_arr = new ArrayList<String>();
|
|
@@ -432,21 +410,19 @@ public class RAUploadManager {
|
|
|
//
|
|
//
|
|
|
// editor.commit();
|
|
// editor.commit();
|
|
|
|
|
|
|
|
- if(tasksBase64.length()>0)
|
|
|
|
|
- {
|
|
|
|
|
- byte[] decode=Base64.decode(tasksBase64,Base64.DEFAULT);
|
|
|
|
|
- ByteArrayInputStream bais= new ByteArrayInputStream(decode);
|
|
|
|
|
|
|
+ if (tasksBase64.length() > 0) {
|
|
|
|
|
+ byte[] decode = Base64.decode(tasksBase64, Base64.DEFAULT);
|
|
|
|
|
+ ByteArrayInputStream bais = new ByteArrayInputStream(decode);
|
|
|
|
|
|
|
|
ObjectInputStream ois = null;
|
|
ObjectInputStream ois = null;
|
|
|
|
|
|
|
|
ois = new ObjectInputStream(bais);
|
|
ois = new ObjectInputStream(bais);
|
|
|
|
|
|
|
|
- ArrayList<String> arr_load=(ArrayList<String>)ois.readObject();
|
|
|
|
|
- for(String s:arr_load)
|
|
|
|
|
- {
|
|
|
|
|
- Log.d("_RAIMAGE", "loadTask: "+s);
|
|
|
|
|
|
|
+ ArrayList<String> arr_load = (ArrayList<String>) ois.readObject();
|
|
|
|
|
+ for (String s : arr_load) {
|
|
|
|
|
+ Log.d("_RAIMAGE", "loadTask: " + s);
|
|
|
JSONObject jsobj = new JSONObject(s);
|
|
JSONObject jsobj = new JSONObject(s);
|
|
|
- Bundle b=RAUtil.Json2Bundle(jsobj);
|
|
|
|
|
|
|
+ Bundle b = RAUtil.Json2Bundle(jsobj);
|
|
|
arr_queue.add(b);
|
|
arr_queue.add(b);
|
|
|
// String sjson=RAUtil.Bundle2Json(b).toString();
|
|
// String sjson=RAUtil.Bundle2Json(b).toString();
|
|
|
|
|
|
|
@@ -462,39 +438,36 @@ public class RAUploadManager {
|
|
|
} catch (JSONException e) {
|
|
} catch (JSONException e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
- for(Bundle b:arr_queue)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ for (Bundle b : arr_queue) {
|
|
|
|
|
|
|
|
- TaskStatus status= TaskStatus.values()[b.getInt("status",0)];
|
|
|
|
|
|
|
+ TaskStatus status = TaskStatus.values()[b.getInt("status", 0)];
|
|
|
|
|
|
|
|
- if (status!=TaskStatus.TaskStatusFinish&&status!=TaskStatus.TaskStatusError)
|
|
|
|
|
|
|
+ if (status != TaskStatus.TaskStatusFinish && status != TaskStatus.TaskStatusError)
|
|
|
startTask(b);
|
|
startTask(b);
|
|
|
}
|
|
}
|
|
|
// int a = 0;
|
|
// int a = 0;
|
|
|
// 此处缺少读取持久话保存任务队列的实现。
|
|
// 此处缺少读取持久话保存任务队列的实现。
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void addTask(Bundle task)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ public void addTask(Bundle task) {
|
|
|
|
|
|
|
|
- synchronized (this)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ synchronized (this) {
|
|
|
Log.d("_synchronized", "addTask: ");
|
|
Log.d("_synchronized", "addTask: ");
|
|
|
long timeStart = System.currentTimeMillis();
|
|
long timeStart = System.currentTimeMillis();
|
|
|
arr_queue.add(task);
|
|
arr_queue.add(task);
|
|
|
saveTasks();
|
|
saveTasks();
|
|
|
Log.d("_synchronized", "addTask: end" + (System.currentTimeMillis() - timeStart));
|
|
Log.d("_synchronized", "addTask: end" + (System.currentTimeMillis() - timeStart));
|
|
|
}
|
|
}
|
|
|
- if(newtaskStatus== TaskStatus.TaskStatusWait)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ if (newtaskStatus == TaskStatus.TaskStatusWait) {
|
|
|
startTask(task);
|
|
startTask(task);
|
|
|
}
|
|
}
|
|
|
- };
|
|
|
|
|
- public void addTasks(ArrayList<Bundle> tasks)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- synchronized (this)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ ;
|
|
|
|
|
+
|
|
|
|
|
+ public void addTasks(ArrayList<Bundle> tasks) {
|
|
|
|
|
+
|
|
|
|
|
+ synchronized (this) {
|
|
|
Log.d("_synchronized", "addTasks: ");
|
|
Log.d("_synchronized", "addTasks: ");
|
|
|
long timeStart = System.currentTimeMillis();
|
|
long timeStart = System.currentTimeMillis();
|
|
|
arr_queue.addAll(tasks);
|
|
arr_queue.addAll(tasks);
|
|
@@ -503,107 +476,97 @@ public class RAUploadManager {
|
|
|
Log.d("_synchronized", "addTasks: end" + (System.currentTimeMillis() - timeStart));
|
|
Log.d("_synchronized", "addTasks: end" + (System.currentTimeMillis() - timeStart));
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
- if(newtaskStatus== TaskStatus.TaskStatusWait)
|
|
|
|
|
- {
|
|
|
|
|
- for (Bundle task:tasks)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ if (newtaskStatus == TaskStatus.TaskStatusWait) {
|
|
|
|
|
+ for (Bundle task : tasks) {
|
|
|
startTask(task);
|
|
startTask(task);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- };
|
|
|
|
|
- public void startTask(Bundle task)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- task.putBoolean("iscancel",false);
|
|
|
|
|
|
|
+ ;
|
|
|
|
|
+
|
|
|
|
|
+ public void startTask(Bundle task) {
|
|
|
|
|
+
|
|
|
|
|
+ task.putBoolean("iscancel", false);
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean canstart = true;
|
|
boolean canstart = true;
|
|
|
|
|
|
|
|
- ConnectivityManager connManager = (ConnectivityManager) RedAntApplication.getInstance()
|
|
|
|
|
- .getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
|
|
|
-
|
|
|
|
|
- NetworkInfo networkInfo = connManager
|
|
|
|
|
- .getActiveNetworkInfo();
|
|
|
|
|
- if (networkInfo == null)
|
|
|
|
|
- {
|
|
|
|
|
- dbgUtil.Logd(
|
|
|
|
|
- "Current Network info",
|
|
|
|
|
- "can not get Active NetworkInfo!");
|
|
|
|
|
- canstart = false;
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- NetworkInfo.State netState = networkInfo
|
|
|
|
|
- .getState();
|
|
|
|
|
- if (netState != NetworkInfo.State.CONNECTED)
|
|
|
|
|
- {
|
|
|
|
|
- dbgUtil.Logd(
|
|
|
|
|
- "Current Network info",
|
|
|
|
|
- "not Connected!State="
|
|
|
|
|
- + netState);
|
|
|
|
|
- canstart = false;
|
|
|
|
|
- }
|
|
|
|
|
- int iconntype = -1;
|
|
|
|
|
- iconntype = networkInfo
|
|
|
|
|
- .getType();
|
|
|
|
|
-
|
|
|
|
|
- if(wifiOnly == true
|
|
|
|
|
- && iconntype !=
|
|
|
|
|
- ConnectivityManager.TYPE_WIFI
|
|
|
|
|
- && iconntype !=
|
|
|
|
|
- 9/* earthnet */)
|
|
|
|
|
- {
|
|
|
|
|
- canstart = false;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ ConnectivityManager connManager = (ConnectivityManager) RedAntApplication.getInstance()
|
|
|
|
|
+ .getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
|
|
|
+
|
|
|
|
|
+ NetworkInfo networkInfo = connManager
|
|
|
|
|
+ .getActiveNetworkInfo();
|
|
|
|
|
+ if (networkInfo == null) {
|
|
|
|
|
+ dbgUtil.Logd(
|
|
|
|
|
+ "Current Network info",
|
|
|
|
|
+ "can not get Active NetworkInfo!");
|
|
|
|
|
+ canstart = false;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ NetworkInfo.State netState = networkInfo
|
|
|
|
|
+ .getState();
|
|
|
|
|
+ if (netState != NetworkInfo.State.CONNECTED) {
|
|
|
|
|
+ dbgUtil.Logd(
|
|
|
|
|
+ "Current Network info",
|
|
|
|
|
+ "not Connected!State="
|
|
|
|
|
+ + netState);
|
|
|
|
|
+ canstart = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ int iconntype = -1;
|
|
|
|
|
+ iconntype = networkInfo
|
|
|
|
|
+ .getType();
|
|
|
|
|
+
|
|
|
|
|
+ if (wifiOnly == true
|
|
|
|
|
+ && iconntype !=
|
|
|
|
|
+ ConnectivityManager.TYPE_WIFI
|
|
|
|
|
+ && iconntype !=
|
|
|
|
|
+ 9/* earthnet */) {
|
|
|
|
|
+ canstart = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if(canstart) {
|
|
|
|
|
|
|
+ if (canstart) {
|
|
|
|
|
|
|
|
- task.putInt("retry_waiting",0);
|
|
|
|
|
|
|
+ task.putInt("retry_waiting", 0);
|
|
|
task.putInt("status", TaskStatus.TaskStatusWait.ordinal());
|
|
task.putInt("status", TaskStatus.TaskStatusWait.ordinal());
|
|
|
operation_queue.addOperation(task);
|
|
operation_queue.addOperation(task);
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ } else {
|
|
|
task.putInt("status", TaskStatus.TaskStatusStop.ordinal());
|
|
task.putInt("status", TaskStatus.TaskStatusStop.ordinal());
|
|
|
- if (uiUpdateListener!=null) {
|
|
|
|
|
|
|
+ if (uiUpdateListener != null) {
|
|
|
int index = arr_queue.indexOf(task);
|
|
int index = arr_queue.indexOf(task);
|
|
|
// uiUpdateListener.onProgress(index,percentage);
|
|
// uiUpdateListener.onProgress(index,percentage);
|
|
|
|
|
|
|
|
- uiUpdateListener.updateCell(index,task);
|
|
|
|
|
|
|
+ uiUpdateListener.updateCell(index, task);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- public void clearTask()
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ ;
|
|
|
|
|
+
|
|
|
|
|
+ public void clearTask() {
|
|
|
ArrayList<Bundle> remove = new ArrayList<Bundle>();
|
|
ArrayList<Bundle> remove = new ArrayList<Bundle>();
|
|
|
- for(Bundle b:arr_queue)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ for (Bundle b : arr_queue) {
|
|
|
// if(TaskStatus.values()[b.getInt("status",0)]==TaskStatus.TaskStatusStart||TaskStatus.values()[b.getInt("status",0)]==TaskStatus.TaskStatusWait)
|
|
// if(TaskStatus.values()[b.getInt("status",0)]==TaskStatus.TaskStatusStart||TaskStatus.values()[b.getInt("status",0)]==TaskStatus.TaskStatusWait)
|
|
|
// continue;
|
|
// continue;
|
|
|
|
|
|
|
|
- if(TaskStatus.values()[b.getInt("status",0)]==TaskStatus.TaskStatusFinish||TaskStatus.values()[b.getInt("status",0)]==TaskStatus.TaskStatusError)
|
|
|
|
|
|
|
+ if (TaskStatus.values()[b.getInt("status", 0)] == TaskStatus.TaskStatusFinish || TaskStatus.values()[b.getInt("status", 0)] == TaskStatus.TaskStatusError)
|
|
|
remove.add(b);
|
|
remove.add(b);
|
|
|
// removeTask(b);
|
|
// removeTask(b);
|
|
|
}
|
|
}
|
|
|
removeTasks(remove);
|
|
removeTasks(remove);
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
- public void removeTask(Bundle task)
|
|
|
|
|
- {
|
|
|
|
|
|
|
|
|
|
|
|
+ public void removeTask(Bundle task) {
|
|
|
|
|
|
|
|
- synchronized (this)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+
|
|
|
|
|
+ synchronized (this) {
|
|
|
Log.d("_synchronized", "removeTask");
|
|
Log.d("_synchronized", "removeTask");
|
|
|
long timeStart = System.currentTimeMillis();
|
|
long timeStart = System.currentTimeMillis();
|
|
|
arr_queue.remove(task);
|
|
arr_queue.remove(task);
|
|
@@ -613,65 +576,66 @@ public class RAUploadManager {
|
|
|
String path = filePath(task);
|
|
String path = filePath(task);
|
|
|
File file = new File(path);
|
|
File file = new File(path);
|
|
|
//只有finish的task 可以删除图片
|
|
//只有finish的task 可以删除图片
|
|
|
- if(file.exists()&&task.getInt("status")== TaskStatus.TaskStatusFinish.ordinal())
|
|
|
|
|
- {
|
|
|
|
|
- String filepath=file.getAbsolutePath();
|
|
|
|
|
|
|
+ if (file.exists() && task.getInt("status") == TaskStatus.TaskStatusFinish.ordinal()) {
|
|
|
|
|
+ String filepath = file.getAbsolutePath();
|
|
|
file.delete();
|
|
file.delete();
|
|
|
RAUtil.updateGallery(filepath);
|
|
RAUtil.updateGallery(filepath);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if(uiUpdateListener!=null)
|
|
|
|
|
|
|
+ if (uiUpdateListener != null)
|
|
|
uiUpdateListener.updateList(arr_queue);
|
|
uiUpdateListener.updateList(arr_queue);
|
|
|
|
|
|
|
|
Log.d("_synchronized", "removeTask: end" + (System.currentTimeMillis() - timeStart));
|
|
Log.d("_synchronized", "removeTask: end" + (System.currentTimeMillis() - timeStart));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- };
|
|
|
|
|
- public void removeTasks(List<Bundle> tasks)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ;
|
|
|
|
|
+
|
|
|
|
|
+ public void removeTasks(List<Bundle> tasks) {
|
|
|
|
|
|
|
|
- synchronized (this)
|
|
|
|
|
- {
|
|
|
|
|
- Log.d("_synchronized", "removeTasks: " );
|
|
|
|
|
|
|
+ synchronized (this) {
|
|
|
|
|
+ Log.d("_synchronized", "removeTasks: ");
|
|
|
long timeStart = System.currentTimeMillis();
|
|
long timeStart = System.currentTimeMillis();
|
|
|
arr_queue.removeAll(tasks);
|
|
arr_queue.removeAll(tasks);
|
|
|
saveTasks();
|
|
saveTasks();
|
|
|
- for(Bundle task:tasks)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ for (Bundle task : tasks) {
|
|
|
|
|
|
|
|
String path = filePath(task);
|
|
String path = filePath(task);
|
|
|
File file = new File(path);
|
|
File file = new File(path);
|
|
|
- if(file.exists()&&task.getInt("status")== TaskStatus.TaskStatusFinish.ordinal())
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ if (file.exists() && task.getInt("status") == TaskStatus.TaskStatusFinish.ordinal()) {
|
|
|
String filepath = file.getAbsolutePath();
|
|
String filepath = file.getAbsolutePath();
|
|
|
file.delete();
|
|
file.delete();
|
|
|
RAUtil.updateGallery(filepath);
|
|
RAUtil.updateGallery(filepath);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if(uiUpdateListener!=null)
|
|
|
|
|
|
|
+ if (uiUpdateListener != null)
|
|
|
uiUpdateListener.updateList(arr_queue);
|
|
uiUpdateListener.updateList(arr_queue);
|
|
|
|
|
|
|
|
|
|
|
|
|
Log.d("_synchronized", "removeTasks: end" + (System.currentTimeMillis() - timeStart));
|
|
Log.d("_synchronized", "removeTasks: end" + (System.currentTimeMillis() - timeStart));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- };
|
|
|
|
|
- public void stopAllTasks()
|
|
|
|
|
- {
|
|
|
|
|
- if(arr_queue==null)
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ;
|
|
|
|
|
+
|
|
|
|
|
+ public void stopAllTasks() {
|
|
|
|
|
+ if (arr_queue == null)
|
|
|
return;
|
|
return;
|
|
|
- for (Bundle task:arr_queue)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ for (Bundle task : arr_queue) {
|
|
|
stopTask(task);
|
|
stopTask(task);
|
|
|
}
|
|
}
|
|
|
- };
|
|
|
|
|
- public void stopTask(Bundle task)
|
|
|
|
|
- {
|
|
|
|
|
- if(task.getInt("status")!= TaskStatus.TaskStatusStart.ordinal()&&task.getInt("status")!= TaskStatus.TaskStatusWait.ordinal())
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ;
|
|
|
|
|
+
|
|
|
|
|
+ public void stopTask(Bundle task) {
|
|
|
|
|
+ if (task.getInt("status") != TaskStatus.TaskStatusStart.ordinal() && task.getInt("status") != TaskStatus.TaskStatusWait.ordinal())
|
|
|
return;
|
|
return;
|
|
|
|
|
|
|
|
- task.putBoolean("iscancel",true);
|
|
|
|
|
|
|
+ task.putBoolean("iscancel", true);
|
|
|
// long tid=task.getLong("tid",-1);
|
|
// long tid=task.getLong("tid",-1);
|
|
|
// if(tid>0)
|
|
// if(tid>0)
|
|
|
// {
|
|
// {
|
|
@@ -684,8 +648,8 @@ public class RAUploadManager {
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
- public void saveTasks()
|
|
|
|
|
- {
|
|
|
|
|
|
|
+
|
|
|
|
|
+ public void saveTasks() {
|
|
|
|
|
|
|
|
Log.d("_RAIMAGE", "saveTasks: RAUploadManager");
|
|
Log.d("_RAIMAGE", "saveTasks: RAUploadManager");
|
|
|
|
|
|
|
@@ -696,10 +660,9 @@ public class RAUploadManager {
|
|
|
try {
|
|
try {
|
|
|
|
|
|
|
|
ArrayList<String> wrap_arr = new ArrayList<String>();
|
|
ArrayList<String> wrap_arr = new ArrayList<String>();
|
|
|
- for( Bundle b:arr_queue)
|
|
|
|
|
- {
|
|
|
|
|
- String sjson=RAUtil.Bundle2Json(b).toString();
|
|
|
|
|
- Log.d("_RAIMAGE", "saveTasks: "+sjson);
|
|
|
|
|
|
|
+ for (Bundle b : arr_queue) {
|
|
|
|
|
+ String sjson = RAUtil.Bundle2Json(b).toString();
|
|
|
|
|
+ Log.d("_RAIMAGE", "saveTasks: " + sjson);
|
|
|
wrap_arr.add(sjson);
|
|
wrap_arr.add(sjson);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -722,9 +685,7 @@ public class RAUploadManager {
|
|
|
// ArrayList<String> arr_load=(ArrayList<String>)ois.readObject();
|
|
// ArrayList<String> arr_load=(ArrayList<String>)ois.readObject();
|
|
|
// int a = 0;
|
|
// int a = 0;
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
- catch (Exception e)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -747,17 +708,17 @@ public class RAUploadManager {
|
|
|
//
|
|
//
|
|
|
// editor.commit();
|
|
// editor.commit();
|
|
|
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ ;
|
|
|
|
|
|
|
|
|
|
|
|
|
- private String filePath(Bundle task)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ private String filePath(Bundle task) {
|
|
|
// String path = Environment.getExternalStorageDirectory().getPath();
|
|
// String path = Environment.getExternalStorageDirectory().getPath();
|
|
|
// path+="/"+task.getString("path");
|
|
// path+="/"+task.getString("path");
|
|
|
// path+="/"+task.getString("file");
|
|
// path+="/"+task.getString("file");
|
|
|
|
|
|
|
|
- return task.getString("path","");
|
|
|
|
|
|
|
+ return task.getString("path", "");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|