@@ -11,6 +11,7 @@ package com.pspdfkit.flutter.pspdfkit
11
11
12
12
import android.content.Context
13
13
import android.graphics.Color
14
+ import android.util.Log
14
15
import androidx.core.util.Pair
15
16
import com.pspdfkit.annotations.AnnotationType
16
17
import com.pspdfkit.annotations.AnnotationType.CIRCLE
@@ -46,6 +47,7 @@ import com.pspdfkit.annotations.configuration.RedactionAnnotationConfiguration
46
47
import com.pspdfkit.annotations.configuration.ShapeAnnotationConfiguration
47
48
import com.pspdfkit.annotations.configuration.SoundAnnotationConfiguration
48
49
import com.pspdfkit.annotations.configuration.StampAnnotationConfiguration
50
+ import com.pspdfkit.annotations.stamps.PredefinedStampType
49
51
import com.pspdfkit.annotations.stamps.StampPickerItem
50
52
import com.pspdfkit.configuration.annotations.AnnotationAggregationStrategy
51
53
import com.pspdfkit.flutter.pspdfkit.annotations.FlutterAnnotationPresetConfiguration
@@ -75,7 +77,7 @@ const val AVAILABLE_BORDER_STYLES_PRESETS = "availableBorderStylePresets"
75
77
const val DEFAULT_BORDER_STYLE = " borderStyle"
76
78
const val AUDION_SAMPLING_RATE = " audioSamplingRate"
77
79
const val AUDIO_RECORDING_TIME_LIMIT = " audioRecordingTimeLimit"
78
- const val AVAILABLE_STAMP_ITEMS = " availableStampPickers "
80
+ const val AVAILABLE_STAMP_ITEMS = " availableStampItems "
79
81
const val DEFAULT_ICON_NAME = " defaultIconName"
80
82
const val AVAILABLE_ICON_NAMES = " availableIconNames"
81
83
const val DEFAULT_LINE_END = " lineEndStyle"
@@ -248,7 +250,7 @@ class AnnotationConfigurationAdaptor {
248
250
}
249
251
250
252
else -> {
251
- throw IllegalArgumentException ( " Unknown annotation type: $key " )
253
+ Log .w( " AnnotationConfigAdaptor " , " Unknown annotation type: $key . Ignoring this configuration. " )
252
254
}
253
255
}
254
256
}
@@ -300,7 +302,7 @@ class AnnotationConfigurationAdaptor {
300
302
301
303
FORCE_DEFAULTS -> builder.setForceDefaults(configuration[key] as Boolean )
302
304
else -> {
303
- throw IllegalArgumentException ( " Unknown annotation configuration key: $key " )
305
+ Log .w( " AnnotationConfigAdaptor " , " Unknown annotation configuration key: $key . Ignoring this property. " )
304
306
}
305
307
}
306
308
}
@@ -353,7 +355,7 @@ class AnnotationConfigurationAdaptor {
353
355
354
356
FORCE_DEFAULTS -> builder.setForceDefaults(configuration[key] as Boolean )
355
357
else -> {
356
- throw IllegalArgumentException ( " Unknown annotation configuration key: $key " )
358
+ Log .w( " AnnotationConfigAdaptor " , " Unknown annotation configuration key: $key . Ignoring this property. " )
357
359
}
358
360
}
359
361
}
@@ -418,7 +420,7 @@ class AnnotationConfigurationAdaptor {
418
420
419
421
FORCE_DEFAULTS -> builder.setForceDefaults(configuration[key] as Boolean )
420
422
else -> {
421
- throw IllegalArgumentException ( " Unknown annotation configuration key: $key " )
423
+ Log .w( " AnnotationConfigAdaptor " , " Unknown annotation configuration key: $key . Ignoring this property. " )
422
424
}
423
425
}
424
426
}
@@ -428,7 +430,8 @@ class AnnotationConfigurationAdaptor {
428
430
private fun extractLineEndPair (lineEndPair : String ): Pair <LineEndType , LineEndType > {
429
431
val lineEnds = lineEndPair.split(" ," )
430
432
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 )
432
435
}
433
436
val firstLineEnd = parseLineEnd(lineEnds[0 ])
434
437
val secondLineEnd = parseLineEnd(lineEnds[1 ])
@@ -523,7 +526,7 @@ class AnnotationConfigurationAdaptor {
523
526
524
527
FORCE_DEFAULTS -> builder.setForceDefaults(configuration[key] as Boolean )
525
528
else -> {
526
- throw IllegalArgumentException ( " Unknown key: $key " )
529
+ Log .w( " AnnotationConfigAdaptor " , " Unknown key: $key . Ignoring this property. " )
527
530
}
528
531
}
529
532
}
@@ -570,7 +573,7 @@ class AnnotationConfigurationAdaptor {
570
573
571
574
FORCE_DEFAULTS -> builder.setForceDefaults(configuration[key] as Boolean )
572
575
else -> {
573
- throw IllegalArgumentException ( " Unknown key: $key " )
576
+ Log .w( " AnnotationConfigAdaptor " , " Unknown key: $key . Ignoring this property. " )
574
577
}
575
578
}
576
579
}
@@ -604,7 +607,7 @@ class AnnotationConfigurationAdaptor {
604
607
605
608
FORCE_DEFAULTS -> builder.setForceDefaults(configuration[key] as Boolean )
606
609
else -> {
607
- throw IllegalArgumentException ( " Unknown key: $key " )
610
+ Log .w( " AnnotationConfigAdaptor " , " Unknown key: $key . Ignoring this property. " )
608
611
}
609
612
610
613
}
@@ -642,7 +645,7 @@ class AnnotationConfigurationAdaptor {
642
645
643
646
FORCE_DEFAULTS -> builder.setForceDefaults(configuration[key] as Boolean )
644
647
else -> {
645
- throw IllegalArgumentException ( " Unknown key: $key " )
648
+ Log .w( " AnnotationConfigAdaptor " , " Unknown key: $key . Ignoring this property. " )
646
649
}
647
650
}
648
651
}
@@ -670,7 +673,7 @@ class AnnotationConfigurationAdaptor {
670
673
671
674
FORCE_DEFAULTS -> builder.setForceDefaults(configuration[key] as Boolean )
672
675
else -> {
673
- throw IllegalArgumentException ( " Unknown key: $key " )
676
+ Log .w( " AnnotationConfigAdaptor " , " Unknown key: $key . Ignoring this property. " )
674
677
}
675
678
}
676
679
}
@@ -687,11 +690,11 @@ class AnnotationConfigurationAdaptor {
687
690
while (iterator.hasNext()) {
688
691
when (val key = iterator.next()) {
689
692
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
694
695
)
696
+ if (availableStampItems.isNotEmpty())
697
+ builder.setAvailableStampPickerItems(availableStampItems)
695
698
}
696
699
697
700
Z_INDEX_EDITING_ENABLED -> builder.setZIndexEditingEnabled(
@@ -707,7 +710,7 @@ class AnnotationConfigurationAdaptor {
707
710
708
711
FORCE_DEFAULTS -> builder.setForceDefaults(configuration[key] as Boolean )
709
712
else -> {
710
- throw IllegalArgumentException ( " Unknown key: $key " )
713
+ Log .w( " AnnotationConfigAdaptor " , " Unknown key: $key . Ignoring this property. " )
711
714
}
712
715
}
713
716
}
@@ -776,7 +779,7 @@ class AnnotationConfigurationAdaptor {
776
779
777
780
FORCE_DEFAULTS -> builder.setForceDefaults(configuration[key] as Boolean )
778
781
else -> {
779
- throw IllegalArgumentException ( " Unknown key: $key " )
782
+ Log .w( " AnnotationConfigAdaptor " , " Unknown key: $key . Ignoring this property. " )
780
783
}
781
784
782
785
}
@@ -833,7 +836,7 @@ class AnnotationConfigurationAdaptor {
833
836
834
837
FORCE_DEFAULTS -> builder.setForceDefaults(configuration[key] as Boolean )
835
838
else -> {
836
- throw IllegalArgumentException ( " Unknown key: $key " )
839
+ Log .w( " AnnotationConfigAdaptor " , " Unknown key: $key . Ignoring this property. " )
837
840
}
838
841
}
839
842
}
@@ -934,7 +937,7 @@ class AnnotationConfigurationAdaptor {
934
937
935
938
FORCE_DEFAULTS -> builder.setForceDefaults(configuration[key] as Boolean )
936
939
else -> {
937
- throw IllegalArgumentException ( " Unknown key: $key " )
940
+ Log .w( " AnnotationConfigAdaptor " , " Unknown key: $key . Ignoring this property. " )
938
941
}
939
942
}
940
943
}
@@ -1040,7 +1043,7 @@ class AnnotationConfigurationAdaptor {
1040
1043
1041
1044
FORCE_DEFAULTS -> builder.setForceDefaults(configuration[key] as Boolean )
1042
1045
else -> {
1043
- throw IllegalArgumentException ( " Unknown key: $key " )
1046
+ Log .w( " AnnotationConfigAdaptor " , " Unknown key: $key . Ignoring this property. " )
1044
1047
}
1045
1048
}
1046
1049
}
@@ -1115,7 +1118,7 @@ class AnnotationConfigurationAdaptor {
1115
1118
extractAggregationStrategy(configuration[key] as String )
1116
1119
)
1117
1120
1118
- else -> throw IllegalArgumentException ( " Unknown property $key " )
1121
+ else -> Log .w( " AnnotationConfigAdaptor " , " Unknown property $key . Ignoring this property. " )
1119
1122
}
1120
1123
}
1121
1124
return builder.build();
@@ -1130,14 +1133,19 @@ class AnnotationConfigurationAdaptor {
1130
1133
}
1131
1134
1132
1135
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 ()
1139
1148
}
1140
- return stampPickerItems
1141
1149
}
1142
1150
1143
1151
private fun extractBorderStyles (it : List <String >): List <BorderStylePreset > {
@@ -1176,7 +1184,10 @@ class AnnotationConfigurationAdaptor {
1176
1184
" automatic" -> AnnotationAggregationStrategy .AUTOMATIC
1177
1185
" merge" -> AnnotationAggregationStrategy .MERGE_IF_POSSIBLE
1178
1186
" 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
+ }
1180
1191
}
1181
1192
}
1182
1193
0 commit comments