make a textview extension more reusable

This commit is contained in:
tibbi 2017-10-08 16:30:32 +02:00
parent 699f4d7780
commit 28143d0eca
4 changed files with 6 additions and 7 deletions

View File

@ -299,7 +299,7 @@ fun Context.addDayNumber(rawTextColor: Int, day: DayMonthly, linearLayout: Linea
}
private fun addTodaysBackground(textView: TextView, res: Resources, dayLabelHeight: Int, mPrimaryColor: Int) =
textView.addResizedBackgroundDrawable(res, dayLabelHeight, mPrimaryColor)
textView.addResizedBackgroundDrawable(res, dayLabelHeight, mPrimaryColor, R.drawable.monthly_today_circle)
fun Context.addDayEvents(day: DayMonthly, linearLayout: LinearLayout, res: Resources, dividerMargin: Int) {
day.dayEvents.forEach {

View File

@ -5,10 +5,9 @@ import android.graphics.Bitmap
import android.graphics.PorterDuff
import android.graphics.drawable.BitmapDrawable
import android.widget.TextView
import com.simplemobiletools.calendar.R
fun TextView.addResizedBackgroundDrawable(res: Resources, drawableHeight: Int, primaryColor: Int) {
val baseDrawable = res.getDrawable(R.drawable.monthly_today_circle)
fun TextView.addResizedBackgroundDrawable(res: Resources, drawableHeight: Int, primaryColor: Int, drawableId: Int) {
val baseDrawable = res.getDrawable(drawableId)
val bitmap = (baseDrawable as BitmapDrawable).bitmap
val scaledDrawable = BitmapDrawable(res, Bitmap.createScaledBitmap(bitmap, drawableHeight, drawableHeight, true))
scaledDrawable.mutate().setColorFilter(primaryColor, PorterDuff.Mode.SRC_IN)

View File

@ -170,7 +170,7 @@ class MonthFragment : Fragment(), MonthlyCalendar {
for (i in 0..5) {
(mHolder.findViewById(mRes.getIdentifier("week_num_$i", "id", mPackageName)) as TextView).apply {
text = "${days[i * 7 + 3].weekOfYear}:"
text = "${days[i * 7 + 3].weekOfYear}:" // fourth day of the week matters
setTextColor(mTextColor)
beVisibleIf(displayWeekNumbers)
}

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<com.simplemobiletools.commons.views.MyTextView
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/day_monthly_number_id"
@ -11,5 +11,5 @@
android:maxLines="1"
android:paddingLeft="@dimen/tiny_margin"
android:paddingRight="@dimen/tiny_margin"
android:textSize="@dimen/small_text_size"
android:textSize="@dimen/day_monthly_text_size"
tools:text="1"/>