public abstract class

MotionKey

extends java.lang.Object

implements TypedValues

 java.lang.Object

↳androidx.constraintlayout.core.motion.key.MotionKey

Subclasses:

MotionKeyTrigger, MotionKeyTimeCycle, MotionKeyCycle, MotionKeyPosition, MotionKeyAttributes

Gradle dependencies

compile group: 'androidx.constraintlayout', name: 'constraintlayout-core', version: '1.1.0-alpha01'

  • groupId: androidx.constraintlayout
  • artifactId: constraintlayout-core
  • version: 1.1.0-alpha01

Artifact androidx.constraintlayout:constraintlayout-core:1.1.0-alpha01 it located at Google repository (https://maven.google.com/)

Overview

Base class in an element in a KeyFrame

Summary

Fields
public static final java.lang.StringALPHA

public static final java.lang.StringCUSTOM

public static final java.lang.StringELEVATION

public java.util.HashMap<java.lang.String, CustomVariable>mCustom

public intmFramePosition

public intmType

public static final java.lang.StringROTATION

public static final java.lang.StringROTATION_X

public static final java.lang.StringSCALE_X

public static final java.lang.StringSCALE_Y

public static final java.lang.StringTRANSITION_PATH_ROTATE

public static final java.lang.StringTRANSLATION_X

public static final java.lang.StringTRANSLATION_Y

public static intUNSET

public static final java.lang.StringVISIBILITY

Constructors
publicMotionKey()

Methods
public abstract voidaddValues(java.util.HashMap<java.lang.String, SplineSet> splines)

Defines method to add a a view to splines derived form this key frame.

public abstract MotionKeyclone()

public MotionKeycopy(MotionKey src)

public abstract voidgetAttributeNames(java.util.HashSet<java.lang.String> attributes)

public intgetFramePosition()

Gets the current frame position

public voidsetCustomAttribute(java.lang.String name, int type, boolean value)

public voidsetCustomAttribute(java.lang.String name, int type, float value)

public voidsetCustomAttribute(java.lang.String name, int type, int value)

public voidsetCustomAttribute(java.lang.String name, int type, java.lang.String value)

public voidsetFramePosition(int pos)

sets the frame position

public voidsetInterpolation(java.util.HashMap<java.lang.String, java.lang.Integer> interpolation)

Key frame can specify the type of interpolation it wants on various attributes For each string it set it to -1, CurveFit.LINEAR or CurveFit.SPLINE

public booleansetValue(int type, boolean value)

public booleansetValue(int type, float value)

public booleansetValue(int type, int value)

public booleansetValue(int type, java.lang.String value)

public MotionKeysetViewId(int id)

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

Fields

public static int UNSET

public int mFramePosition

public int mType

public java.util.HashMap<java.lang.String, CustomVariable> mCustom

public static final java.lang.String ALPHA

public static final java.lang.String ELEVATION

public static final java.lang.String ROTATION

public static final java.lang.String ROTATION_X

public static final java.lang.String TRANSITION_PATH_ROTATE

public static final java.lang.String SCALE_X

public static final java.lang.String SCALE_Y

public static final java.lang.String TRANSLATION_X

public static final java.lang.String TRANSLATION_Y

public static final java.lang.String CUSTOM

public static final java.lang.String VISIBILITY

Constructors

public MotionKey()

Methods

public abstract void getAttributeNames(java.util.HashSet<java.lang.String> attributes)

public abstract void addValues(java.util.HashMap<java.lang.String, SplineSet> splines)

Defines method to add a a view to splines derived form this key frame. The values are written to the spline

Parameters:

splines: splines to write values to

public void setInterpolation(java.util.HashMap<java.lang.String, java.lang.Integer> interpolation)

Key frame can specify the type of interpolation it wants on various attributes For each string it set it to -1, CurveFit.LINEAR or CurveFit.SPLINE

public MotionKey copy(MotionKey src)

public abstract MotionKey clone()

public MotionKey setViewId(int id)

public void setFramePosition(int pos)

sets the frame position

public int getFramePosition()

Gets the current frame position

public boolean setValue(int type, int value)

public boolean setValue(int type, float value)

public boolean setValue(int type, java.lang.String value)

public boolean setValue(int type, boolean value)

public void setCustomAttribute(java.lang.String name, int type, float value)

public void setCustomAttribute(java.lang.String name, int type, int value)

public void setCustomAttribute(java.lang.String name, int type, boolean value)

public void setCustomAttribute(java.lang.String name, int type, java.lang.String value)

Source

/*
 * Copyright (C) 2018 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.constraintlayout.core.motion.key;

import androidx.constraintlayout.core.motion.CustomVariable;
import androidx.constraintlayout.core.motion.utils.SplineSet;
import androidx.constraintlayout.core.motion.utils.TypedValues;

import java.util.HashMap;
import java.util.HashSet;

/**
 * Base class in an element in a KeyFrame
 *
 * @DoNotShow
 */

public abstract class MotionKey implements TypedValues {
    public static int UNSET = -1;
    public int mFramePosition = UNSET;
    int mTargetId = UNSET;
    String mTargetString = null;
    public int mType;
    public HashMap<String, CustomVariable> mCustom;

    /**
     * @TODO: add description
     */
    public abstract void getAttributeNames(HashSet<String> attributes);

    public static final String ALPHA = "alpha";
    public static final String ELEVATION = "elevation";
    public static final String ROTATION = "rotationZ";
    public static final String ROTATION_X = "rotationX";

    public static final String TRANSITION_PATH_ROTATE = "transitionPathRotate";
    public static final String SCALE_X = "scaleX";
    public static final String SCALE_Y = "scaleY";


    public static final String TRANSLATION_X = "translationX";
    public static final String TRANSLATION_Y = "translationY";

    public static final String CUSTOM = "CUSTOM";

    public static final String VISIBILITY = "visibility";

    boolean matches(String constraintTag) {
        if (mTargetString == null || constraintTag == null) return false;
        return constraintTag.matches(mTargetString);
    }

    /**
     * Defines method to add a a view to splines derived form this key frame.
     * The values are written to the spline
     *
     * @param splines splines to write values to
     * @DoNotShow
     */
    public abstract void addValues(HashMap<String, SplineSet> splines);

    /**
     * Return the float given a value. If the value is a "Float" object it is casted
     *
     * @DoNotShow
     */
    float toFloat(Object value) {
        return (value instanceof Float) ? (Float) value : Float.parseFloat(value.toString());
    }

    /**
     * Return the int version of an object if the value is an Integer object it is casted.
     *
     * @DoNotShow
     */
    int toInt(Object value) {
        return (value instanceof Integer) ? (Integer) value : Integer.parseInt(value.toString());
    }

    /**
     * Return the boolean version this object if the object is a Boolean it is casted.
     *
     * @DoNotShow
     */
    boolean toBoolean(Object value) {
        return (value instanceof Boolean)
                ? (Boolean) value : Boolean.parseBoolean(value.toString());
    }

    /**
     * Key frame can specify the type of interpolation it wants on various attributes
     * For each string it set it to -1, CurveFit.LINEAR or  CurveFit.SPLINE
     */
    public void setInterpolation(HashMap<String, Integer> interpolation) {
    }

    /**
     * @TODO: add description
     */
    public MotionKey copy(MotionKey src) {
        mFramePosition = src.mFramePosition;
        mTargetId = src.mTargetId;
        mTargetString = src.mTargetString;
        mType = src.mType;
        return this;
    }

    /**
     * @TODO: add description
     */
    public abstract MotionKey clone();

    /**
     * @TODO: add description
     */
    public MotionKey setViewId(int id) {
        mTargetId = id;
        return this;
    }

    /**
     * sets the frame position
     */
    public void setFramePosition(int pos) {
        mFramePosition = pos;
    }

    /**
     * Gets the current frame position
     */
    public int getFramePosition() {
        return mFramePosition;
    }

    /**
     * @TODO: add description
     */
    public boolean setValue(int type, int value) {

        switch (type) {
            case TypedValues.TYPE_FRAME_POSITION:
                mFramePosition = value;
                return true;
        }
        return false;
    }

    /**
     * @TODO: add description
     */
    public boolean setValue(int type, float value) {
        return false;
    }

    /**
     * @TODO: add description
     */
    public boolean setValue(int type, String value) {
        switch (type) {
            case TypedValues.TYPE_TARGET:
                mTargetString = value;
                return true;
        }
        return false;
    }

    /**
     * @TODO: add description
     */
    public boolean setValue(int type, boolean value) {
        return false;
    }

    /**
     * @TODO: add description
     */
    public void setCustomAttribute(String name, int type, float value) {
        mCustom.put(name, new CustomVariable(name, type, value));
    }

    /**
     * @TODO: add description
     */
    public void setCustomAttribute(String name, int type, int value) {
        mCustom.put(name, new CustomVariable(name, type, value));
    }

    /**
     * @TODO: add description
     */
    public void setCustomAttribute(String name, int type, boolean value) {
        mCustom.put(name, new CustomVariable(name, type, value));
    }

    /**
     * @TODO: add description
     */
    public void setCustomAttribute(String name, int type, String value) {
        mCustom.put(name, new CustomVariable(name, type, value));
    }
}