diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MyWidgetListProvider.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MyWidgetListProvider.kt index 50a45c518..9deb3f86b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MyWidgetListProvider.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MyWidgetListProvider.kt @@ -25,10 +25,10 @@ class MyWidgetListProvider : AppWidgetProvider() { private val LAUNCH_TODAY = "launch_today" override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) { - initVariables(context) + performUpdate(context) } - private fun initVariables(context: Context) { + private fun performUpdate(context: Context) { val fontSize = context.config.getFontSize() val textColor = context.config.widgetTextColor diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MyWidgetMonthlyProvider.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MyWidgetMonthlyProvider.kt index 42d42c89c..a7d84982e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MyWidgetMonthlyProvider.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MyWidgetMonthlyProvider.kt @@ -6,7 +6,7 @@ import android.appwidget.AppWidgetProvider import android.content.ComponentName import android.content.Context import android.content.Intent -import android.graphics.* +import android.content.res.Resources import android.view.View import android.widget.RemoteViews import com.simplemobiletools.calendar.R @@ -34,6 +34,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() { private fun performUpdate(context: Context) { val largerFontSize = context.config.getFontSize() + 3f val textColor = context.config.widgetTextColor + val resources = context.resources val appWidgetManager = AppWidgetManager.getInstance(context) appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach { @@ -43,20 +44,20 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() { views.setTextColor(R.id.top_value, textColor) views.setTextSize(R.id.top_value, largerFontSize) - var bmp = getColoredIcon(context, textColor, R.drawable.ic_pointer_left) + var bmp = resources.getColoredBitmap(R.drawable.ic_pointer_left, textColor) views.setImageViewBitmap(R.id.top_left_arrow, bmp) - bmp = getColoredIcon(context, textColor, R.drawable.ic_pointer_right) + bmp = resources.getColoredBitmap(R.drawable.ic_pointer_right, textColor) views.setImageViewBitmap(R.id.top_right_arrow, bmp) - bmp = getColoredIcon(context, textColor, R.drawable.ic_plus) + bmp = resources.getColoredBitmap(R.drawable.ic_plus, textColor) views.setImageViewBitmap(R.id.top_new_event, bmp) setupIntent(context, views, PREV, R.id.top_left_arrow) setupIntent(context, views, NEXT, R.id.top_right_arrow) setupIntent(context, views, NEW_EVENT, R.id.top_new_event) setupAppOpenIntent(context, views, R.id.top_value) - updateDayLabels(context, views, textColor) + updateDayLabels(context, views, resources, textColor) appWidgetManager.updateAppWidget(it, views) MonthlyCalendarImpl(monthlyCalendar, context).getMonth(targetDate) @@ -132,14 +133,10 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() { val weakTextColor = textColor.adjustAlpha(LOW_ALPHA) for (i in 0 until len) { val day = days[i] - var currTextColor = if (day.isThisMonth) textColor else weakTextColor - val primaryColor = context.config.primaryColor - if (day.isToday) - currTextColor = primaryColor.getContrastColor() - + val currTextColor = if (day.isThisMonth) textColor else weakTextColor val id = res.getIdentifier("day_$i", "id", packageName) views.removeAllViews(id) - addDayNumber(context, views, day, currTextColor, id, primaryColor) + addDayNumber(context, views, day, currTextColor, id) setupDayOpenIntent(context, views, id, day.code) day.dayEvents.forEach { @@ -162,15 +159,16 @@ 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) { val newRemoteView = RemoteViews(context.packageName, R.layout.day_monthly_number_view).apply { 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) if (day.isToday) { - setViewPadding(R.id.day_monthly_number_id, 10, 0, 10, 0) - setBackgroundColor(R.id.day_monthly_number_id, primaryColor) + setBackgroundColor(R.id.day_monthly_number_id, textColor) + setTextColor(R.id.day_monthly_number_id, textColor.getContrastColor()) + } else { + setTextColor(R.id.day_monthly_number_id, textColor) } } views.addView(id, newRemoteView) @@ -188,34 +186,22 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() { } } - private fun updateDayLabels(context: Context, views: RemoteViews, textColor: Int) { + private fun updateDayLabels(context: Context, views: RemoteViews, resources: Resources, textColor: Int) { val sundayFirst = context.config.isSundayFirst val smallerFontSize = context.config.getFontSize() - val res = context.resources val packageName = context.packageName val letters = letterIDs for (i in 0..6) { - val id = res.getIdentifier("label_$i", "id", packageName) + val id = resources.getIdentifier("label_$i", "id", packageName) views.setTextColor(id, textColor) views.setTextSize(id, smallerFontSize) var index = i - if (!sundayFirst) + if (!sundayFirst) { index = (index + 1) % letters.size + } - views.setText(id, res.getString(letters[index])) + views.setText(id, resources.getString(letters[index])) } } - - private fun getColoredIcon(context: Context, newTextColor: Int, id: Int): Bitmap { - val options = BitmapFactory.Options() - options.inMutable = true - val bmp = BitmapFactory.decodeResource(context.resources, id, options) - val paint = Paint() - val filter = LightingColorFilter(newTextColor, 1) - paint.colorFilter = filter - val canvas = Canvas(bmp) - canvas.drawBitmap(bmp, 0f, 0f, paint) - return bmp - } }