mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-24 16:47:32 +01:00
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.
This commit is contained in:
parent
0b731611b9
commit
35217aa405
@ -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);
|
||||
|
@ -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
|
||||
|
@ -21,5 +21,6 @@ public enum WidgetType {
|
||||
TALL, // 1x2
|
||||
WIDE, // 2x1
|
||||
LARGE, // 2x2
|
||||
PORTRAIT_LARGE, // 2x3
|
||||
;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -2698,11 +2698,13 @@
|
||||
<string name="widget_layout_top_1_bot_2">1 top, 2 bottom</string>
|
||||
<string name="widget_layout_top_2_bot_1">2 top, 1 bottom</string>
|
||||
<string name="widget_layout_top_2_bot_2">2 top, 2 bottom</string>
|
||||
<string name="widget_layout_single">1 widget</string>
|
||||
<string name="widget_layout_two">2 widgets</string>
|
||||
<string name="widget_layout_top_wide_bot_large">Wide above, large below</string>
|
||||
<string name="widget_layout_top_large_bot_wide">Large above, wide below</string>
|
||||
<string name="widget_layout">Widget layout</string>
|
||||
<string name="widget_subtype">Widget Subtype</string>
|
||||
<string name="widget_screen_x">Screen %s</string>
|
||||
<string name="widget_layout_single">1 widget</string>
|
||||
<string name="widget_layout_two">2 widgets</string>
|
||||
<string name="widget_move_up">Move up</string>
|
||||
<string name="widget_move_down">Move down</string>
|
||||
<string name="widget_missing_parts">Please select all widgets</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user