Android Open Source - webimageloader Request






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;
//from   w  w  w. j  a va2  s  . c  o m
import java.io.File;
import java.util.EnumSet;

import android.content.ContentResolver;
import android.content.Context;
import android.net.Uri;

import com.webimageloader.loader.LoaderRequest;
import com.webimageloader.transformation.Transformation;

/**
 * Class describing a specific request including transformations to be applied.
 *
 * @author Alexander Blom <alexanderblom.se>
 */
public class Request {
    public enum Flag {
        /**
         * Flag which makes the request ignore any possibly cached bitmaps
         */
        IGNORE_CACHE,
        /**
         * Flag which makes the request don't save its result to cache
         */
        NO_CACHE,
        /**
         * Flag for skipping the disk cache, both for retrieval and storing,
         * useful for images already fetched from disk.
         */
        SKIP_DISK_CACHE
    }

    private String url;
    private Transformation transformation;
    private EnumSet<Flag> flags = EnumSet.noneOf(Flag.class);

    /**
     * Create a request for a resource in /res.
     *
     * Note that this sets the SKIP_DISK_CACHE to skip disk cache
     *
     * @param c the context to use
     * @param resId the resource if
     * @return a request for this resource
     */
    public static Request forResource(Context c, int resId) {
        String url = createUrl(ContentResolver.SCHEME_ANDROID_RESOURCE, c.getPackageName(), String.valueOf(resId));
        return new Request(url).addFlag(Flag.SKIP_DISK_CACHE);
    }

    /**
     * Create a request for an asset in /assets.
     *
     * Note that this sets the SKIP_DISK_CACHE to skip disk cache
     *
     * @param path the path of this asset
     * @return a request for this asset
     */
    public static Request forAsset(String path) {
        String url = createUrl(ContentResolver.SCHEME_FILE, "/android_asset/", path);
        return new Request(url).addFlag(Flag.SKIP_DISK_CACHE);
    }

    /**
     * Create a request for this file on the local file system.
     *
     * Note that this sets the SKIP_DISK_CACHE to skip disk cache
     *
     * @param file path to the file
     * @return a request for this file
     */
    public static Request forFile(File file) {
        String url = Uri.fromFile(file).toString();
        return new Request(url).addFlag(Flag.SKIP_DISK_CACHE);
    }

    /**
     * Constructor for a specific url
     *
     * @param url the url
     */
    public Request(String url) {
        this.url = url;
    }

    /**
     * Constructor for a specific url and transformation
     *
     * @param url the url
     * @param transformation the transformation
     */
    public Request(String url, Transformation transformation) {
        this.url = url;
        this.transformation = transformation;
    }

    public String getUrl() {
        return url;
    }

    public Transformation getTransformation() {
        return transformation;
    }

    /**
     * Create a new request with an added transformation
     *
     * @deprecated Use {@link #setTransformation(Transformation)} instead
     *
     * @param transformation the transformation to apply
     * @return the new request
     */
    @Deprecated
    public Request withTransformation(Transformation transformation) {
        return new Request(url, transformation);
    }

    /**
     * Set the transformation of this request
     *
     * @param transformation the transformation to apply
     * @return this request
     */
    public Request setTransformation(Transformation transformation) {
        this.transformation = transformation;

        return this;
    }

    /**
     * Add a flag to this request
     *
     * @param flag the flag to be added
     * @return this request
     */
    public Request addFlag(Flag flag) {
        flags.add(flag);

        return this;
    }

    /**
     * Add multiple flags to this request
     *
     * @param flags the flags to be added
     * @return this request
     */
    public Request addFlags(EnumSet<Flag> flags) {
        this.flags.addAll(flags);

        return this;
    }

    LoaderRequest toLoaderRequest() {
        return new LoaderRequest(url, transformation, flags);
    }

    private static String createUrl(String scheme, String authority, String path) {
        return scheme + "://" + authority + "/" + path;
    }
}




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