|
|
@@ -0,0 +1,277 @@
|
|
|
+package com.uas.keg_storage.fragment;
|
|
|
+
|
|
|
+import android.app.Activity;
|
|
|
+import android.content.Intent;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.view.KeyEvent;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.Button;
|
|
|
+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.keg_storage.R;
|
|
|
+import com.uas.keg_storage.activity.FunctionActivity;
|
|
|
+import com.uas.keg_storage.global.GloableParams;
|
|
|
+import com.uas.keg_storage.listener.MyEditorActionListener;
|
|
|
+import com.uas.keg_storage.util.CameraUtil;
|
|
|
+import com.uas.keg_storage.util.CommonUtil;
|
|
|
+import com.uas.keg_storage.util.FastjsonUtil;
|
|
|
+import com.uas.keg_storage.util.HttpCallback;
|
|
|
+import com.uas.keg_storage.util.HttpParams;
|
|
|
+import com.uas.keg_storage.util.VollyRequest;
|
|
|
+import com.uas.keg_storage.view.ClearableEditText;
|
|
|
+import com.uuzuche.lib_zxing.activity.CaptureActivity;
|
|
|
+import com.uuzuche.lib_zxing.activity.CodeUtils;
|
|
|
+
|
|
|
+public class BarcodeInfoBindFragment extends BaseFragment {
|
|
|
+ private static final int SCAN_BARCODE_CODE = 116;
|
|
|
+ private ClearableEditText mBarcodeCet, mDcCet,
|
|
|
+ mLotnoCet, mLocationCet;
|
|
|
+ private TextView mResultTv;
|
|
|
+ private Button mConfirmButton;
|
|
|
+ private ImageView mScanImageView;
|
|
|
+ private int mFocusId;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected int getLayout() {
|
|
|
+ return R.layout.fragment_barcode_info_bind;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initViews() {
|
|
|
+ FunctionActivity.setTitle("条码信息绑定");
|
|
|
+ ((FunctionActivity) mActivity).setScanIvVisible(true);
|
|
|
+
|
|
|
+ mBarcodeCet = root.findViewById(R.id.barcode_info_bind_barcode_cet);
|
|
|
+ mDcCet = root.findViewById(R.id.barcode_info_bind_dc_cet);
|
|
|
+ mLotnoCet = root.findViewById(R.id.barcode_info_bind_lotno_cet);
|
|
|
+ mLocationCet = root.findViewById(R.id.barcode_info_bind_location_cet);
|
|
|
+ mResultTv = root.findViewById(R.id.barcode_info_bind_result_tv);
|
|
|
+ mConfirmButton = root.findViewById(R.id.barcode_info_bind_confirm_btn);
|
|
|
+ mScanImageView = (ImageView) mActivity.findViewById(R.id.btn_actionbar_scan_iv);
|
|
|
+
|
|
|
+ mBarcodeCet.requestFocus();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initEvents() {
|
|
|
+ mScanImageView.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (CameraUtil.hasCamera()) {
|
|
|
+ if (root.findFocus() != null) {
|
|
|
+ mFocusId = root.findFocus().getId();
|
|
|
+ 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(mBarcodeCet, new MyEditorActionListener() {
|
|
|
+ @Override
|
|
|
+ public void MyEditorAction(String text, int actionId, KeyEvent event) {
|
|
|
+ if (TextUtils.isEmpty(text)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ barcodeParse(text);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ mBarcodeCet.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
|
|
+ @Override
|
|
|
+ public void onFocusChange(View v, boolean hasFocus) {
|
|
|
+ String barcode = mBarcodeCet.getText().toString().trim();
|
|
|
+ if (!TextUtils.isEmpty(barcode)) {
|
|
|
+ barcodeParse(barcode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ mConfirmButton.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ String barcode = mBarcodeCet.getText().toString().trim();
|
|
|
+ String dc = mDcCet.getText().toString().trim();
|
|
|
+ String lotno = mLotnoCet.getText().toString().trim();
|
|
|
+ String location = mLocationCet.getText().toString().trim();
|
|
|
+
|
|
|
+ if (TextUtils.isEmpty(barcode)) {
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, "请采集条码");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (TextUtils.isEmpty(dc) && TextUtils.isEmpty(lotno) && TextUtils.isEmpty(location)) {
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, "请采集您要绑定的信息");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ progressDialog.show();
|
|
|
+ VollyRequest.getInstance().stringRequest(new HttpParams.Builder()
|
|
|
+ .url(GloableParams.ADDRESS_PDAIOIN_BARCODEINFOBIND)
|
|
|
+ .method(Request.Method.POST)
|
|
|
+ .flag(0)
|
|
|
+ .tag(TAG + "barcodeinfo")
|
|
|
+ .addParam("barcode", barcode)
|
|
|
+ .addParam("dc", dc)
|
|
|
+ .addParam("lotno", lotno)
|
|
|
+ .addParam("location", location)
|
|
|
+ .build(), new HttpCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(int flag, Object o) throws Exception {
|
|
|
+ progressDialog.dismiss();
|
|
|
+ reset();
|
|
|
+ try {
|
|
|
+ String result = o.toString();
|
|
|
+ JSONObject resultObject = JSON.parseObject(result);
|
|
|
+ JSONObject dataObject = resultObject.getJSONObject("data");
|
|
|
+ if (dataObject != null) {
|
|
|
+ mResultTv.setVisibility(View.VISIBLE);
|
|
|
+
|
|
|
+ mResultTv.setVisibility(View.VISIBLE);
|
|
|
+ mResultTv.setText("条码信息绑定成功\n条码:" + barcode
|
|
|
+ + "\nLOTNO:" + FastjsonUtil.getText(dataObject, "BAR_VENDBARCODE")
|
|
|
+ + "\nDC:" + FastjsonUtil.getText(dataObject, "BAR_MADE")
|
|
|
+ + "\n库位:" + FastjsonUtil.getText(dataObject, "BAR_LOCATION"));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFail(int flag, String failStr) throws Exception {
|
|
|
+ progressDialog.dismiss();
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, failStr);
|
|
|
+ mResultTv.setVisibility(View.VISIBLE);
|
|
|
+ mResultTv.setText(failStr);
|
|
|
+
|
|
|
+ reset();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void barcodeParse(String text) {
|
|
|
+ progressDialog.show();
|
|
|
+ VollyRequest.getInstance().stringRequest(new HttpParams.Builder()
|
|
|
+ .url(GloableParams.ADDRESS_PDAIO_IN_GETBARCODEINFORMATION)
|
|
|
+ .method(Request.Method.GET)
|
|
|
+ .tag(TAG + "barcodeinfo")
|
|
|
+ .flag(0)
|
|
|
+ .addParam("barcode", text)
|
|
|
+ .build(), new HttpCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(int flag, Object o) throws Exception {
|
|
|
+ progressDialog.dismiss();
|
|
|
+
|
|
|
+ try {
|
|
|
+ String result = o.toString();
|
|
|
+ JSONObject resultObject = JSON.parseObject(result);
|
|
|
+ JSONObject dataObject = resultObject.getJSONObject("data");
|
|
|
+ if (dataObject != null) {
|
|
|
+ mLotnoCet.setText(FastjsonUtil.getText(dataObject, "BAR_VENDBARCODE"));
|
|
|
+ mDcCet.setText(FastjsonUtil.getText(dataObject, "BAR_MADE"));
|
|
|
+ mLocationCet.setText(FastjsonUtil.getText(dataObject, "BAR_LOCATION"));
|
|
|
+
|
|
|
+ mResultTv.setVisibility(View.VISIBLE);
|
|
|
+ mResultTv.setText("条码信息获取成功!\n"
|
|
|
+ + "条码:" + FastjsonUtil.getText(dataObject, "BAR_CODE")
|
|
|
+ + "\n规格:" + FastjsonUtil.getText(dataObject, "PR_SPEC")
|
|
|
+ + "\n数量:" + FastjsonUtil.getText(dataObject, "BAR_REMAIN")
|
|
|
+ + " 库位:" + FastjsonUtil.getText(dataObject, "BAR_LOCATION")
|
|
|
+ + "\nLOTNO:" + FastjsonUtil.getText(dataObject, "BAR_VENDBARCODE")
|
|
|
+ + " DC:" + FastjsonUtil.getText(dataObject, "BAR_MADE")
|
|
|
+ + "\n品牌:" + FastjsonUtil.getText(dataObject, "BAR_BRAND"));
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFail(int flag, String failStr) throws Exception {
|
|
|
+ progressDialog.dismiss();
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, failStr);
|
|
|
+ mResultTv.setVisibility(View.VISIBLE);
|
|
|
+ mResultTv.setText(failStr);
|
|
|
+
|
|
|
+ mBarcodeCet.setText("");
|
|
|
+ mBarcodeCet.requestFocus();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void reset() {
|
|
|
+ mBarcodeCet.setText("");
|
|
|
+ mDcCet.setText("");
|
|
|
+ mLotnoCet.setText("");
|
|
|
+ mLocationCet.setText("");
|
|
|
+ mBarcodeCet.requestFocus();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initDatas() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @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);
|
|
|
+ if (mFocusId == R.id.barcode_info_bind_barcode_cet) {
|
|
|
+ mBarcodeCet.setText(result);
|
|
|
+ mBarcodeCet.setSelection(result.length());
|
|
|
+ } else if (mFocusId == R.id.barcode_info_bind_dc_cet) {
|
|
|
+ mDcCet.setText(result);
|
|
|
+ mDcCet.setSelection(result.length());
|
|
|
+ } else if (mFocusId == R.id.barcode_info_bind_lotno_cet) {
|
|
|
+ mLotnoCet.setText(result);
|
|
|
+ mLotnoCet.setSelection(result.length());
|
|
|
+ } else if (mFocusId == R.id.barcode_info_bind_location_cet) {
|
|
|
+ mLocationCet.setText(result);
|
|
|
+ mLocationCet.setSelection(result.length());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onHiddenChanged(boolean hidden) {
|
|
|
+ super.onHiddenChanged(hidden);
|
|
|
+ if (!hidden) {
|
|
|
+ FunctionActivity.setTitle("条码信息绑定");
|
|
|
+ ((FunctionActivity) mActivity).setScanIvVisible(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onDestroyView() {
|
|
|
+ super.onDestroyView();
|
|
|
+ ((FunctionActivity) mActivity).setScanIvVisible(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onFragmentBackPressed() {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+}
|