Enabled widget background opacity for Android 12+

This commit is contained in:
M66B 2022-10-29 19:33:29 +02:00
parent 29f00a6893
commit eff83ec9a7
6 changed files with 74 additions and 15 deletions

View File

@ -81,8 +81,12 @@ public class ActivityWidget extends ActivityBase {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
long account = prefs.getLong("widget." + appWidgetId + ".account", -1L);
boolean daynight = prefs.getBoolean("widget." + appWidgetId + ".daynight", false);
boolean semi = prefs.getBoolean("widget." + appWidgetId + ".semi", true);
int background = prefs.getInt("widget." + appWidgetId + ".background", Color.TRANSPARENT);
boolean semi = prefs.getBoolean("widget." + appWidgetId + ".semi",
Build.VERSION.SDK_INT < Build.VERSION_CODES.S);
int background = prefs.getInt("widget." + appWidgetId + ".background",
Build.VERSION.SDK_INT < Build.VERSION_CODES.S
? Color.TRANSPARENT
: ColorUtils.setAlphaComponent(Color.BLACK, 127));
int layout = prefs.getInt("widget." + appWidgetId + ".layout", 1 /* new */);
daynight = daynight && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S);
@ -117,6 +121,8 @@ public class ActivityWidget extends ActivityBase {
cbSemiTransparent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
btnColor.setColor(Color.TRANSPARENT);
setBackground();
}
});
@ -124,6 +130,7 @@ public class ActivityWidget extends ActivityBase {
btnColor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int color = btnColor.getColor();
int editTextColor = Helper.resolveColor(ActivityWidget.this, android.R.attr.editTextColor);
ColorPickerDialogBuilder
@ -133,10 +140,14 @@ public class ActivityWidget extends ActivityBase {
.setColorEditTextColor(editTextColor)
.wheelType(ColorPickerView.WHEEL_TYPE.FLOWER)
.density(6)
.lightnessSliderOnly()
.initialColor(color == Color.TRANSPARENT ? Color.WHITE : color)
.showLightnessSlider(true)
.showAlphaSlider(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
.setPositiveButton(android.R.string.ok, new ColorPickerClickListener() {
@Override
public void onClick(DialogInterface dialog, int selectedColor, Integer[] allColors) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
cbSemiTransparent.setChecked(false);
btnColor.setColor(selectedColor);
setBackground();
}

View File

@ -31,6 +31,7 @@ import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import androidx.core.graphics.ColorUtils;
import androidx.preference.PreferenceManager;
import com.flask.colorpicker.ColorPickerView;
@ -60,8 +61,12 @@ public class ActivityWidgetSync extends ActivityBase {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean daynight = prefs.getBoolean("widget." + appWidgetId + ".daynight", false);
boolean semi = prefs.getBoolean("widget." + appWidgetId + ".semi", true);
int background = prefs.getInt("widget." + appWidgetId + ".background", Color.TRANSPARENT);
boolean semi = prefs.getBoolean("widget." + appWidgetId + ".semi",
Build.VERSION.SDK_INT < Build.VERSION_CODES.S);
int background = prefs.getInt("widget." + appWidgetId + ".background",
Build.VERSION.SDK_INT < Build.VERSION_CODES.S
? Color.TRANSPARENT
: ColorUtils.setAlphaComponent(Color.BLACK, 127));
daynight = daynight && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S);
@ -85,9 +90,18 @@ public class ActivityWidgetSync extends ActivityBase {
}
});
cbSemiTransparent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
btnColor.setColor(Color.TRANSPARENT);
}
});
btnColor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int color = btnColor.getColor();
int editTextColor = Helper.resolveColor(ActivityWidgetSync.this, android.R.attr.editTextColor);
ColorPickerDialogBuilder
@ -97,10 +111,14 @@ public class ActivityWidgetSync extends ActivityBase {
.setColorEditTextColor(editTextColor)
.wheelType(ColorPickerView.WHEEL_TYPE.FLOWER)
.density(6)
.lightnessSliderOnly()
.initialColor(color == Color.TRANSPARENT ? Color.WHITE : color)
.showLightnessSlider(true)
.showAlphaSlider(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
.setPositiveButton(android.R.string.ok, new ColorPickerClickListener() {
@Override
public void onClick(DialogInterface dialog, int selectedColor, Integer[] allColors) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
cbSemiTransparent.setChecked(false);
btnColor.setColor(selectedColor);
}
})

View File

@ -40,6 +40,7 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.Group;
import androidx.core.graphics.ColorUtils;
import androidx.preference.PreferenceManager;
import com.flask.colorpicker.ColorPickerView;
@ -99,8 +100,12 @@ public class ActivityWidgetUnified extends ActivityBase {
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 semi = prefs.getBoolean("widget." + appWidgetId + ".semi", true);
int background = prefs.getInt("widget." + appWidgetId + ".background", Color.TRANSPARENT);
boolean semi = prefs.getBoolean("widget." + appWidgetId + ".semi",
Build.VERSION.SDK_INT < Build.VERSION_CODES.S);
int background = prefs.getInt("widget." + appWidgetId + ".background",
Build.VERSION.SDK_INT < Build.VERSION_CODES.S
? Color.TRANSPARENT
: ColorUtils.setAlphaComponent(Color.BLACK, 127));
boolean separators = prefs.getBoolean("widget." + appWidgetId + ".separators", true);
int font = prefs.getInt("widget." + appWidgetId + ".font", 0);
int padding = prefs.getInt("widget." + appWidgetId + ".padding", 0);
@ -146,6 +151,14 @@ public class ActivityWidgetUnified extends ActivityBase {
}
});
cbSemiTransparent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
btnColor.setColor(Color.TRANSPARENT);
}
});
cbHighlight.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -187,6 +200,7 @@ public class ActivityWidgetUnified extends ActivityBase {
btnColor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int color = btnColor.getColor();
int editTextColor = Helper.resolveColor(ActivityWidgetUnified.this, android.R.attr.editTextColor);
ColorPickerDialogBuilder
@ -196,10 +210,14 @@ public class ActivityWidgetUnified extends ActivityBase {
.setColorEditTextColor(editTextColor)
.wheelType(ColorPickerView.WHEEL_TYPE.FLOWER)
.density(6)
.lightnessSliderOnly()
.initialColor(color == Color.TRANSPARENT ? Color.WHITE : color)
.showLightnessSlider(true)
.showAlphaSlider(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
.setPositiveButton(android.R.string.ok, new ColorPickerClickListener() {
@Override
public void onClick(DialogInterface dialog, int selectedColor, Integer[] allColors) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
cbSemiTransparent.setChecked(false);
btnColor.setColor(selectedColor);
}
})

View File

@ -60,8 +60,12 @@ public class Widget extends AppWidgetProvider {
String name = prefs.getString("widget." + appWidgetId + ".name", null);
long account = prefs.getLong("widget." + appWidgetId + ".account", -1L);
boolean daynight = prefs.getBoolean("widget." + appWidgetId + ".daynight", false);
boolean semi = prefs.getBoolean("widget." + appWidgetId + ".semi", true);
int background = prefs.getInt("widget." + appWidgetId + ".background", Color.TRANSPARENT);
boolean semi = prefs.getBoolean("widget." + appWidgetId + ".semi",
Build.VERSION.SDK_INT < Build.VERSION_CODES.S);
int background = prefs.getInt("widget." + appWidgetId + ".background",
Build.VERSION.SDK_INT < Build.VERSION_CODES.S
? Color.TRANSPARENT
: ColorUtils.setAlphaComponent(Color.BLACK, 127));
int layout = prefs.getInt("widget." + appWidgetId + ".layout", 0);
int version = prefs.getInt("widget." + appWidgetId + ".version", 0);

View File

@ -51,8 +51,12 @@ public class WidgetSync extends AppWidgetProvider {
for (int appWidgetId : appWidgetIds) {
boolean daynight = prefs.getBoolean("widget." + appWidgetId + ".daynight", false);
boolean semi = prefs.getBoolean("widget." + appWidgetId + ".semi", true);
int background = prefs.getInt("widget." + appWidgetId + ".background", Color.TRANSPARENT);
boolean semi = prefs.getBoolean("widget." + appWidgetId + ".semi",
Build.VERSION.SDK_INT < Build.VERSION_CODES.S);
int background = prefs.getInt("widget." + appWidgetId + ".background",
Build.VERSION.SDK_INT < Build.VERSION_CODES.S
? Color.TRANSPARENT
: ColorUtils.setAlphaComponent(Color.BLACK, 127));
int version = prefs.getInt("widget." + appWidgetId + ".version", 0);
if (version <= 1550)

View File

@ -51,8 +51,12 @@ public class WidgetUnified extends AppWidgetProvider {
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 semi = prefs.getBoolean("widget." + appWidgetId + ".semi", true);
int background = prefs.getInt("widget." + appWidgetId + ".background", Color.TRANSPARENT);
boolean semi = prefs.getBoolean("widget." + appWidgetId + ".semi",
Build.VERSION.SDK_INT < Build.VERSION_CODES.S);
int background = prefs.getInt("widget." + appWidgetId + ".background",
Build.VERSION.SDK_INT < Build.VERSION_CODES.S
? Color.TRANSPARENT
: ColorUtils.setAlphaComponent(Color.BLACK, 127));
boolean separators = prefs.getBoolean("widget." + appWidgetId + ".separators", true);
int font = prefs.getInt("widget." + appWidgetId + ".font", 0);
int padding = prefs.getInt("widget." + appWidgetId + ".padding", 0);