BoxPutInMainActivity.java 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996
  1. package com.fxy.detection;
  2. import android.annotation.SuppressLint;
  3. import android.app.AlertDialog;
  4. import android.app.Dialog;
  5. import android.content.BroadcastReceiver;
  6. import android.content.Context;
  7. import android.content.DialogInterface;
  8. import android.content.Intent;
  9. import android.content.IntentFilter;
  10. import android.os.Bundle;
  11. import android.os.Handler;
  12. import android.os.Looper;
  13. import android.os.Message;
  14. import android.support.v7.widget.RecyclerView;
  15. import android.text.Editable;
  16. import android.text.TextWatcher;
  17. import android.view.KeyEvent;
  18. import android.view.View;
  19. import android.view.inputmethod.EditorInfo;
  20. import android.widget.EditText;
  21. import android.widget.ImageButton;
  22. import android.widget.LinearLayout;
  23. import android.widget.ProgressBar;
  24. import android.widget.Switch;
  25. import android.widget.TextView;
  26. import com.elvishew.xlog.XLog;
  27. import com.fxy.R;
  28. import com.fxy.baselibrary.base.BaseActivity;
  29. import com.fxy.baselibrary.bean.BaseEventBusBean;
  30. import com.fxy.baselibrary.interfaces.OnRxScanerListener;
  31. import com.fxy.baselibrary.util.JsonUtil;
  32. import com.fxy.baselibrary.views.MarqueeTextView;
  33. import com.fxy.bean.ActionBean;
  34. import com.fxy.bean.ScanBean;
  35. import com.fxy.common.AsyncPictureSelector;
  36. import com.fxy.common.AsyncPictureUpload;
  37. import com.fxy.common.CommonDialog;
  38. import com.fxy.constant.BaseConfig;
  39. import com.fxy.constant.EventCode;
  40. import com.fxy.detection.bean.TakePictureBean;
  41. import com.fxy.detection.bean.TrackingBoxBean;
  42. import com.fxy.detection.bean.TrayMakeBean;
  43. import com.fxy.net.MyDialogCallback;
  44. import com.fxy.net.Urls;
  45. import com.fxy.utils.UploadUtils;
  46. import com.google.gson.Gson;
  47. import com.google.zxing.Result;
  48. import com.luck.picture.lib.config.PictureConfig;
  49. import com.lzy.okgo.OkGo;
  50. import com.lzy.okgo.model.Response;
  51. import java.util.ArrayList;
  52. import java.util.HashMap;
  53. import java.util.List;
  54. import java.util.Map;
  55. import butterknife.BindView;
  56. import butterknife.ButterKnife;
  57. import butterknife.OnClick;
  58. import butterknife.Unbinder;
  59. import sto.android.app.StoJNI;
  60. import sto.android.app.StoPdaKeyEvent;
  61. import sto.android.app.StoTongJNI;
  62. public class BoxPutInMainActivity extends BaseActivity implements StoJNI.ScanCallBack{
  63. /**
  64. * 列表适配器
  65. */
  66. Context mContext = this;
  67. @BindView(R.id.et_order_number)
  68. EditText etOrderNumber;
  69. @BindView(R.id.et_tracking_number)
  70. EditText etTrackingNumber;
  71. @BindView(R.id.ll_await_num)
  72. LinearLayout llAwaitNum;
  73. @BindView(R.id.ll_extend_info)
  74. LinearLayout llExtendInfo;
  75. @BindView(R.id.tv_await_num)
  76. TextView tvAwaitNum;
  77. @BindView(R.id.mt_customer_code)
  78. MarqueeTextView mtCustomerCode;
  79. @BindView(R.id.ll_label_picture)
  80. LinearLayout llLabelPicture;
  81. @BindView(R.id.ll_order_number)
  82. LinearLayout llOrderNumber;
  83. private HashMap<String, Object> postData = new HashMap<>();
  84. private TrackingBoxBean trackingBoxBean;
  85. private TrackingBoxBean customerTrackingBoxBean;
  86. //
  87. //扫码扫码动作
  88. private ScanBean scanBean;
  89. private boolean showWeightImg = false;
  90. private boolean isRequiredShow = false;
  91. private ArrayList<String> baseImgList = new ArrayList<>();
  92. protected String action;
  93. private HashMap<String, AsyncPictureSelector> mapPictureSelector = new HashMap<>();
  94. private List<TakePictureBean> takePictureBeanList = new ArrayList<>();
  95. private AsyncPictureUpload asyncPictureUpload = new AsyncPictureUpload(this);
  96. private String currentPictureType= "label_img";
  97. private Unbinder unbinder;
  98. private CommonDialog commonDialog;
  99. //是否需要显示客户
  100. private boolean needCustomer;
  101. //客户名称
  102. private String customerCode="";
  103. @Override
  104. public int getContentViewResId() {
  105. return R.layout.activity_fxy_detection_box_putin;
  106. }
  107. @Override
  108. public boolean showToolBar() {
  109. return true;
  110. }
  111. @Override
  112. public boolean openEventBus() {
  113. return true;
  114. }
  115. @Override
  116. protected void getBundleExtras(Bundle bundle) {
  117. //XLog.e("接收数据解析:",bundle);
  118. }
  119. //finish的返回监听
  120. //这里的requestCode参数,就是上面设置的 1 ,当跳转的页面返回的时候,通过这个加以判断
  121. //resultCode ,这个参数是在跳转的页面里面规定的,它也是一个int类型的标志
  122. //第三个参数包含了返回的值
  123. //如果不需要所跳转的页面返回值,也就不需要这个方法了
  124. @Override
  125. public void onActivityResult(int requestCode, int resultCode, Intent data) {
  126. super.onActivityResult(requestCode, resultCode, data);
  127. if (resultCode == RESULT_OK) {
  128. // 图片选择结果回调
  129. if (requestCode == PictureConfig.CHOOSE_REQUEST) {
  130. if (mapPictureSelector.containsKey(currentPictureType)){
  131. mapPictureSelector.get(currentPictureType).getSelectImg(data);
  132. }
  133. totalAwaitNum();
  134. if (mapPictureSelector.get("label_img").getOssPhotoList().size()>0){
  135. //页面跳转
  136. submitLabelImg();
  137. }
  138. }
  139. }
  140. if (requestCode == 200 && resultCode == 200)//之前提到的两个标志,在这里显示出了作用
  141. {
  142. initFinish();
  143. }
  144. }
  145. /**
  146. * EventBus接收信息的方法,开启后才会调用(非粘性事件)
  147. *
  148. * @param event
  149. */
  150. @Override
  151. protected void EventBean(BaseEventBusBean event) {
  152. // XLog.e("----------接收返回--------------");
  153. // XLog.e("接收返回:"+event.getEventCode());
  154. assert event != null;
  155. switch (event.getEventCode()){
  156. case EventCode.file_upload_lister:
  157. totalAwaitNum();
  158. break;
  159. }
  160. }
  161. @Override
  162. public boolean isPlayMusic() {
  163. return true;
  164. }
  165. @Override
  166. protected void initView() {
  167. unbinder = ButterKnife.bind(this);
  168. setTitleName("单箱入库");
  169. initEdit();
  170. iniData();
  171. RecyclerView rvLabelShowImg = (RecyclerView)llLabelPicture.findViewById(R.id.rv_show_img);
  172. mapPictureSelector.put("label_img",setItemPicture("label_img",rvLabelShowImg,1));
  173. initDialog();
  174. totalAwaitNum();
  175. }
  176. /**
  177. * 设置多个上传文件
  178. * @param uploadType String
  179. * @param showImg RecyclerView
  180. */
  181. private AsyncPictureSelector setItemPicture(String uploadType,RecyclerView showImg,int num){
  182. String notifyUrl = Urls.getServiceAddress(this) + Urls.FXY_DETECTION_PUTIN;
  183. AsyncPictureSelector pictureUpload = new AsyncPictureSelector(BoxPutInMainActivity.this,showImg,"detection",uploadType,notifyUrl,false);
  184. pictureUpload.setUploadType(uploadType);
  185. pictureUpload.setCompress(true,100,100);
  186. pictureUpload.setOnlyCamera(true);
  187. pictureUpload.setMaxSelectNum(num);
  188. return pictureUpload;
  189. }
  190. private void initDialog(){
  191. commonDialog = new CommonDialog(mContext, R.style.dialog, "need_customer", new CommonDialog.OnCloseListener() {
  192. @Override
  193. public void onClickCancel(Dialog dialog, boolean confirm) {
  194. customerCode = "" ;
  195. dialog.dismiss();
  196. }
  197. @Override
  198. public void onClickSubmit(Dialog dialog, boolean confirm) {
  199. String string = commonDialog.contentTxt.getText().toString().trim();
  200. if (commonDialog.getTypeCode().equals("need_customer")){
  201. customerCode = string;
  202. }
  203. mtCustomerCode.setText(customerCode);
  204. getCustomer();
  205. // if (etOrderNumber.getText().toString().isEmpty()){
  206. // etOrderNumber.requestFocus();
  207. // }else{
  208. // getBoxNumber();
  209. // }
  210. }
  211. });
  212. commonDialog.setContentLabel("QC");
  213. }
  214. @Override
  215. public boolean dispatchKeyEvent(KeyEvent event) {
  216. //XLog.e("event:"+event.getKeyCode());
  217. if ((event.getKeyCode()==KeyEvent.KEYCODE_DPAD_CENTER || event.getKeyCode()==KeyEvent.KEYCODE_ENTER ) && event.getAction() == KeyEvent.ACTION_DOWN){
  218. //按确定键
  219. }
  220. return super.dispatchKeyEvent(event);
  221. }
  222. //监听按键
  223. public boolean onKeyDown(int keyCode, KeyEvent event) {
  224. XLog.e("监听按键:"+keyCode);XLog.e(event);
  225. if (scanBean.getIsBroadcast()==0 && StoTongJNI.getIns(mContext).getEventFuction(keyCode) == StoPdaKeyEvent.KEYCODE_SCAN
  226. && event.getRepeatCount() == 0) {
  227. if (StoTongJNI.getIns(mContext).GetScannerIsScanning()) {
  228. //
  229. } else {
  230. StoTongJNI.getIns(mContext).SetScannerStart();
  231. }
  232. }
  233. return super.onKeyDown(keyCode, event);
  234. }
  235. @SuppressLint("HandlerLeak")
  236. Handler scanHandler = new Handler() {
  237. @Override
  238. public void handleMessage(Message msg) {
  239. // TODO Auto-generated method stub
  240. if (msg.obj != null) {
  241. String scanResult = msg.obj.toString().trim();
  242. if (!scanResult.isEmpty()){
  243. setScanResult(scanResult);
  244. }
  245. }
  246. }
  247. };
  248. @Override
  249. public void onScanResults(String str) {
  250. Message msg = new Message();
  251. msg.obj = str;
  252. scanHandler.sendMessage(msg);
  253. }
  254. @Override
  255. public void onScanResults(String str, int type) {
  256. }
  257. /**
  258. * 定义广播接受
  259. */
  260. BroadcastReceiver mReceiver = new BroadcastReceiver() {
  261. @Override
  262. public void onReceive(Context context, Intent intent) {
  263. String scanResult = intent.getStringExtra(scanBean.getDataName());
  264. if (scanResult==null){return; }
  265. String scanStatus = "";
  266. if (!scanBean.getStatusName().isEmpty()){
  267. scanStatus = intent.getStringExtra(scanBean.getStatusName());
  268. }else{
  269. scanStatus = scanResult.isEmpty()? "" : "ok"; //有值 默认是扫码成功;
  270. }
  271. //新大陆(MT65,MT90) 需要手动关闭
  272. if (!scanBean.getActionStop().isEmpty()){
  273. Intent stopIntent = new Intent(scanBean.getActionStop());
  274. mContext.sendBroadcast(stopIntent);
  275. }
  276. if ("ok".equals(scanStatus)){
  277. setScanResult(scanResult);
  278. }else{
  279. showErrorToast(getString(R.string.scan_failed));
  280. }
  281. }
  282. };
  283. /**
  284. * 注册广播
  285. */
  286. private void initReceiver(){
  287. try {
  288. String scanStr = getScanSetting();
  289. scanBean = JsonUtil.getObject(scanStr, ScanBean.class);
  290. Integer is_broadcast = scanBean.getIsBroadcast();//是否广播
  291. if (is_broadcast ==1){
  292. IntentFilter mFilter = new IntentFilter(scanBean.getAction());
  293. this.registerReceiver(mReceiver, mFilter);
  294. }else{
  295. //不广播进行处理 jni模式
  296. String pdaBrand = StoTongJNI.getmPdaBrand();
  297. if (!pdaBrand.isEmpty()){
  298. StoTongJNI.getIns(this).setmScanCB(this);
  299. StoTongJNI.getIns(this).SetScannerOn();
  300. }
  301. }
  302. }catch (Exception e) {
  303. showErrorToast("获取扫码配置失败"+e.getMessage());
  304. XLog.e("获取扫码配置失败:" + e.getMessage());
  305. }
  306. }
  307. private void initEdit() {
  308. List<EditText> list = new ArrayList<>();
  309. list.add(etTrackingNumber);
  310. list.add(etOrderNumber);
  311. unifyEdit(list);
  312. }
  313. private void iniData(){
  314. baseImgList.add("label_img");
  315. baseImgList.add("weight_img");
  316. }
  317. //getAwaitNum
  318. private void totalAwaitNum(){
  319. String[] uploadTypeList = {getClass().getSimpleName(),"BoxPutInDetailsMainActivity"};
  320. int awaitNum = UploadUtils.getAwaitNum(mRealm,uploadTypeList);
  321. tvAwaitNum.setText(String.valueOf(awaitNum));
  322. }
  323. //统一按钮回调
  324. @SuppressLint("NonConstantResourceId")
  325. public void callbackEditor(View v){
  326. switch (v.getId()) {
  327. case R.id.et_tracking_number:
  328. getTrackingNumber();
  329. break;
  330. case R.id.et_order_number:
  331. if (etTrackingNumber.getText().toString().isEmpty()){
  332. etTrackingNumber.requestFocus();
  333. return;
  334. }
  335. if (etOrderNumber.getText().toString().isEmpty()){
  336. etOrderNumber.requestFocus();
  337. return;
  338. }
  339. getBoxNumber();
  340. break;
  341. default:
  342. }
  343. }
  344. /**
  345. * 统一设置Edit监听
  346. * @param list
  347. */
  348. public void unifyEdit(List<EditText> list){
  349. for (int i=0;i<list.size();i++){
  350. EditText editText = list.get(i);
  351. LinearLayout linearLayout = (LinearLayout)editText.getParent();
  352. ImageButton imageButton = getChildImageButton(linearLayout);
  353. //监听按确定
  354. editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
  355. @Override
  356. public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
  357. //XLog.e("actionId:"+actionId);
  358. if (actionId == EditorInfo.IME_ACTION_SEND || actionId == EditorInfo.IME_ACTION_DONE ) {
  359. if (v.getText().toString().trim().isEmpty()) {
  360. setEditTextFocused(v,true);
  361. showWarningToast(v.getHint().toString());
  362. return false;
  363. }else{
  364. setEditTextNormal(v,true);
  365. }
  366. callbackEditor(v);
  367. return false;
  368. }
  369. return false;
  370. }
  371. });
  372. editText.addTextChangedListener(new TextWatcher() {
  373. public void onTextChanged(CharSequence s, int start, int before, int count) {
  374. EditText currentEditText = null;
  375. ImageButton currentImage = null;
  376. //获取焦点的view对象
  377. View view=getWindow().getDecorView().findFocus();
  378. //如果是EditText
  379. if(view instanceof EditText){
  380. currentEditText = (EditText) view;
  381. currentImage = getChildImageButton((LinearLayout)currentEditText.getParent());
  382. }
  383. if (s.length() > 0 ) {
  384. if (currentImage !=null ){
  385. currentImage.setVisibility(View.VISIBLE);
  386. }
  387. if (currentEditText!=null){
  388. setEditTextNormal(currentEditText,true);
  389. }
  390. } else {
  391. if (currentImage !=null ){
  392. currentImage.setVisibility(View.INVISIBLE);
  393. }
  394. if (currentEditText!=null && isRequiredShow){
  395. setEditTextFocused(currentEditText,true);
  396. }
  397. }
  398. }
  399. public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  400. }
  401. public void afterTextChanged(Editable s) {
  402. }
  403. });
  404. if (imageButton !=null ){
  405. unifyClearEdit(imageButton);
  406. }
  407. }
  408. }
  409. private OnRxScanerListener mScanerListener = new OnRxScanerListener() {
  410. @Override
  411. public void onSuccess(String type, Result result) {
  412. String scanResult = result.getText();
  413. switch (type){
  414. case BaseConfig.COMMON_SCANNER_ONLY:
  415. setScanResult(scanResult);
  416. break;
  417. }
  418. }
  419. @Override
  420. public void onFail(String type, String message) {
  421. }
  422. };
  423. //把扫描结果赋值
  424. private void setScanResult(String scanResult){
  425. //获取焦点的view对象
  426. View view=getWindow().getDecorView().findFocus();
  427. //如果是EditText
  428. if(view instanceof EditText)
  429. {
  430. ((EditText) view).setText(scanResult);
  431. showSuccessToast("扫描成功");
  432. callbackEditor(view);
  433. }
  434. }
  435. //检查是否存在上传
  436. private void checkIsUpload(){
  437. }
  438. //获取跟踪单号
  439. private void getTrackingNumber(){
  440. checkIsUpload();
  441. if (etTrackingNumber.getText().toString().isEmpty()){
  442. showErrorToast(etTrackingNumber.getHint().toString());
  443. return;
  444. }
  445. Map<String,Object> math = new HashMap<>();
  446. math.put("tracking_number",etTrackingNumber.getText().toString().trim());
  447. String mathJson = (new Gson()).toJson(math);
  448. trackingBoxBean = null;
  449. OkGo.<String>post(Urls.getServiceAddress(this) + Urls.FXY_DETECTION_PUTIN_TRACK).upJson(mathJson)
  450. .execute(new MyDialogCallback(this, true, true) {
  451. @Override
  452. public void onSuccess(Response<String> response) {
  453. super.onSuccess(response);
  454. try {
  455. ActionBean bean = JsonUtil.getObject(response.body(), ActionBean.class);
  456. if (bean.data!=null && !bean.data.isEmpty() && !bean.data.equals("[]")){
  457. trackingBoxBean = JsonUtil.jsonString2Bean(bean.data,TrackingBoxBean.class);
  458. }
  459. if (!trackingBoxBean.getTrackingNumber().isEmpty()){
  460. etTrackingNumber.setText(trackingBoxBean.getTrackingNumber());
  461. }
  462. String voiceName = trackingBoxBean.getVoiceName();
  463. final Bundle bundle = new Bundle();
  464. bundle.putString("data",bean.data);
  465. bundle.putString("customer_code",customerCode);
  466. if (trackingBoxBean.getNeedConfirm().equals("Y")){
  467. new AlertDialog.Builder(mContext).setTitle(R.string.dl_hint)
  468. .setMessage(trackingBoxBean.getConfirmMsg())
  469. .setNegativeButton(R.string.str_cancel, new DialogInterface.OnClickListener() {
  470. @Override
  471. public void onClick(DialogInterface dialogInterface, int i) {
  472. dialogInterface.dismiss();
  473. }
  474. }).setPositiveButton(R.string.str_submit, new DialogInterface.OnClickListener() {
  475. @Override
  476. public void onClick(DialogInterface dialogInterface, int i) {
  477. // etOrderNumber.setEnabled(true);
  478. // etOrderNumber.requestFocus();
  479. intent2Page(BoxPutInMainActivity.this, BoxPutInDetailsMainActivity.class, false,bundle);
  480. }
  481. }).show();
  482. return;
  483. }
  484. needCustomer = trackingBoxBean.getNeedCustomer().equals("Y");
  485. if (needCustomer && !commonDialog.isShowing()){
  486. commonDialog.setTitle("客户编号","请输入客户编号").setContent(customerCode).show();
  487. }else{
  488. commonDialog.dismiss();
  489. }
  490. llExtendInfo.setVisibility(needCustomer ? View.VISIBLE:View.GONE);
  491. llOrderNumber.setVisibility(trackingBoxBean.getBusinessType().equals("1")?View.GONE:View.VISIBLE);
  492. if(bean.code == 1){
  493. showSuccessToast(bean.msg,voiceName);
  494. if (!needCustomer && trackingBoxBean.getBusinessType().equals("1")){
  495. mapPictureSelector.get(currentPictureType).authCamera();
  496. }else{
  497. etOrderNumber.setEnabled(true);
  498. etOrderNumber.requestFocus();
  499. }
  500. }else{
  501. showWarningToast(bean.msg,voiceName);
  502. }
  503. }catch (Exception e) {
  504. e.printStackTrace();
  505. XLog.e("确认错误",e.getMessage());
  506. }
  507. }
  508. });
  509. }
  510. //获取跟踪单号
  511. private void getCustomer(){
  512. checkIsUpload();
  513. if (etTrackingNumber.getText().toString().isEmpty()){
  514. showErrorToast(etTrackingNumber.getHint().toString());
  515. return;
  516. }
  517. Map<String,Object> math = new HashMap<>();
  518. math.put("tracking_number",etTrackingNumber.getText().toString().trim());
  519. math.put("customer_code",customerCode);
  520. math.put("is_customer_code",1);
  521. String mathJson = (new Gson()).toJson(math);
  522. customerTrackingBoxBean = null;
  523. OkGo.<String>post(Urls.getServiceAddress(this) + Urls.FXY_DETECTION_PUTIN_TRACK).upJson(mathJson)
  524. .execute(new MyDialogCallback(this, true, true) {
  525. @Override
  526. public void onSuccess(Response<String> response) {
  527. super.onSuccess(response);
  528. try {
  529. ActionBean bean = JsonUtil.getObject(response.body(), ActionBean.class);
  530. customerTrackingBoxBean = new TrackingBoxBean();
  531. if (bean.data!=null && !bean.data.isEmpty() && !bean.data.equals("[]")){
  532. customerTrackingBoxBean = JsonUtil.jsonString2Bean(bean.data,TrackingBoxBean.class);
  533. }
  534. String voiceName = customerTrackingBoxBean.getVoiceName();
  535. final Bundle bundle = new Bundle();
  536. bundle.putString("data",(new Gson()).toJson(trackingBoxBean));
  537. bundle.putString("customer_code",customerCode);
  538. if (customerTrackingBoxBean.getNeedConfirm().equals("Y")){
  539. new AlertDialog.Builder(mContext).setTitle(R.string.dl_hint)
  540. .setMessage(customerTrackingBoxBean.getConfirmMsg())
  541. .setNegativeButton(R.string.str_cancel, new DialogInterface.OnClickListener() {
  542. @Override
  543. public void onClick(DialogInterface dialogInterface, int i) {
  544. dialogInterface.dismiss();
  545. }
  546. }).setPositiveButton(R.string.str_submit, new DialogInterface.OnClickListener() {
  547. @Override
  548. public void onClick(DialogInterface dialogInterface, int i) {
  549. // etOrderNumber.setEnabled(true);
  550. // etOrderNumber.requestFocus();
  551. intent2Page(BoxPutInMainActivity.this, BoxPutInDetailsMainActivity.class, false,bundle);
  552. }
  553. }).show();
  554. return;
  555. }
  556. llOrderNumber.setVisibility(customerTrackingBoxBean.getBusinessType().equals("1")?View.GONE:View.VISIBLE);
  557. if(bean.code == 1){
  558. commonDialog.dismiss();
  559. showSuccessToast(bean.msg,voiceName);
  560. if (customerTrackingBoxBean.getBusinessType().equals("1")){
  561. mapPictureSelector.get(currentPictureType).authCamera();
  562. }else{
  563. etOrderNumber.setEnabled(true);
  564. etOrderNumber.requestFocus();
  565. }
  566. }else{
  567. showWarningToast(bean.msg,voiceName);
  568. commonDialog.authSoftKeyboard();
  569. }
  570. }catch (Exception e) {
  571. e.printStackTrace();
  572. XLog.e("确认错误",e.getMessage());
  573. }
  574. }
  575. });
  576. }
  577. //获取跟踪单号
  578. private void getBoxNumber(){
  579. checkIsUpload();
  580. if (etTrackingNumber.getText().toString().isEmpty()){
  581. showErrorToast(etTrackingNumber.getHint().toString());
  582. return;
  583. }
  584. if (etOrderNumber.getText().toString().isEmpty()){
  585. showErrorToast(etOrderNumber.getHint().toString());
  586. return;
  587. }
  588. Map<String,Object> math = new HashMap<>();
  589. math.put("tracking_number",etTrackingNumber.getText().toString().trim());
  590. math.put("box_number",etOrderNumber.getText().toString().trim());
  591. if (needCustomer){
  592. if (customerCode.isEmpty()){
  593. showErrorToast("请输入客户代码");
  594. return;
  595. }
  596. math.put("is_customer_code","1");
  597. math.put("customer_code",customerCode);
  598. }
  599. String mathJson = (new Gson()).toJson(math);
  600. trackingBoxBean = null;
  601. customerTrackingBoxBean = null;
  602. OkGo.<String>post(Urls.getServiceAddress(this) + Urls.FXY_DETECTION_PUTIN_TRACK).upJson(mathJson)
  603. .execute(new MyDialogCallback(this, true, true) {
  604. @Override
  605. public void onSuccess(Response<String> response) {
  606. super.onSuccess(response);
  607. try {
  608. ActionBean bean = JsonUtil.getObject(response.body(), ActionBean.class);
  609. if (bean.data!=null && !bean.data.isEmpty() && !bean.data.equals("[]")){
  610. trackingBoxBean = JsonUtil.jsonString2Bean(bean.data,TrackingBoxBean.class);
  611. }
  612. String voiceName = trackingBoxBean.getVoiceName();
  613. if (trackingBoxBean.getNeedConfirm().equals("Y")){
  614. new AlertDialog.Builder(mContext).setTitle(R.string.dl_hint)
  615. .setMessage(trackingBoxBean.getConfirmMsg())
  616. .setNegativeButton(R.string.str_cancel, new DialogInterface.OnClickListener() {
  617. @Override
  618. public void onClick(DialogInterface dialogInterface, int i) {
  619. dialogInterface.dismiss();
  620. }
  621. }).setPositiveButton(R.string.str_submit, new DialogInterface.OnClickListener() {
  622. @Override
  623. public void onClick(DialogInterface dialogInterface, int i) {
  624. if (mapPictureSelector.get(currentPictureType).getOssPhotoList().size()>0){
  625. submitLabelImg();
  626. }else{
  627. mapPictureSelector.get(currentPictureType).authCamera();
  628. }
  629. }
  630. }).show();
  631. }else{
  632. if(bean.code == 1){
  633. showSuccessToast(bean.msg,voiceName);
  634. if (mapPictureSelector.get(currentPictureType).getOssPhotoList().size()>0){
  635. submitLabelImg();
  636. }else{
  637. mapPictureSelector.get(currentPictureType).authCamera();
  638. }
  639. }else{
  640. showWarningToast(bean.msg,voiceName);
  641. }
  642. }
  643. }catch (Exception e) {
  644. e.printStackTrace();
  645. XLog.e("确认错误",e.getMessage());
  646. }
  647. }
  648. });
  649. }
  650. //提交面单信息
  651. private void submitLabelImg(){
  652. checkIsUpload();
  653. if (etTrackingNumber.getText().toString().isEmpty()){
  654. showErrorToast(etTrackingNumber.getHint().toString());
  655. return;
  656. }
  657. if (customerTrackingBoxBean != null){
  658. if (!customerTrackingBoxBean.getBusinessType().equals("1") && etOrderNumber.getText().toString().isEmpty()){
  659. //showErrorToast(etOrderNumber.getHint().toString());
  660. // return;
  661. }
  662. }else{
  663. if (etOrderNumber.getText().toString().isEmpty()){
  664. //showErrorToast(etOrderNumber.getHint().toString());
  665. //return;
  666. }
  667. }
  668. Gson gson = new Gson();
  669. Map<String,Object> math = new HashMap<>();
  670. math.put("tracking_number",trackingBoxBean.getTrackingNumber().trim());
  671. math.put("box_number",etOrderNumber.getText().toString().trim());
  672. if (needCustomer){
  673. if (customerCode.isEmpty()){
  674. showErrorToast("请输入客户代码");
  675. return;
  676. }
  677. math.put("is_customer_code","1");
  678. math.put("customer_code",customerCode);
  679. }
  680. //面单
  681. List<String> stringList = mapPictureSelector.get("label_img").getOssPhotoList();
  682. if (stringList.size()==0){
  683. showWarningToast("面单照片不能为空");
  684. return;
  685. }
  686. math.put("label_img_tag",mapPictureSelector.get("label_img").getUniqueTag());
  687. math.put("label_img",gson.toJson(stringList));
  688. OkGo.<String>post(Urls.getServiceAddress(this) + Urls.FXY_DETECTION_PUTIN).upJson(gson.toJson(math))
  689. .execute(new MyDialogCallback(this, true, false) {
  690. @Override
  691. public void onSuccess(Response<String> response) {
  692. super.onSuccess(response);
  693. try {
  694. ActionBean bean = JsonUtil.getObject(response.body(), ActionBean.class);
  695. if (bean.data!=null && !bean.data.isEmpty() && !bean.data.equals("[]")){
  696. trackingBoxBean = JsonUtil.jsonString2Bean(bean.data,TrackingBoxBean.class);
  697. }
  698. String voiceName = trackingBoxBean.getVoiceName();
  699. if(bean.code == 1){
  700. showSuccessToast(bean.msg,voiceName);
  701. Bundle bundle = new Bundle();
  702. bundle.putString("data",bean.data);
  703. bundle.putString("customer_code",customerCode);
  704. intentPageResult(BoxPutInMainActivity.this, BoxPutInDetailsMainActivity.class, bundle,200);
  705. }else{
  706. showWarningToast(bean.msg,voiceName);
  707. }
  708. }catch (Exception e) {
  709. e.printStackTrace();
  710. XLog.e("错误",e.getMessage());
  711. }
  712. }
  713. });
  714. }
  715. private void initFinish(){
  716. llExtendInfo.setVisibility(View.GONE);
  717. mtCustomerCode.setText("");
  718. customerCode = "";
  719. needCustomer = false;
  720. etOrderNumber.setText("");
  721. etOrderNumber.setEnabled(true);
  722. etTrackingNumber.setText("");
  723. etTrackingNumber.setEnabled(true);
  724. etTrackingNumber.requestFocus();
  725. for (int i=0;i<baseImgList.size();i++){
  726. if (mapPictureSelector.containsKey(baseImgList.get(i))){
  727. mapPictureSelector.get(baseImgList.get(i)).emptyRemake();
  728. }
  729. }
  730. }
  731. //sIsGoodinfoMatch,sIsBattery,sIsMagnetic,sIsWood,sIsExtra,sIsOther
  732. @OnClick({R.id.tv_edit_customer})
  733. public void onViewClicked(View view) {
  734. Bundle bundle = new Bundle();
  735. switch (view.getId()) {
  736. case R.id.tv_edit_customer:
  737. if (needCustomer){
  738. commonDialog.setTitle("客户编号","请输入客户编号").setContent(customerCode).show();
  739. }
  740. break;
  741. default:
  742. break;
  743. }
  744. }
  745. @Override
  746. protected void onDestroy() {
  747. unbinder.unbind();
  748. super.onDestroy();
  749. }
  750. @Override
  751. protected void onResume() {
  752. super.onResume();
  753. initReceiver();
  754. }
  755. @Override
  756. protected void onPause() {
  757. super.onPause();
  758. //销毁在onResume()方法中的广播
  759. try {
  760. //停止扫描
  761. Integer is_broadcast = scanBean.getIsBroadcast();//是否广播
  762. if (is_broadcast==0){
  763. StoTongJNI.getIns(mContext).SetScannerStop();
  764. StoTongJNI.getIns(mContext).SetScannerOff();
  765. }else{
  766. unregisterReceiver(mReceiver);
  767. }
  768. }catch (Exception e){
  769. XLog.e("销毁广播失败:",e.getMessage());
  770. }
  771. }
  772. }