Skip to content

Commit

Permalink
#124 Add "Today's events background color"
Browse files Browse the repository at this point in the history
  • Loading branch information
yvolk committed Aug 28, 2019
1 parent d55693c commit 1b7f2e9
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Color;
import android.net.Uri;
import android.view.View;
import android.widget.RemoteViews;
Expand All @@ -25,17 +24,12 @@

import androidx.annotation.IdRes;

import static android.graphics.Color.alpha;
import static android.graphics.Color.blue;
import static android.graphics.Color.green;
import static android.graphics.Color.red;
import static org.andstatus.todoagenda.Theme.themeNameToResId;
import static org.andstatus.todoagenda.util.CalendarIntentUtil.createOpenCalendarAtDayIntent;
import static org.andstatus.todoagenda.util.CalendarIntentUtil.createOpenCalendarEventPendingIntent;
import static org.andstatus.todoagenda.util.CalendarIntentUtil.createOpenCalendarPendingIntent;
import static org.andstatus.todoagenda.util.RemoteViewsUtil.setAlpha;
import static org.andstatus.todoagenda.util.RemoteViewsUtil.setBackgroundColor;
import static org.andstatus.todoagenda.util.RemoteViewsUtil.setColorFilter;
import static org.andstatus.todoagenda.util.RemoteViewsUtil.setImageFromAttr;
import static org.andstatus.todoagenda.util.RemoteViewsUtil.setTextColorFromAttr;
import static org.andstatus.todoagenda.util.RemoteViewsUtil.setTextSize;
Expand Down Expand Up @@ -69,6 +63,7 @@ public void onUpdate(Context baseContext, AppWidgetManager appWidgetManager, int
configureBackground(settings, rv);
configureWidgetHeader(settings, rv);
configureList(settings, widgetId, rv);
configureNoEvents(settings, rv);
appWidgetManager.updateAppWidget(widgetId, rv);
}
}
Expand All @@ -80,10 +75,10 @@ private void configureBackground(InstanceSettings settings, RemoteViews rv) {
} else {
rv.setViewVisibility(R.id.action_bar, View.GONE);
}
int color = settings.getBackgroundColor();
int opaqueColor = Color.rgb(red(color), green(color), blue(color));
setColorFilter(rv, R.id.background_image, opaqueColor);
setAlpha(rv, R.id.background_image, alpha(color));
// int color = settings.getEventsBackgroundColor();
// int opaqueColor = Color.rgb(red(color), green(color), blue(color));
// setColorFilter(rv, R.id.background_image, opaqueColor);
// setAlpha(rv, R.id.background_image, alpha(color));
}

private void configureWidgetHeader(InstanceSettings settings, RemoteViews rv) {
Expand Down Expand Up @@ -164,21 +159,24 @@ private void configureList(InstanceSettings settings, int widgetId, RemoteViews
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
rv.setRemoteAdapter(R.id.event_list, intent);
}

private void configureNoEvents(InstanceSettings settings, RemoteViews rv) {
boolean permissionsGranted = PermissionsUtil.arePermissionsGranted(settings.getContext());
@IdRes int emptyViewId = R.id.empty_event_list;
rv.setEmptyView(R.id.event_list, emptyViewId);
rv.setTextViewText(emptyViewId, settings.getContext().getText(
@IdRes int viewId = R.id.empty_event_list;
rv.setEmptyView(R.id.event_list, viewId);
rv.setTextViewText(viewId, settings.getContext().getText(
permissionsGranted ? R.string.no_upcoming_events : R.string.grant_permissions_verbose
));
rv.setOnClickPendingIntent(emptyViewId, getPermittedAddEventPendingIntent(settings));
rv.setOnClickPendingIntent(viewId, getPermittedAddEventPendingIntent(settings));
if (permissionsGranted) {
rv.setPendingIntentTemplate(R.id.event_list, createOpenCalendarEventPendingIntent(settings));
rv.setOnClickFillInIntent(emptyViewId,
rv.setOnClickFillInIntent(viewId,
createOpenCalendarAtDayIntent(new DateTime(settings.getTimeZone())));
}
setTextSize(settings, rv, emptyViewId, R.dimen.event_entry_details);
setTextColorFromAttr(settings.getEntryThemeContext(), rv, emptyViewId, R.attr.eventEntryTitle);
setTextSize(settings, rv, viewId, R.dimen.event_entry_details);
setBackgroundColor(rv, viewId, settings.getEventsBackgroundColor());
setTextColorFromAttr(settings.getEntryThemeContext(), rv, viewId, R.attr.eventEntryTitle);
}

public static void updateWidgetsWithData(Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ private void setColor(CalendarEntry entry, RemoteViews rv) {
} else {
rv.setViewVisibility(R.id.event_entry_icon, View.GONE);
}
if (entry.getEndDate().isBefore(DateUtil.now(entry.getEndDate().getZone()))) {
setBackgroundColor(rv, R.id.event_entry, getSettings().getPastEventsBackgroundColor());
} else {
setBackgroundColor(rv, R.id.event_entry, 0);
}
setBackgroundColor(rv, R.id.event_entry, entry.isBeforeToday()
? getSettings().getPastEventsBackgroundColor()
: entry.isToday()
? getSettings().getTodaysEventsBackgroundColor()
: getSettings().getEventsBackgroundColor());
}

public int getViewTypeCount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.List;

public class ApplicationPreferences {

public static final String PREF_WIDGET_ID = "widgetId";

static final String PREF_TEXT_SIZE_SCALE = "textSizeScale";
Expand All @@ -41,21 +40,15 @@ public class ApplicationPreferences {
static final boolean PREF_FILL_ALL_DAY_DEFAULT = true;
static final String PREF_WIDGET_HEADER_THEME = "headerTheme";
static final String PREF_WIDGET_HEADER_THEME_DEFAULT = Theme.DARK.name();
static final String PREF_WIDGET_HEADER_BACKGROUND_COLOR = "widgetHeaderBackgroundColor";
static final int PREF_WIDGET_HEADER_BACKGROUND_COLOR_DEFAULT = Color.TRANSPARENT;
static final String PREF_DAY_HEADER_THEME = "dayHeaderTheme";
static final String PREF_DAY_HEADER_THEME_DEFAULT = Theme.DARK.name();
static final String PREF_DAY_HEADER_ALIGNMENT = "dayHeaderAlignment";
static final String PREF_DAY_HEADER_ALIGNMENT_DEFAULT = Alignment.RIGHT.name();
static final String PREF_ENTRY_THEME = "entryTheme";
public static final String PREF_ENTRY_THEME_DEFAULT = Theme.BLACK.name();
static final String PREF_SHOW_PAST_EVENTS_WITH_DEFAULT_COLOR = "showPastEventsWithDefaultColor";
static final String PREF_PAST_EVENTS_BACKGROUND_COLOR = "pastEventsBackgroundColor";
static final int PREF_PAST_EVENTS_BACKGROUND_COLOR_DEFAULT = 0x4affff2b;
static final String PREF_BACKGROUND_COLOR = "backgroundColor";
static final int PREF_BACKGROUND_COLOR_DEFAULT = 0x80000000;
static final String PREF_SHOW_EVENT_ICON = "showEventIcon";
static final String PREF_SHOW_NUMBER_OF_DAYS_TO_EVENT = "showNumberOfDaysToEvent";
static final String PREF_SHOW_PAST_EVENTS_WITH_DEFAULT_COLOR = "showPastEventsWithDefaultColor";
static final String PREF_HIDE_BASED_ON_KEYWORDS = "hideBasedOnKeywords";
static final String KEY_SHARE_EVENTS_FOR_DEBUGGING = "shareEventsForDebugging";
static final String PREF_ABBREVIATE_DATES = "abbreviateDates";
Expand All @@ -67,6 +60,16 @@ public class ApplicationPreferences {
"showOnlyClosestInstanceOfRecurringEvent";
static final String PREF_WIDGET_INSTANCE_NAME = "widgetInstanceName";

// Colors
static final String PREF_WIDGET_HEADER_BACKGROUND_COLOR = "widgetHeaderBackgroundColor";
static final int PREF_WIDGET_HEADER_BACKGROUND_COLOR_DEFAULT = Color.TRANSPARENT;
static final String PREF_PAST_EVENTS_BACKGROUND_COLOR = "pastEventsBackgroundColor";
static final int PREF_PAST_EVENTS_BACKGROUND_COLOR_DEFAULT = 0x4affff2b;
static final String PREF_TODAYS_EVENTS_BACKGROUND_COLOR = "todaysEventsBackgroundColor";
static final int PREF_TODAYS_EVENTS_BACKGROUND_COLOR_DEFAULT = 0x4A5FFF5D;
static final String PREF_EVENTS_BACKGROUND_COLOR = "backgroundColor";
static final int PREF_EVENTS_BACKGROUND_COLOR_DEFAULT = 0x80000000;

private static volatile String lockedTimeZoneId = null;

private ApplicationPreferences() {
Expand All @@ -84,6 +87,8 @@ public static void startEditing(Context context, Integer widgetId) {
setHideBasedOnKeywords(context, settings.getHideBasedOnKeywords());
setInt(context, PREF_WIDGET_HEADER_BACKGROUND_COLOR, settings.getWidgetHeaderBackgroundColor());
setInt(context, PREF_PAST_EVENTS_BACKGROUND_COLOR, settings.getPastEventsBackgroundColor());
setInt(context, PREF_TODAYS_EVENTS_BACKGROUND_COLOR, settings.getTodaysEventsBackgroundColor());
setInt(context, PREF_EVENTS_BACKGROUND_COLOR, settings.getEventsBackgroundColor());
setShowDaysWithoutEvents(context, settings.getShowDaysWithoutEvents());
setShowDayHeaders(context, settings.getShowDayHeaders());
setShowPastEventsUnderOneHeader(context, settings.getShowPastEventsUnderOneHeader());
Expand All @@ -105,7 +110,6 @@ public static void startEditing(Context context, Integer widgetId) {
setString(context, PREF_DAY_HEADER_THEME, settings.getDayHeaderTheme());
setString(context, PREF_ENTRY_THEME, settings.getEntryTheme());
setBoolean(context, PREF_SHOW_WIDGET_HEADER, settings.getShowWidgetHeader());
setInt(context, PREF_BACKGROUND_COLOR, settings.getBackgroundColor());
setString(context, PREF_TEXT_SIZE_SCALE, settings.getTextSizeScale());
setString(context, PREF_DAY_HEADER_ALIGNMENT, settings.getDayHeaderAlignment());
}
Expand Down Expand Up @@ -187,6 +191,18 @@ public static int getPastEventsBackgroundColor(Context context) {
PREF_PAST_EVENTS_BACKGROUND_COLOR_DEFAULT);
}

public static int getTodaysEventsBackgroundColor(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getInt(
PREF_TODAYS_EVENTS_BACKGROUND_COLOR,
PREF_TODAYS_EVENTS_BACKGROUND_COLOR_DEFAULT);
}

public static int getEventsBackgroundColor(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getInt(
PREF_EVENTS_BACKGROUND_COLOR,
PREF_EVENTS_BACKGROUND_COLOR_DEFAULT);
}

public static boolean getShowDaysWithoutEvents(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(PREF_SHOW_DAYS_WITHOUT_EVENTS, false);
Expand Down Expand Up @@ -323,17 +339,13 @@ public static boolean getBoolean(Context context, String key, boolean defaultVal
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(key, defaultValue);
}

public static void setInt(Context context, String key, int value) {
private static void setInt(Context context, String key, int value) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = prefs.edit();
editor.putInt(key, value);
editor.apply();
}

public static int getInt(Context context, String key, int defaultValue) {
return PreferenceManager.getDefaultSharedPreferences(context).getInt(key, defaultValue);
}

public static String getWidgetInstanceName(Context context) {
return getString(context, PREF_WIDGET_INSTANCE_NAME, "");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_ABBREVIATE_DATES;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_ABBREVIATE_DATES_DEFAULT;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_ACTIVE_SOURCES;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_BACKGROUND_COLOR;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_BACKGROUND_COLOR_DEFAULT;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_DATE_FORMAT;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_DATE_FORMAT_DEFAULT;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_DAY_HEADER_ALIGNMENT;
Expand All @@ -36,6 +34,8 @@
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_DAY_HEADER_THEME_DEFAULT;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_ENTRY_THEME;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_ENTRY_THEME_DEFAULT;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_EVENTS_BACKGROUND_COLOR;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_EVENTS_BACKGROUND_COLOR_DEFAULT;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_EVENTS_ENDED;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_EVENT_ENTRY_LAYOUT;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_EVENT_RANGE;
Expand Down Expand Up @@ -64,6 +64,8 @@
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_SHOW_WIDGET_HEADER;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_TEXT_SIZE_SCALE;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_TEXT_SIZE_SCALE_DEFAULT;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_TODAYS_EVENTS_BACKGROUND_COLOR;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_TODAYS_EVENTS_BACKGROUND_COLOR_DEFAULT;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_WIDGET_HEADER_BACKGROUND_COLOR;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_WIDGET_HEADER_BACKGROUND_COLOR_DEFAULT;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_WIDGET_HEADER_THEME;
Expand Down Expand Up @@ -91,6 +93,8 @@ public class InstanceSettings {
private String hideBasedOnKeywords = "";
private int widgetHeaderBackgroundColor = PREF_WIDGET_HEADER_BACKGROUND_COLOR_DEFAULT;
private int pastEventsBackgroundColor = PREF_PAST_EVENTS_BACKGROUND_COLOR_DEFAULT;
private int todaysEventsBackgroundColor = PREF_TODAYS_EVENTS_BACKGROUND_COLOR_DEFAULT;
private int eventsBackgroundColor = PREF_EVENTS_BACKGROUND_COLOR_DEFAULT;
private boolean showDaysWithoutEvents = false;
private boolean showDayHeaders = true;
private boolean showPastEventsUnderOneHeader = false;
Expand All @@ -111,7 +115,6 @@ public class InstanceSettings {
private String widgetHeaderTheme = PREF_WIDGET_HEADER_THEME_DEFAULT;
private String dayHeaderTheme = PREF_DAY_HEADER_THEME_DEFAULT;
private String entryTheme = PREF_ENTRY_THEME_DEFAULT;
private int backgroundColor = PREF_BACKGROUND_COLOR_DEFAULT;
private String textSizeScale = PREF_TEXT_SIZE_SCALE_DEFAULT;
private String dayHeaderAlignment = PREF_DAY_HEADER_ALIGNMENT_DEFAULT;

Expand Down Expand Up @@ -143,6 +146,12 @@ public static InstanceSettings fromJson(Context context, JSONObject json) throws
if (json.has(PREF_PAST_EVENTS_BACKGROUND_COLOR)) {
settings.pastEventsBackgroundColor = json.getInt(PREF_PAST_EVENTS_BACKGROUND_COLOR);
}
if (json.has(PREF_TODAYS_EVENTS_BACKGROUND_COLOR)) {
settings.todaysEventsBackgroundColor = json.getInt(PREF_TODAYS_EVENTS_BACKGROUND_COLOR);
}
if (json.has(PREF_EVENTS_BACKGROUND_COLOR)) {
settings.eventsBackgroundColor = json.getInt(PREF_EVENTS_BACKGROUND_COLOR);
}
if (json.has(PREF_SHOW_DAYS_WITHOUT_EVENTS)) {
settings.showDaysWithoutEvents = json.getBoolean(PREF_SHOW_DAYS_WITHOUT_EVENTS);
}
Expand Down Expand Up @@ -204,9 +213,6 @@ public static InstanceSettings fromJson(Context context, JSONObject json) throws
if (json.has(PREF_ENTRY_THEME)) {
settings.entryTheme = json.getString(PREF_ENTRY_THEME);
}
if (json.has(PREF_BACKGROUND_COLOR)) {
settings.backgroundColor = json.getInt(PREF_BACKGROUND_COLOR);
}
if (json.has(PREF_TEXT_SIZE_SCALE)) {
settings.textSizeScale = json.getString(PREF_TEXT_SIZE_SCALE);
}
Expand All @@ -227,6 +233,8 @@ static InstanceSettings fromApplicationPreferences(Context context, int widgetId
settings.hideBasedOnKeywords = ApplicationPreferences.getHideBasedOnKeywords(context);
settings.widgetHeaderBackgroundColor = ApplicationPreferences.getWidgetHeaderBackgroundColor(context);
settings.pastEventsBackgroundColor = ApplicationPreferences.getPastEventsBackgroundColor(context);
settings.todaysEventsBackgroundColor = ApplicationPreferences.getTodaysEventsBackgroundColor(context);
settings.eventsBackgroundColor = ApplicationPreferences.getEventsBackgroundColor(context);
settings.showDaysWithoutEvents = ApplicationPreferences.getShowDaysWithoutEvents(context);
settings.showDayHeaders = ApplicationPreferences.getShowDayHeaders(context);
settings.showPastEventsUnderOneHeader = ApplicationPreferences.getShowPastEventsUnderOneHeader(context);
Expand All @@ -248,8 +256,6 @@ static InstanceSettings fromApplicationPreferences(Context context, int widgetId
settings.showWidgetHeader = ApplicationPreferences.getBoolean(context, PREF_SHOW_WIDGET_HEADER, true);
settings.dayHeaderTheme = ApplicationPreferences.getString(context, PREF_DAY_HEADER_THEME, PREF_DAY_HEADER_THEME_DEFAULT);
settings.entryTheme = ApplicationPreferences.getString(context, PREF_ENTRY_THEME, PREF_ENTRY_THEME_DEFAULT);
settings.backgroundColor = ApplicationPreferences.getInt(context, PREF_BACKGROUND_COLOR,
PREF_BACKGROUND_COLOR_DEFAULT);
settings.textSizeScale = ApplicationPreferences.getString(context, PREF_TEXT_SIZE_SCALE,
PREF_TEXT_SIZE_SCALE_DEFAULT);
settings.dayHeaderAlignment = ApplicationPreferences.getString(context, PREF_DAY_HEADER_ALIGNMENT,
Expand Down Expand Up @@ -293,6 +299,8 @@ public JSONObject toJson() {
json.put(PREF_HIDE_BASED_ON_KEYWORDS, hideBasedOnKeywords);
json.put(PREF_WIDGET_HEADER_BACKGROUND_COLOR, widgetHeaderBackgroundColor);
json.put(PREF_PAST_EVENTS_BACKGROUND_COLOR, pastEventsBackgroundColor);
json.put(PREF_TODAYS_EVENTS_BACKGROUND_COLOR, todaysEventsBackgroundColor);
json.put(PREF_EVENTS_BACKGROUND_COLOR, eventsBackgroundColor);
json.put(PREF_SHOW_DAYS_WITHOUT_EVENTS, showDaysWithoutEvents);
json.put(PREF_SHOW_DAY_HEADERS, showDayHeaders);
json.put(PREF_SHOW_PAST_EVENTS_UNDER_ONE_HEADER, showPastEventsUnderOneHeader);
Expand All @@ -313,7 +321,6 @@ public JSONObject toJson() {
json.put(PREF_WIDGET_HEADER_THEME, widgetHeaderTheme);
json.put(PREF_DAY_HEADER_THEME, dayHeaderTheme);
json.put(PREF_ENTRY_THEME, entryTheme);
json.put(PREF_BACKGROUND_COLOR, backgroundColor);
json.put(PREF_TEXT_SIZE_SCALE, textSizeScale);
json.put(PREF_DAY_HEADER_ALIGNMENT, dayHeaderAlignment);
} catch (JSONException e) {
Expand Down Expand Up @@ -377,6 +384,14 @@ public int getPastEventsBackgroundColor() {
return pastEventsBackgroundColor;
}

public int getTodaysEventsBackgroundColor() {
return todaysEventsBackgroundColor;
}

public int getEventsBackgroundColor() {
return eventsBackgroundColor;
}

public boolean getShowDaysWithoutEvents() {
return showDaysWithoutEvents;
}
Expand Down Expand Up @@ -505,10 +520,6 @@ public boolean getShowWidgetHeader() {
return showWidgetHeader;
}

public int getBackgroundColor() {
return backgroundColor;
}

public String getTextSizeScale() {
return textSizeScale;
}
Expand Down
Loading

0 comments on commit 1b7f2e9

Please sign in to comment.