adding an initial monthly view Print implementation

This commit is contained in:
tibbi 2020-10-25 18:32:03 +01:00
parent d676f87c40
commit 830d2c0fcd
4 changed files with 26 additions and 15 deletions

View File

@ -32,4 +32,8 @@ class MyMonthPagerAdapter(fm: FragmentManager, private val mCodes: List<String>,
mFragments[pos + i]?.updateCalendar() mFragments[pos + i]?.updateCalendar()
} }
} }
fun printCurrentView(pos: Int) {
mFragments[pos].printCurrentView()
}
} }

View File

@ -0,0 +1,13 @@
package com.simplemobiletools.calendar.pro.extensions
import android.graphics.Bitmap
import android.graphics.Canvas
import android.view.View
fun View.getViewBitmap(): Bitmap {
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
layout(left, top, right, bottom)
draw(canvas)
return bitmap
}

View File

@ -1,20 +1,18 @@
package com.simplemobiletools.calendar.pro.fragments package com.simplemobiletools.calendar.pro.fragments
import android.content.Context import android.content.Context
import android.content.pm.ActivityInfo
import android.content.res.Resources import android.content.res.Resources
import android.graphics.Bitmap
import android.graphics.Canvas
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.RelativeLayout import android.widget.RelativeLayout
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.print.PrintHelper
import com.simplemobiletools.calendar.pro.R import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.activities.MainActivity import com.simplemobiletools.calendar.pro.activities.MainActivity
import com.simplemobiletools.calendar.pro.extensions.config 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.Config import com.simplemobiletools.calendar.pro.helpers.Config
import com.simplemobiletools.calendar.pro.helpers.DAY_CODE import com.simplemobiletools.calendar.pro.helpers.DAY_CODE
import com.simplemobiletools.calendar.pro.helpers.Formatter import com.simplemobiletools.calendar.pro.helpers.Formatter
@ -23,7 +21,6 @@ import com.simplemobiletools.calendar.pro.interfaces.MonthlyCalendar
import com.simplemobiletools.calendar.pro.interfaces.NavigationListener import com.simplemobiletools.calendar.pro.interfaces.NavigationListener
import com.simplemobiletools.calendar.pro.models.DayMonthly import com.simplemobiletools.calendar.pro.models.DayMonthly
import com.simplemobiletools.commons.extensions.applyColorFilter import com.simplemobiletools.commons.extensions.applyColorFilter
import com.simplemobiletools.commons.helpers.mydebug
import kotlinx.android.synthetic.main.fragment_month.view.* import kotlinx.android.synthetic.main.fragment_month.view.*
import kotlinx.android.synthetic.main.top_navigation.view.* import kotlinx.android.synthetic.main.top_navigation.view.*
import org.joda.time.DateTime import org.joda.time.DateTime
@ -107,14 +104,6 @@ class MonthFragment : Fragment(), MonthlyCalendar {
} }
} }
fun loadBitmapFromView(v: View): Bitmap? {
val b = Bitmap.createBitmap(v.width, v.height, Bitmap.Config.ARGB_8888)
val c = Canvas(b)
v.layout(v.left, v.top, v.right, v.bottom)
v.draw(c)
return b
}
private fun setupButtons() { private fun setupButtons() {
mTextColor = mConfig.textColor mTextColor = mConfig.textColor
@ -122,7 +111,6 @@ class MonthFragment : Fragment(), MonthlyCalendar {
applyColorFilter(mTextColor) applyColorFilter(mTextColor)
background = null background = null
setOnClickListener { setOnClickListener {
val bitmap = loadBitmapFromView(mHolder.month_calendar_holder)
listener?.goLeft() listener?.goLeft()
} }
@ -156,4 +144,8 @@ class MonthFragment : Fragment(), MonthlyCalendar {
(activity as MainActivity).openDayFromMonthly(Formatter.getDateTimeFromCode(it.code)) (activity as MainActivity).openDayFromMonthly(Formatter.getDateTimeFromCode(it.code))
} }
} }
fun printCurrentView() {
context!!.printBitmap(mHolder.month_calendar_holder.getViewBitmap())
}
} }

View File

@ -141,5 +141,7 @@ class MonthFragmentsHolder : MyFragmentHolder(), NavigationListener {
override fun getNewEventDayCode() = if (shouldGoToTodayBeVisible()) currentDayCode else todayDayCode override fun getNewEventDayCode() = if (shouldGoToTodayBeVisible()) currentDayCode else todayDayCode
override fun printView() {} override fun printView() {
(viewPager?.adapter as? MyMonthPagerAdapter)?.printCurrentView(viewPager?.currentItem ?: 0)
}
} }