| | |
| | | |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.content.res.ColorStateList; |
| | | import android.graphics.Color; |
| | | import android.os.Bundle; |
| | | import android.os.Handler; |
| | | import android.os.Message; |
| | |
| | | import android.view.MotionEvent; |
| | | import android.view.View; |
| | | import android.widget.Button; |
| | | import android.widget.RelativeLayout; |
| | | |
| | | import com.example.agvcontroller.action.BackPaddle; |
| | | import com.example.agvcontroller.action.ForwardBackAction; |
| | | import com.example.agvcontroller.action.FrontPaddle; |
| | | import com.example.agvcontroller.action.HandExtendCollect; |
| | | import com.example.agvcontroller.action.HandForkRotatopn; |
| | | import com.example.agvcontroller.action.HandInAction; |
| | | import com.example.agvcontroller.action.HandLift; |
| | | import com.example.agvcontroller.action.RotatopnLeftRight; |
| | | import com.example.agvcontroller.protocol.AgvAction; |
| | | import com.example.agvcontroller.action.ForceSwitchAction; |
| | | import com.example.agvcontroller.action.HandOutAction; |
| | | import com.example.agvcontroller.socket.NettyServerHandler; |
| | | import com.example.agvcontroller.socket.SocketManager; |
| | | import com.example.agvcontroller.utils.DialogUtil; |
| | | import com.example.agvcontroller.utils.SnowflakeIdWorker; |
| | | |
| | | import java.net.Socket; |
| | | import java.sql.Time; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.concurrent.TimeoutException; |
| | | |
| | | |
| | | public class MainActivity extends AppCompatActivity { |
| | | |
| | | public static final Map<String, Object> map = new ConcurrentHashMap(); |
| | | public static final Map<String, Object> car_num = new ConcurrentHashMap(); |
| | | |
| | | private RecyclerView recyclerView; |
| | | private ItemAdapter itemAdapter; |
| | | private List<Item> itemList; |
| | | private Vibrator vibrator; |
| | | private Button stopBtn; // 急停按钮 |
| | | private Button forceSwitchBtn; // 手自动强制开关 |
| | | private Button rotatopnRightBtn; // 右旋转 |
| | | // private Button forceSwitchBtn; // 手自动强制开关 |
| | | private Button rotatopnLeftBtn; // 左旋转 |
| | | private Button rotatopnRightBtn; // 右旋转 |
| | | private Button goForwardBtn; // 前进 |
| | | private Button goBackwardBtn; // 后退 |
| | | private Button modelSwitchBtn; // 进入、退出 手动 |
| | | |
| | | private Button frontPaddleExtendBtn; |
| | | private Button frontPaddleCollectBtn; |
| | | private Button backPaddleExtendBtn; |
| | | private Button backPaddleCollectBtn; |
| | | private Button riseBtn; |
| | | private Button dropBtn; |
| | | private Button extendForkBtn; |
| | | private Button collectForkBtn; |
| | | private Button turnLeftBtn; |
| | | private Button turnRightBtn; |
| | | |
| | | |
| | | private Button bodySwitchBtn; // 底盘/货叉切换 |
| | | private Socket socket; |
| | | private String AgvNo = "12"; |
| | | private RelativeLayout layout_bottom; |
| | | private RelativeLayout layout_top; |
| | | private RelativeLayout layout_single; |
| | | private RelativeLayout layout_reset; |
| | | |
| | | |
| | | SocketManager socketManager; |
| | | |
| | | private boolean isDowm = false; |
| | | private boolean isOpen = false; |
| | | |
| | | // 按钮长按事件 |
| | | private int autoVal = 1; |
| | | private boolean isAuto = true; |
| | | private boolean isGoForward = false; |
| | | private boolean isGoBackward = false; |
| | | private boolean isRotatopnRight = false; |
| | | private boolean isRotatopnLeft = false; |
| | | |
| | | private boolean isFrontPaddleExtendBtn = false; |
| | | private boolean isFrontPaddleCollectBtn = false; |
| | | private boolean isBackPaddleExtendBtn = false; |
| | | private boolean isBackPaddleCollectBtn = false; |
| | | private boolean isRiseBtn = false; |
| | | private boolean isDropBtn = false; |
| | | private boolean isExtendForkBtn = false; |
| | | private boolean isCollectForkBtn = false; |
| | | private boolean isTurnLeftBtn = false; |
| | | private boolean isTurnRightBtn = false; |
| | | |
| | | |
| | | |
| | | |
| | |
| | | private Handler handler = new Handler(new Handler.Callback() { |
| | | @Override |
| | | public boolean handleMessage(Message msg) { |
| | | if (isDowm) { |
| | | if (isGoForward) { |
| | | String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); |
| | | AgvAction agvAction = new AgvAction<>(ForceSwitchAction.class) |
| | | .setAgvNo("1") |
| | | AgvAction agvAction = new AgvAction<>(ForwardBackAction.class) |
| | | .setAgvNo(AgvNo) |
| | | .setSerialNo(substring) |
| | | .setVal(1) |
| | | .bodySync((action) -> action.setPwd((short) 21)); |
| | | |
| | | .bodySync((action) -> action.setPwd((short) 10)); |
| | | nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端 |
| | | handler.sendEmptyMessageDelayed(0, 100); |
| | | |
| | | boolean result = false; |
| | | long timestamp = System.currentTimeMillis(); |
| | | |
| | | while (System.currentTimeMillis() - timestamp < 5000) { |
| | | |
| | | Object o = map.get(substring); |
| | | |
| | | if (null != o) { |
| | | result = true; |
| | | map.remove(o); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (result) { |
| | | // alert ok |
| | | } else { |
| | | throw new TimeoutException("超时"); |
| | | } |
| | | |
| | | } |
| | | if (isOpen) { |
| | | if (isGoBackward) { |
| | | String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); |
| | | AgvAction agvAction = new AgvAction<>(ForceSwitchAction.class) |
| | | .setAgvNo("12") |
| | | AgvAction agvAction = new AgvAction<>(ForwardBackAction.class) |
| | | .setAgvNo(AgvNo) |
| | | .setSerialNo(substring) |
| | | .setVal(1) |
| | | .bodySync((action) -> action.setPwd((short) 21)); |
| | | .bodySync((action) -> action.setPwd((short) -10)); |
| | | nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端 |
| | | handler.sendEmptyMessageDelayed(0, 100); |
| | | } |
| | | if (isRotatopnRight) { |
| | | String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); |
| | | AgvAction agvAction = new AgvAction<>(RotatopnLeftRight.class) |
| | | .setAgvNo(AgvNo) |
| | | .setSerialNo(substring) |
| | | .setVal(1) |
| | | .bodySync((action) -> action.setPwd((short) 10)); |
| | | nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端 |
| | | handler.sendEmptyMessageDelayed(0, 100); |
| | | } |
| | | if (isRotatopnLeft) { |
| | | String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); |
| | | AgvAction agvAction = new AgvAction<>(RotatopnLeftRight.class) |
| | | .setAgvNo(AgvNo) |
| | | .setSerialNo(substring) |
| | | .setVal(1) |
| | | .bodySync((action) -> action.setPwd((short) -10)); |
| | | nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端 |
| | | handler.sendEmptyMessageDelayed(0, 100); |
| | | } |
| | | |
| | | // 前拨杆伸 |
| | | if (isFrontPaddleExtendBtn) { |
| | | String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); |
| | | AgvAction agvAction = new AgvAction<>(FrontPaddle.class) |
| | | .setAgvNo(AgvNo) |
| | | .setSerialNo(substring) |
| | | .setVal(1) |
| | | .bodySync((action) -> action.setPwd((short) -10)); |
| | | nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端 |
| | | handler.sendEmptyMessageDelayed(0, 100); |
| | | } |
| | | // 前拨杆收 |
| | | if (isFrontPaddleCollectBtn) { |
| | | String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); |
| | | AgvAction agvAction = new AgvAction<>(FrontPaddle.class) |
| | | .setAgvNo(AgvNo) |
| | | .setSerialNo(substring) |
| | | .setVal(1) |
| | | .bodySync((action) -> action.setPwd((short) -10)); |
| | | nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端 |
| | | handler.sendEmptyMessageDelayed(0, 100); |
| | | } |
| | | // 后拨杆伸 |
| | | if (isBackPaddleExtendBtn) { |
| | | String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); |
| | | AgvAction agvAction = new AgvAction<>(BackPaddle.class) |
| | | .setAgvNo(AgvNo) |
| | | .setSerialNo(substring) |
| | | .setVal(1) |
| | | .bodySync((action) -> action.setPwd((short) -10)); |
| | | nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端 |
| | | handler.sendEmptyMessageDelayed(0, 100); |
| | | } |
| | | // 后拨杆收 |
| | | if (isBackPaddleCollectBtn) { |
| | | String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); |
| | | AgvAction agvAction = new AgvAction<>(BackPaddle.class) |
| | | .setAgvNo(AgvNo) |
| | | .setSerialNo(substring) |
| | | .setVal(1) |
| | | .bodySync((action) -> action.setPwd((short) -10)); |
| | | nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端 |
| | | handler.sendEmptyMessageDelayed(0, 100); |
| | | } |
| | | // 上升 |
| | | if (isRiseBtn) { |
| | | String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); |
| | | AgvAction agvAction = new AgvAction<>(HandLift.class) |
| | | .setAgvNo(AgvNo) |
| | | .setSerialNo(substring) |
| | | .setVal(1) |
| | | .bodySync((action) -> action.setPwd((short) -10)); |
| | | nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端 |
| | | handler.sendEmptyMessageDelayed(0, 100); |
| | | } |
| | | // 下降 |
| | | if (isDropBtn) { |
| | | String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); |
| | | AgvAction agvAction = new AgvAction<>(HandLift.class) |
| | | .setAgvNo(AgvNo) |
| | | .setSerialNo(substring) |
| | | .setVal(1) |
| | | .bodySync((action) -> action.setPwd((short) -10)); |
| | | nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端 |
| | | handler.sendEmptyMessageDelayed(0, 100); |
| | | } |
| | | // 伸叉 |
| | | if (isExtendForkBtn) { |
| | | String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); |
| | | AgvAction agvAction = new AgvAction<>(HandExtendCollect.class) |
| | | .setAgvNo(AgvNo) |
| | | .setSerialNo(substring) |
| | | .setVal(1) |
| | | .bodySync((action) -> action.setPwd((short) -10)); |
| | | nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端 |
| | | handler.sendEmptyMessageDelayed(0, 100); |
| | | } |
| | | // 收叉 |
| | | if (isCollectForkBtn) { |
| | | String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); |
| | | AgvAction agvAction = new AgvAction<>(HandExtendCollect.class) |
| | | .setAgvNo(AgvNo) |
| | | .setSerialNo(substring) |
| | | .setVal(1) |
| | | .bodySync((action) -> action.setPwd((short) -10)); |
| | | nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端 |
| | | handler.sendEmptyMessageDelayed(0, 100); |
| | | } |
| | | // 货叉左旋 |
| | | if (isTurnLeftBtn) { |
| | | String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); |
| | | AgvAction agvAction = new AgvAction<>(HandForkRotatopn.class) |
| | | .setAgvNo(AgvNo) |
| | | .setSerialNo(substring) |
| | | .setVal(1) |
| | | .bodySync((action) -> action.setPwd((short) -10)); |
| | | nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端 |
| | | handler.sendEmptyMessageDelayed(0, 100); |
| | | } |
| | | // 货叉右旋 |
| | | if (isTurnRightBtn) { |
| | | String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); |
| | | AgvAction agvAction = new AgvAction<>(HandForkRotatopn.class) |
| | | .setAgvNo(AgvNo) |
| | | .setSerialNo(substring) |
| | | .setVal(1) |
| | | .bodySync((action) -> action.setPwd((short) -10)); |
| | | nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端 |
| | | handler.sendEmptyMessageDelayed(0, 100); |
| | | } |
| | |
| | | // 按钮震动 |
| | | vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); |
| | | stopBtn = findViewById(R.id.btn_stop); |
| | | forceSwitchBtn = findViewById(R.id.btn_force_switch); |
| | | // forceSwitchBtn = findViewById(R.id.btn_force_switch); |
| | | goForwardBtn = findViewById(R.id.btn_go_forward); |
| | | goBackwardBtn = findViewById(R.id.btn_go_backward); |
| | | rotatopnLeftBtn = findViewById(R.id.btn_rotatopn_left); |
| | | rotatopnRightBtn = findViewById(R.id.btn_rotatopn_right); |
| | | modelSwitchBtn = findViewById(R.id.btn_model_switch); |
| | | |
| | | frontPaddleExtendBtn = findViewById(R.id.btn_front_paddle_extend); // 前拨杆 |
| | | frontPaddleCollectBtn = findViewById(R.id.btn_front_paddle_collect); // 前拨杆 |
| | | backPaddleExtendBtn = findViewById(R.id.btn_back_paddle_extend); // 后拨杆 |
| | | backPaddleCollectBtn = findViewById(R.id.btn_back_paddle_collect); // 后拨杆 |
| | | riseBtn = findViewById(R.id.btn_rise); |
| | | dropBtn = findViewById(R.id.btn_drop); |
| | | extendForkBtn = findViewById(R.id.btn_extend_fork); |
| | | collectForkBtn = findViewById(R.id.btn_collect_fork); |
| | | turnLeftBtn = findViewById(R.id.btn_turn_left); |
| | | turnRightBtn = findViewById(R.id.btn_turn_right); |
| | | |
| | | bodySwitchBtn = findViewById(R.id.btn_body_switch); |
| | | |
| | | layout_bottom = findViewById(R.id.layout_bottom); |
| | | layout_top = findViewById(R.id.layout_top); |
| | | layout_single = findViewById(R.id.layout_single); |
| | | layout_reset = findViewById(R.id.layout_reset); |
| | | |
| | | Intent intent = getIntent(); |
| | | clientId = intent.getStringExtra("message"); |
| | | Log.i("message1",clientId); |
| | | |
| | | // 进出手动模式 |
| | | forceSwitchBtn.setOnClickListener(new View.OnClickListener() { |
| | | // 强制模式开关 |
| | | // forceSwitchBtn.setOnClickListener(new View.OnClickListener() { |
| | | // @Override |
| | | // public void onClick(View v) { |
| | | // if (vibrator != null && vibrator.hasVibrator()) { |
| | | // vibrator.vibrate(500); |
| | | // } |
| | | // String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); |
| | | // AgvAction agvAction = new AgvAction<>(HandOutAction.class) |
| | | // .setAgvNo(AgvNo) |
| | | // .setSerialNo(substring) |
| | | // .setVal(1) |
| | | // .bodySync((action) -> action.setPwd((short) 21)); |
| | | // nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端 |
| | | // } |
| | | // }); |
| | | |
| | | // 手自动模式开关 |
| | | modelSwitchBtn.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | if (vibrator != null && vibrator.hasVibrator()) { |
| | | vibrator.vibrate(500); |
| | | } |
| | | String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); |
| | | AgvAction agvAction = new AgvAction<>(HandOutAction.class) |
| | | .setAgvNo("12") |
| | | .setSerialNo(substring) |
| | | .setVal(1) |
| | | .bodySync((action) -> action.setPwd((short) 21)); |
| | | nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端 |
| | | if (isAuto) { |
| | | AgvAction agvAction = new AgvAction<>(HandInAction.class) |
| | | .setAgvNo(AgvNo) |
| | | .setSerialNo(substring) |
| | | .setVal(autoVal) |
| | | .bodySync((action) -> action.setPwd((short) 21)); |
| | | nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端 |
| | | } else { |
| | | AgvAction agvAction = new AgvAction<>(HandOutAction.class) |
| | | .setAgvNo(AgvNo) |
| | | .setSerialNo(substring) |
| | | .setVal(autoVal) |
| | | .bodySync((action) -> action.setPwd((short) 21)); |
| | | nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端 |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | boolean result = false; |
| | | long timestamp = System.currentTimeMillis(); |
| | | |
| | | Log.i("substring",substring); |
| | | while (System.currentTimeMillis() - timestamp < 5000) { |
| | | |
| | | Object o = map.get(substring); |
| | | |
| | | if (null != o) { |
| | | result = true; |
| | | isAuto = !isAuto; |
| | | map.remove(o); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (result) { |
| | | // alert ok 修改按钮样式 名称 |
| | | if (isAuto) { |
| | | modelSwitchBtn.setText("自动模式"); |
| | | autoVal = 0; |
| | | // modelSwitchBtn.setBackgroundTintList(ColorStateList.valueOf(Color.RED)); |
| | | } else { |
| | | autoVal = 1; |
| | | modelSwitchBtn.setText("手动模式"); |
| | | } |
| | | |
| | | } else { |
| | | // throw new TimeoutException("超时"); |
| | | DialogUtil.showAlertDialog(MainActivity.this, "提示", "请求应答超时!"); |
| | | } |
| | | } |
| | | }); |
| | | stopBtn.setOnTouchListener(new CarTouchButton()); |
| | | goForwardBtn.setOnTouchListener(new CarTouchButton()); |
| | | goBackwardBtn.setOnTouchListener(new CarTouchButton()); |
| | | rotatopnLeftBtn.setOnTouchListener(new CarTouchButton()); |
| | | rotatopnRightBtn.setOnTouchListener(new CarTouchButton()); |
| | | |
| | | frontPaddleExtendBtn.setOnTouchListener(new CarTouchButton()); |
| | | frontPaddleCollectBtn.setOnTouchListener(new CarTouchButton()); |
| | | backPaddleExtendBtn.setOnTouchListener(new CarTouchButton()); |
| | | backPaddleCollectBtn.setOnTouchListener(new CarTouchButton()); |
| | | riseBtn.setOnTouchListener(new CarTouchButton()); |
| | | dropBtn.setOnTouchListener(new CarTouchButton()); |
| | | extendForkBtn.setOnTouchListener(new CarTouchButton()); |
| | | collectForkBtn.setOnTouchListener(new CarTouchButton()); |
| | | turnLeftBtn.setOnTouchListener(new CarTouchButton()); |
| | | turnRightBtn.setOnTouchListener(new CarTouchButton()); |
| | | |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | public boolean onTouch(View view, MotionEvent motionEvent) { |
| | | |
| | | if (view.getId() == R.id.btn_go_forward) { |
| | | // 前进 |
| | | if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) { |
| | | isDowm = true; |
| | | isGoForward = true; |
| | | handler.sendEmptyMessage(0); |
| | | } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) { |
| | | isDowm = false; |
| | | isGoForward = false; |
| | | } |
| | | |
| | | } else if (view.getId() == R.id.btn_go_backward) { |
| | | // 后退 |
| | | if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) { |
| | | isOpen = true; |
| | | isGoBackward = true; |
| | | handler.sendEmptyMessage(0); |
| | | } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) { |
| | | isOpen = false; |
| | | isGoBackward = false; |
| | | } |
| | | |
| | | } else if (view.getId() == R.id.btn_rotatopn_left) { |
| | | // 左旋转 |
| | | if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) { |
| | | isRotatopnLeft = true; |
| | | handler.sendEmptyMessage(0); |
| | | } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) { |
| | | isRotatopnLeft = false; |
| | | } |
| | | |
| | | } else if (view.getId() == R.id.btn_rotatopn_right) { |
| | | // 右旋转 |
| | | if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) { |
| | | isRotatopnRight = true; |
| | | handler.sendEmptyMessage(0); |
| | | } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) { |
| | | isRotatopnRight = false; |
| | | } |
| | | } else if (view.getId() == R.id.btn_front_paddle_extend) { |
| | | // 前拨杆伸出 |
| | | if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) { |
| | | isFrontPaddleExtendBtn = true; |
| | | handler.sendEmptyMessage(0); |
| | | } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) { |
| | | isFrontPaddleExtendBtn = false; |
| | | } |
| | | } else if (view.getId() == R.id.btn_front_paddle_collect) { |
| | | // 前拨杆收起 |
| | | if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) { |
| | | isFrontPaddleCollectBtn = true; |
| | | handler.sendEmptyMessage(0); |
| | | } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) { |
| | | isFrontPaddleCollectBtn = false; |
| | | } |
| | | } else if (view.getId() == R.id.btn_back_paddle_extend) { |
| | | // 后拨杆伸出 |
| | | if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) { |
| | | isBackPaddleExtendBtn = true; |
| | | handler.sendEmptyMessage(0); |
| | | } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) { |
| | | isBackPaddleExtendBtn = false; |
| | | } |
| | | } else if (view.getId() == R.id.btn_back_paddle_collect) { |
| | | // 后拨杆收起 |
| | | if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) { |
| | | isBackPaddleCollectBtn = true; |
| | | handler.sendEmptyMessage(0); |
| | | } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) { |
| | | isBackPaddleCollectBtn = false; |
| | | } |
| | | } else if (view.getId() == R.id.btn_rise) { |
| | | // 上升 |
| | | if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) { |
| | | isRiseBtn = true; |
| | | handler.sendEmptyMessage(0); |
| | | } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) { |
| | | isRiseBtn = false; |
| | | } |
| | | } else if (view.getId() == R.id.btn_drop) { |
| | | // 下降 |
| | | if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) { |
| | | isDropBtn = true; |
| | | handler.sendEmptyMessage(0); |
| | | } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) { |
| | | isDropBtn = false; |
| | | } |
| | | } else if (view.getId() == R.id.btn_extend_fork) { |
| | | // 伸叉 |
| | | if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) { |
| | | isExtendForkBtn = true; |
| | | handler.sendEmptyMessage(0); |
| | | } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) { |
| | | isExtendForkBtn = false; |
| | | } |
| | | } else if (view.getId() == R.id.btn_collect_fork) { |
| | | // 收叉 |
| | | if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) { |
| | | isCollectForkBtn = true; |
| | | handler.sendEmptyMessage(0); |
| | | } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) { |
| | | isCollectForkBtn = false; |
| | | } |
| | | } else if (view.getId() == R.id.btn_turn_left) { |
| | | // 左旋转 |
| | | if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) { |
| | | isTurnLeftBtn = true; |
| | | handler.sendEmptyMessage(0); |
| | | } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) { |
| | | isTurnLeftBtn = false; |
| | | } |
| | | } else if (view.getId() == R.id.btn_turn_right) { |
| | | // 左旋转 |
| | | if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) { |
| | | isTurnRightBtn = true; |
| | | handler.sendEmptyMessage(0); |
| | | } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) { |
| | | isTurnRightBtn = false; |
| | | } |
| | | } |
| | | |
| | | return false; |
| | | |
| | | } |
| | | } |
| | | |
| | | private boolean isVisble = true; |
| | | |
| | | // 货叉等按钮 |
| | | public void switchover(View view) { |
| | | if (isVisble) { |
| | | layout_bottom.setVisibility(View.GONE); |
| | | layout_top.setVisibility(View.VISIBLE); |
| | | bodySwitchBtn.setText("货叉"); |
| | | } else { |
| | | layout_bottom.setVisibility(View.VISIBLE); |
| | | layout_top.setVisibility(View.GONE); |
| | | bodySwitchBtn.setText("底盘"); |
| | | } |
| | | isVisble = !isVisble; |
| | | |
| | | layout_single.setVisibility(View.GONE); |
| | | layout_reset.setVisibility(View.GONE); |
| | | |
| | | } |
| | | |
| | | // 单轴使能按钮 |
| | | public void switchSingle(View view) { |
| | | layout_bottom.setVisibility(View.GONE); |
| | | layout_top.setVisibility(View.GONE); |
| | | layout_single.setVisibility(View.VISIBLE); |
| | | layout_reset.setVisibility(View.GONE); |
| | | } |
| | | |
| | | // 复位按钮 |
| | | public void switchRest(View view) { |
| | | layout_bottom.setVisibility(View.GONE); |
| | | layout_top.setVisibility(View.GONE); |
| | | layout_single.setVisibility(View.GONE); |
| | | layout_reset.setVisibility(View.VISIBLE); |
| | | } |
| | | |
| | | @Override |
| | | protected void onDestroy() { |
| | | super.onDestroy(); |