Преглед на файлове

RA Image Android

上传成功后删除图片,其他情况下保存图片。
优化验证逻辑,如果因为网络原因无法验证,则允许创建上传任务。
优化上传逻辑,在网络检查失败后,允许添加文件,以后手动上传。
Ray Zhang преди 8 години
родител
ревизия
87360af9ab

+ 7 - 7
RA Image/app/app.iml

@@ -62,13 +62,6 @@
       <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
       <sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
       <sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
-      <sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
-      <sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
-      <sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
-      <sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
-      <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
-      <sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
-      <sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
       <sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
       <sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
       <sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
@@ -76,6 +69,13 @@
       <sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
       <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
       <sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />

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

@@ -486,16 +486,80 @@ public class MainActivity extends AppCompatActivity
 //                        toast.show();
 //                        return;
 
-                        new AlertDialog.Builder(MainActivity.this)
-                                .setTitle("Warning")
-                                .setMessage("can not verify input information.")
-                                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
-                                    @Override
-                                    public void onClick(DialogInterface dialog, int which) {
+//                        new AlertDialog.Builder(MainActivity.this)
+//                                .setTitle("Warning")
+//                                .setMessage("can not verify input information.")
+//                                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+//                                    @Override
+//                                    public void onClick(DialogInterface dialog, int which) {
+//
+//                                    }
+//                                })
+//                                .show();
+
+
+                        			new AlertDialog.Builder(MainActivity.this)
+					.setTitle("Warning")
+					.setMessage("Can not verify input information, add upload task anyway?")
+					.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
+						@Override
+						public void onClick(DialogInterface dialog, int which)             {
+
+
+                            Intent intent = new Intent("REDANT.RAImage.ADD_TASK");
 
+                            ArrayList<Bundle> taskArr = new ArrayList<Bundle>();
+
+                            for (String path : photoList) {
+                                Bundle task = new Bundle();
+
+                                task.putString("path",path);
+                                task.putString("file",RAUtil.lastPathComponent(path));
+                                task.putString("url",RedAntApplication.active_address);
+
+                                String md5 = MD5.md5sum(path);
+                                String encryptUser = AES.encrypt("usai",RedAntApplication.user);
+                                String encryptPwd = AES.encrypt("usai",RedAntApplication.password);
+
+                                Bundle params = new Bundle();
+                                params.putString("user",encryptUser);
+                                params.putString("password",encryptPwd);
+                                params.putString("mode",mode);
+                                params.putString("barcode",pidval.getText().toString());
+                                params.putString("_operate","upload");
+                                params.putString("platform","android");
+                                params.putString("md5",md5);
+
+
+                                if (mode.equals("Model")) {
+
+                                    if (!TextUtils.isEmpty(manufacture)) {
+                                        params.putString("manufacturer",manufacture);
                                     }
-                                })
-                                .show();
+                                    if (!TextUtils.isEmpty(noteTextView.getText().toString())) {
+                                        params.putString("note",noteTextView.getText().toString());
+                                    }
+                                }
+
+                                task.putBundle("params",params);
+
+                                taskArr.add(task);
+                            }
+
+                            intent.putParcelableArrayListExtra("tasks",taskArr);
+
+                            sendBroadcast(intent);
+                            clearfornew();
+                        }
+
+                    })
+					.setNegativeButton("No", new DialogInterface.OnClickListener() {
+						@Override
+						public void onClick(DialogInterface dialog, int which) {
+
+						}
+					})
+					.show();
                         return;
 
                     }
@@ -819,7 +883,7 @@ public class MainActivity extends AppCompatActivity
 
 
 
-				boolean canstart = true;
+		//		boolean canstart = true;
 
 				ConnectivityManager connManager = (ConnectivityManager) RedAntApplication.getInstance()
 						.getSystemService(Context.CONNECTIVITY_SERVICE);
@@ -831,7 +895,17 @@ public class MainActivity extends AppCompatActivity
 					dbgUtil.Logd(
 							"Current Network info",
 							"can not get Active NetworkInfo!");
-					canstart = false;
+//					canstart = false;
+                    new AlertDialog.Builder(MainActivity.this)
+                            .setTitle("Warning")
+                            .setMessage("No available network, new task will not start, you must start it manually.")
+                            .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+                                @Override
+                                public void onClick(DialogInterface dialog, int which) {
+
+                                }
+                            })
+                            .show();
 				}
 				else
 				{
@@ -843,52 +917,98 @@ public class MainActivity extends AppCompatActivity
 								"Current Network info",
 								"not Connected!State="
 										+ netState);
-						canstart = false;
-					}
-					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;
+//						canstart = false;
+
+                        new AlertDialog.Builder(MainActivity.this)
+                                .setTitle("Warning")
+                                .setMessage("No network connection, new task will not start, you must start it manually.")
+                                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+                                    @Override
+                                    public void onClick(DialogInterface dialog, int which) {
+
+                                    }
+                                })
+                                .show();
+
 					}
-				}
-				if(!canstart)
-				{
+					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;
 
 
-                    new AlertDialog.Builder(MainActivity.this)
-                            .setTitle("Warning")
-                            .setMessage("App is set to upload via WIFI only. Please change your setting or try upload later.")
-                            .setPositiveButton("OK", new DialogInterface.OnClickListener() {
-                                @Override
-                                public void onClick(DialogInterface dialog, int which) {
+                            new AlertDialog.Builder(MainActivity.this)
+                                    .setTitle("Warning")
+                                    .setMessage("You have setup upload via WIFI only, new task will not start, you must start it manually.")
+                                    .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+                                        @Override
+                                        public void onClick(DialogInterface dialog, int which) {
+
+                                        }
+                                    })
+                                    .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;
+
+                        }
+                    }
 
-                                }
-                            })
-                            .show();
-                    return;
-//					Toast toast = Toast.makeText(getApplicationContext(),
-//							"App is set to upload via WIFI only. Please change your setting or try upload later.",
-//							Toast.LENGTH_LONG);
-//					toast.setGravity(Gravity.CENTER, 0, 0);
-//					toast.show();
-//					return;
 				}
+//				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.")
+////                            .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+////                                @Override
+////                                public void onClick(DialogInterface dialog, int which) {
+////
+////                                }
+////                            })
+////                            .show();
+////                    return;
+//
+//				}
 				try {
 
 //                    String name = "POP";
@@ -1005,7 +1125,6 @@ public class MainActivity extends AppCompatActivity
 
 
 
-            //photoList.clear();
             if (savedPhotoList != null) {
 				photoList = savedPhotoList;
 
@@ -1120,7 +1239,9 @@ public class MainActivity extends AppCompatActivity
 				outputStream.flush();
 				outputStream.close();
 
+                String rotedpath = routedFile.getAbsolutePath();
                 routedFile.delete();
+                RAUtil.updateGallery(rotedpath);
 //				scaleFile.renameTo(new File(path));
 				return scaleFile;
 
@@ -1202,18 +1323,7 @@ public class MainActivity extends AppCompatActivity
     }
 
 
-//	@Override
-//	public boolean onKeyDown(int keyCode, KeyEvent event)
-//	{
-//		if (keyCode == KeyEvent.KEYCODE_BACK)
-//		{
-//			dbgUtil.fileLog("back button click , clear&exit");
-//			clear();
-//
-//		}
-//		return super.onKeyDown(keyCode, event);
-//
-//	}
+
 
 	@Override
 	protected void onResume()
@@ -1261,85 +1371,12 @@ public class MainActivity extends AppCompatActivity
             return;
         }
 
-//		if (savedInstanceState != null)
-//		{
-//			thumbBitmap = getBitmap(savedInstanceState
-//					.getByteArray("thumbBitmap"));
-//			photoList.clear();
-//			// ArrayList list = (ArrayList)
-//			// Arrays.asList(savedInstanceState.getStringArray("arrayLabel"));
-//			photoList = savedInstanceState.getStringArrayList("photoList");
-//
-//			TextView pidval = (TextView) findViewById(R.id.pidval);
-//			pidval.setText(savedInstanceState.getString("PIID"));
-//			// photoList = A
-//			// savedInstanceState.getStringArrayList("photoList");
-//			photoFile = (File) savedInstanceState.getSerializable("photoFile");
-//
-//			if (thumbBitmap != null)
-//			{
-//				thumbsImageView.setImageBitmap(thumbBitmap);
-//				// Log.d(TAG, "load thumbpath==" + thumbpath);
-//			}
-//			// photoFile.delete();
-//			TextView countTextView = (TextView) findViewById(R.id.tvPhotoCount);
-//			countTextView.setText(photoList.size() + " Photos");
-//
-//		}
-//
-//		ImageButton ibtnscan = (ImageButton) findViewById(R.id.ibtnScan);
-//		ibtnscan.setOnClickListener(new View.OnClickListener()
-//		{
-//
-//			@Override
-//			public void onClick(View v)
-//			{
-//				Log.d(TAG, "==============>Click Scan button");
-//				Intent intent = new Intent();
-//
-//				intent.setClass(MainActivity.this, CaptureActivity.class);
-//				startActivityForResult(intent, REQUEST_SCAN_BARCODE);
-//			}
-//		});
-//
-//		ImageButton captureButton = (ImageButton) findViewById(R.id.ibtnCapture);
-//		captureButton.setOnClickListener(new View.OnClickListener()
-//		{
-//
-//			@Override
-//			public void onClick(View v)
-//			{
-//
-//				StartCamera();
-//			}
-//		});
-//		ImageButton uploadButton = (ImageButton) findViewById(R.id.ibtnOk);
-//		uploadButton.setOnClickListener(new View.OnClickListener()
-//		{
-//
-//			@Override
-//			public void onClick(View v)
-//			{
-//
-//				sendBroadcast(new Intent("REDANT.POP.REQUEST_LOCATION"));
-//				return;
-//
-//			}
-//		});
-//
-//		m_tvalert = (TextView) findViewById(R.id.tvalert);
-//		m_tvalert.setSelected(true);
-//
-//		// Intent intent = ;
-//		sendBroadcast(new Intent("REDANT.POP.MODIFY_QUEUE"));
-//		updateUploadButton();
 	}
 
 	@Override
 	protected void onDestroy()
 	{
-	//	sendBroadcast(new Intent("REDANT.POP.GPS_OFF"));
-//        clear();
+
 		Log.d(TAG, "=======================>MainActivity Destroyed!");
 		unregisterReceiver(MainActivityReceiver);
 		Log.d(TAG, "=======================>msgFilter unregisted!");
@@ -1396,6 +1433,9 @@ public class MainActivity extends AppCompatActivity
 				storageDir /* directory */
 		);
 
+        Log.d(TAG, "File:" + image.getAbsolutePath());
+//        RAUtil.updateGallery(LastFileName);
+
 		// Save a file: path for use with ACTION_VIEW intents
 		// mCurrentPhotoPath = "file:" + image.getAbsolutePath();
 		return image;
@@ -1466,8 +1506,13 @@ public class MainActivity extends AppCompatActivity
 				if (scaleFile != null) {
 					photoFile = scaleFile;
 				}
+
+
 				photoList.add(photoFile.toString());
 
+
+//                Log.d(TAG, "File:" + image.getAbsolutePath());
+        RAUtil.updateGallery(photoFile.toString());
 				StartCamera();
 				// iPhotoCount++;
 //				super.onActivityResult(requestCode, resultCode, data);
@@ -1492,7 +1537,9 @@ public class MainActivity extends AppCompatActivity
 						thumbsImageView.setImageBitmap(thumbBitmap);
 				}
 
+				String photopath=photoFile.getAbsolutePath();
 				photoFile.delete();
+                RAUtil.updateGallery(photopath);
 				TextView countTextView = (TextView) findViewById(R.id.tvPhotoCount);
 				if (newVersion) {
 					countTextView = this.countTextView;
@@ -1665,65 +1712,7 @@ public class MainActivity extends AppCompatActivity
 			}
 			return super.onOptionsItemSelected(item);
 		}
-//		// TODO Auto-generated method stub
-//		switch (item.getItemId())
-//		{
-//			case R.id.action_clear:
-//				dbgUtil.fileLog("menu item clear click , clear...");
-//				clear();
-//				break;
-//			case R.id.action_type_pid:
-//			{
-//				final View edit = new EditText(this);
-//				new AlertDialog.Builder(this)
-//						.setIconAttribute(android.R.attr.alertDialogIcon)
-//						.setTitle(R.string.title_input_pid)
-//						.setView(edit)
-//						.setPositiveButton(android.R.string.ok,
-//								new DialogInterface.OnClickListener()
-//								{
-//									public void onClick(DialogInterface dialog,
-//											int whichButton)
-//									{
-//										String pid = ((EditText) edit)
-//												.getText().toString();
-//										TextView pidval = (TextView) findViewById(R.id.pidval);
-//										pidval.setText(pid);
-//										updateUploadButton();
-//
-//										/* User clicked OK so do some stuff */
-//									}
-//								})
-//						.setNegativeButton(android.R.string.cancel,
-//								new DialogInterface.OnClickListener()
-//								{
-//									public void onClick(DialogInterface dialog,
-//											int whichButton)
-//									{
-//										updateUploadButton();
-//										/* User clicked cancel so do some stuff */
-//									}
-//								}).create().show();
-//			}
-//				break;
-//			case R.id.action_server_settings:
-//			{
-//				Intent intent = new Intent();
-//				intent.setClass(MainActivity.this, ServerSettingActivity.class);
-//				startActivity(intent);
-//
-//			}
-//				break;
-//			case R.id.action_view_queue:
-//			{
-//				Intent intent = new Intent();
-//				intent.setClass(MainActivity.this, UploadQueueActivity.class);
-//				startActivity(intent);
-//				break;
-//			}
-//			default:
-//				break;
-//		}
+
 		return super.onOptionsItemSelected(item);
 	}
 
@@ -1783,11 +1772,7 @@ public class MainActivity extends AppCompatActivity
         super.onBackPressed();
     }
 
-//    @Override
-//    protected void finalize() throws Throwable {
-//        Log.e(TAG, "finalize: photolist clear" );
-//        clear();
-//    }
+
 
     private void clear()
 	{
@@ -1797,86 +1782,18 @@ public class MainActivity extends AppCompatActivity
 
 
 
-//
-//
-//			String timeStamp = new SimpleDateFormat("yyyy_MM_dd")
-//			.format(new Date());
-//
-//			File storageDir = new File(Environment.getExternalStorageDirectory()
-//					.getPath() + "/redant/pop/clear/"+timeStamp);
-//
-//			if (!storageDir.exists())
-//				storageDir.mkdirs();
-
-
-
-            new File(photoList.get(i)).delete();
 
+            //应要求修改,退出上传界面后,不删除未传的图片
 
-//			File dir1 = new File(Environment.getExternalStorageDirectory()
-//					.getPath() + "/redant");
-//			File dir2 = new File(Environment.getExternalStorageDirectory()
-//					.getPath() + "/redant/pop");
-//			File dir3 = new File(Environment.getExternalStorageDirectory()
-//					.getPath() + "/redant/pop/clear");
-//
-//
-//			if (!dir1.exists())
-//			{
-//				boolean b = dir1.mkdir();
-//			}
-//			if (!dir2.exists())
-//			{
-//				boolean b = dir2.mkdir();
-//			}
-//			if (!dir3.exists())
-//			{
-//				boolean b = dir3.mkdir();
-//			}
-//
-//			if (!storageDir.exists())
-//			{
-//				boolean b = storageDir.mkdir();
-//			}
-//
-//			File srcFile = new File(photoList.get(i));
-//		//	file.delete();
-//			dbgUtil.fileLog("move file "+srcFile.getName()+" to "+Environment.getExternalStorageDirectory()
-//					.getPath() + "/redant/pop/clear/"+timeStamp + File.separator);
-//			srcFile.renameTo(new File(Environment.getExternalStorageDirectory()
-//					.getPath() + "/redant/pop/clear/"+timeStamp + File.separator + srcFile.getName()));
-//
+//            new File(photoList.get(i)).delete();
+//            RAUtil.updateGallery(photoList.get(i));
 
 
-//			// Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
-//			// Log.d(TAG, "DIR:" + storageDir);
-//			LastFileName = storageDir + imageFileName + ".jpg";
-//			Log.d(TAG, "File:" + LastFileName);
-//			File image = File.createTempFile(imageFileName, /* prefix */
-//					".jpg", /* suffix */
-//					storageDir /* directory */
-//			);
-
 
 		}
         photoList.clear();
 
 
-//        if (newVersion) {
-//			return;
-//			// 以下会造成Crash
-//		}
-//
-//
-//		TextView pidval = (TextView) findViewById(R.id.pidval);
-//		pidval.setText("");
-//		updateUploadButton();
-//		ImageView thumbsImageView = (ImageView) findViewById(R.id.ivThumbs);
-//		thumbsImageView.setImageResource(R.drawable.no_pic);
-//		thumbBitmap = null;
-//		TextView countTextView = (TextView) findViewById(R.id.tvPhotoCount);
-//		countTextView.setText("no photo");
-
 	}
 
 	private void clearfornew()

+ 2 - 0
RA Image/app/src/main/java/com/usai/redant/raimage/PhotoList/PhotoGridActivity.java

@@ -21,6 +21,7 @@ import android.widget.ImageButton;
 import android.widget.ImageView;
 
 import com.usai.redant.raimage.R;
+import com.usai.util.RAUtil;
 
 import java.io.BufferedOutputStream;
 import java.io.File;
@@ -80,6 +81,7 @@ public class PhotoGridActivity extends AppCompatActivity implements RAGridView.G
                     if (delete == 1) {
                         // 删除文件
                         new File(item.get("path")).delete();
+                        RAUtil.updateGallery(item.get("path"));
                         iterator.remove();
                         int index = photoDic.indexOf(item);
                     }

+ 3 - 6
RA Image/app/src/main/java/com/usai/redant/raimage/PhotoList/PhotoListActivity.java

@@ -1,20 +1,16 @@
 package com.usai.redant.raimage.PhotoList;
 
 import android.content.Intent;
-import android.content.res.Configuration;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
-import android.media.Image;
-import android.net.Uri;
+import android.os.Bundle;
 import android.support.v7.app.ActionBar;
 import android.support.v7.app.AppCompatActivity;
-import android.os.Bundle;
 import android.support.v7.widget.DefaultItemAnimator;
 import android.support.v7.widget.GridLayoutManager;
 import android.support.v7.widget.RecyclerView;
 import android.view.LayoutInflater;
 import android.view.MenuItem;
-import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.Button;
@@ -23,10 +19,10 @@ import android.widget.ImageView;
 import android.widget.Toast;
 
 import com.usai.redant.raimage.R;
+import com.usai.util.RAUtil;
 
 import java.io.File;
 import java.io.Serializable;
-import java.net.URI;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -81,6 +77,7 @@ public class PhotoListActivity extends AppCompatActivity {
                     if (delete == 1) {
                         // 删除文件
                         new File(item.get("path")).delete();
+                        RAUtil.updateGallery(item.get("path"));
                         iterator.remove();
                         int index = photoDic.indexOf(item);
                     }

+ 3 - 0
RA Image/app/src/main/java/com/usai/redant/raimage/PhotoPreviewActivity.java

@@ -23,6 +23,8 @@ import android.widget.LinearLayout;
 import android.widget.ViewSwitcher;
 import android.widget.Gallery.LayoutParams;
 
+import com.usai.util.RAUtil;
+
 public class PhotoPreviewActivity extends Activity implements
 		ViewSwitcher.ViewFactory
 {
@@ -143,6 +145,7 @@ public class PhotoPreviewActivity extends Activity implements
 				mSwitcher.setImageURI(null);
 				Integer idx = (Integer) current_view.getTag();
 				new File(pic_file.get(idx)).delete();
+				RAUtil.updateGallery(pic_file.get(idx));
 				current_view = null;
 				// // pic_file.remove(idx);
 			}

+ 33 - 13
RA Image/app/src/main/java/com/usai/redant/raimage/TaskActivity.java

@@ -326,7 +326,7 @@ public class TaskActivity extends AppCompatActivity {
 
 
 
-                            boolean canstart = true;
+//                            boolean canstart = true;
 
                             ConnectivityManager connManager = (ConnectivityManager) RedAntApplication.getInstance()
                                     .getSystemService(Context.CONNECTIVITY_SERVICE);
@@ -338,7 +338,13 @@ public class TaskActivity extends AppCompatActivity {
                                 dbgUtil.Logd(
                                         "Current Network info",
                                         "can not get Active NetworkInfo!");
-                                canstart = false;
+//                                canstart = false;
+                                Toast toast = Toast.makeText(getApplicationContext(),
+                                        "No available network. Please try upload manually later.",
+                                        Toast.LENGTH_LONG);
+                                toast.setGravity(Gravity.CENTER, 0, 0);
+                                toast.show();
+                                return;
                             }
                             else
                             {
@@ -350,7 +356,14 @@ public class TaskActivity extends AppCompatActivity {
                                             "Current Network info",
                                             "not Connected!State="
                                                     + netState);
-                                    canstart = false;
+//                                    canstart = false;
+
+                                    Toast toast = Toast.makeText(getApplicationContext(),
+                                            "App network connection. Please try upload manually later.",
+                                            Toast.LENGTH_LONG);
+                                    toast.setGravity(Gravity.CENTER, 0, 0);
+                                    toast.show();
+                                    return;
                                 }
                                 int iconntype = -1;
                                 iconntype = networkInfo
@@ -371,18 +384,25 @@ public class TaskActivity extends AppCompatActivity {
                                         && iconntype !=
                                         9/* earthnet */)
                                 {
-                                    canstart = false;
+//                                    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;
                                 }
                             }
-                            if(!canstart)
-                            {
-                                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)
+//                            {
+//                                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;
+//                            }
 
                             v.setVisibility(View.GONE);
                             uploadManager.startTask(task);

+ 24 - 2
RA Image/app/src/main/java/com/usai/util/RAUploadManager.java

@@ -337,6 +337,21 @@ public class RAUploadManager {
             public void operateFinish(Bundle taskinfo) {
 
                 TaskStatus status= TaskStatus.values()[taskinfo.getInt("status",0)];
+
+                //新增逻辑,对于成功上传的图片,从书记删除
+                //taskinfo.getString("msg").indexOf("warning:")<0 没有匹配错误
+                String path = filePath(taskinfo);
+                File file = new File(path);
+                //只有finish的task 可以删除图片
+
+                if(file.exists()&&taskinfo.getInt("status")== TaskStatus.TaskStatusFinish.ordinal()&&taskinfo.getString("msg").indexOf("warning:")<0)
+                {
+                    String filepath=file.getAbsolutePath();
+                    file.delete();
+                    RAUtil.updateGallery(filepath);
+                }
+                ///////////////////////////////////////////////
+
                 boolean removefromlist=false;
 //                if (status==TaskStatus.TaskStatusFinish&&removeFinish)
 //                    removefromlist=true;
@@ -591,11 +606,16 @@ public class RAUploadManager {
             long timeStart = System.currentTimeMillis();
             arr_queue.remove(task);
             saveTasks();
+
+
             String path = filePath(task);
             File file = new File(path);
-            if(file.exists())
+            //只有finish的task 可以删除图片
+            if(file.exists()&&task.getInt("status")== TaskStatus.TaskStatusFinish.ordinal())
             {
+                String filepath=file.getAbsolutePath();
                 file.delete();
+                RAUtil.updateGallery(filepath);
             }
 
             if(uiUpdateListener!=null)
@@ -620,9 +640,11 @@ public class RAUploadManager {
 
                 String path = filePath(task);
                 File file = new File(path);
-                if(file.exists())
+                if(file.exists()&&task.getInt("status")== TaskStatus.TaskStatusFinish.ordinal())
                 {
+                    String filepath = file.getAbsolutePath();
                     file.delete();
+                    RAUtil.updateGallery(filepath);
                 }
             }
             if(uiUpdateListener!=null)

+ 18 - 0
RA Image/app/src/main/java/com/usai/util/RAUtil.java

@@ -6,6 +6,8 @@ import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.graphics.Matrix;
 import android.media.ExifInterface;
+import android.media.MediaScannerConnection;
+import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
 import android.support.v4.app.ActivityCompat;
@@ -89,6 +91,20 @@ public class RAUtil {
 
     }
 
+    public static void updateGallery(String filename)//filename是我们的文件全名,包括后缀哦
+    {
+
+        Context context = RedAntApplication.getInstance().getApplicationContext();
+        MediaScannerConnection.scanFile(context,
+                new String[] { filename }, null,
+                new MediaScannerConnection.OnScanCompletedListener() {
+                    public void onScanCompleted(String path, Uri uri) {
+                        Log.i("ExternalStorage", "Scanned " + path + ":");
+                        Log.i("ExternalStorage", "-> uri=" + uri);
+                    }
+                });
+    }
+
     public static Boolean checkPermissions_23(Activity activity, String[] permissions)
     {
         Log.d("_RAIMAGE", "checkPermissions23:==================================== ");
@@ -296,7 +312,9 @@ public class RAUtil {
             outputStream.flush();
             outputStream.close();
 
+            String filepath = sourceFile.getAbsolutePath();
             sourceFile.delete();
+            RAUtil.updateGallery(filepath);
 //				scaleFile.renameTo(new File(path));
             return routedFile;
 

+ 5 - 3
RA Image/app/src/main/res/layout/activity_task.xml

@@ -8,8 +8,8 @@
 
     <ListView
         android:id="@+id/task_list"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent"
+        android:layout_width="0dp"
+        android:layout_height="0dp"
         android:layout_marginBottom="8dp"
         android:layout_marginLeft="8dp"
         android:layout_marginRight="8dp"
@@ -17,5 +17,7 @@
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintLeft_toLeftOf="parent"
         app:layout_constraintRight_toRightOf="parent"
-        app:layout_constraintTop_toTopOf="parent" />
+        app:layout_constraintTop_toTopOf="parent"
+        android:layout_marginStart="8dp"
+        android:layout_marginEnd="8dp" />
 </android.support.constraint.ConstraintLayout>