|
|
@@ -3,14 +3,12 @@ package com.uas.xuslectronic.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.TextUtils;
|
|
|
import android.util.Log;
|
|
|
import android.view.Gravity;
|
|
|
@@ -30,6 +28,8 @@ 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;
|
|
|
@@ -43,13 +43,17 @@ import com.uas.xuslectronic.activity.FunctionActivity;
|
|
|
import com.uas.xuslectronic.bean.WHBreakingBatchGetBarcodeData;
|
|
|
import com.uas.xuslectronic.bean.WHCombineBatchFragmentCombineBtnClickEvent;
|
|
|
import com.uas.xuslectronic.global.GloableParams;
|
|
|
+import com.uas.xuslectronic.tools.SharedPreUtil;
|
|
|
import com.uas.xuslectronic.tools.VolleyUtil;
|
|
|
import com.uas.xuslectronic.util.CameraUtil;
|
|
|
import com.uas.xuslectronic.util.CommonUtil;
|
|
|
import com.uas.xuslectronic.util.Constants;
|
|
|
import com.uas.xuslectronic.util.FileUtils;
|
|
|
+import com.uas.xuslectronic.util.FragmentUtils;
|
|
|
import com.uas.xuslectronic.util.JsonTools;
|
|
|
import com.uas.xuslectronic.util.LogUtil;
|
|
|
+import com.uas.xuslectronic.util.MyLog;
|
|
|
+import com.uas.xuslectronic.util.PrintUtils;
|
|
|
import com.uas.xuslectronic.view.ClearableEditText;
|
|
|
import com.uuzuche.lib_zxing.activity.CaptureActivity;
|
|
|
import com.uuzuche.lib_zxing.activity.CodeUtils;
|
|
|
@@ -88,6 +92,13 @@ public class WHCombineBatchFragment extends BaseFragment implements View.OnClick
|
|
|
private int lastPress = 0;
|
|
|
private boolean delState = false;
|
|
|
private String mPrintUrl = "";
|
|
|
+
|
|
|
+ private com.alibaba.fastjson.JSONArray listArray;
|
|
|
+ private boolean isConnected = false;
|
|
|
+ private String mOldAddress = "";
|
|
|
+ private int mPrintDpi = 203;
|
|
|
+ private boolean isPrinting = false;
|
|
|
+
|
|
|
private Handler mHandler = new Handler() {
|
|
|
@Override
|
|
|
public void handleMessage(Message msg) {
|
|
|
@@ -149,6 +160,10 @@ public class WHCombineBatchFragment extends BaseFragment implements View.OnClick
|
|
|
myAdapter = new MyAdapter(getActivity(), R.layout.item_list_whcombatchfragment, dataList);
|
|
|
listView.setAdapter(myAdapter);
|
|
|
btnMerge = (Button) root.findViewById(R.id.btn_merge);
|
|
|
+
|
|
|
+ isConnected = (SharedPreUtil.getInt(mActivity, "printConnect", 0) == 1);
|
|
|
+ mOldAddress = SharedPreUtil.getString(mActivity, "printAddress", "");
|
|
|
+ mPrintDpi = SharedPreUtil.getInt(mActivity, "printDpi", 203);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -312,10 +327,10 @@ public class WHCombineBatchFragment extends BaseFragment implements View.OnClick
|
|
|
Toast.makeText(getActivity().getApplicationContext(), "还有必填项值为空", Toast.LENGTH_SHORT).show();
|
|
|
return;
|
|
|
}
|
|
|
- if (!str.matches(Constants.REGEX.NO_SYMBOL)) {
|
|
|
- CommonUtil.toastNoRepeat(getActivity(), getResources().getString(R.string.barcode_cannot_contain_special));
|
|
|
- return;
|
|
|
- }
|
|
|
+// if (!str.matches(Constants.REGEX.NO_SYMBOL)) {
|
|
|
+// CommonUtil.toastNoRepeat(getActivity(), getResources().getString(R.string.barcode_cannot_contain_special));
|
|
|
+// return;
|
|
|
+// }
|
|
|
|
|
|
for (int i = 0; i < dataList.size(); i++) {
|
|
|
if (str.equals(dataList.get(i).getBAR_CODE())) {
|
|
|
@@ -338,30 +353,36 @@ public class WHCombineBatchFragment extends BaseFragment implements View.OnClick
|
|
|
|
|
|
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.uas.xuslectronic", 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();
|
|
|
+ if (listArray != null && listArray.size() > 0) {
|
|
|
+ printEvent(listArray);
|
|
|
} else {
|
|
|
- getPrintData();
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, "数据为空");
|
|
|
}
|
|
|
+
|
|
|
+// 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.uas.xuslectronic", 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();
|
|
|
@@ -369,17 +390,70 @@ public class WHCombineBatchFragment extends BaseFragment implements View.OnClick
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void printEvent(com.alibaba.fastjson.JSONArray printArray) {
|
|
|
+ MyLog.e("aaa","打印的数组是:" + printArray.get(0));
|
|
|
+ if (isPrinting) {
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, "正在打印中,请勿重复操作");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ isPrinting = true;
|
|
|
+ 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();
|
|
|
+ //closeSplitPopupWindow();
|
|
|
+ //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(WHCombineBatchFragment.this, blueToothPrintFragment);
|
|
|
+ } else {
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, "打印成功");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, "打印失败,条码数据为空");
|
|
|
+ }
|
|
|
+ isPrinting = false;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 创建PopupWindow
|
|
|
*/
|
|
|
- protected void initPopuptWindow(String code, String remain) {
|
|
|
+ protected void initPopuptWindow(WHCombineBatchFragmentCombineBtnClickEvent whc2) {
|
|
|
+
|
|
|
LayoutInflater inflater = LayoutInflater.from(getActivity());
|
|
|
popView = inflater.inflate(R.layout.popupwindow_whcombine_bach, null);
|
|
|
+ TextView tv_po = (TextView) popView.findViewById(R.id.tv_po);
|
|
|
+ TextView tv_pn = (TextView) popView.findViewById(R.id.tv_pn);
|
|
|
+ TextView tv_desc = (TextView) popView.findViewById(R.id.tv_desc);
|
|
|
+ TextView tv_dc = (TextView) popView.findViewById(R.id.tv_dc);
|
|
|
+
|
|
|
TextView tvNewBarCode = (TextView) popView.findViewById(R.id.tv_new_bar_code);
|
|
|
TextView tvTotal = (TextView) popView.findViewById(R.id.tv_total);
|
|
|
- tvNewBarCode.setText(code);
|
|
|
- tvTotal.setText(remain);
|
|
|
+ tvNewBarCode.setText(whc2.getData().getBAR_CODE());
|
|
|
+ tvTotal.setText(whc2.getData().getBAR_REMAIN());
|
|
|
+ tv_po.setText(whc2.getData().getBAR_PUCODE());
|
|
|
+ tv_pn.setText(whc2.getData().getPR_CODE());
|
|
|
+ tv_desc.setText(whc2.getData().getPR_SPEC());
|
|
|
+ tv_dc.setText(whc2.getData().getMADEDATE());
|
|
|
+
|
|
|
Button btnPrint = (Button) popView.findViewById(R.id.btn_print);
|
|
|
Button btnClose = (Button) popView.findViewById(R.id.btn_close);
|
|
|
btnPrint.setOnClickListener(this);
|
|
|
@@ -412,7 +486,6 @@ public class WHCombineBatchFragment extends BaseFragment implements View.OnClick
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 并且获取条码的剩余数量
|
|
|
*/
|
|
|
@@ -497,7 +570,27 @@ public class WHCombineBatchFragment extends BaseFragment implements View.OnClick
|
|
|
sum = 0;
|
|
|
tvToatal.setText(sum + "");
|
|
|
btnMerge.setEnabled(false);
|
|
|
- initPopuptWindow(whc2.getData().getBAR_CODE(), CommonUtil.doubleFormat(whc2.getData().getBAR_REMAIN()));
|
|
|
+
|
|
|
+ //新增数据
|
|
|
+ com.alibaba.fastjson.JSONObject resultObject = JSON.parseObject(s);
|
|
|
+ com.alibaba.fastjson.JSONObject jb = resultObject.getJSONObject("data");
|
|
|
+
|
|
|
+ List<Object> list = new ArrayList<>();;
|
|
|
+ list.add(jb);
|
|
|
+ JSONArray jsonArray = new JSONArray(list);
|
|
|
+
|
|
|
+ // for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
+ // Object o = jsonArray.get(0);
|
|
|
+ // com.alibaba.fastjson.JSONObject jsonObject = jsonArray.getJSONObject(0);
|
|
|
+ // MyLog.e("aaa","数据是 Object:" + o);
|
|
|
+ // MyLog.e("aaa","数据是 jsonObject:" + jsonObject.toString());
|
|
|
+ // }
|
|
|
+
|
|
|
+ //listArray = FastjsonUtil.getJSONArray(dataJson.toString(), "nolist");
|
|
|
+ listArray = jsonArray;
|
|
|
+
|
|
|
+ //initPopuptWindow(whc2.getData().getBAR_CODE(), CommonUtil.doubleFormat(whc2.getData().getBAR_REMAIN()));
|
|
|
+ initPopuptWindow(whc2);
|
|
|
}
|
|
|
}, new Response.ErrorListener() {
|
|
|
@Override
|