浏览代码

RA Image Android

1 增加停止任务逻辑
2 增加bundle保存
3 精简项目,去掉部分无用的代码和类
Ray Zhang 8 年之前
父节点
当前提交
f86487f453

+ 7 - 6
RA Image/app/src/main/java/com/usai/redant/raimage/LockerActivity.java

@@ -1,9 +1,5 @@
 package com.usai.redant.raimage;
 
-import com.usai.util.Crypto;
-import com.usai.util.Network;
-import com.usai.util.dbUtil;
-
 import android.animation.Animator;
 import android.animation.AnimatorListenerAdapter;
 import android.annotation.TargetApi;
@@ -27,6 +23,11 @@ import android.widget.EditText;
 import android.widget.TextView;
 import android.widget.Toast;
 
+import com.usai.util.AES;
+import com.usai.util.Crypto;
+import com.usai.util.Network;
+import com.usai.util.dbUtil;
+
 /**
  * Activity which displays a login screen to the user, offering registration as
  * well.
@@ -306,8 +307,8 @@ public class LockerActivity extends Activity
 				String encryptPass="";
 				try
 				{
-					encryptUser=Crypto.encrypt("apexu", m_sName);
-					encryptPass=Crypto.encrypt("apexp", m_sPassword);
+					encryptUser=AES.encrypt("apexu", m_sName);
+					encryptPass= AES.encrypt("apexp", m_sPassword);
 				}
 				catch (Exception e1)
 				{

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

@@ -253,8 +253,8 @@ public class MainActivity extends AppCompatActivity
 					for (String path : photoList) {
 						Bundle task = new Bundle();
 
-						task.putString("path",name);
-						task.putString("file",path);
+						task.putString("path",path);
+						task.putString("file",RAUtil.lastPathComponent(path));
 						task.putString("url",RedAntApplication.active_address);
 
 						String md5 = MD5.md5sum(path);

+ 98 - 9
RA Image/app/src/main/java/com/usai/redant/raimage/UploadList/UploadListActivity.java

@@ -6,13 +6,13 @@ import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.ServiceConnection;
+import android.os.Bundle;
 import android.os.IBinder;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.v4.content.LocalBroadcastManager;
 import android.support.v7.app.ActionBar;
 import android.support.v7.app.AppCompatActivity;
-import android.os.Bundle;
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.MenuItem;
@@ -68,6 +68,68 @@ public class UploadListActivity extends AppCompatActivity {
             });
 
         }
+
+        @Override
+        public void updateCell(long index, final Bundle taskinfo)
+        {
+            final int position = (int)index;
+            final double progress = arr.get(position).getDouble("progress");
+            runOnUiThread(new Runnable() {
+                @Override
+                public void run() {
+                    Log.d("Upload Progress", " " + progress);
+//            Object item = uploadList.getItemAtPosition((int) index);
+                    int startShowIndex = uploadList.getFirstVisiblePosition();
+                    int lastShowIndex = uploadList.getLastVisiblePosition();
+
+                    if (position >= startShowIndex && position <= lastShowIndex) {
+                        View cell = uploadList.getChildAt((int)position - startShowIndex);
+                        uploadAdapter.ViewHolder holder= (uploadAdapter.ViewHolder)cell.getTag();
+//                        holder.progressBar.setProgress((int) (100 * progress));
+//                        holder.progress_tv.setText(String.format("%.1f%%",progress * 100));
+
+
+                        RAUploadManager.TaskStatus istatus = RAUploadManager.TaskStatus.values()[taskinfo.getInt("status",0)];
+                        String status="";
+                        switch(istatus)
+                        {
+                            case TaskStatusStart:
+                                status="uploading";
+                                break;
+                            case TaskStatusStop:
+                                status="stop";
+                                break;
+                            case TaskStatusError:
+                                status="warring";
+                                break;
+                            case TaskStatusWait:
+                                status="waiting";
+                                break;
+                            case TaskStatusFinish:
+                                status="finish";
+                                break;
+
+                            default:
+                                status="warring";
+                                break;
+                        }
+                        double percent = taskinfo.getDouble("progress",0);
+                        String err = taskinfo.getString("msg");
+                        String name = taskinfo.getString("file","");
+                        holder.name_tv.setText(name);
+                        holder.progressBar.setProgress(100 *(int)percent);
+                        holder.state_tv.setText(status);
+                        holder.progress_tv.setText(100*percent+"%");
+                        holder.err_tv.setText(err);
+                    }
+                }
+            });
+        }
+        @Override
+        public void updateList()
+        {
+
+        }
     };
 
     @Override
@@ -154,9 +216,36 @@ public class UploadListActivity extends AppCompatActivity {
         public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
 
             Bundle item = arr.get(position);
-            Bundle params = item.getBundle("params");
-            String barcode = params.getString("barcode");
-
+            Bundle taskinfo = item.getBundle("params");
+//            String barcode = taskinfo.getString("barcode");
+
+            RAUploadManager.TaskStatus istatus = RAUploadManager.TaskStatus.values()[taskinfo.getInt("status",0)];
+            String status="";
+            switch(istatus)
+            {
+                case TaskStatusStart:
+                    status="uploading";
+                    break;
+                case TaskStatusStop:
+                    status="stop";
+                    break;
+                case TaskStatusError:
+                    status="warring";
+                    break;
+                case TaskStatusWait:
+                    status="waiting";
+                    break;
+                case TaskStatusFinish:
+                    status="finish";
+                    break;
+
+                default:
+                    status="warring";
+                    break;
+            }
+            double percent = taskinfo.getDouble("progress",0);
+            String err = taskinfo.getString("msg");
+            String name = taskinfo.getString("file","");
 
             View cell;
             ViewHolder holder;
@@ -178,11 +267,11 @@ public class UploadListActivity extends AppCompatActivity {
                 cell.setTag(holder);
             }
 
-            holder.name_tv.setText(barcode);
-            holder.progressBar.setProgress(0);
-            holder.state_tv.setText("");
-            holder.progress_tv.setText("");
-            holder.err_tv.setText("");
+            holder.name_tv.setText(name);
+            holder.progressBar.setProgress((int)percent);
+            holder.state_tv.setText(status);
+            holder.progress_tv.setText(percent+"");
+            holder.err_tv.setText(err);
 
             return cell;
         }

+ 432 - 443
RA Image/app/src/main/java/com/usai/redant/raimage/UploadService.java

@@ -1,26 +1,11 @@
 package com.usai.redant.raimage;
 
-import java.io.File;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-
-import com.usai.util.Crypto;
-import com.usai.util.Network;
-import com.usai.util.RAUploadManager;
-import com.usai.util.RAUtil;
-import com.usai.util.dbUtil;
-import com.usai.util.dbgUtil;
-
 import android.app.Service;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.SharedPreferences;
-import android.database.Cursor;
-import android.database.sqlite.SQLiteDatabase;
 import android.location.Location;
 import android.location.LocationListener;
 import android.location.LocationManager;
@@ -28,15 +13,19 @@ import android.net.ConnectivityManager;
 import android.net.NetworkInfo;
 import android.os.Binder;
 import android.os.Bundle;
-import android.os.Environment;
 import android.os.IBinder;
 import android.text.TextUtils;
 import android.util.Log;
 
+import com.usai.util.RAUploadManager;
+import com.usai.util.dbgUtil;
+
+import java.util.ArrayList;
+
 public class UploadService extends Service
 {
 
-	private UploadThread	uploadThread;
+//	private UploadThread	uploadThread;
 
 	private boolean			queue_changed	= false;
 	LocationManager			locationManager;
@@ -70,13 +59,13 @@ public class UploadService extends Service
 	{
 
 		Log.d("", "create upload Service!!!");
-		if (uploadThread == null)
-		{
-			uploadThread = new UploadThread();
-			Log.d("", "create upload thread!!!");
-			// upleadThread.start();
-
-		}
+//		if (uploadThread == null)
+//		{
+//			uploadThread = new UploadThread();
+//			Log.d("", "create upload thread!!!");
+//			// upleadThread.start();
+//
+//		}
 
 		IntentFilter msgFilter = new IntentFilter();
 
@@ -139,323 +128,323 @@ public class UploadService extends Service
 
 	}
 
-	void gps_off()
-	{
-		locationManager.removeUpdates(locationListener);
-	}
-
-	void gps_on()
-	{
-		if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
-		{
-
-//            RedAntApplication.getInstance()
-
-//            if(!RAUtil.checkPermission(this.getApplicationContext(),"android.permission.ACCESS_FINE_LOCATION"))
-//                return;
-
-
-
-			locationManager.requestLocationUpdates(
-					LocationManager.GPS_PROVIDER, 60 * 1000, 50,
-					locationListener);
-
-		}
-		else if (locationManager
-				.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
-		{
-
-			locationManager.requestLocationUpdates(
-					LocationManager.NETWORK_PROVIDER, 30 * 1000, 50,
-					locationListener);
-
-		}
-	}
-
-	void update_location()
-	{
-
-		Location location = null;
-		if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
-		{
-
-			location = locationManager
-					.getLastKnownLocation(LocationManager.GPS_PROVIDER);
-
-		}
-		else if (locationManager
-				.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
-		{
-
-			location = locationManager
-					.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
-
-		}
-
-		SharedPreferences pref = RedAntApplication.getInstance()
-				.getSharedPreferences("RA Image", 0);
-
-		SharedPreferences.Editor editor = pref.edit();
-		if (location != null)
-		{
-
-			editor.putFloat("Lat", (float) location.getLatitude());
-			editor.putFloat("Lon", (float) location.getLongitude());
-
-		}
-		editor.commit();
-
-	}
-
-	void check_location()
-	{
-
-		Location location = null;
-		if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
-		{
-
-			location = locationManager
-					.getLastKnownLocation(LocationManager.GPS_PROVIDER);
-
-		}
-		else if (locationManager
-				.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
-		{
-
-			location = locationManager
-					.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
-
-		}
-
-		SharedPreferences pref = RedAntApplication.getInstance()
-				.getSharedPreferences("RA Image", 0);
-		double lat = pref.getFloat("Lat", 9999);
-		double lon = pref.getFloat("Lon", 9999);
-
-		// SharedPreferences.Editor editor = pref.edit();
-		if (location != null)
-		{
-			float[] result = new float[1];
-			if (lat != 9999 && lon != 9999)
-			{
-				Location.distanceBetween(lat, lon, location.getLatitude(),
-						location.getLongitude(), result);
-				if (result[0] > 1000)
-				{
-					sendBroadcast(new Intent("REDANT.POP.STATION_CHANGE"));
-					return;
-				}
-				else
-				{
-					sendBroadcast(new Intent("REDANT.POP.STATION_NOT_CHANGE"));
-					return;
-				}
-			}
-			sendBroadcast(new Intent("REDANT.POP.STATION_NOT_CHANGE"));
-			return;
-			// new Location();
-			//
-			// Location.distanceBetween(lat, lon, endLatitude, endLongitude,
-			// results)
-			//
-			// editor.putFloat("Lat", (float) location.getLatitude());
-			// editor.putFloat("Lon", (float) location.getLongitude());
-
-		}
-		else
-		{
-			sendBroadcast(new Intent("REDANT.POP.STATION_NOT_CHANGE"));
-			return;
-		}
-		// editor.commit();
+//	void gps_off()
+//	{
+//		locationManager.removeUpdates(locationListener);
+//	}
+//
+//	void gps_on()
+//	{
+//		if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
+//		{
+//
+////            RedAntApplication.getInstance()
+//
+////            if(!RAUtil.checkPermission(this.getApplicationContext(),"android.permission.ACCESS_FINE_LOCATION"))
+////                return;
+//
+//
+//
+//			locationManager.requestLocationUpdates(
+//					LocationManager.GPS_PROVIDER, 60 * 1000, 50,
+//					locationListener);
+//
+//		}
+//		else if (locationManager
+//				.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
+//		{
+//
+//			locationManager.requestLocationUpdates(
+//					LocationManager.NETWORK_PROVIDER, 30 * 1000, 50,
+//					locationListener);
+//
+//		}
+//	}
 
-		// Log.d("location:", "lat:" + latitude + "lon:" + longitude);
-	}
+//	void update_location()
+//	{
+//
+//		Location location = null;
+//		if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
+//		{
+//
+//			location = locationManager
+//					.getLastKnownLocation(LocationManager.GPS_PROVIDER);
+//
+//		}
+//		else if (locationManager
+//				.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
+//		{
+//
+//			location = locationManager
+//					.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
+//
+//		}
+//
+//		SharedPreferences pref = RedAntApplication.getInstance()
+//				.getSharedPreferences("RA Image", 0);
+//
+//		SharedPreferences.Editor editor = pref.edit();
+//		if (location != null)
+//		{
+//
+//			editor.putFloat("Lat", (float) location.getLatitude());
+//			editor.putFloat("Lon", (float) location.getLongitude());
+//
+//		}
+//		editor.commit();
+//
+//	}
+//
+//	void check_location()
+//	{
+//
+//		Location location = null;
+//		if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
+//		{
+//
+//			location = locationManager
+//					.getLastKnownLocation(LocationManager.GPS_PROVIDER);
+//
+//		}
+//		else if (locationManager
+//				.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
+//		{
+//
+//			location = locationManager
+//					.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
+//
+//		}
+//
+//		SharedPreferences pref = RedAntApplication.getInstance()
+//				.getSharedPreferences("RA Image", 0);
+//		double lat = pref.getFloat("Lat", 9999);
+//		double lon = pref.getFloat("Lon", 9999);
+//
+//		// SharedPreferences.Editor editor = pref.edit();
+//		if (location != null)
+//		{
+//			float[] result = new float[1];
+//			if (lat != 9999 && lon != 9999)
+//			{
+//				Location.distanceBetween(lat, lon, location.getLatitude(),
+//						location.getLongitude(), result);
+//				if (result[0] > 1000)
+//				{
+//					sendBroadcast(new Intent("REDANT.POP.STATION_CHANGE"));
+//					return;
+//				}
+//				else
+//				{
+//					sendBroadcast(new Intent("REDANT.POP.STATION_NOT_CHANGE"));
+//					return;
+//				}
+//			}
+//			sendBroadcast(new Intent("REDANT.POP.STATION_NOT_CHANGE"));
+//			return;
+//			// new Location();
+//			//
+//			// Location.distanceBetween(lat, lon, endLatitude, endLongitude,
+//			// results)
+//			//
+//			// editor.putFloat("Lat", (float) location.getLatitude());
+//			// editor.putFloat("Lon", (float) location.getLongitude());
+//
+//		}
+//		else
+//		{
+//			sendBroadcast(new Intent("REDANT.POP.STATION_NOT_CHANGE"));
+//			return;
+//		}
+//		// editor.commit();
+//
+//		// Log.d("location:", "lat:" + latitude + "lon:" + longitude);
+//	}
 
 	// void loadlist()
 	// {
 	//
 	// }
 
-	public class UploadThread extends Thread
-	{
-		@Override
-		public void run()
-		{
-
-			Log.d("", "upload thread running");
-
-			super.run();
-			doupload();
-			Log.d("", "upload thread stop");
-
-		}
-
-		private void doupload()
-		{
-			boolean error = false;
-			boolean didupload = false;
-			// int verifyresult = Network.VerifyUser(RedAntApplication.user,
-			// RedAntApplication.password);
-			// if (verifyresult == Network.RESULT_TRUE)
-			// {
-			SQLiteDatabase dbr = dbUtil.OpenDB(UploadService.this, null, false);
-			Cursor cursor = dbr.query("pics", new String[] { "_id", "pid",
-					"local_path", "picker", "server" }, "err_code!="
-					+ Network.AP_UPLOAD_SUCCESS+" and err_code!="+ Network.RESULT_LOCALFILE_ERROR+" and try_count<3 ", null, null, null, "_id", null);
-			while (cursor.moveToNext())
-			{
-				didupload = true;
-				if (queue_changed)
-				{
-					queue_changed = false;
-					dbUtil.CloseCursor(cursor);
-					cursor = dbr.query("pics", new String[] { "_id", "pid",
-							"local_path", "picker", "server" }, "err_code!="
-							+ Network.AP_UPLOAD_SUCCESS+" and err_code!="+ Network.RESULT_LOCALFILE_ERROR +" and try_count<3 ", null, null, null,
-							"_id", null);
-					if (!cursor.moveToNext())
-						break;
-
-				}
-				int _id = cursor.getInt(0);
-				String pid = cursor.getString(1);
-				String path = cursor.getString(2);
-				String picker = cursor.getString(3);
-				String server = cursor.getString(4);
-
-				String encryptUser = "";
-
-				try
-				{
-					encryptUser = Crypto.encrypt("apexu", picker);
-
-				}
-				catch (Exception e1)
-				{
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-
-				Cursor cursor_user = dbr.query("users",
-						new String[] { "pass" }, "name='" + encryptUser + "'",
-						null, null, null, "_id", null);
-				String pass = "";
-				if (cursor_user.moveToNext())
-					pass = cursor_user.getString(0);
-				try
-				{
-					pass = Crypto.decrypt("apexp", pass);
-				}
-				catch (Exception e)
-				{
-					// TODO Auto-generated catch block
-					e.printStackTrace();
-				}
-
-				int uploadresult = Network.UploadImage(path, picker, pass, pid,
-						server);
-				if (uploadresult == Network.RESULT_TRUE)
-				{
-				
-					RedAntApplication.writeLock.lock();
-
-					// write sql process
-					SQLiteDatabase dbw = dbUtil.OpenDB(UploadService.this,
-							null, true);
-					// String sql = "update pics set err_code ="
-					// + Network.AP_UPLOAD_SUCCESS + " where _id="
-					// + _id;
-					String sql = "delete from pics  where _id=" + _id;
-					dbw.execSQL(sql);
-
-					String timeStamp = new SimpleDateFormat("yyyy_MM_dd")
-							.format(new Date());
-
-					File storageDir = new File(Environment
-							.getExternalStorageDirectory().getPath()
-							+ "/redant/pop/done/" + timeStamp);
-
-					if (!storageDir.exists())
-						storageDir.mkdirs();
-
-					File pic = new File(path);
-					// pic.delete();
-
-					dbUtil.CloseDB(dbw);
-					RedAntApplication.writeLock.unlock();
-					dbgUtil.fileLog("upload success move file "
-							+ pic.getName()
-							+ " to "
-							+ Environment.getExternalStorageDirectory()
-									.getPath() + "/redant/pop/done/"
-							+ timeStamp + File.separator);
-					pic.renameTo(new File(Environment
-							.getExternalStorageDirectory().getPath()
-							+ "/redant/pop/done/"
-							+ timeStamp
-							+ File.separator
-							+ pic.getName()));
-					
-
-				}
-				else
-				{
-					error = true;
-					RedAntApplication.writeLock.lock();
-
-					{
-						// write sql process
-						SQLiteDatabase dbw = dbUtil.OpenDB(UploadService.this,
-								null, true);
-						String sql = "update pics set err_code ="
-								+ uploadresult + ", try_count = try_count+1 where _id=" + _id;
-
-						dbw.execSQL(sql);
-						dbUtil.CloseDB(dbw);
-					}
-					RedAntApplication.writeLock.unlock();
-					dbgUtil.fileLog("upload failed pid:" + pid + " file:"
-							+ path + " server:" + server + " err_code:"
-							+ uploadresult);
-					
-				}
-
-				sendBroadcast(new Intent("REDANT.POP.UPDATE_QUEUE_VIEW"));
-			}
-
-			dbUtil.CloseCursor(cursor);
-			dbUtil.CloseDB(dbr);
-
-			// }
-			// else
-			// {
-			// Log.d("upload thread", "user check failed!");
-			//
-			// sendBroadcast(new Intent("REDANT.POP.USER_CHECK_FAILED"));
-			// }
-
-			if (queue_changed)
-			{
-				queue_changed = false;
-				doupload();
-			}
-			if (didupload)
-			{
-				if (error)
-				{
-					sendBroadcast(new Intent(
-							"REDANT.POP.FINISH_UPLOAD_QUEUE_WITH_ERROR"));
-					RedAntApplication.startalarm();
-				}
-				else
-				{
-					sendBroadcast(new Intent("REDANT.POP.FINISH_UPLOAD_QUEUE"));
-					RedAntApplication.cancelalarm();
-				}
-			}
-		}
-	}
+//	public class UploadThread extends Thread
+//	{
+//		@Override
+//		public void run()
+//		{
+//
+//			Log.d("", "upload thread running");
+//
+//			super.run();
+//			doupload();
+//			Log.d("", "upload thread stop");
+//
+//		}
+//
+//		private void doupload()
+//		{
+//			boolean error = false;
+//			boolean didupload = false;
+//			// int verifyresult = Network.VerifyUser(RedAntApplication.user,
+//			// RedAntApplication.password);
+//			// if (verifyresult == Network.RESULT_TRUE)
+//			// {
+//			SQLiteDatabase dbr = dbUtil.OpenDB(UploadService.this, null, false);
+//			Cursor cursor = dbr.query("pics", new String[] { "_id", "pid",
+//					"local_path", "picker", "server" }, "err_code!="
+//					+ Network.AP_UPLOAD_SUCCESS+" and err_code!="+ Network.RESULT_LOCALFILE_ERROR+" and try_count<3 ", null, null, null, "_id", null);
+//			while (cursor.moveToNext())
+//			{
+//				didupload = true;
+//				if (queue_changed)
+//				{
+//					queue_changed = false;
+//					dbUtil.CloseCursor(cursor);
+//					cursor = dbr.query("pics", new String[] { "_id", "pid",
+//							"local_path", "picker", "server" }, "err_code!="
+//							+ Network.AP_UPLOAD_SUCCESS+" and err_code!="+ Network.RESULT_LOCALFILE_ERROR +" and try_count<3 ", null, null, null,
+//							"_id", null);
+//					if (!cursor.moveToNext())
+//						break;
+//
+//				}
+//				int _id = cursor.getInt(0);
+//				String pid = cursor.getString(1);
+//				String path = cursor.getString(2);
+//				String picker = cursor.getString(3);
+//				String server = cursor.getString(4);
+//
+//				String encryptUser = "";
+//
+//				try
+//				{
+//					encryptUser = AES.encrypt("apexu", picker);
+//
+//				}
+//				catch (Exception e1)
+//				{
+//					// TODO Auto-generated catch block
+//					e1.printStackTrace();
+//				}
+//
+//				Cursor cursor_user = dbr.query("users",
+//						new String[] { "pass" }, "name='" + encryptUser + "'",
+//						null, null, null, "_id", null);
+//				String pass = "";
+//				if (cursor_user.moveToNext())
+//					pass = cursor_user.getString(0);
+//				try
+//				{
+//					pass = AES.decrypt("apexp", pass);
+//				}
+//				catch (Exception e)
+//				{
+//					// TODO Auto-generated catch block
+//					e.printStackTrace();
+//				}
+//
+//				int uploadresult = Network.UploadImage(path, picker, pass, pid,
+//						server);
+//				if (uploadresult == Network.RESULT_TRUE)
+//				{
+//
+//					RedAntApplication.writeLock.lock();
+//
+//					// write sql process
+//					SQLiteDatabase dbw = dbUtil.OpenDB(UploadService.this,
+//							null, true);
+//					// String sql = "update pics set err_code ="
+//					// + Network.AP_UPLOAD_SUCCESS + " where _id="
+//					// + _id;
+//					String sql = "delete from pics  where _id=" + _id;
+//					dbw.execSQL(sql);
+//
+//					String timeStamp = new SimpleDateFormat("yyyy_MM_dd")
+//							.format(new Date());
+//
+//					File storageDir = new File(Environment
+//							.getExternalStorageDirectory().getPath()
+//							+ "/redant/pop/done/" + timeStamp);
+//
+//					if (!storageDir.exists())
+//						storageDir.mkdirs();
+//
+//					File pic = new File(path);
+//					// pic.delete();
+//
+//					dbUtil.CloseDB(dbw);
+//					RedAntApplication.writeLock.unlock();
+//					dbgUtil.fileLog("upload success move file "
+//							+ pic.getName()
+//							+ " to "
+//							+ Environment.getExternalStorageDirectory()
+//									.getPath() + "/redant/pop/done/"
+//							+ timeStamp + File.separator);
+//					pic.renameTo(new File(Environment
+//							.getExternalStorageDirectory().getPath()
+//							+ "/redant/pop/done/"
+//							+ timeStamp
+//							+ File.separator
+//							+ pic.getName()));
+//
+//
+//				}
+//				else
+//				{
+//					error = true;
+//					RedAntApplication.writeLock.lock();
+//
+//					{
+//						// write sql process
+//						SQLiteDatabase dbw = dbUtil.OpenDB(UploadService.this,
+//								null, true);
+//						String sql = "update pics set err_code ="
+//								+ uploadresult + ", try_count = try_count+1 where _id=" + _id;
+//
+//						dbw.execSQL(sql);
+//						dbUtil.CloseDB(dbw);
+//					}
+//					RedAntApplication.writeLock.unlock();
+//					dbgUtil.fileLog("upload failed pid:" + pid + " file:"
+//							+ path + " server:" + server + " err_code:"
+//							+ uploadresult);
+//
+//				}
+//
+//				sendBroadcast(new Intent("REDANT.POP.UPDATE_QUEUE_VIEW"));
+//			}
+//
+//			dbUtil.CloseCursor(cursor);
+//			dbUtil.CloseDB(dbr);
+//
+//			// }
+//			// else
+//			// {
+//			// Log.d("upload thread", "user check failed!");
+//			//
+//			// sendBroadcast(new Intent("REDANT.POP.USER_CHECK_FAILED"));
+//			// }
+//
+//			if (queue_changed)
+//			{
+//				queue_changed = false;
+//				doupload();
+//			}
+//			if (didupload)
+//			{
+//				if (error)
+//				{
+//					sendBroadcast(new Intent(
+//							"REDANT.POP.FINISH_UPLOAD_QUEUE_WITH_ERROR"));
+//					RedAntApplication.startalarm();
+//				}
+//				else
+//				{
+//					sendBroadcast(new Intent("REDANT.POP.FINISH_UPLOAD_QUEUE"));
+//					RedAntApplication.cancelalarm();
+//				}
+//			}
+//		}
+//	}
 
 	private BroadcastReceiver	uploadReceiver	=
             new BroadcastReceiver()
@@ -491,97 +480,97 @@ public class UploadService extends Service
                                                             uploadManager.addTasks(tasks);
                                                         }
 
-														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 ("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))
@@ -674,24 +663,24 @@ public class UploadService extends Service
 																			+ 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();
-																}
-															}
+//															if (bavailable)
+//															{
+//																if (uploadThread
+//																		.isAlive())
+//																{
+//
+//																	Log.d("uploadReceiver",
+//																			"upload thread alive");
+//																}
+//																else
+//																{
+//																	Log.d("uploadReceiver",
+//																			"start upload thread");
+//																	uploadThread = new UploadThread();
+//																	uploadThread
+//																			.start();
+//																}
+//															}
 
 														}
 													}

+ 17 - 0
RA Image/app/src/main/java/com/usai/util/Network.java

@@ -1140,6 +1140,13 @@ public class Network
 				Log.i("cky","total="+totalbytes);
 				int len = 0;
 				while((len=is.read(bytes))!=-1){
+					if(listener.interupt())
+					{
+						is.close();
+						String result="{\"result\":0,\"msg\":\"user cancel\"}";
+						listener.onFinish(200,result);
+						return result;
+					}
 					curbytes += len;
 					dos.write(bytes, 0, len);
 					listener.onProgress(curbytes,1.0d*curbytes/totalbytes);
@@ -1158,6 +1165,15 @@ public class Network
 				BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
 				String line;
 				while((line=br.readLine())!=null){
+
+					if(listener.interupt())
+					{
+
+						String result="{\"result\":0,\"msg\":\"user cancel\"}";
+						listener.onFinish(200,result);
+						return result;
+					}
+
 					sb.append(line);
 				}
 				listener.onFinish(code,sb.toString()/*,conn.getHeaderFields()*/);
@@ -1173,6 +1189,7 @@ public class Network
 	}
 
 	public interface FileUploadListener {
+		boolean interupt();
 		void onProgress(long pro, double percentage);
 
 		void onFinish(int code, String res/*, HashMap<String, List<String>> headers*/);

+ 0 - 25
RA Image/app/src/main/java/com/usai/util/RAOperation.java

@@ -1,25 +0,0 @@
-package com.usai.util;
-
-
-import android.os.Bundle;
-
-/**
- * Created by ray on 28/06/2017.
- */
-
-public class RAOperation implements Runnable {
-    public Bundle task;
-    @Override
-    public void run() {
-
-
-//        BaseAdapter adapter;
-//        adapter.notifyDataSetChanged();
-//
-//        Bundle b;
-//        b.put
-
-    }
-
-
-}

+ 13 - 2
RA Image/app/src/main/java/com/usai/util/RAOperationQueue.java

@@ -17,7 +17,8 @@ public class RAOperationQueue {
         /**
             每个具体任务执行的回调
          */
-        public void operate(Bundle taskinfo);
+        public Boolean operate(Bundle taskinfo);
+        public void operateFinish(Bundle taskinfo);
     }
 
     OperationCallback execCallback;
@@ -35,6 +36,8 @@ public class RAOperationQueue {
 //    public RAOperation runThread;
     public void addOperation(final Bundle taskinfo)
     {
+
+
         queue.offer(taskinfo);
         while (((ThreadPoolExecutor)es).getActiveCount()< MaxThread) {
 
@@ -47,6 +50,7 @@ public class RAOperationQueue {
                         Bundle task=queue.poll();
 
                         System.out.println("running  tid="+Thread.currentThread().getId());
+                        task.putLong("tid",Thread.currentThread().getId());
 //                        int min=1000;
 //                        int max=5000;
 //                        int sleep=new Random().nextInt(max)%(max-min+1) + min;
@@ -55,7 +59,14 @@ public class RAOperationQueue {
 //                        }catch(InterruptedException ie){
 //                            ie.printStackTrace();
 //                        }
-                        execCallback.operate(task);
+                        boolean retry=execCallback.operate(task);
+                        if(retry)
+                            queue.offer(task);
+                        else
+                        {
+                            task.remove("tid");
+                            execCallback.operateFinish(task);
+                        }
                         System.out.println("     finish  tid="+Thread.currentThread().getId());
                     }
 

+ 145 - 21
RA Image/app/src/main/java/com/usai/util/RAUploadManager.java

@@ -2,12 +2,16 @@ package com.usai.util;
 
 import android.content.SharedPreferences;
 import android.os.Bundle;
-import android.os.Environment;
 import android.util.Log;
 
 import com.usai.redant.raimage.RedAntApplication;
 
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.ObjectOutputStream;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -27,7 +31,10 @@ public class RAUploadManager {
     public Boolean removeError=false;
     public QueueStatus queue_status;
 
-    public RAUploadOperation.TaskStatus newtaskStatus= RAUploadOperation.TaskStatus.TaskStatusWait;
+
+    public static final  int RESULT_BARCODE_ERROR=-50;
+
+    public TaskStatus newtaskStatus= TaskStatus.TaskStatusWait;
     public ArrayList<Bundle> arr_queue;
 //    private List<Bundle> operation_queue;
 //    private ExecutorService es = Executors.newFixedThreadPool(3);//
@@ -42,14 +49,26 @@ public class RAUploadManager {
         QueueStatusFinish
     }
 
+    public enum TaskStatus {
+        TaskStatusStop,
+        TaskStatusStart,
+        TaskStatusError,
+        TaskStatusWait,
+        TaskStatusFinish,
+        TaskStatusCancel,
+    }
+
     public UIUpdateListener uiUpdateListener;
 
     public interface UIUpdateListener {
         void onProgress(long index, double percentage);
+        void updateCell(long index, Bundle taskinfo);
+        void updateList();
 
 //        void onFinish(int code, String res/*, HashMap<String, List<String>> headers*/);
     }
 
+
 //    class Poll implements Runnable {
 //        public void run() {
 //            // while (queue.size()>0) {
@@ -75,7 +94,7 @@ public class RAUploadManager {
             removeFinish = UMSetting.getBoolean("auto_rm_finish",true);
             removeError = UMSetting.getBoolean("auto_rm_error",false);
             maxRetry = UMSetting.getInt("retry_count",2);
-            newtaskStatus = RAUploadOperation.TaskStatus.values()[UMSetting.getInt("newtask_status",RAUploadOperation.TaskStatus.TaskStatusWait.ordinal())];
+            newtaskStatus = TaskStatus.values()[UMSetting.getInt("newtask_status",TaskStatus.TaskStatusWait.ordinal())];
 
             maxThread = UMSetting.getInt("max_thread",3);
 
@@ -85,22 +104,36 @@ public class RAUploadManager {
         operation_queue = new RAOperationQueue();
         operation_queue.setCallback(new RAOperationQueue.OperationCallback() {
             @Override
-            public void operate(final Bundle taskinfo) {
+            public Boolean operate(final Bundle taskinfo) {
 
-                String path=taskinfo.getString("file");
+                boolean ret=false;
+                String path=taskinfo.getString("path");
                 String url=taskinfo.getString("url")+""+URL_UPLOAD;
 
-                Network.UploadImage(path, taskinfo.getBundle("params"), url, new Network.FileUploadListener() {
+                JSONObject result=Network.UploadImage(path, taskinfo.getBundle("params"), url, new Network.FileUploadListener() {
+                    @Override
+                    public boolean interupt() {
+//                        if(taskinfo.getBoolean("iscancel",false))
+//                            return false;
+                        return taskinfo.getBoolean("iscancel",false);
+                    }
+
                     @Override
                     public void onProgress(long pro, double percentage) {
 
-                        Log.d("", "onProgress: " + percentage);
 
-                        if (uiUpdateListener!=null) {
-                            int index = arr_queue.indexOf(taskinfo);
-                            uiUpdateListener.onProgress(index,percentage);
+                        synchronized(this){
+                            Log.d("", "onProgress: " + percentage);
+                            taskinfo.putDouble("progress",percentage);
+                            if (uiUpdateListener!=null) {
+                                int index = arr_queue.indexOf(taskinfo);
+//                            uiUpdateListener.onProgress(index,percentage);
+
+                                uiUpdateListener.updateCell(index,taskinfo);
+                            }
                         }
 
+
                     }
 
                     @Override
@@ -109,7 +142,55 @@ public class RAUploadManager {
 
                     }
                 });
+                int r = 0;
+                try {
+                    r = result.getInt("result");
+                    String rmsg=result.getString("msg");
+
+                    if(r==2|| r==RESULT_BARCODE_ERROR)
+                    {
+                        taskinfo.putInt("status",TaskStatus.TaskStatusFinish.ordinal());
+                        if(r==2)
+                            taskinfo.putString("msg","upload successful");
+                        else
+                            taskinfo.putString("msg","warring: "+rmsg );
+                    }
+                    else
+                    {
+                        if(taskinfo.getInt("retry",0)>=maxRetry)
+                        {
+                            taskinfo.putInt("status",TaskStatus.TaskStatusError.ordinal());
+                            taskinfo.putDouble("progress",0.0);
+                            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;
+
+                        }
+                    }
+
+
+                    synchronized (this)
+                    {
+                        if (uiUpdateListener!=null) {
+                            int index = arr_queue.indexOf(taskinfo);
+
+                            uiUpdateListener.updateCell(index,taskinfo);
+                        }
+                    }
+
+
 
+                } catch (JSONException e) {
+                    e.printStackTrace();
+                }
+
+                return ret;
 //                int a=0;
 //                System.out.println(a+"running  tid="+Thread.currentThread().getId());
 //                int min=1000;
@@ -123,6 +204,27 @@ public class RAUploadManager {
 //                System.out.println(a+"   "+sleep+"     finish  tid="+Thread.currentThread().getId());
 
             }
+
+            @Override
+            public void operateFinish(Bundle taskinfo) {
+
+                TaskStatus status= TaskStatus.values()[taskinfo.getInt("status",0)];
+                boolean removefromlist=false;
+                if (status==TaskStatus.TaskStatusFinish&&removeFinish)
+                    removefromlist=true;
+                else if (status==TaskStatus.TaskStatusError&&removeError)
+                    removefromlist=true;
+                if(removefromlist)
+                {
+                    synchronized (this)
+                    {
+                        arr_queue.remove(taskinfo);
+                        uiUpdateListener.updateList();
+
+                    }
+                }
+
+            }
         });
 
         //            operation_queue = new List<Bundle>() {};
@@ -141,7 +243,7 @@ public class RAUploadManager {
     public void addTask(Bundle task)
     {
         arr_queue.add(task);
-        if(newtaskStatus== RAUploadOperation.TaskStatus.TaskStatusWait)
+        if(newtaskStatus== TaskStatus.TaskStatusWait)
         {
             startTask(task);
         }
@@ -149,7 +251,7 @@ public class RAUploadManager {
     public void addTasks(ArrayList<Bundle> tasks)
     {
         arr_queue.addAll(tasks);
-        if(newtaskStatus== RAUploadOperation.TaskStatus.TaskStatusWait)
+        if(newtaskStatus== TaskStatus.TaskStatusWait)
         {
             for (Bundle task:tasks)
             {
@@ -197,9 +299,18 @@ public class RAUploadManager {
     };
     public void stopTask(Bundle task)
     {
-        if(task.getInt("status")!= RAUploadOperation.TaskStatus.TaskStatusStart.ordinal()&&task.getInt("status")!= RAUploadOperation.TaskStatus.TaskStatusWait.ordinal())
+        if(task.getInt("status")!= TaskStatus.TaskStatusStart.ordinal()&&task.getInt("status")!= TaskStatus.TaskStatusWait.ordinal())
             return;
 
+        task.putBoolean("iscancel",true);
+//        long tid=task.getLong("tid",-1);
+//        if(tid>0)
+//        {
+//
+//
+//        }
+//        task.tet("tid",Thread.currentThread().getId());
+
 //        RAUploadOperation
 
 
@@ -207,10 +318,23 @@ public class RAUploadManager {
     public void saveTasks()
     {
 
-//        SharedPreferences pref = RedAntApplication.getInstance()
-//                .getSharedPreferences("RA Image", 0);
-//        SharedPreferences.Editor editor = pref.edit();
-//
+        SharedPreferences pref = RedAntApplication.getInstance()
+                .getSharedPreferences("RA Image", 0);
+        SharedPreferences.Editor editor = pref.edit();
+
+        try {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            ObjectOutputStream oos = new ObjectOutputStream(baos);
+            oos.writeObject(arr_queue);
+
+            String personBase64 = android.util.Base64.encodeToString(baos.toByteArray(), android.util.Base64.DEFAULT);//new String(Base64.encodeBase64(baos.toByteArray()));
+        }
+        catch (Exception e)
+        {
+
+        }
+
+
 //        if (m_swSave.isChecked()&&!TextUtils.isEmpty(encryptPass)&&!TextUtils.isEmpty(encryptUser))
 //        {
 //            editor.putString("user", encryptUser);
@@ -234,11 +358,11 @@ public class RAUploadManager {
 
     private String filePath(Bundle task)
     {
-        String path = Environment.getExternalStorageDirectory().getPath();
-        path+="/"+task.getString("path");
-        path+="/"+task.getString("file");
+//        String path = Environment.getExternalStorageDirectory().getPath();
+//        path+="/"+task.getString("path");
+//        path+="/"+task.getString("file");
 
-        return path;
+        return task.getString("path","");
     }
 
 

+ 0 - 41
RA Image/app/src/main/java/com/usai/util/RAUploadOperation.java

@@ -1,41 +0,0 @@
-package com.usai.util;
-
-import org.json.JSONObject;
-
-/**
- * Created by ray on 13/06/2017.
- */
-
-public class RAUploadOperation {
-
-    private JSONObject _taskinfo;
-    private int _maxRetry;
-
-
-    public interface updateUIListener {
-
-    }
-
-
-    public updateUIListener m_updateUIListener;
-
-    public enum TaskStatus {
-        TaskStatusStop,
-        TaskStatusStart,
-        TaskStatusError,
-        TaskStatusWait,
-        TaskStatusFinish
-    }
-
-    public RAUploadOperation(JSONObject taskinfo, int maxRetry) {
-        _taskinfo = taskinfo;
-        _maxRetry = maxRetry;
-
-    }
-
-
-    public void setOnClickListener( updateUIListener l) {
-
-        m_updateUIListener = l;
-    }
-}

+ 12 - 5
RA Image/app/src/main/java/com/usai/util/RAUtil.java

@@ -2,12 +2,7 @@ package com.usai.util;
 
 import android.app.AlertDialog;
 import android.content.Context;
-import android.content.DialogInterface;
-import android.content.Intent;
 import android.content.pm.PackageManager;
-import android.net.Uri;
-import android.provider.Settings;
-import android.text.TextUtils;
 
 /**
  * Created by ray on 27/06/2017.
@@ -35,4 +30,16 @@ public class RAUtil {
         }
         return true;
     }
+
+    public static String lastPathComponent(String path){
+
+        int start=path.lastIndexOf("/");
+        int end=path.lastIndexOf(".");
+        if(start!=-1 && end!=-1){
+            return path.substring(start+1,end);
+        }else{
+            return null;
+        }
+
+    }
 }

+ 22 - 24
RA Image/app/src/main/res/layout/upload_list_cell.xml

@@ -1,63 +1,61 @@
 <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent" android:layout_height="match_parent">
+    android:id="@+id/upload_percent_tv"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
 
     <TextView
         android:id="@+id/upload_name_tv"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_marginStart="10dp"
+        android:layout_marginEnd="10dp"
         android:layout_marginLeft="10dp"
-        android:layout_marginTop="5dp"
         android:layout_marginRight="10dp"
-        android:layout_marginEnd="10dp"
-        android:hint="QS885555464784613654"
-        />
+        android:layout_marginStart="10dp"
+        android:layout_marginTop="5dp"
+        android:hint="QS885555464784613654" />
 
     <ProgressBar
         android:id="@+id/upload_progressBar"
+        style="@style/Widget.AppCompat.ProgressBar.Horizontal"
         android:layout_width="match_parent"
         android:layout_height="5dp"
         android:layout_alignLeft="@id/upload_name_tv"
-        android:layout_marginTop="5dp"
         android:layout_alignRight="@id/upload_name_tv"
-        style="@style/Widget.AppCompat.ProgressBar.Horizontal"
         android:layout_below="@id/upload_name_tv"
+        android:layout_marginTop="5dp"
         android:max="100"
-        android:progress="0"
-        />
+        android:progress="0" />
 
     <TextView
         android:id="@+id/upload_state_tv"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_below="@id/upload_progressBar"
         android:layout_alignLeft="@id/upload_progressBar"
-        android:layout_marginTop="5dp"
-        android:layout_marginRight="10dp"
+        android:layout_below="@id/upload_progressBar"
         android:layout_marginEnd="10dp"
-        android:text="Waiting"
-        />
+        android:layout_marginRight="10dp"
+        android:layout_marginTop="5dp"
+        android:text="Waiting" />
+
     <TextView
         android:id="@+id/upload_progress_tv"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_below="@id/upload_progressBar"
-        android:layout_alignTop="@id/upload_state_tv"
         android:layout_alignRight="@id/upload_progressBar"
-        android:text=""
-        />
+        android:layout_alignTop="@id/upload_state_tv"
+        android:layout_below="@id/upload_progressBar"
+        android:text="" />
 
     <TextView
         android:id="@+id/upload_err_tv"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_below="@id/upload_state_tv"
-        android:layout_marginTop="5dp"
         android:layout_alignLeft="@id/upload_state_tv"
-        android:layout_marginRight="10dp"
+        android:layout_below="@id/upload_state_tv"
         android:layout_marginEnd="10dp"
-        android:text="Error:"
-        />
+        android:layout_marginRight="10dp"
+        android:layout_marginTop="5dp"
+        android:text="Error:" />
 
 </RelativeLayout>