|
|
@@ -0,0 +1,229 @@
|
|
|
+package com.uas.chishun_wms.fragment;
|
|
|
+
|
|
|
+import android.app.Activity;
|
|
|
+import android.content.Intent;
|
|
|
+import android.view.KeyEvent;
|
|
|
+import android.view.View;
|
|
|
+import android.view.inputmethod.EditorInfo;
|
|
|
+import android.widget.Button;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.android.volley.Request;
|
|
|
+import com.android.volley.toolbox.StringRequest;
|
|
|
+import com.uas.chishun_wms.R;
|
|
|
+import com.uas.chishun_wms.activity.FunctionActivity;
|
|
|
+import com.uas.chishun_wms.global.GloableParams;
|
|
|
+import com.uas.chishun_wms.util.CameraUtil;
|
|
|
+import com.uas.chishun_wms.util.CommonUtil;
|
|
|
+import com.uas.chishun_wms.util.FastjsonUtil;
|
|
|
+import com.uas.chishun_wms.util.HttpCallback;
|
|
|
+import com.uas.chishun_wms.util.HttpParams;
|
|
|
+import com.uas.chishun_wms.util.VollyRequest;
|
|
|
+import com.uas.chishun_wms.view.ClearableEditText;
|
|
|
+import com.uuzuche.lib_zxing.activity.CaptureActivity;
|
|
|
+import com.uuzuche.lib_zxing.activity.CodeUtils;
|
|
|
+
|
|
|
+import org.json.JSONObject;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @note:库位上架
|
|
|
+ */
|
|
|
+public class WarehouseLocationOnShelfFragment extends BaseFragment {
|
|
|
+ private static final int SCAN_BARCODE_CODE = 102;
|
|
|
+ private ClearableEditText cet_outbox;
|
|
|
+ private ClearableEditText cet_newlocation;
|
|
|
+ private TextView tv_result;
|
|
|
+ private Button bt_transfer;
|
|
|
+ private ImageView mScanImageView;
|
|
|
+ private int mFocusId;
|
|
|
+ private StringRequest mStringRequest;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected int getLayout() {
|
|
|
+ return R.layout.fragment_warehouse_location_on_shelf;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initViews() {
|
|
|
+ ((FunctionActivity) mActivity).setScanIvVisible(true);
|
|
|
+ cet_outbox = root.findViewById(R.id.cet_outbox);
|
|
|
+ cet_newlocation = root.findViewById(R.id.cet_newlocation);
|
|
|
+ tv_result = root.findViewById(R.id.tv_result);
|
|
|
+ bt_transfer = root.findViewById(R.id.bt_transfer);
|
|
|
+
|
|
|
+ mScanImageView = (ImageView) mActivity.findViewById(R.id.btn_actionbar_scan_iv);
|
|
|
+
|
|
|
+ cet_outbox.requestFocus();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initEvents() {
|
|
|
+ cet_outbox.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
|
|
+ @Override
|
|
|
+ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
|
|
+ if (actionId == EditorInfo.IME_ACTION_DONE
|
|
|
+ || actionId == EditorInfo.IME_ACTION_SEND
|
|
|
+ || actionId == EditorInfo.IME_ACTION_GO
|
|
|
+ || (event != null && event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
|
|
|
+ getBarcodeAnalysis();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ 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));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ bt_transfer.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ getTransferData();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getBarcodeAnalysis() {
|
|
|
+ progressDialog.show();
|
|
|
+ VollyRequest.getInstance().stringRequest(mStringRequest,
|
|
|
+ new HttpParams.Builder()
|
|
|
+ .url(GloableParams.ADDRESS_BARCODE_ANALYSIS)
|
|
|
+ .method(Request.Method.GET)
|
|
|
+ .tag(TAG + "getTransferData")
|
|
|
+ .flag(0)
|
|
|
+ .addParam("barcode", cet_outbox.getText().toString().trim())
|
|
|
+ .build(), new HttpCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(int flag, Object o) throws Exception {
|
|
|
+ try {
|
|
|
+ progressDialog.dismiss();
|
|
|
+ String s = o.toString();
|
|
|
+ Boolean isSuccess = FastjsonUtil.getBoolean(o.toString(), "success");
|
|
|
+ if (isSuccess) {
|
|
|
+ JSONObject jsonObject = new JSONObject(s);
|
|
|
+ JSONObject dataObject = jsonObject.optJSONObject("data");
|
|
|
+ if (dataObject != null) {
|
|
|
+ String tip = dataObject.getString("tip");
|
|
|
+ tv_result.setText(tip);
|
|
|
+ }else {
|
|
|
+ JSONObject exceptionInfo = jsonObject.optJSONObject("exceptionInfo");
|
|
|
+ if (exceptionInfo != null) {
|
|
|
+ String exceptionInfo1 = dataObject.getString("exceptionInfo");
|
|
|
+ tv_result.setText(exceptionInfo1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFail(int flag, String failStr) throws Exception {
|
|
|
+ progressDialog.dismiss();
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, failStr);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getTransferData() {
|
|
|
+ progressDialog.show();
|
|
|
+ VollyRequest.getInstance().stringRequest(mStringRequest,
|
|
|
+ new HttpParams.Builder()
|
|
|
+ .url(GloableParams.ADDRESS_WAREHOUSE_LOCATION_ON_SHELF)
|
|
|
+ .method(Request.Method.POST)
|
|
|
+ .tag(TAG + "getTransferData")
|
|
|
+ .flag(0)
|
|
|
+ .addParam("barcode", cet_outbox.getText().toString().trim())
|
|
|
+ .addParam("location", cet_newlocation.getText().toString().trim())
|
|
|
+ .build(), new HttpCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(int flag, Object o) throws Exception {
|
|
|
+ try {
|
|
|
+ progressDialog.dismiss();
|
|
|
+ String s = o.toString();
|
|
|
+ Boolean isSuccess = FastjsonUtil.getBoolean(o.toString(), "success");
|
|
|
+ if (isSuccess) {
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, "转移成功");
|
|
|
+ // JSONObject jsonObject = new JSONObject(s);
|
|
|
+ // JSONObject dataObject = jsonObject.optJSONObject("data");
|
|
|
+ // if (dataObject == null) {
|
|
|
+ // CommonUtil.toastNoRepeat(mActivity, "转移数据获取失败!");
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFail(int flag, String failStr) throws Exception {
|
|
|
+ progressDialog.dismiss();
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, failStr);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initDatas() {
|
|
|
+ //->Actionbar
|
|
|
+ ((TextView) (getActivity().findViewById(R.id.tv_actionbar_withback))).setText(R.string.warehouse_location_on_shelf);
|
|
|
+ }
|
|
|
+
|
|
|
+ @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.cet_outbox) {
|
|
|
+ cet_outbox.setText(result);
|
|
|
+ cet_outbox.setSelection(result.length());
|
|
|
+ } else if (mFocusId == R.id.cet_newlocation) {
|
|
|
+ cet_newlocation.setText(result);
|
|
|
+ cet_newlocation.setSelection(result.length());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @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;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|