fengshen
parent
4dde09bf41
commit
d90dee93cd
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@ -0,0 +1,187 @@
|
||||
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.broadcast.MyScannerCall;
|
||||
import com.example.writeepc.broadcast.MyScannerReceiver;
|
||||
import com.example.writeepc.databinding.ActivityShuangqianBinding;
|
||||
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 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();
|
||||
initDialog();
|
||||
|
||||
myReceiver = new MyScannerReceiver(this);
|
||||
IntentFilter intentFilter = new IntentFilter();
|
||||
intentFilter.addAction("com.rfid.SCAN");
|
||||
registerReceiver(myReceiver, intentFilter);
|
||||
|
||||
|
||||
}
|
||||
|
||||
// 读取
|
||||
public void readRFID(View view) {
|
||||
readEPC(12);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readTidReault(boolean readState, String result, byte[] rdata) {
|
||||
super.readTidReault(readState, result, rdata);
|
||||
|
||||
binding.socketEpc.setText(result);
|
||||
|
||||
}
|
||||
|
||||
// 清空数据
|
||||
public void clearView(View view) {
|
||||
binding.socketBarcode.setText(null);
|
||||
binding.socketEpc.setText(null);
|
||||
}
|
||||
|
||||
// 提交数据
|
||||
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));
|
||||
|
||||
}
|
||||
|
||||
// MES确认
|
||||
public void mesCormf(View view) {
|
||||
String epc = binding.socketEpc.getText().toString();
|
||||
if (epc.isEmpty()) return;
|
||||
callWebService(buildSelectRequest(epc));
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
@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);
|
||||
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);
|
||||
tipsDialog.show();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Response<String> response) {
|
||||
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void getScannerData(String data) {
|
||||
binding.socketBarcode.setText(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
unregisterReceiver(myReceiver);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package com.example.writeepc.broadcast;
|
||||
|
||||
public interface MyScannerCall {
|
||||
void getScannerData(String data);
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package com.example.writeepc.broadcast;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
public class MyScannerReceiver extends BroadcastReceiver {
|
||||
private MyScannerCall myScannerCall;
|
||||
|
||||
public MyScannerReceiver(MyScannerCall myScannerCall) {
|
||||
this.myScannerCall = myScannerCall;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
||||
String data = intent.getStringExtra("scannerdata");
|
||||
myScannerCall.getScannerData(data);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,63 @@
|
||||
package com.example.writeepc.dialog;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.example.writeepc.R;
|
||||
|
||||
|
||||
/**
|
||||
* Created by wangh on 2020/10/10-14:57。
|
||||
*/
|
||||
public class TipsDialog extends Dialog implements View.OnClickListener {
|
||||
public String tip;
|
||||
public TextView textView,button;
|
||||
private ImageView imageView;
|
||||
private boolean imageState=true;
|
||||
public TipsDialog(@NonNull Context context) {
|
||||
super(context, R.style.MyMiddleDialogStyle);
|
||||
}
|
||||
|
||||
public void setTip(String tip) {
|
||||
this.tip = tip;
|
||||
}
|
||||
|
||||
public void setTip(boolean imageState , String tip) {
|
||||
this.imageState = imageState;
|
||||
this.tip = tip;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.dialog_tip);
|
||||
// imageState=false;
|
||||
imageView=findViewById(R.id.tip_image);
|
||||
textView=findViewById(R.id.tip_tip);
|
||||
button=findViewById(R.id.dialog_no);
|
||||
button.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
super.show();
|
||||
textView.setText(tip);
|
||||
if (imageState){
|
||||
imageView.setImageResource(R.mipmap.chenggong);
|
||||
}else {
|
||||
imageView.setImageResource(R.mipmap.icon_jinggao);
|
||||
}
|
||||
imageState=false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<corners android:radius="8dp"/>
|
||||
<solid android:color="@color/white"/>
|
||||
</shape>
|
||||
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<data>
|
||||
|
||||
</data>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context=".ShuangqianActivity">
|
||||
|
||||
|
||||
<TextView
|
||||
|
||||
style="@style/info_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="55dp"
|
||||
android:layout_gravity="center"
|
||||
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="扫描条码:" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/socket_barcode"
|
||||
style="@style/san_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<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/socket_epc"
|
||||
style="@style/san_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_weight="1"
|
||||
android:text="" />
|
||||
|
||||
<Button
|
||||
style="@style/button_style"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="65dp"
|
||||
android:onClick="readRFID"
|
||||
android:text="扫描RFID" />
|
||||
|
||||
<Button
|
||||
|
||||
style="@style/button_style"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="65dp"
|
||||
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>
|
||||
</layout>
|
||||
@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_margin="10dp"
|
||||
android:layout_height="210dp"
|
||||
android:background="@drawable/bg_tipdialog"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/tip_image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:src="@mipmap/icon_jinggao" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tip_tip"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="55dp"
|
||||
android:layout_marginTop="13dp"
|
||||
android:gravity="center"
|
||||
android:text="提示"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="18sp" />
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:background="#e1e1e1" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dialog_no"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:text="我知道了"
|
||||
android:textColor="@color/blue"
|
||||
android:textSize="20sp" />
|
||||
|
||||
</LinearLayout>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
Loading…
Reference in New Issue