From 3aab607a3f0fc6cce26073e88a9da6a27c862936 Mon Sep 17 00:00:00 2001 From: wanghao Date: Wed, 16 Oct 2024 21:55:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=20handehuoe=E9=A9=B1?= =?UTF-8?q?=E5=8A=A8=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 2 +- .../example/beijing_daxing/BFActivity.java | 15 ++++- .../example/beijing_daxing/CheckActivity.java | 16 ++++- .../example/beijing_daxing/FpInActivity.java | 15 +++++ .../example/beijing_daxing/FpOutActivity.java | 10 +++- .../beijing_daxing/HomePageActivity.java | 15 ++--- .../example/beijing_daxing/InActivity.java | 9 ++- .../example/beijing_daxing/OutActivity.java | 10 ++++ .../beijing_daxing/StoreCheckActivity.java | 6 ++ .../beijing_daxing/base/BaseActivity.java | 15 +---- .../beijing_daxing/base/MyApplication.java | 26 ++++---- .../com/example/beijing_daxing/rfid/RFID.java | 10 ---- .../beijing_daxing/rfid/impl/Device6109.java | 60 ------------------- 13 files changed, 101 insertions(+), 108 deletions(-) delete mode 100644 app/src/main/java/com/example/beijing_daxing/rfid/RFID.java delete mode 100644 app/src/main/java/com/example/beijing_daxing/rfid/impl/Device6109.java diff --git a/app/build.gradle b/app/build.gradle index e972357..7f06bc2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -16,7 +16,7 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" ndk { // 设置支持的SO库架构 - abiFilters 'arm64-v8a' , 'armeabi' , 'armeabi-v7a' + abiFilters 'arm64-v8a' , 'armeabi' , 'armeabi-v7a' } } 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 a51f552..7dfe18c 100644 --- a/app/src/main/java/com/example/beijing_daxing/BFActivity.java +++ b/app/src/main/java/com/example/beijing_daxing/BFActivity.java @@ -43,10 +43,23 @@ public class BFActivity extends BaseActivity implements TakePictureDialog.dialog dataBinding.setVm(wm); takeDialog = new TakePictureDialog(this); takeDialog.setCall(this); - setPower(SharedPreferencesUtils.getInt("powerScrap", 17)); bitmaps = new ArrayList<>(); files = new ArrayList<>(); } + @Override + protected void onResume() { + super.onResume(); + setPower(SharedPreferencesUtils.getInt("powerScrapIn",17)); + uhfLongerManager.setGen2session(true); + uhfLongerManager.asyncStartReading(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + uhfLongerManager.setGen2session(false); + uhfLongerManager.asyncStopReading(); + } @Override protected void sanRfid(List epcs) { 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 1a997b9..f429bf9 100644 --- a/app/src/main/java/com/example/beijing_daxing/CheckActivity.java +++ b/app/src/main/java/com/example/beijing_daxing/CheckActivity.java @@ -194,8 +194,12 @@ public class CheckActivity extends BaseActivity implements AdapterClickCall, InP public void offCheckRead(View view) { var b = checkState.get(); if (b) { + uhfLongerManager.setGen2session(false); + uhfLongerManager.asyncStopReading(); handler.removeCallbacks(runnable); } else { + uhfLongerManager.setGen2session(true); + uhfLongerManager.asyncStartReading(); handler.postDelayed(runnable, 0); } checkState.set(!b); @@ -214,7 +218,7 @@ public class CheckActivity extends BaseActivity implements AdapterClickCall, InP public void run() { // sendBroadcast(broadcastIntent); sanEpc(); - handler.postDelayed(runnable, 1000); + handler.postDelayed(runnable, 50); } }; @@ -243,4 +247,14 @@ public class CheckActivity extends BaseActivity implements AdapterClickCall, InP public void returnListSize(int size) { binding.confirmPictureNumber2.setText(bitmaps.size() + ""); } + + @Override + protected void onDestroy() { + super.onDestroy(); + handler.removeCallbacks(runnable); + uhfLongerManager.setGen2session(false); + uhfLongerManager.asyncStopReading(); + handler = null; + runnable = null; + } } \ No newline at end of file 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 f0c1b52..c113919 100644 --- a/app/src/main/java/com/example/beijing_daxing/FpInActivity.java +++ b/app/src/main/java/com/example/beijing_daxing/FpInActivity.java @@ -33,7 +33,22 @@ public class FpInActivity extends BaseActivity { ActivityFpInBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_fp_in); vm = new FpInVm(); binding.setVm(vm); + + } + + @Override + protected void onResume() { + super.onResume(); setPower(SharedPreferencesUtils.getInt("powerScrapIn",17)); + uhfLongerManager.setGen2session(true); + uhfLongerManager.asyncStartReading(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + uhfLongerManager.setGen2session(false); + uhfLongerManager.asyncStopReading(); } @Override 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 4ccc6ca..26f6e8d 100644 --- a/app/src/main/java/com/example/beijing_daxing/FpOutActivity.java +++ b/app/src/main/java/com/example/beijing_daxing/FpOutActivity.java @@ -45,7 +45,7 @@ public class FpOutActivity extends BaseActivity { binding.setAdapter(adapter); tagList=new ArrayList<>(); initRequest(); - setPower(SharedPreferencesUtils.getInt("powerScrapOut",17)); + setPower(SharedPreferencesUtils.getInt("powerScrapOut",33)); } private List tagList; @@ -87,8 +87,12 @@ public class FpOutActivity extends BaseActivity { public void fp_out_read(View view) { var b = checkState.get(); if (b) { + uhfLongerManager.setGen2session(false); + uhfLongerManager.asyncStopReading(); handler.removeCallbacks(runnable); } else { + uhfLongerManager.setGen2session(true); + uhfLongerManager.asyncStartReading(); handler.postDelayed(runnable, 0); } checkState.set(!b); @@ -139,7 +143,11 @@ public class FpOutActivity extends BaseActivity { protected void onDestroy() { super.onDestroy(); handler.removeCallbacks(runnable); + uhfLongerManager.setGen2session(false); + uhfLongerManager.asyncStopReading(); handler=null; runnable=null; } + + } \ No newline at end of file diff --git a/app/src/main/java/com/example/beijing_daxing/HomePageActivity.java b/app/src/main/java/com/example/beijing_daxing/HomePageActivity.java index 6e6a1c5..7475639 100644 --- a/app/src/main/java/com/example/beijing_daxing/HomePageActivity.java +++ b/app/src/main/java/com/example/beijing_daxing/HomePageActivity.java @@ -21,6 +21,8 @@ import com.example.beijing_daxing.databinding.ActivityHomePageBinding; import com.example.beijing_daxing.been.HomeIcon; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; +import com.handheld.uhfr.UHFRManager; +import com.uhf.api.cls.Reader; import java.util.ArrayList; import java.util.Iterator; @@ -34,11 +36,10 @@ public class HomePageActivity extends AppCompatActivity { super.onCreate(savedInstanceState); ActivityHomePageBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_home_page); initUi(binding); - /* myNetWorkReceiver=new MyNetWorkReceiver(); - IntentFilter intentFilter = new IntentFilter(); - intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); - registerReceiver(myNetWorkReceiver, intentFilter);*/ - + UHFRManager instance = UHFRManager.getInstance(); + MyApplication.getApplication().setUhfrManager(instance); + instance.setRegion(Reader.Region_Conf.RG_PRC); + instance.setPower(33,33); } @@ -62,10 +63,10 @@ public class HomePageActivity extends AppCompatActivity { @Override protected void onDestroy() { super.onDestroy(); - var uhfLongerManager = MyApplication.getUhfLongerManager(); + var uhfLongerManager = MyApplication.getApplication().getUhfrManager(); uhfLongerManager.asyncStopReading(); uhfLongerManager.close(); - MyApplication.uhfLongerManager = null; + MyApplication.getApplication().setUhfrManager(null); Log.e("TAG", "关闭" ); // unregisterReceiver(myNetWorkReceiver); } diff --git a/app/src/main/java/com/example/beijing_daxing/InActivity.java b/app/src/main/java/com/example/beijing_daxing/InActivity.java index a0c8d66..54ed032 100644 --- a/app/src/main/java/com/example/beijing_daxing/InActivity.java +++ b/app/src/main/java/com/example/beijing_daxing/InActivity.java @@ -67,6 +67,7 @@ public class InActivity extends BaseActivity implements AdapterClickCall { protected void sanRfid(List epcs) { epcs.stream().forEach(t -> { var epc = Tools.Bytes2HexString(t.EpcId,t.EpcId.length); + Log.e("TAG", "sanRfid:" + epc); if (!epc.substring(0,8).equals("53574C44")) return; if (tagList.contains(epc)) return; tagList.add(epc); @@ -126,8 +127,6 @@ public class InActivity extends BaseActivity implements AdapterClickCall { private Runnable runnable = new Runnable() { @Override public void run() { - // Log.e("TAG", "发送广播,读取RFID"); - // sendBroadcast(broadcastIntent); sanEpc(); handler.postDelayed(runnable, 50); } @@ -135,8 +134,12 @@ public class InActivity extends BaseActivity implements AdapterClickCall { public void instore_check(View view) { var b = checkState.get(); if (b) { + uhfLongerManager.setGen2session(false); + uhfLongerManager.asyncStopReading(); handler.removeCallbacks(runnable); } else { + uhfLongerManager.setGen2session(true); + uhfLongerManager.asyncStartReading(); handler.postDelayed(runnable, 0); } checkState.set(!b); @@ -146,6 +149,8 @@ public class InActivity extends BaseActivity implements AdapterClickCall { @Override protected void onDestroy() { super.onDestroy(); + uhfLongerManager.setGen2session(false); + uhfLongerManager.asyncStopReading(); handler.removeCallbacks(runnable); handler = null; runnable = null; diff --git a/app/src/main/java/com/example/beijing_daxing/OutActivity.java b/app/src/main/java/com/example/beijing_daxing/OutActivity.java index 03afca6..b34f9b6 100644 --- a/app/src/main/java/com/example/beijing_daxing/OutActivity.java +++ b/app/src/main/java/com/example/beijing_daxing/OutActivity.java @@ -4,6 +4,7 @@ import androidx.databinding.DataBindingUtil; import android.annotation.SuppressLint; import android.os.Bundle; +import android.util.Log; import android.view.View; import android.widget.Toast; import com.example.beijing_daxing.adapter.InAdapter; @@ -51,12 +52,15 @@ public class OutActivity extends BaseActivity implements AdapterClickCall { protected void onResume() { super.onResume(); setPower(SharedPreferencesUtils.getInt("powerOut",17)); + uhfLongerManager.setGen2session(true); + uhfLongerManager.asyncStartReading(); } @SuppressLint("NotifyDataSetChanged") @Override protected void sanRfid(List epcs) { epcs.forEach(t -> { var epc = Tools.Bytes2HexString(t.EpcId,t.EpcId.length); + Log.e("TAG", "sanRfid:" + epc); if (!epc.startsWith("53574C44")) return; if (tagList.contains(epc)) return; tagList.add(epc); @@ -103,4 +107,10 @@ public class OutActivity extends BaseActivity implements AdapterClickCall { }); } + @Override + protected void onDestroy() { + super.onDestroy(); + uhfLongerManager.setGen2session(false); + uhfLongerManager.asyncStopReading(); + } } \ No newline at end of file diff --git a/app/src/main/java/com/example/beijing_daxing/StoreCheckActivity.java b/app/src/main/java/com/example/beijing_daxing/StoreCheckActivity.java index 78fa7b0..9406bf2 100644 --- a/app/src/main/java/com/example/beijing_daxing/StoreCheckActivity.java +++ b/app/src/main/java/com/example/beijing_daxing/StoreCheckActivity.java @@ -110,8 +110,12 @@ public class StoreCheckActivity extends BaseActivity { public void check_read(View view) { var b = checkState.get(); if (b) { + uhfLongerManager.setGen2session(false); + uhfLongerManager.asyncStopReading(); handler.removeCallbacks(runnable); } else { + uhfLongerManager.setGen2session(true); + uhfLongerManager.asyncStartReading(); handler.postDelayed(runnable, 0); } checkState.set(!b); @@ -160,6 +164,8 @@ public class StoreCheckActivity extends BaseActivity { protected void onDestroy() { super.onDestroy(); handler.removeCallbacks(runnable); + uhfLongerManager.setGen2session(false); + uhfLongerManager.asyncStopReading(); handler = null; runnable = null; } 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 6cb68e1..45e73ad 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 @@ -40,8 +40,8 @@ import java.util.List; import okhttp3.MediaType; public abstract class BaseActivity extends AppCompatActivity { - public static String url = "http://192.168.137.1:8090/api"; - // public static String url = "http://119.45.202.115: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; public MediaType JSON = MediaType.parse("application/json; charset=utf-8"); @@ -67,10 +67,8 @@ public abstract class BaseActivity extends AppCompatActivity { public void onReceive(Context context, Intent intent) { var keydown = intent.getBooleanExtra("keydown", false); - Log.e("TAG", "接收到广播:" + keydown); if (!keydown) { - // readTime = System.currentTimeMillis(); sanEpc(); } } @@ -78,11 +76,9 @@ public abstract class BaseActivity extends AppCompatActivity { public void sanEpc() { List strings = uhfLongerManager.tagInventoryRealTime(); - // Log.e("TAG", "驱动" + (uhfLongerManager == null)); if (strings == null || strings.isEmpty()) { return; } - mediaPlayer.start(); sanRfid(strings); } @@ -96,11 +92,7 @@ public abstract class BaseActivity extends AppCompatActivity { } private void initSan() { - uhfLongerManager = MyApplication.getUhfLongerManager(); - // intentFilter.addAction("android.intent.action.FUN_KEY"); - - uhfLongerManager.asyncStartReading(); - + uhfLongerManager = MyApplication.getApplication().getUhfrManager(); myReceiver = new MyReceiver(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction("android.rfid.FUN_KEY"); @@ -112,7 +104,6 @@ public abstract class BaseActivity extends AppCompatActivity { try { Reader.READER_ERR readerErr = uhfLongerManager.setPower(power, power); Log.e("TAG", "setPower:" + readerErr.name()); - int[] power1 = uhfLongerManager.getPower(); Log.e("TAG", "readPower:" + power1[0] + "," + power1[1]); } catch (Exception e) { diff --git a/app/src/main/java/com/example/beijing_daxing/base/MyApplication.java b/app/src/main/java/com/example/beijing_daxing/base/MyApplication.java index fc40979..e055c85 100644 --- a/app/src/main/java/com/example/beijing_daxing/base/MyApplication.java +++ b/app/src/main/java/com/example/beijing_daxing/base/MyApplication.java @@ -38,8 +38,8 @@ import okhttp3.OkHttpClient; */ public class MyApplication extends Application { - MyApplication application; - public static UHFRManager uhfLongerManager; + private static MyApplication application; + private UHFRManager uhfrManager; @Override public void onCreate() { @@ -60,18 +60,18 @@ public class MyApplication extends Application { .init(this); } - public static UHFRManager getUhfLongerManager() { - if (uhfLongerManager==null){ - try { - uhfLongerManager = UHFRManager.getInstance(); - uhfLongerManager.setPower(33,33); - } catch (Exception e) { - e.printStackTrace(); - } - } - - return uhfLongerManager; + public static MyApplication getApplication() { + return application; } + + public UHFRManager getUhfrManager() { + return uhfrManager; + } + + public void setUhfrManager(UHFRManager uhfrManager) { + this.uhfrManager = uhfrManager; + } + // OKGO 初始化 private void okGoBase() { OkHttpClient.Builder builder = new OkHttpClient.Builder(); diff --git a/app/src/main/java/com/example/beijing_daxing/rfid/RFID.java b/app/src/main/java/com/example/beijing_daxing/rfid/RFID.java deleted file mode 100644 index ede3553..0000000 --- a/app/src/main/java/com/example/beijing_daxing/rfid/RFID.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.example.beijing_daxing.rfid; - -public interface RFID { - void initRFIDModel(); - void setPower(int power); - void sanRFID(); - void close(); - - -} diff --git a/app/src/main/java/com/example/beijing_daxing/rfid/impl/Device6109.java b/app/src/main/java/com/example/beijing_daxing/rfid/impl/Device6109.java deleted file mode 100644 index 9c9c81a..0000000 --- a/app/src/main/java/com/example/beijing_daxing/rfid/impl/Device6109.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.example.beijing_daxing.rfid.impl; - -import android.util.Log; - -import com.example.beijing_daxing.rfid.RFID; -import com.handheld.uhfr.UHFRManager; -import com.uhf.api.cls.Reader; - -import java.util.List; - -public class Device6109 implements RFID { - - private UHFRManager uhfrManager; - private EpcDataInterface epcDataInterface; - - public Device6109(EpcDataInterface epcDataInterface) { - this.epcDataInterface = epcDataInterface; - } - - public Device6109() { - } - - @Override - public void initRFIDModel() { - if (uhfrManager == null) { - uhfrManager = UHFRManager.getInstance(); - } - uhfrManager.asyncStartReading(); - } - - @Override - public void setPower(int power) { - Reader.READER_ERR readerErr = uhfrManager.setPower(power, power); - Log.e("TAG", "setPower:" + readerErr); - } - - @Override - public void sanRFID() { - List data = uhfrManager.tagInventoryRealTime(); - if (data == null || data.isEmpty()) { - return; - } - epcDataInterface.epcData(data); - } - - @Override - public void close() { - if (uhfrManager == null) { - return; - } - uhfrManager.asyncStopReading(); - uhfrManager.close(); - uhfrManager = null; - } - - - public interface EpcDataInterface { - void epcData(List data); - } -}