Small widget improvement

pull/194/merge
M66B 3 years ago
parent d937d4edfd
commit aa76c6f478

@ -53,6 +53,7 @@ public class Widget extends AppWidgetProvider {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
NumberFormat nf = NumberFormat.getIntegerInstance(); NumberFormat nf = NumberFormat.getIntegerInstance();
int colorWidgetForeground = context.getResources().getColor(R.color.colorWidgetForeground);
for (int appWidgetId : appWidgetIds) { for (int appWidgetId : appWidgetIds) {
String name = prefs.getString("widget." + appWidgetId + ".name", null); String name = prefs.getString("widget." + appWidgetId + ".name", null);
@ -118,7 +119,6 @@ public class Widget extends AppWidgetProvider {
else else
views.setInt(R.id.background, "setBackgroundColor", background); views.setInt(R.id.background, "setBackgroundColor", background);
int colorWidgetForeground = context.getResources().getColor(R.color.colorWidgetForeground);
views.setInt(R.id.ivMessage, "setColorFilter", colorWidgetForeground); views.setInt(R.id.ivMessage, "setColorFilter", colorWidgetForeground);
views.setTextColor(R.id.tvCount, colorWidgetForeground); views.setTextColor(R.id.tvCount, colorWidgetForeground);
views.setTextColor(R.id.tvAccount, colorWidgetForeground); views.setTextColor(R.id.tvAccount, colorWidgetForeground);
@ -130,11 +130,10 @@ public class Widget extends AppWidgetProvider {
views.setInt(R.id.background, "setBackgroundColor", background); views.setInt(R.id.background, "setBackgroundColor", background);
if (lum > 0.7f) { int fg = (lum > 0.7f ? Color.BLACK : colorWidgetForeground);
views.setInt(R.id.ivMessage, "setColorFilter", Color.BLACK); views.setInt(R.id.ivMessage, "setColorFilter", fg);
views.setTextColor(R.id.tvCount, Color.BLACK); views.setTextColor(R.id.tvCount, layout == 0 ? fg : colorWidgetForeground);
views.setTextColor(R.id.tvAccount, Color.BLACK); views.setTextColor(R.id.tvAccount, fg);
}
} }
if (layout == 1) if (layout == 1)

@ -45,6 +45,8 @@ public class WidgetSync extends AppWidgetProvider {
PendingIntent pi = PendingIntentCompat.getForegroundService( PendingIntent pi = PendingIntentCompat.getForegroundService(
context, ServiceSynchronize.PI_ENABLE, intent, PendingIntent.FLAG_UPDATE_CURRENT); context, ServiceSynchronize.PI_ENABLE, intent, PendingIntent.FLAG_UPDATE_CURRENT);
int colorWidgetForeground = context.getResources().getColor(R.color.colorWidgetForeground);
for (int appWidgetId : appWidgetIds) { for (int appWidgetId : appWidgetIds) {
boolean semi = prefs.getBoolean("widget." + appWidgetId + ".semi", true); boolean semi = prefs.getBoolean("widget." + appWidgetId + ".semi", true);
int background = prefs.getInt("widget." + appWidgetId + ".background", Color.TRANSPARENT); 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); views.setInt(R.id.background, "setBackgroundResource", R.drawable.widget_background);
else else
views.setInt(R.id.background, "setBackgroundColor", background); views.setInt(R.id.background, "setBackgroundColor", background);
views.setInt(R.id.ivSync, "setColorFilter", views.setInt(R.id.ivSync, "setColorFilter", colorWidgetForeground);
context.getResources().getColor(R.color.colorWidgetForeground));
} else { } else {
float lum = (float) ColorUtils.calculateLuminance(background); float lum = (float) ColorUtils.calculateLuminance(background);
@ -72,8 +73,8 @@ public class WidgetSync extends AppWidgetProvider {
views.setInt(R.id.background, "setBackgroundColor", background); views.setInt(R.id.background, "setBackgroundColor", background);
if (lum > 0.7f) int fg = (lum > 0.7f ? Color.BLACK : colorWidgetForeground);
views.setInt(R.id.ivSync, "setColorFilter", Color.BLACK); views.setInt(R.id.ivSync, "setColorFilter", fg);
} }
int dp6 = Helper.dp2pixels(context, 6); int dp6 = Helper.dp2pixels(context, 6);

@ -40,6 +40,8 @@ public class WidgetUnified extends AppWidgetProvider {
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
int colorWidgetForeground = context.getResources().getColor(R.color.colorWidgetForeground);
for (int appWidgetId : appWidgetIds) { for (int appWidgetId : appWidgetIds) {
String name = prefs.getString("widget." + appWidgetId + ".name", null); String name = prefs.getString("widget." + appWidgetId + ".name", null);
long account = prefs.getLong("widget." + appWidgetId + ".account", -1L); long account = prefs.getLong("widget." + appWidgetId + ".account", -1L);
@ -135,7 +137,6 @@ public class WidgetUnified extends AppWidgetProvider {
else else
views.setInt(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); views.setTextColor(R.id.title, colorWidgetForeground);
} else { } else {
float lum = (float) ColorUtils.calculateLuminance(background); float lum = (float) ColorUtils.calculateLuminance(background);
@ -145,8 +146,8 @@ public class WidgetUnified extends AppWidgetProvider {
views.setInt(R.id.background, "setBackgroundColor", background); views.setInt(R.id.background, "setBackgroundColor", background);
if (lum > 0.7f) int fg = (lum > 0.7f ? Color.BLACK : colorWidgetForeground);
views.setTextColor(R.id.title, Color.BLACK); views.setTextColor(R.id.title, fg);
} }
int dp6 = Helper.dp2pixels(context, 6); int dp6 = Helper.dp2pixels(context, 6);

Loading…
Cancel
Save