forked from Dmitry-Borodin/pdfview-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPDFView.kt
49 lines (39 loc) · 1.26 KB
/
PDFView.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.pdfview
import android.content.Context
import android.util.AttributeSet
import com.pdfview.subsamplincscaleimageview.ImageSource
import com.pdfview.subsamplincscaleimageview.SubsamplingScaleImageView
import java.io.File
class PDFView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : SubsamplingScaleImageView(context, attrs) {
private var mfile: File? = null
private var mScale: Float = 8f
init {
setMinimumTileDpi(120)
setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_START)
}
fun fromAsset(assetFileName: String): PDFView {
mfile = FileUtils.fileFromAsset(context, assetFileName)
return this
}
fun fromFile(file: File): PDFView {
mfile = file
return this
}
fun fromFile(filePath: String): PDFView {
mfile = File(filePath)
return this
}
fun scale(scale: Float): PDFView {
mScale = scale
return this
}
fun show() {
val source = ImageSource.uri(mfile!!.path)
setRegionDecoderFactory { PDFRegionDecoder(view = this, file = mfile!!, scale = mScale) }
setImage(source)
}
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
this.recycle()
}
}