allow printing the yearly view
This commit is contained in:
parent
abf8998d5b
commit
eed880c195
|
@ -30,4 +30,8 @@ class MyYearPagerAdapter(fm: FragmentManager, val mYears: List<Int>) : FragmentS
|
|||
mFragments[pos + i]?.updateCalendar()
|
||||
}
|
||||
}
|
||||
|
||||
fun printCurrentView(pos: Int) {
|
||||
mFragments[pos].printCurrentView()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.simplemobiletools.calendar.pro.fragments
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.os.Bundle
|
||||
import android.util.SparseArray
|
||||
import android.view.LayoutInflater
|
||||
|
@ -11,6 +10,8 @@ import androidx.fragment.app.Fragment
|
|||
import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.activities.MainActivity
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.extensions.getViewBitmap
|
||||
import com.simplemobiletools.calendar.pro.extensions.printBitmap
|
||||
import com.simplemobiletools.calendar.pro.helpers.YEAR_LABEL
|
||||
import com.simplemobiletools.calendar.pro.helpers.YearlyCalendarImpl
|
||||
import com.simplemobiletools.calendar.pro.interfaces.YearlyCalendar
|
||||
|
@ -25,6 +26,7 @@ import java.util.*
|
|||
class YearFragment : Fragment(), YearlyCalendar {
|
||||
private var mYear = 0
|
||||
private var mSundayFirst = false
|
||||
private var isPrintVersion = false
|
||||
private var lastHash = 0
|
||||
private var mCalendar: YearlyCalendarImpl? = null
|
||||
|
||||
|
@ -37,7 +39,6 @@ class YearFragment : Fragment(), YearlyCalendar {
|
|||
setupMonths()
|
||||
|
||||
mCalendar = YearlyCalendarImpl(this, context!!, mYear)
|
||||
|
||||
return mView
|
||||
}
|
||||
|
||||
|
@ -65,30 +66,40 @@ class YearFragment : Fragment(), YearlyCalendar {
|
|||
val days = dateTime.dayOfMonth().maximumValue
|
||||
mView.month_2.setDays(days)
|
||||
|
||||
val res = resources
|
||||
markCurrentMonth(res)
|
||||
val now = DateTime()
|
||||
|
||||
for (i in 1..12) {
|
||||
val monthView = mView.findViewById<SmallMonthView>(res.getIdentifier("month_" + i, "id", context!!.packageName))
|
||||
val monthView = mView.findViewById<SmallMonthView>(resources.getIdentifier("month_$i", "id", context!!.packageName))
|
||||
var dayOfWeek = dateTime.withMonthOfYear(i).dayOfWeek().get()
|
||||
if (!mSundayFirst) {
|
||||
dayOfWeek--
|
||||
}
|
||||
|
||||
val monthLabel = mView.findViewById<TextView>(resources.getIdentifier("month_${i}_label", "id", context!!.packageName))
|
||||
val curTextColor = when {
|
||||
isPrintVersion -> resources.getColor(R.color.theme_light_text_color)
|
||||
else -> context!!.config.textColor
|
||||
}
|
||||
|
||||
monthLabel.setTextColor(curTextColor)
|
||||
|
||||
monthView.firstDay = dayOfWeek
|
||||
monthView.setOnClickListener {
|
||||
(activity as MainActivity).openMonthFromYearly(DateTime().withDate(mYear, i, 1))
|
||||
}
|
||||
}
|
||||
|
||||
if (!isPrintVersion) {
|
||||
markCurrentMonth(now)
|
||||
}
|
||||
}
|
||||
|
||||
private fun markCurrentMonth(res: Resources) {
|
||||
val now = DateTime()
|
||||
private fun markCurrentMonth(now: DateTime) {
|
||||
if (now.year == mYear) {
|
||||
val monthLabel = mView.findViewById<TextView>(res.getIdentifier("month_${now.monthOfYear}_label", "id", context!!.packageName))
|
||||
val monthLabel = mView.findViewById<TextView>(resources.getIdentifier("month_${now.monthOfYear}_label", "id", context!!.packageName))
|
||||
monthLabel.setTextColor(context!!.getAdjustedPrimaryColor())
|
||||
|
||||
val monthView = mView.findViewById<SmallMonthView>(res.getIdentifier("month_${now.monthOfYear}", "id", context!!.packageName))
|
||||
val monthView = mView.findViewById<SmallMonthView>(resources.getIdentifier("month_${now.monthOfYear}", "id", context!!.packageName))
|
||||
monthView.todaysId = now.dayOfMonth
|
||||
}
|
||||
}
|
||||
|
@ -102,10 +113,28 @@ class YearFragment : Fragment(), YearlyCalendar {
|
|||
}
|
||||
|
||||
lastHash = hashCode
|
||||
val res = resources
|
||||
for (i in 1..12) {
|
||||
val monthView = mView.findViewById<SmallMonthView>(res.getIdentifier("month_$i", "id", context!!.packageName))
|
||||
val monthView = mView.findViewById<SmallMonthView>(resources.getIdentifier("month_$i", "id", context!!.packageName))
|
||||
monthView.setEvents(events.get(i))
|
||||
}
|
||||
}
|
||||
|
||||
fun printCurrentView() {
|
||||
isPrintVersion = true
|
||||
setupMonths()
|
||||
toggleSmallMonthPrintModes()
|
||||
|
||||
context!!.printBitmap(mView.calendar_holder.getViewBitmap())
|
||||
|
||||
isPrintVersion = false
|
||||
setupMonths()
|
||||
toggleSmallMonthPrintModes()
|
||||
}
|
||||
|
||||
private fun toggleSmallMonthPrintModes() {
|
||||
for (i in 1..12) {
|
||||
val monthView = mView.findViewById<SmallMonthView>(resources.getIdentifier("month_$i", "id", context!!.packageName))
|
||||
monthView.togglePrintMode()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import androidx.appcompat.app.AlertDialog
|
|||
import androidx.viewpager.widget.ViewPager
|
||||
import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.activities.MainActivity
|
||||
import com.simplemobiletools.calendar.pro.adapters.MyMonthPagerAdapter
|
||||
import com.simplemobiletools.calendar.pro.adapters.MyYearPagerAdapter
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.helpers.Formatter
|
||||
|
@ -127,5 +128,7 @@ class YearFragmentsHolder : MyFragmentHolder() {
|
|||
|
||||
override fun getNewEventDayCode() = Formatter.getTodayCode()
|
||||
|
||||
override fun printView() {}
|
||||
override fun printView() {
|
||||
(viewPager?.adapter as? MyYearPagerAdapter)?.printCurrentView(viewPager?.currentItem ?: 0)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
|||
private var textColor = 0
|
||||
private var days = 31
|
||||
private var isLandscape = false
|
||||
private var isPrintVersion = false
|
||||
private var mEvents: ArrayList<DayYearly>? = null
|
||||
|
||||
var firstDay = 0
|
||||
|
@ -81,7 +82,7 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
|||
if (curId in 1..days) {
|
||||
canvas.drawText(curId.toString(), x * dayWidth - (dayWidth / 4), y * dayWidth, getPaint(curId))
|
||||
|
||||
if (curId == todaysId) {
|
||||
if (curId == todaysId && !isPrintVersion) {
|
||||
val dividerConstant = if (isLandscape) 6 else 4
|
||||
canvas.drawCircle(x * dayWidth - dayWidth / 2, y * dayWidth - dayWidth / dividerConstant, dayWidth * 0.41f, todayCirclePaint)
|
||||
}
|
||||
|
@ -101,4 +102,16 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
|||
|
||||
return paint
|
||||
}
|
||||
|
||||
fun togglePrintMode() {
|
||||
isPrintVersion = !isPrintVersion
|
||||
textColor = if (isPrintVersion) {
|
||||
resources.getColor(R.color.theme_light_text_color)
|
||||
} else {
|
||||
context.config.textColor.adjustAlpha(MEDIUM_ALPHA)
|
||||
}
|
||||
|
||||
paint.color = textColor
|
||||
invalidate()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
android:layout_marginEnd="@dimen/yearly_padding_full"
|
||||
android:layout_weight="1">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
<TextView
|
||||
android:id="@+id/month_1_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -41,7 +41,7 @@
|
|||
android:layout_marginEnd="@dimen/yearly_padding_half"
|
||||
android:layout_weight="1">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
<TextView
|
||||
android:id="@+id/month_2_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -65,7 +65,7 @@
|
|||
android:layout_marginStart="@dimen/yearly_padding_full"
|
||||
android:layout_weight="1">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
<TextView
|
||||
android:id="@+id/month_3_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -92,7 +92,7 @@
|
|||
android:layout_marginEnd="@dimen/yearly_padding_full"
|
||||
android:layout_weight="1">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
<TextView
|
||||
android:id="@+id/month_4_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -118,7 +118,7 @@
|
|||
android:layout_marginEnd="@dimen/yearly_padding_half"
|
||||
android:layout_weight="1">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
<TextView
|
||||
android:id="@+id/month_5_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -142,7 +142,7 @@
|
|||
android:layout_marginStart="@dimen/yearly_padding_full"
|
||||
android:layout_weight="1">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
<TextView
|
||||
android:id="@+id/month_6_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -169,7 +169,7 @@
|
|||
android:layout_marginEnd="@dimen/yearly_padding_full"
|
||||
android:layout_weight="1">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
<TextView
|
||||
android:id="@+id/month_7_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -193,7 +193,7 @@
|
|||
android:layout_marginEnd="@dimen/yearly_padding_half"
|
||||
android:layout_weight="1">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
<TextView
|
||||
android:id="@+id/month_8_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -217,7 +217,7 @@
|
|||
android:layout_marginStart="@dimen/yearly_padding_full"
|
||||
android:layout_weight="1">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
<TextView
|
||||
android:id="@+id/month_9_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -245,7 +245,7 @@
|
|||
android:layout_marginEnd="@dimen/yearly_padding_full"
|
||||
android:layout_weight="1">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
<TextView
|
||||
android:id="@+id/month_10_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -270,7 +270,7 @@
|
|||
android:layout_marginEnd="@dimen/yearly_padding_half"
|
||||
android:layout_weight="1">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
<TextView
|
||||
android:id="@+id/month_11_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -295,7 +295,7 @@
|
|||
android:layout_marginStart="@dimen/yearly_padding_full"
|
||||
android:layout_weight="1">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
<TextView
|
||||
android:id="@+id/month_12_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
Loading…
Reference in New Issue