PoC: widget day/night mode

pull/207/head
M66B 3 years ago
parent 92129a522a
commit 316a4bcae8

@ -57,6 +57,7 @@ public class ActivityWidgetUnified extends ActivityBase {
private Spinner spFolder;
private CheckBox cbUnseen;
private CheckBox cbFlagged;
private CheckBox cbDayNight;
private CheckBox cbHighlight;
private ViewButtonColor btnHighlight;
private CheckBox cbSeparatorLines;
@ -94,6 +95,7 @@ public class ActivityWidgetUnified extends ActivityBase {
long folder = prefs.getLong("widget." + appWidgetId + ".folder", -1L);
boolean unseen = prefs.getBoolean("widget." + appWidgetId + ".unseen", false);
boolean flagged = prefs.getBoolean("widget." + appWidgetId + ".flagged", false);
boolean daynight = prefs.getBoolean("widget." + appWidgetId + ".daynight", false);
boolean highlight = prefs.getBoolean("widget." + appWidgetId + ".highlight", false);
int highlight_color = prefs.getInt("widget." + appWidgetId + ".highlight_color", Color.TRANSPARENT);
boolean separators = prefs.getBoolean("widget." + appWidgetId + ".separators", true);
@ -113,6 +115,7 @@ public class ActivityWidgetUnified extends ActivityBase {
spFolder = findViewById(R.id.spFolder);
cbUnseen = findViewById(R.id.cbUnseen);
cbFlagged = findViewById(R.id.cbFlagged);
cbDayNight = findViewById(R.id.cbDayNight);
cbHighlight = findViewById(R.id.cbHighlight);
btnHighlight = findViewById(R.id.btnHighlight);
cbSeparatorLines = findViewById(R.id.cbSeparatorLines);
@ -130,10 +133,20 @@ public class ActivityWidgetUnified 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) {
cbHighlight.setEnabled(!checked);
btnHighlight.setEnabled(cbHighlight.isChecked() && !checked);
cbSemiTransparent.setEnabled(!checked);
btnColor.setEnabled(!checked);
}
});
cbHighlight.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
btnHighlight.setVisibility(checked ? View.VISIBLE : View.GONE);
btnHighlight.setVisibility(checked && cbHighlight.isEnabled() ? View.VISIBLE : View.GONE);
}
});
@ -222,6 +235,7 @@ public class ActivityWidgetUnified extends ActivityBase {
editor.putLong("widget." + appWidgetId + ".folder", folder == null ? -1L : folder.id);
editor.putString("widget." + appWidgetId + ".type", folder == null ? null : folder.type);
editor.putBoolean("widget." + appWidgetId + ".unseen", cbUnseen.isChecked());
editor.putBoolean("widget." + appWidgetId + ".daynight", cbDayNight.isChecked());
editor.putBoolean("widget." + appWidgetId + ".flagged", cbFlagged.isChecked());
editor.putBoolean("widget." + appWidgetId + ".highlight", cbHighlight.isChecked());
editor.putInt("widget." + appWidgetId + ".highlight_color", btnHighlight.getColor());
@ -346,12 +360,17 @@ public class ActivityWidgetUnified extends ActivityBase {
// Initialize
cbUnseen.setChecked(unseen);
cbFlagged.setChecked(flagged);
cbDayNight.setChecked(daynight);
cbHighlight.setChecked(highlight);
cbHighlight.setEnabled(!daynight);
btnHighlight.setVisibility(highlight ? View.VISIBLE : View.GONE);
btnHighlight.setColor(highlight_color);
btnHighlight.setEnabled(highlight && !daynight);
cbSeparatorLines.setChecked(separators);
cbSemiTransparent.setChecked(semi);
cbSemiTransparent.setEnabled(!daynight);
btnColor.setColor(background);
btnColor.setEnabled(!daynight);
spFontSize.setSelection(tinyIn(font));
spPadding.setSelection(tinyIn(padding));
cbAvatars.setChecked(avatars);

@ -49,6 +49,7 @@ public class WidgetUnified extends AppWidgetProvider {
long account = prefs.getLong("widget." + appWidgetId + ".account", -1L);
long folder = prefs.getLong("widget." + appWidgetId + ".folder", -1L);
String type = prefs.getString("widget." + appWidgetId + ".type", null);
boolean daynight = prefs.getBoolean("widget." + appWidgetId + ".daynight", false);
boolean separators = prefs.getBoolean("widget." + appWidgetId + ".separators", true);
boolean semi = prefs.getBoolean("widget." + appWidgetId + ".semi", true);
int background = prefs.getInt("widget." + appWidgetId + ".background", Color.TRANSPARENT);
@ -132,42 +133,43 @@ public class WidgetUnified extends AppWidgetProvider {
boolean syncing = prefs.getBoolean("widget." + appWidgetId + ".syncing", false);
if (background == Color.TRANSPARENT) {
if (semi)
views.setInt(R.id.background, "setBackgroundResource", R.drawable.widget_background);
else
if (!daynight)
if (background == Color.TRANSPARENT) {
if (semi)
views.setInt(R.id.background, "setBackgroundResource", R.drawable.widget_background);
else
views.setInt(R.id.background, "setBackgroundColor", background);
views.setTextColor(R.id.title, colorWidgetForeground);
views.setInt(R.id.separator, "setBackgroundColor", lightColorSeparator);
views.setImageViewResource(R.id.refresh, syncing
? R.drawable.twotone_compare_arrows_24_white
: R.drawable.twotone_sync_24_white);
views.setImageViewResource(R.id.compose, R.drawable.twotone_edit_24_white);
} else {
float lum = (float) ColorUtils.calculateLuminance(background);
if (semi)
background = ColorUtils.setAlphaComponent(background, 127);
views.setInt(R.id.background, "setBackgroundColor", background);
views.setTextColor(R.id.title, colorWidgetForeground);
views.setInt(R.id.separator, "setBackgroundColor", lightColorSeparator);
views.setImageViewResource(R.id.refresh, syncing
? R.drawable.twotone_compare_arrows_24_white
: R.drawable.twotone_sync_24_white);
views.setImageViewResource(R.id.compose, R.drawable.twotone_edit_24_white);
} else {
float lum = (float) ColorUtils.calculateLuminance(background);
if (semi)
background = ColorUtils.setAlphaComponent(background, 127);
views.setInt(R.id.background, "setBackgroundColor", background);
int fg = (lum > 0.7f ? Color.BLACK : colorWidgetForeground);
views.setTextColor(R.id.title, fg);
views.setInt(R.id.separator, "setBackgroundColor",
lum > 0.7f ? darkColorSeparator : lightColorSeparator);
if (syncing)
views.setImageViewResource(R.id.refresh, lum > 0.7f
? R.drawable.twotone_compare_arrows_24_black
: R.drawable.twotone_compare_arrows_24_white);
else
views.setImageViewResource(R.id.refresh, lum > 0.7f
? R.drawable.twotone_sync_24_black
: R.drawable.twotone_sync_24_white);
views.setImageViewResource(R.id.compose, lum > 0.7f
? R.drawable.twotone_edit_24_black
: R.drawable.twotone_edit_24_white);
}
int fg = (lum > 0.7f ? Color.BLACK : colorWidgetForeground);
views.setTextColor(R.id.title, fg);
views.setInt(R.id.separator, "setBackgroundColor",
lum > 0.7f ? darkColorSeparator : lightColorSeparator);
if (syncing)
views.setImageViewResource(R.id.refresh, lum > 0.7f
? R.drawable.twotone_compare_arrows_24_black
: R.drawable.twotone_compare_arrows_24_white);
else
views.setImageViewResource(R.id.refresh, lum > 0.7f
? R.drawable.twotone_sync_24_black
: R.drawable.twotone_sync_24_white);
views.setImageViewResource(R.id.compose, lum > 0.7f
? R.drawable.twotone_edit_24_black
: R.drawable.twotone_edit_24_white);
}
views.setViewVisibility(R.id.separator, separators ? View.VISIBLE : View.GONE);

@ -57,6 +57,7 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot
private long account;
private boolean unseen;
private boolean flagged;
private boolean daynight = true;
private boolean highlight;
private int highlight_color;
private boolean separators;
@ -106,6 +107,7 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot
folder = prefs.getLong("widget." + appWidgetId + ".folder", -1L);
unseen = prefs.getBoolean("widget." + appWidgetId + ".unseen", false);
flagged = prefs.getBoolean("widget." + appWidgetId + ".flagged", false);
daynight = prefs.getBoolean("widget." + appWidgetId + ".daynight", false);
highlight = prefs.getBoolean("widget." + appWidgetId + ".highlight", false);
highlight_color = prefs.getInt("widget." + appWidgetId + ".highlight_color", Color.TRANSPARENT);
separators = prefs.getBoolean("widget." + appWidgetId + ".separators", true);
@ -256,13 +258,16 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot
views.setTextViewText(idSubject, ssSubject);
views.setTextViewText(idAccount, ssAccount);
int textColor = (message.ui_seen ? colorWidgetRead : colorWidgetUnread);
views.setTextColor(idFrom, textColor);
views.setTextColor(idTime, textColor);
views.setTextColor(idSubject, textColor);
views.setTextColor(idAccount, textColor);
if (!daynight) {
int textColor = (message.ui_seen ? colorWidgetRead : colorWidgetUnread);
views.setTextColor(idFrom, textColor);
views.setTextColor(idTime, textColor);
views.setTextColor(idSubject, textColor);
views.setTextColor(idAccount, textColor);
}
views.setInt(R.id.separator, "setBackgroundColor", colorSeparator);
if (!daynight)
views.setInt(R.id.separator, "setBackgroundColor", colorSeparator);
views.setViewVisibility(R.id.separator, separators ? View.VISIBLE : View.GONE);
views.setViewVisibility(idAccount, account < 0 && !allColors ? View.VISIBLE : View.GONE);

@ -65,6 +65,16 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbUnseen" />
<CheckBox
android:id="@+id/cbDayNight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:checked="true"
android:text="@string/title_widget_day_night"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbFlagged" />
<CheckBox
android:id="@+id/cbHighlight"
android:layout_width="wrap_content"
@ -73,7 +83,7 @@
android:checked="true"
android:text="@string/title_advanced_highlight_unread"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbFlagged" />
app:layout_constraintTop_toBottomOf="@id/cbDayNight" />
<eu.faircode.email.ViewButtonColor
android:id="@+id/btnHighlight"

@ -49,7 +49,7 @@
android:maxLines="1"
android:text="From"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@color/colorWidgetForeground" />
android:textColor="?android:textColorPrimary" />
<TextView
android:id="@+id/tvTime"
@ -59,7 +59,7 @@
android:maxLines="1"
android:text="12:34"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@color/colorWidgetForeground" />
android:textColor="?android:textColorPrimary" />
</LinearLayout>
<LinearLayout
@ -76,7 +76,7 @@
android:maxLines="1"
android:text="Subject"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@color/colorWidgetForeground" />
android:textColor="?android:textColorPrimary" />
<TextView
android:id="@+id/tvAccount"
@ -86,7 +86,7 @@
android:maxLines="1"
android:text="Account"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@color/colorWidgetForeground" />
android:textColor="?android:textColorPrimary" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
@ -95,5 +95,5 @@
android:id="@+id/separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/grey" />
android:background="?android:colorControlNormal" />
</LinearLayout>

@ -4,7 +4,8 @@
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/widget_background">
android:background="?android:colorBackground"
android:theme="@style/Theme.AppCompat.DayNight">
<LinearLayout
android:id="@+id/content"
@ -28,7 +29,7 @@
android:padding="6dp"
android:text="@string/title_widget_title_list"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="@color/colorWidgetForeground"
android:textColor="?android:textColorPrimary"
android:textStyle="bold" />
<ImageView
@ -38,8 +39,10 @@
android:layout_weight="0"
android:contentDescription="@string/tile_synchronize"
android:padding="6dp"
android:src="@drawable/twotone_sync_24_white"
android:visibility="gone" />
android:src="@drawable/twotone_sync_24"
android:tint="?android:textColorPrimary"
android:visibility="visible"
app:tint="?android:textColorPrimary" />
<ImageView
android:id="@+id/compose"
@ -48,15 +51,17 @@
android:layout_weight="0"
android:contentDescription="@string/title_compose"
android:padding="6dp"
android:src="@drawable/twotone_edit_24_white"
android:visibility="gone" />
android:src="@drawable/twotone_edit_24"
android:tint="?android:textColorPrimary"
android:visibility="visible"
app:tint="?android:textColorPrimary" />
</LinearLayout>
<FrameLayout
android:id="@+id/separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/grey" />
android:background="?android:colorControlNormal" />
<ListView
android:id="@+id/lv"

@ -1939,6 +1939,7 @@
<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_background">Background color</string>
<string name="title_widget_day_night">Use day/night mode (if available)</string>
<string name="title_accessibility_collapsed">Collapsed</string>
<string name="title_accessibility_expanded">Expanded</string>

Loading…
Cancel
Save