From 35217aa405c301b474a4c0d79c165975bc9c3662 Mon Sep 17 00:00:00 2001 From: MrYoranimo Date: Mon, 8 Apr 2024 13:37:04 +0200 Subject: [PATCH] Xiaomi: add support for 2x3 widget layouts The Xiaomi Smart Band 8 Pro shows widgets in a two by three grid. Previously, opening the widget configuration for such a device from the device-specific preferences would crash Gadgetbridge because the layouts in such a grid was not supported. This commit adds definitions for layouts in a 2x3 grid to the WidgetLayout enum, adds a definition for a full screen widget to the WidgetType enum, defines rendering definitions for the new layouts to WidgetScreenDetailsActivity, and defines translations for the new layouts and type to XiaomiWidgetManager. --- .../widgets/WidgetScreenDetailsActivity.java | 5 +++ .../capabilities/widgets/WidgetLayout.java | 7 +++- .../capabilities/widgets/WidgetType.java | 1 + .../devices/xiaomi/XiaomiWidgetManager.java | 33 +++++++++++++++---- app/src/main/res/values/strings.xml | 6 ++-- 5 files changed, 42 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/widgets/WidgetScreenDetailsActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/widgets/WidgetScreenDetailsActivity.java index 14e60489e..086337705 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/widgets/WidgetScreenDetailsActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/widgets/WidgetScreenDetailsActivity.java @@ -174,6 +174,7 @@ public class WidgetScreenDetailsActivity extends AbstractGBActivity { switch (widgetScreen.getLayout()) { case TOP_1_BOT_2: + case TOP_2X2_BOT_2: updateWidget(cardWidgetTopLeft, labelWidgetTopLeft, -1); updateWidget(cardWidgetTopRight, labelWidgetTopRight, -1); updateWidget(cardWidgetCenter, labelWidgetCenter, 0); @@ -181,6 +182,7 @@ public class WidgetScreenDetailsActivity extends AbstractGBActivity { updateWidget(cardWidgetBotRight, labelWidgetBotRight, 2); break; case TOP_2_BOT_1: + case TOP_2_BOT_2X2: updateWidget(cardWidgetTopLeft, labelWidgetTopLeft, 0); updateWidget(cardWidgetTopRight, labelWidgetTopRight, 1); updateWidget(cardWidgetCenter, labelWidgetCenter, 2); @@ -196,6 +198,7 @@ public class WidgetScreenDetailsActivity extends AbstractGBActivity { break; case ONE_BY_TWO_SINGLE: case TWO_BY_TWO_SINGLE: + case TWO_BY_THREE_SINGLE: updateWidget(cardWidgetTopLeft, labelWidgetTopLeft, -1); updateWidget(cardWidgetTopRight, labelWidgetTopRight, -1); updateWidget(cardWidgetCenter, labelWidgetCenter, 0); @@ -203,6 +206,8 @@ public class WidgetScreenDetailsActivity extends AbstractGBActivity { updateWidget(cardWidgetBotRight, labelWidgetBotRight, -1); break; case TWO: + case TOP_1_BOT_2X2: + case TOP_2X2_BOT_1: updateWidget(cardWidgetTopLeft, labelWidgetTopLeft, -1); updateWidget(cardWidgetTopRight, labelWidgetTopRight, 0); updateWidget(cardWidgetCenter, labelWidgetCenter, 1); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/capabilities/widgets/WidgetLayout.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/capabilities/widgets/WidgetLayout.java index bc677be2c..3df35e436 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/capabilities/widgets/WidgetLayout.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/capabilities/widgets/WidgetLayout.java @@ -31,7 +31,12 @@ public enum WidgetLayout { ONE_BY_TWO_SINGLE(R.string.widget_layout_single, WidgetType.TALL), TWO(R.string.widget_layout_two, WidgetType.SMALL, WidgetType.SMALL), - // TODO Portrait screen layouts, 2x3 + // Portrait 2x3 screen layouts + TOP_2_BOT_2X2(R.string.widget_layout_top_2_bot_1, WidgetType.SMALL, WidgetType.SMALL, WidgetType.LARGE), + TOP_2X2_BOT_2(R.string.widget_layout_top_1_bot_2, WidgetType.LARGE, WidgetType.SMALL, WidgetType.SMALL), + TOP_1_BOT_2X2(R.string.widget_layout_top_wide_bot_large, WidgetType.WIDE, WidgetType.LARGE), + TOP_2X2_BOT_1(R.string.widget_layout_top_large_bot_wide, WidgetType.LARGE, WidgetType.WIDE), + TWO_BY_THREE_SINGLE(R.string.widget_layout_single, WidgetType.PORTRAIT_LARGE), ; @StringRes diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/capabilities/widgets/WidgetType.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/capabilities/widgets/WidgetType.java index 93823d20e..01e3e95ee 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/capabilities/widgets/WidgetType.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/capabilities/widgets/WidgetType.java @@ -21,5 +21,6 @@ public enum WidgetType { TALL, // 1x2 WIDE, // 2x1 LARGE, // 2x2 + PORTRAIT_LARGE, // 2x3 ; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/xiaomi/XiaomiWidgetManager.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/xiaomi/XiaomiWidgetManager.java index e99d5261b..fb68d81bd 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/xiaomi/XiaomiWidgetManager.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/xiaomi/XiaomiWidgetManager.java @@ -379,6 +379,8 @@ public class XiaomiWidgetManager implements WidgetManager { return WidgetType.TALL; case 4: return WidgetType.LARGE; + case 5: + return WidgetType.PORTRAIT_LARGE; default: LOG.warn("Unknown widget type {}", rawType); return null; @@ -395,6 +397,8 @@ public class XiaomiWidgetManager implements WidgetManager { return 3; case LARGE: return 4; + case PORTRAIT_LARGE: + return 5; default: throw new IllegalArgumentException("Unknown widget type " + widgetType); } @@ -415,15 +419,20 @@ public class XiaomiWidgetManager implements WidgetManager { return WidgetLayout.TWO; case 512: // 1x2, full screen return WidgetLayout.ONE_BY_TWO_SINGLE; - case 8: // 2x2, left tall, right 2x square - case 16: // 2x2, left 2x square, right tall + case 1024: // 2x3, top 2x small, bottom 2x2 square + return WidgetLayout.TOP_2_BOT_2X2; + case 2048: // 2x3, top 2x2 square, bottom 2x small + return WidgetLayout.TOP_2X2_BOT_2; + case 4096: // 2x3, top wide, bottom 2x2 small + return WidgetLayout.TOP_1_BOT_2X2; + case 8192: // 2x3, top 2x2 small, bottom wide + return WidgetLayout.TOP_2X2_BOT_1; + case 16384: // 2x3, full screen + return WidgetLayout.TWO_BY_THREE_SINGLE; + case 8: // 2x2, left tall, right 2x small + case 16: // 2x2, left 2x small, right tall case 32: // 2x2, top wide, bottom wide case 64: // 2x2, left tall, right tall - case 1024: // 2x3, top 2x square, bottom 2x2 square - case 2048: // 2x3, top 2x2 square, bottom 2x square - case 4096: // 2x3, top wide, bottom 2x2 square - case 8192: // 2x3, top 2x2 square, bottom wide - case 16384: // 2x3, full screen default: LOG.warn("Unknown widget screens layout {}", rawLayout); return null; @@ -448,6 +457,16 @@ public class XiaomiWidgetManager implements WidgetManager { return 256; case ONE_BY_TWO_SINGLE: return 512; + case TOP_2_BOT_2X2: + return 1024; + case TOP_2X2_BOT_2: + return 2048; + case TOP_1_BOT_2X2: + return 4096; + case TOP_2X2_BOT_1: + return 8192; + case TWO_BY_THREE_SINGLE: + return 16384; default: LOG.warn("Widget layout {} cannot be converted to raw variant", layout); return -1; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f85965d3f..3222cb398 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2698,11 +2698,13 @@ 1 top, 2 bottom 2 top, 1 bottom 2 top, 2 bottom + 1 widget + 2 widgets + Wide above, large below + Large above, wide below Widget layout Widget Subtype Screen %s - 1 widget - 2 widgets Move up Move down Please select all widgets