diff --git a/app/src/main/java/eu/faircode/email/ActivityWidgetSync.java b/app/src/main/java/eu/faircode/email/ActivityWidgetSync.java index 37e608e689..8ab6c9288b 100644 --- a/app/src/main/java/eu/faircode/email/ActivityWidgetSync.java +++ b/app/src/main/java/eu/faircode/email/ActivityWidgetSync.java @@ -55,6 +55,10 @@ public class ActivityWidgetSync extends ActivityBase { appWidgetId = extras.getInt( AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ActivityWidgetSync.this); + boolean semi = prefs.getBoolean("widget." + appWidgetId + ".semi", true); + int background = prefs.getInt("widget." + appWidgetId + ".background", Color.TRANSPARENT); + getSupportActionBar().setSubtitle(R.string.title_widget_title_sync); setContentView(R.layout.activity_widget_sync); @@ -113,7 +117,9 @@ public class ActivityWidgetSync extends ActivityBase { } }); - btnColor.setColor(Color.TRANSPARENT); + // Initialize + cbSemiTransparent.setChecked(semi); + btnColor.setColor(background); setResult(RESULT_CANCELED, resultValue); } diff --git a/app/src/main/java/eu/faircode/email/WidgetSync.java b/app/src/main/java/eu/faircode/email/WidgetSync.java index c835338000..c229b705d8 100644 --- a/app/src/main/java/eu/faircode/email/WidgetSync.java +++ b/app/src/main/java/eu/faircode/email/WidgetSync.java @@ -50,13 +50,20 @@ public class WidgetSync extends AppWidgetProvider { int background = prefs.getInt("widget." + appWidgetId + ".background", Color.TRANSPARENT); int version = prefs.getInt("widget." + appWidgetId + ".version", 0); + if (version <= 1550) + semi = true; // Legacy + RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_sync); views.setOnClickPendingIntent(R.id.ivSync, pi); views.setImageViewResource(R.id.ivSync, enabled ? R.drawable.twotone_sync_24 : R.drawable.twotone_sync_disabled_24); if (background == Color.TRANSPARENT) { - if (!semi && version > 1550) + if (semi) + views.setInt(R.id.widget, "setBackgroundResource", R.drawable.widget_background); + else views.setInt(R.id.widget, "setBackgroundColor", background); + views.setInt(R.id.ivSync, "setColorFilter", + context.getResources().getColor(R.color.colorWidgetForeground)); } else { float lum = (float) ColorUtils.calculateLuminance(background); @@ -69,6 +76,9 @@ public class WidgetSync extends AppWidgetProvider { views.setInt(R.id.ivSync, "setColorFilter", Color.BLACK); } + int dp6 = Helper.dp2pixels(context, 6); + views.setViewPadding(R.id.widget, dp6, dp6, dp6, dp6); + appWidgetManager.updateAppWidget(appWidgetId, views); } } catch (Throwable ex) { diff --git a/app/src/main/res/xml/widget_sync.xml b/app/src/main/res/xml/widget_sync.xml index 064aa4b8b9..b12a40132b 100644 --- a/app/src/main/res/xml/widget_sync.xml +++ b/app/src/main/res/xml/widget_sync.xml @@ -7,4 +7,5 @@ android:previewImage="@drawable/widget_preview_sync" android:resizeMode="horizontal|vertical" android:updatePeriodMillis="0" - android:widgetCategory="home_screen" /> + android:widgetCategory="home_screen" + android:widgetFeatures="reconfigurable" />