|
@@ -86,11 +86,9 @@ public class MainActivity extends AppCompatActivity {
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
- // 强制关闭输入法
|
|
|
- getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
|
|
|
-
|
|
|
binding = ActivityMainBinding.inflate(getLayoutInflater());
|
|
|
- setContentView(binding.getRoot());
|
|
|
+ // 强制关闭输入法
|
|
|
+ getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
|
|
|
// setSupportActionBar(binding.toolbar);
|
|
|
// NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_main);
|
|
|
// appBarConfiguration = new AppBarConfiguration.Builder(navController.getGraph()).build();
|
|
@@ -108,220 +106,220 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
// 获取系统配置
|
|
|
- ICSPClient.getSystemConfig("", BaseUtils.getClientId(), new Callback() {
|
|
|
- @Override
|
|
|
- public void onFailure(@NotNull Call call, @NotNull IOException e) {
|
|
|
- Log.e(TAG, "onFailure: 获取系统配置错误! 网络错误! ", e);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onResponse
|
|
|
- (@NotNull Call call, @NotNull Response response) throws IOException {
|
|
|
-
|
|
|
- try {
|
|
|
- OnDownloadListener listener = new OnDownloadListener() {
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onDownloadSuccess(File file) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onDownloading(int progress) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onDownloadFailed(Exception e) {
|
|
|
-
|
|
|
- }
|
|
|
- };
|
|
|
- String parseResponse = ICSPClient.isSuccessfulAndParseResponse(response);
|
|
|
- ObjectMapper objectMapper = new ObjectMapper();
|
|
|
- ResponseData<Map<String, String>> readValue = objectMapper.readValue(parseResponse, new TypeReference<ResponseData<Map<String, String>>>() {
|
|
|
- });
|
|
|
- if (null != readValue && readValue.getCode().equals(ICSPResponseCodeEnum.OK.getCode())) {
|
|
|
- configMap.putAll(readValue.getData());
|
|
|
- String qrcode_url = configMap.get(SystemConfigConstant.cabinet_take_object_qrcode_url);
|
|
|
-
|
|
|
- try {
|
|
|
- ICSPClient.download(qrcode_url, new Callback() {
|
|
|
- @Override
|
|
|
- public void onFailure(@NotNull Call call, @NotNull IOException e) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
|
|
|
- InputStream is = null;
|
|
|
- byte[] buf = new byte[2048];
|
|
|
- int len = 0;
|
|
|
- FileOutputStream fos = null;
|
|
|
- final String destFileDir = "res/drawable/";
|
|
|
- String destFileName = "e_mp_qrcode_8x8.jpg";
|
|
|
- //储存下载文件的目录
|
|
|
- File dir = new File(getApplication().getFilesDir().getAbsolutePath() + "/" +destFileDir);
|
|
|
- if (!dir.exists()) {
|
|
|
- dir.mkdirs();
|
|
|
- }
|
|
|
-// destFileName = apk_url.substring(apk_url.lastIndexOf('/'), apk_url.length() - 1);
|
|
|
- File file = new File(dir, destFileName);
|
|
|
-
|
|
|
- try {
|
|
|
-
|
|
|
- is = response.body().byteStream();
|
|
|
- long total = response.body().contentLength();
|
|
|
- fos = new FileOutputStream(file);
|
|
|
- long sum = 0;
|
|
|
- while ((len = is.read(buf)) != -1) {
|
|
|
- fos.write(buf, 0, len);
|
|
|
- sum += len;
|
|
|
- int progress = (int) (sum * 1.0f / total * 100);
|
|
|
- //下载中更新进度条
|
|
|
- listener.onDownloading(progress);
|
|
|
- }
|
|
|
- fos.flush();
|
|
|
- //下载完成
|
|
|
- listener.onDownloadSuccess(file);
|
|
|
- } catch (Exception e) {
|
|
|
- listener.onDownloadFailed(e);
|
|
|
- }finally {
|
|
|
- try {
|
|
|
- if (is != null) {
|
|
|
- is.close();
|
|
|
- }
|
|
|
- if (fos != null) {
|
|
|
- fos.close();
|
|
|
- }
|
|
|
- } catch (IOException e) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }, listener);
|
|
|
- } catch (Exception e) {
|
|
|
-
|
|
|
- }
|
|
|
- Log.i(TAG, "onResponse: 获取系统配置成功! ");
|
|
|
- } else {
|
|
|
- Log.w(TAG, "onResponse: code==>" + readValue.getCode() + ", msg==>" + readValue.getMsg());
|
|
|
- }
|
|
|
- } catch (RuntimeException e) {
|
|
|
- Log.e(TAG, "onResponse: 获取系统配置错误! 未知错误! ", e);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- ICHPublishClient ichPublishClient = ICHPublishClient.getInstance();
|
|
|
-
|
|
|
- String clientId = BaseUtils.getClientId();
|
|
|
- ICHTopic.CLIENT_ID = clientId;
|
|
|
- // 订阅主题
|
|
|
-// ICHSubscribeClient ichSubscribeClient = ICHSubscribeClient.getInstance();
|
|
|
- ichPublishClient.subscribe(ICHTopic.LOCK + clientId, (s, msg) -> {
|
|
|
- String payload = new String(msg.getPayload());
|
|
|
- ObjectMapper objectMapper = new ObjectMapper();
|
|
|
- Message message = objectMapper.readValue(payload, Message.class);
|
|
|
- Log.i(TAG, "onCreate: message id: " + s + "--------------消息体: " + message);
|
|
|
-
|
|
|
- DeviceControl.unlockLocker(message.getSection(), message.getPort(), (var1, var2) -> {
|
|
|
- Log.i(TAG, "onCreate: 开锁返回码: " + var1 + "--------------返回消息: " + Arrays.asList(var2));
|
|
|
- MqttMessage mqttMessage;
|
|
|
- if (var1 != 0) {
|
|
|
- try {
|
|
|
- mqttMessage = wrapMessage(message, objectMapper);
|
|
|
- ichPublishClient.publish(String.format(ICHTopic.CALLBACK_FAILED, BaseUtils.getClientId()), mqttMessage);
|
|
|
- } catch (JsonProcessingException e) {
|
|
|
- Log.e(TAG, "onCreate: ---------------------序列化开锁错误消息失败! ", e);
|
|
|
- } catch (Exception e) {
|
|
|
- Log.e(TAG, "onCreate: ---------------------未知错误! ", e);
|
|
|
- }
|
|
|
- } else {
|
|
|
- // TODO 暂时不做 成功需要不断去请求查询锁是否关闭, 关闭后推送成功消息
|
|
|
- Log.i(TAG, "onCreate: -------------------------开锁成功");
|
|
|
-// AtomicBoolean atomicBoolean = new AtomicBoolean(true);
|
|
|
-// AtomicInteger atomicInteger = new AtomicInteger(5);
|
|
|
-// do {
|
|
|
-// try {
|
|
|
-// TimeUnit.SECONDS.sleep(30);
|
|
|
-// } catch (InterruptedException e) {
|
|
|
-// Log.e(TAG, "onCreate: 等待查询锁状态时线程中断! ", e);
|
|
|
+// ICSPClient.getSystemConfig("", BaseUtils.getClientId(), new Callback() {
|
|
|
+// @Override
|
|
|
+// public void onFailure(@NotNull Call call, @NotNull IOException e) {
|
|
|
+// Log.e(TAG, "onFailure: 获取系统配置错误! 网络错误! ", e);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void onResponse
|
|
|
+// (@NotNull Call call, @NotNull Response response) throws IOException {
|
|
|
+//
|
|
|
+// try {
|
|
|
+// OnDownloadListener listener = new OnDownloadListener() {
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void onDownloadSuccess(File file) {
|
|
|
+//
|
|
|
// }
|
|
|
-// DeviceControl.queryLocker(message.getSection(), message.getPort(), (var3, var4) -> {
|
|
|
-// List<String> strings = Arrays.asList(var4);
|
|
|
-// if (var3 == 0 && strings.size() > 0 && !strings.get(0).equals("locked")) {
|
|
|
-// atomicBoolean.set(false);
|
|
|
-// }
|
|
|
-// atomicInteger.decrementAndGet();
|
|
|
-// });
|
|
|
-// if (atomicInteger.get() <= 0) {
|
|
|
-// atomicBoolean.set(false);
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void onDownloading(int progress) {
|
|
|
+//
|
|
|
// }
|
|
|
-// } while(atomicBoolean.get());
|
|
|
- try {
|
|
|
- mqttMessage = wrapMessage(message, objectMapper);
|
|
|
-// if (atomicInteger.get() <= 0) {
|
|
|
-// message.setCause("长时间未关闭柜门!");
|
|
|
-// mqttMessage.setPayload(objectMapper.writeValueAsBytes(message));
|
|
|
-// ichPublishClient.publish(String.format(ICHTopic.CALLBACK_FAILED, BaseUtils.getClientId()), mqttMessage);
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void onDownloadFailed(Exception e) {
|
|
|
+//
|
|
|
// }
|
|
|
-
|
|
|
- ichPublishClient.publish(String.format(ICHTopic.CALLBACK_SUCCESS, BaseUtils.getClientId()), mqttMessage);
|
|
|
- } catch (JsonProcessingException e) {
|
|
|
- Log.e(TAG, "onCreate: ---------------------序列化开锁成功消息失败! ", e);
|
|
|
- } catch (RuntimeException e) {
|
|
|
- Log.e(TAG, "onCreate: ---------------------未知错误! ", e);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- });
|
|
|
-
|
|
|
- // 注册柜子信息
|
|
|
-
|
|
|
- String appVersion = BaseUtils.getAppVersion(getApplicationContext());
|
|
|
- String androidVersion = BaseUtils.getVersionName();
|
|
|
- CountDownLatch countDownLatch = new CountDownLatch(10);
|
|
|
- Cabinet cabinet = DeviceControl.queryCabinetInfo(countDownLatch);
|
|
|
- try {
|
|
|
- countDownLatch.await();
|
|
|
- } catch (InterruptedException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- cabinet.setClientId(clientId);
|
|
|
- cabinet.setSoftwareVersion(appVersion);
|
|
|
- cabinet.setAndroidVersion(androidVersion);
|
|
|
- cabinet.setSoftwareType("android");
|
|
|
- cabinet.setImei(BaseUtils.getIMEI(getApplicationContext()));
|
|
|
- cabinet.setMacIpv4("111");
|
|
|
- cabinet.setMacIpv6("unknown");
|
|
|
- cabinet.setNetType("111");
|
|
|
- cabinet.setPlatType("S905");
|
|
|
- cabinet.setSim("111");
|
|
|
- cabinet.setWifiSSid("111");
|
|
|
-
|
|
|
- ObjectMapper objectMapper = new ObjectMapper();
|
|
|
-
|
|
|
- try {
|
|
|
- String jsonData = objectMapper.writeValueAsString(cabinet);
|
|
|
- Log.i(TAG, "onCreate: jsonData===============>" + jsonData);
|
|
|
-
|
|
|
- MqttMessage message = new MqttMessage();
|
|
|
- message.setQos(1);
|
|
|
- message.setPayload(jsonData.getBytes());
|
|
|
- ichPublishClient.publish(String.format(ICHTopic.CABINET_INFO_REPORT, clientId), message);
|
|
|
- } catch (JsonProcessingException e) {
|
|
|
- Log.e(TAG, "onCreate: 解析成JSON失败!", e);
|
|
|
- }
|
|
|
-
|
|
|
- // TODO 更新版本监听
|
|
|
- ichPublishClient.subscribe(String.format(ICHTopic.APK_UPDATE_PATH, BaseUtils.getClientId()), (msgId, msg) -> {
|
|
|
- String path = new String(msg.getPayload());
|
|
|
- // 发起请求下载APK
|
|
|
- APKUpdateDownload.getInstance().downloadAPK(MainActivity.this, getApplication(), path);
|
|
|
- });
|
|
|
+// };
|
|
|
+// String parseResponse = ICSPClient.isSuccessfulAndParseResponse(response);
|
|
|
+// ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+// ResponseData<Map<String, String>> readValue = objectMapper.readValue(parseResponse, new TypeReference<ResponseData<Map<String, String>>>() {
|
|
|
+// });
|
|
|
+// if (null != readValue && readValue.getCode().equals(ICSPResponseCodeEnum.OK.getCode())) {
|
|
|
+// configMap.putAll(readValue.getData());
|
|
|
+// String qrcode_url = configMap.get(SystemConfigConstant.cabinet_take_object_qrcode_url);
|
|
|
+//
|
|
|
+// try {
|
|
|
+// ICSPClient.download(qrcode_url, new Callback() {
|
|
|
+// @Override
|
|
|
+// public void onFailure(@NotNull Call call, @NotNull IOException e) {
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
|
|
|
+// InputStream is = null;
|
|
|
+// byte[] buf = new byte[2048];
|
|
|
+// int len = 0;
|
|
|
+// FileOutputStream fos = null;
|
|
|
+// final String destFileDir = "res/drawable/";
|
|
|
+// String destFileName = "e_mp_qrcode_8x8.jpg";
|
|
|
+// //储存下载文件的目录
|
|
|
+// File dir = new File(getApplication().getFilesDir().getAbsolutePath() + "/" +destFileDir);
|
|
|
+// if (!dir.exists()) {
|
|
|
+// dir.mkdirs();
|
|
|
+// }
|
|
|
+//// destFileName = apk_url.substring(apk_url.lastIndexOf('/'), apk_url.length() - 1);
|
|
|
+// File file = new File(dir, destFileName);
|
|
|
+//
|
|
|
+// try {
|
|
|
+//
|
|
|
+// is = response.body().byteStream();
|
|
|
+// long total = response.body().contentLength();
|
|
|
+// fos = new FileOutputStream(file);
|
|
|
+// long sum = 0;
|
|
|
+// while ((len = is.read(buf)) != -1) {
|
|
|
+// fos.write(buf, 0, len);
|
|
|
+// sum += len;
|
|
|
+// int progress = (int) (sum * 1.0f / total * 100);
|
|
|
+// //下载中更新进度条
|
|
|
+// listener.onDownloading(progress);
|
|
|
+// }
|
|
|
+// fos.flush();
|
|
|
+// //下载完成
|
|
|
+// listener.onDownloadSuccess(file);
|
|
|
+// } catch (Exception e) {
|
|
|
+// listener.onDownloadFailed(e);
|
|
|
+// }finally {
|
|
|
+// try {
|
|
|
+// if (is != null) {
|
|
|
+// is.close();
|
|
|
+// }
|
|
|
+// if (fos != null) {
|
|
|
+// fos.close();
|
|
|
+// }
|
|
|
+// } catch (IOException e) {
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }, listener);
|
|
|
+// } catch (Exception e) {
|
|
|
+//
|
|
|
+// }
|
|
|
+// Log.i(TAG, "onResponse: 获取系统配置成功! ");
|
|
|
+// } else {
|
|
|
+// Log.w(TAG, "onResponse: code==>" + readValue.getCode() + ", msg==>" + readValue.getMsg());
|
|
|
+// }
|
|
|
+// } catch (RuntimeException e) {
|
|
|
+// Log.e(TAG, "onResponse: 获取系统配置错误! 未知错误! ", e);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// });
|
|
|
+//
|
|
|
+// ICHPublishClient ichPublishClient = ICHPublishClient.getInstance();
|
|
|
+//
|
|
|
+// String clientId = BaseUtils.getClientId();
|
|
|
+// ICHTopic.CLIENT_ID = clientId;
|
|
|
+// // 订阅主题
|
|
|
+//// ICHSubscribeClient ichSubscribeClient = ICHSubscribeClient.getInstance();
|
|
|
+// ichPublishClient.subscribe(ICHTopic.LOCK + clientId, (s, msg) -> {
|
|
|
+// String payload = new String(msg.getPayload());
|
|
|
+// ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+// Message message = objectMapper.readValue(payload, Message.class);
|
|
|
+// Log.i(TAG, "onCreate: message id: " + s + "--------------消息体: " + message);
|
|
|
+//
|
|
|
+// DeviceControl.unlockLocker(message.getSection(), message.getPort(), (var1, var2) -> {
|
|
|
+// Log.i(TAG, "onCreate: 开锁返回码: " + var1 + "--------------返回消息: " + Arrays.asList(var2));
|
|
|
+// MqttMessage mqttMessage;
|
|
|
+// if (var1 != 0) {
|
|
|
+// try {
|
|
|
+// mqttMessage = wrapMessage(message, objectMapper);
|
|
|
+// ichPublishClient.publish(String.format(ICHTopic.CALLBACK_FAILED, BaseUtils.getClientId()), mqttMessage);
|
|
|
+// } catch (JsonProcessingException e) {
|
|
|
+// Log.e(TAG, "onCreate: ---------------------序列化开锁错误消息失败! ", e);
|
|
|
+// } catch (Exception e) {
|
|
|
+// Log.e(TAG, "onCreate: ---------------------未知错误! ", e);
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// // TODO 暂时不做 成功需要不断去请求查询锁是否关闭, 关闭后推送成功消息
|
|
|
+// Log.i(TAG, "onCreate: -------------------------开锁成功");
|
|
|
+//// AtomicBoolean atomicBoolean = new AtomicBoolean(true);
|
|
|
+//// AtomicInteger atomicInteger = new AtomicInteger(5);
|
|
|
+//// do {
|
|
|
+//// try {
|
|
|
+//// TimeUnit.SECONDS.sleep(30);
|
|
|
+//// } catch (InterruptedException e) {
|
|
|
+//// Log.e(TAG, "onCreate: 等待查询锁状态时线程中断! ", e);
|
|
|
+//// }
|
|
|
+//// DeviceControl.queryLocker(message.getSection(), message.getPort(), (var3, var4) -> {
|
|
|
+//// List<String> strings = Arrays.asList(var4);
|
|
|
+//// if (var3 == 0 && strings.size() > 0 && !strings.get(0).equals("locked")) {
|
|
|
+//// atomicBoolean.set(false);
|
|
|
+//// }
|
|
|
+//// atomicInteger.decrementAndGet();
|
|
|
+//// });
|
|
|
+//// if (atomicInteger.get() <= 0) {
|
|
|
+//// atomicBoolean.set(false);
|
|
|
+//// }
|
|
|
+//// } while(atomicBoolean.get());
|
|
|
+// try {
|
|
|
+// mqttMessage = wrapMessage(message, objectMapper);
|
|
|
+//// if (atomicInteger.get() <= 0) {
|
|
|
+//// message.setCause("长时间未关闭柜门!");
|
|
|
+//// mqttMessage.setPayload(objectMapper.writeValueAsBytes(message));
|
|
|
+//// ichPublishClient.publish(String.format(ICHTopic.CALLBACK_FAILED, BaseUtils.getClientId()), mqttMessage);
|
|
|
+//// }
|
|
|
+//
|
|
|
+// ichPublishClient.publish(String.format(ICHTopic.CALLBACK_SUCCESS, BaseUtils.getClientId()), mqttMessage);
|
|
|
+// } catch (JsonProcessingException e) {
|
|
|
+// Log.e(TAG, "onCreate: ---------------------序列化开锁成功消息失败! ", e);
|
|
|
+// } catch (RuntimeException e) {
|
|
|
+// Log.e(TAG, "onCreate: ---------------------未知错误! ", e);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// });
|
|
|
+//
|
|
|
+// });
|
|
|
+//
|
|
|
+// // 注册柜子信息
|
|
|
+//
|
|
|
+// String appVersion = BaseUtils.getAppVersion(getApplicationContext());
|
|
|
+// String androidVersion = BaseUtils.getVersionName();
|
|
|
+// CountDownLatch countDownLatch = new CountDownLatch(10);
|
|
|
+// Cabinet cabinet = DeviceControl.queryCabinetInfo(countDownLatch);
|
|
|
+// try {
|
|
|
+// countDownLatch.await();
|
|
|
+// } catch (InterruptedException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+//
|
|
|
+// cabinet.setClientId(clientId);
|
|
|
+// cabinet.setSoftwareVersion(appVersion);
|
|
|
+// cabinet.setAndroidVersion(androidVersion);
|
|
|
+// cabinet.setSoftwareType("android");
|
|
|
+// cabinet.setImei(BaseUtils.getIMEI(getApplicationContext()));
|
|
|
+// cabinet.setMacIpv4("111");
|
|
|
+// cabinet.setMacIpv6("unknown");
|
|
|
+// cabinet.setNetType("111");
|
|
|
+// cabinet.setPlatType("S905");
|
|
|
+// cabinet.setSim("111");
|
|
|
+// cabinet.setWifiSSid("111");
|
|
|
+//
|
|
|
+// ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+//
|
|
|
+// try {
|
|
|
+// String jsonData = objectMapper.writeValueAsString(cabinet);
|
|
|
+// Log.i(TAG, "onCreate: jsonData===============>" + jsonData);
|
|
|
+//
|
|
|
+// MqttMessage message = new MqttMessage();
|
|
|
+// message.setQos(1);
|
|
|
+// message.setPayload(jsonData.getBytes());
|
|
|
+// ichPublishClient.publish(String.format(ICHTopic.CABINET_INFO_REPORT, clientId), message);
|
|
|
+// } catch (JsonProcessingException e) {
|
|
|
+// Log.e(TAG, "onCreate: 解析成JSON失败!", e);
|
|
|
+// }
|
|
|
+//
|
|
|
+// // TODO 更新版本监听
|
|
|
+// ichPublishClient.subscribe(String.format(ICHTopic.APK_UPDATE_PATH, BaseUtils.getClientId()), (msgId, msg) -> {
|
|
|
+// String path = new String(msg.getPayload());
|
|
|
+// // 发起请求下载APK
|
|
|
+// APKUpdateDownload.getInstance().downloadAPK(MainActivity.this, getApplication(), path);
|
|
|
+// });
|
|
|
}
|
|
|
|
|
|
@Override
|