完成 绑定

master
wangh 8 months ago
parent f7b1ea50aa
commit 0810f5ae96

@ -1,8 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="delegatedBuild" value="true" />
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="LOCAL" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />

@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />

@ -37,6 +37,8 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation files('libs\\SerialPort.jar')
implementation files('libs\\uhfcom13_v15.jar')
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

Binary file not shown.

Binary file not shown.

@ -13,12 +13,15 @@
android:supportsRtl="true"
android:theme="@style/Theme.BGSRFIDTrack"
tools:targetApi="31">
<activity
android:name=".UnBindingActivity"
android:exported="false" />
<receiver
android:name=".receiver.MyKeyReceiver"
android:enabled="true"
android:exported="true" />
<activity
android:name=".BindingActivity"
android:exported="false" />

@ -1,24 +1,48 @@
package com.example.bgsrfidtrack;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import com.android.hdhe.uhf.readerInterface.TagModel;
import com.example.bgsrfidtrack.adapter.AdapterClickCall;
import com.example.bgsrfidtrack.adapter.GoodsInfoAdapter;
import com.example.bgsrfidtrack.base.BaseActivity;
import com.example.bgsrfidtrack.databinding.ActivityBindingBinding;
import com.example.bgsrfidtrack.databinding.ActivityBindingBindingImpl;
import com.example.bgsrfidtrack.model.BindingModel;
import com.example.bgsrfidtrack.receiver.MyKeyInfoCall;
import com.example.bgsrfidtrack.receiver.MyKeyReceiver;
import com.example.bgsrfidtrack.uitls.ASCIIUtil;
import java.util.ArrayList;
import java.util.List;
import cn.pda.serialport.Tools;
public class BindingActivity extends BaseActivity implements MyKeyInfoCall, AdapterClickCall {
private BindingModel model;
private List<String> codeList;
private GoodsInfoAdapter adapter;
public class BindingActivity extends AppCompatActivity {
MyKeyReceiver keyReceiver = new MyKeyReceiver();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_binding);
IntentFilter filter = new IntentFilter();
filter.addAction("android.rfid.FUN_KEY");
filter.addAction("android.intent.action.FUN_KEY");
registerReceiver(keyReceiver, filter);
ActivityBindingBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_binding);
model = new BindingModel();
binding.setModel(model);
initKeyRecriver(this);
initRFID();
codeList = new ArrayList<>();
adapter = new GoodsInfoAdapter(this, this);
adapter.setList(codeList);
binding.setAdapter(adapter);
}
@Override
@ -26,4 +50,41 @@ public class BindingActivity extends AppCompatActivity {
super.onDestroy();
unregisterReceiver(keyReceiver);
}
// 返回条形码
@Override
public void sanCodeCall(String code) {
Log.e("TAG", "广播:" + code);
model.setBarCode(code);
// if (codeList.contains(code)) return;
codeList.add(code);
adapter.notifyDataSetChanged();
}
// 扫描RFID
@Override
public void onkeyDown() {
Log.e("TAG", "点击");
var tagModels = uhfReader.inventoryRealTime();
if (tagModels == null || tagModels.isEmpty()) {
// Toast.makeText(context, "读取失败", Toast.LENGTH_SHORT).show();
return;
}
music.start();
var bytes = tagModels.get(0).getmEpcBytes();
var epc = ASCIIUtil.hex2Str(Tools.Bytes2HexString(bytes, bytes.length));
Log.e("TAG", "onkeyDown:" + epc);
model.setEpc(epc);
}
// 提交
public void bindingSubmit(View view) {
}
@Override
public void deleteItem(int index) {
codeList.remove(index);
adapter.notifyDataSetChanged();
}
}

@ -8,6 +8,7 @@ import android.content.Intent;
import android.os.Bundle;
import com.example.bgsrfidtrack.base.BaseActivity;
import com.example.bgsrfidtrack.base.MyApplication;
import com.example.bgsrfidtrack.databinding.ActivityHomePageBinding;
public class HomePageActivity extends BaseActivity {
@ -20,5 +21,16 @@ public class HomePageActivity extends BaseActivity {
binding.binding.setOnClickListener(v -> {
startActivity(intent);
});
}
@Override
protected void onDestroy() {
super.onDestroy();
if(uhfReader!=null){
uhfReader.close();
}
}
}

@ -0,0 +1,14 @@
package com.example.bgsrfidtrack;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class UnBindingActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_un_binding);
}
}

@ -0,0 +1,9 @@
package com.example.bgsrfidtrack.adapter;
/**
* @author wanghao
* @date 2024/7/10 9:39
*/
public interface AdapterClickCall {
void deleteItem(int index);
}

@ -0,0 +1,68 @@
package com.example.bgsrfidtrack.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;
import com.example.bgsrfidtrack.R;
import com.example.bgsrfidtrack.databinding.ItemGoodsInfoBinding;
import java.util.List;
/**
* @author wanghao
* @date 2024/7/10 15:30
*/
public class GoodsInfoAdapter extends RecyclerView.Adapter<GoodsInfoAdapter.MyViewHolder> {
private Context context;
private List<String> list;
private LayoutInflater inflater;
private AdapterClickCall call;
public GoodsInfoAdapter(Context context, AdapterClickCall call) {
this.context = context;
this.call = call;
inflater = LayoutInflater.from(context);
}
public void setList(List<String> list) {
this.list = list;
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
ItemGoodsInfoBinding binding = DataBindingUtil.inflate(inflater, R.layout.item_goods_info, parent, false);
return new MyViewHolder(binding);
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
var binding = holder.binding;
binding.itemCode.setText(list.get(position));
binding.itemIndex.setText(position+1+"");
binding.itemDelete.setOnClickListener(v -> call.deleteItem(position));
}
@Override
public int getItemCount() {
return list.isEmpty() ? 0 : list.size();
}
static class MyViewHolder extends RecyclerView.ViewHolder {
private ItemGoodsInfoBinding binding;
public MyViewHolder(ItemGoodsInfoBinding binding) {
super(binding.getRoot());
this.binding = binding;
}
}
}

@ -10,6 +10,7 @@ import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@ -23,6 +24,10 @@ import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
import com.android.hdhe.uhf.reader.UhfReader;
import com.example.bgsrfidtrack.R;
import com.example.bgsrfidtrack.receiver.MyKeyInfoCall;
import com.example.bgsrfidtrack.receiver.MyKeyReceiver;
import com.google.gson.Gson;
import java.io.ByteArrayOutputStream;
@ -33,33 +38,40 @@ import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import cn.pda.serialport.Tools;
import okhttp3.MediaType;
public class BaseActivity extends AppCompatActivity {
public static final int CAMERA_PHOTO = 1;
public static String url = "http://175.27.215.92:7018/prod-api";
// public static String url = "http://10.11.40.120:7018/dev-api";
public ProgressDialog dialog;
public Gson gson;
public byte[] accessBytes = Tools.HexString2Bytes("00000000");
public MediaType JSON = MediaType.parse("application/json; charset=utf-8");
private MyReceiver myReceiver;
public String handle = "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoxLCJzdGF0aW9uX2lkIjpudWxsLCJ1c2VyX2tleSI6IjFjNDM3NTRkLWRlMzAtNGU4Ni04MTI3LTE5ZDQ0ZTY2ODc3MCIsInVzZXJuYW1lIjoiYWRtaW4ifQ.Ao_5QTmKFUtNfdyMmWM0cpVdpbihKsae_SCmK2S57NSwse2-CXgSXeGwr_PK_zilZNhSWTaVJrYlJHXXj3cRdA";
public Context context;
public MyKeyReceiver keyReceiver;
@SuppressLint("SimpleDateFormat")
public SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd_HHmmss");
public MyApplication application;
public UhfReader uhfReader;
public MediaPlayer music;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.e("TAG", this.getLocalClassName());
gson = new Gson();
// SharedPreferencesUtils.putstring("access_token",handle);
this.context = this;
music=MediaPlayer.create(this, R.raw.msg);
initDialog();
initSan();
}
public void initRFID(){
application=MyApplication.getApplication();
uhfReader=application.getUhfReader();
}
public class MyReceiver extends BroadcastReceiver {
@Override
@ -77,7 +89,7 @@ public class BaseActivity extends AppCompatActivity {
dialog.setMessage("请求网络中...");
}
private void initSan() {
public void initSan() {
myReceiver = new MyReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("com.rfid.SCAN");
@ -86,6 +98,15 @@ public class BaseActivity extends AppCompatActivity {
}
public void initKeyRecriver(MyKeyInfoCall call) {
keyReceiver=new MyKeyReceiver(call);
IntentFilter filter = new IntentFilter();
filter.addAction("android.rfid.FUN_KEY");
filter.addAction("android.intent.action.FUN_KEY");
registerReceiver(keyReceiver, filter);
}
@Override
protected void onDestroy() {
super.onDestroy();

@ -2,6 +2,7 @@ package com.example.bgsrfidtrack.base;
import android.app.Application;
import com.android.hdhe.uhf.reader.UhfReader;
import com.example.bgsrfidtrack.base.SharedPreferencesUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheEntity;
@ -24,16 +25,27 @@ import okhttp3.OkHttpClient;
*/
public class MyApplication extends Application {
MyApplication application;
private static MyApplication application;
private UhfReader uhfReader;
@Override
public void onCreate() {
super.onCreate();
application = this;
SharedPreferencesUtils.init(getApplicationContext(), "myapp");
okGoBase();
}
public static MyApplication getApplication() {
return application;
}
public UhfReader getUhfReader() {
if (uhfReader==null){
uhfReader=UhfReader.getInstance();
}
return uhfReader;
}
// OKGO 初始化
private void okGoBase() {

@ -0,0 +1,61 @@
package com.example.bgsrfidtrack.model;
import androidx.databinding.BaseObservable;
/**
* @author wanghao
* @date 2024/7/10 15:12
*/
public class BindingModel extends BaseObservable {
private String barCode;
private String epc;
private String localtion;
private String number;
private String weight;
public String getLocaltion() {
return localtion;
}
public void setLocaltion(String localtion) {
this.localtion = localtion;
notifyChange();
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
notifyChange();
}
public String getWeight() {
return weight;
}
public void setWeight(String weight) {
this.weight = weight;
notifyChange();
}
public String getBarCode() {
return barCode;
}
public void setBarCode(String barCode) {
this.barCode = barCode;
notifyChange();
}
public String getEpc() {
return epc;
}
public void setEpc(String epc) {
this.epc = epc;
notifyChange();
}
}

@ -20,7 +20,7 @@ public class MyKeyReceiver extends BroadcastReceiver {
var keydown = intent.getBooleanExtra("keydown", false);
var keyCode = intent.getIntExtra("keyCode", 0);
if (!keydown&&keyCode==135){
myKeyInfoCall.onkeyDown();
}
}
}

@ -0,0 +1,66 @@
package com.example.bgsrfidtrack.uitls;
/**
* @author: wangh
* @description: Ass
* @date: 2019/06/20-15:18
*/
public class ASCIIUtil {
// String明文转ASCII码hex字符串,一个明文字符生成两个字符表示的16进制ASCII码
public static String str2Hex(String str) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
// 这里的第二个参数16表示十六进制
sb.append(Integer.toString(c, 16));
// 或用toHexString方法直接转成16进制
// sb.append(Integer.toHexString(c));
}
return sb.toString();
}
// ASCII码hex字符串转String明文
public static String hex2Str(String hex) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hex.length() - 1; i += 2) {
String h = hex.substring(i, (i + 2));
int decimal = Integer.parseInt(h, 16);
sb.append((char) decimal);
}
return sb.toString();
}
public static String hexTo4ZN(String hex) throws Exception {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hex.length() - 1; i += 4) {
String h = hex.substring(i, (i + 4));
sb.append((char) Integer.parseInt(h, 16));
}
return sb.toString();
}
public static String str4Hex(String str) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < str.length(); i++) {
String s = Integer.toString(str.charAt(i), 16);
sb.append(s.length()==2?"00"+s:s);
}
return sb.toString();
}
public static String convertToAscii(String chineseText) {
StringBuilder asciiText = new StringBuilder();
for (int i = 0; i < chineseText.length(); i++) {
char c = chineseText.charAt(i);
int asciiValue = (int) c;
asciiText.append(asciiValue).append(" ");
}
return asciiText.toString().trim();
}
}

@ -1,13 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
xmlns:tools="http://schemas.android.com/tools"
android:animateLayoutChanges="true">
<data>
<variable
name="title"
type="String" />
<variable
name="model"
type="com.example.bgsrfidtrack.model.BindingModel" />
<variable
name="adapter"
type="com.example.bgsrfidtrack.adapter.GoodsInfoAdapter" />
</data>
<LinearLayout
@ -16,5 +23,175 @@
android:orientation="vertical"
tools:context=".BindingActivity">
<include
layout="@layout/title_bar"
app:title='@{title??"绑定"}' />
<LinearLayout
style="@style/layoutbg"
android:layout_width="match_parent"
android:layout_height="45dp"
android:visibility="gone">
<TextView
style="@style/textbg"
android:layout_width="100dp"
android:layout_height="match_parent"
android:text="当前位置" />
<TextView
style="@style/santextbg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@{model.localtion}"/>
</LinearLayout>
<LinearLayout
style="@style/layoutbg"
android:layout_width="match_parent"
android:layout_height="45dp">
<TextView
style="@style/textbg"
android:layout_width="100dp"
android:layout_height="match_parent"
android:text="货框RFID" />
<TextView
style="@style/santextbg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@{model.epc}"/>
</LinearLayout>
<LinearLayout
style="@style/layoutbg"
android:layout_width="match_parent"
android:layout_height="45dp">
<TextView
style="@style/textbg"
android:layout_width="100dp"
android:layout_height="match_parent"
android:text="货物条码" />
<TextView
style="@style/santextbg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@{model.barCode}"/>
</LinearLayout>
<LinearLayout
style="@style/layoutbg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
style="@style/textbg"
android:layout_width="100dp"
android:layout_height="45dp"
android:layout_gravity="right"
android:text="货物信息" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/san_text_view"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="45dp">
<TextView
style="@style/textbg"
android:layout_width="0dp"
android:layout_height="45dp"
android:layout_weight="1"
android:text="序号" />
<TextView
style="@style/textbg"
android:layout_width="0dp"
android:layout_height="45dp"
android:layout_weight="3"
android:text="货物条码" />
<TextView
style="@style/textbg"
android:layout_width="0dp"
android:layout_height="45dp"
android:layout_weight="1"
android:text="操作" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#e1e1e1"/>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:adapter="@{adapter}"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</LinearLayout>
</LinearLayout>
<LinearLayout
style="@style/layoutbg"
android:layout_width="match_parent"
android:layout_height="45dp"
android:focusable="true"
android:visibility="gone">
<TextView
style="@style/textbg"
android:layout_width="100dp"
android:layout_height="match_parent"
android:imeOptions="actionDone"
android:inputType="number"
android:text="货物数量" />
<EditText
style="@style/santextbg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:imeOptions="actionDone"
android:inputType="number"
android:text="@{model.number}"/>
</LinearLayout>
<LinearLayout
style="@style/layoutbg"
android:layout_width="match_parent"
android:layout_height="45dp"
android:visibility="gone">
<TextView
style="@style/textbg"
android:layout_width="100dp"
android:layout_height="match_parent"
android:text="货物总重" />
<EditText
style="@style/santextbg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@{model.weight}"/>
</LinearLayout>
<Button
style="@style/buttonbg"
android:layout_width="match_parent"
android:layout_height="50dp"
android:onClick="bindingSubmit"
android:text="提交" />
</LinearLayout>
</layout>

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".UnBindingActivity">
</LinearLayout>

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
</data>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="50dp">
<TextView
android:id="@+id/item_index"
style="@style/textbg"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="序号" />
<TextView
android:id="@+id/item_code"
style="@style/textbg"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:text="货物条码" />
<ImageView
android:id="@+id/item_delete"
style="@style/textbg"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="10dp"
android:src="@mipmap/icon_delete" />
</LinearLayout>
</layout>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

@ -5,9 +5,37 @@
<!-- <item name="colorPrimary">@color/my_light_primary</item> -->
<item name="colorPrimary">@color/blue</item>
<item name="android:windowBackground">@color/activity_bg</item>
<item name="android:lines">2</item>
<item name="android:singleLine">false</item>
</style>
<style name="Theme.BGSRFIDTrack" parent="Base.Theme.BGSRFIDTrack" />
<style name="layoutbg">
<item name="android:layout_marginTop">12dp</item>
<item name="android:layout_marginRight">4dp</item>
</style>
<style name="textbg">
<item name="android:gravity">center</item>
<item name="android:textSize">18sp</item>
</style>
<style name="santextbg">
<item name="android:gravity">center</item>
<item name="android:textSize">18sp</item>
<item name="android:background">@drawable/san_text_view</item>
</style>
<style name="buttonbg">
<item name="android:textSize">18sp</item>
<item name="android:letterSpacing">1</item>
<item name="android:textStyle">bold</item>
<item name="android:layout_marginTop">8dp</item>
<item name="android:layout_marginLeft">16dp</item>
<item name="android:layout_marginRight">16dp</item>
<item name="android:layout_marginBottom">8dp</item>
</style>
</resources>
Loading…
Cancel
Save