public class

KeyPositions

extends Keys

 java.lang.Object

androidx.constraintlayout.core.dsl.Keys

↳androidx.constraintlayout.core.dsl.KeyPositions

Gradle dependencies

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

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

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

Overview

Provides the API for creating a KeyPosition Object for use in the Core ConstraintLayout & MotionLayout system This allows multiple KeyPosition positions to defined in one object.

Summary

Constructors
publicKeyPositions(int numOfFrames, java.lang.String targets[])

Methods
public int[]getFrames()

public float[]getPercentHeight()

public float[]getPercentWidth()

public float[]getPercentX()

public float[]getPercentY()

public KeyPositions.TypegetPositionType()

public java.lang.StringgetTarget()

public java.lang.StringgetTransitionEasing()

public voidsetFrames(int[] frames[])

public voidsetPercentHeight(float[] percentHeight[])

public voidsetPercentWidth(float[] percentWidth[])

public voidsetPercentX(float[] percentX[])

public voidsetPercentY(float[] percentY[])

public voidsetPositionType(KeyPositions.Type positionType)

public voidsetTransitionEasing(java.lang.String transitionEasing)

public java.lang.StringtoString()

from Keysappend, append, append, append, append, unpack
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Constructors

public KeyPositions(int numOfFrames, java.lang.String targets[])

Methods

public java.lang.String getTransitionEasing()

public void setTransitionEasing(java.lang.String transitionEasing)

public int[] getFrames()

public void setFrames(int[] frames[])

public float[] getPercentWidth()

public void setPercentWidth(float[] percentWidth[])

public float[] getPercentHeight()

public void setPercentHeight(float[] percentHeight[])

public float[] getPercentX()

public void setPercentX(float[] percentX[])

public float[] getPercentY()

public void setPercentY(float[] percentY[])

public KeyPositions.Type getPositionType()

public void setPositionType(KeyPositions.Type positionType)

public java.lang.String getTarget()

public java.lang.String toString()

Source

/*
 * Copyright (C) 2022 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.dsl;

import java.util.Arrays;

/**
 * Provides the API for creating a KeyPosition Object for use in the Core
 * ConstraintLayout & MotionLayout system
 * This allows multiple KeyPosition positions to defined in one object.
 */
public class KeyPositions extends Keys {

    private String[] mTarget = null;
    private String mTransitionEasing = null;
    private Type mPositionType = null;

    private int[] mFrames = null;
    private float[] mPercentWidth = null;
    private float[] mPercentHeight = null;
    private float[] mPercentX = null;
    private float[] mPercentY = null;

    public enum Type {
        CARTESIAN,
        SCREEN,
        PATH
    }

    public KeyPositions(int numOfFrames, String... targets) {
        mTarget = targets;
        mFrames = new int[numOfFrames];
        // the default is evenly spaced  1 at 50, 2 at 33 & 66, 3 at 25,50,75
        float gap = 100f / (mFrames.length + 1);
        for (int i = 0; i < mFrames.length; i++) {
            mFrames[i] = (int) (i * gap + gap);
        }
    }

    public String getTransitionEasing() {
        return mTransitionEasing;
    }

    public void setTransitionEasing(String transitionEasing) {
        mTransitionEasing = transitionEasing;
    }

    public int[] getFrames() {
        return mFrames;
    }

    public void setFrames(int... frames) {
        mFrames = frames;
    }

    public float[] getPercentWidth() {
        return mPercentWidth;
    }

    public void setPercentWidth(float... percentWidth) {
        mPercentWidth = percentWidth;
    }

    public float[] getPercentHeight() {
        return mPercentHeight;
    }

    public void setPercentHeight(float... percentHeight) {
        mPercentHeight = percentHeight;
    }

    public float[] getPercentX() {
        return mPercentX;
    }

    public void setPercentX(float... percentX) {
        mPercentX = percentX;
    }

    public float[] getPercentY() {
        return mPercentY;
    }

    public void setPercentY(float... percentY) {
        mPercentY = percentY;
    }

    public Type getPositionType() {
        return mPositionType;
    }

    public void setPositionType(Type positionType) {
        mPositionType = positionType;
    }

    public String[] getTarget() {
        return mTarget;
    }

    @Override
    public String toString() {
        StringBuilder ret = new StringBuilder();
        ret.append("KeyPositions:{\n");

        append(ret, "target", mTarget);

        ret.append("frame:").append(Arrays.toString(mFrames)).append(",\n");

        if (mPositionType != null) {
            ret.append("type:'").append(mPositionType).append("',\n");
        }

        append(ret, "easing", mTransitionEasing);
        append(ret, "percentX", mPercentX);
        append(ret, "percentX", mPercentY);
        append(ret, "percentWidth", mPercentWidth);
        append(ret, "percentHeight", mPercentHeight);

        ret.append("},\n");
        return ret.toString();
    }
}