mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-01 22:43:00 +01:00
Battery Info: add styled date range UI
This commit is contained in:
parent
b9647e26c3
commit
0a2920a5ec
@ -190,12 +190,12 @@ public class Widget extends AppWidgetProvider {
|
||||
views.setProgressBar(R.id.todaywidget_sleep_progress, sleepGoalMinutes, sleep, false);
|
||||
views.setProgressBar(R.id.todaywidget_distance_progress, distanceGoal, steps * stepLength, false);
|
||||
views.setViewVisibility(R.id.todaywidget_battery_icon, View.GONE);
|
||||
|
||||
if (selectedDevice != null) {
|
||||
String status = String.format("%1s", selectedDevice.getStateString());
|
||||
if (selectedDevice.isConnected()) {
|
||||
if (selectedDevice.getBatteryLevel() > 1) {
|
||||
views.setViewVisibility(R.id.todaywidget_battery_icon, View.VISIBLE);
|
||||
|
||||
status = String.format("%1s%%", selectedDevice.getBatteryLevel());
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,9 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.DatePicker;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
@ -15,10 +15,12 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
||||
|
||||
public class BatteryInfoActivity extends AbstractGBActivity {
|
||||
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_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);
|
||||
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() {
|
||||
|
||||
@Override
|
||||
@ -69,36 +76,38 @@ public class BatteryInfoActivity extends AbstractGBActivity {
|
||||
String text;
|
||||
switch (i) {
|
||||
case 0:
|
||||
text = "Day";
|
||||
text = getString(R.string.calendar_day);
|
||||
timeSpanDays = 1;
|
||||
break;
|
||||
case 1:
|
||||
text = "Week";
|
||||
text = getString(R.string.calendar_week);
|
||||
timeSpanDays = 7;
|
||||
break;
|
||||
case 2:
|
||||
text = "Two weeks";
|
||||
text = getString(R.string.calendar_two_weeks);
|
||||
timeSpanDays = 14;
|
||||
break;
|
||||
case 3:
|
||||
text = "Month";
|
||||
text = getString(R.string.calendar_month);
|
||||
timeSpanDays = 30;
|
||||
break;
|
||||
case 4:
|
||||
text = "Six months";
|
||||
text = getString(R.string.calendar_six_months);
|
||||
timeSpanDays = 182;
|
||||
break;
|
||||
case 5:
|
||||
text = "Year";
|
||||
text = getString(R.string.calendar_year);
|
||||
timeSpanDays = 365;
|
||||
break;
|
||||
default:
|
||||
text = "Two weeks";
|
||||
text = getString(R.string.calendar_two_weeks);
|
||||
timeSpanDays = 14;
|
||||
}
|
||||
|
||||
battery_status_time_span_text.setText(text);
|
||||
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);
|
||||
}
|
||||
|
||||
@ -114,8 +123,8 @@ public class BatteryInfoActivity extends AbstractGBActivity {
|
||||
}
|
||||
});
|
||||
|
||||
Button battery_status_calendar_button = findViewById(R.id.battery_status_calendar_button);
|
||||
battery_status_calendar_button.setOnClickListener(new View.OnClickListener() {
|
||||
//Button battery_status_calendar_button = findViewById(R.id.battery_status_calendar_button);
|
||||
battery_status_date_to_layout.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
@ -132,6 +141,8 @@ public class BatteryInfoActivity extends AbstractGBActivity {
|
||||
date.set(year, monthOfYear, dayOfMonth);
|
||||
timeTo = (int) (date.getTimeInMillis() / 1000);
|
||||
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);
|
||||
}
|
||||
}, currentDate.get(Calendar.YEAR), currentDate.get(Calendar.MONTH), currentDate.get(Calendar.DATE)).show();
|
||||
|
@ -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.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
|
||||
dataSet.setCubicIntensity(0.1f);
|
||||
@ -238,8 +238,7 @@ public class BatteryInfoChartFragment extends AbstractChartFragment {
|
||||
int ts = (int) value;
|
||||
cal.setTimeInMillis(tsTranslation.toOriginalValue(ts) * 1000L);
|
||||
Date date = cal.getTime();
|
||||
String dateString = annotationDateFormat.format(date);
|
||||
return dateString;
|
||||
return annotationDateFormat.format(date);
|
||||
}
|
||||
}
|
||||
|
||||
@ -289,7 +288,6 @@ public class BatteryInfoChartFragment extends AbstractChartFragment {
|
||||
// center the marker horizontally and vertically
|
||||
mOffset = new MPPointF(-(getWidth() / 2) + 20, -getHeight() - 10);
|
||||
}
|
||||
|
||||
return mOffset;
|
||||
}
|
||||
}
|
||||
|
3
app/src/main/res/drawable/ic_calendar_from.xml
Normal file
3
app/src/main/res/drawable/ic_calendar_from.xml
Normal 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>
|
3
app/src/main/res/drawable/ic_calendar_to.xml
Normal file
3
app/src/main/res/drawable/ic_calendar_to.xml
Normal 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>
|
@ -27,7 +27,7 @@
|
||||
android:id="@+id/battery_status_device_icon"
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="80dp"
|
||||
android:contentDescription="TODO"
|
||||
android:contentDescription="@string/icon_placeholder"
|
||||
app:srcCompat="@drawable/ic_devices_other" />
|
||||
|
||||
<LinearLayout
|
||||
@ -89,13 +89,6 @@
|
||||
android:layout_height="match_parent"
|
||||
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
|
||||
android:id="@+id/battery_status_time_span_seekbar"
|
||||
style="@style/Widget.AppCompat.SeekBar.Discrete"
|
||||
@ -104,11 +97,152 @@
|
||||
android:max="5"
|
||||
android:progress="1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/battery_status_calendar_button"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
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>
|
||||
|
@ -25,7 +25,15 @@
|
||||
<string name="controlcenter_snackbar_connecting">Connecting…</string>
|
||||
<string name="controlcenter_snackbar_requested_screenshot">Taking a screenshot of the 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_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 -->
|
||||
<string name="title_activity_debug">Debug</string>
|
||||
<string name="debugactivity_really_factoryreset_title">Really factory reset?</string>
|
||||
@ -1118,6 +1126,7 @@
|
||||
<string name="medley">Medley</string>
|
||||
<string name="devicetype_nut_mini">Nut mini</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">
|
||||
<item quantity="one">%d hour</item>
|
||||
<item quantity="two">%d hours</item>
|
||||
|
Loading…
Reference in New Issue
Block a user