|
|
@@ -8,18 +8,33 @@ import android.content.ComponentName;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.content.ServiceConnection;
|
|
|
+import android.graphics.drawable.ColorDrawable;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.IBinder;
|
|
|
+import android.util.DisplayMetrics;
|
|
|
+import android.view.Gravity;
|
|
|
import android.view.KeyEvent;
|
|
|
+import android.view.LayoutInflater;
|
|
|
import android.view.MotionEvent;
|
|
|
import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
+import android.view.WindowManager;
|
|
|
import android.widget.AdapterView;
|
|
|
+import android.widget.Button;
|
|
|
+import android.widget.ListView;
|
|
|
+import android.widget.PopupWindow;
|
|
|
+import android.widget.SimpleAdapter;
|
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
import com.google.gson.JsonElement;
|
|
|
import com.google.gson.reflect.TypeToken;
|
|
|
+import com.qy.agv.R;
|
|
|
import com.qy.agv.activity.adapter.DirViewAdapter;
|
|
|
+import com.qy.agv.activity.dao.MainDao;
|
|
|
+import com.qy.agv.activity.model.RelocModel;
|
|
|
import com.qy.agv.activity.model.RobotModel;
|
|
|
+import com.qy.agv.activity.model.ShelfModel;
|
|
|
+import com.qy.agv.activity.model.SiteModel;
|
|
|
import com.qy.agv.activity.model.TaskModel;
|
|
|
import com.qy.agv.comm.BaseActivity;
|
|
|
import com.qy.agv.comm.CacheService;
|
|
|
@@ -59,6 +74,7 @@ public class ControlActivity extends BaseActivity {
|
|
|
private Intent socketIntent;
|
|
|
private int robot_status = 0;
|
|
|
private String speed = "0";
|
|
|
+ private PopupWindow popupWindow;
|
|
|
|
|
|
@Override
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
@@ -85,7 +101,7 @@ public class ControlActivity extends BaseActivity {
|
|
|
ToastUtils.showToast(context, "没有绑定机器人");
|
|
|
return;
|
|
|
}
|
|
|
- push("CDW,"+robotModel.getRobotId(), "重新定位");
|
|
|
+ selPosition();
|
|
|
});
|
|
|
binding.btnConfirmLm.setOnClickListener(view->{
|
|
|
if(robotModel==null){
|
|
|
@@ -384,7 +400,7 @@ public class ControlActivity extends BaseActivity {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- private void sendCommand(String cmd){
|
|
|
+ private void sendCommand(String cmd, String...args){
|
|
|
switch (cmd){
|
|
|
case "rise":
|
|
|
socketService.sendOrder("HriseT");
|
|
|
@@ -401,23 +417,74 @@ public class ControlActivity extends BaseActivity {
|
|
|
socketService.sendOrder("Hback,"+speed+"T");
|
|
|
break;
|
|
|
case "left":
|
|
|
- binding.robotState.setText(getTurnSpeed() + "米/秒");
|
|
|
- socketService.sendOrder("Hleft,"+getTurnSpeed()+"T");
|
|
|
+ binding.robotState.setText(speed + "米/秒");
|
|
|
+ socketService.sendOrder("Hleft,"+speed+"T");
|
|
|
break;
|
|
|
case "right":
|
|
|
- binding.robotState.setText(getTurnSpeed() + "米/秒");
|
|
|
- socketService.sendOrder("Hright,"+getTurnSpeed()+"T");
|
|
|
+ binding.robotState.setText(speed + "米/秒");
|
|
|
+ socketService.sendOrder("Hright,"+speed+"T");
|
|
|
break;
|
|
|
case "stop":
|
|
|
socketService.sendOrder("HstopT");
|
|
|
break;
|
|
|
+ case "cdw":
|
|
|
+ socketService.sendOrder("Hcdw,"+args[0]+"T");
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public String getTurnSpeed(){
|
|
|
- BigDecimal turn_speed = new BigDecimal(speed);
|
|
|
- turn_speed = turn_speed.divide(new BigDecimal(2), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
- return turn_speed.toString();
|
|
|
+ private void selPosition(){
|
|
|
+ View view = binding.getRoot().getRootView();
|
|
|
+ List<Map<String,String>> params = new ArrayList<>();
|
|
|
+ List<RelocModel> relocModels = MainDao.getInstance().searchReloc(context);
|
|
|
+ for (RelocModel relocModel : relocModels) {
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("name", relocModel.getRelocName());
|
|
|
+ map.put("value", relocModel.getId());
|
|
|
+ params.add(map);
|
|
|
+ }
|
|
|
+ if(params.size() == 0){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ListView mListView = new ListView(this);
|
|
|
+ mListView.setBackgroundResource(R.color.white);
|
|
|
+ SimpleAdapter simplead = new SimpleAdapter(this, params,
|
|
|
+ R.layout.popupwindow_list_item, new String[] { "name"},
|
|
|
+ new int[] {R.id.tv_msg});
|
|
|
+ mListView.setAdapter(simplead);
|
|
|
+ mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemClick(AdapterView<?> parent, View view,
|
|
|
+ int position, long id) {
|
|
|
+ try {
|
|
|
+ String value = params.get(position).get("value");
|
|
|
+ sendCommand("cdw",value);
|
|
|
+ ToastUtils.showToast(context, "重定位发送成功");
|
|
|
+ popupWindow.dismiss();
|
|
|
+ }catch (Exception ex){
|
|
|
+ mylog.error("选择位置异常", ex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ WindowManager manager = this.getWindowManager();
|
|
|
+ DisplayMetrics outMetrics = new DisplayMetrics();
|
|
|
+ manager.getDefaultDisplay().getMetrics(outMetrics);
|
|
|
+ double width = outMetrics.widthPixels*0.8;
|
|
|
+ popupWindow = new PopupWindow(view, (int) width,
|
|
|
+ ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
|
+ //设置窗体的内容
|
|
|
+ popupWindow.setContentView(mListView);
|
|
|
+ popupWindow.setOutsideTouchable(false);
|
|
|
+ popupWindow.setFocusable(false);
|
|
|
+ popupWindow.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
|
|
|
+ setBackgroundAlpha(0.5f);
|
|
|
+ popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setBackgroundAlpha(float bgAlpha) {
|
|
|
+ WindowManager.LayoutParams lp = getWindow().getAttributes();
|
|
|
+ lp.alpha = bgAlpha;
|
|
|
+ getWindow().setAttributes(lp);
|
|
|
}
|
|
|
|
|
|
@Override
|