@@ -78,6 +78,8 @@ class AztecText : AppCompatAutoCompleteTextView, TextWatcher, UnknownHtmlSpan.On
7878 val VISIBILITY_KEY = " VISIBILITY_KEY"
7979 val IS_MEDIA_ADDED_KEY = " IS_MEDIA_ADDED_KEY"
8080 val RETAINED_HTML_KEY = " RETAINED_HTML_KEY"
81+
82+ val DEFAULT_IMAGE_WIDTH = 800
8183 }
8284
8385 private var historyEnable = resources.getBoolean(R .bool.history_enable)
@@ -130,6 +132,8 @@ class AztecText : AppCompatAutoCompleteTextView, TextWatcher, UnknownHtmlSpan.On
130132
131133 var verticalParagraphMargin: Int = 0
132134
135+ var maxImagesWidth: Int = 0
136+
133137 interface OnSelectionChangedListener {
134138 fun onSelectionChanged (selStart : Int , selEnd : Int )
135139 }
@@ -235,6 +239,11 @@ class AztecText : AppCompatAutoCompleteTextView, TextWatcher, UnknownHtmlSpan.On
235239
236240 styles.recycle()
237241
242+ // set the pictures max size to the min of screen width/height and DEFAULT_IMAGE_WIDTH
243+ val minScreenSize = Math .min(context.resources.displayMetrics.widthPixels,
244+ context.resources.displayMetrics.heightPixels)
245+ maxImagesWidth = Math .min(minScreenSize, DEFAULT_IMAGE_WIDTH )
246+
238247 if (historyEnable && historySize <= 0 ) {
239248 throw IllegalArgumentException (" historySize must > 0" )
240249 }
@@ -748,6 +757,7 @@ class AztecText : AppCompatAutoCompleteTextView, TextWatcher, UnknownHtmlSpan.On
748757
749758 private fun loadImages () {
750759 val spans = this .text.getSpans(0 , text.length, AztecImageSpan ::class .java)
760+
751761 spans.forEach {
752762 val callbacks = object : Html .ImageGetter .Callbacks {
753763
@@ -770,17 +780,12 @@ class AztecText : AppCompatAutoCompleteTextView, TextWatcher, UnknownHtmlSpan.On
770780 }
771781 }
772782 }
773-
774- // maxidth set to the biggest of screen width/height to cater for device rotation
775- val maxWidth = Math .max(context.resources.displayMetrics.widthPixels,
776- context.resources.displayMetrics.heightPixels)
777- imageGetter?.loadImage(it.getSource(), callbacks, maxWidth)
783+ imageGetter?.loadImage(it.getSource(), callbacks, this @AztecText.maxImagesWidth)
778784 }
779785 }
780786
781787 private fun loadVideos () {
782788 val spans = this .text.getSpans(0 , text.length, AztecVideoSpan ::class .java)
783-
784789 spans.forEach {
785790 val callbacks = object : Html .VideoThumbnailGetter .Callbacks {
786791
@@ -803,8 +808,7 @@ class AztecText : AppCompatAutoCompleteTextView, TextWatcher, UnknownHtmlSpan.On
803808 }
804809 }
805810 }
806-
807- videoThumbnailGetter?.loadVideoThumbnail(it.getSource(), callbacks, context.resources.displayMetrics.widthPixels)
811+ videoThumbnailGetter?.loadVideoThumbnail(it.getSource(), callbacks, this @AztecText.maxImagesWidth)
808812 }
809813 }
810814
0 commit comments