setup the first day of the month
This commit is contained in:
parent
40082abc8a
commit
2fafcf6ea4
|
@ -5,9 +5,11 @@ import android.support.v4.app.Fragment
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.simplemobiletools.calendar.Config
|
||||
import com.simplemobiletools.calendar.Constants
|
||||
import com.simplemobiletools.calendar.NavigationListener
|
||||
import com.simplemobiletools.calendar.R
|
||||
import com.simplemobiletools.calendar.views.SmallMonthView
|
||||
import kotlinx.android.synthetic.main.year_fragment.view.*
|
||||
import org.joda.time.DateTime
|
||||
|
||||
|
@ -20,9 +22,21 @@ class YearFragment : Fragment() {
|
|||
|
||||
mYear = arguments.getInt(Constants.YEAR_LABEL)
|
||||
|
||||
val days = DateTime().withYear(mYear).withDayOfMonth(1).withMonthOfYear(2).dayOfMonth().maximumValue
|
||||
val dateTime = DateTime().withYear(mYear).withDayOfMonth(1).withMonthOfYear(2).withHourOfDay(12)
|
||||
val days = dateTime.dayOfMonth().maximumValue
|
||||
view.month_2.setDays(days)
|
||||
|
||||
val res = resources
|
||||
val sundayFirst = Config.newInstance(context).isSundayFirst
|
||||
for (i in 1..12) {
|
||||
val monthView = view.findViewById(res.getIdentifier("month_" + i, "id", activity.packageName)) as SmallMonthView
|
||||
var dayOfWeek = dateTime.withMonthOfYear(i).dayOfWeek().get()
|
||||
if (!sundayFirst)
|
||||
dayOfWeek--
|
||||
|
||||
monthView.setFirstDay(dayOfWeek)
|
||||
}
|
||||
|
||||
return view
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
|||
var mDayWidth = 0f
|
||||
var mTextColor = 0
|
||||
var mDays = 31
|
||||
var mFirstDay = 0
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0) {
|
||||
}
|
||||
|
@ -25,6 +26,10 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
|||
invalidate()
|
||||
}
|
||||
|
||||
fun setFirstDay(firstDay: Int) {
|
||||
mFirstDay = firstDay
|
||||
}
|
||||
|
||||
init {
|
||||
val a = context.theme.obtainStyledAttributes(
|
||||
attrs,
|
||||
|
@ -52,14 +57,14 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
|||
mDayWidth = (canvas.width / 7).toFloat()
|
||||
}
|
||||
|
||||
var curId = 1
|
||||
var curId = 1 - mFirstDay
|
||||
for (y in 1..6) {
|
||||
for (x in 1..7) {
|
||||
if (curId <= mDays) {
|
||||
if (curId > 0 && curId <= mDays) {
|
||||
canvas.drawText(curId.toString(), x * mDayWidth, y * mDayWidth, mPaint)
|
||||
}
|
||||
curId++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue