PoC: widget day/night mode (3)

This commit is contained in:
M66B 2022-05-05 23:39:52 +02:00
parent 72f57cfaf0
commit 227eb79f9a
7 changed files with 102 additions and 44 deletions

View File

@ -25,6 +25,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
@ -361,6 +362,7 @@ public class ActivityWidgetUnified extends ActivityBase {
cbUnseen.setChecked(unseen);
cbFlagged.setChecked(flagged);
cbDayNight.setChecked(daynight);
cbDayNight.setVisibility(Build.VERSION.SDK_INT < Build.VERSION_CODES.S ? View.GONE : View.VISIBLE);
cbHighlight.setChecked(highlight);
cbHighlight.setEnabled(!daynight);
btnHighlight.setVisibility(highlight ? View.VISIBLE : View.GONE);

View File

@ -28,6 +28,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.util.TypedValue;
import android.view.View;
import android.widget.RemoteViews;
@ -133,43 +134,57 @@ public class WidgetUnified extends AppWidgetProvider {
boolean syncing = prefs.getBoolean("widget." + appWidgetId + ".syncing", false);
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);
if (!daynight && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
views.setColorStateListAttr(R.id.background, "setBackgroundTintList", 0);
views.setColorStateListAttr(R.id.separator, "setBackgroundTintList", 0);
}
if (daynight && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
views.setInt(R.id.background, "setBackgroundColor", Color.WHITE);
views.setColorStateListAttr(R.id.background, "setBackgroundTintList", android.R.attr.colorBackground);
views.setColorStateListAttr(R.id.title, "setTextColor", android.R.attr.textColorPrimary);
views.setInt(R.id.separator, "setBackgroundColor", Color.WHITE);
views.setColorStateListAttr(R.id.separator, "setBackgroundTintList", android.R.attr.colorControlNormal);
views.setImageViewResource(R.id.refresh, syncing
? R.drawable.twotone_compare_arrows_24_dn
: R.drawable.twotone_sync_24_dn);
views.setImageViewResource(R.id.compose, R.drawable.twotone_edit_24_dn);
} else if (background == Color.TRANSPARENT) {
if (semi)
views.setInt(R.id.background, "setBackgroundResource", R.drawable.widget_background);
else
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);
}
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);
}
views.setViewVisibility(R.id.separator, separators ? View.VISIBLE : View.GONE);

View File

@ -57,7 +57,7 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot
private long account;
private boolean unseen;
private boolean flagged;
private boolean daynight = true;
private boolean daynight;
private boolean highlight;
private int highlight_color;
private boolean separators;
@ -258,16 +258,26 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot
views.setTextViewText(idSubject, ssSubject);
views.setTextViewText(idAccount, ssAccount);
if (!daynight) {
if (!daynight && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
views.setColorStateListAttr(R.id.separator, "setBackgroundTintList", 0);
}
if (daynight && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
views.setColorStateListAttr(idFrom, "setTextColor", android.R.attr.textColorPrimary);
views.setColorStateListAttr(idTime, "setTextColor", android.R.attr.textColorPrimary);
views.setColorStateListAttr(idSubject, "setTextColor", android.R.attr.textColorPrimary);
views.setColorStateListAttr(idAccount, "setTextColor", android.R.attr.textColorPrimary);
views.setInt(R.id.separator, "setBackgroundColor", Color.WHITE);
views.setColorStateListAttr(R.id.separator, "setBackgroundTintList", android.R.attr.colorControlNormal);
} else {
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);

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?android:textColorPrimary">
<path
android:fillColor="@android:color/white"
android:pathData="M9.01,14L2,14v2h7.01v3L13,15l-3.99,-4v3zM14.99,13v-3L22,10L22,8h-7.01L14.99,5L11,9l3.99,4z"/>
</vector>

View File

@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?android:textColorPrimary">
<path
android:fillColor="@android:color/white"
android:pathData="M5,18.08V19h0.92l9.06,-9.06 -0.92,-0.92z"
android:strokeAlpha="0.3"
android:fillAlpha="0.3"/>
<path
android:fillColor="@android:color/white"
android:pathData="M20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.2,-0.2 -0.45,-0.29 -0.71,-0.29s-0.51,0.1 -0.7,0.29l-1.83,1.83 3.75,3.75 1.83,-1.83zM3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM5.92,19H5v-0.92l9.06,-9.06 0.92,0.92L5.92,19z"/>
</vector>

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?android:textColorPrimary">
<path
android:fillColor="@android:color/white"
android:pathData="M12.01,4L12.01,1l-4,4 4,4L12.01,6c3.31,0 6,2.69 6,6 0,1.01 -0.25,1.97 -0.7,2.8l1.46,1.46c0.78,-1.23 1.24,-2.69 1.24,-4.26 0,-4.42 -3.58,-8 -8,-8zM12.01,18c-3.31,0 -6,-2.69 -6,-6 0,-1.01 0.25,-1.97 0.7,-2.8L5.25,7.74C4.47,8.97 4.01,10.43 4.01,12c0,4.42 3.58,8 8,8v3l4,-4 -4,-4v3z"/>
</vector>

View File

@ -40,9 +40,7 @@
android:contentDescription="@string/tile_synchronize"
android:padding="6dp"
android:src="@drawable/twotone_sync_24"
android:tint="?android:textColorPrimary"
android:visibility="visible"
app:tint="?android:textColorPrimary" />
android:visibility="gone" />
<ImageView
android:id="@+id/compose"
@ -52,9 +50,7 @@
android:contentDescription="@string/title_compose"
android:padding="6dp"
android:src="@drawable/twotone_edit_24"
android:tint="?android:textColorPrimary"
android:visibility="visible"
app:tint="?android:textColorPrimary" />
android:visibility="gone" />
</LinearLayout>
<FrameLayout