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 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<EntityAccount> 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);

@ -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);
}
}

@ -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<EntityAccount> adapterAccount;
private ArrayAdapter<TupleFolderEx> adapterFolder;
private ArrayAdapter<String> 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);
}
}

@ -38,12 +38,13 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spAccount" />
<Button
<eu.faircode.email.ViewButtonColor
android:id="@+id/btnColor"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:paddingHorizontal="6dp"
android:tag="disable"
android:text="@string/title_widget_background"
app:layout_constraintStart_toStartOf="parent"

@ -21,12 +21,13 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
<eu.faircode.email.ViewButtonColor
android:id="@+id/btnColor"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:paddingHorizontal="6dp"
android:tag="disable"
android:text="@string/title_widget_background"
app:layout_constraintStart_toStartOf="parent"

@ -73,12 +73,13 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbFlagged" />
<Button
<eu.faircode.email.ViewButtonColor
android:id="@+id/btnColor"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:paddingHorizontal="6dp"
android:tag="disable"
android:text="@string/title_widget_background"
app:layout_constraintStart_toStartOf="parent"

Loading…
Cancel
Save