|
|
@@ -1,14 +1,42 @@
|
|
|
package com.uas.pda_mes_sa.fragment;
|
|
|
|
|
|
+import android.app.Activity;
|
|
|
+import android.content.Intent;
|
|
|
+import android.text.TextUtils;
|
|
|
import android.view.KeyEvent;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.CheckBox;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.TextView;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.android.volley.Request;
|
|
|
import com.uas.pda_mes_sa.R;
|
|
|
+import com.uas.pda_mes_sa.global.GloableParams;
|
|
|
+import com.uas.pda_mes_sa.listener.MyEditorActionListener;
|
|
|
+import com.uas.pda_mes_sa.util.CameraUtil;
|
|
|
+import com.uas.pda_mes_sa.util.CommonUtil;
|
|
|
+import com.uas.pda_mes_sa.util.FastjsonUtil;
|
|
|
+import com.uas.pda_mes_sa.util.HttpCallback;
|
|
|
+import com.uas.pda_mes_sa.util.HttpParams;
|
|
|
+import com.uas.pda_mes_sa.util.VolleyRequest;
|
|
|
+import com.uas.pda_mes_sa.view.ClearableEditText;
|
|
|
+import com.uuzuche.lib_zxing.activity.CaptureActivity;
|
|
|
+import com.uuzuche.lib_zxing.activity.CodeUtils;
|
|
|
|
|
|
/**
|
|
|
* Created by RaoMeng on 2020/4/26
|
|
|
* Desc: 工步移交
|
|
|
*/
|
|
|
public class StepTransferFragment extends BaseFragment {
|
|
|
+ private static final int SCAN_BARCODE_CODE = 111;
|
|
|
+
|
|
|
+ private ClearableEditText mBarcodeEditText;
|
|
|
+ private ImageView mScanImageView;
|
|
|
+ private TextView mResultTextView;
|
|
|
+ private CheckBox mCancelCheckBox;
|
|
|
+
|
|
|
@Override
|
|
|
protected int getLayout() {
|
|
|
return R.layout.fragment_step_transfer;
|
|
|
@@ -17,11 +45,34 @@ public class StepTransferFragment extends BaseFragment {
|
|
|
@Override
|
|
|
protected void initViews() {
|
|
|
setTitle("工步移交");
|
|
|
+
|
|
|
+ mBarcodeEditText = root.findViewById(R.id.step_transfer_barcode_et);
|
|
|
+ mScanImageView = root.findViewById(R.id.step_transfer_scan_iv);
|
|
|
+ mResultTextView = root.findViewById(R.id.step_transfer_result_tv);
|
|
|
+ mCancelCheckBox = root.findViewById(R.id.step_transfer_cancel_cb);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void initEvents() {
|
|
|
+ mScanImageView.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (CameraUtil.hasCamera()) {
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.setClass(mActivity, CaptureActivity.class);
|
|
|
+ startActivityForResult(intent, SCAN_BARCODE_CODE);
|
|
|
+ } else {
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, getString(R.string.no_camera_detected));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
+ CommonUtil.setEditorActionListener(mBarcodeEditText, new MyEditorActionListener() {
|
|
|
+ @Override
|
|
|
+ public void MyEditorAction(String text, int actionId, KeyEvent event) {
|
|
|
+ stepSend(text);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -29,6 +80,74 @@ public class StepTransferFragment extends BaseFragment {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private void stepSend(String barcode) {
|
|
|
+ if (TextUtils.isEmpty(barcode)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ mResultTextView.setText("");
|
|
|
+ progressDialog.show();
|
|
|
+ VolleyRequest.getInstance().stringRequest(new HttpParams.Builder()
|
|
|
+ .url(GloableParams.ADDRESS_WIPSTEPTURN_SEND)
|
|
|
+ .method(Request.Method.POST)
|
|
|
+ .addParam("lotno", barcode)
|
|
|
+ .addParam("cancel", String.valueOf(mCancelCheckBox.isChecked()))
|
|
|
+ .build(), new HttpCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(int flag, Object o) throws Exception {
|
|
|
+ progressDialog.dismiss();
|
|
|
+ String msg = "移交成功";
|
|
|
+ if (mCancelCheckBox.isChecked()) {
|
|
|
+ msg = "撤销移交成功";
|
|
|
+ }
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, msg);
|
|
|
+ try {
|
|
|
+ String result = o.toString();
|
|
|
+ JSONObject resultObject = JSON.parseObject(result);
|
|
|
+ JSONObject dataObject = resultObject.getJSONObject("data");
|
|
|
+ if (dataObject != null) {
|
|
|
+ mResultTextView.setText(
|
|
|
+ "批号:" + FastjsonUtil.getText(dataObject, "LOTNO")
|
|
|
+ + "\n数量:" + FastjsonUtil.getText(dataObject, "QTY")
|
|
|
+ + "\n" + msg
|
|
|
+ );
|
|
|
+ }
|
|
|
+ mBarcodeEditText.setText("");
|
|
|
+ mBarcodeEditText.requestFocus();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFail(int flag, String failStr) throws Exception {
|
|
|
+ progressDialog.dismiss();
|
|
|
+ mResultTextView.setText(failStr);
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, failStr);
|
|
|
+ mBarcodeEditText.setText("");
|
|
|
+ mBarcodeEditText.requestFocus();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
+ super.onActivityResult(requestCode, resultCode, data);
|
|
|
+
|
|
|
+ if (resultCode != Activity.RESULT_OK) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (requestCode == SCAN_BARCODE_CODE && data != null) {
|
|
|
+ if (data.getExtras() != null) {
|
|
|
+ String result = data.getExtras().getString(CodeUtils.RESULT_STRING);
|
|
|
+ mBarcodeEditText.setText(result);
|
|
|
+ mBarcodeEditText.setSelection(result.length());
|
|
|
+ stepSend(result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
return false;
|