1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-20 23:57:46 +01:00

Dashboard: Add preference for drawing midnight at bottom of 24h chart

This commit is contained in:
Arjan Schrijver 2024-04-18 20:04:32 +02:00
parent a2c861f66c
commit f186053dab
3 changed files with 33 additions and 10 deletions

View File

@ -137,6 +137,9 @@ public class DashboardTodayWidget extends AbstractDashboardWidget {
} }
private void draw() { private void draw() {
Prefs prefs = GBApplication.getPrefs();
boolean upsideDown24h = prefs.getBoolean("dashboard_widget_today_24h_upside_down", false);
// Prepare circular chart // Prepare circular chart
long midDaySecond = dashboardData.timeFrom + (12 * 60 * 60); long midDaySecond = dashboardData.timeFrom + (12 * 60 * 60);
int width = 500; int width = 500;
@ -183,7 +186,16 @@ public class DashboardTodayWidget extends AbstractDashboardWidget {
textPaint.setTextSize(hourTextPixels); textPaint.setTextSize(hourTextPixels);
textPaint.setTextAlign(Paint.Align.CENTER); textPaint.setTextAlign(Paint.Align.CENTER);
Rect textBounds = new Rect(); Rect textBounds = new Rect();
if (mode_24h) { if (mode_24h && upsideDown24h) {
textPaint.getTextBounds(hours.get(6), 0, hours.get(6).length(), textBounds);
canvas.drawText(hours.get(6), clockMargin + clockStripesWidth + textBounds.width() / 2f, height / 2f + textBounds.height() / 2f, textPaint);
textPaint.getTextBounds(hours.get(12), 0, hours.get(12).length(), textBounds);
canvas.drawText(hours.get(12), width / 2f, clockMargin + clockStripesWidth + textBounds.height(), textPaint);
textPaint.getTextBounds(hours.get(18), 0, hours.get(18).length(), textBounds);
canvas.drawText(hours.get(18), width - (clockMargin + clockStripesWidth + textBounds.width()), height / 2f + textBounds.height() / 2f, textPaint);
textPaint.getTextBounds(hours.get(24), 0, hours.get(24).length(), textBounds);
canvas.drawText(hours.get(24), width / 2f, height - (clockMargin + clockStripesWidth), textPaint);
} else if (mode_24h) {
textPaint.getTextBounds(hours.get(6), 0, hours.get(6).length(), textBounds); textPaint.getTextBounds(hours.get(6), 0, hours.get(6).length(), textBounds);
canvas.drawText(hours.get(6), width - (clockMargin + clockStripesWidth + textBounds.width()), height / 2f + textBounds.height() / 2f, textPaint); canvas.drawText(hours.get(6), width - (clockMargin + clockStripesWidth + textBounds.width()), height / 2f + textBounds.height() / 2f, textPaint);
textPaint.getTextBounds(hours.get(12), 0, hours.get(12).length(), textBounds); textPaint.getTextBounds(hours.get(12), 0, hours.get(12).length(), textBounds);
@ -216,6 +228,7 @@ public class DashboardTodayWidget extends AbstractDashboardWidget {
// Draw generalized activities on circular chart // Draw generalized activities on circular chart
long secondIndex = dashboardData.timeFrom; long secondIndex = dashboardData.timeFrom;
long currentTime = Calendar.getInstance().getTimeInMillis() / 1000; long currentTime = Calendar.getInstance().getTimeInMillis() / 1000;
int startAngle = mode_24h && upsideDown24h ? 90 : 270;
synchronized (dashboardData.generalizedActivities) { synchronized (dashboardData.generalizedActivities) {
for (DashboardFragment.DashboardData.GeneralizedActivity activity : dashboardData.generalizedActivities) { for (DashboardFragment.DashboardData.GeneralizedActivity activity : dashboardData.generalizedActivities) {
// Determine margin depending on 24h/12h mode // Determine margin depending on 24h/12h mode
@ -224,15 +237,15 @@ public class DashboardTodayWidget extends AbstractDashboardWidget {
if (!mode_24h && secondIndex < midDaySecond && activity.timeFrom >= midDaySecond) { if (!mode_24h && secondIndex < midDaySecond && activity.timeFrom >= midDaySecond) {
paint.setStrokeWidth(barWidth / 3f); paint.setStrokeWidth(barWidth / 3f);
paint.setColor(color_unknown); paint.setColor(color_unknown);
canvas.drawArc(innerCircleMargin, innerCircleMargin, width - innerCircleMargin, height - innerCircleMargin, 270 + (secondIndex - dashboardData.timeFrom) / degreeFactor, (midDaySecond - secondIndex) / degreeFactor, false, paint); canvas.drawArc(innerCircleMargin, innerCircleMargin, width - innerCircleMargin, height - innerCircleMargin, startAngle + (secondIndex - dashboardData.timeFrom) / degreeFactor, (midDaySecond - secondIndex) / degreeFactor, false, paint);
secondIndex = midDaySecond; secondIndex = midDaySecond;
} }
if (activity.timeFrom > secondIndex) { if (activity.timeFrom > secondIndex) {
paint.setStrokeWidth(barWidth / 3f); paint.setStrokeWidth(barWidth / 3f);
paint.setColor(color_unknown); paint.setColor(color_unknown);
canvas.drawArc(margin, margin, width - margin, height - margin, 270 + (secondIndex - dashboardData.timeFrom) / degreeFactor, (activity.timeFrom - secondIndex) / degreeFactor, false, paint); canvas.drawArc(margin, margin, width - margin, height - margin, startAngle + (secondIndex - dashboardData.timeFrom) / degreeFactor, (activity.timeFrom - secondIndex) / degreeFactor, false, paint);
} }
float start_angle = 270 + (activity.timeFrom - dashboardData.timeFrom) / degreeFactor; float start_angle = startAngle + (activity.timeFrom - dashboardData.timeFrom) / degreeFactor;
float sweep_angle = (activity.timeTo - activity.timeFrom) / degreeFactor; float sweep_angle = (activity.timeTo - activity.timeFrom) / degreeFactor;
if (activity.activityKind == ActivityKind.TYPE_NOT_MEASURED) { if (activity.activityKind == ActivityKind.TYPE_NOT_MEASURED) {
paint.setStrokeWidth(barWidth / 3f); paint.setStrokeWidth(barWidth / 3f);
@ -271,11 +284,11 @@ public class DashboardTodayWidget extends AbstractDashboardWidget {
// Fill inner bar up until current time // Fill inner bar up until current time
paint.setStrokeWidth(barWidth / 3f); paint.setStrokeWidth(barWidth / 3f);
paint.setColor(color_unknown); paint.setColor(color_unknown);
canvas.drawArc(innerCircleMargin, innerCircleMargin, width - innerCircleMargin, height - innerCircleMargin, 270 + (secondIndex - dashboardData.timeFrom) / degreeFactor, (currentTime - secondIndex) / degreeFactor, false, paint); canvas.drawArc(innerCircleMargin, innerCircleMargin, width - innerCircleMargin, height - innerCircleMargin, startAngle + (secondIndex - dashboardData.timeFrom) / degreeFactor, (currentTime - secondIndex) / degreeFactor, false, paint);
// Fill inner bar up until midday // Fill inner bar up until midday
paint.setStrokeWidth(barWidth / 3f); paint.setStrokeWidth(barWidth / 3f);
paint.setColor(color_unknown); paint.setColor(color_unknown);
canvas.drawArc(innerCircleMargin, innerCircleMargin, width - innerCircleMargin, height - innerCircleMargin, 270 + (currentTime - dashboardData.timeFrom) / degreeFactor, (midDaySecond - currentTime) / degreeFactor, false, paint); canvas.drawArc(innerCircleMargin, innerCircleMargin, width - innerCircleMargin, height - innerCircleMargin, startAngle + (currentTime - dashboardData.timeFrom) / degreeFactor, (midDaySecond - currentTime) / degreeFactor, false, paint);
// Fill outer bar up until midnight // Fill outer bar up until midnight
paint.setStrokeWidth(barWidth / 3f); paint.setStrokeWidth(barWidth / 3f);
paint.setColor(color_unknown); paint.setColor(color_unknown);
@ -287,24 +300,24 @@ public class DashboardTodayWidget extends AbstractDashboardWidget {
if (!mode_24h && secondIndex < midDaySecond) { if (!mode_24h && secondIndex < midDaySecond) {
paint.setStrokeWidth(barWidth / 3f); paint.setStrokeWidth(barWidth / 3f);
paint.setColor(color_unknown); paint.setColor(color_unknown);
canvas.drawArc(innerCircleMargin, innerCircleMargin, width - innerCircleMargin, height - innerCircleMargin, 270 + (secondIndex - dashboardData.timeFrom) / degreeFactor, (midDaySecond - secondIndex) / degreeFactor, false, paint); canvas.drawArc(innerCircleMargin, innerCircleMargin, width - innerCircleMargin, height - innerCircleMargin, startAngle + (secondIndex - dashboardData.timeFrom) / degreeFactor, (midDaySecond - secondIndex) / degreeFactor, false, paint);
secondIndex = midDaySecond; secondIndex = midDaySecond;
} }
// Fill outer bar up until current time // Fill outer bar up until current time
paint.setStrokeWidth(barWidth / 3f); paint.setStrokeWidth(barWidth / 3f);
paint.setColor(color_unknown); paint.setColor(color_unknown);
canvas.drawArc(outerCircleMargin, outerCircleMargin, width - outerCircleMargin, height - outerCircleMargin, 270 + (secondIndex - dashboardData.timeFrom) / degreeFactor, (currentTime - secondIndex) / degreeFactor, false, paint); canvas.drawArc(outerCircleMargin, outerCircleMargin, width - outerCircleMargin, height - outerCircleMargin, startAngle + (secondIndex - dashboardData.timeFrom) / degreeFactor, (currentTime - secondIndex) / degreeFactor, false, paint);
// Fill outer bar up until midnight // Fill outer bar up until midnight
paint.setStrokeWidth(barWidth / 3f); paint.setStrokeWidth(barWidth / 3f);
paint.setColor(color_unknown); paint.setColor(color_unknown);
canvas.drawArc(outerCircleMargin, outerCircleMargin, width - outerCircleMargin, height - outerCircleMargin, 270 + (currentTime - dashboardData.timeFrom) / degreeFactor, (dashboardData.timeTo - currentTime) / degreeFactor, false, paint); canvas.drawArc(outerCircleMargin, outerCircleMargin, width - outerCircleMargin, height - outerCircleMargin, startAngle + (currentTime - dashboardData.timeFrom) / degreeFactor, (dashboardData.timeTo - currentTime) / degreeFactor, false, paint);
} }
// Only when displaying a past day // Only when displaying a past day
if (secondIndex < dashboardData.timeTo && currentTime > dashboardData.timeTo) { if (secondIndex < dashboardData.timeTo && currentTime > dashboardData.timeTo) {
// Fill outer bar up until midnight // Fill outer bar up until midnight
paint.setStrokeWidth(barWidth / 3f); paint.setStrokeWidth(barWidth / 3f);
paint.setColor(color_unknown); paint.setColor(color_unknown);
canvas.drawArc(outerCircleMargin, outerCircleMargin, width - outerCircleMargin, height - outerCircleMargin, 270 + (secondIndex - dashboardData.timeFrom) / degreeFactor, (dashboardData.timeTo - secondIndex) / degreeFactor, false, paint); canvas.drawArc(outerCircleMargin, outerCircleMargin, width - outerCircleMargin, height - outerCircleMargin, startAngle + (secondIndex - dashboardData.timeFrom) / degreeFactor, (dashboardData.timeTo - secondIndex) / degreeFactor, false, paint);
} }
todayChart.setImageBitmap(todayBitmap); todayChart.setImageBitmap(todayBitmap);

View File

@ -2794,4 +2794,6 @@
<string name="pref_title_bottom_navigation_bar">Bottom navigation bar</string> <string name="pref_title_bottom_navigation_bar">Bottom navigation bar</string>
<string name="pref_summary_bottom_navigation_bar_on">Switch between main screens using the navigation bar or horizontal swiping</string> <string name="pref_summary_bottom_navigation_bar_on">Switch between main screens using the navigation bar or horizontal swiping</string>
<string name="pref_summary_bottom_navigation_bar_off">Switch between main screens only using horizontal swiping</string> <string name="pref_summary_bottom_navigation_bar_off">Switch between main screens only using horizontal swiping</string>
<string name="pref_dashboard_widget_today_upside_down_title">Midnight at bottom</string>
<string name="pref_dashboard_widget_today_upside_down_summary">In 24h mode, draw midnight at the bottom, midday at the top of the chart</string>
</resources> </resources>

View File

@ -46,6 +46,14 @@
android:title="@string/pref_dashboard_widget_today_24h_title" android:title="@string/pref_dashboard_widget_today_24h_title"
android:summary="@string/pref_dashboard_widget_today_24h_summary" android:summary="@string/pref_dashboard_widget_today_24h_summary"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="dashboard_widget_today_24h_upside_down"
android:dependency="dashboard_widget_today_24h"
android:layout="@layout/preference_checkbox"
android:title="@string/pref_dashboard_widget_today_upside_down_title"
android:summary="@string/pref_dashboard_widget_today_upside_down_summary"
app:iconSpaceReserved="false" />
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:defaultValue="true" android:defaultValue="true"
android:key="dashboard_widget_today_2columns" android:key="dashboard_widget_today_2columns"