Java Code Examples for com.nostra13.universalimageloader.utils.ImageSizeUtils#defineTargetSizeForView()

The following examples show how to use com.nostra13.universalimageloader.utils.ImageSizeUtils#defineTargetSizeForView() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: talk-android   File: VideoRow.java    License: MIT License 6 votes vote down vote up
Bitmap tryLoadBitmap(ImageViewAware imageAware) {
    Bitmap bitmap = null;
    try {
        java.io.File imageFile = diskCache.get(getMessage().get_id());
        if (imageFile != null && imageFile.exists() && imageFile.length() > 0) {
            ViewScaleType viewScaleType = imageAware.getScaleType();
            ImageSize imageSize = ImageSizeUtils.defineTargetSizeForView(imageAware, new ImageSize(MainApp.CONTEXT.getResources().getDisplayMetrics().widthPixels, MainApp.CONTEXT.getResources().getDisplayMetrics().heightPixels));
            ImageDecodingInfo decodingInfo = new ImageDecodingInfo(getMessage().get_id(),
                    ImageDownloader.Scheme.FILE.wrap(imageFile.getAbsolutePath()), getMessage().get_id(), imageSize, viewScaleType,
                    new BaseImageDownloader(MainApp.CONTEXT), options);
            bitmap = decoder.decode(decodingInfo);
            MainApp.memoryCache.put(getMessage().get_id(), bitmap);
        }
    } catch (Exception ignored) {
        ignored.printStackTrace();
    }
    return bitmap;
}
 
Example 2
Source Project: candybar   File: ImageSizeTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGetImageSizeScaleTo_useImageActualSize() throws Exception {
    // We layout the view to give it a width and height
    mView.measure(View.MeasureSpec.makeMeasureSpec(200, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(200, View.MeasureSpec.EXACTLY));
    mView.layout(0, 0, 200, 200);

    ImageSize expected = new ImageSize(200, 200);
    ImageSize result = ImageSizeUtils.defineTargetSizeForView(mImageAware, new ImageSize(590, 590));
    Assertions.assertThat(result).isNotNull();
    Assertions.assertThat(result.getWidth()).isEqualTo(expected.getWidth());
    Assertions.assertThat(result.getHeight()).isEqualTo(expected.getHeight());
}
 
Example 3
Source Project: candybar   File: ImageSizeTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This will make sure the view falls back to the ViewParams/Max/Or Config if wrap content so that it is never
 * shrunk to the first image size. In this case it falls back to the config size
 *
 * @throws Exception
 */
@Test
public void testGetImageSizeScaleTo_dontUseImageActualSizeWithWrapContent() throws Exception {
    //Set it to wrap content so that it will fall back to
    mView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    mView.measure(View.MeasureSpec.makeMeasureSpec(250, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(250, View.MeasureSpec.EXACTLY));
    // We layout the view to give it a width and height
    mView.layout(0, 0, 200, 200);

    ImageSize expected = new ImageSize(500, 500);
    ImageSize result = ImageSizeUtils.defineTargetSizeForView(mImageAware, new ImageSize(500, 500));
    Assertions.assertThat(result).isNotNull().isEqualToComparingFieldByField(expected);
}
 
Example 4
Source Project: candybar   File: ImageSizeTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGetImageSizeScaleTo_useImageLayoutParams() throws Exception {
    // Set a defined width
    mView.setLayoutParams(new FrameLayout.LayoutParams(300, 300));

    ImageSize expected = new ImageSize(300, 300);
    ImageSize result = ImageSizeUtils.defineTargetSizeForView(mImageAware, new ImageSize(500, 500));
    Assertions.assertThat(result).isNotNull().isEqualToComparingFieldByField(expected);
}
 
Example 5
@Test
public void testGetImageSizeScaleTo_useImageActualSize() throws Exception {
	// We layout the view to give it a width and height
	mView.measure(View.MeasureSpec.makeMeasureSpec(200, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(200, View.MeasureSpec.EXACTLY));
	mView.layout(0, 0, 200, 200);

	ImageSize expected = new ImageSize(200, 200);
	ImageSize result = ImageSizeUtils.defineTargetSizeForView(mImageAware, new ImageSize(590, 590));
	Assertions.assertThat(result).isNotNull();
	Assertions.assertThat(result.getWidth()).isEqualTo(expected.getWidth());
	Assertions.assertThat(result.getHeight()).isEqualTo(expected.getHeight());
}
 
Example 6
/**
 * This will make sure the view falls back to the ViewParams/Max/Or Config if wrap content so that it is never
 * shrunk to the first image size. In this case it falls back to the config size
 * 
 * @throws Exception
 */
@Test
public void testGetImageSizeScaleTo_dontUseImageActualSizeWithWrapContent() throws Exception {
	//Set it to wrap content so that it will fall back to
	mView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
	mView.measure(View.MeasureSpec.makeMeasureSpec(250, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(250, View.MeasureSpec.EXACTLY));
	// We layout the view to give it a width and height
	mView.layout(0, 0, 200, 200);

	ImageSize expected = new ImageSize(500, 500);
	ImageSize result = ImageSizeUtils.defineTargetSizeForView(mImageAware, new ImageSize(500, 500));
	Assertions.assertThat(result).isNotNull().isEqualsToByComparingFields(expected);
}
 
Example 7
@Test
public void testGetImageSizeScaleTo_useImageLayoutParams() throws Exception {
	// Set a defined width
	mView.setLayoutParams(new FrameLayout.LayoutParams(300, 300));

	ImageSize expected = new ImageSize(300, 300);
	ImageSize result = ImageSizeUtils.defineTargetSizeForView(mImageAware, new ImageSize(500, 500));
	Assertions.assertThat(result).isNotNull().isEqualsToByComparingFields(expected);
}
 
Example 8
@Test
public void testGetImageSizeScaleTo_useImageActualSize() throws Exception {
	// We layout the view to give it a width and height
	mView.measure(View.MeasureSpec.makeMeasureSpec(200, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(200, View.MeasureSpec.EXACTLY));
	mView.layout(0, 0, 200, 200);

	ImageSize expected = new ImageSize(200, 200);
	ImageSize result = ImageSizeUtils.defineTargetSizeForView(mImageAware, new ImageSize(590, 590));
	Assertions.assertThat(result).isNotNull();
	Assertions.assertThat(result.getWidth()).isEqualTo(expected.getWidth());
	Assertions.assertThat(result.getHeight()).isEqualTo(expected.getHeight());
}
 
Example 9
/**
 * This will make sure the view falls back to the ViewParams/Max/Or Config if wrap content so that it is never
 * shrunk to the first image size. In this case it falls back to the config size
 * 
 * @throws Exception
 */
@Test
public void testGetImageSizeScaleTo_dontUseImageActualSizeWithWrapContent() throws Exception {
	//Set it to wrap content so that it will fall back to
	mView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
	mView.measure(View.MeasureSpec.makeMeasureSpec(250, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(250, View.MeasureSpec.EXACTLY));
	// We layout the view to give it a width and height
	mView.layout(0, 0, 200, 200);

	ImageSize expected = new ImageSize(500, 500);
	ImageSize result = ImageSizeUtils.defineTargetSizeForView(mImageAware, new ImageSize(500, 500));
	Assertions.assertThat(result).isNotNull().isEqualsToByComparingFields(expected);
}
 
Example 10
@Test
public void testGetImageSizeScaleTo_useImageLayoutParams() throws Exception {
	// Set a defined width
	mView.setLayoutParams(new FrameLayout.LayoutParams(300, 300));

	ImageSize expected = new ImageSize(300, 300);
	ImageSize result = ImageSizeUtils.defineTargetSizeForView(mImageAware, new ImageSize(500, 500));
	Assertions.assertThat(result).isNotNull().isEqualsToByComparingFields(expected);
}
 
Example 11
Source Project: candybar   File: ImageSizeTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testGetImageSizeScaleTo_useImageConfigMaxSize() throws Exception {
    ImageSize expected = new ImageSize(500, 500);
    ImageSize result = ImageSizeUtils.defineTargetSizeForView(mImageAware, new ImageSize(500, 500));
    Assertions.assertThat(result).isNotNull().isEqualToComparingFieldByField(expected);
}
 
Example 12
Source Project: letv   File: ImageLoader.java    License: Apache License 2.0 4 votes vote down vote up
public void displayImage(String uri, ImageAware imageAware, DisplayImageOptions options, ImageLoadingListener listener, ImageLoadingProgressListener progressListener) {
    checkConfiguration();
    if (imageAware == null) {
        throw new IllegalArgumentException(ERROR_WRONG_ARGUMENTS);
    }
    if (listener == null) {
        listener = this.emptyListener;
    }
    if (options == null) {
        options = this.configuration.defaultDisplayImageOptions;
    }
    if (TextUtils.isEmpty(uri)) {
        this.engine.cancelDisplayTaskFor(imageAware);
        listener.onLoadingStarted(uri, imageAware.getWrappedView());
        if (options.shouldShowImageForEmptyUri()) {
            imageAware.setImageDrawable(options.getImageForEmptyUri(this.configuration.resources));
        } else {
            imageAware.setImageDrawable(null);
        }
        listener.onLoadingComplete(uri, imageAware.getWrappedView(), null);
        return;
    }
    ImageSize targetSize = ImageSizeUtils.defineTargetSizeForView(imageAware, this.configuration.getMaxImageSize());
    String memoryCacheKey = MemoryCacheUtils.generateKey(uri, targetSize);
    this.engine.prepareDisplayTaskFor(imageAware, memoryCacheKey);
    listener.onLoadingStarted(uri, imageAware.getWrappedView());
    Bitmap bmp = (Bitmap) this.configuration.memoryCache.get(memoryCacheKey);
    if (bmp == null || bmp.isRecycled()) {
        if (options.shouldShowImageOnLoading()) {
            imageAware.setImageDrawable(options.getImageOnLoading(this.configuration.resources));
        } else if (options.isResetViewBeforeLoading()) {
            imageAware.setImageDrawable(null);
        }
        LoadAndDisplayImageTask displayTask = new LoadAndDisplayImageTask(this.engine, new ImageLoadingInfo(uri, imageAware, targetSize, memoryCacheKey, options, listener, progressListener, this.engine.getLockForUri(uri)), defineHandler(options));
        if (options.isSyncLoading()) {
            displayTask.run();
            return;
        } else {
            this.engine.submit(displayTask);
            return;
        }
    }
    L.d(LOG_LOAD_IMAGE_FROM_MEMORY_CACHE, memoryCacheKey);
    if (options.shouldPostProcess()) {
        ProcessAndDisplayImageTask displayTask2 = new ProcessAndDisplayImageTask(this.engine, bmp, new ImageLoadingInfo(uri, imageAware, targetSize, memoryCacheKey, options, listener, progressListener, this.engine.getLockForUri(uri)), defineHandler(options));
        if (options.isSyncLoading()) {
            displayTask2.run();
            return;
        } else {
            this.engine.submit(displayTask2);
            return;
        }
    }
    options.getDisplayer().display(bmp, imageAware, LoadedFrom.MEMORY_CACHE);
    listener.onLoadingComplete(uri, imageAware.getWrappedView(), bmp);
}
 
Example 13
@Test
public void testGetImageSizeScaleTo_useImageConfigMaxSize() throws Exception {
	ImageSize expected = new ImageSize(500, 500);
	ImageSize result = ImageSizeUtils.defineTargetSizeForView(mImageAware, new ImageSize(500, 500));
	Assertions.assertThat(result).isNotNull().isEqualsToByComparingFields(expected);
}
 
Example 14
@Test
public void testGetImageSizeScaleTo_useImageConfigMaxSize() throws Exception {
	ImageSize expected = new ImageSize(500, 500);
	ImageSize result = ImageSizeUtils.defineTargetSizeForView(mImageAware, new ImageSize(500, 500));
	Assertions.assertThat(result).isNotNull().isEqualsToByComparingFields(expected);
}