完成 配置功能

master
wangh 6 months ago
parent fa86e651ce
commit a88d5e017f

@ -13,6 +13,15 @@
android:supportsRtl="true"
android:theme="@style/Theme.JinYuRFID"
tools:targetApi="31">
<receiver
android:name=".broadcast.ScanERCodeReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.rfid.SCAN1"/>
</intent-filter>
</receiver>
<activity
android:name=".WriteUserActivity"
android:exported="false" />

@ -3,7 +3,9 @@ package com.example.jinyu_rfid;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import com.example.jinyu_rfid.adapter.ConfigurationTableAdapter;
@ -18,9 +20,9 @@ import org.litepal.LitePal;
import java.util.ArrayList;
import java.util.List;
public class ConfigurationTableActivity extends BaseActivity implements ItemClickCall {
public class ConfigurationTableActivity extends BaseActivity {
private ConfigurationTableAdapter adapter;
private List<ConfigurationTable> list;
private List<ConfigurationData> dataList;
@Override
@ -28,30 +30,43 @@ public class ConfigurationTableActivity extends BaseActivity implements ItemClic
super.onCreate(savedInstanceState);
ActivityConfigurationTableBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_configuration_table);
binding.setTitle(getString(R.string.activity_name_configuration));
adapter = new ConfigurationTableAdapter(this, this);
list = LitePal.findAll(ConfigurationTable.class);
dataList = new ArrayList<>();
if (list != null || !list.isEmpty()) {
list.forEach(t->{
ConfigurationData data=new ConfigurationData(t.getIndex(),t.getProjectName(),false);
dataList.add(data);
});
adapter = new ConfigurationTableAdapter(this);
var stringArray = getResources().getStringArray(R.array.project_list);
var length = stringArray.length;
dataList = new ArrayList<>(length);
for (int i = 0; i < length; i++) {
dataList.add(new ConfigurationData(i, stringArray[i], findStateByIndex(i)));
}
adapter.setList(dataList);
binding.setAdapter(adapter);
}
@Override
public void onClick(int position) {
}
/* public void configurationAddItem(View view) {
public void configurationAddItem(View view) {
}
}*/
public void configurationSave(View view) {
Log.e("TAG", "configurationSave:" + dataList.toString());
LitePal.deleteAll(ConfigurationTable.class);
dataList.forEach(t->{
ConfigurationTable configurationTable=new ConfigurationTable();
configurationTable.setIndex(t.getIndex());
configurationTable.setState(t.isState());
configurationTable.save();
});
var intent = new Intent(this, WriteUserActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
finish();
}
private boolean findStateByIndex(int index) {
var list = LitePal.where("index = "+ index).limit(1).find(ConfigurationTable.class);
if (list==null||list.isEmpty()){
return false;
}
return list.get(0).isState();
}
}

@ -1,50 +1,67 @@
package com.example.jinyu_rfid;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
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.broadcast.ScanERCodeReceiver;
import com.example.jinyu_rfid.callback.DataReturnCall;
import com.example.jinyu_rfid.databinding.ActivityWriteUserBinding;
import com.example.jinyu_rfid.rfid.C5106Device;
import com.example.jinyu_rfid.rfid.RFIDModel;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import okhttp3.RequestBody;
public class WriteUserActivity extends BaseActivity implements DataReturnCall {
private Intent intent1;
private Intent intent2;
private RFIDModel rfidModel;
private ActivityWriteUserBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_write_user);
binding.setTitle(getString(R.string.activity_name_configuration));
rfidModel = new C5106Device();
intent1 = new Intent(this, ConfigurationTableActivity.class);
intent2 = new Intent(this, ConfigurationTableActivity.class);
ScanERCodeReceiver scanERCodeReceiver = new ScanERCodeReceiver(this);
registerReceiver(scanERCodeReceiver, new IntentFilter("com.rfid.SCAN"));
rfidModel=new C5106Device();
intent1=new Intent(this, ConfigurationTableActivity.class);
intent2=new Intent(this, ConfigurationTableActivity.class);
}
public void writeReadEPC(View view){
public void writeReadEPC(View view) {
}
public void writeUser(View view){
}
public void writeUser(View view) {
}
public void writeGoRead(View view){
public void writeGoRead(View view) {
startActivity(intent1);
}
public void writeGoConfiguration(View view){
public void writeGoConfiguration(View view) {
startActivity(intent2);
}
@ -61,7 +78,22 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall {
@Override
public void readerCodeInfo(String erCode) {
binding.writeTire.setText(erCode);
// OkGo.post(url+"/readTypeNo")
// .params("")
Map<String,String> map=new HashMap<>();
map.put("TyreNo", erCode);
map.put("token","123456");
OkGo.<MyResult>post(url + "/readTyreNo")
.upRequestBody(RequestBody.create(JSON,gson.toJson(map)))
.execute(new MyRecultCall(dialog, this) {
@Override
public void onSuccess(Response<MyResult> response) {
super.onSuccess(response);
var body = response.body();
if (body.getResultFlag().equals("1")){
List<ReadTyreNoResult> list=gson.fromJson(body.getJson(),new TypeToken<List<ReadTyreNoResult>>(){}.getType());
return;
}
Toast.makeText(WriteUserActivity.this, body.getResultData().toString(), Toast.LENGTH_SHORT).show();
}
});
}
}

@ -25,11 +25,11 @@ import java.util.List;
public class ConfigurationTableAdapter extends RecyclerView.Adapter<ConfigurationTableAdapter.MyViewHolder> {
private Context context;
private LayoutInflater inflater;
private ItemClickCall call;
private List<ConfigurationData> list;
public ConfigurationTableAdapter(Context context, ItemClickCall call) {
public ConfigurationTableAdapter(Context context) {
this.context = context;
this.call = call;
inflater=LayoutInflater.from(context);
}

@ -34,7 +34,7 @@ public class MyApplication extends Application {
application = this;
SharedPreferencesUtils.init(getApplicationContext(), "myapp");
okGoBase();
LitePal.initialize(this);
}

@ -9,6 +9,16 @@ public class MyResult {
private String VerifyMessage;
private Object ResultData;
private String json;
private String ResultFlag;
public String getResultFlag() {
return ResultFlag;
}
public void setResultFlag(String resultFlag) {
ResultFlag = resultFlag;
}
public String getJson() {
return json;

@ -46,4 +46,13 @@ public class ConfigurationData extends BaseObservable {
public void setState(boolean state) {
this.state = state;
}
@Override
public String toString() {
return "ConfigurationData{" +
"index=" + index +
", projectName='" + projectName + '\'' +
", state=" + state +
'}';
}
}

@ -43,4 +43,14 @@ public class ConfigurationTable extends LitePalSupport {
public void setState(boolean state) {
this.state = state;
}
@Override
public String toString() {
return "ConfigurationTable{" +
"id=" + id +
", index=" + index +
", projectName='" + projectName + '\'' +
", state=" + state +
'}';
}
}

@ -0,0 +1,40 @@
package com.example.jinyu_rfid.been;
/**
* @author wanghao
* @date 2024/5/20 16:33
*/
public class ReadTyreNoResult {
/**
*
"PropertyName": "胎号",
"PropertyContent": "32432040640",
"PropertyIndex": 1
*/
private String PropertyName, PropertyContent;
private int PropertyIndex;
public String getPropertyName() {
return PropertyName;
}
public void setPropertyName(String propertyName) {
PropertyName = propertyName;
}
public String getPropertyContent() {
return PropertyContent;
}
public void setPropertyContent(String propertyContent) {
PropertyContent = propertyContent;
}
public int getPropertyIndex() {
return PropertyIndex;
}
public void setPropertyIndex(int propertyIndex) {
PropertyIndex = propertyIndex;
}
}

@ -0,0 +1,29 @@
package com.example.jinyu_rfid.broadcast;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import com.example.jinyu_rfid.callback.DataReturnCall;
public class ScanERCodeReceiver extends BroadcastReceiver {
private DataReturnCall call;
public ScanERCodeReceiver() {
}
public ScanERCodeReceiver(DataReturnCall call) {
this.call = call;
}
@Override
public void onReceive(Context context, Intent intent) {
byte[] data = intent.getByteArrayExtra("data");
if (data != null) {
String barcode = new String(data);
Log.e("", "onReceive, data:" + barcode);
call.readerCodeInfo(barcode);
}
}
}

@ -32,9 +32,9 @@
<TextView
android:id="@+id/item_index"
style="@style/item_text_style"
android:layout_width="40dp"
android:layout_width="60dp"
android:layout_height="match_parent"
android:text="索引" />
android:text="@string/write_index" />
<View
android:layout_width="2dp"
@ -43,9 +43,9 @@
<TextView
style="@style/item_text_style"
android:layout_width="70dp"
android:layout_width="100dp"
android:layout_height="match_parent"
android:text="是否写入" />
android:text="@string/write_state" />
<View
android:layout_width="2dp"
@ -57,19 +57,9 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="写入项目" />
android:text="@string/write_project" />
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="@color/white" />
<TextView
android:id="@+id/item_config_delete"
style="@style/item_text_style"
android:layout_width="63dp"
android:layout_height="match_parent"
android:textColor="#E71717" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
@ -86,14 +76,14 @@
android:layout_height="50dp"
android:layout_margin="15dp">
<Button
<!-- <Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="8dp"
android:layout_weight="1"
android:textSize="18sp"
android:onClick="configurationAddItem"
android:text="@string/configuration_add" />
android:text="@string/configuration_add" />-->
<Button
android:layout_width="match_parent"

@ -18,7 +18,7 @@
<TextView
android:id="@+id/item_index"
style="@style/item_text_style"
android:layout_width="40dp"
android:layout_width="60dp"
android:layout_height="match_parent"
android:text='@{item.index+""}' />
@ -29,7 +29,7 @@
<CheckBox
style="@style/item_text_style"
android:layout_width="70dp"
android:layout_width="100dp"
android:layout_height="match_parent"
android:checked="@={item.state}" />
@ -45,17 +45,8 @@
android:layout_weight="1"
android:text="@{item.projectName}" />
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="@color/white" />
<TextView
android:id="@+id/item_config_delete"
style="@style/item_text_style"
android:layout_width="63dp"
android:layout_height="match_parent"
android:text="删除"
android:textColor="#E71717" />
</LinearLayout>
</layout>

@ -3,15 +3,28 @@
<string name="user_name">login name</string>
<string name="pass_word">pass word</string>
<string name="login_button_name" >login</string>
<string name="remember_me">Remember me</string>
<string name="remember_me">remember me</string>
<string name="language_select">language :</string>
<string name="activity_name_configuration">app configuration</string>
<string name="configuration_save">save</string>
<string name="tire_number">Tire number</string>
<string name="tire_number">tire number</string>
<string name="read_epc">read epc</string>
<string name="write_in">write in</string>
<string name="go_read">go info reading</string>
<string name="go_configuration">go configuration</string>
<string name="epc_code">epc number</string>
<string name="configuration_add">add item</string>
<string name="write_index">index</string>
<string name="write_state">write or not</string>
<string name="write_project">write project</string>
<string name="project_list_brand">brand</string>
<string name="project_list_specifications">specifications</string>
<string name="project_list_pattern">pattern</string>
<string name="project_list_hierarchy">hierarchy</string>
<string name="project_list_name">tire name</string>
<string name="project_list_speed">speed level</string>
<string name="project_list_load">load index</string>
<string name="project_list_rim">rim diameter</string>
<string name="project_list_flat">flat ratio</string>
<string name="project_list_area">sales area</string>
</resources>

@ -4,4 +4,19 @@
<item>English</item>
<item>中文</item>
</string-array>
<string-array name="project_list">
<item>@string/epc_code</item>
<item>@string/tire_number</item>
<item>@string/project_list_brand</item>
<item>@string/project_list_specifications</item>
<item>@string/project_list_pattern</item>
<item>@string/project_list_hierarchy</item>
<item>@string/project_list_name</item>
<item>@string/project_list_speed</item>
<item>@string/project_list_load</item>
<item>@string/project_list_rim</item>
<item>@string/project_list_flat</item>
<item>@string/project_list_area</item>
</string-array>
</resources>

@ -13,5 +13,18 @@
<string name="go_read">信息读取</string>
<string name="go_configuration">写入配置</string>
<string name="epc_code">epc编码</string>
<string name="configuration_add">添加项目</string>>
<string name="configuration_add">添加项目</string>
<string name="write_index">索引</string>
<string name="write_state">是否写入</string>
<string name="write_project">写入项目</string>
<string name="project_list_brand">品牌</string>
<string name="project_list_specifications">规格</string>
<string name="project_list_pattern">花纹</string>
<string name="project_list_hierarchy">层级</string>
<string name="project_list_name">轮胎名称</string>
<string name="project_list_speed">速度级别</string>
<string name="project_list_load">负荷指数</string>
<string name="project_list_rim">轮辋直径</string>
<string name="project_list_flat">扁平比</string>
<string name="project_list_area">销售区域</string>>
</resources>
Loading…
Cancel
Save