|
|
@@ -1,121 +1,192 @@
|
|
|
package com.uas.pda_smart_com.fragment;
|
|
|
|
|
|
|
|
|
-import android.content.Context;
|
|
|
-import android.util.Log;
|
|
|
+import android.app.Activity;
|
|
|
+import android.content.Intent;
|
|
|
+import android.os.Build;
|
|
|
+import android.os.Handler;
|
|
|
+import android.os.Message;
|
|
|
+import android.support.annotation.RequiresApi;
|
|
|
+import android.text.Editable;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.text.TextWatcher;
|
|
|
import android.view.KeyEvent;
|
|
|
import android.view.View;
|
|
|
-import android.view.inputmethod.InputMethodManager;
|
|
|
+import android.view.inputmethod.EditorInfo;
|
|
|
import android.widget.Button;
|
|
|
-import android.widget.EditText;
|
|
|
+import android.widget.ImageView;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
+import com.android.volley.AuthFailureError;
|
|
|
+import com.android.volley.DefaultRetryPolicy;
|
|
|
+import com.android.volley.Request;
|
|
|
+import com.android.volley.Response;
|
|
|
+import com.android.volley.VolleyError;
|
|
|
+import com.android.volley.toolbox.StringRequest;
|
|
|
import com.uas.pda_smart_com.R;
|
|
|
+import com.uas.pda_smart_com.activity.FunctionActivity;
|
|
|
+import com.uas.pda_smart_com.application.PdaApplication;
|
|
|
import com.uas.pda_smart_com.global.GloableParams;
|
|
|
import com.uas.pda_smart_com.tools.VolleyUtil;
|
|
|
+import com.uas.pda_smart_com.util.CameraUtil;
|
|
|
+import com.uas.pda_smart_com.util.CommonUtil;
|
|
|
+import com.uas.pda_smart_com.util.JsonUtils;
|
|
|
import com.uas.pda_smart_com.view.ClearableEditText;
|
|
|
+import com.uuzuche.lib_zxing.activity.CaptureActivity;
|
|
|
+import com.uuzuche.lib_zxing.activity.CodeUtils;
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
/**
|
|
|
* @note:尾料还仓
|
|
|
*/
|
|
|
-public class SCTailingBackFragment extends BaseFragment implements View.OnClickListener, VolleyUtil.VolleyFinishListener {
|
|
|
- ClearableEditText etBarcode,etRemainqty,etLocation;
|
|
|
- TextView tvProcode;
|
|
|
- TextView tvTitle,tvContent;
|
|
|
+public class SCTailingBackFragment extends BaseFragment {
|
|
|
+ private ImageView mScanImageView;
|
|
|
+ private ClearableEditText et_bar_code;
|
|
|
+ private TextView tv_liao_num;
|
|
|
+ private ClearableEditText edit_num;
|
|
|
+ private Button btn_confirm;
|
|
|
+ private TextView tv_msg;
|
|
|
+ private static final int SCAN_BARCODE_CODE = 201;
|
|
|
+ private int mFocusId;
|
|
|
+ private StringRequest mStringRequest;
|
|
|
+ private String currentBarcode;
|
|
|
int requestType = -1;
|
|
|
- int rightColor,errorColor;
|
|
|
- private Button btnOk;
|
|
|
-
|
|
|
@Override
|
|
|
protected int getLayout() {
|
|
|
return R.layout.fragment_scmake_tailback;
|
|
|
}
|
|
|
|
|
|
+ @RequiresApi(api = Build.VERSION_CODES.CUPCAKE)
|
|
|
@Override
|
|
|
protected void initViews() {
|
|
|
- //->采集信息
|
|
|
- etBarcode = (ClearableEditText) root.findViewById(R.id.et_barcode_tailback_scmake);
|
|
|
- etRemainqty = (ClearableEditText) root.findViewById(R.id.et_remainqty_tailback_scmake);
|
|
|
- etLocation = (ClearableEditText) root.findViewById(R.id.et_location_tailback_scmake);
|
|
|
- tvProcode = (TextView) root.findViewById(R.id.tv_procode_tailback_scmake);
|
|
|
- btnOk = (Button) root.findViewById(R.id.btn_collect_tailback);
|
|
|
- //->提示信息
|
|
|
- tvTitle = (TextView) root.findViewById(R.id.tv_innernotice_msgtitle_scmake);
|
|
|
- tvContent = (TextView) root.findViewById(R.id.tv_innernotice_1_scmake);
|
|
|
-
|
|
|
- //接口回调
|
|
|
- VolleyUtil.getVolleyUtil().setOnVolleyFinishListener(this);
|
|
|
+ ((FunctionActivity) getActivity()).setScanIvVisible(true);
|
|
|
+ mScanImageView = (ImageView) mActivity.findViewById(R.id.btn_actionbar_scan_iv);
|
|
|
+ et_bar_code=root.findViewById(R.id.et_bar_code);
|
|
|
+ tv_liao_num=root.findViewById(R.id.tv_liao_num);
|
|
|
+ edit_num=root.findViewById(R.id.edit_num);
|
|
|
+ btn_confirm=root.findViewById(R.id.btn_confirm);
|
|
|
+ tv_msg=root.findViewById(R.id.tv_msg);
|
|
|
+ et_bar_code.requestFocus();
|
|
|
+ VolleyUtil.setVolleyHandler(new Handler(new Handler.Callback() {
|
|
|
+ @Override
|
|
|
+ public boolean handleMessage(Message msg) {
|
|
|
+ progressDialog.dismiss();
|
|
|
+ switch (msg.what) {
|
|
|
+ //连接成功
|
|
|
+ case VolleyUtil.SUCCESS_SUCCESS:
|
|
|
+ try {
|
|
|
+ JSONObject resultJson = new JSONObject(msg.obj.toString());
|
|
|
+ boolean isOk=resultJson.optBoolean("success");
|
|
|
+ if(isOk){
|
|
|
+ tv_msg.setVisibility(View.VISIBLE);
|
|
|
+ tv_msg.setText("还仓成功");
|
|
|
+ et_bar_code.setText("");
|
|
|
+ tv_liao_num.setText("");
|
|
|
+ edit_num.setText("");
|
|
|
+ }else{
|
|
|
+ tv_msg.setVisibility(View.VISIBLE);
|
|
|
+ tv_msg.setText("还仓失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case VolleyUtil.FAILED_FAILED:
|
|
|
+ tv_msg.setVisibility(View.VISIBLE);
|
|
|
+ tv_msg.setText("还仓失败");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }));
|
|
|
}
|
|
|
|
|
|
+ @RequiresApi(api = Build.VERSION_CODES.CUPCAKE)
|
|
|
@Override
|
|
|
protected void initEvents() {
|
|
|
- etBarcode.setOnKeyListener(new View.OnKeyListener() {
|
|
|
+ et_bar_code.addTextChangedListener(new TextWatcher() {
|
|
|
@Override
|
|
|
- public boolean onKey(View v, int keyCode, KeyEvent event) {
|
|
|
- if(keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP){
|
|
|
- disposeBarcodeEnter();
|
|
|
- return true;
|
|
|
+ public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void afterTextChanged(Editable editable) {
|
|
|
+ if (editable.length() == 0) {
|
|
|
+ btn_confirm.setEnabled(false);
|
|
|
+ } else {
|
|
|
+ btn_confirm.setEnabled(true);
|
|
|
}
|
|
|
- return false;
|
|
|
}
|
|
|
});
|
|
|
- /*etBarcode.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
|
|
+
|
|
|
+ et_bar_code.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
|
|
@Override
|
|
|
- public void onFocusChange(View view, boolean b) {
|
|
|
- if (TextUtils.isEmpty(etBarcode.getText())) {
|
|
|
- disposeBarcodeEnter();
|
|
|
+ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
|
|
+ if (actionId == EditorInfo.IME_ACTION_SEND
|
|
|
+ || actionId == EditorInfo.IME_ACTION_DONE
|
|
|
+ || (event != null && event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
|
|
|
+ confirmEvent();
|
|
|
+ return true;
|
|
|
}
|
|
|
-
|
|
|
+ return false;
|
|
|
}
|
|
|
- });*/
|
|
|
- btnOk.setOnClickListener(this);
|
|
|
- }
|
|
|
+ });
|
|
|
|
|
|
- @Override
|
|
|
- protected void initDatas() {
|
|
|
- //->Actionbar
|
|
|
- ((TextView) (getActivity().findViewById(R.id.tv_actionbar_withback))).setText(R.string.title_tailback_smt);
|
|
|
- rightColor = getResources().getColor(R.color.green);
|
|
|
- errorColor = getResources().getColor(R.color.text_error);
|
|
|
- editTextGetFocus(etBarcode);
|
|
|
- }
|
|
|
+ btn_confirm.setOnClickListener(v -> {
|
|
|
+ confirmBarOut();
|
|
|
+ });
|
|
|
+ mScanImageView.setOnClickListener(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));
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public void onDestroy() {
|
|
|
- hideKeyboard(etLocation);
|
|
|
- VolleyUtil.distoryVolley();
|
|
|
- super.onDestroy();
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- //条码采集框回车事件
|
|
|
- private void disposeBarcodeEnter(){
|
|
|
- String bar_code = etBarcode.getText().toString().trim();
|
|
|
- if(bar_code.equals("") || bar_code == null){
|
|
|
- etBarcode.setWarnIconVisible();
|
|
|
+ /***
|
|
|
+ * 确定按钮触发
|
|
|
+ */
|
|
|
+ private void confirmBarOut(){
|
|
|
+ currentBarcode = et_bar_code.getText().toString().trim();
|
|
|
+ String inputNum=edit_num.getText().toString().trim();
|
|
|
+ int qty;
|
|
|
+ try {
|
|
|
+ qty= Integer.parseInt(inputNum);
|
|
|
+ }catch (Exception e){
|
|
|
+ qty=0;
|
|
|
+ }
|
|
|
+ if(TextUtils.isEmpty(currentBarcode)){
|
|
|
+ CommonUtil.toastNoRepeat(mActivity,"请采集条码");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(qty<=0){
|
|
|
+ CommonUtil.toastNoRepeat(mActivity,"预计剩余数量必须大于0");
|
|
|
return;
|
|
|
}
|
|
|
- //请求服务器获取信息
|
|
|
- requestType = VolleyUtil.FRAGMENT_SCMAKE_DETAIL_TAILBACK;
|
|
|
- showLoadingView();
|
|
|
- VolleyUtil.getVolleyUtil().requestTailBack(getActivity(), GloableParams.ADDRESS_TAILBACK_DETAIL_APPLY, VolleyUtil.METHOD_GET,
|
|
|
- requestType, bar_code);
|
|
|
- }
|
|
|
- //确认按钮点击事件
|
|
|
- String bar_code;
|
|
|
- private void disposeOnclice(){
|
|
|
- bar_code = etBarcode.getText().toString().trim();
|
|
|
- String bar_prodcode = tvProcode.getText().toString().trim();
|
|
|
- String bar_fremain = etRemainqty.getText().toString().trim();
|
|
|
- String bar_location = etLocation.getText().toString().trim();
|
|
|
JSONObject paramJson = new JSONObject();
|
|
|
try {
|
|
|
- paramJson.put("bar_code",bar_code);
|
|
|
- paramJson.put("bar_prodcode",bar_prodcode);
|
|
|
- paramJson.put("bar_fremain",bar_fremain);
|
|
|
- paramJson.put("bar_location",bar_location);
|
|
|
+ paramJson.put("bar_code",currentBarcode);
|
|
|
+ paramJson.put("bar_fremain",qty+"");
|
|
|
} catch (JSONException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
@@ -123,56 +194,105 @@ public class SCTailingBackFragment extends BaseFragment implements View.OnClickL
|
|
|
showLoadingView();
|
|
|
VolleyUtil.getVolleyUtil().requestJsonObject(getActivity(), GloableParams.ADDRESS_TAILBACK_OK_APPLY, VolleyUtil.METHOD_POST,
|
|
|
requestType, paramJson);
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- //Volley失败
|
|
|
- private void disposeVolleyFailed(Object msg){
|
|
|
- String title = getString(R.string.notice_tailback_failed);
|
|
|
- String content = (String) msg;
|
|
|
- setNotice(title,content,errorColor);
|
|
|
+ private void confirmEvent() {
|
|
|
+ currentBarcode = et_bar_code.getText().toString().trim();
|
|
|
+ if (TextUtils.isEmpty(currentBarcode)) {
|
|
|
+ CommonUtil.toastNoRepeat(getActivity(), "请采集条码");
|
|
|
+ }else {
|
|
|
+ if (CommonUtil.isNetWorkConnected(getActivity())) {
|
|
|
+ barcodeEnterEvent();
|
|
|
+ } else {
|
|
|
+ CommonUtil.toastNoRepeat(getActivity(), getResources().getString(R.string.str_net_not_connect));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- //Volley获取详细信息
|
|
|
- private void disposeDetailSuccess(Object msg){
|
|
|
- tvTitle.setText("");
|
|
|
- tvContent.setText("");
|
|
|
- String result = (String) msg;
|
|
|
- String bar_prodcode, bar_fremain,bar_location;
|
|
|
+ /**
|
|
|
+ * 解析条码
|
|
|
+ */
|
|
|
+ private void barcodeEnterEvent() {
|
|
|
+ String url = null;
|
|
|
try {
|
|
|
- JSONObject resultJson = new JSONObject(result);
|
|
|
- JSONObject msgJson = resultJson.getJSONObject("message");
|
|
|
- bar_prodcode = msgJson.getString("bar_prodcode");
|
|
|
- bar_fremain = msgJson.getString("bar_forcastremain");
|
|
|
- bar_location = msgJson.getString("bar_location");
|
|
|
- etLocation.setText(bar_location);
|
|
|
- etRemainqty.setText(bar_fremain);
|
|
|
- tvProcode.setText(bar_prodcode);
|
|
|
- editTextGetFocus(etRemainqty);
|
|
|
- } catch (JSONException e) {
|
|
|
+ url = GloableParams.ADDRESS_OUT_PARSE_BARCODE_DEAl + "?barcode=" + URLEncoder.encode(currentBarcode, "utf-8")+"&pi_id=0";
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
+ progressDialog.show();
|
|
|
+ PdaApplication.mRequestQueue.cancelAll(TAG + "parseBarcode");
|
|
|
+ mStringRequest = new StringRequest(Request.Method.GET, url,
|
|
|
+ new Response.Listener<String>() {
|
|
|
+ @Override
|
|
|
+ public void onResponse(String s) {
|
|
|
+ progressDialog.dismiss();
|
|
|
+ try {
|
|
|
+ JSONObject resultJsonObject = new JSONObject(s);
|
|
|
+ boolean isSuccess=resultJsonObject.getBoolean("success");
|
|
|
+ if(isSuccess){
|
|
|
+ JSONObject dataObject = resultJsonObject.getJSONObject("data");
|
|
|
+ String barcode = JsonUtils.optStringNotNull(dataObject, "barcode");//条码号
|
|
|
+ String qty = JsonUtils.optStringNotNull(dataObject, "QTY");
|
|
|
+ String pn = JsonUtils.optStringNotNull(dataObject, "PN");
|
|
|
+ String mpn = JsonUtils.optStringNotNull(dataObject, "MPN");
|
|
|
+ String lot = JsonUtils.optStringNotNull(dataObject, "LOT");
|
|
|
+ String id = JsonUtils.optStringNotNull(dataObject, "ID");
|
|
|
+ tv_liao_num.setText(pn);//料号
|
|
|
+ //edit_num.setText(qty);//剩余数量
|
|
|
+
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ new Response.ErrorListener() {
|
|
|
+ @Override
|
|
|
+ public void onErrorResponse(VolleyError volleyError) {
|
|
|
+ progressDialog.dismiss();
|
|
|
+ tv_msg.setText(CommonUtil.showErrorToast(volleyError));
|
|
|
+
|
|
|
+ }
|
|
|
+ }) {
|
|
|
+ @Override
|
|
|
+ public Map<String, String> getHeaders() throws AuthFailureError {
|
|
|
+ return VolleyUtil.getVolleyUtil().setCookies();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ mStringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000, 0, 1f));
|
|
|
+ mStringRequest.setTag(TAG + "parseBarcode");
|
|
|
+ PdaApplication.mRequestQueue.add(mStringRequest);
|
|
|
+
|
|
|
}
|
|
|
- //Volley响应成功函数
|
|
|
- private void disposeVolleySuccess(Object msg){
|
|
|
- switch (requestType){
|
|
|
- case VolleyUtil.FRAGMENT_SCMAKE_DETAIL_TAILBACK:
|
|
|
- disposeDetailSuccess(msg);
|
|
|
- break;
|
|
|
- case VolleyUtil.FRAGMENT_SCMAKE_OK_TAILBACK:
|
|
|
- disposeTailbackSuccess(msg);
|
|
|
- break;
|
|
|
+ @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.et_bar_code) {
|
|
|
+ et_bar_code.setText(result);
|
|
|
+ et_bar_code.setSelection(result.length());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initDatas() {
|
|
|
+ ((TextView) (getActivity().findViewById(R.id.tv_actionbar_withback))).setText(R.string.title_tailback_smt);
|
|
|
}
|
|
|
|
|
|
- //还仓成功
|
|
|
- private void disposeTailbackSuccess(Object msg){
|
|
|
- String title = getString(R.string.notice_tailback_success);
|
|
|
- String content = getString(R.string.content_tailback_success);
|
|
|
- content = content.replaceAll("replace",bar_code);
|
|
|
- setNotice(title,content,rightColor);
|
|
|
+ @Override
|
|
|
+ public void onDestroy() {
|
|
|
+ super.onDestroy();
|
|
|
+ ((FunctionActivity) getActivity()).setScanIvVisible(false);
|
|
|
}
|
|
|
- /*=============================公用方法===================================*/
|
|
|
+
|
|
|
/**
|
|
|
* 显示loadingView
|
|
|
*/
|
|
|
@@ -181,69 +301,9 @@ public class SCTailingBackFragment extends BaseFragment implements View.OnClickL
|
|
|
progressDialog.show();
|
|
|
}
|
|
|
}
|
|
|
- /**
|
|
|
- * 获取输入框焦点
|
|
|
- */
|
|
|
- private void editTextGetFocus(EditText editText) {
|
|
|
- editText.setFocusable(true);
|
|
|
- editText.setFocusableInTouchMode(true);
|
|
|
- editText.setEnabled(true);
|
|
|
- editText.setClickable(true);
|
|
|
- editText.requestFocus();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 键盘
|
|
|
- */
|
|
|
- InputMethodManager inputManager;
|
|
|
- private void hideKeyboard(final EditText view) {
|
|
|
- inputManager = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
- //获取键盘管理对象
|
|
|
- inputManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
|
|
- }
|
|
|
- /**
|
|
|
- * 设置提示信息*/
|
|
|
- private void setNotice(String title, String content, int pid){
|
|
|
- tvTitle.setText(title);
|
|
|
- tvTitle.setTextColor(pid);
|
|
|
- tvContent.setText(content);
|
|
|
- etLocation.setText("");
|
|
|
- etBarcode.setText("");
|
|
|
- etRemainqty.setText("");
|
|
|
- tvProcode.setText("");
|
|
|
- editTextGetFocus(etBarcode);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- disposeOnclice();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onVolleyFinish(int isSuccess, Object result) {
|
|
|
- Log.e("Error!!!","error1");
|
|
|
- switch (isSuccess){
|
|
|
- case VolleyUtil.SUCCESS_SUCCESS:
|
|
|
- disposeVolleySuccess(result);
|
|
|
- break;
|
|
|
- case VolleyUtil.FAILED_FAILED:
|
|
|
- Log.e("Error!!!","error2");
|
|
|
- disposeVolleyFailed(result);
|
|
|
- break;
|
|
|
- }
|
|
|
- progressDialog.dismiss();
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
- if(keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
|
|
|
- if (progressDialog!=null && progressDialog.isShowing()) {
|
|
|
- //网络请求操作不可撤回
|
|
|
-// loadingView.dismiss();
|
|
|
-// VolleyUtil.distoryVolley();
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
return false;
|
|
|
}
|
|
|
|