Browse Source

餐盘绑定app

plate
applelon 8 months ago
parent
commit
ef04b7a8e2
10 changed files with 531 additions and 12 deletions
  1. +2
    -0
      app/build.gradle
  2. +6
    -10
      app/src/main/AndroidManifest.xml
  3. +261
    -0
      app/src/main/java/com/bpa/scalage/PlateActivity.java
  4. BIN
     
  5. BIN
     
  6. BIN
     
  7. +30
    -0
      app/src/main/res/drawable/switch_button_background.xml
  8. +189
    -0
      app/src/main/res/layout/activity_plate.xml
  9. +41
    -0
      app/src/main/res/layout/pop_scanner_view.xml
  10. +2
    -2
      app/src/main/res/values/strings.xml

+ 2
- 0
app/build.gradle View File

@@ -40,6 +40,8 @@ dependencies {
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
implementation files('libs\\PC_RFID.jar')
implementation files('libs\\gson-2.2.2.jar')
implementation files('libs\\PC_RFID.jar')
implementation files('libs\\HidPosLib_v104.jar')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'


+ 6
- 10
app/src/main/AndroidManifest.xml View File

@@ -7,7 +7,9 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<uses-feature android:name="android.hardware.usb.host" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.USB_PERMISSION" />
<uses-feature android:name="android.hardware.usb.host" android:required="true"/>

<application
android:allowBackup="true"
@@ -16,12 +18,9 @@
android:roundIcon="@drawable/hbl2"
android:supportsRtl="true"
android:theme="@style/FullscreenTheme">

<activity
android:name=".SystemSetActivity"
android:exported="false"
android:windowSoftInputMode="adjustPan|stateHidden" />
<activity
android:name=".MenuSelectionActivity"
android:name=".PlateActivity"
android:configChanges="orientation|screenSize|keyboard|keyboardHidden|navigation"
android:exported="true">
<intent-filter>
@@ -29,10 +28,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize|keyboard|keyboardHidden|navigation"
android:label="@string/app_name"></activity>
<service android:name="com.wsm.hidlib.service.HIDService"/>

<receiver
android:name=".app.BootReceiver"


+ 261
- 0
app/src/main/java/com/bpa/scalage/PlateActivity.java View File

@@ -0,0 +1,261 @@
package com.bpa.scalage;

import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.pc_rfid.api.PC_API;
import com.pc_rfid.api.RFdata;
import com.wsm.hidlib.HIDManager;
import com.wsm.hidlib.callback.HIDDataListener;
import com.wsm.hidlib.callback.HIDOpenListener;
import com.wsm.hidlib.callback.HIDSequenceNumberListener;
import com.wsm.hidlib.constant.FormatConstant;
import com.wsm.hidlib.util.StringFormat;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Queue;

public class PlateActivity extends AppCompatActivity {

private Button btnWrite,btnScan;
private CheckBox cbOpen;
private TextView txtStatus,txtCardUid,txtCardContent,txtCatdEwm;
private EditText etData;

private HIDSequenceNumberListener mHidSequenceNumberListener;

private PC_API pcApi=new PC_API();
private RFdata rFdata=new RFdata();
private boolean isConnected;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_plate);
cbOpen=findViewById(R.id.cb_open);
btnWrite=findViewById(R.id.btn_write);
btnScan=findViewById(R.id.btn_scan);
txtStatus=findViewById(R.id.txt_status);
txtCardUid=findViewById(R.id.txt_cardUid);
txtCardContent=findViewById(R.id.txt_cardContent);
txtCatdEwm=findViewById(R.id.txt_cardEwm);
etData=findViewById(R.id.et_data);


txtStatus.setText("未就绪");
btnWrite.setEnabled(false);
cbOpen.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if(b){
if(isConnected)
return;
boolean res = pcApi.PC_OpenCOM("/dev/ttyS4", 38400, "8N1");
if (res) {
txtStatus.setText("已就绪");
btnWrite.setEnabled(true);
readLoop();
isConnected=true;
}
}else{
boolean res = pcApi.PC_Close();
if (res) {
txtStatus.setText("未连接");
btnWrite.setEnabled(false);
txtCardUid.setText("");
txtCardContent.setText("");
etData.setText("");
}
isConnected=false;
}
}
});


// btnRead.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// boolean res= pcApi.PC_InventoryTag(rFdata,(byte) 0x04);
// if(res){
// try {
// Thread.sleep(500);
// } catch (InterruptedException e) {
// throw new RuntimeException(e);
// }
// byte[] temp=Arrays.copyOfRange(rFdata.RecvData,7,15);
// rFdata.clear();
// res=pcApi.PC_ReadCardOneBlock(rFdata,temp,(byte) 1,(byte)0,(byte)0);
// temp=Arrays.copyOfRange(rFdata.RecvData,8,12);
// String content=new String(temp, StandardCharsets.US_ASCII);
// etData.setText(content);
// }
// }
// });
btnWrite.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
writeBuffer.add(etData.getText().toString());
}
});

btnScan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(PlateActivity.this);
LayoutInflater inflater = LayoutInflater.from(PlateActivity.this);
View v = inflater.inflate(R.layout.pop_scanner_view, null);
EditText content = (EditText) v.findViewById(R.id.et_scan_content);
Button btnScanOK = (Button) v.findViewById(R.id.btn_scan_ok);
Button btn_cancel = (Button) v.findViewById(R.id.btn_scan_cancel);

final Dialog dialog = builder.create();
btnScanOK.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
txtCatdEwm.setText(content.getText().toString());
dialog.dismiss();
}
});
btn_cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});
dialog.show();
dialog.getWindow().setContentView(v);
content.requestFocus();
content.setFocusableInTouchMode(true);
}
});
// mHidSequenceNumberListener = new HIDSequenceNumberListener() {
// @Override
// public void onSequenceNumberReceived(byte[] bytes, int length) {
// if (length > 0) {
// String formatChar = StringFormat.bytes2String(bytes, FormatConstant.FORMAT_UTF8);
// Message message = Message.obtain();
// message.what = READ_OK;
// message.obj = formatChar;
// handler.sendMessage(message);
// }
// }
// };
// HIDManager.getInstance().getSequenceNumber(mHidSequenceNumberListener);
HIDManager.getInstance().openHID(getApplicationContext(), new HIDOpenListener() {
@Override
public void openSuccess(int i) {

}

@Override
public void openError(int i) {

}
}, new HIDDataListener() {
@Override
public void onDataReceived(byte b, String s) {

}

@Override
public void onOriginalDataReceived(byte b, byte[] bytes, int i) {
String formatChar = StringFormat.bytes2String(bytes, FormatConstant.FORMAT_UTF8);
}
});
}

Queue<String> writeBuffer=new PriorityQueue<>();

private void extracted() {
while (writeBuffer.size()>0) {
boolean res = pcApi.PC_InventoryTag(rFdata, (byte) 0x04);
if (res) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
byte[] temp = Arrays.copyOfRange(rFdata.RecvData, 7, 15);
rFdata.clear();
byte[] content = writeBuffer.poll().getBytes(StandardCharsets.US_ASCII);
res = pcApi.PC_WriteCardOneBlock(rFdata, temp, (byte) 1, (byte) 0, content);
if (!res) {

}
}
}
}

private void readLoop(){
new Thread(new Runnable() {
@Override
public void run() {
while (isConnected) {
extracted();
boolean res = pcApi.PC_InventoryTag(rFdata, (byte) 0x04);
if (res) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
byte[] temp = Arrays.copyOfRange(rFdata.RecvData, 7, 15);
String uid = readByte(temp);
if(!"10000000".equals(uid)) {
rFdata.clear();
pcApi.PC_ReadCardOneBlock(rFdata, temp, (byte) 1, (byte) 0, (byte) 0);
temp = Arrays.copyOfRange(rFdata.RecvData, 8, 12);
String content = new String(temp, StandardCharsets.US_ASCII);
runOnUiThread(new Runnable() {
@Override
public void run() {
txtCardUid.setText(uid);
txtCardContent.setText(content);
}
});
}else{
runOnUiThread(new Runnable() {
@Override
public void run() {
txtCardUid.setText("");
txtCardContent.setText("");
}
});
}
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
}).start();
}

private String readByte(byte[] b) {
StringBuilder sb = new StringBuilder();
for(int i=0;i<b.length;i++){
if(i==0){
sb.append(Integer.toHexString(b[i]&0xff));
}else if(i>0){
sb.append(Integer.toHexString(b[i]&0xff));
}
}
String ser = sb.toString();
return ser;
}
}

BIN
View File


BIN
View File


BIN
View File


+ 30
- 0
app/src/main/res/drawable/switch_button_background.xml View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 边框 -->
<item>
<shape android:shape="oval" >

<solid android:color="@color/white" />
<size android:width="168dp" android:height="168dp"/>
</shape>
</item>
<!-- 按下效果 -->
<item android:bottom="8dp" android:right="8dp" android:top="8dp" android:left="8dp" >
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<shape android:shape="oval" >
<solid android:color="#59EC0A" />
<size android:width="168dp" android:height="168dp"/>
</shape>
</item>
<item>
<shape android:shape="oval" >
<solid android:color="#7A8181" />
<size android:width="168dp" android:height="168dp"/>
</shape>
</item>

</selector>
</item>

</layer-list>

+ 189
- 0
app/src/main/res/layout/activity_plate.xml View File

@@ -0,0 +1,189 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:layout_width="match_parent"
android:layout_height="1100dp"
android:orientation="vertical"
android:padding="20dp"
tools:context=".view.PlateActivity">

<ImageView
android:layout_width="210dp"
android:layout_height="50dp"
android:layout_gravity="right"
app:srcCompat="@drawable/logo"></ImageView>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="-30dp"
android:text="黑菠萝餐盘绑定系统"
android:textSize="88sp"></TextView>


<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="50dp"
android:columnCount="2">

<LinearLayout
android:layout_width="850dp"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:textAlignment="center">

<CheckBox
android:id="@+id/cb_open"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:background="@drawable/switch_button_background"
android:button="@null"></CheckBox>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:text="系统状态:"
android:textColor="#50000000"
android:textSize="48sp"></TextView>

<TextView
android:id="@+id/txt_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:text="未就绪"
android:textSize="48sp"></TextView>
</LinearLayout>

<GridLayout
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_marginLeft="35dp"
android:layout_marginTop="50dp"
android:columnCount="2"
android:rowCount="3">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="当前标签UID:"
android:textColor="#50000000"
android:textSize="35sp"></TextView>

<TextView
android:id="@+id/txt_cardUid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:textSize="35sp"></TextView>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="当前标签数据内容:"
android:textColor="#50000000"
android:textSize="35sp"></TextView>

<TextView
android:id="@+id/txt_cardContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="20dp"
android:textSize="35sp"></TextView>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="二维码内容:"
android:textColor="#50000000"
android:textSize="35sp"></TextView>
<TextView
android:id="@+id/txt_cardEwm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:textSize="35sp"></TextView>
</GridLayout>

<Button
android:id="@+id/btn_scan"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_gravity="left"
android:layout_marginLeft="20dp"
android:background="@drawable/scanner"></Button>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="35dp"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="写入新数据:"
android:textSize="35sp"></TextView>

<EditText
android:id="@+id/et_data"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:digits="1234567890"
android:inputType="phone|number"
android:maxLength="4"
android:singleLine="true"
android:textSize="30sp"></EditText>

<Button
android:id="@+id/btn_write"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:text="写入数据"
android:textSize="35sp"></Button>
</LinearLayout>
<TextView
android:layout_marginTop="40dp"
android:layout_marginLeft="35dp"
android:layout_width="700dp"
android:layout_height="wrap_content"
android:textColor="@color/red"
android:textSize="20sp"
android:text="请将餐盘放置于感应区,系统将自动读取当前标签数据内容,在成功读取之后可写入新标签数据"></TextView>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">

</LinearLayout>
<ImageView
android:layout_width="800dp"
android:layout_height="800dp"
app:srcCompat="@drawable/platbg" />
</LinearLayout>
</GridLayout>
</LinearLayout>

+ 41
- 0
app/src/main/res/layout/pop_scanner_view.xml View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#83BEE1B4"
android:orientation="vertical"
android:padding="50dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请将餐盘二维码对准扫码口"
android:textSize="35sp"></TextView>

<EditText
android:id="@+id/et_scan_content"
android:editable="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:textSize="30sp"></EditText>

<Button
android:id="@+id/btn_scan_ok"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:text="确认"
android:textSize="30sp"></Button>

<Button
android:id="@+id/btn_scan_cancel"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:text="取消"
android:textSize="30sp"></Button>
</LinearLayout>

+ 2
- 2
app/src/main/res/values/strings.xml View File

@@ -1,6 +1,6 @@
<resources>
<string name="app_name">菠萝智慧食堂快餐</string>
<string name="title_activity_main">MainActivity</string>
<string name="app_name">菠萝餐盘绑定系统</string>
<string name="title_activity_main">黑菠萝餐盘绑定系统</string>
<string name="dummy_button">Dummy Button</string>
<string name="dummy_content">DUMMY\nCONTENT</string>
</resources>

Loading…
Cancel
Save