| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732 |
- package com.uas.uaspda.fragment;
- import android.content.Context;
- import android.os.Handler;
- import android.os.Message;
- 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.FastjsonUtil;
- import com.uas.uaspda.util.HttpCallback;
- import com.uas.uaspda.util.HttpParams;
- import com.uas.uaspda.util.JsonUtils;
- import com.uas.uaspda.util.VolleyRequest;
- 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;
- /**
- * @note:SMTChild换料操作 modify:2017-05-15
- */
- public class SCSMTChangeFragment extends BaseFragment implements TextViewWithButton.TvHintHelper, View.OnClickListener {
- JSONObject makeCraft;
- TextViewWithButton tvLocation, tvBarcode, tvRemainqty, mLocationTextView, mFeederTextView;
- TextView tvMsgNotice, tvMsgLocation, tvMsgProdcode, tvMsgBarcode, tvMsgQuantity, tvMsgSpec;
- RelativeLayout rlCollect;
- int wrongColor, rightColor;
- int requestType;
- JSONArray smtLocation;
- JSONObject mslChange;
- boolean isAgain = false;
- private LineInfoBean mLineInfoBean;
- private TextView mLinecodeTextView, mTableTextView, mMacodeTextView;
- private ClearableEditText mCollectEditText;
- private String mSmtLocationCache;
- private SmtDslBean mSmtDslBean = new SmtDslBean();
- private StringRequest mStringRequest;
- private TextViewWithButton.OnTextClearListener mLocationClearListener;
- private TextViewWithButton.OnTextClearListener mFeederClearListener;
- @Override
- protected int getLayout() {
- return R.layout.fragment_scmake_smtfeederchild_jointchange;
- }
- @Override
- protected void initViews() {
- //->采集
- tvLocation = (TextViewWithButton) root.findViewById(R.id.tv_location_smtchildadd);
- tvBarcode = (TextViewWithButton) root.findViewById(R.id.tv_barcode_smtchildadd);
- tvRemainqty = (TextViewWithButton) root.findViewById(R.id.tv_remainqty_smtchildadd);
- rlCollect = (RelativeLayout) root.findViewById(R.id.rl_innernotice_smtchildadd);
- //->提示信息
- 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);
- mLinecodeTextView = (TextView) root.findViewById(R.id.smt_change_linecode_tv);
- mTableTextView = (TextView) root.findViewById(R.id.smt_change_table_tv);
- mMacodeTextView = (TextView) root.findViewById(R.id.smt_change_macode_tv);
- mLocationTextView = (TextViewWithButton) root.findViewById(R.id.smt_change_location_tv);
- mCollectEditText = (ClearableEditText) root.findViewById(R.id.smt_change_collect_et);
- mFeederTextView = root.findViewById(R.id.smt_change_feeder_tv);
- mCollectEditText.requestFocus();
- mCollectEditText.setHint("请采集飞达编号");
- wrongColor = getResources().getColor(R.color.text_error);
- rightColor = getResources().getColor(R.color.green);
- //接口回调
- VolleyUtil.setVolleyHandler(volleyHandler);
- mLineInfoBean = (LineInfoBean) PdaApplication.getDataCacheFromMap(Constants.FLAG.SMT_DEVICE_LINE_CACHE);
- // JSONObject paramJson = new JSONObject();
- // try {
- // makeCraft = new JSONObject(makeCraftStr);
- // Log.e(TAG, "makeCraft" + makeCraft);
- // String psId = makeCraft.getString("ps_id");
- // String prodcode = makeCraft.getString("mc_prodcode");
- // paramJson.put("ps_id", psId);
- // paramJson.put("prodcode", prodcode);
- // } catch (JSONException e) {
- // e.printStackTrace();
- // }
- //if(jobCode.equals("")||jobCode == null||jobCode.equals("null")){jobCode = "无";}
- //
- // //获取网络数据
- // requestType = VolleyUtil.FRAGMENT_SCMAKE_SMTCHANGE_DETAIL;
- // VolleyUtil.getVolleyUtil().requestJsonObject(getActivity(), GloableParams.ADDRESS_SMTDETAIL_APPLY, VolleyUtil.METHOD_POST,
- // requestType, paramJson);
- }
- @Override
- protected void initEvents() {
- tvLocation.setTvHintHelper(this);
- tvBarcode.setTvHintHelper(this);
- tvRemainqty.setTvHintHelper(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;
- }
- });
- mFeederClearListener = new TextViewWithButton.OnTextClearListener() {
- @Override
- public void onTextClear() {
- mLocationTextView.setOnTextClearListener(null);
- mLocationTextView.setText("");
- mLocationTextView.setOnTextClearListener(mLocationClearListener);
- mCollectEditText.setHint("请采集飞达编号");
- mCollectEditText.setText("");
- }
- };
- mLocationClearListener = new TextViewWithButton.OnTextClearListener() {
- @Override
- public void onTextClear() {
- mFeederTextView.setOnTextClearListener(null);
- mFeederTextView.setText("");
- mFeederTextView.setOnTextClearListener(mFeederClearListener);
- mCollectEditText.setHint("请采集飞达编号");
- mCollectEditText.setText("");
- }
- };
- mLocationTextView.setOnTextClearListener(mLocationClearListener);
- mFeederTextView.setOnTextClearListener(mFeederClearListener);
- }
- private void confirmEvent(String collect) {
- String location = mLocationTextView.getText().toString().trim();
- if (TextUtils.isEmpty(location)) {
- feederGetLocation(collect);
- } else {
- mSmtDslBean.setDsl_barcode(collect);
- //接料操作
- smtChangeMaterial();
- }
- }
- private void feederGetLocation(String collect) {
- progressDialog.show();
- VolleyRequest.getInstance().stringRequest(new HttpParams.Builder()
- .url(GloableParams.ADDRESS_SMT_GETFEEDERBARCODE)
- .method(Request.Method.POST)
- .addParam("fe_code", collect)
- .build(), new HttpCallback() {
- @Override
- public void onSuccess(int flag, Object o) throws Exception {
- try {
- progressDialog.dismiss();
- String result = o.toString();
- com.alibaba.fastjson.JSONObject resultObject = JSON.parseObject(result);
- com.alibaba.fastjson.JSONObject dataObject = resultObject.getJSONObject("data");
- if (dataObject != null) {
- String fe_code = FastjsonUtil.getText(dataObject, "fe_code");
- String fe_location = FastjsonUtil.getText(dataObject, "fe_location");
- locationCheck(fe_location, fe_code);
- } else {
- tvMsgNotice.setTextColor(getResources().getColor(R.color.red));
- tvMsgNotice.setText("数据为空");
- CommonUtil.makeNotice();
- mCollectEditText.setText("");
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- @Override
- public void onFail(int flag, String failStr) throws Exception {
- progressDialog.dismiss();
- tvMsgNotice.setTextColor(getResources().getColor(R.color.red));
- tvMsgNotice.setText(failStr);
- CommonUtil.makeNotice();
- mCollectEditText.setText("");
- }
- });
- }
- private void locationCheck(String collect, String feeder) {
- 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);
- mFeederTextView.setText(feeder);
- 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));
- tvMsgNotice.setText("站位编号错误");
- CommonUtil.makeNotice();
- mCollectEditText.setText("");
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- } else {
- tvMsgNotice.setTextColor(getResources().getColor(R.color.red));
- tvMsgNotice.setText("站位编号错误");
- CommonUtil.makeNotice();
- mCollectEditText.setText("");
- }
- }
- /**
- * SMT接料
- */
- private void smtChangeMaterial() {
- 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_CHANGE_MATERIAL,
- new Response.Listener<String>() {
- @Override
- public void onResponse(String s) {
- try {
- Log.d("smtchange", 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")));
- tvMsgSpec.setText("飞达规格:" + JsonUtils.optStringNotNull(dataObject, "DSL_FESPEC"));
- 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));
- tvMsgNotice.setText(errorToast);
- if (errorToast.contains("站位已经有在线料卷号")) {
- mLocationTextView.setText("");
- mCollectEditText.setText("");
- } else {
- mCollectEditText.setText("");
- }
- }
- }
- }) {
- @Override
- protected Map<String, String> getParams() throws AuthFailureError {
- Map<String, String> params = new HashMap<String, String>();
- params.put("dsl", smtDsl);
- params.put("deviceLineMake", finalDeviceLineMake);
- return params;
- }
- @Override
- public Map<String, String> 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() {
- //界面配置
- //->Actionbar
- ((TextView) (getActivity().findViewById(R.id.tv_actionbar_withback))).setText(R.string.title_feederchange_smt);
- ((Button) (getActivity().findViewById(R.id.btn_actionbar_right))).setVisibility(View.GONE);
- mSmtLocationCache = SharedPreUtil.getString(mActivity, Constants.FLAG.SMT_LOCATION_CACHE, null);
- if (mLineInfoBean != null) {
- mLinecodeTextView.setText(mLineInfoBean.getDL_LINECODE());
- mTableTextView.setText(mLineInfoBean.getDL_TABLE() + "面");
- mMacodeTextView.setText(mLineInfoBean.getDL_MACODE());
- }
- }
- @Override
- public void onDestroy() {
- VolleyUtil.distoryVolley();
- super.onDestroy();
- }
- @Override
- public void onDestroyView() {
- CommonUtil.closeKeybord(mCollectEditText, mActivity);
- super.onDestroyView();
- }
- String code;
- //采集栏enter事件、按钮点击事件
- 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 qtyStr = tvRemainqty.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();
- }
- }
- //按钮点击事件:当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("");
- 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)) {
- //显示在站位输入框,添加数据项
- tvLocation.setText(tmpLocation);
- mslChange = new JSONObject();
- mslChange.put("msl_location", code);
- mslChange.put("msl_prodcode", tmpJson.getString("psl_prodcode").trim());
- mslChange.put("msl_repcode", tmpJson.getString("psl_repcode").trim());
- mslChange.put("psl_id", tmpJson.getString("psl_id").trim());
- Log.e("SMTCHILD", mslChange.toString());
- //更改etCollect的Hint
- setEtHint();
- //提示框中显示信息
- title = "站位采集成功";
- content = "站位采集成功,请采集物料" + mslChange.get("msl_prodcode") + "的条码";
- color = getResources().getColor(R.color.green);
- setNotice(title, content, color);
- break;
- }
- //如果不匹配
- else {
- 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() {
- //请求判断料卷编号是否正确,获取料卷数量
- JSONObject paramJson = new JSONObject();
- try {
- paramJson.put("bar_code", code);
- paramJson.put("prod_code", mslChange.getString("msl_prodcode"));
- paramJson.put("rep_code", mslChange.getString("msl_repcode"));
- } catch (JSONException e) {
- e.printStackTrace();
- }
- showLoadingView();
- requestType = VolleyUtil.FRAGMENT_SCMAKE_SMTCHANGE_BARREMAIN;
- VolleyUtil.getVolleyUtil().requestJsonObject(getActivity(), GloableParams.ADDRESS_SMT_BARREMAIN_APPLY, VolleyUtil.METHOD_POST,
- requestType, paramJson);
- }
- //扫描料卷编号成功
- String mslBarcode = null, mslRemainQty = null;
- private void disposeBarcodeSuccess(JSONObject resultJson) {
- String title, content;
- int color;
- JSONObject tmpJson, msgJson;
- try {
- //tmpJson = new JSONObject(resultJson);
- tmpJson = resultJson;
- msgJson = tmpJson.getJSONObject("message");
- //将message中的值赋值给变量msl中的值
- mslChange.put("msl_barcode", msgJson.getString("bar_code"));
- mslChange.put("msl_prodcode", msgJson.get("bar_prodcode"));
- mslChange.put("msl_remainqty", msgJson.get("bar_remain"));
- mslBarcode = code;
- mslRemainQty = msgJson.getString("bar_remain");
- //料卷编号和数量输入框显示对应的值,清空采集栏中的值
- tvBarcode.setText(mslBarcode);
- tvRemainqty.setText(mslRemainQty);
- //发送接料请求至服务器进行换料操作
- changeMaterial();
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- //换料操作
- private void changeMaterial() {
- try {
- String mcCode = makeCraft.getString("mc_code");
- int mcId = makeCraft.getInt("mc_id");
- String mcDevcode = makeCraft.getString("mc_devcode");
- String mcSourcecode = makeCraft.getString("mc_sourcecode");
- mslChange.put("mc_code", mcCode);
- mslChange.put("mc_id", "" + mcId);
- mslChange.put("mc_devcode", mcDevcode);
- mslChange.put("mc_sourcecode", mcSourcecode);
- } catch (JSONException e) {
- e.printStackTrace();
- }
- requestType = VolleyUtil.FRAGMENT_SCMAKE_SMTCHANGE_CHANGE;
- showLoadingView();
- VolleyUtil.getVolleyUtil().requestJsonObject(getActivity(), GloableParams.ADDRESS_SMTCHANGE_APPLY, VolleyUtil.METHOD_POST,
- requestType, mslChange);
- }
- //Volley请求换料成功
- private void disposeVolleyJoint(JSONObject resultJson) {
- JSONObject msgJson;
- String productStr = "无", locationStr = "无", fecodeStr = "无", barcodeStr = "无", qtyStr = "无";
- try {
- msgJson = resultJson.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();
- }
- //信息提示框
- tvMsgNotice.setTextColor(getResources().getColor(R.color.green));
- tvMsgNotice.setText(getString(R.string.notice_smtchange_success));
- tvMsgLocation.setText("物料号:" + productStr);
- tvMsgProdcode.setText("站位:" + locationStr);
- tvMsgBarcode.setText("飞达:" + fecodeStr);
- tvMsgQuantity.setText("料卷号:" + barcodeStr);
- tvMsgSpec.setText("数量:" + qtyStr);
- //新一轮采集
- mslChange = null;
- isAgain = true;
- setEtHint();
- }
- /*=================================Volley Handler====================================*/
- Handler volleyHandler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case VolleyUtil.SUCCESS_SUCCESS:
- disposeVolleySuccess(msg);
- break;
- case VolleyUtil.FAILED_FAILED:
- disposeVolleyFailed(msg);
- break;
- }
- progressDialog.dismiss();
- }
- };
- //Volley响应成功
- private void disposeVolleySuccess(Message msg) {
- JSONObject tmpJson;
- switch (requestType) {
- //页面加载:获取详细信息
- case VolleyUtil.FRAGMENT_SCMAKE_SMTCHANGE_DETAIL:
- disposeVolleyDetail(msg);
- break;
- //页面加载:获取详细信息
- case VolleyUtil.FRAGMENT_SCMAKE_SMTCHANGE_BARREMAIN:
- tmpJson = (JSONObject) msg.obj;
- disposeBarcodeSuccess(tmpJson);
- break;
- //页面加载:获取详细信息
- case VolleyUtil.FRAGMENT_SCMAKE_SMTCHANGE_CHANGE:
- tmpJson = (JSONObject) msg.obj;
- disposeVolleyJoint(tmpJson);
- break;
- }
- }
- //Volley响应失败
- private void disposeVolleyFailed(Message msg) {
- String noticeMsg = (String) msg.obj;
- String title = "失败";
- String content = noticeMsg;
- setNotice(title, content, getResources().getColor(R.color.red));
- }
- //Volley请求页面详细数据
- private void disposeVolleyDetail(Message msg) {
- JSONObject tmpJson = (JSONObject) msg.obj;
- try {
- boolean isNull = tmpJson.isNull("message");
- //如果服务器没有返回值
- if (isNull) {
- disposeNullServerData();
- } else {
- smtLocation = tmpJson.getJSONArray("message");
- Log.e(TAG, "smtLocation:" + smtLocation.toString());
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- /*=================================公用方法===========================================*/
- /**
- * 设置采集框提示信息
- */
- @Override
- public void setEtHint() {
- //获取站位\料卷\飞达编号
- String locationStr = tvLocation.getText().toString().trim();
- String barcodeStr = tvBarcode.getText().toString().trim();
- String remainQty = tvRemainqty.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);
- // }
- }
- /**
- * 隐藏采集界面
- */
- private void disposeNullServerData() {
- rlCollect.setVisibility(View.GONE);
- String title = getString(R.string.notice_smtin_nulldata);
- setNotice(title, "", getResources().getColor(R.color.text_error));
- }
- /**
- * 隐藏键盘
- */
- private void hideKeyboard(final EditText view) {
- InputMethodManager inputManager = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
- //获取键盘管理对象
- inputManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
- }
- /**
- * 显示loadingView
- */
- private void showLoadingView() {
- if (!progressDialog.isShowing()) {
- progressDialog.show();
- }
- }
- /**
- * 设置提示信息
- */
- private void setNotice(String title, String content, int pid) {
- tvMsgNotice.setText(title);
- tvMsgNotice.setTextColor(pid);
- tvMsgLocation.setText(content);
- //清除其它信息
- tvMsgSpec.setText("");
- tvMsgBarcode.setText("");
- tvMsgLocation.setText("");
- tvMsgQuantity.setText("");
- }
- /**
- * 获取输入框焦点
- */
- private void editTextGetFocus(EditText editText) {
- editText.setFocusable(true);
- editText.setFocusableInTouchMode(true);
- editText.setEnabled(true);
- editText.setClickable(true);
- editText.requestFocus();
- }
- @Override
- public void onClick(View v) {
- disposeOnClick();
- }
- @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;
- }
- @Override
- public boolean onFragmentBackPressed() {
- return false;
- }
- }
|