@@ -11,6 +11,7 @@ package com.pspdfkit.flutter.pspdfkit
1111
1212import android.content.Context
1313import android.graphics.Color
14+ import android.util.Log
1415import androidx.core.util.Pair
1516import com.pspdfkit.annotations.AnnotationType
1617import com.pspdfkit.annotations.AnnotationType.CIRCLE
@@ -46,6 +47,7 @@ import com.pspdfkit.annotations.configuration.RedactionAnnotationConfiguration
4647import com.pspdfkit.annotations.configuration.ShapeAnnotationConfiguration
4748import com.pspdfkit.annotations.configuration.SoundAnnotationConfiguration
4849import com.pspdfkit.annotations.configuration.StampAnnotationConfiguration
50+ import com.pspdfkit.annotations.stamps.PredefinedStampType
4951import com.pspdfkit.annotations.stamps.StampPickerItem
5052import com.pspdfkit.configuration.annotations.AnnotationAggregationStrategy
5153import com.pspdfkit.flutter.pspdfkit.annotations.FlutterAnnotationPresetConfiguration
@@ -75,7 +77,7 @@ const val AVAILABLE_BORDER_STYLES_PRESETS = "availableBorderStylePresets"
7577const val DEFAULT_BORDER_STYLE = " borderStyle"
7678const val AUDION_SAMPLING_RATE = " audioSamplingRate"
7779const val AUDIO_RECORDING_TIME_LIMIT = " audioRecordingTimeLimit"
78- const val AVAILABLE_STAMP_ITEMS = " availableStampPickers "
80+ const val AVAILABLE_STAMP_ITEMS = " availableStampItems "
7981const val DEFAULT_ICON_NAME = " defaultIconName"
8082const val AVAILABLE_ICON_NAMES = " availableIconNames"
8183const val DEFAULT_LINE_END = " lineEndStyle"
@@ -248,7 +250,7 @@ class AnnotationConfigurationAdaptor {
248250 }
249251
250252 else -> {
251- throw IllegalArgumentException ( " Unknown annotation type: $key " )
253+ Log .w( " AnnotationConfigAdaptor " , " Unknown annotation type: $key . Ignoring this configuration. " )
252254 }
253255 }
254256 }
@@ -300,7 +302,7 @@ class AnnotationConfigurationAdaptor {
300302
301303 FORCE_DEFAULTS -> builder.setForceDefaults(configuration[key] as Boolean )
302304 else -> {
303- throw IllegalArgumentException ( " Unknown annotation configuration key: $key " )
305+ Log .w( " AnnotationConfigAdaptor " , " Unknown annotation configuration key: $key . Ignoring this property. " )
304306 }
305307 }
306308 }
@@ -353,7 +355,7 @@ class AnnotationConfigurationAdaptor {
353355
354356 FORCE_DEFAULTS -> builder.setForceDefaults(configuration[key] as Boolean )
355357 else -> {
356- throw IllegalArgumentException ( " Unknown annotation configuration key: $key " )
358+ Log .w( " AnnotationConfigAdaptor " , " Unknown annotation configuration key: $key . Ignoring this property. " )
357359 }
358360 }
359361 }
@@ -418,7 +420,7 @@ class AnnotationConfigurationAdaptor {
418420
419421 FORCE_DEFAULTS -> builder.setForceDefaults(configuration[key] as Boolean )
420422 else -> {
421- throw IllegalArgumentException ( " Unknown annotation configuration key: $key " )
423+ Log .w( " AnnotationConfigAdaptor " , " Unknown annotation configuration key: $key . Ignoring this property. " )
422424 }
423425 }
424426 }
@@ -428,7 +430,8 @@ class AnnotationConfigurationAdaptor {
428430 private fun extractLineEndPair (lineEndPair : String ): Pair <LineEndType , LineEndType > {
429431 val lineEnds = lineEndPair.split(" ," )
430432 if (lineEnds.size != 2 ) {
431- throw IllegalArgumentException (" Invalid line end pair: $lineEndPair " )
433+ Log .w(" AnnotationConfigAdaptor" , " Invalid line end pair: $lineEndPair . Using default NONE,NONE pair." )
434+ return Pair (LineEndType .NONE , LineEndType .NONE )
432435 }
433436 val firstLineEnd = parseLineEnd(lineEnds[0 ])
434437 val secondLineEnd = parseLineEnd(lineEnds[1 ])
@@ -523,7 +526,7 @@ class AnnotationConfigurationAdaptor {
523526
524527 FORCE_DEFAULTS -> builder.setForceDefaults(configuration[key] as Boolean )
525528 else -> {
526- throw IllegalArgumentException ( " Unknown key: $key " )
529+ Log .w( " AnnotationConfigAdaptor " , " Unknown key: $key . Ignoring this property. " )
527530 }
528531 }
529532 }
@@ -570,7 +573,7 @@ class AnnotationConfigurationAdaptor {
570573
571574 FORCE_DEFAULTS -> builder.setForceDefaults(configuration[key] as Boolean )
572575 else -> {
573- throw IllegalArgumentException ( " Unknown key: $key " )
576+ Log .w( " AnnotationConfigAdaptor " , " Unknown key: $key . Ignoring this property. " )
574577 }
575578 }
576579 }
@@ -604,7 +607,7 @@ class AnnotationConfigurationAdaptor {
604607
605608 FORCE_DEFAULTS -> builder.setForceDefaults(configuration[key] as Boolean )
606609 else -> {
607- throw IllegalArgumentException ( " Unknown key: $key " )
610+ Log .w( " AnnotationConfigAdaptor " , " Unknown key: $key . Ignoring this property. " )
608611 }
609612
610613 }
@@ -642,7 +645,7 @@ class AnnotationConfigurationAdaptor {
642645
643646 FORCE_DEFAULTS -> builder.setForceDefaults(configuration[key] as Boolean )
644647 else -> {
645- throw IllegalArgumentException ( " Unknown key: $key " )
648+ Log .w( " AnnotationConfigAdaptor " , " Unknown key: $key . Ignoring this property. " )
646649 }
647650 }
648651 }
@@ -670,7 +673,7 @@ class AnnotationConfigurationAdaptor {
670673
671674 FORCE_DEFAULTS -> builder.setForceDefaults(configuration[key] as Boolean )
672675 else -> {
673- throw IllegalArgumentException ( " Unknown key: $key " )
676+ Log .w( " AnnotationConfigAdaptor " , " Unknown key: $key . Ignoring this property. " )
674677 }
675678 }
676679 }
@@ -687,11 +690,11 @@ class AnnotationConfigurationAdaptor {
687690 while (iterator.hasNext()) {
688691 when (val key = iterator.next()) {
689692 AVAILABLE_STAMP_ITEMS -> (configuration[key] as List <* >? )?.let { stampItems ->
690- builder.setAvailableStampPickerItems(
691- extractStampPickerItems(
692- stampItems.map { it as String }, context
693- )
693+ val availableStampItems = extractStampPickerItems(
694+ stampItems.map { it as String }, context
694695 )
696+ if (availableStampItems.isNotEmpty())
697+ builder.setAvailableStampPickerItems(availableStampItems)
695698 }
696699
697700 Z_INDEX_EDITING_ENABLED -> builder.setZIndexEditingEnabled(
@@ -707,7 +710,7 @@ class AnnotationConfigurationAdaptor {
707710
708711 FORCE_DEFAULTS -> builder.setForceDefaults(configuration[key] as Boolean )
709712 else -> {
710- throw IllegalArgumentException ( " Unknown key: $key " )
713+ Log .w( " AnnotationConfigAdaptor " , " Unknown key: $key . Ignoring this property. " )
711714 }
712715 }
713716 }
@@ -776,7 +779,7 @@ class AnnotationConfigurationAdaptor {
776779
777780 FORCE_DEFAULTS -> builder.setForceDefaults(configuration[key] as Boolean )
778781 else -> {
779- throw IllegalArgumentException ( " Unknown key: $key " )
782+ Log .w( " AnnotationConfigAdaptor " , " Unknown key: $key . Ignoring this property. " )
780783 }
781784
782785 }
@@ -833,7 +836,7 @@ class AnnotationConfigurationAdaptor {
833836
834837 FORCE_DEFAULTS -> builder.setForceDefaults(configuration[key] as Boolean )
835838 else -> {
836- throw IllegalArgumentException ( " Unknown key: $key " )
839+ Log .w( " AnnotationConfigAdaptor " , " Unknown key: $key . Ignoring this property. " )
837840 }
838841 }
839842 }
@@ -934,7 +937,7 @@ class AnnotationConfigurationAdaptor {
934937
935938 FORCE_DEFAULTS -> builder.setForceDefaults(configuration[key] as Boolean )
936939 else -> {
937- throw IllegalArgumentException ( " Unknown key: $key " )
940+ Log .w( " AnnotationConfigAdaptor " , " Unknown key: $key . Ignoring this property. " )
938941 }
939942 }
940943 }
@@ -1040,7 +1043,7 @@ class AnnotationConfigurationAdaptor {
10401043
10411044 FORCE_DEFAULTS -> builder.setForceDefaults(configuration[key] as Boolean )
10421045 else -> {
1043- throw IllegalArgumentException ( " Unknown key: $key " )
1046+ Log .w( " AnnotationConfigAdaptor " , " Unknown key: $key . Ignoring this property. " )
10441047 }
10451048 }
10461049 }
@@ -1115,7 +1118,7 @@ class AnnotationConfigurationAdaptor {
11151118 extractAggregationStrategy(configuration[key] as String )
11161119 )
11171120
1118- else -> throw IllegalArgumentException ( " Unknown property $key " )
1121+ else -> Log .w( " AnnotationConfigAdaptor " , " Unknown property $key . Ignoring this property. " )
11191122 }
11201123 }
11211124 return builder.build();
@@ -1130,14 +1133,19 @@ class AnnotationConfigurationAdaptor {
11301133 }
11311134
11321135 private fun extractStampPickerItems (it : Any , context : Context ): List <StampPickerItem > {
1133- val stampPickerItems = mutableListOf<StampPickerItem >()
1134- (it as ArrayList <* >).forEach { stampPickerItem ->
1135- val stampPickerItemString = stampPickerItem as String
1136- stampPickerItems.add(
1137- StampPickerItem .fromTitle(context, stampPickerItemString).build()
1138- )
1136+ try {
1137+ val stampPickerItems = mutableListOf<StampPickerItem >()
1138+ (it as ArrayList <* >).forEach { stampPickerItem ->
1139+ val stampPickerItemString = stampPickerItem as String
1140+ stampPickerItems.add(
1141+ StampPickerItem .fromTitle(context, stampPickerItemString).build()
1142+ )
1143+ }
1144+ return stampPickerItems
1145+ }catch (e: Exception ){
1146+ e.printStackTrace()
1147+ return listOf ()
11391148 }
1140- return stampPickerItems
11411149 }
11421150
11431151 private fun extractBorderStyles (it : List <String >): List <BorderStylePreset > {
@@ -1176,7 +1184,10 @@ class AnnotationConfigurationAdaptor {
11761184 " automatic" -> AnnotationAggregationStrategy .AUTOMATIC
11771185 " merge" -> AnnotationAggregationStrategy .MERGE_IF_POSSIBLE
11781186 " separate" -> AnnotationAggregationStrategy .SEPARATE
1179- else -> throw IllegalArgumentException (" Unknown aggregation strategy $string " )
1187+ else -> {
1188+ Log .w(" AnnotationConfigAdaptor" , " Unknown aggregation strategy $string . Using AUTOMATIC as default." )
1189+ AnnotationAggregationStrategy .AUTOMATIC
1190+ }
11801191 }
11811192 }
11821193
0 commit comments