From 5f41a352c2bc933b3595a5c7c63f7f67c8ee5280 Mon Sep 17 00:00:00 2001
From: endian11 <Dana_Lee1016@126.com>
Date: 星期三, 25 十一月 2020 15:42:46 +0800
Subject: [PATCH] 修改app类,把发送规则参数改为权限允许之后(7.0);获取地图先要获取sn改到mainActvity里面,蓝牙连接且sn不为空,权限允许
---
app/src/main/java/safeluck/drive/evaluation/MainActivity.java | 71 +++++++++++++++++++++++++++++++++--
1 files changed, 67 insertions(+), 4 deletions(-)
diff --git a/app/src/main/java/safeluck/drive/evaluation/MainActivity.java b/app/src/main/java/safeluck/drive/evaluation/MainActivity.java
index 109b774..5e5bc31 100644
--- a/app/src/main/java/safeluck/drive/evaluation/MainActivity.java
+++ b/app/src/main/java/safeluck/drive/evaluation/MainActivity.java
@@ -9,6 +9,7 @@
import android.os.Build;
import android.os.Bundle;
+import android.os.Environment;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
@@ -24,12 +25,16 @@
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
+import androidx.work.Data;
+import androidx.work.OneTimeWorkRequest;
+import androidx.work.WorkManager;
import me.yokeyword.fragmentation.SupportActivity;
import safeluck.drive.evaluation.DB.appstatusdb.AppStatus;
import safeluck.drive.evaluation.DB.appstatusdb.AppStatusViewModel;
import safeluck.drive.evaluation.DB.rtktb.RTKConfig;
+import safeluck.drive.evaluation.DB.rtktb.RTKConfigUpdateWorker;
import safeluck.drive.evaluation.DB.rtktb.RTKConfigViewModel;
import safeluck.drive.evaluation.DB.signalConfigdb.SignalConfigViewModel;
import safeluck.drive.evaluation.bean.ExamPlatformData;
@@ -38,6 +43,7 @@
import safeluck.drive.evaluation.cEventCenter.ICEventListener;
import safeluck.drive.evaluation.fragment.HomeFragment;
+import com.anyun.exam.lib.AYSdk;
import com.anyun.im_lib.listener.IMSConnectStatusCallback;
import com.google.gson.Gson;
import com.safeluck.aykj.utils.BytesUtils;
@@ -45,6 +51,7 @@
import org.json.JSONException;
import org.json.JSONObject;
+import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
@@ -61,6 +68,7 @@
import safeluck.drive.evaluation.util.PermissionManager;
import safeluck.drive.evaluation.util.SPUtils;
import safeluck.drive.evaluation.util.Utils;
+import safeluck.drive.evaluation.viewmodels.AuthMapViewmodel;
import safeluck.drive.evaluation.viewmodels.ExamPlatformModel;
import safeluck.drive.evaluation.viewmodels.TimeViewModel;
@@ -84,7 +92,7 @@
public View viewtitle;
private ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
-
+ private AuthMapViewmodel authMapViewmodel;
private ICEventListener icEventListener = new ICEventListener() {
@Override
public void onCEvent(String topic, int msgCode, int resultCode, Object obj) {
@@ -111,6 +119,7 @@
try {
JSONObject jsonObject = new JSONObject((String) obj);
int bleStatus = jsonObject.getInt("bluetooth_stauts");
+ String mac = jsonObject.getString("bluetooth_addr");
String des ="钃濈墮鍏抽棴";
switch (bleStatus){
case 0:
@@ -123,7 +132,9 @@
des ="钃濈墮鏈繛鎺�";
break;
case 3:
+ authMapViewmodel.setAuthValue(3);
des ="钃濈墮杩炴帴";
+ SPUtils.put(getApplicationContext(),SPUtils.BLUETOOTH_MAC,mac);
break;
}
tv_ble_status.setText(des);
@@ -138,8 +149,7 @@
}
};
private List<SignalConfigRemote> signalConfiglist = new ArrayList<>();
-
-
+ private int permissionCount = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -194,7 +204,21 @@
}
});
-
+ authMapViewmodel = ViewModelProviders.of(this).get(AuthMapViewmodel.class);
+ authMapViewmodel.getAuthValue().observe(this, new Observer<Integer>() {
+ @Override
+ public void onChanged(Integer integer) {
+ Log.i(TAG,"AuthMapViewmodel auth="+integer);
+ if (integer.intValue() == Constant.BLUETOOTH_CONNECT){
+ MyLog.i(TAG,"Bluetooth connected锛宎uth permission and sn != null");
+ String sn = ExamPlatformData.getInstance().getMcuSN();
+ MyLog.i(TAG,"鏉冮檺鍏佽锛岃幏寰楀埌鐨剆n="+sn);
+ Data data = new Data.Builder().putString(safeluck.drive.evaluation.DB.Constant.RTK_CONFIG_UPDATE_JSON,sn).build();
+ OneTimeWorkRequest rtkConfigUpdateWorker= new OneTimeWorkRequest.Builder(RTKConfigUpdateWorker.class).setInputData(data).build();
+ WorkManager.getInstance(getApplicationContext()).enqueue(rtkConfigUpdateWorker);
+ }
+ }
+ });
// TODO
// 杩涜tcp杩炴帴
final String userId = "100002";
@@ -254,6 +278,16 @@
@Override
public void authorized(int requestCode) {
Log.d(TAG, "requestCode = " + requestCode);
+ permissionCount++;
+ if (permissionCount == PERMISSIONS.length){
+ ExamPlatformData.getInstance().setCanWriteSD(true);
+ //鍙app涓嶉攢姣侊紙閲嶅惎锛夊彧浼氳姹備竴娆★紝浣嗘槸纭繚PERMISSIONS鏈�鍚庝竴涓厓绱犳槸writeSD
+ CThreadPoolExecutor.runInBackground(()->{
+ MyLog.i(TAG,"鏉冮檺鍏佽锛屽紑濮嬪彂閫侀厤缃弬鏁�");
+ sendJudgeArgs();
+ });
+ }
+
}
@Override
@@ -288,7 +322,36 @@
}
+ private void sendJudgeArgs() {
+ FileUtil.createdirs(getApplicationContext());
+ File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+getPackageName());
+ List<String> names = ExamPlatformData.getRulesettingFilesName();
+ for (int i = 0; i < names.size(); i++) {
+ File settFile = new File(dir,names.get(i));
+ if (settFile.exists() ){
+ Log.i(TAG,settFile.getName()+"瀛樺湪涓嶅鍒�");
+ }else{
+ Log.i(TAG,settFile.getName()+"涓嶅瓨鍦紝澶嶅埗...");
+ FileUtil.copyAssertFileToSD(getApplicationContext(),names.get(i));
+ }
+ }
+
+ if (dir.exists()){
+ File[] files = dir.listFiles();
+ for (int i = 0; i < files.length; i++) {
+ Log.i(TAG,files[i].getName());
+ if (names.contains(files[i].getName())){
+
+
+ byte[] buffer = FileUtil.readFile(files[i].getAbsolutePath());
+ AYSdk.getInstance().sendCmd(Constant.ID_judge_args,new String(buffer).trim());
+ }else{
+
+ }
+ }
+ }
+ }
@Override
protected void onDestroy() {
super.onDestroy();
--
Gitblit v1.8.0