完成 配置功能

master
wangh 6 months ago
parent fa86e651ce
commit a88d5e017f

@ -13,6 +13,15 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.JinYuRFID" android:theme="@style/Theme.JinYuRFID"
tools:targetApi="31"> 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 <activity
android:name=".WriteUserActivity" android:name=".WriteUserActivity"
android:exported="false" /> android:exported="false" />

@ -3,7 +3,9 @@ package com.example.jinyu_rfid;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil; import androidx.databinding.DataBindingUtil;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.View; import android.view.View;
import com.example.jinyu_rfid.adapter.ConfigurationTableAdapter; import com.example.jinyu_rfid.adapter.ConfigurationTableAdapter;
@ -18,9 +20,9 @@ import org.litepal.LitePal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class ConfigurationTableActivity extends BaseActivity implements ItemClickCall { public class ConfigurationTableActivity extends BaseActivity {
private ConfigurationTableAdapter adapter; private ConfigurationTableAdapter adapter;
private List<ConfigurationTable> list;
private List<ConfigurationData> dataList; private List<ConfigurationData> dataList;
@Override @Override
@ -28,30 +30,43 @@ public class ConfigurationTableActivity extends BaseActivity implements ItemClic
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
ActivityConfigurationTableBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_configuration_table); ActivityConfigurationTableBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_configuration_table);
binding.setTitle(getString(R.string.activity_name_configuration)); binding.setTitle(getString(R.string.activity_name_configuration));
adapter = new ConfigurationTableAdapter(this, this); adapter = new ConfigurationTableAdapter(this);
list = LitePal.findAll(ConfigurationTable.class); var stringArray = getResources().getStringArray(R.array.project_list);
dataList = new ArrayList<>(); var length = stringArray.length;
if (list != null || !list.isEmpty()) { dataList = new ArrayList<>(length);
list.forEach(t->{ for (int i = 0; i < length; i++) {
ConfigurationData data=new ConfigurationData(t.getIndex(),t.getProjectName(),false); dataList.add(new ConfigurationData(i, stringArray[i], findStateByIndex(i)));
dataList.add(data);
});
} }
adapter.setList(dataList); adapter.setList(dataList);
binding.setAdapter(adapter); binding.setAdapter(adapter);
} }
@Override
public void onClick(int position) {
} /* public void configurationAddItem(View view) {
public void configurationAddItem(View view) { }*/
}
public void configurationSave(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,56 +1,73 @@
package com.example.jinyu_rfid; package com.example.jinyu_rfid;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil; import androidx.databinding.DataBindingUtil;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.Toast;
import com.example.jinyu_rfid.base.BaseActivity; 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.callback.DataReturnCall;
import com.example.jinyu_rfid.databinding.ActivityWriteUserBinding; import com.example.jinyu_rfid.databinding.ActivityWriteUserBinding;
import com.example.jinyu_rfid.rfid.C5106Device; import com.example.jinyu_rfid.rfid.C5106Device;
import com.example.jinyu_rfid.rfid.RFIDModel; import com.example.jinyu_rfid.rfid.RFIDModel;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.OkGo; 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 { public class WriteUserActivity extends BaseActivity implements DataReturnCall {
private Intent intent1; private Intent intent1;
private Intent intent2; private Intent intent2;
private RFIDModel rfidModel; private RFIDModel rfidModel;
private ActivityWriteUserBinding binding; private ActivityWriteUserBinding binding;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_write_user); binding = DataBindingUtil.setContentView(this, R.layout.activity_write_user);
binding.setTitle(getString(R.string.activity_name_configuration)); 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); startActivity(intent1);
} }
public void writeGoConfiguration(View view){
public void writeGoConfiguration(View view) {
startActivity(intent2); startActivity(intent2);
} }
@Override @Override
public void readEpcCodeInfo(String epc) { public void readEpcCodeInfo(String epc) {
binding.writeEpcCode.setText(epc); binding.writeEpcCode.setText(epc);
} }
@Override @Override
@ -61,7 +78,22 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall {
@Override @Override
public void readerCodeInfo(String erCode) { public void readerCodeInfo(String erCode) {
binding.writeTire.setText(erCode); binding.writeTire.setText(erCode);
// OkGo.post(url+"/readTypeNo") Map<String,String> map=new HashMap<>();
// .params("") 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> { public class ConfigurationTableAdapter extends RecyclerView.Adapter<ConfigurationTableAdapter.MyViewHolder> {
private Context context; private Context context;
private LayoutInflater inflater; private LayoutInflater inflater;
private ItemClickCall call;
private List<ConfigurationData> list; private List<ConfigurationData> list;
public ConfigurationTableAdapter(Context context, ItemClickCall call) { public ConfigurationTableAdapter(Context context) {
this.context = context; this.context = context;
this.call = call;
inflater=LayoutInflater.from(context); inflater=LayoutInflater.from(context);
} }

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

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

@ -46,4 +46,13 @@ public class ConfigurationData extends BaseObservable {
public void setState(boolean state) { public void setState(boolean state) {
this.state = 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) { public void setState(boolean state) {
this.state = 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 <TextView
android:id="@+id/item_index" android:id="@+id/item_index"
style="@style/item_text_style" style="@style/item_text_style"
android:layout_width="40dp" android:layout_width="60dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:text="索引" /> android:text="@string/write_index" />
<View <View
android:layout_width="2dp" android:layout_width="2dp"
@ -43,9 +43,9 @@
<TextView <TextView
style="@style/item_text_style" style="@style/item_text_style"
android:layout_width="70dp" android:layout_width="100dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:text="是否写入" /> android:text="@string/write_state" />
<View <View
android:layout_width="2dp" android:layout_width="2dp"
@ -57,19 +57,9 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1" 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> </LinearLayout>
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent" android:layout_width="match_parent"
@ -86,14 +76,14 @@
android:layout_height="50dp" android:layout_height="50dp"
android:layout_margin="15dp"> android:layout_margin="15dp">
<Button <!-- <Button
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:layout_weight="1" android:layout_weight="1"
android:textSize="18sp" android:textSize="18sp"
android:onClick="configurationAddItem" android:onClick="configurationAddItem"
android:text="@string/configuration_add" /> android:text="@string/configuration_add" />-->
<Button <Button
android:layout_width="match_parent" android:layout_width="match_parent"

@ -18,7 +18,7 @@
<TextView <TextView
android:id="@+id/item_index" android:id="@+id/item_index"
style="@style/item_text_style" style="@style/item_text_style"
android:layout_width="40dp" android:layout_width="60dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:text='@{item.index+""}' /> android:text='@{item.index+""}' />
@ -29,7 +29,7 @@
<CheckBox <CheckBox
style="@style/item_text_style" style="@style/item_text_style"
android:layout_width="70dp" android:layout_width="100dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:checked="@={item.state}" /> android:checked="@={item.state}" />
@ -45,17 +45,8 @@
android:layout_weight="1" android:layout_weight="1"
android:text="@{item.projectName}" /> 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> </LinearLayout>
</layout> </layout>

@ -3,15 +3,28 @@
<string name="user_name">login name</string> <string name="user_name">login name</string>
<string name="pass_word">pass word</string> <string name="pass_word">pass word</string>
<string name="login_button_name" >login</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="language_select">language :</string>
<string name="activity_name_configuration">app configuration</string> <string name="activity_name_configuration">app configuration</string>
<string name="configuration_save">save</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="read_epc">read epc</string>
<string name="write_in">write in</string> <string name="write_in">write in</string>
<string name="go_read">go info reading</string> <string name="go_read">go info reading</string>
<string name="go_configuration">go configuration</string> <string name="go_configuration">go configuration</string>
<string name="epc_code">epc number</string> <string name="epc_code">epc number</string>
<string name="configuration_add">add item</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> </resources>

@ -4,4 +4,19 @@
<item>English</item> <item>English</item>
<item>中文</item> <item>中文</item>
</string-array> </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> </resources>

@ -13,5 +13,18 @@
<string name="go_read">信息读取</string> <string name="go_read">信息读取</string>
<string name="go_configuration">写入配置</string> <string name="go_configuration">写入配置</string>
<string name="epc_code">epc编码</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> </resources>
Loading…
Cancel
Save