PieceActivity.java 79 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684
  1. package com.jiaju.activity;
  2. import java.io.Serializable;
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import org.json.JSONArray;
  7. import org.json.JSONException;
  8. import org.json.JSONObject;
  9. import com.jiaju.adapter.PieceListMessageAdapter;
  10. import com.jiaju.model.Piece;
  11. import com.jiaju.net.WebClient;
  12. import com.jiaju.utils.CommonUtil;
  13. import com.jiaju.utils.Constants;
  14. import com.jiaju.utils.CustomToast;
  15. import com.jiaju.utils.ProcessDialogUtils;
  16. import com.jiaju.utils.Removeduplicate;
  17. import com.jiaju.widget.CommonPopMenu;
  18. import android.app.Activity;
  19. import android.app.Notification;
  20. import android.content.Context;
  21. import android.content.Intent;
  22. import android.content.SharedPreferences;
  23. import android.content.res.Configuration;
  24. import android.content.res.Resources;
  25. import android.os.Bundle;
  26. import android.os.Handler;
  27. import android.os.HandlerThread;
  28. import android.os.Message;
  29. import android.text.Editable;
  30. import android.text.InputFilter;
  31. import android.text.InputType;
  32. import android.text.Spanned;
  33. import android.text.TextUtils;
  34. import android.text.TextWatcher;
  35. import android.view.Gravity;
  36. import android.view.KeyEvent;
  37. import android.view.MotionEvent;
  38. import android.view.View;
  39. import android.view.View.OnClickListener;
  40. import android.view.View.OnFocusChangeListener;
  41. import android.view.inputmethod.EditorInfo;
  42. import android.view.inputmethod.InputMethodManager;
  43. import android.widget.Button;
  44. import android.widget.EditText;
  45. import android.widget.ImageButton;
  46. import android.widget.ImageView;
  47. import android.widget.LinearLayout;
  48. import android.widget.ListView;
  49. import android.widget.PopupWindow;
  50. import android.widget.TextView;
  51. import android.widget.TextView.OnEditorActionListener;
  52. import android.widget.Toast;
  53. //点数装板
  54. public class PieceActivity extends Activity {
  55. private EditText met; // 工号
  56. private EditText barcode; // 条码
  57. public Button bt2;// 确定按键
  58. private ImageButton btnCancle;// 返回
  59. private TextView backtext;
  60. private TextView title;// 标题
  61. private SharedPreferences sp;
  62. private String FILE = "user";// 用于保存SharedPreferences的文件
  63. private String accountCode = "";// 帐套
  64. private String userPassword = "";// 用户密码
  65. private String sessionKey = "";// sessionKey,每次登陆都会改变
  66. private String ServerAddress_ip, ServerAddress_duankou;
  67. private JSONObject jsonObject;
  68. private PieceListMessageAdapter pieceAdapter = null;
  69. private WebClient client;
  70. private int proId;// 工序I
  71. public static boolean isSlide = false;
  72. private String code = "";
  73. private int collectType;// 采集类型:1-集中 2-单点
  74. private ListView list1;
  75. private Boolean produceCodeIsValid = false;// 条码是否验证
  76. private Boolean userCodeIsValid = false;// 生产工号是否验证
  77. private String piece_userCode;
  78. // 生产工号验证返回字段
  79. private String userID1 = "";// 条码对应的产品ID
  80. private String userCode1 = "";// 生产工号Code
  81. private String userName1 = "";// 生产工号Name
  82. private String outErrMsg = "";
  83. // 服务器返回_生产条码检验
  84. private String out_goodsID = "";// 条码对应的产品ID
  85. private String out_goodsCode = "";// 条码对应的产品Code
  86. private String out_goodsName = "";// 条码对应的产品Name
  87. private ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();
  88. private Piece piece = null;
  89. private String procedureName;
  90. public static List<Piece> piecelist = null;
  91. private HandlerThread thread;
  92. private Handler mHandler = null;
  93. private int nodeType;
  94. private ImageView productRecord;
  95. private LinearLayout parent;
  96. private PopupWindow mPopupWindow; // 弹出框
  97. private Object obj = new Object();
  98. private Handler upperH = new Handler();
  99. private String userUpper;
  100. private Handler barcodeUpperH = new Handler();
  101. private String barcodeUpper;
  102. //限制同商标
  103. private String spm_011;
  104. //限制同型号
  105. private String spm_012;
  106. //限制每板装板数量
  107. private String spm_013;
  108. // 最大装车数量
  109. private int plateNum;
  110. private int isGlazeChange;
  111. private String NewWaterEfficiencyLabelActivity;//水效标识flag
  112. private String NewWaterBarcode=""; //水效标识的barcode
  113. @Override
  114. protected void onCreate(Bundle savedInstanceState) {
  115. super.onCreate(savedInstanceState);
  116. setContentView(R.layout.activity_pieces);
  117. piecelist = new ArrayList<Piece>();
  118. initview();
  119. ////CommonUtil.BarcodeMaxLength(barcode, 50);;
  120. alllistener();
  121. Intent intent = getIntent();
  122. Bundle bundle = intent.getExtras();
  123. proId = bundle.getInt("procedureId");
  124. nodeType=bundle.getInt("nodeType");
  125. isGlazeChange=bundle.getInt("isGlazeChange");
  126. NewWaterEfficiencyLabelActivity=bundle.getString("NewWaterEfficiencyLabelActivity");
  127. NewWaterBarcode=bundle.getString("NewWaterBarcode");
  128. collectType = bundle.getInt("collectType");
  129. sp = getSharedPreferences(FILE, MODE_PRIVATE);
  130. procedureName = bundle.getString("procedureName");
  131. title.setText(bundle.getString("procedureName"));// 设置标题
  132. // 获得账户信息;
  133. accountCode = sp.getString("AccountCode", "");
  134. piece_userCode = sp.getString("UserCode", "");
  135. userPassword = sp.getString("UserPassword", "");
  136. sessionKey = sp.getString("SessionKey", "");
  137. // 获取服务ip和端口号
  138. ServerAddress_ip = sp.getString("ServerAddress_ip", "");
  139. ServerAddress_duankou = sp.getString("ServerAddress_duankou", "");
  140. switch (collectType) {
  141. case 2:// 单点采集
  142. met.setEnabled(false);
  143. met.setFocusable(false);
  144. met.setText(piece_userCode);
  145. met.setFilters(new InputFilter[] { new InputFilter() {
  146. @Override
  147. public CharSequence filter(CharSequence source, int start,
  148. int end, Spanned dest, int dstart, int dend) {
  149. return source.length() < 1 ? dest.subSequence(dstart, dend)
  150. : "";
  151. }
  152. } });
  153. bt2.setVisibility(View.INVISIBLE);
  154. barcode.setFocusable(true);
  155. barcode.requestFocus();
  156. barcode.findFocus();
  157. ProcessDialogUtils.showProcessDialog(PieceActivity.this);
  158. thread = null;
  159. thread = new HandlerThread("userHandlerThread", 5);
  160. thread.start();
  161. mHandler = null;
  162. mHandler = new Handler(thread.getLooper());
  163. UserRunnable userRunnable = new UserRunnable();
  164. mHandler.post(userRunnable);
  165. break;
  166. case 1:// 集中采集
  167. met.setEnabled(true);
  168. met.setFocusable(true);
  169. met.requestFocus();
  170. met.findFocus();
  171. met.setSelectAllOnFocus(true);
  172. break;
  173. }
  174. }
  175. /**
  176. * 如果是从水效标识界面过来的 会调用这个方法
  177. */
  178. private void searchBarCode(String etcode) {
  179. String workno = met.getText().toString();
  180. if (TextUtils.isEmpty(workno)) {
  181. // Toast.makeText(getApplicationContext(), "生产工号不能为空",
  182. // Toast.LENGTH_SHORT).show();
  183. CustomToast.showToast(getApplicationContext(),
  184. "生产工号不能为空", 2000);
  185. met.setEnabled(true);
  186. met.setFocusable(true);
  187. met.setFocusableInTouchMode(true);
  188. met.requestFocus();
  189. met.findFocus();
  190. met.setFilters(new InputFilter[] { new InputFilter() {
  191. @Override
  192. public CharSequence filter(CharSequence source,
  193. int start, int end, Spanned dest,
  194. int dstart, int dend) {
  195. return null;
  196. }
  197. } });
  198. return;
  199. } else {
  200. if (!userCodeIsValid) {
  201. ProcessDialogUtils.closeProgressDilog();
  202. CustomToast.showToast(getApplicationContext(),
  203. "请在生产工号输入框内按回车键验证生产工号", 2000);
  204. met.setEnabled(true);
  205. met.setFocusable(true);
  206. met.setFocusableInTouchMode(true);
  207. met.requestFocus();
  208. met.findFocus();
  209. met.setFilters(new InputFilter[] { new InputFilter() {
  210. @Override
  211. public CharSequence filter(CharSequence source,
  212. int start, int end, Spanned dest,
  213. int dstart, int dend) {
  214. return null;
  215. }
  216. } });
  217. return;
  218. }
  219. ProcessDialogUtils
  220. .showProcessDialog(PieceActivity.this);
  221. barcode.setEnabled(false);
  222. barcode.setFocusable(false);
  223. barcode.setFilters(new InputFilter[] { new InputFilter() {
  224. @Override
  225. public CharSequence filter(CharSequence source,
  226. int start, int end, Spanned dest,
  227. int dstart, int dend) {
  228. return source.length() < 1 ? dest.subSequence(
  229. dstart, dend) : "";
  230. }
  231. } });
  232. // if (!CommonUtil.isNumber(etcode)) {
  233. // ProcessDialogUtils.closeProgressDilog();
  234. // CommonUtil.setDefault(Notification.DEFAULT_VIBRATE,
  235. // getApplicationContext());
  236. // //
  237. // CommonUtil.showRepeatDialog(code+"格式不匹配",PieceActivity.this);
  238. // CustomToast.showToast(getApplicationContext(),
  239. // etcode + "格式不匹配", 1000);
  240. // barcode.setEnabled(true);
  241. // barcode.setText("");
  242. // barcode.setFocusable(true);
  243. // barcode.setFocusableInTouchMode(true);
  244. // barcode.requestFocus();
  245. // barcode.findFocus();
  246. // barcode.setFilters(new InputFilter[] { new
  247. // InputFilter() {
  248. // @Override
  249. // public CharSequence filter(CharSequence source,
  250. // int start, int end, Spanned dest,
  251. // int dstart, int dend) {
  252. //
  253. // return null;
  254. // }
  255. // } });
  256. // CommonUtil.BarcodeMaxLength(barcode,50);
  257. // return;
  258. // }
  259. if (collectType == 2) {
  260. if (piecelist != null && piecelist.size() > 0) {
  261. piecelist.removeAll(piecelist);
  262. if (pieceAdapter != null) {
  263. pieceAdapter.notifyDataSetChanged();
  264. }
  265. }
  266. }
  267. if(nodeType!=3) {
  268. if (piecelist.size() > 0) {
  269. boolean b = Removeduplicate.removeBarCode(etcode,
  270. piecelist);
  271. if (b) {
  272. ProcessDialogUtils.closeProgressDilog();
  273. barcode.setEnabled(true);
  274. barcode.setText("");
  275. barcode.setFocusable(true);
  276. barcode.setFocusableInTouchMode(true);
  277. barcode.requestFocus();
  278. barcode.findFocus();
  279. barcode.setFilters(new InputFilter[] { new InputFilter() {
  280. @Override
  281. public CharSequence filter(
  282. CharSequence source, int start,
  283. int end, Spanned dest, int dstart,
  284. int dend) {
  285. return null;
  286. }
  287. } });
  288. //CommonUtil.BarcodeMaxLength(barcode, 50);;
  289. CommonUtil.setDefault(
  290. Notification.DEFAULT_VIBRATE,
  291. getApplicationContext());
  292. if (collectType == 2) {
  293. CommonUtil.showRepeatDialog("条码" + etcode
  294. + "重复", PieceActivity.this);
  295. } else if (collectType == 1) {
  296. // Toast.makeText(getApplicationContext(),"条码"+etcode+"重复",Toast.LENGTH_SHORT).show();
  297. CustomToast.showToast(
  298. getApplicationContext(), "条码"
  299. + etcode + "重复", 2000);
  300. }
  301. ProcessDialogUtils.closeProgressDilog();
  302. return;
  303. }
  304. }
  305. }
  306. if(collectType==1&&nodeType==3) {
  307. if(plateNum>0&&piecelist.size()==plateNum) {
  308. CommonUtil.setDefault(Notification.DEFAULT_VIBRATE,
  309. getApplicationContext());
  310. CommonUtil.showBarCodeAlertDialog(0, "超过装板数量【"+plateNum+"】",
  311. PieceActivity.this, barcode, null, null);
  312. ProcessDialogUtils.closeProgressDilog();
  313. return;
  314. }
  315. }
  316. thread = null;
  317. thread = new HandlerThread("BarCoderThread", 5);
  318. thread.start();
  319. mHandler = null;
  320. mHandler = new Handler(thread.getLooper());
  321. BarcodeRunnable barcodeRunnable = new BarcodeRunnable(
  322. etcode, obj);
  323. mHandler.post(barcodeRunnable);
  324. }
  325. }
  326. private void initview() {
  327. title = (TextView) findViewById(R.id.title);
  328. View head=View.inflate(this,R.layout.piece_head_view,null);
  329. btnCancle = (ImageButton) findViewById(R.id.left_img);
  330. barcode = (EditText) head.findViewById(R.id.good_tm);
  331. barcode.setRawInputType(InputType.TYPE_CLASS_NUMBER);
  332. met = (EditText)head.findViewById(R.id.good_code);
  333. bt2 = (Button) findViewById(R.id.btnsure);
  334. backtext = (TextView) findViewById(R.id.back);
  335. list1 = (ListView) this.findViewById(R.id.message_listview);
  336. list1.addHeaderView(head);
  337. pieceAdapter = new PieceListMessageAdapter(PieceActivity.this,piecelist);
  338. list1.setAdapter(pieceAdapter);
  339. parent = (LinearLayout) findViewById(R.id.parentRel);
  340. productRecord = (ImageView) findViewById(R.id.search);
  341. productRecord.setVisibility(View.VISIBLE);
  342. }
  343. private void alllistener() {
  344. productRecord.setOnClickListener(new View.OnClickListener() {
  345. @Override
  346. public void onClick(View v) {
  347. int height = parent.getHeight() - v.getHeight();
  348. CommonPopMenu recordPopMenu = new CommonPopMenu(
  349. PieceActivity.this, height);
  350. mPopupWindow = recordPopMenu.getMenu();
  351. if (mPopupWindow == null) {
  352. return;
  353. }
  354. if (mPopupWindow.isShowing()) {
  355. mPopupWindow.dismiss();
  356. return;
  357. }
  358. mPopupWindow.showAtLocation(parent, Gravity.BOTTOM, 0, 0);
  359. LinearLayout barcodeLay = (LinearLayout) recordPopMenu.menu
  360. .findViewById(R.id.barcodechangelay);
  361. ImageView scanImg = (ImageView) recordPopMenu.menu
  362. .findViewById(R.id.scanimg);
  363. TextView scanTitle = (TextView) recordPopMenu.menu
  364. .findViewById(R.id.scantitle);
  365. scanTitle.setText("扫一扫");
  366. scanImg.setBackgroundResource(R.drawable.scan);
  367. LinearLayout statisticsLay = (LinearLayout) recordPopMenu.menu
  368. .findViewById(R.id.statisticslay);
  369. statisticsLay.setVisibility(View.VISIBLE);
  370. ImageView statisticsImg = (ImageView) recordPopMenu.menu
  371. .findViewById(R.id.statisticsimg);
  372. statisticsImg.setBackgroundResource(R.drawable.tongji9);
  373. TextView statisticsTitle = (TextView) recordPopMenu.menu
  374. .findViewById(R.id.statisticstitle);
  375. statisticsTitle.setText("采集统计");
  376. statisticsLay.setOnClickListener(new View.OnClickListener() {
  377. @Override
  378. public void onClick(View v) {
  379. Intent intent = new Intent();
  380. Bundle bundle = new Bundle();
  381. bundle.putInt("procedureId", proId);
  382. bundle.putInt("collectType", collectType);
  383. bundle.putString("procedureName", procedureName);
  384. intent.putExtras(bundle);
  385. intent.setClass(PieceActivity.this,
  386. CollectionActivity.class);
  387. startActivity(intent);
  388. if (mPopupWindow.isShowing()) {
  389. mPopupWindow.dismiss();
  390. }
  391. }
  392. });
  393. barcodeLay.setOnClickListener(new View.OnClickListener() {
  394. @Override
  395. public void onClick(View v) {
  396. Intent openCameraIntent = new Intent(
  397. PieceActivity.this, CaptureActivity.class);
  398. startActivityForResult(openCameraIntent, 102);
  399. if (mPopupWindow.isShowing()) {
  400. mPopupWindow.dismiss();
  401. }
  402. }
  403. });
  404. }
  405. });
  406. backtext.setOnClickListener(new OnClickListener() {
  407. @Override
  408. public void onClick(View v) {
  409. finish();
  410. }
  411. });
  412. btnCancle.setOnClickListener(new OnClickListener() {
  413. @Override
  414. public void onClick(View v) {
  415. finish();
  416. }
  417. });
  418. // 保存确定按钮触发事件
  419. bt2.setOnClickListener(new OnClickListener() {
  420. @Override
  421. public void onClick(View v) {
  422. if (collectType == 1) {
  423. String workno = met.getText().toString();
  424. if (TextUtils.isEmpty(workno)) {
  425. CustomToast.showToast(getApplicationContext(),
  426. "生产工号不能为空", 2000);
  427. met.setEnabled(true);
  428. met.setFocusable(true);
  429. met.setFocusableInTouchMode(true);
  430. met.requestFocus();
  431. met.findFocus();
  432. met.setFilters(new InputFilter[] { new InputFilter() {
  433. @Override
  434. public CharSequence filter(CharSequence source,
  435. int start, int end, Spanned dest,
  436. int dstart, int dend) {
  437. return null;
  438. }
  439. } });
  440. return;
  441. } else {
  442. if (!userCodeIsValid) {
  443. CustomToast.showToast(getApplicationContext(),
  444. "请在生产工号输入框内按回车键验证生产工号", 2000);
  445. met.setEnabled(true);
  446. met.setFocusable(true);
  447. met.setFocusableInTouchMode(true);
  448. met.requestFocus();
  449. met.findFocus();
  450. met.setFilters(new InputFilter[] { new InputFilter() {
  451. @Override
  452. public CharSequence filter(CharSequence source,
  453. int start, int end, Spanned dest,
  454. int dstart, int dend) {
  455. return null;
  456. }
  457. } });
  458. return;
  459. }
  460. }
  461. if (piecelist.size() == 0) {
  462. CustomToast.showToast(getApplicationContext(),
  463. "没有可提交的明细信息", 2000);
  464. return;
  465. }
  466. if(collectType==1&&nodeType==3) {
  467. if(plateNum>0&&piecelist.size()!=plateNum) {
  468. CommonUtil.setDefault(Notification.DEFAULT_VIBRATE,
  469. getApplicationContext());
  470. CommonUtil.showBarCodeAlertDialog(0, "未达到装板数量【"+plateNum+"】",
  471. PieceActivity.this, barcode, null, null);
  472. return;
  473. }
  474. }
  475. if(isGlazeChange==1)
  476. {
  477. Intent intent=new Intent();
  478. intent.setClass(PieceActivity.this, GlazePieceSetActivity.class);
  479. Bundle b=new Bundle();
  480. b.putInt("procedureId",proId);
  481. intent.putExtras(b);
  482. startActivityForResult(intent,100);
  483. }
  484. else
  485. {
  486. ProcessDialogUtils.showProcessDialog(PieceActivity.this);
  487. if (bt2.isEnabled()) {
  488. bt2.setEnabled(false);
  489. getDataSaveBarCode();
  490. }
  491. }
  492. }
  493. }
  494. });
  495. met.setOnFocusChangeListener(new OnFocusChangeListener() {
  496. @Override
  497. public void onFocusChange(View v, boolean hasFocus) {
  498. EditText e = (EditText) v;
  499. String woCode = e.getText().toString();
  500. if (!woCode.contains("\n")) {
  501. if (!hasFocus) {
  502. if (!TextUtils.isEmpty(woCode)) {
  503. woCode = woCode.trim();
  504. met.setFocusable(false);
  505. met.setEnabled(false);
  506. met.setFilters(new InputFilter[] { new InputFilter() {
  507. @Override
  508. public CharSequence filter(CharSequence source,
  509. int start, int end, Spanned dest,
  510. int dstart, int dend) {
  511. return source.length() < 1 ? dest
  512. .subSequence(dstart, dend) : "";
  513. }
  514. } });
  515. barcode.setEnabled(false);
  516. barcode.setFocusable(false);
  517. barcode.setFilters(new InputFilter[] { new InputFilter() {
  518. @Override
  519. public CharSequence filter(CharSequence source,
  520. int start, int end, Spanned dest,
  521. int dstart, int dend) {
  522. return source.length() < 1 ? dest
  523. .subSequence(dstart, dend) : "";
  524. }
  525. } });
  526. ProcessDialogUtils
  527. .showProcessDialog(PieceActivity.this);
  528. thread = null;
  529. thread = new HandlerThread("userHandlerThread", 5);
  530. thread.start();
  531. mHandler = null;
  532. mHandler = new Handler(thread.getLooper());
  533. UserRunnable userRunnable = new UserRunnable(woCode);
  534. mHandler.post(userRunnable);
  535. }
  536. }
  537. }
  538. }
  539. });
  540. met.addTextChangedListener(new TextWatcher() {
  541. @Override
  542. public void afterTextChanged(Editable arg0) {
  543. if (met.getText().toString().contains("\n")) {
  544. String woCode = met.getText().toString().trim()
  545. .replaceAll("\\n", "");
  546. met.setFocusable(false);
  547. met.setEnabled(false);
  548. met.setFilters(new InputFilter[] { new InputFilter() {
  549. @Override
  550. public CharSequence filter(CharSequence source,
  551. int start, int end, Spanned dest, int dstart,
  552. int dend) {
  553. return source.length() < 1 ? dest.subSequence(
  554. dstart, dend) : "";
  555. }
  556. } });
  557. barcode.setEnabled(false);
  558. barcode.setFocusable(false);
  559. barcode.setFilters(new InputFilter[] { new InputFilter() {
  560. @Override
  561. public CharSequence filter(CharSequence source,
  562. int start, int end, Spanned dest, int dstart,
  563. int dend) {
  564. return source.length() < 1 ? dest.subSequence(
  565. dstart, dend) : "";
  566. }
  567. } });
  568. ProcessDialogUtils.showProcessDialog(PieceActivity.this);
  569. thread = null;
  570. thread = new HandlerThread("userHandlerThread", 5);
  571. thread.start();
  572. mHandler = null;
  573. mHandler = new Handler(thread.getLooper());
  574. UserRunnable userRunnable = new UserRunnable(woCode);
  575. mHandler.post(userRunnable);
  576. }
  577. }
  578. @Override
  579. public void beforeTextChanged(CharSequence s, int start, int count,
  580. int after) {
  581. }
  582. @Override
  583. public void onTextChanged(CharSequence s, int start, int before,
  584. int count) {
  585. userUpper = met.getText().toString();
  586. // 判断输入的文字是否是小写
  587. for (int i = 0; i < userUpper.length(); i++) {
  588. if (userUpper.charAt(i) - 0 >= 97
  589. && userUpper.charAt(i) - 0 <= 122) {
  590. upperH.postDelayed(UpperCase, 300);
  591. }
  592. }
  593. }
  594. });
  595. barcode.addTextChangedListener(new TextWatcher() {
  596. @Override
  597. public void afterTextChanged(Editable arg0) {
  598. if (barcode.getText().toString().contains("\n")) {
  599. String etcode = barcode.getText().toString().trim()
  600. .replaceAll("\\n", "");
  601. if(etcode.length() >= 73)
  602. {
  603. String[] parts = etcode.split("-", 2);
  604. if (parts.length == 2) {
  605. etcode = parts[1];
  606. }
  607. }
  608. String workno = met.getText().toString();
  609. if (TextUtils.isEmpty(workno)) {
  610. // Toast.makeText(getApplicationContext(), "生产工号不能为空",
  611. // Toast.LENGTH_SHORT).show();
  612. CustomToast.showToast(getApplicationContext(),
  613. "生产工号不能为空", 2000);
  614. met.setEnabled(true);
  615. met.setFocusable(true);
  616. met.setFocusableInTouchMode(true);
  617. met.requestFocus();
  618. met.findFocus();
  619. met.setFilters(new InputFilter[] { new InputFilter() {
  620. @Override
  621. public CharSequence filter(CharSequence source,
  622. int start, int end, Spanned dest,
  623. int dstart, int dend) {
  624. return null;
  625. }
  626. } });
  627. return;
  628. } else {
  629. if (!userCodeIsValid) {
  630. ProcessDialogUtils.closeProgressDilog();
  631. CustomToast.showToast(getApplicationContext(),
  632. "请在生产工号输入框内按回车键验证生产工号", 2000);
  633. met.setEnabled(true);
  634. met.setFocusable(true);
  635. met.setFocusableInTouchMode(true);
  636. met.requestFocus();
  637. met.findFocus();
  638. met.setFilters(new InputFilter[] { new InputFilter() {
  639. @Override
  640. public CharSequence filter(CharSequence source,
  641. int start, int end, Spanned dest,
  642. int dstart, int dend) {
  643. return null;
  644. }
  645. } });
  646. return;
  647. }
  648. ProcessDialogUtils
  649. .showProcessDialog(PieceActivity.this);
  650. barcode.setEnabled(false);
  651. barcode.setFocusable(false);
  652. barcode.setFilters(new InputFilter[] { new InputFilter() {
  653. @Override
  654. public CharSequence filter(CharSequence source,
  655. int start, int end, Spanned dest,
  656. int dstart, int dend) {
  657. return source.length() < 1 ? dest.subSequence(
  658. dstart, dend) : "";
  659. }
  660. } });
  661. // if (!CommonUtil.isNumber(etcode)) {
  662. // ProcessDialogUtils.closeProgressDilog();
  663. // CommonUtil.setDefault(Notification.DEFAULT_VIBRATE,
  664. // getApplicationContext());
  665. // //
  666. // CommonUtil.showRepeatDialog(code+"格式不匹配",PieceActivity.this);
  667. // CustomToast.showToast(getApplicationContext(),
  668. // etcode + "格式不匹配", 1000);
  669. // barcode.setEnabled(true);
  670. // barcode.setText("");
  671. // barcode.setFocusable(true);
  672. // barcode.setFocusableInTouchMode(true);
  673. // barcode.requestFocus();
  674. // barcode.findFocus();
  675. // barcode.setFilters(new InputFilter[] { new
  676. // InputFilter() {
  677. // @Override
  678. // public CharSequence filter(CharSequence source,
  679. // int start, int end, Spanned dest,
  680. // int dstart, int dend) {
  681. //
  682. // return null;
  683. // }
  684. // } });
  685. // CommonUtil.BarcodeMaxLength(barcode,50);
  686. // return;
  687. // }
  688. if (collectType == 2) {
  689. if (piecelist != null && piecelist.size() > 0) {
  690. piecelist.removeAll(piecelist);
  691. if (pieceAdapter != null) {
  692. pieceAdapter.notifyDataSetChanged();
  693. }
  694. }
  695. }
  696. if(nodeType!=3) {
  697. if (piecelist.size() > 0) {
  698. boolean b = Removeduplicate.removeBarCode(etcode,
  699. piecelist);
  700. if (b) {
  701. ProcessDialogUtils.closeProgressDilog();
  702. barcode.setEnabled(true);
  703. barcode.setText("");
  704. barcode.setFocusable(true);
  705. barcode.setFocusableInTouchMode(true);
  706. barcode.requestFocus();
  707. barcode.findFocus();
  708. barcode.setFilters(new InputFilter[] { new InputFilter() {
  709. @Override
  710. public CharSequence filter(
  711. CharSequence source, int start,
  712. int end, Spanned dest, int dstart,
  713. int dend) {
  714. return null;
  715. }
  716. } });
  717. //CommonUtil.BarcodeMaxLength(barcode, 50);;
  718. CommonUtil.setDefault(
  719. Notification.DEFAULT_VIBRATE,
  720. getApplicationContext());
  721. if (collectType == 2) {
  722. CommonUtil.showRepeatDialog("条码" + etcode
  723. + "重复", PieceActivity.this);
  724. } else if (collectType == 1) {
  725. // Toast.makeText(getApplicationContext(),"条码"+etcode+"重复",Toast.LENGTH_SHORT).show();
  726. CustomToast.showToast(
  727. getApplicationContext(), "条码"
  728. + etcode + "重复", 2000);
  729. }
  730. ProcessDialogUtils.closeProgressDilog();
  731. return;
  732. }
  733. }
  734. }
  735. if(collectType==1&&nodeType==3) {
  736. if(plateNum>0&&piecelist.size()==plateNum) {
  737. CommonUtil.setDefault(Notification.DEFAULT_VIBRATE,
  738. getApplicationContext());
  739. CommonUtil.showBarCodeAlertDialog(0, "超过装板数量【"+plateNum+"】",
  740. PieceActivity.this, barcode, null, null);
  741. ProcessDialogUtils.closeProgressDilog();
  742. return;
  743. }
  744. }
  745. thread = null;
  746. thread = new HandlerThread("BarCoderThread", 5);
  747. thread.start();
  748. mHandler = null;
  749. mHandler = new Handler(thread.getLooper());
  750. BarcodeRunnable barcodeRunnable = new BarcodeRunnable(
  751. etcode, obj);
  752. mHandler.post(barcodeRunnable);
  753. }
  754. }
  755. }
  756. @Override
  757. public void beforeTextChanged(CharSequence s, int start, int count,
  758. int after) {
  759. }
  760. @Override
  761. public void onTextChanged(CharSequence s, int start, int before,
  762. int count) {
  763. barcodeUpper = barcode.getText().toString();
  764. if(barcodeUpper.length() >= 73)
  765. {
  766. String[] parts = barcodeUpper.split("-", 2);
  767. if (parts.length == 2) {
  768. barcodeUpper = parts[1];
  769. }
  770. }
  771. // 判断输入的文字是否是小写
  772. for (int i = 0; i < barcodeUpper.length(); i++) {
  773. if (barcodeUpper.charAt(i) - 0 >= 97
  774. && barcodeUpper.charAt(i) - 0 <= 122) {
  775. barcodeUpperH.postDelayed(BarcodeUpperCase, 300);
  776. }
  777. }
  778. }
  779. });
  780. // //产品条码键盘触发事件
  781. barcode.setOnEditorActionListener(new OnEditorActionListener() {
  782. @Override
  783. public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) {
  784. if (arg1 == EditorInfo.IME_ACTION_GO) {
  785. String workno = met.getText().toString();
  786. if (TextUtils.isEmpty(workno)) {
  787. CustomToast.showToast(getApplicationContext(),
  788. "生产工号不能为空", 2000);
  789. met.setEnabled(true);
  790. met.setFocusable(true);
  791. met.setFocusableInTouchMode(true);
  792. met.requestFocus();
  793. met.findFocus();
  794. met.setFilters(new InputFilter[] { new InputFilter() {
  795. @Override
  796. public CharSequence filter(CharSequence source,
  797. int start, int end, Spanned dest,
  798. int dstart, int dend) {
  799. return null;
  800. }
  801. } });
  802. return true;
  803. } else {
  804. if (!userCodeIsValid) {
  805. CustomToast.showToast(getApplicationContext(),
  806. "请在生产工号输入框内按回车键验证生产工号", 2000);
  807. met.setEnabled(true);
  808. met.setFocusable(true);
  809. met.setFocusableInTouchMode(true);
  810. met.requestFocus();
  811. met.findFocus();
  812. met.setFilters(new InputFilter[] { new InputFilter() {
  813. @Override
  814. public CharSequence filter(CharSequence source,
  815. int start, int end, Spanned dest,
  816. int dstart, int dend) {
  817. return null;
  818. }
  819. } });
  820. return true;
  821. }
  822. String etcode = barcode.getText().toString().trim().replaceAll("\\n", "");
  823. if(etcode.length() >= 73)
  824. {
  825. String[] parts = etcode.split("-", 2);
  826. if (parts.length == 2) {
  827. etcode = parts[1];
  828. }
  829. }
  830. ProcessDialogUtils
  831. .showProcessDialog(PieceActivity.this);
  832. barcode.setEnabled(false);
  833. barcode.setFocusable(false);
  834. barcode.setFilters(new InputFilter[] { new InputFilter() {
  835. @Override
  836. public CharSequence filter(CharSequence source,
  837. int start, int end, Spanned dest,
  838. int dstart, int dend) {
  839. return source.length() < 1 ? dest.subSequence(
  840. dstart, dend) : "";
  841. }
  842. } });
  843. if (!TextUtils.isEmpty(etcode)) {
  844. // if (!CommonUtil.isNumber(etcode)) {
  845. // ProcessDialogUtils.closeProgressDilog();
  846. // CommonUtil.setDefault(
  847. // Notification.DEFAULT_VIBRATE,
  848. // getApplicationContext());
  849. // //
  850. // CommonUtil.showRepeatDialog(code+"格式不匹配",PieceActivity.this);
  851. // //
  852. // Toast.makeText(getApplicationContext(),etcode+"格式不匹配",Toast.LENGTH_SHORT).show();
  853. // CustomToast.showToast(getApplicationContext(),
  854. // etcode + "格式不匹配", 1000);
  855. // barcode.setEnabled(true);
  856. // barcode.setText("");
  857. // barcode.setFocusable(true);
  858. // barcode.setFocusableInTouchMode(true);
  859. // barcode.requestFocus();
  860. // barcode.findFocus();
  861. // barcode.setFilters(new InputFilter[] { new
  862. // InputFilter() {
  863. // @Override
  864. // public CharSequence filter(
  865. // CharSequence source, int start,
  866. // int end, Spanned dest, int dstart,
  867. // int dend) {
  868. //
  869. // return null;
  870. // }
  871. // } });
  872. // CommonUtil.BarcodeMaxLength(barcode,50);
  873. // return true;
  874. // }
  875. if (collectType == 2) {
  876. if (piecelist != null && piecelist.size() > 0) {
  877. piecelist.removeAll(piecelist);
  878. }
  879. if (pieceAdapter != null) {
  880. pieceAdapter.notifyDataSetChanged();
  881. }
  882. }
  883. if(nodeType!=3) {
  884. if (piecelist.size() > 0) {
  885. boolean b = Removeduplicate.removeBarCode(
  886. etcode, piecelist);
  887. if (b) {
  888. barcode.setEnabled(true);
  889. barcode.setText("");
  890. barcode.setFocusable(true);
  891. barcode.setFocusableInTouchMode(true);
  892. barcode.requestFocus();
  893. barcode.findFocus();
  894. barcode.setFilters(new InputFilter[] { new InputFilter() {
  895. @Override
  896. public CharSequence filter(
  897. CharSequence source, int start,
  898. int end, Spanned dest,
  899. int dstart, int dend) {
  900. return null;
  901. }
  902. } });
  903. //CommonUtil.BarcodeMaxLength(barcode, 50);;
  904. CommonUtil.setDefault(
  905. Notification.DEFAULT_VIBRATE,
  906. getApplicationContext());
  907. if (collectType == 2) {
  908. CommonUtil.showRepeatDialog("条码"
  909. + etcode + "重复",
  910. PieceActivity.this);
  911. } else if (collectType == 1) {
  912. CustomToast.showToast(
  913. getApplicationContext(), "条码"
  914. + etcode + "重复", 2000);
  915. }
  916. ProcessDialogUtils.closeProgressDilog();
  917. return true;
  918. }
  919. }
  920. }
  921. if(collectType==1&&nodeType==3) {
  922. if(plateNum>0&&piecelist.size()==plateNum) {
  923. CommonUtil.setDefault(Notification.DEFAULT_VIBRATE,
  924. getApplicationContext());
  925. CommonUtil.showBarCodeAlertDialog(0, "超过装板数量【"+plateNum+"】",
  926. PieceActivity.this, barcode, null, null);
  927. ProcessDialogUtils.closeProgressDilog();
  928. return true;
  929. }
  930. }
  931. thread = null;
  932. thread = new HandlerThread("BarCoderThread", 5);
  933. thread.start();
  934. mHandler = null;
  935. mHandler = new Handler(thread.getLooper());
  936. BarcodeRunnable barcodeRunnable = new BarcodeRunnable(
  937. etcode, obj);
  938. mHandler.post(barcodeRunnable);
  939. }
  940. else {
  941. ProcessDialogUtils.closeProgressDilog();
  942. CustomToast.showToast(getApplicationContext(),
  943. "请输入产品条码", 2000);
  944. barcode.setEnabled(true);
  945. barcode.setText("");
  946. barcode.setFocusable(true);
  947. met.setFocusableInTouchMode(true);
  948. met.requestFocus();
  949. met.findFocus();
  950. barcode.setFilters(new InputFilter[] { new InputFilter() {
  951. @Override
  952. public CharSequence filter(CharSequence source,
  953. int start, int end, Spanned dest,
  954. int dstart, int dend) {
  955. return null;
  956. }
  957. } });
  958. //CommonUtil.BarcodeMaxLength(barcode, 50);;
  959. return true;
  960. }
  961. }
  962. }
  963. return true;
  964. }
  965. });
  966. }
  967. private Handler handler1 = new Handler() {
  968. @Override
  969. public void handleMessage(Message msg) {
  970. super.handleMessage(msg);
  971. switch (msg.what) {
  972. case 0:
  973. Bundle b = msg.getData();
  974. String json = b.getString("worknoResult");
  975. ProcessDialogUtils.closeProgressDilog();
  976. try {
  977. JSONObject j = new JSONObject(json);
  978. JSONObject jo = (JSONObject) j.opt("d");
  979. int status = jo.getInt("Status");
  980. String message = jo.getString("Message");
  981. if (status == 0) {
  982. String result = jo.optString("Result");
  983. JSONObject object = new JSONObject(result);
  984. outErrMsg = object.optString("ErrMsg");
  985. if (outErrMsg.equals("null")) {
  986. barcode.setEnabled(true);
  987. barcode.setText("");
  988. barcode.setFocusable(true);
  989. barcode.setFocusableInTouchMode(true);
  990. barcode.requestFocus();
  991. barcode.findFocus();
  992. barcode.setFilters(new InputFilter[] { new InputFilter() {
  993. @Override
  994. public CharSequence filter(CharSequence source,
  995. int start, int end, Spanned dest,
  996. int dstart, int dend) {
  997. return null;
  998. }
  999. } });
  1000. ////CommonUtil.BarcodeMaxLength(barcode, 50);;
  1001. userID1 = object.getString("UserID");
  1002. userCode1 = object.getString("UserCode");
  1003. userName1 = object.getString("UserName");
  1004. userCodeIsValid = true;
  1005. if (mHandler != null) {
  1006. mHandler.removeCallbacksAndMessages(null);
  1007. mHandler.getLooper().quit();
  1008. }
  1009. InputMethodManager im = (InputMethodManager) met
  1010. .getContext().getSystemService(
  1011. Context.INPUT_METHOD_SERVICE);
  1012. im.hideSoftInputFromWindow(met.getWindowToken(),
  1013. InputMethodManager.HIDE_NOT_ALWAYS);
  1014. } else {
  1015. if (mHandler != null) {
  1016. mHandler.removeCallbacksAndMessages(null);
  1017. mHandler.getLooper().quit();
  1018. }
  1019. userCodeIsValid = false;
  1020. CommonUtil.setDefault(Notification.DEFAULT_VIBRATE,
  1021. getApplicationContext());
  1022. CommonUtil.showWorkNoAlertDialog(status, outErrMsg,
  1023. PieceActivity.this, met, barcode, null,
  1024. null, collectType);
  1025. return;
  1026. }
  1027. // 如果是水效标识来的 NewWaterEfficiencyLabelActivity= wangyingjie
  1028. if("wangyingjie".equals(NewWaterEfficiencyLabelActivity)) {
  1029. barcode.setText(NewWaterBarcode);
  1030. searchBarCode(NewWaterBarcode);
  1031. }
  1032. } else {
  1033. if (mHandler != null) {
  1034. mHandler.removeCallbacksAndMessages(null);
  1035. mHandler.getLooper().quit();
  1036. }
  1037. userCodeIsValid = false;
  1038. CommonUtil.setDefault(Notification.DEFAULT_VIBRATE,
  1039. getApplicationContext());
  1040. CommonUtil.showWorkNoAlertDialog(status, message,
  1041. PieceActivity.this, met, barcode, null, null,
  1042. collectType);
  1043. }
  1044. } catch (Exception e) {
  1045. if (mHandler != null) {
  1046. mHandler.removeCallbacksAndMessages(null);
  1047. mHandler.getLooper().quit();
  1048. }
  1049. e.printStackTrace();
  1050. }
  1051. break;
  1052. }
  1053. }
  1054. };
  1055. Runnable BarcodeUpperCase = new Runnable() {
  1056. @Override
  1057. public void run() {
  1058. // 小写转大写
  1059. barcode.setText(barcodeUpper.toUpperCase());
  1060. // 设置EditText光标位置
  1061. barcode.setSelection(barcodeUpper.length());
  1062. }
  1063. };
  1064. private Handler handler2 = new Handler() {
  1065. @Override
  1066. public void handleMessage(Message msg) {
  1067. super.handleMessage(msg);
  1068. switch (msg.what) {
  1069. case 2:
  1070. ProcessDialogUtils.closeProgressDilog();
  1071. if (mHandler != null) {
  1072. mHandler.removeCallbacksAndMessages(null);
  1073. mHandler.getLooper().quit();
  1074. }
  1075. Bundle b2 = msg.getData();
  1076. String errmsg = b2.getString("msg");
  1077. String missFlag = b2.getString("missingFlag");
  1078. Intent intent = new Intent();
  1079. Bundle b1 = new Bundle();
  1080. b1.putString("msg", errmsg);
  1081. b1.putString("missingFlag", missFlag);
  1082. intent.putExtras(b1);
  1083. intent.setClass(PieceActivity.this, MissingScanActivity.class);
  1084. startActivityForResult(intent, 101);
  1085. break;
  1086. }
  1087. }
  1088. };
  1089. private Handler exceptionHandler = new Handler() {
  1090. @Override
  1091. public void handleMessage(Message msg) {
  1092. super.handleMessage(msg);
  1093. switch (msg.what) {
  1094. case 0:
  1095. ProcessDialogUtils.closeProgressDilog();
  1096. if (mHandler != null) {
  1097. mHandler.removeCallbacksAndMessages(null);
  1098. mHandler.getLooper().quit();
  1099. }
  1100. Bundle b = msg.getData();
  1101. String message = b.getString("message");
  1102. CommonUtil.setDefault(Notification.DEFAULT_VIBRATE,
  1103. getApplicationContext());
  1104. Toast.makeText(getApplicationContext(),message, Toast.LENGTH_LONG).show();
  1105. barcode.setEnabled(true);
  1106. barcode.setText("");
  1107. barcode.setFocusable(true);
  1108. barcode.setFocusableInTouchMode(true);
  1109. barcode.requestFocus();
  1110. barcode.findFocus();
  1111. barcode.setFilters(new InputFilter[] { new InputFilter() {
  1112. @Override
  1113. public CharSequence filter(CharSequence source, int start,
  1114. int end, Spanned dest, int dstart, int dend) {
  1115. return null;
  1116. }
  1117. } });
  1118. //CommonUtil.BarcodeMaxLength(barcode, 50);;
  1119. break;
  1120. case 1:
  1121. ProcessDialogUtils.closeProgressDilog();
  1122. if (mHandler != null) {
  1123. mHandler.removeCallbacksAndMessages(null);
  1124. mHandler.getLooper().quit();
  1125. }
  1126. Bundle b1 = msg.getData();
  1127. String message1 = b1.getString("message");
  1128. CommonUtil.setDefault(Notification.DEFAULT_VIBRATE,
  1129. getApplicationContext());
  1130. CustomToast.showToast(getApplicationContext(), message1, 2000);
  1131. if (collectType == 1) {
  1132. met.setEnabled(true);
  1133. met.setText("");
  1134. met.setFocusable(true);
  1135. met.setFocusableInTouchMode(true);
  1136. met.requestFocus();
  1137. met.findFocus();
  1138. met.setFilters(new InputFilter[] { new InputFilter() {
  1139. @Override
  1140. public CharSequence filter(CharSequence source,
  1141. int start, int end, Spanned dest, int dstart,
  1142. int dend) {
  1143. return null;
  1144. }
  1145. } });
  1146. }
  1147. barcode.setEnabled(true);
  1148. barcode.setText("");
  1149. barcode.setFocusable(true);
  1150. barcode.setFocusableInTouchMode(true);
  1151. barcode.setFilters(new InputFilter[] { new InputFilter() {
  1152. @Override
  1153. public CharSequence filter(CharSequence source,
  1154. int start, int end, Spanned dest,
  1155. int dstart, int dend) {
  1156. return null;
  1157. }
  1158. } });
  1159. //CommonUtil.BarcodeMaxLength(barcode, 50);;
  1160. break;
  1161. case 2:
  1162. ProcessDialogUtils.closeProgressDilog();
  1163. if (mHandler != null) {
  1164. mHandler.removeCallbacksAndMessages(null);
  1165. mHandler.getLooper().quit();
  1166. }
  1167. Bundle b2 = msg.getData();
  1168. int status2 = b2.getInt("Status");
  1169. String message2 = b2.getString("Message");
  1170. CommonUtil.setDefault(Notification.DEFAULT_VIBRATE,
  1171. getApplicationContext());
  1172. CommonUtil.showBarCodeAlertDialog(status2, message2,
  1173. PieceActivity.this, barcode, null, null);
  1174. break;
  1175. case 3:
  1176. ProcessDialogUtils.closeProgressDilog();
  1177. if (mHandler != null) {
  1178. mHandler.removeCallbacksAndMessages(null);
  1179. mHandler.getLooper().quit();
  1180. }
  1181. Bundle b3 = msg.getData();
  1182. int status3 = b3.getInt("Status");
  1183. String message3 = b3.getString("Message");
  1184. if (piecelist != null && piecelist.size() > 0) {
  1185. piecelist.removeAll(piecelist);
  1186. if (pieceAdapter != null) {
  1187. pieceAdapter.notifyDataSetChanged();
  1188. }
  1189. CommonUtil.setDefault(Notification.DEFAULT_VIBRATE,
  1190. getApplicationContext());
  1191. CommonUtil.showBarCodeAlertDialog(status3, message3,
  1192. PieceActivity.this, barcode, null, null);
  1193. }
  1194. break;
  1195. case 4:
  1196. ProcessDialogUtils.closeProgressDilog();
  1197. if (mHandler != null) {
  1198. mHandler.removeCallbacksAndMessages(null);
  1199. mHandler.getLooper().quit();
  1200. }
  1201. Bundle b4 = msg.getData();
  1202. String missFlag= b4.getString("missingFlag");
  1203. String message4=b4.getString("Message");
  1204. Intent intent = new Intent();
  1205. Bundle b5 = new Bundle();
  1206. b5.putString("msg", message4);
  1207. b5.putString("missingFlag", missFlag);
  1208. intent.putExtras(b5);
  1209. intent.setClass(PieceActivity.this,
  1210. MissingScanActivity.class);
  1211. startActivityForResult(intent, 101);
  1212. break;
  1213. }
  1214. }
  1215. };
  1216. Handler saveValidHandler = new Handler() {
  1217. @Override
  1218. public void handleMessage(Message msg) {
  1219. switch (msg.what) {
  1220. case 0:
  1221. ProcessDialogUtils.closeProgressDilog();
  1222. if (mHandler != null) {
  1223. mHandler.removeCallbacksAndMessages(null);
  1224. mHandler.getLooper().quit();
  1225. }
  1226. Bundle b = msg.getData();
  1227. String message = b.getString("message");
  1228. CommonUtil.setDefault(Notification.DEFAULT_VIBRATE,
  1229. getApplicationContext());
  1230. CustomToast.showToast(getApplicationContext(), message, 2000);
  1231. bt2.setEnabled(true);
  1232. break;
  1233. }
  1234. }
  1235. };
  1236. // 保存
  1237. private Handler handler3 = new Handler() {
  1238. @Override
  1239. public void handleMessage(Message msg) {
  1240. super.handleMessage(msg);
  1241. switch (msg.what) {
  1242. case 2:
  1243. Bundle b = msg.getData();
  1244. String json = b.getString("saveResult");
  1245. bt2.setEnabled(true);
  1246. ProcessDialogUtils.closeProgressDilog();
  1247. try {
  1248. JSONObject j = new JSONObject(json);
  1249. JSONObject jobj = (JSONObject) j.opt("d");
  1250. int status = jobj.optInt("Status");
  1251. String message = jobj.optString("Message");
  1252. if (status == 0) {
  1253. String result = jobj.optString("Result");
  1254. piecelist.removeAll(piecelist);
  1255. pieceAdapter.notifyDataSetChanged();
  1256. bt2.setText("保存(" + piecelist.size() + ")");
  1257. if (collectType == 1) {
  1258. userCodeIsValid = false;
  1259. }
  1260. produceCodeIsValid = false;
  1261. JSONArray jsonArray2 = new JSONArray(result);
  1262. JSONObject object2 = (JSONObject) jsonArray2.get(0);
  1263. String outErrMsg = object2.getString("out_errMsg");
  1264. if (TextUtils.isEmpty(outErrMsg)) {
  1265. if (collectType == 1) {
  1266. met.setEnabled(true);
  1267. met.setText("");
  1268. met.setFocusable(true);
  1269. met.setFocusableInTouchMode(true);
  1270. met.requestFocus();
  1271. met.findFocus();
  1272. met.setFilters(new InputFilter[] { new InputFilter() {
  1273. @Override
  1274. public CharSequence filter(
  1275. CharSequence source, int start,
  1276. int end, Spanned dest, int dstart,
  1277. int dend) {
  1278. return null;
  1279. }
  1280. } });
  1281. } else {
  1282. barcode.setEnabled(true);
  1283. barcode.setText("");
  1284. barcode.setFocusable(true);
  1285. barcode.setFocusableInTouchMode(true);
  1286. barcode.requestFocus();
  1287. barcode.findFocus();
  1288. barcode.setFilters(new InputFilter[] { new InputFilter() {
  1289. @Override
  1290. public CharSequence filter(
  1291. CharSequence source, int start,
  1292. int end, Spanned dest, int dstart,
  1293. int dend) {
  1294. return null;
  1295. }
  1296. } });
  1297. ////CommonUtil.BarcodeMaxLength(barcode, 50);;
  1298. }
  1299. CustomToast.showToast(getApplicationContext(),
  1300. "上传成功", 2000);
  1301. CommonUtil.playSound(PieceActivity.this);
  1302. if (mHandler != null) {
  1303. mHandler.removeCallbacksAndMessages(null);
  1304. mHandler.getLooper().quit();
  1305. }
  1306. return;
  1307. } else {
  1308. CommonUtil.showSaveAlertDialog(status, outErrMsg,
  1309. PieceActivity.this, met, barcode,
  1310. collectType);
  1311. if (mHandler != null) {
  1312. mHandler.removeCallbacksAndMessages(null);
  1313. mHandler.getLooper().quit();
  1314. }
  1315. return;
  1316. }
  1317. } else {
  1318. if (mHandler != null) {
  1319. mHandler.removeCallbacksAndMessages(null);
  1320. mHandler.getLooper().quit();
  1321. }
  1322. if (status == 1) {
  1323. piecelist.removeAll(piecelist);
  1324. pieceAdapter.notifyDataSetChanged();
  1325. bt2.setText("保存(" + piecelist.size() + ")");
  1326. if (collectType == 1) {
  1327. userCodeIsValid = false;
  1328. }
  1329. produceCodeIsValid = false;
  1330. }
  1331. CommonUtil.setDefault(Notification.DEFAULT_VIBRATE,
  1332. getApplicationContext());
  1333. CommonUtil.showSaveAlertDialog(status, message,
  1334. PieceActivity.this, met, barcode, collectType);
  1335. }
  1336. System.gc();
  1337. break;
  1338. } catch (Exception e) {
  1339. if (mHandler != null) {
  1340. mHandler.removeCallbacksAndMessages(null);
  1341. mHandler.getLooper().quit();
  1342. }
  1343. e.printStackTrace();
  1344. }
  1345. break;
  1346. case 3:
  1347. Bundle b3 = msg.getData();
  1348. String result6=b3.getString("result");
  1349. JSONObject jo6;
  1350. ProcessDialogUtils.closeProgressDilog();
  1351. try {
  1352. jo6 = new JSONObject(result6);
  1353. JSONObject jo7 = jo6.optJSONObject("d");
  1354. int status7 = jo7.optInt("Status");
  1355. String message7 = jo7.optString("Message");
  1356. if (status7 == 0) {
  1357. String result = jo7.optString("Result");
  1358. JSONArray jarray7 = new JSONArray(result);
  1359. if (jarray7 != null && jarray7.length() > 0) {
  1360. JSONObject jo8 = jarray7.optJSONObject(0);
  1361. String outErrMsg = jo8.optString("out_errMsg");
  1362. String missFlag = jo8.optString("out_missFlag");
  1363. if (TextUtils.isEmpty(outErrMsg)) {
  1364. if (userCodeIsValid) {
  1365. piece = null;
  1366. piece = new Piece();
  1367. piece.setUserId(userID1);
  1368. piece.setUserCode(userCode1);
  1369. piece.setUserName(userName1);
  1370. }
  1371. produceCodeIsValid = true;// test
  1372. out_goodsID = jo8.optString("out_goodsID");
  1373. piece.setGoodsId(out_goodsID);
  1374. out_goodsCode = jo8
  1375. .optString("out_goodsCode");
  1376. piece.setGoodsCode(out_goodsCode);
  1377. out_goodsName = jo8
  1378. .optString("out_goodsName");
  1379. piece.setGoodsName(out_goodsName);
  1380. String outbarcode = jo8
  1381. .optString("out_barcode");
  1382. piece.setBarCode(outbarcode);
  1383. String groutingNum = jo8
  1384. .optString("out_groutingNum");
  1385. String mouldCode = jo8
  1386. .optString("out_mouldCode");
  1387. String groutingDate = jo8
  1388. .optString("out_groutingdate");
  1389. String groutingcode = jo8
  1390. .optString("out_groutingUserCode");
  1391. String publicBodyFlag = jo8
  1392. .optString("out_ispublicbody");
  1393. String trademarkName = jo8
  1394. .optString("out_logoName");
  1395. String waterLabelCode=jo8.optString("out_WaterLabelCode");
  1396. String checkFlag=jo8.optString("out_CodeCheckFlag");
  1397. piece.setTrademarkName(trademarkName);
  1398. piece.setGroutingUserCode(groutingcode);
  1399. piece.setMouldNo(mouldCode);
  1400. piece.setGroutingNum(Integer
  1401. .parseInt(groutingNum));
  1402. if (!TextUtils.isEmpty(groutingDate)) {
  1403. if (groutingDate.contains("/")) {
  1404. groutingDate = CommonUtil
  1405. .dateStringConverter(groutingDate);
  1406. } else if (groutingDate.contains("-")) {
  1407. groutingDate = CommonUtil
  1408. .commonDateConverter(groutingDate);
  1409. }
  1410. piece.setGroutingDate(groutingDate);
  1411. } else {
  1412. piece.setGroutingDate("");
  1413. }
  1414. piece.setPublicBilletFlag(publicBodyFlag);
  1415. piecelist.add(0, piece);
  1416. if(pieceAdapter==null){
  1417. pieceAdapter = new PieceListMessageAdapter(PieceActivity.this,piecelist);
  1418. list1.setAdapter(pieceAdapter);
  1419. }
  1420. else{
  1421. pieceAdapter.notifyDataSetChanged();
  1422. }
  1423. CustomToast.showToast(getApplicationContext(),
  1424. "上传成功", 2000);
  1425. CommonUtil.playSound(PieceActivity.this);
  1426. if(checkFlag.equals("1")&&!TextUtils.isEmpty(waterLabelCode)) {
  1427. Intent intent = new Intent();
  1428. Bundle b1 = new Bundle();
  1429. b1.putString("WaterLabelCode", waterLabelCode);
  1430. intent.putExtras(b1);
  1431. intent.setClass(PieceActivity.this, WaterLabelCheckActivity.class);
  1432. startActivityForResult(intent, 103);
  1433. }
  1434. else
  1435. {
  1436. barcode.setEnabled(true);
  1437. barcode.setText("");
  1438. barcode.setFocusable(true);
  1439. barcode.setFocusableInTouchMode(true);
  1440. barcode.requestFocus();
  1441. barcode.findFocus();
  1442. barcode.setFilters(new InputFilter[] { new InputFilter() {
  1443. @Override
  1444. public CharSequence filter(CharSequence source, int start,
  1445. int end, Spanned dest, int dstart, int dend) {
  1446. return null;
  1447. }
  1448. } });
  1449. ////CommonUtil.BarcodeMaxLength(barcode, 50);;
  1450. }
  1451. // 如果是水校标识界面过来的 barcode成功返回后 直接关闭界面
  1452. if("wangyingjie".equals(NewWaterEfficiencyLabelActivity)) {
  1453. finish();
  1454. }
  1455. }
  1456. else {
  1457. produceCodeIsValid = false;
  1458. if (missFlag.equals("0")) {
  1459. CommonUtil.setDefault(Notification.DEFAULT_VIBRATE,
  1460. getApplicationContext());
  1461. CommonUtil.showBarCodeAlertDialog(status7,outErrMsg,
  1462. PieceActivity.this, barcode, null, null);
  1463. }
  1464. else {
  1465. Intent intent = new Intent();
  1466. Bundle b1 = new Bundle();
  1467. b1.putString("msg", outErrMsg);
  1468. b1.putString("missingFlag", missFlag);
  1469. intent.putExtras(b1);
  1470. intent.setClass(PieceActivity.this, MissingScanActivity.class);
  1471. startActivityForResult(intent, 101);
  1472. }
  1473. }
  1474. }
  1475. } else {
  1476. produceCodeIsValid = false;
  1477. CommonUtil.setDefault(Notification.DEFAULT_VIBRATE,
  1478. getApplicationContext());
  1479. CommonUtil.showBarCodeAlertDialog(status7, message7,
  1480. PieceActivity.this, barcode, null, null);
  1481. return;
  1482. }
  1483. bt2.setText("保存(" + piecelist.size() + ")");
  1484. if (mHandler != null) {
  1485. mHandler.removeCallbacksAndMessages(null);
  1486. mHandler.getLooper().quit();
  1487. }
  1488. } catch (JSONException e1) {
  1489. e1.printStackTrace();
  1490. }
  1491. break;
  1492. case 4:
  1493. ProcessDialogUtils.closeProgressDilog();
  1494. if (mHandler != null) {
  1495. mHandler.removeCallbacksAndMessages(null);
  1496. mHandler.getLooper().quit();
  1497. }
  1498. Bundle b4= msg.getData();
  1499. Piece piece=(Piece) b4.getSerializable("piece");
  1500. piecelist.add(0, piece);
  1501. if(pieceAdapter==null){
  1502. pieceAdapter = new PieceListMessageAdapter(
  1503. PieceActivity.this,piecelist);
  1504. list1.setAdapter(pieceAdapter);
  1505. }
  1506. else
  1507. {
  1508. pieceAdapter.notifyDataSetChanged();
  1509. }
  1510. bt2.setText("保存(" + piecelist.size() + ")");
  1511. barcode.setEnabled(true);
  1512. barcode.setText("");
  1513. barcode.setFocusable(true);
  1514. barcode.setFocusableInTouchMode(true);
  1515. barcode.requestFocus();
  1516. barcode.findFocus();
  1517. barcode.setFilters(new InputFilter[] { new InputFilter() {
  1518. @Override
  1519. public CharSequence filter(CharSequence source,
  1520. int start, int end, Spanned dest,
  1521. int dstart, int dend) {
  1522. return null;
  1523. }
  1524. } });
  1525. ////CommonUtil.BarcodeMaxLength(barcode, 50);;
  1526. InputMethodManager im = (InputMethodManager) barcode
  1527. .getContext().getSystemService(
  1528. Context.INPUT_METHOD_SERVICE);
  1529. im.hideSoftInputFromWindow(barcode.getWindowToken(),
  1530. InputMethodManager.HIDE_NOT_ALWAYS);
  1531. ProcessDialogUtils.closeProgressDilog();
  1532. break;
  1533. }
  1534. }
  1535. };
  1536. private class SavePieceRunnable implements Runnable {
  1537. Object obj;
  1538. public SavePieceRunnable(Object obj) {
  1539. this.obj = obj;
  1540. }
  1541. @Override
  1542. public void run() {
  1543. synchronized (obj) {
  1544. try {
  1545. jsonObject = new JSONObject();
  1546. jsonObject.put("accountCode", accountCode);
  1547. jsonObject.put("userCode", piece_userCode);
  1548. jsonObject.put("userPassword", userPassword);
  1549. jsonObject.put("sessionKey", sessionKey);
  1550. jsonObject.put("procedureID", proId);
  1551. JSONArray productionDataEntitys = new JSONArray();
  1552. for (Piece p : piecelist) {
  1553. JSONObject obj = new JSONObject();
  1554. String userId = p.getUserId();
  1555. obj.put("UserID", Long.parseLong(userId));
  1556. String userCode = p.getUserCode();
  1557. obj.put("UserCode", userCode);
  1558. String userName = p.getUserName();
  1559. obj.put("UserName", userName);
  1560. String barcode = p.getBarCode();
  1561. obj.put("Barcode", barcode);
  1562. productionDataEntitys.put(obj);
  1563. }
  1564. jsonObject.put("productionDataEntitys",
  1565. productionDataEntitys);
  1566. client = null;
  1567. client = new WebClient();
  1568. String result = client.doPost("http://" + ServerAddress_ip
  1569. + ":" + ServerAddress_duankou
  1570. + Constants.ADD_WORK_PIECE, jsonObject.toString(),
  1571. "application/json");
  1572. Message m = new Message();
  1573. m.what = 2;
  1574. Bundle b = new Bundle();
  1575. b.putString("saveResult", result);
  1576. m.setData(b);
  1577. handler3.sendMessage(m);
  1578. } catch (JSONException e) {
  1579. e.printStackTrace();
  1580. Message m = new Message();
  1581. m.what = 0;
  1582. Bundle b = new Bundle();
  1583. b.putString("message", "json数据异常");
  1584. m.setData(b);
  1585. saveValidHandler.sendMessage(m);
  1586. ProcessDialogUtils.closeProgressDilog();
  1587. } catch (Exception e) {
  1588. e.printStackTrace();
  1589. Message m = new Message();
  1590. m.what = 0;
  1591. Bundle b = new Bundle();
  1592. b.putString("message", "网络连接异常");
  1593. m.setData(b);
  1594. saveValidHandler.sendMessage(m);
  1595. }
  1596. }
  1597. }
  1598. };
  1599. private class BarcodeRunnable implements Runnable {
  1600. String barcode;
  1601. Object obj;
  1602. public BarcodeRunnable(String barcode, Object obj) {
  1603. this.barcode = barcode;
  1604. this.obj = obj;
  1605. }
  1606. @Override
  1607. public void run() {
  1608. synchronized (obj) {
  1609. try {
  1610. if (collectType == 1) {
  1611. jsonObject = new JSONObject();
  1612. jsonObject.put("accountCode", accountCode);
  1613. jsonObject.put("userCode", piece_userCode);
  1614. jsonObject.put("userPassword", userPassword);
  1615. jsonObject.put("sessionKey", sessionKey);
  1616. jsonObject.put("procedureID", proId);// 工序ID,菜单页面传过来的
  1617. jsonObject.put("barcode", barcode);// 条码
  1618. client = null;
  1619. client = new WebClient();
  1620. String result = client.doPost("http://"
  1621. + ServerAddress_ip + ":"
  1622. + ServerAddress_duankou
  1623. + Constants.BAR_CODE_VALID,
  1624. jsonObject.toString(), "application/json");
  1625. JSONObject j1 = new JSONObject(result);
  1626. JSONObject jobj = (JSONObject) j1.opt("d");
  1627. int status = jobj.optInt("Status");
  1628. String message = jobj.optString("Message");
  1629. if (status == 0) {
  1630. String result1 = jobj.optString("Result");
  1631. JSONArray jsonArray = new JSONArray(result1);
  1632. JSONObject object1 = (JSONObject) jsonArray.get(0);
  1633. outErrMsg = object1.getString("out_errMsg");
  1634. String missFlag = object1.optString("out_missFlag");
  1635. if (!TextUtils.isEmpty(outErrMsg)) {
  1636. if (missFlag.equals("0")) {
  1637. Bundle bundle=new Bundle();
  1638. bundle.putInt("Status", status);
  1639. bundle.putString("Message", outErrMsg);
  1640. Message msg=new Message();
  1641. msg.what=2;
  1642. msg.setData(bundle);
  1643. exceptionHandler.sendMessage(msg);
  1644. return;
  1645. } else {
  1646. Bundle bundle=new Bundle();
  1647. bundle.putString("missingFlag", missFlag);
  1648. bundle.putString("Message", outErrMsg);
  1649. Message msg=new Message();
  1650. msg.what=4;
  1651. msg.setData(bundle);
  1652. exceptionHandler.sendMessage(msg);
  1653. return;
  1654. }
  1655. }
  1656. String outbarcode = object1.getString("out_barcode");
  1657. if(nodeType==3) {
  1658. if (piecelist.size() > 0 ) {
  1659. boolean b = Removeduplicate.removeBarCode(
  1660. outbarcode, piecelist);
  1661. if (b) {
  1662. Bundle bundle=new Bundle();
  1663. bundle.putString("message","条码"+outbarcode+"重复");
  1664. Message msg=new Message();
  1665. msg.what=0;
  1666. msg.setData(bundle);
  1667. exceptionHandler.sendMessage(msg);
  1668. return;
  1669. }
  1670. }
  1671. }
  1672. if (userCodeIsValid) {
  1673. piece = null;
  1674. piece = new Piece();
  1675. piece.setUserId(userID1);
  1676. piece.setUserCode(userCode1);
  1677. piece.setUserName(userName1);
  1678. }
  1679. produceCodeIsValid = true;
  1680. String logoId=object1.optString("out_logoID");
  1681. String logoCode=object1.optString("out_logoCode");
  1682. piece.setLogoCode(logoCode);
  1683. piece.setLogoId(logoId);
  1684. String logoName=object1.optString("out_logoName");
  1685. piece.setLogoName(logoName);
  1686. String goodsModelForCheck=object1.optString("GOODSMODELforCheck");
  1687. String plateLimitNum=object1.optString("PlateLimitNum");
  1688. piece.setPlateLimitNum(plateLimitNum);
  1689. piece.setGoodsModel(goodsModelForCheck);
  1690. out_goodsID = object1.getString("out_goodsID");
  1691. piece.setGoodsId(out_goodsID);
  1692. out_goodsCode = object1.getString("out_goodsCode");
  1693. String outGoodsCodeForCheck=object1.optString("out_goodsCode");
  1694. piece.setGoodsCode(out_goodsCode);
  1695. out_goodsName = object1.getString("out_goodsName");
  1696. piece.setGoodsName(out_goodsName);
  1697. piece.setBarCode(outbarcode);
  1698. String groutingNum = object1
  1699. .optString("out_groutingNum");
  1700. String mouldCode = object1.optString("out_mouldCode");
  1701. String groutingDate = object1
  1702. .optString("out_groutingdate");
  1703. String groutingcode = object1
  1704. .optString("out_groutingUserCode");
  1705. String publicBodyFlag = object1
  1706. .optString("out_ispublicbody");
  1707. String trademarkName = object1
  1708. .optString("out_logoName");
  1709. piece.setTrademarkName(trademarkName);
  1710. piece.setGroutingUserCode(groutingcode);
  1711. piece.setMouldNo(mouldCode);
  1712. piece.setGroutingNum(Integer.parseInt(groutingNum));
  1713. if (!TextUtils.isEmpty(groutingDate)) {
  1714. if (groutingDate.contains("/")) {
  1715. groutingDate = CommonUtil
  1716. .dateStringConverter(groutingDate);
  1717. } else if (groutingDate.contains("-")) {
  1718. groutingDate = CommonUtil
  1719. .commonDateConverter(groutingDate);
  1720. }
  1721. piece.setGroutingDate(groutingDate);
  1722. } else {
  1723. piece.setGroutingDate("");
  1724. }
  1725. piece.setPublicBilletFlag(publicBodyFlag);
  1726. if(piecelist!=null&&piecelist.size()==0&&nodeType==3) {
  1727. jsonObject = new JSONObject();
  1728. jsonObject.put("accountCode", accountCode);
  1729. jsonObject.put("userCode", piece_userCode);
  1730. jsonObject.put("userPassword", userPassword);
  1731. jsonObject.put("sessionKey", sessionKey);
  1732. jsonObject.put("procedureID", proId);// 工序ID,菜单页面传过来的
  1733. jsonObject.put("barcode", barcode);// 条码
  1734. jsonObject.put("module", "FinishedLoadingCar");
  1735. jsonObject.put("action","GetSetting");
  1736. JSONObject data = new JSONObject();
  1737. data.put("GoodsID",out_goodsID);
  1738. jsonObject.put("jsonData",data.toString());
  1739. client = null;
  1740. client = new WebClient();
  1741. String result5 = client.doPost("http://"
  1742. + ServerAddress_ip + ":"
  1743. + ServerAddress_duankou
  1744. + Constants.serverAction + "/DoAction",
  1745. jsonObject.toString( ), "application/json");
  1746. JSONObject jsonObject5=new JSONObject(result5);
  1747. JSONObject json6=(JSONObject) jsonObject5.opt("d");
  1748. int status6=json6.optInt("Status");
  1749. String message6=json6.optString("Message");
  1750. if(status6==0) {
  1751. String result6=json6.optString("Result");
  1752. JSONObject js7=new JSONObject(result6);
  1753. spm_011 =js7.optString("S_PM_011");
  1754. spm_012=js7.optString("S_PM_012");
  1755. spm_013=js7.optString("S_PM_013");
  1756. if(spm_012.equals("1")&&spm_013.equals("1")) {
  1757. plateNum=Integer.parseInt(plateLimitNum);
  1758. }
  1759. else {
  1760. plateNum=0;
  1761. }
  1762. }
  1763. else {
  1764. Bundle bundle=new Bundle();
  1765. bundle.putInt("Status", status6);
  1766. bundle.putString("Message", message6);
  1767. Message msg=new Message();
  1768. msg.what=2;
  1769. msg.setData(bundle);
  1770. exceptionHandler.sendMessage(msg);
  1771. return;
  1772. }
  1773. }
  1774. else if(piecelist!=null&&piecelist.size()>0&&nodeType==3) {
  1775. Piece p2=piecelist.get(0);
  1776. String originalLogoId= p2.getLogoId();
  1777. String originalLogoName=p2.getLogoName();
  1778. String orginalGoodsModelForCheck=p2.getGoodsModel();
  1779. String originalGoodsCode=p2.getGoodsCode();
  1780. if(spm_011.equals("1")) {
  1781. if(!logoId.equals(originalLogoId)) {
  1782. Bundle bundle=new Bundle();
  1783. bundle.putInt("Status",0);
  1784. bundle.putString("Message","此产品【"+outbarcode+"】的商标【"+logoName+"】与此批次商标【"+originalLogoName+"】不同,不能进行该操作。");
  1785. Message msg=new Message();
  1786. msg.what=2;
  1787. msg.setData(bundle);
  1788. exceptionHandler.sendMessage(msg);
  1789. return;
  1790. }
  1791. }
  1792. if(spm_012.equals("1")) {
  1793. if(!goodsModelForCheck.equals(orginalGoodsModelForCheck)) {
  1794. //注掉为点数装板 限制同型号装板
  1795. //由于H01412M与H01412M-G物料编码一致
  1796. //这两个产品可以装入一板内
  1797. //要是不让装入一板将上面if注释
  1798. //而这个注释打开
  1799. // if(!outGoodsCodeForCheck.equals(originalGoodsCode)) {
  1800. Bundle bundle=new Bundle();
  1801. bundle.putInt("Status",0);
  1802. bundle.putString("Message","此产品【"+outbarcode+"】的型号【"+out_goodsCode+"】与此批次型号【"+originalGoodsCode+"】不同,不能进行该操作。");
  1803. Message msg=new Message();
  1804. msg.what=2;
  1805. msg.setData(bundle);
  1806. exceptionHandler.sendMessage(msg);
  1807. return;
  1808. }
  1809. }
  1810. }
  1811. Message m5=new Message();
  1812. m5.what=4;
  1813. Bundle bundle=new Bundle();
  1814. bundle.putSerializable("piece", (Serializable)piece);
  1815. m5.setData(bundle);
  1816. handler3.sendMessage(m5);
  1817. } else {
  1818. Bundle bundle=new Bundle();
  1819. bundle.putInt("Status", status);
  1820. bundle.putString("Message", message);
  1821. Message msg=new Message();
  1822. msg.what=2;
  1823. msg.setData(bundle);
  1824. exceptionHandler.sendMessage(msg);
  1825. return;
  1826. }
  1827. } else if (collectType == 2) {
  1828. jsonObject = new JSONObject();
  1829. // 保存条码信息请求数据
  1830. jsonObject.put("accountCode", accountCode);
  1831. jsonObject.put("userCode", piece_userCode);
  1832. jsonObject.put("userPassword", userPassword);
  1833. jsonObject.put("sessionKey", sessionKey);
  1834. jsonObject.put("procedureID", proId);
  1835. JSONArray productionDataEntitys = new JSONArray();
  1836. JSONObject jsonobj = new JSONObject();
  1837. jsonobj.put("UserID", Long.parseLong(userID1));
  1838. jsonobj.put("UserCode", userCode1);
  1839. jsonobj.put("UserName", userName1);
  1840. jsonobj.put("Barcode", barcode);
  1841. productionDataEntitys.put(jsonobj);
  1842. jsonObject.put("productionDataEntitys",
  1843. productionDataEntitys);
  1844. client = null;
  1845. client = new WebClient();
  1846. String result6 = client.doPost("http://"
  1847. + ServerAddress_ip + ":"
  1848. + ServerAddress_duankou
  1849. + Constants.ADD_WORK_PIECE,
  1850. jsonObject.toString(), "application/json");
  1851. Message m = new Message();
  1852. m.what = 3;
  1853. Bundle b = new Bundle();
  1854. b.putString("result",
  1855. result6);
  1856. m.setData(b);
  1857. handler3.sendMessage(m);
  1858. }
  1859. }
  1860. catch (JSONException e) {
  1861. e.printStackTrace();
  1862. Message m = new Message();
  1863. m.what = 0;
  1864. Bundle b = new Bundle();
  1865. b.putString("message", "json数据异常");
  1866. m.setData(b);
  1867. exceptionHandler.sendMessage(m);
  1868. }
  1869. catch (Exception e) {
  1870. e.printStackTrace();
  1871. Message m = new Message();
  1872. Bundle b = new Bundle();
  1873. b.putString("message", "网络连接异常");
  1874. m.setData(b);
  1875. m.what = 0;
  1876. exceptionHandler.sendMessage(m);
  1877. }
  1878. }
  1879. }
  1880. };
  1881. Runnable UpperCase = new Runnable() {
  1882. @Override
  1883. public void run() {
  1884. // 小写转大写
  1885. met.setText(userUpper.toUpperCase());
  1886. // 设置EditText光标位置
  1887. met.setSelection(userUpper.length());
  1888. }
  1889. };
  1890. // 保存条码
  1891. private void getDataSaveBarCode() {
  1892. thread = null;
  1893. thread = new HandlerThread("SavePieceThread", 5);
  1894. thread.start();
  1895. mHandler = new Handler(thread.getLooper());
  1896. SavePieceRunnable savePieceRunnable = new SavePieceRunnable(obj);
  1897. mHandler.post(savePieceRunnable);
  1898. }
  1899. private class UserRunnable implements Runnable {
  1900. String workno;
  1901. public UserRunnable(String workno) {
  1902. this.workno = workno;
  1903. }
  1904. public UserRunnable() {
  1905. }
  1906. @Override
  1907. public void run() {
  1908. try {
  1909. jsonObject = new JSONObject();
  1910. switch (collectType) {
  1911. case 1:// 集中
  1912. jsonObject.put("accountCode", accountCode);
  1913. jsonObject.put("userCode", piece_userCode);
  1914. jsonObject.put("userPassword", userPassword);
  1915. jsonObject.put("sessionKey", sessionKey);
  1916. jsonObject.put("procedureID", proId);// 工序ID,菜单页面传过来的
  1917. jsonObject.put("procedureUserCode", workno);// 生产工号2
  1918. break;
  1919. case 2:// 单点
  1920. jsonObject.put("accountCode", accountCode);
  1921. jsonObject.put("userCode", piece_userCode);
  1922. jsonObject.put("userPassword", userPassword);
  1923. jsonObject.put("sessionKey", sessionKey);
  1924. jsonObject.put("procedureID", proId);// 工序ID,菜单页面传过来的
  1925. jsonObject.put("procedureUserCode", piece_userCode);// 生产工号2
  1926. break;
  1927. }
  1928. client = new WebClient();
  1929. String result = client.doPost("http://" + ServerAddress_ip
  1930. + ":" + ServerAddress_duankou
  1931. + Constants.PRODUCER_NO_VALID, jsonObject.toString(),
  1932. "application/json");
  1933. Message m = new Message();
  1934. m.what = 0;
  1935. Bundle b = new Bundle();
  1936. b.putString("worknoResult", result);
  1937. m.setData(b);
  1938. handler1.sendMessage(m);
  1939. } catch (Exception e) {
  1940. e.printStackTrace();
  1941. Message m = new Message();
  1942. Bundle b = new Bundle();
  1943. b.putString("message", "网络连接异常");
  1944. m.setData(b);
  1945. m.what = 1;
  1946. exceptionHandler.sendMessage(m);
  1947. }
  1948. }
  1949. };
  1950. @Override
  1951. public void onBackPressed() {
  1952. if (piecelist != null && piecelist.size() > 0) {
  1953. piecelist.clear();
  1954. }
  1955. super.onBackPressed();
  1956. }
  1957. @Override
  1958. protected void onActivityResult(int requestCode, int resultCode,
  1959. Intent intent) {
  1960. if(requestCode==100&&resultCode==101)
  1961. {
  1962. ProcessDialogUtils.showProcessDialog(PieceActivity.this);
  1963. if (bt2.isEnabled()) {
  1964. bt2.setEnabled(false);
  1965. getDataSaveBarCode();
  1966. }
  1967. }
  1968. if (requestCode == 101 && resultCode == 103) {
  1969. barcode.setEnabled(true);
  1970. barcode.setText("");
  1971. barcode.setFocusable(true);
  1972. barcode.setFocusableInTouchMode(true);
  1973. barcode.requestFocus();
  1974. barcode.findFocus();
  1975. barcode.setFilters(new InputFilter[] { new InputFilter() {
  1976. @Override
  1977. public CharSequence filter(CharSequence source, int start,
  1978. int end, Spanned dest, int dstart, int dend) {
  1979. return null;
  1980. }
  1981. } });
  1982. ////CommonUtil.BarcodeMaxLength(barcode, 50);;
  1983. }
  1984. if(requestCode==103&&resultCode==104) {
  1985. barcode.setEnabled(true);
  1986. barcode.setText("");
  1987. barcode.setFocusable(true);
  1988. barcode.setFocusableInTouchMode(true);
  1989. barcode.requestFocus();
  1990. barcode.findFocus();
  1991. barcode.setFilters(new InputFilter[] { new InputFilter() {
  1992. @Override
  1993. public CharSequence filter(CharSequence source, int start,
  1994. int end, Spanned dest, int dstart, int dend) {
  1995. return null;
  1996. }
  1997. } });
  1998. ////CommonUtil.BarcodeMaxLength(barcode, 50);;
  1999. }
  2000. if (requestCode == 102 && resultCode == RESULT_OK) {
  2001. Bundle bundle = intent.getExtras();
  2002. String scanResult = bundle.getString("result");
  2003. View rootview = this.getWindow().getDecorView();
  2004. EditText v = (EditText) rootview.findFocus();
  2005. int id = v.getId();
  2006. v.setText(scanResult);
  2007. v.setSelection(scanResult.length());
  2008. switch (id) {
  2009. case R.id.good_code:
  2010. String woCode = v.getText().toString();
  2011. met.setEnabled(false);
  2012. met.setFocusable(false);
  2013. met.setFilters(new InputFilter[] { new InputFilter() {
  2014. @Override
  2015. public CharSequence filter(CharSequence source, int start,
  2016. int end, Spanned dest, int dstart, int dend) {
  2017. return source.length() < 1 ? dest.subSequence(dstart,
  2018. dend) : "";
  2019. }
  2020. } });
  2021. barcode.setEnabled(false);
  2022. barcode.setFocusable(false);
  2023. barcode.setFilters(new InputFilter[] { new InputFilter() {
  2024. @Override
  2025. public CharSequence filter(CharSequence source, int start,
  2026. int end, Spanned dest, int dstart, int dend) {
  2027. return source.length() < 1 ? dest.subSequence(dstart,
  2028. dend) : "";
  2029. }
  2030. } });
  2031. ProcessDialogUtils.showProcessDialog(PieceActivity.this);
  2032. thread = new HandlerThread("userThread", 5);
  2033. thread.start();
  2034. mHandler = new Handler(thread.getLooper());
  2035. UserRunnable userRunnable = new UserRunnable(woCode);
  2036. mHandler.post(userRunnable);
  2037. break;
  2038. case R.id.good_tm:
  2039. String etcode = v.getText().toString().trim();
  2040. String workno = met.getText().toString();
  2041. if (TextUtils.isEmpty(workno)) {
  2042. CustomToast.showToast(getApplicationContext(), "生产工号不能为空",
  2043. 2000);
  2044. met.setEnabled(true);
  2045. met.setFocusable(true);
  2046. met.setFocusableInTouchMode(true);
  2047. met.requestFocus();
  2048. met.findFocus();
  2049. met.setFilters(new InputFilter[] { new InputFilter() {
  2050. @Override
  2051. public CharSequence filter(CharSequence source,
  2052. int start, int end, Spanned dest, int dstart,
  2053. int dend) {
  2054. return null;
  2055. }
  2056. } });
  2057. return;
  2058. } else {
  2059. if (!userCodeIsValid) {
  2060. // Toast.makeText(getApplicationContext(),
  2061. // "请在生产工号输入框内按回车键验证生产工号",Toast.LENGTH_SHORT).show();
  2062. CustomToast.showToast(getApplicationContext(),
  2063. "请在生产工号输入框内按回车键验证生产工号", 2000);
  2064. met.setEnabled(true);
  2065. met.setFocusable(true);
  2066. met.setFocusableInTouchMode(true);
  2067. met.requestFocus();
  2068. met.findFocus();
  2069. met.setFilters(new InputFilter[] { new InputFilter() {
  2070. @Override
  2071. public CharSequence filter(CharSequence source,
  2072. int start, int end, Spanned dest,
  2073. int dstart, int dend) {
  2074. return null;
  2075. }
  2076. } });
  2077. return;
  2078. }
  2079. }
  2080. ProcessDialogUtils.showProcessDialog(PieceActivity.this);
  2081. barcode.setEnabled(false);
  2082. barcode.setFocusable(false);
  2083. barcode.setFilters(new InputFilter[] { new InputFilter() {
  2084. @Override
  2085. public CharSequence filter(CharSequence source, int start,
  2086. int end, Spanned dest, int dstart, int dend) {
  2087. return source.length() < 1 ? dest.subSequence(dstart,
  2088. dend) : "";
  2089. }
  2090. } });
  2091. if (!TextUtils.isEmpty(etcode)) {
  2092. // if (!CommonUtil.isNumber(etcode)) {
  2093. // ProcessDialogUtils.closeProgressDilog();
  2094. // CommonUtil.setDefault(Notification.DEFAULT_VIBRATE,
  2095. // getApplicationContext());
  2096. // // CommonUtil.showRepeatDialog(code+"格式不匹配",PieceActivity.this);
  2097. // // Toast.makeText(getApplicationContext(),
  2098. // // etcode+"格式不匹配",Toast.LENGTH_SHORT).show();
  2099. // CustomToast.showToast(getApplicationContext(), etcode
  2100. // + "格式不匹配", 2000);
  2101. // barcode.setEnabled(true);
  2102. // barcode.setText("");
  2103. // barcode.setFocusable(true);
  2104. // barcode.setFocusableInTouchMode(true);
  2105. // barcode.requestFocus();
  2106. // barcode.findFocus();
  2107. // barcode.setFilters(new InputFilter[] { new InputFilter() {
  2108. // @Override
  2109. // public CharSequence filter(CharSequence source,
  2110. // int start, int end, Spanned dest,
  2111. // int dstart, int dend) {
  2112. //
  2113. // return null;
  2114. // }
  2115. // } });
  2116. // //CommonUtil.BarcodeMaxLength(barcode, 50);;
  2117. // return;
  2118. // }
  2119. if (collectType == 2) {
  2120. if (piecelist != null && piecelist.size() > 0) {
  2121. piecelist.removeAll(piecelist);
  2122. }
  2123. if (pieceAdapter != null) {
  2124. pieceAdapter.notifyDataSetChanged();
  2125. }
  2126. }
  2127. if (piecelist.size() > 0) {
  2128. boolean b = Removeduplicate.removeBarCode(etcode,
  2129. piecelist);
  2130. if (b) {
  2131. barcode.setEnabled(true);
  2132. barcode.setText("");
  2133. barcode.setFocusable(true);
  2134. barcode.setFocusableInTouchMode(true);
  2135. barcode.requestFocus();
  2136. barcode.findFocus();
  2137. barcode.setFilters(new InputFilter[] { new InputFilter() {
  2138. @Override
  2139. public CharSequence filter(CharSequence source,
  2140. int start, int end, Spanned dest,
  2141. int dstart, int dend) {
  2142. return null;
  2143. }
  2144. } });
  2145. ////CommonUtil.BarcodeMaxLength(barcode, 50);;
  2146. CommonUtil.setDefault(Notification.DEFAULT_VIBRATE,
  2147. getApplicationContext());
  2148. if (collectType == 2) {
  2149. CommonUtil.showRepeatDialog("条码" + etcode
  2150. + "重复", PieceActivity.this);
  2151. } else if (collectType == 1) {
  2152. // Toast.makeText(getApplicationContext(),"条码"+etcode+"重复",Toast.LENGTH_SHORT).show();
  2153. CustomToast.showToast(getApplicationContext(),
  2154. "条码" + etcode + "重复", 2000);
  2155. }
  2156. ProcessDialogUtils.closeProgressDilog();
  2157. return;
  2158. }
  2159. }
  2160. if(collectType==1&&nodeType==3) {
  2161. if(plateNum>0&&piecelist.size()==plateNum) {
  2162. CommonUtil.setDefault(Notification.DEFAULT_VIBRATE,
  2163. getApplicationContext());
  2164. CommonUtil.showBarCodeAlertDialog(0, "超过装板数量【"+plateNum+"】",
  2165. PieceActivity.this, barcode, null, null);
  2166. ProcessDialogUtils.closeProgressDilog();
  2167. return;
  2168. }
  2169. }
  2170. thread = null;
  2171. thread = new HandlerThread("BarCoderThread", 5);
  2172. thread.start();
  2173. mHandler = null;
  2174. mHandler = new Handler(thread.getLooper());
  2175. BarcodeRunnable barcodeRunnable = new BarcodeRunnable(
  2176. etcode, obj);
  2177. mHandler.post(barcodeRunnable);
  2178. }
  2179. else {
  2180. ProcessDialogUtils.closeProgressDilog();
  2181. CustomToast.showToast(getApplicationContext(), "请输入产品条码",
  2182. 2000);
  2183. barcode.setEnabled(true);
  2184. barcode.setText("");
  2185. barcode.setFocusable(true);
  2186. barcode.setFocusableInTouchMode(true);
  2187. barcode.requestFocus();
  2188. barcode.findFocus();
  2189. barcode.setFilters(new InputFilter[] { new InputFilter() {
  2190. @Override
  2191. public CharSequence filter(CharSequence source,
  2192. int start, int end, Spanned dest, int dstart,
  2193. int dend) {
  2194. return null;
  2195. }
  2196. } });
  2197. ////CommonUtil.BarcodeMaxLength(barcode, 50);;
  2198. return;
  2199. }
  2200. break;
  2201. }
  2202. }
  2203. }
  2204. @Override
  2205. public boolean onKeyDown(int keyCode, KeyEvent event) {
  2206. // 获取手机当前音量值
  2207. switch (keyCode) {
  2208. // 音量减小
  2209. case KeyEvent.KEYCODE_VOLUME_DOWN:
  2210. if (event.getRepeatCount() == 0) {
  2211. if (collectType == 1) {
  2212. String workno = met.getText().toString();
  2213. if (TextUtils.isEmpty(workno)) {
  2214. CustomToast.showToast(getApplicationContext(),
  2215. "生产工号不能为空", 2000);
  2216. met.setEnabled(true);
  2217. met.setFocusable(true);
  2218. met.setFocusableInTouchMode(true);
  2219. met.requestFocus();
  2220. met.findFocus();
  2221. met.setFilters(new InputFilter[] { new InputFilter() {
  2222. @Override
  2223. public CharSequence filter(CharSequence source,
  2224. int start, int end, Spanned dest,
  2225. int dstart, int dend) {
  2226. return null;
  2227. }
  2228. } });
  2229. return true;
  2230. } else {
  2231. if (!userCodeIsValid) {
  2232. CustomToast.showToast(getApplicationContext(),
  2233. "请在生产工号输入框内按回车键验证生产工号", 2000);
  2234. met.setEnabled(true);
  2235. met.setFocusable(true);
  2236. met.setFocusableInTouchMode(true);
  2237. met.requestFocus();
  2238. met.findFocus();
  2239. met.setFilters(new InputFilter[] { new InputFilter() {
  2240. @Override
  2241. public CharSequence filter(CharSequence source,
  2242. int start, int end, Spanned dest,
  2243. int dstart, int dend) {
  2244. return null;
  2245. }
  2246. } });
  2247. return true;
  2248. }
  2249. }
  2250. if (piecelist.size() == 0) {
  2251. CustomToast.showToast(getApplicationContext(),
  2252. "没有可提交的明细信息", 2000);
  2253. return true;
  2254. }
  2255. if(collectType==1&&nodeType==3) {
  2256. if(plateNum>0&&piecelist.size()!=plateNum) {
  2257. CommonUtil.setDefault(Notification.DEFAULT_VIBRATE,
  2258. getApplicationContext());
  2259. CommonUtil.showBarCodeAlertDialog(0, "未达到装板数量【"+plateNum+"】",
  2260. PieceActivity.this, barcode, null, null);
  2261. return true;
  2262. }
  2263. }
  2264. if(isGlazeChange==1)
  2265. {
  2266. Intent intent=new Intent();
  2267. intent.setClass(PieceActivity.this, GlazePieceSetActivity.class);
  2268. Bundle b=new Bundle();
  2269. b.putInt("procedureId",proId);
  2270. intent.putExtras(b);
  2271. startActivityForResult(intent,100);
  2272. }
  2273. else
  2274. {
  2275. ProcessDialogUtils.showProcessDialog(PieceActivity.this);
  2276. if (bt2.isEnabled()) {
  2277. bt2.setEnabled(false);
  2278. getDataSaveBarCode();
  2279. }
  2280. }
  2281. }
  2282. }
  2283. // 音量减小时应该执行的功能代码
  2284. return true;
  2285. // 音量增大
  2286. case KeyEvent.KEYCODE_VOLUME_UP:
  2287. if (event.getRepeatCount() == 0) {
  2288. if (collectType == 1) {
  2289. String workno = met.getText().toString();
  2290. if (TextUtils.isEmpty(workno)) {
  2291. CustomToast.showToast(getApplicationContext(),
  2292. "生产工号不能为空", 2000);
  2293. met.setEnabled(true);
  2294. met.setFocusable(true);
  2295. met.setFocusableInTouchMode(true);
  2296. met.requestFocus();
  2297. met.findFocus();
  2298. met.setFilters(new InputFilter[] { new InputFilter() {
  2299. @Override
  2300. public CharSequence filter(CharSequence source,
  2301. int start, int end, Spanned dest,
  2302. int dstart, int dend) {
  2303. return null;
  2304. }
  2305. } });
  2306. return true;
  2307. } else {
  2308. if (!userCodeIsValid) {
  2309. CustomToast.showToast(getApplicationContext(),
  2310. "请在生产工号输入框内按回车键验证生产工号", 2000);
  2311. met.setEnabled(true);
  2312. met.setFocusable(true);
  2313. met.setFocusableInTouchMode(true);
  2314. met.requestFocus();
  2315. met.findFocus();
  2316. met.setFilters(new InputFilter[] { new InputFilter() {
  2317. @Override
  2318. public CharSequence filter(CharSequence source,
  2319. int start, int end, Spanned dest,
  2320. int dstart, int dend) {
  2321. return null;
  2322. }
  2323. } });
  2324. return true;
  2325. }
  2326. }
  2327. if (piecelist.size() == 0) {
  2328. ProcessDialogUtils.closeProgressDilog();
  2329. Toast.makeText(getApplicationContext(), "没有可提交的明细信息",
  2330. Toast.LENGTH_SHORT).show();
  2331. return true;
  2332. }
  2333. if(collectType==1&&nodeType==3) {
  2334. if(plateNum>0&&piecelist.size()!=plateNum) {
  2335. CommonUtil.setDefault(Notification.DEFAULT_VIBRATE,
  2336. getApplicationContext());
  2337. CommonUtil.showBarCodeAlertDialog(0, "未达到装板数量【"+plateNum+"】",
  2338. PieceActivity.this, barcode, null, null);
  2339. return true;
  2340. }
  2341. }
  2342. if(isGlazeChange==1)
  2343. {
  2344. Intent intent=new Intent();
  2345. intent.setClass(PieceActivity.this, GlazePieceSetActivity.class);
  2346. Bundle b=new Bundle();
  2347. b.putInt("procedureId",proId);
  2348. intent.putExtras(b);
  2349. startActivityForResult(intent,100);
  2350. }
  2351. else
  2352. {
  2353. ProcessDialogUtils.showProcessDialog(PieceActivity.this);
  2354. if (bt2.isEnabled()) {
  2355. bt2.setEnabled(false);
  2356. getDataSaveBarCode();
  2357. }
  2358. }
  2359. // 音量增大时应该执行的功能代码
  2360. }
  2361. }
  2362. return true;
  2363. }
  2364. return super.onKeyDown(keyCode, event);
  2365. }
  2366. @Override
  2367. protected void onDestroy() {
  2368. super.onDestroy();
  2369. }
  2370. @Override
  2371. public boolean dispatchTouchEvent(MotionEvent ev) {
  2372. switch (ev.getAction()) {
  2373. case MotionEvent.ACTION_DOWN:
  2374. View view = getCurrentFocus();
  2375. CommonUtil.hideKeyboard(ev, view, PieceActivity.this);//调用方法判断是否需要隐藏键盘
  2376. break;
  2377. default:
  2378. break;
  2379. }
  2380. return super.dispatchTouchEvent(ev);
  2381. }
  2382. @Override
  2383. public Resources getResources() {
  2384. Resources res = super.getResources();
  2385. Configuration config = new Configuration();
  2386. config.setToDefaults();
  2387. res.updateConfiguration(config, res.getDisplayMetrics());
  2388. return res;
  2389. }
  2390. }