com.airbnb.lottie.value.LottieValueCallback Java Examples

The following examples show how to use com.airbnb.lottie.value.LottieValueCallback. 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 File: BaseStrokeContent.java    From lottie-android with Apache License 2.0 7 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
@CallSuper
public <T> void addValueCallback(T property, @Nullable LottieValueCallback<T> callback) {
  if (property == LottieProperty.OPACITY) {
    opacityAnimation.setValueCallback((LottieValueCallback<Integer>) callback);
  } else if (property == LottieProperty.STROKE_WIDTH) {
    widthAnimation.setValueCallback((LottieValueCallback<Float>) callback);
  } else if (property == LottieProperty.COLOR_FILTER) {
    if (colorFilterAnimation != null) {
      layer.removeAnimation(colorFilterAnimation);
    }

    if (callback == null) {
      colorFilterAnimation = null;
    } else {
      colorFilterAnimation =
          new ValueCallbackKeyframeAnimation<>((LottieValueCallback<ColorFilter>) callback);
      colorFilterAnimation.addUpdateListener(this);
      layer.addAnimation(colorFilterAnimation);
    }
  }
}
 
Example #2
Source File: GradientStrokeContent.java    From lottie-android with Apache License 2.0 6 votes vote down vote up
@Override
public <T> void addValueCallback(T property, @Nullable LottieValueCallback<T> callback) {
  super.addValueCallback(property, callback);
  if (property == LottieProperty.GRADIENT_COLOR) {
    if (colorCallbackAnimation != null) {
      layer.removeAnimation(colorCallbackAnimation);
    }

    if (callback == null) {
      colorCallbackAnimation = null;
    } else {
      colorCallbackAnimation = new ValueCallbackKeyframeAnimation<>(callback);
      colorCallbackAnimation.addUpdateListener(this);
      layer.addAnimation(colorCallbackAnimation);
    }
  }
}
 
Example #3
Source File: StrokeContent.java    From lottie-android with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> void addValueCallback(T property, @Nullable LottieValueCallback<T> callback) {
  super.addValueCallback(property, callback);
  if (property == STROKE_COLOR) {
    colorAnimation.setValueCallback((LottieValueCallback<Integer>) callback);
  } else if (property == LottieProperty.COLOR_FILTER) {
    if (colorFilterAnimation != null) {
      layer.removeAnimation(colorFilterAnimation);
    }

    if (callback == null) {
      colorFilterAnimation = null;
    } else {
      colorFilterAnimation =
          new ValueCallbackKeyframeAnimation<>((LottieValueCallback<ColorFilter>) callback);
      colorFilterAnimation.addUpdateListener(this);
      layer.addAnimation(colorAnimation);
    }
  }
}
 
Example #4
Source File: PolystarContent.java    From lottie-android with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> void addValueCallback(T property, @Nullable LottieValueCallback<T> callback) {
  if (property == LottieProperty.POLYSTAR_POINTS) {
    pointsAnimation.setValueCallback((LottieValueCallback<Float>) callback);
  } else if (property == LottieProperty.POLYSTAR_ROTATION) {
    rotationAnimation.setValueCallback((LottieValueCallback<Float>) callback);
  } else if (property == LottieProperty.POSITION) {
    positionAnimation.setValueCallback((LottieValueCallback<PointF>) callback);
  } else if (property == LottieProperty.POLYSTAR_INNER_RADIUS && innerRadiusAnimation != null) {
    innerRadiusAnimation.setValueCallback((LottieValueCallback<Float>) callback);
  } else if (property == LottieProperty.POLYSTAR_OUTER_RADIUS) {
    outerRadiusAnimation.setValueCallback((LottieValueCallback<Float>) callback);
  } else if (property == LottieProperty.POLYSTAR_INNER_ROUNDEDNESS && innerRoundednessAnimation != null) {
    innerRoundednessAnimation.setValueCallback((LottieValueCallback<Float>) callback);
  } else if (property == LottieProperty.POLYSTAR_OUTER_ROUNDEDNESS) {
    outerRoundednessAnimation.setValueCallback((LottieValueCallback<Float>) callback);
  }
}
 
Example #5
Source File: FillContent.java    From lottie-android with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> void addValueCallback(T property, @Nullable LottieValueCallback<T> callback) {
  if (property == LottieProperty.COLOR) {
    colorAnimation.setValueCallback((LottieValueCallback<Integer>) callback);
  } else if (property == LottieProperty.OPACITY) {
    opacityAnimation.setValueCallback((LottieValueCallback<Integer>) callback);
  } else if (property == LottieProperty.COLOR_FILTER) {
    if (colorFilterAnimation != null) {
      layer.removeAnimation(colorFilterAnimation);
    }

    if (callback == null) {
      colorFilterAnimation = null;
    } else {
      colorFilterAnimation =
          new ValueCallbackKeyframeAnimation<>((LottieValueCallback<ColorFilter>) callback);
      colorFilterAnimation.addUpdateListener(this);
      layer.addAnimation(colorFilterAnimation);
    }
  }
}
 
Example #6
Source File: CompositionLayer.java    From lottie-android with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> void addValueCallback(T property, @Nullable LottieValueCallback<T> callback) {
  super.addValueCallback(property, callback);

  if (property == LottieProperty.TIME_REMAP) {
    if (callback == null) {
      if (timeRemapping != null) {
        timeRemapping.setValueCallback(null);
      }
    } else {
      timeRemapping = new ValueCallbackKeyframeAnimation<>((LottieValueCallback<Float>) callback);
      timeRemapping.addUpdateListener(this);
      addAnimation(timeRemapping);
    }
  }
}
 
Example #7
Source File: EllipseContent.java    From lottie-android with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> void addValueCallback(T property, @Nullable LottieValueCallback<T> callback) {
  if (property == LottieProperty.ELLIPSE_SIZE) {
    sizeAnimation.setValueCallback((LottieValueCallback<PointF>) callback);
  } else if (property == LottieProperty.POSITION) {
    positionAnimation.setValueCallback((LottieValueCallback<PointF>) callback);
  }
}
 
Example #8
Source File: SolidLayer.java    From lottie-android with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> void addValueCallback(T property, @Nullable LottieValueCallback<T> callback) {
  super.addValueCallback(property, callback);
  if (property == LottieProperty.COLOR_FILTER) {
    if (callback == null) {
      colorFilterAnimation = null;
    } else {
      colorFilterAnimation =
          new ValueCallbackKeyframeAnimation<>((LottieValueCallback<ColorFilter>) callback);
    }
  }
}
 
Example #9
Source File: ImageLayer.java    From lottie-android with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("SingleStatementInBlock")
@Override
public <T> void addValueCallback(T property, @Nullable LottieValueCallback<T> callback) {
  super.addValueCallback(property, callback);
   if (property == LottieProperty.COLOR_FILTER) {
     if (callback == null) {
       colorFilterAnimation = null;
     } else {
       //noinspection unchecked
       colorFilterAnimation =
           new ValueCallbackKeyframeAnimation<>((LottieValueCallback<ColorFilter>) callback);
     }
  }
}
 
Example #10
Source File: LottieDrawable.java    From lottie-android with Apache License 2.0 5 votes vote down vote up
/**
 * Overload of {@link #addValueCallback(KeyPath, Object, LottieValueCallback)} that takes an interface. This allows you to use a single abstract
 * method code block in Kotlin such as:
 * drawable.addValueCallback(yourKeyPath, LottieProperty.COLOR) { yourColor }
 */
public <T> void addValueCallback(KeyPath keyPath, T property,
                                 final SimpleLottieValueCallback<T> callback) {
  addValueCallback(keyPath, property, new LottieValueCallback<T>() {
    @Override
    public T getValue(LottieFrameInfo<T> frameInfo) {
      return callback.getValue(frameInfo);
    }
  });
}
 
Example #11
Source File: LottieDrawable.java    From lottie-android with Apache License 2.0 5 votes vote down vote up
/**
 * Add an property callback for the specified {@link KeyPath}. This {@link KeyPath} can resolve
 * to multiple contents. In that case, the callbacks's value will apply to all of them.
 * <p>
 * Internally, this will check if the {@link KeyPath} has already been resolved with
 * {@link #resolveKeyPath(KeyPath)} and will resolve it if it hasn't.
 */
public <T> void addValueCallback(
    final KeyPath keyPath, final T property, final LottieValueCallback<T> callback) {
  if (compositionLayer == null) {
    lazyCompositionTasks.add(new LazyCompositionTask() {
      @Override
      public void run(LottieComposition composition) {
        addValueCallback(keyPath, property, callback);
      }
    });
    return;
  }
  boolean invalidate;
  if (keyPath == KeyPath.COMPOSITION) {
    compositionLayer.addValueCallback(property, callback);
    invalidate = true;
  } else if (keyPath.getResolvedElement() != null) {
    keyPath.getResolvedElement().addValueCallback(property, callback);
    invalidate = true;
  } else {
    List<KeyPath> elements = resolveKeyPath(keyPath);

    for (int i = 0; i < elements.size(); i++) {
      //noinspection ConstantConditions
      elements.get(i).getResolvedElement().addValueCallback(property, callback);
    }
    invalidate = !elements.isEmpty();
  }
  if (invalidate) {
    invalidateSelf();
    if (property == LottieProperty.TIME_REMAP) {
      // Time remapping values are read in setProgress. In order for the new value
      // to apply, we have to re-set the progress with the current progress so that the
      // time remapping can be reapplied.
      setProgress(getProgress());
    }
  }
}
 
Example #12
Source File: BaseKeyframeAnimation.java    From lottie-android with Apache License 2.0 5 votes vote down vote up
public void setValueCallback(@Nullable LottieValueCallback<A> valueCallback) {
  if (this.valueCallback != null) {
    this.valueCallback.setAnimation(null);
  }
  this.valueCallback = valueCallback;
  if (valueCallback != null) {
    valueCallback.setAnimation(this);
  }
}
 
Example #13
Source File: AudioView.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
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);
  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);
}
 
Example #14
Source File: RepeaterContent.java    From lottie-android with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> void addValueCallback(T property, @Nullable LottieValueCallback<T> callback) {
  if (transform.applyValueCallback(property, callback)) {
    return;
  }

  if (property == LottieProperty.REPEATER_COPIES) {
    copies.setValueCallback((LottieValueCallback<Float>) callback);
  } else if (property == LottieProperty.REPEATER_OFFSET) {
    offset.setValueCallback((LottieValueCallback<Float>) callback);
  }
}
 
Example #15
Source File: RectangleContent.java    From lottie-android with Apache License 2.0 5 votes vote down vote up
@Override
public <T> void addValueCallback(T property, @Nullable LottieValueCallback<T> callback) {
  if (property == LottieProperty.RECTANGLE_SIZE) {
    sizeAnimation.setValueCallback((LottieValueCallback<PointF>) callback);
  } else if (property == LottieProperty.POSITION) {
    positionAnimation.setValueCallback((LottieValueCallback<PointF>) callback);
  } else if (property == LottieProperty.CORNER_RADIUS) {
    cornerRadiusAnimation.setValueCallback((LottieValueCallback<Float>) callback);
  }
}
 
Example #16
Source File: GradientFillContent.java    From lottie-android with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> void addValueCallback(T property, @Nullable LottieValueCallback<T> callback) {
  if (property == LottieProperty.OPACITY) {
    opacityAnimation.setValueCallback((LottieValueCallback<Integer>) callback);
  } else if (property == LottieProperty.COLOR_FILTER) {
    if (colorFilterAnimation != null) {
      layer.removeAnimation(colorFilterAnimation);
    }

     if (callback == null) {
       colorFilterAnimation = null;
     } else {
       colorFilterAnimation =
           new ValueCallbackKeyframeAnimation<>((LottieValueCallback<ColorFilter>) callback);
       colorFilterAnimation.addUpdateListener(this);
       layer.addAnimation(colorFilterAnimation);
     }
   } else if (property == LottieProperty.GRADIENT_COLOR) {
    if (colorCallbackAnimation != null) {
      layer.removeAnimation(colorCallbackAnimation);
    }

     if (callback == null) {
       colorCallbackAnimation = null;
     } else {
       //noinspection rawtypes
       colorCallbackAnimation = new ValueCallbackKeyframeAnimation<>(callback);
       colorCallbackAnimation.addUpdateListener(this);
       layer.addAnimation(colorCallbackAnimation);
     }
  }
}
 
Example #17
Source File: LottieAnimationView.java    From lottie-android with Apache License 2.0 5 votes vote down vote up
/**
 * Overload of {@link #addValueCallback(KeyPath, Object, LottieValueCallback)} that takes an interface. This allows you to use a single abstract
 * method code block in Kotlin such as:
 * animationView.addValueCallback(yourKeyPath, LottieProperty.COLOR) { yourColor }
 */
public <T> void addValueCallback(KeyPath keyPath, T property,
    final SimpleLottieValueCallback<T> callback) {
  lottieDrawable.addValueCallback(keyPath, property, new LottieValueCallback<T>() {
    @Override public T getValue(LottieFrameInfo<T> frameInfo) {
      return callback.getValue(frameInfo);
    }
  });
}
 
Example #18
Source File: BaseLayer.java    From lottie-android with Apache License 2.0 4 votes vote down vote up
@CallSuper
@Override
public <T> void addValueCallback(T property, @Nullable LottieValueCallback<T> callback) {
  transform.applyValueCallback(property, callback);
}
 
Example #19
Source File: ValueCallbackKeyframeAnimation.java    From lottie-android with Apache License 2.0 4 votes vote down vote up
public ValueCallbackKeyframeAnimation(LottieValueCallback<A> valueCallback, @Nullable A valueCallbackValue) {
  super(Collections.<Keyframe<K>>emptyList());
  setValueCallback(valueCallback);
  this.valueCallbackValue = valueCallbackValue;
}
 
Example #20
Source File: LottieAnimationView.java    From lottie-android with Apache License 2.0 4 votes vote down vote up
private void init(@Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
  TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.LottieAnimationView, defStyleAttr, 0);
  if (!isInEditMode()) {
    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)) {
    wasAnimatingWhenDetached = true;
    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));
  }

  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)) {
    SimpleColorFilter filter = new SimpleColorFilter(
        ta.getColor(R.styleable.LottieAnimationView_lottie_colorFilter, Color.TRANSPARENT));
    KeyPath keyPath = new KeyPath("**");
    LottieValueCallback<ColorFilter> callback = new LottieValueCallback<ColorFilter>(filter);
    addValueCallback(keyPath, LottieProperty.COLOR_FILTER, callback);
  }
  if (ta.hasValue(R.styleable.LottieAnimationView_lottie_scale)) {
    lottieDrawable.setScale(ta.getFloat(R.styleable.LottieAnimationView_lottie_scale, 1f));
  }

  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]);
  }

  if (getScaleType() != null) {
    lottieDrawable.setScaleType(getScaleType());
  }
  ta.recycle();

  lottieDrawable.setSystemAnimationsAreEnabled(Utils.getAnimationScale(getContext()) != 0f);

  enableOrDisableHardwareLayer();
  isInitialized = true;
}
 
Example #21
Source File: TextLayer.java    From lottie-android with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> void addValueCallback(T property, @Nullable LottieValueCallback<T> callback) {
  super.addValueCallback(property, callback);
  if (property == LottieProperty.COLOR) {
    if (colorCallbackAnimation != null) {
      removeAnimation(colorCallbackAnimation);
    }

    if (callback == null) {
        colorCallbackAnimation = null;
    } else {
      colorCallbackAnimation = new ValueCallbackKeyframeAnimation<>((LottieValueCallback<Integer>) callback);
      colorCallbackAnimation.addUpdateListener(this);
      addAnimation(colorCallbackAnimation);
    }
  } else if (property == LottieProperty.STROKE_COLOR) {
    if (strokeColorCallbackAnimation != null) {
      removeAnimation(strokeColorCallbackAnimation);
    }

    if (callback == null) {
      strokeColorCallbackAnimation = null;
    } else {
      strokeColorCallbackAnimation = new ValueCallbackKeyframeAnimation<>((LottieValueCallback<Integer>) callback);
      strokeColorCallbackAnimation.addUpdateListener(this);
      addAnimation(strokeColorCallbackAnimation);
    }
  } else if (property == LottieProperty.STROKE_WIDTH) {
    if (strokeWidthCallbackAnimation != null) {
      removeAnimation(strokeWidthCallbackAnimation);
    }

    if (callback == null) {
      strokeWidthCallbackAnimation = null;
    } else {
      strokeWidthCallbackAnimation = new ValueCallbackKeyframeAnimation<>((LottieValueCallback<Float>) callback);
      strokeWidthCallbackAnimation.addUpdateListener(this);
      addAnimation(strokeWidthCallbackAnimation);
    }
  } else if (property == LottieProperty.TEXT_TRACKING) {
    if (trackingCallbackAnimation != null) {
      removeAnimation(trackingCallbackAnimation);
    }

    if (callback == null) {
      trackingCallbackAnimation = null;
    } else {
      trackingCallbackAnimation = new ValueCallbackKeyframeAnimation<>((LottieValueCallback<Float>) callback);
      trackingCallbackAnimation.addUpdateListener(this);
      addAnimation(trackingCallbackAnimation);
    }
  } else if (property == LottieProperty.TEXT_SIZE) {
    if (textSizeCallbackAnimation != null) {
      removeAnimation(textSizeCallbackAnimation);
    }

    if (callback == null) {
      textSizeCallbackAnimation = null;
    } else {
      textSizeCallbackAnimation = new ValueCallbackKeyframeAnimation<>((LottieValueCallback<Float>) callback);
      textSizeCallbackAnimation.addUpdateListener(this);
      addAnimation(textSizeCallbackAnimation);
    }
  }
}
 
Example #22
Source File: TransformKeyframeAnimation.java    From lottie-android with Apache License 2.0 4 votes vote down vote up
/**
 * Returns whether the callback was applied.
 */
@SuppressWarnings("unchecked")
public <T> boolean applyValueCallback(T property, @Nullable LottieValueCallback<T> callback) {
  if (property == TRANSFORM_ANCHOR_POINT) {
    if (anchorPoint == null) {
      anchorPoint = new ValueCallbackKeyframeAnimation(callback, new PointF());
    } else {
      anchorPoint.setValueCallback((LottieValueCallback<PointF>) callback);
    }
  } else if (property == TRANSFORM_POSITION) {
    if (position == null) {
      position = new ValueCallbackKeyframeAnimation(callback, new PointF());
    } else {
      position.setValueCallback((LottieValueCallback<PointF>) callback);
    }
  } else if (property == TRANSFORM_SCALE) {
    if (scale == null) {
      scale = new ValueCallbackKeyframeAnimation(callback, new ScaleXY());
    } else {
      scale.setValueCallback((LottieValueCallback<ScaleXY>) callback);
    }
  } else if (property == TRANSFORM_ROTATION) {
    if (rotation == null) {
      rotation = new ValueCallbackKeyframeAnimation(callback, 0f);
    } else {
      rotation.setValueCallback((LottieValueCallback<Float>) callback);
    }
  } else if (property == TRANSFORM_OPACITY) {
    if (opacity == null) {
      opacity = new ValueCallbackKeyframeAnimation(callback, 100);
    } else {
      opacity.setValueCallback((LottieValueCallback<Integer>) callback);
    }
  } else if (property == TRANSFORM_START_OPACITY && startOpacity != null) {
    if (startOpacity == null) {
      startOpacity = new ValueCallbackKeyframeAnimation(callback, 100);
    } else {
      startOpacity.setValueCallback((LottieValueCallback<Float>) callback);
    }
  } else if (property == TRANSFORM_END_OPACITY && endOpacity != null) {
    if (endOpacity == null) {
      endOpacity = new ValueCallbackKeyframeAnimation(callback, 100);
    } else {
      endOpacity.setValueCallback((LottieValueCallback<Float>) callback);
    }
  } else if (property == TRANSFORM_SKEW && skew != null) {
    if (skew == null) {
      skew = new FloatKeyframeAnimation(Collections.singletonList(new Keyframe<Float>(0f)));
    }
    skew.setValueCallback((LottieValueCallback<Float>) callback);
  } else if (property == TRANSFORM_SKEW_ANGLE && skewAngle != null) {
    if (skewAngle == null) {
      skewAngle = new FloatKeyframeAnimation(Collections.singletonList(new Keyframe<Float>(0f)));
    }
    skewAngle.setValueCallback((LottieValueCallback<Float>) callback);
  } else {
    return false;
  }
  return true;
}
 
Example #23
Source File: ValueCallbackKeyframeAnimation.java    From lottie-android with Apache License 2.0 4 votes vote down vote up
public ValueCallbackKeyframeAnimation(LottieValueCallback<A> valueCallback) {
  this(valueCallback, null);
}
 
Example #24
Source File: ContentGroup.java    From lottie-android with Apache License 2.0 4 votes vote down vote up
@Override
public <T> void addValueCallback(T property, @Nullable LottieValueCallback<T> callback) {
  if (transformAnimation != null) {
    transformAnimation.applyValueCallback(property, callback);
  }
}
 
Example #25
Source File: LottieAnimationViewPropertyManager.java    From lottie-react-native with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the view with changed fields.
 * Majority of the properties here are independent so they are has to be reset to null
 * as soon as view is updated with the value.
 *
 * The only exception from this rule is the group of the properties for the animation.
 * For now this is animationName and cacheStrategy. These two properties are should be set
 * simultaneously if the dirty flag is set.
 */
public void commitChanges() {
  LottieAnimationView view = viewWeakReference.get();
  if (view == null) {
    return;
  }

  if (animationJson != null) {
    view.setAnimationFromJson(animationJson, Integer.toString(animationJson.hashCode()));
    animationJson = null;
  }

  if (animationNameDirty) {
    view.setAnimation(animationName);
    animationNameDirty = false;
  }

  if (progress != null) {
    view.setProgress(progress);
    progress = null;
  }

  if (loop != null) {
    view.setRepeatCount(loop ? LottieDrawable.INFINITE : 0);
    loop = null;
  }

  if (speed != null) {
    view.setSpeed(speed);
    speed = null;
  }

  if (scaleType != null) {
    view.setScaleType(scaleType);
    scaleType = null;
  }

  if (renderMode != null) {
    view.setRenderMode(renderMode);
    renderMode = null;
  }

  if (imageAssetsFolder != null) {
    view.setImageAssetsFolder(imageAssetsFolder);
    imageAssetsFolder = null;
  }

  if (enableMergePaths != null) {
    view.enableMergePathsForKitKatAndAbove(enableMergePaths);
    enableMergePaths = null;
  }

  if (colorFilters != null && colorFilters.size() > 0) {
    for (int i = 0 ; i < colorFilters.size() ; i++) {
      ReadableMap current = colorFilters.getMap(i);
      String color = current.getString("color");
      String path = current.getString("keypath");
      SimpleColorFilter colorFilter = new SimpleColorFilter(Color.parseColor(color));
      KeyPath keyPath = new KeyPath(path, "**");
      LottieValueCallback<ColorFilter> callback = new LottieValueCallback<>(colorFilter);
      view.addValueCallback(keyPath, LottieProperty.COLOR_FILTER, callback);
    }
  }
}
 
Example #26
Source File: KeyPathElement.java    From lottie-android with Apache License 2.0 2 votes vote down vote up
/**
 * The overridden method should handle appropriate properties and set value callbacks on their
 * animations.
 */
<T> void addValueCallback(T property, @Nullable LottieValueCallback<T> callback);
 
Example #27
Source File: LottieAnimationView.java    From lottie-android with Apache License 2.0 2 votes vote down vote up
/**
 * Add a property callback for the specified {@link KeyPath}. This {@link KeyPath} can resolve
 * to multiple contents. In that case, the callback's value will apply to all of them.
 *
 * Internally, this will check if the {@link KeyPath} has already been resolved with
 * {@link #resolveKeyPath(KeyPath)} and will resolve it if it hasn't.
 */
public <T> void addValueCallback(KeyPath keyPath, T property, LottieValueCallback<T> callback) {
  lottieDrawable.addValueCallback(keyPath, property, callback);
}