| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853 |
- package com.uas.uaspda.fragment;
- import android.app.Activity;
- import android.content.ComponentName;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.graphics.drawable.BitmapDrawable;
- import android.net.Uri;
- import android.os.Build;
- import android.os.Bundle;
- import android.os.Handler;
- import android.os.Message;
- import android.support.v4.content.FileProvider;
- import android.text.Editable;
- import android.text.TextUtils;
- import android.text.TextWatcher;
- import android.util.Log;
- import android.view.Gravity;
- import android.view.KeyEvent;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.view.inputmethod.EditorInfo;
- import android.widget.ArrayAdapter;
- import android.widget.Button;
- import android.widget.ImageView;
- import android.widget.LinearLayout;
- import android.widget.ListView;
- import android.widget.PopupWindow;
- import android.widget.TextView;
- import android.widget.Toast;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.android.volley.AuthFailureError;
- import com.android.volley.Request;
- import com.android.volley.RequestQueue;
- import com.android.volley.Response;
- import com.android.volley.VolleyError;
- import com.android.volley.toolbox.JsonObjectRequest;
- import com.android.volley.toolbox.StringRequest;
- import com.android.volley.toolbox.Volley;
- import com.google.gson.Gson;
- import com.uas.uaspda.R;
- import com.uas.uaspda.activity.FunctionActivity;
- import com.uas.uaspda.bean.WHBreakingBatchBreakingBtnClickEvent;
- import com.uas.uaspda.bean.WHBreakingBatchGetBarcodeData;
- import com.uas.uaspda.global.GloableParams;
- import com.uas.uaspda.tools.SharedPreUtil;
- import com.uas.uaspda.tools.VolleyUtil;
- import com.uas.uaspda.util.CameraUtil;
- import com.uas.uaspda.util.CommonUtil;
- import com.uas.uaspda.util.Constants;
- import com.uas.uaspda.util.FileUtils;
- import com.uas.uaspda.util.FragmentUtils;
- import com.uas.uaspda.util.JsonTools;
- import com.uas.uaspda.util.JsonUtils;
- import com.uas.uaspda.util.LogUtil;
- import com.uas.uaspda.util.PrintUtils;
- import com.uas.uaspda.view.ClearableEditText;
- import com.uuzuche.lib_zxing.activity.CaptureActivity;
- import com.uuzuche.lib_zxing.activity.CodeUtils;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.io.File;
- import java.io.IOException;
- import java.io.UnsupportedEncodingException;
- import java.net.URLEncoder;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- import java.util.concurrent.TimeUnit;
- import okhttp3.Call;
- import okhttp3.Callback;
- import okhttp3.FormBody;
- import okhttp3.OkHttpClient;
- import okhttp3.RequestBody;
- /**
- * @note:分拆批次
- */
- public class WHBreakingBatchFragment extends BaseFragment implements View.OnClickListener, View.OnFocusChangeListener {
- public static final String TAG = "barcodeEnterEvent";
- private static final int SCAN_BARCODE_CODE = 102;
- private final int SPLIT_BARCODE_FAIL = 0x11;
- private final int SPLIT_BARCODE_SUCCESS = 0x12;
- private View popView;
- private PopupWindow pop;
- private Button btnBreaking, btnBack, btnPrintf, btnClose, btnPrintfSet;
- private ImageView mScanImageView;
- private ClearableEditText etOrBarcode, etBarRemain;
- private StringRequest stringRequest, stringRequest3;
- private RequestQueue mRequestQueue;
- private TextView tvOrRemain;
- private List<WHBreakingBatchBreakingBtnClickEvent.DataBean> messages = new ArrayList<>();
- private ListView listView;
- private MyAdapter adapter;
- private String strPrintDataList;
- private JsonObjectRequest jsonRequest;
- private String mPrintUrl = "";
- private okhttp3.Request mRequest;
- private OkHttpClient mOkHttpClient;
- private boolean isConnected = false;
- private String mOldAddress = "";
- private int mPrintDpi = 203;
- private Handler mHandler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- super.handleMessage(msg);
- switch (msg.what) {
- case Constants.CONSTANT.PRINT_SUCCESS:
- if (progressDialog.isShowing())
- progressDialog.dismiss();
- closePopupWindow();
- Toast.makeText(mActivity, R.string.obtain_print_file_success, Toast.LENGTH_LONG).show();
- try {
- Intent intent = new Intent();
- ComponentName comp = new ComponentName("com.dynamixsoftware.printershare", "com.dynamixsoftware.printershare.ActivityPrintPDF");
- intent = new Intent();
- intent.setComponent(comp);
- intent.setAction("android.intent.action.VIEW");
- intent.setType("application/pdf");
- intent.setData(Uri.fromFile(new File(Constants.CONSTANT.PRINT_FILE_PATH, Constants.CONSTANT.PRINT_FILE_NAME)));
- startActivity(intent);
- } catch (Exception e) {
- Toast.makeText(mActivity, "打印失败", Toast.LENGTH_LONG).show();
- e.printStackTrace();
- }
- break;
- case Constants.CONSTANT.PRINT_FAILED:
- if (progressDialog.isShowing())
- progressDialog.dismiss();
- Toast.makeText(mActivity, R.string.obtain_print_file_failed, Toast.LENGTH_LONG).show();
- break;
- case Constants.CONSTANT.PRINT_OVERLOAD:
- if (progressDialog.isShowing())
- progressDialog.dismiss();
- Toast.makeText(mActivity, R.string.obtain_print_file_overload, Toast.LENGTH_LONG).show();
- break;
- case SPLIT_BARCODE_SUCCESS:
- try {
- String s = (String) msg.obj;
- WHBreakingBatchBreakingBtnClickEvent wh = JsonTools.parseJsonToBean(s, WHBreakingBatchBreakingBtnClickEvent.class);
- if (wh.getData() != null) {
- for (int i = 0; i < wh.getData().size(); i++) {
- messages.add(wh.getData().get(i));
- }
- }
- strPrintDataList = new Gson().toJson(messages);
- //打开popupWindow;
- initPopupWindow(s);
- reset();
- } catch (Exception e) {
- }
- break;
- case SPLIT_BARCODE_FAIL:
- String s = (String) msg.obj;
- String errorStr = "请求失败";
- if (JsonUtils.validate(s)) {
- try {
- JSONObject errorObject = new JSONObject(s);
- String exceptionInfo = JsonUtils.optStringNotNull(errorObject, "exceptionInfo");
- if (TextUtils.isEmpty(exceptionInfo)) {
- errorStr = "系统错误";
- } else {
- errorStr = exceptionInfo;
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- if (getActivity() != null) {
- CommonUtil.makeNotice();
- CommonUtil.toastNoRepeat(getActivity(), errorStr);
- etOrBarcode.setText("");
- etBarRemain.setText("");
- tvOrRemain.setText("");
- btnBreaking.setEnabled(false);
- CommonUtil.editTextGetFocus(etOrBarcode);
- progressDialog.dismiss();
- }
- break;
- default:
- break;
- }
- }
- };
- private int mFocusId;
- @Override
- protected int getLayout() {
- return R.layout.fragment_whbreaking_batch;
- }
- @Override
- protected void initViews() {
- ((TextView) (getActivity().findViewById(R.id.tv_actionbar_withback))).setText(getString(R.string.title_breakbatch));
- ((FunctionActivity) mActivity).setScanIvVisible(true);
- btnBreaking = (Button) root.findViewById(R.id.btn_breaking);
- etOrBarcode = (ClearableEditText) root.findViewById(R.id.et_or_barcode);
- etBarRemain = (ClearableEditText) root.findViewById(R.id.et_bar_remain);
- mScanImageView = (ImageView) mActivity.findViewById(R.id.btn_actionbar_scan_iv);
- tvOrRemain = (TextView) root.findViewById(R.id.tv_or_remain);
- mOkHttpClient = new OkHttpClient.Builder()
- .sslSocketFactory(FileUtils.createSSLSocketFactory(), new FileUtils.TrustAllCerts())
- .hostnameVerifier(new FileUtils.TrustAllHostnameVerifier())
- .connectTimeout(30, TimeUnit.SECONDS)
- .readTimeout(30, TimeUnit.SECONDS).build();
- isConnected = (SharedPreUtil.getInt(mActivity, "printConnect", 0) == 1);
- mOldAddress = SharedPreUtil.getString(mActivity, "printAddress", "");
- mPrintDpi = SharedPreUtil.getInt(mActivity, "printDpi", 203);
- }
- @Override
- protected void initEvents() {
- btnBreaking.setOnClickListener(this);
- CommonUtil.editTextGetFocus(etOrBarcode);
- etOrBarcode.setOnFocusChangeListener(this);
- etOrBarcode.addTextChangedListener(new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- }
- @Override
- public void afterTextChanged(Editable s) {
- if (s.length() == 0) {
- etBarRemain.setEnabled(false);
- etBarRemain.setText(null);
- } else {
- etBarRemain.setEnabled(true);
- }
- }
- });
- etOrBarcode.setOnEditorActionListener(new TextView.OnEditorActionListener() {
- @Override
- public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
- if (actionId == EditorInfo.IME_ACTION_SEND
- || actionId == EditorInfo.IME_ACTION_DONE
- || (event != null && event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
- String str = etOrBarcode.getText().toString().trim();
- if (TextUtils.isEmpty(str)) {
- etOrBarcode.setWarnIconVisible();
- return true;
- }
- if (!str.matches(Constants.REGEX.NO_CN_SYMBOL)) {
- CommonUtil.toastNoRepeat(getActivity(), getResources().getString(R.string.barcode_cannot_contain_special));
- etOrBarcode.setText("");
- etOrBarcode.postDelayed(new Runnable() {
- @Override
- public void run() {
- etOrBarcode.requestFocus();
- }
- }, 100);
- return true;
- }
- CommonUtil.closeKeybord(etOrBarcode, mActivity);
- //请求详细数据
- getLoadingView();
- barcodeEnterEvent(str);
- return true;
- }
- return false;
- }
- });
- mScanImageView.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if (CameraUtil.hasCamera()) {
- if (root.findFocus() != null) {
- mFocusId = root.findFocus().getId();
- Intent intent = new Intent();
- intent.setClass(mActivity, CaptureActivity.class);
- startActivityForResult(intent, SCAN_BARCODE_CODE);
- }
- } else {
- CommonUtil.toastNoRepeat(mActivity, getString(R.string.no_camera_detected));
- }
- }
- });
- }
- @Override
- protected void initDatas() {
- }
- @Override
- public void onHiddenChanged(boolean hidden) {
- super.onHiddenChanged(hidden);
- if (!hidden) {
- ((TextView) (getActivity().findViewById(R.id.tv_actionbar_withback))).setText(getString(R.string.title_breakbatch));
- ((FunctionActivity) mActivity).setScanIvVisible(true);
- isConnected = (SharedPreUtil.getInt(mActivity, "printConnect", 0) == 1);
- mOldAddress = SharedPreUtil.getString(mActivity, "printAddress", "");
- mPrintDpi = SharedPreUtil.getInt(mActivity, "printDpi", 203);
- } else {
- ((FunctionActivity) mActivity).setScanIvVisible(true);
- }
- }
- @Override
- public void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if (resultCode != Activity.RESULT_OK) {
- return;
- }
- if (requestCode == SCAN_BARCODE_CODE && data != null) {
- if (data.getExtras() != null) {
- String result = data.getExtras().getString(CodeUtils.RESULT_STRING);
- if (mFocusId == R.id.et_or_barcode) {
- etOrBarcode.setText(result);
- etOrBarcode.setSelection(result.length());
- } else if (mFocusId == R.id.et_bar_remain) {
- etBarRemain.setText(result);
- etBarRemain.setSelection(result.length());
- }
- }
- }
- }
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- return false;
- }
- @Override
- public boolean onFragmentBackPressed() {
- return false;
- }
- /**
- * 创建PopupWindow
- *
- * @param s
- */
- protected void initPopupWindow(String s) {
- com.alibaba.fastjson.JSONObject resultObject = JSON.parseObject(s);
- JSONArray listArray = resultObject.getJSONArray("data");
- popView = LayoutInflater.from(getActivity()).inflate(R.layout.popupwindow_whbreaking_batch, null);
- listView = (ListView) popView.findViewById(R.id.list_view);
- btnPrintf = (Button) popView.findViewById(R.id.btn_print);
- btnPrintfSet = (Button) popView.findViewById(R.id.btn_print_setting);
- btnClose = (Button) popView.findViewById(R.id.btn_close);
- btnBack = (Button) popView.findViewById(R.id.btn_back);
- btnBack.setOnClickListener(this);
- btnClose.setOnClickListener(this);
- btnPrintf.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if (isConnected) {
- progressDialog.show();
- printEvent(listArray);
- } else {
- closePopupWindow();
- BlueToothPrintFragment blueToothPrintFragment = new BlueToothPrintFragment();
- Bundle bundle = new Bundle();
- bundle.putString(Constants.KEY.BARCODE_PRINT_ARRAY, listArray.toString());
- blueToothPrintFragment.setArguments(bundle);
- FragmentUtils.switchFragment(WHBreakingBatchFragment.this, blueToothPrintFragment);
- }
- }
- });
- btnPrintfSet.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- closePopupWindow();
- BlueToothPrintFragment blueToothPrintFragment = new BlueToothPrintFragment();
- Bundle bundle = new Bundle();
- bundle.putString(Constants.KEY.BARCODE_PRINT_ARRAY, listArray.toString());
- blueToothPrintFragment.setArguments(bundle);
- FragmentUtils.switchFragment(WHBreakingBatchFragment.this, blueToothPrintFragment);
- }
- });
- adapter = new MyAdapter(getActivity(), R.layout.item_list_whbreakingbatchfragment, messages);
- listView.setAdapter(adapter);
- //当只有一条数据的时候可以加上
- if (messages.size() == 1) {
- btnBack.setVisibility(View.VISIBLE);
- } else {
- btnBack.setVisibility(View.GONE);
- }
- // PopupWindow实例化,参数的意思是 view,长(不包括状态栏),高(不包括状态栏),是否聚焦
- pop = new PopupWindow(popView, LinearLayout.LayoutParams.WRAP_CONTENT,
- LinearLayout.LayoutParams.WRAP_CONTENT, true);
- pop.setAnimationStyle(R.style.MenuAnimationFade);
- pop.setBackgroundDrawable(new BitmapDrawable());
- pop.setOnDismissListener(new PopupWindow.OnDismissListener() {
- @Override
- public void onDismiss() {
- closePopupWindow();
- }
- });
- // 弹出窗口显示内容视图,默认以锚定视图的左下角为起点,这里为点击按钮
- pop.showAtLocation(btnBreaking, Gravity.CENTER, 0, 0);
- CommonUtil.setBackgroundAlpha(mActivity, 0.5f);
- }
- private void printEvent(JSONArray printArray) {
- if (printArray != null && printArray.size() > 0) {
- boolean isFail = false;
- for (int i = 0; i < printArray.size(); i++) {
- try {
- com.alibaba.fastjson.JSONObject printObject = printArray.getJSONObject(i);
- int printResult = PrintUtils.printBar(mActivity, printObject.toString(), mPrintDpi, null);
- if (printResult <= 0) {
- isFail = true;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- closePopupWindow();
- progressDialog.dismiss();
- if (isFail) {
- isConnected = false;
- SharedPreUtil.saveInt(mActivity, "printConnect", 0);
- CommonUtil.toastNoRepeat(mActivity, "打印失败,请重新连接打印机");
- BlueToothPrintFragment blueToothPrintFragment = new BlueToothPrintFragment();
- Bundle bundle = new Bundle();
- bundle.putString(Constants.KEY.BARCODE_PRINT_ARRAY, printArray.toString());
- blueToothPrintFragment.setArguments(bundle);
- FragmentUtils.switchFragment(WHBreakingBatchFragment.this, blueToothPrintFragment);
- } else {
- CommonUtil.toastNoRepeat(mActivity, "打印成功");
- }
- } else {
- CommonUtil.toastNoRepeat(mActivity, "打印失败,条码数据为空");
- }
- }
- @Override
- public void onClick(View v) {
- switch (v.getId()) {
- case R.id.btn_breaking:
- String str = etBarRemain.getText().toString().trim();
- if (TextUtils.isEmpty(str) || TextUtils.isEmpty(tvOrRemain.getText().toString().trim()) || TextUtils.isEmpty(etOrBarcode.getText().toString().trim())) {
- etBarRemain.setWarnIconVisible();
- //etBarRemain.setHint("还有必填项值为空");
- Toast.makeText(getActivity().getApplicationContext(), "还有必填项值为空", Toast.LENGTH_SHORT).show();
- return;
- }
- if (!etOrBarcode.getText().toString().trim().matches(Constants.REGEX.NO_CN_SYMBOL)) {
- CommonUtil.toastNoRepeat(getActivity(), getResources().getString(R.string.barcode_cannot_contain_special));
- return;
- }
- // if (!str.matches(Constants.REGEX.NO_CN_SYMBOL)) {
- // CommonUtil.toastNoRepeat(getActivity(), "请输入正确的拆分数量");
- // return;
- // }
- if (!str.matches(Constants.REGEX.IS_FLOAT)) {
- Toast.makeText(getActivity(), "请输入正确的拆分数量", Toast.LENGTH_SHORT).show();
- return;
- }
- double i = Double.parseDouble(str);
- double sum = Double.parseDouble(tvOrRemain.getText().toString().trim());
- if (i <= 0 || i >= sum) {
- etBarRemain.setWarnIconVisible();
- //etBarRemain.setHint("拆分数量必须在大于0,小于批数量");
- Toast.makeText(getActivity().getApplicationContext(), "拆分数量必须大于0,小于批数量", Toast.LENGTH_SHORT).show();
- return;
- }
- //隐藏软键盘
- CommonUtil.closeKeybord(etBarRemain, mActivity);
- //请求详细数据
- breakingBtnClickEvent();
- break;
- case R.id.btn_back:
- closePopupWindow();
- if (messages != null && messages.size() > 0) {
- tvOrRemain.setText(CommonUtil.doubleFormat(messages.get(0).getBAR_REMAIN()));
- CommonUtil.editTextGetFocus(etBarRemain);
- }
- break;
- case R.id.btn_print:
- if (!CommonUtil.appIsInstalled(getActivity(), Constants.CONSTANT.PRINT_SHARE_PACKAGE)) {
- new android.app.AlertDialog.Builder(getActivity()).setTitle("提示")
- .setMessage("您还未安装打印程序,点击确认开始安装")
- .setPositiveButton("确认", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- Intent intent = new Intent(Intent.ACTION_VIEW);
- File assetsFileToCacheDir = FileUtils.getAssetsFileToCacheDir(getActivity(), "PrinterShare.apk");
- if (Build.VERSION.SDK_INT >= 24) {
- Uri apkUri = FileProvider.getUriForFile(mActivity, "com.uaspda.fileprovider", assetsFileToCacheDir);
- //Granting Temporary Permissions to a URI
- intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
- } else {
- intent.setDataAndType(Uri.fromFile(assetsFileToCacheDir), "application/vnd.android.package-archive");
- }
- getActivity().startActivity(intent);
- }
- })
- .setNegativeButton("取消", null).create().show();
- } else {
- getPrintData();
- }
- break;
- case R.id.btn_close:
- closePopupWindow();
- reset();
- break;
- }
- }
- /**
- * 关闭窗口
- */
- private void closePopupWindow() {
- if (pop != null) {
- pop.dismiss();
- pop = null;
- CommonUtil.setBackgroundAlpha(mActivity, 1f);
- }
- }
- @Override
- public void onDestroy() {
- progressDialog.dismiss();
- CommonUtil.closeKeybord(etOrBarcode, mActivity);
- CommonUtil.closeKeybord(etBarRemain, mActivity);
- ((TextView) (getActivity().findViewById(R.id.tv_actionbar_withback))).setText(R.string.title_batch_content);
- ((FunctionActivity) mActivity).setScanIvVisible(false);
- super.onDestroy();
- }
- @Override
- public void onStop() {
- super.onStop();
- if (mRequestQueue != null) {
- mRequestQueue.cancelAll(TAG);
- }
- }
- /**
- * 文本焦点改变
- */
- @Override
- public void onFocusChange(View v, boolean hasFocus) {
- switch (v.getId()) {
- case R.id.et_or_barcode:
- if (!hasFocus && isVisible()) {
- String str = etOrBarcode.getText().toString().trim();
- if (TextUtils.isEmpty(str)) {
- etOrBarcode.setWarnIconVisible();
- return;
- }
- if (!str.matches(Constants.REGEX.NO_CN_SYMBOL)) {
- CommonUtil.toastNoRepeat(getActivity(), getResources().getString(R.string.barcode_cannot_contain_special));
- etOrBarcode.setText("");
- etOrBarcode.postDelayed(new Runnable() {
- @Override
- public void run() {
- etOrBarcode.requestFocus();
- }
- }, 100);
- return;
- }
- CommonUtil.closeKeybord(etOrBarcode, mActivity);
- //请求详细数据
- getLoadingView();
- barcodeEnterEvent(str);
- }
- break;
- }
- }
- /**
- * 显示loadingView
- */
- private void getLoadingView() {
- if (!progressDialog.isShowing()) {
- progressDialog.show();
- } else {
- progressDialog.dismiss();
- }
- }
- /**
- * 当编辑框里面的内容完成的时候,自动的,同时获取服务器的批量数
- */
- private void barcodeEnterEvent(String outboxcode) {
- mRequestQueue = Volley.newRequestQueue(getActivity());
- String url = null;
- try {
- url = GloableParams.ADDRESS_BARCODEENTEREVENT + "?code=" + URLEncoder.encode(outboxcode, "utf-8") + "&pr_ismsd=" + "false";
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
- @Override
- public void onResponse(String s) {
- LogUtil.e("msg", "ssss" + s);
- etBarRemain.setEnabled(true);
- etBarRemain.requestFocus();
- WHBreakingBatchGetBarcodeData whBreakingBatchGetBarcodeData = JsonTools.parseJsonToBean(s, WHBreakingBatchGetBarcodeData.class);
- tvOrRemain.setText(whBreakingBatchGetBarcodeData.getData().getData().getBAR_REMAIN() + "");
- getLoadingView();
- CommonUtil.setEnabled(btnBreaking);
- }
- }, new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError volleyError) {
- etOrBarcode.setText("");
- etOrBarcode.requestFocus();
- CommonUtil.showErrorToast(volleyError);
- getLoadingView();
- }
- }) {
- @Override
- public Map<String, String> getHeaders() throws AuthFailureError {
- String cookie = SharedPreUtil.getString(getActivity().getApplicationContext(), "cookie", null);
- Map<String, String> headers = new HashMap<>();
- headers.put("Cookie", cookie);
- return headers;
- }
- };
- stringRequest.setTag(TAG);
- mRequestQueue.add(stringRequest);
- }
- /**
- * 分拆按钮点击事件,获取数据,同时获取popupWindow的数据
- */
- private void breakingBtnClickEvent() {
- messages.clear();
- progressDialog.show();
- String url = GloableParams.ADDRESS_BREAKINGBTNCLICKEVENT;
- Log.d("breakDeal", url);
- RequestBody requestBody = new FormBody.Builder()
- .add("or_barcode", etOrBarcode.getText().toString().trim())
- .add("or_remain", tvOrRemain.getText().toString().trim())
- .add("bar_remain", etBarRemain.getText().toString().trim())
- .build();
- okhttp3.Request.Builder builder = new okhttp3.Request.Builder().url(url).post(requestBody);
- Map<String, String> cookiesMap = VolleyUtil.getVolleyUtil().setCookies();
- if (cookiesMap != null) {
- Set<String> keys = cookiesMap.keySet();
- Iterator<String> iterator = keys.iterator();
- while (iterator.hasNext()) {
- String key = iterator.next();
- String value = cookiesMap.get(key);
- builder.addHeader(key, value);
- }
- }
- mRequest = builder.build();
- mOkHttpClient.newCall(mRequest).enqueue(new Callback() {
- @Override
- public void onFailure(Call call, IOException e) {
- progressDialog.dismiss();
- Message message = Message.obtain();
- message.what = SPLIT_BARCODE_FAIL;
- message.obj = "{\"exceptionInfo\":\"条码拆分异常\"}";
- mHandler.sendMessage(message);
- }
- @Override
- public void onResponse(Call call, okhttp3.Response response) throws IOException {
- progressDialog.dismiss();
- String s = response.body().string();
- if (response.code() == 200) {
- Message message = Message.obtain();
- message.what = SPLIT_BARCODE_SUCCESS;
- message.obj = s;
- mHandler.sendMessage(message);
- } else {
- Message message = Message.obtain();
- message.what = SPLIT_BARCODE_FAIL;
- message.obj = s;
- mHandler.sendMessage(message);
- }
- }
- });
- /*PdaApplication.mRequestQueue.cancelAll(TAG + "break");
- stringRequest = new StringRequest(Request.Method.POST, GloableParams.ADDRESS_BREAKINGBTNCLICKEVENT,
- new Response.Listener<String>() {
- @Override
- public void onResponse(String s) {
- LogUtil.e("breaking", s);
- WHBreakingBatchBreakingBtnClickEvent wh = JsonTools.parseJsonToBean(s, WHBreakingBatchBreakingBtnClickEvent.class);
- if (wh.getData() != null) {
- for (int i = 0; i < wh.getData().size(); i++) {
- messages.add(wh.getData().get(i));
- }
- }
- strPrintDataList = new Gson().toJson(messages);
- //打开popupWindow;
- initPopupWindow();
- reset();
- }
- },
- new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError volleyError) {
- CommonUtil.showErrorToast(volleyError);
- etOrBarcode.setText("");
- etBarRemain.setText("");
- tvOrRemain.setText("");
- btnBreaking.setEnabled(false);
- CommonUtil.editTextGetFocus(etOrBarcode);
- progressDialog.dismiss();
- }
- }) {
- @Override
- protected Map<String, String> getParams() throws AuthFailureError {
- Map<String, String> params = new HashMap<>();
- params.put("or_barcode", etOrBarcode.getText().toString().trim());
- params.put("or_remain", tvOrRemain.getText().toString().trim());
- params.put("bar_remain", etBarRemain.getText().toString().trim());
- return params;
- }
- @Override
- public Map<String, String> getHeaders() throws AuthFailureError {
- return VolleyUtil.getVolleyUtil().setCookies();
- }
- };
- stringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000, 0, 1f));
- stringRequest.setTag(TAG + "break");
- PdaApplication.mRequestQueue.add(stringRequest);*/
- }
- /**
- * popupWindow 设置适配器
- */
- private class MyAdapter extends ArrayAdapter<WHBreakingBatchBreakingBtnClickEvent.DataBean> {
- private int resourceId;
- public MyAdapter(Context context, int resource, List<WHBreakingBatchBreakingBtnClickEvent.DataBean> objects) {
- super(context, resource, objects);
- resourceId = resource;
- }
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- //WHBreakingBatchBreakingBtnClickEvent.Message target = getItem(position);
- WHBreakingBatchBreakingBtnClickEvent.DataBean person = getItem(position);
- convertView = LayoutInflater.from(getContext()).inflate(resourceId,
- null);
- TextView tv_bar_code = (TextView) convertView.findViewById(R.id.tv_bar_code);
- TextView tv_bar_remain = (TextView) convertView.findViewById(R.id.tv_bar_remain);
- // tv_bar_code.setText(target.bar_code);
- // tv_bar_remain.setText(target.bar_remain);
- tv_bar_code.setText(person.getBAR_CODE());
- tv_bar_remain.setText(CommonUtil.doubleFormat(person.getBAR_REMAIN()));
- return convertView;
- }
- }
- /*打印*/
- public static final String GETPRINTDATA = "getPrintData";
- private void getPrintData() {
- progressDialog.show();
- String url = GloableParams.ADDRESS_LABELPRINT + "?data=" + strPrintDataList;
- stringRequest3 = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
- @Override
- public void onResponse(String s) {
- try {
- JSONObject resultObject = new JSONObject(s);
- if (resultObject.optBoolean("success")) {
- mPrintUrl = resultObject.optString("data");
- FileUtils.printBarcode(mPrintUrl, mHandler);
- }
- } catch (JSONException e) {
- if (progressDialog.isShowing())
- progressDialog.dismiss();
- e.printStackTrace();
- }
- }
- }, new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError volleyError) {
- if (progressDialog.isShowing())
- progressDialog.dismiss();
- CommonUtil.showErrorToast(volleyError);
- }
- }) {
- @Override
- public Map<String, String> getHeaders() throws AuthFailureError {
- Map map = VolleyUtil.getVolleyUtil().setCookies();
- //不用改动
- map.put("Content-Type", "text/html; charset=UTF-8");
- return map;
- }
- };
- stringRequest3.setTag(GETPRINTDATA);
- mRequestQueue.add(stringRequest3);
- }
- public void reset() {
- etOrBarcode.getText().clear();
- etBarRemain.getText().clear();
- tvOrRemain.setText("");
- btnBreaking.setEnabled(false);
- CommonUtil.editTextGetFocus(etOrBarcode);
- progressDialog.dismiss();
- }
- }
|