applying some remoteViews extensions
This commit is contained in:
parent
1103c732c9
commit
a5d3e398df
|
@ -16,7 +16,9 @@ import com.simplemobiletools.calendar.helpers.Formatter
|
|||
import com.simplemobiletools.calendar.models.ListEvent
|
||||
import com.simplemobiletools.calendar.models.ListItem
|
||||
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 java.util.*
|
||||
|
||||
|
@ -38,10 +40,10 @@ class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteV
|
|||
if (type == ITEM_EVENT) {
|
||||
val item = events[position] as ListEvent
|
||||
remoteView = RemoteViews(context.packageName, R.layout.event_list_item_widget).apply {
|
||||
setTextViewText(R.id.event_item_title, item.title)
|
||||
setTextViewText(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))
|
||||
setImageViewBitmap(R.id.event_item_color, context.resources.getColoredIcon(item.color, R.drawable.monthly_event_dot))
|
||||
setText(R.id.event_item_title, item.title)
|
||||
setText(R.id.event_item_description, if (replaceDescription) item.location else item.description)
|
||||
setText(R.id.event_item_start, if (item.isAllDay) allDayString else Formatter.getTimeFromTS(context, item.startTS))
|
||||
setImageViewBitmap(R.id.event_item_color, context.resources.getColoredBitmap(R.drawable.monthly_event_dot, item.color))
|
||||
|
||||
if (item.startTS == item.endTS) {
|
||||
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) {
|
||||
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)
|
||||
setInt(R.id.event_item_description, "setTextColor", textColor)
|
||||
setInt(R.id.event_item_start, "setTextColor", textColor)
|
||||
setInt(R.id.event_item_end, "setTextColor", textColor)
|
||||
setTextColor(R.id.event_item_title, textColor)
|
||||
setTextColor(R.id.event_item_description, textColor)
|
||||
setTextColor(R.id.event_item_start, textColor)
|
||||
setTextColor(R.id.event_item_end, textColor)
|
||||
|
||||
setFloat(R.id.event_item_title, "setTextSize", mediumFontSize)
|
||||
setFloat(R.id.event_item_description, "setTextSize", mediumFontSize)
|
||||
setFloat(R.id.event_item_start, "setTextSize", mediumFontSize)
|
||||
setFloat(R.id.event_item_end, "setTextSize", mediumFontSize)
|
||||
setTextSize(R.id.event_item_title, mediumFontSize)
|
||||
setTextSize(R.id.event_item_description, mediumFontSize)
|
||||
setTextSize(R.id.event_item_start, mediumFontSize)
|
||||
setTextSize(R.id.event_item_end, mediumFontSize)
|
||||
|
||||
Intent().apply {
|
||||
putExtra(EVENT_ID, item.id)
|
||||
|
@ -82,9 +84,9 @@ class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteV
|
|||
} else {
|
||||
val item = events[position] as ListSection
|
||||
remoteView = RemoteViews(context.packageName, R.layout.event_list_section_widget).apply {
|
||||
setInt(R.id.event_item_title, "setTextColor", textColor)
|
||||
setFloat(R.id.event_item_title, "setTextSize", mediumFontSize)
|
||||
setTextViewText(R.id.event_item_title, item.title)
|
||||
setTextColor(R.id.event_item_title, textColor)
|
||||
setTextSize(R.id.event_item_title, mediumFontSize)
|
||||
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.launchNewEventIntent
|
||||
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.setText
|
||||
import com.simplemobiletools.commons.extensions.setTextSize
|
||||
import org.joda.time.DateTime
|
||||
|
||||
|
@ -45,9 +46,9 @@ class MyWidgetListProvider : AppWidgetProvider() {
|
|||
val now = (System.currentTimeMillis() / 1000).toInt()
|
||||
val todayCode = Formatter.getDayCodeFromTS(now)
|
||||
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, 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.interfaces.MonthlyCalendar
|
||||
import com.simplemobiletools.calendar.models.DayMonthly
|
||||
import com.simplemobiletools.commons.extensions.adjustAlpha
|
||||
import com.simplemobiletools.commons.extensions.getContrastColor
|
||||
import com.simplemobiletools.commons.extensions.setBackgroundColor
|
||||
import com.simplemobiletools.commons.extensions.setTextSize
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import org.joda.time.DateTime
|
||||
|
||||
class MyWidgetMonthlyProvider : AppWidgetProvider() {
|
||||
|
@ -125,7 +122,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
|
|||
for (i in 0..5) {
|
||||
val id = res.getIdentifier("week_num_$i", "id", packageName)
|
||||
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)
|
||||
setTextSize(id, smallerFontSize)
|
||||
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 {
|
||||
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)
|
||||
setTextSize(R.id.day_monthly_event_id, smallerFontSize - 3f)
|
||||
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) {
|
||||
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)
|
||||
setTextSize(R.id.day_monthly_number_id, context.config.getFontSize() - 3f)
|
||||
|
||||
|
@ -184,7 +181,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
|
|||
val appWidgetManager = AppWidgetManager.getInstance(context)
|
||||
appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach {
|
||||
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)
|
||||
appWidgetManager.updateAppWidget(it, views)
|
||||
}
|
||||
|
@ -206,7 +203,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
|
|||
if (!sundayFirst)
|
||||
index = (index + 1) % letters.size
|
||||
|
||||
views.setTextViewText(id, res.getString(letters[index]))
|
||||
views.setText(id, res.getString(letters[index]))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue