use of org.wordpress.android.editor.legacy.WPEditImageSpan in project WordPress-Android by wordpress-mobile.
the class LegacyEditorFragment method loadWPImageSpanThumbnail.
private void loadWPImageSpanThumbnail(MediaFile mediaFile, String imageURL, ImageLoader imageLoader) {
if (mediaFile == null || imageURL == null) {
return;
}
final String mediaId = mediaFile.getMediaId();
if (mediaId == null) {
return;
}
final int maxThumbWidth = ImageUtils.getMaximumThumbnailWidthForEditor(getActivity());
imageLoader.get(imageURL, new ImageLoader.ImageListener() {
@Override
public void onErrorResponse(VolleyError arg0) {
}
@Override
public void onResponse(ImageLoader.ImageContainer container, boolean arg1) {
Bitmap downloadedBitmap = container.getBitmap();
if (downloadedBitmap == null) {
// no bitmap downloaded from the server.
return;
}
if (downloadedBitmap.getWidth() < MIN_THUMBNAIL_WIDTH) {
// Picture is too small. Show the placeholder in this case.
return;
}
Bitmap resizedBitmap;
// resize the downloaded bitmap
resizedBitmap = ImageUtils.getScaledBitmapAtLongestSide(downloadedBitmap, maxThumbWidth);
if (resizedBitmap == null) {
return;
}
final EditText editText = mContentEditText;
Editable s = editText.getText();
if (s == null) {
return;
}
WPImageSpan[] spans = s.getSpans(0, s.length(), WPImageSpan.class);
if (spans.length != 0 && getActivity() != null) {
for (WPImageSpan is : spans) {
MediaFile mediaFile = is.getMediaFile();
if (mediaFile == null) {
continue;
}
if (mediaId.equals(mediaFile.getMediaId()) && !is.isNetworkImageLoaded()) {
// replace the existing span with a new one with the correct image, re-add
// it to the same position.
int spanStart = is.getStartPosition();
int spanEnd = is.getEndPosition();
WPEditImageSpan imageSpan = new WPEditImageSpan(getActivity(), resizedBitmap, is.getImageSource());
imageSpan.setMediaFile(is.getMediaFile());
imageSpan.setNetworkImageLoaded(true);
imageSpan.setPosition(spanStart, spanEnd);
s.removeSpan(is);
s.setSpan(imageSpan, spanStart, spanEnd + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
break;
}
}
}
}
}, 0, 0);
}
use of org.wordpress.android.editor.legacy.WPEditImageSpan in project WordPress-Android by wordpress-mobile.
the class LegacyEditorFragment method createWPEditImageSpanLocal.
private WPEditImageSpan createWPEditImageSpanLocal(Context context, MediaFile mediaFile) {
if (context == null || mediaFile == null || mediaFile.getFilePath() == null) {
return null;
}
Uri imageUri = Uri.parse(mediaFile.getFilePath());
Bitmap thumbnailBitmap;
if (MediaUtils.isVideo(imageUri.toString())) {
thumbnailBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.media_movieclip);
} else {
thumbnailBitmap = ImageUtils.getWPImageSpanThumbnailFromFilePath(context, imageUri.getEncodedPath(), ImageUtils.getMaximumThumbnailWidthForEditor(context));
if (thumbnailBitmap == null) {
// Use a placeholder in case thumbnail can't be decoded (OOM for instance)
thumbnailBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.legacy_dashicon_format_image_big_grey);
}
}
WPEditImageSpan imageSpan = new WPEditImageSpan(context, thumbnailBitmap, imageUri);
mediaFile.setWidth(MediaUtils.getMaximumImageWidth(context, imageUri, mBlogSettingMaxImageWidth));
imageSpan.setMediaFile(mediaFile);
return imageSpan;
}
use of org.wordpress.android.editor.legacy.WPEditImageSpan in project WordPress-Android by wordpress-mobile.
the class LegacyEditorFragment method createWPEditImageSpanRemote.
private WPEditImageSpan createWPEditImageSpanRemote(Context context, MediaFile mediaFile) {
if (context == null || mediaFile == null || mediaFile.getFileURL() == null) {
return null;
}
int drawable = mediaFile.isVideo() ? R.drawable.media_movieclip : R.drawable.legacy_dashicon_format_image_big_grey;
Uri uri = Uri.parse(mediaFile.getFileURL());
WPEditImageSpan imageSpan = new WPEditImageSpan(context, drawable, uri);
imageSpan.setMediaFile(mediaFile);
return imageSpan;
}
Aggregations