From 6d2031f1a43cb2dee1310d164e13a78525039063 Mon Sep 17 00:00:00 2001 From: wanghao Date: Fri, 27 Sep 2024 17:04:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=20=E6=8A=A5=E5=BA=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/beijing_daxing/BFActivity.java | 91 ++++++++++++++----- .../example/beijing_daxing/CheckActivity.java | 5 +- .../example/beijing_daxing/FpInActivity.java | 5 +- .../example/beijing_daxing/FpOutActivity.java | 9 +- .../beijing_daxing/base/BaseActivity.java | 10 +- .../com/example/beijing_daxing/vm/BFWm.java | 42 +++++++++ .../main/res/layout/activity_bfactivity.xml | 68 +++++++++++++- app/src/main/res/values/array.xml | 8 ++ 8 files changed, 195 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/com/example/beijing_daxing/BFActivity.java b/app/src/main/java/com/example/beijing_daxing/BFActivity.java index d7f34a7..a51f552 100644 --- a/app/src/main/java/com/example/beijing_daxing/BFActivity.java +++ b/app/src/main/java/com/example/beijing_daxing/BFActivity.java @@ -1,9 +1,8 @@ package com.example.beijing_daxing; -import androidx.appcompat.app.AppCompatActivity; import androidx.databinding.DataBindingUtil; -import androidx.databinding.ViewDataBinding; +import android.graphics.Bitmap; import android.os.Bundle; import android.view.View; import android.widget.Toast; @@ -13,46 +12,61 @@ import com.example.beijing_daxing.base.MyRecultCall; import com.example.beijing_daxing.base.MyResult; import com.example.beijing_daxing.been.LedgerRfid; import com.example.beijing_daxing.databinding.ActivityBfactivityBinding; +import com.example.beijing_daxing.dialog.TakePictureDialog; +import com.example.beijing_daxing.uitls.HexAscii; import com.example.beijing_daxing.uitls.SharedPreferencesUtils; import com.example.beijing_daxing.vm.BFWm; import com.lzy.okgo.OkGo; import com.lzy.okgo.model.Response; import com.uhf.api.cls.Reader; +import java.io.File; +import java.util.ArrayList; import java.util.List; import cn.pda.serialport.Tools; -public class BFActivity extends BaseActivity { +public class BFActivity extends BaseActivity implements TakePictureDialog.dialogReturnListSizeCall { private BFWm wm; + private TakePictureDialog takeDialog; + private List files; + private List bitmaps; + + private ActivityBfactivityBinding dataBinding; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - ActivityBfactivityBinding dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_bfactivity); - wm=new BFWm(); + dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_bfactivity); + wm = new BFWm(); + wm.setList(List.of(getResources().getStringArray(R.array.bfyy))); dataBinding.setVm(wm); - setPower(17); + takeDialog = new TakePictureDialog(this); + takeDialog.setCall(this); + setPower(SharedPreferencesUtils.getInt("powerScrap", 17)); + bitmaps = new ArrayList<>(); + files = new ArrayList<>(); } @Override protected void sanRfid(List epcs) { var epc = epcs.get(0); byte[] epcId = epc.EpcId; - String epc1 = Tools.Bytes2HexString(epcId, epcId.length); + String epc1 = HexAscii.hex2Str(Tools.Bytes2HexString(epcId, epcId.length)); wm.setEpc(epc1); - OkGo.post(url+"/bf/select") + OkGo.post(url + "/bf/select") .tag(this) - .params("epc",epc1) - .execute(new MyRecultCall(dialog,this){ + .params("epc", epc1) + .execute(new MyRecultCall(dialog, this) { @Override public void onSuccess(Response response) { super.onSuccess(response); var body = response.body(); - if (body.getCode()==0){ - LedgerRfid ledgerRfid=gson.fromJson(body.getData().toString(),LedgerRfid.class); + if (body.getCode() == 0) { + LedgerRfid ledgerRfid = gson.fromJson(body.getData().toString(), LedgerRfid.class); wm.setPcode(ledgerRfid.getBatchCode()); wm.setState(ledgerRfid.getDictLabel()); - }else { + } else { wm.clearText(); Toast.makeText(BFActivity.this, body.getMsg(), Toast.LENGTH_SHORT).show(); } @@ -61,28 +75,57 @@ public class BFActivity extends BaseActivity { }); } - public void bf_submit(View view){ - if (wm.getState().equals("正常")){ - OkGo.post(url+"/bf/submit") - .params("epc",wm.getEpc()) - .params("remark",wm.getRemark()) - .params("user", SharedPreferencesUtils.getstring("user","test-user")) - .execute(new MyRecultCall(dialog,this){ + public void bfTackPhoto(View view) { + takePhoto(); + } + + public void bfShowPhoto(View view) { + takeDialog.setBitmaps(bitmaps, files); + takeDialog.show(); + } + + public void bf_submit(View view) { + String state = wm.getState(); + if (state==null ) return; + if ( state.equals("正常")) { + String reason = wm.getReason(); + String remark = wm.getRemark(); + if (reason.equals("其他") && remark ==null ) return; + OkGo.post(url + "/bf/submit") + .params("epc", wm.getEpc()) + .params("reason", reason) + .params("remark", remark) + .params("user", SharedPreferencesUtils.getstring("user", "")) + .addFileParams("files",files) + .execute(new MyRecultCall(dialog, this) { @Override public void onSuccess(Response response) { super.onSuccess(response); var body = response.body(); - if (body.getCode()==0){ + if (body.getCode() == 0) { Toast.makeText(BFActivity.this, "提交成功", Toast.LENGTH_SHORT).show(); + files.forEach(File::delete); finish(); - }else { - Toast.makeText(BFActivity.this,body.getMsg(), Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(BFActivity.this, body.getMsg(), Toast.LENGTH_SHORT).show(); } } }); - }else { + } else { Toast.makeText(this, "轮挡已报废,无需操作", Toast.LENGTH_SHORT).show(); } } + + @Override + public void returnListSize(int size) { + dataBinding.bfPictureNumber.setText(bitmaps.size() + ""); + } + + @Override + public void takePhotoCall(File outputImage, Bitmap bitmap) { + files.add(outputImage); + bitmaps.add(bitmap); + dataBinding.bfPictureNumber.setText(bitmaps.size() + ""); + } } \ No newline at end of file diff --git a/app/src/main/java/com/example/beijing_daxing/CheckActivity.java b/app/src/main/java/com/example/beijing_daxing/CheckActivity.java index 297dd80..1a997b9 100644 --- a/app/src/main/java/com/example/beijing_daxing/CheckActivity.java +++ b/app/src/main/java/com/example/beijing_daxing/CheckActivity.java @@ -11,7 +11,6 @@ import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.View; -import android.widget.AdapterView; import android.widget.Toast; import com.example.beijing_daxing.adapter.CheckAdapter; @@ -32,9 +31,7 @@ import com.uhf.api.cls.Reader; import java.io.File; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; import cn.pda.serialport.Tools; @@ -223,7 +220,7 @@ public class CheckActivity extends BaseActivity implements AdapterClickCall, InP // 拍照 public void check_tackPhoto(View view) { - teke_photo(); + takePhoto(); } // 显示拍的照片 diff --git a/app/src/main/java/com/example/beijing_daxing/FpInActivity.java b/app/src/main/java/com/example/beijing_daxing/FpInActivity.java index 69f1374..f0c1b52 100644 --- a/app/src/main/java/com/example/beijing_daxing/FpInActivity.java +++ b/app/src/main/java/com/example/beijing_daxing/FpInActivity.java @@ -13,6 +13,7 @@ import com.example.beijing_daxing.base.MyRecultCall; import com.example.beijing_daxing.base.MyResult; import com.example.beijing_daxing.been.LedgerRfid; import com.example.beijing_daxing.databinding.ActivityFpInBinding; +import com.example.beijing_daxing.uitls.HexAscii; import com.example.beijing_daxing.uitls.SharedPreferencesUtils; import com.example.beijing_daxing.vm.FpInVm; import com.lzy.okgo.OkGo; @@ -32,13 +33,13 @@ public class FpInActivity extends BaseActivity { ActivityFpInBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_fp_in); vm = new FpInVm(); binding.setVm(vm); - setPower(17); + setPower(SharedPreferencesUtils.getInt("powerScrapIn",17)); } @Override protected void sanRfid(List epcs) { Reader.TAGINFO taginfo = epcs.get(0); - var epc = Tools.Bytes2HexString(taginfo.EpcId,taginfo.EpcId.length); + var epc = HexAscii.hex2Str(Tools.Bytes2HexString(taginfo.EpcId,taginfo.EpcId.length)); vm.setEpc(epc); OkGo.post(url+"/fpin/select") .tag(this).params("epc",epc) diff --git a/app/src/main/java/com/example/beijing_daxing/FpOutActivity.java b/app/src/main/java/com/example/beijing_daxing/FpOutActivity.java index e87d253..4ccc6ca 100644 --- a/app/src/main/java/com/example/beijing_daxing/FpOutActivity.java +++ b/app/src/main/java/com/example/beijing_daxing/FpOutActivity.java @@ -19,6 +19,7 @@ import com.example.beijing_daxing.base.MyRecultCall; import com.example.beijing_daxing.base.MyResult; import com.example.beijing_daxing.been.Stock; import com.example.beijing_daxing.databinding.ActivityFpOutBinding; +import com.example.beijing_daxing.uitls.HexAscii; import com.example.beijing_daxing.uitls.SharedPreferencesUtils; import com.google.gson.reflect.TypeToken; import com.lzy.okgo.OkGo; @@ -42,8 +43,9 @@ public class FpOutActivity extends BaseActivity { binding.setCheckState(checkState); adapter = new OutAdapter(this); binding.setAdapter(adapter); + tagList=new ArrayList<>(); initRequest(); - setPower(17); + setPower(SharedPreferencesUtils.getInt("powerScrapOut",17)); } private List tagList; @@ -53,11 +55,11 @@ public class FpOutActivity extends BaseActivity { epcs.forEach(t -> { var epc = Tools.Bytes2HexString(t.EpcId,t.EpcId.length); if (tagList.contains(epc)){ - tagList.add(epc); return; } + tagList.add(epc); var stock = new Stock(); - stock.setEpcCode(epc); + stock.setEpcCode(HexAscii.hex2Str(epc)); var index = list.indexOf(stock); if (index != -1) { list.get(index).setState("Y"); @@ -74,7 +76,6 @@ public class FpOutActivity extends BaseActivity { if (body.getCode() == 0) { list = gson.fromJson(body.getData().toString(), new TypeToken>() { }.getType()); - tagList=new ArrayList<>(); adapter.setList(list); adapter.notifyDataSetChanged(); } else { diff --git a/app/src/main/java/com/example/beijing_daxing/base/BaseActivity.java b/app/src/main/java/com/example/beijing_daxing/base/BaseActivity.java index 1ccfcc3..6cb68e1 100644 --- a/app/src/main/java/com/example/beijing_daxing/base/BaseActivity.java +++ b/app/src/main/java/com/example/beijing_daxing/base/BaseActivity.java @@ -4,7 +4,6 @@ import android.Manifest; import android.annotation.SuppressLint; import android.app.ProgressDialog; import android.content.BroadcastReceiver; -import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; @@ -17,9 +16,7 @@ import android.os.Build; import android.os.Bundle; import android.provider.MediaStore; import android.util.Log; -import android.view.KeyEvent; import android.view.Window; -import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; @@ -36,7 +33,6 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; -import java.io.InputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; @@ -44,7 +40,7 @@ import java.util.List; import okhttp3.MediaType; public abstract class BaseActivity extends AppCompatActivity { - public static String url = "http://192.168.0.102:8090/api"; + public static String url = "http://192.168.137.1:8090/api"; // public static String url = "http://119.45.202.115:8090/api"; public ProgressDialog dialog; public Gson gson; @@ -140,7 +136,7 @@ public abstract class BaseActivity extends AppCompatActivity { public SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss"); // 拍照 - public void teke_photo() { + public void takePhoto() { if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1); } @@ -182,7 +178,7 @@ public abstract class BaseActivity extends AppCompatActivity { Log.e("TAG", "onActivityResult:" + img_uri.getPath()); bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(img_uri)); FileOutputStream outputStream = new FileOutputStream(outputImage); - bitmap.compress(Bitmap.CompressFormat.JPEG, 70, outputStream); + bitmap.compress(Bitmap.CompressFormat.JPEG, 50, outputStream); takePhotoCall(outputImage, bitmap); outputStream.close(); } catch (FileNotFoundException e) { diff --git a/app/src/main/java/com/example/beijing_daxing/vm/BFWm.java b/app/src/main/java/com/example/beijing_daxing/vm/BFWm.java index 574f38b..be3a3b9 100644 --- a/app/src/main/java/com/example/beijing_daxing/vm/BFWm.java +++ b/app/src/main/java/com/example/beijing_daxing/vm/BFWm.java @@ -1,7 +1,12 @@ package com.example.beijing_daxing.vm; +import android.view.View; +import android.widget.AdapterView; + import androidx.databinding.BaseObservable; +import java.util.List; + /** * @author wanghao * @date 2024/1/25 16:59 @@ -10,8 +15,38 @@ public class BFWm extends BaseObservable { private String epc; private String pcode; private String state; + private String reason; private String remark; + private List list; + private boolean editState; + + + public String getReason() { + return reason; + } + + public void setReason(String reason) { + this.reason = reason; + } + + public List getList() { + return list; + } + + public void setList(List list) { + this.list = list; + } + + public boolean isEditState() { + return editState; + } + + public void setEditState(boolean editState) { + this.editState = editState; + notifyChange(); + } + public String getRemark() { return remark; } @@ -51,4 +86,11 @@ public class BFWm extends BaseObservable { state = remark = pcode = null; notifyChange(); } + + + public void itemSelect(AdapterView parent, View view, int position, long id){ + String s = list.get(position); + setEditState(s.equals("其他")); + setReason(s); + } } diff --git a/app/src/main/res/layout/activity_bfactivity.xml b/app/src/main/res/layout/activity_bfactivity.xml index 518e9c1..0d57107 100644 --- a/app/src/main/res/layout/activity_bfactivity.xml +++ b/app/src/main/res/layout/activity_bfactivity.xml @@ -7,6 +7,7 @@ + + android:text="选择原因:" /> + + + + + + + + + +