|
@@ -0,0 +1,1135 @@
|
|
|
|
|
+package com.usai.redant.apexdrivers.update;
|
|
|
|
|
+
|
|
|
|
|
+import android.Manifest;
|
|
|
|
|
+import android.app.Activity;
|
|
|
|
|
+import android.app.AlertDialog;
|
|
|
|
|
+import android.app.ProgressDialog;
|
|
|
|
|
+import android.content.ContentValues;
|
|
|
|
|
+import android.content.Context;
|
|
|
|
|
+import android.content.DialogInterface;
|
|
|
|
|
+import android.content.Intent;
|
|
|
|
|
+import android.database.Cursor;
|
|
|
|
|
+import android.graphics.Bitmap;
|
|
|
|
|
+import android.graphics.BitmapFactory;
|
|
|
|
|
+import android.location.Location;
|
|
|
|
|
+import android.net.Uri;
|
|
|
|
|
+import android.os.Bundle;
|
|
|
|
|
+import android.os.Environment;
|
|
|
|
|
+import android.os.Handler;
|
|
|
|
|
+import android.os.Message;
|
|
|
|
|
+import android.provider.MediaStore;
|
|
|
|
|
+import android.support.v4.content.PermissionChecker;
|
|
|
|
|
+import android.support.v4.widget.SwipeRefreshLayout;
|
|
|
|
|
+import android.text.TextUtils;
|
|
|
|
|
+import android.util.Log;
|
|
|
|
|
+import android.view.Menu;
|
|
|
|
|
+import android.view.MenuItem;
|
|
|
|
|
+import android.view.View;
|
|
|
|
|
+import android.widget.ExpandableListView;
|
|
|
|
|
+import android.widget.TextView;
|
|
|
|
|
+import android.widget.Toast;
|
|
|
|
|
+
|
|
|
|
|
+import com.usai.redant.apexdrivers.ApexDriverApplication;
|
|
|
|
|
+import com.usai.redant.apexdrivers.MainActivity;
|
|
|
|
|
+import com.usai.redant.apexdrivers.R;
|
|
|
|
|
+import com.usai.redant.apexdrivers.base.BasicActivity;
|
|
|
|
|
+import com.usai.redant.apexdrivers.codescanner.CaptureActivity;
|
|
|
|
|
+import com.usai.redant.apexdrivers.home.HomeFragment;
|
|
|
|
|
+import com.usai.redant.apexdrivers.network.Network;
|
|
|
|
|
+import com.usai.redant.apexdrivers.signature.SignatureActivity;
|
|
|
|
|
+import com.usai.redant.apexdrivers.update.model.UpdateBaseModel;
|
|
|
|
|
+import com.usai.redant.apexdrivers.update.model.UpdateImageBaseModel;
|
|
|
|
|
+import com.usai.redant.apexdrivers.update.model.UpdateInputModel;
|
|
|
|
|
+import com.usai.redant.apexdrivers.update.model.UpdateMultInputModel;
|
|
|
|
|
+import com.usai.redant.apexdrivers.update.model.UpdatePhotoModel;
|
|
|
|
|
+import com.usai.redant.apexdrivers.update.model.UpdateSignatureModel;
|
|
|
|
|
+import com.usai.redant.rautils.receiver.RABroadcast;
|
|
|
|
|
+import com.usai.redant.rautils.utils.FileManager;
|
|
|
|
|
+import com.usai.redant.rautils.utils.ImageUtil;
|
|
|
|
|
+import com.usai.redant.rautils.utils.RAUtil;
|
|
|
|
|
+
|
|
|
|
|
+import org.json.JSONArray;
|
|
|
|
|
+import org.json.JSONException;
|
|
|
|
|
+import org.json.JSONObject;
|
|
|
|
|
+
|
|
|
|
|
+import java.io.File;
|
|
|
|
|
+import java.io.FileInputStream;
|
|
|
|
|
+import java.io.FileNotFoundException;
|
|
|
|
|
+import java.io.FileOutputStream;
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.lang.ref.WeakReference;
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Objects;
|
|
|
|
|
+
|
|
|
|
|
+import static com.usai.redant.rautils.utils.Network.RESULT_TRUE;
|
|
|
|
|
+
|
|
|
|
|
+public class UpdateActivity extends BasicActivity implements UpdateAdapter.UpdateAdapterDelegate {
|
|
|
|
|
+
|
|
|
|
|
+ private final static String OrderIDKey = "OrderID";
|
|
|
|
|
+ private final static String ActionIDKey = "ActionID";
|
|
|
|
|
+ private final static String ActionTitleKey = "ActionTitle";
|
|
|
|
|
+ private final static String OrderType2Key = "OrderType2";
|
|
|
|
|
+
|
|
|
|
|
+ private final static String SaveDataKey = "UpdateSavedJson";
|
|
|
|
|
+ private final static String SaveOrderIDKey = "UpdateSavedOrderID";
|
|
|
|
|
+ private final static String SaveActionIDKey = "UpdateSavedActionID";
|
|
|
|
|
+ private final static String SaveTitleKey = "UpdateSavedTitle";
|
|
|
|
|
+ private final static String SaveOrderType2Key = "UpdateSaveOrderType2";
|
|
|
|
|
+
|
|
|
|
|
+ private final static int REQUEST_SCANNER_CODE = 0;
|
|
|
|
|
+ private final static int REQUEST_CAMERA_CODE = 1;
|
|
|
|
|
+ private final static int REQUEST_PREVIEW_CODE = 2;
|
|
|
|
|
+ private final static int REQUEST_SIGNATURE_CODE = 3;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ public static Intent build(Context ctx, String orderID, int actionID,String actionTitle, String orderType2) {
|
|
|
|
|
+
|
|
|
|
|
+ Intent intent = new Intent(ctx, UpdateActivity.class);
|
|
|
|
|
+ if (orderID != null) {
|
|
|
|
|
+ intent.putExtra(OrderIDKey,orderID);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (actionTitle != null) {
|
|
|
|
|
+ intent.putExtra(ActionTitleKey,actionTitle);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (orderType2 != null) {
|
|
|
|
|
+ intent.putExtra(OrderType2Key,orderType2);
|
|
|
|
|
+ }
|
|
|
|
|
+ intent.putExtra(ActionIDKey,actionID);
|
|
|
|
|
+
|
|
|
|
|
+ return intent;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String mOrderID;
|
|
|
|
|
+ private String mTitle;
|
|
|
|
|
+ private int mActionID;
|
|
|
|
|
+ private String mOrderType2;
|
|
|
|
|
+
|
|
|
|
|
+ private Context mCtx = this;
|
|
|
|
|
+ private UpdateActivity self = this;
|
|
|
|
|
+ private UpdateHandler mHandler;
|
|
|
|
|
+ private ArrayList<UpdateSectionModel> mSectionArray = new ArrayList<>();
|
|
|
|
|
+ private UpdateAdapter mAdapter;
|
|
|
|
|
+
|
|
|
|
|
+ private ExpandableListView mListView;
|
|
|
|
|
+ private SwipeRefreshLayout mRefresh;
|
|
|
|
|
+
|
|
|
|
|
+ private UpdateInputModel mInputModel;
|
|
|
|
|
+ private UpdatePhotoModel mPhotoModel;
|
|
|
|
|
+ private UpdateSignatureModel mSignatueModel;
|
|
|
|
|
+
|
|
|
|
|
+ private File photoFile = null;
|
|
|
|
|
+
|
|
|
|
|
+ private ProgressDialog mProgressDialog;
|
|
|
|
|
+ private AlertDialog mDialog;
|
|
|
|
|
+ private ArrayList<File> mPhotoArray = new ArrayList<>();// 用于直接返回后删除Photo文件
|
|
|
|
|
+
|
|
|
|
|
+ private TextView mEmptyView;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
|
|
+ setContentView(R.layout.activity_update);
|
|
|
|
|
+
|
|
|
|
|
+ android.support.v7.app.ActionBar actionBar = getSupportActionBar();
|
|
|
|
|
+ if(actionBar != null){
|
|
|
|
|
+ actionBar.setHomeButtonEnabled(true);
|
|
|
|
|
+ actionBar.setDisplayHomeAsUpEnabled(true);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (getIntent() != null) {
|
|
|
|
|
+ mTitle = getIntent().getStringExtra(ActionTitleKey);
|
|
|
|
|
+ setTitle(mTitle);
|
|
|
|
|
+
|
|
|
|
|
+ mOrderID = getIntent().getStringExtra(OrderIDKey);
|
|
|
|
|
+ mActionID = getIntent().getIntExtra(ActionIDKey,0);
|
|
|
|
|
+ mOrderType2 = getIntent().getStringExtra(OrderType2Key);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ mHandler = new UpdateHandler(self);
|
|
|
|
|
+
|
|
|
|
|
+ mListView = findViewById(R.id.update_list_view);
|
|
|
|
|
+ mAdapter = new UpdateAdapter(mCtx,mSectionArray,self);
|
|
|
|
|
+
|
|
|
|
|
+ mListView.setGroupIndicator(null);
|
|
|
|
|
+ mListView.setAdapter(mAdapter);
|
|
|
|
|
+ mListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
|
|
|
|
|
+ return true; // 不允许GroupView点击
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ mRefresh = findViewById(R.id.update_refresh);
|
|
|
|
|
+ mRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onRefresh() {
|
|
|
|
|
+ loadData();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ mEmptyView = findViewById(R.id.update_empty_btn);
|
|
|
|
|
+ mEmptyView.setText("There is no data\nPlease click to reload");
|
|
|
|
|
+ mEmptyView.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(View v) {
|
|
|
|
|
+ loadData();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ mListView.setEmptyView(findViewById(R.id.update_empty_view));
|
|
|
|
|
+
|
|
|
|
|
+ if (savedInstanceState != null) {
|
|
|
|
|
+
|
|
|
|
|
+ mTitle = savedInstanceState.getString(SaveTitleKey);
|
|
|
|
|
+ setTitle(mTitle);
|
|
|
|
|
+
|
|
|
|
|
+ mOrderID = savedInstanceState.getString(SaveOrderIDKey);
|
|
|
|
|
+ mActionID = savedInstanceState.getInt(SaveActionIDKey,0);
|
|
|
|
|
+ mOrderType2 = savedInstanceState.getString(SaveOrderType2Key);
|
|
|
|
|
+
|
|
|
|
|
+ String jsonStr = savedInstanceState.getString(SaveDataKey);
|
|
|
|
|
+ if (jsonStr != null) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ JSONObject json = new JSONObject(jsonStr);
|
|
|
|
|
+
|
|
|
|
|
+ handleJSON(json);
|
|
|
|
|
+ changeData();
|
|
|
|
|
+
|
|
|
|
|
+ } catch (JSONException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ loadData();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ checkCameraPermission();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void onSaveInstanceState(Bundle outState) {
|
|
|
|
|
+ super.onSaveInstanceState(outState);
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject json = prepareSavedJson();
|
|
|
|
|
+ if (json != null) {
|
|
|
|
|
+ outState.putString(SaveDataKey,json.toString());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (mOrderID != null) {
|
|
|
|
|
+ outState.putString(SaveOrderIDKey, mOrderID);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (mTitle != null) {
|
|
|
|
|
+ outState.putString(SaveTitleKey, mTitle);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (mOrderType2 != null) {
|
|
|
|
|
+ outState.putString(SaveOrderType2Key,mOrderType2);
|
|
|
|
|
+ }
|
|
|
|
|
+ outState.putInt(SaveActionIDKey, mActionID);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void onStop() {
|
|
|
|
|
+ super.onStop();
|
|
|
|
|
+
|
|
|
|
|
+ dismissProgressDialog();
|
|
|
|
|
+ if (mDialog != null && mDialog.isShowing()) {
|
|
|
|
|
+ mDialog.dismiss();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
+ int i = item.getItemId();
|
|
|
|
|
+ if (i == android.R.id.home) {
|
|
|
|
|
+ clearPhotos();
|
|
|
|
|
+ this.finish(); // back buttonreturn true;
|
|
|
|
|
+ } else if (i == R.id.update_btn) {
|
|
|
|
|
+ update();
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return super.onOptionsItemSelected(item);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onBackPressed() {
|
|
|
|
|
+ clearPhotos();
|
|
|
|
|
+ super.onBackPressed();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
|
+
|
|
|
|
|
+ getMenuInflater().inflate(R.menu.update_menu,menu);
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
|
+ super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
|
+
|
|
|
|
|
+ switch (requestCode) {
|
|
|
|
|
+ case REQUEST_SCANNER_CODE: {
|
|
|
|
|
+
|
|
|
|
|
+ if (resultCode == Activity.RESULT_OK) {
|
|
|
|
|
+ Bundle bundle = data.getExtras();
|
|
|
|
|
+ String pid = bundle.getString("pid");
|
|
|
|
|
+ if (mInputModel != null) {
|
|
|
|
|
+ mInputModel.setScannerInputValue(pid);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ mInputModel = null;
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case REQUEST_CAMERA_CODE: {
|
|
|
|
|
+
|
|
|
|
|
+ if (resultCode == Activity.RESULT_OK) {
|
|
|
|
|
+
|
|
|
|
|
+ File scaleFile = compressImageFile(photoFile);
|
|
|
|
|
+// File scaleFile = photoFile;
|
|
|
|
|
+ if (scaleFile != null) {
|
|
|
|
|
+
|
|
|
|
|
+ ImageUtil.updateGallery(mCtx,scaleFile.getAbsolutePath());
|
|
|
|
|
+
|
|
|
|
|
+ if (mPhotoModel != null) {
|
|
|
|
|
+ mPhotoModel.setPhotoPath(scaleFile.getAbsolutePath());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ mPhotoArray.add(scaleFile);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (photoFile.exists()) {
|
|
|
|
|
+ photoFile.delete(); // 没有拍照直接返回,需要将文件删除
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ mPhotoModel = null;
|
|
|
|
|
+ photoFile = null;
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case REQUEST_PREVIEW_CODE: {
|
|
|
|
|
+ if (resultCode == Activity.RESULT_OK) {
|
|
|
|
|
+
|
|
|
|
|
+ boolean delete = data.getBooleanExtra(PhotoPreviewActivity.PreviewActionDeleteKey,false);
|
|
|
|
|
+ if (delete) {
|
|
|
|
|
+ mPhotoModel.setPhotoPath(null);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ mPhotoModel = null;
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case REQUEST_SIGNATURE_CODE: {
|
|
|
|
|
+ if (resultCode == Activity.RESULT_OK) {
|
|
|
|
|
+ String signaturePath = data.getStringExtra("signaturePath");
|
|
|
|
|
+ if (mSignatueModel != null) {
|
|
|
|
|
+ mSignatueModel.setSignaturePath(signaturePath);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ mSignatueModel = null;
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void clearPhotos() {
|
|
|
|
|
+
|
|
|
|
|
+ for(File file : mPhotoArray) {
|
|
|
|
|
+ if (file.exists()) {
|
|
|
|
|
+ file.delete();
|
|
|
|
|
+ ImageUtil.updateGallery(mCtx,file.getAbsolutePath());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private File compressImageFile(File imgFile) {
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ String imageFileName = imgFile.getName();
|
|
|
|
|
+
|
|
|
|
|
+ File routedFile = ImageUtil.routeBitmap(mCtx,imgFile,null);
|
|
|
|
|
+
|
|
|
|
|
+ Bitmap source = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ FileInputStream stream = new FileInputStream(routedFile);
|
|
|
|
|
+ source = BitmapFactory.decodeStream(stream);
|
|
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
|
|
+ return routedFile;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (source == null) {
|
|
|
|
|
+ return routedFile;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ int originWidth = source.getWidth();
|
|
|
|
|
+ int originHeight = source.getHeight();
|
|
|
|
|
+
|
|
|
|
|
+ int width = originWidth, height = originHeight;
|
|
|
|
|
+
|
|
|
|
|
+ if (originHeight > 1024 || originWidth > 1024)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (originWidth > originHeight)
|
|
|
|
|
+ {
|
|
|
|
|
+ width = 1024;
|
|
|
|
|
+ height = originHeight * 1024 / originWidth;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ height = 1024;
|
|
|
|
|
+ width = originWidth * 1024 / originHeight;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ Bitmap scaled = Bitmap.createScaledBitmap(source, width, height, true);
|
|
|
|
|
+
|
|
|
|
|
+ String scalePath = FileManager.internalStorageFileDir(mCtx) + File.separator + "Photo" + File.separator +imageFileName;
|
|
|
|
|
+ File scaleFile = new File(scalePath);
|
|
|
|
|
+ if (!scaleFile.getParentFile().exists()) {
|
|
|
|
|
+ scaleFile.getParentFile().mkdirs();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+
|
|
|
|
|
+ FileOutputStream outputStream = new FileOutputStream(scaleFile);
|
|
|
|
|
+ scaled.compress(Bitmap.CompressFormat.JPEG, 95, outputStream);
|
|
|
|
|
+
|
|
|
|
|
+ outputStream.flush();
|
|
|
|
|
+ outputStream.close();
|
|
|
|
|
+
|
|
|
|
|
+ String rotedpath = routedFile.getAbsolutePath();
|
|
|
|
|
+ routedFile.delete();
|
|
|
|
|
+
|
|
|
|
|
+ ImageUtil.updateGallery(mCtx,rotedpath);
|
|
|
|
|
+
|
|
|
|
|
+ return scaleFile;
|
|
|
|
|
+
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ return routedFile;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Camera Permission
|
|
|
|
|
+ * */
|
|
|
|
|
+ private void checkCameraPermission() {
|
|
|
|
|
+
|
|
|
|
|
+ String[] permissions = {Manifest.permission.CAMERA,Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.READ_EXTERNAL_STORAGE};
|
|
|
|
|
+
|
|
|
|
|
+ RAUtil.checkPermissions(self,permissions);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * data
|
|
|
|
|
+ * */
|
|
|
|
|
+
|
|
|
|
|
+ private void showProgressDialog() {
|
|
|
|
|
+ if (mProgressDialog == null) {
|
|
|
|
|
+ mProgressDialog = new ProgressDialog(this);
|
|
|
|
|
+ mProgressDialog.setMessage("loading...");
|
|
|
|
|
+ mProgressDialog.setCancelable(false);
|
|
|
|
|
+ mProgressDialog.show();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void dismissProgressDialog() {
|
|
|
|
|
+ if (mProgressDialog != null && mProgressDialog.isShowing()) {
|
|
|
|
|
+ mProgressDialog.dismiss();
|
|
|
|
|
+ }
|
|
|
|
|
+ mProgressDialog = null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void showWarningMsg(String msg) {
|
|
|
|
|
+ if (msg == null || msg.length() == 0) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ new android.support.v7.app.AlertDialog.Builder(mCtx).setTitle("Warning")
|
|
|
|
|
+ .setMessage(msg)
|
|
|
|
|
+ .setPositiveButton("Ok",null)
|
|
|
|
|
+ .show();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void loadData() {
|
|
|
|
|
+
|
|
|
|
|
+ showProgressDialog();
|
|
|
|
|
+
|
|
|
|
|
+ if (mSectionArray != null) {
|
|
|
|
|
+ mSectionArray.clear();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (mAdapter != null) {
|
|
|
|
|
+ mAdapter.notifyDataSetChanged();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ new Thread(new Runnable() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject json = com.usai.redant.apexdrivers.network.Network.requestOrderUpdateInfo(mCtx,mOrderID,mActionID);
|
|
|
|
|
+
|
|
|
|
|
+ Message msg = new Message();
|
|
|
|
|
+ msg.what = UpdateHandler.UpdateActionReloadData;
|
|
|
|
|
+ msg.obj = json;
|
|
|
|
|
+ mHandler.sendMessage(msg);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }).start();
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void handleJSON(JSONObject json) {
|
|
|
|
|
+
|
|
|
|
|
+ JSONArray sectionArr = json.optJSONArray("sections");
|
|
|
|
|
+ if (sectionArr != null) {
|
|
|
|
|
+
|
|
|
|
|
+ mSectionArray.clear();
|
|
|
|
|
+ try {
|
|
|
|
|
+ for (int i = 0; i < sectionArr.length(); i++) {
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject section = sectionArr.getJSONObject(i);
|
|
|
|
|
+ UpdateSectionModel sectionModel = new UpdateSectionModel();
|
|
|
|
|
+ sectionModel.title = section.optString("title");
|
|
|
|
|
+ sectionModel.setItems(section.optJSONArray("items"));
|
|
|
|
|
+
|
|
|
|
|
+ mSectionArray.add(sectionModel);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (JSONException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void changeData() {
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 手动调用打开/关闭 Group,否则默认关闭
|
|
|
|
|
+ * */
|
|
|
|
|
+ if (mSectionArray.size() > 0) {
|
|
|
|
|
+ for (int i = 0; i < mSectionArray.size(); i++) {
|
|
|
|
|
+ mListView.expandGroup(i);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ mAdapter.notifyDataSetChanged();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String list2String(List<String> list, String seperator) {
|
|
|
|
|
+
|
|
|
|
|
+ Objects.requireNonNull(seperator);
|
|
|
|
|
+
|
|
|
|
|
+ if (list == null || list.size() == 0) {
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
+ if (list.size() == 1) {
|
|
|
|
|
+ return list.get(0);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ StringBuffer stringBuffer = new StringBuffer();
|
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
+ String e = list.get(i);
|
|
|
|
|
+
|
|
|
|
|
+ stringBuffer.append(e);
|
|
|
|
|
+
|
|
|
|
|
+ if (i != list.size() - 1) {
|
|
|
|
|
+ stringBuffer.append(seperator);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return stringBuffer.toString();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void update() {
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ Bundle params = new Bundle();
|
|
|
|
|
+ if (mOrderType2 != null) {
|
|
|
|
|
+ params.putString("orderType2",mOrderType2);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (ApexDriverApplication.sharedApplication().getRequiredLocation()) {
|
|
|
|
|
+ Location location = ApexDriverApplication.sharedApplication().getCurrentLocation();
|
|
|
|
|
+
|
|
|
|
|
+ String locationStr = null;
|
|
|
|
|
+ if (location != null) {
|
|
|
|
|
+ locationStr = location.getLatitude() + "," + location.getLongitude();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ locationStr = "-999,-999";
|
|
|
|
|
+ }
|
|
|
|
|
+ params.putString("location",locationStr);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ArrayList<String> emptyArr = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ final ArrayList<UpdateImageBaseModel> photoArr = prepareParams(params,emptyArr);
|
|
|
|
|
+
|
|
|
|
|
+ if (emptyArr.size() > 0) {
|
|
|
|
|
+
|
|
|
|
|
+ String msg = "please complete missing field:\n" + list2String(emptyArr,"\n");
|
|
|
|
|
+
|
|
|
|
|
+ new AlertDialog.Builder(mCtx)
|
|
|
|
|
+ .setTitle("Warning")
|
|
|
|
|
+ .setMessage(msg)
|
|
|
|
|
+ .setPositiveButton("Ok",null)
|
|
|
|
|
+ .show();
|
|
|
|
|
+
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ showProgressDialog();
|
|
|
|
|
+
|
|
|
|
|
+ final Bundle finalParams = params;
|
|
|
|
|
+ new Thread(new Runnable() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+
|
|
|
|
|
+ final JSONObject json = com.usai.redant.apexdrivers.network.Network.submitUpdateParams(finalParams);
|
|
|
|
|
+
|
|
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+
|
|
|
|
|
+ if (json != null) {
|
|
|
|
|
+ final int result = json.optInt("result",0);
|
|
|
|
|
+ if (result == RESULT_TRUE) {
|
|
|
|
|
+
|
|
|
|
|
+ boolean requiredLocation = json.optBoolean("requiredLocation");
|
|
|
|
|
+ ApexDriverApplication.sharedApplication().setRequiredLocation(requiredLocation);
|
|
|
|
|
+
|
|
|
|
|
+ if (photoArr.size() > 0) {
|
|
|
|
|
+ syncUploadPhotos(photoArr,json);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ dismissProgressDialog();
|
|
|
|
|
+ goHome();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ dismissProgressDialog();
|
|
|
|
|
+ // error
|
|
|
|
|
+ String errMsg = json.optString("err_msg");
|
|
|
|
|
+ if (errMsg == null || errMsg.length() == 0) {
|
|
|
|
|
+ errMsg = "Sorry,there is something wrong";
|
|
|
|
|
+ }
|
|
|
|
|
+ showWarningMsg(errMsg);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ dismissProgressDialog();
|
|
|
|
|
+ // error
|
|
|
|
|
+ String errMsg = "Sorry,there is something wrong";
|
|
|
|
|
+ showWarningMsg(errMsg);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }).start();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void syncUploadPhotos(ArrayList<UpdateImageBaseModel> photos, final JSONObject json) {
|
|
|
|
|
+
|
|
|
|
|
+ if (photos == null || (photos != null && photos.size() == 0) || json == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ final ArrayList<UpdateImageBaseModel> photoArr = photos;
|
|
|
|
|
+ final String serial = json.optString("serial");
|
|
|
|
|
+ new Thread(new Runnable() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+ int retryCount = 0;
|
|
|
|
|
+ ArrayList<UpdateImageBaseModel> finishArr = new ArrayList<>();
|
|
|
|
|
+ for (int i = 0; i < photoArr.size(); i++) {
|
|
|
|
|
+
|
|
|
|
|
+ UpdateImageBaseModel model = photoArr.get(i);
|
|
|
|
|
+
|
|
|
|
|
+ if (serial != null && serial.length() > 0) {
|
|
|
|
|
+
|
|
|
|
|
+ Bundle fileParams = new Bundle();
|
|
|
|
|
+ fileParams.putString("serial",serial);
|
|
|
|
|
+ if (mOrderType2 != null) {
|
|
|
|
|
+ fileParams.putString("orderType2",mOrderType2);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (model.key != null) {
|
|
|
|
|
+ fileParams.putString("key",model.key);
|
|
|
|
|
+ }
|
|
|
|
|
+ fileParams.putInt("type",model.type);
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject jsonObj = com.usai.redant.apexdrivers.network.Network.uploadFile(model.getImagePath(),fileParams);
|
|
|
|
|
+ if (jsonObj != null) {
|
|
|
|
|
+ int result = jsonObj.optInt("result",0);
|
|
|
|
|
+ if (result != RESULT_TRUE) {
|
|
|
|
|
+ i--;
|
|
|
|
|
+ retryCount++;
|
|
|
|
|
+ if (retryCount >= 3) {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ retryCount = 0;
|
|
|
|
|
+ File photoFile = new File(model.getImagePath());
|
|
|
|
|
+ if (photoFile.exists()) {
|
|
|
|
|
+ photoFile.delete();
|
|
|
|
|
+ ImageUtil.updateGallery(mCtx,model.getImagePath());
|
|
|
|
|
+ }
|
|
|
|
|
+ finishArr.add(model);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // error
|
|
|
|
|
+ i--;
|
|
|
|
|
+ retryCount++;
|
|
|
|
|
+ if (retryCount >= 3) {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for (UpdateImageBaseModel model : finishArr) {
|
|
|
|
|
+ photoArr.remove(model);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ final ArrayList<UpdateImageBaseModel> uploadFaildArr = photoArr;
|
|
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+ dismissProgressDialog();
|
|
|
|
|
+ if (uploadFaildArr.size() > 0) {
|
|
|
|
|
+
|
|
|
|
|
+ mDialog = new AlertDialog.Builder(mCtx)
|
|
|
|
|
+ .setTitle("Warning")
|
|
|
|
|
+ .setMessage("upload the photos failed,would you like to retry or do it background?")
|
|
|
|
|
+ .setPositiveButton("Background", new DialogInterface.OnClickListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
+
|
|
|
|
|
+ backgroundUpload(uploadFaildArr,json);
|
|
|
|
|
+ goHome();
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .setNegativeButton("Retry", new DialogInterface.OnClickListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
+ syncUploadPhotos(uploadFaildArr,json);
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .show();
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+
|
|
|
|
|
+ goHome();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }).start();
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void goHome() {
|
|
|
|
|
+ Intent intent = new Intent(self, MainActivity.class);
|
|
|
|
|
+ intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
|
+ self.startActivity(intent);
|
|
|
|
|
+
|
|
|
|
|
+ sendBroadcast(new Intent(HomeFragment.HomeReloadBroadcastAction));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void backgroundUpload(ArrayList<UpdateImageBaseModel> photos, final JSONObject json) {
|
|
|
|
|
+
|
|
|
|
|
+ if (photos == null || (photos != null && photos.size() == 0) || json == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ArrayList<Bundle> taskArr = new ArrayList<Bundle>();
|
|
|
|
|
+ final ArrayList<UpdateImageBaseModel> photoArr = photos;
|
|
|
|
|
+
|
|
|
|
|
+ Date currentTime = new Date();
|
|
|
|
|
+ SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/YYYY HH:mm");
|
|
|
|
|
+ String dateString = formatter.format(currentTime);
|
|
|
|
|
+
|
|
|
|
|
+ final String serial = json.optString("serial");
|
|
|
|
|
+
|
|
|
|
|
+ for (int i = 0; i < photoArr.size(); i++) {
|
|
|
|
|
+
|
|
|
|
|
+ UpdateImageBaseModel model = photoArr.get(i);
|
|
|
|
|
+
|
|
|
|
|
+ if (serial != null && serial.length() > 0) {
|
|
|
|
|
+
|
|
|
|
|
+ Bundle task = new Bundle();
|
|
|
|
|
+ task.putString("path",model.getImagePath());
|
|
|
|
|
+ task.putString("file", FileManager.lastPathComponent(model.getImagePath()));
|
|
|
|
|
+ task.putString("url", Network.URL_UPLOAD);
|
|
|
|
|
+ task.putString("order",mOrderID);
|
|
|
|
|
+ task.putString("action",getTitle().toString());
|
|
|
|
|
+ task.putString("time",dateString);
|
|
|
|
|
+ task.putString("name",model.title);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ Bundle params = new Bundle();
|
|
|
|
|
+ params.putString("platform","android");
|
|
|
|
|
+ params.putString("serial", serial);
|
|
|
|
|
+ params.putString("name",ApexDriverApplication.sharedApplication().encryptUser());
|
|
|
|
|
+ params.putString("password",ApexDriverApplication.sharedApplication().encryptPassword());
|
|
|
|
|
+ if (mOrderType2 != null) {
|
|
|
|
|
+ params.putString("orderType2",mOrderType2);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (model.key != null) {
|
|
|
|
|
+ params.putString("key",model.key);
|
|
|
|
|
+ }
|
|
|
|
|
+ params.putInt("type",model.type);
|
|
|
|
|
+
|
|
|
|
|
+ task.putBundle("params",params);
|
|
|
|
|
+ taskArr.add(task);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (taskArr.size() > 0) {
|
|
|
|
|
+
|
|
|
|
|
+ Intent intent = new Intent(RABroadcast.ACTION_UPLOAD_ADD_TASK);
|
|
|
|
|
+ intent.putParcelableArrayListExtra("tasks",taskArr);
|
|
|
|
|
+
|
|
|
|
|
+ sendBroadcast(intent);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private ArrayList<UpdateImageBaseModel> prepareParams(Bundle params,ArrayList<String> emptyArr) {
|
|
|
|
|
+
|
|
|
|
|
+ if (params == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ArrayList<UpdateImageBaseModel> photoArr = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ if (mOrderID != null) {
|
|
|
|
|
+ params.putString("orderID",mOrderID);
|
|
|
|
|
+ }
|
|
|
|
|
+ params.putInt("actionID",mActionID);
|
|
|
|
|
+
|
|
|
|
|
+ String user = ApexDriverApplication.sharedApplication().encryptUser();
|
|
|
|
|
+ String password = ApexDriverApplication.sharedApplication().encryptPassword();
|
|
|
|
|
+ if (user != null) {
|
|
|
|
|
+ params.putString("user",user);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (password != null) {
|
|
|
|
|
+ params.putString("password",password);
|
|
|
|
|
+ }
|
|
|
|
|
+ params.putString("platform","android");
|
|
|
|
|
+// params.putString("location",lat + "," + lon);
|
|
|
|
|
+
|
|
|
|
|
+ for (int i = 0; i < mSectionArray.size(); i++) {
|
|
|
|
|
+ UpdateSectionModel sectionModel = mSectionArray.get(i);
|
|
|
|
|
+ for (int j = 0; j < sectionModel.itemCount(); j++) {
|
|
|
|
|
+ UpdateBaseModel baseModel = sectionModel.itemModelForIndex(j);
|
|
|
|
|
+ switch (baseModel.type) {
|
|
|
|
|
+ case UpdateBaseModel.UpdateTypeLabel: {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case UpdateBaseModel.UpdateTypeInput: {
|
|
|
|
|
+
|
|
|
|
|
+ UpdateInputModel inputModel = (UpdateInputModel)baseModel;
|
|
|
|
|
+
|
|
|
|
|
+ if (emptyArr != null && baseModel.required && (TextUtils.isEmpty(inputModel.value))) {
|
|
|
|
|
+ emptyArr.add(emptyArr.size() + 1 + "." + baseModel.title);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (inputModel.key != null && inputModel.value != null && inputModel.value.length() > 0) {
|
|
|
|
|
+ params.putString(inputModel.key,inputModel.value);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case UpdateBaseModel.UpdateTypeMultInput: {
|
|
|
|
|
+
|
|
|
|
|
+ UpdateMultInputModel multInputModel = (UpdateMultInputModel)baseModel;
|
|
|
|
|
+
|
|
|
|
|
+ if (emptyArr != null && baseModel.required && (TextUtils.isEmpty(multInputModel.value))) {
|
|
|
|
|
+ emptyArr.add(emptyArr.size() + 1 + "." + baseModel.title);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (multInputModel.key != null && multInputModel.value != null && multInputModel.value.length() > 0) {
|
|
|
|
|
+ params.putString(multInputModel.key,multInputModel.value);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case UpdateBaseModel.UpdateTypeSignature:
|
|
|
|
|
+ case UpdateBaseModel.UpdateTypePhoto: {
|
|
|
|
|
+
|
|
|
|
|
+ UpdateImageBaseModel photoModel = (UpdateImageBaseModel)baseModel;
|
|
|
|
|
+
|
|
|
|
|
+ if (emptyArr != null && baseModel.required && (TextUtils.isEmpty(photoModel.getImagePath()))) {
|
|
|
|
|
+ emptyArr.add(emptyArr.size() + 1 + "." + baseModel.title);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (photoModel.getImagePath() != null && photoModel.getImagePath().length() > 0 && photoModel.key != null) {
|
|
|
|
|
+ params.putString(photoModel.key,photoModel.getImageName());
|
|
|
|
|
+
|
|
|
|
|
+ photoArr.add(photoModel);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return photoArr;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Adapter Delegate
|
|
|
|
|
+ * */
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void scannerButtonDidClick(UpdateInputModel model) {
|
|
|
|
|
+
|
|
|
|
|
+ if (model == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (PermissionChecker.checkSelfPermission(mCtx,Manifest.permission.CAMERA)!= PermissionChecker.PERMISSION_GRANTED) {
|
|
|
|
|
+
|
|
|
|
|
+ Toast.makeText(mCtx,"please allow app use camera",Toast.LENGTH_LONG).show();
|
|
|
|
|
+
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ mInputModel = model;
|
|
|
|
|
+
|
|
|
|
|
+ Intent intent = new Intent();
|
|
|
|
|
+ intent.setClass(mCtx, CaptureActivity.class);
|
|
|
|
|
+ startActivityForResult(intent, REQUEST_SCANNER_CODE);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void photoButtonDidClick(UpdatePhotoModel model) {
|
|
|
|
|
+
|
|
|
|
|
+ if (model == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ mPhotoModel = model;
|
|
|
|
|
+ if (model.getImagePath() == null || model.getImagePath().length() == 0) {
|
|
|
|
|
+
|
|
|
|
|
+ startCamera();
|
|
|
|
|
+ } else {
|
|
|
|
|
+
|
|
|
|
|
+ Intent intent = PhotoPreviewActivity.build(self,model.getImagePath(),true);
|
|
|
|
|
+ startActivityForResult(intent,REQUEST_PREVIEW_CODE);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void signatureClick(UpdateSignatureModel model) {
|
|
|
|
|
+ if (model == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ mSignatueModel = model;
|
|
|
|
|
+ SignatureActivity.startSignature(this,REQUEST_SIGNATURE_CODE);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Camera
|
|
|
|
|
+ * */
|
|
|
|
|
+ private void startCamera()
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ boolean cameraPermission = PermissionChecker.checkSelfPermission(mCtx,Manifest.permission.CAMERA) == PermissionChecker.PERMISSION_GRANTED;
|
|
|
|
|
+ boolean storageReadPermission = PermissionChecker.checkSelfPermission(mCtx,Manifest.permission.READ_EXTERNAL_STORAGE) == PermissionChecker.PERMISSION_GRANTED;
|
|
|
|
|
+ boolean storageWritePermission = PermissionChecker.checkSelfPermission(mCtx,Manifest.permission.WRITE_EXTERNAL_STORAGE) == PermissionChecker.PERMISSION_GRANTED;
|
|
|
|
|
+
|
|
|
|
|
+ if (!cameraPermission || !storageReadPermission || !storageWritePermission) {
|
|
|
|
|
+
|
|
|
|
|
+ Toast.makeText(mCtx,"please allow app use camera and storage",Toast.LENGTH_LONG).show();
|
|
|
|
|
+
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
|
|
|
|
+ // Ensure that there's a camera activity to handle the intent
|
|
|
|
|
+
|
|
|
|
|
+ if (takePictureIntent.resolveActivity(getPackageManager()) != null)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (photoFile != null)
|
|
|
|
|
+ photoFile = null;
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ photoFile = createImageFile();
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (IOException ex)
|
|
|
|
|
+ {
|
|
|
|
|
+ Log.d("Update Order", "StartCamera: " + ex);
|
|
|
|
|
+ }
|
|
|
|
|
+ // Continue only if the File was successfully created
|
|
|
|
|
+ if (photoFile != null)
|
|
|
|
|
+ {
|
|
|
|
|
+ takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, getImageContentUri(this,photoFile));
|
|
|
|
|
+ startActivityForResult(takePictureIntent, REQUEST_CAMERA_CODE);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private File createImageFile() throws IOException
|
|
|
|
|
+ {
|
|
|
|
|
+ // Create an image file name
|
|
|
|
|
+ String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmSS").format(new Date());
|
|
|
|
|
+ String imageFileName = "JPEG_" + timeStamp + "_";
|
|
|
|
|
+ String appName = RAUtil.getApplicationName(mCtx);
|
|
|
|
|
+
|
|
|
|
|
+ File storageDir = new File(Environment.getExternalStorageDirectory().getPath() + "/" + appName + "/photo/temp/");
|
|
|
|
|
+
|
|
|
|
|
+ File dir1 = new File(Environment.getExternalStorageDirectory().getPath() + "/" + appName);
|
|
|
|
|
+ File dir2 = new File(Environment.getExternalStorageDirectory().getPath() + "/" + appName + "/photo");
|
|
|
|
|
+ File dir3 = new File(Environment.getExternalStorageDirectory().getPath() + "/" + appName + "/photo/temp/");
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if (!dir1.exists())
|
|
|
|
|
+ {
|
|
|
|
|
+ boolean b = dir1.mkdir();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!dir2.exists())
|
|
|
|
|
+ {
|
|
|
|
|
+ boolean b = dir2.mkdir();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!dir3.exists())
|
|
|
|
|
+ {
|
|
|
|
|
+ boolean b = dir3.mkdir();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ File image = File.createTempFile(imageFileName, /* prefix */
|
|
|
|
|
+ ".jpg", /* suffix */
|
|
|
|
|
+ storageDir /* directory */
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ return image;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Uri getImageContentUri(Context context, File imageFile) {
|
|
|
|
|
+ String filePath = imageFile.getAbsolutePath();
|
|
|
|
|
+ Cursor cursor = context.getContentResolver().query(
|
|
|
|
|
+ MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
|
|
|
|
|
+ new String[] { MediaStore.Images.Media._ID },
|
|
|
|
|
+ MediaStore.Images.Media.DATA + "=? ",
|
|
|
|
|
+ new String[] { filePath }, null);
|
|
|
|
|
+
|
|
|
|
|
+ if (cursor != null && cursor.moveToFirst()) {
|
|
|
|
|
+ int id = cursor.getInt(cursor
|
|
|
|
|
+ .getColumnIndex(MediaStore.MediaColumns._ID));
|
|
|
|
|
+ Uri baseUri = Uri.parse("content://media/external/images/media");
|
|
|
|
|
+ return Uri.withAppendedPath(baseUri, "" + id);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (imageFile.exists()) {
|
|
|
|
|
+ ContentValues values = new ContentValues();
|
|
|
|
|
+ values.put(MediaStore.Images.Media.DATA, filePath);
|
|
|
|
|
+ return context.getContentResolver().insert(
|
|
|
|
|
+ MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Handler
|
|
|
|
|
+ * */
|
|
|
|
|
+ private static class UpdateHandler extends Handler {
|
|
|
|
|
+
|
|
|
|
|
+ public static final int UpdateActionReloadData = 0;
|
|
|
|
|
+
|
|
|
|
|
+ private WeakReference<UpdateActivity> mWeakActivity;
|
|
|
|
|
+
|
|
|
|
|
+ UpdateHandler(UpdateActivity activity) {
|
|
|
|
|
+ if (activity != null) {
|
|
|
|
|
+ mWeakActivity = new WeakReference<>(activity);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void handleMessage(Message msg) {
|
|
|
|
|
+ super.handleMessage(msg);
|
|
|
|
|
+
|
|
|
|
|
+ UpdateActivity activity = mWeakActivity.get();
|
|
|
|
|
+ activity.dismissProgressDialog();
|
|
|
|
|
+
|
|
|
|
|
+ switch (msg.what) {
|
|
|
|
|
+ case UpdateActionReloadData: {
|
|
|
|
|
+ if (activity.mRefresh.isRefreshing()) {
|
|
|
|
|
+ activity.mRefresh.setRefreshing(false);
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONObject json = (JSONObject) msg.obj;
|
|
|
|
|
+ if (json != null) {
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+
|
|
|
|
|
+ int restul = json.getInt("result");
|
|
|
|
|
+ if (restul == RESULT_TRUE) {
|
|
|
|
|
+
|
|
|
|
|
+ activity.handleJSON(json);
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // error
|
|
|
|
|
+ String errMsg = json.optString("err_msg");
|
|
|
|
|
+ if (errMsg == null || errMsg.length() == 0) {
|
|
|
|
|
+ errMsg = "Sorry,there is something wrong";
|
|
|
|
|
+ }
|
|
|
|
|
+ activity.showWarningMsg(errMsg);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (JSONException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ // error
|
|
|
|
|
+ String errMsg = "Sorry,there is something wrong";
|
|
|
|
|
+ activity.showWarningMsg(errMsg);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // error
|
|
|
|
|
+ String errMsg = "Sorry,there is something wrong";
|
|
|
|
|
+ activity.showWarningMsg(errMsg);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ activity.changeData();
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Save
|
|
|
|
|
+ * */
|
|
|
|
|
+
|
|
|
|
|
+ private JSONObject prepareSavedJson() {
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
|
|
+ JSONArray sections = new JSONArray();
|
|
|
|
|
+ try {
|
|
|
|
|
+ for (int i = 0; i < mSectionArray.size(); i++) {
|
|
|
|
|
+
|
|
|
|
|
+ UpdateSectionModel sectionModel = mSectionArray.get(i);
|
|
|
|
|
+ JSONObject sectionJson = sectionModel.sectionModel2Json();
|
|
|
|
|
+ if (sectionJson != null) {
|
|
|
|
|
+ sections.put(sectionJson);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ json.put("sections",sections);
|
|
|
|
|
+ } catch (JSONException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ return json;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|