| | |
| | | package com.lotaai.canguiayw; |
| | | |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.os.Bundle; |
| | | import android.os.Handler; |
| | | import android.os.Looper; |
| | |
| | | import com.lotaai.canguiayw.device.DeviceMessage; |
| | | import com.lotaai.canguiayw.device.DeviceType; |
| | | import com.lotaai.canguiayw.device.MessageType; |
| | | import com.lotaai.canguiayw.device.service.CanGuiService; |
| | | import com.lotaai.canguiayw.device.service.CrontrolGridModel; |
| | | import com.lotaai.canguiayw.view.TipDialog; |
| | | import com.pranavpandey.android.dynamic.toasts.DynamicToast; |
| | | |
| | | import org.greenrobot.eventbus.EventBus; |
| | |
| | | public class StartSaveActivity extends AppCompatActivity { |
| | | private Context context; |
| | | private EditText editText; |
| | | CanguiStatus canguidata; |
| | | private TextView titleinfo; |
| | | private TextView tv_see_code; |
| | | // CanguiStatus canguidata; |
| | | String ss; |
| | | |
| | | @Override |
| | | protected void onCreate(Bundle savedInstanceState) { |
| | | super.onCreate(savedInstanceState); |
| | | setContentView(R.layout.activity_startsave); |
| | | canguidata = (CanguiStatus) getIntent().getSerializableExtra("info"); |
| | | initView(); |
| | | ss = CrontrolGridModel.getGridNoStr(canguidata.getGuiHao(), canguidata.getGridNo()); |
| | | titleinfo.setText("选择的格子号:" + ss); |
| | | // canguidata = (CanguiStatus) getIntent().getSerializableExtra("info"); |
| | | // ss = CrontrolGridModel.getGridNoStr(canguidata.getGuiHao(), canguidata.getGridNo()); |
| | | context = StartSaveActivity.this; |
| | | Intent startIntent = new Intent(context, CanGuiService.class); |
| | | startService(startIntent); |
| | | editText = (EditText) findViewById(R.id.edt_borrow_case_number); |
| | | tv_see_code = (TextView) findViewById(R.id.tv_see_code); |
| | | editText.setInputType(InputType.TYPE_NULL); // 屏蔽软键盘 |
| | | DynamicToast.Config.getInstance().setTextSize(30).apply(); |
| | | // 软键盘设置统一按钮监听方法,数字键直接将text内容填充到edittext中,删除和确认才设置事件 |
| | |
| | | // 调用后台 |
| | | String gridNo = editable.toString(); |
| | | if (null == gridNo || "".equals(gridNo.trim())) { |
| | | DynamicToast.makeError(context, "取餐码不能为空。", 3).show(); |
| | | showResult("Please enter pickup code."); |
| | | return; |
| | | } else { |
| | | if (gridNo.length() != 6) { |
| | | editText.setText(""); |
| | | DynamicToast.makeError(context, "取餐码输入错误,请重试。", 3).show(); |
| | | showResult("The pickup code input is incorrect,\nplease try again."); |
| | | return; |
| | | } |
| | | //调用判断是否可以取餐 |
| | | editText.setText(""); |
| | | takeCheckCode(gridNo, canguidata.getGuiHao(), canguidata.getGridNo()); |
| | | // takeCheckCode(gridNo, canguidata.getGuiHao(), canguidata.getGridNo()); |
| | | checkCode(gridNo,0); |
| | | } |
| | | |
| | | |
| | | } else if (key == R.id.tv_by_hand) { |
| | | // 调用后台 |
| | | String gridNo = editable.toString(); |
| | | if (null == gridNo || "".equals(gridNo.trim())) { |
| | | showResult("Please enter pickup code."); |
| | | return; |
| | | } else { |
| | | //调用判断是否可以取餐 |
| | | editText.setText(""); |
| | | // takeCheckCode(gridNo, canguidata.getGuiHao(), canguidata.getGridNo()); |
| | | checkCode(gridNo,1); |
| | | } |
| | | } else { |
| | | Button button = (Button) v; |
| | | editable.insert(index, button.getText()); |
| | |
| | | View view0 = findViewById(R.id.borrow_bt0); |
| | | View view11 = findViewById(R.id.borrow_bt_delete); |
| | | View view12 = findViewById(R.id.borrow_bt_confirm); |
| | | View view13 = findViewById(R.id.tv_by_hand); |
| | | view1.setOnClickListener(clickListener); |
| | | view2.setOnClickListener(clickListener); |
| | | view3.setOnClickListener(clickListener); |
| | |
| | | view0.setOnClickListener(clickListener); |
| | | view11.setOnClickListener(clickListener); |
| | | view12.setOnClickListener(clickListener); |
| | | view13.setOnClickListener(clickListener); |
| | | |
| | | tv_see_code.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View view) { |
| | | Intent intent = new Intent(StartSaveActivity.this, PickCodeListActivity.class); |
| | | startActivity(intent); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | public void backMian(View view) { |
| | |
| | | finish(); |
| | | } |
| | | |
| | | public void takeCheckCode(String code, int guino, int gridno) { |
| | | public void checkCode(final String code, final int isHand) { |
| | | HttpLoggerInterceptor loggingInterceptor = new HttpLoggerInterceptor(true); |
| | | OkHttpClient client = new OkHttpClient.Builder() |
| | | .connectTimeout(20, TimeUnit.SECONDS)//响应时间,读取时间 |
| | |
| | | .callTimeout(20, TimeUnit.SECONDS) |
| | | .addInterceptor(loggingInterceptor)//添加日志拦截器 |
| | | .build(); |
| | | |
| | | LogUtils.i(CacheDiskUtils.getInstance().getString(SettingConfig.getInstance().Cache_Device_Code), code); |
| | | String sn = CacheDiskUtils.getInstance().getString(SettingConfig.getInstance().Cache_Device_Code); |
| | | RequestBody body = new FormBody.Builder() |
| | | .build(); |
| | | |
| | | final Request request = new Request.Builder() |
| | | .url(HttpUrlDefine.checkStatus + "?pickNum=" + code + "&boxNum=" + guino + "&cartNum=" + gridno) |
| | | .url(HttpUrlDefine.check + "?pickNum=" + code + "&sn=" + sn+ "&isHand=" + isHand) |
| | | /* .addHeader("language", "zh-CN")*/ |
| | | .post(body) |
| | | .build(); |
| | |
| | | runOnUiThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | DynamicToast.makeError(context, "请求失败!", 3).show(); |
| | | DynamicToast.makeError(context, "Request error!", 3).show(); |
| | | } |
| | | }); |
| | | |
| | |
| | | @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);*/ |
| | | DynamicToast.makeSuccess(context, "订单已创建,请将餐食放入" + ss + "柜中", 3).show(); |
| | | // new Handler(Looper.getMainLooper()).postDelayed(() -> finish(), 3000); |
| | | |
| | | finish(); |
| | | |
| | | //取餐码可用,去选柜子 |
| | | Intent intent = new Intent(StartSaveActivity.this, CunOjbActivity.class); |
| | | intent.putExtra("code",code); |
| | | intent.putExtra("isHand",isHand); |
| | | startActivity(intent); |
| | | } else { |
| | | DynamicToast.makeError(context, baseDto.getMsg(), 3).show(); |
| | | showResult(baseDto.getMsg()); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | |
| | | } |
| | | }); |
| | | } |
| | |
| | | }; |
| | | |
| | | private void initView() { |
| | | titleinfo = (TextView) findViewById(R.id.titleinfo); |
| | | } |
| | | |
| | | public void showResult(String msg){ |
| | | TipDialog tipDialog = new TipDialog(); |
| | | Bundle bundle = new Bundle(); |
| | | bundle.putString("msg",msg); |
| | | tipDialog.setArguments(bundle); |
| | | tipDialog.show(getSupportFragmentManager(),"res"); |
| | | } |
| | | } |