use some helper functions when setting up widget elements

This commit is contained in:
tibbi 2017-09-23 11:52:45 +02:00
parent 72cd60cb3a
commit 33e27164e3
3 changed files with 26 additions and 20 deletions

View File

@ -44,7 +44,7 @@ ext {
}
dependencies {
compile 'com.simplemobiletools:commons:2.27.10'
compile 'com.simplemobiletools:commons:2.28.4'
compile 'joda-time:joda-time:2.9.1'
compile 'com.facebook.stetho:stetho:1.4.1'
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'

View File

@ -16,6 +16,8 @@ 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.setBackgroundColor
import com.simplemobiletools.commons.extensions.setTextSize
import org.joda.time.DateTime
class MyWidgetListProvider : AppWidgetProvider() {
@ -43,15 +45,15 @@ class MyWidgetListProvider : AppWidgetProvider() {
mWidgetManager = AppWidgetManager.getInstance(context)
mRemoteViews = RemoteViews(context.packageName, R.layout.widget_event_list)
mIntent = Intent(context, MyWidgetListProvider::class.java)
mRemoteViews = RemoteViews(context.packageName, R.layout.widget_event_list).apply {
setBackgroundColor(R.id.widget_event_list_holder, context.config.widgetBgColor)
setTextColor(R.id.widget_event_list_empty, mTextColor)
setTextSize(R.id.widget_event_list_empty, context.config.getFontSize())
mRemoteViews.setInt(R.id.widget_event_list_holder, "setBackgroundColor", context.config.widgetBgColor)
mRemoteViews.setInt(R.id.widget_event_list_empty, "setTextColor", mTextColor)
mRemoteViews.setFloat(R.id.widget_event_list_empty, "setTextSize", context.config.getFontSize())
mRemoteViews.setInt(R.id.widget_event_list_today, "setTextColor", mTextColor)
mRemoteViews.setFloat(R.id.widget_event_list_today, "setTextSize", context.config.getFontSize() + 3)
setTextColor(R.id.widget_event_list_today, mTextColor)
setTextSize(R.id.widget_event_list_today, context.config.getFontSize() + 3)
}
val now = (System.currentTimeMillis() / 1000).toInt()
val todayCode = Formatter.getDayCodeFromTS(now)

View File

@ -20,6 +20,8 @@ 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.setBackgroundColor
import com.simplemobiletools.commons.extensions.setTextSize
import org.joda.time.DateTime
class MyWidgetMonthlyProvider : AppWidgetProvider(), MonthlyCalendar {
@ -65,7 +67,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider(), MonthlyCalendar {
mLargerFontSize = getFontSize() + 3f
mRemoteViews = RemoteViews(mContext.packageName, R.layout.fragment_month_widget)
mRemoteViews?.setInt(R.id.calendar_holder, "setBackgroundColor", widgetBgColor)
mRemoteViews?.setBackgroundColor(R.id.calendar_holder, widgetBgColor)
}
mIntent = Intent(mContext, MyWidgetMonthlyProvider::class.java)
@ -139,16 +141,18 @@ class MyWidgetMonthlyProvider : AppWidgetProvider(), MonthlyCalendar {
val displayWeekNumbers = mContext.config.displayWeekNumbers
val len = days.size
val packageName = mContext.packageName
mRemoteViews?.setInt(R.id.week_num, "setTextColor", mTextColor)
mRemoteViews?.setFloat(R.id.week_num, "setTextSize", mSmallerFontSize)
mRemoteViews?.setViewVisibility(R.id.week_num, if (displayWeekNumbers) View.VISIBLE else View.GONE)
mRemoteViews?.apply {
setTextColor(R.id.week_num, mTextColor)
setTextSize(R.id.week_num, mSmallerFontSize)
setViewVisibility(R.id.week_num, if (displayWeekNumbers) View.VISIBLE else View.GONE)
}
for (i in 0..5) {
val id = mRes.getIdentifier("week_num_$i", "id", packageName)
mRemoteViews?.apply {
setTextViewText(id, days[i * 7 + 3].weekOfYear.toString() + ":")
setInt(id, "setTextColor", mTextColor)
setFloat(id, "setTextSize", mSmallerFontSize)
setTextColor(id, mTextColor)
setTextSize(id, mSmallerFontSize)
setViewVisibility(id, if (displayWeekNumbers) View.VISIBLE else View.GONE)
}
}
@ -182,8 +186,8 @@ class MyWidgetMonthlyProvider : AppWidgetProvider(), MonthlyCalendar {
mRemoteViews?.setViewVisibility(circleId, View.GONE)
}
mRemoteViews?.setInt(id, "setTextColor", curTextColor)
mRemoteViews?.setFloat(id, "setTextSize", mMediumFontSize)
mRemoteViews?.setTextColor(id, curTextColor)
mRemoteViews?.setTextSize(id, mMediumFontSize)
setupDayOpenIntent(id, day.code)
}
}
@ -198,8 +202,8 @@ class MyWidgetMonthlyProvider : AppWidgetProvider(), MonthlyCalendar {
}
private fun updateTopViews() {
mRemoteViews?.setInt(R.id.top_value, "setTextColor", mTextColor)
mRemoteViews?.setFloat(R.id.top_value, "setTextSize", mLargerFontSize)
mRemoteViews?.setTextColor(R.id.top_value, mTextColor)
mRemoteViews?.setTextSize(R.id.top_value, mLargerFontSize)
var bmp = getColoredIcon(mContext, mTextColor, R.drawable.ic_pointer_left)
mRemoteViews?.setImageViewBitmap(R.id.top_left_arrow, bmp)
@ -230,8 +234,8 @@ class MyWidgetMonthlyProvider : AppWidgetProvider(), MonthlyCalendar {
val letters = letterIDs
for (i in 0..6) {
val id = mRes.getIdentifier("label_$i", "id", packageName)
mRemoteViews?.setInt(id, "setTextColor", mTextColor)
mRemoteViews?.setFloat(id, "setTextSize", mSmallerFontSize)
mRemoteViews?.setTextColor(id, mTextColor)
mRemoteViews?.setTextSize(id, mSmallerFontSize)
var index = i
if (!mSundayFirst)