Allow semi transparent widget color

pull/196/head
M66B 5 years ago
parent fae306ee3f
commit 2230cbc40f

@ -96,11 +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) {
if (isChecked) {
btnColor.setColor(Color.TRANSPARENT);
setBackground(); setBackground();
} }
}
}); });
btnColor.setOnClickListener(new View.OnClickListener() { btnColor.setOnClickListener(new View.OnClickListener() {
@ -119,7 +116,6 @@ 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) {
cbSemiTransparent.setChecked(false);
btnColor.setColor(selectedColor); btnColor.setColor(selectedColor);
setBackground(); setBackground();
} }
@ -127,7 +123,6 @@ public class ActivityWidget extends ActivityBase {
.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) {
cbSemiTransparent.setChecked(false);
btnColor.setColor(Color.TRANSPARENT); btnColor.setColor(Color.TRANSPARENT);
setBackground(); setBackground();
} }
@ -224,15 +219,19 @@ public class ActivityWidget extends ActivityBase {
} }
private void setBackground() { private void setBackground() {
if (cbSemiTransparent.isChecked()) { boolean semi = cbSemiTransparent.isChecked();
int background = btnColor.getColor();
if (background == Color.TRANSPARENT) {
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);
inNew.setBackgroundColor(background);
float lum = (float) ColorUtils.calculateLuminance(background); float lum = (float) ColorUtils.calculateLuminance(background);
int color = (lum > 0.7 ? Color.BLACK : getResources().getColor(R.color.colorWidgetForeground)); int color = (lum > 0.7 ? Color.BLACK : getResources().getColor(R.color.colorWidgetForeground));
if (semi)
background = ColorUtils.setAlphaComponent(background, 127);
inOld.setBackgroundColor(background);
inNew.setBackgroundColor(background);
((ImageView) inOld.findViewById(R.id.ivMessage)).setColorFilter(color); ((ImageView) inOld.findViewById(R.id.ivMessage)).setColorFilter(color);
((TextView) inOld.findViewById(R.id.tvCount)).setTextColor(color); ((TextView) inOld.findViewById(R.id.tvCount)).setTextColor(color);

@ -28,7 +28,6 @@ import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.CompoundButton;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
@ -66,14 +65,6 @@ public class ActivityWidgetSync extends ActivityBase {
final Intent resultValue = new Intent(); final Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
cbSemiTransparent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked)
btnColor.setColor(Color.TRANSPARENT);
}
});
btnColor.setOnClickListener(new View.OnClickListener() { btnColor.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -90,14 +81,12 @@ 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) {
cbSemiTransparent.setChecked(false);
btnColor.setColor(selectedColor); 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) {
cbSemiTransparent.setChecked(false);
btnColor.setColor(Color.TRANSPARENT); btnColor.setColor(Color.TRANSPARENT);
} }
}) })

@ -32,7 +32,6 @@ import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
@ -100,14 +99,6 @@ public class ActivityWidgetUnified extends ActivityBase {
final Intent resultValue = new Intent(); final Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
cbSemiTransparent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked)
btnColor.setColor(Color.TRANSPARENT);
}
});
btnColor.setOnClickListener(new View.OnClickListener() { btnColor.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -124,14 +115,12 @@ 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) {
cbSemiTransparent.setChecked(false);
btnColor.setColor(selectedColor); 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) {
cbSemiTransparent.setChecked(false);
btnColor.setColor(Color.TRANSPARENT); btnColor.setColor(Color.TRANSPARENT);
} }
}) })

@ -100,9 +100,6 @@ public class Widget extends AppWidgetProvider {
views.setOnClickPendingIntent(R.id.widget, pi); views.setOnClickPendingIntent(R.id.widget, pi);
if (!semi)
views.setInt(R.id.widget, "setBackgroundColor", background);
if (layout == 1) if (layout == 1)
views.setImageViewResource(R.id.ivMessage, unseen == 0 views.setImageViewResource(R.id.ivMessage, unseen == 0
? R.drawable.baseline_mail_outline_widget_24 ? R.drawable.baseline_mail_outline_widget_24
@ -119,8 +116,14 @@ public class Widget extends AppWidgetProvider {
views.setViewVisibility(R.id.tvAccount, ViewStripe.VISIBLE); views.setViewVisibility(R.id.tvAccount, ViewStripe.VISIBLE);
} }
if (!semi && background != Color.TRANSPARENT) { if (background != Color.TRANSPARENT) {
float lum = (float) ColorUtils.calculateLuminance(background); float lum = (float) ColorUtils.calculateLuminance(background);
if (semi)
background = ColorUtils.setAlphaComponent(background, 127);
views.setInt(R.id.widget, "setBackgroundColor", background);
if (lum > 0.7f) { if (lum > 0.7f) {
views.setInt(R.id.ivMessage, "setColorFilter", Color.BLACK); views.setInt(R.id.ivMessage, "setColorFilter", Color.BLACK);
views.setTextColor(R.id.tvCount, Color.BLACK); views.setTextColor(R.id.tvCount, Color.BLACK);

@ -49,11 +49,14 @@ public class WidgetSync extends AppWidgetProvider {
views.setOnClickPendingIntent(R.id.ivSync, pi); views.setOnClickPendingIntent(R.id.ivSync, pi);
views.setImageViewResource(R.id.ivSync, enabled ? R.drawable.twotone_sync_24 : R.drawable.twotone_sync_disabled_24); views.setImageViewResource(R.id.ivSync, enabled ? R.drawable.twotone_sync_24 : R.drawable.twotone_sync_disabled_24);
if (!semi) if (background != Color.TRANSPARENT) {
float lum = (float) ColorUtils.calculateLuminance(background);
if (semi)
background = ColorUtils.setAlphaComponent(background, 127);
views.setInt(R.id.widget, "setBackgroundColor", background); views.setInt(R.id.widget, "setBackgroundColor", background);
if (!semi && background != Color.TRANSPARENT) {
float lum = (float) ColorUtils.calculateLuminance(background);
if (lum > 0.7f) if (lum > 0.7f)
views.setInt(R.id.ivSync, "setColorFilter", Color.BLACK); views.setInt(R.id.ivSync, "setColorFilter", Color.BLACK);
} }

@ -59,9 +59,6 @@ public class WidgetUnified extends AppWidgetProvider {
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_unified); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_unified);
if (!semi)
views.setInt(R.id.widget, "setBackgroundColor", background);
if (font > 0) if (font > 0)
views.setTextViewTextSize(R.id.title, TypedValue.COMPLEX_UNIT_SP, getFontSizeSp(font)); views.setTextViewTextSize(R.id.title, TypedValue.COMPLEX_UNIT_SP, getFontSizeSp(font));
@ -70,10 +67,6 @@ public class WidgetUnified extends AppWidgetProvider {
views.setViewPadding(R.id.title, px, px, px, px); 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) if (name == null)
views.setTextViewText(R.id.title, context.getString(R.string.title_folder_unified)); views.setTextViewText(R.id.title, context.getString(R.string.title_folder_unified));
else else
@ -99,6 +92,18 @@ public class WidgetUnified extends AppWidgetProvider {
views.setPendingIntentTemplate(R.id.lv, piItem); views.setPendingIntentTemplate(R.id.lv, piItem);
if (background != Color.TRANSPARENT) {
float lum = (float) ColorUtils.calculateLuminance(background);
if (semi)
background = ColorUtils.setAlphaComponent(background, 127);
views.setInt(R.id.widget, "setBackgroundColor", background);
if (lum > 0.7f)
views.setTextColor(R.id.title, Color.BLACK);
}
appWidgetManager.updateAppWidget(appWidgetId, views); appWidgetManager.updateAppWidget(appWidgetId, views);
} }
} }

@ -55,7 +55,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="24dp" android:layout_marginTop="24dp"
android:background="@color/lightBluePrimary" android:background="@android:color/darker_gray"
android:padding="24dp" android:padding="24dp"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnColor"> app:layout_constraintTop_toBottomOf="@id/btnColor">

Loading…
Cancel
Save