/*
 * Copyright (c) 2011 Bohemian Wrappsody AB
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package com.wrapp.android.webimage;

import android.content.Context;
import android.graphics.BitmapFactory;

import java.net.URL;

/** Endpoint class for all main library tasks. */
@SuppressWarnings({"UnusedDeclaration"})
public class WebImage {
  // Loading Images ////////////////////////////////////////////////////////////////////////////////////////////////////

  /**
   * Load an image from URL to the given listener. This is a non-blocking call which is run in
   * a background thread. It is safe to call this method multiple times; duplicate requests will
   * be ignored.
   * @param context Context used for getting app's package name
   * @param imageUrl URL to load the image from
   * @param listener Object which will be notified when the request is complete
   */
  public static void load(final Context context, URL imageUrl, ImageRequest.Listener listener) {
    ImageLoader.load(context, imageUrl, listener, null);
  }

  /**
   * Load an image from URL to the given listener. This is a non-blocking call which is run in
   * a background thread. It is safe to call this method multiple times; duplicate requests will
   * be ignored.
   * @param context Context used for getting app's package name
   * @param imageUrl URL to load the image from
   * @param listener Object which will be notified when the request is complete
   * @param options Options to use when loading the image. See the documentation for {@link BitmapFactory.Options}
   * for more details. Can be null.
   */
  public static void load(final Context context, URL imageUrl, ImageRequest.Listener listener, BitmapFactory.Options options) {
    ImageLoader.load(context, imageUrl, listener, options);
  }

  // Image Cache Operations ////////////////////////////////////////////////////////////////////////////////////////////

  /**
   * Check to see if an image has already been saved in the file cache. This can be useful when
   * you want to display an animation or other GUI notification in case the image has to be
   * fetched from the net.
   * @param context Context used for getting app's package name
   * @param imageUrl URL to check
   * @return True if the image is in the file cache, false otherwise
   */
  public static boolean isImageCached(final Context context, URL imageUrl) {
    return ImageCache.isImageCached(context, ImageCache.getCacheKeyForUrl(imageUrl));
  }

  /**
   * Remove old files from the file cache. The parent application should call this method once during
   * initialization to prevent the file cache from growing too large.
   * @param context Context used for getting app's package name
   */
  public static void clearOldCacheFiles(final Context context) {
    ImageCache.clearOldCacheFiles(context);
  }

  /**
   * Remove cached files older than this many seconds from the file cache. Call with 0 to remove all
   * files in the cache.
   * @param context Context used for getting app's package name
   * @param cacheAgeInSec Maximum age of file, in seconds
   */
  public static void clearOldCacheFiles(final Context context, long cacheAgeInSec) {
    ImageCache.clearOldCacheFiles(context, cacheAgeInSec);
  }

  /**
   * Remove a single image from the disk cache
   * @param context Context used for getting app's package name
   * @param imageUrl Image URL to remove
   */
  public static void clearImageFromCaches(final Context context, final URL imageUrl) {
    ImageCache.clearImageFromCaches(context, imageUrl);
  }

  // Configuration /////////////////////////////////////////////////////////////////////////////////////////////////////

  /**
   * By default, the WebImage library is silent and will not produce any output to the console. During
   * debugging you may wish to call this method in your app's initialization method to see debugging
   * output to the logcat.
   * @param tag Android logging tag to use
   * @param level Android log level to use
   */
  public static void enableLogging(String tag, int level) {
    LogWrapper.enableLogging(tag, level);
  }

  public static void setMaxDownloadThreads(int value) {
    DownloadThreadPool.setMaxThreads(value);
  }

  // Thread Control Operations /////////////////////////////////////////////////////////////////////////////////////////

  /**
   * Cancel all pending requests. The parent activity should call this method when it is about
   * to be stopped or paused, or else you will waste resources by running in the background.
   */
  public static void cancelAllRequests() {
    ImageLoader.cancelAllRequests();
  }

  public static void onNetworkStatusChanged(Context context) {
    DownloadThreadPool.resizeThreadPool(context);
  }

  /**
   * Stop all background threads. Call this when your activity quits.
   */
  public static void shutdown() {
    ImageLoader.shutdown();
  }
}

@@ -5132,32 +5132,517 @@
 g, level);%0A  %7D%0A%0A
+  /**%0A   * Set the maximum number of threads to be used for downloading images. The actual number of download%0A   * threads varies depending on the phone's network connection. Smaller apps which only load a few%0A   * images may want to set this value to 1.%0A   * Note that this does not effect the total number of threads started by WebImage; there will still%0A   * be other background threads for reading cached images, checking timestamps, etc.%0A   * @param value Number of threads%0A   */%0A
   public static 
@@ -6144,198 +6144,856 @@
 %0A%0A  
-public static void onNetworkStatusChanged(Context context) %7B%0A    DownloadThreadPool.resizeThreadPool(context);%0A  %7D%0A%0A  /**%0A   * Stop all background threads. Call this when your activity quits
+/**%0A   * Call this method to manually force a resize check for the download thread pool size. Normally%0A   * the preferred way of doing this is to instead use the BroadcastReceiver provided by the%0A   * DownloadThreadPool class (see the example app for a demonstration of this).%0A   * However, you may also wish to manually call this, for instance when your application is resumed%0A   * and any network changes may not have been caught by your app.%0A   * @param context Activity's context%0A   */%0A  public static void onNetworkStatusChanged(Context context) %7B%0A    DownloadThreadPool.resizeThreadPool(context);%0A  %7D%0A%0A  /**%0A   * Stop all background threads. Call this when your application quits. Can also be called when%0A   * the app is paused to free up additional resources. Note that the next request to load an%0A   * image will re-inialize the thread pool
 .%0A  

Add some more documentation