增加 读取网络模式

master
wangh 6 months ago
parent ce32ecb483
commit c428464f45

@ -13,35 +13,42 @@
android:supportsRtl="true"
android:theme="@style/Theme.JinYuRFID"
tools:targetApi="31">
<activity
android:name=".AppLoginActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".broadcast.ScanERCodeReceiver"
android:enabled="true"
android:exported="true" />
<activity
android:name=".AppLoginActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ReadActivity"
android:exported="true"/>
android:exported="true" />
<activity
android:name=".WriteUserActivity"
android:exported="false" />
android:exported="true">
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
</activity>
<activity
android:name=".ConfigurationTableActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
</activity>
</application>

@ -7,6 +7,7 @@ import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import com.example.jinyu_rfid.databinding.ActivityAppLoginBinding;
@ -42,15 +43,18 @@ public class AppLoginActivity extends AppCompatActivity {
// 工作模式 0=net
var workModeStr = binding.mainWork.getSelectedItem().toString();
var strings = Arrays.asList(getResources().getStringArray(R.array.work_mode));
SharedPreferencesUtils.putInt("workmode", strings.indexOf(workModeStr));
var value = strings.indexOf(workModeStr);
SharedPreferencesUtils.putInt("workmode", value);
// 选择语言
var s = binding.appLanguage.getSelectedItem().toString();
SharedPreferencesUtils.putstring("language", s);
getLocaleStringXML(s);
resources.updateConfiguration(config, resources.getDisplayMetrics());
startActivity(new Intent(this, ReadActivity.class));
//
var intent = new Intent(this, ReadActivity.class);
Log.e("TAG", "appLoginClick:" + value);
intent.putExtra("work",value);
startActivity(intent);
finish();
}

@ -6,47 +6,94 @@ import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import com.example.jinyu_rfid.adapter.ResultAdapter;
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.callback.DataReturnCall;
import com.example.jinyu_rfid.databinding.ActivityReadBinding;
import com.example.jinyu_rfid.rfid.C5106Device;
import com.example.jinyu_rfid.rfid.RFIDModel;
import com.example.jinyu_rfid.uitls.ASCIIUtil;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import okhttp3.RequestBody;
public class ReadActivity extends BaseActivity implements DataReturnCall {
private ResultAdapter adapter;
private RFIDModel rfidModel;
private String[] stringArray;
private List<ReadTyreNoResult> list;
private ActivityReadBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityReadBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_read);
binding = DataBindingUtil.setContentView(this, R.layout.activity_read);
binding.setTitle(getString(R.string.go_read));
adapter = new ResultAdapter(this);
list = new ArrayList<>(11);
adapter.setList(list);
binding.setAdapter(adapter);
// 名称
var workmode = getIntent().getIntExtra("work", 0);
binding.setType(workmode == 1);
// 名称
stringArray = getResources().getStringArray(R.array.project_list);
rfidModel = new C5106Device(this);
list = new ArrayList<>(11);
adapter.setList(list);
}
public void readInfo(View view) {
rfidModel.sanUser(80);
}
public void readEPCInfo(View view) {
rfidModel.sanEpc(6);
}
@SuppressLint("NotifyDataSetChanged")
@Override
public void readEpcCodeInfo(String info, boolean state, String stateInfo) {
if (state) {
music.start();
list.clear();
binding.readText.setText(info);
Map<String, String> map = new HashMap<>();
map.put("EpcCode", info);
map.put("token", "123456");
OkGo.<MyResult>post(url + "/readEPCCode")
.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.addAll(gson.fromJson(body.getJson(),new TypeToken<List<ReadTyreNoResult>>(){}.getType()));
adapter.notifyDataSetChanged();
} else {
Toast.makeText(ReadActivity.this, body.getJson(), Toast.LENGTH_SHORT).show();
adapter.notifyDataSetChanged();
}
}
});
}else {
binding.readText.setText(null);
}
}
@SuppressLint("NotifyDataSetChanged")
@ -54,16 +101,23 @@ public class ReadActivity extends BaseActivity implements DataReturnCall {
public void readUserInfo(String user, boolean state, String stateInfo) {
list.clear();
if (state) {
binding.readText.setText(user);
music.start();
String info = ASCIIUtil.hex2Str(user);
Log.e("TAG", "readUserInfo:" + info);
var infos = info.split("~");
for (int i = 0; i < 12; i++) {
list.add( new ReadTyreNoResult(i,stringArray[i],infos[i]));
list.add(new ReadTyreNoResult(i, stringArray[i], infos[i]));
}
}else {
binding.readText.setText(null);
}
adapter.notifyDataSetChanged();
}
@Override
protected void onDestroy() {
super.onDestroy();
rfidModel.close();
}
}

@ -52,6 +52,7 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
binding = DataBindingUtil.setContentView(this, R.layout.activity_write_user);
rfidModel = new C5106Device(this);
intent1 = new Intent(this, ReadActivity.class);
intent1.putExtra("work", 1);
intent2 = new Intent(this, ConfigurationTableActivity.class);
ScanERCodeReceiver scanERCodeReceiver = new ScanERCodeReceiver(this);
registerReceiver(scanERCodeReceiver, new IntentFilter("com.rfid.SCAN"));
@ -70,6 +71,7 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
private boolean writeUserState = false;
// 写入
@SuppressLint("NotifyDataSetChanged")
public void writeUser(View view) {
if (list == null || list.isEmpty()) return;
var epcStr = binding.writeEpcCode.getText().toString();
@ -81,14 +83,6 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
for (int i = 1; i < 12; i++) {
var configuration = tagList.get(i);
var state = configuration.isState();
/* if (state) {
Optional<ReadTyreNoResult> optionalResult = Optional.ofNullable(list.get(i - 1));
String propertyContent = optionalResult.map(ReadTyreNoResult::getPropertyContent).orElse("_");
tagUserStr.append(propertyContent);
} else {
tagUserStr.append("_");
}*/
if (state) {
try {
var result = list.get(i - 1);
@ -105,12 +99,7 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
String user = ASCIIUtil.str2Hex(tagUserStr.toString());
if (!writeUserState) {
Log.e("TAG", "writeUser:" + 1);
writeUserState = rfidModel.writeUser(validateDataLength(user), epcStr);
Toast.makeText(context, getString(writeUserState ? R.string.write_success : R.string.write_failed), Toast.LENGTH_SHORT).show();
}
if (writeUserState) {
Log.e("TAG", "请求");
Map<String, String> map = new HashMap<>();
map.put("EpcCode", epcStr);
map.put("TyreNo", list.get(0).getPropertyContent());
@ -123,12 +112,8 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
super.onSuccess(response);
var body = response.body();
if (body.getSaveFlag().equals("1")) {
list.clear();
adapter.notifyDataSetChanged();
binding.writeEpcCode.setText(null);
binding.writeTire.setText(null);
Toast.makeText(WriteUserActivity.this, getString(R.string.binding_success), Toast.LENGTH_SHORT).show();
writeUserState = false;
writeUserState = true;
return;
}
Toast.makeText(WriteUserActivity.this, body.getSaveMessage(), Toast.LENGTH_SHORT).show();
@ -136,7 +121,18 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
});
}
if (writeUserState){
Log.e("TAG", "写入");
var writeState = rfidModel.writeUser(validateDataLength(user), epcStr);
Toast.makeText(context, getString(writeState ? R.string.write_success : R.string.write_failed), Toast.LENGTH_SHORT).show();
if (writeState) {
list.clear();
adapter.notifyDataSetChanged();
binding.writeEpcCode.setText(null);
binding.writeTire.setText(null);
writeUserState=false;
}
}
}
@ -157,8 +153,6 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
}
@Override
public void readEpcCodeInfo(String info, boolean state, String stateInfo) {
if (state) {
@ -196,7 +190,11 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
}
});
}
public void writeGoMenu(View view) {popupMenu.show();}
public void writeGoMenu(View view) {
popupMenu.show();
}
@Override
public boolean onMenuItemClick(MenuItem item) {
if (item.getItemId() == R.id.menu_read) {

@ -11,7 +11,7 @@ public class ReadTyreNoResult {
"PropertyContent": "32432040640",
"PropertyIndex": 1
*/
private String PropertyName, PropertyContent;
private String PropertyName, PropertyContent,IsShow;
private int PropertyIndex;
public ReadTyreNoResult() {
@ -21,6 +21,22 @@ public class ReadTyreNoResult {
PropertyName = propertyName;
PropertyContent = propertyContent;
PropertyIndex = propertyIndex;
IsShow="1";
}
public ReadTyreNoResult(String propertyName, String propertyContent, String isShow, int propertyIndex) {
PropertyName = propertyName;
PropertyContent = propertyContent;
IsShow = isShow;
PropertyIndex = propertyIndex;
}
public String getIsShow() {
return IsShow;
}
public void setIsShow(String isShow) {
IsShow = isShow;
}
public String getPropertyName() {

@ -71,4 +71,10 @@ public class C5106Device implements RFIDModel {
Reader.READER_ERR readerErr = uhfrManager.getTagData(3, 0, len, rdata, accessBytes, (short) 200);
call.readUserInfo(Tools.Bytes2HexString(rdata, rdata.length), readerErr == Reader.READER_ERR.MT_OK_ERR, readerErr.toString());
}
@Override
public void close() {
if (uhfrManager != null)
uhfrManager.close();
}
}

@ -10,4 +10,5 @@ public interface RFIDModel {
boolean writeUser(String writeStr, String tagEpc);
void sanUser(int len);
void close();
}

@ -8,9 +8,16 @@
<variable
name="title"
type="String" />
<variable
name="adapter"
type="com.example.jinyu_rfid.adapter.ResultAdapter" />
<variable
name="type"
type="Boolean" />
<import type="android.view.View" />
</data>
<LinearLayout
@ -22,21 +29,52 @@
<include
layout="@layout/toolbar"
app:title="@{title}" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="8dp">
<TextView
style="@style/text_name"
android:layout_width="120dp"
android:layout_height="match_parent"
android:text="@string/scanning_area" />
<TextView
android:id="@+id/read_text"
style="@style/text_name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/san_text" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
android:layout_weight="1"
android:adapter="@{adapter}"
android:padding="8dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
<Button
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_margin="10dp"
android:onClick="readInfo"
android:text="@string/go_read"
android:textSize="18sp"
android:visibility="@{type?View.VISIBLE:View.GONE}" />
<Button
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_margin="10dp"
android:onClick="readEPCInfo"
android:text="@string/read_epc"
android:textSize="18sp"
android:onClick="readInfo"
android:text="@string/go_read" />
android:visibility="@{type?View.GONE:View.VISIBLE}" />
</LinearLayout>
</layout>

@ -33,4 +33,5 @@
<string name="work_model_select">working mode</string>
<string name="net_model">network mode</string>
<string name="standalone_mode">"standalone mode "</string>
<string name="scanning_area">scanning area</string>
</resources>

@ -34,4 +34,5 @@
<string name="work_model_select">Chế độ làm việc</string>
<string name="net_model">Chế độ mạng</string>
<string name="standalone_mode">Chế độ đơn</string>
<string name="scanning_area">Khu vực quét</string>
</resources>

@ -32,5 +32,6 @@
<string name="binding_success">MES 绑定成功</string>
<string name="work_model_select">工作模式</string>
<string name="net_model">网络模式</string>
<string name="standalone_mode">单机模式</string>>
<string name="standalone_mode">单机模式</string>
<string name="scanning_area">扫描区域</string>>
</resources>
Loading…
Cancel
Save