|
|
|
@ -6,64 +6,118 @@ import android.annotation.SuppressLint;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
import com.example.jinyu_rfid.adapter.ResultAdapter;
|
|
|
|
|
import com.example.jinyu_rfid.base.BaseActivity;
|
|
|
|
|
import com.example.jinyu_rfid.base.MyRecultCall;
|
|
|
|
|
import com.example.jinyu_rfid.base.MyResult;
|
|
|
|
|
import com.example.jinyu_rfid.been.ReadTyreNoResult;
|
|
|
|
|
import com.example.jinyu_rfid.callback.DataReturnCall;
|
|
|
|
|
import com.example.jinyu_rfid.databinding.ActivityReadBinding;
|
|
|
|
|
import com.example.jinyu_rfid.rfid.C5106Device;
|
|
|
|
|
import com.example.jinyu_rfid.rfid.RFIDModel;
|
|
|
|
|
import com.example.jinyu_rfid.uitls.ASCIIUtil;
|
|
|
|
|
import com.google.gson.reflect.TypeToken;
|
|
|
|
|
import com.lzy.okgo.OkGo;
|
|
|
|
|
import com.lzy.okgo.model.Response;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import okhttp3.RequestBody;
|
|
|
|
|
|
|
|
|
|
public class ReadActivity extends BaseActivity implements DataReturnCall {
|
|
|
|
|
private ResultAdapter adapter;
|
|
|
|
|
private RFIDModel rfidModel;
|
|
|
|
|
private String[] stringArray;
|
|
|
|
|
private List<ReadTyreNoResult> list;
|
|
|
|
|
private ActivityReadBinding binding;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
ActivityReadBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_read);
|
|
|
|
|
|
|
|
|
|
binding = DataBindingUtil.setContentView(this, R.layout.activity_read);
|
|
|
|
|
binding.setTitle(getString(R.string.go_read));
|
|
|
|
|
adapter = new ResultAdapter(this);
|
|
|
|
|
list = new ArrayList<>(11);
|
|
|
|
|
adapter.setList(list);
|
|
|
|
|
binding.setAdapter(adapter);
|
|
|
|
|
// 名称
|
|
|
|
|
var workmode = getIntent().getIntExtra("work", 0);
|
|
|
|
|
binding.setType(workmode == 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 名称
|
|
|
|
|
stringArray = getResources().getStringArray(R.array.project_list);
|
|
|
|
|
rfidModel = new C5106Device(this);
|
|
|
|
|
list = new ArrayList<>(11);
|
|
|
|
|
adapter.setList(list);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void readInfo(View view) {
|
|
|
|
|
rfidModel.sanUser(80);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void readEPCInfo(View view) {
|
|
|
|
|
rfidModel.sanEpc(6);
|
|
|
|
|
}
|
|
|
|
|
@SuppressLint("NotifyDataSetChanged")
|
|
|
|
|
@Override
|
|
|
|
|
public void readEpcCodeInfo(String info, boolean state, String stateInfo) {
|
|
|
|
|
if (state) {
|
|
|
|
|
music.start();
|
|
|
|
|
list.clear();
|
|
|
|
|
binding.readText.setText(info);
|
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
|
|
map.put("EpcCode", info);
|
|
|
|
|
map.put("token", "123456");
|
|
|
|
|
OkGo.<MyResult>post(url + "/readEPCCode")
|
|
|
|
|
.upRequestBody(RequestBody.create(JSON, gson.toJson(map))).execute(new MyRecultCall(dialog, this) {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onSuccess(Response<MyResult> response) {
|
|
|
|
|
super.onSuccess(response);
|
|
|
|
|
var body = response.body();
|
|
|
|
|
if (body.getResultFlag().equals("1")) {
|
|
|
|
|
list.addAll(gson.fromJson(body.getJson(),new TypeToken<List<ReadTyreNoResult>>(){}.getType()));
|
|
|
|
|
adapter.notifyDataSetChanged();
|
|
|
|
|
} else {
|
|
|
|
|
Toast.makeText(ReadActivity.this, body.getJson(), Toast.LENGTH_SHORT).show();
|
|
|
|
|
adapter.notifyDataSetChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
binding.readText.setText(null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressLint("NotifyDataSetChanged")
|
|
|
|
|
@Override
|
|
|
|
|
public void readUserInfo(String user, boolean state, String stateInfo) {
|
|
|
|
|
list.clear();
|
|
|
|
|
if (state) {
|
|
|
|
|
binding.readText.setText(user);
|
|
|
|
|
music.start();
|
|
|
|
|
String info = ASCIIUtil.hex2Str(user);
|
|
|
|
|
Log.e("TAG", "readUserInfo:" + info);
|
|
|
|
|
var infos = info.split("~");
|
|
|
|
|
for (int i = 0; i < 12; i++) {
|
|
|
|
|
list.add( new ReadTyreNoResult(i,stringArray[i],infos[i]));
|
|
|
|
|
list.add(new ReadTyreNoResult(i, stringArray[i], infos[i]));
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
binding.readText.setText(null);
|
|
|
|
|
}
|
|
|
|
|
adapter.notifyDataSetChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onDestroy() {
|
|
|
|
|
super.onDestroy();
|
|
|
|
|
rfidModel.close();
|
|
|
|
|
}
|
|
|
|
|
}
|