Android Open Source - image-loader Bitmap Utils Should






From Project

Back to project page image-loader.

License

The source code is released under:

Apache License

If you think the Android project image-loader 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

package com.novoda.imageloader.acceptance;
//  w ww .ja v a 2 s .  c o  m
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.test.InstrumentationTestCase;

import com.novoda.imageloader.core.bitmap.BitmapUtil;

public class BitmapUtilsShould extends InstrumentationTestCase {

    private static final boolean UPSAMPLING_ENABLED = true;
    private static final boolean UPSAMPLING_DISABLED = false;

    private final int biggerScaledBitmapSize = 400;
    private final int smallerScaledBitmapSize = 10;

    public BitmapUtilsShould(String name) {
        super();
        setName(name);
    }

    public void test_scale_existing_bitmaps_to_specified_size() {
        Bitmap bmOriginal = BitmapFactory.decodeResource(getInstrumentation().getContext().getResources(), R.drawable.icon);
        assertFalse(bmOriginal.getHeight() == biggerScaledBitmapSize);
        assertFalse(bmOriginal.getWidth() == biggerScaledBitmapSize);

        Bitmap bm = new BitmapUtil().scaleBitmap(bmOriginal, biggerScaledBitmapSize, biggerScaledBitmapSize, UPSAMPLING_ENABLED);

        assertEquals(biggerScaledBitmapSize, bm.getHeight());
        assertEquals(biggerScaledBitmapSize, bm.getWidth());
    }

    public void test_create_bitmaps_of_a_specified_size() {
        Bitmap bm = new BitmapUtil().decodeResourceBitmapAndScale(getInstrumentation().getContext(),
                biggerScaledBitmapSize, biggerScaledBitmapSize, R.drawable.icon, UPSAMPLING_ENABLED);

        assertTrue(bm.getHeight() == biggerScaledBitmapSize);
        assertTrue(bm.getWidth() == biggerScaledBitmapSize);
    }

    public void test_keep_original_bitmap_when_scaling_to_a_bigger_size_when_upscaling_is_set_to_false() {
        Bitmap bm = new BitmapUtil().decodeResourceBitmapAndScale(getInstrumentation().getContext(),
                biggerScaledBitmapSize, biggerScaledBitmapSize, R.drawable.icon, UPSAMPLING_DISABLED);

        assertFalse(bm.getHeight() == biggerScaledBitmapSize);
        assertFalse(bm.getWidth() == biggerScaledBitmapSize);
    }

    public void test_scale_bitmap_when_scaling_to_a_smaller_size_when_upscaling_is_set_to_false() {
        Bitmap bm = new BitmapUtil().decodeResourceBitmapAndScale(getInstrumentation().getContext(),
                smallerScaledBitmapSize, smallerScaledBitmapSize, R.drawable.icon, UPSAMPLING_DISABLED);

        assertTrue(bm.getHeight() == smallerScaledBitmapSize);
        assertTrue(bm.getWidth() == smallerScaledBitmapSize);
    }

}




Java Source Code List

com.novoda.imageloader.acceptance.BitmapUtilsInstrumentationTest.java
com.novoda.imageloader.acceptance.BitmapUtilsShould.java
com.novoda.imageloader.acceptance.ImageLoaderDemoActivityTest.java
com.novoda.imageloader.acceptance.ImageManagerInstrumentationTest.java
com.novoda.imageloader.acceptance.LruBitmapCacheInstrumentationTest.java
com.novoda.imageloader.core.ImageManager.java
com.novoda.imageloader.core.LoaderContext.java
com.novoda.imageloader.core.LoaderSettings.java
com.novoda.imageloader.core.OnImageLoadedListener.java
com.novoda.imageloader.core.bitmap.BitmapUtil.java
com.novoda.imageloader.core.cache.CacheManager.java
com.novoda.imageloader.core.cache.LruBitmapCache.java
com.novoda.imageloader.core.cache.NoCache.java
com.novoda.imageloader.core.cache.SoftMapCache.java
com.novoda.imageloader.core.cache.util.LruCache.java
com.novoda.imageloader.core.exception.ImageCopyException.java
com.novoda.imageloader.core.exception.ImageNotFoundException.java
com.novoda.imageloader.core.exception.MissingSettingException.java
com.novoda.imageloader.core.file.BasicFileManager.java
com.novoda.imageloader.core.file.FileManager.java
com.novoda.imageloader.core.file.util.AndroidFileContext.java
com.novoda.imageloader.core.file.util.FileUtil.java
com.novoda.imageloader.core.file.util.FlushedInputStream.java
com.novoda.imageloader.core.loader.ConcurrentLoader.java
com.novoda.imageloader.core.loader.Loader.java
com.novoda.imageloader.core.loader.SimpleLoader.java
com.novoda.imageloader.core.loader.util.AsyncResult.java
com.novoda.imageloader.core.loader.util.AsyncTask.java
com.novoda.imageloader.core.loader.util.BitmapDisplayer.java
com.novoda.imageloader.core.loader.util.BitmapRetriever.java
com.novoda.imageloader.core.loader.util.LoaderTask.java
com.novoda.imageloader.core.loader.util.SingleThreadedLoader.java
com.novoda.imageloader.core.model.ImageTagFactory.java
com.novoda.imageloader.core.model.ImageTag.java
com.novoda.imageloader.core.model.ImageWrapper.java
com.novoda.imageloader.core.network.NetworkManager.java
com.novoda.imageloader.core.network.UrlNetworkManager.java
com.novoda.imageloader.core.network.UrlUtil.java
com.novoda.imageloader.core.util.AnimationHelper.java
com.novoda.imageloader.core.util.DirectLoader.java
com.novoda.imageloader.core.util.Log.java
com.novoda.imageloader.demo.DemoApplication.java
com.novoda.imageloader.demo.activity.BigImages.java
com.novoda.imageloader.demo.activity.Demos.java
com.novoda.imageloader.demo.activity.DirectLoading.java
com.novoda.imageloader.demo.activity.ImageLongList.java
com.novoda.imageloader.demo.activity.LongSmallImageList.java
com.novoda.imageloader.demo.activity.base.ImageLoaderBaseActivity.java
com.novoda.imageloader.demo.provider.CustomUriMatcher.java
com.novoda.imageloader.demo.provider.DatabaseManager.java
com.novoda.imageloader.demo.provider.ImageLoaderDemoProvider.java
com.novoda.imageloader.demo.provider.SqlFile.java
com.novoda.imageloader.demo.util.BugSenseHelper.java
com.novoda.imageloader.demo.util.BugsenseApiKeyFailedException.java