SCSMTIndexFragment.java 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312
  1. package com.uas.uaspda.fragment;
  2. import android.content.Context;
  3. import android.content.DialogInterface;
  4. import android.graphics.drawable.BitmapDrawable;
  5. import android.os.AsyncTask;
  6. import android.os.Handler;
  7. import android.os.Message;
  8. import android.support.v4.app.Fragment;
  9. import android.support.v7.app.AlertDialog;
  10. import android.text.Editable;
  11. import android.text.TextUtils;
  12. import android.text.TextWatcher;
  13. import android.util.Log;
  14. import android.view.Gravity;
  15. import android.view.KeyEvent;
  16. import android.view.LayoutInflater;
  17. import android.view.View;
  18. import android.widget.AdapterView;
  19. import android.widget.AutoCompleteTextView;
  20. import android.widget.Button;
  21. import android.widget.CheckBox;
  22. import android.widget.CompoundButton;
  23. import android.widget.GridView;
  24. import android.widget.ImageView;
  25. import android.widget.LinearLayout;
  26. import android.widget.PopupWindow;
  27. import android.widget.RadioButton;
  28. import android.widget.RadioGroup;
  29. import android.widget.SimpleAdapter;
  30. import android.widget.TextView;
  31. import com.alibaba.fastjson.JSON;
  32. import com.android.volley.AuthFailureError;
  33. import com.android.volley.DefaultRetryPolicy;
  34. import com.android.volley.Request;
  35. import com.android.volley.Response;
  36. import com.android.volley.VolleyError;
  37. import com.android.volley.toolbox.StringRequest;
  38. import com.uas.uaspda.R;
  39. import com.uas.uaspda.application.PdaApplication;
  40. import com.uas.uaspda.bean.ErrorMsg;
  41. import com.uas.uaspda.bean.LineInfoBean;
  42. import com.uas.uaspda.global.GloableParams;
  43. import com.uas.uaspda.tools.DataSourceManager;
  44. import com.uas.uaspda.tools.SharedPreUtil;
  45. import com.uas.uaspda.tools.VolleyUtil;
  46. import com.uas.uaspda.util.CommonUtil;
  47. import com.uas.uaspda.util.Constants;
  48. import com.uas.uaspda.util.FragmentUtils;
  49. import com.uas.uaspda.util.JsonTools;
  50. import com.uas.uaspda.util.JsonUtils;
  51. import com.uas.uaspda.util.MyArrayAdapter;
  52. import com.uas.uaspda.view.ClearableEditText;
  53. import com.uas.uaspda.view.ConfirmDialog;
  54. import org.json.JSONArray;
  55. import org.json.JSONException;
  56. import org.json.JSONObject;
  57. import java.io.UnsupportedEncodingException;
  58. import java.net.URLEncoder;
  59. import java.util.ArrayList;
  60. import java.util.HashMap;
  61. import java.util.List;
  62. import java.util.Map;
  63. /**
  64. * SMT作业页面
  65. */
  66. public class SCSMTIndexFragment extends BaseFragment implements AdapterView.OnItemClickListener {
  67. private static final String TAG = "SCSMTIndexFragment";
  68. private static final int MACODE_FUZZY = 0;
  69. private static final int PRODCODE_FUZZY = 1;
  70. GridView lvIndex;
  71. List<Map<String, Object>> operationIndexList;
  72. private LineInfoBean mLineInfoBean;
  73. private PopupWindow mPasswordPopupWindow, mSwitchPopupWindow, mMachinePopupWindow, mDownAllPopupWindow;
  74. private ClearableEditText mPasswordEditText;
  75. private TextView mConfirmTextView, mCancelTextView;
  76. private TextView mDecodeTextView, mStatusTextView, mLinecodeTextView, mTableTextView, mMacodeTextView, mProdcodeTextView;
  77. private StringRequest mStringRequest;
  78. private int dl_madeqty, ma_qty;//产出数,工单数
  79. private MyArrayAdapter mAutoStringAdapter;
  80. View downAllView;
  81. AlertDialog switchDialog;
  82. @Override
  83. protected int getLayout() {
  84. return R.layout.fragment_scmake_smtcontent;
  85. }
  86. @Override
  87. protected void initViews() {
  88. ((TextView) (getActivity().findViewById(R.id.tv_actionbar_withback))).setText(R.string.title_operation_smt);
  89. ((Button) (getActivity().findViewById(R.id.btn_actionbar_right))).setVisibility(View.GONE);
  90. downAllView = View.inflate(getActivity(), R.layout.pop_smt_down_all, null);
  91. switchDialog = new AlertDialog.Builder(getActivity()).setView(downAllView).create();
  92. lvIndex = (GridView) root.findViewById(R.id.lv_index_smt);
  93. mDecodeTextView = (TextView) root.findViewById(R.id.smt_content_decode_tv);
  94. mStatusTextView = (TextView) root.findViewById(R.id.smt_content_status_tv);
  95. mLinecodeTextView = (TextView) root.findViewById(R.id.smt_content_linecode_tv);
  96. mTableTextView = (TextView) root.findViewById(R.id.smt_content_table_tv);
  97. mMacodeTextView = (TextView) root.findViewById(R.id.smt_content_macode_tv);
  98. mProdcodeTextView = (TextView) root.findViewById(R.id.smt_content_prodcode_tv);
  99. //接口回调
  100. VolleyUtil.setVolleyHandler(volleyHandler);
  101. //获取数据
  102. operationIndexList = DataSourceManager.getDataSourceManager().getFeederOperationIndex();
  103. mLineInfoBean = (LineInfoBean) PdaApplication.getDataCacheFromMap(Constants.FLAG.SMT_DEVICE_LINE_CACHE);
  104. }
  105. @Override
  106. protected void initEvents() {
  107. //配置监听
  108. lvIndex.setOnItemClickListener(this);
  109. }
  110. @Override
  111. protected void initDatas() {
  112. SimpleAdapter adapter = new SimpleAdapter(mActivity, operationIndexList, R.layout.item_grid_first,
  113. new String[]{DataSourceManager.KEY_GRID_ITEMIMG, DataSourceManager.KEY_GRID_ITEMNAME},
  114. new int[]{R.id.first_griditem_img, R.id.first_griditem_name});
  115. lvIndex.setAdapter(adapter);
  116. if (mLineInfoBean != null) {
  117. mDecodeTextView.setText(mLineInfoBean.getDL_DECODE());
  118. mStatusTextView.setText(mLineInfoBean.getDL_STATUS());
  119. mLinecodeTextView.setText(mLineInfoBean.getDL_LINECODE());
  120. mTableTextView.setText(mLineInfoBean.getDL_TABLE() + "面");
  121. mMacodeTextView.setText(mLineInfoBean.getDL_MACODE());
  122. mProdcodeTextView.setText(mLineInfoBean.getDL_PRODCODE());
  123. if (CommonUtil.isNetWorkConnected(mActivity)) {
  124. getSmtLocation();
  125. } else {
  126. CommonUtil.toastNoRepeat(mActivity, getString(R.string.net_not_connect));
  127. SharedPreUtil.saveString(mActivity, Constants.FLAG.SMT_LOCATION_CACHE, "");
  128. }
  129. }
  130. }
  131. @Override
  132. public void onHiddenChanged(boolean hidden) {
  133. super.onHiddenChanged(hidden);
  134. if (!hidden) {
  135. VolleyUtil.setVolleyHandler(volleyHandler);
  136. ((TextView) (getActivity().findViewById(R.id.tv_actionbar_withback))).setText(R.string.title_operation_smt);
  137. ((Button) (getActivity().findViewById(R.id.btn_actionbar_right))).setVisibility(View.GONE);
  138. }
  139. }
  140. /**
  141. * 获取当前工单站位信息
  142. */
  143. private void getSmtLocation() {
  144. progressDialog.show();
  145. String url = GloableParams.ADDRESS_SMT_GET_SMT_LOCATION
  146. + "?ps_id=" + mLineInfoBean.getPS_ID()
  147. + "&dl_table=" + mLineInfoBean.getDL_TABLE();
  148. PdaApplication.mRequestQueue.cancelAll(TAG + "location");
  149. mStringRequest = new StringRequest(Request.Method.GET, url,
  150. new Response.Listener<String>() {
  151. @Override
  152. public void onResponse(String s) {
  153. if (progressDialog.isShowing())
  154. progressDialog.dismiss();
  155. try {
  156. JSONObject resultObject = new JSONObject(s);
  157. if (resultObject.optBoolean("success")) {
  158. String smtLocation = resultObject.optString("data");
  159. Log.d("smtLocation", smtLocation);
  160. SharedPreUtil.saveString(mActivity, Constants.FLAG.SMT_LOCATION_CACHE, smtLocation);
  161. }
  162. } catch (JSONException e) {
  163. e.printStackTrace();
  164. }
  165. }
  166. },
  167. new Response.ErrorListener() {
  168. @Override
  169. public void onErrorResponse(VolleyError volleyError) {
  170. if (progressDialog.isShowing())
  171. progressDialog.dismiss();
  172. CommonUtil.showErrorToast(volleyError, true);
  173. SharedPreUtil.saveString(mActivity, Constants.FLAG.SMT_LOCATION_CACHE, "");
  174. }
  175. }) {
  176. @Override
  177. public Map<String, String> getHeaders() throws AuthFailureError {
  178. return VolleyUtil.getVolleyUtil().setCookies();
  179. }
  180. };
  181. mStringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000, 0, 1f));
  182. mStringRequest.setTag(TAG + "location");
  183. PdaApplication.mRequestQueue.add(mStringRequest);
  184. }
  185. @Override
  186. public void onDestroy() {
  187. VolleyUtil.distoryVolley();
  188. PdaApplication.removeDataCacheFromMap(Constants.FLAG.SMT_REQUEST_CACHE);
  189. super.onDestroy();
  190. }
  191. @Override
  192. public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  193. if (!CommonUtil.isRepeatClick()) {
  194. String mSmtLocationCache = SharedPreUtil.getString(mActivity, Constants.FLAG.SMT_LOCATION_CACHE, null);
  195. if (TextUtils.isEmpty(mSmtLocationCache)) {
  196. new AlertDialog.Builder(mActivity).setTitle("提示")
  197. .setMessage("获取站位表失败,无法进行后续操作。点击确定重新获取站位表!")
  198. .setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
  199. @Override
  200. public void onClick(DialogInterface dialog, int which) {
  201. if (CommonUtil.isNetWorkConnected(mActivity)) {
  202. getSmtLocation();
  203. } else {
  204. CommonUtil.toastNoRepeat(mActivity, getString(R.string.net_not_connect));
  205. SharedPreUtil.saveString(mActivity, Constants.FLAG.SMT_LOCATION_CACHE, "");
  206. }
  207. }
  208. })
  209. .setNegativeButton(R.string.cancel, null).create().show();
  210. } else {
  211. //获取选择的列表Name
  212. String selectedName = operationIndexList.get(position).get(DataSourceManager.KEY_GRID_ITEMNAME).toString();
  213. Fragment fragment;
  214. switch (selectedName) {
  215. //上料
  216. case GloableParams.LISTNAME_FEEDER_IN:
  217. fragment = new SCSMTInFragment();
  218. FragmentUtils.switchFragment(this, fragment);
  219. break;
  220. //接料
  221. case GloableParams.LISTNAME_FEEDER_JOIN:
  222. fragment = new SCSMTJointFragment();
  223. FragmentUtils.switchFragment(this, fragment);
  224. break;
  225. //换料
  226. case GloableParams.LISTNAME_FEEDER_CHANGE:
  227. fragment = new SCSMTChangeFragment();
  228. FragmentUtils.switchFragment(this, fragment);
  229. break;
  230. //下料
  231. case GloableParams.LISTNAME_FEEDER_DOWN:
  232. fragment = new SCSMTDownFragment();
  233. FragmentUtils.switchFragment(this, fragment);
  234. break;
  235. //全部下料
  236. case GloableParams.LISTNAME_FEEDER_DOWNALL:
  237. queryMakeqty(1);
  238. break;
  239. //料卷查询
  240. case GloableParams.LISTNAME_FEEDER_QUERY:
  241. fragment = new SCSMTQueryFragment();
  242. FragmentUtils.switchFragment(this, fragment);
  243. break;
  244. //工单切换
  245. case GloableParams.LISTNAME_FEEDER_SWITCH:
  246. queryMakeqty(2);
  247. break;
  248. //校验
  249. case GloableParams.LISTNAME_FEEDER_CHECK:
  250. fragment = new SCSMTCheckFragment();
  251. FragmentUtils.switchFragment(this, fragment);
  252. break;
  253. //机台操作
  254. case GloableParams.LISTNAME_FEEDER_MACHINE:
  255. operationMachine();
  256. break;
  257. //叫料
  258. case GloableParams.LISTNAME_REQUEST_MACHINE:
  259. fragment = new SCSMTRequestFragment();
  260. FragmentUtils.switchFragment(this, fragment);
  261. break;
  262. //站位反查
  263. case GloableParams.LISTNAME_LOCATION_QUERY:
  264. fragment = new SMTLocationQueryFragment();
  265. FragmentUtils.switchFragment(this, fragment);
  266. break;
  267. //备料查询
  268. case GloableParams.LISTNAME_PREMATERIAL_QUERY:
  269. fragment = new SMTPreMaterialQueryFragment();
  270. FragmentUtils.switchFragment(this, fragment);
  271. break;
  272. //飞达料盘绑定
  273. case GloableParams.LISTNAME_FEEDER_BIND:
  274. fragment = new SCSMTBindFragment();
  275. FragmentUtils.switchFragment(this, fragment);
  276. break;
  277. //飞达料盘解绑
  278. case GloableParams.LISTNAME_FEEDER_UNBIND:
  279. fragment = new SCSMTUnBindFragment();
  280. FragmentUtils.switchFragment(this, fragment);
  281. break;
  282. //复检效验
  283. case GloableParams.LISTNAME_FEEDER_CHECKINSPECTION:
  284. fragment = new SCSMTInspectionFragment();
  285. FragmentUtils.switchFragment(this, fragment);
  286. break;
  287. }
  288. }
  289. }
  290. }
  291. private void operationMachine() {
  292. View machineView = View.inflate(mActivity, R.layout.popupwindow_machine_operation, null);
  293. TextView mMsgTextView = (TextView) machineView.findViewById(R.id.pop_machine_operation_msg_tv);
  294. TextView mCancelTextView = (TextView) machineView.findViewById(R.id.pop_machine_operation_cancel_tv);
  295. TextView mConfirmTextView = (TextView) machineView.findViewById(R.id.pop_machine_operation_confirm_tv);
  296. mCancelTextView.setOnClickListener(new View.OnClickListener() {
  297. @Override
  298. public void onClick(View v) {
  299. closeMachinePopupWindow();
  300. }
  301. });
  302. if ("UNUSED".equals(mLineInfoBean.getDL_STATUSCODE().trim())
  303. || "STOP".equals(mLineInfoBean.getDL_STATUSCODE().trim())) {
  304. mMsgTextView.setText("机台正处于停止状态,是否启动机台?");
  305. mConfirmTextView.setText("启动机台");
  306. mConfirmTextView.setTextColor(getResources().getColor(R.color.text_blue));
  307. mConfirmTextView.setOnClickListener(new View.OnClickListener() {
  308. @Override
  309. public void onClick(View v) {
  310. startMachine(false);
  311. }
  312. });
  313. }
  314. if ("STARTED".equals(mLineInfoBean.getDL_STATUSCODE().trim())) {
  315. mMsgTextView.setText("机台正处于启动状态,是否暂停机台?");
  316. mConfirmTextView.setText("暂停机台");
  317. mConfirmTextView.setTextColor(getResources().getColor(R.color.color_red));
  318. mConfirmTextView.setOnClickListener(new View.OnClickListener() {
  319. @Override
  320. public void onClick(View v) {
  321. stopMachine();
  322. }
  323. });
  324. }
  325. mMachinePopupWindow = new PopupWindow(machineView, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, true);
  326. mMachinePopupWindow.setBackgroundDrawable(new BitmapDrawable());
  327. mMachinePopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
  328. @Override
  329. public void onDismiss() {
  330. closeMachinePopupWindow();
  331. }
  332. });
  333. CommonUtil.setBackgroundAlpha(mActivity, 0.5f);
  334. mMachinePopupWindow.showAtLocation(mActivity.getWindow().getDecorView(), Gravity.CENTER, 0, -100);
  335. }
  336. /**
  337. * 获取对应工单产出数
  338. *
  339. * @param i
  340. */
  341. private void queryMakeqty(final int i) {
  342. progressDialog.show();
  343. String url = GloableParams.ADDRESS_SMT_QUERY_MADEQTY + "?dl_macode=" + mLineInfoBean.getDL_MACODE()
  344. + "&dl_linecode=" + mLineInfoBean.getDL_LINECODE();
  345. PdaApplication.mRequestQueue.cancelAll(TAG + "downall");
  346. mStringRequest = new StringRequest(Request.Method.GET, url,
  347. new Response.Listener<String>() {
  348. @Override
  349. public void onResponse(String s) {
  350. if (progressDialog.isShowing())
  351. progressDialog.dismiss();
  352. if (s != null) {
  353. try {
  354. Log.d("madeqty", s);
  355. JSONObject resultObject = new JSONObject(s);
  356. if (!resultObject.isNull("data")) {
  357. JSONObject dataObject = resultObject.optJSONObject("data");
  358. if (dataObject != null) {
  359. dl_madeqty = (int) JsonUtils.optLongNotNull(dataObject, "DL_MADEQTY");
  360. ma_qty = (int) JsonUtils.optLongNotNull(dataObject, "MA_QTY");
  361. showVerificationPop(i);
  362. } else {
  363. CommonUtil.toastNoRepeat(mActivity, "产出数获取失败,请重新获取");
  364. }
  365. } else {
  366. dl_madeqty = 0;
  367. ma_qty = 0;
  368. showVerificationPop(i);
  369. }
  370. } catch (JSONException e) {
  371. e.printStackTrace();
  372. CommonUtil.toastNoRepeat(mActivity, "产出数获取异常,请重新获取");
  373. }
  374. } else {
  375. CommonUtil.toastNoRepeat(mActivity, "产出数获取失败,请重新获取");
  376. }
  377. }
  378. },
  379. new Response.ErrorListener() {
  380. @Override
  381. public void onErrorResponse(VolleyError volleyError) {
  382. if (progressDialog.isShowing())
  383. progressDialog.dismiss();
  384. CommonUtil.showErrorToast(volleyError, true);
  385. }
  386. }) {
  387. @Override
  388. public Map<String, String> getHeaders() throws AuthFailureError {
  389. return VolleyUtil.getVolleyUtil().setCookies();
  390. }
  391. };
  392. mStringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000, 0, 1f));
  393. mStringRequest.setTag(TAG + "downall");
  394. PdaApplication.mRequestQueue.add(mStringRequest);
  395. }
  396. /**
  397. * 开启机台
  398. *
  399. * @param force
  400. */
  401. private void startMachine(final boolean force) {
  402. progressDialog.show();
  403. PdaApplication.mRequestQueue.cancelAll(TAG + "start");
  404. mStringRequest = new StringRequest(Request.Method.POST, GloableParams.ADDRESS_SMT_START_SMT,
  405. new Response.Listener<String>() {
  406. @Override
  407. public void onResponse(String s) {
  408. closeMachinePopupWindow();
  409. if (progressDialog.isShowing())
  410. progressDialog.dismiss();
  411. try {
  412. Log.d("result", s);
  413. JSONObject resultObject = new JSONObject(s);
  414. if (resultObject.optBoolean("success")) {
  415. JSONObject dataObject = resultObject.optJSONObject("data");
  416. if (dataObject != null) {
  417. JSONObject devicelineObject = dataObject.optJSONObject("deviceline");
  418. if (devicelineObject != null) {
  419. mLineInfoBean = new LineInfoBean();
  420. mLineInfoBean.setDL_ID(JsonUtils.optLongNotNull(devicelineObject, "DL_ID"));
  421. mLineInfoBean.setDL_DECODE(JsonUtils.optStringNull(devicelineObject, "DL_DECODE"));
  422. mLineInfoBean.setDL_LINECODE(JsonUtils.optStringNull(devicelineObject, "DL_LINECODE"));
  423. mLineInfoBean.setDL_MACODE(JsonUtils.optStringNull(devicelineObject, "DL_MACODE"));
  424. mLineInfoBean.setDL_TABLE(JsonUtils.optStringNull(devicelineObject, "DL_TABLE"));
  425. mLineInfoBean.setDL_STATUSCODE(JsonUtils.optStringNull(devicelineObject, "DL_STATUSCODE"));
  426. mLineInfoBean.setDL_STATUS(JsonUtils.optStringNull(devicelineObject, "DL_STATUS"));
  427. mLineInfoBean.setPS_ID(JsonUtils.optLongNotNull(devicelineObject, "PS_ID"));
  428. mLineInfoBean.setMA_ID(JsonUtils.optLongNotNull(devicelineObject, "MA_ID"));
  429. mLineInfoBean.setDL_PRODCODE(JsonUtils.optStringNotNull(devicelineObject, "DL_PRODCODE"));
  430. PdaApplication.putDataCache2Map(Constants.FLAG.SMT_DEVICE_LINE_CACHE, mLineInfoBean);
  431. mDecodeTextView.setText(mLineInfoBean.getDL_DECODE());
  432. mStatusTextView.setText(mLineInfoBean.getDL_STATUS());
  433. mLinecodeTextView.setText(mLineInfoBean.getDL_LINECODE());
  434. mTableTextView.setText(mLineInfoBean.getDL_TABLE() + "面");
  435. mMacodeTextView.setText(mLineInfoBean.getDL_MACODE());
  436. mProdcodeTextView.setText(mLineInfoBean.getDL_PRODCODE());
  437. }
  438. String smtLocation = dataObject.optString("smtlocation");
  439. Log.d("smtLocation", smtLocation);
  440. if (!TextUtils.isEmpty(smtLocation))
  441. SharedPreUtil.saveString(mActivity, Constants.FLAG.SMT_LOCATION_CACHE, smtLocation);
  442. CommonUtil.toastNoRepeat(mActivity, "机台启动成功");
  443. }
  444. }
  445. } catch (JSONException e) {
  446. e.printStackTrace();
  447. }
  448. }
  449. }, new Response.ErrorListener() {
  450. @Override
  451. public void onErrorResponse(VolleyError volleyError) {
  452. if (progressDialog.isShowing())
  453. progressDialog.dismiss();
  454. closeMachinePopupWindow();
  455. int exceptionCode = 0;
  456. if (volleyError != null && volleyError.networkResponse != null && volleyError.networkResponse.data != null) {
  457. ErrorMsg errorMsg = JsonTools.parseJsonToBean(new String(volleyError.networkResponse.data), ErrorMsg.class);
  458. if (errorMsg != null) {
  459. exceptionCode = errorMsg.exceptionCode;
  460. }
  461. if (exceptionCode == 3001) {
  462. new AlertDialog.Builder(mActivity).setTitle("提示")
  463. .setMessage(errorMsg.exceptionInfo + ",是否强制启动?")
  464. .setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
  465. @Override
  466. public void onClick(DialogInterface dialog, int which) {
  467. startMachine(true);
  468. }
  469. }).setNegativeButton(R.string.cancel, null).create().show();
  470. } else {
  471. CommonUtil.showErrorToast(volleyError, true);
  472. }
  473. }
  474. }
  475. }) {
  476. @Override
  477. public Map<String, String> getHeaders() throws AuthFailureError {
  478. return VolleyUtil.getVolleyUtil().setCookies();
  479. }
  480. @Override
  481. protected Map<String, String> getParams() throws AuthFailureError {
  482. Map<String, String> params = new HashMap<String, String>();
  483. String deviceLineMake = JSON.toJSONString(mLineInfoBean);
  484. params.put("deviceLineMake", deviceLineMake);
  485. params.put("force", force + "");
  486. return params;
  487. }
  488. };
  489. mStringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000, 0, 1f));
  490. mStringRequest.setTag(TAG + "start");
  491. PdaApplication.mRequestQueue.add(mStringRequest);
  492. }
  493. /**
  494. * 暂停机台
  495. */
  496. private void stopMachine() {
  497. progressDialog.show();
  498. PdaApplication.mRequestQueue.cancelAll(TAG + "stop");
  499. mStringRequest = new StringRequest(Request.Method.POST, GloableParams.ADDRESS_SMT_STOP_SMT,
  500. new Response.Listener<String>() {
  501. @Override
  502. public void onResponse(String s) {
  503. closeMachinePopupWindow();
  504. if (progressDialog.isShowing())
  505. progressDialog.dismiss();
  506. try {
  507. JSONObject resultObject = new JSONObject(s);
  508. if (resultObject.optBoolean("success")) {
  509. JSONObject dataObject = resultObject.optJSONObject("data");
  510. if (dataObject != null) {
  511. JSONObject devicelineObject = dataObject.optJSONObject("deviceline");
  512. if (devicelineObject != null) {
  513. mLineInfoBean = new LineInfoBean();
  514. mLineInfoBean.setDL_ID(JsonUtils.optLongNotNull(devicelineObject, "DL_ID"));
  515. mLineInfoBean.setDL_DECODE(JsonUtils.optStringNull(devicelineObject, "DL_DECODE"));
  516. mLineInfoBean.setDL_LINECODE(JsonUtils.optStringNull(devicelineObject, "DL_LINECODE"));
  517. mLineInfoBean.setDL_MACODE(JsonUtils.optStringNull(devicelineObject, "DL_MACODE"));
  518. mLineInfoBean.setDL_TABLE(JsonUtils.optStringNull(devicelineObject, "DL_TABLE"));
  519. mLineInfoBean.setDL_STATUSCODE(JsonUtils.optStringNull(devicelineObject, "DL_STATUSCODE"));
  520. mLineInfoBean.setDL_STATUS(JsonUtils.optStringNull(devicelineObject, "DL_STATUS"));
  521. mLineInfoBean.setPS_ID(JsonUtils.optLongNotNull(devicelineObject, "PS_ID"));
  522. mLineInfoBean.setMA_ID(JsonUtils.optLongNotNull(devicelineObject, "MA_ID"));
  523. mLineInfoBean.setDL_PRODCODE(JsonUtils.optStringNotNull(devicelineObject, "DL_PRODCODE"));
  524. PdaApplication.putDataCache2Map(Constants.FLAG.SMT_DEVICE_LINE_CACHE, mLineInfoBean);
  525. mDecodeTextView.setText(mLineInfoBean.getDL_DECODE());
  526. mStatusTextView.setText(mLineInfoBean.getDL_STATUS());
  527. mLinecodeTextView.setText(mLineInfoBean.getDL_LINECODE());
  528. mTableTextView.setText(mLineInfoBean.getDL_TABLE() + "面");
  529. mMacodeTextView.setText(mLineInfoBean.getDL_MACODE());
  530. mProdcodeTextView.setText(mLineInfoBean.getDL_PRODCODE());
  531. }
  532. String smtLocation = dataObject.optString("smtlocation");
  533. if (!TextUtils.isEmpty(smtLocation))
  534. SharedPreUtil.saveString(mActivity, Constants.FLAG.SMT_LOCATION_CACHE, smtLocation);
  535. CommonUtil.toastNoRepeat(mActivity, "机台暂停成功");
  536. }
  537. }
  538. } catch (Exception e) {
  539. }
  540. }
  541. }, new Response.ErrorListener() {
  542. @Override
  543. public void onErrorResponse(VolleyError volleyError) {
  544. if (progressDialog.isShowing())
  545. progressDialog.dismiss();
  546. CommonUtil.showErrorToast(volleyError, true);
  547. closeMachinePopupWindow();
  548. }
  549. }) {
  550. @Override
  551. public Map<String, String> getHeaders() throws AuthFailureError {
  552. return VolleyUtil.getVolleyUtil().setCookies();
  553. }
  554. @Override
  555. protected Map<String, String> getParams() throws AuthFailureError {
  556. Map<String, String> params = new HashMap<String, String>();
  557. String deviceLineMake = JSON.toJSONString(mLineInfoBean);
  558. params.put("deviceLineMake", deviceLineMake);
  559. return params;
  560. }
  561. };
  562. mStringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000, 0, 1f));
  563. mStringRequest.setTag(TAG + "stop");
  564. PdaApplication.mRequestQueue.add(mStringRequest);
  565. }
  566. /**
  567. * 验证登录密码
  568. *
  569. * @param whichFunc 1:全部下料;2:工单切换
  570. */
  571. private void showVerificationPop(final int whichFunc) {
  572. LayoutInflater layoutInflater = (LayoutInflater) mActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  573. View popView = layoutInflater.inflate(R.layout.pop_password_verification, null);
  574. mCancelTextView = (TextView) popView.findViewById(R.id.pop_password_verification_cancel_tv);
  575. mConfirmTextView = (TextView) popView.findViewById(R.id.pop_password_verification_confirm_tv);
  576. mPasswordEditText = (ClearableEditText) popView.findViewById(R.id.pop_password_verification_et);
  577. mConfirmTextView.setOnClickListener(new View.OnClickListener() {
  578. @Override
  579. public void onClick(View v) {
  580. verificationPassword(whichFunc);
  581. }
  582. });
  583. mCancelTextView.setOnClickListener(new View.OnClickListener() {
  584. @Override
  585. public void onClick(View v) {
  586. closePasswordPopupWindow();
  587. }
  588. });
  589. mPasswordPopupWindow = new PopupWindow(popView, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, true);
  590. mPasswordPopupWindow.setBackgroundDrawable(new BitmapDrawable());
  591. mPasswordPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
  592. @Override
  593. public void onDismiss() {
  594. closePasswordPopupWindow();
  595. }
  596. });
  597. CommonUtil.setBackgroundAlpha(mActivity, 0.5f);
  598. mPasswordPopupWindow.showAtLocation(mActivity.getWindow().getDecorView(), Gravity.CENTER, 0, -100);
  599. CommonUtil.openKeybord(mPasswordEditText, mActivity);
  600. }
  601. /**
  602. * 验证登录密码
  603. *
  604. * @param whichFunc
  605. */
  606. private void verificationPassword(int whichFunc) {
  607. String input = mPasswordEditText.getText().toString().trim();
  608. if (TextUtils.isEmpty(input)) {
  609. CommonUtil.toastNoRepeat(mActivity, "请输入密码!");
  610. } else {
  611. /*String str = SharedPreUtil.getString(mActivity, SharedPreUtil.KEY_URI, null);
  612. if (str != null) {
  613. try {
  614. IPPORT ip = JsonTools.parseJsonToBean(str, IPPORT.class);
  615. String ipStr = ip.uriArray.get(0).ip;
  616. String portStr = ip.uriArray.get(0).port;
  617. String mUserCache = SharedPreUtil.getString(mActivity, ipStr + ":" + portStr, null);
  618. if (mUserCache != null) {
  619. JSONObject userCacheJsonObject = null;
  620. userCacheJsonObject = new JSONObject(mUserCache);
  621. JSONArray userCacheArray = userCacheJsonObject.getJSONArray(DataSourceManager.KEY_INFOARRAY);
  622. JSONObject userCacheObject = (JSONObject) userCacheArray.get(0);
  623. String password = userCacheObject.getString(DataSourceManager.KEY_PASSWORD);
  624. if (password != null) {
  625. if (password.equals(input)) {
  626. // CommonUtil.toastNoRepeat(mActivity, "验证通过!");
  627. closePasswordPopupWindow();
  628. if (whichFunc == 1)
  629. showConfirmAllDownDialog();
  630. else if (whichFunc == 2) {
  631. showWitchPopupWindow();
  632. }
  633. } else {
  634. CommonUtil.toastNoRepeat(mActivity, "密码错误,请重新输入!");
  635. mPasswordEditText.setText("");
  636. mPasswordEditText.requestFocus();
  637. }
  638. } else {
  639. CommonUtil.toastNoRepeat(mActivity, "密码丢失,请重新登录!");
  640. closePasswordPopupWindow();
  641. }
  642. } else {
  643. CommonUtil.toastNoRepeat(mActivity, "密码丢失,请重新登录!");
  644. closePasswordPopupWindow();
  645. }
  646. } catch (JSONException e) {
  647. e.printStackTrace();
  648. }
  649. } else {
  650. CommonUtil.toastNoRepeat(mActivity, "密码丢失,请重新登录!");
  651. closePasswordPopupWindow();
  652. }*/
  653. String verificationPwd = SharedPreUtil.getString(mActivity, Constants.FLAG.VERIFICATION_PASSWORD, null);
  654. if (TextUtils.isEmpty(verificationPwd)) {
  655. CommonUtil.toastNoRepeat(mActivity, "密码丢失,请重新登录!");
  656. CommonUtil.makeNotice();
  657. closePasswordPopupWindow();
  658. } else {
  659. if (verificationPwd.equals(input)) {
  660. // CommonUtil.toastNoRepeat(mActivity, "验证通过!");
  661. closePasswordPopupWindow();
  662. if (whichFunc == 1)
  663. showConfirmAllDownDialog();
  664. else if (whichFunc == 2) {
  665. showWitchPopupWindow();
  666. }
  667. } else {
  668. CommonUtil.toastNoRepeat(mActivity, "密码错误,请重新输入!");
  669. CommonUtil.makeNotice();
  670. mPasswordEditText.setText("");
  671. mPasswordEditText.requestFocus();
  672. }
  673. }
  674. }
  675. }
  676. /**
  677. * 切换工单
  678. */
  679. private void showWitchPopupWindow() {
  680. View switchView = View.inflate(mActivity, R.layout.popupwindom_switch_jobs, null);
  681. final AlertDialog switchDialog = new AlertDialog.Builder(mActivity).setView(switchView).create();
  682. final AutoCompleteTextView jobsEditText = (AutoCompleteTextView) switchView.findViewById(R.id.pop_switch_jobs_number_et);
  683. jobsEditText.setThreshold(1);
  684. final ClearableEditText outputEditText = (ClearableEditText) switchView.findViewById(R.id.pop_switch_jobs_output_et);
  685. final ImageView cleanIv = (ImageView) switchView.findViewById(R.id.pop_switch_jobs_clean_iv);
  686. RadioGroup mTableRadioGroup = (RadioGroup) switchView.findViewById(R.id.pop_switch_jobs_table_rg);
  687. final RadioButton mARadioButton = (RadioButton) switchView.findViewById(R.id.pop_switch_jobs_a_rb);
  688. final RadioButton mBRadioButton = (RadioButton) switchView.findViewById(R.id.pop_switch_jobs_b_rb);
  689. final TextView mConfirmTextView = (TextView) switchView.findViewById(R.id.pop_switch_jobs_confirm_tv);
  690. TextView mCancelTextView = (TextView) switchView.findViewById(R.id.pop_switch_jobs_cancel_tv);
  691. final CheckBox orderCheckBox = (CheckBox) switchView.findViewById(R.id.pop_switch_jobs_order_cb);
  692. LinearLayout mOperationLinearLayout = (LinearLayout) switchView.findViewById(R.id.pop_switch_jobs_operation_ll);
  693. final LinearLayout mExceptionLinearLayout = (LinearLayout) switchView.findViewById(R.id.pop_switch_jobs_exception_ll);
  694. final TextView mExceptionTextView = (TextView) switchView.findViewById(R.id.pop_switch_jobs_exception_msg_tv);
  695. final TextView mKnownTextView = (TextView) switchView.findViewById(R.id.pop_switch_jobs_exception_confirm_tv);
  696. mOperationLinearLayout.setVisibility(View.VISIBLE);
  697. mExceptionLinearLayout.setVisibility(View.GONE);
  698. outputEditText.requestFocus();
  699. outputEditText.setText(dl_madeqty + "");
  700. outputEditText.setSelection(outputEditText.getText().toString().trim().length());
  701. cleanIv.setOnClickListener(new View.OnClickListener() {
  702. @Override
  703. public void onClick(View v) {
  704. jobsEditText.setText("");
  705. }
  706. });
  707. mKnownTextView.setOnClickListener(new View.OnClickListener() {
  708. @Override
  709. public void onClick(View v) {
  710. mExceptionLinearLayout.setVisibility(View.GONE);
  711. mExceptionTextView.setText("");
  712. }
  713. });
  714. jobsEditText.addTextChangedListener(new TextWatcher() {
  715. @Override
  716. public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  717. }
  718. @Override
  719. public void onTextChanged(CharSequence s, int start, int before, int count) {
  720. if (!orderCheckBox.isChecked()) {
  721. if (s.length() >= 3) {
  722. if (!s.toString().matches(Constants.REGEX.NO_SYMBOL)) {
  723. CommonUtil.toastNoRepeat(getActivity(), getResources().getString(R.string.note_number_cannot_contain_special));
  724. jobsEditText.setText(null);
  725. jobsEditText.requestFocus();
  726. } else {
  727. fuzzySearch(jobsEditText, MACODE_FUZZY);
  728. }
  729. }
  730. } else {
  731. if (s.length() >= 3) {
  732. if (!s.toString().matches(Constants.REGEX.NO_SYMBOL)) {
  733. CommonUtil.toastNoRepeat(getActivity(), getResources().getString(R.string.product_code_cannot_contain_special));
  734. jobsEditText.setText(null);
  735. jobsEditText.requestFocus();
  736. } else {
  737. fuzzySearch(jobsEditText, PRODCODE_FUZZY);
  738. }
  739. }
  740. }
  741. }
  742. @Override
  743. public void afterTextChanged(Editable s) {
  744. if (s == null || s.length() == 0) {
  745. mConfirmTextView.setEnabled(false);
  746. cleanIv.setVisibility(View.GONE);
  747. } else {
  748. mConfirmTextView.setEnabled(true);
  749. cleanIv.setVisibility(View.VISIBLE);
  750. }
  751. }
  752. });
  753. orderCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  754. @Override
  755. public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  756. if (!isChecked) {
  757. jobsEditText.setHint("请输入新工单号");
  758. mAutoStringAdapter = new MyArrayAdapter<String>(mActivity, android.R.layout.simple_dropdown_item_1line, new ArrayList<String>());
  759. jobsEditText.setAdapter(mAutoStringAdapter);
  760. } else {
  761. jobsEditText.setHint("请输入产品代码");
  762. mAutoStringAdapter = new MyArrayAdapter<String>(mActivity, android.R.layout.simple_dropdown_item_1line, new ArrayList<String>());
  763. jobsEditText.setAdapter(mAutoStringAdapter);
  764. }
  765. }
  766. });
  767. mConfirmTextView.setOnClickListener(new View.OnClickListener() {
  768. @Override
  769. public void onClick(View v) {
  770. final String linecode = mLineInfoBean.getDL_LINECODE();
  771. final String jobs = jobsEditText.getText().toString().trim();
  772. String outputStr = outputEditText.getText().toString().trim();
  773. String table = "A";
  774. if (!TextUtils.isEmpty(jobs)) {
  775. if (mARadioButton.isChecked()) {
  776. table = "A";
  777. } else if (mBRadioButton.isChecked()) {
  778. table = "B";
  779. }
  780. if (jobs.equals(mLineInfoBean.getDL_MACODE()) && table.equals(mLineInfoBean.getDL_TABLE())) {
  781. if (!orderCheckBox.isChecked()) {
  782. CommonUtil.toastNoRepeat(mActivity, "无法切换至相同的工单号+板面!");
  783. } else {
  784. CommonUtil.toastNoRepeat(mActivity, "无法切换至相同的产品代码+板面!");
  785. }
  786. CommonUtil.makeNotice();
  787. } else {
  788. try {
  789. if (TextUtils.isEmpty(outputStr)) {
  790. CommonUtil.toastNoRepeat(mActivity, "请输入原工单产出数");
  791. } else {
  792. int quantity = (int) Long.parseLong(outputStr);
  793. if (quantity >= dl_madeqty && quantity <= ma_qty) {
  794. switchJobs(linecode, jobs, table, jobsEditText, outputEditText, switchDialog, orderCheckBox.isChecked(), mExceptionLinearLayout, mExceptionTextView);
  795. } else {
  796. CommonUtil.toastNoRepeat(mActivity, "数量必须介于产出数和工单数之间");
  797. CommonUtil.makeNotice();
  798. }
  799. }
  800. } catch (Exception e) {
  801. outputEditText.setText(dl_madeqty + "");
  802. outputEditText.setSelection(outputEditText.getText().toString().trim().length());
  803. CommonUtil.toastNoRepeat(mActivity, "产出数应为正整数");
  804. CommonUtil.makeNotice();
  805. }
  806. }
  807. }
  808. }
  809. });
  810. mCancelTextView.setOnClickListener(new View.OnClickListener() {
  811. @Override
  812. public void onClick(View v) {
  813. // closeSwitchPopupWindow();
  814. switchDialog.dismiss();
  815. }
  816. });
  817. switchDialog.show();
  818. // mSwitchPopupWindow = new PopupWindow(switchView, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, true);
  819. // mSwitchPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
  820. // @Override
  821. // public void onDismiss() {
  822. // closeSwitchPopupWindow();
  823. // }
  824. // });
  825. // CommonUtil.setBackgroundAlpha(mActivity, 0.5f);
  826. // mSwitchPopupWindow.showAtLocation(mActivity.getWindow().getDecorView(), Gravity.CENTER, 0, -100);
  827. CommonUtil.openKeybord(outputEditText, mActivity);
  828. }
  829. /**
  830. * 模糊查询
  831. *
  832. * @param jobsEditText
  833. * @param fuzzy
  834. */
  835. private void fuzzySearch(final AutoCompleteTextView jobsEditText, final int fuzzy) {
  836. String url = null;
  837. try {
  838. if (fuzzy == MACODE_FUZZY)
  839. url = GloableParams.ADDRESS_SMT_FUZZY_SEARCH
  840. + "?inoutNo=" + URLEncoder.encode(jobsEditText.getText().toString().toLowerCase(), "utf-8");
  841. else if (fuzzy == PRODCODE_FUZZY)
  842. url = GloableParams.ADDRESS_SMT_FUZZY_SEARCH_PRODUCT
  843. + "?pr_code=" + URLEncoder.encode(jobsEditText.getText().toString().toLowerCase(), "utf-8");
  844. } catch (UnsupportedEncodingException e) {
  845. e.printStackTrace();
  846. if (fuzzy == MACODE_FUZZY)
  847. url = GloableParams.ADDRESS_SMT_FUZZY_SEARCH
  848. + "?inoutNo=" + jobsEditText.getText().toString().toLowerCase();
  849. else
  850. url = GloableParams.ADDRESS_SMT_FUZZY_SEARCH_PRODUCT
  851. + "?pr_code=" + jobsEditText.getText().toString().toLowerCase();
  852. }
  853. PdaApplication.mRequestQueue.cancelAll(TAG + "fuzzysearch");
  854. mStringRequest = new StringRequest(Request.Method.GET, url,
  855. new Response.Listener<String>() {
  856. @Override
  857. public void onResponse(String s) {
  858. Log.e("autoStrings", s);
  859. List<String> mAutoStrings = new ArrayList<String>();
  860. try {
  861. mAutoStrings.clear();
  862. mAutoStringAdapter = new MyArrayAdapter<String>(mActivity, android.R.layout.simple_dropdown_item_1line, mAutoStrings);
  863. if (jobsEditText != null) {
  864. jobsEditText.setAdapter(mAutoStringAdapter);
  865. }
  866. JSONObject resultObject = new JSONObject(s);
  867. JSONArray dataArray = resultObject.optJSONArray("data");
  868. if (dataArray != null) {
  869. for (int i = 0; i < dataArray.length(); i++) {
  870. JSONObject dataObject = dataArray.optJSONObject(i);
  871. if (dataObject != null) {
  872. String pi_inoutno = JsonUtils.optStringNotNull(dataObject, fuzzy == MACODE_FUZZY ? "MA_CODE" : "PR_CODE");
  873. if (!TextUtils.isEmpty(pi_inoutno))
  874. mAutoStringAdapter.add(pi_inoutno);
  875. }
  876. }
  877. }
  878. } catch (JSONException e) {
  879. e.printStackTrace();
  880. }
  881. }
  882. },
  883. new Response.ErrorListener() {
  884. @Override
  885. public void onErrorResponse(VolleyError volleyError) {
  886. CommonUtil.showErrorToast(volleyError);
  887. jobsEditText.setText("");
  888. jobsEditText.requestFocus();
  889. CommonUtil.openKeybord(jobsEditText, mActivity);
  890. }
  891. }) {
  892. @Override
  893. public Map<String, String> getHeaders() throws AuthFailureError {
  894. return VolleyUtil.getVolleyUtil().setCookies();
  895. }
  896. };
  897. mStringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000, 0, 1f));
  898. mStringRequest.setTag(TAG + "fuzzysearch");
  899. PdaApplication.mRequestQueue.add(mStringRequest);
  900. }
  901. /**
  902. * 切换工单
  903. *
  904. * @param linecode 线别
  905. * @param jobs 工单
  906. * @param table 板面
  907. * @param jobsEditText 工单输入框
  908. * @param outputEditText
  909. * @param switchDialog 弹出框
  910. * @param checked 是否被选中
  911. * @param mExceptionLinearLayout
  912. * @param mExceptionTextView
  913. */
  914. private void switchJobs(final String linecode, final String jobs, String table, final AutoCompleteTextView jobsEditText, final ClearableEditText outputEditText, final AlertDialog switchDialog, final boolean checked, final LinearLayout mExceptionLinearLayout, final TextView mExceptionTextView) {
  915. progressDialog.show();
  916. PdaApplication.mRequestQueue.cancelAll(TAG + "change");
  917. final String finalTable = table;
  918. mStringRequest = new StringRequest(Request.Method.POST, GloableParams.ADDRESS_SMT_CHANGE_MAKE,
  919. new Response.Listener<String>() {
  920. @Override
  921. public void onResponse(String s) {
  922. switchDialog.dismiss();
  923. if (progressDialog.isShowing())
  924. progressDialog.dismiss();
  925. try {
  926. Log.d("result", s);
  927. JSONObject resultObject = new JSONObject(s);
  928. if (resultObject.optBoolean("success")) {
  929. JSONObject dataObject = resultObject.optJSONObject("data");
  930. if (dataObject != null) {
  931. JSONObject devicelineObject = dataObject.optJSONObject("deviceline");
  932. if (devicelineObject != null) {
  933. mLineInfoBean = new LineInfoBean();
  934. mLineInfoBean.setDL_ID(JsonUtils.optLongNotNull(devicelineObject, "DL_ID"));
  935. mLineInfoBean.setDL_DECODE(JsonUtils.optStringNull(devicelineObject, "DL_DECODE"));
  936. mLineInfoBean.setDL_LINECODE(JsonUtils.optStringNull(devicelineObject, "DL_LINECODE"));
  937. mLineInfoBean.setDL_MACODE(JsonUtils.optStringNull(devicelineObject, "DL_MACODE"));
  938. mLineInfoBean.setDL_TABLE(JsonUtils.optStringNull(devicelineObject, "DL_TABLE"));
  939. mLineInfoBean.setDL_STATUSCODE(JsonUtils.optStringNull(devicelineObject, "DL_STATUSCODE"));
  940. mLineInfoBean.setDL_STATUS(JsonUtils.optStringNull(devicelineObject, "DL_STATUS"));
  941. mLineInfoBean.setPS_ID(JsonUtils.optLongNotNull(devicelineObject, "PS_ID"));
  942. mLineInfoBean.setMA_ID(JsonUtils.optLongNotNull(devicelineObject, "MA_ID"));
  943. mLineInfoBean.setDL_PRODCODE(JsonUtils.optStringNotNull(devicelineObject, "DL_PRODCODE"));
  944. PdaApplication.putDataCache2Map(Constants.FLAG.SMT_DEVICE_LINE_CACHE, mLineInfoBean);
  945. CommonUtil.toastNoRepeat(mActivity, "工单切换成功!");
  946. mDecodeTextView.setText(mLineInfoBean.getDL_DECODE());
  947. mStatusTextView.setText(mLineInfoBean.getDL_STATUS());
  948. mLinecodeTextView.setText(mLineInfoBean.getDL_LINECODE());
  949. mTableTextView.setText(mLineInfoBean.getDL_TABLE() + "面");
  950. mMacodeTextView.setText(mLineInfoBean.getDL_MACODE());
  951. mProdcodeTextView.setText(mLineInfoBean.getDL_PRODCODE());
  952. }
  953. String smtLocation = dataObject.optString("smtlocation");
  954. Log.d("smtLocation", smtLocation);
  955. if (!TextUtils.isEmpty(smtLocation))
  956. SharedPreUtil.saveString(mActivity, Constants.FLAG.SMT_LOCATION_CACHE, smtLocation);
  957. }
  958. }
  959. } catch (JSONException e) {
  960. e.printStackTrace();
  961. }
  962. }
  963. },
  964. new Response.ErrorListener() {
  965. @Override
  966. public void onErrorResponse(VolleyError volleyError) {
  967. if (progressDialog.isShowing())
  968. progressDialog.dismiss();
  969. String errorToast = CommonUtil.showErrorToast(volleyError, false);
  970. mExceptionLinearLayout.setVisibility(View.VISIBLE);
  971. mExceptionTextView.setText(errorToast);
  972. jobsEditText.setText("");
  973. outputEditText.setText(dl_madeqty + "");
  974. outputEditText.setSelection(outputEditText.getText().toString().trim().length());
  975. outputEditText.requestFocus();
  976. }
  977. }) {
  978. @Override
  979. public Map<String, String> getHeaders() throws AuthFailureError {
  980. return VolleyUtil.getVolleyUtil().setCookies();
  981. }
  982. @Override
  983. protected Map<String, String> getParams() throws AuthFailureError {
  984. Map<String, String> params = new HashMap<String, String>();
  985. params.put("dl_linecode", linecode);
  986. params.put("ma_code", jobs);
  987. params.put("table", finalTable);
  988. params.put("dl_actmadeqty", outputEditText.getText().toString().trim());
  989. params.put("has_noma", checked + "");
  990. return params;
  991. }
  992. };
  993. mStringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000, 0, 1f));
  994. mStringRequest.setTag(TAG + "change");
  995. PdaApplication.mRequestQueue.add(mStringRequest);
  996. }
  997. private void closeMachinePopupWindow() {
  998. if (mMachinePopupWindow != null) {
  999. mMachinePopupWindow.dismiss();
  1000. CommonUtil.setBackgroundAlpha(mActivity, 1f);
  1001. }
  1002. }
  1003. private void closeSwitchPopupWindow() {
  1004. if (mSwitchPopupWindow != null) {
  1005. mSwitchPopupWindow.dismiss();
  1006. CommonUtil.setBackgroundAlpha(mActivity, 1f);
  1007. }
  1008. }
  1009. private void closeDownAllPopupWindow() {
  1010. if (mDownAllPopupWindow != null) {
  1011. mDownAllPopupWindow.dismiss();
  1012. CommonUtil.setBackgroundAlpha(mActivity, 1f);
  1013. }
  1014. }
  1015. private void closePasswordPopupWindow() {
  1016. if (mPasswordPopupWindow != null) {
  1017. mPasswordPopupWindow.dismiss();
  1018. CommonUtil.setBackgroundAlpha(mActivity, 1f);
  1019. }
  1020. }
  1021. /*=============================全部下料=========================================*/
  1022. //全部下料对话框
  1023. /**
  1024. * 弹出全部下料对话框
  1025. */
  1026. private void showConfirmAllDownDialog() {
  1027. final ClearableEditText quantityEditText = (ClearableEditText) downAllView.findViewById(R.id.pop_smt_down_all_et);
  1028. CheckBox unbindCheckBox = downAllView.findViewById(R.id.pop_smt_down_unbind_cb);
  1029. unbindCheckBox.setChecked(true);
  1030. final TextView mConfirmTextView = (TextView) downAllView.findViewById(R.id.pop_smt_down_all_confirm_tv);
  1031. TextView mCancelTextView = (TextView) downAllView.findViewById(R.id.pop_smt_down_all_cancel_tv);
  1032. quantityEditText.setText(dl_madeqty + "");
  1033. quantityEditText.setSelection(quantityEditText.getText().toString().trim().length());
  1034. mConfirmTextView.addTextChangedListener(new TextWatcher() {
  1035. @Override
  1036. public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  1037. }
  1038. @Override
  1039. public void onTextChanged(CharSequence s, int start, int before, int count) {
  1040. }
  1041. @Override
  1042. public void afterTextChanged(Editable s) {
  1043. if (s == null || s.length() == 0) {
  1044. mConfirmTextView.setEnabled(false);
  1045. } else {
  1046. mConfirmTextView.setEnabled(true);
  1047. }
  1048. }
  1049. });
  1050. mConfirmTextView.setOnClickListener(new View.OnClickListener() {
  1051. @Override
  1052. public void onClick(View v) {
  1053. String quantityStr = quantityEditText.getText().toString().trim();
  1054. try {
  1055. int quantity = (int) Long.parseLong(quantityStr);
  1056. if (quantity >= dl_madeqty && quantity <= ma_qty) {
  1057. disposeAllDown(quantity, unbindCheckBox.isChecked());
  1058. } else {
  1059. CommonUtil.toastNoRepeat(mActivity, "数量必须介于产出数和工单数之间");
  1060. CommonUtil.makeNotice();
  1061. }
  1062. } catch (Exception e) {
  1063. quantityEditText.setText(dl_madeqty + "");
  1064. quantityEditText.setSelection(quantityEditText.getText().toString().trim().length());
  1065. CommonUtil.toastNoRepeat(mActivity, "产出数应为正整数");
  1066. CommonUtil.makeNotice();
  1067. }
  1068. }
  1069. });
  1070. mCancelTextView.setOnClickListener(new View.OnClickListener() {
  1071. @Override
  1072. public void onClick(View v) {
  1073. // closeDownAllPopupWindow();
  1074. switchDialog.dismiss();
  1075. }
  1076. });
  1077. switchDialog.show();
  1078. //
  1079. // mDownAllPopupWindow = new PopupWindow(downAllView, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, true);
  1080. //
  1081. // mDownAllPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
  1082. // @Override
  1083. // public void onDismiss() {
  1084. // closeDownAllPopupWindow();
  1085. // }
  1086. // });
  1087. // CommonUtil.setBackgroundAlpha(mActivity, 0.5f);
  1088. // mDownAllPopupWindow.showAtLocation(mActivity.getWindow().getDecorView(), Gravity.CENTER, 0, -100);
  1089. CommonUtil.openKeybord(quantityEditText, mActivity);
  1090. }
  1091. //全部下料
  1092. private void disposeAllDown(int quantity, boolean unbind) {
  1093. showLoadingView();
  1094. VolleyUtil.getVolleyUtil().requestSMTAllDown(getActivity(),
  1095. GloableParams.ADDRESS_SMT_CUTTING_ALLSTOCK,
  1096. VolleyUtil.METHOD_POST,
  1097. VolleyUtil.FRAGMENT_SCMAKE_SMTALLDOWN,
  1098. mLineInfoBean.getDL_MACODE(),
  1099. mLineInfoBean.getDL_LINECODE(),
  1100. quantity,
  1101. unbind);
  1102. }
  1103. /*======================ConfirmDialog==========================================*/
  1104. ConfirmDialog confirmDialog;
  1105. boolean isOk = false;
  1106. //关闭确认对话框
  1107. public void closeConfirmDialog() {
  1108. confirmDialog.dismiss();
  1109. }
  1110. /*============================Volley Handler=========================================*/
  1111. Handler volleyHandler = new Handler() {
  1112. @Override
  1113. public void handleMessage(Message msg) {
  1114. // closeDownAllPopupWindow();
  1115. switchDialog.dismiss();
  1116. if (progressDialog.isShowing())
  1117. progressDialog.dismiss();
  1118. String noticeMsg = (String) msg.obj;
  1119. CommonUtil.toastNoRepeat(mActivity, noticeMsg);
  1120. if (msg.what == VolleyUtil.SUCCESS_SUCCESS) {
  1121. SharedPreUtil.saveString(mActivity, Constants.FLAG.SMT_LOCATION_CACHE, "");
  1122. getActivity().getSupportFragmentManager().popBackStack();
  1123. }
  1124. }
  1125. };
  1126. /*============================公用方法=========================================*/
  1127. /**
  1128. * @注释:显示错误提示
  1129. */
  1130. ConfirmDialog noticeDialog;
  1131. private void showNotice(String noticeMsg) {
  1132. noticeDialog = new ConfirmDialog(getActivity());
  1133. noticeDialog.show(noticeMsg, ConfirmDialog.NOTICE);
  1134. new AsyncTask<String, Void, Float>() {
  1135. @Override
  1136. protected Float doInBackground(String... params) {
  1137. try {
  1138. //notice显示1.5s
  1139. Thread.sleep(1500);
  1140. } catch (InterruptedException e) {
  1141. e.printStackTrace();
  1142. }
  1143. return null;
  1144. }
  1145. @Override
  1146. protected void onPostExecute(Float aFloat) {
  1147. //notice退出
  1148. //noticeTextView.startAnimation(noticeOut);
  1149. // noticeTextView.setVisibility(View.GONE);
  1150. noticeDialog.dismiss();
  1151. }
  1152. }.execute();
  1153. }
  1154. /**
  1155. * 显示loadingView
  1156. */
  1157. private void showLoadingView() {
  1158. if (!progressDialog.isShowing()) {
  1159. progressDialog.show();
  1160. }
  1161. }
  1162. @Override
  1163. public boolean onKeyDown(int keyCode, KeyEvent event) {
  1164. Log.e("SMTINDEX", "onKeyDown");
  1165. if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
  1166. if (progressDialog != null && progressDialog.isShowing()) {
  1167. // loadingView.dismiss();
  1168. // VolleyUtil.distoryVolley();
  1169. return true;
  1170. }
  1171. if (confirmDialog != null && confirmDialog.isShowing()) {
  1172. Log.e("SMTINDEX", "confirmDialog");
  1173. closeConfirmDialog();
  1174. return true;
  1175. }
  1176. if (noticeDialog != null && noticeDialog.isShowing()) {
  1177. noticeDialog.dismiss();
  1178. return true;
  1179. }
  1180. }
  1181. return false;
  1182. }
  1183. @Override
  1184. public boolean onFragmentBackPressed() {
  1185. return false;
  1186. }
  1187. }