From d060febc4d3ce28bc7e234e437c13bfb8af2517e Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 5 Mar 2022 11:10:53 +0100 Subject: [PATCH] Refactoring --- .../main/java/eu/faircode/email/Widget.java | 52 +++++++++---------- .../java/eu/faircode/email/WidgetSync.java | 6 +-- .../java/eu/faircode/email/WidgetUnified.java | 6 +-- app/src/main/res/layout/widget.xml | 2 +- app/src/main/res/layout/widget_new.xml | 2 +- app/src/main/res/layout/widget_sync.xml | 2 +- app/src/main/res/layout/widget_unified.xml | 2 +- 7 files changed, 36 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Widget.java b/app/src/main/java/eu/faircode/email/Widget.java index 9f65757676..463ef54a6c 100644 --- a/app/src/main/java/eu/faircode/email/Widget.java +++ b/app/src/main/java/eu/faircode/email/Widget.java @@ -110,7 +110,32 @@ public class Widget extends AppWidgetProvider { RemoteViews views = new RemoteViews(context.getPackageName(), layout == 0 ? R.layout.widget : R.layout.widget_new); - views.setOnClickPendingIntent(android.R.id.background, pi); + views.setOnClickPendingIntent(R.id.background, pi); + + if (background == Color.TRANSPARENT) { + if (semi) + views.setInt(R.id.background, "setBackgroundResource", R.drawable.widget_background); + 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); + } else { + float lum = (float) ColorUtils.calculateLuminance(background); + + if (semi) + background = ColorUtils.setAlphaComponent(background, 127); + + 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); + } + } if (layout == 1) views.setImageViewResource(R.id.ivMessage, unseen == 0 @@ -128,31 +153,6 @@ public class Widget extends AppWidgetProvider { views.setViewVisibility(R.id.tvAccount, ViewStripe.VISIBLE); } - if (background == Color.TRANSPARENT) { - if (semi) - views.setInt(android.R.id.background, "setBackgroundResource", R.drawable.widget_background); - else - views.setInt(android.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); - } else { - float lum = (float) ColorUtils.calculateLuminance(background); - - if (semi) - background = ColorUtils.setAlphaComponent(background, 127); - - views.setInt(android.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 pad = Helper.dp2pixels(context, layout == 0 ? 3 : 6); views.setViewPadding(R.id.content, pad, pad, pad, pad); diff --git a/app/src/main/java/eu/faircode/email/WidgetSync.java b/app/src/main/java/eu/faircode/email/WidgetSync.java index 975421a94f..876ec540cb 100644 --- a/app/src/main/java/eu/faircode/email/WidgetSync.java +++ b/app/src/main/java/eu/faircode/email/WidgetSync.java @@ -59,9 +59,9 @@ public class WidgetSync extends AppWidgetProvider { if (background == Color.TRANSPARENT) { if (semi) - views.setInt(android.R.id.background, "setBackgroundResource", R.drawable.widget_background); + views.setInt(R.id.background, "setBackgroundResource", R.drawable.widget_background); else - views.setInt(android.R.id.background, "setBackgroundColor", background); + views.setInt(R.id.background, "setBackgroundColor", background); views.setInt(R.id.ivSync, "setColorFilter", context.getResources().getColor(R.color.colorWidgetForeground)); } else { @@ -70,7 +70,7 @@ public class WidgetSync extends AppWidgetProvider { if (semi) background = ColorUtils.setAlphaComponent(background, 127); - views.setInt(android.R.id.background, "setBackgroundColor", background); + views.setInt(R.id.background, "setBackgroundColor", background); if (lum > 0.7f) views.setInt(R.id.ivSync, "setColorFilter", Color.BLACK); diff --git a/app/src/main/java/eu/faircode/email/WidgetUnified.java b/app/src/main/java/eu/faircode/email/WidgetUnified.java index ab2fd84ede..924ff6a2b3 100644 --- a/app/src/main/java/eu/faircode/email/WidgetUnified.java +++ b/app/src/main/java/eu/faircode/email/WidgetUnified.java @@ -131,9 +131,9 @@ public class WidgetUnified extends AppWidgetProvider { if (background == Color.TRANSPARENT) { if (semi) - views.setInt(android.R.id.background, "setBackgroundResource", R.drawable.widget_background); + views.setInt(R.id.background, "setBackgroundResource", R.drawable.widget_background); else - views.setInt(android.R.id.background, "setBackgroundColor", background); + views.setInt(R.id.background, "setBackgroundColor", background); int colorWidgetForeground = context.getResources().getColor(R.color.colorWidgetForeground); views.setTextColor(R.id.title, colorWidgetForeground); @@ -143,7 +143,7 @@ public class WidgetUnified extends AppWidgetProvider { if (semi) background = ColorUtils.setAlphaComponent(background, 127); - views.setInt(android.R.id.background, "setBackgroundColor", background); + views.setInt(R.id.background, "setBackgroundColor", background); if (lum > 0.7f) views.setTextColor(R.id.title, Color.BLACK); diff --git a/app/src/main/res/layout/widget.xml b/app/src/main/res/layout/widget.xml index 10752f0b18..72e3ce6240 100644 --- a/app/src/main/res/layout/widget.xml +++ b/app/src/main/res/layout/widget.xml @@ -1,7 +1,7 @@ diff --git a/app/src/main/res/layout/widget_new.xml b/app/src/main/res/layout/widget_new.xml index 873cab7daf..6911bf4e10 100644 --- a/app/src/main/res/layout/widget_new.xml +++ b/app/src/main/res/layout/widget_new.xml @@ -1,7 +1,7 @@ diff --git a/app/src/main/res/layout/widget_sync.xml b/app/src/main/res/layout/widget_sync.xml index 91e76061ff..0a0da560db 100644 --- a/app/src/main/res/layout/widget_sync.xml +++ b/app/src/main/res/layout/widget_sync.xml @@ -1,7 +1,7 @@ diff --git a/app/src/main/res/layout/widget_unified.xml b/app/src/main/res/layout/widget_unified.xml index d8588fbfd0..9ba18d9a0e 100644 --- a/app/src/main/res/layout/widget_unified.xml +++ b/app/src/main/res/layout/widget_unified.xml @@ -1,7 +1,7 @@