add 昊华外网查询
parent
511212d59f
commit
e0b6e04e55
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="com.codeverse.userSettings.MarscodeWorkspaceAppSettingsState">
|
||||||
|
<option name="ckgOperationStatus" value="SUCCESS" />
|
||||||
|
<option name="progress" value="0.90625" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@ -0,0 +1,230 @@
|
|||||||
|
package com.example.writeepc;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.text.Editable;
|
||||||
|
import android.text.TextWatcher;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
|
||||||
|
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.ActivityIntentSelectBinding;
|
||||||
|
import com.example.writeepc.utils.SharedPreferencesUtils;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import com.lzy.okgo.OkGo;
|
||||||
|
import com.lzy.okgo.model.Response;
|
||||||
|
import com.uhf.api.cls.Reader;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import okhttp3.MediaType;
|
||||||
|
import okhttp3.RequestBody;
|
||||||
|
|
||||||
|
public class IntentSelectActivity extends BaseActivity {
|
||||||
|
private final Handler handler = new Handler();
|
||||||
|
public MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
||||||
|
private ActivityIntentSelectBinding binding;
|
||||||
|
private MyMesInfoAdapter adapter;
|
||||||
|
private Button traceSanButton;
|
||||||
|
private boolean sanState = true;
|
||||||
|
private Runnable runnable;
|
||||||
|
private Runnable tokenRunnable;
|
||||||
|
private MyKeyReceiver keyReceiver;
|
||||||
|
private String ip;
|
||||||
|
private String token;
|
||||||
|
|
||||||
|
@SuppressLint("UnspecifiedRegisterReceiverFlag")
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
binding = DataBindingUtil.setContentView(this, R.layout.activity_intent_select);
|
||||||
|
initUHFRManager1();
|
||||||
|
// 设置功率
|
||||||
|
String powerTrace1 = SharedPreferencesUtils.getstring("powerTrace", "22");
|
||||||
|
int powerTrace = Integer.parseInt(powerTrace1);
|
||||||
|
Reader.READER_ERR readerErr = uhfrManager.setPower(powerTrace, powerTrace);
|
||||||
|
Log.e("TAG", "追溯设置功率" + powerTrace1 + ":" + readerErr.name());
|
||||||
|
initDialog();
|
||||||
|
adapter = new MyMesInfoAdapter(this);
|
||||||
|
binding.setAdapter(adapter);
|
||||||
|
traceSanButton = binding.traceSanButton;
|
||||||
|
runnable = () -> {
|
||||||
|
if (sanState) {
|
||||||
|
handler.removeCallbacks(runnable);
|
||||||
|
} else {
|
||||||
|
readEPC(12);
|
||||||
|
handler.postDelayed(runnable, 1000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
tokenRunnable = () -> {
|
||||||
|
requestToken();
|
||||||
|
};
|
||||||
|
handler.postDelayed(tokenRunnable, 0);
|
||||||
|
keyReceiver = new MyKeyReceiver();
|
||||||
|
IntentFilter intentFilter = new IntentFilter();
|
||||||
|
intentFilter.addAction("android.rfid.FUN_KEY");
|
||||||
|
registerReceiver(keyReceiver, intentFilter);
|
||||||
|
String ACTION_CLOSE_SCAN = "com.rfid.CLOSE_SCAN";
|
||||||
|
Intent toKillService = new Intent();
|
||||||
|
toKillService.setAction(ACTION_CLOSE_SCAN);
|
||||||
|
sendBroadcast(toKillService);
|
||||||
|
binding.dataEpc.addTextChangedListener(new TextWatcher() {
|
||||||
|
@Override
|
||||||
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterTextChanged(Editable s) {
|
||||||
|
if (s.length() == 24) {
|
||||||
|
haohuaMesSelect(s.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ip = SharedPreferencesUtils.getstring("ip", "https://rfidpub.haohuatire.com:7443");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void requestToken() {
|
||||||
|
Map<String, String> map = new HashMap<>();
|
||||||
|
map.put("AppId", "app-20250704032545-nmmhn8jw");
|
||||||
|
map.put("AppSecret", "dXJZQKubbqhSPCugtA49rsDGACmN5CMD4ItTfP11+DA=");
|
||||||
|
OkGo.<MyResult>post(ip + "/UMInterface/Auth/AccessToken").upRequestBody(RequestBody.create(JSON, gson.toJson(map))).execute(new MyRecultCall(dialog, this) {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(Response<MyResult> response) {
|
||||||
|
super.onSuccess(response);
|
||||||
|
MyResult body = response.body();
|
||||||
|
if (body.getCode() == 200) {
|
||||||
|
String dataJson = body.getDataJson();
|
||||||
|
JsonObject jsonObject = JsonParser.parseString(dataJson).getAsJsonObject();
|
||||||
|
token = jsonObject.get("Token").getAsString();
|
||||||
|
Log.e("TAG", "onSuccess:token=" + token);
|
||||||
|
binding.traceSanButton1.setVisibility(View.GONE);
|
||||||
|
handler.postDelayed(tokenRunnable, 60 * 1000 * 90);
|
||||||
|
} else {
|
||||||
|
tipsDialog.setTip(false, body.getInfo());
|
||||||
|
tipsDialog.show();
|
||||||
|
binding.traceSanButton1.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void intentRequestToken(View view) {
|
||||||
|
requestToken();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dataReadRFID(View view) {
|
||||||
|
if (sanState) {
|
||||||
|
handler.postDelayed(runnable, 0);
|
||||||
|
sanState = false;
|
||||||
|
traceSanButton.setBackgroundResource(R.drawable.button_bg2);
|
||||||
|
traceSanButton.setText("停止扫描");
|
||||||
|
} else {
|
||||||
|
sanState = true;
|
||||||
|
handler.removeCallbacks(runnable);
|
||||||
|
traceSanButton.setBackgroundResource(R.drawable.button_bg1);
|
||||||
|
traceSanButton.setText("开始扫描");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void readTidReault(boolean readState, String result, byte[] rdata) {
|
||||||
|
super.readTidReault(readState, result, rdata);
|
||||||
|
binding.dataEpc.setText(result);
|
||||||
|
|
||||||
|
if (readState) {
|
||||||
|
dataReadRFID(null);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void haohuaMesSelect(String result) {
|
||||||
|
OkGo.<MyResult>post(ip + "/UMInterface/RFID/sellTyreTracingBack")
|
||||||
|
.headers("Token", token)
|
||||||
|
.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) {
|
||||||
|
String dataJson = body.getDataJson();
|
||||||
|
if (dataJson == null || dataJson.equals("[]")) {
|
||||||
|
tipsDialog.setTip(false, "未查询到相关信息");
|
||||||
|
tipsDialog.show();
|
||||||
|
adapter.setList(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dataJson = dataJson.replace("[{", "").replace("\"", "").trim();
|
||||||
|
String[] split = dataJson.split(",");
|
||||||
|
List<MESInfo> mesInfos = new ArrayList<>();
|
||||||
|
for (String item : split) {
|
||||||
|
String[] split1 = item.split(":");
|
||||||
|
MESInfo mesInfo = new MESInfo();
|
||||||
|
mesInfo.setTitle(split1[0]);
|
||||||
|
mesInfo.setInfo(split1[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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
unregisterReceiver(keyReceiver);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class MyKeyReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
var keydown = intent.getBooleanExtra("keydown", false);
|
||||||
|
if (!keydown) {
|
||||||
|
dataReadRFID(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,102 @@
|
|||||||
|
<?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=".IntentSelectActivity">
|
||||||
|
|
||||||
|
<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" />
|
||||||
|
|
||||||
|
<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:" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
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" />
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="15dp">
|
||||||
|
<Button
|
||||||
|
android:id="@+id/trace_san_button1"
|
||||||
|
style="@style/button_style"
|
||||||
|
android:layout_width="150dp"
|
||||||
|
android:layout_height="55dp"
|
||||||
|
android:onClick="intentRequestToken"
|
||||||
|
android:background="@drawable/button_bg2"
|
||||||
|
android:text="重新连接" />
|
||||||
|
<Button
|
||||||
|
android:id="@+id/trace_san_button"
|
||||||
|
style="@style/button_style"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:layout_height="55dp"
|
||||||
|
android:onClick="dataReadRFID"
|
||||||
|
android:background="@drawable/button_bg1"
|
||||||
|
android:text="开始扫描" />
|
||||||
|
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</layout>
|
||||||
Loading…
Reference in New Issue