Android Open Source - webimageloader Loader Work






From Project

Back to project page webimageloader.

License

The source code is released under:

Apache License

If you think the Android project webimageloader 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.webimageloader.loader;
/*w  w w . ja  v a 2 s.c  om*/
import android.graphics.Bitmap;
import com.webimageloader.ImageLoader;
import com.webimageloader.util.InputSupplier;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Future;

public class LoaderWork {
    private final Loader.Listener listener;
    private final ImageLoader.ProgressListener progressListener;
    private final List<Future<?>> futures;

    private volatile boolean cancelled = false;

    public LoaderWork(Loader.Listener listener, ImageLoader.ProgressListener progressListener) {
        this.listener = listener;
        this.progressListener = progressListener;
        this.futures = new ArrayList<Future<?>>();
    }

    public void cancel() {
        cancelled = true;

        synchronized (futures) {
            for (Future<?> future : futures) {
                future.cancel(false);
            }
        }
    }

    public void start(List<Loader> loaderChain, LoaderRequest request) {
        Iterator<Loader> it = loaderChain.iterator();
        Loader loader = it.next();

        loader.load(new Manager(it, listener), request);
    }

    public class Manager {
        private Iterator<Loader> chain;
        private Loader.Listener listener;

        private Loader nextLoader;

        Manager(Iterator<Loader> chain, Loader.Listener listener) {
            this.chain = chain;
            this.listener = listener;

            if (chain.hasNext()) {
                nextLoader = chain.next();
            }
        }

        public boolean isCancelled() {
            return cancelled;
        }

        public void addFuture(Future<?> future) {
            synchronized (futures) {
                futures.add(future);
            }
        }

        public void next(LoaderRequest request) {
            // Load using old listener
            next(request, listener);
        }

        public void next(LoaderRequest request, Loader.Listener listener) {
            if (!cancelled) {
                Manager nextManager = new Manager(chain, listener);
                nextLoader.load(nextManager, request);
            }
        }

        public void publishProgress(float value) {
            if (!cancelled) {
                progressListener.onProgress(value);
            }
        }

        public void deliverStream(InputSupplier is, Metadata metadata) {
            if (!cancelled) {
                listener.onStreamLoaded(is, metadata);
            }
        }

        public void deliverBitmap(Bitmap b, Metadata metadata) {
            if (!cancelled) {
                listener.onBitmapLoaded(b, metadata);
            }
        }

        public void deliverError(Throwable t) {
            if (!cancelled) {
                listener.onError(t);
            }
        }

        public void deliverNotMotified(Metadata metadata) {
            if (!cancelled) {
                listener.onNotModified(metadata);
            }
        }
    }
}




Java Source Code List

com.webimageloader.ConnectionFactory.java
com.webimageloader.ConnectionHandler.java
com.webimageloader.Constants.java
com.webimageloader.ImageLoaderImpl.java
com.webimageloader.ImageLoader.java
com.webimageloader.Request.java
com.webimageloader.content.ContentURLConnection.java
com.webimageloader.content.ContentURLStreamHandler.java
com.webimageloader.ext.ImageHelper.java
com.webimageloader.ext.ImageLoaderApplication.java
com.webimageloader.loader.BackgroundLoader.java
com.webimageloader.loader.DiskLoader.java
com.webimageloader.loader.LoaderManager.java
com.webimageloader.loader.LoaderRequest.java
com.webimageloader.loader.LoaderWork.java
com.webimageloader.loader.Loader.java
com.webimageloader.loader.MemoryCache.java
com.webimageloader.loader.MemoryLoader.java
com.webimageloader.loader.Metadata.java
com.webimageloader.loader.NetworkLoader.java
com.webimageloader.loader.PendingRequests.java
com.webimageloader.loader.SimpleBackgroundLoader.java
com.webimageloader.loader.TransformingLoader.java
com.webimageloader.sample.AsyncLoader.java
com.webimageloader.sample.ExampleApplication.java
com.webimageloader.sample.FastImageView.java
com.webimageloader.sample.MainActivity.java
com.webimageloader.sample.numbers.NumberDetailsActivity.java
com.webimageloader.sample.numbers.NumbersActivity.java
com.webimageloader.sample.patterns.PatternDetailsActivity.java
com.webimageloader.sample.patterns.PatternsActivity.java
com.webimageloader.sample.patterns.PatternsListFragment.java
com.webimageloader.sample.progress.ProgressActivity.java
com.webimageloader.transformation.ScaleTransformation.java
com.webimageloader.transformation.SimpleTransformation.java
com.webimageloader.transformation.Transformation.java
com.webimageloader.util.AbstractImageLoader.java
com.webimageloader.util.Android.java
com.webimageloader.util.BitmapUtils.java
com.webimageloader.util.FlushedInputStream.java
com.webimageloader.util.Hasher.java
com.webimageloader.util.HeaderParser.java
com.webimageloader.util.IOUtil.java
com.webimageloader.util.InputSupplier.java
com.webimageloader.util.ListenerFuture.java
com.webimageloader.util.LruCache.java
com.webimageloader.util.PriorityThreadFactory.java
com.webimageloader.util.WaitFuture.java