Android Open Source - com.elsewhat.android.slideshow Queueable Photo Object






From Project

Back to project page com.elsewhat.android.slideshow.

License

The source code is released under:

Copyright (C) 2012 Dagfinn Parnas <dagfinn.parnas@gmail.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Sof...

If you think the Android project com.elsewhat.android.slideshow listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.elsewhat.android.slideshow.api;
/*from w ww. j  a  va 2s  .c om*/
import java.io.File;
import java.io.IOException;
import java.lang.ref.WeakReference;

import com.elsewhat.android.slideshow.R;

import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;


/**
 * Queueable object that cause a heavy file IO read load (300-2000 ms)
 * 
 * Will use WeakReferences in order to make sure objects are still needed when it is ready for processing
 * 
 * @author dagfinn.parnas
 *
 */
public class QueueablePhotoObject implements AsyncQueueableObject {
  protected SlideshowPhoto slideshowPhoto;
  protected File rootFolder;
  protected WeakReference<View> weakRefslideshowView;
  protected ImageView myImageView;
  protected boolean wasGarbageCollected = false;
  protected boolean wasOutOfMemory = false;
  protected Drawable result;
  protected String tagOnCompletion=null;
  protected int maxWidth;
  protected int maxHeight;

  /**
   * Constructor The View is stored as a WeakReference
   * 
   * @param slideshowPhoto
   * @param imageView
   */
  public QueueablePhotoObject(SlideshowPhoto slideshowPhoto,
      View slideshowView, File rootFolder, String tagOnCompletion, int maxWidth, int maxHeight) {
    this.slideshowPhoto = slideshowPhoto;
    this.rootFolder = rootFolder;
    this.weakRefslideshowView = new WeakReference<View>(slideshowView);
    this.tagOnCompletion=tagOnCompletion;
    this.maxWidth=maxWidth;
    this.maxHeight=maxHeight;
  }

  /**
   * Perform the operation of reading the photo from file in the background
   * 
   */
  @Override
  public void performOperation() {
    View slideshowView = weakRefslideshowView.get();
    if (slideshowView == null) {
      wasGarbageCollected = true;
      return;
    } else {
      try {
        result= slideshowPhoto.getLargePhotoDrawable(rootFolder,maxWidth,maxHeight);
        return;
      } catch (OutOfMemoryError e) {
        Log.i("QueueablePhotoObject",
        "Out of memory while getting drawable");
        wasOutOfMemory = true;
        return;
      } catch (IOException e2) {
        Log.i("QueueablePhotoObject",
        "IOException file reading photo "+ slideshowPhoto,e2);
        wasOutOfMemory = true;
      }
    }
  }  
  
  /**
   * Handle operation results will be run on the UI thread 
   * and will be responsible for setting the read drawable to the ImageView drawable 
   * 
   */
  @Override
  public void handleOperationResult() {
    View slideshowView = weakRefslideshowView.get();
    
    
    if(wasOutOfMemory){
      return;
    }else if(wasGarbageCollected){
      return;
    }else if (slideshowView == null) {
      Log
          .d("QueueablePhotoObject",
              "Drawable loaded, but imageview has been garbage collected since read started");
      return;
    } else {
      ImageView imageView = (ImageView)slideshowView.findViewById(R.id.slideshow_photo);  
      imageView.setImageDrawable(result);
      if(tagOnCompletion!=null){
        imageView.setTag(tagOnCompletion);
      }
      imageView.requestLayout();
      return;
    }
  }

  

  
  
  public String toString(){
    if(slideshowPhoto!=null){
      return "QueueablePhotoObject:"+slideshowPhoto.getTitle();
    }else {
      return super.toString();
    }
  }

}




Java Source Code List

com.elsewhat.android.slideshow.activities.ChromecastAddin.java
com.elsewhat.android.slideshow.activities.ISlideshowInstance.java
com.elsewhat.android.slideshow.activities.SlideshowActivity.java
com.elsewhat.android.slideshow.activities.SlideshowDreamService.java
com.elsewhat.android.slideshow.activities.SlideshowPreferences.java
com.elsewhat.android.slideshow.api.Analytics.java
com.elsewhat.android.slideshow.api.AndroidUtils.java
com.elsewhat.android.slideshow.api.AsyncQueueableObject.java
com.elsewhat.android.slideshow.api.AsyncReadQueue.java
com.elsewhat.android.slideshow.api.CustomGallery.java
com.elsewhat.android.slideshow.api.DeletablePreference.java
com.elsewhat.android.slideshow.api.DownloadableObject.java
com.elsewhat.android.slideshow.api.FileDownloader.java
com.elsewhat.android.slideshow.api.FileUtils.java
com.elsewhat.android.slideshow.api.FlingKeyEvent.java
com.elsewhat.android.slideshow.api.ImageAdapter.java
com.elsewhat.android.slideshow.api.QueueablePhotoObject.java
com.elsewhat.android.slideshow.api.ReadOnlyPreference.java
com.elsewhat.android.slideshow.api.SlideshowBackend.java
com.elsewhat.android.slideshow.api.SlideshowPhotoCached.java
com.elsewhat.android.slideshow.api.SlideshowPhotoDrawable.java
com.elsewhat.android.slideshow.api.SlideshowPhoto.java
com.elsewhat.android.slideshow.backend.FlickrPublicSetBackend.java
com.elsewhat.android.slideshow.backend.OPMLBackend.java
com.elsewhat.android.slideshow.backend.SmugMugRecentBackend.java