@capgo/capacitor-widget-kit 9.0.1 → 9.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -30,6 +30,7 @@ We build, improve and fix our plugins with heavy use of AI, so issues usually ge
|
|
|
30
30
|
|
|
31
31
|
## Key features
|
|
32
32
|
|
|
33
|
+
- **Foldable ready**: tested on iPhone Duo. See [Foldables, tablets and split screen](#foldables-tablets-and-split-screen).
|
|
33
34
|
- **SVG template widgets**: `startTemplateWidget()` and `startTemplateActivity()` store layouts for the Home Screen, Lock Screen, Dynamic Island and Android.
|
|
34
35
|
- **Updates and actions**: `updateTemplateActivity()`, `endTemplateActivity()` and `performTemplateAction()` with declarative state patches and timers.
|
|
35
36
|
- **Interaction events**: `listTemplateEvents()` and `acknowledgeTemplateEvents()` process widget taps in your app.
|
|
@@ -83,6 +84,13 @@ Capacitor 9 needs Node.js 24+, iOS 16+ (Xcode 27) and Android minSdk 26 / compil
|
|
|
83
84
|
|
|
84
85
|
No plugin API was removed: the JavaScript API of v9 is the same as v8.
|
|
85
86
|
|
|
87
|
+
## Foldables, tablets and split screen
|
|
88
|
+
|
|
89
|
+
On iOS, widget previews and hotspots size correctly on the folded cover screen and the unfolded inner screen.
|
|
90
|
+
|
|
91
|
+
- **iPhone Duo**: tested on the iPhone Duo simulator (iOS 27.2) on the folded cover screen, the unfolded inner screen, and through a live fold and unfold.
|
|
92
|
+
- **Android foldables (Galaxy Z Fold, Pixel Fold), tablets and multi-window**: the renderer fits the bitmap to the maximum width and height the launcher reports through `AppWidgetManager` options (Android reports size ranges, not one exact current size), with the bitmap edge capped. Re-render from your `AppWidgetProvider.onAppWidgetOptionsChanged`, as the example widget does, so the bitmap is redrawn when those bounds change after a resize or fold; switching between sizes that share the same maximum bounds does not change it. Android hosts lay out their own hotspot actions.
|
|
93
|
+
|
|
86
94
|
## Install
|
|
87
95
|
|
|
88
96
|
You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
package app.capgo.widgetkit;
|
|
2
2
|
|
|
3
|
+
import android.appwidget.AppWidgetManager;
|
|
4
|
+
import android.content.Context;
|
|
3
5
|
import android.graphics.Bitmap;
|
|
4
6
|
import android.graphics.Canvas;
|
|
7
|
+
import android.os.Bundle;
|
|
5
8
|
import com.caverock.androidsvg.SVG;
|
|
6
9
|
import org.json.JSONObject;
|
|
7
10
|
|
|
8
11
|
public final class CapgoTemplateSvgBitmapRenderer {
|
|
9
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Longest bitmap edge produced for a home screen widget. RemoteViews bitmaps count against the
|
|
15
|
+
* launcher's IPC memory budget, so a widget stretched across an unfolded inner screen must not
|
|
16
|
+
* produce a full-resolution bitmap.
|
|
17
|
+
*/
|
|
18
|
+
public static final int DEFAULT_MAX_WIDGET_BITMAP_EDGE_PX = 1024;
|
|
19
|
+
|
|
10
20
|
private CapgoTemplateSvgBitmapRenderer() {}
|
|
11
21
|
|
|
12
22
|
public static Bitmap render(final JSONObject layout, final int targetWidthPx, final int targetHeightPx) throws Exception {
|
|
@@ -22,4 +32,90 @@ public final class CapgoTemplateSvgBitmapRenderer {
|
|
|
22
32
|
svg.renderToCanvas(canvas);
|
|
23
33
|
return bitmap;
|
|
24
34
|
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Renders the template for the widget's current size. Launchers report a new size through
|
|
38
|
+
* {@code onAppWidgetOptionsChanged} when the widget is resized, the device rotates, or a foldable
|
|
39
|
+
* switches between its cover and inner screens; call this again from there so the bitmap follows
|
|
40
|
+
* the new cell size instead of a size fixed at install time.
|
|
41
|
+
*/
|
|
42
|
+
public static Bitmap renderForWidget(
|
|
43
|
+
final Context context,
|
|
44
|
+
final AppWidgetManager appWidgetManager,
|
|
45
|
+
final int appWidgetId,
|
|
46
|
+
final JSONObject layout,
|
|
47
|
+
final int fallbackWidthPx,
|
|
48
|
+
final int fallbackHeightPx
|
|
49
|
+
) throws Exception {
|
|
50
|
+
final Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId);
|
|
51
|
+
final int[] size = widgetBitmapSize(
|
|
52
|
+
options != null ? options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, 0) : 0,
|
|
53
|
+
options != null ? options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, 0) : 0,
|
|
54
|
+
options != null ? options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, 0) : 0,
|
|
55
|
+
options != null ? options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, 0) : 0,
|
|
56
|
+
context.getResources().getDisplayMetrics().density,
|
|
57
|
+
layout.optDouble("width", 0d),
|
|
58
|
+
layout.optDouble("height", 0d),
|
|
59
|
+
fallbackWidthPx,
|
|
60
|
+
fallbackHeightPx,
|
|
61
|
+
DEFAULT_MAX_WIDGET_BITMAP_EDGE_PX
|
|
62
|
+
);
|
|
63
|
+
return render(layout, size[0], size[1]);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Computes the bitmap size for a widget from its reported option bounds (in dp).
|
|
68
|
+
*
|
|
69
|
+
* <p>The bitmap is fitted to the largest reported bounds ({@code maxWidth x maxHeight}). The
|
|
70
|
+
* min/max bounds cannot tell which size is on screen: they cover portrait and landscape, and on
|
|
71
|
+
* Android 12+ launchers they also span every display of a foldable (cover and inner), so picking
|
|
72
|
+
* one by orientation could hand the inner screen a cover-sized bitmap that the ImageView then
|
|
73
|
+
* upscales and blurs. A single bitmap sized for the largest cell is scaled down sharply on the
|
|
74
|
+
* smaller ones. When the launcher reports nothing yet, the fallback size is used. When the template reports its own size, the result takes the template's aspect
|
|
75
|
+
* ratio and is the largest such size that fits the widget, so the SVG is not letterboxed twice.
|
|
76
|
+
* The result is scaled down so that neither edge exceeds {@code maxEdgePx}.
|
|
77
|
+
*
|
|
78
|
+
* @return {@code [widthPx, heightPx]}, both at least 1.
|
|
79
|
+
*/
|
|
80
|
+
public static int[] widgetBitmapSize(
|
|
81
|
+
final int minWidthDp,
|
|
82
|
+
final int maxWidthDp,
|
|
83
|
+
final int minHeightDp,
|
|
84
|
+
final int maxHeightDp,
|
|
85
|
+
final float density,
|
|
86
|
+
final double templateWidth,
|
|
87
|
+
final double templateHeight,
|
|
88
|
+
final int fallbackWidthPx,
|
|
89
|
+
final int fallbackHeightPx,
|
|
90
|
+
final int maxEdgePx
|
|
91
|
+
) {
|
|
92
|
+
final int widthDp = Math.max(Math.max(0, minWidthDp), maxWidthDp);
|
|
93
|
+
final int heightDp = Math.max(Math.max(0, minHeightDp), maxHeightDp);
|
|
94
|
+
final float scale = density > 0f ? density : 1f;
|
|
95
|
+
|
|
96
|
+
double width = widthDp > 0 && heightDp > 0 ? widthDp * scale : fallbackWidthPx;
|
|
97
|
+
double height = widthDp > 0 && heightDp > 0 ? heightDp * scale : fallbackHeightPx;
|
|
98
|
+
width = Math.max(1d, width);
|
|
99
|
+
height = Math.max(1d, height);
|
|
100
|
+
|
|
101
|
+
if (templateWidth > 0d && templateHeight > 0d && !Double.isNaN(templateWidth) && !Double.isNaN(templateHeight)) {
|
|
102
|
+
final double templateAspect = templateWidth / templateHeight;
|
|
103
|
+
if (width / height > templateAspect) {
|
|
104
|
+
width = height * templateAspect;
|
|
105
|
+
} else {
|
|
106
|
+
height = width / templateAspect;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (maxEdgePx > 0) {
|
|
111
|
+
final double longest = Math.max(width, height);
|
|
112
|
+
if (longest > maxEdgePx) {
|
|
113
|
+
final double ratio = maxEdgePx / longest;
|
|
114
|
+
width *= ratio;
|
|
115
|
+
height *= ratio;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return new int[] { Math.max(1, (int) Math.round(width)), Math.max(1, (int) Math.round(height)) };
|
|
120
|
+
}
|
|
25
121
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capgo/capacitor-widget-kit",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Capacitor plugin for generic iOS Home Screen widgets, WidgetKit, and Live Activities using SVG templates, declarative actions, and shared App Group persistence.",
|
|
6
6
|
"main": "dist/plugin.cjs.js",
|