applying some remoteViews extensions

This commit is contained in:
tibbi 2017-11-06 23:16:45 +01:00
parent 1103c732c9
commit a5d3e398df
3 changed files with 29 additions and 29 deletions
app/src/main/kotlin/com/simplemobiletools/calendar

@ -16,7 +16,9 @@ import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.models.ListEvent import com.simplemobiletools.calendar.models.ListEvent
import com.simplemobiletools.calendar.models.ListItem import com.simplemobiletools.calendar.models.ListItem
import com.simplemobiletools.calendar.models.ListSection import com.simplemobiletools.calendar.models.ListSection
import com.simplemobiletools.commons.extensions.getColoredIcon import com.simplemobiletools.commons.extensions.getColoredBitmap
import com.simplemobiletools.commons.extensions.setText
import com.simplemobiletools.commons.extensions.setTextSize
import org.joda.time.DateTime import org.joda.time.DateTime
import java.util.* import java.util.*
@ -38,10 +40,10 @@ class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteV
if (type == ITEM_EVENT) { if (type == ITEM_EVENT) {
val item = events[position] as ListEvent val item = events[position] as ListEvent
remoteView = RemoteViews(context.packageName, R.layout.event_list_item_widget).apply { remoteView = RemoteViews(context.packageName, R.layout.event_list_item_widget).apply {
setTextViewText(R.id.event_item_title, item.title) setText(R.id.event_item_title, item.title)
setTextViewText(R.id.event_item_description, if (replaceDescription) item.location else item.description) setText(R.id.event_item_description, if (replaceDescription) item.location else item.description)
setTextViewText(R.id.event_item_start, if (item.isAllDay) allDayString else Formatter.getTimeFromTS(context, item.startTS)) setText(R.id.event_item_start, if (item.isAllDay) allDayString else Formatter.getTimeFromTS(context, item.startTS))
setImageViewBitmap(R.id.event_item_color, context.resources.getColoredIcon(item.color, R.drawable.monthly_event_dot)) setImageViewBitmap(R.id.event_item_color, context.resources.getColoredBitmap(R.drawable.monthly_event_dot, item.color))
if (item.startTS == item.endTS) { if (item.startTS == item.endTS) {
setViewVisibility(R.id.event_item_end, View.INVISIBLE) setViewVisibility(R.id.event_item_end, View.INVISIBLE)
@ -60,18 +62,18 @@ class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteV
} else if (item.isAllDay) { } else if (item.isAllDay) {
setViewVisibility(R.id.event_item_end, View.INVISIBLE) setViewVisibility(R.id.event_item_end, View.INVISIBLE)
} }
setTextViewText(R.id.event_item_end, endString) setText(R.id.event_item_end, endString)
} }
setInt(R.id.event_item_title, "setTextColor", textColor) setTextColor(R.id.event_item_title, textColor)
setInt(R.id.event_item_description, "setTextColor", textColor) setTextColor(R.id.event_item_description, textColor)
setInt(R.id.event_item_start, "setTextColor", textColor) setTextColor(R.id.event_item_start, textColor)
setInt(R.id.event_item_end, "setTextColor", textColor) setTextColor(R.id.event_item_end, textColor)
setFloat(R.id.event_item_title, "setTextSize", mediumFontSize) setTextSize(R.id.event_item_title, mediumFontSize)
setFloat(R.id.event_item_description, "setTextSize", mediumFontSize) setTextSize(R.id.event_item_description, mediumFontSize)
setFloat(R.id.event_item_start, "setTextSize", mediumFontSize) setTextSize(R.id.event_item_start, mediumFontSize)
setFloat(R.id.event_item_end, "setTextSize", mediumFontSize) setTextSize(R.id.event_item_end, mediumFontSize)
Intent().apply { Intent().apply {
putExtra(EVENT_ID, item.id) putExtra(EVENT_ID, item.id)
@ -82,9 +84,9 @@ class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteV
} else { } else {
val item = events[position] as ListSection val item = events[position] as ListSection
remoteView = RemoteViews(context.packageName, R.layout.event_list_section_widget).apply { remoteView = RemoteViews(context.packageName, R.layout.event_list_section_widget).apply {
setInt(R.id.event_item_title, "setTextColor", textColor) setTextColor(R.id.event_item_title, textColor)
setFloat(R.id.event_item_title, "setTextSize", mediumFontSize) setTextSize(R.id.event_item_title, mediumFontSize)
setTextViewText(R.id.event_item_title, item.title) setText(R.id.event_item_title, item.title)
} }
} }

@ -14,8 +14,9 @@ import com.simplemobiletools.calendar.activities.SplashActivity
import com.simplemobiletools.calendar.extensions.config import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.extensions.launchNewEventIntent import com.simplemobiletools.calendar.extensions.launchNewEventIntent
import com.simplemobiletools.calendar.services.WidgetService import com.simplemobiletools.calendar.services.WidgetService
import com.simplemobiletools.commons.extensions.getColoredIcon import com.simplemobiletools.commons.extensions.getColoredBitmap
import com.simplemobiletools.commons.extensions.setBackgroundColor import com.simplemobiletools.commons.extensions.setBackgroundColor
import com.simplemobiletools.commons.extensions.setText
import com.simplemobiletools.commons.extensions.setTextSize import com.simplemobiletools.commons.extensions.setTextSize
import org.joda.time.DateTime import org.joda.time.DateTime
@ -45,9 +46,9 @@ class MyWidgetListProvider : AppWidgetProvider() {
val now = (System.currentTimeMillis() / 1000).toInt() val now = (System.currentTimeMillis() / 1000).toInt()
val todayCode = Formatter.getDayCodeFromTS(now) val todayCode = Formatter.getDayCodeFromTS(now)
val todayText = Formatter.getDayTitle(context, todayCode) val todayText = Formatter.getDayTitle(context, todayCode)
views.setTextViewText(R.id.widget_event_list_today, todayText) views.setText(R.id.widget_event_list_today, todayText)
views.setImageViewBitmap(R.id.widget_event_new_event, context.resources.getColoredIcon(textColor, R.drawable.ic_plus)) views.setImageViewBitmap(R.id.widget_event_new_event, context.resources.getColoredBitmap(R.drawable.ic_plus, textColor))
setupIntent(context, views, NEW_EVENT, R.id.widget_event_new_event) setupIntent(context, views, NEW_EVENT, R.id.widget_event_new_event)
setupIntent(context, views, LAUNCH_TODAY, R.id.widget_event_list_today) setupIntent(context, views, LAUNCH_TODAY, R.id.widget_event_list_today)

@ -15,10 +15,7 @@ import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.extensions.launchNewEventIntent import com.simplemobiletools.calendar.extensions.launchNewEventIntent
import com.simplemobiletools.calendar.interfaces.MonthlyCalendar import com.simplemobiletools.calendar.interfaces.MonthlyCalendar
import com.simplemobiletools.calendar.models.DayMonthly import com.simplemobiletools.calendar.models.DayMonthly
import com.simplemobiletools.commons.extensions.adjustAlpha import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.extensions.getContrastColor
import com.simplemobiletools.commons.extensions.setBackgroundColor
import com.simplemobiletools.commons.extensions.setTextSize
import org.joda.time.DateTime import org.joda.time.DateTime
class MyWidgetMonthlyProvider : AppWidgetProvider() { class MyWidgetMonthlyProvider : AppWidgetProvider() {
@ -125,7 +122,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
for (i in 0..5) { for (i in 0..5) {
val id = res.getIdentifier("week_num_$i", "id", packageName) val id = res.getIdentifier("week_num_$i", "id", packageName)
views.apply { views.apply {
setTextViewText(id, "${days[i * 7 + 3].weekOfYear}:") // fourth day of the week matters at determining week of the year setText(id, "${days[i * 7 + 3].weekOfYear}:") // fourth day of the week matters at determining week of the year
setTextColor(id, textColor) setTextColor(id, textColor)
setTextSize(id, smallerFontSize) setTextSize(id, smallerFontSize)
setViewVisibility(id, if (displayWeekNumbers) View.VISIBLE else View.GONE) setViewVisibility(id, if (displayWeekNumbers) View.VISIBLE else View.GONE)
@ -155,7 +152,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
} }
val newRemoteView = RemoteViews(packageName, R.layout.day_monthly_event_view).apply { val newRemoteView = RemoteViews(packageName, R.layout.day_monthly_event_view).apply {
setTextViewText(R.id.day_monthly_event_id, it.title.replace(" ", "\u00A0")) setText(R.id.day_monthly_event_id, it.title.replace(" ", "\u00A0"))
setTextColor(R.id.day_monthly_event_id, eventTextColor) setTextColor(R.id.day_monthly_event_id, eventTextColor)
setTextSize(R.id.day_monthly_event_id, smallerFontSize - 3f) setTextSize(R.id.day_monthly_event_id, smallerFontSize - 3f)
setBackgroundColor(R.id.day_monthly_event_id, backgroundColor) setBackgroundColor(R.id.day_monthly_event_id, backgroundColor)
@ -167,7 +164,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
private fun addDayNumber(context: Context, views: RemoteViews, day: DayMonthly, textColor: Int, id: Int, primaryColor: Int) { private fun addDayNumber(context: Context, views: RemoteViews, day: DayMonthly, textColor: Int, id: Int, primaryColor: Int) {
val newRemoteView = RemoteViews(context.packageName, R.layout.day_monthly_number_view).apply { val newRemoteView = RemoteViews(context.packageName, R.layout.day_monthly_number_view).apply {
setTextViewText(R.id.day_monthly_number_id, day.value.toString()) setText(R.id.day_monthly_number_id, day.value.toString())
setTextColor(R.id.day_monthly_number_id, textColor) setTextColor(R.id.day_monthly_number_id, textColor)
setTextSize(R.id.day_monthly_number_id, context.config.getFontSize() - 3f) setTextSize(R.id.day_monthly_number_id, context.config.getFontSize() - 3f)
@ -184,7 +181,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
val appWidgetManager = AppWidgetManager.getInstance(context) val appWidgetManager = AppWidgetManager.getInstance(context)
appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach { appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach {
val views = RemoteViews(context.packageName, R.layout.fragment_month_widget) val views = RemoteViews(context.packageName, R.layout.fragment_month_widget)
views.setTextViewText(R.id.top_value, month) views.setText(R.id.top_value, month)
updateDays(context, views, days) updateDays(context, views, days)
appWidgetManager.updateAppWidget(it, views) appWidgetManager.updateAppWidget(it, views)
} }
@ -206,7 +203,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
if (!sundayFirst) if (!sundayFirst)
index = (index + 1) % letters.size index = (index + 1) % letters.size
views.setTextViewText(id, res.getString(letters[index])) views.setText(id, res.getString(letters[index]))
} }
} }