Search in sources :

Example 1 with AttributesImpl

use of org.ccil.cowan.tagsoup.AttributesImpl in project WordPress-Android by wordpress-mobile.

the class AztecEditorFragment method onMediaUploadSucceeded.

@Override
public void onMediaUploadSucceeded(final String localMediaId, final MediaFile mediaFile) {
    if (!isAdded()) {
        return;
    }
    final MediaType mediaType = mUploadingMedia.get(localMediaId);
    if (mediaType != null) {
        String remoteUrl = Utils.escapeQuotes(mediaFile.getFileURL());
        if (mediaType.equals(MediaType.IMAGE)) {
            AttributesImpl attrs = new AttributesImpl();
            attrs.addAttribute("", "src", "src", "string", remoteUrl);
            // clear overlay
            content.clearOverlays(ImagePredicate.localMediaIdPredicate(localMediaId), attrs);
            content.refreshText();
            mUploadingMedia.remove(localMediaId);
        } else if (mediaType.equals(MediaType.VIDEO)) {
        // TODO: update video element
        }
    }
}
Also used : AttributesImpl(org.ccil.cowan.tagsoup.AttributesImpl)

Example 2 with AttributesImpl

use of org.ccil.cowan.tagsoup.AttributesImpl in project WordPress-Android by wordpress-mobile.

the class AztecEditorFragment method appendMediaFile.

@Override
public void appendMediaFile(final MediaFile mediaFile, final String mediaUrl, ImageLoader imageLoader) {
    final String safeMediaUrl = Utils.escapeQuotes(mediaUrl);
    if (URLUtil.isNetworkUrl(mediaUrl)) {
        if (mediaFile.isVideo()) {
            // TODO: insert video
            ToastUtils.showToast(getActivity(), R.string.media_insert_unimplemented);
        } else {
            // TODO: insert image
            ToastUtils.showToast(getActivity(), R.string.media_insert_unimplemented);
        }
        mActionStartedAt = System.currentTimeMillis();
    } else {
        String localMediaId = String.valueOf(mediaFile.getId());
        if (mediaFile.isVideo()) {
            // TODO: insert local video
            ToastUtils.showToast(getActivity(), R.string.media_insert_unimplemented);
        } else {
            AttributesImpl attrs = new AttributesImpl();
            attrs.addAttribute("", "data-wpid", "data-wpid", "string", localMediaId);
            attrs.addAttribute("", "src", "src", "string", safeMediaUrl);
            // load a scaled version of the image to prevent OOM exception
            int maxWidth = DisplayUtils.getDisplayPixelWidth(getActivity());
            Bitmap bitmapToShow = ImageUtils.getWPImageSpanThumbnailFromFilePath(getActivity(), safeMediaUrl, maxWidth);
            if (bitmapToShow != null) {
                content.insertMedia(new BitmapDrawable(getResources(), bitmapToShow), attrs);
            } else {
                // Use a placeholder
                ToastUtils.showToast(getActivity(), R.string.error_media_load);
                Drawable d = getResources().getDrawable(R.drawable.ic_gridicons_image);
                d.setBounds(0, 0, maxWidth, maxWidth);
                content.insertMedia(d, attrs);
            }
            // set intermediate shade overlay
            content.setOverlay(ImagePredicate.localMediaIdPredicate(localMediaId), 0, new ColorDrawable(getResources().getColor(R.color.media_shade_overlay_color)), Gravity.FILL, attrs);
            Drawable progressDrawable = getResources().getDrawable(android.R.drawable.progress_horizontal);
            // set the height of the progress bar to 2 (it's in dp since the drawable will be adjusted by the span)
            progressDrawable.setBounds(0, 0, 0, 4);
            content.setOverlay(ImagePredicate.localMediaIdPredicate(localMediaId), 1, progressDrawable, Gravity.FILL_HORIZONTAL | Gravity.TOP, attrs);
            content.refreshText();
            mUploadingMedia.put(localMediaId, MediaType.IMAGE);
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) AttributesImpl(org.ccil.cowan.tagsoup.AttributesImpl) ColorDrawable(android.graphics.drawable.ColorDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Aggregations

AttributesImpl (org.ccil.cowan.tagsoup.AttributesImpl)2 Bitmap (android.graphics.Bitmap)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1