Search in sources :

Example 16 with ImageSize

use of com.nostra13.universalimageloader.core.assist.ImageSize in project fdroidclient by f-droid.

the class NotificationHelper method getLargeIconForEntry.

private Bitmap getLargeIconForEntry(AppUpdateStatusManager.AppUpdateStatus entry) {
    final Point largeIconSize = getLargeIconSize();
    Bitmap iconLarge = null;
    if (TextUtils.isEmpty(entry.app.iconUrl)) {
        return null;
    } else if (entry.status == AppUpdateStatusManager.Status.Downloading || entry.status == AppUpdateStatusManager.Status.Installing) {
        Bitmap bitmap = Bitmap.createBitmap(largeIconSize.x, largeIconSize.y, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        Drawable downloadIcon = ContextCompat.getDrawable(context, R.drawable.ic_notification_download);
        if (downloadIcon != null) {
            downloadIcon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
            downloadIcon.draw(canvas);
        }
        return bitmap;
    } else if (DiskCacheUtils.findInCache(entry.app.iconUrl, ImageLoader.getInstance().getDiskCache()) != null) {
        iconLarge = ImageLoader.getInstance().loadImageSync(entry.app.iconUrl, new ImageSize(largeIconSize.x, largeIconSize.y));
    } else {
        // Load it for later!
        ImageLoader.getInstance().loadImage(entry.app.iconUrl, new ImageSize(largeIconSize.x, largeIconSize.y), new ImageLoadingListener() {

            AppUpdateStatusManager.AppUpdateStatus entry;

            ImageLoadingListener init(AppUpdateStatusManager.AppUpdateStatus entry) {
                this.entry = entry;
                return this;
            }

            @Override
            public void onLoadingStarted(String imageUri, View view) {
            }

            @Override
            public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
            }

            @Override
            public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                // Need to check that the notification is still valid, and also that the image
                // is indeed cached now, so we won't get stuck in an endless loop.
                AppUpdateStatusManager.AppUpdateStatus oldEntry = appUpdateStatusManager.get(entry.getUniqueKey());
                if (oldEntry != null && oldEntry.app != null && oldEntry.app.iconUrl != null && DiskCacheUtils.findInCache(oldEntry.app.iconUrl, ImageLoader.getInstance().getDiskCache()) != null) {
                    // Update with new image!
                    createNotification(oldEntry);
                }
            }

            @Override
            public void onLoadingCancelled(String imageUri, View view) {
            }
        }.init(entry));
    }
    return iconLarge;
}
Also used : Bitmap(android.graphics.Bitmap) ImageLoadingListener(com.nostra13.universalimageloader.core.listener.ImageLoadingListener) ImageSize(com.nostra13.universalimageloader.core.assist.ImageSize) Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable) Point(android.graphics.Point) FailReason(com.nostra13.universalimageloader.core.assist.FailReason) View(android.view.View)

Example 17 with ImageSize

use of com.nostra13.universalimageloader.core.assist.ImageSize in project Android-Universal-Image-Loader by nostra13.

the class ImageLoader method loadImage.

/**
 * Adds load image task to execution pool. Image will be returned with
 * {@link ImageLoadingListener#onLoadingComplete(String, android.view.View, android.graphics.Bitmap)} callback}.
 * <br />
 * <b>NOTE:</b> {@link #init(ImageLoaderConfiguration)} method must be called before this method call
 *
 * @param uri              Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
 * @param targetImageSize  Minimal size for {@link Bitmap} which will be returned in
 *                         {@linkplain ImageLoadingListener#onLoadingComplete(String, android.view.View,
 *                         android.graphics.Bitmap)} callback}. Downloaded image will be decoded
 *                         and scaled to {@link Bitmap} of the size which is <b>equal or larger</b> (usually a bit
 *                         larger) than incoming targetImageSize.
 * @param options          {@linkplain com.nostra13.universalimageloader.core.DisplayImageOptions Options} for image
 *                         decoding and displaying. If <b>null</b> - default display image options
 *                         {@linkplain ImageLoaderConfiguration.Builder#defaultDisplayImageOptions(DisplayImageOptions)
 *                         from configuration} will be used.<br />
 * @param listener         {@linkplain ImageLoadingListener Listener} for image loading process. Listener fires
 *                         events on UI thread if this method is called on UI thread.
 * @param progressListener {@linkplain com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener
 *                         Listener} for image loading progress. Listener fires events on UI thread if this method
 *                         is called on UI thread. Caching on disk should be enabled in
 *                         {@linkplain com.nostra13.universalimageloader.core.DisplayImageOptions options} to make
 *                         this listener work.
 * @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called before
 */
public void loadImage(String uri, ImageSize targetImageSize, DisplayImageOptions options, ImageLoadingListener listener, ImageLoadingProgressListener progressListener) {
    checkConfiguration();
    if (targetImageSize == null) {
        targetImageSize = configuration.getMaxImageSize();
    }
    if (options == null) {
        options = configuration.defaultDisplayImageOptions;
    }
    NonViewAware imageAware = new NonViewAware(uri, targetImageSize, ViewScaleType.CROP);
    displayImage(uri, imageAware, options, listener, progressListener);
}
Also used : NonViewAware(com.nostra13.universalimageloader.core.imageaware.NonViewAware)

Example 18 with ImageSize

use of com.nostra13.universalimageloader.core.assist.ImageSize in project Android-Universal-Image-Loader by nostra13.

the class BaseImageDecoder method defineImageSizeAndRotation.

protected ImageFileInfo defineImageSizeAndRotation(InputStream imageStream, ImageDecodingInfo decodingInfo) throws IOException {
    Options options = new Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeStream(imageStream, null, options);
    ExifInfo exif;
    String imageUri = decodingInfo.getImageUri();
    if (decodingInfo.shouldConsiderExifParams() && canDefineExifParams(imageUri, options.outMimeType)) {
        exif = defineExifOrientation(imageUri);
    } else {
        exif = new ExifInfo();
    }
    return new ImageFileInfo(new ImageSize(options.outWidth, options.outHeight, exif.rotation), exif);
}
Also used : Options(android.graphics.BitmapFactory.Options) ImageSize(com.nostra13.universalimageloader.core.assist.ImageSize)

Example 19 with ImageSize

use of com.nostra13.universalimageloader.core.assist.ImageSize in project Android-Universal-Image-Loader by nostra13.

the class BaseImageDecoder method considerExactScaleAndOrientatiton.

protected Bitmap considerExactScaleAndOrientatiton(Bitmap subsampledBitmap, ImageDecodingInfo decodingInfo, int rotation, boolean flipHorizontal) {
    Matrix m = new Matrix();
    // Scale to exact size if need
    ImageScaleType scaleType = decodingInfo.getImageScaleType();
    if (scaleType == ImageScaleType.EXACTLY || scaleType == ImageScaleType.EXACTLY_STRETCHED) {
        ImageSize srcSize = new ImageSize(subsampledBitmap.getWidth(), subsampledBitmap.getHeight(), rotation);
        float scale = ImageSizeUtils.computeImageScale(srcSize, decodingInfo.getTargetSize(), decodingInfo.getViewScaleType(), scaleType == ImageScaleType.EXACTLY_STRETCHED);
        if (Float.compare(scale, 1f) != 0) {
            m.setScale(scale, scale);
            if (loggingEnabled) {
                L.d(LOG_SCALE_IMAGE, srcSize, srcSize.scale(scale), scale, decodingInfo.getImageKey());
            }
        }
    }
    // Flip bitmap if need
    if (flipHorizontal) {
        m.postScale(-1, 1);
        if (loggingEnabled)
            L.d(LOG_FLIP_IMAGE, decodingInfo.getImageKey());
    }
    // Rotate bitmap if need
    if (rotation != 0) {
        m.postRotate(rotation);
        if (loggingEnabled)
            L.d(LOG_ROTATE_IMAGE, rotation, decodingInfo.getImageKey());
    }
    Bitmap finalBitmap = Bitmap.createBitmap(subsampledBitmap, 0, 0, subsampledBitmap.getWidth(), subsampledBitmap.getHeight(), m, true);
    if (finalBitmap != subsampledBitmap) {
        subsampledBitmap.recycle();
    }
    return finalBitmap;
}
Also used : ImageScaleType(com.nostra13.universalimageloader.core.assist.ImageScaleType) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) ImageSize(com.nostra13.universalimageloader.core.assist.ImageSize)

Example 20 with ImageSize

use of com.nostra13.universalimageloader.core.assist.ImageSize in project Android-Universal-Image-Loader by nostra13.

the class UILWidgetProvider method updateAppWidget.

static void updateAppWidget(Context context, final AppWidgetManager appWidgetManager, final int appWidgetId) {
    final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
    // 70 - approximate size of ImageView in widget
    ImageSize minImageSize = new ImageSize(70, 70);
    ImageLoader.getInstance().loadImage(IMAGES[0], minImageSize, displayOptions, 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, displayOptions, new SimpleImageLoadingListener() {

        @Override
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
            views.setImageViewBitmap(R.id.image_right, loadedImage);
            appWidgetManager.updateAppWidget(appWidgetId, views);
        }
    });
}
Also used : SimpleImageLoadingListener(com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener) RemoteViews(android.widget.RemoteViews) Bitmap(android.graphics.Bitmap) ImageSize(com.nostra13.universalimageloader.core.assist.ImageSize) View(android.view.View)

Aggregations

ImageSize (com.nostra13.universalimageloader.core.assist.ImageSize)20 Bitmap (android.graphics.Bitmap)11 View (android.view.View)5 Options (android.graphics.BitmapFactory.Options)4 ImageScaleType (com.nostra13.universalimageloader.core.assist.ImageScaleType)4 File (java.io.File)4 ImageView (android.widget.ImageView)3 SimpleImageLoadingListener (com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener)3 Matrix (android.graphics.Matrix)2 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 DisplayMetrics (android.util.DisplayMetrics)2 RemoteViews (android.widget.RemoteViews)2 DisplayImageOptions (com.nostra13.universalimageloader.core.DisplayImageOptions)2 FailReason (com.nostra13.universalimageloader.core.assist.FailReason)2 ImageDecodingInfo (com.nostra13.universalimageloader.core.decode.ImageDecodingInfo)2 NonViewAware (com.nostra13.universalimageloader.core.imageaware.NonViewAware)2 Intent (android.content.Intent)1 Canvas (android.graphics.Canvas)1 Point (android.graphics.Point)1 Drawable (android.graphics.drawable.Drawable)1