@@ -97,6 +97,9 @@ class AztecText : EditText, TextWatcher, UnknownHtmlSpan.OnUnknownHtmlClickListe
9797
9898 private var isNewStyleSelected = false
9999
100+ private var drawableFailed: Int = 0
101+ private var drawableLoading: Int = 0
102+
100103 var isMediaAdded = false
101104
102105 lateinit var history: History
@@ -135,57 +138,60 @@ class AztecText : EditText, TextWatcher, UnknownHtmlSpan.OnUnknownHtmlClickListe
135138 }
136139
137140 private fun init (attrs : AttributeSet ? ) {
138- val array = context.obtainStyledAttributes(attrs, R .styleable.AztecText , 0 , R .style.AztecTextStyle )
141+ val styles = context.obtainStyledAttributes(attrs, R .styleable.AztecText , 0 , R .style.AztecTextStyle )
139142 setLineSpacing(
140- array .getDimension(
143+ styles .getDimension(
141144 R .styleable.AztecText_lineSpacingExtra ,
142145 resources.getDimension(R .dimen.spacing_extra)
143146 ),
144- array .getFloat(
147+ styles .getFloat(
145148 R .styleable.AztecText_lineSpacingMultiplier ,
146149 resources.getString(R .dimen.spacing_multiplier).toFloat()
147150 )
148151 )
149- setBackgroundColor(array.getColor(R .styleable.AztecText_backgroundColor , ContextCompat .getColor(context, R .color.background)))
150- setTextColor(array.getColor(R .styleable.AztecText_textColor , ContextCompat .getColor(context, R .color.text)))
151- setHintTextColor(array.getColor(R .styleable.AztecText_textColorHint , ContextCompat .getColor(context, R .color.text_hint)))
152+ setBackgroundColor(styles.getColor(R .styleable.AztecText_backgroundColor , ContextCompat .getColor(context, R .color.background)))
153+ setTextColor(styles.getColor(R .styleable.AztecText_textColor , ContextCompat .getColor(context, R .color.text)))
154+ setHintTextColor(styles.getColor(R .styleable.AztecText_textColorHint , ContextCompat .getColor(context, R .color.text_hint)))
155+
156+ drawableLoading = styles.getResourceId(R .styleable.AztecText_drawableLoading , R .drawable.ic_image_loading)
157+ drawableFailed = styles.getResourceId(R .styleable.AztecText_drawableFailed , R .drawable.ic_image_failed)
152158
153- historyEnable = array .getBoolean(R .styleable.AztecText_historyEnable , historyEnable)
154- historySize = array .getInt(R .styleable.AztecText_historySize , historySize)
159+ historyEnable = styles .getBoolean(R .styleable.AztecText_historyEnable , historyEnable)
160+ historySize = styles .getInt(R .styleable.AztecText_historySize , historySize)
155161
156162 inlineFormatter = InlineFormatter (this ,
157163 InlineFormatter .CodeStyle (
158- array .getColor(R .styleable.AztecText_codeBackground , 0 ),
159- array .getFraction(R .styleable.AztecText_codeBackgroundAlpha , 1 , 1 , 0f ),
160- array .getColor(R .styleable.AztecText_codeColor , 0 )),
164+ styles .getColor(R .styleable.AztecText_codeBackground , 0 ),
165+ styles .getFraction(R .styleable.AztecText_codeBackgroundAlpha , 1 , 1 , 0f ),
166+ styles .getColor(R .styleable.AztecText_codeColor , 0 )),
161167 LineBlockFormatter .HeaderStyle (
162- array .getDimensionPixelSize(R .styleable.AztecText_blockVerticalPadding , 0 )))
168+ styles .getDimensionPixelSize(R .styleable.AztecText_blockVerticalPadding , 0 )))
163169
164170 blockFormatter = BlockFormatter (this ,
165171 BlockFormatter .ListStyle (
166- array .getColor(R .styleable.AztecText_bulletColor , 0 ),
167- array .getDimensionPixelSize(R .styleable.AztecText_bulletMargin , 0 ),
168- array .getDimensionPixelSize(R .styleable.AztecText_bulletPadding , 0 ),
169- array .getDimensionPixelSize(R .styleable.AztecText_bulletWidth , 0 ),
170- array .getDimensionPixelSize(R .styleable.AztecText_blockVerticalPadding , 0 )),
172+ styles .getColor(R .styleable.AztecText_bulletColor , 0 ),
173+ styles .getDimensionPixelSize(R .styleable.AztecText_bulletMargin , 0 ),
174+ styles .getDimensionPixelSize(R .styleable.AztecText_bulletPadding , 0 ),
175+ styles .getDimensionPixelSize(R .styleable.AztecText_bulletWidth , 0 ),
176+ styles .getDimensionPixelSize(R .styleable.AztecText_blockVerticalPadding , 0 )),
171177 BlockFormatter .QuoteStyle (
172- array .getColor(R .styleable.AztecText_quoteBackground , 0 ),
173- array .getColor(R .styleable.AztecText_quoteColor , 0 ),
174- array .getFraction(R .styleable.AztecText_quoteBackgroundAlpha , 1 , 1 , 0f ),
175- array .getDimensionPixelSize(R .styleable.AztecText_quoteMargin , 0 ),
176- array .getDimensionPixelSize(R .styleable.AztecText_quotePadding , 0 ),
177- array .getDimensionPixelSize(R .styleable.AztecText_quoteWidth , 0 ),
178- array .getDimensionPixelSize(R .styleable.AztecText_blockVerticalPadding , 0 )
178+ styles .getColor(R .styleable.AztecText_quoteBackground , 0 ),
179+ styles .getColor(R .styleable.AztecText_quoteColor , 0 ),
180+ styles .getFraction(R .styleable.AztecText_quoteBackgroundAlpha , 1 , 1 , 0f ),
181+ styles .getDimensionPixelSize(R .styleable.AztecText_quoteMargin , 0 ),
182+ styles .getDimensionPixelSize(R .styleable.AztecText_quotePadding , 0 ),
183+ styles .getDimensionPixelSize(R .styleable.AztecText_quoteWidth , 0 ),
184+ styles .getDimensionPixelSize(R .styleable.AztecText_blockVerticalPadding , 0 )
179185 ))
180186
181- linkFormatter = LinkFormatter (this , LinkFormatter .LinkStyle (array .getColor(
187+ linkFormatter = LinkFormatter (this , LinkFormatter .LinkStyle (styles .getColor(
182188 R .styleable.AztecText_linkColor , 0 ),
183- array .getBoolean(R .styleable.AztecText_linkUnderline , true )))
189+ styles .getBoolean(R .styleable.AztecText_linkUnderline , true )))
184190
185191 lineBlockFormatter = LineBlockFormatter (this , LineBlockFormatter .HeaderStyle (
186- array .getDimensionPixelSize(R .styleable.AztecText_blockVerticalPadding , 0 )))
192+ styles .getDimensionPixelSize(R .styleable.AztecText_blockVerticalPadding , 0 )))
187193
188- array .recycle()
194+ styles .recycle()
189195
190196 if (historyEnable && historySize <= 0 ) {
191197 throw IllegalArgumentException (" historySize must > 0" )
@@ -674,17 +680,20 @@ class AztecText : EditText, TextWatcher, UnknownHtmlSpan.OnUnknownHtmlClickListe
674680 spans.forEach {
675681 val callbacks = object : Html .ImageGetter .Callbacks {
676682
677- override fun onUseDefaultImage () {
678- // we already have a default image loaded so, noop
683+ override fun onImageFailed () {
684+ replaceImage( ContextCompat .getDrawable(context, drawableFailed))
679685 }
680686
681687 override fun onImageLoaded (drawable : Drawable ? ) {
682688 replaceImage(drawable)
683689 }
684690
685- override fun onImageLoadingFailed () {
686- val drawable = ContextCompat .getDrawable(context, R .drawable.ic_image_failed)
687- replaceImage(drawable)
691+ override fun onImageLoading (drawable : Drawable ? ) {
692+ replaceImage(ContextCompat .getDrawable(context, drawableLoading))
693+ }
694+
695+ override fun onUseDefaultImage () {
696+ // we already have a default image loaded so, noop
688697 }
689698
690699 private fun replaceImage (drawable : Drawable ? ) {
0 commit comments