PieceActivity.java 89 KB

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