package com.nostra13.example.universalimageloader.widget;

import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.RemoteViews;

import com.nostra13.example.universalimageloader.R;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.SimpleImageLoadingListener;

/**
 * Example widget provider
 * 
 * @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
 */
public class UILWidgetProvider extends AppWidgetProvider {
	@Override
	public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
		// Initialize ImageLoader with configuration.
		ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
				.threadPoolSize(3)
				.threadPriority(Thread.NORM_PRIORITY - 2)
				.memoryCacheSize(1500000) // 1.5 Mb
				.denyCacheImageMultipleSizesInMemory()
				.discCacheFileNameGenerator(new Md5FileNameGenerator())
				.enableLogging() // Not necessary in common
				.build();
		ImageLoader.getInstance().init(config);

		final int N = appWidgetIds.length;
		for (int i = 0; i < N; i++) {
			int appWidgetId = appWidgetIds[i];
			updateAppWidget(context, appWidgetManager, appWidgetId);
		}
	}

	static void updateAppWidget(Context context, final AppWidgetManager appWidgetManager, final int appWidgetId) {
		final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);

		String[] imageUrls = context.getResources().getStringArray(R.array.heavy_images);
		ImageView tempImageView1 = new ImageView(context);
		ImageView tempImageView2 = new ImageView(context);
		tempImageView1.setLayoutParams(new LayoutParams(70, 70)); // 70 - approximate size of ImageView in widget
		tempImageView2.setLayoutParams(new LayoutParams(70, 70)); // 70 - approximate size of ImageView in widget

		ImageLoader.getInstance().displayImage(imageUrls[0], tempImageView1, new SimpleImageLoadingListener() {
			@Override
			public void onLoadingComplete(Bitmap loadedImage) {
				views.setImageViewBitmap(R.id.image_left, loadedImage);
				appWidgetManager.updateAppWidget(appWidgetId, views);
			}
		});
		ImageLoader.getInstance().displayImage(imageUrls[1], tempImageView2, new SimpleImageLoadingListener() {
			@Override
			public void onLoadingComplete(Bitmap loadedImage) {
				views.setImageViewBitmap(R.id.image_right, loadedImage);
				appWidgetManager.updateAppWidget(appWidgetId, views);
			}
		});
	}
}

@@ -207,85 +207,8 @@
 ap;%0A
-import android.view.ViewGroup.LayoutParams;%0Aimport android.widget.ImageView;%0A
 impo
@@ -372,16 +372,83 @@
 erator;%0A
+import com.nostra13.universalimageloader.core.DisplayImageOptions;%0A
 import c
@@ -570,16 +570,80 @@
 ration;%0A
+import com.nostra13.universalimageloader.core.assist.ImageSize;%0A
 import c
@@ -714,16 +714,91 @@
 istener;
+%0Aimport com.nostra13.universalimageloader.core.display.FakeBitmapDisplayer;
 %0A%0A/**%0A *
@@ -946,16 +946,213 @@
 vider %7B%0A
+%0A%09private static DisplayImageOptions optionsWithFakeDisplayer;%0A%0A%09static %7B%0A%09%09optionsWithFakeDisplayer = new DisplayImageOptions.Builder()%0A%09%09%09%09.displayer(new FakeBitmapDisplayer())%0A%09%09%09%09.build();%0A%09%7D%0A%0A
 %09@Overri
@@ -2161,279 +2161,57 @@
 s);%0A
+%0A
 %09%09Image
-View tempImageView1 = new ImageView(context);%0A%09%09ImageView tempImageView2 = new ImageView(context);%0A%09%09tempImageView1.setLayoutParams(new LayoutParams(70, 70)); // 70 - approximate size of ImageView in widget%0A%09%09tempImageView2.setLayoutParams(new LayoutParams
+Size minImageSize = new ImageSize
 (70, 70)
 ); /
@@ -2206,17 +2206,16 @@
 (70, 70)
-)
 ; // 70 
@@ -2256,17 +2256,16 @@
  widget%0A
-%0A
 %09%09ImageL
@@ -2280,37 +2280,43 @@
 tInstance().
-displayImage(
+loadImage(context, 
 imageUrls%5B0%5D
@@ -2321,22 +2321,46 @@
 0%5D, 
-temp
+min
 Image
-View1
+Size, optionsWithFakeDisplayer
 , ne
@@ -2621,21 +2621,27 @@
 e().
-displayImage(
+loadImage(context, 
 imag
@@ -2654,22 +2654,46 @@
 1%5D, 
-temp
+min
 Image
-View2
+Size, optionsWithFakeDisplayer
 , ne

Use ImageLoader.loadImage(...) for widget