Use color button for widget configuration

pull/196/head
M66B 4 years ago
parent 06212ba5ff
commit bdb5d4d8a5

@ -52,7 +52,7 @@ public class ActivityWidget extends ActivityBase {
private Spinner spAccount; private Spinner spAccount;
private CheckBox cbSemiTransparent; private CheckBox cbSemiTransparent;
private Button btnColor; private ViewButtonColor btnColor;
private View inOld; private View inOld;
private View inNew; private View inNew;
private RadioButton rbOld; private RadioButton rbOld;
@ -61,7 +61,6 @@ public class ActivityWidget extends ActivityBase {
private ContentLoadingProgressBar pbWait; private ContentLoadingProgressBar pbWait;
private Group grpReady; private Group grpReady;
private int background = Color.TRANSPARENT;
private ArrayAdapter<EntityAccount> adapterAccount; private ArrayAdapter<EntityAccount> adapterAccount;
@Override @Override
@ -74,9 +73,6 @@ public class ActivityWidget extends ActivityBase {
return; return;
} }
if (savedInstanceState != null)
background = savedInstanceState.getInt("fair:color");
appWidgetId = extras.getInt( appWidgetId = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
@ -100,8 +96,8 @@ public class ActivityWidget extends ActivityBase {
cbSemiTransparent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { cbSemiTransparent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
btnColor.setColor(Color.TRANSPARENT);
setBackground(); setBackground();
btnColor.setEnabled(!isChecked);
} }
}); });
@ -121,14 +117,16 @@ public class ActivityWidget extends ActivityBase {
.setPositiveButton(android.R.string.ok, new ColorPickerClickListener() { .setPositiveButton(android.R.string.ok, new ColorPickerClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int selectedColor, Integer[] allColors) { public void onClick(DialogInterface dialog, int selectedColor, Integer[] allColors) {
background = selectedColor; cbSemiTransparent.setChecked(false);
btnColor.setColor(selectedColor);
setBackground(); setBackground();
} }
}) })
.setNegativeButton(R.string.title_reset, new DialogInterface.OnClickListener() { .setNegativeButton(R.string.title_reset, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
background = Color.TRANSPARENT; cbSemiTransparent.setChecked(false);
btnColor.setColor(Color.TRANSPARENT);
setBackground(); setBackground();
} }
}) })
@ -166,7 +164,7 @@ public class ActivityWidget extends ActivityBase {
editor.remove("widget." + appWidgetId + ".name"); editor.remove("widget." + appWidgetId + ".name");
editor.putLong("widget." + appWidgetId + ".account", account == null ? -1L : account.id); editor.putLong("widget." + appWidgetId + ".account", account == null ? -1L : account.id);
editor.putBoolean("widget." + appWidgetId + ".semi", cbSemiTransparent.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 + ".layout", rbNew.isChecked() ? 1 : 0); editor.putInt("widget." + appWidgetId + ".layout", rbNew.isChecked() ? 1 : 0);
editor.apply(); editor.apply();
@ -184,7 +182,8 @@ public class ActivityWidget extends ActivityBase {
((TextView) inOld.findViewById(R.id.tvCount)).setText("12"); ((TextView) inOld.findViewById(R.id.tvCount)).setText("12");
((TextView) inNew.findViewById(R.id.tvCount)).setText("12"); ((TextView) inNew.findViewById(R.id.tvCount)).setText("12");
btnColor.setEnabled(!cbSemiTransparent.isChecked()); setBackground();
grpReady.setVisibility(View.GONE); grpReady.setVisibility(View.GONE);
pbWait.setVisibility(View.VISIBLE); pbWait.setVisibility(View.VISIBLE);
@ -222,17 +221,12 @@ public class ActivityWidget extends ActivityBase {
}.execute(this, new Bundle(), "widget:accounts"); }.execute(this, new Bundle(), "widget:accounts");
} }
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putInt("fair:color", background);
super.onSaveInstanceState(outState);
}
private void setBackground() { private void setBackground() {
if (cbSemiTransparent.isChecked()) { if (cbSemiTransparent.isChecked()) {
inOld.setBackgroundResource(R.drawable.widget_background); inOld.setBackgroundResource(R.drawable.widget_background);
inNew.setBackgroundResource(R.drawable.widget_background); inNew.setBackgroundResource(R.drawable.widget_background);
} else { } else {
int background = btnColor.getColor();
inOld.setBackgroundColor(background); inOld.setBackgroundColor(background);
inNew.setBackgroundColor(background); inNew.setBackgroundColor(background);
float lum = (float) ColorUtils.calculateLuminance(background); float lum = (float) ColorUtils.calculateLuminance(background);

@ -40,11 +40,9 @@ public class ActivityWidgetSync extends ActivityBase {
private int appWidgetId; private int appWidgetId;
private CheckBox cbSemiTransparent; private CheckBox cbSemiTransparent;
private Button btnColor; private ViewButtonColor btnColor;
private Button btnSave; private Button btnSave;
private int background = Color.TRANSPARENT;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -55,9 +53,6 @@ public class ActivityWidgetSync extends ActivityBase {
return; return;
} }
if (savedInstanceState != null)
background = savedInstanceState.getInt("fair:color");
appWidgetId = extras.getInt( appWidgetId = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
@ -74,7 +69,7 @@ public class ActivityWidgetSync extends ActivityBase {
cbSemiTransparent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { cbSemiTransparent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 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() { .setPositiveButton(android.R.string.ok, new ColorPickerClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int selectedColor, Integer[] allColors) { 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() { .setNegativeButton(R.string.title_reset, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
background = Color.TRANSPARENT; cbSemiTransparent.setChecked(false);
btnColor.setColor(Color.TRANSPARENT);
} }
}) })
.build() .build()
@ -114,7 +111,7 @@ public class ActivityWidgetSync extends ActivityBase {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ActivityWidgetSync.this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ActivityWidgetSync.this);
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("widget." + appWidgetId + ".semi", cbSemiTransparent.isChecked()); editor.putBoolean("widget." + appWidgetId + ".semi", cbSemiTransparent.isChecked());
editor.putInt("widget." + appWidgetId + ".background", background); editor.putInt("widget." + appWidgetId + ".background", btnColor.getColor());
editor.apply(); editor.apply();
WidgetSync.init(ActivityWidgetSync.this, appWidgetId); WidgetSync.init(ActivityWidgetSync.this, appWidgetId);
@ -124,14 +121,6 @@ public class ActivityWidgetSync extends ActivityBase {
} }
}); });
btnColor.setEnabled(!cbSemiTransparent.isChecked());
setResult(RESULT_CANCELED, resultValue); setResult(RESULT_CANCELED, resultValue);
} }
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putInt("fair:color", background);
super.onSaveInstanceState(outState);
}
} }

@ -57,14 +57,13 @@ public class ActivityWidgetUnified extends ActivityBase {
private CheckBox cbUnseen; private CheckBox cbUnseen;
private CheckBox cbFlagged; private CheckBox cbFlagged;
private CheckBox cbSemiTransparent; private CheckBox cbSemiTransparent;
private Button btnColor; private ViewButtonColor btnColor;
private Spinner spFontSize; private Spinner spFontSize;
private Spinner spPadding; private Spinner spPadding;
private Button btnSave; private Button btnSave;
private ContentLoadingProgressBar pbWait; private ContentLoadingProgressBar pbWait;
private Group grpReady; private Group grpReady;
private int background = Color.TRANSPARENT;
private ArrayAdapter<EntityAccount> adapterAccount; private ArrayAdapter<EntityAccount> adapterAccount;
private ArrayAdapter<TupleFolderEx> adapterFolder; private ArrayAdapter<TupleFolderEx> adapterFolder;
private ArrayAdapter<String> adapterFontSize; private ArrayAdapter<String> adapterFontSize;
@ -80,9 +79,6 @@ public class ActivityWidgetUnified extends ActivityBase {
return; return;
} }
if (savedInstanceState != null)
background = savedInstanceState.getInt("fair:color");
appWidgetId = extras.getInt( appWidgetId = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
@ -107,7 +103,7 @@ public class ActivityWidgetUnified extends ActivityBase {
cbSemiTransparent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { cbSemiTransparent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 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() { .setPositiveButton(android.R.string.ok, new ColorPickerClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int selectedColor, Integer[] allColors) { 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() { .setNegativeButton(R.string.title_reset, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
background = Color.TRANSPARENT; cbSemiTransparent.setChecked(false);
btnColor.setColor(Color.TRANSPARENT);
} }
}) })
.build() .build()
@ -164,7 +162,7 @@ public class ActivityWidgetUnified extends ActivityBase {
editor.putBoolean("widget." + appWidgetId + ".unseen", cbUnseen.isChecked()); editor.putBoolean("widget." + appWidgetId + ".unseen", cbUnseen.isChecked());
editor.putBoolean("widget." + appWidgetId + ".flagged", cbFlagged.isChecked()); editor.putBoolean("widget." + appWidgetId + ".flagged", cbFlagged.isChecked());
editor.putBoolean("widget." + appWidgetId + ".semi", cbSemiTransparent.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 + ".font", spFontSize.getSelectedItemPosition());
editor.putInt("widget." + appWidgetId + ".padding", spPadding.getSelectedItemPosition()); editor.putInt("widget." + appWidgetId + ".padding", spPadding.getSelectedItemPosition());
@ -267,7 +265,6 @@ public class ActivityWidgetUnified extends ActivityBase {
adapterPadding.setDropDownViewResource(R.layout.spinner_item1_dropdown); adapterPadding.setDropDownViewResource(R.layout.spinner_item1_dropdown);
spPadding.setAdapter(adapterPadding); spPadding.setAdapter(adapterPadding);
btnColor.setEnabled(!cbSemiTransparent.isChecked());
grpReady.setVisibility(View.GONE); grpReady.setVisibility(View.GONE);
pbWait.setVisibility(View.VISIBLE); pbWait.setVisibility(View.VISIBLE);
@ -304,10 +301,4 @@ public class ActivityWidgetUnified extends ActivityBase {
} }
}.execute(this, new Bundle(), "widget:accounts"); }.execute(this, new Bundle(), "widget:accounts");
} }
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putInt("fair:color", background);
super.onSaveInstanceState(outState);
}
} }

@ -38,12 +38,13 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spAccount" /> app:layout_constraintTop_toBottomOf="@id/spAccount" />
<Button <eu.faircode.email.ViewButtonColor
android:id="@+id/btnColor" android:id="@+id/btnColor"
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"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:paddingHorizontal="6dp"
android:tag="disable" android:tag="disable"
android:text="@string/title_widget_background" android:text="@string/title_widget_background"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"

@ -21,12 +21,13 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<Button <eu.faircode.email.ViewButtonColor
android:id="@+id/btnColor" android:id="@+id/btnColor"
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"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:paddingHorizontal="6dp"
android:tag="disable" android:tag="disable"
android:text="@string/title_widget_background" android:text="@string/title_widget_background"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"

@ -73,12 +73,13 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbFlagged" /> app:layout_constraintTop_toBottomOf="@id/cbFlagged" />
<Button <eu.faircode.email.ViewButtonColor
android:id="@+id/btnColor" android:id="@+id/btnColor"
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"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:paddingHorizontal="6dp"
android:tag="disable" android:tag="disable"
android:text="@string/title_widget_background" android:text="@string/title_widget_background"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"

Loading…
Cancel
Save