use of com.zzhoujay.richtext.drawable.DrawableWrapper in project RichText by zzhoujay.
the class AbstractImageLoader method onLoading.
@Override
public void onLoading() {
if (!activityIsAlive()) {
return;
}
DrawableWrapper drawableWrapper = drawableWrapperWeakReference.get();
if (drawableWrapper == null) {
return;
}
holder.setImageState(ImageHolder.ImageState.LOADING);
drawableWrapper.setDrawable(config.placeHolder);
if (holder.getCachedBound() != null) {
drawableWrapper.setBounds(holder.getCachedBound());
} else {
if (!config.autoFix && config.imageFixCallback != null) {
config.imageFixCallback.onLoading(holder);
}
int width;
int height = 0;
if (config.autoFix || holder.isAutoFix() || !holder.isInvalidateSize()) {
width = getRealWidth();
int ow = config.placeHolder.getBounds().width();
if (ow != 0) {
height = config.placeHolder.getBounds().height() * width / ow;
}
if (height == 0) {
height = width / 2;
}
} else {
width = (int) holder.getScaleWidth();
height = (int) holder.getScaleHeight();
}
drawableWrapper.setBounds(0, 0, width, height);
}
}
use of com.zzhoujay.richtext.drawable.DrawableWrapper in project RichText by zzhoujay.
the class DefaultImageGetter method done.
@Override
public void done(Object from) {
if (from instanceof AbstractImageLoader) {
AbstractImageLoader imageLoader = ((AbstractImageLoader) from);
DrawableWrapper drawableWrapper = (DrawableWrapper) imageLoader.drawableWrapperWeakReference.get();
if (drawableWrapper != null) {
if (imageLoader.config.cacheType > CacheType.NONE) {
cacheBound(imageLoader.holder.getSource(), drawableWrapper.getBounds());
}
if (imageLoader.config.cacheType > CacheType.LAYOUT) {
Drawable drawable = drawableWrapper.getDrawable();
if (drawable instanceof BitmapDrawable) {
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
if (bitmap != null) {
cacheBitmap(imageLoader.holder.getSource(), bitmap);
}
}
}
}
synchronized (lock) {
Cancelable cancelable = taskMap.get(imageLoader);
if (cancelable != null) {
tasks.remove(cancelable);
}
taskMap.remove(imageLoader);
}
loadedCount++;
if (notify != null) {
notify.done(loadedCount);
}
}
}
use of com.zzhoujay.richtext.drawable.DrawableWrapper in project RichText by zzhoujay.
the class DefaultImageGetter method getDrawable.
@Override
public Drawable getDrawable(final ImageHolder holder, final RichTextConfig config, final TextView textView) {
final DrawableWrapper drawableWrapper = new DrawableWrapper();
if (config.cacheType >= CacheType.LAYOUT) {
Rect rect = loadCacheBound(holder.getSource());
if (rect != null) {
holder.setCachedBound(rect);
drawableWrapper.setBounds(rect);
}
} else {
drawableWrapper.setBounds(0, 0, (int) holder.getScaleWidth(), (int) holder.getScaleHeight());
}
if (config.cacheType > CacheType.LAYOUT) {
Bitmap bitmap = loadCacheBitmap(holder.getSource());
if (bitmap != null) {
drawableWrapper.setDrawable(new BitmapDrawable(textView.getResources(), bitmap));
return drawableWrapper;
}
}
Cancelable cancelable;
AbstractImageLoader imageLoader;
if (TextKit.isLocalPath(holder.getSource())) {
LocalFileImageLoader localFileImageLoader = new LocalFileImageLoader(holder, config, textView, drawableWrapper, this);
Future<?> future = getExecutorService().submit(localFileImageLoader);
cancelable = new FutureCancelableWrapper(future);
imageLoader = localFileImageLoader;
} else {
byte[] src = Base64.decode(holder.getSource());
if (src != null) {
Base64ImageLoader base64ImageLoader = new Base64ImageLoader(src, holder, config, textView, drawableWrapper, this);
Future<?> future = getExecutorService().submit(base64ImageLoader);
cancelable = new FutureCancelableWrapper(future);
imageLoader = base64ImageLoader;
} else {
Request builder = new Request.Builder().url(holder.getSource()).get().build();
Call call = getClient().newCall(builder);
CallbackImageLoader callback = new CallbackImageLoader(holder, config, textView, drawableWrapper, this);
cancelable = new CallCancelableWrapper(call);
imageLoader = callback;
call.enqueue(callback);
}
}
checkTarget(textView);
synchronized (lock) {
tasks.add(cancelable);
taskMap.put(imageLoader, cancelable);
}
return drawableWrapper;
}
use of com.zzhoujay.richtext.drawable.DrawableWrapper in project RichText by zzhoujay.
the class GlideImageGetter method done.
@Override
public void done(Object from) {
if (from instanceof ImageTarget) {
ImageTarget imageTarget = (ImageTarget) from;
DrawableWrapper drawableWrapper = (DrawableWrapper) imageTarget.urlDrawableWeakReference.get();
if (drawableWrapper != null && imageTarget.config.cacheType >= CacheType.LAYOUT) {
cache(imageTarget.holder.getSource(), drawableWrapper.getBounds());
}
targets.remove(imageTarget);
loadedCount++;
if (imageLoadNotify != null) {
imageLoadNotify.done(loadedCount);
}
}
}
use of com.zzhoujay.richtext.drawable.DrawableWrapper in project RichText by zzhoujay.
the class ImageTarget method onLoadStarted.
@Override
public void onLoadStarted(Drawable placeholder) {
super.onLoadStarted(placeholder);
if (placeholder == null || !activityIsAlive()) {
return;
}
DrawableWrapper drawableWrapper = urlDrawableWeakReference.get();
if (drawableWrapper == null) {
return;
}
holder.setImageState(ImageHolder.ImageState.LOADING);
drawableWrapper.setDrawable(placeholder);
if (holder.getCachedBound() != null) {
drawableWrapper.setBounds(holder.getCachedBound());
} else {
if (!config.autoFix && config.imageFixCallback != null) {
config.imageFixCallback.onLoading(holder);
}
int width;
int height = 0;
if (config.autoFix || holder.isAutoFix() || !holder.isInvalidateSize()) {
width = getRealWidth();
int ow = placeholder.getBounds().width();
if (ow != 0) {
height = placeholder.getBounds().height() * width / ow;
}
if (height == 0) {
height = width / 2;
}
} else {
width = (int) holder.getScaleWidth();
height = (int) holder.getScaleHeight();
}
drawableWrapper.setBounds(0, 0, width, height);
}
resetText();
}
Aggregations