瀏覽代碼

RA Image Android

任务列表clear 按钮只能清除错误和完成的任务。
Ray Zhang 8 年之前
父節點
當前提交
5eeab42906

+ 5 - 24
RA Image/app/src/main/java/com/usai/redant/raimage/MainActivity.java

@@ -500,8 +500,9 @@ public class MainActivity extends AppCompatActivity
 
                         			new AlertDialog.Builder(MainActivity.this)
 					.setTitle("Warning")
-					.setMessage("Can not verify input information, add upload task anyway?")
-					.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
+					.setMessage("Can not connect to server and verify input information for now, add upload task anyway?")
+					.setPositiveButton("Yes", new DialogInterface.OnClickListener()
+                    {
 						@Override
 						public void onClick(DialogInterface dialog, int which)             {
 
@@ -966,17 +967,7 @@ public class MainActivity extends AppCompatActivity
                                     })
                                     .show();
 
-//                        new AlertDialog.Builder(MainActivity.this)
-//                                .setTitle("Warning")
-//                                .setMessage("You have setup upload via WIFI only, new task will not start until your phone connect to WIFI.")
-//                                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
-//                                    @Override
-//                                    public void onClick(DialogInterface dialog, int which) {
-//
-//                                    }
-//                                })
-//                                .show();
-//                        return;
+
 
                         }
                     }
@@ -985,17 +976,7 @@ public class MainActivity extends AppCompatActivity
 //				if(!canstart)
 //				{
 //
-//
-//                    new AlertDialog.Builder(MainActivity.this)
-//                            .setTitle("Warning")
-//                            .setMessage("You have setup upload via WIFI only, new task will not start until your phone connect to WIFI.")
-//                            .setPositiveButton("OK", new DialogInterface.OnClickListener() {
-//                                @Override
-//                                public void onClick(DialogInterface dialog, int which) {
-//
-//                                }
-//                            })
-//                            .show();
+
 ////                    new AlertDialog.Builder(MainActivity.this)
 ////                            .setTitle("Warning")
 ////                            .setMessage("App is set to upload via WIFI only. Please change your setting or try upload later.")

+ 28 - 24
RA Image/app/src/main/java/com/usai/redant/raimage/TaskActivity.java

@@ -365,34 +365,38 @@ public class TaskActivity extends AppCompatActivity {
                                     toast.show();
                                     return;
                                 }
-                                int iconntype = -1;
-                                iconntype = networkInfo
-                                        .getType();
-
-                                SharedPreferences pref = RedAntApplication
-                                        .getInstance()
-                                        .getSharedPreferences(
-                                                "UploadManager",
-                                                0);
-                                boolean
-                                        wifi_only
-                                        =pref.getBoolean("wifi_only",
-                                        false);
-                                if(wifi_only == true
-                                        && iconntype !=
-                                        ConnectivityManager.TYPE_WIFI
-                                        && iconntype !=
-                                        9/* earthnet */)
+                                else
                                 {
+                                    int iconntype = -1;
+                                    iconntype = networkInfo
+                                            .getType();
+
+                                    SharedPreferences pref = RedAntApplication
+                                            .getInstance()
+                                            .getSharedPreferences(
+                                                    "UploadManager",
+                                                    0);
+                                    boolean
+                                            wifi_only
+                                            =pref.getBoolean("wifi_only",
+                                            false);
+                                    if(wifi_only == true
+                                            && iconntype !=
+                                            ConnectivityManager.TYPE_WIFI
+                                            && iconntype !=
+                                            9/* earthnet */)
+                                    {
 //                                    canstart = false;
 
-                                    Toast toast = Toast.makeText(getApplicationContext(),
-                                            "App is set to upload via WIFI only. Please change your setting or try upload manually later.",
-                                            Toast.LENGTH_LONG);
-                                    toast.setGravity(Gravity.CENTER, 0, 0);
-                                    toast.show();
-                                    return;
+                                        Toast toast = Toast.makeText(getApplicationContext(),
+                                                "App is set to upload via WIFI only. Please change your setting or try upload manually later.",
+                                                Toast.LENGTH_LONG);
+                                        toast.setGravity(Gravity.CENTER, 0, 0);
+                                        toast.show();
+                                        return;
+                                    }
                                 }
+
                             }
 //                            if(!canstart)
 //                            {

+ 123 - 291
RA Image/app/src/main/java/com/usai/redant/raimage/UploadService.java

@@ -23,39 +23,37 @@ public class UploadService extends Service
 
 //	private UploadThread	uploadThread;
 
-	private boolean			queue_changed	= false;
+    private boolean queue_changed = false;
 //	LocationManager			locationManager;
 //	LocationListener		locationListener;
 
-	public RAUploadManager			uploadManager = new RAUploadManager();
+    public RAUploadManager uploadManager = new RAUploadManager();
 
-	// private boolean location_changed = false;
+    // private boolean location_changed = false;
 
-	@Override
-	public IBinder onBind(Intent intent)
-	{
-		// TODO Auto-generated method stub
+    @Override
+    public IBinder onBind(Intent intent) {
+        // TODO Auto-generated method stub
         Log.d("", "onBind: bind service");
         return new MyBinder();
-	}
-
+    }
 
 
-    public class MyBinder extends Binder{
+    public class MyBinder extends Binder {
         /**
          * 获取当前Service的实例
+         *
          * @return
          */
-        public UploadService getService(){
+        public UploadService getService() {
             return UploadService.this;
         }
     }
 
     @Override
-	public void onCreate()
-	{
+    public void onCreate() {
 
-		Log.d("_SERVICE", "create upload Service!!!");
+        Log.d("_SERVICE", "create upload Service!!!");
 //		if (uploadThread == null)
 //		{
 //			uploadThread = new UploadThread();
@@ -65,44 +63,44 @@ public class UploadService extends Service
 //		}
 
 
-		// 初始化异常捕获器
-		CrashHandler.getSharedInstance().init(getApplicationContext());
-		CrashHandler.getSharedInstance().preserver = new CrashHandler.InfoPreserver() {
-			@Override
-			public void saveUserInformation() {
-				if (uploadManager != null) {
-					uploadManager.saveTasks();
-				}
-			}
-
-			@Override
-			public void handleCrashInfo(String deviceInfo, String exception) {
-				dbgUtil.fileLog("============================ app crash ============================");
-				dbgUtil.fileLog("DEVICE");
-				dbgUtil.fileLog(deviceInfo);
-				dbgUtil.fileLog("EXCEPTION");
-				dbgUtil.fileLog(exception);
-				dbgUtil.fileLog("=============================== end ===============================");
-				Log.d("_SERVICE", "Device Info: " + deviceInfo);
-				Log.d("_SERVICE", "Crash Info: " + exception);
-			}
-		};
-
-		IntentFilter msgFilter = new IntentFilter();
-
-		msgFilter.addAction("REDANT.POP.MODIFY_QUEUE");
+        // 初始化异常捕获器
+        CrashHandler.getSharedInstance().init(getApplicationContext());
+        CrashHandler.getSharedInstance().preserver = new CrashHandler.InfoPreserver() {
+            @Override
+            public void saveUserInformation() {
+                if (uploadManager != null) {
+                    uploadManager.saveTasks();
+                }
+            }
+
+            @Override
+            public void handleCrashInfo(String deviceInfo, String exception) {
+                dbgUtil.fileLog("============================ app crash ============================");
+                dbgUtil.fileLog("DEVICE");
+                dbgUtil.fileLog(deviceInfo);
+                dbgUtil.fileLog("EXCEPTION");
+                dbgUtil.fileLog(exception);
+                dbgUtil.fileLog("=============================== end ===============================");
+                Log.d("_SERVICE", "Device Info: " + deviceInfo);
+                Log.d("_SERVICE", "Crash Info: " + exception);
+            }
+        };
+
+        IntentFilter msgFilter = new IntentFilter();
+
+        msgFilter.addAction("REDANT.POP.MODIFY_QUEUE");
 //		msgFilter.addAction("REDANT.POP.GPS_ON");
 //		msgFilter.addAction("REDANT.POP.GPS_OFF");
 //		msgFilter.addAction("REDANT.POP.REQUEST_LOCATION");
-		msgFilter.addAction("REDANT.POP.RESET_LOCATION");
-		msgFilter.addAction("REDANT.POP.QUERY_UPLOAD_STATE");
+        msgFilter.addAction("REDANT.POP.RESET_LOCATION");
+        msgFilter.addAction("REDANT.POP.QUERY_UPLOAD_STATE");
         msgFilter.addAction("REDANT.RAImage.ADD_TASK");
-		msgFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
-		msgFilter.addAction("REDANT.POP.RETRY_UPLOAD");
-		
-		registerReceiver(uploadReceiver, msgFilter);
-		// registerReceiver(uploadReceiver,
-		// new IntentFilter("modify upload queue"));
+        msgFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
+        msgFilter.addAction("REDANT.POP.RETRY_UPLOAD");
+
+        registerReceiver(uploadReceiver, msgFilter);
+        // registerReceiver(uploadReceiver,
+        // new IntentFilter("modify upload queue"));
 
 //		locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
 
@@ -145,13 +143,13 @@ public class UploadService extends Service
 //			}
 //		};
 
-		super.onCreate();
+        super.onCreate();
 
-	}
+    }
 
     @Override
     public void onDestroy() {
-        Log.e("_SERVICE", "onDestroy: " );
+        Log.e("_SERVICE", "onDestroy: ");
         uploadManager.saveTasks();
     }
 //	void gps_off()
@@ -287,10 +285,10 @@ public class UploadService extends Service
 //		// Log.d("location:", "lat:" + latitude + "lon:" + longitude);
 //	}
 
-	// void loadlist()
-	// {
-	//
-	// }
+    // void loadlist()
+    // {
+    //
+    // }
 
 //	public class UploadThread extends Thread
 //	{
@@ -472,245 +470,79 @@ public class UploadService extends Service
 //		}
 //	}
 
-	private BroadcastReceiver	uploadReceiver	=
-            new BroadcastReceiver()
-												{
-
-													public void onReceive(
-															Context context,
-															Intent intent)
-													{
-														String action = intent
-																.getAction();
-														// 如果捕捉到的action是ACTION_BATTERY_CHANGED
-
-                                                        if("REDANT.RAImage.ADD_TASK".equals(action))
-                                                        {
-
-                                                            ArrayList<Bundle> tasks= intent.getParcelableArrayListExtra("tasks");
-
-//                                                            uploadManager.addTasks();
-//
-//                                                            Bundle task=intent.getExtras();
-//
-//                                                            ArrayList<Bundle> arr= new ArrayList<Bundle>();
-//                                                            arr.add(new Bundle());
-//                                                            arr.add(new Bundle());
-//                                                            arr.add(new Bundle());
-//                                                            intent.putParcelableArrayListExtra("tasks",arr);
-//
-//                                                            intent.putParcelableArrayListExtra()
-//                                                            HashMap<>
-
-
-                                                            uploadManager.addTasks(tasks);
-                                                        }
-                                                        else if("REDANT.RAImage.SAVE_TASK".equals(action))
-                                                        {
-                                                            uploadManager.stopAllTasks();
-                                                        }
-
-//														else if ("REDANT.POP.REQUEST_LOCATION"
-//																.equals(action))
-//														{
-//															check_location();
-//															// if
-//															// (location_changed)
-//															// sendBroadcast(new
-//															// Intent(
-//															// "REDANT.POP.CHANGE_STATION"));
-//
-//														}
-//														else if ("REDANT.POP.RETRY_UPLOAD"
-//																.equals(action))
-//														{
-//															if (uploadThread != null)
-//															{
-//																if (uploadThread
-//																		.isAlive())
-//																{
-//
-//																	Log.d("uploadReceiver",
-//																			"upload thread alive");
-//																}
-//																else
-//																{
-//																	Log.d("uploadReceiver",
-//																			"start upload thread");
-//																	uploadThread = new UploadThread();
-//																	uploadThread
-//																			.start();
-//																}
-//															}
-//														}
-//														else if ("REDANT.POP.GPS_ON"
-//																.equals(action))
-//														{
-//															gps_on();
-//														}
-//														else if ("REDANT.POP.GPS_OFF"
-//																.equals(action))
-//														{
-//
-//															gps_off();
-//														}
-//														else if ("REDANT.POP.RESET_LOCATION"
-//																.equals(action))
-//														{
-//															update_location();
-//															// location_changed
-//															// = false;
-//														}
-//														else if ("REDANT.POP.MODIFY_QUEUE"
-//																.equals(action))
-//														{
-//															Log.d("uploadservice",
-//																	"recieve upload queue change");
-//															// update_location();
-//															if (uploadThread != null)
-//															{
-//																if (uploadThread
-//																		.isAlive())
-//																{
-//
-//																	Log.d("uploadReceiver",
-//																			"upload thread alive");
-//																}
-//																else
-//																{
-//																	Log.d("uploadReceiver",
-//																			"start upload thread");
-//																	uploadThread = new UploadThread();
-//																	uploadThread
-//																			.start();
-//																}
-//															}
-//														}
-//														else if ("REDANT.POP.QUERY_UPLOAD_STATE"
-//																.equals(action))
-//														{
-//															if (uploadThread
-//																	.isAlive())
-//															{
-//																sendBroadcast(new Intent(
-//																		"REDANT.POP.UPLOAD_STATE_TRUE"));
-//															}
-//															else
-//															{
-//																sendBroadcast(new Intent(
-//																		"REDANT.POP.UPLOAD_STATE_FALSE"));
-//															}
-//														}
-														else if (intent
-																.getAction()
-																.equals(ConnectivityManager.CONNECTIVITY_ACTION))
-														{
-
-															ConnectivityManager connManager = (ConnectivityManager) context
-																	.getSystemService(Context.CONNECTIVITY_SERVICE);
-
-															NetworkInfo networkInfo = connManager
-																	.getActiveNetworkInfo();
-															if (networkInfo == null)
-															{
-																dbgUtil.Logd(
-																		"Current Network info",
-																		"can not get Active NetworkInfo!");
-																return;
-															}
-															NetworkInfo.State netState = networkInfo
-																	.getState();
-															if (netState != NetworkInfo.State.CONNECTED)
-															{
-																dbgUtil.Logd(
-																		"Current Network info",
-																		"not Connected!State="
-																				+ netState);
-																return;
-															}
-															int iconntype = -1;
-															iconntype = networkInfo
-																	.getType();
-															SharedPreferences pref = RedAntApplication
-																	.getInstance()
-																	.getSharedPreferences(
-																			"UploadManager",
-																			0);
-
-//															String aa = pref
-//																	.getString(
-//																			"aa",
-//																			null);
-//															String ea = pref
-//																	.getString(
-//																			"ea",
-//																			null);
-//															if (iconntype == ConnectivityManager.TYPE_WIFI)
-//															{
-//																if (!TextUtils
-//																		.isEmpty(aa))
-//																	RedAntApplication.active_address = aa;
-//															}
-//															else
-//															{
-//																if (!TextUtils
-//																		.isEmpty(ea))
-//																	RedAntApplication.active_address = ea;
-//															}
-															 boolean
-																	 wifi_only
-															 =pref.getBoolean("wifi_only",
-															 false);
-
-															 if
-															 (wifi_only
-															 == true
-															 && iconntype !=
-															 ConnectivityManager.TYPE_WIFI
-															 && iconntype !=
-															 9/* earthnet */)
-															 {
-																 uploadManager.stopAllTasks();
+    private BroadcastReceiver uploadReceiver = new BroadcastReceiver() {
+
+        public void onReceive(Context context, Intent intent) {
+            String action = intent
+                    .getAction();
+            // 如果捕捉到的action是ACTION_BATTERY_CHANGED
+
+            if ("REDANT.RAImage.ADD_TASK".equals(action)) {
+
+                ArrayList<Bundle> tasks = intent.getParcelableArrayListExtra("tasks");
+
+
+                uploadManager.addTasks(tasks);
+            } else if ("REDANT.RAImage.SAVE_TASK".equals(action)) {
+                uploadManager.stopAllTasks();
+            } else if (intent
+                    .getAction()
+                    .equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
+
+                ConnectivityManager connManager = (ConnectivityManager) context
+                        .getSystemService(Context.CONNECTIVITY_SERVICE);
+
+                NetworkInfo networkInfo = connManager
+                        .getActiveNetworkInfo();
+                if (networkInfo == null) {
+                    dbgUtil.Logd(
+                            "Current Network info",
+                            "can not get Active NetworkInfo!");
+                    return;
+                }
+                NetworkInfo.State netState = networkInfo
+                        .getState();
+                if (netState != NetworkInfo.State.CONNECTED) {
+                    dbgUtil.Logd(
+                            "Current Network info",
+                            "not Connected!State="
+                                    + netState);
+                    return;
+                } else {
+                    int iconntype = -1;
+                    iconntype = networkInfo
+                            .getType();
+                    SharedPreferences pref = RedAntApplication
+                            .getInstance()
+                            .getSharedPreferences(
+                                    "UploadManager",
+                                    0);
+
+
+                    boolean
+                            wifi_only
+                            = pref.getBoolean("wifi_only",
+                            false);
+
+                    if
+                            (wifi_only
+                            == true
+                            && iconntype !=
+                            ConnectivityManager.TYPE_WIFI
+                            && iconntype !=
+                            9/* earthnet */) {
+                        uploadManager.stopAllTasks();
 //															 dbgUtil.Log(Log.DEBUG,
 //															 "Current Network info",
 //															 "not allowed!Connection type="
 //															 +
 //															 networkInfo.getTypeName());
-															 return ;
-															 }
-//															boolean bavailable = networkInfo
-//																	.isAvailable();
-//															String strtype = networkInfo
-//																	.getTypeName();
-//
-//															dbgUtil.Logd(
-//																	"Current Network info",
-//																	" type = "
-//																			+ strtype
-//																			+ " abailable = "
-//																			+ bavailable
-//																			+ " state "
-//																			+ netState);
-//															if (bavailable)
-//															{
-//																if (uploadThread
-//																		.isAlive())
-//																{
-//
-//																	Log.d("uploadReceiver",
-//																			"upload thread alive");
-//																}
-//																else
-//																{
-//																	Log.d("uploadReceiver",
-//																			"start upload thread");
-//																	uploadThread = new UploadThread();
-//																	uploadThread
-//																			.start();
-//																}
-//															}
-
-														}
-													}
-												};
+                        return;
+                    }
+                }
+
+
+            }
+        }
+    };
 }

+ 5 - 3
RA Image/app/src/main/java/com/usai/util/RAUploadManager.java

@@ -585,9 +585,11 @@ public class RAUploadManager {
         ArrayList<Bundle> remove = new ArrayList<Bundle>();
         for(Bundle b:arr_queue)
         {
-            if(TaskStatus.values()[b.getInt("status",0)]==TaskStatus.TaskStatusStart||TaskStatus.values()[b.getInt("status",0)]==TaskStatus.TaskStatusWait)
-                continue;
-            remove.add(b);
+//            if(TaskStatus.values()[b.getInt("status",0)]==TaskStatus.TaskStatusStart||TaskStatus.values()[b.getInt("status",0)]==TaskStatus.TaskStatusWait)
+//                continue;
+
+            if(TaskStatus.values()[b.getInt("status",0)]==TaskStatus.TaskStatusFinish||TaskStatus.values()[b.getInt("status",0)]==TaskStatus.TaskStatusError)
+                remove.add(b);
 //            removeTask(b);
         }
         removeTasks(remove);