Skip to content

Annotation toolbar customisation #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.pspdfkit.flutter.pspdfkit

import android.content.Context
import com.pspdfkit.ui.toolbar.ContextualToolbar
import com.pspdfkit.ui.toolbar.grouping.presets.MenuItem
import com.pspdfkit.ui.toolbar.grouping.presets.PresetMenuItemGroupingRule

class CustomAnnotationToolbarMenu(context: Context) : PresetMenuItemGroupingRule(context) {
override fun getGroupPreset(capacity: Int, itemsCount: Int): List<MenuItem> {
return listOf(
MenuItem(com.pspdfkit.R.id.pspdf__annotation_creation_toolbar_item_highlight),
MenuItem(com.pspdfkit.R.id.pspdf__annotation_creation_toolbar_item_underline),
MenuItem(com.pspdfkit.R.id.pspdf__annotation_creation_toolbar_item_picker),
MenuItem(com.pspdfkit.R.id.pspdf__annotation_creation_toolbar_item_note),
)
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
package com.pspdfkit.flutter.pspdfkit

import android.os.Bundle
import android.view.View
import com.pspdfkit.annotations.measurements.FloatPrecision
import com.pspdfkit.annotations.measurements.Scale
import com.pspdfkit.document.PdfDocument
import com.pspdfkit.ui.PdfUiFragment
import com.pspdfkit.ui.toolbar.AnnotationCreationToolbar
import com.pspdfkit.ui.toolbar.ContextualToolbar
import com.pspdfkit.ui.toolbar.ToolbarCoordinatorLayout
import java.util.EnumSet

class FlutterPdfUiFragment : PdfUiFragment() {
class FlutterPdfUiFragment : PdfUiFragment(),
ToolbarCoordinatorLayout.OnContextualToolbarLifecycleListener {

private var scale: Scale? = null
private var precision: FloatPrecision? = null

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setOnContextualToolbarLifecycleListener(this)
}

override fun onDocumentLoaded(document: PdfDocument) {
super.onDocumentLoaded(document)
// Notify the Flutter PSPDFKit plugin that the document has been loaded.
Expand All @@ -31,4 +43,19 @@ class FlutterPdfUiFragment : PdfUiFragment() {
this.precision = precision
}

override fun onPrepareContextualToolbar(toolbar: ContextualToolbar<*>) {
if (toolbar is AnnotationCreationToolbar) {
toolbar.setMenuItemGroupingRule(CustomAnnotationToolbarMenu(requireContext()))
toolbar.layoutParams = ToolbarCoordinatorLayout.LayoutParams(
ToolbarCoordinatorLayout.LayoutParams.Position.TOP, EnumSet.of(ToolbarCoordinatorLayout.LayoutParams.Position.TOP)
)
}
}

override fun onDisplayContextualToolbar(p0: ContextualToolbar<*>) {
}

override fun onRemoveContextualToolbar(p0: ContextualToolbar<*>) {
}

}
14 changes: 14 additions & 0 deletions ios/Classes/PspdfPlatformView.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ - (instancetype)initWithFrame:(CGRect)frame viewIdentifier:(int64_t)viewId argum
[_channel setMethodCallHandler:^(FlutterMethodCall * _Nonnull call, FlutterResult _Nonnull result) {
[weakSelf handleMethodCall:call result:result];
}];

PSPDFAnnotationToolbarConfiguration *configuration = [[PSPDFAnnotationToolbarConfiguration alloc] initWithAnnotationGroups:@[
[PSPDFAnnotationGroup groupWithItems:@[
[PSPDFAnnotationGroupItem itemWithType:PSPDFAnnotationStringHighlight],
]],
[PSPDFAnnotationGroup groupWithItems:@[
[PSPDFAnnotationGroupItem itemWithType:PSPDFAnnotationStringUnderline]
]],
[PSPDFAnnotationGroup groupWithItems:@[
[PSPDFAnnotationGroupItem itemWithType:PSPDFAnnotationStringNote]
]]
]];

_pdfViewController.annotationToolbarController.annotationToolbar.configurations = @[configuration];
}

return self;
Expand Down