| | |
| | | package safeluck.drive.evaluation.DB.signalConfigdb; |
| | | |
| | | import android.content.Context; |
| | | import android.util.Log; |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.work.Worker; |
| | | import androidx.work.WorkerParameters; |
| | | |
| | | import com.anyun.exam.lib.AYSdk; |
| | | import com.anyun.exam.lib.MyLog; |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.reflect.TypeToken; |
| | |
| | | import java.io.InputStream; |
| | | import java.io.InputStreamReader; |
| | | import java.lang.reflect.Type; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import safeluck.drive.evaluation.DB.WorkRoomDataBase; |
| | | import safeluck.drive.evaluation.bean.SignalConfigRemote; |
| | | |
| | | public class SignalConfigInitWorker extends Worker { |
| | | private static final String TAG = "SignalConfigInitWorker"; |
| | | private List<SignalConfigRemote> signalConfiglist = new ArrayList<>(); |
| | | private Gson gson; |
| | | public SignalConfigInitWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) { |
| | | super(context, workerParams); |
| | | gson = new Gson(); |
| | | } |
| | | |
| | | @NonNull |
| | | @Override |
| | | public Result doWork() { |
| | | MyLog.i(TAG,"信号配置表初始化"); |
| | | MyLog.i("信号配置表初始化"); |
| | | |
| | | try { |
| | | InputStream inputStream = getApplicationContext().getAssets().open("signal_config_file.json"); |
| | |
| | | } |
| | | return Result.success(); |
| | | } |
| | | |
| | | private void sendSignalConfigsToRemote(List<Integer> indexs) { |
| | | if (signalConfiglist.size() > 0) { |
| | | if (listContainsSameValue(indexs)) { |
| | | Log.i(TAG, "sendSignalConfigsToRemote: 有相同的index,不能发送" + gson.toJson(signalConfiglist)); |
| | | } else { |
| | | AYSdk.getInstance().sendCmd(safeluck.drive.evaluation.Constant.SEND_CONFIG_SIGNAL, gson.toJson(signalConfiglist)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private boolean listContainsSameValue(List<Integer> indexs) { |
| | | for (int i=0;i<indexs.size();i++) { //可以默认是0 0不判断是否有相同的index |
| | | if (indexs.get(i) == 0) { |
| | | continue; |
| | | } |
| | | for (int j =i + 1 ;j<indexs.size();j++) { |
| | | if (indexs.get(i) == indexs.get(j)) { |
| | | return true; |
| | | } |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | } |