use of com.zzhoujay.richtext.callback.OnImageLongClickListener in project RichText by zzhoujay.
the class CachedSpannedParser method handleImage.
private int handleImage(SpannableStringBuilder ssb, ImageGetterWrapper imageGetterWrapper, RichTextConfig config, boolean cached) {
if (cached) {
ClickableImageSpan[] cis = ssb.getSpans(0, ssb.length(), ClickableImageSpan.class);
if (cis != null && cis.length > 0) {
for (ClickableImageSpan ci : cis) {
int start = ssb.getSpanStart(ci);
int end = ssb.getSpanEnd(ci);
ssb.removeSpan(ci);
OnImageClickListener onImageClickListener = null;
OnImageLongClickListener onImageLongClickListener = null;
if (config.clickable > 0) {
onImageClickListener = config.onImageClickListener;
onImageLongClickListener = config.onImageLongClickListener;
}
Drawable drawable = imageGetterWrapper.getDrawable(ci.getSource());
if (drawable == null) {
drawable = new ColorDrawable(Color.TRANSPARENT);
}
ClickableImageSpan nci = new ClickableImageSpan(drawable, ci, onImageClickListener, onImageLongClickListener);
ssb.setSpan(nci, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return cis.length;
}
} else if (!config.noImage) {
ImageSpan[] iss = ssb.getSpans(0, ssb.length(), ImageSpan.class);
if (iss != null && iss.length > 0) {
ArrayList<String> imageUrls = new ArrayList<>(iss.length);
for (int i = 0; i < iss.length; i++) {
ImageSpan imageSpan = iss[i];
String imageUrl = imageSpan.getSource();
imageUrls.add(imageUrl);
int start = ssb.getSpanStart(imageSpan);
int end = ssb.getSpanEnd(imageSpan);
ClickableSpan[] clickableSpans = ssb.getSpans(start, end, ClickableSpan.class);
if (clickableSpans != null && clickableSpans.length != 0) {
for (ClickableSpan cs : clickableSpans) {
ssb.removeSpan(cs);
}
}
OnImageClickListener onImageClickListener = null;
OnImageLongClickListener onImageLongClickListener = null;
if (config.clickable > 0) {
onImageClickListener = config.onImageClickListener;
onImageLongClickListener = config.onImageLongClickListener;
}
Drawable drawable = imageGetterWrapper.getDrawable(imageUrl);
if (drawable == null) {
drawable = new ColorDrawable(Color.TRANSPARENT);
}
ClickableImageSpan cacheImageSpan = new ClickableImageSpan(drawable, imageUrls, i, onImageClickListener, onImageLongClickListener);
ssb.removeSpan(imageSpan);
ssb.setSpan(cacheImageSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return iss.length;
}
}
return 0;
}
Aggregations