Added widget icon color option

pull/214/head
M66B 1 year ago
parent e765bc28ad
commit 73892c4797

@ -40,6 +40,7 @@ import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import androidx.constraintlayout.widget.Group; import androidx.constraintlayout.widget.Group;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.ColorUtils; import androidx.core.graphics.ColorUtils;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
@ -56,7 +57,8 @@ public class ActivityWidget extends ActivityBase {
private Spinner spAccount; private Spinner spAccount;
private CheckBox cbDayNight; private CheckBox cbDayNight;
private CheckBox cbSemiTransparent; private CheckBox cbSemiTransparent;
private ViewButtonColor btnColor; private ViewButtonColor btnBgColor;
private ViewButtonColor btnFgColor;
private View inOld; private View inOld;
private View inNew; private View inNew;
private RadioButton rbOld; private RadioButton rbOld;
@ -87,6 +89,7 @@ public class ActivityWidget extends ActivityBase {
boolean daynight = prefs.getBoolean("widget." + appWidgetId + ".daynight", false); boolean daynight = prefs.getBoolean("widget." + appWidgetId + ".daynight", false);
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);
int foreground = prefs.getInt("widget." + appWidgetId + ".foreground", Color.TRANSPARENT);
int layout = prefs.getInt("widget." + appWidgetId + ".layout", 1 /* new */); int layout = prefs.getInt("widget." + appWidgetId + ".layout", 1 /* new */);
boolean top = prefs.getBoolean("widget." + appWidgetId + ".top", false); boolean top = prefs.getBoolean("widget." + appWidgetId + ".top", false);
int size = prefs.getInt("widget." + appWidgetId + ".text_size", -1); int size = prefs.getInt("widget." + appWidgetId + ".text_size", -1);
@ -100,7 +103,8 @@ public class ActivityWidget extends ActivityBase {
spAccount = findViewById(R.id.spAccount); spAccount = findViewById(R.id.spAccount);
cbDayNight = findViewById(R.id.cbDayNight); cbDayNight = findViewById(R.id.cbDayNight);
cbSemiTransparent = findViewById(R.id.cbSemiTransparent); cbSemiTransparent = findViewById(R.id.cbSemiTransparent);
btnColor = findViewById(R.id.btnColor); btnBgColor = findViewById(R.id.btnBgColor);
btnFgColor = findViewById(R.id.btnFgColor);
inOld = findViewById(R.id.inOld); inOld = findViewById(R.id.inOld);
inNew = findViewById(R.id.inNew); inNew = findViewById(R.id.inNew);
rbOld = findViewById(R.id.rbOld); rbOld = findViewById(R.id.rbOld);
@ -118,7 +122,8 @@ public class ActivityWidget extends ActivityBase {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
cbSemiTransparent.setEnabled(!checked); cbSemiTransparent.setEnabled(!checked);
btnColor.setEnabled(!checked); btnBgColor.setEnabled(!checked);
updatePreview();
} }
}); });
@ -126,15 +131,15 @@ public class ActivityWidget extends ActivityBase {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) if (isChecked && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
btnColor.setColor(Color.TRANSPARENT); btnBgColor.setColor(Color.TRANSPARENT);
updatePreview(); updatePreview();
} }
}); });
btnColor.setOnClickListener(new View.OnClickListener() { btnBgColor.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
int color = btnColor.getColor(); int color = btnBgColor.getColor();
int editTextColor = Helper.resolveColor(ActivityWidget.this, android.R.attr.editTextColor); int editTextColor = Helper.resolveColor(ActivityWidget.this, android.R.attr.editTextColor);
if (color == Color.TRANSPARENT) { if (color == Color.TRANSPARENT) {
@ -158,7 +163,7 @@ public class ActivityWidget extends ActivityBase {
public void onClick(DialogInterface dialog, int selectedColor, Integer[] allColors) { public void onClick(DialogInterface dialog, int selectedColor, Integer[] allColors) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
cbSemiTransparent.setChecked(false); cbSemiTransparent.setChecked(false);
btnColor.setColor(selectedColor); btnBgColor.setColor(selectedColor);
updatePreview(); updatePreview();
} }
}) })
@ -166,7 +171,42 @@ public class ActivityWidget extends ActivityBase {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
cbSemiTransparent.setChecked(false); cbSemiTransparent.setChecked(false);
btnColor.setColor(Color.TRANSPARENT); btnBgColor.setColor(Color.TRANSPARENT);
updatePreview();
}
})
.build()
.show();
}
});
btnFgColor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int color = btnFgColor.getColor();
int editTextColor = Helper.resolveColor(ActivityWidget.this, android.R.attr.editTextColor);
ColorPickerDialogBuilder
.with(ActivityWidget.this)
.setTitle(R.string.title_widget_icon)
.showColorEdit(true)
.setColorEditTextColor(editTextColor)
.wheelType(ColorPickerView.WHEEL_TYPE.FLOWER)
.density(6)
.initialColor(color == Color.TRANSPARENT ? Color.WHITE : color)
.showLightnessSlider(true)
.showAlphaSlider(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
.setPositiveButton(android.R.string.ok, new ColorPickerClickListener() {
@Override
public void onClick(DialogInterface dialog, int selectedColor, Integer[] allColors) {
btnFgColor.setColor(selectedColor);
updatePreview();
}
})
.setNegativeButton(R.string.title_reset, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
btnFgColor.setColor(Color.TRANSPARENT);
updatePreview(); updatePreview();
} }
}) })
@ -226,7 +266,8 @@ public class ActivityWidget extends ActivityBase {
editor.putLong("widget." + appWidgetId + ".account", account == null ? -1L : account.id); editor.putLong("widget." + appWidgetId + ".account", account == null ? -1L : account.id);
editor.putBoolean("widget." + appWidgetId + ".daynight", cbDayNight.isChecked()); editor.putBoolean("widget." + appWidgetId + ".daynight", cbDayNight.isChecked());
editor.putBoolean("widget." + appWidgetId + ".semi", cbSemiTransparent.isChecked()); editor.putBoolean("widget." + appWidgetId + ".semi", cbSemiTransparent.isChecked());
editor.putInt("widget." + appWidgetId + ".background", btnColor.getColor()); editor.putInt("widget." + appWidgetId + ".background", btnBgColor.getColor());
editor.putInt("widget." + appWidgetId + ".foreground", btnFgColor.getColor());
editor.putInt("widget." + appWidgetId + ".layout", rbNew.isChecked() ? 1 : 0); editor.putInt("widget." + appWidgetId + ".layout", rbNew.isChecked() ? 1 : 0);
editor.putBoolean("widget." + appWidgetId + ".top", cbTop.isChecked()); editor.putBoolean("widget." + appWidgetId + ".top", cbTop.isChecked());
if (pos > 0) if (pos > 0)
@ -256,8 +297,9 @@ public class ActivityWidget extends ActivityBase {
cbDayNight.setVisibility(Build.VERSION.SDK_INT < Build.VERSION_CODES.S ? View.GONE : View.VISIBLE); cbDayNight.setVisibility(Build.VERSION.SDK_INT < Build.VERSION_CODES.S ? View.GONE : View.VISIBLE);
cbSemiTransparent.setChecked(semi); cbSemiTransparent.setChecked(semi);
cbSemiTransparent.setEnabled(!daynight); cbSemiTransparent.setEnabled(!daynight);
btnColor.setColor(background); btnBgColor.setColor(background);
btnColor.setEnabled(!daynight); btnBgColor.setEnabled(!daynight);
btnFgColor.setColor(foreground);
rbOld.setChecked(layout != 1); rbOld.setChecked(layout != 1);
rbNew.setChecked(layout == 1); rbNew.setChecked(layout == 1);
cbTop.setChecked(top); cbTop.setChecked(top);
@ -310,8 +352,14 @@ public class ActivityWidget extends ActivityBase {
} }
private void updatePreview() { private void updatePreview() {
boolean daynight = cbDayNight.isChecked();
boolean semi = cbSemiTransparent.isChecked(); boolean semi = cbSemiTransparent.isChecked();
int background = btnColor.getColor(); int background = btnBgColor.getColor();
int foreground = btnFgColor.getColor();
int textColorPrimary = Helper.resolveColor(ActivityWidget.this, android.R.attr.textColorPrimary);
int colorWidgetForeground = ContextCompat.getColor(ActivityWidget.this, R.color.colorWidgetForeground);
if (background == Color.TRANSPARENT) { if (background == Color.TRANSPARENT) {
if (semi) { if (semi) {
inOld.setBackgroundResource(R.drawable.widget_background); inOld.setBackgroundResource(R.drawable.widget_background);
@ -321,22 +369,49 @@ public class ActivityWidget extends ActivityBase {
inNew.setBackgroundColor(background); inNew.setBackgroundColor(background);
} }
} else { } else {
float lum = (float) ColorUtils.calculateLuminance(background);
int color = (lum > 0.7 ? Color.BLACK : getResources().getColor(R.color.colorWidgetForeground));
if (semi) if (semi)
background = ColorUtils.setAlphaComponent(background, 127); background = ColorUtils.setAlphaComponent(background, 127);
inOld.setBackgroundColor(background); inOld.setBackgroundColor(background);
inNew.setBackgroundColor(background); inNew.setBackgroundColor(background);
}
((ImageView) inOld.findViewById(R.id.ivMessage)).setColorFilter(color); if (daynight && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
((TextView) inOld.findViewById(R.id.tvCount)).setTextColor(color); ((ImageView) inOld.findViewById(R.id.ivMessage)).setColorFilter(
((TextView) inOld.findViewById(R.id.tvAccount)).setTextColor(color); foreground == Color.TRANSPARENT ? textColorPrimary : foreground);
((TextView) inOld.findViewById(R.id.tvCount)).setTextColor(textColorPrimary);
((ImageView) inNew.findViewById(R.id.ivMessage)).setColorFilter(color); ((TextView) inOld.findViewById(R.id.tvAccount)).setTextColor(textColorPrimary);
((TextView) inNew.findViewById(R.id.tvCount)).setTextColor(color);
((TextView) inNew.findViewById(R.id.tvCountTop)).setTextColor(color); ((ImageView) inNew.findViewById(R.id.ivMessage)).setColorFilter(
((TextView) inNew.findViewById(R.id.tvAccount)).setTextColor(color); foreground == Color.TRANSPARENT ? textColorPrimary : foreground);
((TextView) inNew.findViewById(R.id.tvCount)).setTextColor(colorWidgetForeground);
((TextView) inNew.findViewById(R.id.tvCountTop)).setTextColor(colorWidgetForeground);
((TextView) inNew.findViewById(R.id.tvAccount)).setTextColor(textColorPrimary);
} else if (background == Color.TRANSPARENT) {
((ImageView) inOld.findViewById(R.id.ivMessage)).setColorFilter(
foreground == Color.TRANSPARENT ? colorWidgetForeground : foreground);
((TextView) inOld.findViewById(R.id.tvCount)).setTextColor(colorWidgetForeground);
((TextView) inOld.findViewById(R.id.tvAccount)).setTextColor(colorWidgetForeground);
((ImageView) inNew.findViewById(R.id.ivMessage)).setColorFilter(
foreground == Color.TRANSPARENT ? colorWidgetForeground : foreground);
((TextView) inNew.findViewById(R.id.tvCount)).setTextColor(colorWidgetForeground);
((TextView) inNew.findViewById(R.id.tvCountTop)).setTextColor(colorWidgetForeground);
((TextView) inNew.findViewById(R.id.tvAccount)).setTextColor(colorWidgetForeground);
} else {
float lum = (float) ColorUtils.calculateLuminance(background);
int fg = (lum > 0.7f ? Color.BLACK : colorWidgetForeground);
((ImageView) inOld.findViewById(R.id.ivMessage)).setColorFilter(
foreground == Color.TRANSPARENT ? fg : foreground);
((TextView) inOld.findViewById(R.id.tvCount)).setTextColor(fg);
((TextView) inOld.findViewById(R.id.tvAccount)).setTextColor(fg);
((ImageView) inNew.findViewById(R.id.ivMessage)).setColorFilter(
foreground == Color.TRANSPARENT ? fg : foreground);
((TextView) inNew.findViewById(R.id.tvCount)).setTextColor(colorWidgetForeground);
((TextView) inNew.findViewById(R.id.tvCountTop)).setTextColor(colorWidgetForeground);
((TextView) inNew.findViewById(R.id.tvAccount)).setTextColor(fg);
} }
boolean top = cbTop.isChecked(); boolean top = cbTop.isChecked();

@ -62,6 +62,7 @@ public class Widget extends AppWidgetProvider {
boolean daynight = prefs.getBoolean("widget." + appWidgetId + ".daynight", false); boolean daynight = prefs.getBoolean("widget." + appWidgetId + ".daynight", false);
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);
int foreground = prefs.getInt("widget." + appWidgetId + ".foreground", Color.TRANSPARENT);
int layout = prefs.getInt("widget." + appWidgetId + ".layout", 0); int layout = prefs.getInt("widget." + appWidgetId + ".layout", 0);
boolean top = prefs.getBoolean("widget." + appWidgetId + ".top", false); boolean top = prefs.getBoolean("widget." + appWidgetId + ".top", false);
int size = prefs.getInt("widget." + appWidgetId + ".text_size", -1); int size = prefs.getInt("widget." + appWidgetId + ".text_size", -1);
@ -146,7 +147,8 @@ public class Widget extends AppWidgetProvider {
// Set color // Set color
if (daynight && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { if (daynight && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
views.setColorAttr(R.id.ivMessage, "setColorFilter", android.R.attr.textColorPrimary); views.setColorAttr(R.id.ivMessage, "setColorFilter",
foreground == Color.TRANSPARENT ? android.R.attr.textColorPrimary : foreground);
if (layout == 0) if (layout == 0)
views.setColorStateListAttr(R.id.tvCount, "setTextColor", android.R.attr.textColorPrimary); views.setColorStateListAttr(R.id.tvCount, "setTextColor", android.R.attr.textColorPrimary);
else { else {
@ -155,14 +157,16 @@ public class Widget extends AppWidgetProvider {
} }
views.setColorStateListAttr(R.id.tvAccount, "setTextColor", android.R.attr.textColorPrimary); views.setColorStateListAttr(R.id.tvAccount, "setTextColor", android.R.attr.textColorPrimary);
} else if (background == Color.TRANSPARENT) { } else if (background == Color.TRANSPARENT) {
views.setInt(R.id.ivMessage, "setColorFilter", colorWidgetForeground); views.setInt(R.id.ivMessage, "setColorFilter",
foreground == Color.TRANSPARENT ? colorWidgetForeground : foreground);
views.setTextColor(R.id.tvCount, colorWidgetForeground); views.setTextColor(R.id.tvCount, colorWidgetForeground);
views.setTextColor(R.id.tvCountTop, colorWidgetForeground); views.setTextColor(R.id.tvCountTop, 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);
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",
foreground == Color.TRANSPARENT ? fg : foreground);
views.setTextColor(R.id.tvCount, layout == 0 ? fg : colorWidgetForeground); views.setTextColor(R.id.tvCount, layout == 0 ? fg : colorWidgetForeground);
views.setTextColor(R.id.tvCountTop, layout == 0 ? fg : colorWidgetForeground); views.setTextColor(R.id.tvCountTop, layout == 0 ? fg : colorWidgetForeground);
views.setTextColor(R.id.tvAccount, fg); views.setTextColor(R.id.tvAccount, fg);

@ -54,7 +54,7 @@
app:layout_constraintTop_toBottomOf="@id/cbDayNight" /> app:layout_constraintTop_toBottomOf="@id/cbDayNight" />
<eu.faircode.email.ViewButtonColor <eu.faircode.email.ViewButtonColor
android:id="@+id/btnColor" android:id="@+id/btnBgColor"
style="?android:attr/buttonStyleSmall" style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -66,6 +66,19 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbSemiTransparent" /> app:layout_constraintTop_toBottomOf="@id/cbSemiTransparent" />
<eu.faircode.email.ViewButtonColor
android:id="@+id/btnFgColor"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:paddingHorizontal="6dp"
android:tag="disable"
android:text="@string/title_widget_icon"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnBgColor" />
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/clLayout" android:id="@+id/clLayout"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -74,7 +87,7 @@
android:background="@android:color/darker_gray" android:background="@android:color/darker_gray"
android:padding="24dp" android:padding="24dp"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnColor"> app:layout_constraintTop_toBottomOf="@id/btnFgColor">
<include <include
android:id="@+id/inOld" android:id="@+id/inOld"

@ -2333,6 +2333,7 @@
<string name="title_widget_refresh">Show refresh messages button</string> <string name="title_widget_refresh">Show refresh messages button</string>
<string name="title_widget_compose">Show compose new message button</string> <string name="title_widget_compose">Show compose new message button</string>
<string name="title_widget_background">Background color</string> <string name="title_widget_background">Background color</string>
<string name="title_widget_icon">Icon color</string>
<string name="title_widget_day_night">Follow dark system theme</string> <string name="title_widget_day_night">Follow dark system theme</string>
<string name="title_compat_dark">Google removed dark mode for Android versions before version 10</string> <string name="title_compat_dark">Google removed dark mode for Android versions before version 10</string>

Loading…
Cancel
Save