properly adjust the colors before printing the month view
This commit is contained in:
parent
830d2c0fcd
commit
0cb88a1405
|
@ -21,6 +21,8 @@ import com.simplemobiletools.calendar.pro.interfaces.MonthlyCalendar
|
|||
import com.simplemobiletools.calendar.pro.interfaces.NavigationListener
|
||||
import com.simplemobiletools.calendar.pro.models.DayMonthly
|
||||
import com.simplemobiletools.commons.extensions.applyColorFilter
|
||||
import com.simplemobiletools.commons.extensions.beGone
|
||||
import com.simplemobiletools.commons.extensions.beVisible
|
||||
import kotlinx.android.synthetic.main.fragment_month.view.*
|
||||
import kotlinx.android.synthetic.main.top_navigation.view.*
|
||||
import org.joda.time.DateTime
|
||||
|
@ -146,6 +148,20 @@ class MonthFragment : Fragment(), MonthlyCalendar {
|
|||
}
|
||||
|
||||
fun printCurrentView() {
|
||||
context!!.printBitmap(mHolder.month_calendar_holder.getViewBitmap())
|
||||
val darkColor = resources.getColor(R.color.theme_light_text_color)
|
||||
|
||||
mHolder.apply {
|
||||
top_left_arrow.beGone()
|
||||
top_right_arrow.beGone()
|
||||
top_value.setTextColor(darkColor)
|
||||
month_view_wrapper.togglePrintMode()
|
||||
|
||||
context!!.printBitmap(month_calendar_holder.getViewBitmap())
|
||||
|
||||
top_left_arrow.beVisible()
|
||||
top_right_arrow.beVisible()
|
||||
top_value.setTextColor(mConfig.textColor)
|
||||
month_view_wrapper.togglePrintMode()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
|||
private var horizontalOffset = 0
|
||||
private var showWeekNumbers = false
|
||||
private var dimPastEvents = true
|
||||
private var isPrintVersion = false
|
||||
private var allEvents = ArrayList<MonthViewEvent>()
|
||||
private var bgRectF = RectF()
|
||||
private var dayLetters = ArrayList<String>()
|
||||
|
@ -142,7 +143,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
|||
val xPos = x * dayWidth + horizontalOffset
|
||||
val yPos = y * dayHeight + verticalOffset
|
||||
val xPosCenter = xPos + dayWidth / 2
|
||||
if (day.isToday) {
|
||||
if (day.isToday && !isPrintVersion) {
|
||||
canvas.drawCircle(xPosCenter, yPos + paint.textSize * 0.7f, paint.textSize * 0.75f, getCirclePaint(day))
|
||||
}
|
||||
|
||||
|
@ -179,7 +180,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
|||
for (i in 0..6) {
|
||||
val xPos = horizontalOffset + (i + 1) * dayWidth - dayWidth / 2
|
||||
var weekDayLetterPaint = paint
|
||||
if (i == currDayOfWeek) {
|
||||
if (i == currDayOfWeek && !isPrintVersion) {
|
||||
weekDayLetterPaint = getColoredPaint(primaryColor)
|
||||
}
|
||||
canvas.drawText(dayLetters[i], xPos, weekDaysLetterHeight * 0.7f, weekDayLetterPaint)
|
||||
|
@ -192,7 +193,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
|||
|
||||
for (i in 0 until ROW_COUNT) {
|
||||
val weekDays = days.subList(i * 7, i * 7 + 7)
|
||||
weekNumberPaint.color = if (weekDays.any { it.isToday }) primaryColor else textColor
|
||||
weekNumberPaint.color = if (weekDays.any { it.isToday && !isPrintVersion }) primaryColor else textColor
|
||||
|
||||
// fourth day of the week determines the week of the year number
|
||||
val weekOfYear = days.getOrNull(i * 7 + 3)?.weekOfYear ?: 1
|
||||
|
@ -257,7 +258,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
|||
|
||||
private fun getTextPaint(startDay: DayMonthly): Paint {
|
||||
var paintColor = textColor
|
||||
if (startDay.isToday) {
|
||||
if (startDay.isToday && !isPrintVersion) {
|
||||
paintColor = primaryColor.getContrastColor()
|
||||
}
|
||||
|
||||
|
@ -276,7 +277,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
|||
|
||||
private fun getEventBackgroundColor(event: MonthViewEvent, startDay: DayMonthly, endDay: DayMonthly): Paint {
|
||||
var paintColor = event.color
|
||||
if ((!startDay.isThisMonth && !endDay.isThisMonth) || (dimPastEvents && event.isPastEvent)) {
|
||||
if ((!startDay.isThisMonth && !endDay.isThisMonth) || (dimPastEvents && event.isPastEvent && !isPrintVersion)) {
|
||||
paintColor = paintColor.adjustAlpha(MEDIUM_ALPHA)
|
||||
}
|
||||
|
||||
|
@ -285,7 +286,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
|||
|
||||
private fun getEventTitlePaint(event: MonthViewEvent, startDay: DayMonthly, endDay: DayMonthly): Paint {
|
||||
var paintColor = event.color.getContrastColor()
|
||||
if ((!startDay.isThisMonth && !endDay.isThisMonth) || (dimPastEvents && event.isPastEvent)) {
|
||||
if ((!startDay.isThisMonth && !endDay.isThisMonth) || (dimPastEvents && event.isPastEvent && !isPrintVersion)) {
|
||||
paintColor = paintColor.adjustAlpha(MEDIUM_ALPHA)
|
||||
}
|
||||
|
||||
|
@ -348,4 +349,18 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
|||
val date = Formatter.getDateTimeFromCode(code)
|
||||
return event.startTS != event.endTS && Formatter.getDateTimeFromTS(event.endTS) == Formatter.getDateTimeFromTS(date.seconds()).withTimeAtStartOfDay()
|
||||
}
|
||||
|
||||
fun togglePrintMode() {
|
||||
isPrintVersion = !isPrintVersion
|
||||
textColor = if (isPrintVersion) {
|
||||
resources.getColor(R.color.theme_light_text_color)
|
||||
} else {
|
||||
config.textColor
|
||||
}
|
||||
|
||||
paint.color = textColor
|
||||
gridPaint.color = textColor.adjustAlpha(LOW_ALPHA)
|
||||
invalidate()
|
||||
initWeekDayLetters()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,4 +96,8 @@ class MonthViewWrapper(context: Context, attrs: AttributeSet, defStyle: Int) : F
|
|||
addView(this)
|
||||
}
|
||||
}
|
||||
|
||||
fun togglePrintMode() {
|
||||
monthView.togglePrintMode()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue