Allow semi transparent widget color

This commit is contained in:
M66B 2021-03-26 14:38:51 +01:00
parent fae306ee3f
commit 2230cbc40f
7 changed files with 35 additions and 47 deletions

View File

@ -96,10 +96,7 @@ public class ActivityWidget extends ActivityBase {
cbSemiTransparent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
btnColor.setColor(Color.TRANSPARENT);
setBackground();
}
setBackground();
}
});
@ -119,7 +116,6 @@ public class ActivityWidget extends ActivityBase {
.setPositiveButton(android.R.string.ok, new ColorPickerClickListener() {
@Override
public void onClick(DialogInterface dialog, int selectedColor, Integer[] allColors) {
cbSemiTransparent.setChecked(false);
btnColor.setColor(selectedColor);
setBackground();
}
@ -127,7 +123,6 @@ public class ActivityWidget extends ActivityBase {
.setNegativeButton(R.string.title_reset, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
cbSemiTransparent.setChecked(false);
btnColor.setColor(Color.TRANSPARENT);
setBackground();
}
@ -224,15 +219,19 @@ public class ActivityWidget extends ActivityBase {
}
private void setBackground() {
if (cbSemiTransparent.isChecked()) {
boolean semi = cbSemiTransparent.isChecked();
int background = btnColor.getColor();
if (background == Color.TRANSPARENT) {
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);
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);
((TextView) inOld.findViewById(R.id.tvCount)).setTextColor(color);

View File

@ -28,7 +28,6 @@ import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import androidx.preference.PreferenceManager;
@ -66,14 +65,6 @@ public class ActivityWidgetSync extends ActivityBase {
final Intent resultValue = new Intent();
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() {
@Override
public void onClick(View view) {
@ -90,14 +81,12 @@ public class ActivityWidgetSync extends ActivityBase {
.setPositiveButton(android.R.string.ok, new ColorPickerClickListener() {
@Override
public void onClick(DialogInterface dialog, int selectedColor, Integer[] allColors) {
cbSemiTransparent.setChecked(false);
btnColor.setColor(selectedColor);
}
})
.setNegativeButton(R.string.title_reset, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
cbSemiTransparent.setChecked(false);
btnColor.setColor(Color.TRANSPARENT);
}
})

View File

@ -32,7 +32,6 @@ import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Spinner;
import android.widget.TextView;
@ -100,14 +99,6 @@ public class ActivityWidgetUnified extends ActivityBase {
final Intent resultValue = new Intent();
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() {
@Override
public void onClick(View view) {
@ -124,14 +115,12 @@ public class ActivityWidgetUnified extends ActivityBase {
.setPositiveButton(android.R.string.ok, new ColorPickerClickListener() {
@Override
public void onClick(DialogInterface dialog, int selectedColor, Integer[] allColors) {
cbSemiTransparent.setChecked(false);
btnColor.setColor(selectedColor);
}
})
.setNegativeButton(R.string.title_reset, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
cbSemiTransparent.setChecked(false);
btnColor.setColor(Color.TRANSPARENT);
}
})

View File

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

View File

@ -49,11 +49,14 @@ public class WidgetSync extends AppWidgetProvider {
views.setOnClickPendingIntent(R.id.ivSync, pi);
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);
if (!semi && background != Color.TRANSPARENT) {
float lum = (float) ColorUtils.calculateLuminance(background);
if (lum > 0.7f)
views.setInt(R.id.ivSync, "setColorFilter", Color.BLACK);
}

View File

@ -59,9 +59,6 @@ public class WidgetUnified extends AppWidgetProvider {
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_unified);
if (!semi)
views.setInt(R.id.widget, "setBackgroundColor", background);
if (font > 0)
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);
}
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
@ -99,6 +92,18 @@ public class WidgetUnified extends AppWidgetProvider {
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);
}
}

View File

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