Picasso vs. Setting src to ImageView via XML - java

Is there a difference between using Picasso to put an image into an ImageView and just using android:src in the xml of the imageview? Right now I have an app that contains about 500 images, and I set them all using android:src in XML. Should I be using Picasso for something like this? Am I wasting precious memory?

Picasso is mainly used to load image from the network. You all your images are resources of your application; you can safely set them in the XML.

I think there may still be some advantages to using picasso even for loading local resources. I think you would still get the caching which might speed up certain operations. For example maybe you get a memory cached image when you switch back and forth between two activities, or scroll in and out of view.
The following is from the Picasso web site. I am thinking Square saw some value in this otherwise I don't know that they would have implemented this.
RESOURCE LOADING
Resources, assets, files, content providers are all supported as image sources.
Picasso.with(context).load(R.drawable.landing_screen).into(imageView1);
Picasso.with(context).load(new File(...)).into(imageView2);

Related

AWS S3 and Cloudfront for storage of images

I'm using AWS S3 for storage my images and accessing them by Cloudfront. Here is mine access url formate. For example:
http://mybucket.s3.amazonaws.com/qGdyRHeptWqR5sl.jpg
I want to use thumbnail for this image. Generating thumbnails at upload time is not modern approach especially when you are required a lot of different size images. It's not good in maintenance point of view. A little change in design required to regenerate all of thumbnails again.
Is there any possibility for thumbnail image to be generated on the fly by just requesting a URL something like below:
http://mybucket.s3.amazonaws.com/thumb/200/150/qGdyRHeptWqR5sl.jpg
OR
http://mybucket.s3.amazonaws.com/qGdyRHeptWqR5sl.jpg?size=200x200
OR
http://mybucket.s3.amazonaws.com/qGdyRHeptWqR5sl.jpg?width=200&height=200
I've tried all the above url but no success. DO i need to use some image resizing plugin to do so? Do i need to request image from cloudefront & resize it then reupload it on S3?
I'm using Java as programming language please recommend me some plugin or better approach in this case.
One of possible solutions related to ngx_http_image_filter_module plugin for Nginx. You can install Nginx and configure it to resize images from S3 by request.
Here is article which describe how to do it.

Best way to download images on Android

I'm developing an Android application which uses several images and I would like transfer bigger images (2-6 MB) on a web server to download them when need.
I've never tried it before so I've found a method which uses AsyncTask to download images on button click, is this the best solution?
Any better options or opinions?
EDIT: I'm trying koush's ion
EDIT 2: I tried ion (https://github.com/koush/ion) and I like it here very well, very easy to use. advised
Use Universal image loader for downloading images asynchronously.
[https://github.com/nostra13/Android-Universal-Image-Loader][1].
The Library itself has a sample code to download image.you may refer it..
[1]: https://github.com/nostra13/Android-Universal-Image-Loader
After downloading library add library with your project and insert the below code at necessary place
String final_url="www.google.com/.....";
ImageView image;
ImageLoader imageloader = ImageLoader.getInstance();
imageloader.init(ImageLoaderConfiguration.createDefault(context));
DisplayImageOptions options; = new DisplayImageOptions.Builder()
.showImageForEmptyUri(R.drawable.ic_empty)
.showImageOnFail(R.drawable.ic_error)
.resetViewBeforeLoading(true).cacheOnDisk(true)
.imageScaleType(ImageScaleType.EXACTLY)
.bitmapConfig(Bitmap.Config.RGB_565).considerExifParams(true)
.cacheInMemory(true)
.displayer(new FadeInBitmapDisplayer(300)).build();
imageloader.displayImage(final_url, image);
I strongly recommend to use Glide or Picasso, which are the most used libraries nowadays.
Just google "Glide for Android" or "Picasso for Android" and they take care of the threading, caching, optimization, etc.
I hope it helps!
Best practice:
http://developer.android.com/training/displaying-bitmaps/index.html.
Useful libraries:
Picasso - http://square.github.io/picasso;
Glide - github.com/bumptech/glide.
Actually the most important reason to useAsyncTask is that you want a mechanism to do a lengthy operation with out blocking your UI. With it you also get rid of managing child thread and synchronization. And that's it. If you want other functionalities, such as bitmap caching, you will have to implement on your own or use some third-party tools.
Use lazy loading images for this and use image caching.This is the best way to do it.
https://github.com/thest1/LazyList
http://androidexample.com/Download_Images_From_Web_And_Lazy_Load_In_ListView_-_Android_Example/index.php?view=article_discription&aid=112&aaid=134
http://sunil-android.blogspot.in/2013/09/lazy-loading-image-download-from.html
You can find some more examples for lazyloading.Hope the above links are also useful.

where on android to save files downloaded from server

I am downloading a number of images from the server. That happens once in a while (i.e. as needed). I need to know which is more efficient to the operation of my app: do I download the images to a HashMap of images or do I download them and save them as resources in the asset or drawable directory and then access them by id? Please do explain, at least a little, why whichever option is better.
Ideally you need to download all the images to sdcard and store them.
Access them through the file apis and load them using lazy loading to your image views.
If you are going to load all the images in the app resource folders, then it is going to eat up lot of memory. And keep in mind do not cache all the images on to the memory. I would suggest you to use, UniversalImageLoader from my experience. It gives you a bunch of options to play with.

gdx parse layout files to object files

we use libgdx for graphics rendering for our game on android. Seems like libgdx can drop support for layout files in the future. Disadvantages of using layout file is that it take longer to parse it. Advantages being it is very convenient to build UI using it instead of building UI in java files.
So I would like to know if there is a way to parse layout into serializable object files and load these object files in the game instead of layout files. This way if we can maintain a utility, using old gdx library which produces object files from layout files and upgrade gdx in out actual game.
edit : the layout files are of libgdx's not android's
There currently isn't any way to serialize your layout information with libgdx. You will likely need to write your own wrappers and somehow store this layout information, as I don't know of anyone who has done this. If you are using an old version of the library, which still has the tablelayout files, I'm not sure how easy it will be considering the amount of changes which has been made to libgdx since that time. The alternative is to re-write you files using the Java api, which you will likely need to do going forward.
I am not sure how you are still using the tablelayout ui files. They have been deprecated for over a year now and are not included with any of the latest releases of libgdx. If you want a more detailed explanation on what happened to the layout files you can look at this post. I do miss the layout files because of the extra bloat created by having to code the ui formatting. However, I also find you get much finer control over dynamic layouts by using the Java api.

pull path of the screen image

I'm trying to pull the path of a screen image I'm looking at on the android phone of the app im testing. The app shows various pictures. I want to pull the path of the picture to pull the picture name, but have no clue how to start. Any guidance?
edit:
I'm trying to find out if I could pull the path from the app code to see which image the user is viewing. for example. if im looking at an image, I want to know whats the path of the image (path should be coming from someone's harddrive)
there's not necessarily a path for an image. it's better to say the source of the image, be it a file, an HTTP stream, or otherwise. and unfortunately, that info is lost once it's set into an ImageView.
to set the image bits into an ImageView, you construct a Bitmap, usually using one of the decode*() methods in BitmapFactory. that is what determines the source of the image. in your unit test framework, you can get a handle to the ImageView by getting the Activity and calling findViewById(), but that's not going to help you.
there may be other places for you to hook into the code to determine that sources for the image data, but i can't say without knowing your application source code.
you could ask your developers to make the source available in the ImageView's tag (see setTag() / getTag()). that way you could pull it out in your unit tests. of course, you'll have to have an understanding with them as to what the source will be (a URL, a database URI, a file path, ?).

Categories

Resources