Code Monkey home page Code Monkey logo

frescoloader's Introduction

FrescoLoader

FrescoLoader is a framework which uses fresco to load an image into the android.widget.ImageView.

Changelog

See changelog details in CHANGELOG.

Examples

I have provided a sample.

See sample here on Github.

To run the sample application, simply clone this repository and use android studio to compile it, then install it on a connected device.

Note

If you use this FrescoLoader, please make sure you have not use the ImageView's tag.

Usage

Dependency

latest version

Download

current not release a version

gradle

dependencies {
    compile "io.github.lizhangqu:fresco-loader:${latest_version}"
}

maven

<dependencies>
    <dependency>
      <groupId>io.github.lizhangqu</groupId>
      <artifactId>fresco-loader</artifactId>
      <version>${latest_version}</version>
    </dependency>
</dependencies>

Fresco

Add fresco dependencies as you need.

// fresco base
compile("com.facebook.fresco:fresco:${FRESCO_VERSION}") {
    exclude group: 'com.android.support'
}
// fresco gif support(if you need gif add this)
compile("com.facebook.fresco:animated-gif:${FRESCO_VERSION}") {
    exclude group: 'com.android.support'
}
// fresco dynamic webp support(if you need dynamic webp add this)
compile("com.facebook.fresco:animated-webp:${FRESCO_VERSION}") {
    exclude group: 'com.android.support'
}
// fresco static webp support(if you need static webp add this)
compile("com.facebook.fresco:webpsupport:${FRESCO_VERSION}") {
    exclude group: 'com.android.support'
}

Loader Sample

FrescoLoader.with(view.getContext())
            .progressiveRenderingEnabled(true)
            .fadeDuration(2000)
            .autoPlayAnimations(true)
            .autoRotateEnabled(true)
            .retainImageOnFailure(true)
            .desiredAspectRatioWithHeight(0.5F)
            .tapToRetryEnabled(true)
            .focusPoint(new PointF(30, 50))
            .resize(400, 400)
            .fadeDuration(1000)
            .border(Color.RED, 10)
            .borderColor(Color.RED)
            .borderWidth(10)
            .cornersRadii(10, 10, 10, 10)
            .cornersRadius(10)
            .roundAsCircle()
            .backgroundDrawable(ContextCompat.getDrawable(getApplicationContext(), R.mipmap.bg_zero))
            .progressBar(ContextCompat.getDrawable(getApplicationContext(), R.mipmap.icon_progress_bar))
            .progressBarScaleType(ImageView.ScaleType.CENTER_CROP)
            .placeholder(ContextCompat.getDrawable(getApplicationContext(), R.mipmap.icon_placeholder))
            .placeholderScaleType(ImageView.ScaleType.CENTER_CROP)
            .failure(ContextCompat.getDrawable(getApplicationContext(), R.mipmap.icon_failure))
            .failureScaleType(ImageView.ScaleType.CENTER_CROP)
            .retry(ContextCompat.getDrawable(getApplicationContext(), R.mipmap.icon_retry))
            .retryScaleType(ImageView.ScaleType.CENTER_CROP)
            .colorFilter(new PorterDuffColorFilter(Color.RED, PorterDuff.Mode.DARKEN))
            .overlays(overlays)
            .pressedStateOverlay(ContextCompat.getDrawable(getApplicationContext(), R.mipmap.bg_one))
            .actualScaleType(ImageView.ScaleType.CENTER_CROP)
            .lowerLoad(R.mipmap.ic_launcher_round)
            .load("http://desk.fd.zol-img.com.cn/t_s960x600c5/g5/M00/0D/01/ChMkJlgq0z-IC78PAA1UbwykJUgAAXxIwMAwQcADVSH340.jpg")
            .localThumbnailPreviewsEnabled(true)
            .into(image);

See more details in class FrescoLoader.java

If you have extended the android.widget.ImageView class and you can add some method to it, you'd better add this. But it's not necessary if you don't want.

public class MyImageView extends ImageView implements FrescoLoader.TemporaryDetachListener {
    //holder the TemporaryDetachListener
    FrescoLoader.TemporaryDetachListener listener;

    public MyImageView(Context context) {
        super(context);
    }

    public MyImageView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public MyImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public void onStartTemporaryDetach() {
        super.onStartTemporaryDetach();
        //call delegete
        if (this.listener != null) {
            listener.onStartTemporaryDetach(this);
        }

    }

    @Override
    public void onFinishTemporaryDetach() {
        super.onFinishTemporaryDetach();
        //call delegete
        if (this.listener != null) {
            listener.onFinishTemporaryDetach(this);
        }
    }

    @Override
    public void onSaveTemporaryDetachListener(FrescoLoader.TemporaryDetachListener listener) {
        //holder it
        this.listener = listener;
    }

    @Override
    public void onStartTemporaryDetach(View view) {
        //empty
    }

    @Override
    public void onFinishTemporaryDetach(View view) {
        //empty
    }
}

License

FrescoLoader is under the BSD license. See the LICENSE file for details.

frescoloader's People

Contributors

lizhangqu avatar

Stargazers

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

Watchers

 avatar  avatar

frescoloader's Issues

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.