删除数据库升级方法;插入数据库改到Activity,否则application insert会报错;
| | |
| | | public static final String RTK_CONFIG_JSON = "rtk_config.json"; |
| | | public static final String BIND_DRIVING_TOPIC = "driving"; |
| | | public static final long TEST_STU_ID = 1001; |
| | | |
| | | //I类评判表 |
| | | public static final int SUBJECT_I = 1; |
| | | } |
| | |
| | | private static final int NUMBER_OF_THREADS = 4; |
| | | |
| | | public static final ExecutorService dataBaseWriteExecutor = Executors.newFixedThreadPool(NUMBER_OF_THREADS); |
| | | static Migration migration = new Migration(1,2) { |
| | | @Override |
| | | public void migrate(@NonNull SupportSQLiteDatabase database) { |
| | | database.execSQL("alter table student_table ADD COLUMN begin_time INTEGER NOT NULL DEFAULT 0"); |
| | | } |
| | | }; |
| | | private static final Migration[] ALL_MIGRATIONS = new Migration[]{migration}; |
| | | // static Migration migration = new Migration(1,2) { |
| | | // @Override |
| | | // public void migrate(@NonNull SupportSQLiteDatabase database) { |
| | | // database.execSQL("alter table student_table ADD COLUMN begin_time INTEGER NOT NULL DEFAULT 0"); |
| | | // } |
| | | // }; |
| | | //private static final Migration[] ALL_MIGRATIONS = new Migration[]{migration}; |
| | | |
| | | |
| | | public static WorkRoomDataBase getWorkRoomDataBase(final Context mContext){ |
| | |
| | | if (workRoomDataBase == null){ |
| | | Log.i(TAG, "getWorkRoomDataBase==null "); |
| | | workRoomDataBase = Room.databaseBuilder(mContext.getApplicationContext(),WorkRoomDataBase.class,"work_database") |
| | | .addMigrations(ALL_MIGRATIONS) |
| | | // .addMigrations(ALL_MIGRATIONS) |
| | | .addCallback(new Callback() { |
| | | @Override |
| | | public void onCreate(@NonNull SupportSQLiteDatabase db) { |
| | | super.onCreate(db); |
| | | OneTimeWorkRequest oneTimeWorkRequest = OneTimeWorkRequest.from(SeedDatabaseWorker.class); |
| | | OneTimeWorkRequest oneTimeWorkRequest1 = OneTimeWorkRequest.from(CriteriaForIWorker.class); |
| | | OneTimeWorkRequest oneTimeWorkRequest2 = OneTimeWorkRequest.from(FailedProjWorker.class); |
| | | OneTimeWorkRequest oneTimeWorkRequest3 = OneTimeWorkRequest.from(CriteriaForIIWorker.class); |
| | | OneTimeWorkRequest oneTimeWorkRequest2 = OneTimeWorkRequest.from(FailedProjWorker.class); |
| | | Log.i(TAG, "onCreate: 创建数据库后建立数据表插入数据"); |
| | | WorkManager.getInstance(mContext).enqueue(oneTimeWorkRequest); |
| | | WorkManager.getInstance(mContext).enqueue(oneTimeWorkRequest1); |
| | |
| | | @Query("SELECT COUNT(*) from fail_projects where subject=:subject_id") |
| | | LiveData<Integer> getSubject(int subject_id); |
| | | |
| | | @Query("delete from fail_projects") |
| | | void deleteAll(); |
| | | } |
| | |
| | | */ |
| | | @Entity(tableName = "fail_projects",foreignKeys = {@ForeignKey(entity = CriteriaForI.class, |
| | | parentColumns = "item_id",childColumns = "emp_id",onDelete = CASCADE),@ForeignKey(entity = CriteriaForII.class, |
| | | parentColumns = "item_id",childColumns = "emp_id")},indices = @Index(value = {"emp_id"})) |
| | | parentColumns = "item_id",childColumns = "emp_id",onDelete = CASCADE)},indices = @Index(value = {"emp_id"})) |
| | | public class FailedProj { |
| | | @PrimaryKey(autoGenerate = true) |
| | | private int id; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 删除fail_projects表中所有数据 |
| | | */ |
| | | public void deleteAll() { |
| | | WorkRoomDataBase.dataBaseWriteExecutor.execute(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | failProjDao.deleteAll(); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 获得科目二 I类考场失败项目扣分项 |
| | | * |
| | | * @param stu_id |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 获得科目二 II类考场失败项目扣分项 |
| | | * |
| | | * @param stu_id |
| | | * @return |
| | | */ |
| | |
| | | @NonNull |
| | | @Override |
| | | public Result doWork() { |
| | | MyLog.i(TAG,"预置一条失败项目"); |
| | | // WorkRoomDataBase.getWorkRoomDataBase(getApplicationContext()).getFailProjDao().insert(new FailedProj(1,5)); //加上这一行会报错,不知道为什么,包key constraint fail崩溃 |
| | | return Result.success(); |
| | | } |
| | |
| | | import androidx.lifecycle.ViewModelProviders; |
| | | |
| | | import me.yokeyword.fragmentation.SupportActivity; |
| | | import safeluck.drive.evaluation.DB.Student; |
| | | import safeluck.drive.evaluation.DB.WokViewModel; |
| | | import safeluck.drive.evaluation.fragment.HomeFragment; |
| | | import com.anyun.exam.lib.MyLog; |
| | | |
| | | import java.util.List; |
| | | |
| | | import safeluck.drive.evaluation.util.PermissionManager; |
| | | import safeluck.drive.evaluation.viewmodels.MainViewModel; |
| | | |
| | |
| | | |
| | | setContentView(R.layout.activity_main); |
| | | |
| | | WokViewModel wokViewModel = ViewModelProviders.of(this).get(WokViewModel.class); |
| | | wokViewModel.getStudents().observe(this, new Observer<List<Student>>() { |
| | | @Override |
| | | public void onChanged(List<Student> students) { |
| | | for (Student student: |
| | | students) { |
| | | Log.i(TAG, "onChanged: "+student.toString()); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | |
| | | mPermissionsManager = new PermissionManager(this) { |
| | | @Override |
| | | public void authorized(int requestCode) { |
| | |
| | | package safeluck.drive.evaluation; |
| | | |
| | | import android.app.Application; |
| | | import android.os.Handler; |
| | | import android.util.Log; |
| | | import android.widget.Toast; |
| | | |
| | |
| | | |
| | | import me.yokeyword.fragmentation.Fragmentation; |
| | | import me.yokeyword.fragmentation.helper.ExceptionHandler; |
| | | |
| | | import com.anyun.exam.lib.MyLog; |
| | | import com.anyun.exam.lib.crash.CrashHandler; |
| | | import com.facebook.stetho.Stetho; |
| | |
| | | import org.json.JSONException; |
| | | import org.json.JSONObject; |
| | | |
| | | import java.util.Random; |
| | | |
| | | import safeluck.drive.evaluation.DB.failitems.FailedProj; |
| | | import safeluck.drive.evaluation.DB.failitems.FailedProjRepository; |
| | | import safeluck.drive.evaluation.bean.RTKConfig; |
| | | import safeluck.drive.evaluation.cEventCenter.CEventCenter; |
| | | import safeluck.drive.evaluation.util.FileUtil; |
| | | import safeluck.drive.evaluation.util.SystemUtil; |
| | | |
| | | /** |
| | |
| | | private static final String TAG = "app"; |
| | | private Gson gson; |
| | | RTKConfig rtkConfig; |
| | | FailedProjRepository failedProjRepository; |
| | | Random random = new Random(); |
| | | |
| | | @Override |
| | | public void onCreate() { |
| | | super.onCreate(); |
| | |
| | | crashHandler.init(getApplicationContext()); |
| | | AYSdk.getInstance().init(getApplicationContext()); |
| | | AYSdk.getInstance().registListener(this); |
| | | Log.i(TAG, "onCreate: "); |
| | | MyLog.createIfNotExist(); |
| | | Stetho.initializeWithDefaults(this); |
| | | |
| | | |
| | | //RTK配置信息 |
| | | rtkConfig = new RTKConfig(); |
| | |
| | | rtkConfig.setPort(12125); |
| | | rtkConfig.setProvince(23); |
| | | rtkConfig.setSn("2019101500000001"); |
| | | //数据库操作 |
| | | MyLog.i(TAG, "onCreate111"); |
| | | failedProjRepository = new FailedProjRepository(this); |
| | | } |
| | | |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void callBackMsg(int cmd, String json) { |
| | | public void callBackMsg(final int cmd, String json) { |
| | | MyLog.d(TAG, String.format("收到命令[%d],Json内容为%s",cmd,json)); |
| | | switch (cmd){ |
| | | case Constant.NDK_START: |
| | | Toast.makeText(this, "NDK start", Toast.LENGTH_SHORT).show(); |
| | | break; |
| | | case Constant.RTK_PLATFORM_REGISTER_STATUS: |
| | | failedProjRepository.insert(new FailedProj(Constant.SUBJECT_I, cmd + random.nextInt(30), Constant.TEST_STU_ID)); |
| | | try { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | int reg_code = jsonObject.getInt("register_code"); |
| | | JSONObject jsonObject = new JSONObject(json); |
| | | String rtkLoginPwd = jsonObject.getString("password"); |
| | | int reg_code = jsonObject.getInt("register_code"); |
| | | rtkConfig.setPassword(rtkLoginPwd); |
| | | rtkConfig.setRegistered(reg_code); |
| | | } catch (JSONException e) { |
| | |
| | | } |
| | | break; |
| | | case Constant.RTK_PLATFORM_REGISTER_RESULT: |
| | | |
| | | failedProjRepository.insert(new FailedProj(Constant.SUBJECT_I, cmd + random.nextInt(30), Constant.TEST_STU_ID)); |
| | | |
| | | |
| | | break; |
| | | case Constant.FETCH_RTK_PLATFORM_INFO: |
| | | if (gson == null){ |
| | |
| | | AYSdk.getInstance().sendCmd(Constant.PUSH_RTK_PLATFORM_INFO,gson.toJson(rtkConfig)); |
| | | break; |
| | | case Constant.JUDGE_INFO: |
| | | FailedProjRepository failedProjRepository = new FailedProjRepository(this); |
| | | failedProjRepository.insert(new FailedProj(1,cmd,Constant.TEST_STU_ID)); |
| | | |
| | | |
| | | failedProjRepository.insert(new FailedProj(Constant.SUBJECT_I, cmd, Constant.TEST_STU_ID)); |
| | | |
| | | break; |
| | | case Constant.EXAM_STATUS_REPLY: |
| | | MyLog.d(TAG, "考试开始,需要删除上一个考试学员的数据库失败项目表"); |
| | | failedProjRepository.deleteAll(); |
| | | break; |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.annotation.Nullable; |
| | | import androidx.lifecycle.Observer; |
| | | import androidx.lifecycle.ViewModelProviders; |
| | | |
| | | import com.anyun.exam.lib.AYSdk; |
| | | import com.google.gson.Gson; |
| | |
| | | |
| | | import me.yokeyword.fragmentation.SupportFragment; |
| | | import safeluck.drive.evaluation.Constant; |
| | | import safeluck.drive.evaluation.DB.failitems.FailedProjViewModel; |
| | | import safeluck.drive.evaluation.DB.failitems.FailedProj_select; |
| | | import safeluck.drive.evaluation.R; |
| | | import safeluck.drive.evaluation.adapter.ScoreAdapter; |
| | | import safeluck.drive.evaluation.bean.ScoreBean; |
| | |
| | | private Button btn_start_exam; |
| | | private ScoreAdapter mScoreAdapter; |
| | | |
| | | private int item_id;//扣分分数总和 |
| | | |
| | | private List<ScoreBean> mArrayList = new ArrayList<>(); |
| | | |
| | | public static SupportFragment newInstance() { |
| | |
| | | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { |
| | | View view = inflater.inflate(R.layout.layout_train_fragment,container,false); |
| | | initView(view); |
| | | |
| | | FailedProjViewModel failedProjViewModel = ViewModelProviders.of(this).get(FailedProjViewModel.class); |
| | | failedProjViewModel.getFailedProjectsForI(Constant.TEST_STU_ID).observe(this, new Observer<List<FailedProj_select>>() { |
| | | @Override |
| | | public void onChanged(List<FailedProj_select> failedProj_selects) { |
| | | item_id = 0; |
| | | mArrayList.clear(); |
| | | for (FailedProj_select f : |
| | | failedProj_selects) { |
| | | item_id += f.getScore_deducting(); |
| | | Log.i(TAG, "onChanged: "+f.toString()); |
| | | mArrayList.add(new ScoreBean(f.getScore_deducting(),f.getItem_content(),f.getDeducting_reason())); |
| | | mScoreAdapter.addDatas(mArrayList); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | |
| | | return view; |
| | | } |
| | | |
| | |
| | | btn_start_exam.setOnClickListener(this); |
| | | view.findViewById(R.id.tv_stop).setOnClickListener(this); |
| | | mListView.addHeaderView(LayoutInflater.from(_mActivity).inflate(R.layout.layout_score_item,null)); |
| | | mArrayList.add(new ScoreBean(12,"直角转弯","后轮胎压线")); |
| | | mArrayList.add(new ScoreBean(100,"倒车入库","未系安全带")); |
| | | mArrayList.add(new ScoreBean(10,"坡道起步","一次熄火")); |
| | | mArrayList.add(new ScoreBean(0,"","")); |
| | | mArrayList.add(new ScoreBean(0,"","")); |
| | | |
| | | mScoreAdapter.addDatas(mArrayList); |
| | | |
| | | } |
| | | |
| | |
| | | private Button btn_train; |
| | | private ScoreAdapter mScoreAdapter; |
| | | |
| | | private int item_id; |
| | | private int item_id;//扣分分数总和 |
| | | |
| | | private List<ScoreBean> mArrayList = new ArrayList<>(); |
| | | |
| | |
| | | View view = inflater.inflate(R.layout.layout_train_fragment,container,false); |
| | | initView(view); |
| | | |
| | | WokViewModel wokViewModel = ViewModelProviders.of(this).get(WokViewModel.class); |
| | | wokViewModel.getStudents().observe(this, new Observer<List<Student>>() { |
| | | @Override |
| | | public void onChanged(List<Student> students) { |
| | | for (Student student: |
| | | students) { |
| | | Log.i(TAG, "onChanged: "+student.toString()); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | |
| | | FailedProjViewModel failedProjViewModel =ViewModelProviders.of(this).get(FailedProjViewModel.class); |
| | |
| | | @Override |
| | | public void onChanged(List<FailedProj_select> failedProj_selects) { |
| | | item_id = 0; |
| | | mArrayList.clear(); |
| | | for (FailedProj_select f : |
| | | failedProj_selects) { |
| | | item_id += f.getScore_deducting(); |
| | | Log.i(TAG, "onChanged: "+f.toString()); |
| | | Toast.makeText(getActivity().getApplicationContext(),"得分"+item_id,Toast.LENGTH_SHORT).show(); |
| | | mArrayList.add(new ScoreBean(f.getScore_deducting(),f.getItem_content(),f.getDeducting_reason())); |
| | | mScoreAdapter.addDatas(mArrayList); |
| | | } |
| | | } |
| | | }); |
| | |
| | | mListView.setAdapter(mScoreAdapter); |
| | | |
| | | mListView.addHeaderView(LayoutInflater.from(_mActivity).inflate(R.layout.layout_score_item,null)); |
| | | mArrayList.add(new ScoreBean(12,"直角转弯","后轮胎压线")); |
| | | mArrayList.add(new ScoreBean(100,"倒车入库","未系安全带")); |
| | | mArrayList.add(new ScoreBean(10,"坡道起步","一次熄火")); |
| | | mScoreAdapter.addDatas(mArrayList); |
| | | |
| | | |
| | | } |
| | | |