ProductPathActivity.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. package com.jiaju.activity;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import java.util.List;
  5. import org.json.JSONArray;
  6. import org.json.JSONObject;
  7. import com.jiaju.net.WebClient;
  8. import com.jiaju.utils.CommonUtil;
  9. import com.jiaju.utils.Constants;
  10. import com.jiaju.utils.CustomToast;
  11. import com.jiaju.utils.ProcessDialogUtils;
  12. import com.jiaju.widget.DefectCommonPopMenu;
  13. import android.app.Activity;
  14. import android.app.Notification;
  15. import android.content.Context;
  16. import android.content.Intent;
  17. import android.content.SharedPreferences;
  18. import android.content.res.Configuration;
  19. import android.content.res.Resources;
  20. import android.os.Bundle;
  21. import android.os.Handler;
  22. import android.os.HandlerThread;
  23. import android.os.Message;
  24. import android.text.Editable;
  25. import android.text.InputFilter;
  26. import android.text.InputType;
  27. import android.text.Spanned;
  28. import android.text.TextUtils;
  29. import android.text.TextWatcher;
  30. import android.view.Gravity;
  31. import android.view.KeyEvent;
  32. import android.view.View;
  33. import android.view.View.OnClickListener;
  34. import android.view.inputmethod.EditorInfo;
  35. import android.view.inputmethod.InputMethodManager;
  36. import android.widget.EditText;
  37. import android.widget.ImageButton;
  38. import android.widget.ImageView;
  39. import android.widget.LinearLayout;
  40. import android.widget.ListView;
  41. import android.widget.PopupWindow;
  42. import android.widget.SimpleAdapter;
  43. import android.widget.TextView;
  44. import android.widget.TextView.OnEditorActionListener;
  45. import android.widget.Toast;
  46. public class ProductPathActivity extends Activity {
  47. private EditText barcodeEdt;// 条码
  48. private TextView productcode;// 产品编码
  49. private TextView modelcode;// 模具编码
  50. private TextView groutingcount;// 注浆次数
  51. private TextView state;// 产品状态
  52. private TextView title;
  53. private TextView back;
  54. private String barcode;
  55. private ImageButton leftBtn;
  56. private ListView listw;
  57. private int collectType;// 采集类型:1-单点 2-集中
  58. private int proId;// 工序I
  59. private WebClient client;
  60. private String model;
  61. private String FILE = "user";// 用于保存SharedPreferences的文件
  62. private String accountCode = "";// 帐套
  63. private String userPassword = "";// 用户密码
  64. private String sessionKey = "";// sessionKey,每次登陆都会改变
  65. private String productPath_userCode;// 生产工号Code
  66. private SharedPreferences sp;
  67. private String ServerAddress_ip, ServerAddress_duankou;
  68. private Message message;
  69. private String result = null;
  70. private JSONObject jsonObject;
  71. private TextView Bcode;
  72. private HandlerThread thread;
  73. private Handler mHandler = null;
  74. private SimpleAdapter simpleAdapter;
  75. private ImageView productRecord;
  76. private LinearLayout parent;
  77. private PopupWindow mPopupWindow; // 弹出框
  78. private TextView productType;
  79. private TextView glazeColorType;
  80. private TextView groutingLineCode;
  81. private TextView groutingWorkNo;
  82. private TextView groutingDate;
  83. private TextView goodsLevel;
  84. private TextView trademark;
  85. private TextView tvMaterialCode;
  86. private TextView tvOutLabelCode;
  87. private Handler barcodeUpperH = new Handler();
  88. private String barcodeUpper;
  89. private Object obj = new Object();
  90. List<HashMap<String, Object>> listItem;
  91. @Override
  92. protected void onCreate(Bundle savedInstanceState) {
  93. super.onCreate(savedInstanceState);
  94. setContentView(R.layout.activity_product_path);
  95. sp = getSharedPreferences(FILE, MODE_PRIVATE);
  96. accountCode = sp.getString("AccountCode", "");
  97. productPath_userCode = sp.getString("UserCode", "");
  98. userPassword = sp.getString("UserPassword", "");
  99. sessionKey = sp.getString("SessionKey", "");
  100. // 获取服务ip和端口号
  101. ServerAddress_ip = sp.getString("ServerAddress_ip", "");
  102. ServerAddress_duankou = sp.getString("ServerAddress_duankou", "");
  103. SysApplication.getInstance().addActivity(this);
  104. listItem = new ArrayList<HashMap<String, Object>>();
  105. initview();
  106. //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
  107. title.setText("产品跟踪");
  108. title.setTextSize(24);
  109. alllistener();
  110. }
  111. private void initview() {
  112. barcodeEdt = (EditText)findViewById(R.id.etbarcode);
  113. barcodeEdt.setRawInputType(InputType.TYPE_CLASS_NUMBER);
  114. Bcode = (TextView) findViewById(R.id.textV);
  115. productType = (TextView)findViewById(R.id.productType);
  116. productcode = (TextView) findViewById(R.id.textV1);
  117. tvMaterialCode=(TextView) findViewById(R.id.tvMaterialCode);
  118. tvOutLabelCode=(TextView) findViewById(R.id.tvOutLabelCode);
  119. glazeColorType = (TextView)findViewById(R.id.glazeColorType);
  120. groutingLineCode = (TextView) findViewById(R.id.groutingLineCode);
  121. groutingWorkNo = (TextView)findViewById(R.id.groutingWorkNo);
  122. groutingDate = (TextView) findViewById(R.id.groutingDate);
  123. goodsLevel = (TextView)findViewById(R.id.goodsLevel);
  124. modelcode = (TextView) findViewById(R.id.textV3);
  125. groutingcount = (TextView) findViewById(R.id.textV4);
  126. state = (TextView) findViewById(R.id.textV5);
  127. listw = (ListView) findViewById(R.id.listvw_path);
  128. title = (TextView) findViewById(R.id.title);
  129. trademark = (TextView) findViewById(R.id.trademark);
  130. back = (TextView) findViewById(R.id.back);
  131. leftBtn = (ImageButton) findViewById(R.id.left_img);
  132. productRecord = (ImageView) findViewById(R.id.search);
  133. productRecord.setVisibility(View.VISIBLE);
  134. parent = (LinearLayout) findViewById(R.id.parentRel);
  135. }
  136. private void alllistener() {
  137. leftBtn.setOnClickListener(new OnClickListener() {
  138. @Override
  139. public void onClick(View v) {
  140. finish();
  141. }
  142. });
  143. productRecord.setOnClickListener(new View.OnClickListener() {
  144. @Override
  145. public void onClick(View v) {
  146. int height = parent.getHeight() - v.getHeight();
  147. DefectCommonPopMenu recordPopMenu = new DefectCommonPopMenu(ProductPathActivity.this, height);
  148. mPopupWindow = recordPopMenu.getMenu();
  149. if (mPopupWindow == null) {
  150. return;
  151. }
  152. if (mPopupWindow.isShowing()) {
  153. mPopupWindow.dismiss();
  154. return;
  155. }
  156. mPopupWindow.showAtLocation(parent, Gravity.BOTTOM, 0, 0);
  157. LinearLayout scanLay = (LinearLayout) recordPopMenu.menu.findViewById(R.id.scanlay);
  158. ImageView scanImg = (ImageView) recordPopMenu.menu.findViewById(R.id.scanimg);
  159. TextView scanTitle = (TextView) recordPopMenu.menu.findViewById(R.id.scantitle);
  160. scanTitle.setText("扫一扫");
  161. scanImg.setBackgroundResource(R.drawable.scan);
  162. scanLay.setOnClickListener(new View.OnClickListener() {
  163. @Override
  164. public void onClick(View v) {
  165. Intent openCameraIntent = new Intent(ProductPathActivity.this, CaptureActivity.class);
  166. startActivityForResult(openCameraIntent, 102);
  167. if (mPopupWindow.isShowing()) {
  168. mPopupWindow.dismiss();
  169. }
  170. }
  171. });
  172. }
  173. });
  174. back.setOnClickListener(new OnClickListener() {
  175. @Override
  176. public void onClick(View v) {
  177. finish();
  178. }
  179. });
  180. barcodeEdt.setOnEditorActionListener(new OnEditorActionListener() {
  181. @Override
  182. public boolean onEditorAction(TextView v, int actionId,
  183. KeyEvent event) {
  184. if (actionId == EditorInfo.IME_ACTION_GO) {
  185. barcode = barcodeEdt.getText().toString().trim();
  186. ProcessDialogUtils.showProcessDialog(ProductPathActivity.this);
  187. Bcode.setText("");
  188. productType.setText("");
  189. productcode.setText("");
  190. glazeColorType.setText("");
  191. groutingLineCode.setText("");
  192. groutingDate.setText("");
  193. groutingWorkNo.setText("");
  194. modelcode.setText("");
  195. goodsLevel.setText("");
  196. trademark.setText("");
  197. tvMaterialCode.setText("");
  198. tvOutLabelCode.setText("");
  199. groutingcount.setText("");
  200. state.setText("");
  201. if(simpleAdapter!=null){
  202. listItem.clear();
  203. simpleAdapter.notifyDataSetChanged();
  204. }
  205. barcodeEdt.setEnabled(false);
  206. barcodeEdt.setFocusable(false);
  207. barcodeEdt.setFilters(new InputFilter[] { new InputFilter() {
  208. @Override
  209. public CharSequence filter(CharSequence source,
  210. int start, int end, Spanned dest, int dstart,
  211. int dend) {
  212. return source.length() < 1 ? dest.subSequence(dstart, dend): "";
  213. }
  214. } });
  215. if(barcode.substring(0, 4).equals("http"))
  216. {
  217. String[] parts = barcode.split("-", 2); // 第二个参数限制分割后的数组长度,这里为2
  218. if (parts.length == 2) {
  219. //System.out.println("第一部分: " + parts[0]);
  220. //System.out.println("第二部分: " + parts[1]);
  221. barcode = parts[1];
  222. }
  223. }
  224. thread = null;
  225. thread = new HandlerThread("BarCoderThread", 5);
  226. thread.start();
  227. mHandler = null;
  228. mHandler = new Handler(thread.getLooper());
  229. BarcodeRunnable barcodeRunnable=new BarcodeRunnable(obj);
  230. mHandler.post(barcodeRunnable);
  231. return true;
  232. }
  233. return false;
  234. }
  235. });
  236. barcodeEdt.addTextChangedListener(new TextWatcher() {
  237. @Override
  238. public void onTextChanged(CharSequence s, int start, int before, int count) {
  239. barcodeUpper = barcodeEdt.getText().toString().trim();
  240. // 判断输入的文字是否是小写
  241. for (int i = 0; i < barcodeUpper.length(); i++) {
  242. if (barcodeUpper.charAt(i) - 0 >= 97 && barcodeUpper.charAt(i) - 0 <= 122) {
  243. barcodeUpperH.postDelayed(BarcodeUpperCase, 300);
  244. }
  245. }
  246. if(start==0&&before==0&&count>1) {
  247. barcode = barcodeEdt.getText().toString().trim();
  248. ProcessDialogUtils.showProcessDialog(ProductPathActivity.this);
  249. Bcode.setText("");
  250. productType.setText("");
  251. productcode.setText("");
  252. glazeColorType.setText("");
  253. groutingLineCode.setText("");
  254. groutingDate.setText("");
  255. groutingWorkNo.setText("");
  256. modelcode.setText("");
  257. goodsLevel.setText("");
  258. trademark.setText("");
  259. groutingcount.setText("");
  260. tvMaterialCode.setText("");
  261. tvOutLabelCode.setText("");
  262. state.setText("");
  263. if(simpleAdapter!=null){
  264. listItem.clear();
  265. simpleAdapter.notifyDataSetChanged();
  266. }
  267. barcodeEdt.setEnabled(false);
  268. barcodeEdt.setFocusable(false);
  269. barcodeEdt.setFilters(new InputFilter[] { new InputFilter() {
  270. @Override
  271. public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
  272. int dend) {
  273. return source.length() < 1 ? dest.subSequence(dstart, dend) : "";
  274. }
  275. } });
  276. if(barcode.substring(0, 4).equals("http"))
  277. {
  278. String[] parts = barcode.split("-", 2); // 第二个参数限制分割后的数组长度,这里为2
  279. if (parts.length == 2) {
  280. //System.out.println("第一部分: " + parts[0]);
  281. //System.out.println("第二部分: " + parts[1]);
  282. barcode = parts[1];
  283. }
  284. }
  285. thread = null;
  286. thread = new HandlerThread("BarCoderThread", 5);
  287. thread.start();
  288. mHandler = null;
  289. mHandler = new Handler(thread.getLooper());
  290. BarcodeRunnable barcodeRunnable = new BarcodeRunnable(obj);
  291. mHandler.post(barcodeRunnable);
  292. }
  293. }
  294. @Override
  295. public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  296. }
  297. @Override
  298. public void afterTextChanged(Editable s) {
  299. }
  300. });
  301. }
  302. Handler h = new Handler() {
  303. @Override
  304. public void handleMessage(Message msg) {
  305. super.handleMessage(msg);
  306. switch (msg.what) {
  307. case 0:
  308. Bundle b;
  309. b = msg.getData();
  310. String json = b.getString("barcodeResult");
  311. ProcessDialogUtils.closeProgressDilog();
  312. try {
  313. JSONObject j = new JSONObject(json);
  314. JSONObject jobj = (JSONObject) j.opt("d");
  315. int status = jobj.optInt("Status");
  316. String message = jobj.optString("Message");
  317. if (status == 0) {
  318. String Result = jobj.getString("Result");
  319. JSONObject object1 = new JSONObject(Result);
  320. JSONArray array1 = object1.optJSONArray("Table");
  321. if (array1 != null && array1.length() > 0) {
  322. JSONObject jo1 = array1.optJSONObject(0);
  323. String barcode = jo1.optString("BARCODE");
  324. Bcode.setText(barcode);
  325. String goodsType = jo1.optString("GOODSTYPENAME");
  326. productType.setText(goodsType);
  327. String goodsCode = jo1.optString("GOODSCODE");
  328. int groutingBatchNo=jo1.optInt("GROUTINGBATCHNO");
  329. String goodsSpecification = jo1.optString("GOODSSPECIFICATION");
  330. if (!goodsSpecification.equals("null")) {
  331. productcode.setText(goodsCode+"["+goodsSpecification+"]");
  332. } else {
  333. productcode.setText(goodsCode);
  334. }
  335. String trademarkName = jo1.optString("LOGOCODENAME");
  336. if (!trademark.equals("null")) {
  337. trademark.setText(trademarkName);
  338. } else {
  339. trademark.setText("");
  340. }
  341. String materialCode=jo1.optString("MATERIALCODE");
  342. String outLabelCode=jo1.optString("OUTLABELCODE");
  343. if(outLabelCode.equals("null")) {
  344. outLabelCode="";
  345. }
  346. tvMaterialCode.setText(materialCode);
  347. tvOutLabelCode.setText(outLabelCode);
  348. String glazecolorType = jo1.optString("DICTIONARYVALUE");
  349. glazeColorType.setText(glazecolorType);
  350. String groutingCode = jo1.optString("GROUTINGLINECODE");
  351. groutingLineCode.setText(groutingCode);
  352. String mouldcode = jo1.optString("GROUTINGMOULDCODE");
  353. modelcode.setText(mouldcode);
  354. int groutingNum = jo1.optInt("GROUTINGNUM");
  355. groutingcount.setText(groutingNum + "");
  356. String groutingUserCode = jo1.optString("GROUTINGUSERCODE");
  357. groutingWorkNo.setText(groutingUserCode);
  358. String date = jo1.optString("GROUTINGDATE");
  359. if (!date.equals("null")) {
  360. if (date.contains("/")) {
  361. date = CommonUtil.dateStringConverter(date);
  362. } else if (date.contains("-")) {
  363. date = CommonUtil.commonDateConverter(date);
  364. }
  365. groutingDate.setText(date+" ("+groutingBatchNo+")");
  366. } else {
  367. groutingDate.setText("("+groutingBatchNo+")");
  368. }
  369. String statusName = jo1.optString("STATUSNAME");
  370. state.setText(statusName);
  371. String level = jo1.optString("LEVELNAME");
  372. if (!level.equals("null")) {
  373. goodsLevel.setText(level);
  374. } else {
  375. goodsLevel.setText("");
  376. }
  377. }
  378. JSONArray array2 = object1.optJSONArray("Table1");
  379. if (array2 != null && array2.length() > 0) {
  380. for (int i = 0; i < array2.length(); i++) {
  381. JSONObject j2 = array2.optJSONObject(i);
  382. String productLineName = j2.optString("PRODUCTIONLINENAME");
  383. String procedureName = j2.optString("PROCEDURENAME");
  384. String userCode = j2.optString("USERCODE");
  385. String operationTime = j2.optString("CREATETIME");
  386. String operator = j2.optString("CREATEUSERNAME");
  387. String goodsLevelName = j2.optString("GOODSLEVELNAME");
  388. HashMap<String, Object> map1 = new HashMap<String, Object>();
  389. if (productLineName.equals("null")) {
  390. map1.put("ProductLineName", "");
  391. } else {
  392. map1.put("ProductLineName", productLineName);
  393. }
  394. if (!procedureName.equals("null")) {
  395. map1.put("ProcedureName", procedureName);
  396. } else {
  397. map1.put("ProcedureName", "");
  398. }
  399. map1.put("UserCode", userCode);
  400. map1.put("OperationTime", operationTime);
  401. map1.put("Operator", operator);
  402. if (!goodsLevelName.equals("null")) {
  403. map1.put("GoodsLevelName", goodsLevelName);
  404. } else {
  405. map1.put("GoodsLevelName", "");
  406. }
  407. listItem.add(map1);
  408. }
  409. if (simpleAdapter == null) {
  410. simpleAdapter = new SimpleAdapter(ProductPathActivity.this, listItem,
  411. R.layout.path_item,
  412. new String[] { "ProductLineName", "ProcedureName", "UserCode", "OperationTime",
  413. "Operator", "GoodsLevelName" },
  414. new int[] { R.id.productlineName, R.id.procedureName, R.id.workno,
  415. R.id.operationTime, R.id.operator, R.id.operationDesc });
  416. listw.setAdapter(simpleAdapter);
  417. } else {
  418. simpleAdapter.notifyDataSetChanged();
  419. }
  420. }
  421. barcodeEdt.setEnabled(true);
  422. barcodeEdt.setText("");
  423. barcodeEdt.setFocusable(true);
  424. barcodeEdt.setFocusableInTouchMode(true);
  425. barcodeEdt.requestFocus();
  426. barcodeEdt.findFocus();
  427. barcodeEdt.setFilters(new InputFilter[] { new InputFilter() {
  428. @Override
  429. public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
  430. int dstart, int dend) {
  431. return null;
  432. }
  433. } });
  434. //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
  435. InputMethodManager im = (InputMethodManager) barcodeEdt.getContext()
  436. .getSystemService(Context.INPUT_METHOD_SERVICE);
  437. im.hideSoftInputFromWindow(barcodeEdt.getWindowToken(),
  438. InputMethodManager.HIDE_NOT_ALWAYS);
  439. if (mHandler != null) {
  440. mHandler.removeCallbacksAndMessages(null);
  441. mHandler.getLooper().quit();
  442. }
  443. } else {
  444. if (mHandler != null) {
  445. mHandler.removeCallbacksAndMessages(null);
  446. mHandler.getLooper().quit();
  447. }
  448. CommonUtil.setDefault(Notification.DEFAULT_VIBRATE, getApplicationContext());
  449. CommonUtil.showBarCodeAlertDialog(status, message, ProductPathActivity.this, barcodeEdt, null,
  450. null);
  451. }
  452. }
  453. catch (Exception e) {
  454. e.printStackTrace();
  455. }
  456. break;
  457. case 1:
  458. ProcessDialogUtils.closeProgressDilog();
  459. if (mHandler != null) {
  460. mHandler.removeCallbacksAndMessages(null);
  461. mHandler.getLooper().quit();
  462. }
  463. barcodeEdt.setEnabled(true);
  464. barcodeEdt.setText("");
  465. barcodeEdt.setFocusable(true);
  466. barcodeEdt.setFocusableInTouchMode(true);
  467. barcodeEdt.requestFocus();
  468. barcodeEdt.findFocus();
  469. barcodeEdt.setFilters(new InputFilter[] { new InputFilter() {
  470. @Override
  471. public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
  472. int dend) {
  473. return null;
  474. }
  475. } });
  476. //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
  477. Bundle b1 = msg.getData();
  478. String message = b1.getString("message");
  479. CustomToast.showToast(getApplicationContext(), message, 2000);
  480. break;
  481. }
  482. }
  483. };
  484. Runnable BarcodeUpperCase = new Runnable() {
  485. @Override
  486. public void run() {
  487. // 小写转大写
  488. barcodeEdt.setText(barcodeUpper.toUpperCase());
  489. // 设置EditText光标位置
  490. barcodeEdt.setSelection(barcodeUpper.length());
  491. }
  492. };
  493. private class BarcodeRunnable implements Runnable {
  494. private Object obj;
  495. public BarcodeRunnable(Object obj) {
  496. this.obj = obj;
  497. }
  498. @Override
  499. public void run() {
  500. synchronized (obj) {
  501. try {
  502. client = new WebClient();
  503. JSONObject js = new JSONObject();
  504. js.put("accountCode", accountCode);
  505. js.put("userCode", productPath_userCode);
  506. js.put("userPassword", userPassword);
  507. js.put("sessionKey", sessionKey);
  508. js.put("barcode", barcode);
  509. String result = client.doPost("http://" + ServerAddress_ip + ":" + ServerAddress_duankou
  510. + Constants.StatisticsProductTrack, js.toString(), "application/json");
  511. Message m = new Message();
  512. m.what = 0;
  513. Bundle b = new Bundle();
  514. b.putString("barcodeResult", result);
  515. m.setData(b);
  516. h.sendMessage(m);
  517. } catch (Exception e) {
  518. e.printStackTrace();
  519. Message m = new Message();
  520. m.what = 1;
  521. Bundle b = new Bundle();
  522. b.putString("message", "网络连接异常");
  523. m.setData(b);
  524. h.sendMessage(m);
  525. }
  526. }
  527. }
  528. };
  529. @Override
  530. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  531. if (requestCode == 102 && resultCode == RESULT_OK) {
  532. Bundle bundle = data.getExtras();
  533. String scanResult = bundle.getString("result");
  534. View rootview = this.getWindow().getDecorView();
  535. EditText v = (EditText) rootview.findFocus();
  536. int id = v.getId();
  537. v.setText(scanResult);
  538. v.setSelection(scanResult.length());
  539. switch (id) {
  540. case R.id.etbarcode:
  541. barcode = v.getText().toString();
  542. ProcessDialogUtils.showProcessDialog(ProductPathActivity.this);
  543. if (!CommonUtil.isNumber(barcode)) {
  544. ProcessDialogUtils.closeProgressDilog();
  545. CommonUtil.showRepeatDialog(barcode + "格式不匹配", ProductPathActivity.this);
  546. barcodeEdt.setText("");
  547. barcodeEdt.setFocusable(true);
  548. barcodeEdt.requestFocus();
  549. return;
  550. }
  551. barcodeEdt.setEnabled(false);
  552. barcodeEdt.setFocusable(false);
  553. barcodeEdt.setFilters(new InputFilter[] { new InputFilter() {
  554. @Override
  555. public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
  556. int dend) {
  557. return source.length() < 1 ? dest.subSequence(dstart, dend) : "";
  558. }
  559. } });
  560. if(barcode.substring(0, 4).equals("http"))
  561. {
  562. String[] parts = barcode.split("-", 2); // 第二个参数限制分割后的数组长度,这里为2
  563. if (parts.length == 2) {
  564. //System.out.println("第一部分: " + parts[0]);
  565. //System.out.println("第二部分: " + parts[1]);
  566. barcode = parts[1];
  567. }
  568. }
  569. thread = null;
  570. thread = new HandlerThread("BarCoderThread", 5);
  571. thread.start();
  572. mHandler = null;
  573. mHandler = new Handler(thread.getLooper());
  574. BarcodeRunnable barcodeRunnable = new BarcodeRunnable(obj);
  575. mHandler.post(barcodeRunnable);
  576. break;
  577. }
  578. }
  579. }
  580. @Override
  581. public Resources getResources() {
  582. Resources res = super.getResources();
  583. Configuration config = new Configuration();
  584. config.setToDefaults();
  585. res.updateConfiguration(config, res.getDisplayMetrics());
  586. return res;
  587. }
  588. }