From 4ac1c4a83359f25aabfa35e18a74ae3383e678e4 Mon Sep 17 00:00:00 2001 From: Yuri Volkov Date: Mon, 31 Aug 2020 08:55:30 +0300 Subject: [PATCH] #15 Add "Compact layout" option. When it's turned on, most of spaces between Widget parts are removed. --- README.md | 4 ++- app/build.gradle | 4 +-- .../prefs/ApplicationPreferences.java | 6 +++++ .../todoagenda/prefs/InstanceSettings.java | 11 ++++++++ .../widget/DayHeaderVisualizer.java | 27 +++++++++++++------ .../widget/WidgetEntryVisualizer.java | 5 ++++ .../main/res/layout/event_entry_one_line.xml | 4 +-- app/src/main/res/values/dimens.xml | 1 + app/src/main/res/values/strings.xml | 5 +++- app/src/main/res/xml/appwidget_info.xml | 2 +- app/src/main/res/xml/preferences_layout.xml | 9 +++++++ 11 files changed, 62 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 242c956e..e045c7a5 100644 --- a/README.md +++ b/README.md @@ -90,11 +90,13 @@ If the problem is still present: In a case the widget doesn't work properly even after this, please [search, read and follow up on similar issues here](https://github.com/andstatus/todoagenda/issues?q=is%3Aissue+sort%3Aupdated-desc). -### 2020-08-29 v4.2.0 Integration with "Tasks: Astrid To-Do List Clone" and with Google Tasks via it. +### 2020-08-31 v4.2.1 Integration with "Tasks: Astrid To-Do List Clone" and with Google Tasks via it. * Support of "[Tasks: Astrid To-Do List Clone v.10+](https://github.com/tasks/tasks#readme)" not only gives us another app to manage tasks, but also allows to see Google tasks in our widget and manage them via the Tasks app. Please note that this works only with "[Tasks app v.10+](https://github.com/tasks/tasks/blob/main/CHANGELOG.md)" [#2](https://github.com/andstatus/todoagenda/issues/2). +* [Compact layout](https://github.com/andstatus/todoagenda/issues/15) option added. + When it's turned on, most of spaces between widget parts are removed. ### 2020-03-01 v4.0.8 Three powerful date format preferences. * This version is for Android 7+ only. Versions for older devices are still available e.g. diff --git a/app/build.gradle b/app/build.gradle index 6d41d52e..dd15a808 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,8 +7,8 @@ android { useLibrary 'android.test.mock' defaultConfig { - versionCode 683 - versionName '4.2.0' + versionCode 684 + versionName '4.2.1' minSdkVersion rootProject.minSdkVersion targetSdkVersion rootProject.targetSdkVersion 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 800cec08..fc4c7dde 100644 --- a/app/src/main/java/org/andstatus/todoagenda/prefs/ApplicationPreferences.java +++ b/app/src/main/java/org/andstatus/todoagenda/prefs/ApplicationPreferences.java @@ -16,6 +16,7 @@ import java.util.Map; import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_ACTIVE_SOURCES; +import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_COMPACT_LAYOUT; import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_DAY_HEADER_ALIGNMENT; import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_DAY_HEADER_DATE_FORMAT; import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_DAY_HEADER_DATE_FORMAT_DEFAULT; @@ -119,6 +120,7 @@ public static void fromInstanceSettings(Context context, Integer widgetId) { for (Map.Entry entry: settings.shadings.entrySet()) { setString(context, entry.getKey().preferenceName, entry.getValue().name()); } + setBoolean(context, PREF_COMPACT_LAYOUT, settings.isCompactLayout()); setString(context, PREF_WIDGET_HEADER_LAYOUT, settings.getWidgetHeaderLayout().value); setString(context, PREF_TEXT_SIZE_SCALE, settings.getTextSizeScale().preferenceValue); setString(context, PREF_DAY_HEADER_ALIGNMENT, settings.getDayHeaderAlignment()); @@ -408,6 +410,10 @@ public static String getWidgetInstanceName(Context context) { return getString(context, PREF_WIDGET_INSTANCE_NAME, ""); } + public static boolean isCompactLayout(Context context) { + return getBoolean(context, PREF_COMPACT_LAYOUT, false); + } + public static WidgetHeaderLayout getWidgetHeaderLayout(Context context) { return WidgetHeaderLayout.fromValue(getString(context, PREF_WIDGET_HEADER_LAYOUT, "")); } 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 39656b2a..c30aeb12 100644 --- a/app/src/main/java/org/andstatus/todoagenda/prefs/InstanceSettings.java +++ b/app/src/main/java/org/andstatus/todoagenda/prefs/InstanceSettings.java @@ -53,6 +53,8 @@ public class InstanceSettings { // ---------------------------------------------------------------------------------- // Layout + static final String PREF_COMPACT_LAYOUT = "compactLayout"; + private boolean compactLayout = false; static final String PREF_WIDGET_HEADER_LAYOUT = "widgetHeaderLayout"; private WidgetHeaderLayout widgetHeaderLayout = WidgetHeaderLayout.defaultValue; private static final String PREF_SHOW_DATE_ON_WIDGET_HEADER = "showDateOnWidgetHeader"; // till v 4.0 @@ -313,6 +315,9 @@ private InstanceSettings setFromJson(JSONObject json) { TextShading.fromName(json.getString(pref.preferenceName), pref.defaultShading)); } } + if (json.has(PREF_COMPACT_LAYOUT)) { + compactLayout = json.getBoolean(PREF_COMPACT_LAYOUT); + } if (json.has(PREF_WIDGET_HEADER_LAYOUT)) { widgetHeaderLayout = WidgetHeaderLayout.fromValue(json.getString(PREF_WIDGET_HEADER_LAYOUT)); } @@ -371,6 +376,7 @@ static InstanceSettings fromApplicationPreferences(Context context, int widgetId settings.filterMode = ApplicationPreferences.getFilterMode(context); settings.indicateAlerts = ApplicationPreferences.getBoolean(context, PREF_INDICATE_ALERTS, true); settings.indicateRecurring = ApplicationPreferences.getBoolean(context, PREF_INDICATE_RECURRING, false); + settings.compactLayout = ApplicationPreferences.isCompactLayout(context); settings.widgetHeaderLayout = ApplicationPreferences.getWidgetHeaderLayout(context); for (TextShadingPref pref: TextShadingPref.values()) { String themeName = ApplicationPreferences.getString(context, pref.preferenceName, @@ -462,6 +468,7 @@ public JSONObject toJson() { json.put(PREF_FILTER_MODE, filterMode.value); json.put(PREF_INDICATE_ALERTS, indicateAlerts); json.put(PREF_INDICATE_RECURRING, indicateRecurring); + json.put(PREF_COMPACT_LAYOUT, compactLayout); json.put(PREF_WIDGET_HEADER_LAYOUT, widgetHeaderLayout.value); for (TextShadingPref pref: TextShadingPref.values()) { json.put(pref.preferenceName, getShading(pref).name()); @@ -718,6 +725,10 @@ public ContextThemeWrapper getShadingContext(TextShadingPref pref) { return new ContextThemeWrapper(context, getShading(pref).themeResId); } + public boolean isCompactLayout() { + return compactLayout; + } + public WidgetHeaderLayout getWidgetHeaderLayout() { return widgetHeaderLayout; } 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 06e6e059..53347e14 100644 --- a/app/src/main/java/org/andstatus/todoagenda/widget/DayHeaderVisualizer.java +++ b/app/src/main/java/org/andstatus/todoagenda/widget/DayHeaderVisualizer.java @@ -14,6 +14,7 @@ import org.andstatus.todoagenda.provider.EventProvider; import org.andstatus.todoagenda.provider.EventProviderType; import org.andstatus.todoagenda.util.MyClock; +import org.andstatus.todoagenda.util.RemoteViewsUtil; import java.util.Collections; import java.util.List; @@ -47,6 +48,11 @@ public RemoteViews getRemoteViews(WidgetEntry eventEntry, int position) { ContextThemeWrapper shadingContext = getSettings().getShadingContext(TextShadingPref.forDayHeader(entry)); setBackgroundColor(rv, R.id.event_entry, getSettings().getEntryBackgroundColor(entry)); + if (getSettings().isCompactLayout()) { + RemoteViewsUtil.setPadding(getSettings(), rv, R.id.event_entry, R.dimen.zero, R.dimen.zero, R.dimen.zero, R.dimen.zero); + } else { + RemoteViewsUtil.setPadding(getSettings(), rv, R.id.event_entry, R.dimen.calender_padding, R.dimen.zero, R.dimen.calender_padding, R.dimen.entry_bottom_padding); + } setDayHeaderTitle(position, entry, rv, shadingContext); setDayHeaderSeparator(position, rv, shadingContext); return rv; @@ -64,14 +70,19 @@ private void setDayHeaderTitle(int position, DayHeader entry, RemoteViews rv, Co setTextSize(getSettings(), rv, R.id.day_header_title, R.dimen.day_header_title); setTextColorFromAttr(shadingContext, rv, R.id.day_header_title, R.attr.dayHeaderTitle); - 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); + if (getSettings().isCompactLayout()) { + setPadding(getSettings(), rv, R.id.day_header_title, + R.dimen.zero, R.dimen.zero, R.dimen.zero, R.dimen.zero); + } else { + 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); + } } protected CharSequence getTitleString(DayHeader entry) { diff --git a/app/src/main/java/org/andstatus/todoagenda/widget/WidgetEntryVisualizer.java b/app/src/main/java/org/andstatus/todoagenda/widget/WidgetEntryVisualizer.java index b85ab3d9..68faa03a 100644 --- a/app/src/main/java/org/andstatus/todoagenda/widget/WidgetEntryVisualizer.java +++ b/app/src/main/java/org/andstatus/todoagenda/widget/WidgetEntryVisualizer.java @@ -42,6 +42,11 @@ public RemoteViews getRemoteViews(WidgetEntry entry, int position) { setTime(entry, rv); setIndicators(entry, rv); + if (getSettings().isCompactLayout()) { + RemoteViewsUtil.setPadding(getSettings(), rv, R.id.event_entry, R.dimen.zero, R.dimen.zero, R.dimen.zero, R.dimen.zero); + } else { + RemoteViewsUtil.setPadding(getSettings(), rv, R.id.event_entry, R.dimen.calender_padding, R.dimen.zero, R.dimen.calender_padding, R.dimen.entry_bottom_padding); + } setBackgroundColor(rv, R.id.event_entry, getSettings().getEntryBackgroundColor(entry)); return rv; } diff --git a/app/src/main/res/layout/event_entry_one_line.xml b/app/src/main/res/layout/event_entry_one_line.xml index 5c71a002..ddabcf8b 100644 --- a/app/src/main/res/layout/event_entry_one_line.xml +++ b/app/src/main/res/layout/event_entry_one_line.xml @@ -87,10 +87,8 @@ layout="@layout/event_entry_indicator" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_alignBottom="@id/text_container" android:layout_alignParentEnd="true" - android:layout_alignTop="@id/text_container" - /> + android:layout_alignTop="@id/text_container" /> \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 94db6b29..34297506 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -1,6 +1,7 @@ + 0dp 0dp 14dp 8dp diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 51e96deb..9a402cb0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -68,7 +68,10 @@ Android 7+ supported. Supports Android tablets. - Place, show and hide widget elements + Compact layout + Normal space between widget parts + Minimum space between widget parts, thin borders + Place, show and hide widget parts Layout Widget header layout Event entry layout diff --git a/app/src/main/res/xml/appwidget_info.xml b/app/src/main/res/xml/appwidget_info.xml index 38d6181a..54f21fa2 100644 --- a/app/src/main/res/xml/appwidget_info.xml +++ b/app/src/main/res/xml/appwidget_info.xml @@ -2,7 +2,7 @@ android:initialLayout="@layout/widget_initial" android:minWidth="250dp" android:minHeight="110dp" - android:minResizeWidth="110dp" + android:minResizeWidth="40dp" android:minResizeHeight="40dp" android:previewImage="@drawable/calendar_widget_preview" android:resizeMode="horizontal|vertical" diff --git a/app/src/main/res/xml/preferences_layout.xml b/app/src/main/res/xml/preferences_layout.xml index f80a726b..30fbe5b1 100644 --- a/app/src/main/res/xml/preferences_layout.xml +++ b/app/src/main/res/xml/preferences_layout.xml @@ -1,6 +1,15 @@ + +