| | |
| | | import android.widget.AdapterView; |
| | | import android.widget.Button; |
| | | import android.widget.GridView; |
| | | import android.widget.TextView; |
| | | import android.widget.ThemedSpinnerAdapter; |
| | | |
| | | import androidx.fragment.app.Fragment; |
| | | |
| | | import com.blankj.utilcode.util.CacheDiskUtils; |
| | | import com.blankj.utilcode.util.GsonUtils; |
| | | import com.blankj.utilcode.util.LogUtils; |
| | | import com.liys.lswitch.BaseSwitch; |
| | | import com.liys.lswitch.LSwitch; |
| | | import com.lotaai.canguiayw.common.HttpLoggerInterceptor; |
| | | import com.lotaai.canguiayw.common.HttpUrlDefine; |
| | | import com.lotaai.canguiayw.common.SettingConfig; |
| | | import com.lotaai.canguiayw.data.BaseDto; |
| | | import com.lotaai.canguiayw.device.CanGuiCommand; |
| | | import com.lotaai.canguiayw.device.CanguiStatus; |
| | | import com.lotaai.canguiayw.device.DeviceMessage; |
| | | import com.lotaai.canguiayw.device.DeviceType; |
| | | import com.lotaai.canguiayw.device.MessageType; |
| | | import com.lotaai.canguiayw.view.GridTableAdapter; |
| | | import com.lotaai.canguiayw.view.GridTableAdapterNew; |
| | | import com.pranavpandey.android.dynamic.toasts.DynamicToast; |
| | | |
| | | import org.greenrobot.eventbus.EventBus; |
| | | import org.greenrobot.eventbus.Subscribe; |
| | | import org.greenrobot.eventbus.ThreadMode; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | import okhttp3.Call; |
| | | import okhttp3.Callback; |
| | | import okhttp3.FormBody; |
| | | import okhttp3.OkHttpClient; |
| | | import okhttp3.Request; |
| | | import okhttp3.RequestBody; |
| | | import okhttp3.Response; |
| | | |
| | | public class OpenDoorFragment extends Fragment { |
| | | |
| | |
| | | private Button fugui003; |
| | | private Button fugui004; |
| | | private Button fugui005; |
| | | private int cureentSelectGui =0; |
| | | private boolean isCanRun = true; |
| | | private TextView tv_close; |
| | | private int cureentSelectGui = 0; |
| | | private boolean isCanRun = false; |
| | | |
| | | |
| | | @Override |
| | |
| | | super.onDestroy(); |
| | | } |
| | | |
| | | |
| | | @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); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| | |
| | | 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); |
| | | Log.i(TAG,"在运行"); |
| | | } 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){ |
| | | tv_close = root.findViewById(R.id.tv_close); |
| | | 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(); |
| | | } |
| | | }); |
| | | |
| | | tv_close.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View view) { |
| | | requireActivity().finish(); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | 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(); |
| | |
| | | } |
| | | } |
| | | Collections.sort(gridStatusList); |
| | | GridTableAdapter adapter = new GridTableAdapter(context, gridStatusList, R.layout.framgment_tablegrid_item); |
| | | if (gridStatusList.size() == 8){ |
| | | CanguiStatus e = new CanguiStatus(); |
| | | e.setGridNo(-1); |
| | | gridStatusList.add(4, e); |
| | | } |
| | | GridTableAdapterNew adapter = new GridTableAdapterNew(context, gridStatusList, R.layout.item_box_new); |
| | | gridtable = root.findViewById(R.id.gridtable); |
| | | gridtable.setAdapter(adapter); |
| | | gridtable.setOnItemClickListener(new AdapterView.OnItemClickListener() { |
| | | @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); |
| | | if (checkIsSelectedAndOrRemove(cangui,true)) { |
| | | item.setBackgroundColor(getResources().getColor(R.color.cheng)); |
| | | } else { |
| | | item.setBackgroundColor(Color.GRAY); |
| | | if (cangui.getGridNo()!=-1){ |
| | | //存餐 |
| | | takeCheckCode(((CunOjbActivity) getActivity()).pickupCode,0,cangui.getGridNo(),((CunOjbActivity) getActivity()).isHand); |
| | | } |
| | | // ((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)); |
| | | }*/ |
| | | } |
| | | }); |
| | | } |
| | | |
| | | public void takeCheckCode(String code, final int guino, final int gridno, int isHand) { |
| | | HttpLoggerInterceptor loggingInterceptor = new HttpLoggerInterceptor(true); |
| | | OkHttpClient client = new OkHttpClient.Builder() |
| | | .connectTimeout(20, TimeUnit.SECONDS)//响应时间,读取时间 |
| | | .readTimeout(20, TimeUnit.SECONDS) |
| | | .callTimeout(20, TimeUnit.SECONDS) |
| | | .addInterceptor(loggingInterceptor)//添加日志拦截器 |
| | | .build(); |
| | | |
| | | LogUtils.i(CacheDiskUtils.getInstance().getString(SettingConfig.getInstance().Cache_Device_Code), code); |
| | | RequestBody body = new FormBody.Builder() |
| | | .build(); |
| | | |
| | | final Request request = new Request.Builder() |
| | | .url(HttpUrlDefine.checkStatus + "?pickNum=" + code + "&boxNum=" + guino + "&cartNum=" + gridno+ "&isHand=" + isHand+ "&sn=" + CacheDiskUtils.getInstance().getString(SettingConfig.getInstance().Cache_Device_Code)) |
| | | /* .addHeader("language", "zh-CN")*/ |
| | | .post(body) |
| | | .build(); |
| | | client.newCall(request).enqueue(new Callback() { |
| | | @Override |
| | | public void onFailure(Call call, IOException e) { |
| | | requireActivity().runOnUiThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | DynamicToast.makeError(context, "Request error!", 3).show(); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onResponse(Call call, Response response) throws IOException { |
| | | String result = response.body().string(); |
| | | LogUtils.i("获取到的数据:" + result); |
| | | final BaseDto baseDto = GsonUtils.fromJson(result, BaseDto.class); |
| | | requireActivity().runOnUiThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | if (baseDto.getCode() == 200) { |
| | | byte[] command = CanGuiCommand.getInstance().controlGridCommand(guino, |
| | | gridno, 1, 255, 0, 0, 0, 0); |
| | | DeviceMessage message = new DeviceMessage(); |
| | | message.setMessageType(MessageType.SENDMESSAGE.ordinal()); |
| | | message.setDeviceType(DeviceType.CANGUI.ordinal()); |
| | | message.setMessageByte(command); |
| | | EventBus.getDefault().post(message); |
| | | // new Handler(Looper.getMainLooper()).postDelayed(() -> finish(), 3000); |
| | | ((CunOjbActivity)requireActivity()).showResult("Place meal into the box."); |
| | | } else { |
| | | DynamicToast.makeError(context, baseDto.getMsg(), 3).show(); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * |
| | | * @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()) { |