Code Monkey home page Code Monkey logo

malevich's Introduction

malevich

Android displaying bitmaps library

This library is just wrapper for Google tutorial Loading Large Bitmaps Efficiently:

http://developer.android.com/intl/ru/training/displaying-bitmaps/load-bitmap.html

Example of usage:

https://github.com/recoilme/android-DisplayingBitmaps

How to use:

// init
Malevich malevich = new Malevich.Builder(this).build();


// use
malevich.load(mImageUrl).into(mImageView);

Thats all!

Advansed usage:

Memory and disk caching params

ImageCache.ImageCacheParams cacheParams = new ImageCache.ImageCacheParams(this, "dir");
        cacheParams.memoryCacheEnabled = true; //Enable memory cache
        cacheParams.setMemCacheSizePercent(0.4f);  //Percent of available memory for cache
        cacheParams.compressQuality = 90; // Compress quality
        cacheParams.compressFormat = Bitmap.CompressFormat.PNG; // Compress format
        cacheParams.diskCacheEnabled = true; // Use disk cache
        cacheParams.diskCacheSize = 10485760; // Disk cache size

Malevich Builder

malevich = new Malevich.Builder(this)
        .debug(true) // write log
        .maxSize(1024) // max size of image in px
        .LoadingImage(R.drawable.some) // preloader image or recource
        .CacheParams(casheParams) // custom cache
        .build();

Loading image

malevich.load(some).into(ImageView);

you may load:

  1. Bitmap
  2. BitmapDrawable
  3. Resource id
  4. HttpUrl

Transform image after loading with prebuild utils or custom method

malevich.load(url).width(mItemHeight).height(mItemHeight).imageDecodedListener(new Malevich.ImageDecodedListener() {
                    @Override
                    public Bitmap onImageDecoded(String data, int reqWidth, int reqHeight, Bitmap bitmap) {

                        // Get squared bitmap and transform it to circle
                        return Malevich.Utils.getSquaredCircleBitmap(bitmap,reqWidth);
                    }
                }).into(imageView);

Pause loading on scroll

mGridView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView absListView, int scrollState) {
                // Pause fetcher to ensure smoother scrolling when flinging
                if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING) {
                    // Pause image loading on scroll to help with performance
                    malevich.setPauseWork(true);
                } else {
                    malevich.setPauseWork(false);
                }
            }

            @Override
            public void onScroll(AbsListView absListView, int firstVisibleItem,
                    int visibleItemCount, int totalItemCount) {
            }
        });

Canсel and pausing tasks

    @Override
    public void onResume() {
        super.onResume();
        malevich.setExitTasksEarly(false);
        mAdapter.notifyDataSetChanged();
    }

    @Override
    public void onPause() {
        super.onPause();
        malevich.setPauseWork(false);
        malevich.setExitTasksEarly(true);
        malevich.flushCache();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        malevich.closeCache();
    }

malevich's People

Contributors

aol-nnov avatar lucky-spirit avatar recoilme avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

malevich's Issues

вопрос

// я в ro на хабре, так что, поспамлю сюда.

Было бы интересно почитать сравнение велосипедов, и чем, например, ваш малевич лучше другого художника?

Wrong behavior in ListView

Hi there, I faced in issue with using this library with ListView or RecyclerView:
if listView have a few of duplicate images on first page than images goest to the wrong imageView.
If you use

            public Bitmap onImageDecoded(String data, int reqWidth, int reqHeight, Bitmap bitmap) {
                return Malevich.Utils.getCircleBitmap(bitmap);
            }

than app crashes with java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap.

I can't found the reason of issue, but for fix this you can disable memoryCache:

            ImageCache.ImageCacheParams cacheParams = new ImageCache.ImageCacheParams(context, "images");
            cacheParams.memoryCacheEnabled = false;
            malevich = new Malevich.Builder(context).CacheParams(cacheParams).build();

Minimal sample to reproduce an issue:
https://github.com/akadatsky/testMalevich

Screenshot actual VS expected:
ex

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.