diff --git a/app/src/main/java/org/andstatus/todoagenda/Alignment.java b/app/src/main/java/org/andstatus/todoagenda/Alignment.java index e2b8a9b4..87175223 100644 --- a/app/src/main/java/org/andstatus/todoagenda/Alignment.java +++ b/app/src/main/java/org/andstatus/todoagenda/Alignment.java @@ -1,18 +1,17 @@ package org.andstatus.todoagenda; +import android.view.Gravity; + public enum Alignment { - LEFT(R.layout.day_header_left), - CENTER(R.layout.day_header_center), - RIGHT(R.layout.day_header_right); + LEFT(Gravity.LEFT), + CENTER(android.view.Gravity.CENTER), + RIGHT(Gravity.RIGHT); - private int layoutId; + public final int gravity; - Alignment(int layoutId) { - this.layoutId = layoutId; + Alignment(int gravity) { + this.gravity = gravity; } - public int getLayoutId() { - return layoutId; - } } diff --git a/app/src/main/java/org/andstatus/todoagenda/prefs/ApplicationPreferences.java b/app/src/main/java/org/andstatus/todoagenda/prefs/ApplicationPreferences.java index d7f06bb2..5d09e6b5 100644 --- a/app/src/main/java/org/andstatus/todoagenda/prefs/ApplicationPreferences.java +++ b/app/src/main/java/org/andstatus/todoagenda/prefs/ApplicationPreferences.java @@ -28,6 +28,7 @@ import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_FILL_ALL_DAY; import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_FILL_ALL_DAY_DEFAULT; import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_HIDE_BASED_ON_KEYWORDS; +import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_HORIZONTAL_LINE_BELOW_DAY_HEADER; import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_INDICATE_ALERTS; import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_INDICATE_RECURRING; import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_LOCKED_TIME_ZONE_ID; @@ -79,6 +80,7 @@ public static void fromInstanceSettings(Context context, Integer widgetId) { setInt(context, PREF_EVENTS_BACKGROUND_COLOR, settings.getEventsBackgroundColor()); setShowDaysWithoutEvents(context, settings.getShowDaysWithoutEvents()); setShowDayHeaders(context, settings.getShowDayHeaders()); + setHorizontalLineBelowDayHeader(context, settings.getHorizontalLineBelowDayHeader()); setShowPastEventsUnderOneHeader(context, settings.getShowPastEventsUnderOneHeader()); setShowPastEventsWithDefaultColor(context, settings.getShowPastEventsWithDefaultColor()); setShowEventIcon(context, settings.getShowEventIcon()); @@ -196,6 +198,15 @@ public static int getEventsBackgroundColor(Context context) { PREF_EVENTS_BACKGROUND_COLOR_DEFAULT); } + public static boolean getHorizontalLineBelowDayHeader(Context context) { + return PreferenceManager.getDefaultSharedPreferences(context) + .getBoolean(PREF_HORIZONTAL_LINE_BELOW_DAY_HEADER, false); + } + + private static void setHorizontalLineBelowDayHeader(Context context, boolean value) { + setBoolean(context, PREF_HORIZONTAL_LINE_BELOW_DAY_HEADER, value); + } + public static boolean getShowDaysWithoutEvents(Context context) { return PreferenceManager.getDefaultSharedPreferences(context) .getBoolean(PREF_SHOW_DAYS_WITHOUT_EVENTS, false); diff --git a/app/src/main/java/org/andstatus/todoagenda/prefs/InstanceSettings.java b/app/src/main/java/org/andstatus/todoagenda/prefs/InstanceSettings.java index 85d8fc4d..f545baaa 100644 --- a/app/src/main/java/org/andstatus/todoagenda/prefs/InstanceSettings.java +++ b/app/src/main/java/org/andstatus/todoagenda/prefs/InstanceSettings.java @@ -55,6 +55,8 @@ public class InstanceSettings { static final String PREF_DAY_HEADER_ALIGNMENT = "dayHeaderAlignment"; private static final String PREF_DAY_HEADER_ALIGNMENT_DEFAULT = Alignment.RIGHT.name(); private String dayHeaderAlignment = PREF_DAY_HEADER_ALIGNMENT_DEFAULT; + static final String PREF_HORIZONTAL_LINE_BELOW_DAY_HEADER = "horizontalLineBelowDayHeader"; + private boolean horizontalLineBelowDayHeader = false; static final String PREF_SHOW_DAYS_WITHOUT_EVENTS = "showDaysWithoutEvents"; private boolean showDaysWithoutEvents = false; static final String PREF_EVENT_ENTRY_LAYOUT = "eventEntryLayout"; @@ -185,6 +187,9 @@ public static InstanceSettings fromJson(Context context, JSONObject json) throws if (json.has(PREF_SHOW_DAY_HEADERS)) { settings.showDayHeaders = json.getBoolean(PREF_SHOW_DAY_HEADERS); } + if (json.has(PREF_HORIZONTAL_LINE_BELOW_DAY_HEADER)) { + settings.horizontalLineBelowDayHeader = json.getBoolean(PREF_HORIZONTAL_LINE_BELOW_DAY_HEADER); + } if (json.has(PREF_SHOW_PAST_EVENTS_UNDER_ONE_HEADER)) { settings.showPastEventsUnderOneHeader = json.getBoolean(PREF_SHOW_PAST_EVENTS_UNDER_ONE_HEADER); } @@ -263,6 +268,7 @@ static InstanceSettings fromApplicationPreferences(Context context, int widgetId settings.eventsBackgroundColor = ApplicationPreferences.getEventsBackgroundColor(context); settings.showDaysWithoutEvents = ApplicationPreferences.getShowDaysWithoutEvents(context); settings.showDayHeaders = ApplicationPreferences.getShowDayHeaders(context); + settings.horizontalLineBelowDayHeader = ApplicationPreferences.getHorizontalLineBelowDayHeader(context); settings.showPastEventsUnderOneHeader = ApplicationPreferences.getShowPastEventsUnderOneHeader(context); settings.showPastEventsWithDefaultColor = ApplicationPreferences.getShowPastEventsWithDefaultColor(context); settings.showEventIcon = ApplicationPreferences.getShowEventIcon(context); @@ -333,6 +339,7 @@ public JSONObject toJson() { 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_HORIZONTAL_LINE_BELOW_DAY_HEADER, horizontalLineBelowDayHeader); json.put(PREF_SHOW_PAST_EVENTS_UNDER_ONE_HEADER, showPastEventsUnderOneHeader); json.put(PREF_SHOW_PAST_EVENTS_WITH_DEFAULT_COLOR, showPastEventsWithDefaultColor); json.put(PREF_SHOW_EVENT_ICON, showEventIcon); @@ -539,6 +546,10 @@ public String getDayHeaderAlignment() { return dayHeaderAlignment; } + public boolean getHorizontalLineBelowDayHeader() { + return horizontalLineBelowDayHeader; + } + public void logMe(Class tag, String message, int widgetId) { Log.v(tag.getSimpleName(), message + ", widgetId:" + widgetId + "\n" + toJson()); } diff --git a/app/src/main/java/org/andstatus/todoagenda/widget/DayHeaderVisualizer.java b/app/src/main/java/org/andstatus/todoagenda/widget/DayHeaderVisualizer.java index 2089711c..6b3f656c 100644 --- a/app/src/main/java/org/andstatus/todoagenda/widget/DayHeaderVisualizer.java +++ b/app/src/main/java/org/andstatus/todoagenda/widget/DayHeaderVisualizer.java @@ -26,8 +26,13 @@ public class DayHeaderVisualizer extends WidgetEntryVisualizer { + private final Alignment alignment; + private final boolean horizontalLineBelowDayHeader; + public DayHeaderVisualizer(Context context, int widgetId) { super(new EventProvider(EventProviderType.EMPTY, context, widgetId)); + alignment = Alignment.valueOf(getSettings().getDayHeaderAlignment()); + horizontalLineBelowDayHeader = getSettings().getHorizontalLineBelowDayHeader(); } @Override @@ -35,35 +40,55 @@ public RemoteViews getRemoteViews(WidgetEntry eventEntry, int position) { if(!(eventEntry instanceof DayHeader)) return null; DayHeader entry = (DayHeader) eventEntry; - String alignment = getSettings().getDayHeaderAlignment(); - RemoteViews rv = new RemoteViews(getContext().getPackageName(), Alignment.valueOf(alignment).getLayoutId()); + RemoteViews rv = new RemoteViews(getContext().getPackageName(), horizontalLineBelowDayHeader + ? R.layout.day_header_separator_below : R.layout.day_header_separator_above); + rv.setInt(R.id.day_header_title_wrapper, "setGravity", alignment.gravity); + + ContextThemeWrapper shadingContext = getSettings().getShadingContext(TextShadingPref.getDayHeader(entry)); + setBackgroundColor(rv, R.id.day_header, getSettings().getEntryBackgroundColor(entry)); + setDayHeaderTitle(position, entry, rv, shadingContext); + setDayHeaderSeparator(position, rv, shadingContext); + Intent intent = createOpenCalendarAtDayIntent(entry.getStartDate()); + rv.setOnClickFillInIntent(R.id.day_header, intent); + return rv; + } + + private void setDayHeaderTitle(int position, DayHeader entry, RemoteViews rv, ContextThemeWrapper shadingContext) { String dateString = (entry.getStartDate().equals(DateUtil.DATETIME_MIN) ? getContext().getString(R.string.past_header) : DateUtil.createDayHeaderTitle(getSettings(), entry.getStartDate())) .toUpperCase(Locale.getDefault()); rv.setTextViewText(R.id.day_header_title, dateString); setTextSize(getSettings(), rv, R.id.day_header_title, R.dimen.day_header_title); - setBackgroundColor(rv, R.id.day_header, getSettings().getEntryBackgroundColor(entry)); - ContextThemeWrapper shadingContext = getSettings().getShadingContext(TextShadingPref.getDayHeader(entry)); setTextColorFromAttr(shadingContext, rv, R.id.day_header_title, R.attr.dayHeaderTitle); - if (position == 0) { - rv.setViewVisibility(R.id.day_header_separator, View.GONE); + + int paddingTopId = horizontalLineBelowDayHeader + ? R.dimen.day_header_padding_bottom + : (position == 0 ? R.dimen.day_header_padding_top_first : R.dimen.day_header_padding_top); + int paddingBottomId = horizontalLineBelowDayHeader + ? R.dimen.day_header_padding_top + : R.dimen.day_header_padding_bottom; + setPadding(getSettings(), rv, R.id.day_header_title, + R.dimen.day_header_padding_left, paddingTopId, R.dimen.day_header_padding_right, paddingBottomId); + } + + private void setDayHeaderSeparator(int position, RemoteViews rv, ContextThemeWrapper shadingContext) { + int viewId = R.id.day_header_separator; + if (horizontalLineBelowDayHeader) { + setBackgroundColorFromAttr(shadingContext, rv, viewId, R.attr.dayHeaderSeparator); } else { - rv.setViewVisibility(R.id.day_header_separator, View.VISIBLE); - setBackgroundColorFromAttr(shadingContext, rv, R.id.day_header_separator, R.attr.dayHeaderSeparator); + if (position == 0) { + rv.setViewVisibility(viewId, View.GONE); + } else { + rv.setViewVisibility(viewId, View.VISIBLE); + setBackgroundColorFromAttr(shadingContext, rv, viewId, R.attr.dayHeaderSeparator); + } } - setPadding(getSettings(), rv, R.id.day_header_title, - R.dimen.day_header_padding_left, - position == 0 ? R.dimen.day_header_padding_top_first : R.dimen.day_header_padding_top, - R.dimen.day_header_padding_right, R.dimen.day_header_padding_bottom); - Intent intent = createOpenCalendarAtDayIntent(entry.getStartDate()); - rv.setOnClickFillInIntent(R.id.day_header, intent); - return rv; } @Override public int getViewTypeCount() { - return 3; // we have 3 because of the "left", "right" and "center" day headers + return 2; // we have 2 because of top and botton separator placement } @Override diff --git a/app/src/main/res/layout/day_header_right.xml b/app/src/main/res/layout/day_header_right.xml deleted file mode 100644 index a8ad858f..00000000 --- a/app/src/main/res/layout/day_header_right.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/day_header_center.xml b/app/src/main/res/layout/day_header_separator_above.xml similarity index 58% rename from app/src/main/res/layout/day_header_center.xml rename to app/src/main/res/layout/day_header_separator_above.xml index 0dee2622..2a1ca81b 100644 --- a/app/src/main/res/layout/day_header_center.xml +++ b/app/src/main/res/layout/day_header_separator_above.xml @@ -13,16 +13,23 @@ - + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/day_header_left.xml b/app/src/main/res/layout/day_header_separator_below.xml similarity index 58% rename from app/src/main/res/layout/day_header_left.xml rename to app/src/main/res/layout/day_header_separator_below.xml index 2392490b..43d84db9 100644 --- a/app/src/main/res/layout/day_header_left.xml +++ b/app/src/main/res/layout/day_header_separator_below.xml @@ -10,19 +10,26 @@ android:paddingRight="@dimen/calender_padding" android:paddingBottom="@dimen/entry_bottom_padding"> + + + + + - - \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b727d5d3..bba85b68 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -93,6 +93,7 @@ Left Center Right + Horizontal line below Day header Multiline title Spread event title over multiple lines Show days without events diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 732b0ac5..b254f33a 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -14,10 +14,6 @@