Show/hide presented pages by tapping thumbnails
This commit is contained in:
parent
f10c9a9ae7
commit
75be87a8fe
|
@ -6,6 +6,9 @@ Minimum Viable Goals:
|
||||||
- [x] Autocrop margins
|
- [x] Autocrop margins
|
||||||
- [ ] Open files the Android way - currently just a bundled test file
|
- [ ] Open files the Android way - currently just a bundled test file
|
||||||
- [ ] Delete+Reorder Pages - doesn't have to save the source file, but does need to save a change journal
|
- [ ] Delete+Reorder Pages - doesn't have to save the source file, but does need to save a change journal
|
||||||
|
- - [x] Tap thumbnails to hide/show pages
|
||||||
|
- - [ ] Drag thumbnails to rearrange pages
|
||||||
|
- - [ ] Save metadata of these actions between sessions
|
||||||
- [ ] Text Annotations - as above
|
- [ ] Text Annotations - as above
|
||||||
|
|
||||||
Stretch Goals:
|
Stretch Goals:
|
||||||
|
@ -14,4 +17,5 @@ Stretch Goals:
|
||||||
- - [ ] synchronize views for different readers
|
- - [ ] synchronize views for different readers
|
||||||
- - [ ] coordinate views for one reader multiscreen
|
- - [ ] coordinate views for one reader multiscreen
|
||||||
- [ ] Pen Annotations
|
- [ ] Pen Annotations
|
||||||
|
- [ ] Autocrop undesired elements (e.g. logo in top right corner, copyright footer)
|
||||||
- [ ] Improve overall UI
|
- [ ] Improve overall UI
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.lhw.pdf
|
||||||
|
|
||||||
import android.app.Presentation
|
import android.app.Presentation
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.graphics.PorterDuff
|
||||||
import android.media.MediaRouter
|
import android.media.MediaRouter
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.DisplayMetrics
|
import android.util.DisplayMetrics
|
||||||
|
@ -40,6 +41,7 @@ class MainActivity : AppCompatActivity() {
|
||||||
private lateinit var pdfDocument: PdfDocument
|
private lateinit var pdfDocument: PdfDocument
|
||||||
private lateinit var presentationScroll: HorizontalScrollView
|
private lateinit var presentationScroll: HorizontalScrollView
|
||||||
private lateinit var presentationLayout: LinearLayout
|
private lateinit var presentationLayout: LinearLayout
|
||||||
|
private val showPages = mutableListOf<Boolean>()
|
||||||
|
|
||||||
private fun inputStreamToCache(outputFilename: String, inputStream: InputStream): File {
|
private fun inputStreamToCache(outputFilename: String, inputStream: InputStream): File {
|
||||||
val fileCached = File(cacheDir, outputFilename)
|
val fileCached = File(cacheDir, outputFilename)
|
||||||
|
@ -61,12 +63,15 @@ class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updatePresentationImages() {
|
private fun updatePresentationImages(rerender: Boolean = true) {
|
||||||
val maxHeight: Int = presentationDisplayMetrics.heightPixels
|
if (rerender) {
|
||||||
val maxWidth: Int = min(maxHeight*5/7, (presentationDisplayMetrics.widthPixels/pagesPerLandscape).toInt())
|
val maxHeight: Int = presentationDisplayMetrics.heightPixels
|
||||||
pdfDocument.renderPagesPresentation(maxWidth, maxHeight, renderAutoCrop)
|
val maxWidth: Int = min(maxHeight*5/7, (presentationDisplayMetrics.widthPixels/pagesPerLandscape).toInt())
|
||||||
|
pdfDocument.renderPagesPresentation(maxWidth, maxHeight, renderAutoCrop)
|
||||||
|
}
|
||||||
presentationLayout.removeAllViewsInLayout()
|
presentationLayout.removeAllViewsInLayout()
|
||||||
for (bitmap in pdfDocument.bitmapPagesPresentation.values) {
|
showPages.withIndex().filter { (i, show) -> (show) }.forEach { (i, show) ->
|
||||||
|
val bitmap = pdfDocument.bitmapPagesPresentation[i]
|
||||||
val img = ImageView(this)
|
val img = ImageView(this)
|
||||||
img.setImageBitmap(bitmap)
|
img.setImageBitmap(bitmap)
|
||||||
presentationLayout.addView(img)
|
presentationLayout.addView(img)
|
||||||
|
@ -110,10 +115,16 @@ class MainActivity : AppCompatActivity() {
|
||||||
initializePdfDocument()
|
initializePdfDocument()
|
||||||
pdfDocument.renderThumbnails(thumbnailWidth, thumbnailHeight)
|
pdfDocument.renderThumbnails(thumbnailWidth, thumbnailHeight)
|
||||||
val container = binding.appBarMain.contentMain.thumbnailsLayout
|
val container = binding.appBarMain.contentMain.thumbnailsLayout
|
||||||
for (bitmap in pdfDocument.bitmapThumbnails.values) {
|
for ((index, bitmap) in pdfDocument.bitmapThumbnails) {
|
||||||
val img = ImageView(this)
|
val img = ImageView(this)
|
||||||
img.setImageBitmap(bitmap)
|
img.setImageBitmap(bitmap)
|
||||||
|
img.setOnClickListener {
|
||||||
|
showPages[index] = !showPages[index]
|
||||||
|
img.setColorFilter(if (showPages[index]) 0 else 0x7F000000, PorterDuff.Mode.DARKEN)
|
||||||
|
updatePresentationImages(false)
|
||||||
|
}
|
||||||
container.addView(img)
|
container.addView(img)
|
||||||
|
showPages.add(true)
|
||||||
}
|
}
|
||||||
presentationView()
|
presentationView()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue