fill the months with proper day count

This commit is contained in:
tibbi 2016-10-19 18:50:52 +02:00
parent b5e5233a9f
commit ffc528ce15
5 changed files with 42 additions and 7 deletions

View File

@ -8,6 +8,8 @@ import android.view.ViewGroup
import com.simplemobiletools.calendar.Constants
import com.simplemobiletools.calendar.NavigationListener
import com.simplemobiletools.calendar.R
import kotlinx.android.synthetic.main.year_fragment.view.*
import java.util.*
class YearFragment : Fragment() {
private var mListener: NavigationListener? = null
@ -18,6 +20,9 @@ class YearFragment : Fragment() {
mYear = arguments.getInt(Constants.YEAR_LABEL)
val calendar = GregorianCalendar(mYear, Calendar.FEBRUARY, 1)
view.february_value.setDays(calendar.getActualMaximum(Calendar.DAY_OF_MONTH))
return view
}

View File

@ -15,11 +15,28 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
var mPaint: Paint
var mDayWidth = 0f
var mTextColor = 0
var mDays = 31
constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0) {
}
fun setDays(days: Int) {
mDays = days
invalidate()
}
init {
val a = context.theme.obtainStyledAttributes(
attrs,
R.styleable.SmallMonthView,
0, 0)
try {
mDays = a.getInt(R.styleable.SmallMonthView_days, 31)
} finally {
a.recycle()
}
val baseColor = if (Config.newInstance(context).isDarkTheme) Color.WHITE else Color.BLACK
mTextColor = Utils.adjustAlpha(baseColor, Constants.MEDIUM_ALPHA)
@ -38,8 +55,10 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
var curId = 1
for (y in 1..6) {
for (x in 1..7) {
canvas.drawText(curId.toString(), x * mDayWidth, y * mDayWidth, mPaint)
curId++
if (curId <= mDays) {
canvas.drawText(curId.toString(), x * mDayWidth, y * mDayWidth, mPaint)
curId++
}
}
}
}

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/calendar_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -103,7 +104,8 @@
android:id="@+id/april_value"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/april_label"/>
android:layout_below="@+id/april_label"
app:days="30"/>
</RelativeLayout>
<RelativeLayout
@ -151,7 +153,8 @@
android:id="@+id/june_value"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/june_label"/>
android:layout_below="@+id/june_label"
app:days="30"/>
</RelativeLayout>
</TableRow>
@ -224,7 +227,8 @@
android:id="@+id/september_value"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/september_label"/>
android:layout_below="@+id/september_label"
app:days="30"/>
</RelativeLayout>
</TableRow>
@ -274,7 +278,8 @@
android:id="@+id/november_value"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/november_label"/>
android:layout_below="@+id/november_label"
app:days="30"/>
</RelativeLayout>
<RelativeLayout

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="SmallMonthView">
<attr name="days" format="integer"/>
</declare-styleable>
</resources>

View File

@ -12,7 +12,7 @@
<dimen name="min_widget_width">250dp</dimen>
<dimen name="min_widget_height">250dp</dimen>
<dimen name="tiny_text_size">8sp</dimen>
<dimen name="tiny_text_size">9sp</dimen>
<dimen name="normal_text_size">14sp</dimen>
<dimen name="day_text_size">16sp</dimen>
<dimen name="month_text_size">22sp</dimen>