Android Open Source - WhatsOnTV Bitmap Downloader Task






From Project

Back to project page WhatsOnTV.

License

The source code is released under:

GNU General Public License

If you think the Android project WhatsOnTV 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 net.oncaphillis.whatsontv;
/*from w  w w  .  j a va  2 s  . c  om*/
import java.lang.ref.WeakReference;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;

class BitmapDownloaderTask extends AsyncTask<String, Void, Bitmap> {

  private final Bitmap    _defBitmap;
  private String          _path;
  private ProgressBar     _pb;
  private WeakReference<ImageView> _imageView;
  private Activity         _act;
  private ProgressBar     _pb_group;
  
    public BitmapDownloaderTask(ImageView imageView, Activity act,ProgressBar pb, Bitmap defBitmap,ProgressBar pb_group) {
        _imageView = new WeakReference<ImageView>(imageView);
        _path      = imageView.getTag().toString();
        _defBitmap = defBitmap; 
        _pb        = pb;
        _act       = act;
        _pb_group  = pb_group;
    }

    @Override
    protected Bitmap doInBackground(String... params) {
      if(_imageView!=null && _imageView.get()!=null &&
          _imageView.get().getTag()!=null &&
          _imageView.get().getTag().toString().equals(_path)) 
        return Tmdb.get().loadPoster(0,_path,_act,_pb);           
      else
        return null;
    }

    @Override
    // Once the image is downloaded, associates it to the imageView
    protected void onPostExecute(Bitmap bm) {
      if(bm!=null && _imageView!=null && _imageView.get()!=null &&
          _imageView.get().getTag()!=null &&
          _imageView.get().getTag().toString().equals(_path)) 
           _imageView.get().setImageBitmap(bm);
    
      if(_pb_group!=null && _pb_group.getTag()!=null) {
        Integer c=(Integer)_pb_group.getTag();
        if(c>0) {
          c--;
          _pb_group.setTag(new Integer(c));
        }
        if(c==0) {
          _pb_group.setVisibility(View.INVISIBLE);
        }
      }
    }
}




Java Source Code List

net.oncaphillis.whatsontv.AboutActivity.java
net.oncaphillis.whatsontv.BitmapDownloaderTask.java
net.oncaphillis.whatsontv.ErrorActivity.java
net.oncaphillis.whatsontv.MainActivity.java
net.oncaphillis.whatsontv.MainFragment.java
net.oncaphillis.whatsontv.MainPagerAdapter.java
net.oncaphillis.whatsontv.Pager.java
net.oncaphillis.whatsontv.SearchActivity.java
net.oncaphillis.whatsontv.SearchThread.java
net.oncaphillis.whatsontv.SeriesCollectionPagerAdapter.java
net.oncaphillis.whatsontv.SeriesObjectFragment.java
net.oncaphillis.whatsontv.SeriesPagerActivity.java
net.oncaphillis.whatsontv.TmdbKey.java
net.oncaphillis.whatsontv.Tmdb.java
net.oncaphillis.whatsontv.TvSeriesListAdapter.java