增加 webapi

fengshen
wanghao 7 months ago
parent d90dee93cd
commit 5722c0f6fc

@ -47,6 +47,7 @@ dependencies {
implementation files('libs\\ModuleAPI_J.jar')
implementation files('libs\\reader(1).jar')
implementation files('libs\\UHF67_v3.6.jar')
implementation 'androidx.preference:preference:1.2.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
@ -55,5 +56,6 @@ dependencies {
//使 OkSocketServer Java,Server.
implementation 'com.tonystark.android:socket-server:4.1.0'
implementation 'com.lzy.net:okgo:3.0.4'
implementation 'com.google.code.gson:gson:2.10.1'
}

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
xmlns:tools="http://schemas.android.com/tools" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
@ -16,26 +16,42 @@
android:supportsRtl="true"
android:theme="@style/Theme.WriteEpc"
android:usesCleartextTraffic="true"
tools:targetApi="31">
tools:targetApi="31" >
<activity
android:name=".ShuangqianActivity"
android:exported="true">
android:name=".SettingsActivity"
android:exported="false"
android:label="@string/title_activity_settings" />
<activity
android:name=".ShuangqianActivity2"
android:exported="false" />
<activity
android:name=".HomeActivity"
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=".ShuangqianActivity"
android:exported="true" >
</activity>
<receiver
android:name=".broadcast.MyScannerReceiver"
android:enabled="true"
android:exported="true" />
android:exported="true"
android:permission="TODO"
tools:ignore="ExportedReceiver" />
<activity
android:name=".SocketActivity"
android:exported="true"
android:theme="@style/socketActivityStyle"></activity>
android:theme="@style/socketActivityStyle" />
<activity
android:name=".KillActivity"
android:exported="true">
android:exported="true" >
<!-- <intent-filter> -->
<!-- <action android:name="android.intent.action.MAIN" /> -->
@ -44,7 +60,7 @@
</activity>
<activity
android:name=".MoreActivity"
android:exported="true">
android:exported="true" >
<!-- <intent-filter> -->
<!-- <action android:name="android.intent.action.MAIN" /> -->
@ -53,9 +69,10 @@
</activity>
<activity
android:name=".MainActivity"
android:exported="true">
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,56 @@
package com.example.writeepc;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.RadioButton;
import android.widget.Toast;
import com.example.writeepc.base.BaseActivity;
import com.example.writeepc.base.MyApplication;
import com.handheld.uhfr.UHFRManager;
public class HomeActivity extends BaseActivity {
private UHFRManager uhfrManager;
private long exitTime = 0L;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
uhfrManager = UHFRManager.getInstance();
MyApplication.getApplication().setUhfrManager(uhfrManager);
RadioButton button1 = this.findViewById(R.id.home_1);
RadioButton button2 = this.findViewById(R.id.home_2);
button1.setOnClickListener(v -> {
startActivity(new Intent(this, ShuangqianActivity.class));
});
button2.setOnClickListener(v -> {
startActivity(new Intent(this, ShuangqianActivity2.class));
});
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == 4) {
if ((System.currentTimeMillis() - exitTime) > 2000) {
Toast.makeText(getApplicationContext(), "再按一次退出程序", Toast.LENGTH_SHORT).show();
exitTime = System.currentTimeMillis();
return true;
} else {
finish();
}
}
return false;
}
@Override
protected void onDestroy() {
super.onDestroy();
if (uhfrManager != null) {
uhfrManager.close();
uhfrManager = null;
}
}
}

@ -0,0 +1,32 @@
package com.example.writeepc;
import android.os.Bundle;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.PreferenceFragmentCompat;
public class SettingsActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_activity);
if (savedInstanceState == null) {
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.settings, new SettingsFragment())
.commit();
}
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
public static class SettingsFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.root_preferences, rootKey);
}
}
}

@ -2,14 +2,13 @@ package com.example.writeepc;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Toast;
import androidx.databinding.DataBindingUtil;
import com.example.writeepc.base.BaseActivity;
import com.example.writeepc.base.okgo.MyRecultCall;
import com.example.writeepc.base.okgo.MyResult;
import com.example.writeepc.broadcast.MyScannerCall;
import com.example.writeepc.broadcast.MyScannerReceiver;
import com.example.writeepc.databinding.ActivityShuangqianBinding;
@ -18,20 +17,18 @@ import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;
import okhttp3.MediaType;
public class ShuangqianActivity extends BaseActivity implements MyScannerCall {
public MediaType mediaType = MediaType.parse("text/xml; charset=utf-8");
private ActivityShuangqianBinding binding;
private MyScannerReceiver myReceiver;
private long exitTime = 0L;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_shuangqian);
initUHFRManager();
initUHFRManager1();
initDialog();
myReceiver = new MyScannerReceiver(this);
@ -50,9 +47,7 @@ public class ShuangqianActivity extends BaseActivity implements MyScannerCall {
@Override
protected void readTidReault(boolean readState, String result, byte[] rdata) {
super.readTidReault(readState, result, rdata);
binding.socketEpc.setText(result);
}
// 清空数据
@ -65,112 +60,104 @@ public class ShuangqianActivity extends BaseActivity implements MyScannerCall {
public void submit(View view) {
String epc = binding.socketEpc.getText().toString();
String code = binding.socketBarcode.getText().toString();
if (epc.isEmpty() || code.isEmpty()) return;
callWebService(buildSoapRequest(epc, code));
haohuaSubmit(epc, code);
// callWebService(buildSoapRequest(epc, code));//双钱
}
// MES确认
public void mesCormf(View view) {
String epc = binding.socketEpc.getText().toString();
if (epc.isEmpty()) return;
callWebService(buildSelectRequest(epc));
}
private void haohuaSubmit(String epc, String code) {
OkGo.<MyResult>post("http://192.168.26.26:5050/UMInterface/RFID/barcodeAndRFIDBinding")
.params("rfid", epc).params("barCode", code).execute(new MyRecultCall(dialog, this) {
@Override
public void onSuccess(Response<MyResult> response) {
super.onSuccess(response);
MyResult body = response.body();
try {
if (body.getCode() == 200) {
tipsDialog.setTip(true, body.getInfo());
tipsDialog.show();
binding.socketBarcode.setText(null);
binding.socketEpc.setText(null);
} else {
tipsDialog.setTip(false, body.getInfo());
tipsDialog.show();
}
} catch (Exception e) {
tipsDialog.setTip(false, "接口返回信息异常");
tipsDialog.show();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == 4) {
if ((System.currentTimeMillis() - exitTime) > 2000) {
Toast.makeText(getApplicationContext(), "再按一次退出程序", Toast.LENGTH_SHORT).show();
exitTime = System.currentTimeMillis();
return true;
} else {
finish();
}
}
return false;
});
}
private void callWebService(String soapRequest) {
// 发送 POST 请求
OkGo.<String>post("http://10.135.55.206:99/WebService.asmx")
.headers("Content-Type", "text/xml; charset=utf-8")
.upString(soapRequest, mediaType)
.execute(new StringCallback() {
@Override
public void onStart(Request<String, ? extends Request> request) {
super.onStart(request);
dialog.show();
OkGo.<String>post("http://10.135.55.206:99/WebService.asmx").headers("Content-Type", "text/xml; charset=utf-8").upString(soapRequest, mediaType).execute(new StringCallback() {
@Override
public void onStart(Request<String, ? extends Request> request) {
super.onStart(request);
dialog.show();
}
@Override
public void onSuccess(Response<String> response) {
// 处理响应结果
String result = response.body();
try {
String str = "<faultstring>";
int faultstringIndex = result.indexOf(str);
if (faultstringIndex > -1) {
String faultstring = result.substring(faultstringIndex + str.length(), result.indexOf("</faultstring>"));
tipsDialog.setTip(false, faultstring);
tipsDialog.show();
return;
}
@Override
public void onSuccess(Response<String> response) {
// 处理响应结果
String result = response.body();
Log.e("TAG", "onSuccess:" + result);
String str = "<faultstring>";
int faultstringIndex = result.indexOf(str);
if (faultstringIndex > -1) {
String faultstring = result.substring(faultstringIndex + str.length(), result.indexOf("</faultstring>"));
tipsDialog.setTip(false, faultstring);
int codeIndex = result.indexOf("<Code>");
if (codeIndex > -1) {
String resultCode = result.substring(codeIndex + 6, result.indexOf("</Code>"));
String resultMsg = result.substring(result.indexOf("<Msg>") + 5, result.indexOf("</Msg>"));
if (resultCode.equals("200")) {
tipsDialog.setTip(true, resultMsg);
tipsDialog.show();
return;
}
int codeIndex = result.indexOf("<Code>");
if (codeIndex > -1) {
String resultCode = result.substring(codeIndex + 6, result.indexOf("</Code>"));
String resultMsg = result.substring(result.indexOf("<Msg>") + 5, result.indexOf("</Msg>"));
tipsDialog.setTip(resultCode.equals("200"), resultMsg);
binding.socketBarcode.setText(null);
binding.socketEpc.setText(null);
} else {
tipsDialog.setTip(false, resultMsg);
tipsDialog.show();
}
// clearView(null);
}
} catch (Exception e) {
tipsDialog.setTip(false, "接口返回信息异常");
tipsDialog.show();
}
}
@Override
public void onError(Response<String> response) {
}
@Override
public void onFinish() {
super.onFinish();
dialog.dismiss();
}
});
@Override
public void onFinish() {
super.onFinish();
dialog.dismiss();
}
});
}
// 创建提交信息
private String buildSoapRequest(String epcid, String barcode) {
StringBuilder soapRequest = new StringBuilder();
soapRequest.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
soapRequest.append("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">");
soapRequest.append("<soap:Body>");
soapRequest.append("<RFID_BarcodBind xmlns=\"http://tempuri.org/\">");
soapRequest.append("<epcid>").append(epcid).append("</epcid>");
soapRequest.append("<barcode>").append(barcode).append("</barcode>");
soapRequest.append("</RFID_BarcodBind>");
soapRequest.append("</soap:Body>");
soapRequest.append("</soap:Envelope>");
return soapRequest.toString();
}
// 创建验证信息
private String buildSelectRequest(String epcid) {
StringBuilder soapRequest = new StringBuilder();
soapRequest.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
soapRequest.append("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">");
soapRequest.append("<soap:Body>");
soapRequest.append("<TyreTracingBack xmlns=\"http://tempuri.org/\">");
soapRequest.append("<epcid>").append(epcid).append("</epcid>");
soapRequest.append("</TyreTracingBack>");
soapRequest.append("</soap:Body>");
soapRequest.append("</soap:Envelope>");
return soapRequest.toString();
String soapRequest = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
"<soap:Body>" +
"<RFID_BarcodBind xmlns=\"http://tempuri.org/\">" +
"<epcid>" + epcid + "</epcid>" +
"<barcode>" + barcode + "</barcode>" +
"</RFID_BarcodBind>" +
"</soap:Body>" +
"</soap:Envelope>";
return soapRequest;
}

@ -0,0 +1,253 @@
package com.example.writeepc;
import static androidx.constraintlayout.helper.widget.MotionEffect.TAG;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import androidx.databinding.DataBindingUtil;
import com.example.writeepc.adapter.MyMesInfoAdapter;
import com.example.writeepc.base.BaseActivity;
import com.example.writeepc.base.okgo.MyRecultCall;
import com.example.writeepc.base.okgo.MyResult;
import com.example.writeepc.been.MESInfo;
import com.example.writeepc.databinding.ActivityShuangqian2Binding;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
public class ShuangqianActivity2 extends BaseActivity {
private ActivityShuangqian2Binding binding;
private MyMesInfoAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_shuangqian2);
initUHFRManager1();
initDialog();
adapter=new MyMesInfoAdapter(this);
binding.setAdapter(adapter);
}
public void dataReadRFID(View view) {
readEPC(12);
// String msg="<Entity><ID>37f82ad8-6a16-4b9b-880c-78ebf644970a</ID><FAC>02</FAC><BARCODE>2408418883</BARCODE><STATE>1</STATE><CUSQTY>0</CUSQTY><CUDQTY>0</CUDQTY><CUBQTY>0</CUBQTY><CUIQTY>0</CUIQTY><BUITNBR>000000000080435113</BUITNBR><BUITDSC>2045</BUITDSC><BUDAT xsi:type=\"xsd:dateTime\">2025-08-04T00:00:00</BUDAT><BUTIM xsi:type=\"xsd:dateTime\">2025-08-04T10:55:31.517</BUTIM><BUSHT>1</BUSHT><BUBAN /><BUMCH>L403</BUMCH><BUNAM>张磊</BUNAM><BUNAMCOD>HL4969</BUNAMCOD><BUSQTY>1</BUSQTY><BUDQTY>0</BUDQTY><BUBQTY>0</BUBQTY><BUIQTY>0</BUIQTY><BUPLANCOD>YC250804L403204511</BUPLANCOD><BUCOTCOD /><NORMALSTA>P</NORMALSTA><TYRENO>2408418883</TYRENO><BUVERSION /><CRTIM xsi:type=\"xsd:dateTime\">2025-08-04T10:55:31.517</CRTIM><IS_DELETE>0</IS_DELETE><BUHELPER1 /><BUHELPER2 /><BUQCSTATE>1</BUQCSTATE><CUWARNING xsi:nil=\"true\" /><CULTIM>0</CULTIM><CUKTIM>0</CUKTIM><SPEC>S2045-05</SPEC><DOT>0</DOT><BUHELPER3 /><BUASS1 /><BUASS2 /><BUASS3 /><BUASS4 /><BUASS5 /><WMS_FLAG>0</WMS_FLAG><BUCARNO /></Entity>";
// jiexi(msg);
}
@Override
protected void readTidReault(boolean readState, String result, byte[] rdata) {
super.readTidReault(readState, result, rdata);
binding.dataEpc.setText(result);
if (readState) {
// callWebService(buildSelectRequest(result));
haohuaMesSelect(result);
}
}
private void haohuaMesSelect(String result) {
OkGo.<MyResult>post("http://192.168.26.26:5050/UMInterface/RFID/tyreTracingBack")
.params("rfid",result)
.execute(new MyRecultCall(dialog,this) {
@SuppressLint("NotifyDataSetChanged")
@Override
public void onSuccess(Response<MyResult> response) {
super.onSuccess(response);
MyResult body = response.body();
try {
if (body.getCode() == 200) {
List<String> list=gson.fromJson(body.getDataJson(),new TypeToken<List<String>>(){}.getType());
if (list.isEmpty()){
tipsDialog.setTip(false, "未返回信息");
tipsDialog.show();
return;
}
List<MESInfo> mesInfos=new ArrayList<>(list.size());
list.forEach(item->{
String[] split = item.split(":");
MESInfo mesInfo=new MESInfo();
mesInfo.setTitle(split[0]);
mesInfo.setInfo(split[1]);
mesInfos.add(mesInfo);
});
adapter.setList(mesInfos);
} else {
tipsDialog.setTip(false, body.getInfo());
tipsDialog.show();
adapter.setList(null);
}
} catch (Exception e) {
tipsDialog.setTip(false, "接口返回信息异常,解析失败");
tipsDialog.show();
}
adapter.notifyDataSetChanged();
}
});
}
private void callWebService(String soapRequest) {
// 发送 POST 请求
OkGo.<String>post("http://10.135.55.206:99/WebService.asmx")
.headers("Content-Type", "text/xml; charset=utf-8")
.upString(soapRequest, mediaType)
.execute(new StringCallback() {
@Override
public void onStart(Request<String, ? extends Request> request) {
super.onStart(request);
dialog.show();
}
@Override
public void onSuccess(Response<String> response) {
// 处理响应结果
String result = response.body();
try {
String str = "<faultstring>";
int faultstringIndex = result.indexOf(str);
if (faultstringIndex > -1) {
String faultstring = result.substring(faultstringIndex + str.length(), result.indexOf("</faultstring>"));
tipsDialog.setTip(false, faultstring);
tipsDialog.show();
return;
}
int codeIndex = result.indexOf("<Code>");
if (codeIndex > -1) {
String resultCode = result.substring(codeIndex + 6, result.indexOf("</Code>"));
if (resultCode.equals("200")) {
String resultMsg = result.substring(result.indexOf("<Entity>") + 8, result.indexOf("</Entity>"));
jiexi(resultMsg);
return;
}
String resultMsg = result.substring(result.indexOf("<Msg>") + 5, result.indexOf("</Msg>"));
tipsDialog.setTip(false, resultMsg);
tipsDialog.show();
}
} catch (Exception e) {
tipsDialog.setTip(false, "接口返回信息异常");
tipsDialog.show();
}
}
@Override
public void onFinish() {
super.onFinish();
dialog.dismiss();
}
});
}
// 创建验证信息
private String buildSelectRequest(String epcid) {
StringBuilder soapRequest = new StringBuilder();
soapRequest.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
soapRequest.append("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">");
soapRequest.append("<soap:Body>");
soapRequest.append("<TyreTracingBack xmlns=\"http://tempuri.org/\">");
soapRequest.append("<epcid>").append(epcid).append("</epcid>");
soapRequest.append("</TyreTracingBack>");
soapRequest.append("</soap:Body>");
soapRequest.append("</soap:Envelope>");
return soapRequest.toString();
}
private void jiexi(String msg) {
StringBuilder stringBuilder = new StringBuilder();
try {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser parser = factory.newPullParser();
parser.setInput(new StringReader(msg));
String currentTag = null;
int eventType = parser.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
switch (eventType) {
case XmlPullParser.START_TAG:
currentTag = parser.getName();
break;
case XmlPullParser.TEXT:
if (currentTag != null && parser.getText() != null) {
String text = parser.getText().trim();
// 解析字段值
switch (currentTag) {
case "BARCODE":
stringBuilder.append("条 码:").append(text).append("\n");
break;
case "BUITNBR":
stringBuilder.append("ERP编码").append(text).append("\n");
break;
case "BUITDSC":
stringBuilder.append("规格名称:").append(text).append("\n");
break;
case "BUDAT":
stringBuilder.append("成型日期:").append(text).append("\n");
break;
case "BUTIM":
stringBuilder.append("成型时间:").append(text).append("\n");
break;
case "BUSHT":
stringBuilder.append("成型班次:").append(text).append("\n");
break;
case "BUMCH":
stringBuilder.append("成型机台:").append(text).append("\n");
break;
case "BUNAM":
stringBuilder.append("成 型 工:").append(text).append("\n");
break;
case "BUNAMCOD":
stringBuilder.append("成型工账号:").append(text).append("\n");
break;
case "BUPLANCOD":
stringBuilder.append("成型计划号:").append(text).append("\n");
break;
case "TYRENO":
stringBuilder.append("生 胎 码:").append(text).append("\n");
break;
}
}
break;
case XmlPullParser.END_TAG:
currentTag = null;
break;
}
eventType = parser.next();
}
binding.dataInfo.setText(stringBuilder.toString());
} catch (XmlPullParserException | IOException e) {
Log.e("TAG", "解析XML失败: " + e.getMessage());
e.printStackTrace();
}
}
}

@ -0,0 +1,68 @@
package com.example.writeepc.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;
import com.example.writeepc.BR;
import com.example.writeepc.R;
import com.example.writeepc.been.MESInfo;
import com.example.writeepc.databinding.ItemMesInfoBinding;
import java.util.List;
public class MyMesInfoAdapter extends RecyclerView.Adapter<MyMesInfoAdapter.MyMesInfoAdapterViewHolder> {
private Context context;
private LayoutInflater inflater;
private List<MESInfo> list;
public MyMesInfoAdapter(Context context) {
this.context = context;
inflater = LayoutInflater.from(context);
}
public void setList(List<MESInfo> list) {
this.list = list;
}
@NonNull
@Override
public MyMesInfoAdapterViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
ItemMesInfoBinding binding = DataBindingUtil.inflate(inflater, R.layout.item_mes_info, parent, false);
return new MyMesInfoAdapterViewHolder(binding);
}
@Override
public void onBindViewHolder(@NonNull MyMesInfoAdapterViewHolder holder, int position) {
ItemMesInfoBinding binding = holder.getBinding();
MESInfo mesInfo = list.get(position);
binding.setVariable(BR.data,mesInfo);
}
@Override
public int getItemCount() {
return list == null ? 0 : list.size();
}
class MyMesInfoAdapterViewHolder extends RecyclerView.ViewHolder {
private ItemMesInfoBinding binding;
public ItemMesInfoBinding getBinding() {
return binding;
}
public MyMesInfoAdapterViewHolder(ItemMesInfoBinding binding) {
super(binding.getRoot());
this.binding = binding;
}
}
}

@ -11,23 +11,29 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.example.writeepc.dialog.TipsDialog;
import com.google.gson.Gson;
import com.handheld.uhfr.UHFRManager;
import com.uhf.api.cls.Reader;
import cn.pda.serialport.Tools;
import okhttp3.MediaType;
public class BaseActivity extends AppCompatActivity {
public UHFRManager uhfrManager;
public byte[] accesspwd;
public short timeOut = 2000;
public short timeOut = 2500;
public MediaPlayer music;
public ProgressDialog dialog;
public TipsDialog tipsDialog;
public MediaType mediaType = MediaType.parse("text/xml; charset=utf-8");
public Gson gson;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tipsDialog=new TipsDialog(this);
tipsDialog = new TipsDialog(this);
gson = new Gson();
}
@ -50,6 +56,17 @@ public class BaseActivity extends AppCompatActivity {
// Log.e("TAG", "initUHFRManager:" + power[1]);
}
public void initUHFRManager1() {
uhfrManager = MyApplication.getApplication().getUhfrManager();
uhfrManager.setGen2session(false);
uhfrManager.setPower(22, 22);
accesspwd = Tools.HexString2Bytes("00000000");
music = MediaPlayer.create(this, com.example.writeepc.R.raw.msg);
// int[] power = uhfrManager.getPower();
// Log.e("TAG", "initUHFRManager:" + power[0]);
// Log.e("TAG", "initUHFRManager:" + power[1]);
}
// 1- 读取TID
public void readTid() {
@ -85,13 +102,13 @@ public class BaseActivity extends AppCompatActivity {
}
@Override
protected void onDestroy() {
super.onDestroy();
if (uhfrManager != null) {
uhfrManager.close();
uhfrManager = null;
}
}
// @Override
// protected void onDestroy() {
// super.onDestroy();
// if (uhfrManager != null) {
// uhfrManager.close();
// uhfrManager = null;
// }
//
// }
}

@ -3,6 +3,7 @@ package com.example.writeepc.base;
import android.app.Application;
import com.example.writeepc.utils.SharedPreferencesUtils;
import com.handheld.uhfr.UHFRManager;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheEntity;
import com.lzy.okgo.cache.CacheMode;
@ -25,7 +26,21 @@ import okhttp3.OkHttpClient;
*/
public class MyApplication extends Application {
MyApplication application;
private static MyApplication application;
private UHFRManager uhfrManager;
public static MyApplication getApplication() {
return application;
}
public UHFRManager getUhfrManager() {
return uhfrManager;
}
public void setUhfrManager(UHFRManager uhfrManager) {
this.uhfrManager = uhfrManager;
}
@Override
public void onCreate() {

@ -0,0 +1,68 @@
package com.example.writeepc.base.okgo;
import android.app.ProgressDialog;
import android.content.Context;
import android.util.Log;
import android.widget.Toast;
import com.google.gson.Gson;
import com.lzy.okgo.callback.AbsCallback;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;
import okhttp3.ResponseBody;
/**
* @author wanghao
* @date 2023/11/20 14:27
*/
public abstract class MyRecultCall extends AbsCallback<MyResult> {
private ProgressDialog dialog;
private Context context;
public MyRecultCall(ProgressDialog dialog, Context context) {
this.dialog = dialog;
this.context = context;
}
@Override
public void onSuccess(Response<MyResult> response) {
dialog.dismiss();
// Log.e("网络请求情况", "onSuccess:");
}
@Override
public MyResult convertResponse(okhttp3.Response response) throws Throwable {
ResponseBody body = response.body();
if (body == null) return null;
Gson gson = new Gson();
MyResult resust = gson.fromJson(body.string(), MyResult.class);
resust.setDataJson(gson.toJson(resust.getData()));
return resust;
}
@Override
public void onError(Response<MyResult> response) {
super.onError(response);
dialog.dismiss();
Log.e("网络请求情况", "onError:" );
Toast.makeText(context, "接口请求连接失败", Toast.LENGTH_LONG).show();
}
@Override
public void onStart(Request<MyResult, ? extends Request> request) {
super.onStart(request);
dialog.show();
// Log.e("网络请求情况", "onStart:" );
}
@Override
public void onFinish() {
super.onFinish();
dialog.dismiss();
Log.e("网络请求情况", "onFinish:" );
}
}

@ -0,0 +1,72 @@
package com.example.writeepc.base.okgo;
/**
* @author wanghao
* @date 2023/12/21 15:31
*/
public class MyResult {
private int code;
private String msg;
private String info;
private Object data;
private String dataJson;
private Object rows;
private int total;
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
public String getDataJson() {
return dataJson;
}
public void setDataJson(String dataJson) {
this.dataJson = dataJson;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
public Object getRows() {
return rows;
}
public void setRows(Object rows) {
this.rows = rows;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
}

@ -0,0 +1,22 @@
package com.example.writeepc.been;
public class MESInfo {
private String title;
private String info;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
}

@ -5,7 +5,10 @@ import android.content.Context;
import android.content.Intent;
public class MyScannerReceiver extends BroadcastReceiver {
private MyScannerCall myScannerCall;
public MyScannerCall myScannerCall;
public MyScannerReceiver() {
}
public MyScannerReceiver(MyScannerCall myScannerCall) {
this.myScannerCall = myScannerCall;

@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".HomeActivity">
<TextView
style="@style/info_text"
android:layout_width="match_parent"
android:layout_height="55dp"
android:background="#6750A4"
android:letterSpacing="0.2"
android:text="主页"
android:textColor="@color/white"
android:textSize="22sp"
android:textStyle="bold" />
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal">
<RadioButton
android:id="@+id/home_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:button="@null"
android:drawableTop="@mipmap/ic_binding"
android:drawablePadding="10dp"
android:gravity="center"
android:text="MES绑定"
android:textSize="20sp" />
<RadioButton
android:id="@+id/home_2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:button="@null"
android:drawableTop="@mipmap/ic_home"
android:drawablePadding="10dp"
android:gravity="center"
android:text="信息追溯"
android:textSize="20sp" />
</RadioGroup>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:visibility="gone"
android:orientation="horizontal">
<RadioButton
android:id="@+id/home_3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:button="@null"
android:drawableTop="@mipmap/ic_info"
android:drawablePadding="10dp"
android:gravity="center"
android:text="轮胎信息查询"
android:textSize="20sp" />
<RadioButton
android:id="@+id/home_4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:button="@null"
android:drawableTop="@mipmap/home_setting"
android:drawablePadding="10dp"
android:gravity="center"
android:text="设置"
android:textSize="20sp" />
</RadioGroup>
</LinearLayout>

@ -40,7 +40,7 @@
android:layout_gravity="center"
android:text="扫描条码:" />
<EditText
<TextView
android:id="@+id/socket_barcode"
style="@style/san_text"
android:layout_width="match_parent"
@ -62,7 +62,7 @@
android:layout_gravity="center"
android:text="扫描RFID:" />
<EditText
<TextView
android:id="@+id/socket_epc"
style="@style/san_text"
android:layout_width="match_parent"
@ -92,28 +92,7 @@
android:onClick="submit"
android:text="数据提交" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp">
<Button
style="@style/button_style1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="清空" />
<Button
style="@style/button_style1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="mesCormf"
android:text="MES验证" />
</LinearLayout>
</LinearLayout>

@ -0,0 +1,85 @@
<?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="adapter"
type="com.example.writeepc.adapter.MyMesInfoAdapter" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ShuangqianActivity2">
<TextView
style="@style/info_text"
android:layout_width="match_parent"
android:layout_height="55dp"
android:background="#6750A4"
android:letterSpacing="0.2"
android:text="MES追溯"
android:textColor="@color/white"
android:textSize="22sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginTop="20dp"
android:orientation="horizontal">
<TextView
style="@style/info_text"
android:layout_width="110dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:text="扫描RFID:" />
<TextView
android:id="@+id/data_epc"
style="@style/san_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" />
</LinearLayout>
<TextView
android:id="@+id/data_info"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="left|center"
android:padding="20dp"
android:textSize="18sp"
android:visibility="gone" />
<TextView
android:layout_width="110dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="查询信息"
android:textColor="@color/blue" />
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:adapter="@{adapter}"
android:padding="10dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
<Button
style="@style/button_style"
android:layout_width="match_parent"
android:layout_height="65dp"
android:layout_marginBottom="15dp"
android:onClick="dataReadRFID"
android:text="扫描RFID" />
</LinearLayout>
</layout>

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="data"
type="com.example.writeepc.been.MESInfo" />
</data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="52dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp">
<TextView
style="@style/item_text"
android:layout_width="110dp"
android:layout_height="match_parent"
android:text='@{data.title+" :"}' />
<TextView
style="@style/item_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@{data.info}" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_marginTop="1dp"
android:layout_height="1dp"
android:background="#e1e1e1" />
</LinearLayout>
</layout>

@ -0,0 +1,9 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/settings"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

@ -32,4 +32,14 @@
<item>33</item>
</string-array>
<!-- Reply Preference -->
<string-array name="reply_entries">
<item>Reply</item>
<item>Reply to all</item>
</string-array>
<string-array name="reply_values">
<item>reply</item>
<item>reply_all</item>
</string-array>
</resources>

@ -1,3 +1,19 @@
<resources>
<string name="app_name">WriteEpc</string>
<string name="title_activity_settings">SettingsActivity</string>
<!-- Preference Titles -->
<string name="messages_header">Messages</string>
<string name="sync_header">Sync</string>
<!-- Messages Preferences -->
<string name="signature_title">Your signature</string>
<string name="reply_title">Default reply action</string>
<!-- Sync Preferences -->
<string name="sync_title">Sync email periodically</string>
<string name="attachment_title">Download incoming attachments</string>
<string name="attachment_summary_on">Automatically download attachments for incoming emails
</string>
<string name="attachment_summary_off">Only download attachments when manually requested</string>
</resources>

@ -26,6 +26,11 @@
<item name="android:gravity">center</item>
</style>
<style name="item_text">
<item name="android:textSize">15sp</item>
<item name="android:gravity">center</item>
<item name="android:textColor">@color/black</item>
</style>
<style name="san_text">
<item name="android:textColor">@color/black</item>
<item name="android:textSize">18sp</item>

@ -0,0 +1,38 @@
<PreferenceScreen
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory
app:title="@string/messages_header">
<EditTextPreference
app:key="signature"
app:title="@string/signature_title"
app:useSimpleSummaryProvider="true"/>
<ListPreference
app:key="reply"
app:title="@string/reply_title"
app:entries="@array/reply_entries"
app:entryValues="@array/reply_values"
app:defaultValue="reply"
app:useSimpleSummaryProvider="true"/>
</PreferenceCategory>
<PreferenceCategory
app:title="@string/sync_header">
<SwitchPreferenceCompat
app:key="sync"
app:title="@string/sync_title"/>
<SwitchPreferenceCompat
app:key="attachment"
app:title="@string/attachment_title"
app:summaryOn="@string/attachment_summary_on"
app:summaryOff="@string/attachment_summary_off"
app:dependency="sync"/>
</PreferenceCategory>
</PreferenceScreen>
Loading…
Cancel
Save