|
@@ -1,44 +1,79 @@
|
|
|
package com.uas.pda_smart_com.fragment;
|
|
|
|
|
|
import android.app.Activity;
|
|
|
+import android.app.AlertDialog;
|
|
|
+import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
+import android.graphics.drawable.BitmapDrawable;
|
|
|
import android.os.Bundle;
|
|
|
+import android.os.Message;
|
|
|
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 com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.android.volley.AuthFailureError;
|
|
|
import com.android.volley.DefaultRetryPolicy;
|
|
|
import com.android.volley.Request;
|
|
|
import com.android.volley.Response;
|
|
|
import com.android.volley.VolleyError;
|
|
|
import com.android.volley.toolbox.StringRequest;
|
|
|
+import com.google.gson.Gson;
|
|
|
import com.uas.pda_smart_com.R;
|
|
|
import com.uas.pda_smart_com.activity.FunctionActivity;
|
|
|
import com.uas.pda_smart_com.application.PdaApplication;
|
|
|
+import com.uas.pda_smart_com.bean.CodePrinBean;
|
|
|
+import com.uas.pda_smart_com.bean.WHBreakingBatchBreakingBtnClickEvent;
|
|
|
import com.uas.pda_smart_com.global.GloableParams;
|
|
|
+import com.uas.pda_smart_com.tools.SharedPreUtil;
|
|
|
import com.uas.pda_smart_com.tools.VolleyUtil;
|
|
|
import com.uas.pda_smart_com.util.CameraUtil;
|
|
|
import com.uas.pda_smart_com.util.CommonUtil;
|
|
|
import com.uas.pda_smart_com.util.Constants;
|
|
|
+import com.uas.pda_smart_com.util.FastjsonUtil;
|
|
|
+import com.uas.pda_smart_com.util.FragmentUtils;
|
|
|
+import com.uas.pda_smart_com.util.HttpCallback;
|
|
|
+import com.uas.pda_smart_com.util.HttpParams;
|
|
|
import com.uas.pda_smart_com.util.JsonUtils;
|
|
|
+import com.uas.pda_smart_com.util.PrintUtils;
|
|
|
+import com.uas.pda_smart_com.util.VolleyRequest;
|
|
|
import com.uas.pda_smart_com.view.ClearableEditText;
|
|
|
+import com.umeng.commonsdk.debug.E;
|
|
|
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.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 okhttp3.Call;
|
|
|
+import okhttp3.Callback;
|
|
|
+import okhttp3.FormBody;
|
|
|
+import okhttp3.RequestBody;
|
|
|
|
|
|
/**
|
|
|
* Created by RaoMeng on 2017/5/4.
|
|
@@ -58,6 +93,16 @@ public class ModifyBarcodeQuantityFragment extends BaseFragment {
|
|
|
private boolean mIgnoreFocusChange = false;
|
|
|
private boolean isShop = false;
|
|
|
|
|
|
+ private View popView;
|
|
|
+ private PopupWindow pop;
|
|
|
+ private Button btnBack, btnPrintf, btnClose, btnPrintfSet;
|
|
|
+ private List<WHBreakingBatchBreakingBtnClickEvent.DataBean> messages = new ArrayList<>();
|
|
|
+ private ListView listView;
|
|
|
+ private MyAdapter adapter;
|
|
|
+ private boolean isConnected = false;
|
|
|
+ private String mOldAddress = "";
|
|
|
+ private int mPrintDpi = 203;
|
|
|
+
|
|
|
@Override
|
|
|
protected int getLayout() {
|
|
|
return R.layout.fragment_modify_barcode_quantity;
|
|
@@ -75,6 +120,10 @@ public class ModifyBarcodeQuantityFragment extends BaseFragment {
|
|
|
mScanImageView = (ImageView) mActivity.findViewById(R.id.btn_actionbar_scan_iv);
|
|
|
|
|
|
mBarcodeEditText.requestFocus();
|
|
|
+
|
|
|
+ isConnected = (SharedPreUtil.getInt(mActivity, "printConnect", 0) == 1);
|
|
|
+ mOldAddress = SharedPreUtil.getString(mActivity, "printAddress", "");
|
|
|
+ mPrintDpi = SharedPreUtil.getInt(mActivity, "printDpi", 203);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -155,6 +204,8 @@ public class ModifyBarcodeQuantityFragment extends BaseFragment {
|
|
|
mResultTextView.setVisibility(View.VISIBLE);
|
|
|
mResultTextView.setText("修改数量成功,条码:" + barcode + " 修改后数量为:" + quantity);
|
|
|
mBarcodeEditText.requestFocus();
|
|
|
+
|
|
|
+ initPopupWindow(s);
|
|
|
}
|
|
|
} catch (JSONException e) {
|
|
|
e.printStackTrace();
|
|
@@ -210,6 +261,181 @@ public class ModifyBarcodeQuantityFragment extends BaseFragment {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 蓝牙打印pop
|
|
|
+ * @param s
|
|
|
+ */
|
|
|
+ protected void initPopupWindow(String s) {
|
|
|
+ JSONArray listArray = new JSONArray();
|
|
|
+ try {
|
|
|
+ Gson gson = new Gson();
|
|
|
+ CodePrinBean codePrinBean = gson.fromJson(s, CodePrinBean.class);
|
|
|
+ if (codePrinBean.getData() == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ CodePrinBean.DataBean data = codePrinBean.getData();
|
|
|
+ String json = gson.toJson(data);
|
|
|
+ com.alibaba.fastjson.JSONObject resultObject = JSON.parseObject(json);
|
|
|
+ listArray.add(new com.alibaba.fastjson.JSONObject(resultObject));
|
|
|
+ messages.clear();
|
|
|
+ for (int i = 0; i < listArray.size(); i++) {
|
|
|
+ com.alibaba.fastjson.JSONObject barcodeObject = listArray.getJSONObject(i);
|
|
|
+ WHBreakingBatchBreakingBtnClickEvent.DataBean dataBean = new WHBreakingBatchBreakingBtnClickEvent.DataBean();
|
|
|
+ dataBean.setBAR_CODE(barcodeObject.getString("BAR_CODE"));
|
|
|
+ dataBean.setBAR_REMAIN(barcodeObject.getString("BAR_REMAIN"));
|
|
|
+ messages.add(dataBean);
|
|
|
+ }
|
|
|
+ }catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ 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.setVisibility(View.GONE);
|
|
|
+ btnClose.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ closePopupWindow();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ 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(ModifyBarcodeQuantityFragment.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(ModifyBarcodeQuantityFragment.this, blueToothPrintFragment);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ MyAdapter adapter = new MyAdapter(getActivity(), R.layout.item_list_whbreakingbatchfragment, messages);
|
|
|
+ listView.setAdapter(adapter);
|
|
|
+ //当只有一条数据的时候可以加上
|
|
|
+ /*
|
|
|
+ if (messages.size()>1){
|
|
|
+ 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.showAtLocation(getActivity().getWindow().getDecorView(), Gravity.CENTER, 0, 0);
|
|
|
+ pop.setOnDismissListener(new PopupWindow.OnDismissListener() {
|
|
|
+ @Override
|
|
|
+ public void onDismiss() {
|
|
|
+ closePopupWindow();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ CommonUtil.setBackgroundAlpha(mActivity, 0.5f);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 关闭窗口
|
|
|
+ */
|
|
|
+ private void closePopupWindow() {
|
|
|
+ if (pop != null) {
|
|
|
+ pop.dismiss();
|
|
|
+ pop = null;
|
|
|
+ CommonUtil.setBackgroundAlpha(mActivity, 1f);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void reset() {
|
|
|
+ progressDialog.dismiss();
|
|
|
+ }
|
|
|
+
|
|
|
+ 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(ModifyBarcodeQuantityFragment.this, blueToothPrintFragment);
|
|
|
+ } else {
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, "打印成功");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, "打印失败,条码数据为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 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(person.getBAR_REMAIN());
|
|
|
+ return convertView;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
@@ -315,6 +541,10 @@ public class ModifyBarcodeQuantityFragment extends BaseFragment {
|
|
|
if (!hidden) {
|
|
|
FunctionActivity.setTitle("条码数量修改");
|
|
|
((FunctionActivity) mActivity).setScanIvVisible(true);
|
|
|
+
|
|
|
+ isConnected = (SharedPreUtil.getInt(mActivity, "printConnect", 0) == 1);
|
|
|
+ mOldAddress = SharedPreUtil.getString(mActivity, "printAddress", "");
|
|
|
+ mPrintDpi = SharedPreUtil.getInt(mActivity, "printDpi", 203);
|
|
|
}
|
|
|
}
|
|
|
|