|
@@ -15,14 +15,13 @@ import com.compdfkit.core.annotation.form.CPDFTextWidget
|
|
|
import com.compdfkit.core.annotation.form.CPDFWidgetItem
|
|
|
import com.compdfkit.core.annotation.form.CPDFWidgetItems
|
|
|
import com.compdfkit.core.document.CPDFDestination
|
|
|
-import com.compdfkit.core.document.action.CPDFAction.ActionType
|
|
|
+import com.compdfkit.core.document.action.CPDFAction
|
|
|
import com.compdfkit.core.document.action.CPDFGoToAction
|
|
|
import com.compdfkit.core.document.action.CPDFUriAction
|
|
|
import com.compdfkit.core.edit.CPDFEditTextArea
|
|
|
import com.compdfkit.core.utils.TFileUtils
|
|
|
import com.compdfkit.core.utils.TMathUtils
|
|
|
import com.compdfkit.demo.activity.ReaderActivity
|
|
|
-import com.compdfkit.demo.component.annottool.listener.OnLinkInfoChangeListener
|
|
|
import com.compdfkit.demo.component.annottool.popupwindow.*
|
|
|
import com.compdfkit.demo.component.annottool.popupwindow.LinkAnnotationPopupWindow.LinkType
|
|
|
import com.compdfkit.demo.component.toolbar.popupwindow.AddFormListContentPopupWindow
|
|
@@ -38,6 +37,10 @@ import com.compdfkit.pdfviewer.flutter.helpers.PluginUtils.EVENT_ANNOT_ATTR_FONT
|
|
|
import com.compdfkit.pdfviewer.flutter.helpers.PluginUtils.EVENT_ANNOT_ATTR_FONT_ITALIC
|
|
|
import com.compdfkit.pdfviewer.flutter.helpers.PluginUtils.EVENT_ANNOT_ATTR_FONT_SIZE
|
|
|
import com.compdfkit.pdfviewer.flutter.helpers.PluginUtils.EVENT_ANNOT_ATTR_FONT_TYPE
|
|
|
+import com.compdfkit.pdfviewer.flutter.helpers.PluginUtils.EVENT_ANNOT_ATTR_LINK_EMAIL
|
|
|
+import com.compdfkit.pdfviewer.flutter.helpers.PluginUtils.EVENT_ANNOT_ATTR_LINK_PAGE
|
|
|
+import com.compdfkit.pdfviewer.flutter.helpers.PluginUtils.EVENT_ANNOT_ATTR_LINK_TYPE
|
|
|
+import com.compdfkit.pdfviewer.flutter.helpers.PluginUtils.EVENT_ANNOT_ATTR_LINK_WEB
|
|
|
import com.compdfkit.pdfviewer.flutter.helpers.PluginUtils.EVENT_ANNOT_ATTR_SHAPE_TYPE
|
|
|
import com.compdfkit.pdfviewer.flutter.helpers.PluginUtils.EVENT_ANNOT_ATTR_TEXT_COLOR
|
|
|
import com.compdfkit.pdfviewer.flutter.helpers.PluginUtils.EVENT_ANNOT_ATTR_TEXT_COLOR_ALPHA
|
|
@@ -57,9 +60,6 @@ import com.compdfkit.ui.reader.CPDFReaderView
|
|
|
import com.compdfkit.ui.reader.IPDFErrorMessageCallback
|
|
|
import com.compdfkit.ui.utils.CPDFTextUtils
|
|
|
import io.flutter.plugin.common.BinaryMessenger
|
|
|
-import io.flutter.plugin.common.EventChannel
|
|
|
-import io.flutter.plugin.common.EventChannel.EventSink
|
|
|
-import io.flutter.plugin.common.MethodChannel
|
|
|
import java.io.File
|
|
|
import java.io.FileOutputStream
|
|
|
import java.io.IOException
|
|
@@ -77,18 +77,14 @@ import kotlin.math.round
|
|
|
class SampleContextMenuHelper(readerView: CPDFReaderView, mContext: Context, messenger: BinaryMessenger) : CPDFContextMenuShowHelper(readerView) {
|
|
|
private val annotAttribute: CPDFAnnotAttribute
|
|
|
private val mContext: Context
|
|
|
- private var contextMenuHelperEventEmitter: EventSink? = null
|
|
|
private var linkAnnotationPopupWindow: LinkAnnotationPopupWindow? = null
|
|
|
- private var freeTextPopupWindow: FreeTextPopupWindow? = null
|
|
|
- private var modifyAnnotationAttrChannel: MethodChannel
|
|
|
private var selectMarkupAnnotImpl: CPDFBaseAnnotImpl<*>? = null
|
|
|
private var selectPageView: CPDFPageView? = null
|
|
|
|
|
|
init {
|
|
|
annotAttribute = readerView.readerAttribute.annotAttribute
|
|
|
this.mContext = mContext
|
|
|
- modifyAnnotationAttrChannel = MethodChannel(messenger, PluginUtils.METHOD_CHANNEL_MODIFY_ANNOTATION_ATTRIBUTE)
|
|
|
- modifyAnnotationAttrChannel.setMethodCallHandler { call, result ->
|
|
|
+ ContextMenuEventDispatcher.addModifyAnnotationCallBack("SampleContextMenuHelper") { call, result ->
|
|
|
val configuration = call.arguments as? HashMap<String, Any>
|
|
|
when (call.method) {
|
|
|
KEY_MODIFY_ANNOTATION_ATTRIBUTE -> {
|
|
@@ -106,6 +102,11 @@ class SampleContextMenuHelper(readerView: CPDFReaderView, mContext: Context, mes
|
|
|
val textColorAlpha = configuration.getInt(EVENT_ANNOT_ATTR_TEXT_COLOR_ALPHA)
|
|
|
val fontSize = configuration.getInt(EVENT_ANNOT_ATTR_FONT_SIZE) ?: 40
|
|
|
val fontTypeStr = configuration.getString(EVENT_ANNOT_ATTR_FONT_TYPE)
|
|
|
+ val linkType = configuration.getString(EVENT_ANNOT_ATTR_LINK_TYPE)
|
|
|
+ val linkWeb = configuration.getString(EVENT_ANNOT_ATTR_LINK_WEB)
|
|
|
+ val linkPage = configuration.getInt(EVENT_ANNOT_ATTR_LINK_PAGE)
|
|
|
+ val linkEmail = configuration.getString(EVENT_ANNOT_ATTR_LINK_EMAIL)
|
|
|
+
|
|
|
|
|
|
selectMarkupAnnotImpl?.let {
|
|
|
when (it) {
|
|
@@ -222,6 +223,38 @@ class SampleContextMenuHelper(readerView: CPDFReaderView, mContext: Context, mes
|
|
|
selectPageView?.invalidate()
|
|
|
}
|
|
|
}
|
|
|
+ is CPDFLinkAnnotImpl -> {
|
|
|
+ it.onGetAnnotation()?.let {
|
|
|
+ if (linkType.isNullOrEmpty()) {
|
|
|
+ return@addModifyAnnotationCallBack
|
|
|
+ }
|
|
|
+ when (LinkType.valueOf(linkType.uppercase())) {
|
|
|
+ LinkType.WEBSITE -> {
|
|
|
+ it.linkAction = CPDFUriAction().also {uriAction->
|
|
|
+ uriAction.uri = linkWeb
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LinkType.PAGE -> {
|
|
|
+ if (linkPage != null) {
|
|
|
+ val gotoAction = CPDFGoToAction()
|
|
|
+ val size = readerView.getPageNoZoomSize(linkPage)
|
|
|
+ val destination = CPDFDestination(linkPage, 0F, size.height(), 1F)
|
|
|
+ if (readerView.pdfDocument == null) {
|
|
|
+ return@addModifyAnnotationCallBack
|
|
|
+ }
|
|
|
+ gotoAction.setDestination(readerView.pdfDocument, destination)
|
|
|
+ it.linkAction = gotoAction
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LinkType.EMAIL -> {
|
|
|
+ it.linkAction = CPDFUriAction().also {uriAction->
|
|
|
+ uriAction.uri = linkEmail
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
else -> {
|
|
|
|
|
|
}
|
|
@@ -233,6 +266,7 @@ class SampleContextMenuHelper(readerView: CPDFReaderView, mContext: Context, mes
|
|
|
selectPageView = null
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -291,8 +325,7 @@ class SampleContextMenuHelper(readerView: CPDFReaderView, mContext: Context, mes
|
|
|
emptyMap<String, Any>()
|
|
|
}
|
|
|
}
|
|
|
- contextMenuHelperEventEmitter?.success(attr)
|
|
|
-
|
|
|
+ ContextMenuEventDispatcher.sendEvent(attr)
|
|
|
} else if (id == R.id.delete) {
|
|
|
pageView.deleteAnnotation(annotImpl)
|
|
|
}
|
|
@@ -359,7 +392,7 @@ class SampleContextMenuHelper(readerView: CPDFReaderView, mContext: Context, mes
|
|
|
selectPageView = pageView
|
|
|
|
|
|
val fontName = freetextAnnotation.freetextDa.fontName
|
|
|
- contextMenuHelperEventEmitter?.success(
|
|
|
+ ContextMenuEventDispatcher.sendEvent(
|
|
|
mapOf(
|
|
|
KEY_ANNOT_TYPE to AnnotType.FREETEXT.name.lowercase(),
|
|
|
EVENT_ANNOT_ATTR_FONT_BOLD to CPDFTextAttribute.FontNameHelper.isBold(fontName),
|
|
@@ -399,7 +432,7 @@ class SampleContextMenuHelper(readerView: CPDFReaderView, mContext: Context, mes
|
|
|
selectMarkupAnnotImpl = markupAnnotImpl
|
|
|
selectPageView = pageView
|
|
|
//Notify the flutter side to open the annotation attribute modification interface
|
|
|
- contextMenuHelperEventEmitter?.success(
|
|
|
+ ContextMenuEventDispatcher.sendEvent(
|
|
|
mapOf(
|
|
|
KEY_ANNOT_TYPE to markupAnnotation.type.name.lowercase(),
|
|
|
EVENT_ANNOT_ATTR_COLOR to markupAnnotation.color.toHexColor(),
|
|
@@ -437,7 +470,7 @@ class SampleContextMenuHelper(readerView: CPDFReaderView, mContext: Context, mes
|
|
|
selectMarkupAnnotImpl = inkAnnotImpl
|
|
|
selectPageView = pageView
|
|
|
//Notify the flutter side to open the annotation attribute modification interface
|
|
|
- contextMenuHelperEventEmitter?.success(
|
|
|
+ ContextMenuEventDispatcher.sendEvent(
|
|
|
mapOf(
|
|
|
KEY_ANNOT_TYPE to inkAnnotation.type.name.lowercase(),
|
|
|
EVENT_ANNOT_ATTR_COLOR to inkAnnotation.color.toHexColor(),
|
|
@@ -500,6 +533,8 @@ class SampleContextMenuHelper(readerView: CPDFReaderView, mContext: Context, mes
|
|
|
if (readerView == null || pageView == null) {
|
|
|
return null
|
|
|
}
|
|
|
+ selectMarkupAnnotImpl = linkAnnotImpl
|
|
|
+ selectPageView = pageView
|
|
|
val document = readerView.pdfDocument ?: return null
|
|
|
invokeOnClickListener(contentView, { v: View ->
|
|
|
val id = v.id
|
|
@@ -509,70 +544,40 @@ class SampleContextMenuHelper(readerView: CPDFReaderView, mContext: Context, mes
|
|
|
if (action == null && destination == null) {
|
|
|
return@invokeOnClickListener
|
|
|
}
|
|
|
- if (linkAnnotationPopupWindow == null) {
|
|
|
- linkAnnotationPopupWindow = LinkAnnotationPopupWindow(context, readerView)
|
|
|
- }
|
|
|
- linkAnnotationPopupWindow!!.setOnInfoChangeListener(object : OnLinkInfoChangeListener {
|
|
|
- override fun cancelCreateLink(): Boolean {
|
|
|
- return false
|
|
|
- }
|
|
|
-
|
|
|
- override fun createWebsiteLink(website: String): Boolean {
|
|
|
- val uriAction = CPDFUriAction()
|
|
|
- uriAction.uri = website
|
|
|
- linkAnnotation.linkAction = uriAction
|
|
|
- return true
|
|
|
- }
|
|
|
-
|
|
|
- override fun createEmailLink(email: String): Boolean {
|
|
|
- val uriAction = CPDFUriAction()
|
|
|
- uriAction.uri = email
|
|
|
- linkAnnotation.linkAction = uriAction
|
|
|
- return true
|
|
|
- }
|
|
|
-
|
|
|
- override fun createPageLink(pageNum: Int): Boolean {
|
|
|
- val goToAction = CPDFGoToAction()
|
|
|
- val size = readerView.getPageNoZoomSize(pageNum)
|
|
|
- val destination = CPDFDestination(pageNum, 0F, size.height(), 1F)
|
|
|
- val document = readerView.pdfDocument
|
|
|
- if (document == null) {
|
|
|
- return false
|
|
|
- }
|
|
|
- goToAction.setDestination(document, destination)
|
|
|
- linkAnnotation.linkAction = goToAction
|
|
|
- return true
|
|
|
+ val map = when {
|
|
|
+ destination != null -> {
|
|
|
+ mapOf(
|
|
|
+ KEY_ANNOT_TYPE to linkAnnotation.type.name.lowercase(),
|
|
|
+ EVENT_ANNOT_ATTR_LINK_TYPE to LinkType.PAGE.name.lowercase(),
|
|
|
+ EVENT_ANNOT_ATTR_LINK_PAGE to destination.pageIndex + 1
|
|
|
+ )
|
|
|
}
|
|
|
- })
|
|
|
- var linkType = LinkType.PAGE
|
|
|
- var url = ""
|
|
|
- if (destination != null) {
|
|
|
- linkType = LinkType.PAGE
|
|
|
- url = destination.pageIndex.toString()
|
|
|
- } else {
|
|
|
- when (action!!.actionType) {
|
|
|
- ActionType.PDFActionType_GoTo -> {
|
|
|
- linkType = LinkType.PAGE
|
|
|
- val goToAction = action as CPDFGoToAction
|
|
|
- val destination1 = goToAction.getDestination(document)
|
|
|
- if (destination1 != null) {
|
|
|
- url = destination1.pageIndex.toString()
|
|
|
+ else -> {
|
|
|
+ when (action.actionType) {
|
|
|
+ CPDFAction.ActionType.PDFActionType_GoTo -> {
|
|
|
+ mapOf(
|
|
|
+ KEY_ANNOT_TYPE to linkAnnotation.type.name.lowercase(),
|
|
|
+ EVENT_ANNOT_ATTR_LINK_TYPE to LinkType.PAGE.name.lowercase(),
|
|
|
+ EVENT_ANNOT_ATTR_LINK_PAGE to (action as CPDFGoToAction).getDestination(readerView.pdfDocument).pageIndex + 1
|
|
|
+ )
|
|
|
}
|
|
|
- }
|
|
|
- ActionType.PDFActionType_URI -> {
|
|
|
- val uriAction = action as CPDFUriAction
|
|
|
- url = uriAction.uri
|
|
|
- linkType = if (url.startsWith("mailto:")) {
|
|
|
- LinkType.EMAIL
|
|
|
- } else {
|
|
|
- LinkType.WEBSITE
|
|
|
+ CPDFAction.ActionType.PDFActionType_URI -> {
|
|
|
+ val uri = (action as CPDFUriAction).uri
|
|
|
+ val linkType = if (uri.startsWith("mailto:")) LinkType.EMAIL else LinkType.WEBSITE
|
|
|
+ mapOf(
|
|
|
+ KEY_ANNOT_TYPE to linkAnnotation.type.name.lowercase(),
|
|
|
+ EVENT_ANNOT_ATTR_LINK_TYPE to linkType.name.lowercase(),
|
|
|
+ EVENT_ANNOT_ATTR_LINK_WEB to uri,
|
|
|
+ EVENT_ANNOT_ATTR_LINK_EMAIL to uri.replace("mailto:", "")
|
|
|
+ )
|
|
|
+ }
|
|
|
+ else -> {
|
|
|
+ mapOf<String, Any>()
|
|
|
}
|
|
|
}
|
|
|
- else -> {}
|
|
|
}
|
|
|
}
|
|
|
- linkAnnotationPopupWindow!!.setInitData(linkType, url)
|
|
|
- linkAnnotationPopupWindow!!.show(linkType)
|
|
|
+ ContextMenuEventDispatcher.sendEvent(map)
|
|
|
} else if (id == R.id.delete) {
|
|
|
pageView.deleteAnnotation(annotImpl)
|
|
|
}
|
|
@@ -1258,8 +1263,5 @@ class SampleContextMenuHelper(readerView: CPDFReaderView, mContext: Context, mes
|
|
|
return contentView
|
|
|
}
|
|
|
|
|
|
- fun setContextMenuHelperEventEmitter(emitter: EventChannel.EventSink?) {
|
|
|
- this.contextMenuHelperEventEmitter = emitter
|
|
|
- }
|
|
|
|
|
|
}
|