Android Open Source - Android-Universal-Image-Loader-Wrapper U I L Widget Provider






From Project

Back to project page Android-Universal-Image-Loader-Wrapper.

License

The source code is released under:

Apache License

If you think the Android project Android-Universal-Image-Loader-Wrapper 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

/*******************************************************************************
 * Copyright 2011-2013 Sergey Tarasevich
 */*from  www. j  a v  a2 s . c  o  m*/
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
package com.nostra13.example.universalimageloader.widget;

import static com.nostra13.example.universalimageloader.Constants.IMAGES;

import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.RemoteViews;

import com.nostra13.example.universalimageloader.R;
import com.nostra13.example.universalimageloader.UILApplication;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageSize;
import com.nostra13.universalimageloader.core.assist.SimpleImageLoadingListener;
import com.nostra13.universalimageloader.core.display.FakeBitmapDisplayer;

/**
 * Example widget provider
 * 
 * @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
 */
public class UILWidgetProvider extends AppWidgetProvider {

  private static DisplayImageOptions optionsWithFakeDisplayer;

  static {
    optionsWithFakeDisplayer = new DisplayImageOptions.Builder().displayer(new FakeBitmapDisplayer()).build();
  }

  @Override
  public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    UILApplication.initImageLoader(context);

    final int widgetCount = appWidgetIds.length;
    for (int i = 0; i < widgetCount; 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);

    ImageSize minImageSize = new ImageSize(70, 70); // 70 - approximate size of ImageView in widget
    ImageLoader.getInstance().loadImage(IMAGES[0], minImageSize, optionsWithFakeDisplayer, new SimpleImageLoadingListener() {
      @Override
      public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
        views.setImageViewBitmap(R.id.image_left, loadedImage);
        appWidgetManager.updateAppWidget(appWidgetId, views);
      }
    });
    ImageLoader.getInstance().loadImage(IMAGES[1], minImageSize, optionsWithFakeDisplayer, new SimpleImageLoadingListener() {
      @Override
      public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
        views.setImageViewBitmap(R.id.image_right, loadedImage);
        appWidgetManager.updateAppWidget(appWidgetId, views);
      }
    });
  }
}




Java Source Code List

com.nostra13.example.universalimageloader.AbsListViewBaseActivity.java
com.nostra13.example.universalimageloader.BaseActivity.java
com.nostra13.example.universalimageloader.Constants.java
com.nostra13.example.universalimageloader.HomeActivity.java
com.nostra13.example.universalimageloader.ImageGalleryActivity.java
com.nostra13.example.universalimageloader.ImageGridActivity.java
com.nostra13.example.universalimageloader.ImageListActivity.java
com.nostra13.example.universalimageloader.ImagePagerActivity.java
com.nostra13.example.universalimageloader.UILApplication.java
com.nostra13.example.universalimageloader.widget.UILWidgetProvider.java
mobi.sherif.example.universalimageloaderwrapper.ImageLoadingViewActivity.java
mobi.sherif.util.ui.ImageLoadingView.java