使用 PSPDFKit 创建 PDF 注释时如何显示自定义 Dialogfragment

How to display Custom Dialogfragment when creating PDF Annotations with PSPDFKit

我正在调查 PDF 库 PSPDFKit for Android

// Inside my app's dependencies {}
implementation 'com.pspdfkit:pspdfkit-demo:4.0.2'

该库令人印象深刻,具有许多有价值的功能 "Out Of The Box"。 但是,我遇到了创建注释注释时显示的对话框片段的问题。

我需要一个自定义对话框 UI,因为我的应用程序显示的 PDF 允许多个用户 add/edit 注释。这需要在编辑注释时显示的对话框包含创建注释的用户个人资料图像和全名。

我在我的应用程序中使用 com.pspdfkit.ui.PdfFragment 作为子片段,并且在创建 and/or 编辑注释注释时看不到任何允许我提供自定义 dialogFragment 的方法。

是否可以自定义当creating/editing PSPDFKit 中的注释片段时显示的对话框片段?

从我看到的源代码来看,我需要在 PSPDFKit 中重写这个方法。

public void enterAnnotationCreationMode(@NonNull final AnnotationTool annotationTool) {
        this.viewCoordinator.a(new b() {
            public void run(@NonNull FrameLayout container, @NonNull PdfPasswordView passwordView, @NonNull View errorView, @NonNull final DocumentView documentView) {
                el var10000 = com.pspdfkit.framework.a.d();
                PdfFragment.this.getContext();
                if(var10000.a(PdfFragment.this.configuration)) {
                    if(!PdfFragment.this.getAnnotationPreferences().isAnnotationCreatorSet()) {
                        AnnotationCreatorInputDialogFragment.show(PdfFragment.this.getActivity().getSupportFragmentManager(), (String)null, new OnAnnotationCreatorSetListener() {
                            public void onAnnotationCreatorSet(String annotationCreator) {
                                documentView.enterAnnotationCreationMode(annotationTool);
                            }

                            public void onAbort() {
                            }
                        });
                        com.pspdfkit.framework.a.f().a("show_annotation_creator_dialog").a();
                    } else {
                        documentView.enterAnnotationCreationMode(annotationTool);
                    }
                } else {
                    throw new PSPDFKitException("Entering annotation creation mode for " + annotationTool + " is not permitted, either by the license or configuration.");
                }
            }
        }, true);
    }

从 PSPDFKit 4.0.2 开始,无法替换注释注释编辑器 UI。一般来说,直接联系 PSPDFKit 支持 https://pspdfkit.com/support/request/

是个不错的主意

但是,PSPDFKit 团队已经对此进行了跟踪,很可能会在未来的版本中提供。

解决方法:您可以实施自定义注释操作并将其添加到 AnnotationCreationToolbar。关于如何使用工具栏分组 API 修改工具栏上的操作,有一个 guide article。这也可用于删除现有操作并添加新操作。

使用 OnContextualToolbarLifecycleListener 您可以注册您的自定义过滤器逻辑,删除默认的注释操作并将其替换为您的自定义逻辑(然后将显示您的自定义对话框)。

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        toolbarCoordinatorLayout.setOnContextualToolbarLifecycleListener(this);
    }

    @Override
    public void onPrepareContextualToolbar(@NonNull ContextualToolbar toolbar) {
        if (toolbar instanceof AnnotationCreationToolbar) {
            toolbar.setMenuItemGroupingRule(new CustomNoteAnnotationActionRule(this));
        }
    }

您可以在按下自定义笔记图标切换到 "note creation mode" 时进行注册。每当 DocumentListener#onPageClick() 被调用时,您可以显示您的自定义注释创建 UI.