start rewriting the monthly view into a custom view for better performance

This commit is contained in:
tibbi 2018-03-24 11:06:22 +01:00
parent 72645d1fcb
commit ba07fbcfd3
5 changed files with 65 additions and 493 deletions

View File

@ -152,7 +152,7 @@ class WidgetMonthlyConfigureActivity : SimpleActivity(), MonthlyCalendar {
}
private fun updateDays() {
val len = mDays!!.size
/*val len = mDays!!.size
if (applicationContext.config.displayWeekNumbers) {
week_num.setTextColor(mTextColor)
@ -176,7 +176,7 @@ class WidgetMonthlyConfigureActivity : SimpleActivity(), MonthlyCalendar {
context.addDayNumber(mTextColor, day, this, dayLabelHeight) { dayLabelHeight = it }
context.addDayEvents(day, this, mRes, dividerMargin)
}
}
}*/
}
private val bgSeekbarChangeListener = object : SeekBar.OnSeekBarChangeListener {

View File

@ -9,13 +9,9 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.DatePicker
import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.MainActivity
import com.simplemobiletools.calendar.extensions.addDayEvents
import com.simplemobiletools.calendar.extensions.addDayNumber
import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.helpers.Config
import com.simplemobiletools.calendar.helpers.DAY_CODE
@ -24,8 +20,10 @@ import com.simplemobiletools.calendar.helpers.MonthlyCalendarImpl
import com.simplemobiletools.calendar.interfaces.MonthlyCalendar
import com.simplemobiletools.calendar.interfaces.NavigationListener
import com.simplemobiletools.calendar.models.DayMonthly
import com.simplemobiletools.commons.extensions.*
import kotlinx.android.synthetic.main.first_row.*
import com.simplemobiletools.commons.extensions.applyColorFilter
import com.simplemobiletools.commons.extensions.beGone
import com.simplemobiletools.commons.extensions.getDialogTheme
import com.simplemobiletools.commons.extensions.setupDialogStuff
import kotlinx.android.synthetic.main.fragment_month.view.*
import kotlinx.android.synthetic.main.top_navigation.view.*
import org.joda.time.DateTime
@ -169,7 +167,7 @@ class MonthFragment : Fragment(), MonthlyCalendar {
}
private fun updateDays(days: List<DayMonthly>) {
val displayWeekNumbers = mConfig.displayWeekNumbers
/*val displayWeekNumbers = mConfig.displayWeekNumbers
val len = days.size
if (week_num == null)
@ -198,6 +196,6 @@ class MonthFragment : Fragment(), MonthlyCalendar {
context.addDayNumber(mTextColor, day, this, mDayLabelHeight) { mDayLabelHeight = it }
context.addDayEvents(day, this, mRes, dividerMargin)
}
}
}*/
}
}

View File

@ -0,0 +1,51 @@
package com.simplemobiletools.calendar.views
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.extensions.config
// used in the Monthly view fragment, 1 view per screen
class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(context, attrs, defStyle) {
private var paint: Paint
private var dayWidth = 0f
private var dayHeight = 0f
private var textColor = 0
private var days = 42
constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0)
init {
textColor = context.config.textColor
paint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
color = textColor
textSize = resources.getDimensionPixelSize(R.dimen.normal_text_size).toFloat()
textAlign = Paint.Align.CENTER
}
}
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
if (dayWidth == 0f) {
dayWidth = (canvas.width / 7).toFloat()
}
if (dayHeight == 0f) {
dayHeight = (canvas.height / 6).toFloat()
}
var curId = 1
for (y in 0..5) {
for (x in 1..7) {
if (curId in 1..days) {
canvas.drawText(curId.toString(), x * dayWidth - dayWidth / 2, y * dayHeight + paint.textSize, paint)
}
curId++
}
}
}
}

View File

@ -14,6 +14,7 @@ import com.simplemobiletools.commons.extensions.adjustAlpha
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
import java.util.*
// used for displaying months at Yearly view
class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(context, attrs, defStyle) {
private var paint: Paint
private var todayCirclePaint: Paint

View File

@ -17,489 +17,11 @@
android:layout_below="@+id/top_value"
tools:ignore="UnknownIdInLayout"/>
<LinearLayout
android:id="@+id/table_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
<com.simplemobiletools.calendar.views.MonthView
android:id="@+id/month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/first_row"
android:gravity="center"
android:orientation="vertical">
android:layout_centerInParent="true"/>
<LinearLayout
android:id="@+id/month_line_holder_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="horizontal">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/week_num_0"
style="@style/WeekNumberStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:visibility="gone"/>
<LinearLayout
android:id="@+id/day_0"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_4"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_5"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_6"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
</LinearLayout>
<LinearLayout
android:id="@+id/month_line_holder_2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="horizontal">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/week_num_1"
style="@style/WeekNumberStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:visibility="gone"/>
<LinearLayout
android:id="@+id/day_7"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_8"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_9"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_10"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_11"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_12"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_13"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
</LinearLayout>
<LinearLayout
android:id="@+id/month_line_holder_3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="horizontal">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/week_num_2"
style="@style/WeekNumberStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:visibility="gone"/>
<LinearLayout
android:id="@+id/day_14"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_15"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_16"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_17"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_18"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_19"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_20"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
</LinearLayout>
<LinearLayout
android:id="@+id/month_line_holder_4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="horizontal">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/week_num_3"
style="@style/WeekNumberStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:visibility="gone"/>
<LinearLayout
android:id="@+id/day_21"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_22"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_23"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_24"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_25"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_26"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_27"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
</LinearLayout>
<LinearLayout
android:id="@+id/month_line_holder_5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="horizontal">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/week_num_4"
style="@style/WeekNumberStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:visibility="gone"/>
<LinearLayout
android:id="@+id/day_28"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_29"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_30"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_31"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_32"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_33"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_34"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
</LinearLayout>
<LinearLayout
android:id="@+id/month_line_holder_6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="horizontal">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/week_num_5"
style="@style/WeekNumberStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:visibility="gone"/>
<LinearLayout
android:id="@+id/day_35"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_36"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_37"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_38"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_39"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_40"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/day_41"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center_horizontal"
android:orientation="vertical"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>