xiugai 读取
parent
71d1194158
commit
bdea369f5b
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<litepal>
|
||||||
|
<dbname value="rfidcon" />
|
||||||
|
<version value="1" />
|
||||||
|
<list>
|
||||||
|
<mapping class="com.example.beijing_daxing.been.RFIDLocation"></mapping>
|
||||||
|
</list>
|
||||||
|
</litepal>
|
||||||
@ -0,0 +1,86 @@
|
|||||||
|
package com.example.beijing_daxing;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.databinding.DataBindingUtil;
|
||||||
|
import androidx.databinding.ObservableBoolean;
|
||||||
|
import androidx.databinding.ViewDataBinding;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.example.beijing_daxing.adapter.StoreCheckAdapter;
|
||||||
|
import com.example.beijing_daxing.base.BaseActivity;
|
||||||
|
import com.example.beijing_daxing.been.RFIDLocation;
|
||||||
|
import com.example.beijing_daxing.been.Stock;
|
||||||
|
import com.example.beijing_daxing.databinding.ActivityOffLineCheckBinding;
|
||||||
|
|
||||||
|
import org.litepal.LitePal;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class OffLineCheckActivity extends BaseActivity {
|
||||||
|
private StoreCheckAdapter checkAdapter;
|
||||||
|
private ObservableBoolean checkState;
|
||||||
|
private List<Stock> list;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
ActivityOffLineCheckBinding binding;
|
||||||
|
binding = DataBindingUtil.setContentView(this, R.layout.activity_off_line_check);
|
||||||
|
checkState = new ObservableBoolean();
|
||||||
|
binding.setCheckState(checkState);
|
||||||
|
/* var all = LitePal.findAll(RFIDLocation.class);
|
||||||
|
if (all == null || all.isEmpty()) {
|
||||||
|
Toast.makeText(this, "", Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}*/
|
||||||
|
list = new ArrayList<>();
|
||||||
|
// all.forEach(t -> {
|
||||||
|
// Stock stock = new Stock();
|
||||||
|
// stock.setLocationCode(t.getLocationCode());
|
||||||
|
// stock.setEpcCode(t.getEpcCode());
|
||||||
|
// list.add(stock);
|
||||||
|
// });
|
||||||
|
checkAdapter=new StoreCheckAdapter(this);
|
||||||
|
checkAdapter.setList(list);
|
||||||
|
checkAdapter = new StoreCheckAdapter(this);
|
||||||
|
binding.setAdapter(checkAdapter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void sanRfid(List<String> epcs) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void offCheckRead(View view) {
|
||||||
|
var b = checkState.get();
|
||||||
|
if (b) {
|
||||||
|
handler.removeCallbacks(runnable);
|
||||||
|
} else {
|
||||||
|
handler.postDelayed(runnable, 0);
|
||||||
|
}
|
||||||
|
checkState.set(!b);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("HandlerLeak")
|
||||||
|
private Handler handler = new Handler() {
|
||||||
|
@Override
|
||||||
|
public void handleMessage(@NonNull Message msg) {
|
||||||
|
super.handleMessage(msg);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
private Runnable runnable = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
sendBroadcast(broadcastIntent);
|
||||||
|
handler.postDelayed(runnable, 1000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
package com.example.beijing_daxing.been;
|
||||||
|
|
||||||
|
import org.litepal.crud.LitePalSupport;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author wanghao
|
||||||
|
* @date 2024/5/13 16:40
|
||||||
|
*/
|
||||||
|
public class RFIDLocation extends LitePalSupport {
|
||||||
|
|
||||||
|
private int id;
|
||||||
|
private String epcCode;
|
||||||
|
private String locationCode;
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEpcCode() {
|
||||||
|
return epcCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEpcCode(String epcCode) {
|
||||||
|
this.epcCode = epcCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLocationCode() {
|
||||||
|
return locationCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocationCode(String locationCode) {
|
||||||
|
this.locationCode = locationCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,82 @@
|
|||||||
|
package com.example.beijing_daxing.broadcast;
|
||||||
|
|
||||||
|
import static com.example.beijing_daxing.base.BaseActivity.url;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.NetworkInfo;
|
||||||
|
import android.net.wifi.WifiInfo;
|
||||||
|
import android.net.wifi.WifiManager;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.example.beijing_daxing.base.MyRecultCall;
|
||||||
|
import com.example.beijing_daxing.base.MyResult;
|
||||||
|
import com.example.beijing_daxing.been.RFIDLocation;
|
||||||
|
import com.example.beijing_daxing.been.Stock;
|
||||||
|
import com.example.beijing_daxing.uitls.SharedPreferencesUtils;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import com.lzy.okgo.OkGo;
|
||||||
|
import com.lzy.okgo.callback.StringCallback;
|
||||||
|
import com.lzy.okgo.model.Response;
|
||||||
|
|
||||||
|
import org.litepal.LitePal;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MyNetWorkReceiver extends BroadcastReceiver {
|
||||||
|
private String wifiName = "";
|
||||||
|
private Gson gson;
|
||||||
|
|
||||||
|
public MyNetWorkReceiver() {
|
||||||
|
gson=new Gson();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(intent.getAction())) {
|
||||||
|
NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
|
||||||
|
|
||||||
|
Log.e("TAG", "正在连接:" + networkInfo.isConnectedOrConnecting());
|
||||||
|
Log.e("TAG", "已连接:" + networkInfo.isConnected());
|
||||||
|
if (networkInfo != null && networkInfo.isConnected()) {
|
||||||
|
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||||
|
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
||||||
|
String ssid = wifiInfo.getSSID();
|
||||||
|
if (ssid != null) {
|
||||||
|
var newWifiNameState = ssid.equals("\"wang\"");
|
||||||
|
if (newWifiNameState && !wifiName.equals(ssid)) {
|
||||||
|
wifiName = ssid;
|
||||||
|
// 执行你的业务逻辑
|
||||||
|
Log.e("TAG", "onReceive:连接成功");
|
||||||
|
OkGo.<String>post(url + "/xj/selectLite")
|
||||||
|
.params("user", SharedPreferencesUtils.getstring("user", ""))
|
||||||
|
.execute(new StringCallback() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(Response<String> response) {
|
||||||
|
var body = response.body();
|
||||||
|
if (!body.equals("null")){
|
||||||
|
List<RFIDLocation> list = gson.fromJson(body, new TypeToken<List<RFIDLocation>>() {}.getType());
|
||||||
|
if (list!=null &&!list.isEmpty()){
|
||||||
|
LitePal.deleteAll(RFIDLocation.class);
|
||||||
|
LitePal.saveAll(list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Log.e("TAG", "onReceive:连接断开");
|
||||||
|
wifiName = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,66 @@
|
|||||||
|
<?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">
|
||||||
|
|
||||||
|
<data>
|
||||||
|
|
||||||
|
<variable
|
||||||
|
name="checkState"
|
||||||
|
type="androidx.databinding.ObservableBoolean" />
|
||||||
|
|
||||||
|
<variable
|
||||||
|
name="adapter"
|
||||||
|
type="com.example.beijing_daxing.adapter.StoreCheckAdapter" />
|
||||||
|
</data>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
tools:context=".OffLineCheckActivity">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
style="@style/title_text"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="45dp"
|
||||||
|
android:text="轮挡巡检" />
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:adapter="@{adapter}"
|
||||||
|
android:background="@color/white"
|
||||||
|
android:padding="10dp"
|
||||||
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="55dp"
|
||||||
|
android:layout_marginTop="20dp"
|
||||||
|
android:layout_marginBottom="20dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginStart="20dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:backgroundTint="@{checkState?@color/yellow:@color/black}"
|
||||||
|
android:onClick="offCheckRead"
|
||||||
|
android:text='@{checkState?"停止读取":"开始扫描"}'
|
||||||
|
android:textSize="20sp" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
style="@style/button_style"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:onClick="store_check_submit"
|
||||||
|
android:text="提交" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
</layout>
|
||||||
Loading…
Reference in New Issue