Search in sources :

Example 1 with LottieValueCallback

use of com.airbnb.lottie.value.LottieValueCallback in project lottie-android by airbnb.

the class LottieAnimationView method init.

private void init(@Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
    TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.LottieAnimationView, defStyleAttr, 0);
    cacheComposition = ta.getBoolean(R.styleable.LottieAnimationView_lottie_cacheComposition, true);
    boolean hasRawRes = ta.hasValue(R.styleable.LottieAnimationView_lottie_rawRes);
    boolean hasFileName = ta.hasValue(R.styleable.LottieAnimationView_lottie_fileName);
    boolean hasUrl = ta.hasValue(R.styleable.LottieAnimationView_lottie_url);
    if (hasRawRes && hasFileName) {
        throw new IllegalArgumentException("lottie_rawRes and lottie_fileName cannot be used at " + "the same time. Please use only one at once.");
    } else if (hasRawRes) {
        int rawResId = ta.getResourceId(R.styleable.LottieAnimationView_lottie_rawRes, 0);
        if (rawResId != 0) {
            setAnimation(rawResId);
        }
    } else if (hasFileName) {
        String fileName = ta.getString(R.styleable.LottieAnimationView_lottie_fileName);
        if (fileName != null) {
            setAnimation(fileName);
        }
    } else if (hasUrl) {
        String url = ta.getString(R.styleable.LottieAnimationView_lottie_url);
        if (url != null) {
            setAnimationFromUrl(url);
        }
    }
    setFallbackResource(ta.getResourceId(R.styleable.LottieAnimationView_lottie_fallbackRes, 0));
    if (ta.getBoolean(R.styleable.LottieAnimationView_lottie_autoPlay, false)) {
        autoPlay = true;
    }
    if (ta.getBoolean(R.styleable.LottieAnimationView_lottie_loop, false)) {
        lottieDrawable.setRepeatCount(LottieDrawable.INFINITE);
    }
    if (ta.hasValue(R.styleable.LottieAnimationView_lottie_repeatMode)) {
        setRepeatMode(ta.getInt(R.styleable.LottieAnimationView_lottie_repeatMode, LottieDrawable.RESTART));
    }
    if (ta.hasValue(R.styleable.LottieAnimationView_lottie_repeatCount)) {
        setRepeatCount(ta.getInt(R.styleable.LottieAnimationView_lottie_repeatCount, LottieDrawable.INFINITE));
    }
    if (ta.hasValue(R.styleable.LottieAnimationView_lottie_speed)) {
        setSpeed(ta.getFloat(R.styleable.LottieAnimationView_lottie_speed, 1f));
    }
    if (ta.hasValue(R.styleable.LottieAnimationView_lottie_clipToCompositionBounds)) {
        setClipToCompositionBounds(ta.getBoolean(R.styleable.LottieAnimationView_lottie_clipToCompositionBounds, true));
    }
    setImageAssetsFolder(ta.getString(R.styleable.LottieAnimationView_lottie_imageAssetsFolder));
    setProgress(ta.getFloat(R.styleable.LottieAnimationView_lottie_progress, 0));
    enableMergePathsForKitKatAndAbove(ta.getBoolean(R.styleable.LottieAnimationView_lottie_enableMergePathsForKitKatAndAbove, false));
    if (ta.hasValue(R.styleable.LottieAnimationView_lottie_colorFilter)) {
        int colorRes = ta.getResourceId(R.styleable.LottieAnimationView_lottie_colorFilter, -1);
        ColorStateList csl = AppCompatResources.getColorStateList(getContext(), colorRes);
        SimpleColorFilter filter = new SimpleColorFilter(csl.getDefaultColor());
        KeyPath keyPath = new KeyPath("**");
        LottieValueCallback<ColorFilter> callback = new LottieValueCallback<>(filter);
        addValueCallback(keyPath, LottieProperty.COLOR_FILTER, callback);
    }
    if (ta.hasValue(R.styleable.LottieAnimationView_lottie_renderMode)) {
        int renderModeOrdinal = ta.getInt(R.styleable.LottieAnimationView_lottie_renderMode, RenderMode.AUTOMATIC.ordinal());
        if (renderModeOrdinal >= RenderMode.values().length) {
            renderModeOrdinal = RenderMode.AUTOMATIC.ordinal();
        }
        setRenderMode(RenderMode.values()[renderModeOrdinal]);
    }
    setIgnoreDisabledSystemAnimations(ta.getBoolean(R.styleable.LottieAnimationView_lottie_ignoreDisabledSystemAnimations, false));
    ta.recycle();
    lottieDrawable.setSystemAnimationsAreEnabled(Utils.getAnimationScale(getContext()) != 0f);
}
Also used : ColorFilter(android.graphics.ColorFilter) TypedArray(android.content.res.TypedArray) ColorStateList(android.content.res.ColorStateList) SimpleLottieValueCallback(com.airbnb.lottie.value.SimpleLottieValueCallback) LottieValueCallback(com.airbnb.lottie.value.LottieValueCallback) KeyPath(com.airbnb.lottie.model.KeyPath)

Example 2 with LottieValueCallback

use of com.airbnb.lottie.value.LottieValueCallback in project Signal-Android by WhisperSystems.

the class AudioView method setTint.

public void setTint(int foregroundTint) {
    post(() -> this.playPauseButton.addValueCallback(new KeyPath("**"), LottieProperty.COLOR_FILTER, new LottieValueCallback<>(new SimpleColorFilter(foregroundTint))));
    this.downloadButton.setColorFilter(foregroundTint, PorterDuff.Mode.SRC_IN);
    if (circleProgress != null) {
        this.circleProgress.setBarColor(foregroundTint);
    }
    if (this.duration != null) {
        this.duration.setTextColor(foregroundTint);
    }
    this.seekBar.getProgressDrawable().setColorFilter(foregroundTint, PorterDuff.Mode.SRC_IN);
    this.seekBar.getThumb().setColorFilter(foregroundTint, PorterDuff.Mode.SRC_IN);
}
Also used : SimpleColorFilter(com.airbnb.lottie.SimpleColorFilter) LottieValueCallback(com.airbnb.lottie.value.LottieValueCallback) KeyPath(com.airbnb.lottie.model.KeyPath)

Example 3 with LottieValueCallback

use of com.airbnb.lottie.value.LottieValueCallback in project Signal-Android by signalapp.

the class AudioView method setTint.

public void setTint(int foregroundTint) {
    post(() -> this.playPauseButton.addValueCallback(new KeyPath("**"), LottieProperty.COLOR_FILTER, new LottieValueCallback<>(new SimpleColorFilter(foregroundTint))));
    this.downloadButton.setColorFilter(foregroundTint, PorterDuff.Mode.SRC_IN);
    if (circleProgress != null) {
        this.circleProgress.setBarColor(foregroundTint);
    }
    if (this.duration != null) {
        this.duration.setTextColor(foregroundTint);
    }
    this.seekBar.getProgressDrawable().setColorFilter(foregroundTint, PorterDuff.Mode.SRC_IN);
    this.seekBar.getThumb().setColorFilter(foregroundTint, PorterDuff.Mode.SRC_IN);
}
Also used : SimpleColorFilter(com.airbnb.lottie.SimpleColorFilter) LottieValueCallback(com.airbnb.lottie.value.LottieValueCallback) KeyPath(com.airbnb.lottie.model.KeyPath)

Aggregations

KeyPath (com.airbnb.lottie.model.KeyPath)3 LottieValueCallback (com.airbnb.lottie.value.LottieValueCallback)3 SimpleColorFilter (com.airbnb.lottie.SimpleColorFilter)2 ColorStateList (android.content.res.ColorStateList)1 TypedArray (android.content.res.TypedArray)1 ColorFilter (android.graphics.ColorFilter)1 SimpleLottieValueCallback (com.airbnb.lottie.value.SimpleLottieValueCallback)1