Fix default opacity for existing widgets

pull/996/head
Alex Baker 5 years ago
parent 8368c3b3d4
commit 697f658c42

@ -59,7 +59,7 @@ class ScrollableWidget : InjectingPreferenceFragment() {
val row = setupSlider(R.string.p_widget_opacity, 100)
val header = setupSlider(R.string.p_widget_header_opacity, row.value)
val footer = setupSlider(R.string.p_widget_empty_space_opacity, row.value)
val footer = setupSlider(R.string.p_widget_footer_opacity, row.value)
val opacity = findPreference(R.string.opacity) as SeekBarPreference
opacity.value = max(header.value, row.value, footer.value)

@ -100,7 +100,7 @@ public class TasksWidget extends InjectingAppWidgetProvider {
remoteViews.setInt(
R.id.empty_view,
"setBackgroundColor",
ColorUtils.setAlphaComponent(bgColor, widgetPreferences.getEmptySpaceOpacity()));
ColorUtils.setAlphaComponent(bgColor, widgetPreferences.getFooterOpacity()));
Filter filter = defaultFilterProvider.getFilterFromPreference(filterId);
remoteViews.setTextViewText(R.id.widget_title, filter.listingTitle);

@ -90,23 +90,29 @@ public class WidgetPreferences {
}
int getHeaderOpacity() {
return getAlphaValue(R.string.p_widget_header_opacity);
int headerOpacity = preferences.getInt(getKey(R.string.p_widget_header_opacity), -1);
return headerOpacity >= 0 && headerOpacity <= 100
? getAlphaValue(headerOpacity)
: getRowOpacity();
}
int getRowOpacity() {
return getAlphaValue(R.string.p_widget_opacity);
int getFooterOpacity() {
int footerOpacity = preferences.getInt(getKey(R.string.p_widget_footer_opacity), -1);
return footerOpacity >= 0 && footerOpacity <= 100
? getAlphaValue(footerOpacity)
: getRowOpacity();
}
int getEmptySpaceOpacity() {
return getAlphaValue(R.string.p_widget_empty_space_opacity);
int getRowOpacity() {
return getAlphaValue(preferences.getInt(getKey(R.string.p_widget_opacity), 100));
}
boolean openOnEmptySpaceClick() {
return preferences.getIntegerFromString(getKey(R.string.p_widget_empty_space_click), 0) == 1;
}
private int getAlphaValue(int resId) {
return (int) ((preferences.getInt(getKey(resId), 100) / 100.0) * 255.0);
private int getAlphaValue(int percentage) {
return (int) (percentage / 100.0 * 255.0);
}
public void setColor(int color) {

@ -300,7 +300,7 @@
<string name="p_widget_show_settings">widget-show-settings-</string>
<string name="p_widget_show_menu">widget-show-menu-</string>
<string name="p_widget_header_opacity">widget-header-opacity-</string>
<string name="p_widget_empty_space_opacity">widget-empty-space-opacity-</string>
<string name="p_widget_footer_opacity">widget-empty-space-opacity-</string>
<string name="p_widget_empty_space_click">widget-empty-space-click-</string>
<string name="p_widget_due_date_position">widget-due-date-position-</string>
<string name="p_widget_spacing">widget-spacing-</string>

@ -43,7 +43,7 @@
<SeekBarPreference
android:defaultValue="100"
android:key="@string/p_widget_empty_space_opacity"
android:key="@string/p_widget_footer_opacity"
android:max="100"
android:title="@string/opacity_footer"
app:min="0"

Loading…
Cancel
Save