From aa76c6f478b56d9cd4e43836c39aa78e49a79e29 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 5 Mar 2022 14:24:46 +0100 Subject: [PATCH] Small widget improvement --- app/src/main/java/eu/faircode/email/Widget.java | 11 +++++------ app/src/main/java/eu/faircode/email/WidgetSync.java | 9 +++++---- .../main/java/eu/faircode/email/WidgetUnified.java | 7 ++++--- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Widget.java b/app/src/main/java/eu/faircode/email/Widget.java index 463ef54a6c..69d20d3740 100644 --- a/app/src/main/java/eu/faircode/email/Widget.java +++ b/app/src/main/java/eu/faircode/email/Widget.java @@ -53,6 +53,7 @@ public class Widget extends AppWidgetProvider { DB db = DB.getInstance(context); NumberFormat nf = NumberFormat.getIntegerInstance(); + int colorWidgetForeground = context.getResources().getColor(R.color.colorWidgetForeground); for (int appWidgetId : appWidgetIds) { String name = prefs.getString("widget." + appWidgetId + ".name", null); @@ -118,7 +119,6 @@ public class Widget extends AppWidgetProvider { else views.setInt(R.id.background, "setBackgroundColor", background); - int colorWidgetForeground = context.getResources().getColor(R.color.colorWidgetForeground); views.setInt(R.id.ivMessage, "setColorFilter", colorWidgetForeground); views.setTextColor(R.id.tvCount, colorWidgetForeground); views.setTextColor(R.id.tvAccount, colorWidgetForeground); @@ -130,11 +130,10 @@ public class Widget extends AppWidgetProvider { views.setInt(R.id.background, "setBackgroundColor", background); - if (lum > 0.7f) { - views.setInt(R.id.ivMessage, "setColorFilter", Color.BLACK); - views.setTextColor(R.id.tvCount, Color.BLACK); - views.setTextColor(R.id.tvAccount, Color.BLACK); - } + int fg = (lum > 0.7f ? Color.BLACK : colorWidgetForeground); + views.setInt(R.id.ivMessage, "setColorFilter", fg); + views.setTextColor(R.id.tvCount, layout == 0 ? fg : colorWidgetForeground); + views.setTextColor(R.id.tvAccount, fg); } if (layout == 1) diff --git a/app/src/main/java/eu/faircode/email/WidgetSync.java b/app/src/main/java/eu/faircode/email/WidgetSync.java index 876ec540cb..ea8bee0faf 100644 --- a/app/src/main/java/eu/faircode/email/WidgetSync.java +++ b/app/src/main/java/eu/faircode/email/WidgetSync.java @@ -45,6 +45,8 @@ public class WidgetSync extends AppWidgetProvider { PendingIntent pi = PendingIntentCompat.getForegroundService( context, ServiceSynchronize.PI_ENABLE, intent, PendingIntent.FLAG_UPDATE_CURRENT); + int colorWidgetForeground = context.getResources().getColor(R.color.colorWidgetForeground); + for (int appWidgetId : appWidgetIds) { boolean semi = prefs.getBoolean("widget." + appWidgetId + ".semi", true); int background = prefs.getInt("widget." + appWidgetId + ".background", Color.TRANSPARENT); @@ -62,8 +64,7 @@ public class WidgetSync extends AppWidgetProvider { views.setInt(R.id.background, "setBackgroundResource", R.drawable.widget_background); else views.setInt(R.id.background, "setBackgroundColor", background); - views.setInt(R.id.ivSync, "setColorFilter", - context.getResources().getColor(R.color.colorWidgetForeground)); + views.setInt(R.id.ivSync, "setColorFilter", colorWidgetForeground); } else { float lum = (float) ColorUtils.calculateLuminance(background); @@ -72,8 +73,8 @@ public class WidgetSync extends AppWidgetProvider { views.setInt(R.id.background, "setBackgroundColor", background); - if (lum > 0.7f) - views.setInt(R.id.ivSync, "setColorFilter", Color.BLACK); + int fg = (lum > 0.7f ? Color.BLACK : colorWidgetForeground); + views.setInt(R.id.ivSync, "setColorFilter", fg); } int dp6 = Helper.dp2pixels(context, 6); diff --git a/app/src/main/java/eu/faircode/email/WidgetUnified.java b/app/src/main/java/eu/faircode/email/WidgetUnified.java index 924ff6a2b3..a983e588c5 100644 --- a/app/src/main/java/eu/faircode/email/WidgetUnified.java +++ b/app/src/main/java/eu/faircode/email/WidgetUnified.java @@ -40,6 +40,8 @@ public class WidgetUnified extends AppWidgetProvider { public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + int colorWidgetForeground = context.getResources().getColor(R.color.colorWidgetForeground); + for (int appWidgetId : appWidgetIds) { String name = prefs.getString("widget." + appWidgetId + ".name", null); long account = prefs.getLong("widget." + appWidgetId + ".account", -1L); @@ -135,7 +137,6 @@ public class WidgetUnified extends AppWidgetProvider { else views.setInt(R.id.background, "setBackgroundColor", background); - int colorWidgetForeground = context.getResources().getColor(R.color.colorWidgetForeground); views.setTextColor(R.id.title, colorWidgetForeground); } else { float lum = (float) ColorUtils.calculateLuminance(background); @@ -145,8 +146,8 @@ public class WidgetUnified extends AppWidgetProvider { views.setInt(R.id.background, "setBackgroundColor", background); - if (lum > 0.7f) - views.setTextColor(R.id.title, Color.BLACK); + int fg = (lum > 0.7f ? Color.BLACK : colorWidgetForeground); + views.setTextColor(R.id.title, fg); } int dp6 = Helper.dp2pixels(context, 6);