123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803 |
- package com.fxy.detection;
- import android.annotation.SuppressLint;
- import android.app.AlertDialog;
- import android.content.BroadcastReceiver;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.content.IntentFilter;
- import android.os.Bundle;
- import android.os.Handler;
- import android.os.Looper;
- import android.os.Message;
- import android.support.v7.widget.LinearLayoutManager;
- import android.support.v7.widget.RecyclerView;
- import android.text.Editable;
- import android.text.TextWatcher;
- import android.view.KeyEvent;
- import android.view.View;
- import android.view.ViewGroup;
- import android.view.inputmethod.EditorInfo;
- import android.widget.EditText;
- import android.widget.ImageButton;
- import android.widget.LinearLayout;
- import android.widget.TextView;
- import com.chad.library.adapter.base.BaseQuickAdapter;
- import com.chad.library.adapter.base.BaseViewHolder;
- import com.elvishew.xlog.XLog;
- import com.fxy.R;
- import com.fxy.baselibrary.base.BaseActivity;
- import com.fxy.baselibrary.bean.BaseEventBusBean;
- import com.fxy.baselibrary.interfaces.OnRxScanerListener;
- import com.fxy.baselibrary.util.JsonUtil;
- import com.fxy.baselibrary.views.MarqueeTextView;
- import com.fxy.bean.ActionBean;
- import com.fxy.bean.ScanBean;
- import com.fxy.common.AsyncPictureSelector;
- import com.fxy.common.AsyncPictureUpload;
- import com.fxy.constant.BaseConfig;
- import com.fxy.constant.EventCode;
- import com.fxy.constant.SPCache;
- import com.fxy.detection.bean.StorageRecordBean;
- import com.fxy.detection.bean.TakePictureBean;
- import com.fxy.detection.bean.TrackingBoxBean;
- import com.fxy.detection.bean.TrayMakeBean;
- import com.fxy.net.MyDialogCallback;
- import com.fxy.net.Urls;
- import com.google.gson.Gson;
- import com.google.zxing.Result;
- import com.luck.picture.lib.config.PictureConfig;
- import com.lzy.okgo.OkGo;
- import com.lzy.okgo.model.Response;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import butterknife.BindView;
- import butterknife.ButterKnife;
- import butterknife.OnClick;
- import butterknife.Unbinder;
- import sto.android.app.StoJNI;
- import sto.android.app.StoPdaKeyEvent;
- import sto.android.app.StoTongJNI;
- public class TrayMakeFourMainActivity extends BaseActivity implements StoJNI.ScanCallBack{
- /**
- * 列表适配器
- */
- Context mContext = this;
-
- @BindView(R.id.et_unit_code)
- EditText etUnitCode;
-
- @BindView(R.id.ll_await_num)
- LinearLayout llAwaitNum;
- @BindView(R.id.tv_await_num)
- TextView tvAwaitNum;
-
- @BindView(R.id.ll_btn_confirm)
- LinearLayout llConfirm;
-
- @BindView(R.id.ll_unit_code)
- LinearLayout llUnitCode;
- @BindView(R.id.recyclerview)
- RecyclerView recyclerView;
- @BindView(R.id.mt_tracking_number)
- MarqueeTextView mtTrackingNumber;
- @BindView(R.id.mt_box_number)
- MarqueeTextView mtBoxNumber;
- @BindView(R.id.mt_operate_number)
- MarqueeTextView mtOperateNumber;
- @BindView(R.id.mt_contents_number)
- MarqueeTextView mtContentsNumber;
- @BindView(R.id.ll_box_number)
- LinearLayout llBoxNumber;
- @BindView(R.id.ll_contents_number)
- LinearLayout llContentsNumber;
- private TrayMakeBean trayMakeBean;
- private int abImgId;
- private HashMap<String, Object> postData = new HashMap<>();
- private AsyncPictureUpload asyncPictureUpload = new AsyncPictureUpload(this);
- private String currentPictureType= "";
- private boolean currentUploadStatus = false;
- private boolean isRequiredShow = false;
- //
- //扫码扫码动作
- private ScanBean scanBean;
-
- private Unbinder unbinder;
- private JSONObject postParam = new JSONObject();
- private int leisure = 10;
- private Handler workHandler;
- private Runnable idleRunnable;
- private View notDataView; //没有数据显示页
- private View errorView; //错误显示页
- private View emptyView; //空显示页
- /**
- * 列表适配器
- */
- private FinishWorkAdapter mAdapter;
- private List<StorageRecordBean> tallyDataList = new ArrayList<>() ;
- @Override
- public int getContentViewResId() {
- return R.layout.activity_fxy_detection_tray_make_four;
- }
- @Override
- public boolean showToolBar() {
- return true;
- }
- @Override
- public boolean openEventBus() {
- return true;
- }
- @Override
- protected void getBundleExtras(Bundle bundle) {
- //XLog.e("接收数据解析:",bundle);
- trayMakeBean = JsonUtil.jsonString2Bean(bundle.getString("data"),TrayMakeBean.class);
- abImgId = bundle.getInt("ab_img_id");
- }
- //finish的返回监听
- //这里的requestCode参数,就是上面设置的 1 ,当跳转的页面返回的时候,通过这个加以判断
- //resultCode ,这个参数是在跳转的页面里面规定的,它也是一个int类型的标志
- //第三个参数包含了返回的值
- //如果不需要所跳转的页面返回值,也就不需要这个方法了
- @Override
- public void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- }
- /**
- * EventBus接收信息的方法,开启后才会调用(非粘性事件)
- *
- * @param event BaseEventBusBean
- */
- @Override
- protected void EventBean(BaseEventBusBean event) {
- // XLog.e("----------接收返回--------------");
- // XLog.e("接收返回:"+event.getEventCode());
- assert event != null;
- switch (event.getEventCode()){
- case EventCode.picture_selector_lister:
- currentPictureType = event.getData().toString();
- break;
- case EventCode.file_upload_lister:
- totalAwaitNum();
- break;
- }
- }
- @Override
- public boolean isPlayMusic() {
- return true;
- }
- @Override
- protected void initView() {
- unbinder = ButterKnife.bind(this);
- setTitleName("托盘清点-内件码");
- initAdapter();
- setRequestResult();
- initEdit();
- totalAwaitNum();
- workHandler = new Handler(Looper.getMainLooper());
- // 定义空闲任务
- idleRunnable = new Runnable() {
- @Override
- public void run() {
- // 执行空闲后的操作
- operateStartUpload();
- }
- };
- SPCache spCache = SPCache.getInstance(this);
- leisure = spCache.getLeisure();
- // 初始化时设置计时器
- workHandler.postDelayed(idleRunnable, leisure * 60 * 1000);
- }
- private void setNewTiming(){
- try {
- // 取消之前的计时器
- workHandler.removeCallbacks(idleRunnable);
- // 重新计时
- workHandler.postDelayed(idleRunnable, leisure * 60 * 1000); // 2 分钟
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * 设置多个上传文件
- * @param uploadType String
- * @param showImg RecyclerView
- */
- private AsyncPictureSelector setItemPicture(String uploadType,RecyclerView showImg,int num){
- String notifyUrl = Urls.getServiceAddress(this) + Urls.FXY_DETECTION_PUTIN;
- AsyncPictureSelector pictureUpload = new AsyncPictureSelector(TrayMakeFourMainActivity.this,showImg,"detection",uploadType,notifyUrl,false);
- pictureUpload.setUploadType(uploadType);
- pictureUpload.setCompress(true,100,100);
- pictureUpload.setOnlyCamera(true);
- pictureUpload.setMaxSelectNum(num);
- return pictureUpload;
- }
- @Override
- public boolean dispatchKeyEvent(KeyEvent event) {
- //XLog.e("event:"+event.getKeyCode());
- if ((event.getKeyCode()==KeyEvent.KEYCODE_DPAD_CENTER || event.getKeyCode()==KeyEvent.KEYCODE_ENTER ) && event.getAction() == KeyEvent.ACTION_DOWN){
- //按确定键
- }
- return super.dispatchKeyEvent(event);
- }
- public HashMap<String, Object> getNotifyParam(){
- postData.put("tracking_number",trayMakeBean.getTrackingNumber().trim());
- postData.put("box_number",trayMakeBean.getBoxNumber().trim());
- postData.put("unit_code",etUnitCode.getText().toString().trim());
- return postData;
- }
- private static class FinishWorkAdapter extends BaseQuickAdapter<StorageRecordBean, BaseViewHolder> {
- public FinishWorkAdapter(List<StorageRecordBean> data){
- super(R.layout.item_card_intercept, data);
- }
- @Override
- protected void convert(BaseViewHolder helper, StorageRecordBean item) {
- helper.addOnClickListener(R.id.tv_status);//定义setOnItemChildClickListener 事件点击
- try {
- helper.setText(R.id.tv_order_no,item.getUnitCode());
- helper.getView(R.id.tv_location).setVisibility(View.GONE);
- helper.getView(R.id.tv_status).setVisibility(View.GONE);
- } catch (Exception e) {
- XLog.e("列表赋值错误",e);
- e.printStackTrace();
- }
- }
- }
- private void initAdapter(){
- emptyView = this.getLayoutInflater().inflate(R.layout.pager_empty, (ViewGroup) recyclerView.getParent(), false);
- errorView = this.getLayoutInflater().inflate(R.layout.pager_error, (ViewGroup) recyclerView.getParent(), false);
- notDataView = emptyView;
- mAdapter = new FinishWorkAdapter(tallyDataList);
- mAdapter.setEmptyView(emptyView);
- mAdapter.openLoadAnimation(BaseQuickAdapter.SCALEIN);
- recyclerView.setLayoutManager(new LinearLayoutManager(this));
- recyclerView.setAdapter(mAdapter);
- }
- //监听按键
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- XLog.e("监听按键:"+keyCode);XLog.e(event);
- if (scanBean.getIsBroadcast()==0 && StoTongJNI.getIns(mContext).getEventFuction(keyCode) == StoPdaKeyEvent.KEYCODE_SCAN
- && event.getRepeatCount() == 0) {
- if (StoTongJNI.getIns(mContext).GetScannerIsScanning()) {
- //
- } else {
- StoTongJNI.getIns(mContext).SetScannerStart();
- }
- }
- return super.onKeyDown(keyCode, event);
- }
- @SuppressLint("HandlerLeak")
- Handler scanHandler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- // TODO Auto-generated method stub
- if (msg.obj != null) {
- String scanResult = msg.obj.toString().trim();
- if (!scanResult.isEmpty()){
- setScanResult(scanResult);
- }
- }
- }
- };
- @Override
- public void onScanResults(String str) {
- Message msg = new Message();
- msg.obj = str;
- scanHandler.sendMessage(msg);
- }
- @Override
- public void onScanResults(String str, int type) {
- }
- /**
- * 定义广播接受
- */
- BroadcastReceiver mReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- String scanResult = intent.getStringExtra(scanBean.getDataName());
- if (scanResult==null){return; }
- String scanStatus = "";
- if (!scanBean.getStatusName().isEmpty()){
- scanStatus = intent.getStringExtra(scanBean.getStatusName());
- }else{
- scanStatus = scanResult.isEmpty()? "" : "ok"; //有值 默认是扫码成功;
- }
- //新大陆(MT65,MT90) 需要手动关闭
- if (!scanBean.getActionStop().isEmpty()){
- Intent stopIntent = new Intent(scanBean.getActionStop());
- mContext.sendBroadcast(stopIntent);
- }
- if ("ok".equals(scanStatus)){
- setScanResult(scanResult);
- }else{
- showErrorToast(getString(R.string.scan_failed));
- }
- }
- };
- /**
- * 注册广播
- */
- private void initReceiver(){
- try {
- String scanStr = getScanSetting();
- scanBean = JsonUtil.getObject(scanStr, ScanBean.class);
- Integer is_broadcast = scanBean.getIsBroadcast();//是否广播
- if (is_broadcast ==1){
- IntentFilter mFilter = new IntentFilter(scanBean.getAction());
- this.registerReceiver(mReceiver, mFilter);
- }else{
- //不广播进行处理 jni模式
- String pdaBrand = StoTongJNI.getmPdaBrand();
- if (!pdaBrand.isEmpty()){
- StoTongJNI.getIns(this).setmScanCB(this);
- StoTongJNI.getIns(this).SetScannerOn();
- }
- }
- }catch (Exception e) {
- showErrorToast("获取扫码配置失败"+e.getMessage());
- XLog.e("获取扫码配置失败:" + e.getMessage());
- }
- }
- private void initEdit() {
- List<EditText> list = new ArrayList<>();
- list.add(etUnitCode);
- unifyEdit(list);
- }
- //getAwaitNum
- private void totalAwaitNum(){
- int awaitNum = asyncPictureUpload.getAwaitNum();
- tvAwaitNum.setText(String.valueOf(awaitNum));
- if (awaitNum == 0){
- operateStopUpload();
- }
- }
- //统一按钮回调
- @SuppressLint("NonConstantResourceId")
- public void callbackEditor(View v){
- setNewTiming();
- switch (v.getId()) {
- case R.id.et_unit_code:
- checkUnitCode();
- break;
- default:
- }
- }
- /**
- * 统一设置Edit监听
- * @param list
- */
- public void unifyEdit(List<EditText> list){
- for (int i=0;i<list.size();i++){
- EditText editText = list.get(i);
- LinearLayout linearLayout = (LinearLayout)editText.getParent();
- ImageButton imageButton = getChildImageButton(linearLayout);
- //监听按确定
- editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
- @Override
- public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
- //XLog.e("actionId:"+actionId);
- if (actionId == EditorInfo.IME_ACTION_SEND || actionId == EditorInfo.IME_ACTION_DONE ) {
- if (v.getText().toString().trim().isEmpty()) {
- setEditTextFocused(v,true);
- showWarningToast(v.getHint().toString());
- return false;
- }else{
- setEditTextNormal(v,true);
- }
- callbackEditor(v);
- return false;
- }
- return false;
- }
- });
- editText.addTextChangedListener(new TextWatcher() {
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- EditText currentEditText = null;
- ImageButton currentImage = null;
- //获取焦点的view对象
- View view=getWindow().getDecorView().findFocus();
- //如果是EditText
- if(view instanceof EditText){
- currentEditText = (EditText) view;
- currentImage = getChildImageButton((LinearLayout)currentEditText.getParent());
- }
- if (s.length() > 0 ) {
- if (currentImage !=null ){
- currentImage.setVisibility(View.VISIBLE);
- }
- if (currentEditText!=null){
- setEditTextNormal(currentEditText,true);
- }
- } else {
- if (currentImage !=null ){
- currentImage.setVisibility(View.INVISIBLE);
- }
- if (currentEditText!=null && isRequiredShow){
- setEditTextFocused(currentEditText,true);
- }
- }
- }
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
- public void afterTextChanged(Editable s) {
- }
- });
- if (imageButton !=null ){
- unifyClearEdit(imageButton);
- }
- }
- }
- private OnRxScanerListener mScanerListener = new OnRxScanerListener() {
- @Override
- public void onSuccess(String type, Result result) {
- String scanResult = result.getText();
- switch (type){
- case BaseConfig.COMMON_SCANNER_ONLY:
- setScanResult(scanResult);
- break;
- }
- }
- @Override
- public void onFail(String type, String message) {
- }
- };
- //把扫描结果赋值
- private void setScanResult(String scanResult){
- //获取焦点的view对象
- View view=getWindow().getDecorView().findFocus();
- //如果是EditText
- if(view instanceof EditText)
- {
- ((EditText) view).setText(scanResult);
- showSuccessToast("扫描成功");
- callbackEditor(view);
- }
- }
- //检查是否存在上传
- private void checkIsUpload(){
- int awaitNum = asyncPictureUpload.getAwaitNum();
- if (currentUploadStatus && awaitNum>0){
- operateStartUpload();
- }
- }
- //设置返回
- private void setRequestResult(){
- tallyDataList.clear();
- tallyDataList = trayMakeBean.getZuijinNums();
- mtOperateNumber.setText(String.valueOf(trayMakeBean.getHasDoDui()));
- mtTrackingNumber.setText(trayMakeBean.getTrackingNumber());
- mtContentsNumber.setText(String.valueOf(trayMakeBean.getBenBoxQty()));
- mtBoxNumber.setText(trayMakeBean.getBoxNumber());
- llBoxNumber.setVisibility(View.VISIBLE);
- llContentsNumber.setVisibility(View.VISIBLE);
- mAdapter.setNewData(tallyDataList);
- mAdapter.notifyDataSetChanged();
- }
- private void checkUnitCode(){
- checkIsUpload();
- if (etUnitCode.getText().toString().isEmpty()){
- showErrorToast(etUnitCode.getHint().toString());
- return;
- }
- Gson gson = new Gson();
- Map<String,Object> math = new HashMap<>();
- math.put("tracking_number",trayMakeBean.getTrackingNumber().trim());
- math.put("box_number",trayMakeBean.getBoxNumber().trim());
- math.put("unit_code",etUnitCode.getText().toString().trim());
- math.put("is_check",1);
- math.put("ab_img_id",abImgId);
- OkGo.<String>post(Urls.getServiceAddress(this) + Urls.FXY_DETECTION_PALLET_BOX_UNIT).upJson(gson.toJson(math))
- .execute(new MyDialogCallback(this, true, false) {
- @Override
- public void onSuccess(Response<String> response) {
- super.onSuccess(response);
- try {
- ActionBean bean = JsonUtil.getObject(response.body(), ActionBean.class);
- trayMakeBean = new TrayMakeBean();
- if (bean.data!=null && !bean.data.isEmpty() && !bean.data.equals("[]")){
- trayMakeBean = JsonUtil.jsonString2Bean(bean.data,TrayMakeBean.class);
- setRequestResult();
- }
- String voiceName = trayMakeBean.getVoiceName();
- if(bean.code == 1){
- showSuccessToast(bean.msg,voiceName);
- initFinish();
- }else{
- showWarningToast(bean.msg,voiceName);
- }
- }catch (Exception e) {
- e.printStackTrace();
- XLog.e("第二步确认错误",e.getMessage());
- }
- }
- });
- }
- //提交内件码
- private void finishInbound(){
- isRequiredShow = true;
- if (!validate()){
- return;
- }
- OkGo.<String>post(Urls.getServiceAddress(this) + Urls.FXY_DETECTION_PUTIN).upJson(postParam)
- .execute(new MyDialogCallback(this, true, false) {
- @Override
- public void onSuccess(Response<String> response) {
- super.onSuccess(response);
- try {
- ActionBean bean = JsonUtil.getObject(response.body(), ActionBean.class);
- if(bean.code == 1){
- showSuccessToast(bean.msg);
- if (bean.data!=null && !bean.data.isEmpty() && !bean.data.equals("[]")){
- trayMakeBean = JsonUtil.jsonString2Bean(bean.data,TrayMakeBean.class);
- setRequestResult();
- }
- initFinish();
- }else{
- showWarningToast(bean.msg);
- }
- } catch (Exception e) {
- e.printStackTrace();
- XLog.e("添加开箱拆柜数据结果返回错误",e.getMessage());
- }
- }
- });
- }
- private void initFinish(){
- etUnitCode.setText("");
- etUnitCode.requestFocus();
- llConfirm.setVisibility(View.VISIBLE);
- }
- /*
- * 校验必录
- */
- private boolean validate(){
- if (etUnitCode.getText().toString().isEmpty()){
- showWarningToast(etUnitCode.getHint().toString());
- return false;
- }
- try {
- postParam = new JSONObject();
- Gson gson = new Gson();
- postParam.put("box_number",trayMakeBean.getBoxNumber().trim());
- postParam.put("tracking_number",trayMakeBean.getTrackingNumber().trim());
- postParam.put("unit_code",etUnitCode.getText().toString().trim());
- postParam.put("is_check",1);
- postParam.put("ab_img_id",abImgId);
- } catch (JSONException e) {
- showWarningToast("系统异常"+e.getMessage());
- e.printStackTrace();
- return false;
- }
- return true;
- }
- //sIsGoodinfoMatch,sIsBattery,sIsMagnetic,sIsWood,sIsExtra,sIsOther
- @SuppressLint("NonConstantResourceId")
- @OnClick({R.id.btn_confirm})
- public void onViewClicked(View view) {
- Bundle bundle = new Bundle();
- switch (view.getId()) {
- case R.id.btn_confirm:
- Intent intent = new Intent();
- setResult(200, intent);//返回值,2 是改返回的标志,也会返回
- showSuccessToast("success");
- intent.putExtra("data",(new Gson()).toJson(trayMakeBean));
- finish();
- break;
- default:
- break;
- }
- }
- private void operateStopUpload(){
- if (currentUploadStatus){
- asyncPictureUpload.setStopUpload();
- }
- }
- private void operateStartUpload(){
- if (!currentUploadStatus){
- asyncPictureUpload.setStartUpload();
- }
- }
- @Override
- protected void onDestroy() {
- unbinder.unbind();
- asyncPictureUpload.removeHandler();
- // 确保清除所有的回调以防止内存泄漏
- workHandler.removeCallbacks(idleRunnable);
- super.onDestroy();
- }
- @Override
- protected void onResume() {
- super.onResume();
- initReceiver();
- }
- @Override
- protected void onPause() {
- super.onPause();
- //销毁在onResume()方法中的广播
- try {
- //停止扫描
- Integer is_broadcast = scanBean.getIsBroadcast();//是否广播
- if (is_broadcast==0){
- StoTongJNI.getIns(mContext).SetScannerStop();
- StoTongJNI.getIns(mContext).SetScannerOff();
- }else{
- unregisterReceiver(mReceiver);
- }
- }catch (Exception e){
- XLog.e("销毁广播失败:",e.getMessage());
- }
- }
- }
|