Skip to content

Commit

Permalink
fix: don't overwrite content of TextViews if we have no data to display
Browse files Browse the repository at this point in the history
  • Loading branch information
marcnause committed Nov 20, 2024
1 parent 89f41f3 commit 71ed328
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,19 @@ public boolean onOptionsItemSelected(MenuItem item) {

protected abstract class SensorDataFetch {

private boolean isSensorDataAcquired;

protected float getTimeElapsed() {
return (System.currentTimeMillis() - getStartTime()) / 1000f;
}

protected boolean isSensorDataAcquired() {
return isSensorDataAcquired;
}

protected void execute() {
getSensorData();
isSensorDataAcquired = true;
updateUi();
}

Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/io/pslab/sensors/SensorADS1115.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ public void getSensorData() {

@Override
public void updateUi() {
tvSensorADS1115.setText(String.valueOf(dataADS1115));
if (isSensorDataAcquired()) {
tvSensorADS1115.setText(String.valueOf(dataADS1115));
}

LineDataSet dataSet = new LineDataSet(entries, getString(R.string.bx));
dataSet.setDrawCircles(true);
Expand Down
15 changes: 9 additions & 6 deletions app/src/main/java/io/pslab/sensors/SensorAPDS9960.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,14 @@ public void getSensorData() {

public void updateUi() {
if (spinnerMode.getSelectedItemPosition() == 0) {
tvSensorAPDS9960Red.setText(DataFormatter.formatDouble(dataAPDS9960Color[0], DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorAPDS9960Green.setText(DataFormatter.formatDouble(dataAPDS9960Color[1], DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorAPDS9960Blue.setText(DataFormatter.formatDouble(dataAPDS9960Color[2], DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorAPDS9960Clear.setText(DataFormatter.formatDouble(dataAPDS9960Color[3], DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorAPDS9960Proximity.setText(DataFormatter.formatDouble(dataAPDS9960Proximity, DataFormatter.HIGH_PRECISION_FORMAT));

if (isSensorDataAcquired()) {
tvSensorAPDS9960Red.setText(DataFormatter.formatDouble(dataAPDS9960Color[0], DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorAPDS9960Green.setText(DataFormatter.formatDouble(dataAPDS9960Color[1], DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorAPDS9960Blue.setText(DataFormatter.formatDouble(dataAPDS9960Color[2], DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorAPDS9960Clear.setText(DataFormatter.formatDouble(dataAPDS9960Color[3], DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorAPDS9960Proximity.setText(DataFormatter.formatDouble(dataAPDS9960Proximity, DataFormatter.HIGH_PRECISION_FORMAT));
}

LineDataSet dataSet1 = new LineDataSet(entriesLux, getString(R.string.light_lux));
LineDataSet dataSet2 = new LineDataSet(entriesProximity, getString(R.string.proximity));
Expand All @@ -220,7 +223,7 @@ public void updateUi() {
mChartProximity.notifyDataSetChanged();
mChartProximity.setVisibleXRangeMaximum(10);
mChartProximity.moveViewToX(timeElapsed);
} else {
} else if (isSensorDataAcquired()) {
switch (dataAPDS9960Gesture) {
case 1:
tvSensorAPDS9960Gesture.setText(R.string.up);
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/java/io/pslab/sensors/SensorBMP180.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,12 @@ public void getSensorData() {
}

public void updateUi() {
tvSensorBMP180Temp.setText(DataFormatter.formatDouble(dataBMP180[0], DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorBMP180Altitude.setText(DataFormatter.formatDouble(dataBMP180[1], DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorBMP180Pressure.setText(DataFormatter.formatDouble(dataBMP180[2], DataFormatter.HIGH_PRECISION_FORMAT));

if (isSensorDataAcquired()) {
tvSensorBMP180Temp.setText(DataFormatter.formatDouble(dataBMP180[0], DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorBMP180Altitude.setText(DataFormatter.formatDouble(dataBMP180[1], DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorBMP180Pressure.setText(DataFormatter.formatDouble(dataBMP180[2], DataFormatter.HIGH_PRECISION_FORMAT));
}

LineDataSet dataSet1 = new LineDataSet(entriesTemperature, getString(R.string.temperature));
LineDataSet dataSet2 = new LineDataSet(entriesAltitude, getString(R.string.altitude));
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/java/io/pslab/sensors/SensorCCS811.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,11 @@ public void getSensorData() {
}

public void updateUi() {
tvSensorCCS811eCO2.setText(DataFormatter.formatDouble(dataCCS811eCO2, DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorCCS811TVOC.setText(DataFormatter.formatDouble(dataCCS811TVOC, DataFormatter.HIGH_PRECISION_FORMAT));

if (isSensorDataAcquired()) {
tvSensorCCS811eCO2.setText(DataFormatter.formatDouble(dataCCS811eCO2, DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorCCS811TVOC.setText(DataFormatter.formatDouble(dataCCS811TVOC, DataFormatter.HIGH_PRECISION_FORMAT));
}

LineDataSet dataSet1 = new LineDataSet(entrieseCO2, getString(R.string.eCO2));
LineDataSet dataSet2 = new LineDataSet(entriesTVOC, getString(R.string.eTVOC));
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/java/io/pslab/sensors/SensorHMC5883L.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,12 @@ public void getSensorData() {
}

public void updateUi() {
tvSensorHMC5883Lbx.setText(DataFormatter.formatDouble(dataHMC5883L.get(0), DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorHMC5883Lby.setText(DataFormatter.formatDouble(dataHMC5883L.get(1), DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorHMC5883Lbz.setText(DataFormatter.formatDouble(dataHMC5883L.get(2), DataFormatter.HIGH_PRECISION_FORMAT));

if (isSensorDataAcquired()) {
tvSensorHMC5883Lbx.setText(DataFormatter.formatDouble(dataHMC5883L.get(0), DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorHMC5883Lby.setText(DataFormatter.formatDouble(dataHMC5883L.get(1), DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorHMC5883Lbz.setText(DataFormatter.formatDouble(dataHMC5883L.get(2), DataFormatter.HIGH_PRECISION_FORMAT));
}

LineDataSet dataset1 = new LineDataSet(entriesBx, getString(R.string.bx));
LineDataSet dataSet2 = new LineDataSet(entriesBy, getString(R.string.by));
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/java/io/pslab/sensors/SensorMLX90614.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,11 @@ public void getSensorData() {
}

public void updateUi() {
tvSensorMLX90614ObjectTemp.setText(DataFormatter.formatDouble(dataMLX90614ObjectTemp, DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorMLX90614AmbientTemp.setText(DataFormatter.formatDouble(dataMLX90614AmbientTemp, DataFormatter.HIGH_PRECISION_FORMAT));

if (isSensorDataAcquired()) {
tvSensorMLX90614ObjectTemp.setText(DataFormatter.formatDouble(dataMLX90614ObjectTemp, DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorMLX90614AmbientTemp.setText(DataFormatter.formatDouble(dataMLX90614AmbientTemp, DataFormatter.HIGH_PRECISION_FORMAT));
}

LineDataSet dataSet1 = new LineDataSet(entriesObjectTemperature, getString(R.string.object_temp));
LineDataSet dataSet2 = new LineDataSet(entriesAmbientTemperature, getString(R.string.ambient_temp));
Expand Down
17 changes: 10 additions & 7 deletions app/src/main/java/io/pslab/sensors/SensorMPU6050.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,16 @@ public void getSensorData() {
}

public void updateUi() {
tvSensorMPU6050ax.setText(DataFormatter.formatDouble(dataMPU6050.get(0), DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorMPU6050ay.setText(DataFormatter.formatDouble(dataMPU6050.get(1), DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorMPU6050az.setText(DataFormatter.formatDouble(dataMPU6050.get(2), DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorMPU6050gx.setText(DataFormatter.formatDouble(dataMPU6050.get(4), DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorMPU6050gy.setText(DataFormatter.formatDouble(dataMPU6050.get(5), DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorMPU6050gz.setText(DataFormatter.formatDouble(dataMPU6050.get(6), DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorMPU6050temp.setText(DataFormatter.formatDouble(dataMPU6050.get(3), DataFormatter.HIGH_PRECISION_FORMAT));

if (isSensorDataAcquired()) {
tvSensorMPU6050ax.setText(DataFormatter.formatDouble(dataMPU6050.get(0), DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorMPU6050ay.setText(DataFormatter.formatDouble(dataMPU6050.get(1), DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorMPU6050az.setText(DataFormatter.formatDouble(dataMPU6050.get(2), DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorMPU6050gx.setText(DataFormatter.formatDouble(dataMPU6050.get(4), DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorMPU6050gy.setText(DataFormatter.formatDouble(dataMPU6050.get(5), DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorMPU6050gz.setText(DataFormatter.formatDouble(dataMPU6050.get(6), DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorMPU6050temp.setText(DataFormatter.formatDouble(dataMPU6050.get(3), DataFormatter.HIGH_PRECISION_FORMAT));
}

LineDataSet dataset1 = new LineDataSet(entriesAx, getString(R.string.ax));
LineDataSet dataSet2 = new LineDataSet(entriesAy, getString(R.string.ay));
Expand Down
18 changes: 11 additions & 7 deletions app/src/main/java/io/pslab/sensors/SensorMPU925X.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,17 @@ public void getSensorData() {
}

public void updateUi() {
tvSensorMPU925Xax.setText(DataFormatter.formatDouble(dataAccel[0], DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorMPU925Xay.setText(DataFormatter.formatDouble(dataAccel[1], DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorMPU925Xaz.setText(DataFormatter.formatDouble(dataAccel[2], DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorMPU925Xgx.setText(DataFormatter.formatDouble(dataGyro[0], DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorMPU925Xgy.setText(DataFormatter.formatDouble(dataGyro[1], DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorMPU925Xgz.setText(DataFormatter.formatDouble(dataGyro[2], DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorMPU925Xtemp.setText(DataFormatter.formatDouble(dataTemp, DataFormatter.HIGH_PRECISION_FORMAT));

if (isSensorDataAcquired()) {
tvSensorMPU925Xax.setText(DataFormatter.formatDouble(dataAccel[0], DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorMPU925Xay.setText(DataFormatter.formatDouble(dataAccel[1], DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorMPU925Xaz.setText(DataFormatter.formatDouble(dataAccel[2], DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorMPU925Xgx.setText(DataFormatter.formatDouble(dataGyro[0], DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorMPU925Xgy.setText(DataFormatter.formatDouble(dataGyro[1], DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorMPU925Xgz.setText(DataFormatter.formatDouble(dataGyro[2], DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorMPU925Xtemp.setText(DataFormatter.formatDouble(dataTemp, DataFormatter.HIGH_PRECISION_FORMAT));
}

LineDataSet dataSet1 = new LineDataSet(entriesAx, getString(R.string.ax));
LineDataSet dataSet2 = new LineDataSet(entriesAy, getString(R.string.ay));
LineDataSet dataSet3 = new LineDataSet(entriesAz, getString(R.string.az));
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/java/io/pslab/sensors/SensorSHT21.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,11 @@ public void getSensorData() {
}

public void updateUi() {
tvSensorSHT21Temp.setText(DataFormatter.formatDouble(dataSHT21Temp.get(0), DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorSHT21Humidity.setText(DataFormatter.formatDouble(dataSHT21Humidity.get(0), DataFormatter.HIGH_PRECISION_FORMAT));

if (isSensorDataAcquired()) {
tvSensorSHT21Temp.setText(DataFormatter.formatDouble(dataSHT21Temp.get(0), DataFormatter.HIGH_PRECISION_FORMAT));
tvSensorSHT21Humidity.setText(DataFormatter.formatDouble(dataSHT21Humidity.get(0), DataFormatter.HIGH_PRECISION_FORMAT));
}

LineDataSet dataSet1 = new LineDataSet(entriesTemperature, getString(R.string.temperature));
LineDataSet dataSet2 = new LineDataSet(entriesHumidity, getString(R.string.humidity));
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/java/io/pslab/sensors/SensorTSL2561.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,12 @@ public void getSensorData() {
}

public void updateUi() {
tvSensorTSL2561FullSpectrum.setText(String.valueOf(dataTSL2561[0]));
tvSensorTSL2561Infrared.setText(String.valueOf(dataTSL2561[1]));
tvSensorTSL2561Visible.setText(String.valueOf(dataTSL2561[2]));

if (isSensorDataAcquired()) {
tvSensorTSL2561FullSpectrum.setText(String.valueOf(dataTSL2561[0]));
tvSensorTSL2561Infrared.setText(String.valueOf(dataTSL2561[1]));
tvSensorTSL2561Visible.setText(String.valueOf(dataTSL2561[2]));
}

LineDataSet dataset1 = new LineDataSet(entriesFull, getString(R.string.full));
LineDataSet dataSet2 = new LineDataSet(entriesInfrared, getString(R.string.infrared));
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/io/pslab/sensors/SensorVL53L0X.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ public void getSensorData() {
}

public void updateUi() {
tvSensorVL53L0X.setText(String.valueOf(dataVL53L0X));

if (isSensorDataAcquired()) {
tvSensorVL53L0X.setText(String.valueOf(dataVL53L0X));
}

LineDataSet dataSet = new LineDataSet(entries, getString(R.string.bx));
dataSet.setDrawCircles(true);
Expand Down

0 comments on commit 71ed328

Please sign in to comment.