public final class

PathInterpolatorCompat

extends java.lang.Object

 java.lang.Object

↳androidx.core.view.animation.PathInterpolatorCompat

Gradle dependencies

compile group: 'androidx.core', name: 'core', version: '1.9.0-alpha04'

  • groupId: androidx.core
  • artifactId: core
  • version: 1.9.0-alpha04

Artifact androidx.core:core:1.9.0-alpha04 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.core:core com.android.support:support-compat

Androidx class mapping:

androidx.core.view.animation.PathInterpolatorCompat android.support.v4.view.animation.PathInterpolatorCompat

Overview

Helper for creating path-based instances. On API 21 or newer, the platform implementation will be used and on older platforms a compatible alternative implementation will be used.

Summary

Methods
public static Interpolatorcreate(float controlX, float controlY)

Create an for a quadratic Bezier curve.

public static Interpolatorcreate(float controlX1, float controlY1, float controlX2, float controlY2)

Create an for a cubic Bezier curve.

public static Interpolatorcreate(Path path)

Create an for an arbitrary .

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Methods

public static Interpolator create(Path path)

Create an for an arbitrary . The must begin at (0, 0) and end at (1, 1). The x-coordinate along the is the input value and the output is the y coordinate of the line at that point. This means that the Path must conform to a function y = f(x).

The must not have gaps in the x direction and must not loop back on itself such that there can be two points sharing the same x coordinate.

Parameters:

path: the to use to make the line representing the

Returns:

the representing the

public static Interpolator create(float controlX, float controlY)

Create an for a quadratic Bezier curve. The end points (0, 0) and (1, 1) are assumed.

Parameters:

controlX: the x coordinate of the quadratic Bezier control point
controlY: the y coordinate of the quadratic Bezier control point

Returns:

the representing the quadratic Bezier curve

public static Interpolator create(float controlX1, float controlY1, float controlX2, float controlY2)

Create an for a cubic Bezier curve. The end points (0, 0) and (1, 1) are assumed.

Parameters:

controlX1: the x coordinate of the first control point of the cubic Bezier
controlY1: the y coordinate of the first control point of the cubic Bezier
controlX2: the x coordinate of the second control point of the cubic Bezier
controlY2: the y coordinate of the second control point of the cubic Bezier

Returns:

the representing the cubic Bezier curve

Source

/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.core.view.animation;

import android.graphics.Path;
import android.os.Build;
import android.view.animation.Interpolator;
import android.view.animation.PathInterpolator;

import androidx.annotation.DoNotInline;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;

/**
 * Helper for creating path-based {@link Interpolator} instances. On API 21 or newer, the
 * platform implementation will be used and on older platforms a compatible alternative
 * implementation will be used.
 */
public final class PathInterpolatorCompat {

    private PathInterpolatorCompat() {
        // prevent instantiation
    }

    /**
     * Create an {@link Interpolator} for an arbitrary {@link Path}. The {@link Path}
     * must begin at {@code (0, 0)} and end at {@code (1, 1)}. The x-coordinate along the
     * {@link Path} is the input value and the output is the y coordinate of the line at that
     * point. This means that the Path must conform to a function {@code y = f(x)}.
     * <p/>
     * The {@link Path} must not have gaps in the x direction and must not
     * loop back on itself such that there can be two points sharing the same x coordinate.
     *
     * @param path the {@link Path} to use to make the line representing the {@link Interpolator}
     * @return the {@link Interpolator} representing the {@link Path}
     */
    @NonNull
    public static Interpolator create(@NonNull Path path) {
        if (Build.VERSION.SDK_INT >= 21) {
            return Api21Impl.createPathInterpolator(path);
        }
        return new PathInterpolatorApi14(path);
    }

    /**
     * Create an {@link Interpolator} for a quadratic Bezier curve. The end points
     * {@code (0, 0)} and {@code (1, 1)} are assumed.
     *
     * @param controlX the x coordinate of the quadratic Bezier control point
     * @param controlY the y coordinate of the quadratic Bezier control point
     * @return the {@link Interpolator} representing the quadratic Bezier curve
     */
    @NonNull
    public static Interpolator create(float controlX, float controlY) {
        if (Build.VERSION.SDK_INT >= 21) {
            return Api21Impl.createPathInterpolator(controlX, controlY);
        }
        return new PathInterpolatorApi14(controlX, controlY);
    }

    /**
     * Create an {@link Interpolator} for a cubic Bezier curve.  The end points
     * {@code (0, 0)} and {@code (1, 1)} are assumed.
     *
     * @param controlX1 the x coordinate of the first control point of the cubic Bezier
     * @param controlY1 the y coordinate of the first control point of the cubic Bezier
     * @param controlX2 the x coordinate of the second control point of the cubic Bezier
     * @param controlY2 the y coordinate of the second control point of the cubic Bezier
     * @return the {@link Interpolator} representing the cubic Bezier curve
     */
    @NonNull
    public static Interpolator create(float controlX1, float controlY1,
            float controlX2, float controlY2) {
        if (Build.VERSION.SDK_INT >= 21) {
            return Api21Impl.createPathInterpolator(controlX1, controlY1, controlX2, controlY2);
        }
        return new PathInterpolatorApi14(controlX1, controlY1, controlX2, controlY2);
    }

    @RequiresApi(21)
    static class Api21Impl {
        private Api21Impl() {
            // This class is not instantiable.
        }

        @DoNotInline
        static PathInterpolator createPathInterpolator(Path path) {
            return new PathInterpolator(path);
        }

        @DoNotInline
        static PathInterpolator createPathInterpolator(float controlX, float controlY) {
            return new PathInterpolator(controlX, controlY);
        }

        @DoNotInline
        static PathInterpolator createPathInterpolator(float controlX1, float controlY1,
                float controlX2, float controlY2) {
            return new PathInterpolator(controlX1, controlY1, controlX2, controlY2);
        }
    }
}