Skip to content

Commit

Permalink
#88 "Text shadow" option added to Colors section with these values: "…
Browse files Browse the repository at this point in the history
…No shadow" (default, nothing changes for existing widgets), "Dark shadow" and "Light shadow". For simplicity the same shadow applies to all parts of the widget.
  • Loading branch information
yvolk committed Jan 8, 2024
1 parent 3446931 commit 748e3c6
Show file tree
Hide file tree
Showing 42 changed files with 1,299 additions and 33 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,16 @@ In particular, see these solutions:

## Changelog

<a id="next"/>

### 2024- ...
* Added settings to limit maximum number of lines for an event's title and for details (i.e. for time and location)
[#109](https://github.com/andstatus/todoagenda/issues/109).
* Event details -> "Description" option added to show Calendar event Description. [#78](https://github.com/andstatus/todoagenda/issues/78)
<a id="v4.9"/>

### 2024-01-08 v4.9.0 Text shadow and Event description
* "Text shadow" option added to Colors section with these values: "No shadow" (default, nothing changes for existing widgets),
"Dark shadow" and "Light shadow". For simplicity the same shadow applies to all parts of the widget.
[#88](https://github.com/andstatus/todoagenda/issues/88)
* Event details -> "Description" option added to show Calendar event Description.
[#78](https://github.com/andstatus/todoagenda/issues/78)
* Added settings to limit maximum number of lines for an event's title and for details (i.e. for time,
location and description). [#109](https://github.com/andstatus/todoagenda/issues/109).

<a id="v4.8"/>

Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
}

defaultConfig {
versionCode 704
versionName '4.8.0'
versionCode 705
versionName '4.9.0'
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.andstatus.todoagenda.util.CalendarIntentUtil
import org.andstatus.todoagenda.util.DateUtil
import org.andstatus.todoagenda.util.PermissionsUtil
import org.andstatus.todoagenda.widget.WidgetEntry
import org.andstatus.todoagenda.widget.WidgetLayout
import org.joda.time.DateTime
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicReference
Expand Down Expand Up @@ -118,7 +119,8 @@ class EnvironmentChangedReceiver : BroadcastReceiver() {
private fun gotoPosition(context: Context, widgetId: Int, position: Int) {
if (widgetId == 0 || position < 0) return
val appWidgetManager = AppWidgetManager.getInstance(context)
val rv = RemoteViews(context.packageName, R.layout.widget_initial)
val settings = AllSettings.instanceFromId(context, widgetId)
val rv = RemoteViews(context.packageName, WidgetLayout.WIDGET_INITIAL.shadowed(settings.textShadow))
Log.d(TAG, "gotoPosition, Scrolling widget $widgetId to position $position")
rv.setScrollPosition(R.id.event_list, position)
appWidgetManager.updateAppWidget(widgetId, rv)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.andstatus.todoagenda.widget.WidgetEntry
import org.andstatus.todoagenda.widget.WidgetEntryPosition
import org.andstatus.todoagenda.widget.WidgetEntryVisualizer
import org.andstatus.todoagenda.widget.WidgetHeaderLayout
import org.andstatus.todoagenda.widget.WidgetLayout
import org.joda.time.DateTime
import java.util.Locale
import java.util.concurrent.ConcurrentHashMap
Expand Down Expand Up @@ -295,7 +296,7 @@ class RemoteViewsFactory(val context: Context, private val widgetId: Int, create
return
}
val settings = AllSettings.instanceFromId(context, widgetId)
val rv = RemoteViews(context.packageName, R.layout.widget_initial)
val rv = RemoteViews(context.packageName, WidgetLayout.WIDGET_INITIAL.shadowed(settings.textShadow))
settings.clock().updateZone()
configureWidgetHeader(settings, rv)
configureWidgetEntriesList(settings, rv)
Expand All @@ -311,7 +312,7 @@ class RemoteViewsFactory(val context: Context, private val widgetId: Int, create
if (settings.widgetHeaderLayout != WidgetHeaderLayout.HIDDEN) {
val headerView = RemoteViews(
settings.context.packageName,
settings.widgetHeaderLayout.layoutId
settings.widgetHeaderLayout.widgetLayout?.shadowed(settings.textShadow) ?: 0
)
rv.addView(R.id.header_parent, headerView)
RemoteViewsUtil.setBackgroundColor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.andstatus.todoagenda.prefs
import android.content.Context
import android.text.TextUtils
import androidx.preference.PreferenceManager
import org.andstatus.todoagenda.prefs.InstanceSettings.Companion.PREF_TEXT_SHADOW
import org.andstatus.todoagenda.prefs.colors.BackgroundColorPref
import org.andstatus.todoagenda.prefs.colors.ColorThemeType
import org.andstatus.todoagenda.prefs.colors.TextColorPref
Expand All @@ -11,6 +12,7 @@ import org.andstatus.todoagenda.prefs.colors.ThemeColors
import org.andstatus.todoagenda.prefs.dateformat.DateFormatValue
import org.andstatus.todoagenda.util.StringUtil
import org.andstatus.todoagenda.widget.EventEntryLayout
import org.andstatus.todoagenda.widget.TextShadow
import org.andstatus.todoagenda.widget.WidgetHeaderLayout

object ApplicationPreferences {
Expand All @@ -34,6 +36,7 @@ object ApplicationPreferences {
setFillAllDayEvents(context, settings.fillAllDayEvents)
setHideBasedOnKeywords(context, settings.hideBasedOnKeywords)
setShowBasedOnKeywords(context, settings.showBasedOnKeywords)

val colors = settings.colors()
setString(context, PREF_COLOR_THEME_TYPE, colors.colorThemeType.value)
setBoolean(context, PREF_DIFFERENT_COLORS_FOR_DARK, colors.colorThemeType != ColorThemeType.SINGLE)
Expand All @@ -45,6 +48,8 @@ object ApplicationPreferences {
setString(context, pref.shadingPreferenceName, colors.getTextShadingStored(pref).shading.themeName)
setInt(context, pref.colorPreferenceName, colors.getTextColorStored(pref).color)
}
setString(context, PREF_TEXT_SHADOW, settings.textShadow.value)

setShowDaysWithoutEvents(context, settings.showDaysWithoutEvents)
setShowDayHeaders(context, settings.showDayHeaders)
setDateFormat(context, InstanceSettings.PREF_DAY_HEADER_DATE_FORMAT, settings.dayHeaderDateFormat)
Expand Down Expand Up @@ -209,6 +214,16 @@ object ApplicationPreferences {
)
}

fun getTextShadow(context: Context): TextShadow {
return TextShadow.fromValue(
getString(
context,
PREF_TEXT_SHADOW,
TextShadow.NO_SHADOW.value
)
)
}

fun getHorizontalLineBelowDayHeader(context: Context?): Boolean {
return getBoolean(context, InstanceSettings.PREF_HORIZONTAL_LINE_BELOW_DAY_HEADER, false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.andstatus.todoagenda.util.MyClock
import org.andstatus.todoagenda.util.StringUtil
import org.andstatus.todoagenda.widget.Alignment
import org.andstatus.todoagenda.widget.EventEntryLayout
import org.andstatus.todoagenda.widget.TextShadow
import org.andstatus.todoagenda.widget.WidgetHeaderLayout
import org.joda.time.DateTime
import org.json.JSONException
Expand Down Expand Up @@ -67,6 +68,11 @@ class InstanceSettings(private val contextIn: Context?, val widgetId: Int, propo
// Colors
private var defaultColors: ThemeColors
private var darkColors: ThemeColors = ThemeColors.EMPTY
var textShadow: TextShadow = TextShadow.NO_SHADOW
private set

// ----------------------------------------------------------------------------------
// ,,,
var showEndTime = PREF_SHOW_END_TIME_DEFAULT
private set
var showLocation = PREF_SHOW_LOCATION_DEFAULT
Expand Down Expand Up @@ -165,6 +171,10 @@ class InstanceSettings(private val contextIn: Context?, val widgetId: Int, propo
PREF_DARK_THEME
)
) else ThemeColors.EMPTY
if (json.has(PREF_TEXT_SHADOW)) {
textShadow = TextShadow.fromValue(json.getString(PREF_TEXT_SHADOW))
}

if (json.has(PREF_SHOW_DAYS_WITHOUT_EVENTS)) {
showDaysWithoutEvents = json.getBoolean(PREF_SHOW_DAYS_WITHOUT_EVENTS)
}
Expand Down Expand Up @@ -326,6 +336,8 @@ class InstanceSettings(private val contextIn: Context?, val widgetId: Int, propo
)
}
}
textShadow = ApplicationPreferences.getTextShadow(context)

showDaysWithoutEvents = ApplicationPreferences.getShowDaysWithoutEvents(context)
showDayHeaders = ApplicationPreferences.getShowDayHeaders(context)
dayHeaderDateFormat = ApplicationPreferences.getDayHeaderDateFormat(context)
Expand Down Expand Up @@ -372,7 +384,11 @@ class InstanceSettings(private val contextIn: Context?, val widgetId: Int, propo
}

init {
widgetInstanceName = if (contextIn == null) "(empty)" else AllSettings.uniqueInstanceName(context, widgetId, proposedInstanceName)
widgetInstanceName = if (contextIn == null) "(empty)" else AllSettings.uniqueInstanceName(
context,
widgetId,
proposedInstanceName
)
defaultColors = if (contextIn == null) ThemeColors.EMPTY else ThemeColors(context, ColorThemeType.SINGLE)
}

Expand Down Expand Up @@ -419,6 +435,7 @@ class InstanceSettings(private val contextIn: Context?, val widgetId: Int, propo
if (!darkColors.isEmpty) {
json.put(PREF_DARK_THEME, darkColors.toJson(JSONObject()))
}
json.put(PREF_TEXT_SHADOW, textShadow.value)
json.put(PREF_SHOW_DAYS_WITHOUT_EVENTS, showDaysWithoutEvents)
json.put(PREF_SHOW_DAY_HEADERS, showDayHeaders)
json.put(PREF_DAY_HEADER_DATE_FORMAT, dayHeaderDateFormat.save())
Expand Down Expand Up @@ -634,6 +651,11 @@ ${toJson()}"""
const val PREF_MAXLINES_DETAILS_DEFAULT = 5
const val PREF_DARK_THEME = "darkTheme"

// ----------------------------------------------------------------------------------
// Color
const val PREF_TEXT_SHADOW = "textShadow"
val PREF_TEXT_SHADOW_DEFAULT = TextShadow.NO_SHADOW.name

// ----------------------------------------------------------------------------------
// Event details
const val PREF_SHOW_END_TIME = "showEndTime"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import org.andstatus.todoagenda.R
import org.andstatus.todoagenda.WidgetConfigurationActivity
import org.andstatus.todoagenda.prefs.ApplicationPreferences
import org.andstatus.todoagenda.prefs.InstanceSettings
import org.andstatus.todoagenda.prefs.InstanceSettings.Companion.PREF_TEXT_SHADOW
import org.andstatus.todoagenda.prefs.MyPreferenceFragment
import org.andstatus.todoagenda.widget.TextShadow
import org.andstatus.todoagenda.widget.TimeSection
import java.util.Arrays
import java.util.stream.Collectors
Expand All @@ -41,6 +43,7 @@ class ColorsPreferencesFragment : MyPreferenceFragment(), OnSharedPreferenceChan
removeUnavailablePreferences()
preferenceManager.sharedPreferences!!.registerOnSharedPreferenceChangeListener(this)
showTextSources()
showTextShadow()
}

private fun showTextSources() {
Expand Down Expand Up @@ -133,10 +136,17 @@ class ColorsPreferencesFragment : MyPreferenceFragment(), OnSharedPreferenceChan
}
}

private fun showTextShadow() {
findPreference<ListPreference>(PREF_TEXT_SHADOW)?.let { preference ->
TextShadow.fromValue(preference.value).let { textShadow ->
preference.summary = requireActivity().getString(textShadow.titleResId)
}
}
}

private fun showShadings() {
for (shadingPref in TextColorPref.entries) {
val preference = findPreference<ListPreference>(shadingPref.shadingPreferenceName)
if (preference != null) {
findPreference<ListPreference>(shadingPref.shadingPreferenceName)?.let { preference ->
val shading: Shading = Shading.fromThemeName(preference.value, shadingPref.defaultShading)
preference.summary = requireActivity().getString(shading.titleResId)
}
Expand Down Expand Up @@ -180,6 +190,7 @@ class ColorsPreferencesFragment : MyPreferenceFragment(), OnSharedPreferenceChan
else -> {
saveSettings()
showTextSources()
showTextShadow()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class DayHeaderVisualizer(context: Context, widgetId: Int) :
val entry = eventEntry as DayHeader
val rv = RemoteViews(
context.packageName,
if (horizontalLineBelowDayHeader) R.layout.day_header_separator_below else R.layout.day_header_separator_above
if (horizontalLineBelowDayHeader) WidgetLayout.DAY_HEADER_SEPARATOR_BELOW.shadowed(settings.textShadow)
else WidgetLayout.DAY_HEADER_SEPARATOR_ABOVE.shadowed(settings.textShadow)
)
rv.setInt(R.id.day_header_title_wrapper, "setGravity", alignment.gravity)
val textColorPref: TextColorPref = TextColorPref.forDayHeader(entry)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package org.andstatus.todoagenda.widget

import androidx.annotation.LayoutRes
import androidx.annotation.StringRes
import org.andstatus.todoagenda.R

/**
* @author [email protected]
*/
enum class EventEntryLayout(
@field:LayoutRes @param:LayoutRes val layoutId: Int,
val widgetLayout: WidgetLayout,
val value: String,
@field:StringRes val summaryResId: Int
) {
DEFAULT(R.layout.event_entry, "DEFAULT", R.string.default_multiline_layout),
ONE_LINE(R.layout.event_entry_one_line, "ONE_LINE", R.string.single_line_layout);
DEFAULT(WidgetLayout.EVENT_ENTRY_DEFAULT, "DEFAULT", R.string.default_multiline_layout),
ONE_LINE(WidgetLayout.EVENT_ENTRY_ONE_LINE, "ONE_LINE", R.string.single_line_layout);

companion object {
const val SPACE_PIPE_SPACE = " | "
Expand Down
11 changes: 5 additions & 6 deletions app/src/main/kotlin/org/andstatus/todoagenda/widget/LastEntry.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.andstatus.todoagenda.widget

import org.andstatus.todoagenda.R
import org.andstatus.todoagenda.prefs.InstanceSettings
import org.andstatus.todoagenda.prefs.OrderedEventSource
import org.andstatus.todoagenda.util.PermissionsUtil
Expand All @@ -13,11 +12,11 @@ class LastEntry(settings: InstanceSettings, val type: LastEntryType, date: DateT
override val source: OrderedEventSource
get() = OrderedEventSource.LAST_ENTRY

enum class LastEntryType(val layoutId: Int) {
NOT_LOADED(R.layout.item_not_loaded),
NO_PERMISSIONS(R.layout.item_no_permissions),
EMPTY(R.layout.item_empty_list),
LAST(R.layout.item_last)
enum class LastEntryType(val widgetLayout: WidgetLayout) {
NOT_LOADED(WidgetLayout.ITEM_NOT_LOADED),
NO_PERMISSIONS(WidgetLayout.ITEM_NO_PERMISSIONS),
EMPTY(WidgetLayout.ITEM_EMPTY_LIST),
LAST(WidgetLayout.ITEM_LAST)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class LastEntryVisualizer(context: Context, widgetId: Int) :
override fun getRemoteViews(eventEntry: WidgetEntry<*>, position: Int): RemoteViews {
val entry = eventEntry as LastEntry
Log.d(TAG, "lastEntry: " + entry.type)
val rv = RemoteViews(context.packageName, entry.type.layoutId)
val rv = RemoteViews(context.packageName, entry.type.widgetLayout.shadowed(settings.textShadow))
val viewId = R.id.event_entry
if (position < 0) {
rv.setOnClickPendingIntent(
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/kotlin/org/andstatus/todoagenda/widget/TextShadow.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.andstatus.todoagenda.widget

import androidx.annotation.StringRes
import org.andstatus.todoagenda.R

enum class TextShadow(val value: String,
@field:StringRes val titleResId: Int,
) {
NO_SHADOW("no", R.string.text_shadow_no_shadow),
DARK_SHADOW("dark", R.string.text_shadow_dark),
LIGHT_SHADOW("light", R.string.text_shadow_light);

companion object {
fun fromValue(value: String?): TextShadow {
for (item in entries) {
if (item.value == value) {
return item
}
}
return NO_SHADOW
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.andstatus.todoagenda.util.RemoteViewsUtil

abstract class WidgetEntryVisualizer<T : WidgetEntry<T>>(protected val eventProvider: EventProvider) {
open fun getRemoteViews(entry: WidgetEntry<*>, position: Int): RemoteViews {
val rv = RemoteViews(context.packageName, settings.eventEntryLayout.layoutId)
val rv = RemoteViews(context.packageName, settings.eventEntryLayout.widgetLayout.shadowed(settings.textShadow))
setTitle(entry, rv)
setDetails(entry, rv)
setDate(entry, rv)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package org.andstatus.todoagenda.widget

import androidx.annotation.LayoutRes
import androidx.annotation.StringRes
import org.andstatus.todoagenda.R

/**
* @author [email protected]
*/
enum class WidgetHeaderLayout(
@field:LayoutRes @param:LayoutRes val layoutId: Int,
val widgetLayout: WidgetLayout?,
val value: String,
@field:StringRes @param:StringRes val summaryResId: Int
) {
ONE_ROW(R.layout.widget_header_one_row, "ONE_ROW", R.string.single_line_layout),
TWO_ROWS(R.layout.widget_header_two_rows, "TWO_ROWS", R.string.two_rows_layout),
HIDDEN(0, "HIDDEN", R.string.hidden);
ONE_ROW(WidgetLayout.WIDGET_HEADER_ONE_ROW, "ONE_ROW", R.string.single_line_layout),
TWO_ROWS(WidgetLayout.WIDGET_HEADER_TWO_ROWS, "TWO_ROWS", R.string.two_rows_layout),
HIDDEN(null, "HIDDEN", R.string.hidden);

companion object {
var defaultValue = ONE_ROW
Expand Down
Loading

0 comments on commit 748e3c6

Please sign in to comment.