| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627 |
- package com.jiaju.activity;
- import java.util.ArrayList;
- import java.util.List;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import com.jiaju.adapter.CancelFinishedProductHandOverAdapter;
- import com.jiaju.model.BarcodeInfo;
- import com.jiaju.net.WebClient;
- import com.jiaju.utils.CommonUtil;
- import com.jiaju.utils.Constants;
- import com.jiaju.utils.ProcessDialogUtils;
- import com.jiaju.utils.Removeduplicate;
- import android.app.Activity;
- import android.app.Notification;
- import android.content.Context;
- import android.content.SharedPreferences;
- 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.KeyEvent;
- import android.view.Menu;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.inputmethod.EditorInfo;
- import android.view.inputmethod.InputMethodManager;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.ImageButton;
- import android.widget.ListView;
- import android.widget.TextView;
- import android.widget.Toast;
- //裸辞交接 撤销
- public class LuociRevokeActivity extends Activity {
- private TextView title;
- private EditText barcodeEdt;
- private String accountCode;
- private String cancelPacking_userCode;
- private String password;
- private String sessionkey;
- private SharedPreferences preferences;
- private String ServerAddress_ip;
- private String ServerAddress_duankou;
- private HandlerThread thread;
- private Handler mHandler;
- private WebClient client = null;
- private TextView backtext;
- private ImageButton backbtn;
- private Object obj = new Object();
- private List<BarcodeInfo> barcodeList;
- private CancelFinishedProductHandOverAdapter adapter = null;
- private ListView cancellstview;
- private Button saveBtn;
- private String procedureName;
- private Handler barcodeUpperH = new Handler();
- private String barcodeUpper;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_cancel_finished_product_hand_over);
- initView();
- preferences = getSharedPreferences("user", Context.MODE_PRIVATE);
- ServerAddress_ip = preferences.getString("ServerAddress_ip", "");
- ServerAddress_duankou = preferences.getString("ServerAddress_duankou",
- "");
- accountCode = preferences.getString("AccountCode", "");
- cancelPacking_userCode = preferences.getString("UserCode", "");
- password = preferences.getString("UserPassword", "");
- sessionkey = preferences.getString("SessionKey", "");
- Bundle b = getIntent().getExtras();
- procedureName = b.getString("title");
- title.setText(procedureName);
- CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
- barcodeList = new ArrayList<BarcodeInfo>();
- allListeners();
- }
- public void initView() {
- title = (TextView) findViewById(R.id.title);
- barcodeEdt = (EditText) findViewById(R.id.barcodeEdt);
- barcodeEdt.setRawInputType(InputType.TYPE_CLASS_NUMBER);
- backbtn = (ImageButton) findViewById(R.id.left_img);
- backtext = (TextView) findViewById(R.id.back);
- cancellstview = (ListView) findViewById(R.id.cancel_listview);
- saveBtn = (Button) findViewById(R.id.saveBtn);
- }
- public void allListeners() {
- saveBtn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if (barcodeList == null) {
- Toast.makeText(getApplicationContext(), "条码信息不能为空",
- Toast.LENGTH_SHORT).show();
- return;
- } else {
- if (barcodeList.size() == 0) {
- Toast.makeText(getApplicationContext(), "条码信息不能为空",
- Toast.LENGTH_SHORT).show();
- return;
- }
- BarcodeInfo info = barcodeList.get(0);
- String barcode = info.getBarcode();
- ProcessDialogUtils.showProcessDialog(
- LuociRevokeActivity.this);
- if (saveBtn.isEnabled()) {
- saveBtn.setEnabled(false);
- thread = new HandlerThread("saveThread", 5);
- thread.start();
- mHandler = new Handler(thread.getLooper());
- SaveRunnable saveRunnable = new SaveRunnable(barcode,
- obj);
- mHandler.post(saveRunnable);
- }
- }
- }
- });
- backtext.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- finish();
- }
- });
- backbtn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- finish();
- }
- });
- barcodeEdt.addTextChangedListener(new TextWatcher() {
- @Override
- public void afterTextChanged(Editable arg0) {
- }
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count,
- int after) {
- }
- @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(UpperCase, 300);
- }
- }
- if (start == 0 && before == 0 && count > 1) {
- String barcode = barcodeEdt.getText().toString().trim();
- if (!TextUtils.isEmpty(barcode)) {
- if (barcodeList.size() > 0) {
- boolean b = Removeduplicate.removeBarCode(barcode,
- barcodeList);
- if (b) {
- barcodeEdt.setText("");
- barcodeEdt.setFocusable(true);
- barcodeEdt.requestFocus();
- CommonUtil.setDefault(
- Notification.DEFAULT_VIBRATE,
- getApplicationContext());
- Toast.makeText(getApplicationContext(),
- "条码" + barcode + "重复",
- Toast.LENGTH_SHORT).show();
- return;
- }
- }
- if (barcodeList != null && barcodeList.size() > 0) {
- barcodeList.removeAll(barcodeList);
- if (adapter != null) {
- adapter.notifyDataSetChanged();
- }
- }
- ProcessDialogUtils.showProcessDialog(
- LuociRevokeActivity.this);
- 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)
- : "";
- }
- }});
- thread = new HandlerThread("barcodeThread", 5);
- thread.start();
- mHandler = new Handler(thread.getLooper());
- BarcodeRunnable barcodeRunnable = new BarcodeRunnable(
- barcode, obj);
- mHandler.post(barcodeRunnable);
- }
- }
- }
- });
- barcodeEdt.setOnEditorActionListener(
- new TextView.OnEditorActionListener() {
- @Override
- public boolean onEditorAction(TextView v, int actionId,
- KeyEvent event) {
- if (actionId == EditorInfo.IME_ACTION_GO) {
- String barcode = barcodeEdt.getText().toString();
- if (!TextUtils.isEmpty(barcode)) {
- if (barcodeList.size() > 0) {
- boolean b = Removeduplicate.removeBarCode(
- barcode, barcodeList);
- if (b) {
- barcodeEdt.setText("");
- barcodeEdt.setFocusable(true);
- barcodeEdt.requestFocus();
- CommonUtil.setDefault(
- Notification.DEFAULT_VIBRATE,
- getApplicationContext());
- Toast.makeText(getApplicationContext(),
- "条码" + barcode + "重复",
- Toast.LENGTH_SHORT).show();
- return true;
- }
- }
- if (barcodeList != null
- && barcodeList.size() > 0) {
- barcodeList.removeAll(barcodeList);
- if (adapter != null) {
- adapter.notifyDataSetChanged();
- }
- }
- ProcessDialogUtils.showProcessDialog(
- LuociRevokeActivity.this);
- 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)
- : "";
- }
- }});
- thread = new HandlerThread("barcodeThread", 5);
- thread.start();
- mHandler = new Handler(thread.getLooper());
- BarcodeRunnable barcodeRunnable = new BarcodeRunnable(
- barcode, obj);
- mHandler.post(barcodeRunnable);
- return true;
- } else {
- Toast.makeText(getApplicationContext(),
- "产品条码不能为空", Toast.LENGTH_SHORT).show();
- return true;
- }
- }
- return false;
- }
- });
- }
- Runnable BarcodeUpperCase = new Runnable() {
- @Override
- public void run() {
- // 小写转大写
- barcodeEdt.setText(barcodeUpper.toUpperCase());
- // 设置EditText光标位置
- barcodeEdt.setSelection(barcodeUpper.length());
- }
- };
- Runnable UpperCase = new Runnable() {
- @Override
- public void run() {
- // 小写转大写
- barcodeEdt.setText(barcodeUpper.toUpperCase());
- // 设置EditText光标位置
- barcodeEdt.setSelection(barcodeUpper.length());
- }
- };
- Handler h = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case 0 :
- Bundle b1 = msg.getData();
- String json1 = b1.getString("barcodeResult");
- ProcessDialogUtils.closeProgressDilog();
- try {
- JSONObject jo2 = new JSONObject(json1);
- JSONObject jo3 = jo2.optJSONObject("d");
- int status = jo3.optInt("Status");
- String message = jo3.optString("Message");
- if (status == 0) {
- String result = jo3.optString("Result");
- JSONObject resultObj = new JSONObject(result);
- JSONArray jarray = resultObj.optJSONArray("Table");
- if (jarray != null && jarray.length() > 0) {
- for (int i = 0; i < jarray.length(); i++) {
- JSONObject jo = jarray.optJSONObject(i);
- String orderNo = jo.optString("ORDERNO");
- String goodsCode = jo
- .optString("GOODSCODE");
- String groutingUserCode = jo
- .optString("GROUTINGUSERCODE");
- int logoId = jo.optInt("LOGOID");
- String logoCode = jo.optString("LOGOCODE");
- String logoName = jo.optString("LOGONAME");
- String barcode = jo.optString("BARCODE");
- String finishedBarcode = jo
- .optString("FINISHEDBARCODE");
- String groutingDate = jo
- .optString("GROUTINGDATE");
- String billetDate = jo
- .optString("DELIVERTIME");
- String mouldCode = jo
- .optString("GROUTINGMOULDCODE");
- BarcodeInfo info = new BarcodeInfo();
- info.setBarcode(barcode);
- info.setFinishedBarCode(finishedBarcode);
- info.setOrderNo(orderNo);
- info.setGoodsCode(goodsCode);
- info.setUserCode(groutingUserCode);
- info.setLogoId(logoId);
- info.setLogoCode(logoCode);
- info.setLogoName(logoName);
- info.setBanMa(
- (jo.optString("BANMA") == "null")
- ? ""
- : jo.optString("BANMA"));
- if (!TextUtils.isEmpty(groutingDate)) {
- if (groutingDate.contains("/")) {
- groutingDate = CommonUtil
- .dateStringConverter(
- groutingDate);
- } else if (groutingDate.contains("-")) {
- groutingDate = CommonUtil
- .commonDateConverter(
- groutingDate);
- }
- info.setGroutingDate(groutingDate);
- } else {
- info.setGroutingDate("");
- }
- if (!TextUtils.isEmpty(billetDate)) {
- if (billetDate.contains("/")) {
- billetDate = CommonUtil
- .dateStringConverter(
- billetDate);
- } else if (billetDate.contains("-")) {
- billetDate = CommonUtil
- .commonDateConverter(
- billetDate);
- }
- info.setDeliverTime(billetDate);
- } else {
- info.setDeliverTime("");
- }
- info.setMouldCode(mouldCode);
- barcodeList.add(info);
- }
- adapter = new CancelFinishedProductHandOverAdapter(
- LuociRevokeActivity.this,
- barcodeList);
- cancellstview.setAdapter(adapter);
- saveBtn.setText(
- "保存(" + barcodeList.size() + ")");
- } else {
- Toast.makeText(getApplicationContext(),
- "此条码不存在", Toast.LENGTH_SHORT).show();
- }
- 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);
- } else {
- CommonUtil.setDefault(Notification.DEFAULT_VIBRATE,
- getApplicationContext());
- CommonUtil.showBarCodeAlertDialog(status, message,
- LuociRevokeActivity.this,
- barcodeEdt, null, null);
- }
- if (mHandler != null) {
- mHandler.removeCallbacksAndMessages(null);
- mHandler.getLooper().quit();
- }
- } catch (JSONException e1) {
- e1.printStackTrace();
- Toast.makeText(getApplicationContext(), "json数据异常",
- Toast.LENGTH_SHORT).show();
- }
- break;
- case 1 :
- Bundle b = msg.getData();
- String json = b.getString("saveResult");
- ProcessDialogUtils.closeProgressDilog();
- if (mHandler != null) {
- mHandler.removeCallbacksAndMessages(null);
- mHandler.getLooper().quit();
- }
- saveBtn.setEnabled(true);
- try {
- JSONObject jo = new JSONObject(json);
- JSONObject jo1 = jo.optJSONObject("d");
- int status = jo1.optInt("Status");
- String message = jo1.optString("Message");
- if (barcodeList != null && barcodeList.size() > 0) {
- barcodeList.removeAll(barcodeList);
- if (adapter != null) {
- adapter.notifyDataSetChanged();
- }
- }
- saveBtn.setText("保存(" + barcodeList.size() + ")");
- if (status == 0) {
- 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(
- LuociRevokeActivity.this
- .getCurrentFocus().getWindowToken(),
- InputMethodManager.HIDE_NOT_ALWAYS);
- Toast.makeText(getApplicationContext(), "上传成功",
- Toast.LENGTH_SHORT).show();
- CommonUtil.playSound(getApplicationContext());
- } else {
- CommonUtil.showBarCodeAlertDialog(status, message,
- LuociRevokeActivity.this,
- barcodeEdt, null, null);
- CommonUtil.setDefault(Notification.DEFAULT_VIBRATE,
- getApplicationContext());
- }
- } catch (JSONException e) {
- e.printStackTrace();
- Toast.makeText(getApplicationContext(), "json数据异常",
- Toast.LENGTH_SHORT).show();
- }
- break;
- }
- }
- };
- private Handler exceptionHandler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- super.handleMessage(msg);
- switch (msg.what) {
- case 0 :
- ProcessDialogUtils.closeProgressDilog();
- saveBtn.setEnabled(true);
- if (mHandler != null) {
- mHandler.removeCallbacksAndMessages(null);
- mHandler.getLooper().quit();
- }
- Bundle b = msg.getData();
- String message = b.getString("message");
- CommonUtil.setDefault(Notification.DEFAULT_VIBRATE,
- getApplicationContext());
- Toast.makeText(getApplicationContext(), message,
- Toast.LENGTH_SHORT).show();
- 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);
- break;
- }
- }
- };
- public class SaveRunnable implements Runnable {
- String barcode;
- Object obj;
- public SaveRunnable(String barcode, Object obj) {
- this.barcode = barcode;
- this.obj = obj;
- }
- @Override
- public void run() {
- synchronized (obj) {
- try {
- client = new WebClient();
- JSONObject js = new JSONObject();
- js.put("accountCode", accountCode);
- js.put("userCode", cancelPacking_userCode);
- js.put("userPassword", password);
- js.put("sessionKey", sessionkey);
- js.put("module", "LCFinishedProduct");
- js.put("action", "LCBackFinishedHandover");
- JSONArray barcodeArray = new JSONArray();
- for (int i = 0; i < barcodeList.size(); i++) {
- BarcodeInfo barcodeInfo = barcodeList.get(i);
- JSONObject jobj = new JSONObject();
- jobj.put("BarCode", barcodeInfo.getBarcode());
- jobj.put("GoodsModel", barcodeInfo.getGoodsCode());
- jobj.put("logoID", barcodeInfo.getLogoId());
- jobj.put("LogoName", barcodeInfo.getLogoName());
- barcodeArray.put(jobj);
- }
- JSONObject data = new JSONObject();
- data.put("Table", barcodeArray);
- js.put("jsonData", data.toString());
- String result = client.doPost(
- "http://" + ServerAddress_ip + ":"
- + ServerAddress_duankou
- + Constants.serverAction + "/DoAction",
- js.toString(), "application/json");
- Message m = new Message();
- m.what = 1;
- Bundle b = new Bundle();
- b.putString("saveResult", result);
- m.setData(b);
- h.sendMessage(m);
- } catch (Exception e) {
- e.printStackTrace();
- Message m = new Message();
- m.what = 0;
- Bundle b = new Bundle();
- b.putString("message", "网络连接异常");
- m.setData(b);
- exceptionHandler.sendMessage(m);
- return;
- }
- }
- }
- };
- public class BarcodeRunnable implements Runnable {
- String barcode;
- Object obj;
- public BarcodeRunnable(String barcode, Object obj) {
- this.barcode = barcode;
- this.obj = obj;
- }
- @Override
- public void run() {
- synchronized (obj) {
- try {
- client = new WebClient();
- JSONObject js = new JSONObject();
- js.put("accountCode", accountCode);
- js.put("userCode", cancelPacking_userCode);
- js.put("userPassword", password);
- js.put("sessionKey", sessionkey);
- js.put("module", "LCFinishedProduct");
- js.put("action", "LCBackFinishedHandoverCheck");
- JSONObject data = new JSONObject();
- data.put("Barcode", barcode);
- js.put("jsonData", data.toString());
- String result = client.doPost(
- "http://" + ServerAddress_ip + ":"
- + ServerAddress_duankou
- + Constants.serverAction + "/DoAction",
- 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 = 0;
- Bundle b = new Bundle();
- b.putString("message", "网络连接异常");
- m.setData(b);
- exceptionHandler.sendMessage(m);
- return;
- }
- }
- }
- };
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.cancel_packing, menu);
- return true;
- }
- }
|