
* Add `html-parser-api` and `html-parser-impl` modules * Add `HtmlEmptyTagReplacement` * Implement Appendable and CharSequence in SpannableBuilder * Renamed library modules to reflect maven artifact names * Rename `markwon-syntax` to `markwon-syntax-highlight` * Add HtmlRenderer asbtraction * Add CssInlineStyleParser * Fix Theme#listItemColor and OL * Fix task list block parser to revert parsing state when line is not matching * Defined test format files * image-loader add datauri parser * image-loader add support for inline data uri image references * Add travis configuration * Fix image with width greater than canvas scaled * Fix blockquote span * Dealing with white spaces at the end of a document * image-loader add SchemeHandler abstraction * Add sample-latex-math module
61 lines
1.6 KiB
Java
61 lines
1.6 KiB
Java
package ru.noties.markwon.il;
|
|
|
|
import android.content.res.Resources;
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.BitmapFactory;
|
|
import android.graphics.drawable.BitmapDrawable;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.support.annotation.NonNull;
|
|
import android.support.annotation.Nullable;
|
|
|
|
import java.io.InputStream;
|
|
|
|
/**
|
|
* This class can be used as the last {@link MediaDecoder} to _try_ to handle all rest cases.
|
|
* Here we just assume that supplied InputStream is of image type and try to decode it.
|
|
*
|
|
* @since 1.1.0
|
|
*/
|
|
public class ImageMediaDecoder extends MediaDecoder {
|
|
|
|
@NonNull
|
|
public static ImageMediaDecoder create(@NonNull Resources resources) {
|
|
return new ImageMediaDecoder(resources);
|
|
}
|
|
|
|
private final Resources resources;
|
|
|
|
@SuppressWarnings("WeakerAccess")
|
|
ImageMediaDecoder(Resources resources) {
|
|
this.resources = resources;
|
|
}
|
|
|
|
@Override
|
|
public boolean canDecodeByContentType(@Nullable String contentType) {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean canDecodeByFileName(@NonNull String fileName) {
|
|
return true;
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public Drawable decode(@NonNull InputStream inputStream) {
|
|
|
|
final Drawable out;
|
|
|
|
// absolutely not optimal... thing
|
|
final Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
|
|
if (bitmap != null) {
|
|
out = new BitmapDrawable(resources, bitmap);
|
|
DrawableUtils.intrinsicBounds(out);
|
|
} else {
|
|
out = null;
|
|
}
|
|
|
|
return out;
|
|
}
|
|
}
|