1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-03 08:52:58 +01:00

UM25: added some fields to UI

This commit is contained in:
Daniel Dakhno 2021-10-03 02:43:42 +02:00
parent a6ed6c91da
commit 1a892aa159
4 changed files with 104 additions and 18 deletions

View File

@ -20,10 +20,16 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.um25.Support.UM25Sup
public class DataActivity extends AbstractGBActivity {
private HashMap<Integer, TextView> valueViews = new HashMap<>(ValueDisplay.values().length);
private TextView chargeDurationTextView;
private enum ValueDisplay{
VOLTAGE("voltage", "%.3fV", R.id.um25_text_voltage, 1000),
CURRENT("current", "%.4fA", R.id.um25_text_current, 10000),
CURRENT_SUM("chargedCurrent", "%.0fmAh", R.id.um25_text_current_sum, 1),
WATTAGE("wattage", "%.3fW", R.id.um25_text_wattage, 1000),
WATTAGE_SUM("chargedWattage", "%.3fWh", R.id.um25_text_wattage_sum, 1000),
TEMPERATURE_CELCIUS("temperatureCelcius", "%.0f°", R.id.um25_text_temperature, 1),
CABLE_RESISTANCE("cableResistance", "%.1fΩ", R.id.um25_cable_resistance, 10),
;
private String variableName;
@ -43,6 +49,8 @@ public class DataActivity extends AbstractGBActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_um25_data);
chargeDurationTextView = findViewById(R.id.um25_text_charge_duration);
}
@Override
@ -81,6 +89,19 @@ public class DataActivity extends AbstractGBActivity {
e.printStackTrace();
}
}
int durationSeconds = data.getChargingSeconds();
int hours = durationSeconds / 3600;
int minutes = durationSeconds % 3600 / 60;
int seconds = durationSeconds % 60;
String timeString = String.format("%02d:%02d:%02d", hours, minutes, seconds);
int thresholdCurrent = data.getThresholdCurrent();
int current = data.getCurrent() / 10;
chargeDurationTextView.setTextColor(current > thresholdCurrent ? 0xff669900 : 0xffcc0000);
chargeDurationTextView.setText(timeString);
}
private BroadcastReceiver measurementReceiver = new BroadcastReceiver() {

View File

@ -74,7 +74,7 @@ public class MeasurementData implements Serializable {
}
public int getThresholdCurrent() {
return thresholdCurrent;
return thresholdCurrent * 10;
}
public int getChargingSeconds() {

View File

@ -1,36 +1,100 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/um25_text_voltage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:textColor="@android:color/holo_green_dark"
android:textSize="@dimen/um25_value_text_size" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center_horizontal"
android:textSize="@dimen/um25_value_text_size"
android:textColor="@android:color/holo_green_dark"/>
android:orientation="vertical">
<TextView
android:id="@+id/um25_text_current"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/holo_red_dark"
android:textSize="@dimen/um25_value_text_size" />
<TextView
android:id="@+id/um25_text_current_sum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/holo_red_dark"
android:textSize="@dimen/um25_value_text_size_small" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="vertical"
android:gravity="center_horizontal">
<TextView
android:id="@+id/um25_text_wattage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:textColor="@android:color/white"
android:textSize="@dimen/um25_value_text_size" />
<TextView
android:id="@+id/um25_text_wattage_sum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:textSize="@dimen/um25_value_text_size_small" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:id="@+id/um25_text_charge_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/um25_text_current"
android:gravity="center_horizontal"
android:textSize="@dimen/um25_value_text_size"
android:textColor="@android:color/holo_red_dark"/>
android:layout_margin="10dp"
android:textColor="@android:color/white"
android:textSize="@dimen/um25_value_text_size" />
<TextView
android:layout_width="match_parent"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/um25_text_wattage"
android:gravity="center_horizontal"
android:textSize="@dimen/um25_value_text_size"
android:textColor="@android:color/white"/>
android:layout_margin="10dp"
android:orientation="horizontal">
<TextView
android:id="@+id/um25_text_temperature"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:textSize="@dimen/um25_value_text_size_small"
android:layout_marginEnd="20dp"/>
<TextView
android:id="@+id/um25_cable_resistance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:textSize="@dimen/um25_value_text_size_small" />
</LinearLayout>
</LinearLayout>

View File

@ -15,4 +15,5 @@ http://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout
<dimen name="fab_margin">16dp</dimen>
<dimen name="dialog_margin">20dp</dimen>
<dimen name="um25_value_text_size">60dp</dimen>
<dimen name="um25_value_text_size_small">30dp</dimen>
</resources>