TrayMakeFourMainActivity.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  1. package com.fxy.detection;
  2. import android.annotation.SuppressLint;
  3. import android.app.AlertDialog;
  4. import android.content.BroadcastReceiver;
  5. import android.content.Context;
  6. import android.content.DialogInterface;
  7. import android.content.Intent;
  8. import android.content.IntentFilter;
  9. import android.os.Bundle;
  10. import android.os.Handler;
  11. import android.os.Looper;
  12. import android.os.Message;
  13. import android.support.v7.widget.LinearLayoutManager;
  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.ViewGroup;
  20. import android.view.inputmethod.EditorInfo;
  21. import android.widget.EditText;
  22. import android.widget.ImageButton;
  23. import android.widget.LinearLayout;
  24. import android.widget.TextView;
  25. import com.chad.library.adapter.base.BaseQuickAdapter;
  26. import com.chad.library.adapter.base.BaseViewHolder;
  27. import com.elvishew.xlog.XLog;
  28. import com.fxy.R;
  29. import com.fxy.baselibrary.base.BaseActivity;
  30. import com.fxy.baselibrary.bean.BaseEventBusBean;
  31. import com.fxy.baselibrary.interfaces.OnRxScanerListener;
  32. import com.fxy.baselibrary.util.JsonUtil;
  33. import com.fxy.baselibrary.views.MarqueeTextView;
  34. import com.fxy.bean.ActionBean;
  35. import com.fxy.bean.ScanBean;
  36. import com.fxy.common.AsyncPictureSelector;
  37. import com.fxy.common.AsyncPictureUpload;
  38. import com.fxy.constant.BaseConfig;
  39. import com.fxy.constant.EventCode;
  40. import com.fxy.constant.SPCache;
  41. import com.fxy.detection.bean.StorageRecordBean;
  42. import com.fxy.detection.bean.TakePictureBean;
  43. import com.fxy.detection.bean.TrackingBoxBean;
  44. import com.fxy.detection.bean.TrayMakeBean;
  45. import com.fxy.net.MyDialogCallback;
  46. import com.fxy.net.Urls;
  47. import com.google.gson.Gson;
  48. import com.google.zxing.Result;
  49. import com.luck.picture.lib.config.PictureConfig;
  50. import com.lzy.okgo.OkGo;
  51. import com.lzy.okgo.model.Response;
  52. import org.json.JSONException;
  53. import org.json.JSONObject;
  54. import java.util.ArrayList;
  55. import java.util.HashMap;
  56. import java.util.List;
  57. import java.util.Map;
  58. import butterknife.BindView;
  59. import butterknife.ButterKnife;
  60. import butterknife.OnClick;
  61. import butterknife.Unbinder;
  62. import sto.android.app.StoJNI;
  63. import sto.android.app.StoPdaKeyEvent;
  64. import sto.android.app.StoTongJNI;
  65. public class TrayMakeFourMainActivity extends BaseActivity implements StoJNI.ScanCallBack{
  66. /**
  67. * 列表适配器
  68. */
  69. Context mContext = this;
  70. @BindView(R.id.et_unit_code)
  71. EditText etUnitCode;
  72. @BindView(R.id.ll_await_num)
  73. LinearLayout llAwaitNum;
  74. @BindView(R.id.tv_await_num)
  75. TextView tvAwaitNum;
  76. @BindView(R.id.ll_btn_confirm)
  77. LinearLayout llConfirm;
  78. @BindView(R.id.ll_unit_code)
  79. LinearLayout llUnitCode;
  80. @BindView(R.id.recyclerview)
  81. RecyclerView recyclerView;
  82. @BindView(R.id.mt_tracking_number)
  83. MarqueeTextView mtTrackingNumber;
  84. @BindView(R.id.mt_box_number)
  85. MarqueeTextView mtBoxNumber;
  86. @BindView(R.id.mt_operate_number)
  87. MarqueeTextView mtOperateNumber;
  88. @BindView(R.id.mt_contents_number)
  89. MarqueeTextView mtContentsNumber;
  90. @BindView(R.id.ll_box_number)
  91. LinearLayout llBoxNumber;
  92. @BindView(R.id.ll_contents_number)
  93. LinearLayout llContentsNumber;
  94. private TrayMakeBean trayMakeBean;
  95. private int abImgId;
  96. private HashMap<String, Object> postData = new HashMap<>();
  97. private AsyncPictureUpload asyncPictureUpload = new AsyncPictureUpload(this);
  98. private String currentPictureType= "";
  99. private boolean currentUploadStatus = false;
  100. private boolean isRequiredShow = false;
  101. //
  102. //扫码扫码动作
  103. private ScanBean scanBean;
  104. private Unbinder unbinder;
  105. private JSONObject postParam = new JSONObject();
  106. private int leisure = 10;
  107. private Handler workHandler;
  108. private Runnable idleRunnable;
  109. private View notDataView; //没有数据显示页
  110. private View errorView; //错误显示页
  111. private View emptyView; //空显示页
  112. /**
  113. * 列表适配器
  114. */
  115. private FinishWorkAdapter mAdapter;
  116. private List<StorageRecordBean> tallyDataList = new ArrayList<>() ;
  117. @Override
  118. public int getContentViewResId() {
  119. return R.layout.activity_fxy_detection_tray_make_four;
  120. }
  121. @Override
  122. public boolean showToolBar() {
  123. return true;
  124. }
  125. @Override
  126. public boolean openEventBus() {
  127. return true;
  128. }
  129. @Override
  130. protected void getBundleExtras(Bundle bundle) {
  131. //XLog.e("接收数据解析:",bundle);
  132. trayMakeBean = JsonUtil.jsonString2Bean(bundle.getString("data"),TrayMakeBean.class);
  133. abImgId = bundle.getInt("ab_img_id");
  134. }
  135. //finish的返回监听
  136. //这里的requestCode参数,就是上面设置的 1 ,当跳转的页面返回的时候,通过这个加以判断
  137. //resultCode ,这个参数是在跳转的页面里面规定的,它也是一个int类型的标志
  138. //第三个参数包含了返回的值
  139. //如果不需要所跳转的页面返回值,也就不需要这个方法了
  140. @Override
  141. public void onActivityResult(int requestCode, int resultCode, Intent data) {
  142. super.onActivityResult(requestCode, resultCode, data);
  143. }
  144. /**
  145. * EventBus接收信息的方法,开启后才会调用(非粘性事件)
  146. *
  147. * @param event BaseEventBusBean
  148. */
  149. @Override
  150. protected void EventBean(BaseEventBusBean event) {
  151. // XLog.e("----------接收返回--------------");
  152. // XLog.e("接收返回:"+event.getEventCode());
  153. assert event != null;
  154. switch (event.getEventCode()){
  155. case EventCode.picture_selector_lister:
  156. currentPictureType = event.getData().toString();
  157. break;
  158. case EventCode.file_upload_lister:
  159. totalAwaitNum();
  160. break;
  161. }
  162. }
  163. @Override
  164. public boolean isPlayMusic() {
  165. return true;
  166. }
  167. @Override
  168. protected void initView() {
  169. unbinder = ButterKnife.bind(this);
  170. setTitleName("托盘清点-内件码");
  171. initAdapter();
  172. setRequestResult();
  173. initEdit();
  174. totalAwaitNum();
  175. workHandler = new Handler(Looper.getMainLooper());
  176. // 定义空闲任务
  177. idleRunnable = new Runnable() {
  178. @Override
  179. public void run() {
  180. // 执行空闲后的操作
  181. operateStartUpload();
  182. }
  183. };
  184. SPCache spCache = SPCache.getInstance(this);
  185. leisure = spCache.getLeisure();
  186. // 初始化时设置计时器
  187. workHandler.postDelayed(idleRunnable, leisure * 60 * 1000);
  188. }
  189. private void setNewTiming(){
  190. try {
  191. // 取消之前的计时器
  192. workHandler.removeCallbacks(idleRunnable);
  193. // 重新计时
  194. workHandler.postDelayed(idleRunnable, leisure * 60 * 1000); // 2 分钟
  195. } catch (Exception e) {
  196. e.printStackTrace();
  197. }
  198. }
  199. /**
  200. * 设置多个上传文件
  201. * @param uploadType String
  202. * @param showImg RecyclerView
  203. */
  204. private AsyncPictureSelector setItemPicture(String uploadType,RecyclerView showImg,int num){
  205. String notifyUrl = Urls.getServiceAddress(this) + Urls.FXY_DETECTION_PUTIN;
  206. AsyncPictureSelector pictureUpload = new AsyncPictureSelector(TrayMakeFourMainActivity.this,showImg,"detection",uploadType,notifyUrl,false);
  207. pictureUpload.setUploadType(uploadType);
  208. pictureUpload.setCompress(true,100,100);
  209. pictureUpload.setOnlyCamera(true);
  210. pictureUpload.setMaxSelectNum(num);
  211. return pictureUpload;
  212. }
  213. @Override
  214. public boolean dispatchKeyEvent(KeyEvent event) {
  215. //XLog.e("event:"+event.getKeyCode());
  216. if ((event.getKeyCode()==KeyEvent.KEYCODE_DPAD_CENTER || event.getKeyCode()==KeyEvent.KEYCODE_ENTER ) && event.getAction() == KeyEvent.ACTION_DOWN){
  217. //按确定键
  218. }
  219. return super.dispatchKeyEvent(event);
  220. }
  221. public HashMap<String, Object> getNotifyParam(){
  222. postData.put("tracking_number",trayMakeBean.getTrackingNumber().trim());
  223. postData.put("box_number",trayMakeBean.getBoxNumber().trim());
  224. postData.put("unit_code",etUnitCode.getText().toString().trim());
  225. return postData;
  226. }
  227. private static class FinishWorkAdapter extends BaseQuickAdapter<StorageRecordBean, BaseViewHolder> {
  228. public FinishWorkAdapter(List<StorageRecordBean> data){
  229. super(R.layout.item_card_intercept, data);
  230. }
  231. @Override
  232. protected void convert(BaseViewHolder helper, StorageRecordBean item) {
  233. helper.addOnClickListener(R.id.tv_status);//定义setOnItemChildClickListener 事件点击
  234. try {
  235. helper.setText(R.id.tv_order_no,item.getUnitCode());
  236. helper.getView(R.id.tv_location).setVisibility(View.GONE);
  237. helper.getView(R.id.tv_status).setVisibility(View.GONE);
  238. } catch (Exception e) {
  239. XLog.e("列表赋值错误",e);
  240. e.printStackTrace();
  241. }
  242. }
  243. }
  244. private void initAdapter(){
  245. emptyView = this.getLayoutInflater().inflate(R.layout.pager_empty, (ViewGroup) recyclerView.getParent(), false);
  246. errorView = this.getLayoutInflater().inflate(R.layout.pager_error, (ViewGroup) recyclerView.getParent(), false);
  247. notDataView = emptyView;
  248. mAdapter = new FinishWorkAdapter(tallyDataList);
  249. mAdapter.setEmptyView(emptyView);
  250. mAdapter.openLoadAnimation(BaseQuickAdapter.SCALEIN);
  251. recyclerView.setLayoutManager(new LinearLayoutManager(this));
  252. recyclerView.setAdapter(mAdapter);
  253. }
  254. //监听按键
  255. public boolean onKeyDown(int keyCode, KeyEvent event) {
  256. XLog.e("监听按键:"+keyCode);XLog.e(event);
  257. if (scanBean.getIsBroadcast()==0 && StoTongJNI.getIns(mContext).getEventFuction(keyCode) == StoPdaKeyEvent.KEYCODE_SCAN
  258. && event.getRepeatCount() == 0) {
  259. if (StoTongJNI.getIns(mContext).GetScannerIsScanning()) {
  260. //
  261. } else {
  262. StoTongJNI.getIns(mContext).SetScannerStart();
  263. }
  264. }
  265. return super.onKeyDown(keyCode, event);
  266. }
  267. @SuppressLint("HandlerLeak")
  268. Handler scanHandler = new Handler() {
  269. @Override
  270. public void handleMessage(Message msg) {
  271. // TODO Auto-generated method stub
  272. if (msg.obj != null) {
  273. String scanResult = msg.obj.toString().trim();
  274. if (!scanResult.isEmpty()){
  275. setScanResult(scanResult);
  276. }
  277. }
  278. }
  279. };
  280. @Override
  281. public void onScanResults(String str) {
  282. Message msg = new Message();
  283. msg.obj = str;
  284. scanHandler.sendMessage(msg);
  285. }
  286. @Override
  287. public void onScanResults(String str, int type) {
  288. }
  289. /**
  290. * 定义广播接受
  291. */
  292. BroadcastReceiver mReceiver = new BroadcastReceiver() {
  293. @Override
  294. public void onReceive(Context context, Intent intent) {
  295. String scanResult = intent.getStringExtra(scanBean.getDataName());
  296. if (scanResult==null){return; }
  297. String scanStatus = "";
  298. if (!scanBean.getStatusName().isEmpty()){
  299. scanStatus = intent.getStringExtra(scanBean.getStatusName());
  300. }else{
  301. scanStatus = scanResult.isEmpty()? "" : "ok"; //有值 默认是扫码成功;
  302. }
  303. //新大陆(MT65,MT90) 需要手动关闭
  304. if (!scanBean.getActionStop().isEmpty()){
  305. Intent stopIntent = new Intent(scanBean.getActionStop());
  306. mContext.sendBroadcast(stopIntent);
  307. }
  308. if ("ok".equals(scanStatus)){
  309. setScanResult(scanResult);
  310. }else{
  311. showErrorToast(getString(R.string.scan_failed));
  312. }
  313. }
  314. };
  315. /**
  316. * 注册广播
  317. */
  318. private void initReceiver(){
  319. try {
  320. String scanStr = getScanSetting();
  321. scanBean = JsonUtil.getObject(scanStr, ScanBean.class);
  322. Integer is_broadcast = scanBean.getIsBroadcast();//是否广播
  323. if (is_broadcast ==1){
  324. IntentFilter mFilter = new IntentFilter(scanBean.getAction());
  325. this.registerReceiver(mReceiver, mFilter);
  326. }else{
  327. //不广播进行处理 jni模式
  328. String pdaBrand = StoTongJNI.getmPdaBrand();
  329. if (!pdaBrand.isEmpty()){
  330. StoTongJNI.getIns(this).setmScanCB(this);
  331. StoTongJNI.getIns(this).SetScannerOn();
  332. }
  333. }
  334. }catch (Exception e) {
  335. showErrorToast("获取扫码配置失败"+e.getMessage());
  336. XLog.e("获取扫码配置失败:" + e.getMessage());
  337. }
  338. }
  339. private void initEdit() {
  340. List<EditText> list = new ArrayList<>();
  341. list.add(etUnitCode);
  342. unifyEdit(list);
  343. }
  344. //getAwaitNum
  345. private void totalAwaitNum(){
  346. int awaitNum = asyncPictureUpload.getAwaitNum();
  347. tvAwaitNum.setText(String.valueOf(awaitNum));
  348. if (awaitNum == 0){
  349. operateStopUpload();
  350. }
  351. }
  352. //统一按钮回调
  353. @SuppressLint("NonConstantResourceId")
  354. public void callbackEditor(View v){
  355. setNewTiming();
  356. switch (v.getId()) {
  357. case R.id.et_unit_code:
  358. checkUnitCode();
  359. break;
  360. default:
  361. }
  362. }
  363. /**
  364. * 统一设置Edit监听
  365. * @param list
  366. */
  367. public void unifyEdit(List<EditText> list){
  368. for (int i=0;i<list.size();i++){
  369. EditText editText = list.get(i);
  370. LinearLayout linearLayout = (LinearLayout)editText.getParent();
  371. ImageButton imageButton = getChildImageButton(linearLayout);
  372. //监听按确定
  373. editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
  374. @Override
  375. public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
  376. //XLog.e("actionId:"+actionId);
  377. if (actionId == EditorInfo.IME_ACTION_SEND || actionId == EditorInfo.IME_ACTION_DONE ) {
  378. if (v.getText().toString().trim().isEmpty()) {
  379. setEditTextFocused(v,true);
  380. showWarningToast(v.getHint().toString());
  381. return false;
  382. }else{
  383. setEditTextNormal(v,true);
  384. }
  385. callbackEditor(v);
  386. return false;
  387. }
  388. return false;
  389. }
  390. });
  391. editText.addTextChangedListener(new TextWatcher() {
  392. public void onTextChanged(CharSequence s, int start, int before, int count) {
  393. EditText currentEditText = null;
  394. ImageButton currentImage = null;
  395. //获取焦点的view对象
  396. View view=getWindow().getDecorView().findFocus();
  397. //如果是EditText
  398. if(view instanceof EditText){
  399. currentEditText = (EditText) view;
  400. currentImage = getChildImageButton((LinearLayout)currentEditText.getParent());
  401. }
  402. if (s.length() > 0 ) {
  403. if (currentImage !=null ){
  404. currentImage.setVisibility(View.VISIBLE);
  405. }
  406. if (currentEditText!=null){
  407. setEditTextNormal(currentEditText,true);
  408. }
  409. } else {
  410. if (currentImage !=null ){
  411. currentImage.setVisibility(View.INVISIBLE);
  412. }
  413. if (currentEditText!=null && isRequiredShow){
  414. setEditTextFocused(currentEditText,true);
  415. }
  416. }
  417. }
  418. public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  419. }
  420. public void afterTextChanged(Editable s) {
  421. }
  422. });
  423. if (imageButton !=null ){
  424. unifyClearEdit(imageButton);
  425. }
  426. }
  427. }
  428. private OnRxScanerListener mScanerListener = new OnRxScanerListener() {
  429. @Override
  430. public void onSuccess(String type, Result result) {
  431. String scanResult = result.getText();
  432. switch (type){
  433. case BaseConfig.COMMON_SCANNER_ONLY:
  434. setScanResult(scanResult);
  435. break;
  436. }
  437. }
  438. @Override
  439. public void onFail(String type, String message) {
  440. }
  441. };
  442. //把扫描结果赋值
  443. private void setScanResult(String scanResult){
  444. //获取焦点的view对象
  445. View view=getWindow().getDecorView().findFocus();
  446. //如果是EditText
  447. if(view instanceof EditText)
  448. {
  449. ((EditText) view).setText(scanResult);
  450. showSuccessToast("扫描成功");
  451. callbackEditor(view);
  452. }
  453. }
  454. //检查是否存在上传
  455. private void checkIsUpload(){
  456. int awaitNum = asyncPictureUpload.getAwaitNum();
  457. if (currentUploadStatus && awaitNum>0){
  458. operateStartUpload();
  459. }
  460. }
  461. //设置返回
  462. private void setRequestResult(){
  463. tallyDataList.clear();
  464. tallyDataList = trayMakeBean.getZuijinNums();
  465. mtOperateNumber.setText(String.valueOf(trayMakeBean.getHasDoDui()));
  466. mtTrackingNumber.setText(trayMakeBean.getTrackingNumber());
  467. mtContentsNumber.setText(String.valueOf(trayMakeBean.getBenBoxQty()));
  468. mtBoxNumber.setText(trayMakeBean.getBoxNumber());
  469. llBoxNumber.setVisibility(View.VISIBLE);
  470. llContentsNumber.setVisibility(View.VISIBLE);
  471. mAdapter.setNewData(tallyDataList);
  472. mAdapter.notifyDataSetChanged();
  473. }
  474. private void checkUnitCode(){
  475. checkIsUpload();
  476. if (etUnitCode.getText().toString().isEmpty()){
  477. showErrorToast(etUnitCode.getHint().toString());
  478. return;
  479. }
  480. Gson gson = new Gson();
  481. Map<String,Object> math = new HashMap<>();
  482. math.put("tracking_number",trayMakeBean.getTrackingNumber().trim());
  483. math.put("box_number",trayMakeBean.getBoxNumber().trim());
  484. math.put("unit_code",etUnitCode.getText().toString().trim());
  485. math.put("is_check",1);
  486. math.put("ab_img_id",abImgId);
  487. OkGo.<String>post(Urls.getServiceAddress(this) + Urls.FXY_DETECTION_PALLET_BOX_UNIT).upJson(gson.toJson(math))
  488. .execute(new MyDialogCallback(this, true, false) {
  489. @Override
  490. public void onSuccess(Response<String> response) {
  491. super.onSuccess(response);
  492. try {
  493. ActionBean bean = JsonUtil.getObject(response.body(), ActionBean.class);
  494. trayMakeBean = new TrayMakeBean();
  495. if (bean.data!=null && !bean.data.isEmpty() && !bean.data.equals("[]")){
  496. trayMakeBean = JsonUtil.jsonString2Bean(bean.data,TrayMakeBean.class);
  497. setRequestResult();
  498. }
  499. String voiceName = trayMakeBean.getVoiceName();
  500. if(bean.code == 1){
  501. showSuccessToast(bean.msg,voiceName);
  502. initFinish();
  503. }else{
  504. showWarningToast(bean.msg,voiceName);
  505. }
  506. }catch (Exception e) {
  507. e.printStackTrace();
  508. XLog.e("第二步确认错误",e.getMessage());
  509. }
  510. }
  511. });
  512. }
  513. //提交内件码
  514. private void finishInbound(){
  515. isRequiredShow = true;
  516. if (!validate()){
  517. return;
  518. }
  519. OkGo.<String>post(Urls.getServiceAddress(this) + Urls.FXY_DETECTION_PUTIN).upJson(postParam)
  520. .execute(new MyDialogCallback(this, true, false) {
  521. @Override
  522. public void onSuccess(Response<String> response) {
  523. super.onSuccess(response);
  524. try {
  525. ActionBean bean = JsonUtil.getObject(response.body(), ActionBean.class);
  526. if(bean.code == 1){
  527. showSuccessToast(bean.msg);
  528. if (bean.data!=null && !bean.data.isEmpty() && !bean.data.equals("[]")){
  529. trayMakeBean = JsonUtil.jsonString2Bean(bean.data,TrayMakeBean.class);
  530. setRequestResult();
  531. }
  532. initFinish();
  533. }else{
  534. showWarningToast(bean.msg);
  535. }
  536. } catch (Exception e) {
  537. e.printStackTrace();
  538. XLog.e("添加开箱拆柜数据结果返回错误",e.getMessage());
  539. }
  540. }
  541. });
  542. }
  543. private void initFinish(){
  544. etUnitCode.setText("");
  545. etUnitCode.requestFocus();
  546. llConfirm.setVisibility(View.VISIBLE);
  547. }
  548. /*
  549. * 校验必录
  550. */
  551. private boolean validate(){
  552. if (etUnitCode.getText().toString().isEmpty()){
  553. showWarningToast(etUnitCode.getHint().toString());
  554. return false;
  555. }
  556. try {
  557. postParam = new JSONObject();
  558. Gson gson = new Gson();
  559. postParam.put("box_number",trayMakeBean.getBoxNumber().trim());
  560. postParam.put("tracking_number",trayMakeBean.getTrackingNumber().trim());
  561. postParam.put("unit_code",etUnitCode.getText().toString().trim());
  562. postParam.put("is_check",1);
  563. postParam.put("ab_img_id",abImgId);
  564. } catch (JSONException e) {
  565. showWarningToast("系统异常"+e.getMessage());
  566. e.printStackTrace();
  567. return false;
  568. }
  569. return true;
  570. }
  571. //sIsGoodinfoMatch,sIsBattery,sIsMagnetic,sIsWood,sIsExtra,sIsOther
  572. @SuppressLint("NonConstantResourceId")
  573. @OnClick({R.id.btn_confirm})
  574. public void onViewClicked(View view) {
  575. Bundle bundle = new Bundle();
  576. switch (view.getId()) {
  577. case R.id.btn_confirm:
  578. Intent intent = new Intent();
  579. setResult(200, intent);//返回值,2 是改返回的标志,也会返回
  580. showSuccessToast("success");
  581. intent.putExtra("data",(new Gson()).toJson(trayMakeBean));
  582. finish();
  583. break;
  584. default:
  585. break;
  586. }
  587. }
  588. private void operateStopUpload(){
  589. if (currentUploadStatus){
  590. asyncPictureUpload.setStopUpload();
  591. }
  592. }
  593. private void operateStartUpload(){
  594. if (!currentUploadStatus){
  595. asyncPictureUpload.setStartUpload();
  596. }
  597. }
  598. @Override
  599. protected void onDestroy() {
  600. unbinder.unbind();
  601. asyncPictureUpload.removeHandler();
  602. // 确保清除所有的回调以防止内存泄漏
  603. workHandler.removeCallbacks(idleRunnable);
  604. super.onDestroy();
  605. }
  606. @Override
  607. protected void onResume() {
  608. super.onResume();
  609. initReceiver();
  610. }
  611. @Override
  612. protected void onPause() {
  613. super.onPause();
  614. //销毁在onResume()方法中的广播
  615. try {
  616. //停止扫描
  617. Integer is_broadcast = scanBean.getIsBroadcast();//是否广播
  618. if (is_broadcast==0){
  619. StoTongJNI.getIns(mContext).SetScannerStop();
  620. StoTongJNI.getIns(mContext).SetScannerOff();
  621. }else{
  622. unregisterReceiver(mReceiver);
  623. }
  624. }catch (Exception e){
  625. XLog.e("销毁广播失败:",e.getMessage());
  626. }
  627. }
  628. }