|
@@ -9,6 +9,7 @@ import com.cherry.sdk.controller.callback.OnScanListen;
|
|
|
import com.cherry.sdk.controller.utils.ScanGunKeyEventHelper;
|
|
|
import com.emato.ich.api.ICSPClient;
|
|
|
import com.emato.ich.api.ICSPResponseCodeEnum;
|
|
|
+import com.emato.ich.api.SystemConfigConstant;
|
|
|
import com.emato.ich.crash.CrashApplication;
|
|
|
import com.emato.ich.crash.UncaughtExceptionHandlerImpl;
|
|
|
import com.emato.ich.device.DeviceControl;
|
|
@@ -20,6 +21,7 @@ import com.emato.ich.message.ICHPublishClient;
|
|
|
import com.emato.ich.message.ICHSubscribeClient;
|
|
|
import com.emato.ich.message.ICHTopic;
|
|
|
import com.emato.ich.update.APKUpdateDownload;
|
|
|
+import com.emato.ich.update.OnDownloadListener;
|
|
|
import com.emato.ich.utils.BaseUtils;
|
|
|
import com.emato.ich.utils.Md5Utils;
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
@@ -54,7 +56,10 @@ import org.eclipse.paho.client.mqttv3.IMqttMessageListener;
|
|
|
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
@@ -104,12 +109,90 @@ public class MainActivity extends AppCompatActivity {
|
|
|
(@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());
|