From bdb5d4d8a501d1456ce4165f023d00b4a5ad3914 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 26 Mar 2021 08:48:03 +0100 Subject: [PATCH] Use color button for widget configuration --- .../eu/faircode/email/ActivityWidget.java | 26 +++++++------------ .../eu/faircode/email/ActivityWidgetSync.java | 25 +++++------------- .../faircode/email/ActivityWidgetUnified.java | 23 +++++----------- app/src/main/res/layout/activity_widget.xml | 3 ++- .../main/res/layout/activity_widget_sync.xml | 3 ++- .../res/layout/activity_widget_unified.xml | 3 ++- 6 files changed, 30 insertions(+), 53 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityWidget.java b/app/src/main/java/eu/faircode/email/ActivityWidget.java index 3d14ac333a..bc1a84b1bc 100644 --- a/app/src/main/java/eu/faircode/email/ActivityWidget.java +++ b/app/src/main/java/eu/faircode/email/ActivityWidget.java @@ -52,7 +52,7 @@ public class ActivityWidget extends ActivityBase { private Spinner spAccount; private CheckBox cbSemiTransparent; - private Button btnColor; + private ViewButtonColor btnColor; private View inOld; private View inNew; private RadioButton rbOld; @@ -61,7 +61,6 @@ public class ActivityWidget extends ActivityBase { private ContentLoadingProgressBar pbWait; private Group grpReady; - private int background = Color.TRANSPARENT; private ArrayAdapter adapterAccount; @Override @@ -74,9 +73,6 @@ public class ActivityWidget extends ActivityBase { return; } - if (savedInstanceState != null) - background = savedInstanceState.getInt("fair:color"); - appWidgetId = extras.getInt( AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); @@ -100,8 +96,8 @@ public class ActivityWidget extends ActivityBase { cbSemiTransparent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + btnColor.setColor(Color.TRANSPARENT); setBackground(); - btnColor.setEnabled(!isChecked); } }); @@ -121,14 +117,16 @@ public class ActivityWidget extends ActivityBase { .setPositiveButton(android.R.string.ok, new ColorPickerClickListener() { @Override public void onClick(DialogInterface dialog, int selectedColor, Integer[] allColors) { - background = selectedColor; + cbSemiTransparent.setChecked(false); + btnColor.setColor(selectedColor); setBackground(); } }) .setNegativeButton(R.string.title_reset, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - background = Color.TRANSPARENT; + cbSemiTransparent.setChecked(false); + btnColor.setColor(Color.TRANSPARENT); setBackground(); } }) @@ -166,7 +164,7 @@ public class ActivityWidget extends ActivityBase { editor.remove("widget." + appWidgetId + ".name"); editor.putLong("widget." + appWidgetId + ".account", account == null ? -1L : account.id); editor.putBoolean("widget." + appWidgetId + ".semi", cbSemiTransparent.isChecked()); - editor.putInt("widget." + appWidgetId + ".background", background); + editor.putInt("widget." + appWidgetId + ".background", btnColor.getColor()); editor.putInt("widget." + appWidgetId + ".layout", rbNew.isChecked() ? 1 : 0); editor.apply(); @@ -184,7 +182,8 @@ public class ActivityWidget extends ActivityBase { ((TextView) inOld.findViewById(R.id.tvCount)).setText("12"); ((TextView) inNew.findViewById(R.id.tvCount)).setText("12"); - btnColor.setEnabled(!cbSemiTransparent.isChecked()); + setBackground(); + grpReady.setVisibility(View.GONE); pbWait.setVisibility(View.VISIBLE); @@ -222,17 +221,12 @@ public class ActivityWidget extends ActivityBase { }.execute(this, new Bundle(), "widget:accounts"); } - @Override - protected void onSaveInstanceState(Bundle outState) { - outState.putInt("fair:color", background); - super.onSaveInstanceState(outState); - } - private void setBackground() { if (cbSemiTransparent.isChecked()) { inOld.setBackgroundResource(R.drawable.widget_background); inNew.setBackgroundResource(R.drawable.widget_background); } else { + int background = btnColor.getColor(); inOld.setBackgroundColor(background); inNew.setBackgroundColor(background); float lum = (float) ColorUtils.calculateLuminance(background); diff --git a/app/src/main/java/eu/faircode/email/ActivityWidgetSync.java b/app/src/main/java/eu/faircode/email/ActivityWidgetSync.java index 1987a67dbf..3ea5d486bb 100644 --- a/app/src/main/java/eu/faircode/email/ActivityWidgetSync.java +++ b/app/src/main/java/eu/faircode/email/ActivityWidgetSync.java @@ -40,11 +40,9 @@ public class ActivityWidgetSync extends ActivityBase { private int appWidgetId; private CheckBox cbSemiTransparent; - private Button btnColor; + private ViewButtonColor btnColor; private Button btnSave; - private int background = Color.TRANSPARENT; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -55,9 +53,6 @@ public class ActivityWidgetSync extends ActivityBase { return; } - if (savedInstanceState != null) - background = savedInstanceState.getInt("fair:color"); - appWidgetId = extras.getInt( AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); @@ -74,7 +69,7 @@ public class ActivityWidgetSync extends ActivityBase { cbSemiTransparent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - btnColor.setEnabled(!isChecked); + btnColor.setColor(Color.TRANSPARENT); } }); @@ -94,13 +89,15 @@ public class ActivityWidgetSync extends ActivityBase { .setPositiveButton(android.R.string.ok, new ColorPickerClickListener() { @Override public void onClick(DialogInterface dialog, int selectedColor, Integer[] allColors) { - background = selectedColor; + cbSemiTransparent.setChecked(false); + btnColor.setColor(selectedColor); } }) .setNegativeButton(R.string.title_reset, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - background = Color.TRANSPARENT; + cbSemiTransparent.setChecked(false); + btnColor.setColor(Color.TRANSPARENT); } }) .build() @@ -114,7 +111,7 @@ public class ActivityWidgetSync extends ActivityBase { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ActivityWidgetSync.this); SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean("widget." + appWidgetId + ".semi", cbSemiTransparent.isChecked()); - editor.putInt("widget." + appWidgetId + ".background", background); + editor.putInt("widget." + appWidgetId + ".background", btnColor.getColor()); editor.apply(); WidgetSync.init(ActivityWidgetSync.this, appWidgetId); @@ -124,14 +121,6 @@ public class ActivityWidgetSync extends ActivityBase { } }); - btnColor.setEnabled(!cbSemiTransparent.isChecked()); - setResult(RESULT_CANCELED, resultValue); } - - @Override - protected void onSaveInstanceState(Bundle outState) { - outState.putInt("fair:color", background); - super.onSaveInstanceState(outState); - } } diff --git a/app/src/main/java/eu/faircode/email/ActivityWidgetUnified.java b/app/src/main/java/eu/faircode/email/ActivityWidgetUnified.java index 2b2c1d3a16..b44338443b 100644 --- a/app/src/main/java/eu/faircode/email/ActivityWidgetUnified.java +++ b/app/src/main/java/eu/faircode/email/ActivityWidgetUnified.java @@ -57,14 +57,13 @@ public class ActivityWidgetUnified extends ActivityBase { private CheckBox cbUnseen; private CheckBox cbFlagged; private CheckBox cbSemiTransparent; - private Button btnColor; + private ViewButtonColor btnColor; private Spinner spFontSize; private Spinner spPadding; private Button btnSave; private ContentLoadingProgressBar pbWait; private Group grpReady; - private int background = Color.TRANSPARENT; private ArrayAdapter adapterAccount; private ArrayAdapter adapterFolder; private ArrayAdapter adapterFontSize; @@ -80,9 +79,6 @@ public class ActivityWidgetUnified extends ActivityBase { return; } - if (savedInstanceState != null) - background = savedInstanceState.getInt("fair:color"); - appWidgetId = extras.getInt( AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); @@ -107,7 +103,7 @@ public class ActivityWidgetUnified extends ActivityBase { cbSemiTransparent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - btnColor.setEnabled(!isChecked); + btnColor.setColor(Color.TRANSPARENT); } }); @@ -127,13 +123,15 @@ public class ActivityWidgetUnified extends ActivityBase { .setPositiveButton(android.R.string.ok, new ColorPickerClickListener() { @Override public void onClick(DialogInterface dialog, int selectedColor, Integer[] allColors) { - background = selectedColor; + cbSemiTransparent.setChecked(false); + btnColor.setColor(selectedColor); } }) .setNegativeButton(R.string.title_reset, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - background = Color.TRANSPARENT; + cbSemiTransparent.setChecked(false); + btnColor.setColor(Color.TRANSPARENT); } }) .build() @@ -164,7 +162,7 @@ public class ActivityWidgetUnified extends ActivityBase { editor.putBoolean("widget." + appWidgetId + ".unseen", cbUnseen.isChecked()); editor.putBoolean("widget." + appWidgetId + ".flagged", cbFlagged.isChecked()); editor.putBoolean("widget." + appWidgetId + ".semi", cbSemiTransparent.isChecked()); - editor.putInt("widget." + appWidgetId + ".background", background); + editor.putInt("widget." + appWidgetId + ".background", btnColor.getColor()); editor.putInt("widget." + appWidgetId + ".font", spFontSize.getSelectedItemPosition()); editor.putInt("widget." + appWidgetId + ".padding", spPadding.getSelectedItemPosition()); @@ -267,7 +265,6 @@ public class ActivityWidgetUnified extends ActivityBase { adapterPadding.setDropDownViewResource(R.layout.spinner_item1_dropdown); spPadding.setAdapter(adapterPadding); - btnColor.setEnabled(!cbSemiTransparent.isChecked()); grpReady.setVisibility(View.GONE); pbWait.setVisibility(View.VISIBLE); @@ -304,10 +301,4 @@ public class ActivityWidgetUnified extends ActivityBase { } }.execute(this, new Bundle(), "widget:accounts"); } - - @Override - protected void onSaveInstanceState(Bundle outState) { - outState.putInt("fair:color", background); - super.onSaveInstanceState(outState); - } } diff --git a/app/src/main/res/layout/activity_widget.xml b/app/src/main/res/layout/activity_widget.xml index 23a8eec90d..cfef2a3a1b 100644 --- a/app/src/main/res/layout/activity_widget.xml +++ b/app/src/main/res/layout/activity_widget.xml @@ -38,12 +38,13 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/spAccount" /> -