adding a Print menu button
This commit is contained in:
parent
ad7c67682f
commit
d676f87c40
|
@ -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'
|
||||
|
|
|
@ -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("")
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -138,4 +138,6 @@ class DayFragmentsHolder : MyFragmentHolder(), NavigationListener {
|
|||
}
|
||||
|
||||
override fun getNewEventDayCode() = currentDayCode
|
||||
|
||||
override fun printView() {}
|
||||
}
|
||||
|
|
|
@ -210,4 +210,6 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
|
|||
}
|
||||
|
||||
override fun getNewEventDayCode() = Formatter.getTodayCode()
|
||||
|
||||
override fun printView() {}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
@ -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() {}
|
||||
}
|
||||
|
|
|
@ -14,4 +14,6 @@ abstract class MyFragmentHolder : Fragment() {
|
|||
abstract fun updateActionBarTitle()
|
||||
|
||||
abstract fun getNewEventDayCode(): String
|
||||
|
||||
abstract fun printView()
|
||||
}
|
||||
|
|
|
@ -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() {}
|
||||
}
|
||||
|
|
|
@ -126,4 +126,6 @@ class YearFragmentsHolder : MyFragmentHolder() {
|
|||
}
|
||||
|
||||
override fun getNewEventDayCode() = Formatter.getTodayCode()
|
||||
|
||||
override fun printView() {}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,10 @@
|
|||
android:id="@+id/go_to_date"
|
||||
android:title="@string/go_to_date"
|
||||
app:showAsAction="never"/>
|
||||
<item
|
||||
android:id="@+id/print"
|
||||
android:title="@string/print"
|
||||
app:showAsAction="never"/>
|
||||
<item
|
||||
android:id="@+id/add_holidays"
|
||||
android:title="@string/add_holidays"
|
||||
|
|
|
@ -10,7 +10,7 @@ buildscript {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:4.0.1'
|
||||
classpath 'com.android.tools.build:gradle:4.0.2'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath "de.timfreiheit.resourceplaceholders:placeholders:0.3"
|
||||
|
||||
|
|
Loading…
Reference in New Issue