| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660 |
- package com.jiaju.activity;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import org.json.JSONArray;
- import org.json.JSONObject;
- import com.jiaju.net.WebClient;
- import com.jiaju.utils.CommonUtil;
- import com.jiaju.utils.Constants;
- import com.jiaju.utils.CustomToast;
- import com.jiaju.utils.ProcessDialogUtils;
- import com.jiaju.widget.DefectCommonPopMenu;
- import android.app.Activity;
- import android.app.Notification;
- import android.content.Context;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.content.res.Configuration;
- import android.content.res.Resources;
- import android.os.Bundle;
- import android.os.Handler;
- import android.os.HandlerThread;
- import android.os.Message;
- import android.text.Editable;
- import android.text.InputFilter;
- import android.text.InputType;
- import android.text.Spanned;
- import android.text.TextUtils;
- import android.text.TextWatcher;
- import android.view.Gravity;
- import android.view.KeyEvent;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.inputmethod.EditorInfo;
- import android.view.inputmethod.InputMethodManager;
- import android.widget.EditText;
- import android.widget.ImageButton;
- import android.widget.ImageView;
- import android.widget.LinearLayout;
- import android.widget.ListView;
- import android.widget.PopupWindow;
- import android.widget.SimpleAdapter;
- import android.widget.TextView;
- import android.widget.TextView.OnEditorActionListener;
- import android.widget.Toast;
- public class ProductPathActivity extends Activity {
- private EditText barcodeEdt;// 条码
- private TextView productcode;// 产品编码
- private TextView modelcode;// 模具编码
- private TextView groutingcount;// 注浆次数
- private TextView state;// 产品状态
- private TextView title;
- private TextView back;
- private String barcode;
- private ImageButton leftBtn;
- private ListView listw;
- private int collectType;// 采集类型:1-单点 2-集中
- private int proId;// 工序I
- private WebClient client;
- private String model;
- private String FILE = "user";// 用于保存SharedPreferences的文件
- private String accountCode = "";// 帐套
- private String userPassword = "";// 用户密码
- private String sessionKey = "";// sessionKey,每次登陆都会改变
- private String productPath_userCode;// 生产工号Code
- private SharedPreferences sp;
- private String ServerAddress_ip, ServerAddress_duankou;
- private Message message;
- private String result = null;
- private JSONObject jsonObject;
- private TextView Bcode;
- private HandlerThread thread;
- private Handler mHandler = null;
- private SimpleAdapter simpleAdapter;
- private ImageView productRecord;
- private LinearLayout parent;
- private PopupWindow mPopupWindow; // 弹出框
- private TextView productType;
- private TextView glazeColorType;
- private TextView groutingLineCode;
- private TextView groutingWorkNo;
- private TextView groutingDate;
- private TextView goodsLevel;
- private TextView trademark;
- private TextView tvMaterialCode;
- private TextView tvOutLabelCode;
- private Handler barcodeUpperH = new Handler();
- private String barcodeUpper;
- private Object obj = new Object();
- List<HashMap<String, Object>> listItem;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_product_path);
- sp = getSharedPreferences(FILE, MODE_PRIVATE);
- accountCode = sp.getString("AccountCode", "");
- productPath_userCode = sp.getString("UserCode", "");
- userPassword = sp.getString("UserPassword", "");
- sessionKey = sp.getString("SessionKey", "");
- // 获取服务ip和端口号
- ServerAddress_ip = sp.getString("ServerAddress_ip", "");
- ServerAddress_duankou = sp.getString("ServerAddress_duankou", "");
- SysApplication.getInstance().addActivity(this);
- listItem = new ArrayList<HashMap<String, Object>>();
- initview();
- //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
- title.setText("产品跟踪");
- title.setTextSize(24);
- alllistener();
- }
- private void initview() {
- barcodeEdt = (EditText)findViewById(R.id.etbarcode);
- barcodeEdt.setRawInputType(InputType.TYPE_CLASS_NUMBER);
- Bcode = (TextView) findViewById(R.id.textV);
- productType = (TextView)findViewById(R.id.productType);
- productcode = (TextView) findViewById(R.id.textV1);
- tvMaterialCode=(TextView) findViewById(R.id.tvMaterialCode);
- tvOutLabelCode=(TextView) findViewById(R.id.tvOutLabelCode);
- glazeColorType = (TextView)findViewById(R.id.glazeColorType);
- groutingLineCode = (TextView) findViewById(R.id.groutingLineCode);
- groutingWorkNo = (TextView)findViewById(R.id.groutingWorkNo);
- groutingDate = (TextView) findViewById(R.id.groutingDate);
- goodsLevel = (TextView)findViewById(R.id.goodsLevel);
- modelcode = (TextView) findViewById(R.id.textV3);
- groutingcount = (TextView) findViewById(R.id.textV4);
- state = (TextView) findViewById(R.id.textV5);
- listw = (ListView) findViewById(R.id.listvw_path);
- title = (TextView) findViewById(R.id.title);
- trademark = (TextView) findViewById(R.id.trademark);
- back = (TextView) findViewById(R.id.back);
- leftBtn = (ImageButton) findViewById(R.id.left_img);
- productRecord = (ImageView) findViewById(R.id.search);
- productRecord.setVisibility(View.VISIBLE);
- parent = (LinearLayout) findViewById(R.id.parentRel);
-
-
- }
- private void alllistener() {
- leftBtn.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- finish();
- }
- });
- productRecord.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- int height = parent.getHeight() - v.getHeight();
- DefectCommonPopMenu recordPopMenu = new DefectCommonPopMenu(ProductPathActivity.this, height);
- mPopupWindow = recordPopMenu.getMenu();
- if (mPopupWindow == null) {
- return;
- }
- if (mPopupWindow.isShowing()) {
- mPopupWindow.dismiss();
- return;
- }
- mPopupWindow.showAtLocation(parent, Gravity.BOTTOM, 0, 0);
- LinearLayout scanLay = (LinearLayout) recordPopMenu.menu.findViewById(R.id.scanlay);
- ImageView scanImg = (ImageView) recordPopMenu.menu.findViewById(R.id.scanimg);
- TextView scanTitle = (TextView) recordPopMenu.menu.findViewById(R.id.scantitle);
- scanTitle.setText("扫一扫");
- scanImg.setBackgroundResource(R.drawable.scan);
- scanLay.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent openCameraIntent = new Intent(ProductPathActivity.this, CaptureActivity.class);
- startActivityForResult(openCameraIntent, 102);
- if (mPopupWindow.isShowing()) {
- mPopupWindow.dismiss();
- }
- }
- });
- }
- });
- back.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- finish();
- }
- });
- barcodeEdt.setOnEditorActionListener(new OnEditorActionListener() {
-
- @Override
- public boolean onEditorAction(TextView v, int actionId,
- KeyEvent event) {
- if (actionId == EditorInfo.IME_ACTION_GO) {
- barcode = barcodeEdt.getText().toString().trim();
- ProcessDialogUtils.showProcessDialog(ProductPathActivity.this);
- Bcode.setText("");
- productType.setText("");
- productcode.setText("");
- glazeColorType.setText("");
- groutingLineCode.setText("");
- groutingDate.setText("");
- groutingWorkNo.setText("");
- modelcode.setText("");
- goodsLevel.setText("");
- trademark.setText("");
- tvMaterialCode.setText("");
- tvOutLabelCode.setText("");
- groutingcount.setText("");
- state.setText("");
- if(simpleAdapter!=null){
- listItem.clear();
- simpleAdapter.notifyDataSetChanged();
- }
-
- barcodeEdt.setEnabled(false);
- barcodeEdt.setFocusable(false);
- barcodeEdt.setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(CharSequence source,
- int start, int end, Spanned dest, int dstart,
- int dend) {
-
- return source.length() < 1 ? dest.subSequence(dstart, dend): "";
- }
- } });
- if(barcode.substring(0, 4).equals("http"))
- {
- String[] parts = barcode.split("-", 2); // 第二个参数限制分割后的数组长度,这里为2
-
- if (parts.length == 2) {
- //System.out.println("第一部分: " + parts[0]);
- //System.out.println("第二部分: " + parts[1]);
- barcode = parts[1];
- }
- }
- thread = null;
- thread = new HandlerThread("BarCoderThread", 5);
- thread.start();
- mHandler = null;
- mHandler = new Handler(thread.getLooper());
- BarcodeRunnable barcodeRunnable=new BarcodeRunnable(obj);
- mHandler.post(barcodeRunnable);
- return true;
- }
-
- return false;
- }
- });
-
-
- barcodeEdt.addTextChangedListener(new TextWatcher() {
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- barcodeUpper = barcodeEdt.getText().toString().trim();
- // 判断输入的文字是否是小写
- for (int i = 0; i < barcodeUpper.length(); i++) {
- if (barcodeUpper.charAt(i) - 0 >= 97 && barcodeUpper.charAt(i) - 0 <= 122) {
- barcodeUpperH.postDelayed(BarcodeUpperCase, 300);
- }
- }
-
- if(start==0&&before==0&&count>1) {
- barcode = barcodeEdt.getText().toString().trim();
- ProcessDialogUtils.showProcessDialog(ProductPathActivity.this);
- Bcode.setText("");
- productType.setText("");
- productcode.setText("");
- glazeColorType.setText("");
- groutingLineCode.setText("");
- groutingDate.setText("");
- groutingWorkNo.setText("");
- modelcode.setText("");
- goodsLevel.setText("");
- trademark.setText("");
- groutingcount.setText("");
- tvMaterialCode.setText("");
- tvOutLabelCode.setText("");
- state.setText("");
- if(simpleAdapter!=null){
- listItem.clear();
- simpleAdapter.notifyDataSetChanged();
- }
- barcodeEdt.setEnabled(false);
- barcodeEdt.setFocusable(false);
- barcodeEdt.setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
- int dend) {
- return source.length() < 1 ? dest.subSequence(dstart, dend) : "";
- }
- } });
- if(barcode.substring(0, 4).equals("http"))
- {
- String[] parts = barcode.split("-", 2); // 第二个参数限制分割后的数组长度,这里为2
-
- if (parts.length == 2) {
- //System.out.println("第一部分: " + parts[0]);
- //System.out.println("第二部分: " + parts[1]);
- barcode = parts[1];
- }
- }
- thread = null;
- thread = new HandlerThread("BarCoderThread", 5);
- thread.start();
- mHandler = null;
- mHandler = new Handler(thread.getLooper());
- BarcodeRunnable barcodeRunnable = new BarcodeRunnable(obj);
- mHandler.post(barcodeRunnable);
- }
- }
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
- @Override
- public void afterTextChanged(Editable s) {
- }
- });
- }
- Handler h = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- super.handleMessage(msg);
- switch (msg.what) {
- case 0:
- Bundle b;
- b = msg.getData();
- String json = b.getString("barcodeResult");
- ProcessDialogUtils.closeProgressDilog();
- try {
-
- JSONObject j = new JSONObject(json);
- JSONObject jobj = (JSONObject) j.opt("d");
- int status = jobj.optInt("Status");
- String message = jobj.optString("Message");
- if (status == 0) {
- String Result = jobj.getString("Result");
- JSONObject object1 = new JSONObject(Result);
- JSONArray array1 = object1.optJSONArray("Table");
- if (array1 != null && array1.length() > 0) {
- JSONObject jo1 = array1.optJSONObject(0);
- String barcode = jo1.optString("BARCODE");
- Bcode.setText(barcode);
- String goodsType = jo1.optString("GOODSTYPENAME");
- productType.setText(goodsType);
- String goodsCode = jo1.optString("GOODSCODE");
-
- int groutingBatchNo=jo1.optInt("GROUTINGBATCHNO");
-
- String goodsSpecification = jo1.optString("GOODSSPECIFICATION");
- if (!goodsSpecification.equals("null")) {
- productcode.setText(goodsCode+"["+goodsSpecification+"]");
- } else {
- productcode.setText(goodsCode);
- }
- String trademarkName = jo1.optString("LOGOCODENAME");
- if (!trademark.equals("null")) {
- trademark.setText(trademarkName);
- } else {
- trademark.setText("");
- }
-
- String materialCode=jo1.optString("MATERIALCODE");
- String outLabelCode=jo1.optString("OUTLABELCODE");
- if(outLabelCode.equals("null")) {
- outLabelCode="";
- }
- tvMaterialCode.setText(materialCode);
- tvOutLabelCode.setText(outLabelCode);
- String glazecolorType = jo1.optString("DICTIONARYVALUE");
- glazeColorType.setText(glazecolorType);
- String groutingCode = jo1.optString("GROUTINGLINECODE");
- groutingLineCode.setText(groutingCode);
- String mouldcode = jo1.optString("GROUTINGMOULDCODE");
- modelcode.setText(mouldcode);
- int groutingNum = jo1.optInt("GROUTINGNUM");
- groutingcount.setText(groutingNum + "");
- String groutingUserCode = jo1.optString("GROUTINGUSERCODE");
- groutingWorkNo.setText(groutingUserCode);
- String date = jo1.optString("GROUTINGDATE");
- if (!date.equals("null")) {
- if (date.contains("/")) {
- date = CommonUtil.dateStringConverter(date);
- } else if (date.contains("-")) {
- date = CommonUtil.commonDateConverter(date);
- }
- groutingDate.setText(date+" ("+groutingBatchNo+")");
-
- } else {
- groutingDate.setText("("+groutingBatchNo+")");
-
- }
- String statusName = jo1.optString("STATUSNAME");
- state.setText(statusName);
- String level = jo1.optString("LEVELNAME");
- if (!level.equals("null")) {
- goodsLevel.setText(level);
- } else {
- goodsLevel.setText("");
- }
- }
- JSONArray array2 = object1.optJSONArray("Table1");
- if (array2 != null && array2.length() > 0) {
- for (int i = 0; i < array2.length(); i++) {
- JSONObject j2 = array2.optJSONObject(i);
- String productLineName = j2.optString("PRODUCTIONLINENAME");
- String procedureName = j2.optString("PROCEDURENAME");
- String userCode = j2.optString("USERCODE");
- String operationTime = j2.optString("CREATETIME");
- String operator = j2.optString("CREATEUSERNAME");
- String goodsLevelName = j2.optString("GOODSLEVELNAME");
- HashMap<String, Object> map1 = new HashMap<String, Object>();
- if (productLineName.equals("null")) {
- map1.put("ProductLineName", "");
- } else {
- map1.put("ProductLineName", productLineName);
- }
- if (!procedureName.equals("null")) {
- map1.put("ProcedureName", procedureName);
- } else {
- map1.put("ProcedureName", "");
- }
- map1.put("UserCode", userCode);
- map1.put("OperationTime", operationTime);
- map1.put("Operator", operator);
- if (!goodsLevelName.equals("null")) {
- map1.put("GoodsLevelName", goodsLevelName);
- } else {
- map1.put("GoodsLevelName", "");
- }
- listItem.add(map1);
- }
- if (simpleAdapter == null) {
- simpleAdapter = new SimpleAdapter(ProductPathActivity.this, listItem,
- R.layout.path_item,
- new String[] { "ProductLineName", "ProcedureName", "UserCode", "OperationTime",
- "Operator", "GoodsLevelName" },
- new int[] { R.id.productlineName, R.id.procedureName, R.id.workno,
- R.id.operationTime, R.id.operator, R.id.operationDesc });
- listw.setAdapter(simpleAdapter);
- } else {
- simpleAdapter.notifyDataSetChanged();
- }
- }
- barcodeEdt.setEnabled(true);
- barcodeEdt.setText("");
- barcodeEdt.setFocusable(true);
- barcodeEdt.setFocusableInTouchMode(true);
- barcodeEdt.requestFocus();
- barcodeEdt.findFocus();
- barcodeEdt.setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
- int dstart, int dend) {
- return null;
- }
- } });
- //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
- InputMethodManager im = (InputMethodManager) barcodeEdt.getContext()
- .getSystemService(Context.INPUT_METHOD_SERVICE);
- im.hideSoftInputFromWindow(barcodeEdt.getWindowToken(),
- InputMethodManager.HIDE_NOT_ALWAYS);
- if (mHandler != null) {
- mHandler.removeCallbacksAndMessages(null);
- mHandler.getLooper().quit();
- }
- } else {
- if (mHandler != null) {
- mHandler.removeCallbacksAndMessages(null);
- mHandler.getLooper().quit();
- }
- CommonUtil.setDefault(Notification.DEFAULT_VIBRATE, getApplicationContext());
- CommonUtil.showBarCodeAlertDialog(status, message, ProductPathActivity.this, barcodeEdt, null,
- null);
- }
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- break;
- case 1:
- ProcessDialogUtils.closeProgressDilog();
- if (mHandler != null) {
- mHandler.removeCallbacksAndMessages(null);
- mHandler.getLooper().quit();
- }
-
- barcodeEdt.setEnabled(true);
- barcodeEdt.setText("");
- barcodeEdt.setFocusable(true);
- barcodeEdt.setFocusableInTouchMode(true);
- barcodeEdt.requestFocus();
- barcodeEdt.findFocus();
- barcodeEdt.setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
- int dend) {
- return null;
- }
- } });
- //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
- Bundle b1 = msg.getData();
- String message = b1.getString("message");
- CustomToast.showToast(getApplicationContext(), message, 2000);
- break;
- }
- }
- };
- Runnable BarcodeUpperCase = new Runnable() {
- @Override
- public void run() {
- // 小写转大写
- barcodeEdt.setText(barcodeUpper.toUpperCase());
- // 设置EditText光标位置
- barcodeEdt.setSelection(barcodeUpper.length());
- }
- };
- private class BarcodeRunnable implements Runnable {
- private Object obj;
- public BarcodeRunnable(Object obj) {
- this.obj = obj;
- }
- @Override
- public void run() {
- synchronized (obj) {
- try {
- client = new WebClient();
- JSONObject js = new JSONObject();
- js.put("accountCode", accountCode);
- js.put("userCode", productPath_userCode);
- js.put("userPassword", userPassword);
- js.put("sessionKey", sessionKey);
- js.put("barcode", barcode);
- String result = client.doPost("http://" + ServerAddress_ip + ":" + ServerAddress_duankou
- + Constants.StatisticsProductTrack, js.toString(), "application/json");
- Message m = new Message();
- m.what = 0;
- Bundle b = new Bundle();
- b.putString("barcodeResult", result);
- m.setData(b);
- h.sendMessage(m);
- } catch (Exception e) {
- e.printStackTrace();
- Message m = new Message();
- m.what = 1;
- Bundle b = new Bundle();
- b.putString("message", "网络连接异常");
- m.setData(b);
- h.sendMessage(m);
- }
- }
- }
- };
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (requestCode == 102 && resultCode == RESULT_OK) {
- Bundle bundle = data.getExtras();
- String scanResult = bundle.getString("result");
- View rootview = this.getWindow().getDecorView();
- EditText v = (EditText) rootview.findFocus();
- int id = v.getId();
- v.setText(scanResult);
- v.setSelection(scanResult.length());
- switch (id) {
- case R.id.etbarcode:
- barcode = v.getText().toString();
- ProcessDialogUtils.showProcessDialog(ProductPathActivity.this);
- if (!CommonUtil.isNumber(barcode)) {
- ProcessDialogUtils.closeProgressDilog();
- CommonUtil.showRepeatDialog(barcode + "格式不匹配", ProductPathActivity.this);
- barcodeEdt.setText("");
- barcodeEdt.setFocusable(true);
- barcodeEdt.requestFocus();
- return;
- }
- barcodeEdt.setEnabled(false);
- barcodeEdt.setFocusable(false);
- barcodeEdt.setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
- int dend) {
- return source.length() < 1 ? dest.subSequence(dstart, dend) : "";
- }
- } });
- if(barcode.substring(0, 4).equals("http"))
- {
- String[] parts = barcode.split("-", 2); // 第二个参数限制分割后的数组长度,这里为2
-
- if (parts.length == 2) {
- //System.out.println("第一部分: " + parts[0]);
- //System.out.println("第二部分: " + parts[1]);
- barcode = parts[1];
- }
- }
- thread = null;
- thread = new HandlerThread("BarCoderThread", 5);
- thread.start();
- mHandler = null;
- mHandler = new Handler(thread.getLooper());
- BarcodeRunnable barcodeRunnable = new BarcodeRunnable(obj);
- mHandler.post(barcodeRunnable);
- break;
- }
- }
- }
- @Override
- public Resources getResources() {
- Resources res = super.getResources();
- Configuration config = new Configuration();
- config.setToDefaults();
- res.updateConfiguration(config, res.getDisplayMetrics());
- return res;
- }
- }
|