mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-09 18:43:23 +02:00
Added day/night mode for count widget
This commit is contained in:
@@ -25,6 +25,7 @@ import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
@@ -51,6 +52,7 @@ public class ActivityWidget extends ActivityBase {
|
||||
private int appWidgetId;
|
||||
|
||||
private Spinner spAccount;
|
||||
private CheckBox cbDayNight;
|
||||
private CheckBox cbSemiTransparent;
|
||||
private ViewButtonColor btnColor;
|
||||
private View inOld;
|
||||
@@ -78,15 +80,19 @@ public class ActivityWidget extends ActivityBase {
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
long account = prefs.getLong("widget." + appWidgetId + ".account", -1L);
|
||||
boolean daynight = prefs.getBoolean("widget." + appWidgetId + ".daynight", false);
|
||||
boolean semi = prefs.getBoolean("widget." + appWidgetId + ".semi", true);
|
||||
int background = prefs.getInt("widget." + appWidgetId + ".background", Color.TRANSPARENT);
|
||||
int layout = prefs.getInt("widget." + appWidgetId + ".layout", 1 /* new */);
|
||||
|
||||
daynight = daynight && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S);
|
||||
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setSubtitle(R.string.title_widget_title_count);
|
||||
setContentView(R.layout.activity_widget);
|
||||
|
||||
spAccount = findViewById(R.id.spAccount);
|
||||
cbDayNight = findViewById(R.id.cbDayNight);
|
||||
cbSemiTransparent = findViewById(R.id.cbSemiTransparent);
|
||||
btnColor = findViewById(R.id.btnColor);
|
||||
inOld = findViewById(R.id.inOld);
|
||||
@@ -100,6 +106,14 @@ public class ActivityWidget extends ActivityBase {
|
||||
final Intent resultValue = new Intent();
|
||||
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
|
||||
|
||||
cbDayNight.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
cbSemiTransparent.setEnabled(!checked);
|
||||
btnColor.setEnabled(!checked);
|
||||
}
|
||||
});
|
||||
|
||||
cbSemiTransparent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
@@ -167,6 +181,7 @@ public class ActivityWidget extends ActivityBase {
|
||||
else
|
||||
editor.remove("widget." + appWidgetId + ".name");
|
||||
editor.putLong("widget." + appWidgetId + ".account", account == null ? -1L : account.id);
|
||||
editor.putBoolean("widget." + appWidgetId + ".daynight", cbDayNight.isChecked());
|
||||
editor.putBoolean("widget." + appWidgetId + ".semi", cbSemiTransparent.isChecked());
|
||||
editor.putInt("widget." + appWidgetId + ".background", btnColor.getColor());
|
||||
editor.putInt("widget." + appWidgetId + ".layout", rbNew.isChecked() ? 1 : 0);
|
||||
@@ -188,8 +203,12 @@ public class ActivityWidget extends ActivityBase {
|
||||
((TextView) inOld.findViewById(R.id.tvCount)).setText("12");
|
||||
((TextView) inNew.findViewById(R.id.tvCount)).setText("12");
|
||||
|
||||
cbDayNight.setChecked(daynight);
|
||||
cbDayNight.setVisibility(Build.VERSION.SDK_INT < Build.VERSION_CODES.S ? View.GONE : View.VISIBLE);
|
||||
cbSemiTransparent.setChecked(semi);
|
||||
cbSemiTransparent.setEnabled(!daynight);
|
||||
btnColor.setColor(background);
|
||||
btnColor.setEnabled(!daynight);
|
||||
rbOld.setChecked(layout != 1);
|
||||
rbNew.setChecked(layout == 1);
|
||||
setBackground();
|
||||
|
||||
@@ -27,6 +27,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.RemoteViews;
|
||||
@@ -58,6 +59,7 @@ public class Widget extends AppWidgetProvider {
|
||||
for (int appWidgetId : appWidgetIds) {
|
||||
String name = prefs.getString("widget." + appWidgetId + ".name", null);
|
||||
long account = prefs.getLong("widget." + appWidgetId + ".account", -1L);
|
||||
boolean daynight = prefs.getBoolean("widget." + appWidgetId + ".daynight", false);
|
||||
boolean semi = prefs.getBoolean("widget." + appWidgetId + ".semi", true);
|
||||
int background = prefs.getInt("widget." + appWidgetId + ".background", Color.TRANSPARENT);
|
||||
int layout = prefs.getInt("widget." + appWidgetId + ".layout", 0);
|
||||
@@ -114,7 +116,12 @@ public class Widget extends AppWidgetProvider {
|
||||
views.setOnClickPendingIntent(R.id.background, pi);
|
||||
|
||||
// Set background
|
||||
if (semi)
|
||||
if (!daynight && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
|
||||
views.setColorStateListAttr(R.id.background, "setBackgroundTintList", 0);
|
||||
if (daynight && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
views.setInt(R.id.background, "setBackgroundColor", Color.WHITE);
|
||||
views.setColorStateListAttr(R.id.background, "setBackgroundTintList", android.R.attr.colorBackground);
|
||||
} else if (semi)
|
||||
if (background == Color.TRANSPARENT)
|
||||
views.setInt(R.id.background, "setBackgroundResource",
|
||||
R.drawable.widget_background);
|
||||
@@ -125,17 +132,35 @@ public class Widget extends AppWidgetProvider {
|
||||
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);
|
||||
if (daynight && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
if (layout == 1)
|
||||
views.setImageViewResource(R.id.ivMessage, unseen == 0
|
||||
? R.drawable.baseline_mail_outline_widget_24_dn
|
||||
: R.drawable.baseline_mail_widget_24_dn);
|
||||
else
|
||||
views.setImageViewResource(R.id.ivMessage, unseen == 0
|
||||
? R.drawable.twotone_mail_outline_24_dn
|
||||
: R.drawable.baseline_mail_24_dn);
|
||||
} else {
|
||||
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) {
|
||||
if (daynight && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
views.setColorAttr(R.id.ivMessage, "setColorFilter", android.R.attr.textColorPrimary);
|
||||
if (layout == 0)
|
||||
views.setColorStateListAttr(R.id.tvCount, "setTextColor", android.R.attr.textColorPrimary);
|
||||
else
|
||||
views.setTextColor(R.id.tvCount, colorWidgetForeground);
|
||||
views.setColorStateListAttr(R.id.tvAccount, "setTextColor", android.R.attr.textColorPrimary);
|
||||
} else if (background == Color.TRANSPARENT) {
|
||||
views.setInt(R.id.ivMessage, "setColorFilter", colorWidgetForeground);
|
||||
views.setTextColor(R.id.tvCount, colorWidgetForeground);
|
||||
views.setTextColor(R.id.tvAccount, colorWidgetForeground);
|
||||
|
||||
Reference in New Issue
Block a user