Universal Image Loader is too slow - java

I am trying to show images from URL.
In my code I used, imageLoader.get function but loading images are too slow.
imageLoader.get(c.getImgUrl(), ImageLoader.getImageListener(holder.mImage, R.drawable.img_loading, R.drawable.img_loading)); //450x200 px images.
Then I tried to compress but the problem is still alive.
imageLoader.get(c.getImgUrl(), ImageLoader.getImageListener(holder.mImage, R.drawable.img_loading, R.drawable.img_loading),225,100);
Besides, images are not shown in correct order firstly. When I scroll down(I show 20 images at the same time with recycler view), at first glance it shows images in wrong order. After 3-4 seconds, it shows correctly. Images changes automatically if I scroll down.
As a result, How can I solve my problem? How to speed up? How to show in correct order at first glance?

You can use Glide for that which is far better in memory consumption than compared to other libraries. Also, it provides the diskCacheStrategy, imageResizing, centerCropping, placeholder for the image if not available and can set error image or message if error loading image occurs.
Below is the latest dependency you can include in you app level build.gradle file:
implementation 'com.github.bumptech.glide:glide:4.7.1'

you can use Picasso image library easy to use
http://square.github.io/picasso/

Related

CodenameOne - Importing set of images in the theme

My CodenameOne app is mainly intended to be the iOS counterpart of an existing Android app. It is for older devices, in fact, as soon as possible, or in the future, a Swift app is going to replace it for OS 14>.
I need some customised icons and I have the svg code for it.
Initially I had to use the Flamingo tool, that converts svg files in Java classes.
I used it like
ScaleImageButton appButton=new ScaleImageButton(new AppIcon().scaled(doubleButtonSize,doubleButtonSize).toImage());
It is cumbersome but it does not even work on iOS.
So now I resorted to create png images for every icon in every dpi level, as it can also be done on Android.
I renamed the files so they follow the standard I think it is proposed in CodenameOne.
The possible names are:
verylow.png
low.png
medium.png
high.png
veryhigh.png
560.png
hd.png
2hd.png
4k.png
In the end it has to be used like
Image icon = theme.getImage("icon.png");
It seems that the images can be imported in the project in more than one way.
I was said to include them in the theme.
According to the CN1 developer guide I have to set the size for each.
If I import them as a whole (selecting the folder or selecting all images and hitting the "Open" button) in the theme editor a dialog appears with all wrong sizes (but they resemble a particular set of choice, although very unlikely).
They are not always the same sizes but neither they are defaulted according to the provided set of images.
I provide images as 24px, 36px, 48px, 72px, 96px, 144px, 192px, 288px, 384px for normal size icons, and also I provide double sized images for double size icons in my app (the values are not doubled as expected).
I also have to check "Square image" and "Preserve aspect ratio" options (my images are already square).
Then the strangest part is that there is a percentage, I see it is 20 for example.
The caption reads "will affect all entries". I understood that it is to scale images, that is what a developer just do not want, unless the developer has wrong sizes, but still proportioned among themselves, that cannot be the case I think.
However I do not need any scaling, the images are right as they are. I created them on purpose.
The developer guide is not enough clear to me.
So I am asking
is it right to tweak the wrong size to match the right ones, and what about the percentage?
This specific UI is a bit out of date by now and wasn't used much even when it was added. Most users opted to do desktop scaling for multi images.
The scale option is designed to scale down from a high resolution image on the desktop. You don't want/need that.
You don't need to edit the file. Just make sure to turn on the XML team mode and make sure your images use the right file names. Then once you save the images will appear in the resource file.
I suggest adding a multi-image using the standard method of add in the menu. Then replacing all the generated images with your copies and reopening the file, then saving again (the last save is important as it will override the res file).

ImageView causes lag

I have a ImageView in my app. Everything was fine with the first version of my image:
Version 1 of image. But when I updated the image: Version 2 of image, my GUI starts to lag!
For example the animation of a button-click is just displayed with 3~4 frames!
But for me it makes no sense. Both images are png and have a transparent background. The image that causes the lags is even smaller than the old one.
Move the image to a drawable-nodpi folder and see if it makes a difference. Ideally you should put different size images for different resolutions in different folders so that scaling does not cause lags.
You cannot use larger image like that. Because of size the phone lag so much.
In my experience i use the following rules:
if image bigger than 1080x1920 (today many phone has similar resolution) I convert image into a JPG image
if smaller, I keep going to use PNG

How do I load all images using Universal Image Loader whether they're on screen or not?

I want to make my Universal Image Loader project work as fast as Quickpic. In order to do so, I want to start caching my images before they're ever shown on screen. Right now they only load when I can see them. Any ideas? I'm using their gridview

Best way to store and display images in Android

I am developing an application which can edit images. At the start of my program the user sees a list of folders that contain images. Instead of showing default folder icon i am showing an image from folder. I have database where i store path to images and information about which image is displaying in the list near the folder name. Every time when my application starts it takes a lot of time to load a scaled down image into memory and then display it, especially when there are a lot of folders with images and for each i need to load its icon. I have read this article http://developer.android.com/training/displaying-bitmaps/index.html and every time when my app starts i am scaling down every image.
May be the best way in this situation is to resize (not scale down) every image and then store it in the database? But i have read that this is not good.
So i want to ask an advice of how to do in this case? And i also need an advice of how to optimize displaying images in the Android Galllery widget to make it scrolling more faster. Thank you very much!
1 Never store images in database. It is inefficient and slow.
2 There are several image loading libraries that solve the same problem. My favorites are Picasso and Universal Image Loader

work on Samsung but blank screen on Nexus 7

Happy New Year,
I am developing my application by following This tutorial (using LibGdx, extents Game, with AbstractScreen, using Stage). However, currently I am experiencing a very funny issue. Everything display correct on my Samsung phone but not on my ASUS Nexus 7. Please see this link for the recorded video (MP4: ~800kb) of both devices. As you can see from the Samsung phone, you can see the “Fullmoon Inc.” splash screen (~25 secs). However, my nexus 7 display nothing at all even though I am sure that my application is running on my nexus 7 (sound played on certain timeframe). I tried to update my nexus 7, reset back to factory default, run on empty profile, still no luck at all. I am absolutely no idea what to do to fix it.
Another thing is that the loading bar on the loading screen (from 5secs – 23secs) is not display correctly. According to the following code, the loading bar (the yellow windows) should load in a smooth manner. However, as per what you can see on the video, it is not. Currently the bar only display "After" everything is loaded. Can anyone please lead me back to the correct path?
loadingPercent = Interpolation.linear.apply(loadingPercent, thisApps.assetManager.getProgress(), 0.1f);
this.loadingYellowBox.setWidth(-1040 + (int) (loadingPercent * 1040));
Thank you very much, and all comments are welcome.
I can answer the second part of question. AssetManager calculates percent based om number of asssets not on their size. Suppose you have huge texture atlas which is packed in one texture and several other small resources. Loading of the atlas takes 9 seconds and there are 4 other small resource which take 1 second to load.
So, see what happens. You have 20%-20%-20%-20%-20% when you expect 90%-10&.
If you want to more precise percentage you need to calculate percentage some other way.
Blank screen glitch is trickier. You need to check that Stage is properly initialized, aspect ratio is correct, resources are loaded correctly. You can download source code for libgdx, add it to your project and go through render method with debugger. If you find something suspicious there you can update this post or create a new one.
i finally figured out where the problem came from. the issue is that when i pack all my images, i set the Max page width and Max page height to 4086. i am guessing that somehow Nexus did not "really" load those images. problem solved when i reduced both Max page width and Max page height to 2048. anyway, i still appreciated helps from both #noone and #son-of-the-northern-darkness

Categories

Resources