package com.uas.uaspda.fragment; import android.content.Context; import android.os.Handler; import android.os.Message; import android.text.SpannableString; import android.text.TextUtils; import android.util.Log; import android.view.KeyEvent; import android.view.View; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; import android.widget.Button; import android.widget.EditText; import android.widget.RelativeLayout; import android.widget.TextView; import com.alibaba.fastjson.JSON; 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.uaspda.R; import com.uas.uaspda.application.PdaApplication; import com.uas.uaspda.bean.LineInfoBean; import com.uas.uaspda.bean.SmtDslBean; import com.uas.uaspda.global.GloableParams; import com.uas.uaspda.tools.SharedPreUtil; import com.uas.uaspda.tools.VolleyUtil; import com.uas.uaspda.util.CommonUtil; import com.uas.uaspda.util.Constants; import com.uas.uaspda.util.JsonUtils; import com.uas.uaspda.util.LogUtil; import com.uas.uaspda.util.SoundUtil; import com.uas.uaspda.view.ClearableEditText; import com.uas.uaspda.view.TextViewWithButton; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.util.HashMap; import java.util.Map; /** * SMT上料:上料子页面 * modify:2017-05-15 */ public class SCSMTInFragment extends BaseFragment implements View.OnClickListener, TextViewWithButton.TvHintHelper { private TextViewWithButton tvLocation, tvBarcode, tvRemainqty, tvFecode, mLocationTextView; private TextView tvMsgNotice, tvMsgLocation, tvMsgProdcode, tvMsgBarcode, tvMsgQuantity, tvMsgSpec; private RelativeLayout rlCollect; private JSONArray smtLocation; private JSONObject makeCraft; private TextView mLinecodeTextView, mTableTextView, mMacodeTextView; private ClearableEditText mCollectEditText; int requestType = -1; private Button btnCollect; private LineInfoBean mLineInfoBean; private String mSmtLocationCache; private SmtDslBean mSmtDslBean = new SmtDslBean(); private StringRequest mStringRequest; private String mNoticeStr = ""; @Override protected int getLayout() { return R.layout.fragment_scmake_smtfeederchild_in; } @Override protected void initViews() { //获取组件 //->采集信息 btnCollect = (Button) root.findViewById(R.id.btn_collect_smtchildin); tvLocation = (TextViewWithButton) root.findViewById(R.id.tv_innernotice_location_smtchildin); tvFecode = (TextViewWithButton) root.findViewById(R.id.tv_innernotice_fecode_smtchildin); tvBarcode = (TextViewWithButton) root.findViewById(R.id.tv_innernotice_barcode_smtchildin); tvRemainqty = (TextViewWithButton) root.findViewById(R.id.tv_innernotice_remainqty_smtchildin); rlCollect = (RelativeLayout) root.findViewById(R.id.rl_innernotice_smtchildin); mLocationTextView = (TextViewWithButton) root.findViewById(R.id.smt_feeding_in_location_tv); mLinecodeTextView = (TextView) root.findViewById(R.id.smt_feeding_in_linecode_tv); mTableTextView = (TextView) root.findViewById(R.id.smt_feeding_in_table_tv); mMacodeTextView = (TextView) root.findViewById(R.id.smt_feeding_in_macode_tv); mCollectEditText = (ClearableEditText) root.findViewById(R.id.smt_feeding_in_collect_et); mCollectEditText.requestFocus(); //->提示信息 tvMsgNotice = (TextView) root.findViewById(R.id.tv_innernotice_msgtitle_scmake); tvMsgProdcode = (TextView) root.findViewById(R.id.tv_innernotice_1_scmake); tvMsgLocation = (TextView) root.findViewById(R.id.tv_innernotice_2_scmake); tvMsgBarcode = (TextView) root.findViewById(R.id.tv_innernotice_3_scmake); tvMsgQuantity = (TextView) root.findViewById(R.id.tv_innernotice_4_scmake); tvMsgSpec = (TextView) root.findViewById(R.id.tv_innernotice_5_scmake); //接口回调 VolleyUtil.setVolleyHandler(handler); mLineInfoBean = (LineInfoBean) PdaApplication.getDataCacheFromMap(Constants.FLAG.SMT_DEVICE_LINE_CACHE); // JSONObject paramJson = new JSONObject(); // try { // makeCraft = new JSONObject(makeCraftStr); // String ps_id = makeCraft.get("ps_id").toString(); // String mcjob = makeCraft.get("mc_prodcode").toString(); // paramJson.put("ps_id", ps_id); // paramJson.put("prodcode", mcjob); // } catch (JSONException e) { // e.printStackTrace(); // } // Log.e("SMTINCHILD", "makecraft" + makeCraft.toString()); // //获取网络数据 // showLoadingView(); // requestType = VolleyUtil.FRAGMENT_SCMAKE_SMTINDETAIL; // VolleyUtil.getVolleyUtil().requestJsonObject(getActivity(), GloableParams.ADDRESS_SMTDETAIL_APPLY, VolleyUtil.METHOD_POST, // VolleyUtil.FRAGMENT_SCMAKE_SMTINDETAIL, paramJson); } @Override protected void initEvents() { tvLocation.setTvHintHelper(this); tvBarcode.setTvHintHelper(this); tvRemainqty.setTvHintHelper(this); tvFecode.setTvHintHelper(this); mLocationTextView.setTvHintHelper(this); btnCollect.setOnClickListener(this); mCollectEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { String collect = mCollectEditText.getText().toString().trim(); if (!TextUtils.isEmpty(collect)) { if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_SEND || (event != null && event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) { confirmEvent(collect); return true; } } return false; } }); mLocationTextView.setOnTextClearListener(new TextViewWithButton.OnTextClearListener() { @Override public void onTextClear() { mCollectEditText.setHint("请录入站位编号"); mCollectEditText.setText(""); // tvMsgNotice.setText(""); // tvMsgProdcode.setText(""); // tvMsgLocation.setText(""); // tvMsgBarcode.setText(""); // tvMsgQuantity.setText(""); // tvMsgSpec.setText(""); } }); } private void confirmEvent(String collect) { String location = mLocationTextView.getText().toString().trim(); if (TextUtils.isEmpty(location)) { locationCheck(collect); } else { /* mSmtDslBean.setDsl_barcode(collect); String dsl_repcode = mSmtDslBean.getDsl_repcode(); if (!TextUtils.isEmpty(dsl_repcode)) { boolean isExist = false; String[] repcodes = dsl_repcode.split(","); for (int j = 0; j < repcodes.length; j++) { String repcode = repcodes[j]; if (repcode != null && repcode.equals(collect)) { isExist = true; } } if (isExist) { } else { //上料操作 feedLoading(); } } else {*/ mSmtDslBean.setDsl_fecode(collect); feedLoading(); // } } } /** * 站位本地校验 * * @param collect 采集框采集内容 */ private void locationCheck(String collect) { tvMsgProdcode.setText(""); tvMsgLocation.setText(""); tvMsgBarcode.setText(""); tvMsgQuantity.setText(""); tvMsgSpec.setText(""); if (!TextUtils.isEmpty(mSmtLocationCache)) { try { JSONArray locationArray = new JSONArray(mSmtLocationCache); boolean isExist = false; for (int i = 0; i < locationArray.length(); i++) { JSONObject locationObject = locationArray.getJSONObject(i); if (collect.equals(JsonUtils.optStringNotNull(locationObject, "PSL_LOCATION"))) { isExist = true; mLocationTextView.setText(collect); mCollectEditText.setText(""); String psl_prodcode = JsonUtils.optStringNotNull(locationObject, "PSL_PRODCODE"); String psl_repcode = JsonUtils.optStringNotNull(locationObject, "PSL_REPCODE"); mSmtDslBean = new SmtDslBean(); mSmtDslBean.setDsl_location(collect); mSmtDslBean.setDsl_prodcode(psl_prodcode); mCollectEditText.setHint("请录入飞达编号"); if (!TextUtils.isEmpty(psl_repcode)) { // if (TextUtils.isEmpty(psl_repcode) || "null".equals(psl_repcode)) // tvMsgNotice.setText("站位采集成功,请采集首选料[" + psl_prodcode + "]的料卷编号"); // else String[] repcodes = psl_repcode.split(","); String notice = "站位采集成功,请采集物料\n"; for (int j = 0; j < repcodes.length; j++) { String repcode = repcodes[j]; notice = notice + repcode + "\n"; } notice = notice + "的料卷编号/物料编号"; tvMsgNotice.setTextColor(getResources().getColor(R.color.green)); tvMsgNotice.setText(notice); } else if (!TextUtils.isEmpty(psl_prodcode)) { tvMsgNotice.setTextColor(getResources().getColor(R.color.green)); tvMsgNotice.setText("站位采集成功,请采集物料\n" + psl_prodcode + "\n的飞达编号"); } else { tvMsgNotice.setTextColor(getResources().getColor(R.color.green)); tvMsgNotice.setText("站位采集成功,物料编号获取失败"); } } } if (!isExist) { tvMsgNotice.setTextColor(getResources().getColor(R.color.red)); String notice = "站位编号错误\n" + mNoticeStr; SpannableString spannableString = CommonUtil.spanString(notice, mActivity, "站位编号错误\n".length(), notice.length(), R.color.green); tvMsgNotice.setText(spannableString); CommonUtil.makeNotice(); mCollectEditText.setText(""); } } catch (JSONException e) { e.printStackTrace(); } } else { tvMsgNotice.setTextColor(getResources().getColor(R.color.red)); String notice = "站位编号错误\n" + mNoticeStr; SpannableString spannableString = CommonUtil.spanString(notice, mActivity, "站位编号错误\n".length(), notice.length(), R.color.green); tvMsgNotice.setText(spannableString); CommonUtil.makeNotice(); mCollectEditText.setText(""); } } /** * 站位上料 */ private void feedLoading() { progressDialog.show(); PdaApplication.mRequestQueue.cancelAll(TAG + "loading"); final String smtDsl = JSON.toJSONString(mSmtDslBean); String deviceLineMake = ""; if (mLineInfoBean != null) deviceLineMake = JSON.toJSONString(mLineInfoBean); final String finalDeviceLineMake = deviceLineMake; mStringRequest = new StringRequest(Request.Method.POST, GloableParams.ADDRESS_SMT_LOADING, new Response.Listener() { @Override public void onResponse(String s) { try { LogUtil.i("inloading", s); if (progressDialog.isShowing()) progressDialog.dismiss(); JSONObject jsonObject = new JSONObject(s); JSONObject dataObject = jsonObject.optJSONObject("data"); if (dataObject != null) { tvMsgNotice.setTextColor(getResources().getColor(R.color.green)); tvMsgNotice.setText("上料成功"); tvMsgProdcode.setText("料号:" + JsonUtils.optStringNotNull(dataObject, "DSL_PRODCODE")); tvMsgLocation.setText("位号:" + JsonUtils.optStringNotNull(dataObject, "DSL_LOCATION")); tvMsgBarcode.setText("料卷号:" + JsonUtils.optStringNotNull(dataObject, "DSL_BARCODE")); tvMsgQuantity.setText("数量:" + CommonUtil.doubleFormat(JsonUtils.optDoubleNotNull(dataObject, "DSL_REMAINQTY"))); double notCheckCount = JsonUtils.optDoubleNotNull(dataObject, "NotFeedCount"); String notice = "飞达规格:" + JsonUtils.optStringNotNull(dataObject, "DSL_FESPEC"); if (notCheckCount == 0) { notice = notice + "\n\n上料已完成"; mNoticeStr = "上料已完成"; SoundUtil.play(SoundUtil.SOUND_CERES); tvMsgSpec.setText(notice); } else { String buffer = notice; notice = notice + "\n\n未上料站位" + CommonUtil.doubleFormat(notCheckCount) + "条"; String noticeStr = "未上料站位" + CommonUtil.doubleFormat(notCheckCount) + "条"; JSONArray notFeedArray = dataObject.optJSONArray("NotFeedLocation"); if (notFeedArray != null && notFeedArray.length() != 0) { notice = notice + "\n站位:"; noticeStr = noticeStr + "\n站位:"; for (int i = 0; i < notFeedArray.length(); i++) { JSONObject notCheckObject = notFeedArray.optJSONObject(i); if (notCheckObject != null) { String psl_location = JsonUtils.optStringNotNull(notCheckObject, "PSL_LOCATION"); notice = notice + psl_location + ","; noticeStr = noticeStr + psl_location + ","; } } notice = notice.substring(0, notice.length() - 1); noticeStr = noticeStr.substring(0, noticeStr.length() - 1); } mNoticeStr = noticeStr; SpannableString spannableString = CommonUtil.spanString(notice, mActivity, (buffer + "\n\n未上料站位").length(), (buffer + "\n\n未上料站位").length() + CommonUtil.doubleFormat(notCheckCount).length(), R.color.blue_800); tvMsgSpec.setText(spannableString); } mLocationTextView.setText(""); mCollectEditText.setText(""); mSmtDslBean = new SmtDslBean(); mCollectEditText.setHint("请录入站位编号"); } } catch (JSONException e) { e.printStackTrace(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { if (progressDialog.isShowing()) progressDialog.dismiss(); String errorToast = CommonUtil.showErrorToast(volleyError, false); if (errorToast != null) { tvMsgNotice.setTextColor(getResources().getColor(R.color.red)); String errorNotice = errorToast + "\n" + mNoticeStr; SpannableString spannableString = CommonUtil.spanString(errorNotice, mActivity, (errorToast + "\n").length(), errorNotice.length(), R.color.green); tvMsgNotice.setText(spannableString); if (errorToast.contains("站位已经有在线料卷号")) { mLocationTextView.setText(""); mCollectEditText.setText(""); } else { mCollectEditText.setText(""); } } } }) { @Override protected Map getParams() throws AuthFailureError { Map params = new HashMap(); params.put("dsl", smtDsl); params.put("deviceLineMake", finalDeviceLineMake); return params; } @Override public Map getHeaders() throws AuthFailureError { return VolleyUtil.getVolleyUtil().setCookies(); } }; mStringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000, 0, 1f)); mStringRequest.setTag(TAG + "loading"); PdaApplication.mRequestQueue.add(mStringRequest); } @Override protected void initDatas() { //配置界面 ((TextView) (getActivity().findViewById(R.id.tv_actionbar_withback))).setText(R.string.title_feederin_smt); mSmtLocationCache = SharedPreUtil.getString(mActivity, Constants.FLAG.SMT_LOCATION_CACHE, null); if (mSmtLocationCache != null) { Log.d("smtLocation", mSmtLocationCache); } if (mLineInfoBean != null) { mLinecodeTextView.setText(mLineInfoBean.getDL_LINECODE()); mTableTextView.setText(mLineInfoBean.getDL_TABLE() + "面"); mMacodeTextView.setText(mLineInfoBean.getDL_MACODE()); } getUnloadingLocation(); } /** * 获取未上料站位 */ private void getUnloadingLocation() { progressDialog.show(); String url = GloableParams.ADDRESS_SMT_GET_UNLOADING_LOCATION + "?linecode=" + (mLineInfoBean == null ? "" : mLineInfoBean.getDL_LINECODE()); PdaApplication.mRequestQueue.cancelAll(TAG + "unloading"); mStringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener() { @Override public void onResponse(String s) { try { if (progressDialog.isShowing()) progressDialog.dismiss(); JSONObject resultObject = new JSONObject(s); JSONObject dataObject = resultObject.optJSONObject("data"); if (dataObject != null) { double NotFeedCount = JsonUtils.optDoubleNotNull(dataObject, "NotFeedCount"); String notice = ""; if (NotFeedCount == 0) { notice = notice + "上料已完成"; mNoticeStr = notice; SoundUtil.play(SoundUtil.SOUND_CERES); tvMsgNotice.setTextColor(getResources().getColor(R.color.green)); tvMsgNotice.setText(notice); } else { notice = notice + "未上料站位" + CommonUtil.doubleFormat(NotFeedCount) + "条"; JSONArray notFeedArray = dataObject.optJSONArray("NotFeedLocation"); if (notFeedArray != null && notFeedArray.length() != 0) { notice = notice + "\n站位:"; for (int i = 0; i < notFeedArray.length(); i++) { JSONObject notCheckObject = notFeedArray.optJSONObject(i); if (notCheckObject != null) { String psl_location = JsonUtils.optStringNotNull(notCheckObject, "PSL_LOCATION"); notice = notice + psl_location + ","; } } notice = notice.substring(0, notice.length() - 1); } mNoticeStr = notice; tvMsgNotice.setTextColor(getResources().getColor(R.color.green)); SpannableString spannableString = CommonUtil.spanString(notice, mActivity, 5, 5 + CommonUtil.doubleFormat(NotFeedCount).length(), R.color.blue_800); tvMsgNotice.setText(spannableString); } } } catch (Exception e) { } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { if (progressDialog.isShowing()) progressDialog.dismiss(); String errorToast = CommonUtil.showErrorToast(volleyError, false); tvMsgNotice.setTextColor(getResources().getColor(R.color.red)); tvMsgNotice.setText(errorToast); } }) { @Override public Map getHeaders() throws AuthFailureError { return VolleyUtil.getVolleyUtil().setCookies(); } }; mStringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000, 0, 1f)); mStringRequest.setTag(TAG + "unloading"); PdaApplication.mRequestQueue.add(mStringRequest); } @Override public void onDestroy() { VolleyUtil.distoryVolley(); super.onDestroy(); } @Override public void onDestroyView() { CommonUtil.closeKeybord(mCollectEditText, mActivity); super.onDestroyView(); } //按钮点击事件:当Location为空的时候 private void disposeOnClickLocation() { Log.e("SMTChildInOnclick", "站位为空"); String tmpLocation = null; String title = null; String content = null; int color = 0; isAgain = false; //信息框都清空 tvBarcode.setText(""); tvRemainqty.setText(""); tvFecode.setText(""); try { //比对smtLocation for (int i = 0; i < smtLocation.length(); i++) { JSONObject tmpJson = smtLocation.getJSONObject(i); tmpLocation = tmpJson.getString("psl_location").trim(); //如果匹配 if (tmpLocation.equals(code)) { Log.e("SMTCHILD", "匹配"); //显示在站位输入框,添加数据项 tvLocation.setText(tmpLocation); msl = new JSONObject(); msl.put("msl_location", code); msl.put("msl_prodcode", tmpJson.getString("psl_prodcode").trim()); msl.put("msl_repcode", tmpJson.getString("psl_repcode").trim()); // msl.put("msl_repcode","无"); msl.put("psl_id", tmpJson.getString("psl_id").trim()); msl.put("msl_fespec", tmpJson.getString("psl_feeder").trim()); //msl = smtLocation.getJSONObject(i); Log.e("SMTCHILD", msl.toString()); //更改etCollect的Hint setEtHint(); //提示框中显示信息 title = "站位采集成功"; content = "站位采集成功,请采集物料" + msl.get("msl_prodcode") + "的条码"; color = getResources().getColor(R.color.green); setNotice(title, content, color); break; } //如果不匹配 else { Log.e("SMTCHILD", "不匹配"); title = "错误"; content = getString(R.string.notice_smtchild_barcode); color = getResources().getColor(R.color.text_error); } } } catch (JSONException e) { e.printStackTrace(); } setNotice(title, content, color); } //按钮点击事件:当料卷号为空的时候 private void disposeOnClickBarcode() { Log.e("SMTChildInOnclick", "料卷为空"); //请求判断料卷编号是否正确,获取料卷数量 JSONObject paramJson = new JSONObject(); try { paramJson.put("bar_code", code); paramJson.put("prod_code", msl.getString("msl_prodcode")); paramJson.put("rep_code", msl.getString("msl_repcode")); } catch (JSONException e) { e.printStackTrace(); } showLoadingView(); requestType = VolleyUtil.FRAGMENT_SCMAKE_SMTIN_BARREMAIN; VolleyUtil.getVolleyUtil().requestJsonObject(getActivity(), GloableParams.ADDRESS_SMT_BARREMAIN_APPLY, VolleyUtil.METHOD_POST, VolleyUtil.FRAGMENT_SCMAKE_SMTIN_BARREMAIN, paramJson); } //按钮点击事件:当飞达编号为空时 private void disposeOnClickFecode() { //获取飞达编号 String fecodeStr = tvFecode.getText().toString().trim(); //->else if(msl_fecode为空),料卷号不为空,飞达编号为空时 if (fecodeStr.equals("") || fecodeStr == null) { //tvFecode.setText(code); try { msl.put("msl_fecode", code); } catch (JSONException e) { e.printStackTrace(); } //上料操作 requestType = VolleyUtil.FRAGMENT_SCMAKE_SMTIN_UPLOAD; showLoadingView(); VolleyUtil.getVolleyUtil().requestSMTInUpLoad(getActivity(), GloableParams.ADDRESS_SMTIN_UPLOAD_APPLY, VolleyUtil.METHOD_POST, requestType, msl.toString(), makeCraft.toString()); } } //扫描料卷编号成功 String mslBarcode = null, mslRemainQty = null; private void disposeBarcodeSuccess(String result) { String title, content; int color; JSONObject tmpJson, msgJson; try { tmpJson = new JSONObject(result); msgJson = tmpJson.getJSONObject("message"); //将message中的值赋值给变量msl中的值 msl.put("msl_barcode", msgJson.getString("bar_code")); msl.put("msl_prodcode", msgJson.get("bar_prodcode")); msl.put("msl_remainqty", msgJson.get("bar_remain")); mslBarcode = code; mslRemainQty = msgJson.getString("bar_remain"); //料卷编号和数量输入框显示对应的值,清空采集栏中的值 tvBarcode.setText(mslBarcode); tvRemainqty.setText(mslRemainQty); //将采集栏中的提示文字修改为“请录入飞达编号” setEtHint(); //清空提示栏信息 title = "料卷采集成功"; content = "请采集物料" + msl.get("msl_prodcode") + "的飞达编号"; color = getResources().getColor(R.color.green); setNotice(title, content, color); } catch (JSONException e) { e.printStackTrace(); } } //上料成功 private void disposeUpLoadSuccess(String result) { JSONObject msgJson; String productStr = "无", locationStr = "无", fecodeStr = "无", barcodeStr = "无", qtyStr = "无"; try { JSONObject tmpJson = new JSONObject(result); msgJson = tmpJson.getJSONObject("message"); productStr = msgJson.getString("msl_prodcode"); locationStr = msgJson.getString("msl_location"); fecodeStr = msgJson.getString("msl_fecode"); barcodeStr = msgJson.getString("msl_barcode"); qtyStr = msgJson.getString("msl_remainqty"); } catch (JSONException e) { e.printStackTrace(); } tvFecode.setText(code); //信息提示框 tvMsgNotice.setTextColor(getResources().getColor(R.color.green)); tvMsgNotice.setText("上料成功"); tvMsgNotice.setTextColor(getResources().getColor(R.color.green)); tvMsgLocation.setText("物料号:" + productStr); tvMsgProdcode.setText("站位:" + locationStr); tvMsgBarcode.setText("飞达:" + fecodeStr); tvMsgQuantity.setText("料卷号:" + barcodeStr); tvMsgSpec.setText("数量:" + qtyStr); //新一轮采集 msl = null; isAgain = true; setEtHint(); } /*========================Volley Handler=================================*/ Handler handler = new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case VolleyUtil.SUCCESS_SUCCESS: disposeVolleySuccess(msg); break; case VolleyUtil.FAILED_FAILED: disposeVolleyFaild(msg); break; } } }; //Volley响应失败 private void disposeVolleyFaild(Message msg) { String noticeMsg = (String) msg.obj; String title = "失败"; String content = noticeMsg; setNotice(title, content, getResources().getColor(R.color.red)); progressDialog.dismiss(); } //Volley响应成功函数 private void disposeVolleySuccess(Message msg) { Log.e("SCSMTFEEDER", "HandlerSuccess"); String result = (String) msg.obj; switch (requestType) { //请求详细数据 case VolleyUtil.FRAGMENT_SCMAKE_SMTINDETAIL: Log.e("SCSMTFEEDER", "requestType:" + requestType); String smtLocationStr = (String) msg.obj; try { //保存请求的变量 JSONObject tmpJson = new JSONObject(smtLocationStr); //如果没有获取到网络数据 boolean isNull = tmpJson.isNull("message"); if (isNull) { disposeNullServerData(); } else { smtLocation = tmpJson.getJSONArray("message"); //这里获取了数据 没有填充上去 Log.e("SMTINChild", "smtLocation:" + smtLocation.toString()); } } catch (JSONException e) { e.printStackTrace(); } break; //物料 case VolleyUtil.FRAGMENT_SCMAKE_SMTIN_BARREMAIN: Log.e("SMTWULIAO", "BARREMAIN"); disposeBarcodeSuccess(result); // disposeFecodeCollect(); break; //上料操作:上料成功以后,需要重新获取输入框文字 case VolleyUtil.FRAGMENT_SCMAKE_SMTIN_UPLOAD: disposeUpLoadSuccess(result); break; } progressDialog.dismiss(); } //隐藏采集界面 private void disposeNullServerData() { rlCollect.setVisibility(View.GONE); String title = getString(R.string.notice_smtin_nulldata); setNotice(title, "", getResources().getColor(R.color.text_error)); } /*========================公用方法=================================*/ /** * 显示loadingView */ private void showLoadingView() { if (!progressDialog.isShowing()) { progressDialog.show(); } } /** * 键盘 */ InputMethodManager inputManager; private void hideKeyboard(final EditText view) { inputManager = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); //获取键盘管理对象 inputManager.hideSoftInputFromWindow(view.getWindowToken(), 0); } /** * 获取输入框焦点 */ private void editTextGetFocus(EditText editText) { editText.setFocusable(true); editText.setFocusableInTouchMode(true); editText.setEnabled(true); editText.setClickable(true); editText.requestFocus(); } /** * 设置提示信息 */ private void setNotice(String title, String content, int pid) { tvMsgNotice.setText(title); tvMsgNotice.setTextColor(pid); tvMsgProdcode.setText(content); //清除其它信息 tvMsgSpec.setText(""); tvMsgBarcode.setText(""); tvMsgLocation.setText(""); tvMsgQuantity.setText(""); } /** * 设置采集框提示信息 */ @Override public void setEtHint() { //获取站位\料卷\飞达编号 String locationStr = tvLocation.getText().toString().trim(); String barcodeStr = tvBarcode.getText().toString().trim(); String remainQty = tvRemainqty.getText().toString().trim(); String fecodeStr = tvFecode.getText().toString().trim(); /*//->if(msl_location为空),如果站位为null if (isAgain || locationStr.equals("") || locationStr == null) { etCollect.setHint(R.string.hint_smtchild_location); } //->else if(msl_barcode为空) 如果站位不为空,料卷号为空 else if (barcodeStr.equals("") || barcodeStr == null) { etCollect.setHint(R.string.hint_smtchild_barcode); } //->else if(msl_remainqty为空) 如果数量为空 else if (remainQty.equals("") || remainQty == null) { etCollect.setHint(R.string.hint_smtchild_barcode); } //->else if(msl_fecode为空),料卷号不为空,飞达编号为空时 else if (fecodeStr.equals("") || barcodeStr == null) { etCollect.setHint(R.string.hint_smtchild_fecode); }*/ } /** * 按钮点击事件 */ @Override public void onClick(View v) { disposeOnClick(); } JSONObject msl = new JSONObject(); String code = null; boolean isAgain = false; private void disposeOnClick() { //->获取输入框文字内容 // code = etCollect.getText().toString().trim(); if (code.equals("") || code == null) { return; } Log.e("SCSMT:code", "" + code); //获取站位\料卷\飞达编号 String locationStr = tvLocation.getText().toString().trim(); String barcodeStr = tvBarcode.getText().toString().trim(); String fecodeStr = tvFecode.getText().toString().trim(); //->if(msl_location为空),如果站位为null,或者是新一轮采集 if (isAgain || locationStr.equals("") || locationStr == null) { disposeOnClickLocation(); } //->else if(msl_barcode为空) 如果站位不为空,料卷号为空 else if (barcodeStr.equals("") || barcodeStr == null) { disposeOnClickBarcode(); } //->else if(msl_fecode为空),料卷号不为空,飞达编号为空时 else if (fecodeStr.equals("") || barcodeStr == null) { disposeOnClickFecode(); } } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { if (progressDialog != null && progressDialog.isShowing()) { // loadingView.dismiss(); return true; } } return false; } @Override public boolean onFragmentBackPressed() { return false; } }