android.transition.PathMotion Java Examples

The following examples show how to use android.transition.PathMotion. 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: BezierTransition.java    From CrazyDaily with Apache License 2.0 5 votes vote down vote up
public BezierTransition() {
    setPathMotion(new PathMotion() {
        @Override
        public Path getPath(float startX, float startY, float endX, float endY) {
            Path path = new Path();
            path.moveTo(startX, startY);

            float controlPointX = (startX + endX) / 4;
            float controlPointY = (startY + endY) * 1.0f / 2;

            path.quadTo(controlPointX, controlPointY, endX, endY);
            return path;
        }
    });
}
 
Example #2
Source File: ReflowTextAnimatorHelper.java    From reflow-animator with Apache License 2.0 5 votes vote down vote up
@TargetApi(LOLLIPOP)
private PropertyValuesHolder getPathValuesHolder(Run run, int dy, int dx) {
    PropertyValuesHolder propertyValuesHolder;
    if (IS_LOLLIPOP_OR_ABOVE) {
        PathMotion pathMotion = new PathMotion() {
            @Override
            public Path getPath(float startX, float startY, float endX, float endY) {
                return ReflowTextAnimatorHelper.getPath(startX, startY, endX, endY);
            }
        };
        propertyValuesHolder = PropertyValuesHolder.ofObject(SwitchDrawable.TOP_LEFT, null,
                pathMotion.getPath(
                        run.getStart().left,
                        run.getStart().top,
                        run.getEnd().left - dx,
                        run.getEnd().top - dy));
    } else {
        PointF startPoint = new PointF(run.getStart().left, run.getStart().top);
        PointF endPoint = new PointF(run.getEnd().left - dx, run.getEnd().top - dy);
        propertyValuesHolder = PropertyValuesHolder.ofObject(SwitchDrawable.TOP_LEFT, new TypeEvaluator<PointF>() {
            private final PointF point = new PointF();

            @Override
            public PointF evaluate(float fraction, PointF startValue, PointF endValue) {
                float x = startValue.x + (endValue.x - startValue.x) * fraction;
                float y = startValue.y + (endValue.y - startValue.y) * fraction;

                point.set(x, y);

                return point;
            }
        }, startPoint, endPoint);
    }

    return propertyValuesHolder;
}
 
Example #3
Source File: MaterialContainerTransform.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
private ProgressThresholdsGroup buildThresholdsGroup(boolean entering) {
  PathMotion pathMotion = getPathMotion();
  if (pathMotion instanceof ArcMotion || pathMotion instanceof MaterialArcMotion) {
    return getThresholdsOrDefault(
        entering, DEFAULT_ENTER_THRESHOLDS_ARC, DEFAULT_RETURN_THRESHOLDS_ARC);
  } else {
    return getThresholdsOrDefault(entering, DEFAULT_ENTER_THRESHOLDS, DEFAULT_RETURN_THRESHOLDS);
  }
}
 
Example #4
Source File: MaterialContainerTransform.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
private TransitionDrawable(
    PathMotion pathMotion,
    View startView,
    RectF startBounds,
    ShapeAppearanceModel startShapeAppearanceModel,
    float startElevation,
    View endView,
    RectF endBounds,
    ShapeAppearanceModel endShapeAppearanceModel,
    float endElevation,
    @ColorInt int containerColor,
    @ColorInt int startContainerColor,
    @ColorInt int endContainerColor,
    int scrimColor,
    boolean entering,
    boolean elevationShadowEnabled,
    FadeModeEvaluator fadeModeEvaluator,
    FitModeEvaluator fitModeEvaluator,
    ProgressThresholdsGroup progressThresholds,
    boolean drawDebugEnabled) {
  this.startView = startView;
  this.startBounds = startBounds;
  this.startShapeAppearanceModel = startShapeAppearanceModel;
  this.startElevation = startElevation;
  this.endView = endView;
  this.endBounds = endBounds;
  this.endShapeAppearanceModel = endShapeAppearanceModel;
  this.endElevation = endElevation;
  this.entering = entering;
  this.elevationShadowEnabled = elevationShadowEnabled;
  this.fadeModeEvaluator = fadeModeEvaluator;
  this.fitModeEvaluator = fitModeEvaluator;
  this.progressThresholds = progressThresholds;
  this.drawDebugEnabled = drawDebugEnabled;

  containerPaint.setColor(containerColor);
  startContainerPaint.setColor(startContainerColor);
  endContainerPaint.setColor(endContainerColor);

  compatShadowDrawable.setFillColor(ColorStateList.valueOf(Color.TRANSPARENT));
  compatShadowDrawable.setShadowCompatibilityMode(
      MaterialShapeDrawable.SHADOW_COMPAT_MODE_ALWAYS);
  compatShadowDrawable.setShadowBitmapDrawingEnable(false);
  compatShadowDrawable.setShadowColor(COMPAT_SHADOW_COLOR);

  currentStartBounds = new RectF(startBounds);
  currentStartBoundsMasked = new RectF(currentStartBounds);
  currentEndBounds = new RectF(currentStartBounds);
  currentEndBoundsMasked = new RectF(currentEndBounds);

  // Calculate motion path
  PointF startPoint = getMotionPathPoint(startBounds);
  PointF endPoint = getMotionPathPoint(endBounds);
  Path motionPath = pathMotion.getPath(startPoint.x, startPoint.y, endPoint.x, endPoint.y);
  motionPathMeasure = new PathMeasure(motionPath, false);
  motionPathLength = motionPathMeasure.getLength();

  scrimPaint.setStyle(Paint.Style.FILL);
  scrimPaint.setShader(createColorShader(scrimColor));

  debugPaint.setStyle(Paint.Style.STROKE);
  debugPaint.setStrokeWidth(10);

  // Initializes calculations the drawable
  updateProgress(0);
}