|
@@ -0,0 +1,496 @@
|
|
|
+package com.fxy.detection;
|
|
|
+
|
|
|
+import android.annotation.SuppressLint;
|
|
|
+import android.app.AlertDialog;
|
|
|
+import android.content.BroadcastReceiver;
|
|
|
+import android.content.Context;
|
|
|
+import android.content.DialogInterface;
|
|
|
+import android.content.Intent;
|
|
|
+import android.content.IntentFilter;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.os.Handler;
|
|
|
+import android.os.Message;
|
|
|
+import android.support.v7.widget.RecyclerView;
|
|
|
+import android.text.Editable;
|
|
|
+import android.text.TextWatcher;
|
|
|
+import android.view.KeyEvent;
|
|
|
+import android.view.View;
|
|
|
+import android.view.inputmethod.EditorInfo;
|
|
|
+import android.widget.EditText;
|
|
|
+import android.widget.ImageButton;
|
|
|
+import android.widget.LinearLayout;
|
|
|
+import android.widget.TextView;
|
|
|
+import android.widget.Toast;
|
|
|
+
|
|
|
+import com.elvishew.xlog.XLog;
|
|
|
+import com.fxy.R;
|
|
|
+import com.fxy.baselibrary.base.BaseActivity;
|
|
|
+import com.fxy.baselibrary.bean.BaseEventBusBean;
|
|
|
+import com.fxy.baselibrary.interfaces.OnRxScanerListener;
|
|
|
+import com.fxy.baselibrary.qrcode.ActivityScanerCode;
|
|
|
+import com.fxy.baselibrary.util.JsonUtil;
|
|
|
+import com.fxy.baselibrary.util.StringUtils;
|
|
|
+import com.fxy.bean.ActionBean;
|
|
|
+import com.fxy.bean.ScanBean;
|
|
|
+import com.fxy.common.PictureSelectorUpload;
|
|
|
+import com.fxy.constant.BaseConfig;
|
|
|
+import com.fxy.constant.EventCode;
|
|
|
+import com.fxy.net.MyDialogCallback;
|
|
|
+import com.fxy.net.Urls;
|
|
|
+import com.fxy.view.FloatingImageView;
|
|
|
+import com.google.gson.Gson;
|
|
|
+import com.google.zxing.Result;
|
|
|
+import com.luck.picture.lib.config.PictureConfig;
|
|
|
+import com.lzy.okgo.OkGo;
|
|
|
+import com.lzy.okgo.model.Response;
|
|
|
+
|
|
|
+import org.json.JSONException;
|
|
|
+import org.json.JSONObject;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+
|
|
|
+import butterknife.BindView;
|
|
|
+import butterknife.ButterKnife;
|
|
|
+import butterknife.OnClick;
|
|
|
+import butterknife.Unbinder;
|
|
|
+import sto.android.app.StoJNI;
|
|
|
+import sto.android.app.StoPdaKeyEvent;
|
|
|
+import sto.android.app.StoTongJNI;
|
|
|
+
|
|
|
+public class ScanPhotosMainActivity extends BaseActivity implements StoJNI.ScanCallBack{
|
|
|
+
|
|
|
+
|
|
|
+ * 列表适配器
|
|
|
+ */
|
|
|
+ Context mContext = this;
|
|
|
+
|
|
|
+
|
|
|
+ @BindView(R.id.ll_take_picture)
|
|
|
+ LinearLayout llTakePicture;
|
|
|
+
|
|
|
+
|
|
|
+ private ArrayList photoList =new ArrayList<>();
|
|
|
+
|
|
|
+ private PictureSelectorUpload pictureSelectorUpload;
|
|
|
+
|
|
|
+
|
|
|
+ private ScanBean scanBean;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @BindView(R.id.iv_drag)
|
|
|
+ FloatingImageView iv_drag;
|
|
|
+
|
|
|
+
|
|
|
+ private String urlCode = "";
|
|
|
+
|
|
|
+ protected String action;
|
|
|
+
|
|
|
+
|
|
|
+ private Unbinder unbinder;
|
|
|
+
|
|
|
+ private JSONObject postParam = new JSONObject();
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getContentViewResId() {
|
|
|
+ return R.layout.activity_fxy_scan_photos;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean showToolBar() {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean openEventBus() {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void getBundleExtras(Bundle bundle) {
|
|
|
+
|
|
|
+ action = bundle.getString("action","add");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
+ super.onActivityResult(requestCode, resultCode, data);
|
|
|
+
|
|
|
+ if (resultCode == RESULT_OK) {
|
|
|
+ if (requestCode == PictureConfig.CHOOSE_REQUEST) {
|
|
|
+ pictureSelectorUpload.getSelectImg(data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * EventBus接收信息的方法,开启后才会调用(非粘性事件)
|
|
|
+ *
|
|
|
+ * @param event
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ protected void EventBean(BaseEventBusBean event) {
|
|
|
+
|
|
|
+
|
|
|
+ if (event != null && event.getEventCode() == EventCode.displacement_refresh){
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean isPlayMusic() {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initView() {
|
|
|
+ unbinder = ButterKnife.bind(this);
|
|
|
+ setTitleName("扫码拍照");
|
|
|
+
|
|
|
+ initEdit();
|
|
|
+ iniData();
|
|
|
+
|
|
|
+ RecyclerView rvShowImg = (RecyclerView)llTakePicture.findViewById(R.id.rv_show_img);
|
|
|
+ pictureSelectorUpload = setItemPicture("detection",rvShowImg,9,PictureConfig.TYPE_IMAGE);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ iv_drag.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if(!iv_drag.isDrag()){
|
|
|
+ ActivityScanerCode.setScanerListener(mScanerListener);
|
|
|
+ ActivityScanerCode.intent2Activity(mContext, BaseConfig.COMMON_SCANNER_ONLY);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * 设置多个上传文件
|
|
|
+ * @param actionType String
|
|
|
+ * @param showImg RecyclerView
|
|
|
+ */
|
|
|
+ private PictureSelectorUpload setItemPicture(String actionType,RecyclerView showImg,int maxNum,int pictureType){
|
|
|
+ PictureSelectorUpload pictureUpload = new PictureSelectorUpload(ScanPhotosMainActivity.this,showImg,"work",maxNum,pictureType);
|
|
|
+ pictureUpload.setActionType(actionType);
|
|
|
+ pictureUpload.setCompress(true,100,500);
|
|
|
+ pictureUpload.setOnlyCamera(true);
|
|
|
+
|
|
|
+
|
|
|
+ pictureUpload.setOnChangeListener(new PictureSelectorUpload.UploadChangeListener() {
|
|
|
+ @Override
|
|
|
+ public void uploadResult(boolean State,String actionType) {
|
|
|
+ if (State) {
|
|
|
+ pictureInbound();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void uploadActionType(String actionType) {
|
|
|
+
|
|
|
+ System.out.println("actionType:"+actionType);
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return pictureUpload;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean dispatchKeyEvent(KeyEvent event) {
|
|
|
+
|
|
|
+ if ((event.getKeyCode()==KeyEvent.KEYCODE_DPAD_CENTER || event.getKeyCode()==KeyEvent.KEYCODE_ENTER ) && event.getAction() == KeyEvent.ACTION_DOWN){
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ return super.dispatchKeyEvent(event);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
+ XLog.e("监听按键:"+keyCode);XLog.e(event);
|
|
|
+ if (scanBean.getIsBroadcast()==0 && StoTongJNI.getIns(mContext).getEventFuction(keyCode) == StoPdaKeyEvent.KEYCODE_SCAN
|
|
|
+ && event.getRepeatCount() == 0) {
|
|
|
+
|
|
|
+ if (StoTongJNI.getIns(mContext).GetScannerIsScanning()) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+ StoTongJNI.getIns(mContext).SetScannerStart();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return super.onKeyDown(keyCode, event);
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressLint("HandlerLeak")
|
|
|
+ Handler scanHandler = new Handler() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void handleMessage(Message msg) {
|
|
|
+
|
|
|
+ if (msg.obj != null) {
|
|
|
+
|
|
|
+ String scanResult = msg.obj.toString().trim();
|
|
|
+ if (!scanResult.isEmpty()){
|
|
|
+ setScanResult(scanResult);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ };
|
|
|
+ @Override
|
|
|
+ public void onScanResults(String str) {
|
|
|
+ Message msg = new Message();
|
|
|
+ msg.obj = str;
|
|
|
+ scanHandler.sendMessage(msg);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onScanResults(String str, int type) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ * 定义广播接受
|
|
|
+ */
|
|
|
+ BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
|
|
+ @Override
|
|
|
+ public void onReceive(Context context, Intent intent) {
|
|
|
+ String scanResult = intent.getStringExtra(scanBean.getDataName());
|
|
|
+ if (scanResult==null){return; }
|
|
|
+ String scanStatus = "";
|
|
|
+ if (!scanBean.getStatusName().isEmpty()){
|
|
|
+ scanStatus = intent.getStringExtra(scanBean.getStatusName());
|
|
|
+ }else{
|
|
|
+ scanStatus = scanResult.isEmpty()? "" : "ok";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (!scanBean.getActionStop().isEmpty()){
|
|
|
+ Intent stopIntent = new Intent(scanBean.getActionStop());
|
|
|
+ mContext.sendBroadcast(stopIntent);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ("ok".equals(scanStatus)){
|
|
|
+ setScanResult(scanResult);
|
|
|
+ }else{
|
|
|
+ showErrorToast(getString(R.string.scan_failed));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+ * 注册广播
|
|
|
+ */
|
|
|
+ private void initReceiver(){
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ String scanStr = getScanSetting();
|
|
|
+ scanBean = JsonUtil.getObject(scanStr, ScanBean.class);
|
|
|
+ Integer is_broadcast = scanBean.getIsBroadcast();
|
|
|
+
|
|
|
+ if (is_broadcast ==1){
|
|
|
+ IntentFilter mFilter = new IntentFilter(scanBean.getAction());
|
|
|
+ this.registerReceiver(mReceiver, mFilter);
|
|
|
+ }else{
|
|
|
+
|
|
|
+ String pdaBrand = StoTongJNI.getmPdaBrand();
|
|
|
+ if (!pdaBrand.isEmpty()){
|
|
|
+ StoTongJNI.getIns(this).setmScanCB(this);
|
|
|
+ StoTongJNI.getIns(this).SetScannerOn();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }catch (Exception e) {
|
|
|
+ showErrorToast("获取扫码配置失败"+e.getMessage());
|
|
|
+ XLog.e("获取扫码配置失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initEdit() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void iniData(){
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private OnRxScanerListener mScanerListener = new OnRxScanerListener() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(String type, Result result) {
|
|
|
+ String scanResult = result.getText();
|
|
|
+ switch (type){
|
|
|
+ case BaseConfig.COMMON_SCANNER_ONLY:
|
|
|
+ setScanResult(scanResult);
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public void onFail(String type, String message) {
|
|
|
+
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+ private void setScanResult(String scanResult){
|
|
|
+ showSuccessToast("扫描成功");
|
|
|
+ urlCode = scanResult;
|
|
|
+ pictureSelectorUpload.authCamera();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void pictureInbound(){
|
|
|
+ if (!validate()){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (!checkRepeat(Urls.FXY_DETECTION_CODE_PHOTO+(postParam.toString()))){
|
|
|
+ Toast.makeText(this, getString(R.string.error_data_processed), Toast.LENGTH_LONG).show();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ OkGo.<String>post(Urls.getServiceAddress(this) + Urls.FXY_DETECTION_CODE_PHOTO).upJson(postParam)
|
|
|
+ .execute(new MyDialogCallback(this, true, true) {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(Response<String> response) {
|
|
|
+ super.onSuccess(response);
|
|
|
+ try {
|
|
|
+ ActionBean bean = JsonUtil.getObject(response.body(), ActionBean.class);
|
|
|
+ if(bean.code == 1){
|
|
|
+ showSuccessToast(bean.msg);
|
|
|
+ pictureSelectorUpload.emptyRemake();
|
|
|
+ photoList.clear();
|
|
|
+ urlCode = "";
|
|
|
+
|
|
|
+ }else{
|
|
|
+ showWarningToast(bean.msg);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ XLog.e("添加理货数据结果返回错误",e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * 校验必录
|
|
|
+ */
|
|
|
+ private boolean validate(){
|
|
|
+ photoList = pictureSelectorUpload.getPhotoList();
|
|
|
+
|
|
|
+ if (urlCode.isEmpty()){
|
|
|
+ showWarningToast("请选扫码");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ postParam = new JSONObject();
|
|
|
+
|
|
|
+ if (photoList.size()==0){
|
|
|
+ showWarningToast("请拍照上传");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ Gson gson = new Gson();
|
|
|
+ postParam.put("label_img",gson.toJson(photoList));
|
|
|
+ postParam.put("url_code",urlCode);
|
|
|
+
|
|
|
+ } catch (JSONException e) {
|
|
|
+ showWarningToast("系统异常"+e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @OnClick({R.id.btn_confirm})
|
|
|
+ public void onViewClicked(View view) {
|
|
|
+ Bundle bundle = new Bundle();
|
|
|
+ switch (view.getId()) {
|
|
|
+
|
|
|
+ case R.id.btn_confirm:
|
|
|
+ if (urlCode.isEmpty() || (pictureSelectorUpload!=null && pictureSelectorUpload.getPhotoList().size()==0) ){
|
|
|
+ ActivityScanerCode.setScanerListener(mScanerListener);
|
|
|
+ ActivityScanerCode.intent2Activity(mContext, BaseConfig.COMMON_SCANNER_ONLY);
|
|
|
+ }else{
|
|
|
+ new AlertDialog.Builder(mContext)
|
|
|
+ .setTitle(R.string.dl_hint)
|
|
|
+ .setMessage("还拍照数据未上传,需要重新上传吗?")
|
|
|
+ .setNegativeButton(R.string.str_cancel, new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
+
|
|
|
+ dialogInterface.dismiss();
|
|
|
+
|
|
|
+ }
|
|
|
+ }).setPositiveButton(R.string.str_submit, new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
+
|
|
|
+ pictureInbound();
|
|
|
+
|
|
|
+ }
|
|
|
+ }).show();
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onDestroy() {
|
|
|
+ unbinder.unbind();
|
|
|
+ pictureSelectorUpload.removeHandler();
|
|
|
+ super.onDestroy();
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ protected void onResume() {
|
|
|
+ super.onResume();
|
|
|
+ initReceiver();
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ protected void onPause() {
|
|
|
+ super.onPause();
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ Integer is_broadcast = scanBean.getIsBroadcast();
|
|
|
+ if (is_broadcast==0){
|
|
|
+ StoTongJNI.getIns(mContext).SetScannerStop();
|
|
|
+ StoTongJNI.getIns(mContext).SetScannerOff();
|
|
|
+ }else{
|
|
|
+ unregisterReceiver(mReceiver);
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ XLog.e("销毁广播失败:",e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|