-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
320 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-keep class com.shockwave.** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
affogato-pdf-viewer/src/main/java/com/parsuomash/affogato/pdfviewer/HorizontalPDFView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
@file:Suppress("unused") | ||
|
||
package com.parsuomash.affogato.pdfviewer | ||
|
||
import android.net.Uri | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableIntStateOf | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.saveable.rememberSaveable | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.viewinterop.AndroidView | ||
import com.github.barteksc.pdfviewer.PDFView | ||
import com.github.barteksc.pdfviewer.util.FitPolicy | ||
import com.parsuomash.affogato.pdfviewer.zoomable.ZoomableDefaults | ||
import com.parsuomash.affogato.pdfviewer.zoomable.ZoomableState | ||
import com.parsuomash.affogato.pdfviewer.zoomable.rememberZoomableState | ||
import java.io.File | ||
import java.io.InputStream | ||
|
||
@Composable | ||
fun HorizontalPDFView( | ||
modifier: Modifier = Modifier, | ||
uri: Uri, | ||
zoomableState: ZoomableState = rememberZoomableState( | ||
minScale = ZoomableDefaults.DefaultScale | ||
) | ||
) { | ||
HorizontalPDFViewImpl(modifier = modifier, zoomableState = zoomableState) { | ||
it.fromUri(uri) | ||
} | ||
} | ||
|
||
@Composable | ||
fun HorizontalPDFView( | ||
modifier: Modifier = Modifier, | ||
file: File, | ||
zoomableState: ZoomableState = rememberZoomableState( | ||
minScale = ZoomableDefaults.DefaultScale | ||
) | ||
) { | ||
HorizontalPDFViewImpl(modifier = modifier, zoomableState = zoomableState) { | ||
it.fromFile(file) | ||
} | ||
} | ||
|
||
@Composable | ||
fun HorizontalPDFView( | ||
modifier: Modifier = Modifier, | ||
assetName: String, | ||
zoomableState: ZoomableState = rememberZoomableState( | ||
minScale = ZoomableDefaults.DefaultScale | ||
) | ||
) { | ||
HorizontalPDFViewImpl(modifier = modifier, zoomableState = zoomableState) { | ||
it.fromAsset(assetName) | ||
} | ||
} | ||
|
||
@Composable | ||
fun HorizontalPDFView( | ||
modifier: Modifier = Modifier, | ||
bytes: ByteArray, | ||
zoomableState: ZoomableState = rememberZoomableState( | ||
minScale = ZoomableDefaults.DefaultScale | ||
) | ||
) { | ||
HorizontalPDFViewImpl(modifier = modifier, zoomableState = zoomableState) { | ||
it.fromBytes(bytes) | ||
} | ||
} | ||
|
||
@Composable | ||
fun HorizontalPDFView( | ||
modifier: Modifier = Modifier, | ||
stream: InputStream, | ||
zoomableState: ZoomableState = rememberZoomableState( | ||
minScale = ZoomableDefaults.DefaultScale | ||
) | ||
) { | ||
HorizontalPDFViewImpl(modifier = modifier, zoomableState = zoomableState) { | ||
it.fromStream(stream) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun HorizontalPDFViewImpl( | ||
modifier: Modifier, | ||
zoomableState: ZoomableState, | ||
configurator: (PDFView) -> PDFView.Configurator | ||
) { | ||
var currentPage by rememberSaveable { mutableIntStateOf(0) } | ||
var isDefaultPageLoaded by rememberSaveable { mutableStateOf(false) } | ||
|
||
AndroidView( | ||
modifier = modifier, | ||
factory = { context -> | ||
PDFView(context, null).also { | ||
it.clipToOutline = true | ||
} | ||
}, | ||
update = { pdfView -> | ||
pdfView.apply { | ||
configurator(pdfView).apply { | ||
minZoom = zoomableState.minScale | ||
midZoom = zoomableState.doubleTapScale | ||
maxZoom = zoomableState.maxScale | ||
pageFitPolicy(FitPolicy.WIDTH) | ||
useBestQuality(true) | ||
|
||
swipeHorizontal(true) | ||
pageSnap(true) | ||
autoSpacing(true) | ||
pageFling(true) | ||
|
||
if (isDefaultPageLoaded.not()) { | ||
defaultPage(currentPage) | ||
isDefaultPageLoaded = true | ||
} | ||
}.load() | ||
} | ||
}, | ||
onRelease = { pdfView -> | ||
currentPage = pdfView.currentPage | ||
isDefaultPageLoaded = false | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
affogato-pdf-viewer/src/main/java/com/parsuomash/affogato/pdfviewer/VerticalPDFView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
@file:Suppress("unused") | ||
|
||
package com.parsuomash.affogato.pdfviewer | ||
|
||
import android.net.Uri | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableIntStateOf | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.saveable.rememberSaveable | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.viewinterop.AndroidView | ||
import com.github.barteksc.pdfviewer.PDFView | ||
import com.github.barteksc.pdfviewer.util.FitPolicy | ||
import com.parsuomash.affogato.pdfviewer.zoomable.ZoomableDefaults | ||
import com.parsuomash.affogato.pdfviewer.zoomable.ZoomableState | ||
import com.parsuomash.affogato.pdfviewer.zoomable.rememberZoomableState | ||
import java.io.File | ||
import java.io.InputStream | ||
|
||
@Composable | ||
fun VerticalPDFView( | ||
modifier: Modifier = Modifier, | ||
uri: Uri, | ||
zoomableState: ZoomableState = rememberZoomableState( | ||
minScale = ZoomableDefaults.DefaultScale | ||
) | ||
) { | ||
VerticalPDFViewImpl(modifier = modifier, zoomableState = zoomableState) { | ||
it.fromUri(uri) | ||
} | ||
} | ||
|
||
@Composable | ||
fun VerticalPDFView( | ||
modifier: Modifier = Modifier, | ||
file: File, | ||
zoomableState: ZoomableState = rememberZoomableState( | ||
minScale = ZoomableDefaults.DefaultScale | ||
) | ||
) { | ||
VerticalPDFViewImpl(modifier = modifier, zoomableState = zoomableState) { | ||
it.fromFile(file) | ||
} | ||
} | ||
|
||
@Composable | ||
fun VerticalPDFView( | ||
modifier: Modifier = Modifier, | ||
assetName: String, | ||
zoomableState: ZoomableState = rememberZoomableState( | ||
minScale = ZoomableDefaults.DefaultScale | ||
) | ||
) { | ||
VerticalPDFViewImpl(modifier = modifier, zoomableState = zoomableState) { | ||
it.fromAsset(assetName) | ||
} | ||
} | ||
|
||
@Composable | ||
fun VerticalPDFView( | ||
modifier: Modifier = Modifier, | ||
bytes: ByteArray, | ||
zoomableState: ZoomableState = rememberZoomableState( | ||
minScale = ZoomableDefaults.DefaultScale | ||
) | ||
) { | ||
VerticalPDFViewImpl(modifier = modifier, zoomableState = zoomableState) { | ||
it.fromBytes(bytes) | ||
} | ||
} | ||
|
||
@Composable | ||
fun VerticalPDFView( | ||
modifier: Modifier = Modifier, | ||
stream: InputStream, | ||
zoomableState: ZoomableState = rememberZoomableState( | ||
minScale = ZoomableDefaults.DefaultScale | ||
) | ||
) { | ||
VerticalPDFViewImpl(modifier = modifier, zoomableState = zoomableState) { | ||
it.fromStream(stream) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun VerticalPDFViewImpl( | ||
modifier: Modifier, | ||
zoomableState: ZoomableState, | ||
configurator: (PDFView) -> PDFView.Configurator | ||
) { | ||
var currentPage by rememberSaveable { mutableIntStateOf(0) } | ||
var isDefaultPageLoaded by rememberSaveable { mutableStateOf(false) } | ||
|
||
AndroidView( | ||
modifier = modifier, | ||
factory = { context -> | ||
PDFView(context, null).also { | ||
it.clipToOutline = true | ||
} | ||
}, | ||
update = { pdfView -> | ||
pdfView.apply { | ||
configurator(pdfView).apply { | ||
minZoom = zoomableState.minScale | ||
midZoom = zoomableState.doubleTapScale | ||
maxZoom = zoomableState.maxScale | ||
pageFitPolicy(FitPolicy.WIDTH) | ||
useBestQuality(true) | ||
|
||
if (isDefaultPageLoaded.not()) { | ||
defaultPage(currentPage) | ||
isDefaultPageLoaded = true | ||
} | ||
}.load() | ||
} | ||
}, | ||
onRelease = { pdfView -> | ||
currentPage = pdfView.currentPage | ||
isDefaultPageLoaded = false | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.