1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-29 21:32:57 +01:00

Battery Info: add styled date range UI

This commit is contained in:
vanous 2021-02-14 16:46:57 +01:00
parent b9647e26c3
commit 0a2920a5ec
7 changed files with 184 additions and 26 deletions

View File

@ -190,12 +190,12 @@ public class Widget extends AppWidgetProvider {
views.setProgressBar(R.id.todaywidget_sleep_progress, sleepGoalMinutes, sleep, false); views.setProgressBar(R.id.todaywidget_sleep_progress, sleepGoalMinutes, sleep, false);
views.setProgressBar(R.id.todaywidget_distance_progress, distanceGoal, steps * stepLength, false); views.setProgressBar(R.id.todaywidget_distance_progress, distanceGoal, steps * stepLength, false);
views.setViewVisibility(R.id.todaywidget_battery_icon, View.GONE); views.setViewVisibility(R.id.todaywidget_battery_icon, View.GONE);
if (selectedDevice != null) { if (selectedDevice != null) {
String status = String.format("%1s", selectedDevice.getStateString()); String status = String.format("%1s", selectedDevice.getStateString());
if (selectedDevice.isConnected()) { if (selectedDevice.isConnected()) {
if (selectedDevice.getBatteryLevel() > 1) { if (selectedDevice.getBatteryLevel() > 1) {
views.setViewVisibility(R.id.todaywidget_battery_icon, View.VISIBLE); views.setViewVisibility(R.id.todaywidget_battery_icon, View.VISIBLE);
status = String.format("%1s%%", selectedDevice.getBatteryLevel()); status = String.format("%1s%%", selectedDevice.getBatteryLevel());
} }
} }

View File

@ -5,9 +5,9 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.Button;
import android.widget.DatePicker; import android.widget.DatePicker;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SeekBar; import android.widget.SeekBar;
import android.widget.TextView; import android.widget.TextView;
@ -15,10 +15,12 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date;
import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
public class BatteryInfoActivity extends AbstractGBActivity { public class BatteryInfoActivity extends AbstractGBActivity {
private static final Logger LOG = LoggerFactory.getLogger(BatteryInfoActivity.class); private static final Logger LOG = LoggerFactory.getLogger(BatteryInfoActivity.class);
@ -59,9 +61,14 @@ public class BatteryInfoActivity extends AbstractGBActivity {
TextView battery_status_device_name_text = (TextView) findViewById(R.id.battery_status_device_name); TextView battery_status_device_name_text = (TextView) findViewById(R.id.battery_status_device_name);
TextView battery_status_battery_voltage = (TextView) findViewById(R.id.battery_status_battery_voltage); TextView battery_status_battery_voltage = (TextView) findViewById(R.id.battery_status_battery_voltage);
final TextView battery_status_date_from_text = (TextView) findViewById(R.id.battery_status_date_from_text);
final TextView battery_status_date_to_text = (TextView) findViewById(R.id.battery_status_date_to_text);
SeekBar battery_status_time_span_seekbar = (SeekBar) findViewById(R.id.battery_status_time_span_seekbar); SeekBar battery_status_time_span_seekbar = (SeekBar) findViewById(R.id.battery_status_time_span_seekbar);
final TextView battery_status_time_span_text = (TextView) findViewById(R.id.battery_status_time_span_text); final TextView battery_status_time_span_text = (TextView) findViewById(R.id.battery_status_time_span_text);
LinearLayout battery_status_date_to_layout = (LinearLayout) findViewById(R.id.battery_status_date_to_layout);
battery_status_time_span_seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { battery_status_time_span_seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override @Override
@ -69,36 +76,38 @@ public class BatteryInfoActivity extends AbstractGBActivity {
String text; String text;
switch (i) { switch (i) {
case 0: case 0:
text = "Day"; text = getString(R.string.calendar_day);
timeSpanDays = 1; timeSpanDays = 1;
break; break;
case 1: case 1:
text = "Week"; text = getString(R.string.calendar_week);
timeSpanDays = 7; timeSpanDays = 7;
break; break;
case 2: case 2:
text = "Two weeks"; text = getString(R.string.calendar_two_weeks);
timeSpanDays = 14; timeSpanDays = 14;
break; break;
case 3: case 3:
text = "Month"; text = getString(R.string.calendar_month);
timeSpanDays = 30; timeSpanDays = 30;
break; break;
case 4: case 4:
text = "Six months"; text = getString(R.string.calendar_six_months);
timeSpanDays = 182; timeSpanDays = 182;
break; break;
case 5: case 5:
text = "Year"; text = getString(R.string.calendar_year);
timeSpanDays = 365; timeSpanDays = 365;
break; break;
default: default:
text = "Two weeks"; text = getString(R.string.calendar_two_weeks);
timeSpanDays = 14; timeSpanDays = 14;
} }
battery_status_time_span_text.setText(text); battery_status_time_span_text.setText(text);
timeFrom = timeTo - 24 * 3600 * timeSpanDays; timeFrom = timeTo - 24 * 3600 * timeSpanDays;
battery_status_date_from_text.setText(DateTimeUtils.formatDate(new Date(timeFrom * 1000L)));
battery_status_date_to_text.setText(DateTimeUtils.formatDate(new Date(timeTo * 1000L)));
batteryInfoChartFragment.setDateAndGetData(gbDevice, timeFrom, timeTo); batteryInfoChartFragment.setDateAndGetData(gbDevice, timeFrom, timeTo);
} }
@ -114,8 +123,8 @@ public class BatteryInfoActivity extends AbstractGBActivity {
} }
}); });
Button battery_status_calendar_button = findViewById(R.id.battery_status_calendar_button); //Button battery_status_calendar_button = findViewById(R.id.battery_status_calendar_button);
battery_status_calendar_button.setOnClickListener(new View.OnClickListener() { battery_status_date_to_layout.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -132,6 +141,8 @@ public class BatteryInfoActivity extends AbstractGBActivity {
date.set(year, monthOfYear, dayOfMonth); date.set(year, monthOfYear, dayOfMonth);
timeTo = (int) (date.getTimeInMillis() / 1000); timeTo = (int) (date.getTimeInMillis() / 1000);
timeFrom = timeTo - 24 * 3600 * timeSpanDays; timeFrom = timeTo - 24 * 3600 * timeSpanDays;
battery_status_date_from_text.setText(DateTimeUtils.formatDate(new Date(timeFrom * 1000L)));
battery_status_date_to_text.setText(DateTimeUtils.formatDate(new Date(timeTo * 1000L)));
batteryInfoChartFragment.setDateAndGetData(gbDevice, timeFrom, timeTo); batteryInfoChartFragment.setDateAndGetData(gbDevice, timeFrom, timeTo);
} }
}, currentDate.get(Calendar.YEAR), currentDate.get(Calendar.MONTH), currentDate.get(Calendar.DATE)).show(); }, currentDate.get(Calendar.YEAR), currentDate.get(Calendar.MONTH), currentDate.get(Calendar.DATE)).show();

View File

@ -118,7 +118,7 @@ public class BatteryInfoChartFragment extends AbstractChartFragment {
} }
} }
LineDataSet dataSet = new LineDataSet(entries, "Battery level"); LineDataSet dataSet = new LineDataSet(entries, getString(R.string.battery_level));
dataSet.setLineWidth(2.2f); dataSet.setLineWidth(2.2f);
dataSet.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER); dataSet.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
dataSet.setCubicIntensity(0.1f); dataSet.setCubicIntensity(0.1f);
@ -238,8 +238,7 @@ public class BatteryInfoChartFragment extends AbstractChartFragment {
int ts = (int) value; int ts = (int) value;
cal.setTimeInMillis(tsTranslation.toOriginalValue(ts) * 1000L); cal.setTimeInMillis(tsTranslation.toOriginalValue(ts) * 1000L);
Date date = cal.getTime(); Date date = cal.getTime();
String dateString = annotationDateFormat.format(date); return annotationDateFormat.format(date);
return dateString;
} }
} }
@ -289,7 +288,6 @@ public class BatteryInfoChartFragment extends AbstractChartFragment {
// center the marker horizontally and vertically // center the marker horizontally and vertically
mOffset = new MPPointF(-(getWidth() / 2) + 20, -getHeight() - 10); mOffset = new MPPointF(-(getWidth() / 2) + 20, -getHeight() - 10);
} }
return mOffset; return mOffset;
} }
} }

View File

@ -0,0 +1,3 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:tint="#7E7E7E" android:viewportWidth="24" android:viewportHeight="24">
<path android:fillColor="@android:color/white" android:pathData="M19 3h-1V1h-2v2H8V1H6v2H5C3.89 3 3 3.9 3 5v14c0 1.1 0.89 2 2 2h14c1.1 0 2-0.9 2-2V5c0-1.1-0.9-2-2-2zm0 16H5V9h14v10zm0-12H5V5h14v2zM7 11h5v5H7z"/>
</vector>

View File

@ -0,0 +1,3 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:tint="#7E7E7E" android:viewportWidth="24" android:viewportHeight="24">
<path android:fillColor="@android:color/white" android:pathData="M19 4h-1V2h-2v2H8V2H6v2H5C3.89 4 3.01 4.9 3.01 6L3 20c0 1.1 0.89 2 2 2h14c1.1 0 2-0.9 2-2V6c0-1.1-0.9-2-2-2zm0 16H5V10h14v10zm0-12H5V6h14v2zm-7 5h5v5h-5z"/>
</vector>

View File

@ -27,7 +27,7 @@
android:id="@+id/battery_status_device_icon" android:id="@+id/battery_status_device_icon"
android:layout_width="80dp" android:layout_width="80dp"
android:layout_height="80dp" android:layout_height="80dp"
android:contentDescription="TODO" android:contentDescription="@string/icon_placeholder"
app:srcCompat="@drawable/ic_devices_other" /> app:srcCompat="@drawable/ic_devices_other" />
<LinearLayout <LinearLayout
@ -89,13 +89,6 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<TextView
android:id="@+id/battery_status_time_span_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textSize="20sp" />
<SeekBar <SeekBar
android:id="@+id/battery_status_time_span_seekbar" android:id="@+id/battery_status_time_span_seekbar"
style="@style/Widget.AppCompat.SeekBar.Discrete" style="@style/Widget.AppCompat.SeekBar.Discrete"
@ -104,11 +97,152 @@
android:max="5" android:max="5"
android:progress="1" /> android:progress="1" />
<Button <LinearLayout
android:id="@+id/battery_status_calendar_button"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Choose end date" /> android:layout_marginTop="0dp"
android:layout_marginBottom="10dp"
android:baselineAligned="false"
android:gravity="bottom|center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center|top"
android:layout_marginStart="1dp"
android:layout_marginEnd="1dp"
android:layout_weight="1"
android:gravity="center|top"
android:orientation="vertical">
<ImageView
android:layout_width="19dp"
android:layout_height="19dp"
android:layout_gravity="center"
android:contentDescription="@string/icon_placeholder"
android:scaleX="-1"
app:srcCompat="@drawable/ic_calendar_to" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:maxLines="2"
android:scrollHorizontally="false"
android:text="@string/activity_filter_date_from"
android:textAllCaps="true"
android:textColor="@color/accent"
android:textStyle="bold" />
<TextView
android:id="@+id/battery_status_date_from_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="sans-serif-black"
android:gravity="center"
android:maxLines="1"
android:scrollHorizontally="false"
android:text="@string/lorem_ipsum"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center|top"
android:layout_marginStart="1dp"
android:layout_marginEnd="1dp"
android:layout_weight="1"
android:gravity="center|top"
android:orientation="vertical">
<ImageView
android:layout_width="19dp"
android:layout_height="19dp"
android:layout_gravity="center"
android:contentDescription="@string/candidate_item_device_image"
app:srcCompat="@drawable/ic_date_range" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:maxLines="2"
android:scrollHorizontally="false"
android:text="@string/activity_detail_duration_label"
android:textAllCaps="true"
android:textColor="@color/accent"
android:textStyle="bold" />
<TextView
android:id="@+id/battery_status_time_span_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="sans-serif-black"
android:gravity="center"
android:maxLines="1"
android:scrollHorizontally="false"
android:text="@string/lorem_ipsum"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/battery_status_date_to_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center|top"
android:layout_marginStart="1dp"
android:layout_marginEnd="1dp"
android:layout_weight="1"
android:gravity="center|top"
android:orientation="vertical">
<ImageView
android:layout_width="19dp"
android:layout_height="19dp"
android:layout_gravity="center"
android:contentDescription="@string/candidate_item_device_image"
app:srcCompat="@drawable/ic_calendar_to" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:maxLines="2"
android:scrollHorizontally="false"
android:text="@string/activity_filter_date_to"
android:textAllCaps="true"
android:textColor="@color/accent"
android:textStyle="bold" />
<TextView
android:id="@+id/battery_status_date_to_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="sans-serif-black"
android:gravity="center"
android:maxLines="1"
android:scrollHorizontally="false"
android:text="@string/lorem_ipsum"
android:textColor="@color/accent"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

View File

@ -25,7 +25,15 @@
<string name="controlcenter_snackbar_connecting">Connecting…</string> <string name="controlcenter_snackbar_connecting">Connecting…</string>
<string name="controlcenter_snackbar_requested_screenshot">Taking a screenshot of the device</string> <string name="controlcenter_snackbar_requested_screenshot">Taking a screenshot of the device</string>
<string name="controlcenter_calibrate_device">Calibrate Device</string> <string name="controlcenter_calibrate_device">Calibrate Device</string>
<!-- Strings related to battery Info Activity -->
<string name="battery_detail_activity_title">Battery info</string> <string name="battery_detail_activity_title">Battery info</string>
<string name="battery_level">Battery level</string>
<string name="calendar_day">Day</string>
<string name="calendar_week">Week</string>
<string name="calendar_two_weeks">Two weeks</string>
<string name="calendar_month">Month</string>
<string name="calendar_six_months">Six months</string>
<string name="calendar_year">Year</string>
<!-- Strings related to Debug Activity --> <!-- Strings related to Debug Activity -->
<string name="title_activity_debug">Debug</string> <string name="title_activity_debug">Debug</string>
<string name="debugactivity_really_factoryreset_title">Really factory reset?</string> <string name="debugactivity_really_factoryreset_title">Really factory reset?</string>
@ -1118,6 +1126,7 @@
<string name="medley">Medley</string> <string name="medley">Medley</string>
<string name="devicetype_nut_mini">Nut mini</string> <string name="devicetype_nut_mini">Nut mini</string>
<string name="qhybrid_calibration_align_hint">align hands to 12:00</string> <string name="qhybrid_calibration_align_hint">align hands to 12:00</string>
<string translatable="false" name="lorem_ipsum">Lorem Ipsum</string>
<plurals name="widget_alarm_target_hours"> <plurals name="widget_alarm_target_hours">
<item quantity="one">%d hour</item> <item quantity="one">%d hour</item>
<item quantity="two">%d hours</item> <item quantity="two">%d hours</item>