diff --git a/app/build.gradle b/app/build.gradle
index 72e4454e1..8b94ce5a4 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -64,11 +64,12 @@ android {
}
dependencies {
- implementation 'com.simplemobiletools:commons:5.30.24'
+ implementation 'com.simplemobiletools:commons:5.31.8'
implementation 'joda-time:joda-time:2.10.1'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
+ implementation "androidx.print:print:1.0.0"
kapt 'androidx.room:room-compiler:2.2.5'
implementation 'androidx.room:room-runtime:2.2.5'
diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt
index 991223ecf..bfe24d4ea 100644
--- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt
@@ -192,6 +192,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
R.id.change_view -> showViewDialog()
R.id.go_to_today -> goToToday()
R.id.go_to_date -> showGoToDateDialog()
+ R.id.print -> printView()
R.id.filter -> showFilterDialog()
R.id.refresh_caldav_calendars -> refreshCalDAVCalendars(true)
R.id.add_holidays -> addHolidays()
@@ -424,6 +425,10 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
currentFragments.last().showGoToDateDialog()
}
+ fun printView() {
+ currentFragments.last().printView()
+ }
+
private fun resetActionBarTitle() {
updateActionBarTitle(getString(R.string.app_launcher_name))
updateActionBarSubtitle("")
diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt
index cd0d20413..566b3ca86 100644
--- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt
@@ -8,7 +8,9 @@ import android.content.ComponentName
import android.content.ContentResolver
import android.content.Context
import android.content.Intent
+import android.content.pm.ActivityInfo
import android.content.res.Resources
+import android.graphics.Bitmap
import android.media.AudioAttributes
import android.net.Uri
import android.os.Bundle
@@ -20,6 +22,7 @@ import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.app.AlarmManagerCompat
import androidx.core.app.NotificationCompat
+import androidx.print.PrintHelper
import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.activities.EventActivity
import com.simplemobiletools.calendar.pro.activities.SnoozeReminderActivity
@@ -544,3 +547,10 @@ fun Context.getWeeklyViewItemHeight(): Float {
val multiplier = config.weeklyViewItemHeightMultiplier
return defaultHeight * multiplier
}
+
+fun Context.printBitmap(bitmap: Bitmap) {
+ val printHelper = PrintHelper(this)
+ printHelper.scaleMode = PrintHelper.SCALE_MODE_FIT
+ printHelper.orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
+ printHelper.printBitmap(getString(R.string.app_name), bitmap)
+}
diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/DayFragmentsHolder.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/DayFragmentsHolder.kt
index 17c9d508a..5fd2a744c 100644
--- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/DayFragmentsHolder.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/DayFragmentsHolder.kt
@@ -138,4 +138,6 @@ class DayFragmentsHolder : MyFragmentHolder(), NavigationListener {
}
override fun getNewEventDayCode() = currentDayCode
+
+ override fun printView() {}
}
diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/EventListFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/EventListFragment.kt
index da553b923..fdf849aea 100644
--- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/EventListFragment.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/EventListFragment.kt
@@ -210,4 +210,6 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
}
override fun getNewEventDayCode() = Formatter.getTodayCode()
+
+ override fun printView() {}
}
diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/MonthFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/MonthFragment.kt
index 718dc0da8..57f40ddc8 100644
--- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/MonthFragment.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/MonthFragment.kt
@@ -1,13 +1,17 @@
package com.simplemobiletools.calendar.pro.fragments
import android.content.Context
+import android.content.pm.ActivityInfo
import android.content.res.Resources
+import android.graphics.Bitmap
+import android.graphics.Canvas
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.RelativeLayout
import androidx.fragment.app.Fragment
+import androidx.print.PrintHelper
import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.activities.MainActivity
import com.simplemobiletools.calendar.pro.extensions.config
@@ -19,6 +23,7 @@ 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.helpers.mydebug
import kotlinx.android.synthetic.main.fragment_month.view.*
import kotlinx.android.synthetic.main.top_navigation.view.*
import org.joda.time.DateTime
@@ -102,6 +107,14 @@ 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() {
mTextColor = mConfig.textColor
@@ -109,6 +122,7 @@ class MonthFragment : Fragment(), MonthlyCalendar {
applyColorFilter(mTextColor)
background = null
setOnClickListener {
+ val bitmap = loadBitmapFromView(mHolder.month_calendar_holder)
listener?.goLeft()
}
diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/MonthFragmentsHolder.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/MonthFragmentsHolder.kt
index e9eebd787..c504809ea 100644
--- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/MonthFragmentsHolder.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/MonthFragmentsHolder.kt
@@ -115,11 +115,11 @@ class MonthFragmentsHolder : MyFragmentHolder(), NavigationListener {
datePicker.init(dateTime.year, dateTime.monthOfYear - 1, 1, null)
AlertDialog.Builder(context!!)
- .setNegativeButton(R.string.cancel, null)
- .setPositiveButton(R.string.ok) { dialog, which -> datePicked(dateTime, datePicker) }
- .create().apply {
- activity?.setupDialogStuff(view, this)
- }
+ .setNegativeButton(R.string.cancel, null)
+ .setPositiveButton(R.string.ok) { dialog, which -> datePicked(dateTime, datePicker) }
+ .create().apply {
+ activity?.setupDialogStuff(view, this)
+ }
}
private fun datePicked(dateTime: DateTime, datePicker: DatePicker) {
@@ -140,4 +140,6 @@ class MonthFragmentsHolder : MyFragmentHolder(), NavigationListener {
}
override fun getNewEventDayCode() = if (shouldGoToTodayBeVisible()) currentDayCode else todayDayCode
+
+ override fun printView() {}
}
diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/MyFragmentHolder.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/MyFragmentHolder.kt
index a7708e98e..faf2008b6 100644
--- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/MyFragmentHolder.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/MyFragmentHolder.kt
@@ -14,4 +14,6 @@ abstract class MyFragmentHolder : Fragment() {
abstract fun updateActionBarTitle()
abstract fun getNewEventDayCode(): String
+
+ abstract fun printView()
}
diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragmentsHolder.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragmentsHolder.kt
index a0cd07745..91a725c3b 100644
--- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragmentsHolder.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragmentsHolder.kt
@@ -258,4 +258,6 @@ class WeekFragmentsHolder : MyFragmentHolder(), WeekFragmentListener {
}
override fun getFullFragmentHeight() = weekHolder!!.week_view_holder.height - weekHolder!!.week_view_seekbar.height - weekHolder!!.week_view_days_count_divider.height
+
+ override fun printView() {}
}
diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/YearFragmentsHolder.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/YearFragmentsHolder.kt
index ff3221d8f..347d4cce3 100644
--- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/YearFragmentsHolder.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/YearFragmentsHolder.kt
@@ -126,4 +126,6 @@ class YearFragmentsHolder : MyFragmentHolder() {
}
override fun getNewEventDayCode() = Formatter.getTodayCode()
+
+ override fun printView() {}
}
diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml
index cdfb2ca48..db4216148 100644
--- a/app/src/main/res/menu/menu_main.xml
+++ b/app/src/main/res/menu/menu_main.xml
@@ -31,6 +31,10 @@
android:id="@+id/go_to_date"
android:title="@string/go_to_date"
app:showAsAction="never"/>
+