diff --git a/app/src/main/java/com/casic/detector/greendao/SmallLabelBeanDao.java b/app/src/main/java/com/casic/detector/greendao/SmallLabelBeanDao.java index 925c804..1d82f51 100644 --- a/app/src/main/java/com/casic/detector/greendao/SmallLabelBeanDao.java +++ b/app/src/main/java/com/casic/detector/greendao/SmallLabelBeanDao.java @@ -12,9 +12,10 @@ import org.greenrobot.greendao.internal.DaoConfig; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** + +/** * DAO for table "SMALL_LABEL_BEAN". -*/ + */ public class SmallLabelBeanDao extends AbstractDao { public static final String TABLENAME = "SMALL_LABEL_BEAN"; @@ -51,14 +52,16 @@ public SmallLabelBeanDao(DaoConfig config) { super(config); } - + public SmallLabelBeanDao(DaoConfig config, DaoSession daoSession) { super(config, daoSession); } - /** Creates the underlying database table. */ + /** + * Creates the underlying database table. + */ public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; db.execSQL("CREATE TABLE " + constraint + "\"SMALL_LABEL_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id "\"MARKER_ID\" TEXT," + // 1: markerId @@ -83,7 +86,9 @@ "\"MEMO3\" TEXT);"); // 20: memo3 } - /** Drops the underlying database table. */ + /** + * Drops the underlying database table. + */ public static void dropTable(Database db, boolean ifExists) { String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"SMALL_LABEL_BEAN\""; db.execSQL(sql); @@ -92,107 +97,107 @@ @Override protected final void bindValues(DatabaseStatement stmt, SmallLabelBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String markerId = entity.getMarkerId(); if (markerId != null) { stmt.bindString(2, markerId); } - + String locationNo = entity.getLocationNo(); if (locationNo != null) { stmt.bindString(3, locationNo); } - + String locationName = entity.getLocationName(); if (locationName != null) { stmt.bindString(4, locationName); } - + String smallMarkerId = entity.getSmallMarkerId(); if (smallMarkerId != null) { stmt.bindString(5, smallMarkerId); } - + String cableName = entity.getCableName(); if (cableName != null) { stmt.bindString(6, cableName); } - + String cableNo = entity.getCableNo(); if (cableNo != null) { stmt.bindString(7, cableNo); } - + String line = entity.getLine(); if (line != null) { stmt.bindString(8, line); } - + String pressLevel = entity.getPressLevel(); if (pressLevel != null) { stmt.bindString(9, pressLevel); } - + String cableType = entity.getCableType(); if (cableType != null) { stmt.bindString(10, cableType); } - + String cableSpec = entity.getCableSpec(); if (cableSpec != null) { stmt.bindString(11, cableSpec); } - + String cableBrand = entity.getCableBrand(); if (cableBrand != null) { stmt.bindString(12, cableBrand); } - + String cableStart = entity.getCableStart(); if (cableStart != null) { stmt.bindString(13, cableStart); } - + String cableEnd = entity.getCableEnd(); if (cableEnd != null) { stmt.bindString(14, cableEnd); } - + String hasJoint = entity.getHasJoint(); if (hasJoint != null) { stmt.bindString(15, hasJoint); } - + String jointCreator = entity.getJointCreator(); if (jointCreator != null) { stmt.bindString(16, jointCreator); } - + String createTime = entity.getCreateTime(); if (createTime != null) { stmt.bindString(17, createTime); } - + String path = entity.getPath(); if (path != null) { stmt.bindString(18, path); } - + String memo1 = entity.getMemo1(); if (memo1 != null) { stmt.bindString(19, memo1); } - + String memo2 = entity.getMemo2(); if (memo2 != null) { stmt.bindString(20, memo2); } - + String memo3 = entity.getMemo3(); if (memo3 != null) { stmt.bindString(21, memo3); @@ -202,107 +207,107 @@ @Override protected final void bindValues(SQLiteStatement stmt, SmallLabelBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String markerId = entity.getMarkerId(); if (markerId != null) { stmt.bindString(2, markerId); } - + String locationNo = entity.getLocationNo(); if (locationNo != null) { stmt.bindString(3, locationNo); } - + String locationName = entity.getLocationName(); if (locationName != null) { stmt.bindString(4, locationName); } - + String smallMarkerId = entity.getSmallMarkerId(); if (smallMarkerId != null) { stmt.bindString(5, smallMarkerId); } - + String cableName = entity.getCableName(); if (cableName != null) { stmt.bindString(6, cableName); } - + String cableNo = entity.getCableNo(); if (cableNo != null) { stmt.bindString(7, cableNo); } - + String line = entity.getLine(); if (line != null) { stmt.bindString(8, line); } - + String pressLevel = entity.getPressLevel(); if (pressLevel != null) { stmt.bindString(9, pressLevel); } - + String cableType = entity.getCableType(); if (cableType != null) { stmt.bindString(10, cableType); } - + String cableSpec = entity.getCableSpec(); if (cableSpec != null) { stmt.bindString(11, cableSpec); } - + String cableBrand = entity.getCableBrand(); if (cableBrand != null) { stmt.bindString(12, cableBrand); } - + String cableStart = entity.getCableStart(); if (cableStart != null) { stmt.bindString(13, cableStart); } - + String cableEnd = entity.getCableEnd(); if (cableEnd != null) { stmt.bindString(14, cableEnd); } - + String hasJoint = entity.getHasJoint(); if (hasJoint != null) { stmt.bindString(15, hasJoint); } - + String jointCreator = entity.getJointCreator(); if (jointCreator != null) { stmt.bindString(16, jointCreator); } - + String createTime = entity.getCreateTime(); if (createTime != null) { stmt.bindString(17, createTime); } - + String path = entity.getPath(); if (path != null) { stmt.bindString(18, path); } - + String memo1 = entity.getMemo1(); if (memo1 != null) { stmt.bindString(19, memo1); } - + String memo2 = entity.getMemo2(); if (memo2 != null) { stmt.bindString(20, memo2); } - + String memo3 = entity.getMemo3(); if (memo3 != null) { stmt.bindString(21, memo3); @@ -312,36 +317,36 @@ @Override public Long readKey(Cursor cursor, int offset) { return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } + } @Override public SmallLabelBean readEntity(Cursor cursor, int offset) { SmallLabelBean entity = new SmallLabelBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // markerId - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // locationNo - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // locationName - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // smallMarkerId - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // cableName - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // cableNo - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // line - cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // pressLevel - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // cableType - cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // cableSpec - cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // cableBrand - cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12), // cableStart - cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13), // cableEnd - cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14), // hasJoint - cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15), // jointCreator - cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16), // createTime - cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17), // path - cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18), // memo1 - cursor.isNull(offset + 19) ? null : cursor.getString(offset + 19), // memo2 - cursor.isNull(offset + 20) ? null : cursor.getString(offset + 20) // memo3 + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // markerId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // locationNo + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // locationName + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // smallMarkerId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // cableName + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // cableNo + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // line + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // pressLevel + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // cableType + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // cableSpec + cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // cableBrand + cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12), // cableStart + cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13), // cableEnd + cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14), // hasJoint + cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15), // jointCreator + cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16), // createTime + cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17), // path + cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18), // memo1 + cursor.isNull(offset + 19) ? null : cursor.getString(offset + 19), // memo2 + cursor.isNull(offset + 20) ? null : cursor.getString(offset + 20) // memo3 ); return entity; } - + @Override public void readEntity(Cursor cursor, SmallLabelBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); @@ -365,17 +370,17 @@ entity.setMemo1(cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18)); entity.setMemo2(cursor.isNull(offset + 19) ? null : cursor.getString(offset + 19)); entity.setMemo3(cursor.isNull(offset + 20) ? null : cursor.getString(offset + 20)); - } - + } + @Override protected final Long updateKeyAfterInsert(SmallLabelBean entity, long rowId) { entity.setId(rowId); return rowId; } - + @Override public Long getKey(SmallLabelBean entity) { - if(entity != null) { + if (entity != null) { return entity.getId(); } else { return null; @@ -391,5 +396,5 @@ protected final boolean isEntityUpdateable() { return true; } - + } diff --git a/app/src/main/java/com/casic/detector/greendao/SmallLabelBeanDao.java b/app/src/main/java/com/casic/detector/greendao/SmallLabelBeanDao.java index 925c804..1d82f51 100644 --- a/app/src/main/java/com/casic/detector/greendao/SmallLabelBeanDao.java +++ b/app/src/main/java/com/casic/detector/greendao/SmallLabelBeanDao.java @@ -12,9 +12,10 @@ import org.greenrobot.greendao.internal.DaoConfig; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** + +/** * DAO for table "SMALL_LABEL_BEAN". -*/ + */ public class SmallLabelBeanDao extends AbstractDao { public static final String TABLENAME = "SMALL_LABEL_BEAN"; @@ -51,14 +52,16 @@ public SmallLabelBeanDao(DaoConfig config) { super(config); } - + public SmallLabelBeanDao(DaoConfig config, DaoSession daoSession) { super(config, daoSession); } - /** Creates the underlying database table. */ + /** + * Creates the underlying database table. + */ public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; db.execSQL("CREATE TABLE " + constraint + "\"SMALL_LABEL_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id "\"MARKER_ID\" TEXT," + // 1: markerId @@ -83,7 +86,9 @@ "\"MEMO3\" TEXT);"); // 20: memo3 } - /** Drops the underlying database table. */ + /** + * Drops the underlying database table. + */ public static void dropTable(Database db, boolean ifExists) { String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"SMALL_LABEL_BEAN\""; db.execSQL(sql); @@ -92,107 +97,107 @@ @Override protected final void bindValues(DatabaseStatement stmt, SmallLabelBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String markerId = entity.getMarkerId(); if (markerId != null) { stmt.bindString(2, markerId); } - + String locationNo = entity.getLocationNo(); if (locationNo != null) { stmt.bindString(3, locationNo); } - + String locationName = entity.getLocationName(); if (locationName != null) { stmt.bindString(4, locationName); } - + String smallMarkerId = entity.getSmallMarkerId(); if (smallMarkerId != null) { stmt.bindString(5, smallMarkerId); } - + String cableName = entity.getCableName(); if (cableName != null) { stmt.bindString(6, cableName); } - + String cableNo = entity.getCableNo(); if (cableNo != null) { stmt.bindString(7, cableNo); } - + String line = entity.getLine(); if (line != null) { stmt.bindString(8, line); } - + String pressLevel = entity.getPressLevel(); if (pressLevel != null) { stmt.bindString(9, pressLevel); } - + String cableType = entity.getCableType(); if (cableType != null) { stmt.bindString(10, cableType); } - + String cableSpec = entity.getCableSpec(); if (cableSpec != null) { stmt.bindString(11, cableSpec); } - + String cableBrand = entity.getCableBrand(); if (cableBrand != null) { stmt.bindString(12, cableBrand); } - + String cableStart = entity.getCableStart(); if (cableStart != null) { stmt.bindString(13, cableStart); } - + String cableEnd = entity.getCableEnd(); if (cableEnd != null) { stmt.bindString(14, cableEnd); } - + String hasJoint = entity.getHasJoint(); if (hasJoint != null) { stmt.bindString(15, hasJoint); } - + String jointCreator = entity.getJointCreator(); if (jointCreator != null) { stmt.bindString(16, jointCreator); } - + String createTime = entity.getCreateTime(); if (createTime != null) { stmt.bindString(17, createTime); } - + String path = entity.getPath(); if (path != null) { stmt.bindString(18, path); } - + String memo1 = entity.getMemo1(); if (memo1 != null) { stmt.bindString(19, memo1); } - + String memo2 = entity.getMemo2(); if (memo2 != null) { stmt.bindString(20, memo2); } - + String memo3 = entity.getMemo3(); if (memo3 != null) { stmt.bindString(21, memo3); @@ -202,107 +207,107 @@ @Override protected final void bindValues(SQLiteStatement stmt, SmallLabelBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String markerId = entity.getMarkerId(); if (markerId != null) { stmt.bindString(2, markerId); } - + String locationNo = entity.getLocationNo(); if (locationNo != null) { stmt.bindString(3, locationNo); } - + String locationName = entity.getLocationName(); if (locationName != null) { stmt.bindString(4, locationName); } - + String smallMarkerId = entity.getSmallMarkerId(); if (smallMarkerId != null) { stmt.bindString(5, smallMarkerId); } - + String cableName = entity.getCableName(); if (cableName != null) { stmt.bindString(6, cableName); } - + String cableNo = entity.getCableNo(); if (cableNo != null) { stmt.bindString(7, cableNo); } - + String line = entity.getLine(); if (line != null) { stmt.bindString(8, line); } - + String pressLevel = entity.getPressLevel(); if (pressLevel != null) { stmt.bindString(9, pressLevel); } - + String cableType = entity.getCableType(); if (cableType != null) { stmt.bindString(10, cableType); } - + String cableSpec = entity.getCableSpec(); if (cableSpec != null) { stmt.bindString(11, cableSpec); } - + String cableBrand = entity.getCableBrand(); if (cableBrand != null) { stmt.bindString(12, cableBrand); } - + String cableStart = entity.getCableStart(); if (cableStart != null) { stmt.bindString(13, cableStart); } - + String cableEnd = entity.getCableEnd(); if (cableEnd != null) { stmt.bindString(14, cableEnd); } - + String hasJoint = entity.getHasJoint(); if (hasJoint != null) { stmt.bindString(15, hasJoint); } - + String jointCreator = entity.getJointCreator(); if (jointCreator != null) { stmt.bindString(16, jointCreator); } - + String createTime = entity.getCreateTime(); if (createTime != null) { stmt.bindString(17, createTime); } - + String path = entity.getPath(); if (path != null) { stmt.bindString(18, path); } - + String memo1 = entity.getMemo1(); if (memo1 != null) { stmt.bindString(19, memo1); } - + String memo2 = entity.getMemo2(); if (memo2 != null) { stmt.bindString(20, memo2); } - + String memo3 = entity.getMemo3(); if (memo3 != null) { stmt.bindString(21, memo3); @@ -312,36 +317,36 @@ @Override public Long readKey(Cursor cursor, int offset) { return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } + } @Override public SmallLabelBean readEntity(Cursor cursor, int offset) { SmallLabelBean entity = new SmallLabelBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // markerId - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // locationNo - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // locationName - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // smallMarkerId - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // cableName - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // cableNo - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // line - cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // pressLevel - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // cableType - cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // cableSpec - cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // cableBrand - cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12), // cableStart - cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13), // cableEnd - cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14), // hasJoint - cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15), // jointCreator - cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16), // createTime - cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17), // path - cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18), // memo1 - cursor.isNull(offset + 19) ? null : cursor.getString(offset + 19), // memo2 - cursor.isNull(offset + 20) ? null : cursor.getString(offset + 20) // memo3 + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // markerId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // locationNo + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // locationName + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // smallMarkerId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // cableName + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // cableNo + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // line + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // pressLevel + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // cableType + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // cableSpec + cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // cableBrand + cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12), // cableStart + cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13), // cableEnd + cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14), // hasJoint + cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15), // jointCreator + cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16), // createTime + cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17), // path + cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18), // memo1 + cursor.isNull(offset + 19) ? null : cursor.getString(offset + 19), // memo2 + cursor.isNull(offset + 20) ? null : cursor.getString(offset + 20) // memo3 ); return entity; } - + @Override public void readEntity(Cursor cursor, SmallLabelBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); @@ -365,17 +370,17 @@ entity.setMemo1(cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18)); entity.setMemo2(cursor.isNull(offset + 19) ? null : cursor.getString(offset + 19)); entity.setMemo3(cursor.isNull(offset + 20) ? null : cursor.getString(offset + 20)); - } - + } + @Override protected final Long updateKeyAfterInsert(SmallLabelBean entity, long rowId) { entity.setId(rowId); return rowId; } - + @Override public Long getKey(SmallLabelBean entity) { - if(entity != null) { + if (entity != null) { return entity.getId(); } else { return null; @@ -391,5 +396,5 @@ protected final boolean isEntityUpdateable() { return true; } - + } diff --git a/app/src/main/java/com/casic/detector/greendao/TaskBeanDao.java b/app/src/main/java/com/casic/detector/greendao/TaskBeanDao.java index 3f9d999..59eee37 100644 --- a/app/src/main/java/com/casic/detector/greendao/TaskBeanDao.java +++ b/app/src/main/java/com/casic/detector/greendao/TaskBeanDao.java @@ -12,9 +12,10 @@ import org.greenrobot.greendao.internal.DaoConfig; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** + +/** * DAO for table "TASK_BEAN". -*/ + */ public class TaskBeanDao extends AbstractDao { public static final String TABLENAME = "TASK_BEAN"; @@ -40,14 +41,16 @@ public TaskBeanDao(DaoConfig config) { super(config); } - + public TaskBeanDao(DaoConfig config, DaoSession daoSession) { super(config, daoSession); } - /** Creates the underlying database table. */ + /** + * Creates the underlying database table. + */ public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; db.execSQL("CREATE TABLE " + constraint + "\"TASK_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id "\"SCANNER\" TEXT," + // 1: scanner @@ -61,7 +64,9 @@ "\"STATE\" TEXT);"); // 9: state } - /** Drops the underlying database table. */ + /** + * Drops the underlying database table. + */ public static void dropTable(Database db, boolean ifExists) { String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_BEAN\""; db.execSQL(sql); @@ -70,52 +75,52 @@ @Override protected final void bindValues(DatabaseStatement stmt, TaskBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String scanner = entity.getScanner(); if (scanner != null) { stmt.bindString(2, scanner); } - + String desc = entity.getDesc(); if (desc != null) { stmt.bindString(3, desc); } - + String taskId = entity.getTaskId(); if (taskId != null) { stmt.bindString(4, taskId); } - + String taskCode = entity.getTaskCode(); if (taskCode != null) { stmt.bindString(5, taskCode); } - + String markerId = entity.getMarkerId(); if (markerId != null) { stmt.bindString(6, markerId); } - + String markerRealId = entity.getMarkerRealId(); if (markerRealId != null) { stmt.bindString(7, markerRealId); } - + String lng = entity.getLng(); if (lng != null) { stmt.bindString(8, lng); } - + String lat = entity.getLat(); if (lat != null) { stmt.bindString(9, lat); } - + String state = entity.getState(); if (state != null) { stmt.bindString(10, state); @@ -125,52 +130,52 @@ @Override protected final void bindValues(SQLiteStatement stmt, TaskBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String scanner = entity.getScanner(); if (scanner != null) { stmt.bindString(2, scanner); } - + String desc = entity.getDesc(); if (desc != null) { stmt.bindString(3, desc); } - + String taskId = entity.getTaskId(); if (taskId != null) { stmt.bindString(4, taskId); } - + String taskCode = entity.getTaskCode(); if (taskCode != null) { stmt.bindString(5, taskCode); } - + String markerId = entity.getMarkerId(); if (markerId != null) { stmt.bindString(6, markerId); } - + String markerRealId = entity.getMarkerRealId(); if (markerRealId != null) { stmt.bindString(7, markerRealId); } - + String lng = entity.getLng(); if (lng != null) { stmt.bindString(8, lng); } - + String lat = entity.getLat(); if (lat != null) { stmt.bindString(9, lat); } - + String state = entity.getState(); if (state != null) { stmt.bindString(10, state); @@ -180,25 +185,25 @@ @Override public Long readKey(Cursor cursor, int offset) { return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } + } @Override public TaskBean readEntity(Cursor cursor, int offset) { TaskBean entity = new TaskBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // scanner - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // desc - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // taskId - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskCode - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // markerId - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // markerRealId - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // lng - cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // lat - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9) // state + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // scanner + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // desc + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // taskId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskCode + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // markerId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // markerRealId + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // lng + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // lat + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9) // state ); return entity; } - + @Override public void readEntity(Cursor cursor, TaskBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); @@ -211,17 +216,17 @@ entity.setLng(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); entity.setLat(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); entity.setState(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - } - + } + @Override protected final Long updateKeyAfterInsert(TaskBean entity, long rowId) { entity.setId(rowId); return rowId; } - + @Override public Long getKey(TaskBean entity) { - if(entity != null) { + if (entity != null) { return entity.getId(); } else { return null; @@ -237,5 +242,5 @@ protected final boolean isEntityUpdateable() { return true; } - + } diff --git a/app/src/main/java/com/casic/detector/greendao/SmallLabelBeanDao.java b/app/src/main/java/com/casic/detector/greendao/SmallLabelBeanDao.java index 925c804..1d82f51 100644 --- a/app/src/main/java/com/casic/detector/greendao/SmallLabelBeanDao.java +++ b/app/src/main/java/com/casic/detector/greendao/SmallLabelBeanDao.java @@ -12,9 +12,10 @@ import org.greenrobot.greendao.internal.DaoConfig; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** + +/** * DAO for table "SMALL_LABEL_BEAN". -*/ + */ public class SmallLabelBeanDao extends AbstractDao { public static final String TABLENAME = "SMALL_LABEL_BEAN"; @@ -51,14 +52,16 @@ public SmallLabelBeanDao(DaoConfig config) { super(config); } - + public SmallLabelBeanDao(DaoConfig config, DaoSession daoSession) { super(config, daoSession); } - /** Creates the underlying database table. */ + /** + * Creates the underlying database table. + */ public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; db.execSQL("CREATE TABLE " + constraint + "\"SMALL_LABEL_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id "\"MARKER_ID\" TEXT," + // 1: markerId @@ -83,7 +86,9 @@ "\"MEMO3\" TEXT);"); // 20: memo3 } - /** Drops the underlying database table. */ + /** + * Drops the underlying database table. + */ public static void dropTable(Database db, boolean ifExists) { String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"SMALL_LABEL_BEAN\""; db.execSQL(sql); @@ -92,107 +97,107 @@ @Override protected final void bindValues(DatabaseStatement stmt, SmallLabelBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String markerId = entity.getMarkerId(); if (markerId != null) { stmt.bindString(2, markerId); } - + String locationNo = entity.getLocationNo(); if (locationNo != null) { stmt.bindString(3, locationNo); } - + String locationName = entity.getLocationName(); if (locationName != null) { stmt.bindString(4, locationName); } - + String smallMarkerId = entity.getSmallMarkerId(); if (smallMarkerId != null) { stmt.bindString(5, smallMarkerId); } - + String cableName = entity.getCableName(); if (cableName != null) { stmt.bindString(6, cableName); } - + String cableNo = entity.getCableNo(); if (cableNo != null) { stmt.bindString(7, cableNo); } - + String line = entity.getLine(); if (line != null) { stmt.bindString(8, line); } - + String pressLevel = entity.getPressLevel(); if (pressLevel != null) { stmt.bindString(9, pressLevel); } - + String cableType = entity.getCableType(); if (cableType != null) { stmt.bindString(10, cableType); } - + String cableSpec = entity.getCableSpec(); if (cableSpec != null) { stmt.bindString(11, cableSpec); } - + String cableBrand = entity.getCableBrand(); if (cableBrand != null) { stmt.bindString(12, cableBrand); } - + String cableStart = entity.getCableStart(); if (cableStart != null) { stmt.bindString(13, cableStart); } - + String cableEnd = entity.getCableEnd(); if (cableEnd != null) { stmt.bindString(14, cableEnd); } - + String hasJoint = entity.getHasJoint(); if (hasJoint != null) { stmt.bindString(15, hasJoint); } - + String jointCreator = entity.getJointCreator(); if (jointCreator != null) { stmt.bindString(16, jointCreator); } - + String createTime = entity.getCreateTime(); if (createTime != null) { stmt.bindString(17, createTime); } - + String path = entity.getPath(); if (path != null) { stmt.bindString(18, path); } - + String memo1 = entity.getMemo1(); if (memo1 != null) { stmt.bindString(19, memo1); } - + String memo2 = entity.getMemo2(); if (memo2 != null) { stmt.bindString(20, memo2); } - + String memo3 = entity.getMemo3(); if (memo3 != null) { stmt.bindString(21, memo3); @@ -202,107 +207,107 @@ @Override protected final void bindValues(SQLiteStatement stmt, SmallLabelBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String markerId = entity.getMarkerId(); if (markerId != null) { stmt.bindString(2, markerId); } - + String locationNo = entity.getLocationNo(); if (locationNo != null) { stmt.bindString(3, locationNo); } - + String locationName = entity.getLocationName(); if (locationName != null) { stmt.bindString(4, locationName); } - + String smallMarkerId = entity.getSmallMarkerId(); if (smallMarkerId != null) { stmt.bindString(5, smallMarkerId); } - + String cableName = entity.getCableName(); if (cableName != null) { stmt.bindString(6, cableName); } - + String cableNo = entity.getCableNo(); if (cableNo != null) { stmt.bindString(7, cableNo); } - + String line = entity.getLine(); if (line != null) { stmt.bindString(8, line); } - + String pressLevel = entity.getPressLevel(); if (pressLevel != null) { stmt.bindString(9, pressLevel); } - + String cableType = entity.getCableType(); if (cableType != null) { stmt.bindString(10, cableType); } - + String cableSpec = entity.getCableSpec(); if (cableSpec != null) { stmt.bindString(11, cableSpec); } - + String cableBrand = entity.getCableBrand(); if (cableBrand != null) { stmt.bindString(12, cableBrand); } - + String cableStart = entity.getCableStart(); if (cableStart != null) { stmt.bindString(13, cableStart); } - + String cableEnd = entity.getCableEnd(); if (cableEnd != null) { stmt.bindString(14, cableEnd); } - + String hasJoint = entity.getHasJoint(); if (hasJoint != null) { stmt.bindString(15, hasJoint); } - + String jointCreator = entity.getJointCreator(); if (jointCreator != null) { stmt.bindString(16, jointCreator); } - + String createTime = entity.getCreateTime(); if (createTime != null) { stmt.bindString(17, createTime); } - + String path = entity.getPath(); if (path != null) { stmt.bindString(18, path); } - + String memo1 = entity.getMemo1(); if (memo1 != null) { stmt.bindString(19, memo1); } - + String memo2 = entity.getMemo2(); if (memo2 != null) { stmt.bindString(20, memo2); } - + String memo3 = entity.getMemo3(); if (memo3 != null) { stmt.bindString(21, memo3); @@ -312,36 +317,36 @@ @Override public Long readKey(Cursor cursor, int offset) { return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } + } @Override public SmallLabelBean readEntity(Cursor cursor, int offset) { SmallLabelBean entity = new SmallLabelBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // markerId - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // locationNo - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // locationName - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // smallMarkerId - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // cableName - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // cableNo - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // line - cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // pressLevel - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // cableType - cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // cableSpec - cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // cableBrand - cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12), // cableStart - cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13), // cableEnd - cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14), // hasJoint - cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15), // jointCreator - cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16), // createTime - cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17), // path - cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18), // memo1 - cursor.isNull(offset + 19) ? null : cursor.getString(offset + 19), // memo2 - cursor.isNull(offset + 20) ? null : cursor.getString(offset + 20) // memo3 + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // markerId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // locationNo + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // locationName + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // smallMarkerId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // cableName + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // cableNo + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // line + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // pressLevel + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // cableType + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // cableSpec + cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // cableBrand + cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12), // cableStart + cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13), // cableEnd + cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14), // hasJoint + cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15), // jointCreator + cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16), // createTime + cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17), // path + cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18), // memo1 + cursor.isNull(offset + 19) ? null : cursor.getString(offset + 19), // memo2 + cursor.isNull(offset + 20) ? null : cursor.getString(offset + 20) // memo3 ); return entity; } - + @Override public void readEntity(Cursor cursor, SmallLabelBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); @@ -365,17 +370,17 @@ entity.setMemo1(cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18)); entity.setMemo2(cursor.isNull(offset + 19) ? null : cursor.getString(offset + 19)); entity.setMemo3(cursor.isNull(offset + 20) ? null : cursor.getString(offset + 20)); - } - + } + @Override protected final Long updateKeyAfterInsert(SmallLabelBean entity, long rowId) { entity.setId(rowId); return rowId; } - + @Override public Long getKey(SmallLabelBean entity) { - if(entity != null) { + if (entity != null) { return entity.getId(); } else { return null; @@ -391,5 +396,5 @@ protected final boolean isEntityUpdateable() { return true; } - + } diff --git a/app/src/main/java/com/casic/detector/greendao/TaskBeanDao.java b/app/src/main/java/com/casic/detector/greendao/TaskBeanDao.java index 3f9d999..59eee37 100644 --- a/app/src/main/java/com/casic/detector/greendao/TaskBeanDao.java +++ b/app/src/main/java/com/casic/detector/greendao/TaskBeanDao.java @@ -12,9 +12,10 @@ import org.greenrobot.greendao.internal.DaoConfig; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** + +/** * DAO for table "TASK_BEAN". -*/ + */ public class TaskBeanDao extends AbstractDao { public static final String TABLENAME = "TASK_BEAN"; @@ -40,14 +41,16 @@ public TaskBeanDao(DaoConfig config) { super(config); } - + public TaskBeanDao(DaoConfig config, DaoSession daoSession) { super(config, daoSession); } - /** Creates the underlying database table. */ + /** + * Creates the underlying database table. + */ public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; db.execSQL("CREATE TABLE " + constraint + "\"TASK_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id "\"SCANNER\" TEXT," + // 1: scanner @@ -61,7 +64,9 @@ "\"STATE\" TEXT);"); // 9: state } - /** Drops the underlying database table. */ + /** + * Drops the underlying database table. + */ public static void dropTable(Database db, boolean ifExists) { String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_BEAN\""; db.execSQL(sql); @@ -70,52 +75,52 @@ @Override protected final void bindValues(DatabaseStatement stmt, TaskBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String scanner = entity.getScanner(); if (scanner != null) { stmt.bindString(2, scanner); } - + String desc = entity.getDesc(); if (desc != null) { stmt.bindString(3, desc); } - + String taskId = entity.getTaskId(); if (taskId != null) { stmt.bindString(4, taskId); } - + String taskCode = entity.getTaskCode(); if (taskCode != null) { stmt.bindString(5, taskCode); } - + String markerId = entity.getMarkerId(); if (markerId != null) { stmt.bindString(6, markerId); } - + String markerRealId = entity.getMarkerRealId(); if (markerRealId != null) { stmt.bindString(7, markerRealId); } - + String lng = entity.getLng(); if (lng != null) { stmt.bindString(8, lng); } - + String lat = entity.getLat(); if (lat != null) { stmt.bindString(9, lat); } - + String state = entity.getState(); if (state != null) { stmt.bindString(10, state); @@ -125,52 +130,52 @@ @Override protected final void bindValues(SQLiteStatement stmt, TaskBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String scanner = entity.getScanner(); if (scanner != null) { stmt.bindString(2, scanner); } - + String desc = entity.getDesc(); if (desc != null) { stmt.bindString(3, desc); } - + String taskId = entity.getTaskId(); if (taskId != null) { stmt.bindString(4, taskId); } - + String taskCode = entity.getTaskCode(); if (taskCode != null) { stmt.bindString(5, taskCode); } - + String markerId = entity.getMarkerId(); if (markerId != null) { stmt.bindString(6, markerId); } - + String markerRealId = entity.getMarkerRealId(); if (markerRealId != null) { stmt.bindString(7, markerRealId); } - + String lng = entity.getLng(); if (lng != null) { stmt.bindString(8, lng); } - + String lat = entity.getLat(); if (lat != null) { stmt.bindString(9, lat); } - + String state = entity.getState(); if (state != null) { stmt.bindString(10, state); @@ -180,25 +185,25 @@ @Override public Long readKey(Cursor cursor, int offset) { return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } + } @Override public TaskBean readEntity(Cursor cursor, int offset) { TaskBean entity = new TaskBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // scanner - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // desc - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // taskId - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskCode - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // markerId - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // markerRealId - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // lng - cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // lat - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9) // state + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // scanner + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // desc + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // taskId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskCode + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // markerId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // markerRealId + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // lng + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // lat + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9) // state ); return entity; } - + @Override public void readEntity(Cursor cursor, TaskBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); @@ -211,17 +216,17 @@ entity.setLng(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); entity.setLat(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); entity.setState(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - } - + } + @Override protected final Long updateKeyAfterInsert(TaskBean entity, long rowId) { entity.setId(rowId); return rowId; } - + @Override public Long getKey(TaskBean entity) { - if(entity != null) { + if (entity != null) { return entity.getId(); } else { return null; @@ -237,5 +242,5 @@ protected final boolean isEntityUpdateable() { return true; } - + } diff --git a/app/src/main/java/com/casic/detector/view/MainActivity.kt b/app/src/main/java/com/casic/detector/view/MainActivity.kt index 1cbecc3..8d772fc 100644 --- a/app/src/main/java/com/casic/detector/view/MainActivity.kt +++ b/app/src/main/java/com/casic/detector/view/MainActivity.kt @@ -9,10 +9,16 @@ import android.graphics.Color import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable +import android.hardware.Sensor +import android.hardware.SensorEvent +import android.hardware.SensorEventListener +import android.hardware.SensorManager import android.media.AudioAttributes import android.media.SoundPool import android.os.Bundle import android.os.CountDownTimer +import android.os.Handler +import android.os.Message import android.util.Log import android.view.KeyEvent import android.view.View @@ -81,6 +87,7 @@ import com.pengxh.kt.lite.extensions.createDownloadFileDir import com.pengxh.kt.lite.extensions.dateToTimestamp import com.pengxh.kt.lite.extensions.dp2px +import com.pengxh.kt.lite.extensions.getSystemService import com.pengxh.kt.lite.extensions.initDialogLayoutParams import com.pengxh.kt.lite.extensions.isNetworkConnected import com.pengxh.kt.lite.extensions.navigatePageTo @@ -92,6 +99,7 @@ import com.pengxh.kt.lite.utils.LoadState import com.pengxh.kt.lite.utils.LoadingDialogHub import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler import com.pengxh.kt.lite.widget.dialog.AlertControlDialog import com.pengxh.kt.lite.widget.dialog.AlertInputDialog import com.pengxh.kt.lite.widget.dialog.AlertMessageDialog @@ -107,7 +115,8 @@ import java.util.TimerTask @SuppressLint("all") -class MainActivity : SerialPortActivity() { +class MainActivity : SerialPortActivity(), SensorEventListener, + Handler.Callback { private val kTag = "MainActivity" private val context = this@MainActivity @@ -118,6 +127,9 @@ private val installDialog by lazy { InstallMarkerDialog(this) } private val searchDialog by lazy { SearchMarkerDialog(this) } private val searchNewDialog by lazy { SearchMarkerNewDialog(this) } + private val sensorMessageCode = 2024022301 + private val rotationMatrix = FloatArray(9)//旋转矩阵缓存 + private val valueArray = FloatArray(3)//方位角数值 private var clickTime: Long = 0 private var labelBeans = ArrayList() private var clusterOverlay: ClusterOverlay? = null @@ -128,17 +140,20 @@ private var signalTask: TimerTask? = null private var searchMarkerTimer: Timer? = null private var taskId: String? = null + private var gravity: FloatArray? = null + private var geomagnetic: FloatArray? = null private lateinit var aMap: AMap private lateinit var task: TaskBean + private lateinit var sensorManager: SensorManager + private lateinit var weakReferenceHandler: WeakReferenceHandler + /***inner class 需要用到*****start*/ private val gpioManager by lazy { GpioManager() } private val locationHub by lazy { LocationHub(this) } private val taskViewModel by lazy { ViewModelProvider(this)[TaskViewModel::class.java] } - private val attr = AudioAttributes.Builder() - .setUsage(AudioAttributes.USAGE_ALARM) - .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) - .build() + private val attr = AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_ALARM) + .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC).build() private val soundPool = SoundPool.Builder().setMaxStreams(16).setAudioAttributes(attr).build() private var soundResourceId = 0 private var slowSoundResourceId = 0 @@ -167,6 +182,9 @@ samplePopupWindow.setPopupMenuItem(LocaleConstant.POPUP_TITLES) samplePopupWindow.setBackgroundDrawable(null) + sensorManager = getSystemService()!! + weakReferenceHandler = WeakReferenceHandler(this) + //task网络请求监听 taskViewModel.markerFileResult.observe(this) { if (it.isSuccess) { @@ -228,12 +246,9 @@ override fun initEvent() { binding.rightImageView.setOnClickListener { if (isFreeTask) { - AlertMessageDialog.Builder() - .setContext(this) - .setTitle("温馨提示") + AlertMessageDialog.Builder().setContext(this).setTitle("温馨提示") .setMessage("正在自由巡检任务中,请完成此次任务之后再使用此功能") - .setPositiveButton("好的") - .setOnDialogButtonClickListener(object : + .setPositiveButton("好的").setOnDialogButtonClickListener(object : AlertMessageDialog.OnDialogButtonClickListener { override fun onConfirmClick() { @@ -273,12 +288,9 @@ * 改为Dialog方式,避免频繁打开/关闭串口 * */ if (isFreeTask) { - AlertMessageDialog.Builder() - .setContext(this) - .setTitle("温馨提示") + AlertMessageDialog.Builder().setContext(this).setTitle("温馨提示") .setMessage("正在自由巡检任务中,请完成此次任务之后再使用此功能") - .setPositiveButton("好的") - .setOnDialogButtonClickListener(object : + .setPositiveButton("好的").setOnDialogButtonClickListener(object : AlertMessageDialog.OnDialogButtonClickListener { override fun onConfirmClick() { @@ -358,11 +370,8 @@ override fun onActionItemClick(position: Int) { task = tasks[position] SaveKeyValues.putValue(LocaleConstant.TASK_ID, task.taskId) - AlertControlDialog.Builder() - .setContext(context) - .setTitle("提示") - .setMessage("请选择操作方式") - .setPositiveButton("执行工单") + AlertControlDialog.Builder().setContext(context).setTitle("提示") + .setMessage("请选择操作方式").setPositiveButton("执行工单") .setNegativeButton("提交工单") .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { @@ -407,31 +416,25 @@ * 如果开启自由巡检就不让探测 * */ if (isFreeTask) { - AlertMessageDialog.Builder() - .setContext(this) - .setTitle("温馨提示") + AlertMessageDialog.Builder().setContext(this).setTitle("温馨提示") .setMessage("正在自由巡检任务中,请完成此次任务之后再使用此功能") - .setPositiveButton("好的") - .setOnDialogButtonClickListener(object : + .setPositiveButton("好的").setOnDialogButtonClickListener(object : AlertMessageDialog.OnDialogButtonClickListener { override fun onConfirmClick() { } }).build().show() } else { - searchDialog.show() +// searchDialog.show() //TODO 新探测界面 -// searchNewDialog.show() + searchNewDialog.show() } } //自由巡检 binding.stopFreeTaskButton.setOnLongClickListener { - AlertMessageDialog.Builder() - .setContext(context) - .setTitle("温馨提示") - .setMessage("是否确定结束此次自由巡检任务?") - .setPositiveButton("是") + AlertMessageDialog.Builder().setContext(context).setTitle("温馨提示") + .setMessage("是否确定结束此次自由巡检任务?").setPositiveButton("是") .setOnDialogButtonClickListener(object : AlertMessageDialog.OnDialogButtonClickListener { override fun onConfirmClick() { @@ -513,9 +516,12 @@ if (labels.isNotEmpty()) { val bean = labels.first() aMap.addMarker( - MarkerOptions() - .position(LatLng(bean.lat.toDouble(), bean.lng.toDouble())) - .icon(BitmapDescriptorFactory.fromResource(R.mipmap.label_blue1)) + MarkerOptions().position( + LatLng( + bean.lat.toDouble(), + bean.lng.toDouble() + ) + ).icon(BitmapDescriptorFactory.fromResource(R.mipmap.label_blue1)) ) } } @@ -888,6 +894,40 @@ } else super.onKeyDown(keyCode, event) } + override fun onAccuracyChanged(sensor: Sensor?, accuracy: Int) { + //精度发生变化时触发 + } + + override fun onSensorChanged(event: SensorEvent?) { + //值发生变化时触发 + val type = event?.sensor?.type + + if (type == Sensor.TYPE_ACCELEROMETER) { + gravity = event.values + } else if (type == Sensor.TYPE_MAGNETIC_FIELD) { + geomagnetic = event.values + } + + if (gravity == null || geomagnetic == null) { + Log.d(kTag, "onSensorChanged => 数据不全,不计算") + return + } + + weakReferenceHandler.sendEmptyMessage(sensorMessageCode) + } + + override fun handleMessage(msg: Message): Boolean { + if (msg.what == sensorMessageCode) { + if (SensorManager.getRotationMatrix(rotationMatrix, null, gravity, geomagnetic)) { + SensorManager.getOrientation(rotationMatrix, valueArray) + + val degree = ((360f + valueArray[0] * 180f / Math.PI) % 360).toInt() + searchNewDialog.updateDegreeValue(degree) + } + } + return true + } + /***以下是地图生命周期管理************************************************************************/ override fun onResume() { @@ -900,11 +940,20 @@ } showLabelsOnMap() } + + //注册加速度传感器监听 + val accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) + sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL) + + //注册磁场传感器监听 + val magnetic = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) + sensorManager.registerListener(this, magnetic, SensorManager.SENSOR_DELAY_NORMAL) } override fun onPause() { super.onPause() binding.mapView.onPause() + sensorManager.unregisterListener(this) } override fun onSaveInstanceState(outState: Bundle) { @@ -1739,7 +1788,7 @@ binding.energyValueView.text = "${energy}dB" if (energy <= 700) {//18° - binding.energyTipsView.text = "标识器信号较弱,可能距离较远" + binding.energyTipsView.text = "信号较弱,可能距离较远" binding.energyTipsView.setTextColor(Color.parseColor("#8D1717")) binding.energyTipsView.setBackgroundResource(R.mipmap.bg_large_text_red) @@ -1754,11 +1803,11 @@ binding.searchResultView.setTextColor(Color.parseColor("#8D1717")) binding.searchResultView.setBackgroundResource(R.mipmap.bg_small_text_red) } else if (energy >= 4100) { - binding.energyTipsView.text = "标识器信号极强,可能在正下方" + binding.energyTipsView.text = "信号极强,接近标识器正上方" binding.energyTipsView.setTextColor(Color.parseColor("#428d00")) binding.energyTipsView.setBackgroundResource(R.mipmap.bg_large_text_green) } else { - binding.energyTipsView.text = "已靠近标识器,请继续移动位置" + binding.energyTipsView.text = "已靠近,请继续移动位置" binding.energyTipsView.setTextColor(Color.parseColor("#8C5700")) binding.energyTipsView.setBackgroundResource(R.mipmap.bg_large_text_yellow) } @@ -1771,6 +1820,15 @@ try { val depthResponse = hex.take(10).hexToString() val depth = depthResponse.drop(2).toInt() + + //根据型号设置不同的进度比例 + val result = DataBaseManager.get.queryLabelById(markerId) + when (result.first().identifierType) { + "EM30" -> binding.distancePgBar.progress = depth / 110 + "EM50" -> binding.distancePgBar.progress = depth / 150 + "EM14" -> binding.distancePgBar.progress = depth / 70 + } + AlertMessageDialog.Builder().setContext(context).setTitle("温馨提示") .setMessage("标识器埋深:${depth}厘米").setPositiveButton("知道了") .setOnDialogButtonClickListener(object : @@ -1812,6 +1870,12 @@ } } + //更新罗盘角度 + fun updateDegreeValue(degree: Int) { + binding.degreeView.text = degree.toString() + binding.radarScanView.setDegreeValue(degree) + } + private fun initTimer() { searchMarkerTimer = Timer() diff --git a/app/src/main/java/com/casic/detector/greendao/SmallLabelBeanDao.java b/app/src/main/java/com/casic/detector/greendao/SmallLabelBeanDao.java index 925c804..1d82f51 100644 --- a/app/src/main/java/com/casic/detector/greendao/SmallLabelBeanDao.java +++ b/app/src/main/java/com/casic/detector/greendao/SmallLabelBeanDao.java @@ -12,9 +12,10 @@ import org.greenrobot.greendao.internal.DaoConfig; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** + +/** * DAO for table "SMALL_LABEL_BEAN". -*/ + */ public class SmallLabelBeanDao extends AbstractDao { public static final String TABLENAME = "SMALL_LABEL_BEAN"; @@ -51,14 +52,16 @@ public SmallLabelBeanDao(DaoConfig config) { super(config); } - + public SmallLabelBeanDao(DaoConfig config, DaoSession daoSession) { super(config, daoSession); } - /** Creates the underlying database table. */ + /** + * Creates the underlying database table. + */ public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; db.execSQL("CREATE TABLE " + constraint + "\"SMALL_LABEL_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id "\"MARKER_ID\" TEXT," + // 1: markerId @@ -83,7 +86,9 @@ "\"MEMO3\" TEXT);"); // 20: memo3 } - /** Drops the underlying database table. */ + /** + * Drops the underlying database table. + */ public static void dropTable(Database db, boolean ifExists) { String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"SMALL_LABEL_BEAN\""; db.execSQL(sql); @@ -92,107 +97,107 @@ @Override protected final void bindValues(DatabaseStatement stmt, SmallLabelBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String markerId = entity.getMarkerId(); if (markerId != null) { stmt.bindString(2, markerId); } - + String locationNo = entity.getLocationNo(); if (locationNo != null) { stmt.bindString(3, locationNo); } - + String locationName = entity.getLocationName(); if (locationName != null) { stmt.bindString(4, locationName); } - + String smallMarkerId = entity.getSmallMarkerId(); if (smallMarkerId != null) { stmt.bindString(5, smallMarkerId); } - + String cableName = entity.getCableName(); if (cableName != null) { stmt.bindString(6, cableName); } - + String cableNo = entity.getCableNo(); if (cableNo != null) { stmt.bindString(7, cableNo); } - + String line = entity.getLine(); if (line != null) { stmt.bindString(8, line); } - + String pressLevel = entity.getPressLevel(); if (pressLevel != null) { stmt.bindString(9, pressLevel); } - + String cableType = entity.getCableType(); if (cableType != null) { stmt.bindString(10, cableType); } - + String cableSpec = entity.getCableSpec(); if (cableSpec != null) { stmt.bindString(11, cableSpec); } - + String cableBrand = entity.getCableBrand(); if (cableBrand != null) { stmt.bindString(12, cableBrand); } - + String cableStart = entity.getCableStart(); if (cableStart != null) { stmt.bindString(13, cableStart); } - + String cableEnd = entity.getCableEnd(); if (cableEnd != null) { stmt.bindString(14, cableEnd); } - + String hasJoint = entity.getHasJoint(); if (hasJoint != null) { stmt.bindString(15, hasJoint); } - + String jointCreator = entity.getJointCreator(); if (jointCreator != null) { stmt.bindString(16, jointCreator); } - + String createTime = entity.getCreateTime(); if (createTime != null) { stmt.bindString(17, createTime); } - + String path = entity.getPath(); if (path != null) { stmt.bindString(18, path); } - + String memo1 = entity.getMemo1(); if (memo1 != null) { stmt.bindString(19, memo1); } - + String memo2 = entity.getMemo2(); if (memo2 != null) { stmt.bindString(20, memo2); } - + String memo3 = entity.getMemo3(); if (memo3 != null) { stmt.bindString(21, memo3); @@ -202,107 +207,107 @@ @Override protected final void bindValues(SQLiteStatement stmt, SmallLabelBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String markerId = entity.getMarkerId(); if (markerId != null) { stmt.bindString(2, markerId); } - + String locationNo = entity.getLocationNo(); if (locationNo != null) { stmt.bindString(3, locationNo); } - + String locationName = entity.getLocationName(); if (locationName != null) { stmt.bindString(4, locationName); } - + String smallMarkerId = entity.getSmallMarkerId(); if (smallMarkerId != null) { stmt.bindString(5, smallMarkerId); } - + String cableName = entity.getCableName(); if (cableName != null) { stmt.bindString(6, cableName); } - + String cableNo = entity.getCableNo(); if (cableNo != null) { stmt.bindString(7, cableNo); } - + String line = entity.getLine(); if (line != null) { stmt.bindString(8, line); } - + String pressLevel = entity.getPressLevel(); if (pressLevel != null) { stmt.bindString(9, pressLevel); } - + String cableType = entity.getCableType(); if (cableType != null) { stmt.bindString(10, cableType); } - + String cableSpec = entity.getCableSpec(); if (cableSpec != null) { stmt.bindString(11, cableSpec); } - + String cableBrand = entity.getCableBrand(); if (cableBrand != null) { stmt.bindString(12, cableBrand); } - + String cableStart = entity.getCableStart(); if (cableStart != null) { stmt.bindString(13, cableStart); } - + String cableEnd = entity.getCableEnd(); if (cableEnd != null) { stmt.bindString(14, cableEnd); } - + String hasJoint = entity.getHasJoint(); if (hasJoint != null) { stmt.bindString(15, hasJoint); } - + String jointCreator = entity.getJointCreator(); if (jointCreator != null) { stmt.bindString(16, jointCreator); } - + String createTime = entity.getCreateTime(); if (createTime != null) { stmt.bindString(17, createTime); } - + String path = entity.getPath(); if (path != null) { stmt.bindString(18, path); } - + String memo1 = entity.getMemo1(); if (memo1 != null) { stmt.bindString(19, memo1); } - + String memo2 = entity.getMemo2(); if (memo2 != null) { stmt.bindString(20, memo2); } - + String memo3 = entity.getMemo3(); if (memo3 != null) { stmt.bindString(21, memo3); @@ -312,36 +317,36 @@ @Override public Long readKey(Cursor cursor, int offset) { return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } + } @Override public SmallLabelBean readEntity(Cursor cursor, int offset) { SmallLabelBean entity = new SmallLabelBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // markerId - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // locationNo - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // locationName - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // smallMarkerId - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // cableName - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // cableNo - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // line - cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // pressLevel - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // cableType - cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // cableSpec - cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // cableBrand - cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12), // cableStart - cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13), // cableEnd - cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14), // hasJoint - cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15), // jointCreator - cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16), // createTime - cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17), // path - cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18), // memo1 - cursor.isNull(offset + 19) ? null : cursor.getString(offset + 19), // memo2 - cursor.isNull(offset + 20) ? null : cursor.getString(offset + 20) // memo3 + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // markerId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // locationNo + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // locationName + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // smallMarkerId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // cableName + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // cableNo + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // line + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // pressLevel + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // cableType + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // cableSpec + cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // cableBrand + cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12), // cableStart + cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13), // cableEnd + cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14), // hasJoint + cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15), // jointCreator + cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16), // createTime + cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17), // path + cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18), // memo1 + cursor.isNull(offset + 19) ? null : cursor.getString(offset + 19), // memo2 + cursor.isNull(offset + 20) ? null : cursor.getString(offset + 20) // memo3 ); return entity; } - + @Override public void readEntity(Cursor cursor, SmallLabelBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); @@ -365,17 +370,17 @@ entity.setMemo1(cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18)); entity.setMemo2(cursor.isNull(offset + 19) ? null : cursor.getString(offset + 19)); entity.setMemo3(cursor.isNull(offset + 20) ? null : cursor.getString(offset + 20)); - } - + } + @Override protected final Long updateKeyAfterInsert(SmallLabelBean entity, long rowId) { entity.setId(rowId); return rowId; } - + @Override public Long getKey(SmallLabelBean entity) { - if(entity != null) { + if (entity != null) { return entity.getId(); } else { return null; @@ -391,5 +396,5 @@ protected final boolean isEntityUpdateable() { return true; } - + } diff --git a/app/src/main/java/com/casic/detector/greendao/TaskBeanDao.java b/app/src/main/java/com/casic/detector/greendao/TaskBeanDao.java index 3f9d999..59eee37 100644 --- a/app/src/main/java/com/casic/detector/greendao/TaskBeanDao.java +++ b/app/src/main/java/com/casic/detector/greendao/TaskBeanDao.java @@ -12,9 +12,10 @@ import org.greenrobot.greendao.internal.DaoConfig; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** + +/** * DAO for table "TASK_BEAN". -*/ + */ public class TaskBeanDao extends AbstractDao { public static final String TABLENAME = "TASK_BEAN"; @@ -40,14 +41,16 @@ public TaskBeanDao(DaoConfig config) { super(config); } - + public TaskBeanDao(DaoConfig config, DaoSession daoSession) { super(config, daoSession); } - /** Creates the underlying database table. */ + /** + * Creates the underlying database table. + */ public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; db.execSQL("CREATE TABLE " + constraint + "\"TASK_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id "\"SCANNER\" TEXT," + // 1: scanner @@ -61,7 +64,9 @@ "\"STATE\" TEXT);"); // 9: state } - /** Drops the underlying database table. */ + /** + * Drops the underlying database table. + */ public static void dropTable(Database db, boolean ifExists) { String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_BEAN\""; db.execSQL(sql); @@ -70,52 +75,52 @@ @Override protected final void bindValues(DatabaseStatement stmt, TaskBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String scanner = entity.getScanner(); if (scanner != null) { stmt.bindString(2, scanner); } - + String desc = entity.getDesc(); if (desc != null) { stmt.bindString(3, desc); } - + String taskId = entity.getTaskId(); if (taskId != null) { stmt.bindString(4, taskId); } - + String taskCode = entity.getTaskCode(); if (taskCode != null) { stmt.bindString(5, taskCode); } - + String markerId = entity.getMarkerId(); if (markerId != null) { stmt.bindString(6, markerId); } - + String markerRealId = entity.getMarkerRealId(); if (markerRealId != null) { stmt.bindString(7, markerRealId); } - + String lng = entity.getLng(); if (lng != null) { stmt.bindString(8, lng); } - + String lat = entity.getLat(); if (lat != null) { stmt.bindString(9, lat); } - + String state = entity.getState(); if (state != null) { stmt.bindString(10, state); @@ -125,52 +130,52 @@ @Override protected final void bindValues(SQLiteStatement stmt, TaskBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String scanner = entity.getScanner(); if (scanner != null) { stmt.bindString(2, scanner); } - + String desc = entity.getDesc(); if (desc != null) { stmt.bindString(3, desc); } - + String taskId = entity.getTaskId(); if (taskId != null) { stmt.bindString(4, taskId); } - + String taskCode = entity.getTaskCode(); if (taskCode != null) { stmt.bindString(5, taskCode); } - + String markerId = entity.getMarkerId(); if (markerId != null) { stmt.bindString(6, markerId); } - + String markerRealId = entity.getMarkerRealId(); if (markerRealId != null) { stmt.bindString(7, markerRealId); } - + String lng = entity.getLng(); if (lng != null) { stmt.bindString(8, lng); } - + String lat = entity.getLat(); if (lat != null) { stmt.bindString(9, lat); } - + String state = entity.getState(); if (state != null) { stmt.bindString(10, state); @@ -180,25 +185,25 @@ @Override public Long readKey(Cursor cursor, int offset) { return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } + } @Override public TaskBean readEntity(Cursor cursor, int offset) { TaskBean entity = new TaskBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // scanner - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // desc - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // taskId - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskCode - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // markerId - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // markerRealId - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // lng - cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // lat - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9) // state + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // scanner + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // desc + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // taskId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskCode + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // markerId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // markerRealId + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // lng + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // lat + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9) // state ); return entity; } - + @Override public void readEntity(Cursor cursor, TaskBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); @@ -211,17 +216,17 @@ entity.setLng(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); entity.setLat(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); entity.setState(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - } - + } + @Override protected final Long updateKeyAfterInsert(TaskBean entity, long rowId) { entity.setId(rowId); return rowId; } - + @Override public Long getKey(TaskBean entity) { - if(entity != null) { + if (entity != null) { return entity.getId(); } else { return null; @@ -237,5 +242,5 @@ protected final boolean isEntityUpdateable() { return true; } - + } diff --git a/app/src/main/java/com/casic/detector/view/MainActivity.kt b/app/src/main/java/com/casic/detector/view/MainActivity.kt index 1cbecc3..8d772fc 100644 --- a/app/src/main/java/com/casic/detector/view/MainActivity.kt +++ b/app/src/main/java/com/casic/detector/view/MainActivity.kt @@ -9,10 +9,16 @@ import android.graphics.Color import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable +import android.hardware.Sensor +import android.hardware.SensorEvent +import android.hardware.SensorEventListener +import android.hardware.SensorManager import android.media.AudioAttributes import android.media.SoundPool import android.os.Bundle import android.os.CountDownTimer +import android.os.Handler +import android.os.Message import android.util.Log import android.view.KeyEvent import android.view.View @@ -81,6 +87,7 @@ import com.pengxh.kt.lite.extensions.createDownloadFileDir import com.pengxh.kt.lite.extensions.dateToTimestamp import com.pengxh.kt.lite.extensions.dp2px +import com.pengxh.kt.lite.extensions.getSystemService import com.pengxh.kt.lite.extensions.initDialogLayoutParams import com.pengxh.kt.lite.extensions.isNetworkConnected import com.pengxh.kt.lite.extensions.navigatePageTo @@ -92,6 +99,7 @@ import com.pengxh.kt.lite.utils.LoadState import com.pengxh.kt.lite.utils.LoadingDialogHub import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler import com.pengxh.kt.lite.widget.dialog.AlertControlDialog import com.pengxh.kt.lite.widget.dialog.AlertInputDialog import com.pengxh.kt.lite.widget.dialog.AlertMessageDialog @@ -107,7 +115,8 @@ import java.util.TimerTask @SuppressLint("all") -class MainActivity : SerialPortActivity() { +class MainActivity : SerialPortActivity(), SensorEventListener, + Handler.Callback { private val kTag = "MainActivity" private val context = this@MainActivity @@ -118,6 +127,9 @@ private val installDialog by lazy { InstallMarkerDialog(this) } private val searchDialog by lazy { SearchMarkerDialog(this) } private val searchNewDialog by lazy { SearchMarkerNewDialog(this) } + private val sensorMessageCode = 2024022301 + private val rotationMatrix = FloatArray(9)//旋转矩阵缓存 + private val valueArray = FloatArray(3)//方位角数值 private var clickTime: Long = 0 private var labelBeans = ArrayList() private var clusterOverlay: ClusterOverlay? = null @@ -128,17 +140,20 @@ private var signalTask: TimerTask? = null private var searchMarkerTimer: Timer? = null private var taskId: String? = null + private var gravity: FloatArray? = null + private var geomagnetic: FloatArray? = null private lateinit var aMap: AMap private lateinit var task: TaskBean + private lateinit var sensorManager: SensorManager + private lateinit var weakReferenceHandler: WeakReferenceHandler + /***inner class 需要用到*****start*/ private val gpioManager by lazy { GpioManager() } private val locationHub by lazy { LocationHub(this) } private val taskViewModel by lazy { ViewModelProvider(this)[TaskViewModel::class.java] } - private val attr = AudioAttributes.Builder() - .setUsage(AudioAttributes.USAGE_ALARM) - .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) - .build() + private val attr = AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_ALARM) + .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC).build() private val soundPool = SoundPool.Builder().setMaxStreams(16).setAudioAttributes(attr).build() private var soundResourceId = 0 private var slowSoundResourceId = 0 @@ -167,6 +182,9 @@ samplePopupWindow.setPopupMenuItem(LocaleConstant.POPUP_TITLES) samplePopupWindow.setBackgroundDrawable(null) + sensorManager = getSystemService()!! + weakReferenceHandler = WeakReferenceHandler(this) + //task网络请求监听 taskViewModel.markerFileResult.observe(this) { if (it.isSuccess) { @@ -228,12 +246,9 @@ override fun initEvent() { binding.rightImageView.setOnClickListener { if (isFreeTask) { - AlertMessageDialog.Builder() - .setContext(this) - .setTitle("温馨提示") + AlertMessageDialog.Builder().setContext(this).setTitle("温馨提示") .setMessage("正在自由巡检任务中,请完成此次任务之后再使用此功能") - .setPositiveButton("好的") - .setOnDialogButtonClickListener(object : + .setPositiveButton("好的").setOnDialogButtonClickListener(object : AlertMessageDialog.OnDialogButtonClickListener { override fun onConfirmClick() { @@ -273,12 +288,9 @@ * 改为Dialog方式,避免频繁打开/关闭串口 * */ if (isFreeTask) { - AlertMessageDialog.Builder() - .setContext(this) - .setTitle("温馨提示") + AlertMessageDialog.Builder().setContext(this).setTitle("温馨提示") .setMessage("正在自由巡检任务中,请完成此次任务之后再使用此功能") - .setPositiveButton("好的") - .setOnDialogButtonClickListener(object : + .setPositiveButton("好的").setOnDialogButtonClickListener(object : AlertMessageDialog.OnDialogButtonClickListener { override fun onConfirmClick() { @@ -358,11 +370,8 @@ override fun onActionItemClick(position: Int) { task = tasks[position] SaveKeyValues.putValue(LocaleConstant.TASK_ID, task.taskId) - AlertControlDialog.Builder() - .setContext(context) - .setTitle("提示") - .setMessage("请选择操作方式") - .setPositiveButton("执行工单") + AlertControlDialog.Builder().setContext(context).setTitle("提示") + .setMessage("请选择操作方式").setPositiveButton("执行工单") .setNegativeButton("提交工单") .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { @@ -407,31 +416,25 @@ * 如果开启自由巡检就不让探测 * */ if (isFreeTask) { - AlertMessageDialog.Builder() - .setContext(this) - .setTitle("温馨提示") + AlertMessageDialog.Builder().setContext(this).setTitle("温馨提示") .setMessage("正在自由巡检任务中,请完成此次任务之后再使用此功能") - .setPositiveButton("好的") - .setOnDialogButtonClickListener(object : + .setPositiveButton("好的").setOnDialogButtonClickListener(object : AlertMessageDialog.OnDialogButtonClickListener { override fun onConfirmClick() { } }).build().show() } else { - searchDialog.show() +// searchDialog.show() //TODO 新探测界面 -// searchNewDialog.show() + searchNewDialog.show() } } //自由巡检 binding.stopFreeTaskButton.setOnLongClickListener { - AlertMessageDialog.Builder() - .setContext(context) - .setTitle("温馨提示") - .setMessage("是否确定结束此次自由巡检任务?") - .setPositiveButton("是") + AlertMessageDialog.Builder().setContext(context).setTitle("温馨提示") + .setMessage("是否确定结束此次自由巡检任务?").setPositiveButton("是") .setOnDialogButtonClickListener(object : AlertMessageDialog.OnDialogButtonClickListener { override fun onConfirmClick() { @@ -513,9 +516,12 @@ if (labels.isNotEmpty()) { val bean = labels.first() aMap.addMarker( - MarkerOptions() - .position(LatLng(bean.lat.toDouble(), bean.lng.toDouble())) - .icon(BitmapDescriptorFactory.fromResource(R.mipmap.label_blue1)) + MarkerOptions().position( + LatLng( + bean.lat.toDouble(), + bean.lng.toDouble() + ) + ).icon(BitmapDescriptorFactory.fromResource(R.mipmap.label_blue1)) ) } } @@ -888,6 +894,40 @@ } else super.onKeyDown(keyCode, event) } + override fun onAccuracyChanged(sensor: Sensor?, accuracy: Int) { + //精度发生变化时触发 + } + + override fun onSensorChanged(event: SensorEvent?) { + //值发生变化时触发 + val type = event?.sensor?.type + + if (type == Sensor.TYPE_ACCELEROMETER) { + gravity = event.values + } else if (type == Sensor.TYPE_MAGNETIC_FIELD) { + geomagnetic = event.values + } + + if (gravity == null || geomagnetic == null) { + Log.d(kTag, "onSensorChanged => 数据不全,不计算") + return + } + + weakReferenceHandler.sendEmptyMessage(sensorMessageCode) + } + + override fun handleMessage(msg: Message): Boolean { + if (msg.what == sensorMessageCode) { + if (SensorManager.getRotationMatrix(rotationMatrix, null, gravity, geomagnetic)) { + SensorManager.getOrientation(rotationMatrix, valueArray) + + val degree = ((360f + valueArray[0] * 180f / Math.PI) % 360).toInt() + searchNewDialog.updateDegreeValue(degree) + } + } + return true + } + /***以下是地图生命周期管理************************************************************************/ override fun onResume() { @@ -900,11 +940,20 @@ } showLabelsOnMap() } + + //注册加速度传感器监听 + val accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) + sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL) + + //注册磁场传感器监听 + val magnetic = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) + sensorManager.registerListener(this, magnetic, SensorManager.SENSOR_DELAY_NORMAL) } override fun onPause() { super.onPause() binding.mapView.onPause() + sensorManager.unregisterListener(this) } override fun onSaveInstanceState(outState: Bundle) { @@ -1739,7 +1788,7 @@ binding.energyValueView.text = "${energy}dB" if (energy <= 700) {//18° - binding.energyTipsView.text = "标识器信号较弱,可能距离较远" + binding.energyTipsView.text = "信号较弱,可能距离较远" binding.energyTipsView.setTextColor(Color.parseColor("#8D1717")) binding.energyTipsView.setBackgroundResource(R.mipmap.bg_large_text_red) @@ -1754,11 +1803,11 @@ binding.searchResultView.setTextColor(Color.parseColor("#8D1717")) binding.searchResultView.setBackgroundResource(R.mipmap.bg_small_text_red) } else if (energy >= 4100) { - binding.energyTipsView.text = "标识器信号极强,可能在正下方" + binding.energyTipsView.text = "信号极强,接近标识器正上方" binding.energyTipsView.setTextColor(Color.parseColor("#428d00")) binding.energyTipsView.setBackgroundResource(R.mipmap.bg_large_text_green) } else { - binding.energyTipsView.text = "已靠近标识器,请继续移动位置" + binding.energyTipsView.text = "已靠近,请继续移动位置" binding.energyTipsView.setTextColor(Color.parseColor("#8C5700")) binding.energyTipsView.setBackgroundResource(R.mipmap.bg_large_text_yellow) } @@ -1771,6 +1820,15 @@ try { val depthResponse = hex.take(10).hexToString() val depth = depthResponse.drop(2).toInt() + + //根据型号设置不同的进度比例 + val result = DataBaseManager.get.queryLabelById(markerId) + when (result.first().identifierType) { + "EM30" -> binding.distancePgBar.progress = depth / 110 + "EM50" -> binding.distancePgBar.progress = depth / 150 + "EM14" -> binding.distancePgBar.progress = depth / 70 + } + AlertMessageDialog.Builder().setContext(context).setTitle("温馨提示") .setMessage("标识器埋深:${depth}厘米").setPositiveButton("知道了") .setOnDialogButtonClickListener(object : @@ -1812,6 +1870,12 @@ } } + //更新罗盘角度 + fun updateDegreeValue(degree: Int) { + binding.degreeView.text = degree.toString() + binding.radarScanView.setDegreeValue(degree) + } + private fun initTimer() { searchMarkerTimer = Timer() diff --git a/app/src/main/java/com/casic/detector/widgets/RadarScanView.kt b/app/src/main/java/com/casic/detector/widgets/RadarScanView.kt index f87089b..4f4f2e3 100644 --- a/app/src/main/java/com/casic/detector/widgets/RadarScanView.kt +++ b/app/src/main/java/com/casic/detector/widgets/RadarScanView.kt @@ -58,13 +58,18 @@ //雷达扫描角度步长 private var degrees = 0f + //方位角 + private var degreeValue = 0 + private lateinit var tickPaint: Paint private lateinit var backPaint: Paint private lateinit var borderPaint: Paint private lateinit var shaderPaint: Paint private lateinit var dataPaint: Paint + private lateinit var trianglePaint: Paint private lateinit var innerPaint: TextPaint private lateinit var innerTextPath: Path + private lateinit var trianglePath: Path //雷达扫描线后面的渐变梯度 private lateinit var sweepGradient: SweepGradient @@ -72,9 +77,18 @@ //背景栅格图 private lateinit var bitmap: Bitmap + //指示针 + private lateinit var needleBitmap: Bitmap + //雷达旋转矩阵 private lateinit var matrix: Matrix + //方位三角形边长 + private val tickLength = 20f.dp2px(context) + + //背景区域范围 + private var bgRect: Rect + init { val type = context.obtainStyledAttributes(attrs, R.styleable.RadarScanView) borderColor = type.getColor(R.styleable.RadarScanView_radar_borderColor, Color.GRAY) @@ -86,10 +100,12 @@ innerRadius = radius - 10.dp2px(context) //需要给外围刻度留位置 - viewSideLength = radius + 10.dp2px(context) + viewSideLength = radius + 30.dp2px(context) //辅助框 rect = Rect(-viewSideLength, -viewSideLength, viewSideLength, viewSideLength) + bgRect = Rect(-radius, -radius, radius, radius) + initPaint() //控制转动 @@ -142,6 +158,17 @@ ) innerTextPath.addArc(innerRectF, -90f, 360f) + trianglePaint = Paint() + trianglePaint.color = Color.RED + trianglePaint.style = Paint.Style.FILL + trianglePaint.isAntiAlias = true + trianglePath = Path() + trianglePath.moveTo(0f, -viewSideLength.toFloat() + tickLength * 1.5f) + trianglePath.lineTo(tickLength * 0.5f, -viewSideLength.toFloat() + tickLength * 0.75f) + trianglePath.lineTo(-tickLength * 0.5f, -viewSideLength.toFloat() + tickLength * 0.75f) + trianglePath.close() + needleBitmap = BitmapFactory.decodeResource(context.resources, R.mipmap.bg_needle) + //扫描线画笔 shaderPaint = Paint() shaderPaint.isAntiAlias = true @@ -200,7 +227,7 @@ canvas.translate(centerX, centerY) //画背景 - canvas.drawBitmap(bitmap, -radius.toFloat(), -radius.toFloat(), backPaint) + canvas.drawBitmap(bitmap, null, bgRect, backPaint) // drawGuides(canvas) @@ -263,6 +290,26 @@ ) } + //画正北方小三角 + canvas.drawPath(trianglePath, trianglePaint) + + //画实时方位角 +// for (angle in 0..degreeValue step 3) { +// //角度需要转为弧度 +// val radians = (angle - 90) * (Math.PI / 180) +// +// canvas.drawBitmap( +// needleBitmap, +// -(needleBitmap.width shr 1).toFloat(), +// -(radians + needleBitmap.height).toFloat(), +// trianglePaint +// ) +// } + //角度需要转为弧度 + val radians = degreeValue * (Math.PI / 180) + +// canvas.drawBitmap(needleBitmap, null, bgRect, trianglePaint) + //画数据点 points.forEach { canvas.drawCircle(it.x, it.y, 10f, dataPaint) @@ -290,6 +337,16 @@ } /** + * 更新罗盘方位角度 + * @param value 方位角 + * */ + fun setDegreeValue(value: Int) { + degreeValue = value + //实时刷新角度值 + invalidate() + } + + /** * 数据点 * @param dataPoints 数据点集合 * */ diff --git a/app/src/main/java/com/casic/detector/greendao/SmallLabelBeanDao.java b/app/src/main/java/com/casic/detector/greendao/SmallLabelBeanDao.java index 925c804..1d82f51 100644 --- a/app/src/main/java/com/casic/detector/greendao/SmallLabelBeanDao.java +++ b/app/src/main/java/com/casic/detector/greendao/SmallLabelBeanDao.java @@ -12,9 +12,10 @@ import org.greenrobot.greendao.internal.DaoConfig; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** + +/** * DAO for table "SMALL_LABEL_BEAN". -*/ + */ public class SmallLabelBeanDao extends AbstractDao { public static final String TABLENAME = "SMALL_LABEL_BEAN"; @@ -51,14 +52,16 @@ public SmallLabelBeanDao(DaoConfig config) { super(config); } - + public SmallLabelBeanDao(DaoConfig config, DaoSession daoSession) { super(config, daoSession); } - /** Creates the underlying database table. */ + /** + * Creates the underlying database table. + */ public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; db.execSQL("CREATE TABLE " + constraint + "\"SMALL_LABEL_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id "\"MARKER_ID\" TEXT," + // 1: markerId @@ -83,7 +86,9 @@ "\"MEMO3\" TEXT);"); // 20: memo3 } - /** Drops the underlying database table. */ + /** + * Drops the underlying database table. + */ public static void dropTable(Database db, boolean ifExists) { String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"SMALL_LABEL_BEAN\""; db.execSQL(sql); @@ -92,107 +97,107 @@ @Override protected final void bindValues(DatabaseStatement stmt, SmallLabelBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String markerId = entity.getMarkerId(); if (markerId != null) { stmt.bindString(2, markerId); } - + String locationNo = entity.getLocationNo(); if (locationNo != null) { stmt.bindString(3, locationNo); } - + String locationName = entity.getLocationName(); if (locationName != null) { stmt.bindString(4, locationName); } - + String smallMarkerId = entity.getSmallMarkerId(); if (smallMarkerId != null) { stmt.bindString(5, smallMarkerId); } - + String cableName = entity.getCableName(); if (cableName != null) { stmt.bindString(6, cableName); } - + String cableNo = entity.getCableNo(); if (cableNo != null) { stmt.bindString(7, cableNo); } - + String line = entity.getLine(); if (line != null) { stmt.bindString(8, line); } - + String pressLevel = entity.getPressLevel(); if (pressLevel != null) { stmt.bindString(9, pressLevel); } - + String cableType = entity.getCableType(); if (cableType != null) { stmt.bindString(10, cableType); } - + String cableSpec = entity.getCableSpec(); if (cableSpec != null) { stmt.bindString(11, cableSpec); } - + String cableBrand = entity.getCableBrand(); if (cableBrand != null) { stmt.bindString(12, cableBrand); } - + String cableStart = entity.getCableStart(); if (cableStart != null) { stmt.bindString(13, cableStart); } - + String cableEnd = entity.getCableEnd(); if (cableEnd != null) { stmt.bindString(14, cableEnd); } - + String hasJoint = entity.getHasJoint(); if (hasJoint != null) { stmt.bindString(15, hasJoint); } - + String jointCreator = entity.getJointCreator(); if (jointCreator != null) { stmt.bindString(16, jointCreator); } - + String createTime = entity.getCreateTime(); if (createTime != null) { stmt.bindString(17, createTime); } - + String path = entity.getPath(); if (path != null) { stmt.bindString(18, path); } - + String memo1 = entity.getMemo1(); if (memo1 != null) { stmt.bindString(19, memo1); } - + String memo2 = entity.getMemo2(); if (memo2 != null) { stmt.bindString(20, memo2); } - + String memo3 = entity.getMemo3(); if (memo3 != null) { stmt.bindString(21, memo3); @@ -202,107 +207,107 @@ @Override protected final void bindValues(SQLiteStatement stmt, SmallLabelBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String markerId = entity.getMarkerId(); if (markerId != null) { stmt.bindString(2, markerId); } - + String locationNo = entity.getLocationNo(); if (locationNo != null) { stmt.bindString(3, locationNo); } - + String locationName = entity.getLocationName(); if (locationName != null) { stmt.bindString(4, locationName); } - + String smallMarkerId = entity.getSmallMarkerId(); if (smallMarkerId != null) { stmt.bindString(5, smallMarkerId); } - + String cableName = entity.getCableName(); if (cableName != null) { stmt.bindString(6, cableName); } - + String cableNo = entity.getCableNo(); if (cableNo != null) { stmt.bindString(7, cableNo); } - + String line = entity.getLine(); if (line != null) { stmt.bindString(8, line); } - + String pressLevel = entity.getPressLevel(); if (pressLevel != null) { stmt.bindString(9, pressLevel); } - + String cableType = entity.getCableType(); if (cableType != null) { stmt.bindString(10, cableType); } - + String cableSpec = entity.getCableSpec(); if (cableSpec != null) { stmt.bindString(11, cableSpec); } - + String cableBrand = entity.getCableBrand(); if (cableBrand != null) { stmt.bindString(12, cableBrand); } - + String cableStart = entity.getCableStart(); if (cableStart != null) { stmt.bindString(13, cableStart); } - + String cableEnd = entity.getCableEnd(); if (cableEnd != null) { stmt.bindString(14, cableEnd); } - + String hasJoint = entity.getHasJoint(); if (hasJoint != null) { stmt.bindString(15, hasJoint); } - + String jointCreator = entity.getJointCreator(); if (jointCreator != null) { stmt.bindString(16, jointCreator); } - + String createTime = entity.getCreateTime(); if (createTime != null) { stmt.bindString(17, createTime); } - + String path = entity.getPath(); if (path != null) { stmt.bindString(18, path); } - + String memo1 = entity.getMemo1(); if (memo1 != null) { stmt.bindString(19, memo1); } - + String memo2 = entity.getMemo2(); if (memo2 != null) { stmt.bindString(20, memo2); } - + String memo3 = entity.getMemo3(); if (memo3 != null) { stmt.bindString(21, memo3); @@ -312,36 +317,36 @@ @Override public Long readKey(Cursor cursor, int offset) { return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } + } @Override public SmallLabelBean readEntity(Cursor cursor, int offset) { SmallLabelBean entity = new SmallLabelBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // markerId - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // locationNo - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // locationName - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // smallMarkerId - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // cableName - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // cableNo - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // line - cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // pressLevel - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // cableType - cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // cableSpec - cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // cableBrand - cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12), // cableStart - cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13), // cableEnd - cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14), // hasJoint - cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15), // jointCreator - cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16), // createTime - cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17), // path - cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18), // memo1 - cursor.isNull(offset + 19) ? null : cursor.getString(offset + 19), // memo2 - cursor.isNull(offset + 20) ? null : cursor.getString(offset + 20) // memo3 + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // markerId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // locationNo + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // locationName + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // smallMarkerId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // cableName + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // cableNo + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // line + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // pressLevel + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // cableType + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // cableSpec + cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // cableBrand + cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12), // cableStart + cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13), // cableEnd + cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14), // hasJoint + cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15), // jointCreator + cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16), // createTime + cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17), // path + cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18), // memo1 + cursor.isNull(offset + 19) ? null : cursor.getString(offset + 19), // memo2 + cursor.isNull(offset + 20) ? null : cursor.getString(offset + 20) // memo3 ); return entity; } - + @Override public void readEntity(Cursor cursor, SmallLabelBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); @@ -365,17 +370,17 @@ entity.setMemo1(cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18)); entity.setMemo2(cursor.isNull(offset + 19) ? null : cursor.getString(offset + 19)); entity.setMemo3(cursor.isNull(offset + 20) ? null : cursor.getString(offset + 20)); - } - + } + @Override protected final Long updateKeyAfterInsert(SmallLabelBean entity, long rowId) { entity.setId(rowId); return rowId; } - + @Override public Long getKey(SmallLabelBean entity) { - if(entity != null) { + if (entity != null) { return entity.getId(); } else { return null; @@ -391,5 +396,5 @@ protected final boolean isEntityUpdateable() { return true; } - + } diff --git a/app/src/main/java/com/casic/detector/greendao/TaskBeanDao.java b/app/src/main/java/com/casic/detector/greendao/TaskBeanDao.java index 3f9d999..59eee37 100644 --- a/app/src/main/java/com/casic/detector/greendao/TaskBeanDao.java +++ b/app/src/main/java/com/casic/detector/greendao/TaskBeanDao.java @@ -12,9 +12,10 @@ import org.greenrobot.greendao.internal.DaoConfig; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** + +/** * DAO for table "TASK_BEAN". -*/ + */ public class TaskBeanDao extends AbstractDao { public static final String TABLENAME = "TASK_BEAN"; @@ -40,14 +41,16 @@ public TaskBeanDao(DaoConfig config) { super(config); } - + public TaskBeanDao(DaoConfig config, DaoSession daoSession) { super(config, daoSession); } - /** Creates the underlying database table. */ + /** + * Creates the underlying database table. + */ public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; db.execSQL("CREATE TABLE " + constraint + "\"TASK_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id "\"SCANNER\" TEXT," + // 1: scanner @@ -61,7 +64,9 @@ "\"STATE\" TEXT);"); // 9: state } - /** Drops the underlying database table. */ + /** + * Drops the underlying database table. + */ public static void dropTable(Database db, boolean ifExists) { String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_BEAN\""; db.execSQL(sql); @@ -70,52 +75,52 @@ @Override protected final void bindValues(DatabaseStatement stmt, TaskBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String scanner = entity.getScanner(); if (scanner != null) { stmt.bindString(2, scanner); } - + String desc = entity.getDesc(); if (desc != null) { stmt.bindString(3, desc); } - + String taskId = entity.getTaskId(); if (taskId != null) { stmt.bindString(4, taskId); } - + String taskCode = entity.getTaskCode(); if (taskCode != null) { stmt.bindString(5, taskCode); } - + String markerId = entity.getMarkerId(); if (markerId != null) { stmt.bindString(6, markerId); } - + String markerRealId = entity.getMarkerRealId(); if (markerRealId != null) { stmt.bindString(7, markerRealId); } - + String lng = entity.getLng(); if (lng != null) { stmt.bindString(8, lng); } - + String lat = entity.getLat(); if (lat != null) { stmt.bindString(9, lat); } - + String state = entity.getState(); if (state != null) { stmt.bindString(10, state); @@ -125,52 +130,52 @@ @Override protected final void bindValues(SQLiteStatement stmt, TaskBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String scanner = entity.getScanner(); if (scanner != null) { stmt.bindString(2, scanner); } - + String desc = entity.getDesc(); if (desc != null) { stmt.bindString(3, desc); } - + String taskId = entity.getTaskId(); if (taskId != null) { stmt.bindString(4, taskId); } - + String taskCode = entity.getTaskCode(); if (taskCode != null) { stmt.bindString(5, taskCode); } - + String markerId = entity.getMarkerId(); if (markerId != null) { stmt.bindString(6, markerId); } - + String markerRealId = entity.getMarkerRealId(); if (markerRealId != null) { stmt.bindString(7, markerRealId); } - + String lng = entity.getLng(); if (lng != null) { stmt.bindString(8, lng); } - + String lat = entity.getLat(); if (lat != null) { stmt.bindString(9, lat); } - + String state = entity.getState(); if (state != null) { stmt.bindString(10, state); @@ -180,25 +185,25 @@ @Override public Long readKey(Cursor cursor, int offset) { return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } + } @Override public TaskBean readEntity(Cursor cursor, int offset) { TaskBean entity = new TaskBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // scanner - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // desc - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // taskId - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskCode - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // markerId - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // markerRealId - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // lng - cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // lat - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9) // state + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // scanner + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // desc + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // taskId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskCode + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // markerId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // markerRealId + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // lng + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // lat + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9) // state ); return entity; } - + @Override public void readEntity(Cursor cursor, TaskBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); @@ -211,17 +216,17 @@ entity.setLng(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); entity.setLat(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); entity.setState(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - } - + } + @Override protected final Long updateKeyAfterInsert(TaskBean entity, long rowId) { entity.setId(rowId); return rowId; } - + @Override public Long getKey(TaskBean entity) { - if(entity != null) { + if (entity != null) { return entity.getId(); } else { return null; @@ -237,5 +242,5 @@ protected final boolean isEntityUpdateable() { return true; } - + } diff --git a/app/src/main/java/com/casic/detector/view/MainActivity.kt b/app/src/main/java/com/casic/detector/view/MainActivity.kt index 1cbecc3..8d772fc 100644 --- a/app/src/main/java/com/casic/detector/view/MainActivity.kt +++ b/app/src/main/java/com/casic/detector/view/MainActivity.kt @@ -9,10 +9,16 @@ import android.graphics.Color import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable +import android.hardware.Sensor +import android.hardware.SensorEvent +import android.hardware.SensorEventListener +import android.hardware.SensorManager import android.media.AudioAttributes import android.media.SoundPool import android.os.Bundle import android.os.CountDownTimer +import android.os.Handler +import android.os.Message import android.util.Log import android.view.KeyEvent import android.view.View @@ -81,6 +87,7 @@ import com.pengxh.kt.lite.extensions.createDownloadFileDir import com.pengxh.kt.lite.extensions.dateToTimestamp import com.pengxh.kt.lite.extensions.dp2px +import com.pengxh.kt.lite.extensions.getSystemService import com.pengxh.kt.lite.extensions.initDialogLayoutParams import com.pengxh.kt.lite.extensions.isNetworkConnected import com.pengxh.kt.lite.extensions.navigatePageTo @@ -92,6 +99,7 @@ import com.pengxh.kt.lite.utils.LoadState import com.pengxh.kt.lite.utils.LoadingDialogHub import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler import com.pengxh.kt.lite.widget.dialog.AlertControlDialog import com.pengxh.kt.lite.widget.dialog.AlertInputDialog import com.pengxh.kt.lite.widget.dialog.AlertMessageDialog @@ -107,7 +115,8 @@ import java.util.TimerTask @SuppressLint("all") -class MainActivity : SerialPortActivity() { +class MainActivity : SerialPortActivity(), SensorEventListener, + Handler.Callback { private val kTag = "MainActivity" private val context = this@MainActivity @@ -118,6 +127,9 @@ private val installDialog by lazy { InstallMarkerDialog(this) } private val searchDialog by lazy { SearchMarkerDialog(this) } private val searchNewDialog by lazy { SearchMarkerNewDialog(this) } + private val sensorMessageCode = 2024022301 + private val rotationMatrix = FloatArray(9)//旋转矩阵缓存 + private val valueArray = FloatArray(3)//方位角数值 private var clickTime: Long = 0 private var labelBeans = ArrayList() private var clusterOverlay: ClusterOverlay? = null @@ -128,17 +140,20 @@ private var signalTask: TimerTask? = null private var searchMarkerTimer: Timer? = null private var taskId: String? = null + private var gravity: FloatArray? = null + private var geomagnetic: FloatArray? = null private lateinit var aMap: AMap private lateinit var task: TaskBean + private lateinit var sensorManager: SensorManager + private lateinit var weakReferenceHandler: WeakReferenceHandler + /***inner class 需要用到*****start*/ private val gpioManager by lazy { GpioManager() } private val locationHub by lazy { LocationHub(this) } private val taskViewModel by lazy { ViewModelProvider(this)[TaskViewModel::class.java] } - private val attr = AudioAttributes.Builder() - .setUsage(AudioAttributes.USAGE_ALARM) - .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) - .build() + private val attr = AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_ALARM) + .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC).build() private val soundPool = SoundPool.Builder().setMaxStreams(16).setAudioAttributes(attr).build() private var soundResourceId = 0 private var slowSoundResourceId = 0 @@ -167,6 +182,9 @@ samplePopupWindow.setPopupMenuItem(LocaleConstant.POPUP_TITLES) samplePopupWindow.setBackgroundDrawable(null) + sensorManager = getSystemService()!! + weakReferenceHandler = WeakReferenceHandler(this) + //task网络请求监听 taskViewModel.markerFileResult.observe(this) { if (it.isSuccess) { @@ -228,12 +246,9 @@ override fun initEvent() { binding.rightImageView.setOnClickListener { if (isFreeTask) { - AlertMessageDialog.Builder() - .setContext(this) - .setTitle("温馨提示") + AlertMessageDialog.Builder().setContext(this).setTitle("温馨提示") .setMessage("正在自由巡检任务中,请完成此次任务之后再使用此功能") - .setPositiveButton("好的") - .setOnDialogButtonClickListener(object : + .setPositiveButton("好的").setOnDialogButtonClickListener(object : AlertMessageDialog.OnDialogButtonClickListener { override fun onConfirmClick() { @@ -273,12 +288,9 @@ * 改为Dialog方式,避免频繁打开/关闭串口 * */ if (isFreeTask) { - AlertMessageDialog.Builder() - .setContext(this) - .setTitle("温馨提示") + AlertMessageDialog.Builder().setContext(this).setTitle("温馨提示") .setMessage("正在自由巡检任务中,请完成此次任务之后再使用此功能") - .setPositiveButton("好的") - .setOnDialogButtonClickListener(object : + .setPositiveButton("好的").setOnDialogButtonClickListener(object : AlertMessageDialog.OnDialogButtonClickListener { override fun onConfirmClick() { @@ -358,11 +370,8 @@ override fun onActionItemClick(position: Int) { task = tasks[position] SaveKeyValues.putValue(LocaleConstant.TASK_ID, task.taskId) - AlertControlDialog.Builder() - .setContext(context) - .setTitle("提示") - .setMessage("请选择操作方式") - .setPositiveButton("执行工单") + AlertControlDialog.Builder().setContext(context).setTitle("提示") + .setMessage("请选择操作方式").setPositiveButton("执行工单") .setNegativeButton("提交工单") .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { @@ -407,31 +416,25 @@ * 如果开启自由巡检就不让探测 * */ if (isFreeTask) { - AlertMessageDialog.Builder() - .setContext(this) - .setTitle("温馨提示") + AlertMessageDialog.Builder().setContext(this).setTitle("温馨提示") .setMessage("正在自由巡检任务中,请完成此次任务之后再使用此功能") - .setPositiveButton("好的") - .setOnDialogButtonClickListener(object : + .setPositiveButton("好的").setOnDialogButtonClickListener(object : AlertMessageDialog.OnDialogButtonClickListener { override fun onConfirmClick() { } }).build().show() } else { - searchDialog.show() +// searchDialog.show() //TODO 新探测界面 -// searchNewDialog.show() + searchNewDialog.show() } } //自由巡检 binding.stopFreeTaskButton.setOnLongClickListener { - AlertMessageDialog.Builder() - .setContext(context) - .setTitle("温馨提示") - .setMessage("是否确定结束此次自由巡检任务?") - .setPositiveButton("是") + AlertMessageDialog.Builder().setContext(context).setTitle("温馨提示") + .setMessage("是否确定结束此次自由巡检任务?").setPositiveButton("是") .setOnDialogButtonClickListener(object : AlertMessageDialog.OnDialogButtonClickListener { override fun onConfirmClick() { @@ -513,9 +516,12 @@ if (labels.isNotEmpty()) { val bean = labels.first() aMap.addMarker( - MarkerOptions() - .position(LatLng(bean.lat.toDouble(), bean.lng.toDouble())) - .icon(BitmapDescriptorFactory.fromResource(R.mipmap.label_blue1)) + MarkerOptions().position( + LatLng( + bean.lat.toDouble(), + bean.lng.toDouble() + ) + ).icon(BitmapDescriptorFactory.fromResource(R.mipmap.label_blue1)) ) } } @@ -888,6 +894,40 @@ } else super.onKeyDown(keyCode, event) } + override fun onAccuracyChanged(sensor: Sensor?, accuracy: Int) { + //精度发生变化时触发 + } + + override fun onSensorChanged(event: SensorEvent?) { + //值发生变化时触发 + val type = event?.sensor?.type + + if (type == Sensor.TYPE_ACCELEROMETER) { + gravity = event.values + } else if (type == Sensor.TYPE_MAGNETIC_FIELD) { + geomagnetic = event.values + } + + if (gravity == null || geomagnetic == null) { + Log.d(kTag, "onSensorChanged => 数据不全,不计算") + return + } + + weakReferenceHandler.sendEmptyMessage(sensorMessageCode) + } + + override fun handleMessage(msg: Message): Boolean { + if (msg.what == sensorMessageCode) { + if (SensorManager.getRotationMatrix(rotationMatrix, null, gravity, geomagnetic)) { + SensorManager.getOrientation(rotationMatrix, valueArray) + + val degree = ((360f + valueArray[0] * 180f / Math.PI) % 360).toInt() + searchNewDialog.updateDegreeValue(degree) + } + } + return true + } + /***以下是地图生命周期管理************************************************************************/ override fun onResume() { @@ -900,11 +940,20 @@ } showLabelsOnMap() } + + //注册加速度传感器监听 + val accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) + sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL) + + //注册磁场传感器监听 + val magnetic = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) + sensorManager.registerListener(this, magnetic, SensorManager.SENSOR_DELAY_NORMAL) } override fun onPause() { super.onPause() binding.mapView.onPause() + sensorManager.unregisterListener(this) } override fun onSaveInstanceState(outState: Bundle) { @@ -1739,7 +1788,7 @@ binding.energyValueView.text = "${energy}dB" if (energy <= 700) {//18° - binding.energyTipsView.text = "标识器信号较弱,可能距离较远" + binding.energyTipsView.text = "信号较弱,可能距离较远" binding.energyTipsView.setTextColor(Color.parseColor("#8D1717")) binding.energyTipsView.setBackgroundResource(R.mipmap.bg_large_text_red) @@ -1754,11 +1803,11 @@ binding.searchResultView.setTextColor(Color.parseColor("#8D1717")) binding.searchResultView.setBackgroundResource(R.mipmap.bg_small_text_red) } else if (energy >= 4100) { - binding.energyTipsView.text = "标识器信号极强,可能在正下方" + binding.energyTipsView.text = "信号极强,接近标识器正上方" binding.energyTipsView.setTextColor(Color.parseColor("#428d00")) binding.energyTipsView.setBackgroundResource(R.mipmap.bg_large_text_green) } else { - binding.energyTipsView.text = "已靠近标识器,请继续移动位置" + binding.energyTipsView.text = "已靠近,请继续移动位置" binding.energyTipsView.setTextColor(Color.parseColor("#8C5700")) binding.energyTipsView.setBackgroundResource(R.mipmap.bg_large_text_yellow) } @@ -1771,6 +1820,15 @@ try { val depthResponse = hex.take(10).hexToString() val depth = depthResponse.drop(2).toInt() + + //根据型号设置不同的进度比例 + val result = DataBaseManager.get.queryLabelById(markerId) + when (result.first().identifierType) { + "EM30" -> binding.distancePgBar.progress = depth / 110 + "EM50" -> binding.distancePgBar.progress = depth / 150 + "EM14" -> binding.distancePgBar.progress = depth / 70 + } + AlertMessageDialog.Builder().setContext(context).setTitle("温馨提示") .setMessage("标识器埋深:${depth}厘米").setPositiveButton("知道了") .setOnDialogButtonClickListener(object : @@ -1812,6 +1870,12 @@ } } + //更新罗盘角度 + fun updateDegreeValue(degree: Int) { + binding.degreeView.text = degree.toString() + binding.radarScanView.setDegreeValue(degree) + } + private fun initTimer() { searchMarkerTimer = Timer() diff --git a/app/src/main/java/com/casic/detector/widgets/RadarScanView.kt b/app/src/main/java/com/casic/detector/widgets/RadarScanView.kt index f87089b..4f4f2e3 100644 --- a/app/src/main/java/com/casic/detector/widgets/RadarScanView.kt +++ b/app/src/main/java/com/casic/detector/widgets/RadarScanView.kt @@ -58,13 +58,18 @@ //雷达扫描角度步长 private var degrees = 0f + //方位角 + private var degreeValue = 0 + private lateinit var tickPaint: Paint private lateinit var backPaint: Paint private lateinit var borderPaint: Paint private lateinit var shaderPaint: Paint private lateinit var dataPaint: Paint + private lateinit var trianglePaint: Paint private lateinit var innerPaint: TextPaint private lateinit var innerTextPath: Path + private lateinit var trianglePath: Path //雷达扫描线后面的渐变梯度 private lateinit var sweepGradient: SweepGradient @@ -72,9 +77,18 @@ //背景栅格图 private lateinit var bitmap: Bitmap + //指示针 + private lateinit var needleBitmap: Bitmap + //雷达旋转矩阵 private lateinit var matrix: Matrix + //方位三角形边长 + private val tickLength = 20f.dp2px(context) + + //背景区域范围 + private var bgRect: Rect + init { val type = context.obtainStyledAttributes(attrs, R.styleable.RadarScanView) borderColor = type.getColor(R.styleable.RadarScanView_radar_borderColor, Color.GRAY) @@ -86,10 +100,12 @@ innerRadius = radius - 10.dp2px(context) //需要给外围刻度留位置 - viewSideLength = radius + 10.dp2px(context) + viewSideLength = radius + 30.dp2px(context) //辅助框 rect = Rect(-viewSideLength, -viewSideLength, viewSideLength, viewSideLength) + bgRect = Rect(-radius, -radius, radius, radius) + initPaint() //控制转动 @@ -142,6 +158,17 @@ ) innerTextPath.addArc(innerRectF, -90f, 360f) + trianglePaint = Paint() + trianglePaint.color = Color.RED + trianglePaint.style = Paint.Style.FILL + trianglePaint.isAntiAlias = true + trianglePath = Path() + trianglePath.moveTo(0f, -viewSideLength.toFloat() + tickLength * 1.5f) + trianglePath.lineTo(tickLength * 0.5f, -viewSideLength.toFloat() + tickLength * 0.75f) + trianglePath.lineTo(-tickLength * 0.5f, -viewSideLength.toFloat() + tickLength * 0.75f) + trianglePath.close() + needleBitmap = BitmapFactory.decodeResource(context.resources, R.mipmap.bg_needle) + //扫描线画笔 shaderPaint = Paint() shaderPaint.isAntiAlias = true @@ -200,7 +227,7 @@ canvas.translate(centerX, centerY) //画背景 - canvas.drawBitmap(bitmap, -radius.toFloat(), -radius.toFloat(), backPaint) + canvas.drawBitmap(bitmap, null, bgRect, backPaint) // drawGuides(canvas) @@ -263,6 +290,26 @@ ) } + //画正北方小三角 + canvas.drawPath(trianglePath, trianglePaint) + + //画实时方位角 +// for (angle in 0..degreeValue step 3) { +// //角度需要转为弧度 +// val radians = (angle - 90) * (Math.PI / 180) +// +// canvas.drawBitmap( +// needleBitmap, +// -(needleBitmap.width shr 1).toFloat(), +// -(radians + needleBitmap.height).toFloat(), +// trianglePaint +// ) +// } + //角度需要转为弧度 + val radians = degreeValue * (Math.PI / 180) + +// canvas.drawBitmap(needleBitmap, null, bgRect, trianglePaint) + //画数据点 points.forEach { canvas.drawCircle(it.x, it.y, 10f, dataPaint) @@ -290,6 +337,16 @@ } /** + * 更新罗盘方位角度 + * @param value 方位角 + * */ + fun setDegreeValue(value: Int) { + degreeValue = value + //实时刷新角度值 + invalidate() + } + + /** * 数据点 * @param dataPoints 数据点集合 * */ diff --git a/app/src/main/res/layout/dialog_search_marker_new.xml b/app/src/main/res/layout/dialog_search_marker_new.xml index c341a72..a3ff080 100644 --- a/app/src/main/res/layout/dialog_search_marker_new.xml +++ b/app/src/main/res/layout/dialog_search_marker_new.xml @@ -8,6 +8,13 @@ android:gravity="center_horizontal" android:orientation="vertical"> + + diff --git a/app/src/main/java/com/casic/detector/greendao/SmallLabelBeanDao.java b/app/src/main/java/com/casic/detector/greendao/SmallLabelBeanDao.java index 925c804..1d82f51 100644 --- a/app/src/main/java/com/casic/detector/greendao/SmallLabelBeanDao.java +++ b/app/src/main/java/com/casic/detector/greendao/SmallLabelBeanDao.java @@ -12,9 +12,10 @@ import org.greenrobot.greendao.internal.DaoConfig; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** + +/** * DAO for table "SMALL_LABEL_BEAN". -*/ + */ public class SmallLabelBeanDao extends AbstractDao { public static final String TABLENAME = "SMALL_LABEL_BEAN"; @@ -51,14 +52,16 @@ public SmallLabelBeanDao(DaoConfig config) { super(config); } - + public SmallLabelBeanDao(DaoConfig config, DaoSession daoSession) { super(config, daoSession); } - /** Creates the underlying database table. */ + /** + * Creates the underlying database table. + */ public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; db.execSQL("CREATE TABLE " + constraint + "\"SMALL_LABEL_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id "\"MARKER_ID\" TEXT," + // 1: markerId @@ -83,7 +86,9 @@ "\"MEMO3\" TEXT);"); // 20: memo3 } - /** Drops the underlying database table. */ + /** + * Drops the underlying database table. + */ public static void dropTable(Database db, boolean ifExists) { String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"SMALL_LABEL_BEAN\""; db.execSQL(sql); @@ -92,107 +97,107 @@ @Override protected final void bindValues(DatabaseStatement stmt, SmallLabelBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String markerId = entity.getMarkerId(); if (markerId != null) { stmt.bindString(2, markerId); } - + String locationNo = entity.getLocationNo(); if (locationNo != null) { stmt.bindString(3, locationNo); } - + String locationName = entity.getLocationName(); if (locationName != null) { stmt.bindString(4, locationName); } - + String smallMarkerId = entity.getSmallMarkerId(); if (smallMarkerId != null) { stmt.bindString(5, smallMarkerId); } - + String cableName = entity.getCableName(); if (cableName != null) { stmt.bindString(6, cableName); } - + String cableNo = entity.getCableNo(); if (cableNo != null) { stmt.bindString(7, cableNo); } - + String line = entity.getLine(); if (line != null) { stmt.bindString(8, line); } - + String pressLevel = entity.getPressLevel(); if (pressLevel != null) { stmt.bindString(9, pressLevel); } - + String cableType = entity.getCableType(); if (cableType != null) { stmt.bindString(10, cableType); } - + String cableSpec = entity.getCableSpec(); if (cableSpec != null) { stmt.bindString(11, cableSpec); } - + String cableBrand = entity.getCableBrand(); if (cableBrand != null) { stmt.bindString(12, cableBrand); } - + String cableStart = entity.getCableStart(); if (cableStart != null) { stmt.bindString(13, cableStart); } - + String cableEnd = entity.getCableEnd(); if (cableEnd != null) { stmt.bindString(14, cableEnd); } - + String hasJoint = entity.getHasJoint(); if (hasJoint != null) { stmt.bindString(15, hasJoint); } - + String jointCreator = entity.getJointCreator(); if (jointCreator != null) { stmt.bindString(16, jointCreator); } - + String createTime = entity.getCreateTime(); if (createTime != null) { stmt.bindString(17, createTime); } - + String path = entity.getPath(); if (path != null) { stmt.bindString(18, path); } - + String memo1 = entity.getMemo1(); if (memo1 != null) { stmt.bindString(19, memo1); } - + String memo2 = entity.getMemo2(); if (memo2 != null) { stmt.bindString(20, memo2); } - + String memo3 = entity.getMemo3(); if (memo3 != null) { stmt.bindString(21, memo3); @@ -202,107 +207,107 @@ @Override protected final void bindValues(SQLiteStatement stmt, SmallLabelBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String markerId = entity.getMarkerId(); if (markerId != null) { stmt.bindString(2, markerId); } - + String locationNo = entity.getLocationNo(); if (locationNo != null) { stmt.bindString(3, locationNo); } - + String locationName = entity.getLocationName(); if (locationName != null) { stmt.bindString(4, locationName); } - + String smallMarkerId = entity.getSmallMarkerId(); if (smallMarkerId != null) { stmt.bindString(5, smallMarkerId); } - + String cableName = entity.getCableName(); if (cableName != null) { stmt.bindString(6, cableName); } - + String cableNo = entity.getCableNo(); if (cableNo != null) { stmt.bindString(7, cableNo); } - + String line = entity.getLine(); if (line != null) { stmt.bindString(8, line); } - + String pressLevel = entity.getPressLevel(); if (pressLevel != null) { stmt.bindString(9, pressLevel); } - + String cableType = entity.getCableType(); if (cableType != null) { stmt.bindString(10, cableType); } - + String cableSpec = entity.getCableSpec(); if (cableSpec != null) { stmt.bindString(11, cableSpec); } - + String cableBrand = entity.getCableBrand(); if (cableBrand != null) { stmt.bindString(12, cableBrand); } - + String cableStart = entity.getCableStart(); if (cableStart != null) { stmt.bindString(13, cableStart); } - + String cableEnd = entity.getCableEnd(); if (cableEnd != null) { stmt.bindString(14, cableEnd); } - + String hasJoint = entity.getHasJoint(); if (hasJoint != null) { stmt.bindString(15, hasJoint); } - + String jointCreator = entity.getJointCreator(); if (jointCreator != null) { stmt.bindString(16, jointCreator); } - + String createTime = entity.getCreateTime(); if (createTime != null) { stmt.bindString(17, createTime); } - + String path = entity.getPath(); if (path != null) { stmt.bindString(18, path); } - + String memo1 = entity.getMemo1(); if (memo1 != null) { stmt.bindString(19, memo1); } - + String memo2 = entity.getMemo2(); if (memo2 != null) { stmt.bindString(20, memo2); } - + String memo3 = entity.getMemo3(); if (memo3 != null) { stmt.bindString(21, memo3); @@ -312,36 +317,36 @@ @Override public Long readKey(Cursor cursor, int offset) { return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } + } @Override public SmallLabelBean readEntity(Cursor cursor, int offset) { SmallLabelBean entity = new SmallLabelBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // markerId - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // locationNo - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // locationName - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // smallMarkerId - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // cableName - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // cableNo - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // line - cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // pressLevel - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // cableType - cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // cableSpec - cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // cableBrand - cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12), // cableStart - cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13), // cableEnd - cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14), // hasJoint - cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15), // jointCreator - cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16), // createTime - cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17), // path - cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18), // memo1 - cursor.isNull(offset + 19) ? null : cursor.getString(offset + 19), // memo2 - cursor.isNull(offset + 20) ? null : cursor.getString(offset + 20) // memo3 + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // markerId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // locationNo + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // locationName + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // smallMarkerId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // cableName + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // cableNo + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // line + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // pressLevel + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // cableType + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // cableSpec + cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // cableBrand + cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12), // cableStart + cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13), // cableEnd + cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14), // hasJoint + cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15), // jointCreator + cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16), // createTime + cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17), // path + cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18), // memo1 + cursor.isNull(offset + 19) ? null : cursor.getString(offset + 19), // memo2 + cursor.isNull(offset + 20) ? null : cursor.getString(offset + 20) // memo3 ); return entity; } - + @Override public void readEntity(Cursor cursor, SmallLabelBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); @@ -365,17 +370,17 @@ entity.setMemo1(cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18)); entity.setMemo2(cursor.isNull(offset + 19) ? null : cursor.getString(offset + 19)); entity.setMemo3(cursor.isNull(offset + 20) ? null : cursor.getString(offset + 20)); - } - + } + @Override protected final Long updateKeyAfterInsert(SmallLabelBean entity, long rowId) { entity.setId(rowId); return rowId; } - + @Override public Long getKey(SmallLabelBean entity) { - if(entity != null) { + if (entity != null) { return entity.getId(); } else { return null; @@ -391,5 +396,5 @@ protected final boolean isEntityUpdateable() { return true; } - + } diff --git a/app/src/main/java/com/casic/detector/greendao/TaskBeanDao.java b/app/src/main/java/com/casic/detector/greendao/TaskBeanDao.java index 3f9d999..59eee37 100644 --- a/app/src/main/java/com/casic/detector/greendao/TaskBeanDao.java +++ b/app/src/main/java/com/casic/detector/greendao/TaskBeanDao.java @@ -12,9 +12,10 @@ import org.greenrobot.greendao.internal.DaoConfig; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** + +/** * DAO for table "TASK_BEAN". -*/ + */ public class TaskBeanDao extends AbstractDao { public static final String TABLENAME = "TASK_BEAN"; @@ -40,14 +41,16 @@ public TaskBeanDao(DaoConfig config) { super(config); } - + public TaskBeanDao(DaoConfig config, DaoSession daoSession) { super(config, daoSession); } - /** Creates the underlying database table. */ + /** + * Creates the underlying database table. + */ public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; db.execSQL("CREATE TABLE " + constraint + "\"TASK_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id "\"SCANNER\" TEXT," + // 1: scanner @@ -61,7 +64,9 @@ "\"STATE\" TEXT);"); // 9: state } - /** Drops the underlying database table. */ + /** + * Drops the underlying database table. + */ public static void dropTable(Database db, boolean ifExists) { String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_BEAN\""; db.execSQL(sql); @@ -70,52 +75,52 @@ @Override protected final void bindValues(DatabaseStatement stmt, TaskBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String scanner = entity.getScanner(); if (scanner != null) { stmt.bindString(2, scanner); } - + String desc = entity.getDesc(); if (desc != null) { stmt.bindString(3, desc); } - + String taskId = entity.getTaskId(); if (taskId != null) { stmt.bindString(4, taskId); } - + String taskCode = entity.getTaskCode(); if (taskCode != null) { stmt.bindString(5, taskCode); } - + String markerId = entity.getMarkerId(); if (markerId != null) { stmt.bindString(6, markerId); } - + String markerRealId = entity.getMarkerRealId(); if (markerRealId != null) { stmt.bindString(7, markerRealId); } - + String lng = entity.getLng(); if (lng != null) { stmt.bindString(8, lng); } - + String lat = entity.getLat(); if (lat != null) { stmt.bindString(9, lat); } - + String state = entity.getState(); if (state != null) { stmt.bindString(10, state); @@ -125,52 +130,52 @@ @Override protected final void bindValues(SQLiteStatement stmt, TaskBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String scanner = entity.getScanner(); if (scanner != null) { stmt.bindString(2, scanner); } - + String desc = entity.getDesc(); if (desc != null) { stmt.bindString(3, desc); } - + String taskId = entity.getTaskId(); if (taskId != null) { stmt.bindString(4, taskId); } - + String taskCode = entity.getTaskCode(); if (taskCode != null) { stmt.bindString(5, taskCode); } - + String markerId = entity.getMarkerId(); if (markerId != null) { stmt.bindString(6, markerId); } - + String markerRealId = entity.getMarkerRealId(); if (markerRealId != null) { stmt.bindString(7, markerRealId); } - + String lng = entity.getLng(); if (lng != null) { stmt.bindString(8, lng); } - + String lat = entity.getLat(); if (lat != null) { stmt.bindString(9, lat); } - + String state = entity.getState(); if (state != null) { stmt.bindString(10, state); @@ -180,25 +185,25 @@ @Override public Long readKey(Cursor cursor, int offset) { return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } + } @Override public TaskBean readEntity(Cursor cursor, int offset) { TaskBean entity = new TaskBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // scanner - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // desc - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // taskId - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskCode - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // markerId - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // markerRealId - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // lng - cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // lat - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9) // state + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // scanner + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // desc + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // taskId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskCode + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // markerId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // markerRealId + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // lng + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // lat + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9) // state ); return entity; } - + @Override public void readEntity(Cursor cursor, TaskBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); @@ -211,17 +216,17 @@ entity.setLng(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); entity.setLat(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); entity.setState(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - } - + } + @Override protected final Long updateKeyAfterInsert(TaskBean entity, long rowId) { entity.setId(rowId); return rowId; } - + @Override public Long getKey(TaskBean entity) { - if(entity != null) { + if (entity != null) { return entity.getId(); } else { return null; @@ -237,5 +242,5 @@ protected final boolean isEntityUpdateable() { return true; } - + } diff --git a/app/src/main/java/com/casic/detector/view/MainActivity.kt b/app/src/main/java/com/casic/detector/view/MainActivity.kt index 1cbecc3..8d772fc 100644 --- a/app/src/main/java/com/casic/detector/view/MainActivity.kt +++ b/app/src/main/java/com/casic/detector/view/MainActivity.kt @@ -9,10 +9,16 @@ import android.graphics.Color import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable +import android.hardware.Sensor +import android.hardware.SensorEvent +import android.hardware.SensorEventListener +import android.hardware.SensorManager import android.media.AudioAttributes import android.media.SoundPool import android.os.Bundle import android.os.CountDownTimer +import android.os.Handler +import android.os.Message import android.util.Log import android.view.KeyEvent import android.view.View @@ -81,6 +87,7 @@ import com.pengxh.kt.lite.extensions.createDownloadFileDir import com.pengxh.kt.lite.extensions.dateToTimestamp import com.pengxh.kt.lite.extensions.dp2px +import com.pengxh.kt.lite.extensions.getSystemService import com.pengxh.kt.lite.extensions.initDialogLayoutParams import com.pengxh.kt.lite.extensions.isNetworkConnected import com.pengxh.kt.lite.extensions.navigatePageTo @@ -92,6 +99,7 @@ import com.pengxh.kt.lite.utils.LoadState import com.pengxh.kt.lite.utils.LoadingDialogHub import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler import com.pengxh.kt.lite.widget.dialog.AlertControlDialog import com.pengxh.kt.lite.widget.dialog.AlertInputDialog import com.pengxh.kt.lite.widget.dialog.AlertMessageDialog @@ -107,7 +115,8 @@ import java.util.TimerTask @SuppressLint("all") -class MainActivity : SerialPortActivity() { +class MainActivity : SerialPortActivity(), SensorEventListener, + Handler.Callback { private val kTag = "MainActivity" private val context = this@MainActivity @@ -118,6 +127,9 @@ private val installDialog by lazy { InstallMarkerDialog(this) } private val searchDialog by lazy { SearchMarkerDialog(this) } private val searchNewDialog by lazy { SearchMarkerNewDialog(this) } + private val sensorMessageCode = 2024022301 + private val rotationMatrix = FloatArray(9)//旋转矩阵缓存 + private val valueArray = FloatArray(3)//方位角数值 private var clickTime: Long = 0 private var labelBeans = ArrayList() private var clusterOverlay: ClusterOverlay? = null @@ -128,17 +140,20 @@ private var signalTask: TimerTask? = null private var searchMarkerTimer: Timer? = null private var taskId: String? = null + private var gravity: FloatArray? = null + private var geomagnetic: FloatArray? = null private lateinit var aMap: AMap private lateinit var task: TaskBean + private lateinit var sensorManager: SensorManager + private lateinit var weakReferenceHandler: WeakReferenceHandler + /***inner class 需要用到*****start*/ private val gpioManager by lazy { GpioManager() } private val locationHub by lazy { LocationHub(this) } private val taskViewModel by lazy { ViewModelProvider(this)[TaskViewModel::class.java] } - private val attr = AudioAttributes.Builder() - .setUsage(AudioAttributes.USAGE_ALARM) - .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) - .build() + private val attr = AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_ALARM) + .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC).build() private val soundPool = SoundPool.Builder().setMaxStreams(16).setAudioAttributes(attr).build() private var soundResourceId = 0 private var slowSoundResourceId = 0 @@ -167,6 +182,9 @@ samplePopupWindow.setPopupMenuItem(LocaleConstant.POPUP_TITLES) samplePopupWindow.setBackgroundDrawable(null) + sensorManager = getSystemService()!! + weakReferenceHandler = WeakReferenceHandler(this) + //task网络请求监听 taskViewModel.markerFileResult.observe(this) { if (it.isSuccess) { @@ -228,12 +246,9 @@ override fun initEvent() { binding.rightImageView.setOnClickListener { if (isFreeTask) { - AlertMessageDialog.Builder() - .setContext(this) - .setTitle("温馨提示") + AlertMessageDialog.Builder().setContext(this).setTitle("温馨提示") .setMessage("正在自由巡检任务中,请完成此次任务之后再使用此功能") - .setPositiveButton("好的") - .setOnDialogButtonClickListener(object : + .setPositiveButton("好的").setOnDialogButtonClickListener(object : AlertMessageDialog.OnDialogButtonClickListener { override fun onConfirmClick() { @@ -273,12 +288,9 @@ * 改为Dialog方式,避免频繁打开/关闭串口 * */ if (isFreeTask) { - AlertMessageDialog.Builder() - .setContext(this) - .setTitle("温馨提示") + AlertMessageDialog.Builder().setContext(this).setTitle("温馨提示") .setMessage("正在自由巡检任务中,请完成此次任务之后再使用此功能") - .setPositiveButton("好的") - .setOnDialogButtonClickListener(object : + .setPositiveButton("好的").setOnDialogButtonClickListener(object : AlertMessageDialog.OnDialogButtonClickListener { override fun onConfirmClick() { @@ -358,11 +370,8 @@ override fun onActionItemClick(position: Int) { task = tasks[position] SaveKeyValues.putValue(LocaleConstant.TASK_ID, task.taskId) - AlertControlDialog.Builder() - .setContext(context) - .setTitle("提示") - .setMessage("请选择操作方式") - .setPositiveButton("执行工单") + AlertControlDialog.Builder().setContext(context).setTitle("提示") + .setMessage("请选择操作方式").setPositiveButton("执行工单") .setNegativeButton("提交工单") .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { @@ -407,31 +416,25 @@ * 如果开启自由巡检就不让探测 * */ if (isFreeTask) { - AlertMessageDialog.Builder() - .setContext(this) - .setTitle("温馨提示") + AlertMessageDialog.Builder().setContext(this).setTitle("温馨提示") .setMessage("正在自由巡检任务中,请完成此次任务之后再使用此功能") - .setPositiveButton("好的") - .setOnDialogButtonClickListener(object : + .setPositiveButton("好的").setOnDialogButtonClickListener(object : AlertMessageDialog.OnDialogButtonClickListener { override fun onConfirmClick() { } }).build().show() } else { - searchDialog.show() +// searchDialog.show() //TODO 新探测界面 -// searchNewDialog.show() + searchNewDialog.show() } } //自由巡检 binding.stopFreeTaskButton.setOnLongClickListener { - AlertMessageDialog.Builder() - .setContext(context) - .setTitle("温馨提示") - .setMessage("是否确定结束此次自由巡检任务?") - .setPositiveButton("是") + AlertMessageDialog.Builder().setContext(context).setTitle("温馨提示") + .setMessage("是否确定结束此次自由巡检任务?").setPositiveButton("是") .setOnDialogButtonClickListener(object : AlertMessageDialog.OnDialogButtonClickListener { override fun onConfirmClick() { @@ -513,9 +516,12 @@ if (labels.isNotEmpty()) { val bean = labels.first() aMap.addMarker( - MarkerOptions() - .position(LatLng(bean.lat.toDouble(), bean.lng.toDouble())) - .icon(BitmapDescriptorFactory.fromResource(R.mipmap.label_blue1)) + MarkerOptions().position( + LatLng( + bean.lat.toDouble(), + bean.lng.toDouble() + ) + ).icon(BitmapDescriptorFactory.fromResource(R.mipmap.label_blue1)) ) } } @@ -888,6 +894,40 @@ } else super.onKeyDown(keyCode, event) } + override fun onAccuracyChanged(sensor: Sensor?, accuracy: Int) { + //精度发生变化时触发 + } + + override fun onSensorChanged(event: SensorEvent?) { + //值发生变化时触发 + val type = event?.sensor?.type + + if (type == Sensor.TYPE_ACCELEROMETER) { + gravity = event.values + } else if (type == Sensor.TYPE_MAGNETIC_FIELD) { + geomagnetic = event.values + } + + if (gravity == null || geomagnetic == null) { + Log.d(kTag, "onSensorChanged => 数据不全,不计算") + return + } + + weakReferenceHandler.sendEmptyMessage(sensorMessageCode) + } + + override fun handleMessage(msg: Message): Boolean { + if (msg.what == sensorMessageCode) { + if (SensorManager.getRotationMatrix(rotationMatrix, null, gravity, geomagnetic)) { + SensorManager.getOrientation(rotationMatrix, valueArray) + + val degree = ((360f + valueArray[0] * 180f / Math.PI) % 360).toInt() + searchNewDialog.updateDegreeValue(degree) + } + } + return true + } + /***以下是地图生命周期管理************************************************************************/ override fun onResume() { @@ -900,11 +940,20 @@ } showLabelsOnMap() } + + //注册加速度传感器监听 + val accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) + sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL) + + //注册磁场传感器监听 + val magnetic = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) + sensorManager.registerListener(this, magnetic, SensorManager.SENSOR_DELAY_NORMAL) } override fun onPause() { super.onPause() binding.mapView.onPause() + sensorManager.unregisterListener(this) } override fun onSaveInstanceState(outState: Bundle) { @@ -1739,7 +1788,7 @@ binding.energyValueView.text = "${energy}dB" if (energy <= 700) {//18° - binding.energyTipsView.text = "标识器信号较弱,可能距离较远" + binding.energyTipsView.text = "信号较弱,可能距离较远" binding.energyTipsView.setTextColor(Color.parseColor("#8D1717")) binding.energyTipsView.setBackgroundResource(R.mipmap.bg_large_text_red) @@ -1754,11 +1803,11 @@ binding.searchResultView.setTextColor(Color.parseColor("#8D1717")) binding.searchResultView.setBackgroundResource(R.mipmap.bg_small_text_red) } else if (energy >= 4100) { - binding.energyTipsView.text = "标识器信号极强,可能在正下方" + binding.energyTipsView.text = "信号极强,接近标识器正上方" binding.energyTipsView.setTextColor(Color.parseColor("#428d00")) binding.energyTipsView.setBackgroundResource(R.mipmap.bg_large_text_green) } else { - binding.energyTipsView.text = "已靠近标识器,请继续移动位置" + binding.energyTipsView.text = "已靠近,请继续移动位置" binding.energyTipsView.setTextColor(Color.parseColor("#8C5700")) binding.energyTipsView.setBackgroundResource(R.mipmap.bg_large_text_yellow) } @@ -1771,6 +1820,15 @@ try { val depthResponse = hex.take(10).hexToString() val depth = depthResponse.drop(2).toInt() + + //根据型号设置不同的进度比例 + val result = DataBaseManager.get.queryLabelById(markerId) + when (result.first().identifierType) { + "EM30" -> binding.distancePgBar.progress = depth / 110 + "EM50" -> binding.distancePgBar.progress = depth / 150 + "EM14" -> binding.distancePgBar.progress = depth / 70 + } + AlertMessageDialog.Builder().setContext(context).setTitle("温馨提示") .setMessage("标识器埋深:${depth}厘米").setPositiveButton("知道了") .setOnDialogButtonClickListener(object : @@ -1812,6 +1870,12 @@ } } + //更新罗盘角度 + fun updateDegreeValue(degree: Int) { + binding.degreeView.text = degree.toString() + binding.radarScanView.setDegreeValue(degree) + } + private fun initTimer() { searchMarkerTimer = Timer() diff --git a/app/src/main/java/com/casic/detector/widgets/RadarScanView.kt b/app/src/main/java/com/casic/detector/widgets/RadarScanView.kt index f87089b..4f4f2e3 100644 --- a/app/src/main/java/com/casic/detector/widgets/RadarScanView.kt +++ b/app/src/main/java/com/casic/detector/widgets/RadarScanView.kt @@ -58,13 +58,18 @@ //雷达扫描角度步长 private var degrees = 0f + //方位角 + private var degreeValue = 0 + private lateinit var tickPaint: Paint private lateinit var backPaint: Paint private lateinit var borderPaint: Paint private lateinit var shaderPaint: Paint private lateinit var dataPaint: Paint + private lateinit var trianglePaint: Paint private lateinit var innerPaint: TextPaint private lateinit var innerTextPath: Path + private lateinit var trianglePath: Path //雷达扫描线后面的渐变梯度 private lateinit var sweepGradient: SweepGradient @@ -72,9 +77,18 @@ //背景栅格图 private lateinit var bitmap: Bitmap + //指示针 + private lateinit var needleBitmap: Bitmap + //雷达旋转矩阵 private lateinit var matrix: Matrix + //方位三角形边长 + private val tickLength = 20f.dp2px(context) + + //背景区域范围 + private var bgRect: Rect + init { val type = context.obtainStyledAttributes(attrs, R.styleable.RadarScanView) borderColor = type.getColor(R.styleable.RadarScanView_radar_borderColor, Color.GRAY) @@ -86,10 +100,12 @@ innerRadius = radius - 10.dp2px(context) //需要给外围刻度留位置 - viewSideLength = radius + 10.dp2px(context) + viewSideLength = radius + 30.dp2px(context) //辅助框 rect = Rect(-viewSideLength, -viewSideLength, viewSideLength, viewSideLength) + bgRect = Rect(-radius, -radius, radius, radius) + initPaint() //控制转动 @@ -142,6 +158,17 @@ ) innerTextPath.addArc(innerRectF, -90f, 360f) + trianglePaint = Paint() + trianglePaint.color = Color.RED + trianglePaint.style = Paint.Style.FILL + trianglePaint.isAntiAlias = true + trianglePath = Path() + trianglePath.moveTo(0f, -viewSideLength.toFloat() + tickLength * 1.5f) + trianglePath.lineTo(tickLength * 0.5f, -viewSideLength.toFloat() + tickLength * 0.75f) + trianglePath.lineTo(-tickLength * 0.5f, -viewSideLength.toFloat() + tickLength * 0.75f) + trianglePath.close() + needleBitmap = BitmapFactory.decodeResource(context.resources, R.mipmap.bg_needle) + //扫描线画笔 shaderPaint = Paint() shaderPaint.isAntiAlias = true @@ -200,7 +227,7 @@ canvas.translate(centerX, centerY) //画背景 - canvas.drawBitmap(bitmap, -radius.toFloat(), -radius.toFloat(), backPaint) + canvas.drawBitmap(bitmap, null, bgRect, backPaint) // drawGuides(canvas) @@ -263,6 +290,26 @@ ) } + //画正北方小三角 + canvas.drawPath(trianglePath, trianglePaint) + + //画实时方位角 +// for (angle in 0..degreeValue step 3) { +// //角度需要转为弧度 +// val radians = (angle - 90) * (Math.PI / 180) +// +// canvas.drawBitmap( +// needleBitmap, +// -(needleBitmap.width shr 1).toFloat(), +// -(radians + needleBitmap.height).toFloat(), +// trianglePaint +// ) +// } + //角度需要转为弧度 + val radians = degreeValue * (Math.PI / 180) + +// canvas.drawBitmap(needleBitmap, null, bgRect, trianglePaint) + //画数据点 points.forEach { canvas.drawCircle(it.x, it.y, 10f, dataPaint) @@ -290,6 +337,16 @@ } /** + * 更新罗盘方位角度 + * @param value 方位角 + * */ + fun setDegreeValue(value: Int) { + degreeValue = value + //实时刷新角度值 + invalidate() + } + + /** * 数据点 * @param dataPoints 数据点集合 * */ diff --git a/app/src/main/res/layout/dialog_search_marker_new.xml b/app/src/main/res/layout/dialog_search_marker_new.xml index c341a72..a3ff080 100644 --- a/app/src/main/res/layout/dialog_search_marker_new.xml +++ b/app/src/main/res/layout/dialog_search_marker_new.xml @@ -8,6 +8,13 @@ android:gravity="center_horizontal" android:orientation="vertical"> + + diff --git a/app/src/main/res/mipmap-xhdpi/bg_needle.png b/app/src/main/res/mipmap-xhdpi/bg_needle.png new file mode 100644 index 0000000..ece3665 --- /dev/null +++ b/app/src/main/res/mipmap-xhdpi/bg_needle.png Binary files differ diff --git a/app/src/main/java/com/casic/detector/greendao/SmallLabelBeanDao.java b/app/src/main/java/com/casic/detector/greendao/SmallLabelBeanDao.java index 925c804..1d82f51 100644 --- a/app/src/main/java/com/casic/detector/greendao/SmallLabelBeanDao.java +++ b/app/src/main/java/com/casic/detector/greendao/SmallLabelBeanDao.java @@ -12,9 +12,10 @@ import org.greenrobot.greendao.internal.DaoConfig; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** + +/** * DAO for table "SMALL_LABEL_BEAN". -*/ + */ public class SmallLabelBeanDao extends AbstractDao { public static final String TABLENAME = "SMALL_LABEL_BEAN"; @@ -51,14 +52,16 @@ public SmallLabelBeanDao(DaoConfig config) { super(config); } - + public SmallLabelBeanDao(DaoConfig config, DaoSession daoSession) { super(config, daoSession); } - /** Creates the underlying database table. */ + /** + * Creates the underlying database table. + */ public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; db.execSQL("CREATE TABLE " + constraint + "\"SMALL_LABEL_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id "\"MARKER_ID\" TEXT," + // 1: markerId @@ -83,7 +86,9 @@ "\"MEMO3\" TEXT);"); // 20: memo3 } - /** Drops the underlying database table. */ + /** + * Drops the underlying database table. + */ public static void dropTable(Database db, boolean ifExists) { String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"SMALL_LABEL_BEAN\""; db.execSQL(sql); @@ -92,107 +97,107 @@ @Override protected final void bindValues(DatabaseStatement stmt, SmallLabelBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String markerId = entity.getMarkerId(); if (markerId != null) { stmt.bindString(2, markerId); } - + String locationNo = entity.getLocationNo(); if (locationNo != null) { stmt.bindString(3, locationNo); } - + String locationName = entity.getLocationName(); if (locationName != null) { stmt.bindString(4, locationName); } - + String smallMarkerId = entity.getSmallMarkerId(); if (smallMarkerId != null) { stmt.bindString(5, smallMarkerId); } - + String cableName = entity.getCableName(); if (cableName != null) { stmt.bindString(6, cableName); } - + String cableNo = entity.getCableNo(); if (cableNo != null) { stmt.bindString(7, cableNo); } - + String line = entity.getLine(); if (line != null) { stmt.bindString(8, line); } - + String pressLevel = entity.getPressLevel(); if (pressLevel != null) { stmt.bindString(9, pressLevel); } - + String cableType = entity.getCableType(); if (cableType != null) { stmt.bindString(10, cableType); } - + String cableSpec = entity.getCableSpec(); if (cableSpec != null) { stmt.bindString(11, cableSpec); } - + String cableBrand = entity.getCableBrand(); if (cableBrand != null) { stmt.bindString(12, cableBrand); } - + String cableStart = entity.getCableStart(); if (cableStart != null) { stmt.bindString(13, cableStart); } - + String cableEnd = entity.getCableEnd(); if (cableEnd != null) { stmt.bindString(14, cableEnd); } - + String hasJoint = entity.getHasJoint(); if (hasJoint != null) { stmt.bindString(15, hasJoint); } - + String jointCreator = entity.getJointCreator(); if (jointCreator != null) { stmt.bindString(16, jointCreator); } - + String createTime = entity.getCreateTime(); if (createTime != null) { stmt.bindString(17, createTime); } - + String path = entity.getPath(); if (path != null) { stmt.bindString(18, path); } - + String memo1 = entity.getMemo1(); if (memo1 != null) { stmt.bindString(19, memo1); } - + String memo2 = entity.getMemo2(); if (memo2 != null) { stmt.bindString(20, memo2); } - + String memo3 = entity.getMemo3(); if (memo3 != null) { stmt.bindString(21, memo3); @@ -202,107 +207,107 @@ @Override protected final void bindValues(SQLiteStatement stmt, SmallLabelBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String markerId = entity.getMarkerId(); if (markerId != null) { stmt.bindString(2, markerId); } - + String locationNo = entity.getLocationNo(); if (locationNo != null) { stmt.bindString(3, locationNo); } - + String locationName = entity.getLocationName(); if (locationName != null) { stmt.bindString(4, locationName); } - + String smallMarkerId = entity.getSmallMarkerId(); if (smallMarkerId != null) { stmt.bindString(5, smallMarkerId); } - + String cableName = entity.getCableName(); if (cableName != null) { stmt.bindString(6, cableName); } - + String cableNo = entity.getCableNo(); if (cableNo != null) { stmt.bindString(7, cableNo); } - + String line = entity.getLine(); if (line != null) { stmt.bindString(8, line); } - + String pressLevel = entity.getPressLevel(); if (pressLevel != null) { stmt.bindString(9, pressLevel); } - + String cableType = entity.getCableType(); if (cableType != null) { stmt.bindString(10, cableType); } - + String cableSpec = entity.getCableSpec(); if (cableSpec != null) { stmt.bindString(11, cableSpec); } - + String cableBrand = entity.getCableBrand(); if (cableBrand != null) { stmt.bindString(12, cableBrand); } - + String cableStart = entity.getCableStart(); if (cableStart != null) { stmt.bindString(13, cableStart); } - + String cableEnd = entity.getCableEnd(); if (cableEnd != null) { stmt.bindString(14, cableEnd); } - + String hasJoint = entity.getHasJoint(); if (hasJoint != null) { stmt.bindString(15, hasJoint); } - + String jointCreator = entity.getJointCreator(); if (jointCreator != null) { stmt.bindString(16, jointCreator); } - + String createTime = entity.getCreateTime(); if (createTime != null) { stmt.bindString(17, createTime); } - + String path = entity.getPath(); if (path != null) { stmt.bindString(18, path); } - + String memo1 = entity.getMemo1(); if (memo1 != null) { stmt.bindString(19, memo1); } - + String memo2 = entity.getMemo2(); if (memo2 != null) { stmt.bindString(20, memo2); } - + String memo3 = entity.getMemo3(); if (memo3 != null) { stmt.bindString(21, memo3); @@ -312,36 +317,36 @@ @Override public Long readKey(Cursor cursor, int offset) { return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } + } @Override public SmallLabelBean readEntity(Cursor cursor, int offset) { SmallLabelBean entity = new SmallLabelBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // markerId - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // locationNo - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // locationName - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // smallMarkerId - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // cableName - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // cableNo - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // line - cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // pressLevel - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // cableType - cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // cableSpec - cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // cableBrand - cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12), // cableStart - cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13), // cableEnd - cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14), // hasJoint - cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15), // jointCreator - cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16), // createTime - cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17), // path - cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18), // memo1 - cursor.isNull(offset + 19) ? null : cursor.getString(offset + 19), // memo2 - cursor.isNull(offset + 20) ? null : cursor.getString(offset + 20) // memo3 + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // markerId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // locationNo + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // locationName + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // smallMarkerId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // cableName + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // cableNo + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // line + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // pressLevel + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // cableType + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // cableSpec + cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // cableBrand + cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12), // cableStart + cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13), // cableEnd + cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14), // hasJoint + cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15), // jointCreator + cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16), // createTime + cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17), // path + cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18), // memo1 + cursor.isNull(offset + 19) ? null : cursor.getString(offset + 19), // memo2 + cursor.isNull(offset + 20) ? null : cursor.getString(offset + 20) // memo3 ); return entity; } - + @Override public void readEntity(Cursor cursor, SmallLabelBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); @@ -365,17 +370,17 @@ entity.setMemo1(cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18)); entity.setMemo2(cursor.isNull(offset + 19) ? null : cursor.getString(offset + 19)); entity.setMemo3(cursor.isNull(offset + 20) ? null : cursor.getString(offset + 20)); - } - + } + @Override protected final Long updateKeyAfterInsert(SmallLabelBean entity, long rowId) { entity.setId(rowId); return rowId; } - + @Override public Long getKey(SmallLabelBean entity) { - if(entity != null) { + if (entity != null) { return entity.getId(); } else { return null; @@ -391,5 +396,5 @@ protected final boolean isEntityUpdateable() { return true; } - + } diff --git a/app/src/main/java/com/casic/detector/greendao/TaskBeanDao.java b/app/src/main/java/com/casic/detector/greendao/TaskBeanDao.java index 3f9d999..59eee37 100644 --- a/app/src/main/java/com/casic/detector/greendao/TaskBeanDao.java +++ b/app/src/main/java/com/casic/detector/greendao/TaskBeanDao.java @@ -12,9 +12,10 @@ import org.greenrobot.greendao.internal.DaoConfig; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** + +/** * DAO for table "TASK_BEAN". -*/ + */ public class TaskBeanDao extends AbstractDao { public static final String TABLENAME = "TASK_BEAN"; @@ -40,14 +41,16 @@ public TaskBeanDao(DaoConfig config) { super(config); } - + public TaskBeanDao(DaoConfig config, DaoSession daoSession) { super(config, daoSession); } - /** Creates the underlying database table. */ + /** + * Creates the underlying database table. + */ public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; db.execSQL("CREATE TABLE " + constraint + "\"TASK_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id "\"SCANNER\" TEXT," + // 1: scanner @@ -61,7 +64,9 @@ "\"STATE\" TEXT);"); // 9: state } - /** Drops the underlying database table. */ + /** + * Drops the underlying database table. + */ public static void dropTable(Database db, boolean ifExists) { String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_BEAN\""; db.execSQL(sql); @@ -70,52 +75,52 @@ @Override protected final void bindValues(DatabaseStatement stmt, TaskBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String scanner = entity.getScanner(); if (scanner != null) { stmt.bindString(2, scanner); } - + String desc = entity.getDesc(); if (desc != null) { stmt.bindString(3, desc); } - + String taskId = entity.getTaskId(); if (taskId != null) { stmt.bindString(4, taskId); } - + String taskCode = entity.getTaskCode(); if (taskCode != null) { stmt.bindString(5, taskCode); } - + String markerId = entity.getMarkerId(); if (markerId != null) { stmt.bindString(6, markerId); } - + String markerRealId = entity.getMarkerRealId(); if (markerRealId != null) { stmt.bindString(7, markerRealId); } - + String lng = entity.getLng(); if (lng != null) { stmt.bindString(8, lng); } - + String lat = entity.getLat(); if (lat != null) { stmt.bindString(9, lat); } - + String state = entity.getState(); if (state != null) { stmt.bindString(10, state); @@ -125,52 +130,52 @@ @Override protected final void bindValues(SQLiteStatement stmt, TaskBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String scanner = entity.getScanner(); if (scanner != null) { stmt.bindString(2, scanner); } - + String desc = entity.getDesc(); if (desc != null) { stmt.bindString(3, desc); } - + String taskId = entity.getTaskId(); if (taskId != null) { stmt.bindString(4, taskId); } - + String taskCode = entity.getTaskCode(); if (taskCode != null) { stmt.bindString(5, taskCode); } - + String markerId = entity.getMarkerId(); if (markerId != null) { stmt.bindString(6, markerId); } - + String markerRealId = entity.getMarkerRealId(); if (markerRealId != null) { stmt.bindString(7, markerRealId); } - + String lng = entity.getLng(); if (lng != null) { stmt.bindString(8, lng); } - + String lat = entity.getLat(); if (lat != null) { stmt.bindString(9, lat); } - + String state = entity.getState(); if (state != null) { stmt.bindString(10, state); @@ -180,25 +185,25 @@ @Override public Long readKey(Cursor cursor, int offset) { return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } + } @Override public TaskBean readEntity(Cursor cursor, int offset) { TaskBean entity = new TaskBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // scanner - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // desc - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // taskId - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskCode - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // markerId - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // markerRealId - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // lng - cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // lat - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9) // state + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // scanner + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // desc + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // taskId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskCode + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // markerId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // markerRealId + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // lng + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // lat + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9) // state ); return entity; } - + @Override public void readEntity(Cursor cursor, TaskBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); @@ -211,17 +216,17 @@ entity.setLng(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); entity.setLat(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); entity.setState(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - } - + } + @Override protected final Long updateKeyAfterInsert(TaskBean entity, long rowId) { entity.setId(rowId); return rowId; } - + @Override public Long getKey(TaskBean entity) { - if(entity != null) { + if (entity != null) { return entity.getId(); } else { return null; @@ -237,5 +242,5 @@ protected final boolean isEntityUpdateable() { return true; } - + } diff --git a/app/src/main/java/com/casic/detector/view/MainActivity.kt b/app/src/main/java/com/casic/detector/view/MainActivity.kt index 1cbecc3..8d772fc 100644 --- a/app/src/main/java/com/casic/detector/view/MainActivity.kt +++ b/app/src/main/java/com/casic/detector/view/MainActivity.kt @@ -9,10 +9,16 @@ import android.graphics.Color import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable +import android.hardware.Sensor +import android.hardware.SensorEvent +import android.hardware.SensorEventListener +import android.hardware.SensorManager import android.media.AudioAttributes import android.media.SoundPool import android.os.Bundle import android.os.CountDownTimer +import android.os.Handler +import android.os.Message import android.util.Log import android.view.KeyEvent import android.view.View @@ -81,6 +87,7 @@ import com.pengxh.kt.lite.extensions.createDownloadFileDir import com.pengxh.kt.lite.extensions.dateToTimestamp import com.pengxh.kt.lite.extensions.dp2px +import com.pengxh.kt.lite.extensions.getSystemService import com.pengxh.kt.lite.extensions.initDialogLayoutParams import com.pengxh.kt.lite.extensions.isNetworkConnected import com.pengxh.kt.lite.extensions.navigatePageTo @@ -92,6 +99,7 @@ import com.pengxh.kt.lite.utils.LoadState import com.pengxh.kt.lite.utils.LoadingDialogHub import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler import com.pengxh.kt.lite.widget.dialog.AlertControlDialog import com.pengxh.kt.lite.widget.dialog.AlertInputDialog import com.pengxh.kt.lite.widget.dialog.AlertMessageDialog @@ -107,7 +115,8 @@ import java.util.TimerTask @SuppressLint("all") -class MainActivity : SerialPortActivity() { +class MainActivity : SerialPortActivity(), SensorEventListener, + Handler.Callback { private val kTag = "MainActivity" private val context = this@MainActivity @@ -118,6 +127,9 @@ private val installDialog by lazy { InstallMarkerDialog(this) } private val searchDialog by lazy { SearchMarkerDialog(this) } private val searchNewDialog by lazy { SearchMarkerNewDialog(this) } + private val sensorMessageCode = 2024022301 + private val rotationMatrix = FloatArray(9)//旋转矩阵缓存 + private val valueArray = FloatArray(3)//方位角数值 private var clickTime: Long = 0 private var labelBeans = ArrayList() private var clusterOverlay: ClusterOverlay? = null @@ -128,17 +140,20 @@ private var signalTask: TimerTask? = null private var searchMarkerTimer: Timer? = null private var taskId: String? = null + private var gravity: FloatArray? = null + private var geomagnetic: FloatArray? = null private lateinit var aMap: AMap private lateinit var task: TaskBean + private lateinit var sensorManager: SensorManager + private lateinit var weakReferenceHandler: WeakReferenceHandler + /***inner class 需要用到*****start*/ private val gpioManager by lazy { GpioManager() } private val locationHub by lazy { LocationHub(this) } private val taskViewModel by lazy { ViewModelProvider(this)[TaskViewModel::class.java] } - private val attr = AudioAttributes.Builder() - .setUsage(AudioAttributes.USAGE_ALARM) - .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) - .build() + private val attr = AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_ALARM) + .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC).build() private val soundPool = SoundPool.Builder().setMaxStreams(16).setAudioAttributes(attr).build() private var soundResourceId = 0 private var slowSoundResourceId = 0 @@ -167,6 +182,9 @@ samplePopupWindow.setPopupMenuItem(LocaleConstant.POPUP_TITLES) samplePopupWindow.setBackgroundDrawable(null) + sensorManager = getSystemService()!! + weakReferenceHandler = WeakReferenceHandler(this) + //task网络请求监听 taskViewModel.markerFileResult.observe(this) { if (it.isSuccess) { @@ -228,12 +246,9 @@ override fun initEvent() { binding.rightImageView.setOnClickListener { if (isFreeTask) { - AlertMessageDialog.Builder() - .setContext(this) - .setTitle("温馨提示") + AlertMessageDialog.Builder().setContext(this).setTitle("温馨提示") .setMessage("正在自由巡检任务中,请完成此次任务之后再使用此功能") - .setPositiveButton("好的") - .setOnDialogButtonClickListener(object : + .setPositiveButton("好的").setOnDialogButtonClickListener(object : AlertMessageDialog.OnDialogButtonClickListener { override fun onConfirmClick() { @@ -273,12 +288,9 @@ * 改为Dialog方式,避免频繁打开/关闭串口 * */ if (isFreeTask) { - AlertMessageDialog.Builder() - .setContext(this) - .setTitle("温馨提示") + AlertMessageDialog.Builder().setContext(this).setTitle("温馨提示") .setMessage("正在自由巡检任务中,请完成此次任务之后再使用此功能") - .setPositiveButton("好的") - .setOnDialogButtonClickListener(object : + .setPositiveButton("好的").setOnDialogButtonClickListener(object : AlertMessageDialog.OnDialogButtonClickListener { override fun onConfirmClick() { @@ -358,11 +370,8 @@ override fun onActionItemClick(position: Int) { task = tasks[position] SaveKeyValues.putValue(LocaleConstant.TASK_ID, task.taskId) - AlertControlDialog.Builder() - .setContext(context) - .setTitle("提示") - .setMessage("请选择操作方式") - .setPositiveButton("执行工单") + AlertControlDialog.Builder().setContext(context).setTitle("提示") + .setMessage("请选择操作方式").setPositiveButton("执行工单") .setNegativeButton("提交工单") .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { @@ -407,31 +416,25 @@ * 如果开启自由巡检就不让探测 * */ if (isFreeTask) { - AlertMessageDialog.Builder() - .setContext(this) - .setTitle("温馨提示") + AlertMessageDialog.Builder().setContext(this).setTitle("温馨提示") .setMessage("正在自由巡检任务中,请完成此次任务之后再使用此功能") - .setPositiveButton("好的") - .setOnDialogButtonClickListener(object : + .setPositiveButton("好的").setOnDialogButtonClickListener(object : AlertMessageDialog.OnDialogButtonClickListener { override fun onConfirmClick() { } }).build().show() } else { - searchDialog.show() +// searchDialog.show() //TODO 新探测界面 -// searchNewDialog.show() + searchNewDialog.show() } } //自由巡检 binding.stopFreeTaskButton.setOnLongClickListener { - AlertMessageDialog.Builder() - .setContext(context) - .setTitle("温馨提示") - .setMessage("是否确定结束此次自由巡检任务?") - .setPositiveButton("是") + AlertMessageDialog.Builder().setContext(context).setTitle("温馨提示") + .setMessage("是否确定结束此次自由巡检任务?").setPositiveButton("是") .setOnDialogButtonClickListener(object : AlertMessageDialog.OnDialogButtonClickListener { override fun onConfirmClick() { @@ -513,9 +516,12 @@ if (labels.isNotEmpty()) { val bean = labels.first() aMap.addMarker( - MarkerOptions() - .position(LatLng(bean.lat.toDouble(), bean.lng.toDouble())) - .icon(BitmapDescriptorFactory.fromResource(R.mipmap.label_blue1)) + MarkerOptions().position( + LatLng( + bean.lat.toDouble(), + bean.lng.toDouble() + ) + ).icon(BitmapDescriptorFactory.fromResource(R.mipmap.label_blue1)) ) } } @@ -888,6 +894,40 @@ } else super.onKeyDown(keyCode, event) } + override fun onAccuracyChanged(sensor: Sensor?, accuracy: Int) { + //精度发生变化时触发 + } + + override fun onSensorChanged(event: SensorEvent?) { + //值发生变化时触发 + val type = event?.sensor?.type + + if (type == Sensor.TYPE_ACCELEROMETER) { + gravity = event.values + } else if (type == Sensor.TYPE_MAGNETIC_FIELD) { + geomagnetic = event.values + } + + if (gravity == null || geomagnetic == null) { + Log.d(kTag, "onSensorChanged => 数据不全,不计算") + return + } + + weakReferenceHandler.sendEmptyMessage(sensorMessageCode) + } + + override fun handleMessage(msg: Message): Boolean { + if (msg.what == sensorMessageCode) { + if (SensorManager.getRotationMatrix(rotationMatrix, null, gravity, geomagnetic)) { + SensorManager.getOrientation(rotationMatrix, valueArray) + + val degree = ((360f + valueArray[0] * 180f / Math.PI) % 360).toInt() + searchNewDialog.updateDegreeValue(degree) + } + } + return true + } + /***以下是地图生命周期管理************************************************************************/ override fun onResume() { @@ -900,11 +940,20 @@ } showLabelsOnMap() } + + //注册加速度传感器监听 + val accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) + sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL) + + //注册磁场传感器监听 + val magnetic = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) + sensorManager.registerListener(this, magnetic, SensorManager.SENSOR_DELAY_NORMAL) } override fun onPause() { super.onPause() binding.mapView.onPause() + sensorManager.unregisterListener(this) } override fun onSaveInstanceState(outState: Bundle) { @@ -1739,7 +1788,7 @@ binding.energyValueView.text = "${energy}dB" if (energy <= 700) {//18° - binding.energyTipsView.text = "标识器信号较弱,可能距离较远" + binding.energyTipsView.text = "信号较弱,可能距离较远" binding.energyTipsView.setTextColor(Color.parseColor("#8D1717")) binding.energyTipsView.setBackgroundResource(R.mipmap.bg_large_text_red) @@ -1754,11 +1803,11 @@ binding.searchResultView.setTextColor(Color.parseColor("#8D1717")) binding.searchResultView.setBackgroundResource(R.mipmap.bg_small_text_red) } else if (energy >= 4100) { - binding.energyTipsView.text = "标识器信号极强,可能在正下方" + binding.energyTipsView.text = "信号极强,接近标识器正上方" binding.energyTipsView.setTextColor(Color.parseColor("#428d00")) binding.energyTipsView.setBackgroundResource(R.mipmap.bg_large_text_green) } else { - binding.energyTipsView.text = "已靠近标识器,请继续移动位置" + binding.energyTipsView.text = "已靠近,请继续移动位置" binding.energyTipsView.setTextColor(Color.parseColor("#8C5700")) binding.energyTipsView.setBackgroundResource(R.mipmap.bg_large_text_yellow) } @@ -1771,6 +1820,15 @@ try { val depthResponse = hex.take(10).hexToString() val depth = depthResponse.drop(2).toInt() + + //根据型号设置不同的进度比例 + val result = DataBaseManager.get.queryLabelById(markerId) + when (result.first().identifierType) { + "EM30" -> binding.distancePgBar.progress = depth / 110 + "EM50" -> binding.distancePgBar.progress = depth / 150 + "EM14" -> binding.distancePgBar.progress = depth / 70 + } + AlertMessageDialog.Builder().setContext(context).setTitle("温馨提示") .setMessage("标识器埋深:${depth}厘米").setPositiveButton("知道了") .setOnDialogButtonClickListener(object : @@ -1812,6 +1870,12 @@ } } + //更新罗盘角度 + fun updateDegreeValue(degree: Int) { + binding.degreeView.text = degree.toString() + binding.radarScanView.setDegreeValue(degree) + } + private fun initTimer() { searchMarkerTimer = Timer() diff --git a/app/src/main/java/com/casic/detector/widgets/RadarScanView.kt b/app/src/main/java/com/casic/detector/widgets/RadarScanView.kt index f87089b..4f4f2e3 100644 --- a/app/src/main/java/com/casic/detector/widgets/RadarScanView.kt +++ b/app/src/main/java/com/casic/detector/widgets/RadarScanView.kt @@ -58,13 +58,18 @@ //雷达扫描角度步长 private var degrees = 0f + //方位角 + private var degreeValue = 0 + private lateinit var tickPaint: Paint private lateinit var backPaint: Paint private lateinit var borderPaint: Paint private lateinit var shaderPaint: Paint private lateinit var dataPaint: Paint + private lateinit var trianglePaint: Paint private lateinit var innerPaint: TextPaint private lateinit var innerTextPath: Path + private lateinit var trianglePath: Path //雷达扫描线后面的渐变梯度 private lateinit var sweepGradient: SweepGradient @@ -72,9 +77,18 @@ //背景栅格图 private lateinit var bitmap: Bitmap + //指示针 + private lateinit var needleBitmap: Bitmap + //雷达旋转矩阵 private lateinit var matrix: Matrix + //方位三角形边长 + private val tickLength = 20f.dp2px(context) + + //背景区域范围 + private var bgRect: Rect + init { val type = context.obtainStyledAttributes(attrs, R.styleable.RadarScanView) borderColor = type.getColor(R.styleable.RadarScanView_radar_borderColor, Color.GRAY) @@ -86,10 +100,12 @@ innerRadius = radius - 10.dp2px(context) //需要给外围刻度留位置 - viewSideLength = radius + 10.dp2px(context) + viewSideLength = radius + 30.dp2px(context) //辅助框 rect = Rect(-viewSideLength, -viewSideLength, viewSideLength, viewSideLength) + bgRect = Rect(-radius, -radius, radius, radius) + initPaint() //控制转动 @@ -142,6 +158,17 @@ ) innerTextPath.addArc(innerRectF, -90f, 360f) + trianglePaint = Paint() + trianglePaint.color = Color.RED + trianglePaint.style = Paint.Style.FILL + trianglePaint.isAntiAlias = true + trianglePath = Path() + trianglePath.moveTo(0f, -viewSideLength.toFloat() + tickLength * 1.5f) + trianglePath.lineTo(tickLength * 0.5f, -viewSideLength.toFloat() + tickLength * 0.75f) + trianglePath.lineTo(-tickLength * 0.5f, -viewSideLength.toFloat() + tickLength * 0.75f) + trianglePath.close() + needleBitmap = BitmapFactory.decodeResource(context.resources, R.mipmap.bg_needle) + //扫描线画笔 shaderPaint = Paint() shaderPaint.isAntiAlias = true @@ -200,7 +227,7 @@ canvas.translate(centerX, centerY) //画背景 - canvas.drawBitmap(bitmap, -radius.toFloat(), -radius.toFloat(), backPaint) + canvas.drawBitmap(bitmap, null, bgRect, backPaint) // drawGuides(canvas) @@ -263,6 +290,26 @@ ) } + //画正北方小三角 + canvas.drawPath(trianglePath, trianglePaint) + + //画实时方位角 +// for (angle in 0..degreeValue step 3) { +// //角度需要转为弧度 +// val radians = (angle - 90) * (Math.PI / 180) +// +// canvas.drawBitmap( +// needleBitmap, +// -(needleBitmap.width shr 1).toFloat(), +// -(radians + needleBitmap.height).toFloat(), +// trianglePaint +// ) +// } + //角度需要转为弧度 + val radians = degreeValue * (Math.PI / 180) + +// canvas.drawBitmap(needleBitmap, null, bgRect, trianglePaint) + //画数据点 points.forEach { canvas.drawCircle(it.x, it.y, 10f, dataPaint) @@ -290,6 +337,16 @@ } /** + * 更新罗盘方位角度 + * @param value 方位角 + * */ + fun setDegreeValue(value: Int) { + degreeValue = value + //实时刷新角度值 + invalidate() + } + + /** * 数据点 * @param dataPoints 数据点集合 * */ diff --git a/app/src/main/res/layout/dialog_search_marker_new.xml b/app/src/main/res/layout/dialog_search_marker_new.xml index c341a72..a3ff080 100644 --- a/app/src/main/res/layout/dialog_search_marker_new.xml +++ b/app/src/main/res/layout/dialog_search_marker_new.xml @@ -8,6 +8,13 @@ android:gravity="center_horizontal" android:orientation="vertical"> + + diff --git a/app/src/main/res/mipmap-xhdpi/bg_needle.png b/app/src/main/res/mipmap-xhdpi/bg_needle.png new file mode 100644 index 0000000..ece3665 --- /dev/null +++ b/app/src/main/res/mipmap-xhdpi/bg_needle.png Binary files differ diff --git a/app/src/main/res/mipmap-xhdpi/bg_radar.png b/app/src/main/res/mipmap-xhdpi/bg_radar.png index 8329c2d..ff6c02c 100644 --- a/app/src/main/res/mipmap-xhdpi/bg_radar.png +++ b/app/src/main/res/mipmap-xhdpi/bg_radar.png Binary files differ