TallyVolumeMainActivity.java 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978
  1. package com.fxy.fms.putIn;
  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.Build;
  10. import android.os.Bundle;
  11. import android.os.Handler;
  12. import android.os.Message;
  13. import android.view.KeyEvent;
  14. import android.view.View;
  15. import android.view.inputmethod.EditorInfo;
  16. import android.view.inputmethod.InputMethodManager;
  17. import android.widget.EditText;
  18. import android.widget.LinearLayout;
  19. import android.widget.TextView;
  20. import androidx.annotation.RequiresApi;
  21. import com.elvishew.xlog.XLog;
  22. import com.google.gson.Gson;
  23. import com.google.zxing.Result;
  24. import com.lzy.okgo.OkGo;
  25. import com.lzy.okgo.model.Response;
  26. import com.fxy.baselibrary.base.BaseActivity;
  27. import com.fxy.baselibrary.bean.BaseEventBusBean;
  28. import com.fxy.baselibrary.interfaces.OnRxScanerListener;
  29. import com.fxy.baselibrary.qrcode.ActivityScanerCode;
  30. import com.fxy.baselibrary.util.JsonUtil;
  31. import com.fxy.R;
  32. import com.fxy.bean.ActionBean;
  33. import com.fxy.bean.ScanBean;
  34. import com.fxy.constant.BaseConfig;
  35. import com.fxy.constant.EventCode;
  36. import com.fxy.fms.logic.ViewLogic;
  37. import com.fxy.net.MyDialogCallback;
  38. import com.fxy.net.Urls;
  39. import com.fxy.view.FloatingImageView;
  40. import org.json.JSONException;
  41. import org.json.JSONObject;
  42. import java.util.ArrayList;
  43. import java.util.HashMap;
  44. import java.util.Map;
  45. import java.util.regex.Matcher;
  46. import java.util.regex.Pattern;
  47. import butterknife.BindView;
  48. import butterknife.ButterKnife;
  49. import butterknife.OnClick;
  50. import butterknife.Unbinder;
  51. import sto.android.app.StoJNI;
  52. import sto.android.app.StoPdaKeyEvent;
  53. import sto.android.app.StoTongJNI;
  54. public class TallyVolumeMainActivity extends BaseActivity implements StoJNI.ScanCallBack {
  55. /**
  56. * 列表适配器
  57. */
  58. Context mContext = this;
  59. //材积明细
  60. @BindView(R.id.ll_volume_content)
  61. LinearLayout llVolumeContent;
  62. @BindView(R.id.tv_add_pallet)
  63. TextView tvAddPallet;
  64. //浮动按钮
  65. @BindView(R.id.iv_drag)
  66. FloatingImageView iv_drag;
  67. @BindView(R.id.ll_tally_info)
  68. LinearLayout llTallyInfo;
  69. private EditText edittext;
  70. //扫码扫码动作
  71. private ScanBean scanBean;
  72. //订单信息对象
  73. private JSONObject inboundObject;
  74. private JSONObject paramObject;
  75. private Unbinder unbinder;
  76. protected String action;
  77. //订单号
  78. private String orderNumber;
  79. //是否确认 Y 或 N 默认:N
  80. private String isConfirm = "N";
  81. //理货总件数
  82. private int total_pieces = 0;
  83. private ArrayList<Map<String, String>> volumeList = new ArrayList<Map<String, String>>();
  84. private JSONObject postParam = new JSONObject();
  85. @Override
  86. public int getContentViewResId() {
  87. return R.layout.activity_fms_tally_volume;
  88. }
  89. @Override
  90. public boolean showToolBar() {
  91. return true;
  92. }
  93. @Override
  94. public boolean openEventBus() {
  95. return true;
  96. }
  97. @Override
  98. protected void getBundleExtras(Bundle bundle) {
  99. try {
  100. action = bundle.getString("action","receive");
  101. inboundObject = new JSONObject(bundle.getString("inbound_object"));
  102. paramObject = new JSONObject(bundle.getString("param"));
  103. } catch (JSONException e) {
  104. XLog.e("接收数据解析:"+e.getMessage());
  105. e.printStackTrace();
  106. }
  107. }
  108. //finish的返回监听
  109. //这里的requestCode参数,就是上面设置的 1 ,当跳转的页面返回的时候,通过这个加以判断
  110. //resultCode ,这个参数是在跳转的页面里面规定的,它也是一个int类型的标志
  111. //第三个参数包含了返回的值
  112. //如果不需要所跳转的页面返回值,也就不需要这个方法了
  113. @Override
  114. public void onActivityResult(int requestCode, int resultCode, Intent data) {
  115. super.onActivityResult(requestCode, resultCode, data);
  116. // XLog.e("requestCode:"+requestCode);
  117. // XLog.e("resultCode:"+resultCode);
  118. if (requestCode == 200 && resultCode == 200)//之前提到的两个标志,在这里显示出了作用
  119. {
  120. String opt_status = data.getStringExtra("opt_status").toString();
  121. if (opt_status.equals("success")){
  122. Intent intent = new Intent();
  123. intent.putExtra("opt_status", opt_status);
  124. setResult(200, intent);//返回值,200 是改返回的标志,也会返回
  125. finish();
  126. }
  127. }else if (resultCode==0){
  128. }
  129. }
  130. /**
  131. * EventBus接收信息的方法,开启后才会调用(非粘性事件)
  132. *
  133. * @param event
  134. */
  135. @Override
  136. protected void EventBean(BaseEventBusBean event) {
  137. // XLog.e("----------接收返回--------------");
  138. // XLog.e("接收返回:"+event.getEventCode());
  139. if (event != null && event.getEventCode() == EventCode.displacement_refresh){
  140. }
  141. }
  142. @Override
  143. public boolean isPlayMusic() {
  144. return true;
  145. }
  146. @Override
  147. protected void initView() {
  148. unbinder = ButterKnife.bind(this);
  149. setTitleName("录入材积重");
  150. initEdit();
  151. //loadServiceData();
  152. initData();
  153. //监听浮动按钮
  154. iv_drag.setOnClickListener(new View.OnClickListener() {
  155. @Override
  156. public void onClick(View v) {
  157. if(!iv_drag.isDrag()){
  158. ActivityScanerCode.setScanerListener(mScanerListener);
  159. ActivityScanerCode.intent2Activity(mContext, BaseConfig.COMMON_SCANNER_ONLY);
  160. }
  161. }
  162. });
  163. if (inboundObject!=null){
  164. //设置订单信息
  165. ViewLogic logic = new ViewLogic(llTallyInfo);
  166. logic.setTallyData(inboundObject);
  167. logic.setTallyMore(paramObject);
  168. }
  169. //默认添加一条
  170. addPallet();
  171. }
  172. private void initData(){
  173. }
  174. @Override
  175. public boolean dispatchKeyEvent(KeyEvent event) {
  176. //XLog.e("event:"+event.getKeyCode());
  177. if ((event.getKeyCode()==KeyEvent.KEYCODE_DPAD_CENTER || event.getKeyCode()==KeyEvent.KEYCODE_ENTER ) && event.getAction() == KeyEvent.ACTION_DOWN){
  178. //按确定键
  179. if(this.validate()){
  180. addReceive();
  181. }
  182. }
  183. return super.dispatchKeyEvent(event);
  184. }
  185. //监听按键
  186. public boolean onKeyDown(int keyCode, KeyEvent event) {
  187. XLog.e("监听按键:"+keyCode);XLog.e(event);
  188. if (scanBean.getIsBroadcast()==0 && StoTongJNI.getIns(mContext).getEventFuction(keyCode) == StoPdaKeyEvent.KEYCODE_SCAN
  189. && event.getRepeatCount() == 0) {
  190. if (StoTongJNI.getIns(mContext).GetScannerIsScanning()) {
  191. //
  192. } else {
  193. StoTongJNI.getIns(mContext).SetScannerStart();
  194. }
  195. }
  196. return super.onKeyDown(keyCode, event);
  197. }
  198. @SuppressLint("HandlerLeak")
  199. Handler scanHandler = new Handler() {
  200. @Override
  201. public void handleMessage(Message msg) {
  202. // TODO Auto-generated method stub
  203. if (msg.obj != null) {
  204. String scanResult = msg.obj.toString().trim();
  205. if (!scanResult.isEmpty()){
  206. setScanResult(scanResult);
  207. }
  208. }
  209. }
  210. };
  211. @Override
  212. public void onScanResults(String str) {
  213. Message msg = new Message();
  214. msg.obj = str;
  215. scanHandler.sendMessage(msg);
  216. }
  217. @Override
  218. public void onScanResults(String str, int type) {
  219. }
  220. /**
  221. * 定义广播接受
  222. */
  223. BroadcastReceiver mReceiver = new BroadcastReceiver() {
  224. @Override
  225. public void onReceive(Context context, Intent intent) {
  226. String scanResult = intent.getStringExtra(scanBean.getDataName());
  227. if (scanResult==null){return; }
  228. String scanStatus = "";
  229. if (!scanBean.getStatusName().isEmpty()){
  230. scanStatus = intent.getStringExtra(scanBean.getStatusName());
  231. }else{
  232. scanStatus = scanResult.isEmpty()? "" : "ok"; //有值 默认是扫码成功;
  233. }
  234. //新大陆(MT65,MT90) 需要手动关闭
  235. if (!scanBean.getActionStop().isEmpty()){
  236. Intent stopIntent = new Intent(scanBean.getActionStop());
  237. mContext.sendBroadcast(stopIntent);
  238. }
  239. if ("ok".equals(scanStatus)){
  240. setScanResult(scanResult);
  241. }else{
  242. showErrorToast(getString(R.string.scan_failed));
  243. }
  244. }
  245. };
  246. /**
  247. * 注册广播
  248. */
  249. private void initReceiver(){
  250. try {
  251. String scanStr = getScanSetting();
  252. scanBean = JsonUtil.getObject(scanStr, ScanBean.class);
  253. Integer is_broadcast = scanBean.getIsBroadcast();//是否广播
  254. if (is_broadcast ==1){
  255. IntentFilter mFilter = new IntentFilter(scanBean.getAction());
  256. this.registerReceiver(mReceiver, mFilter);
  257. }else{
  258. //不广播进行处理 jni模式
  259. String pdaBrand = StoTongJNI.getmPdaBrand();
  260. if (!pdaBrand.isEmpty()){
  261. StoTongJNI.getIns(this).setmScanCB(this);
  262. StoTongJNI.getIns(this).SetScannerOn();
  263. }
  264. }
  265. }catch (Exception e) {
  266. showErrorToast("获取扫码配置失败"+e.getMessage());
  267. XLog.e("获取扫码配置失败:" + e.getMessage());
  268. }
  269. }
  270. private void initEdit() {
  271. }
  272. private OnRxScanerListener mScanerListener = new OnRxScanerListener() {
  273. @Override
  274. public void onSuccess(String type, Result result) {
  275. String scanResult = result.getText();
  276. switch (type){
  277. case BaseConfig.COMMON_SCANNER_ONLY:
  278. setScanResult(scanResult);
  279. break;
  280. }
  281. }
  282. @Override
  283. public void onFail(String type, String message) {
  284. }
  285. };
  286. //把扫描结果赋值
  287. private void setScanResult(String scanResult){
  288. //获取焦点的view对象
  289. View view=getWindow().getDecorView().findFocus();
  290. //如果是EditText
  291. if(view instanceof EditText)
  292. {
  293. ((EditText) view).setText(scanResult);
  294. switch (view.getId()) {
  295. case R.id.et_order_no:
  296. break;
  297. default:
  298. }
  299. }
  300. }
  301. /*
  302. * 校验必录
  303. */
  304. private boolean validate(){
  305. int len = llVolumeContent.getChildCount();
  306. if (len==0){
  307. showWarningToast("请先添加材积信息");
  308. return false;
  309. }
  310. volumeList.clear();//清空材积信息
  311. total_pieces = 0;
  312. int num = 0;//第几个卡板
  313. for(int i=0;i<len ;i++) {
  314. View view_c = llVolumeContent.getChildAt(i);
  315. EditText etWeight = (EditText) view_c.findViewById(R.id.et_weight);
  316. EditText etPalletWeight = (EditText) view_c.findViewById(R.id.et_pallet_weight);
  317. if (etWeight==null){
  318. continue;
  319. }
  320. num++;
  321. //1、检查重量是否填写(一个卡板只有一个重量)
  322. if (!isNumber(getValStr(etWeight),3)){
  323. setEditTextFocused(etWeight,false);
  324. showWarningToast(getString(R.string.msg_gt_zero_3));
  325. return false;
  326. }
  327. etWeight.setBackgroundResource(R.drawable.edit_background);
  328. //1.1 检查卡板重量
  329. if (etPalletWeight.getText().toString().isEmpty()){
  330. setEditTextFocused(etPalletWeight,false);
  331. showWarningToast("必填项不能空");
  332. return false;
  333. }
  334. etPalletWeight.setBackgroundResource(R.drawable.edit_background);
  335. //总重量
  336. double weightTotal= Double.parseDouble(etWeight.getText().toString());
  337. //卡板重量
  338. double palletWeightTotal= Double.parseDouble(etPalletWeight.getText().toString());
  339. //1.2 检查卡板重量必需小于重量
  340. if (palletWeightTotal>=weightTotal){
  341. setEditTextFocused(etWeight,false);
  342. showWarningToast("卡板重量必需小于总重量");
  343. return false;
  344. }
  345. LinearLayout pallLayout = (LinearLayout) view_c.findViewById(R.id.ll_pall_center);
  346. //3、遍历卡板下的材积 ,由于removeAllViews 没有删除视图
  347. int volumeCopies = 0;
  348. int starIndex = volumeList.size();
  349. for(int j=2;j<pallLayout.getChildCount();j++) {
  350. View pallView = pallLayout.getChildAt(j);
  351. if (pallView.findViewById(R.id.et_copies)!=null){
  352. EditText etCopies = (EditText) pallView.findViewById(R.id.et_copies);
  353. EditText etLength = (EditText) pallView.findViewById(R.id.et_length);
  354. EditText etWidth = (EditText) pallView.findViewById(R.id.et_width);
  355. EditText etHeight = (EditText) pallView.findViewById(R.id.et_height);
  356. if (!validateVolume(etCopies,etLength,etWidth,etHeight)){
  357. return false;
  358. }
  359. String copies= etCopies.getText().toString().trim();
  360. Map<String,String> hostMap = new HashMap<>();
  361. hostMap.put("qty",copies);
  362. hostMap.put("inbound_weight","0");
  363. hostMap.put("inbound_length",etLength.getText().toString().trim());
  364. hostMap.put("inbound_width",etWidth.getText().toString().trim());
  365. hostMap.put("inbound_height",etHeight.getText().toString().trim());
  366. hostMap.put("pallet_height",etPalletWeight.getText().toString().trim());
  367. hostMap.put("total_width",etWeight.getText().toString().trim());
  368. volumeList.add(hostMap);
  369. volumeCopies = volumeCopies+Integer.parseInt(copies);
  370. }
  371. }
  372. if (volumeCopies==0){
  373. showWarningToast("卡板"+num+"材积不能为空");
  374. return false;
  375. }
  376. total_pieces = total_pieces+volumeCopies;
  377. //单件重量
  378. String inbound_weight = String .format("%.2f",(weightTotal-palletWeightTotal)/volumeCopies);;
  379. for (int n=starIndex ;n<volumeList.size();n++){
  380. Map<String,String> hostMap = volumeList.get(n);
  381. hostMap.put("inbound_weight",inbound_weight);
  382. volumeList.set(n,hostMap);
  383. }
  384. }
  385. return true;
  386. }
  387. private boolean validateVolume(EditText etCopies,EditText etLength,EditText etWidth,EditText etHeight){
  388. if (etCopies.getText().toString().isEmpty() || !isNumber(getValStr(etCopies),0)){
  389. setEditTextFocused(etCopies,false);
  390. showWarningToast(getString(R.string.error_please_int_num));
  391. return false;
  392. }
  393. //清除红色框框
  394. etCopies.setBackgroundResource(R.drawable.edit_background);
  395. if (!isNumber(getValStr(etLength),3)){
  396. setEditTextFocused(etLength,false);
  397. showWarningToast(getString(R.string.msg_gt_zero_3));
  398. return false;
  399. }
  400. //清除红色框框
  401. etLength.setBackgroundResource(R.drawable.edit_background);
  402. if (!isNumber(getValStr(etWidth),3)){
  403. setEditTextFocused(etWidth,false);
  404. showWarningToast(getString(R.string.msg_gt_zero_3));
  405. return false;
  406. }
  407. //清除红色框框
  408. etWidth.setBackgroundResource(R.drawable.edit_background);
  409. if (!isNumber(getValStr(etHeight),3)){
  410. setEditTextFocused(etHeight,false);
  411. showWarningToast(getString(R.string.msg_gt_zero_3));
  412. return false;
  413. }
  414. //清除红色框框
  415. etHeight.setBackgroundResource(R.drawable.edit_background);
  416. return true;
  417. }
  418. @OnClick({R.id.btn_confirm,R.id.tv_add_pallet})
  419. public void onViewClicked(final View view) {
  420. Bundle bundle = new Bundle();
  421. switch (view.getId()) {
  422. case R.id.btn_confirm:
  423. addReceive();
  424. break;
  425. case R.id.tv_add_pallet:
  426. addPallet();
  427. break;
  428. default:
  429. break;
  430. }
  431. }
  432. private void addPallet(){
  433. View newView = View.inflate(TallyVolumeMainActivity.this, R.layout.item_tally_pallet, null);
  434. //找到里面需要动态改变的控件
  435. TextView tvPalletTitle = (TextView) newView.findViewById(R.id.tv_pallet_num);
  436. //给控件赋值
  437. tvPalletTitle.setText("卡板"+(llVolumeContent.getChildCount()+1));
  438. TextView tvPalletDel = (TextView) newView.findViewById(R.id.tv_pallet_del);
  439. TextView tvVolumeDel = (TextView) newView.findViewById(R.id.tv_volume_del);
  440. TextView tvAddVolume = (TextView) newView.findViewById(R.id.tv_add_volume);
  441. if (llVolumeContent.getChildCount()==0){
  442. tvPalletDel.setVisibility(View.GONE);
  443. }
  444. tvVolumeDel.setVisibility(View.GONE);
  445. //监听删除按钮
  446. onClickVolumeDel(tvVolumeDel);
  447. onEditorAction((EditText) newView.findViewById(R.id.et_copies));
  448. onEditorAction((EditText) newView.findViewById(R.id.et_weight));
  449. onEditorAction((EditText) newView.findViewById(R.id.et_pallet_weight));
  450. onEditorAction((EditText) newView.findViewById(R.id.et_length));
  451. onEditorAction((EditText) newView.findViewById(R.id.et_width));
  452. onEditorAction((EditText) newView.findViewById(R.id.et_height));
  453. //监听删除卡托点击事件
  454. tvPalletDel.setOnClickListener(new View.OnClickListener() {
  455. @RequiresApi(api = Build.VERSION_CODES.KITKAT)
  456. @Override
  457. public void onClick(View v) {
  458. try {
  459. final LinearLayout linearLayout = (LinearLayout) v.getParent().getParent().getParent();
  460. new AlertDialog.Builder(mContext)
  461. .setTitle(R.string.dl_hint)
  462. .setMessage("确定要删除卡板吗?")
  463. .setNegativeButton(R.string.str_cancel, new DialogInterface.OnClickListener() {
  464. @Override
  465. public void onClick(DialogInterface dialogInterface, int i) {
  466. dialogInterface.dismiss();
  467. }
  468. }).setPositiveButton(R.string.str_submit, new DialogInterface.OnClickListener() {
  469. @Override
  470. public void onClick(DialogInterface dialogInterface, int i) {
  471. linearLayout.removeAllViews();
  472. setPalletTitle();
  473. }
  474. }).show();
  475. } catch (Exception e) {
  476. e.printStackTrace();
  477. showErrorToast("删除卡板失败");
  478. }
  479. }
  480. });
  481. //监听添加材积
  482. tvAddVolume.setOnClickListener(new View.OnClickListener() {
  483. @Override
  484. public void onClick(View v) {
  485. LinearLayout pallLayout = (LinearLayout) v.getParent().getParent();
  486. addVolume(pallLayout);
  487. }
  488. });
  489. llVolumeContent.addView(newView); //添加一个View
  490. setPalletTitle();
  491. }
  492. //统计
  493. //添加材积
  494. private void addVolume(LinearLayout pallLayout){
  495. try {
  496. int childCount = pallLayout.getChildCount();
  497. //卡板的Layout
  498. View newView = View.inflate(TallyVolumeMainActivity.this, R.layout.item_tally_volume, null);
  499. TextView tvVolumeDel = (TextView) newView.findViewById(R.id.tv_volume_del);
  500. TextView tvTitleNum = (TextView) newView.findViewById(R.id.tv_title_num);
  501. onEditorAction((EditText) newView.findViewById(R.id.et_copies));
  502. onEditorAction((EditText) newView.findViewById(R.id.et_length));
  503. onEditorAction((EditText) newView.findViewById(R.id.et_width));
  504. onEditorAction((EditText) newView.findViewById(R.id.et_height));
  505. //监听删除按钮
  506. onClickVolumeDel(tvVolumeDel);
  507. //index 获取插入卡板的第几个子元素
  508. pallLayout.addView(newView,childCount-1);
  509. setVolumeTitle(pallLayout);
  510. } catch (Exception e) {
  511. e.printStackTrace();
  512. showErrorToast("添加失败");
  513. }
  514. }
  515. //监听删除事件
  516. private void onClickVolumeDel(View tvVolumeDel){
  517. //监听删除材积
  518. tvVolumeDel.setOnClickListener(new View.OnClickListener() {
  519. @RequiresApi(api = Build.VERSION_CODES.KITKAT)
  520. @Override
  521. public void onClick(View v) {
  522. try {
  523. final LinearLayout linearLayout = (LinearLayout) v.getParent().getParent().getParent();
  524. new AlertDialog.Builder(mContext)
  525. .setTitle(R.string.dl_hint)
  526. .setMessage("确定要删除材积信息吗?")
  527. .setNegativeButton(R.string.str_cancel, new DialogInterface.OnClickListener() {
  528. @Override
  529. public void onClick(DialogInterface dialogInterface, int i) {
  530. dialogInterface.dismiss();
  531. }
  532. }).setPositiveButton(R.string.str_submit, new DialogInterface.OnClickListener() {
  533. @Override
  534. public void onClick(DialogInterface dialogInterface, int i) {
  535. LinearLayout pallLayout = (LinearLayout) linearLayout.getParent();
  536. linearLayout.removeAllViews();
  537. setVolumeTitle(pallLayout);
  538. }
  539. }).show();
  540. } catch (Exception e) {
  541. e.printStackTrace();
  542. showErrorToast("删除材积信息失败");
  543. }
  544. }
  545. });
  546. }
  547. //设置卡板标题
  548. private void setPalletTitle(){
  549. int num = 1;
  550. for(int j=0;j<llVolumeContent.getChildCount();j++) {
  551. View view_c = llVolumeContent.getChildAt(j);
  552. TextView tvPalletTitle = (TextView) view_c.findViewById(R.id.tv_pallet_num);
  553. if (tvPalletTitle!=null){
  554. tvPalletTitle.setText("卡板"+(num));
  555. num++;
  556. }
  557. }
  558. }
  559. //设置材积标题
  560. private void setVolumeTitle(LinearLayout pallLayout){
  561. int num = 1;
  562. for(int j=0;j<pallLayout.getChildCount();j++) {
  563. View view_c = pallLayout.getChildAt(j);
  564. if (view_c.findViewById(R.id.ll_volume_container)!=null){
  565. TextView tvTitle = (TextView) view_c.findViewById(R.id.tv_title_num);
  566. tvTitle.setText("材积信息("+num+")");
  567. num++;
  568. }
  569. }
  570. }
  571. //监听所有输入框
  572. private void onEditorAction(EditText editText){
  573. editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
  574. @Override
  575. public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
  576. if (actionId == EditorInfo.IME_ACTION_DONE) {
  577. int len = llVolumeContent.getChildCount();
  578. int num = 0;//第几个卡板
  579. for(int i=0;i<len ;i++) {
  580. View view_c = llVolumeContent.getChildAt(i);
  581. EditText etWeight = (EditText) view_c.findViewById(R.id.et_weight);
  582. EditText etPalletWeight = (EditText) view_c.findViewById(R.id.et_pallet_weight);
  583. if (etWeight==null){
  584. continue;
  585. }
  586. num++;
  587. if (etWeight.getText().toString().isEmpty()){
  588. etWeight.requestFocus();
  589. return false;
  590. }
  591. if (etPalletWeight.getText().toString().isEmpty()){
  592. etPalletWeight.requestFocus();
  593. return false;
  594. }
  595. LinearLayout pallLayout = (LinearLayout) view_c.findViewById(R.id.ll_pall_center);
  596. int a = pallLayout.getChildCount();
  597. //2、查验卡板下是否有材积信息
  598. if (pallLayout.getChildCount()<4){
  599. showWarningToast("卡板"+(num)+"材积不能为空");
  600. //return true;
  601. continue; //不终止
  602. }
  603. //3、遍历卡板下的材积
  604. for(int j=2;j<pallLayout.getChildCount();j++) {
  605. View pallView = pallLayout.getChildAt(j);
  606. if (pallView.findViewById(R.id.et_copies)!=null){
  607. EditText etCopies = (EditText) pallView.findViewById(R.id.et_copies);
  608. if (etCopies.getText().toString().isEmpty()){
  609. etCopies.requestFocus();
  610. return false;
  611. }
  612. EditText etLength = (EditText) pallView.findViewById(R.id.et_length);
  613. if (etLength.getText().toString().isEmpty()){
  614. etLength.requestFocus();
  615. return false;
  616. }
  617. EditText etWidth = (EditText) pallView.findViewById(R.id.et_width);
  618. if (etWidth.getText().toString().isEmpty()){
  619. etWidth.requestFocus();
  620. return false;
  621. }
  622. EditText etHeight = (EditText) pallView.findViewById(R.id.et_height);
  623. if (etHeight.getText().toString().isEmpty()){
  624. etHeight.requestFocus();
  625. return false;
  626. }
  627. }
  628. }
  629. }
  630. //软键盘
  631. View view = getWindow().peekDecorView();
  632. if (view != null) {
  633. InputMethodManager inputmanger = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
  634. inputmanger.hideSoftInputFromWindow(view.getWindowToken(), 0);
  635. }
  636. }
  637. return false;
  638. }
  639. });
  640. }
  641. private void addReceive(){
  642. if (!validate()){
  643. return;
  644. }
  645. try {
  646. //理货数量
  647. int inbound_pieces = inboundObject.getInt("inbound_pieces");
  648. //预报数量
  649. int forecast_pieces = inboundObject.getInt("forecast_pieces");
  650. if (forecast_pieces>inbound_pieces+total_pieces){
  651. new AlertDialog.Builder(TallyVolumeMainActivity.this)
  652. .setTitle(R.string.dl_hint)
  653. .setMessage("入库件数"+(inbound_pieces+total_pieces)+"与预报件数"+(forecast_pieces)+"不一致,确定是否入库")
  654. .setNegativeButton(R.string.str_cancel, new DialogInterface.OnClickListener() {
  655. @RequiresApi(api = Build.VERSION_CODES.KITKAT)
  656. @Override
  657. public void onClick(DialogInterface dialogInterface, int i) {
  658. dialogInterface.dismiss();
  659. }
  660. }).setPositiveButton(R.string.str_submit, new DialogInterface.OnClickListener() {
  661. @Override
  662. public void onClick(DialogInterface dialogInterface, int i) {
  663. addReceiveDo();
  664. }
  665. }).show();
  666. }else{
  667. addReceiveDo();
  668. }
  669. } catch (JSONException e) {
  670. e.printStackTrace();
  671. }
  672. //数据检查不通过
  673. }
  674. private void addReceiveDo(){
  675. try {
  676. postParam = new JSONObject();
  677. Gson gson = new Gson();
  678. postParam.put("order_number",inboundObject.getString("order_number"));
  679. postParam.put("docker_id",paramObject.getInt("docker_id"));
  680. postParam.put("has_label",paramObject.getString("has_label"));
  681. postParam.put("is_confirm",isConfirm);
  682. postParam.put("receive_list",gson.toJson(volumeList));
  683. postParam.put("action",action);
  684. if (!checkRepeat(Urls.FMS_ADD_RECEIVE+(postParam.toString()))){return;}
  685. OkGo.<String>post(Urls.getServiceAddress(this) + Urls.FMS_ADD_RECEIVE).upJson(postParam)
  686. .execute(new MyDialogCallback(this, true, true) {
  687. @Override
  688. public void onSuccess(Response<String> response) {
  689. super.onSuccess(response);
  690. try {
  691. ActionBean bean = JsonUtil.getObject(response.body(), ActionBean.class);
  692. if(bean.code == 1){
  693. showSuccessToast(getString(R.string.str_tally_success));
  694. Intent intent = new Intent();
  695. intent.putExtra("opt_status", "success");
  696. setResult(200, intent);//返回值,2 是改返回的标志,也会返回
  697. finish();
  698. }else{
  699. JSONObject result = new JSONObject();
  700. if (bean.data!=null && !bean.data.isEmpty()){
  701. result = new JSONObject(bean.data);
  702. }
  703. if (result.has("is_warning") && result.getInt("is_warning")==1){
  704. new AlertDialog.Builder(TallyVolumeMainActivity.this)
  705. .setTitle(R.string.dl_hint)
  706. .setMessage(bean.msg)
  707. .setNegativeButton("录入准确,拍照", new DialogInterface.OnClickListener() {
  708. @RequiresApi(api = Build.VERSION_CODES.KITKAT)
  709. @Override
  710. public void onClick(DialogInterface dialogInterface, int i) {
  711. Bundle bundle = new Bundle();
  712. bundle.putString("inbound_object",inboundObject.toString());
  713. bundle.putString("param",paramObject.toString());
  714. bundle.putString("post_param",postParam.toString());
  715. intentPageResult(TallyVolumeMainActivity.this,TallyPictureMainActivity.class, bundle,200);
  716. }
  717. }).setPositiveButton("重新录入", new DialogInterface.OnClickListener() {
  718. @Override
  719. public void onClick(DialogInterface dialogInterface, int i) {
  720. //取消不做操作
  721. }
  722. }).show();
  723. }else {
  724. showWarningToast(bean.msg);
  725. }
  726. }
  727. } catch (Exception e) {
  728. e.printStackTrace();
  729. XLog.e("添加理货数据结果返回错误",e.getMessage());
  730. }
  731. }
  732. });
  733. } catch (JSONException e) {
  734. XLog.e("sku数据解析出错",e);
  735. e.printStackTrace();
  736. }
  737. }
  738. //金额验证
  739. public static boolean isNumber(String str,Integer num){
  740. Pattern pattern=Pattern.compile("^(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,"+num+"})?$"); // 判断小数点后2位的数字的正则表达式
  741. Matcher match=pattern.matcher(str);
  742. if (match.matches()){
  743. return Double.parseDouble(str) > 0;
  744. }else{
  745. return false ;
  746. }
  747. }
  748. public static boolean isNumber(String str,Integer num,int min){
  749. Pattern pattern=Pattern.compile("^(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,"+num+"})?$"); // 判断小数点后2位的数字的正则表达式
  750. Matcher match=pattern.matcher(str);
  751. if (match.matches()){
  752. return Double.parseDouble(str) > min;
  753. }else{
  754. return false ;
  755. }
  756. }
  757. public static boolean isNum(String str,Integer num){
  758. Pattern pattern=Pattern.compile("^(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,"+num+"})?$"); // 判断小数点后2位的数字的正则表达式
  759. Matcher match=pattern.matcher(str);
  760. return match.matches();
  761. }
  762. //获取输入框值
  763. private String getValStr(EditText v){
  764. return v.getText().toString().trim();
  765. }
  766. @Override
  767. protected void onDestroy() {
  768. unbinder.unbind();
  769. super.onDestroy();
  770. }
  771. @Override
  772. protected void onResume() {
  773. super.onResume();
  774. initReceiver();
  775. }
  776. @Override
  777. protected void onPause() {
  778. super.onPause();
  779. //销毁在onResume()方法中的广播
  780. try {
  781. //停止扫描
  782. Integer is_broadcast = scanBean.getIsBroadcast();//是否广播
  783. if (is_broadcast==0){
  784. StoTongJNI.getIns(mContext).SetScannerStop();
  785. StoTongJNI.getIns(mContext).SetScannerOff();
  786. }else{
  787. unregisterReceiver(mReceiver);
  788. }
  789. }catch (Exception e){
  790. XLog.e("销毁广播失败:",e.getMessage());
  791. }
  792. }
  793. }