增加 设置功率

master
wangh 4 months ago
parent 644fb42674
commit f16dd3f01e

@ -48,7 +48,10 @@
<activity
android:name=".WriteUserActivity"
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"
@ -56,10 +59,7 @@
<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>
</activity>
</application>

@ -65,7 +65,6 @@ public class ReadActivity extends BaseActivity implements DataReturnCall {
// 名称
stringArray = getResources().getStringArray(R.array.project_list);
rfidModel = new C5106Device(this,this);
// rfidModel=new AutoID9UDevice(this,this);
}

@ -19,6 +19,8 @@ import com.example.jinyu_rfid.been.ConfigurationTable;
import com.example.jinyu_rfid.been.ReadTyreNoResult;
import com.example.jinyu_rfid.callback.DataReturnCall;
import com.example.jinyu_rfid.databinding.ActivityWriteUserBinding;
import com.example.jinyu_rfid.dialog.DialogCall;
import com.example.jinyu_rfid.dialog.MyAlertDialog;
import com.example.jinyu_rfid.rfid.AutoID9UDevice;
import com.example.jinyu_rfid.rfid.C5106Device;
import com.example.jinyu_rfid.rfid.RFIDModel;
@ -37,7 +39,7 @@ import java.util.Optional;
import okhttp3.RequestBody;
public class WriteUserActivity extends BaseActivity implements DataReturnCall, PopupMenu.OnMenuItemClickListener {
public class WriteUserActivity extends BaseActivity implements DataReturnCall, PopupMenu.OnMenuItemClickListener, DialogCall {
private Intent intent1;
private Intent intent2;
private RFIDModel rfidModel;
@ -45,7 +47,7 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
private ResultAdapter adapter;
private List<ReadTyreNoResult> list;
private PopupMenu popupMenu;
private MyAlertDialog myAlertDialog;
@SuppressLint("UnspecifiedRegisterReceiverFlag")
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -58,13 +60,21 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
popupMenu = new PopupMenu(this, binding.writeMenu);
popupMenu.setOnMenuItemClickListener(this);
getMenuInflater().inflate(R.menu.activity_menu, popupMenu.getMenu());
// rfidModel = new C5106Device(this,this);
rfidModel=new AutoID9UDevice(this,this);
rfidModel = new C5106Device(this, this);
// rfidModel = new AutoID9UDevice(this, this);
if (rfidModel instanceof C5106Device) {
intent1 = new Intent(this, ReadActivity.class);
} else {
intent1 = new Intent(this, Read2Activity.class);
}
myAlertDialog = new MyAlertDialog(this);
myAlertDialog.setDialogCall(this);
var power = SharedPreferencesUtils.getInt("power", 30);
Log.e("TAG", "记忆功率:" + power);
if (power!=30){
rfidModel.setPower(power);
}
}
@ -136,8 +146,8 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
}
}
private void writeUser(String user, String epcStr) {
Log.e("TAG", "写入");
var writeState = rfidModel.writeUser(validateDataLength(user), epcStr);
@ -152,7 +162,6 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
}
public String validateDataLength(String data) {
int length = data.length();
int remainder = length % 4;
@ -213,14 +222,30 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
@Override
public boolean onMenuItemClick(MenuItem item) {
if (item.getItemId() == R.id.menu_read) {
var itemId = item.getItemId();
if (itemId == R.id.menu_read) {
startActivity(intent1);
} else {
} else if (itemId == R.id.menu_configuration) {
startActivity(intent2);
} else if (itemId == R.id.menu_setPower) {
myAlertDialog.show(SharedPreferencesUtils.getInt("power",30));
}
return true;
}
@Override
public void returnData(int power) {
if (rfidModel.setPower(power)){
Toast.makeText(context, getString(R.string.tip_set_success), Toast.LENGTH_SHORT).show();
SharedPreferencesUtils.putInt("power",power);
myAlertDialog.dismiss();
return;
}
Toast.makeText(context, getString(R.string.tip_set_failed), Toast.LENGTH_SHORT).show();
}
}

@ -0,0 +1,9 @@
package com.example.jinyu_rfid.dialog;
/**
* @author wanghao
* @date 2024/4/25 9:12
*/
public interface DialogCall {
void returnData(int power );
}

@ -0,0 +1,59 @@
package com.example.jinyu_rfid.dialog;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.widget.EditText;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.example.jinyu_rfid.dialog.DialogCall;
import com.example.jinyu_rfid.R;
/**
* @author wanghao
* @date 2024/4/25 9:07
*/
public class MyAlertDialog extends Dialog {
private DialogCall dialogCall;
private int power;
public void setPower(int power) {
this.power = power;
}
public void setDialogCall(DialogCall dialogCall) {
this.dialogCall = dialogCall;
}
public MyAlertDialog(Context context) {
super(context, R.style.dialog);
}
private EditText editText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_power_layout);
editText = findViewById(R.id.dialog_text);
TextView textView = findViewById(R.id.dialog1_button);
textView.setOnClickListener(view -> {
String string = editText.getText().toString();
if (!string.isEmpty()) {
int power = Integer.parseInt(string);
Log.e("TAG", "onCreate:" + power);
if (power < 5 || power > 30) return;
dialogCall.returnData(power);
}
});
}
public void show(int power){
super.show();
editText.setText(power+"");
}
}

@ -36,7 +36,6 @@ public class AutoID9UDevice implements RFIDModel {
if (!uhfService.isopen()) {
uhfService.open();
}
Log.e("TAG", "上电:" + uhfService.isopen());
Log.e("TAG", "功率:" + uhfService.getPower());
scanERCodeReceiver = new AutoIDdeviceScanERCodeReceiver();
@ -128,6 +127,12 @@ public class AutoID9UDevice implements RFIDModel {
context.unregisterReceiver(scanERCodeReceiver);
}
@Override
public boolean setPower(int power) {
var b = uhfService.setPower(power);
return b;
}
class AutoIDdeviceScanERCodeReceiver extends BroadcastReceiver {

@ -27,6 +27,7 @@ public class C5106Device implements RFIDModel {
public C5106Device(DataReturnCall call, Context context) {
uhfrManager = UHFRManager.getInstance();
Log.e("TAG", "功率:" +uhfrManager.getPower()[0] );
this.call = call;
this.context = context;
scanERCodeReceiver = new ScanERCodeReceiver();
@ -78,7 +79,6 @@ public class C5106Device implements RFIDModel {
@Override
public void sanUser(int len) {
byte[] rdata = new byte[len * 2];
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());
@ -91,6 +91,13 @@ public class C5106Device implements RFIDModel {
context.unregisterReceiver(scanERCodeReceiver);
}
@Override
public boolean setPower(int power) {
Log.e("TAG", "开始设置功率:"+power );
var readerErr = uhfrManager.setPower(power, power);
return readerErr == Reader.READER_ERR.MT_OK_ERR;
}
class ScanERCodeReceiver extends BroadcastReceiver {
@Override

@ -16,4 +16,6 @@ public interface RFIDModel {
}
void close();
boolean setPower(int power);
}

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/dialog_bg"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="@string/tip_set_power"
android:textSize="20sp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#e1e1e1"/>
<EditText
android:id="@+id/dialog_text"
style="@style/text_name"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_margin="30dp"
android:inputType="number"
android:hint="5~30"
android:background="@drawable/san_text" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#e1e1e1"/>
<TextView
android:id="@+id/dialog1_button"
android:layout_width="match_parent"
android:layout_height="55dp"
android:text="@string/configuration_save"
android:textSize="18sp"
android:gravity="center"
android:letterSpacing="0.5"
android:textColor="@color/design_default_color_secondary"/>
</LinearLayout>

@ -7,5 +7,9 @@
<item
android:id="@+id/menu_configuration"
android:title="@string/go_configuration" />
<item
android:id="@+id/menu_setPower"
android:title="@string/tip_set_power" />
</group>
</menu>

@ -40,4 +40,7 @@
<string name="service_addr">service address</string>
<string name="server_port">service port</string>
<string name="label_error">Label error, unable to parse</string>
<string name="tip_set_power">Set power</string>
<string name="tip_set_success">Setting successful</string>
<string name="tip_set_failed">Setting failed</string>
</resources>

@ -41,4 +41,7 @@
<string name="service_addr">Địa chỉ dịch vụ</string>
<string name="server_port">Cổng dịch vụ</string>
<string name="label_error">Lỗi thẻ, không thể giải quyết</string>
<string name="tip_set_power">Đặt điện</string>
<string name="tip_set_success">Thiết lập thành công</string>
<string name="tip_set_failed">Thiết lập thất bại</string>
</resources>

@ -39,5 +39,8 @@
<string name="bluetooth_open_secess">蓝牙连接成功</string>
<string name="service_addr">服务地址</string>
<string name="server_port">服务端口</string>
<string name="label_error">标签错误,无法解析</string>>
<string name="label_error">标签错误,无法解析</string>
<string name="tip_set_power">设置功率</string>
<string name="tip_set_success">设置成功</string>
<string name="tip_set_failed">设置功率失败</string>>
</resources>
Loading…
Cancel
Save