Widget: refactoring

pull/194/merge
M66B 4 years ago
parent bc851f44c8
commit c8ff96f2b7

@ -113,40 +113,45 @@ public class Widget extends AppWidgetProvider {
views.setOnClickPendingIntent(R.id.background, pi); views.setOnClickPendingIntent(R.id.background, pi);
if (background == Color.TRANSPARENT) { // Set background
if (semi) if (semi)
views.setInt(R.id.background, "setBackgroundResource", R.drawable.widget_background); if (background == Color.TRANSPARENT)
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",
ColorUtils.setAlphaComponent(background, 127));
else
views.setInt(R.id.background, "setBackgroundColor", background);
// Set image
if (layout == 1)
views.setImageViewResource(R.id.ivMessage, unseen == 0
? R.drawable.baseline_mail_outline_widget_24
: R.drawable.baseline_mail_widget_24);
else
views.setImageViewResource(R.id.ivMessage, unseen == 0
? R.drawable.twotone_mail_outline_24
: R.drawable.baseline_mail_24);
// Set color
if (background == Color.TRANSPARENT) {
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);
} else { } else {
float lum = (float) ColorUtils.calculateLuminance(background); float lum = (float) ColorUtils.calculateLuminance(background);
if (semi)
background = ColorUtils.setAlphaComponent(background, 127);
views.setInt(R.id.background, "setBackgroundColor", background);
int fg = (lum > 0.7f ? Color.BLACK : colorWidgetForeground); int fg = (lum > 0.7f ? Color.BLACK : colorWidgetForeground);
views.setInt(R.id.ivMessage, "setColorFilter", fg); views.setInt(R.id.ivMessage, "setColorFilter", fg);
views.setTextColor(R.id.tvCount, layout == 0 ? fg : colorWidgetForeground); views.setTextColor(R.id.tvCount, layout == 0 ? fg : colorWidgetForeground);
views.setTextColor(R.id.tvAccount, fg); views.setTextColor(R.id.tvAccount, fg);
} }
if (layout == 1) // Set count
views.setImageViewResource(R.id.ivMessage, unseen == 0
? R.drawable.baseline_mail_outline_widget_24
: R.drawable.baseline_mail_widget_24);
else
views.setImageViewResource(R.id.ivMessage, unseen == 0
? R.drawable.twotone_mail_outline_24
: R.drawable.baseline_mail_24);
views.setTextViewText(R.id.tvCount, unseen < 100 ? nf.format(unseen) : "99+"); views.setTextViewText(R.id.tvCount, unseen < 100 ? nf.format(unseen) : "99+");
views.setViewVisibility(R.id.tvCount, layout == 1 && unseen == 0 ? View.GONE : View.VISIBLE); views.setViewVisibility(R.id.tvCount, layout == 1 && unseen == 0 ? View.GONE : View.VISIBLE);
// Set account name
if (!TextUtils.isEmpty(name)) { if (!TextUtils.isEmpty(name)) {
views.setTextViewText(R.id.tvAccount, name); views.setTextViewText(R.id.tvAccount, name);
views.setViewVisibility(R.id.tvAccount, ViewStripe.VISIBLE); views.setViewVisibility(R.id.tvAccount, ViewStripe.VISIBLE);

Loading…
Cancel
Save