添加 menu

master
wangh 6 months ago
parent 9b641db9c0
commit 2b9c76ddd4

@ -13,6 +13,10 @@
android:supportsRtl="true"
android:theme="@style/Theme.JinYuRFID"
tools:targetApi="31">
<activity
android:name=".ReadActivity"
android:exported="false" />
<receiver
android:name=".broadcast.ScanERCodeReceiver"
android:enabled="true"
@ -27,19 +31,21 @@
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> -->
</activity>

@ -0,0 +1,14 @@
package com.example.jinyu_rfid;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class ReadActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_read);
}
}

@ -7,7 +7,9 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.PopupMenu;
import android.widget.Toast;
import com.example.jinyu_rfid.adapter.ResultAdapter;
@ -35,19 +37,19 @@ import java.util.Optional;
import okhttp3.RequestBody;
public class WriteUserActivity extends BaseActivity implements DataReturnCall {
public class WriteUserActivity extends BaseActivity implements DataReturnCall, PopupMenu.OnMenuItemClickListener {
private Intent intent1;
private Intent intent2;
private RFIDModel rfidModel;
private ActivityWriteUserBinding binding;
private ResultAdapter adapter;
private List<ReadTyreNoResult> list;
private PopupMenu popupMenu;
@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(this);
intent1 = new Intent(this, ConfigurationTableActivity.class);
intent2 = new Intent(this, ConfigurationTableActivity.class);
@ -56,6 +58,9 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall {
adapter = new ResultAdapter(this);
binding.setAdapter(adapter);
popupMenu = new PopupMenu(this, binding.writeMenu);
popupMenu.setOnMenuItemClickListener(this);
getMenuInflater().inflate(R.menu.activity_menu, popupMenu.getMenu());
}
@ -67,7 +72,7 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall {
// 写入
public void writeUser(View view) {
/* if (list == null || list.isEmpty()) return;
if (list == null || list.isEmpty()) return;
var epcStr = binding.writeEpcCode.getText().toString();
if (epcStr.isEmpty()) return;
// EPC编码~胎号~品牌~规格~花纹~层级~轮胎名称~速度级别~负荷指数~轮辋直径~扁平比~销售区域
@ -77,13 +82,13 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall {
var configuration = tagList.get(i);
var state = configuration.isState();
tagUserStr.append("~");
*//* if (state) {
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);
@ -98,7 +103,7 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall {
}
String user = ASCIIUtil.str2Hex(tagUserStr.toString());
Log.e("TAG", "writeUser:" + user);
Log.e("TAG", "writeUser:" + user.length());*/
Log.e("TAG", "writeUser:" + user.length());
if (!writeUserState) {
Log.e("TAG", "writeUser:" + 1);
// writeUserState = rfidModel.writeUser(user, epcStr);
@ -115,23 +120,36 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall {
Log.e("TAG", "writeUser:" + 2);
OkGo.<MyResult>post(url + "/write")
.upRequestBody(RequestBody.create(JSON, gson.toJson(map))).execute(new MyRecultCall(dialog, this) {
});
.upRequestBody(RequestBody.create(JSON, gson.toJson(map)))
.execute(new MyRecultCall(dialog, this) {
@SuppressLint("NotifyDataSetChanged")
@Override
public void onSuccess(Response<MyResult> response) {
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();
return;
}
// writeUserState=false;
Toast.makeText(WriteUserActivity.this, body.getSaveMessage(), Toast.LENGTH_SHORT).show();
}
});
}
// writeUserState=false;
}
public void writeGoRead(View view) {
startActivity(intent1);
public void writeGoMenu(View view){
popupMenu.show();
}
public void writeGoConfiguration(View view) {
startActivity(intent2);
}
@Override
public void readEpcCodeInfo(String info, boolean state, String stateInfo) {
@ -155,7 +173,8 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall {
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) {
OkGo.<MyResult>post(url + "/readTyreNo").upRequestBody(RequestBody.create(JSON, gson.toJson(map)))
.execute(new MyRecultCall(dialog, this) {
@SuppressLint("NotifyDataSetChanged")
@Override
public void onSuccess(Response<MyResult> response) {
@ -174,4 +193,18 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall {
}
});
}
@Override
public boolean onMenuItemClick(MenuItem item) {
if (item.getItemId() == R.id.menu_read) {
startActivity(intent1);
}else {
startActivity(intent2);
}
return true;
}
}

@ -10,8 +10,26 @@ public class MyResult {
private Object ResultData;
private String json;
private String ResultFlag;
private String SaveFlag;
private String SaveMessage;
public String getSaveFlag() {
return SaveFlag;
}
public void setSaveFlag(String saveFlag) {
SaveFlag = saveFlag;
}
public String getSaveMessage() {
return SaveMessage;
}
public void setSaveMessage(String saveMessage) {
SaveMessage = saveMessage;
}
public String getResultFlag() {
return ResultFlag;
}

@ -0,0 +1,30 @@
<?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="title"
type="String" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ReadActivity">
<include
layout="@layout/toolbar"
app:title="@{title}" />
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
/>
</LinearLayout>
</layout>

@ -8,6 +8,7 @@
<variable
name="title"
type="String" />
<variable
name="adapter"
type="com.example.jinyu_rfid.adapter.ResultAdapter" />
@ -19,9 +20,41 @@
android:orientation="vertical"
tools:context=".WriteUserActivity">
<include
layout="@layout/toolbar"
app:title="@{title}" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:orientation="vertical">
<ImageView
android:layout_width="66dp"
android:layout_height="match_parent"
android:onClick="titleToolClick"
android:padding="16dp"
android:src="@mipmap/ic_back" />
<ImageView
android:id="@+id/write_menu"
android:layout_width="66dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:onClick="writeGoMenu"
android:padding="16dp"
android:src="@mipmap/menu" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/write_in"
android:textColor="@color/white"
android:textSize="22sp"
android:textStyle="bold" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
@ -42,13 +75,14 @@
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:layout_weight="1"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:adapter="@{adapter}"
android:padding="5dp"/>
android:padding="5dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
<LinearLayout
android:layout_width="match_parent"
@ -72,9 +106,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginStart="20dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="20dp">
android:layout_margin="10dp">
<Button
android:layout_width="match_parent"
@ -92,30 +124,7 @@
android:onClick="writeUser"
android:text="@string/write_in" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginStart="20dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="8dp"
android:layout_weight="1"
android:onClick="writeGoRead"
android:text="@string/go_read" />
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="8dp"
android:layout_weight="1"
android:onClick="writeGoConfiguration"
android:text="@string/go_configuration" />
</LinearLayout>
</LinearLayout>
</layout>

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group>
<item
android:id="@+id/menu_read"
android:title="@string/go_read" />
<item
android:id="@+id/menu_configuration"
android:title="@string/go_configuration" />
</group>
</menu>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

@ -10,7 +10,7 @@
<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_read">info reading</string>
<string name="go_configuration">go configuration</string>
<string name="epc_code">epc number</string>
<string name="configuration_add">add item</string>
@ -29,4 +29,5 @@
<string name="project_list_area">sales area</string>
<string name="write_failed">write failed</string>
<string name="write_success">write success</string>
<string name="binding_success">mes binding success</string>
</resources>

@ -11,7 +11,7 @@
<string name="read_epc">读取 epc</string>
<string name="write_in">信息写入</string>
<string name="go_read">信息读取</string>
<string name="go_configuration">写入配置</string>
<string name="go_configuration">配置</string>
<string name="epc_code">epc编码</string>
<string name="configuration_add">添加项目</string>
<string name="write_index">索引</string>
@ -28,5 +28,6 @@
<string name="project_list_flat">扁平比</string>
<string name="project_list_area">销售区域</string>
<string name="write_failed">写入失败</string>
<string name="write_success">写入成功</string>>
<string name="write_success">写入成功</string>
<string name="binding_success">MES 绑定成功</string>>
</resources>
Loading…
Cancel
Save