|
|
@@ -5,19 +5,44 @@ import android.content.Context;
|
|
|
import android.os.Bundle;
|
|
|
import android.view.View;
|
|
|
import android.widget.AdapterView;
|
|
|
+
|
|
|
+import com.google.gson.Gson;
|
|
|
+import com.google.gson.JsonElement;
|
|
|
+import com.google.gson.reflect.TypeToken;
|
|
|
import com.qy.agv.activity.adapter.DirViewAdapter;
|
|
|
+import com.qy.agv.activity.model.RobotModel;
|
|
|
+import com.qy.agv.activity.model.TaskModel;
|
|
|
import com.qy.agv.comm.BaseActivity;
|
|
|
import com.qy.agv.comm.CacheService;
|
|
|
import com.qy.agv.databinding.QyRobotBinding;
|
|
|
+import com.qy.agv.util.Constant;
|
|
|
import com.qy.agv.util.DataUtil;
|
|
|
+import com.qy.agv.util.DateUtil;
|
|
|
+import com.qy.agv.util.MyProgress;
|
|
|
import com.qy.agv.util.StringUtils;
|
|
|
import com.qy.agv.util.ToastUtils;
|
|
|
+
|
|
|
+import org.apache.log4j.Logger;
|
|
|
+import org.json.JSONException;
|
|
|
+import org.json.JSONObject;
|
|
|
+import org.xutils.common.Callback;
|
|
|
+import org.xutils.http.RequestParams;
|
|
|
import org.xutils.x;
|
|
|
|
|
|
+import java.lang.reflect.Type;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
public class ControlActivity extends BaseActivity {
|
|
|
+ public static Logger mylog =Logger.getLogger(ControlActivity.class);
|
|
|
+
|
|
|
private Context context;
|
|
|
private DirViewAdapter dirViewAdapter;
|
|
|
private QyRobotBinding binding;
|
|
|
+ private RobotModel robotModel;
|
|
|
+ private final Map<Integer, String> statusMap = new HashMap<Integer, String>();
|
|
|
|
|
|
@Override
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
@@ -29,10 +54,18 @@ public class ControlActivity extends BaseActivity {
|
|
|
initCommonTop2();
|
|
|
init();
|
|
|
bindRobot();
|
|
|
+ initStatus();
|
|
|
}
|
|
|
|
|
|
@SuppressLint("ClickableViewAccessibility")
|
|
|
public void init(){
|
|
|
+ binding.btnResetLm.setOnClickListener(view->{
|
|
|
+
|
|
|
+ });
|
|
|
+ binding.btnConfirmLm.setOnClickListener(view->{
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
dirViewAdapter = new DirViewAdapter(DataUtil.getDir(""),this);
|
|
|
binding.gridView.setAdapter(dirViewAdapter);
|
|
|
binding.gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
@@ -64,7 +97,7 @@ public class ControlActivity extends BaseActivity {
|
|
|
|
|
|
@Override
|
|
|
public void receiverTask(String barcode) {
|
|
|
- searchRobot(barcode);
|
|
|
+ parserRobot(barcode);
|
|
|
}
|
|
|
|
|
|
public void bindRobot() {
|
|
|
@@ -74,16 +107,72 @@ public class ControlActivity extends BaseActivity {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void searchRobot(String bindRobotID){
|
|
|
+ public void parserRobot(String bindRobotID){
|
|
|
if(StringUtils.isEmpty(bindRobotID)){
|
|
|
- ToastUtils.showToast(context, "没有绑定机器人");
|
|
|
+ ToastUtils.showToast(context, "机器人编号不能为空");
|
|
|
return;
|
|
|
}
|
|
|
if(bindRobotID.startsWith("02-")){
|
|
|
bindRobotID = bindRobotID.replace("02-", "");
|
|
|
+ searchRobot(bindRobotID);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void searchRobot(String bindRobotID) {
|
|
|
+ MyProgress myProgress = MyProgress.getInstance();
|
|
|
+ myProgress.show(context, "提示", "正在加载");
|
|
|
+ RequestParams params = httParams(Constant.ROBOT_DETAIL);
|
|
|
+ params.addBodyParameter("robotId", bindRobotID);
|
|
|
+ x.http().get(params, new Callback.CommonCallback<JSONObject>() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(JSONObject rs) {
|
|
|
+ mylog.info(rs.toString());
|
|
|
+ try {
|
|
|
+ if (rs.getInt("code") != 200) {
|
|
|
+ ToastUtils.showToast(context, "请求失败");
|
|
|
+ } else {
|
|
|
+ if (rs.getBoolean("success")) {
|
|
|
+ Object data_o = rs.get("data");
|
|
|
+ robotModel = new Gson().fromJson(data_o.toString(), RobotModel.class);
|
|
|
+ binding.robotNo.setText(robotModel.getRobotId());
|
|
|
+ Integer robot_status = robotModel.getRobotStatus();
|
|
|
+ binding.robotState.setText(statusMap.get(robot_status));
|
|
|
+ CacheService.getInstance(context).saveCache("BIND_CONTROL", "ROBOT_ID", robotModel.getRobotId());
|
|
|
+ ToastUtils.showToast(context, "绑定成功");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(Throwable ex, boolean isOnCallback) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ mylog.error("请求异常:", ex);
|
|
|
+ ToastUtils.showToast(context, "请求异常:" + ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFinished() {myProgress.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onCancelled(CancelledException arg0) {
|
|
|
+ mylog.error("onRead:", arg0);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initStatus(){
|
|
|
+ statusMap.put(0, "空闲");
|
|
|
+ statusMap.put(1, "已分配");
|
|
|
+ statusMap.put(2, "执行中");
|
|
|
+ statusMap.put(3, "锁定中");
|
|
|
+ statusMap.put(4, "充电中");
|
|
|
+ statusMap.put(5, "等待中");
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
protected String getCommonTopTitle() {
|
|
|
return "单机控制";
|