Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 

This blog is part of 1 Tute Sets.

Android Video Tutorials For Beginners to Learn Mobile App Development
1 3 7
  • Android Image Loading Libraries Video Tutorial

    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1
    • 1.46k
    Comment on it
    Error loading player: No playable sources found

    In this Android Video Tutorial I am guiding about four different libraries for loading images using URL:

    • Universal Image Loader
    • Picasso
    • Glide
    • Fresco

    Along with I am explaining their description, performance and implementation procedure is also added in this tutorial.

     

    You can use these libraries by adding following dependencies and their implementation code:

    1. Universal Image Loader:-

    1. compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
    1. ImageLoaderConfiguration imageLoaderConfiguration = new ImageLoaderConfiguration.Builder(this).build();
    2. ImageLoader imageLoader = ImageLoader.getInstance();
    3. imageLoader.init(imageLoaderConfiguration);
    4.  
    5. DisplayImageOptions options = new DisplayImageOptions.Builder()
    6. .showImageOnLoading(R.drawable.placeholder) // resource or drawable
    7. .showImageForEmptyUri(R.drawable.empty) // resource or drawable
    8. .showImageOnFail(R.drawable.failed) // resource or drawable
    9. .delayBeforeLoading(1000)
    10. .resetViewBeforeLoading(true) // default
    11. .cacheInMemory(true) // default => false
    12. .cacheOnDisk(true) // default => false
    13. .build();
    14.  
    15. imageLoader.displayImage(imageURI, ivImage, options, new ImageLoadingListener() {
    16. @Override
    17. public void onLoadingStarted(String imageUri, View view) {
    18. Toast.makeText(getApplicationContext(), "Loading Started", Toast.LENGTH_SHORT).show();
    19. }
    20.  
    21. @Override
    22. public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
    23. Toast.makeText(getApplicationContext(), "Loading Failed", Toast.LENGTH_SHORT).show();
    24. }
    25.  
    26. @Override
    27. public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
    28. Toast.makeText(getApplicationContext(), "Loading Complete", Toast.LENGTH_SHORT).show();
    29. }
    30.  
    31. @Override
    32. public void onLoadingCancelled(String imageUri, View view) {
    33. Toast.makeText(getApplicationContext(), "Loading Cancelled", Toast.LENGTH_SHORT).show();
    34. }
    35. });


    2. Picasso:-

    1. compile 'com.squareup.picasso:picasso:2.5.2'
    1. Picasso.with(this)
    2. .load(imageURI)
    3. .placeholder(R.drawable.placeholder)
    4. .error(R.drawable.failed)
    5. .into(ivImage);


    3. Glide:-

    1. compile 'com.github.bumptech.glide:glide:3.6.1'
    1. Glide.with(this)
    2. .load(imageURI)
    3. .placeholder(R.drawable.placeholder)
    4. .error(R.drawable.failed)
    5. .into(ivImage);


    4. Fresco:-

    1. compile 'com.facebook.fresco:fresco:0.14.1'
    1. ControllerListener controllerListener = new ControllerListener() {
    2. @Override
    3. public void onSubmit(String id, Object callerContext) {
    4. Toast.makeText(ImageLoaderActivity.this, "Called before the image request is submitted", Toast.LENGTH_SHORT).show();
    5. }
    6.  
    7. @Override
    8. public void onFinalImageSet(String id, Object imageInfo, Animatable animatable) {
    9. Toast.makeText(ImageLoaderActivity.this, "When final image is loaded", Toast.LENGTH_SHORT).show();
    10. }
    11.  
    12. @Override
    13. public void onIntermediateImageSet(String id, Object imageInfo) {
    14. Toast.makeText(ImageLoaderActivity.this, "When intermediate image is Loaded", Toast.LENGTH_SHORT).show();
    15. }
    16.  
    17. @Override
    18. public void onIntermediateImageFailed(String id, Throwable throwable) {
    19. Toast.makeText(ImageLoaderActivity.this, "While intermediate image loading failed", Toast.LENGTH_SHORT).show();
    20. }
    21.  
    22. @Override
    23. public void onFailure(String id, Throwable throwable) {
    24. Toast.makeText(ImageLoaderActivity.this, "Image Loading failed", Toast.LENGTH_SHORT).show();
    25. }
    26.  
    27. @Override
    28. public void onRelease(String id) {
    29. Toast.makeText(ImageLoaderActivity.this, "When controller releases the fetched Image", Toast.LENGTH_SHORT).show();
    30. }
    31. };
    32.  
    33. Uri imageUri = Uri.parse(imageURI);
    34. DraweeController controller = Fresco.newDraweeControllerBuilder()
    35. .setUri(imageUri)
    36. .setControllerListener(controllerListener)
    37. .setAutoPlayAnimations(true)
    38. .build();
    39.  
    40. sdvImage.setController(controller);

     

    I had also attached image loader demo file, you can download it for further reference.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: