37
37
import androidx .annotation .ColorInt ;
38
38
import androidx .annotation .NonNull ;
39
39
import androidx .annotation .Nullable ;
40
+ import androidx .annotation .Px ;
40
41
import androidx .annotation .RestrictTo ;
41
42
import androidx .annotation .StyleRes ;
42
43
import androidx .core .app .ActivityCompat ;
@@ -229,7 +230,8 @@ public class DynamicTheme implements DynamicListener, DynamicResolver {
229
230
/**
230
231
* Default corner size for the theme.
231
232
*/
232
- private static final int CORNER_SIZE_DEFAULT = DynamicUnitUtils .convertDpToPixels (2 );
233
+ private static final int CORNER_SIZE_DEFAULT =
234
+ DynamicUnitUtils .convertDpToPixels (Theme .Corner .DEFAULT );
233
235
234
236
/**
235
237
* Singleton instance of {@link DynamicTheme}.
@@ -1192,6 +1194,16 @@ public void setLocalVersion(@Version int version) {
1192
1194
? (Context ) getLocalListener () : getLocalListener ().getContext ();
1193
1195
}
1194
1196
1197
+ /**
1198
+ * Returns the currently used context.
1199
+ * <p>Generally, either application or an activity.
1200
+ *
1201
+ * @return The currently used context.
1202
+ */
1203
+ private @ NonNull Context getResolvedContext () {
1204
+ return getLocalContext () != null ? getLocalContext () : getContext ();
1205
+ }
1206
+
1195
1207
/**
1196
1208
* Get the power manager used by the application.
1197
1209
*
@@ -1407,16 +1419,6 @@ public void onLocalDestroy(@Nullable DynamicListener listener) {
1407
1419
mDefaultLocalTheme = null ;
1408
1420
}
1409
1421
1410
- /**
1411
- * Generates default theme according to the current settings.
1412
- *
1413
- * @return The generated default theme.
1414
- */
1415
- public @ NonNull DynamicAppTheme generateDefaultTheme () {
1416
- return new DynamicAppTheme ().setBackgroundColor (
1417
- getDefault ().getBackgroundColor (), false );
1418
- }
1419
-
1420
1422
/**
1421
1423
* Generates default background color according to the application theme.
1422
1424
*
@@ -1429,6 +1431,43 @@ public void onLocalDestroy(@Nullable DynamicListener listener) {
1429
1431
? R .color .ads_window_background : R .color .ads_window_background_light );
1430
1432
}
1431
1433
1434
+ /**
1435
+ * Try to get the corner radius for the widget background from the system.
1436
+ *
1437
+ * @param fallback The fallback radius to be used in case of any issues.
1438
+ *
1439
+ * @return The corner radius for the widget background from the system.
1440
+ */
1441
+ @ TargetApi (Build .VERSION_CODES .S )
1442
+ public @ Px int getWidgetCornerRadius (int fallback ) {
1443
+ if (DynamicSdkUtils .is31 ()) {
1444
+ return Math .min (getContext ().getResources ().getDimensionPixelOffset (
1445
+ android .R .dimen .system_app_widget_background_radius ),
1446
+ DynamicUnitUtils .convertDpToPixels (Theme .Corner .MAX ));
1447
+ }
1448
+
1449
+ return fallback ;
1450
+ }
1451
+
1452
+ /**
1453
+ * Returns the default contrast with color to tint the background aware views accordingly.
1454
+ *
1455
+ * @return The default contrast with color.
1456
+ */
1457
+ public @ ColorInt int getDefaultContrastWith () {
1458
+ return get ().getBackgroundColor ();
1459
+ }
1460
+
1461
+ /**
1462
+ * Generates default theme according to the current settings.
1463
+ *
1464
+ * @return The generated default theme.
1465
+ */
1466
+ public @ NonNull DynamicAppTheme generateDefaultTheme () {
1467
+ return new DynamicAppTheme ().setBackgroundColor (
1468
+ getDefault ().getBackgroundColor (), false );
1469
+ }
1470
+
1432
1471
/**
1433
1472
* Generates stroke color according to the supplied color.
1434
1473
*
@@ -1491,25 +1530,6 @@ public void onLocalDestroy(@Nullable DynamicListener listener) {
1491
1530
return Dynamic .getTintColor (color );
1492
1531
}
1493
1532
1494
- /**
1495
- * Returns the currently used context.
1496
- * <p>Generally, either application or an activity.
1497
- *
1498
- * @return The currently used context.
1499
- */
1500
- private @ NonNull Context getResolvedContext () {
1501
- return getLocalContext () != null ? getLocalContext () : getContext ();
1502
- }
1503
-
1504
- /**
1505
- * Returns the default contrast with color to tint the background aware views accordingly.
1506
- *
1507
- * @return The default contrast with color.
1508
- */
1509
- public @ ColorInt int getDefaultContrastWith () {
1510
- return get ().getBackgroundColor ();
1511
- }
1512
-
1513
1533
/**
1514
1534
* Returns the resolver used by the dynamic theme.
1515
1535
*
0 commit comments