88 */
99package com .pspdfkit .flutter .pspdfkit ;
1010
11+ import static com .pspdfkit .flutter .pspdfkit .util .Preconditions .requireNotNullNotEmpty ;
12+ import static io .flutter .util .Preconditions .checkNotNull ;
13+
1114import android .content .Context ;
1215import android .util .Log ;
1316
1417import androidx .annotation .NonNull ;
1518import androidx .annotation .Nullable ;
1619import androidx .annotation .StyleRes ;
1720
21+ import com .pspdfkit .configuration .PdfConfiguration ;
1822import com .pspdfkit .configuration .activity .PdfActivityConfiguration ;
1923import com .pspdfkit .configuration .activity .ThumbnailBarMode ;
2024import com .pspdfkit .configuration .activity .UserInterfaceViewMode ;
2529import com .pspdfkit .configuration .settings .SettingsMenuItemType ;
2630import com .pspdfkit .configuration .sharing .ShareFeatures ;
2731import com .pspdfkit .configuration .theming .ThemeMode ;
32+ import com .pspdfkit .ui .special_mode .controller .AnnotationTool ;
2833
2934import java .util .ArrayList ;
3035import java .util .EnumSet ;
3136import java .util .HashMap ;
32-
33- import static com .pspdfkit .flutter .pspdfkit .util .Preconditions .requireNotNullNotEmpty ;
34- import static io .flutter .util .Preconditions .checkNotNull ;
37+ import java .util .List ;
3538
3639class ConfigurationAdapter {
3740 private static final String LOG_TAG = "ConfigurationAdapter" ;
@@ -117,12 +120,12 @@ class ConfigurationAdapter {
117120 */
118121 @ Deprecated
119122 private static final String SHOW_DOCUMENT_LABEL = "showDocumentLabel" ;
120- /**
123+ /**
121124 * @deprecated This key word was deprecated with PSPDFKit for Fluttter 3.1.
122125 * Use {@code FIRST_PAGE_ALWAYS_SINGLE} instead, which replaces it.
123126 */
124127 private static final String IS_FIRST_PAGE_ALWAYS_SINGLE = "isFirstPageAlwaysSingle" ;
125- /**
128+ /**
126129 * @deprecated This key word was deprecated with PSPDFKit for Fluttter 3.1.
127130 * Use {@code SHOW_BOOKMARKS_ACTION} instead, which replaces it.
128131 */
@@ -134,7 +137,7 @@ class ConfigurationAdapter {
134137 private static final String PAGE_TRANSITION_SCROLL_PER_SPREAD = "scrollPerSpread" ;
135138 private static final String PAGE_TRANSITION_SCROLL_CONTINUOUS = "scrollContinuous" ;
136139 private static final String PAGE_TRANSITION_CURL = "curl" ;
137-
140+
138141 // Document Presentation Values
139142 private static final String PAGE_MODE_AUTOMATIC = "automatic" ;
140143 private static final String PAGE_MODE_SINGLE = "single" ;
@@ -175,8 +178,14 @@ class ConfigurationAdapter {
175178 private static final String SHOW_THUMBNAIL_BAR_SCRUBBER_BAR = "scrubberBar" ;
176179 private static final String SHOW_THUMBNAIL_BAR_SCROLLABLE = "scrollable" ;
177180
178- @ NonNull private final PdfActivityConfiguration .Builder configuration ;
179- @ Nullable private String password = null ;
181+ // Instant Options
182+ private static final String ENABLE_INSTANT_COMMENTS = "enableInstantComments" ;
183+
184+ @ NonNull
185+ private final PdfActivityConfiguration .Builder configuration ;
186+ @ Nullable
187+ private String password = null ;
188+ private boolean enableInstantComments = false ;
180189
181190 ConfigurationAdapter (@ NonNull Context context ,
182191 @ Nullable HashMap <String , Object > configurationMap ) {
@@ -349,6 +358,11 @@ class ConfigurationAdapter {
349358 if (key != null ) {
350359 configureAutosaveEnabled (!(Boolean ) configurationMap .get (key ));
351360 }
361+
362+ key = getKeyOfType (configurationMap , ENABLE_INSTANT_COMMENTS , Boolean .class );
363+ if (key != null ) {
364+ enableInstantComments = (boolean ) configurationMap .get (key );
365+ }
352366 }
353367 }
354368
@@ -661,27 +675,27 @@ private <T> void configureSettingsMenuItems(@NonNull ArrayList<T> settingsMenuIt
661675 case SETTINGS_MENU_ITEM_THEME :
662676 case SETTINGS_MENU_ITEM_ANDROID_THEME :
663677 settingsMenuItemTypes .add (SettingsMenuItemType .THEME );
664- break ;
678+ break ;
665679 case SETTINGS_MENU_ITEM_SCREEN_AWAKE :
666680 case SETTINGS_MENU_ITEM_ANDROID_SCREEN_AWAKE :
667681 settingsMenuItemTypes .add (SettingsMenuItemType .SCREEN_AWAKE );
668- break ;
682+ break ;
669683 case SETTINGS_MENU_ITEM_PAGE_LAYOUT :
670684 case SETTINGS_MENU_ITEM_ANDROID_PAGE_LAYOUT :
671685 settingsMenuItemTypes .add (SettingsMenuItemType .PAGE_LAYOUT );
672- break ;
686+ break ;
673687 case SETTINGS_MENU_ITEM_PAGE_TRANSITION :
674688 settingsMenuItemTypes .add (SettingsMenuItemType .PAGE_TRANSITION );
675- break ;
689+ break ;
676690 case SETTINGS_MENU_ITEM_SCROLL_DIRECTION :
677691 settingsMenuItemTypes .add (SettingsMenuItemType .SCROLL_DIRECTION );
678- break ;
692+ break ;
679693 case SETTINGS_MENU_ITEM_IOS_APPEARANCE :
680694 case SETTINGS_MENU_ITEM_IOS_BRIGHTNESS :
681695 case SETTINGS_MENU_ITEM_IOS_PAGE_MODE :
682696 case SETTINGS_MENU_ITEM_IOS_SPREAD_FITTING :
683697 // NO-OP. Only supported on iOS.
684- break ;
698+ break ;
685699 default :
686700 throw new IllegalArgumentException ("Undefined settings menu item " + menuType );
687701 }
@@ -718,13 +732,13 @@ private static <T> void checkCast(Object object, Class<T> clazz, String key) {
718732 * When reading configuration options, we check not only for the given configuration string,
719733 * but also for a string with the `android` prefix. For instance if the user enters
720734 * `androidPageScrollDirection`, it is considered a valid string equal to `pageScrollDirection`.
721- *
735+ * <p>
722736 * When documenting, we always prefer configuration option strings:
723- *
737+ * <p>
724738 * - No prefix : If the key works for both iOS and Android.
725739 * - `android` prefix : If the key works only for Android.
726740 * - `iOS` prefix : If the key works only for iOS.
727- */
741+ */
728742 private String addAndroidPrefix (String key ) {
729743 // Capitalize the first letter.
730744 String cap = String .valueOf (key .charAt (0 )).toUpperCase () + key .substring (1 );
@@ -733,8 +747,8 @@ private String addAndroidPrefix(String key) {
733747
734748 @ Nullable
735749 private <T > String getKeyOfType (@ NonNull HashMap <String , Object > configurationMap ,
736- @ NonNull String key ,
737- @ NonNull Class <T > clazz ) {
750+ @ NonNull String key ,
751+ @ NonNull Class <T > clazz ) {
738752 if (containsKeyOfType (configurationMap , key , clazz )) {
739753 return key ;
740754 }
@@ -784,6 +798,19 @@ String getPassword() {
784798 }
785799
786800 PdfActivityConfiguration build () {
801+ // Turn on Instant comments;
802+ if (enableInstantComments ) {
803+ PdfConfiguration pdfConfiguration = this .configuration .build ().getConfiguration ();
804+
805+ final List <AnnotationTool > annotationTools = pdfConfiguration
806+ .getEnabledAnnotationTools ();
807+ // Explicitly enable Instant comment markers if your server supports this feature.
808+ annotationTools .add (AnnotationTool .INSTANT_COMMENT_MARKER );
809+ annotationTools .add (AnnotationTool .INSTANT_HIGHLIGHT_COMMENT );
810+ this .configuration
811+ .enabledAnnotationTools (annotationTools );
812+ }
813+
787814 return configuration .build ();
788815 }
789816}
0 commit comments