From c428464f454f6ec9e8af109e1a56e3942c8795c2 Mon Sep 17 00:00:00 2001 From: wangh <123456> Date: Fri, 24 May 2024 13:42:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E7=BD=91=E7=BB=9C=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 35 ++++++---- .../example/jinyu_rfid/AppLoginActivity.java | 12 ++-- .../com/example/jinyu_rfid/ReadActivity.java | 66 +++++++++++++++++-- .../example/jinyu_rfid/WriteUserActivity.java | 44 ++++++------- .../jinyu_rfid/been/ReadTyreNoResult.java | 18 ++++- .../example/jinyu_rfid/rfid/C5106Device.java | 6 ++ .../example/jinyu_rfid/rfid/RFIDModel.java | 1 + app/src/main/res/layout/activity_read.xml | 44 ++++++++++++- app/src/main/res/values-en-rUS/strings.xml | 1 + app/src/main/res/values-vi-rVN/strings.xml | 1 + app/src/main/res/values/strings.xml | 3 +- 11 files changed, 179 insertions(+), 52 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 75966ef..4a921bf 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -13,35 +13,42 @@ android:supportsRtl="true" android:theme="@style/Theme.JinYuRFID" tools:targetApi="31"> - - - - - - + + + + + + + + + android:exported="true" /> + android:exported="true"> + + + + + - - - - + + + + diff --git a/app/src/main/java/com/example/jinyu_rfid/AppLoginActivity.java b/app/src/main/java/com/example/jinyu_rfid/AppLoginActivity.java index addb279..0c8a41e 100644 --- a/app/src/main/java/com/example/jinyu_rfid/AppLoginActivity.java +++ b/app/src/main/java/com/example/jinyu_rfid/AppLoginActivity.java @@ -7,6 +7,7 @@ import android.content.Intent; import android.content.res.Configuration; import android.content.res.Resources; import android.os.Bundle; +import android.util.Log; import android.view.View; import com.example.jinyu_rfid.databinding.ActivityAppLoginBinding; @@ -42,15 +43,18 @@ public class AppLoginActivity extends AppCompatActivity { // 工作模式 0=net var workModeStr = binding.mainWork.getSelectedItem().toString(); var strings = Arrays.asList(getResources().getStringArray(R.array.work_mode)); - SharedPreferencesUtils.putInt("workmode", strings.indexOf(workModeStr)); + var value = strings.indexOf(workModeStr); + SharedPreferencesUtils.putInt("workmode", value); // 选择语言 var s = binding.appLanguage.getSelectedItem().toString(); SharedPreferencesUtils.putstring("language", s); getLocaleStringXML(s); resources.updateConfiguration(config, resources.getDisplayMetrics()); - - - startActivity(new Intent(this, ReadActivity.class)); + // + var intent = new Intent(this, ReadActivity.class); + Log.e("TAG", "appLoginClick:" + value); + intent.putExtra("work",value); + startActivity(intent); finish(); } diff --git a/app/src/main/java/com/example/jinyu_rfid/ReadActivity.java b/app/src/main/java/com/example/jinyu_rfid/ReadActivity.java index 72f58ee..e084d88 100644 --- a/app/src/main/java/com/example/jinyu_rfid/ReadActivity.java +++ b/app/src/main/java/com/example/jinyu_rfid/ReadActivity.java @@ -6,47 +6,94 @@ import android.annotation.SuppressLint; import android.os.Bundle; import android.util.Log; import android.view.View; +import android.widget.Toast; import com.example.jinyu_rfid.adapter.ResultAdapter; import com.example.jinyu_rfid.base.BaseActivity; +import com.example.jinyu_rfid.base.MyRecultCall; +import com.example.jinyu_rfid.base.MyResult; import com.example.jinyu_rfid.been.ReadTyreNoResult; import com.example.jinyu_rfid.callback.DataReturnCall; import com.example.jinyu_rfid.databinding.ActivityReadBinding; import com.example.jinyu_rfid.rfid.C5106Device; import com.example.jinyu_rfid.rfid.RFIDModel; import com.example.jinyu_rfid.uitls.ASCIIUtil; +import com.google.gson.reflect.TypeToken; +import com.lzy.okgo.OkGo; +import com.lzy.okgo.model.Response; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; + +import okhttp3.RequestBody; public class ReadActivity extends BaseActivity implements DataReturnCall { private ResultAdapter adapter; private RFIDModel rfidModel; private String[] stringArray; private List list; + private ActivityReadBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - ActivityReadBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_read); + + binding = DataBindingUtil.setContentView(this, R.layout.activity_read); binding.setTitle(getString(R.string.go_read)); adapter = new ResultAdapter(this); + list = new ArrayList<>(11); + adapter.setList(list); binding.setAdapter(adapter); - // 名称 + var workmode = getIntent().getIntExtra("work", 0); + binding.setType(workmode == 1); + + // 名称 stringArray = getResources().getStringArray(R.array.project_list); rfidModel = new C5106Device(this); - list = new ArrayList<>(11); - adapter.setList(list); + } public void readInfo(View view) { rfidModel.sanUser(80); } + public void readEPCInfo(View view) { + rfidModel.sanEpc(6); + } + @SuppressLint("NotifyDataSetChanged") @Override public void readEpcCodeInfo(String info, boolean state, String stateInfo) { + if (state) { + music.start(); + list.clear(); + binding.readText.setText(info); + Map map = new HashMap<>(); + map.put("EpcCode", info); + map.put("token", "123456"); + OkGo.post(url + "/readEPCCode") + .upRequestBody(RequestBody.create(JSON, gson.toJson(map))).execute(new MyRecultCall(dialog, this) { + + @Override + public void onSuccess(Response response) { + super.onSuccess(response); + var body = response.body(); + if (body.getResultFlag().equals("1")) { + list.addAll(gson.fromJson(body.getJson(),new TypeToken>(){}.getType())); + adapter.notifyDataSetChanged(); + } else { + Toast.makeText(ReadActivity.this, body.getJson(), Toast.LENGTH_SHORT).show(); + adapter.notifyDataSetChanged(); + } + } + }); + + }else { + binding.readText.setText(null); + } } @SuppressLint("NotifyDataSetChanged") @@ -54,16 +101,23 @@ public class ReadActivity extends BaseActivity implements DataReturnCall { public void readUserInfo(String user, boolean state, String stateInfo) { list.clear(); if (state) { + binding.readText.setText(user); music.start(); String info = ASCIIUtil.hex2Str(user); Log.e("TAG", "readUserInfo:" + info); var infos = info.split("~"); for (int i = 0; i < 12; i++) { - list.add( new ReadTyreNoResult(i,stringArray[i],infos[i])); + list.add(new ReadTyreNoResult(i, stringArray[i], infos[i])); } + }else { + binding.readText.setText(null); } adapter.notifyDataSetChanged(); } - + @Override + protected void onDestroy() { + super.onDestroy(); + rfidModel.close(); + } } \ No newline at end of file diff --git a/app/src/main/java/com/example/jinyu_rfid/WriteUserActivity.java b/app/src/main/java/com/example/jinyu_rfid/WriteUserActivity.java index 6e165a2..11e0795 100644 --- a/app/src/main/java/com/example/jinyu_rfid/WriteUserActivity.java +++ b/app/src/main/java/com/example/jinyu_rfid/WriteUserActivity.java @@ -52,6 +52,7 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P binding = DataBindingUtil.setContentView(this, R.layout.activity_write_user); rfidModel = new C5106Device(this); intent1 = new Intent(this, ReadActivity.class); + intent1.putExtra("work", 1); intent2 = new Intent(this, ConfigurationTableActivity.class); ScanERCodeReceiver scanERCodeReceiver = new ScanERCodeReceiver(this); registerReceiver(scanERCodeReceiver, new IntentFilter("com.rfid.SCAN")); @@ -70,6 +71,7 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P private boolean writeUserState = false; // 写入 + @SuppressLint("NotifyDataSetChanged") public void writeUser(View view) { if (list == null || list.isEmpty()) return; var epcStr = binding.writeEpcCode.getText().toString(); @@ -81,14 +83,6 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P for (int i = 1; i < 12; i++) { var configuration = tagList.get(i); var state = configuration.isState(); - - /* if (state) { - Optional optionalResult = Optional.ofNullable(list.get(i - 1)); - String propertyContent = optionalResult.map(ReadTyreNoResult::getPropertyContent).orElse("_"); - tagUserStr.append(propertyContent); - } else { - tagUserStr.append("_"); - }*/ if (state) { try { var result = list.get(i - 1); @@ -105,12 +99,7 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P String user = ASCIIUtil.str2Hex(tagUserStr.toString()); if (!writeUserState) { - Log.e("TAG", "writeUser:" + 1); - writeUserState = rfidModel.writeUser(validateDataLength(user), epcStr); - Toast.makeText(context, getString(writeUserState ? R.string.write_success : R.string.write_failed), Toast.LENGTH_SHORT).show(); - } - - if (writeUserState) { + Log.e("TAG", "请求"); Map map = new HashMap<>(); map.put("EpcCode", epcStr); map.put("TyreNo", list.get(0).getPropertyContent()); @@ -123,12 +112,8 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P super.onSuccess(response); var body = response.body(); if (body.getSaveFlag().equals("1")) { - list.clear(); - adapter.notifyDataSetChanged(); - binding.writeEpcCode.setText(null); - binding.writeTire.setText(null); Toast.makeText(WriteUserActivity.this, getString(R.string.binding_success), Toast.LENGTH_SHORT).show(); - writeUserState = false; + writeUserState = true; return; } Toast.makeText(WriteUserActivity.this, body.getSaveMessage(), Toast.LENGTH_SHORT).show(); @@ -136,7 +121,18 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P }); } - + if (writeUserState){ + Log.e("TAG", "写入"); + var writeState = rfidModel.writeUser(validateDataLength(user), epcStr); + Toast.makeText(context, getString(writeState ? R.string.write_success : R.string.write_failed), Toast.LENGTH_SHORT).show(); + if (writeState) { + list.clear(); + adapter.notifyDataSetChanged(); + binding.writeEpcCode.setText(null); + binding.writeTire.setText(null); + writeUserState=false; + } + } } @@ -157,8 +153,6 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P } - - @Override public void readEpcCodeInfo(String info, boolean state, String stateInfo) { if (state) { @@ -196,7 +190,11 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P } }); } - public void writeGoMenu(View view) {popupMenu.show();} + + public void writeGoMenu(View view) { + popupMenu.show(); + } + @Override public boolean onMenuItemClick(MenuItem item) { if (item.getItemId() == R.id.menu_read) { diff --git a/app/src/main/java/com/example/jinyu_rfid/been/ReadTyreNoResult.java b/app/src/main/java/com/example/jinyu_rfid/been/ReadTyreNoResult.java index aab53e6..83e2921 100644 --- a/app/src/main/java/com/example/jinyu_rfid/been/ReadTyreNoResult.java +++ b/app/src/main/java/com/example/jinyu_rfid/been/ReadTyreNoResult.java @@ -11,7 +11,7 @@ public class ReadTyreNoResult { "PropertyContent": "32432040640", "PropertyIndex": 1 */ - private String PropertyName, PropertyContent; + private String PropertyName, PropertyContent,IsShow; private int PropertyIndex; public ReadTyreNoResult() { @@ -21,6 +21,22 @@ public class ReadTyreNoResult { PropertyName = propertyName; PropertyContent = propertyContent; PropertyIndex = propertyIndex; + IsShow="1"; + } + + public ReadTyreNoResult(String propertyName, String propertyContent, String isShow, int propertyIndex) { + PropertyName = propertyName; + PropertyContent = propertyContent; + IsShow = isShow; + PropertyIndex = propertyIndex; + } + + public String getIsShow() { + return IsShow; + } + + public void setIsShow(String isShow) { + IsShow = isShow; } public String getPropertyName() { diff --git a/app/src/main/java/com/example/jinyu_rfid/rfid/C5106Device.java b/app/src/main/java/com/example/jinyu_rfid/rfid/C5106Device.java index 2e550a7..e1bc3b0 100644 --- a/app/src/main/java/com/example/jinyu_rfid/rfid/C5106Device.java +++ b/app/src/main/java/com/example/jinyu_rfid/rfid/C5106Device.java @@ -71,4 +71,10 @@ public class C5106Device implements RFIDModel { Reader.READER_ERR readerErr = uhfrManager.getTagData(3, 0, len, rdata, accessBytes, (short) 200); call.readUserInfo(Tools.Bytes2HexString(rdata, rdata.length), readerErr == Reader.READER_ERR.MT_OK_ERR, readerErr.toString()); } + + @Override + public void close() { + if (uhfrManager != null) + uhfrManager.close(); + } } diff --git a/app/src/main/java/com/example/jinyu_rfid/rfid/RFIDModel.java b/app/src/main/java/com/example/jinyu_rfid/rfid/RFIDModel.java index a905bb8..2d391de 100644 --- a/app/src/main/java/com/example/jinyu_rfid/rfid/RFIDModel.java +++ b/app/src/main/java/com/example/jinyu_rfid/rfid/RFIDModel.java @@ -10,4 +10,5 @@ public interface RFIDModel { boolean writeUser(String writeStr, String tagEpc); void sanUser(int len); + void close(); } diff --git a/app/src/main/res/layout/activity_read.xml b/app/src/main/res/layout/activity_read.xml index 94256ec..027201c 100644 --- a/app/src/main/res/layout/activity_read.xml +++ b/app/src/main/res/layout/activity_read.xml @@ -8,9 +8,16 @@ + + + + + + + + + + + +