| | |
| | | import com.lotaai.canguiayw.device.DeviceType; |
| | | import com.lotaai.canguiayw.device.MessageType; |
| | | import com.lotaai.canguiayw.view.GridTableAdapter; |
| | | |
| | | import org.greenrobot.eventbus.EventBus; |
| | | import org.greenrobot.eventbus.Subscribe; |
| | | import org.greenrobot.eventbus.ThreadMode; |
| | |
| | | private Button fugui003; |
| | | private Button fugui004; |
| | | private Button fugui005; |
| | | private int cureentSelectGui =0; |
| | | private boolean isCanRun = true; |
| | | private int cureentSelectGui = 0; |
| | | private boolean isCanRun = false; |
| | | |
| | | |
| | | @Override |
| | |
| | | |
| | | |
| | | @Subscribe(threadMode = ThreadMode.ASYNC) |
| | | public void recvCommand(DeviceMessage mssage){ |
| | | public void recvCommand(DeviceMessage mssage) { |
| | | try { |
| | | if (mssage.getMessageType() == MessageType.FANHUI.ordinal()){ |
| | | if (mssage.getMessageType() == MessageType.FANHUI.ordinal()) { |
| | | isCanRun = false; |
| | | } |
| | | }catch (Exception e){ |
| | | } catch (Exception e) { |
| | | LogUtils.e(e); |
| | | } |
| | | } |
| | |
| | | initView(); |
| | | intitSwitch(); |
| | | initButton(); |
| | | SettingConfig.getInstance().getExecutor().execute(syncRunnable); |
| | | // SettingConfig.getInstance().getExecutor().execute(syncRunnable); |
| | | return root; |
| | | } |
| | | |
| | | Runnable syncRunnable = new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | while (isCanRun){ |
| | | try { |
| | | Thread.sleep(1000); |
| | | showHandler.sendEmptyMessage(1); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | }catch (Exception e){ |
| | | while (isCanRun) { |
| | | try { |
| | | Thread.sleep(1000); |
| | | showHandler.sendEmptyMessage(1); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | |
| | | private void initButton(){ |
| | | private void initButton() { |
| | | zhugui = root.findViewById(R.id.zhu001); |
| | | fugui001 = root.findViewById(R.id.gui001); |
| | | fugui002 = root.findViewById(R.id.gui002); |
| | | fugui003 = root.findViewById(R.id.gui003); |
| | | fugui004 = root.findViewById(R.id.gui004); |
| | | fugui005 = root.findViewById(R.id.gui005); |
| | | for (int g =0; g <SettingConfig.getInstance().statusList.size();g++){ |
| | | if (SettingConfig.getInstance().statusList.get(g).getGuiHao() == 0){ |
| | | if (zhugui.getVisibility()!=View.VISIBLE){ |
| | | for (int g = 0; g < SettingConfig.getInstance().statusList.size(); g++) { |
| | | if (SettingConfig.getInstance().statusList.get(g).getGuiHao() == 0) { |
| | | if (zhugui.getVisibility() != View.VISIBLE) { |
| | | zhugui.setVisibility(View.VISIBLE); |
| | | } |
| | | } |
| | | |
| | | if (SettingConfig.getInstance().statusList.get(g).getGuiHao() == 1){ |
| | | if (fugui001.getVisibility()!=View.VISIBLE){ |
| | | if (SettingConfig.getInstance().statusList.get(g).getGuiHao() == 1) { |
| | | if (fugui001.getVisibility() != View.VISIBLE) { |
| | | fugui001.setVisibility(View.VISIBLE); |
| | | } |
| | | } |
| | | |
| | | if (SettingConfig.getInstance().statusList.get(g).getGuiHao() == 2){ |
| | | if (fugui002.getVisibility()!=View.VISIBLE){ |
| | | if (SettingConfig.getInstance().statusList.get(g).getGuiHao() == 2) { |
| | | if (fugui002.getVisibility() != View.VISIBLE) { |
| | | fugui002.setVisibility(View.VISIBLE); |
| | | } |
| | | } |
| | | |
| | | if (SettingConfig.getInstance().statusList.get(g).getGuiHao() == 3){ |
| | | if (fugui003.getVisibility()!=View.VISIBLE){ |
| | | if (SettingConfig.getInstance().statusList.get(g).getGuiHao() == 3) { |
| | | if (fugui003.getVisibility() != View.VISIBLE) { |
| | | fugui003.setVisibility(View.VISIBLE); |
| | | } |
| | | } |
| | | |
| | | if (SettingConfig.getInstance().statusList.get(g).getGuiHao() == 4){ |
| | | if (fugui004.getVisibility()!=View.VISIBLE){ |
| | | if (SettingConfig.getInstance().statusList.get(g).getGuiHao() == 4) { |
| | | if (fugui004.getVisibility() != View.VISIBLE) { |
| | | fugui004.setVisibility(View.VISIBLE); |
| | | } |
| | | } |
| | | |
| | | if (SettingConfig.getInstance().statusList.get(g).getGuiHao() == 5){ |
| | | if (fugui005.getVisibility()!=View.VISIBLE){ |
| | | if (SettingConfig.getInstance().statusList.get(g).getGuiHao() == 5) { |
| | | if (fugui005.getVisibility() != View.VISIBLE) { |
| | | fugui005.setVisibility(View.VISIBLE); |
| | | } |
| | | } |
| | |
| | | cancelAllBtn(); |
| | | zhugui.setBackgroundColor(getResources().getColor(R.color.cheng)); |
| | | cureentSelectGui = 0; |
| | | |
| | | /* CanguiStatus cangui =new CanguiStatus(); |
| | | cangui.setGuiHao(8); |
| | | cangui.setGridNo(88); |
| | | ((CunOjbActivity) getActivity()).setData(cangui);*/ |
| | | } |
| | | }); |
| | | |
| | |
| | | cancelAllBtn(); |
| | | fugui001.setBackgroundColor(getResources().getColor(R.color.cheng)); |
| | | cureentSelectGui = 1; |
| | | initView(); |
| | | } |
| | | }); |
| | | |
| | |
| | | cancelAllBtn(); |
| | | fugui002.setBackgroundColor(getResources().getColor(R.color.cheng)); |
| | | cureentSelectGui = 2; |
| | | |
| | | initView(); |
| | | } |
| | | }); |
| | | |
| | |
| | | cancelAllBtn(); |
| | | fugui003.setBackgroundColor(getResources().getColor(R.color.cheng)); |
| | | cureentSelectGui = 3; |
| | | |
| | | initView(); |
| | | } |
| | | }); |
| | | |
| | |
| | | cancelAllBtn(); |
| | | fugui004.setBackgroundColor(getResources().getColor(R.color.cheng)); |
| | | cureentSelectGui = 4; |
| | | |
| | | initView(); |
| | | } |
| | | }); |
| | | |
| | |
| | | cancelAllBtn(); |
| | | fugui005.setBackgroundColor(getResources().getColor(R.color.cheng)); |
| | | cureentSelectGui = 5; |
| | | |
| | | initView(); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | public void cancelAllBtn(){ |
| | | public void cancelAllBtn() { |
| | | zhugui.setBackgroundColor(Color.GRAY); |
| | | fugui001.setBackgroundColor(Color.GRAY); |
| | | fugui002.setBackgroundColor(Color.GRAY); |
| | |
| | | } |
| | | for (int p = 0; p < selectedList.size(); p++) { |
| | | CanguiStatus grid = selectedList.get(p); |
| | | byte[] command = CanGuiCommand.getInstance().controlGridCommand(grid.getGuiHao() , |
| | | grid.getGridNo() , 0, 255, 0, caozuo, 0, 0); |
| | | byte[] command = CanGuiCommand.getInstance().controlGridCommand(grid.getGuiHao(), |
| | | grid.getGridNo(), 0, 255, 0, caozuo, 0, 0); |
| | | DeviceMessage message = new DeviceMessage(); |
| | | message.setMessageType(MessageType.SENDMESSAGE.ordinal()); |
| | | message.setDeviceType(DeviceType.CANGUI.ordinal()); |
| | |
| | | public void onClick(View view) { |
| | | for (int p = 0; p < selectedList.size(); p++) { |
| | | CanguiStatus grid = selectedList.get(p); |
| | | LogUtils.i(TAG,grid.getGuiHao(),grid.getGridNo()); |
| | | byte[] command = CanGuiCommand.getInstance().controlGridCommand(grid.getGuiHao() , |
| | | grid.getGridNo() , 1, 255, 0, 0, 0, 0); |
| | | LogUtils.i(TAG, grid.getGuiHao(), grid.getGridNo()); |
| | | byte[] command = CanGuiCommand.getInstance().controlGridCommand(grid.getGuiHao(), |
| | | grid.getGridNo(), 1, 255, 0, 0, 0, 0); |
| | | DeviceMessage message = new DeviceMessage(); |
| | | message.setMessageType(MessageType.SENDMESSAGE.ordinal()); |
| | | message.setDeviceType(DeviceType.CANGUI.ordinal()); |
| | |
| | | |
| | | public void initView() { |
| | | gridStatusList.clear(); |
| | | for (int i = 0; i< SettingConfig.getInstance().statusList.size();i++){ |
| | | for (int i = 0; i < SettingConfig.getInstance().statusList.size(); i++) { |
| | | CanguiStatus ss = SettingConfig.getInstance().statusList.get(i); |
| | | if (ss.getGuiHao() == cureentSelectGui) { |
| | | CanguiStatus status = new CanguiStatus(); |
| | |
| | | @Override |
| | | public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { |
| | | CanguiStatus cangui = gridStatusList.get(i); |
| | | View item = gridtable.getChildAt(i).findViewById(R.id.gridLineLayout); |
| | | ((CunOjbActivity) getActivity()).setData(cangui); |
| | | |
| | | /* View item = gridtable.getChildAt(i).findViewById(R.id.gridLineLayout); |
| | | if (checkIsSelectedAndOrRemove(cangui,true)) { |
| | | item.setBackgroundColor(Color.GRAY); |
| | | } else { |
| | | item.setBackgroundColor(getResources().getColor(R.color.cheng)); |
| | | } |
| | | }*/ |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param status |
| | | * @param isControl 是否从控制删除和添加,选中变不选,不选变选 |
| | | * @param isControl 是否从控制删除和添加,选中变不选,不选变选 |
| | | * @return |
| | | */ |
| | | private boolean checkIsSelectedAndOrRemove(CanguiStatus status,boolean isControl) { |
| | | private boolean checkIsSelectedAndOrRemove(CanguiStatus status, boolean isControl) { |
| | | boolean isFind = false; |
| | | for (int i = 0; i < selectedList.size(); i++) { |
| | | if (selectedList.get(i).getGridNo() == status.getGridNo() && selectedList.get(i).getGuiHao() == status.getGuiHao()) { |