完成 绑定接口

master
wangh 6 months ago
parent 0810f5ae96
commit 42d2bff843

@ -12,6 +12,7 @@
android:roundIcon="@mipmap/logo"
android:supportsRtl="true"
android:theme="@style/Theme.BGSRFIDTrack"
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:name=".UnBindingActivity"

@ -13,17 +13,23 @@ 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.base.MyRecultCall;
import com.example.bgsrfidtrack.base.MyResult;
import com.example.bgsrfidtrack.base.SharedPreferencesUtils;
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 com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import java.util.ArrayList;
import java.util.List;
import cn.pda.serialport.Tools;
import okhttp3.RequestBody;
public class BindingActivity extends BaseActivity implements MyKeyInfoCall, AdapterClickCall {
private BindingModel model;
@ -38,7 +44,6 @@ public class BindingActivity extends BaseActivity implements MyKeyInfoCall, Adap
binding.setModel(model);
initKeyRecriver(this);
initRFID();
codeList = new ArrayList<>();
adapter = new GoodsInfoAdapter(this, this);
adapter.setList(codeList);
@ -56,7 +61,7 @@ public class BindingActivity extends BaseActivity implements MyKeyInfoCall, Adap
public void sanCodeCall(String code) {
Log.e("TAG", "广播:" + code);
model.setBarCode(code);
// if (codeList.contains(code)) return;
if (codeList.contains(code)) return;
codeList.add(code);
adapter.notifyDataSetChanged();
}
@ -65,21 +70,33 @@ public class BindingActivity extends BaseActivity implements MyKeyInfoCall, Adap
@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);
super.readEPC();
}
@Override
public void sanEpcCall(String epc) {
super.sanEpcCall(epc);
model.setEpc(epc);
}
// 提交
public void bindingSubmit(View view) {
model.setWatBills(codeList);
OkGo.<MyResult>post("http://"+ SharedPreferencesUtils.getstring("ip","")+
"/api/bindingSubmit")
.upRequestBody(RequestBody.create(JSON, gson.toJson(model)))
.execute(new MyRecultCall(dialog,this){
@Override
public void onSuccess(Response<MyResult> response) {
super.onSuccess(response);
if (response.body().getCode()==0){
Toast.makeText(BindingActivity.this, "请求成功", Toast.LENGTH_SHORT).show();
finish();
return;
}
Toast.makeText(BindingActivity.this, response.body().getMsg(), Toast.LENGTH_SHORT).show();
}
});
}
@Override

@ -18,9 +18,13 @@ public class HomePageActivity extends BaseActivity {
super.onCreate(savedInstanceState);
ActivityHomePageBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_home_page);
Intent intent = new Intent(this, BindingActivity.class);
Intent intent2 = new Intent(this, UnBindingActivity.class);
binding.binding.setOnClickListener(v -> {
startActivity(intent);
});
binding.unBinding.setOnClickListener(v -> {
startActivity(intent2);
});
}
@ -29,7 +33,7 @@ public class HomePageActivity extends BaseActivity {
@Override
protected void onDestroy() {
super.onDestroy();
if(uhfReader!=null){
if (uhfReader != null) {
uhfReader.close();
}
}

@ -31,35 +31,38 @@ public class MainActivity extends BaseActivity {
if (isRemember) {
login.setUsername(SharedPreferencesUtils.getstring("user", ""));
login.setPassword(SharedPreferencesUtils.getstring("pass", ""));
login.setIp(SharedPreferencesUtils.getstring("ip", ""));
login.setRemember(isRemember);
}
binding.setUser(login);
}
public void login_click(View view) {
// String pass = login.getPassword();
// String name = login.getUsername();
// if (pass == null || name == null || pass.isEmpty() || name.isEmpty()) return;
// OkGo.<MyResult>post(url+"/auth/pdaLogin")
// .upRequestBody(RequestBody.create(JSON, gson.toJson(login)))
// .execute(new MyRecultCall(dialog, this) {
// @Override
// public void onSuccess(Response<MyResult> response) {
// super.onSuccess(response);
// var body = response.body();
// if (body.getCode() == 200) {
// boolean remember = login.isRemember();
// if (remember) {
// SharedPreferencesUtils.putboolean("isRemember", remember);
// SharedPreferencesUtils.putstring("user", name);
// SharedPreferencesUtils.putstring("pass", pass);
// }
Intent intent=new Intent(MainActivity.this, HomePageActivity.class);
startActivity(intent);
finish();
// }
//
//
// }
// });
String pass = login.getPassword();
String name = login.getUsername();
if (pass == null || name == null || pass.isEmpty() || name.isEmpty()) return;
var ip = login.getIp();
OkGo.<MyResult>post("http://"+ ip + "/api/login/finduser")
.params("name",name)
.params("pass",pass)
.execute(new MyRecultCall(dialog, this) {
@Override
public void onSuccess(Response<MyResult> response) {
super.onSuccess(response);
var body = response.body();
if (body.getCode() == 0) {
boolean remember = login.isRemember();
if (remember) {
SharedPreferencesUtils.putboolean("isRemember", remember);
SharedPreferencesUtils.putstring("user", name);
SharedPreferencesUtils.putstring("pass", pass);
SharedPreferencesUtils.putstring("ip", ip);
}
Intent intent = new Intent(MainActivity.this, HomePageActivity.class);
startActivity(intent);
finish();
}
}
});
}
}

@ -1,14 +1,43 @@
package com.example.bgsrfidtrack;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
public class UnBindingActivity extends AppCompatActivity {
import com.example.bgsrfidtrack.adapter.UnBindingGoodsInfoAdapter;
import com.example.bgsrfidtrack.base.BaseActivity;
import com.example.bgsrfidtrack.databinding.ActivityUnBindingBinding;
import com.example.bgsrfidtrack.receiver.MyKeyInfoCall;
import com.example.bgsrfidtrack.uitls.ASCIIUtil;
import cn.pda.serialport.Tools;
public class UnBindingActivity extends BaseActivity implements MyKeyInfoCall {
private UnBindingGoodsInfoAdapter adapter;
private ActivityUnBindingBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_un_binding);
binding = DataBindingUtil.setContentView(this, R.layout.activity_un_binding);
initRFID();
initKeyRecriver(this);
}
public void unBindingSubmit(View view) {
}
// 扫描RFID
@Override
public void onkeyDown() {
readEPC();
}
@Override
public void sanEpcCall(String epc) {
super.sanEpcCall(epc);
binding.unbindingEpc.setText(epc);
}
}

@ -0,0 +1,68 @@
package com.example.bgsrfidtrack.adapter;
import android.content.Context;
import android.view.LayoutInflater;
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.ItemGoodsInfo2Binding;
import com.example.bgsrfidtrack.databinding.ItemGoodsInfoBinding;
import java.util.List;
/**
* @author wanghao
* @date 2024/7/10 15:30
*/
public class UnBindingGoodsInfoAdapter extends RecyclerView.Adapter<UnBindingGoodsInfoAdapter.MyViewHolder> {
private Context context;
private List<String> list;
private LayoutInflater inflater;
private AdapterClickCall call;
public UnBindingGoodsInfoAdapter(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) {
ItemGoodsInfo2Binding binding = DataBindingUtil.inflate(inflater, R.layout.item_goods_info2, 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 ItemGoodsInfo2Binding binding;
public MyViewHolder(ItemGoodsInfo2Binding binding) {
super(binding.getRoot());
this.binding = binding;
}
}
}

@ -28,6 +28,7 @@ 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.example.bgsrfidtrack.uitls.ASCIIUtil;
import com.google.gson.Gson;
import java.io.ByteArrayOutputStream;
@ -56,22 +57,26 @@ public class BaseActivity extends AppCompatActivity {
public SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd_HHmmss");
public MyApplication application;
public UhfReader uhfReader;
public MediaPlayer music;
public MediaPlayer music;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.e("TAG", this.getLocalClassName());
gson = new Gson();
this.context = this;
music=MediaPlayer.create(this, R.raw.msg);
initDialog();
initSan();
}
public void initRFID(){
application=MyApplication.getApplication();
uhfReader=application.getUhfReader();
public void initRFID() {
application = MyApplication.getApplication();
uhfReader = application.getUhfReader();
music = MediaPlayer.create(this, R.raw.msg);
}
public class MyReceiver extends BroadcastReceiver {
@Override
@ -99,7 +104,7 @@ public class BaseActivity extends AppCompatActivity {
public void initKeyRecriver(MyKeyInfoCall call) {
keyReceiver=new MyKeyReceiver(call);
keyReceiver = new MyKeyReceiver(call);
IntentFilter filter = new IntentFilter();
filter.addAction("android.rfid.FUN_KEY");
filter.addAction("android.intent.action.FUN_KEY");
@ -121,6 +126,22 @@ public class BaseActivity extends AppCompatActivity {
}
public void sanEpcCall(String epc) {
}
protected void readEPC() {
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);
sanEpcCall(epc);
}
// 拍照
/* private Uri img_uri;
private File outputImage;

@ -2,6 +2,8 @@ package com.example.bgsrfidtrack.model;
import androidx.databinding.BaseObservable;
import java.util.List;
/**
* @author wanghao
* @date 2024/7/10 15:12
@ -12,7 +14,15 @@ public class BindingModel extends BaseObservable {
private String localtion;
private String number;
private String weight;
private List<String> watBills;
public List<String> getWatBills() {
return watBills;
}
public void setWatBills(List<String> watBills) {
this.watBills = watBills;
}
public String getLocaltion() {
return localtion;

@ -7,10 +7,20 @@ import androidx.databinding.BaseObservable;
* @date 2023/12/21 14:00
*/
public class LoginModel extends BaseObservable {
private String ip;
private String username;
private String password;
private boolean remember;
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
notifyChange();
}
public String getUsername() {
return username;
}

@ -4,16 +4,17 @@
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="user"
type="com.example.bgsrfidtrack.model.LoginModel" />
<variable
name="user"
type="com.example.bgsrfidtrack.model.LoginModel" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/white"
android:orientation="vertical"
tools:context=".MainActivity">
<ImageView
@ -33,12 +34,30 @@
android:textSize="22sp" />
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:gravity="center"
android:hint="请求接口ip:端口">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@={user.ip}" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_marginTop="10dp"
android:layout_marginRight="20dp"
android:hint="用户名">
@ -54,7 +73,7 @@
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="15dp"
android:layout_marginTop="10dp"
android:layout_marginRight="20dp"
android:hint="密码"
app:passwordToggleEnabled="true">

@ -1,10 +1,115 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".UnBindingActivity">
xmlns:tools="http://schemas.android.com/tools">
</LinearLayout>
<data>
<variable
name="title"
type="String" />
<variable
name="adapter"
type="com.example.bgsrfidtrack.adapter.UnBindingGoodsInfoAdapter" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".UnBindingActivity">
<include
layout="@layout/title_bar"
app:title='@{title??"解绑"}' />
<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
android:id="@+id/unbinding_epc"
style="@style/santextbg"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</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="wrap_content"
android:layout_height="45dp"
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>
<Button
style="@style/buttonbg"
android:layout_width="match_parent"
android:layout_height="50dp"
android:onClick="unBindingSubmit"
android:text="全部解绑" />
</LinearLayout>
</layout>

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="51dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<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_unbind" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="#e1e1e1"/>
</LinearLayout>
</layout>
Loading…
Cancel
Save