diff --git a/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java b/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java index 259243d..f252abc 100644 --- a/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java +++ b/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java @@ -14,7 +14,7 @@ /** * {@inheritDoc} - * + * * @see org.greenrobot.greendao.AbstractDaoSession */ public class DaoSession extends AbstractDaoSession { @@ -34,7 +34,7 @@ registerDao(GasValueBean.class, gasValueBeanDao); } - + public void clear() { gasValueBeanDaoConfig.clearIdentityScope(); } diff --git a/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java b/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java index 259243d..f252abc 100644 --- a/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java +++ b/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java @@ -14,7 +14,7 @@ /** * {@inheritDoc} - * + * * @see org.greenrobot.greendao.AbstractDaoSession */ public class DaoSession extends AbstractDaoSession { @@ -34,7 +34,7 @@ registerDao(GasValueBean.class, gasValueBeanDao); } - + public void clear() { gasValueBeanDaoConfig.clearIdentityScope(); } diff --git a/app/src/main/java/com/casic/endoscope/greendao/GasValueBeanDao.java b/app/src/main/java/com/casic/endoscope/greendao/GasValueBeanDao.java index 5149375..6025bbf 100644 --- a/app/src/main/java/com/casic/endoscope/greendao/GasValueBeanDao.java +++ b/app/src/main/java/com/casic/endoscope/greendao/GasValueBeanDao.java @@ -12,9 +12,10 @@ import org.greenrobot.greendao.internal.DaoConfig; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** + +/** * DAO for table "GAS_VALUE_BEAN". -*/ + */ public class GasValueBeanDao extends AbstractDao { public static final String TABLENAME = "GAS_VALUE_BEAN"; @@ -34,14 +35,16 @@ public GasValueBeanDao(DaoConfig config) { super(config); } - + public GasValueBeanDao(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 + "\"GAS_VALUE_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id "\"TIME\" TEXT," + // 1: time @@ -49,7 +52,9 @@ "\"LOCATION\" TEXT);"); // 3: location } - /** 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 " : "") + "\"GAS_VALUE_BEAN\""; db.execSQL(sql); @@ -58,18 +63,18 @@ @Override protected final void bindValues(DatabaseStatement stmt, GasValueBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String time = entity.getTime(); if (time != null) { stmt.bindString(2, time); } stmt.bindLong(3, entity.getValue()); - + String location = entity.getLocation(); if (location != null) { stmt.bindString(4, location); @@ -79,18 +84,18 @@ @Override protected final void bindValues(SQLiteStatement stmt, GasValueBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String time = entity.getTime(); if (time != null) { stmt.bindString(2, time); } stmt.bindLong(3, entity.getValue()); - + String location = entity.getLocation(); if (location != null) { stmt.bindString(4, location); @@ -100,36 +105,36 @@ @Override public Long readKey(Cursor cursor, int offset) { return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } + } @Override public GasValueBean readEntity(Cursor cursor, int offset) { GasValueBean entity = new GasValueBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // time - cursor.getInt(offset + 2), // value - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3) // location + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // time + cursor.getInt(offset + 2), // value + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3) // location ); return entity; } - + @Override public void readEntity(Cursor cursor, GasValueBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); entity.setTime(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); entity.setValue(cursor.getInt(offset + 2)); entity.setLocation(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - } - + } + @Override protected final Long updateKeyAfterInsert(GasValueBean entity, long rowId) { entity.setId(rowId); return rowId; } - + @Override public Long getKey(GasValueBean entity) { - if(entity != null) { + if (entity != null) { return entity.getId(); } else { return null; @@ -145,5 +150,5 @@ protected final boolean isEntityUpdateable() { return true; } - + } diff --git a/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java b/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java index 259243d..f252abc 100644 --- a/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java +++ b/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java @@ -14,7 +14,7 @@ /** * {@inheritDoc} - * + * * @see org.greenrobot.greendao.AbstractDaoSession */ public class DaoSession extends AbstractDaoSession { @@ -34,7 +34,7 @@ registerDao(GasValueBean.class, gasValueBeanDao); } - + public void clear() { gasValueBeanDaoConfig.clearIdentityScope(); } diff --git a/app/src/main/java/com/casic/endoscope/greendao/GasValueBeanDao.java b/app/src/main/java/com/casic/endoscope/greendao/GasValueBeanDao.java index 5149375..6025bbf 100644 --- a/app/src/main/java/com/casic/endoscope/greendao/GasValueBeanDao.java +++ b/app/src/main/java/com/casic/endoscope/greendao/GasValueBeanDao.java @@ -12,9 +12,10 @@ import org.greenrobot.greendao.internal.DaoConfig; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** + +/** * DAO for table "GAS_VALUE_BEAN". -*/ + */ public class GasValueBeanDao extends AbstractDao { public static final String TABLENAME = "GAS_VALUE_BEAN"; @@ -34,14 +35,16 @@ public GasValueBeanDao(DaoConfig config) { super(config); } - + public GasValueBeanDao(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 + "\"GAS_VALUE_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id "\"TIME\" TEXT," + // 1: time @@ -49,7 +52,9 @@ "\"LOCATION\" TEXT);"); // 3: location } - /** 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 " : "") + "\"GAS_VALUE_BEAN\""; db.execSQL(sql); @@ -58,18 +63,18 @@ @Override protected final void bindValues(DatabaseStatement stmt, GasValueBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String time = entity.getTime(); if (time != null) { stmt.bindString(2, time); } stmt.bindLong(3, entity.getValue()); - + String location = entity.getLocation(); if (location != null) { stmt.bindString(4, location); @@ -79,18 +84,18 @@ @Override protected final void bindValues(SQLiteStatement stmt, GasValueBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String time = entity.getTime(); if (time != null) { stmt.bindString(2, time); } stmt.bindLong(3, entity.getValue()); - + String location = entity.getLocation(); if (location != null) { stmt.bindString(4, location); @@ -100,36 +105,36 @@ @Override public Long readKey(Cursor cursor, int offset) { return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } + } @Override public GasValueBean readEntity(Cursor cursor, int offset) { GasValueBean entity = new GasValueBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // time - cursor.getInt(offset + 2), // value - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3) // location + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // time + cursor.getInt(offset + 2), // value + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3) // location ); return entity; } - + @Override public void readEntity(Cursor cursor, GasValueBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); entity.setTime(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); entity.setValue(cursor.getInt(offset + 2)); entity.setLocation(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - } - + } + @Override protected final Long updateKeyAfterInsert(GasValueBean entity, long rowId) { entity.setId(rowId); return rowId; } - + @Override public Long getKey(GasValueBean entity) { - if(entity != null) { + if (entity != null) { return entity.getId(); } else { return null; @@ -145,5 +150,5 @@ protected final boolean isEntityUpdateable() { return true; } - + } diff --git a/app/src/main/java/com/casic/endoscope/utils/DataBaseManager.kt b/app/src/main/java/com/casic/endoscope/utils/DataBaseManager.kt index c683db1..c46dafd 100644 --- a/app/src/main/java/com/casic/endoscope/utils/DataBaseManager.kt +++ b/app/src/main/java/com/casic/endoscope/utils/DataBaseManager.kt @@ -1,6 +1,8 @@ package com.casic.endoscope.utils import com.casic.endoscope.base.BaseApplication +import com.casic.endoscope.bean.GasValueBean +import com.pengxh.kt.lite.extensions.timestampToTime class DataBaseManager private constructor() { @@ -12,4 +14,15 @@ } private var gasValueBeanDao = BaseApplication.get().getDaoSession().gasValueBeanDao + + fun loadAll(): List { + return gasValueBeanDao.loadAll() + } + + fun saveGasDensity(density: Int) { + val bean = GasValueBean() + bean.value = density + bean.time = System.currentTimeMillis().timestampToTime() + gasValueBeanDao.insert(bean) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java b/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java index 259243d..f252abc 100644 --- a/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java +++ b/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java @@ -14,7 +14,7 @@ /** * {@inheritDoc} - * + * * @see org.greenrobot.greendao.AbstractDaoSession */ public class DaoSession extends AbstractDaoSession { @@ -34,7 +34,7 @@ registerDao(GasValueBean.class, gasValueBeanDao); } - + public void clear() { gasValueBeanDaoConfig.clearIdentityScope(); } diff --git a/app/src/main/java/com/casic/endoscope/greendao/GasValueBeanDao.java b/app/src/main/java/com/casic/endoscope/greendao/GasValueBeanDao.java index 5149375..6025bbf 100644 --- a/app/src/main/java/com/casic/endoscope/greendao/GasValueBeanDao.java +++ b/app/src/main/java/com/casic/endoscope/greendao/GasValueBeanDao.java @@ -12,9 +12,10 @@ import org.greenrobot.greendao.internal.DaoConfig; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** + +/** * DAO for table "GAS_VALUE_BEAN". -*/ + */ public class GasValueBeanDao extends AbstractDao { public static final String TABLENAME = "GAS_VALUE_BEAN"; @@ -34,14 +35,16 @@ public GasValueBeanDao(DaoConfig config) { super(config); } - + public GasValueBeanDao(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 + "\"GAS_VALUE_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id "\"TIME\" TEXT," + // 1: time @@ -49,7 +52,9 @@ "\"LOCATION\" TEXT);"); // 3: location } - /** 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 " : "") + "\"GAS_VALUE_BEAN\""; db.execSQL(sql); @@ -58,18 +63,18 @@ @Override protected final void bindValues(DatabaseStatement stmt, GasValueBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String time = entity.getTime(); if (time != null) { stmt.bindString(2, time); } stmt.bindLong(3, entity.getValue()); - + String location = entity.getLocation(); if (location != null) { stmt.bindString(4, location); @@ -79,18 +84,18 @@ @Override protected final void bindValues(SQLiteStatement stmt, GasValueBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String time = entity.getTime(); if (time != null) { stmt.bindString(2, time); } stmt.bindLong(3, entity.getValue()); - + String location = entity.getLocation(); if (location != null) { stmt.bindString(4, location); @@ -100,36 +105,36 @@ @Override public Long readKey(Cursor cursor, int offset) { return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } + } @Override public GasValueBean readEntity(Cursor cursor, int offset) { GasValueBean entity = new GasValueBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // time - cursor.getInt(offset + 2), // value - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3) // location + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // time + cursor.getInt(offset + 2), // value + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3) // location ); return entity; } - + @Override public void readEntity(Cursor cursor, GasValueBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); entity.setTime(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); entity.setValue(cursor.getInt(offset + 2)); entity.setLocation(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - } - + } + @Override protected final Long updateKeyAfterInsert(GasValueBean entity, long rowId) { entity.setId(rowId); return rowId; } - + @Override public Long getKey(GasValueBean entity) { - if(entity != null) { + if (entity != null) { return entity.getId(); } else { return null; @@ -145,5 +150,5 @@ protected final boolean isEntityUpdateable() { return true; } - + } diff --git a/app/src/main/java/com/casic/endoscope/utils/DataBaseManager.kt b/app/src/main/java/com/casic/endoscope/utils/DataBaseManager.kt index c683db1..c46dafd 100644 --- a/app/src/main/java/com/casic/endoscope/utils/DataBaseManager.kt +++ b/app/src/main/java/com/casic/endoscope/utils/DataBaseManager.kt @@ -1,6 +1,8 @@ package com.casic.endoscope.utils import com.casic.endoscope.base.BaseApplication +import com.casic.endoscope.bean.GasValueBean +import com.pengxh.kt.lite.extensions.timestampToTime class DataBaseManager private constructor() { @@ -12,4 +14,15 @@ } private var gasValueBeanDao = BaseApplication.get().getDaoSession().gasValueBeanDao + + fun loadAll(): List { + return gasValueBeanDao.loadAll() + } + + fun saveGasDensity(density: Int) { + val bean = GasValueBean() + bean.value = density + bean.time = System.currentTimeMillis().timestampToTime() + gasValueBeanDao.insert(bean) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/endoscope/view/MainActivity.kt b/app/src/main/java/com/casic/endoscope/view/MainActivity.kt index 91a4ba1..7fae476 100644 --- a/app/src/main/java/com/casic/endoscope/view/MainActivity.kt +++ b/app/src/main/java/com/casic/endoscope/view/MainActivity.kt @@ -27,6 +27,7 @@ import com.casic.endoscope.extensions.init import com.casic.endoscope.extensions.toTime import com.casic.endoscope.service.VideoTranscodeService +import com.casic.endoscope.utils.DataBaseManager import com.casic.endoscope.utils.ProjectConstant import com.casic.endoscope.utils.ble.BleDeviceManager import com.casic.endoscope.utils.ble.OnDeviceConnectListener @@ -191,6 +192,11 @@ } } + binding.outputDataView.setOnClickListener { + val valueBeans = DataBaseManager.get.loadAll() + //导出到本地文件 + } + binding.upScaleButton.setOnTouchListener { _, event -> when (event.action) { MotionEvent.ACTION_DOWN -> { @@ -643,10 +649,11 @@ //[97, 97, 32, 48, 49, 32, 48, 48, 32, 48, 48, 32, 48, 48, 32, 48, 100, 32, 53, 53, 32] if (value.check()) { //解析返回值 + val density = value.convertValue() + //将数据保存在数据库 + DataBaseManager.get.saveGasDensity(density) + /***将值渲染到曲线图****************************************************************/ lifecycleScope.launch(Dispatchers.Main) { - val density = value.convertValue() - /***将值渲染到曲线图****************************************************************/ - //时间作为X轴 xAxisLabels.add(System.currentTimeMillis().timestampToTime()) diff --git a/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java b/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java index 259243d..f252abc 100644 --- a/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java +++ b/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java @@ -14,7 +14,7 @@ /** * {@inheritDoc} - * + * * @see org.greenrobot.greendao.AbstractDaoSession */ public class DaoSession extends AbstractDaoSession { @@ -34,7 +34,7 @@ registerDao(GasValueBean.class, gasValueBeanDao); } - + public void clear() { gasValueBeanDaoConfig.clearIdentityScope(); } diff --git a/app/src/main/java/com/casic/endoscope/greendao/GasValueBeanDao.java b/app/src/main/java/com/casic/endoscope/greendao/GasValueBeanDao.java index 5149375..6025bbf 100644 --- a/app/src/main/java/com/casic/endoscope/greendao/GasValueBeanDao.java +++ b/app/src/main/java/com/casic/endoscope/greendao/GasValueBeanDao.java @@ -12,9 +12,10 @@ import org.greenrobot.greendao.internal.DaoConfig; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** + +/** * DAO for table "GAS_VALUE_BEAN". -*/ + */ public class GasValueBeanDao extends AbstractDao { public static final String TABLENAME = "GAS_VALUE_BEAN"; @@ -34,14 +35,16 @@ public GasValueBeanDao(DaoConfig config) { super(config); } - + public GasValueBeanDao(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 + "\"GAS_VALUE_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id "\"TIME\" TEXT," + // 1: time @@ -49,7 +52,9 @@ "\"LOCATION\" TEXT);"); // 3: location } - /** 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 " : "") + "\"GAS_VALUE_BEAN\""; db.execSQL(sql); @@ -58,18 +63,18 @@ @Override protected final void bindValues(DatabaseStatement stmt, GasValueBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String time = entity.getTime(); if (time != null) { stmt.bindString(2, time); } stmt.bindLong(3, entity.getValue()); - + String location = entity.getLocation(); if (location != null) { stmt.bindString(4, location); @@ -79,18 +84,18 @@ @Override protected final void bindValues(SQLiteStatement stmt, GasValueBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String time = entity.getTime(); if (time != null) { stmt.bindString(2, time); } stmt.bindLong(3, entity.getValue()); - + String location = entity.getLocation(); if (location != null) { stmt.bindString(4, location); @@ -100,36 +105,36 @@ @Override public Long readKey(Cursor cursor, int offset) { return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } + } @Override public GasValueBean readEntity(Cursor cursor, int offset) { GasValueBean entity = new GasValueBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // time - cursor.getInt(offset + 2), // value - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3) // location + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // time + cursor.getInt(offset + 2), // value + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3) // location ); return entity; } - + @Override public void readEntity(Cursor cursor, GasValueBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); entity.setTime(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); entity.setValue(cursor.getInt(offset + 2)); entity.setLocation(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - } - + } + @Override protected final Long updateKeyAfterInsert(GasValueBean entity, long rowId) { entity.setId(rowId); return rowId; } - + @Override public Long getKey(GasValueBean entity) { - if(entity != null) { + if (entity != null) { return entity.getId(); } else { return null; @@ -145,5 +150,5 @@ protected final boolean isEntityUpdateable() { return true; } - + } diff --git a/app/src/main/java/com/casic/endoscope/utils/DataBaseManager.kt b/app/src/main/java/com/casic/endoscope/utils/DataBaseManager.kt index c683db1..c46dafd 100644 --- a/app/src/main/java/com/casic/endoscope/utils/DataBaseManager.kt +++ b/app/src/main/java/com/casic/endoscope/utils/DataBaseManager.kt @@ -1,6 +1,8 @@ package com.casic.endoscope.utils import com.casic.endoscope.base.BaseApplication +import com.casic.endoscope.bean.GasValueBean +import com.pengxh.kt.lite.extensions.timestampToTime class DataBaseManager private constructor() { @@ -12,4 +14,15 @@ } private var gasValueBeanDao = BaseApplication.get().getDaoSession().gasValueBeanDao + + fun loadAll(): List { + return gasValueBeanDao.loadAll() + } + + fun saveGasDensity(density: Int) { + val bean = GasValueBean() + bean.value = density + bean.time = System.currentTimeMillis().timestampToTime() + gasValueBeanDao.insert(bean) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/endoscope/view/MainActivity.kt b/app/src/main/java/com/casic/endoscope/view/MainActivity.kt index 91a4ba1..7fae476 100644 --- a/app/src/main/java/com/casic/endoscope/view/MainActivity.kt +++ b/app/src/main/java/com/casic/endoscope/view/MainActivity.kt @@ -27,6 +27,7 @@ import com.casic.endoscope.extensions.init import com.casic.endoscope.extensions.toTime import com.casic.endoscope.service.VideoTranscodeService +import com.casic.endoscope.utils.DataBaseManager import com.casic.endoscope.utils.ProjectConstant import com.casic.endoscope.utils.ble.BleDeviceManager import com.casic.endoscope.utils.ble.OnDeviceConnectListener @@ -191,6 +192,11 @@ } } + binding.outputDataView.setOnClickListener { + val valueBeans = DataBaseManager.get.loadAll() + //导出到本地文件 + } + binding.upScaleButton.setOnTouchListener { _, event -> when (event.action) { MotionEvent.ACTION_DOWN -> { @@ -643,10 +649,11 @@ //[97, 97, 32, 48, 49, 32, 48, 48, 32, 48, 48, 32, 48, 48, 32, 48, 100, 32, 53, 53, 32] if (value.check()) { //解析返回值 + val density = value.convertValue() + //将数据保存在数据库 + DataBaseManager.get.saveGasDensity(density) + /***将值渲染到曲线图****************************************************************/ lifecycleScope.launch(Dispatchers.Main) { - val density = value.convertValue() - /***将值渲染到曲线图****************************************************************/ - //时间作为X轴 xAxisLabels.add(System.currentTimeMillis().timestampToTime()) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 38c4c80..4c07edc 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -87,24 +87,40 @@ - + android:layout_weight="1" + android:orientation="horizontal"> + + + + + @@ -241,6 +257,7 @@ android:layout_width="@dimen/dp_60" android:layout_height="@dimen/dp_60" android:layout_alignParentBottom="true" + android:layout_centerHorizontal="true" android:layout_margin="@dimen/dp_7" android:background="@drawable/selector_scale_button" android:src="@drawable/ic_minus" />