Android Open Source - listmyaps Icon Loader Task






From Project

Back to project page listmyaps.

License

The source code is released under:

Apache License

If you think the Android project listmyaps 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 de.onyxbits.listmyapps;
/*from   ww w  .j  av  a  2  s . c o m*/
import java.lang.ref.WeakReference;


import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.view.View;
import android.widget.ImageView;

/**
 * Helper for loading images without blocking the UI thread.
 * 
 * @author patrick
 * 
 */
class IconLoaderTask extends AsyncTask<ApplicationInfo, Void, Drawable> {
  private final WeakReference<ImageView> imageViewReference;
  

  private PackageManager packageManager;
  
  public IconLoaderTask(PackageManager pm, ImageView imageView) {
    // Use a WeakReference to ensure the ImageView can be garbage collected
    imageViewReference = new WeakReference<ImageView>(imageView);
    this.packageManager = pm;
  }

  // Decode image in background.
  @Override
  protected Drawable doInBackground(ApplicationInfo... params) {
    return params[0].loadIcon(packageManager);
  }

  // Once complete, see if ImageView is still around and set bitmap.
  @Override
  protected void onPostExecute(Drawable drawable) {
    if (imageViewReference != null) {
      final ImageView imageView = imageViewReference.get();
      if (imageView != null) {

        if (drawable != null) {
          imageView.setImageDrawable(drawable);
        }
      }
    }
  }
}




Java Source Code List

de.onyxbits.listmyapps.AnnotationsActivity.java
de.onyxbits.listmyapps.AnnotationsSource.java
de.onyxbits.listmyapps.AppAdapter.java
de.onyxbits.listmyapps.AppRater.java
de.onyxbits.listmyapps.IconLoaderTask.java
de.onyxbits.listmyapps.ListTask.java
de.onyxbits.listmyapps.MainActivity.java
de.onyxbits.listmyapps.Schema.java
de.onyxbits.listmyapps.SortablePackageInfo.java
de.onyxbits.listmyapps.TagSelectionListener.java
de.onyxbits.listmyapps.TemplateData.java
de.onyxbits.listmyapps.TemplateEditorActivity.java
de.onyxbits.listmyapps.TemplateSource.java
de.onyxbits.listmyapps.TemplatesActivity.java
de.onyxbits.listmyapps.ViewHolder.java