Auto adjust widget text color

pull/183/head
M66B 5 years ago
parent 8f92b18a9f
commit f1f9d59ce0

@ -31,11 +31,13 @@ import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.TextView;
import androidx.constraintlayout.widget.Group;
import androidx.core.graphics.ColorUtils;
import androidx.preference.PreferenceManager;
import com.flask.colorpicker.ColorPickerView;
@ -230,6 +232,16 @@ public class ActivityWidget extends ActivityBase {
} else {
inOld.setBackgroundColor(background);
inNew.setBackgroundColor(background);
float lum = (float) ColorUtils.calculateLuminance(background);
int color = (lum > 0.7 ? Color.BLACK : getResources().getColor(R.color.colorWidgetForeground));
((ImageView) inOld.findViewById(R.id.ivMessage)).setColorFilter(color);
((TextView) inOld.findViewById(R.id.tvCount)).setTextColor(color);
((TextView) inOld.findViewById(R.id.tvAccount)).setTextColor(color);
((ImageView) inNew.findViewById(R.id.ivMessage)).setColorFilter(color);
((TextView) inNew.findViewById(R.id.tvCount)).setTextColor(color);
((TextView) inNew.findViewById(R.id.tvAccount)).setTextColor(color);
}
}
}

@ -31,6 +31,7 @@ import android.text.TextUtils;
import android.view.View;
import android.widget.RemoteViews;
import androidx.core.graphics.ColorUtils;
import androidx.preference.PreferenceManager;
import java.text.NumberFormat;
@ -118,6 +119,15 @@ public class Widget extends AppWidgetProvider {
views.setViewVisibility(R.id.tvAccount, ViewStripe.VISIBLE);
}
if (!semi && background != Color.TRANSPARENT) {
float lum = (float) ColorUtils.calculateLuminance(background);
if (lum > 0.7f) {
views.setInt(R.id.ivMessage, "setColorFilter", Color.BLACK);
views.setTextColor(R.id.tvCount, Color.BLACK);
views.setTextColor(R.id.tvAccount, Color.BLACK);
}
}
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}

@ -31,6 +31,7 @@ import android.net.Uri;
import android.util.TypedValue;
import android.widget.RemoteViews;
import androidx.core.graphics.ColorUtils;
import androidx.preference.PreferenceManager;
public class WidgetUnified extends AppWidgetProvider {
@ -69,6 +70,10 @@ public class WidgetUnified extends AppWidgetProvider {
views.setViewPadding(R.id.title, px, px, px, px);
}
float lum = (float) ColorUtils.calculateLuminance(background);
if (lum > 0.7f)
views.setTextColor(R.id.title, Color.BLACK);
if (name == null)
views.setTextViewText(R.id.title, context.getString(R.string.title_folder_unified));
else

@ -23,6 +23,7 @@ import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.Typeface;
import android.text.SpannableString;
import android.text.Spanned;
@ -34,6 +35,7 @@ import android.widget.RemoteViews;
import android.widget.RemoteViewsService;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.ColorUtils;
import androidx.preference.PreferenceManager;
import java.util.ArrayList;
@ -51,6 +53,8 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot
private long account;
private boolean unseen;
private boolean flagged;
private boolean semi;
private int background;
private int font;
private int padding;
private int colorWidgetForeground;
@ -85,12 +89,20 @@ 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);
semi = prefs.getBoolean("widget." + appWidgetId + ".semi", true);
background = prefs.getInt("widget." + appWidgetId + ".background", Color.TRANSPARENT);
font = prefs.getInt("widget." + appWidgetId + ".font", 0);
padding = prefs.getInt("widget." + appWidgetId + ".padding", 0);
colorWidgetForeground = ContextCompat.getColor(context, R.color.colorWidgetForeground);
colorWidgetRead = ContextCompat.getColor(context, R.color.colorWidgetRead);
colorSeparator = ContextCompat.getColor(context, R.color.lightColorSeparator);
float lum = (float) ColorUtils.calculateLuminance(background);
if (lum > 0.7f) {
colorWidgetForeground = ColorUtils.blendARGB(colorWidgetForeground, Color.BLACK, 1.0f);
colorWidgetRead = ColorUtils.blendARGB(colorWidgetRead, Color.BLACK, 1.0f);
}
pro = ActivityBilling.isPro(context);
DB db = DB.getInstance(context);

@ -21,9 +21,10 @@
android:textStyle="bold" />
<FrameLayout
android:id="@+id/separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/colorWidgetForeground" />
android:background="@color/colorWidgetRead" />
<ListView
android:id="@+id/lv"

Loading…
Cancel
Save