Configure header, row, and empty space opacity

pull/996/head
Alex Baker 5 years ago
parent e2cb1c74bc
commit de86e87d6d

@ -22,7 +22,6 @@ import org.tasks.injection.InjectingPreferenceFragment
import org.tasks.locale.Locale
import org.tasks.preferences.DefaultFilterProvider
import org.tasks.preferences.Preferences
import org.tasks.widget.TasksWidget
import org.tasks.widget.WidgetPreferences
import javax.inject.Inject
@ -60,7 +59,9 @@ class ScrollableWidget : InjectingPreferenceFragment() {
appWidgetId = arguments!!.getInt(EXTRA_WIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID)
widgetPreferences = WidgetPreferences(context, preferences, appWidgetId)
setupSlider(R.string.p_widget_header_opacity, 100)
setupSlider(R.string.p_widget_opacity, 100)
setupSlider(R.string.p_widget_empty_space_opacity, 100)
setupSlider(R.string.p_widget_font_size, 16)
val showDueDate = setupCheckbox(R.string.p_widget_show_due_date)
setupCheckbox(R.string.p_widget_due_date_underneath, false).dependency = showDueDate.key

@ -9,13 +9,12 @@ import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.net.Uri;
import android.view.View;
import android.widget.RemoteViews;
import androidx.annotation.ColorInt;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.ColorUtils;
import com.todoroo.astrid.activity.MainActivity;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.dao.TaskDao;
@ -41,12 +40,6 @@ public class TasksWidget extends InjectingAppWidgetProvider {
@Inject TaskDao taskDao;
@Inject @ForApplication Context context;
private static Bitmap getSolidBackground(@ColorInt int bgColor) {
Bitmap bitmap = Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_8888); // Create a Bitmap
new Canvas(bitmap).drawColor(bgColor); // Set the color
return bitmap;
}
@Override
protected void inject(BroadcastComponent component) {
component.inject(this);
@ -94,20 +87,24 @@ public class TasksWidget extends InjectingAppWidgetProvider {
} else {
remoteViews.setViewVisibility(R.id.widget_header, View.GONE);
}
int opacityPercentage = widgetPreferences.getOpacity();
int opacity = (int) ((opacityPercentage / 100.0) * 255.0);
remoteViews.setImageViewBitmap(
R.id.widget_background,
getSolidBackground(getBackgroundColor(widgetPreferences.getThemeIndex())));
remoteViews.setImageViewBitmap(
R.id.widget_header_background, getSolidBackground(color.getPrimaryColor()));
remoteViews.setInt(R.id.widget_background, "setAlpha", opacity);
remoteViews.setInt(R.id.widget_header_background, "setAlpha", opacity);
remoteViews.setInt(
R.id.widget_header,
"setBackgroundColor",
ColorUtils.setAlphaComponent(color.getPrimaryColor(), widgetPreferences.getHeaderOpacity()));
int bgColor = getBackgroundColor(widgetPreferences.getThemeIndex());
remoteViews.setInt(
R.id.list_view,
"setBackgroundColor",
ColorUtils.setAlphaComponent(bgColor, widgetPreferences.getRowOpacity()));
remoteViews.setInt(
R.id.empty_view,
"setBackgroundColor",
ColorUtils.setAlphaComponent(bgColor, widgetPreferences.getEmptySpaceOpacity()));
Filter filter = defaultFilterProvider.getFilterFromPreference(filterId);
remoteViews.setTextViewText(R.id.widget_title, filter.listingTitle);
remoteViews.setRemoteAdapter(R.id.list_view, rvIntent);
remoteViews.setEmptyView(R.id.list_view, R.id.empty_view);
remoteViews.setOnClickPendingIntent(R.id.widget_title, getOpenListIntent(context, filter, id));
remoteViews.setOnClickPendingIntent(R.id.widget_button, getNewTaskIntent(context, filter, id));
remoteViews.setOnClickPendingIntent(R.id.widget_change_list, getChooseListIntent(context, filter, id));

@ -86,8 +86,20 @@ public class WidgetPreferences {
return color;
}
public int getOpacity() {
return preferences.getInt(getKey(R.string.p_widget_opacity), 100);
int getHeaderOpacity() {
return getAlphaValue(R.string.p_widget_header_opacity);
}
int getRowOpacity() {
return getAlphaValue(R.string.p_widget_opacity);
}
int getEmptySpaceOpacity() {
return getAlphaValue(R.string.p_widget_empty_space_opacity);
}
private int getAlphaValue(int resId) {
return (int) ((preferences.getInt(getKey(resId), 100) / 100.0) * 255.0);
}
public void setColor(int color) {

@ -11,13 +11,6 @@
android:layout_height="48dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/widget_header_background"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
tools:ignore="ContentDescription" />
<ImageButton
android:id="@+id/widget_change_list"
android:layout_width="wrap_content"
@ -70,26 +63,18 @@
</RelativeLayout>
<ImageView
android:id="@+id/widget_background"
android:layout_below="@id/widget_header"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
tools:ignore="ContentDescription" />
<ListView
android:id="@+id/list_view"
android:layout_below="@id/widget_header"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_height="wrap_content"
android:listSelector="@android:color/transparent"
android:divider="@null"
android:dividerHeight="0dp"/>
<TextView
android:id="@+id/empty_view"
android:layout_below="@id/widget_header"
android:layout_below="@id/list_view"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:gravity="center"/>

@ -277,6 +277,8 @@
<string name="p_widget_show_settings">widget-show-settings-</string>
<string name="p_widget_show_menu">widget-show-menu-</string>
<string name="p_widget_due_date_underneath">widget-due-date-underneath-</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_spacing">widget-spacing-</string>
<string name="p_dashclock_filter">dashclock_filter</string>
<string name="p_default_remote_list">default_remote_list</string>

@ -305,6 +305,7 @@ File %1$s contained %2$s.\n\n
<string name="widget_show_due_date">Show due dates</string>
<string name="widget_show_checkboxes">Show checkboxes</string>
<string name="widget_due_date_underneath">Due date below title</string>
<string name="widget_hide_background">Hide background</string>
<string name="widget_show_header">Show header</string>
<string name="widget_show_settings">Show settings</string>
<string name="widget_show_menu">Show menu</string>
@ -411,6 +412,7 @@ File %1$s contained %2$s.\n\n
<string name="widget_settings">Widget settings</string>
<string name="widget_header_settings">Header settings</string>
<string name="widget_row_settings">Row settings</string>
<string name="widget_empty_space">Empty space</string>
<string name="clear_completed_tasks_confirmation">Clear completed tasks?</string>
<string name="copy_multiple_tasks_confirmation">%s copied</string>
<string name="delete_multiple_tasks_confirmation">%s deleted</string>

@ -10,15 +10,6 @@
android:key="@string/p_widget_theme"
android:title="@string/theme" />
<SeekBarPreference
android:defaultValue="100"
android:key="@string/p_widget_opacity"
android:max="100"
android:title="@string/opacity"
app:min="0"
app:seekBarIncrement="5"
app:showSeekBarValue="true" />
<PreferenceCategory android:title="@string/widget_header_settings">
<SwitchPreferenceCompat
@ -29,6 +20,15 @@
android:key="@string/p_widget_color_v2"
android:title="@string/color" />
<SeekBarPreference
android:defaultValue="100"
android:key="@string/p_widget_header_opacity"
android:max="100"
android:title="@string/opacity"
app:min="0"
app:seekBarIncrement="5"
app:showSeekBarValue="true" />
<SwitchPreferenceCompat
android:key="@string/p_widget_show_menu"
android:title="@string/widget_show_menu" />
@ -41,6 +41,15 @@
<PreferenceCategory android:title="@string/widget_row_settings">
<SeekBarPreference
android:defaultValue="100"
android:key="@string/p_widget_opacity"
android:max="100"
android:title="@string/opacity"
app:min="0"
app:seekBarIncrement="5"
app:showSeekBarValue="true" />
<SeekBarPreference
android:defaultValue="16"
android:key="@string/p_widget_font_size"
@ -87,4 +96,17 @@
</PreferenceCategory>
<PreferenceCategory android:title="@string/widget_empty_space">
<SeekBarPreference
android:defaultValue="100"
android:key="@string/p_widget_empty_space_opacity"
android:max="100"
android:title="@string/opacity"
app:min="0"
app:seekBarIncrement="5"
app:showSeekBarValue="true" />
</PreferenceCategory>
</PreferenceScreen>
Loading…
Cancel
Save