Adding Video in Placeholder - android

I want to use a video placeholder before the actual images loads up. I am using a Fullscreen ImageView to load the image but till the time image is loaded to the imageview, i want to show a placeholder video at that place. I am not sure, even if it is feasible or not. If in any case it is feasible, would be looking for the way to get out of this.

Finally got this working, i was able to use GIF animation as my Placeholder using Glide.
Loaded GIF file from drawable resource.
RequestOptions requestOptions = new RequestOptions();
requestOptions.placeholder(R.drawable.placeholder);
Glide.with(context)
.setDefaultRequestOptions(requestOptions)
.load(articlesListChild.get(position).getArticleImage())
.thumbnail(Glide.with(context).load(R.drawable.logo_anim_full)) // This line did the magic
.into(imageContentIv);

Related

How to show Glide images when ready? They are shown incorrectly if not fully downloaded

I am working on an application that has this image gallery activity where images are loaded from disk using Glide. These images are downloaded separately through DownloadManager. The problem is that these images might not have been downloaded by the time the user opens the gallery. I guess one way would be to load these images dynamically once each file gets downloaded by going through a BroadcastReceiver but I am wondering if there is an easier solution? Some of the images only shows parts of itself while others don't show at all, and in order to view the full images I have to navigate back into the gallery so that Glide can redo the loading. I would instead like the images to be displayed once they are able to load. I also tried using a placeholder but it will never be replaced by the image (I would also like to avoid using a placeholder image since I don't have any). The images are displayed in a GridView and loaded in getView method of a BaseAdapter. (Currently I also have to avoid storing the images in cache otherwise the incomplete images will be shown the next time as well). Code:
val file = File(urls[position].toString())
Glide.with(context)
.asBitmap()
.load(file)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.fitCenter()
.apply(RequestOptions())
.into(imageView)

How to display gif in AppIntro library?

I am using the AppIntro https://github.com/apl-devs/AppIntro
library with the default slides builder.
It works great but I am having trouble passing gifs as the drawable for the default builder.
addSlide(AppIntroFragment.newInstance(title, description, image, backgroundColor));
I read that android has issues displaying gif by default and I have to use GifImageLoader or Glide to load the gif.
Glide
.with(context)
.load("imageUrl")
.asGif()
.placeholder(R.drawable.gifImage)
.crossFade()
.into(imageView)
I could try this but I don't have an imageView where I can pass into the argument if I use the default builder.
I also tried GifDrawable gifFromResource = new GifDrawable( getResources(), R.drawable.anim ); from Display Animated GIF but it gives an error.
My next closest option is to create a custom fragment to use with AppIntro and I really don't want to do that.
Is there any way to pass the gif into the default slide builder and have it play?
You can use Simple Target from Glide library. Override onResourceReady() and load this as image in new slide. Please note I have not tried this with gif and have not access to my dev machine now.
Simple Target docs

Android Glide: Show a blurred image before loading actual image

I am developing an Android app which displays full screen images to the user. Images are fetched from the server. I am using Glide to show the image. But I want to display a very small size blurred image before displaying the actual image. Once the image is cached, directly full sized image should be shown.
Image Displaying flows goes like this:
- If image is downloaded for the first time, first download a small scaled image, and then download full resolution image.
- If image has been downloaded before, directly show full scale image.
I cannot find any method in Glide library, which tell me if a file exist in cache or not.
Any idea, how this can be done.
Glide.with(context.getApplicationContext())
.load(Your Path) //passing your url to load image.
.override(18, 18) //just set override like this
.error(R.drawable.placeholder)
.listener(glide_callback)
.animate(R.anim.rotate_backward)
.centerCrop()
.into(image.score);
with Glide v4:
Glide.with(context)
.load(URL)
.thumbnail(0.1f)
.into(image_view)
Better you can get idea from this Library or Use this library.
2 ways to do Blur and Original image in Android.
1) Initially load Blur Image Server URL path and once get success bitmap caching mechanism to load Original(Large) Image Server URL path.
Point 1 is possible, I got answer for you( Ask your server team to get Blur image or Low quality image to make blur and then load large image).
APK Link
Glide.with(mContext)
.load(image.getMedium())
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(new SimpleTarget<Bitmap>() {
#Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
// Do something with bitmap here.
holder.thumbnail.setImageBitmap(bitmap);
Log.e("GalleryAdapter","Glide getMedium ");
Glide.with(mContext)
.load(image.getLarge())
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(new SimpleTarget<Bitmap>() {
#Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
// Do something with bitmap here.
holder.thumbnail.setImageBitmap(bitmap);
Log.e("GalleryAdapter","Glide getLarge ");
}
});
}
});
2) Fresco by Facebook is a new image library for Android. Here’s the official blog post introducing the library. It supports the streaming of progressive JPEG images over the network which can be really helpful to display large images over slow connections. One can see the image gradually improve in quality.
Progressive JPEGs with Facebook Fresco
Use BitmapFactory.Options.inSampleSize to make a downsampled version of the image, and upload both versions. Load the sample image (which should take less time) and when the bigger version is downloaded, switch to that. You could also use a TransitionDrawable to make a fade transition.
this is not a perfect way but it will be easiest way to make it.
make placeHolder image as blur and set it into glide. then always it will show blur image and then after load the actual image it will appear.
you can refer this code to use glide.
//crete this method into your Utils class and call this method wherever you want to use.
//you can set these placeHolder() and error() image static as well. I made it as comment inside this method, then no need to use [placeHolderUrl and errorImageUrl] parameters. remove it from this method.
public static void loadImage(final Activity context, ImageView imageView, String url, int placeHolderUrl, int errorImageUrl) {
if (context == null || context.isDestroyed()) return;
//placeHolderUrl=R.drawable.ic_user;
//errorImageUrl=R.drawable.ic_error;
Glide.with(context) //passing context
.load(getFullUrl(url)) //passing your url to load image.
.placeholder(placeHolderUrl) //this would be your default image (like default profile or logo etc). it would be loaded at initial time and it will replace with your loaded image once glide successfully load image using url.
.error(errorImageUrl)//in case of any glide exception or not able to download then this image will be appear . if you won't mention this error() then nothing to worry placeHolder image would be remain as it is.
.diskCacheStrategy(DiskCacheStrategy.ALL) //using to load into cache then second time it will load fast.
.animate(R.anim.fade_in) // when image (url) will be loaded by glide then this face in animation help to replace url image in the place of placeHolder (default) image.
.fitCenter()//this method help to fit image into center of your ImageView
.into(imageView); //pass imageView reference to appear the image.
}
glide has a direct way of doing this :
val thumbnailRequest = Glide.with(this)
.load("https://picsum.photos/50/50?image=0")
Glide.with(this)
.load("https://picsum.photos/2000/2000?image=0")
.thumbnail(thumbnailRequest)
.into(imageThumbnail)
from the blog:
Thumbnails are a dynamic placeholders, that can be loaded from the Internet. Fetched thumbnail will be displayed until the actual request is loaded and processed. If the thumbnail for some reason arrives after the original image, it will be dismissed.
You must have a small-size and a full-size image on your server. You can use Firebase Resize Image Extension if you are using Firebase as your backend. Once you have a small-size image URL and a full-size image URL you can use Glide like this:
Glide.with(context)
.load(fullSizeImageUrl)
.thumbnail(
Glide.with(context)
.load(smallSizeImageUrl)
).into(imageView)
You'll get that blurry effect as the small-size image will be blurry
According to Glide Doc:
.thumbnail()
loads and displays the resource retrieved by the given thumbnail request if it finishes before this request. Best used for loading thumbnail resources that are smaller and will be loaded more quickly than the full size resource. There are no guarantees about the order in which the requests will actually finish. However, if the thumb request completes after the full request, the thumb resource will never replace the full resource.
use BitmapFactory.Options.inSamleSize to load a downsampled version of the image. Then load the bigger image and do a fade transition using a TransitionDrawable
Hope this will Helps you ! Cheers !

loading image into android imageView with ion returns a blurry result

I'm trying to load an image from filesystem into an imageView with the ion library.
When I'm using the following code:
Ion.with(imageView)
.placeholder(R.drawable.placeholder_image)
.error(R.drawable.error_image)
.load(uri);
it (sometimes) results in a kind of blurry image.
When not using ion like the following the pictures appear sharply:
imageView.setImageBitmap(BitmapFactory.decodeFile(uri.toString()));
Is there a standard compression coming with ion that I can disable?
Strangely not every picture is blurry when using ion, e.g. I have two identical images, only with another name. When I load them into the imageView with ion one is blurry, one is not.
Any help or tips are appreciated!
Ion tries to load the image to fit the bounds of the ImageView. So make sure your ImageView is sized properly in your layout. Alternatively, if you use adjustViewBounds=true to indicate the ImageView is adjusted by the image contents, it won't do that. Or alternatively smartsize(false).
Try this,
Ion.with(context)
.load(url)
.withBitmap()
.placeholder(R.drawable.placeholder_image)
.error(R.drawable.error_image)
.intoImageView(imageView);

Glide doesn't set GlideDrawable into ImageView after loading image

I'm loading images using Glide this way in a Fragment
Glide.with(this).load(pictureUrl)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.default)
.into(image);
but the image is never set into the ImageView although the image IS indeed being loaded (I investigated this using a listener). I believe this only happens when the image is not being loaded from memory since it does load if the Fragment is resumed.
If I add asBitmap() above, then the image successfully loads. Also, setting the GlideDrawable into the ImageView from an attached RequestListener's onResourceReady() method also works.
For anyone else with a similar problem, it turned out to be related to a custom View. See the post on the discussion list for more information.

Categories

Resources