public class

MotionHelper

extends ConstraintHelper

implements MotionHelperInterface

 java.lang.Object

↳View

androidx.constraintlayout.widget.ConstraintHelper

↳androidx.constraintlayout.motion.widget.MotionHelper

Subclasses:

Carousel, MotionEffect

Gradle dependencies

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

  • groupId: androidx.constraintlayout
  • artifactId: constraintlayout
  • version: 2.2.0-alpha01

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

Androidx artifact mapping:

androidx.constraintlayout:constraintlayout com.android.support.constraint:constraint-layout

Summary

Fields
protected Viewviews

from ConstraintHelpermCount, mHelperWidget, mIds[], mMap, mReferenceIds, mReferenceTags, mUseViewMeasure, myContext
Constructors
publicMotionHelper(Context context)

publicMotionHelper(Context context, AttributeSet attrs)

publicMotionHelper(Context context, AttributeSet attrs, int defStyleAttr)

Methods
public floatgetProgress()

protected voidinit(AttributeSet attrs)

public booleanisDecorator()

public booleanisUsedOnShow()

public booleanisUseOnHide()

public voidonFinishedMotionScene(MotionLayout motionLayout)

public voidonPostDraw(Canvas canvas)

public voidonPreDraw(Canvas canvas)

public voidonPreSetup(MotionLayout motionLayout, java.util.HashMap<View, MotionController> controllerMap)

public voidonTransitionChange(MotionLayout motionLayout, int startId, int endId, float progress)

public voidonTransitionCompleted(MotionLayout motionLayout, int currentId)

public voidonTransitionStarted(MotionLayout motionLayout, int startId, int endId)

public voidonTransitionTrigger(MotionLayout motionLayout, int triggerId, boolean positive, float progress)

public voidsetProgress(float progress)

public voidsetProgress(View view, float progress)

from ConstraintHelperaddView, applyLayoutFeatures, applyLayoutFeatures, applyLayoutFeaturesInConstraintSet, containsId, getReferencedIds, getViews, indexFromId, loadParameters, onAttachedToWindow, onDraw, onMeasure, removeView, resolveRtl, setIds, setReferencedIds, setReferenceTags, setTag, updatePostConstraints, updatePostLayout, updatePostMeasure, updatePreDraw, updatePreLayout, updatePreLayout, validateParams
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Fields

protected View views

Constructors

public MotionHelper(Context context)

public MotionHelper(Context context, AttributeSet attrs)

public MotionHelper(Context context, AttributeSet attrs, int defStyleAttr)

Methods

protected void init(AttributeSet attrs)

public boolean isUsedOnShow()

Returns:

public boolean isUseOnHide()

Returns:

public float getProgress()

public void setProgress(float progress)

public void setProgress(View view, float progress)

Parameters:

view:
progress:

public void onTransitionStarted(MotionLayout motionLayout, int startId, int endId)

public void onTransitionChange(MotionLayout motionLayout, int startId, int endId, float progress)

public void onTransitionCompleted(MotionLayout motionLayout, int currentId)

public void onTransitionTrigger(MotionLayout motionLayout, int triggerId, boolean positive, float progress)

public boolean isDecorator()

public void onPreDraw(Canvas canvas)

public void onFinishedMotionScene(MotionLayout motionLayout)

public void onPostDraw(Canvas canvas)

public void onPreSetup(MotionLayout motionLayout, java.util.HashMap<View, MotionController> controllerMap)

Source

/*
 * Copyright (C) 2021 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.motion.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;

import androidx.constraintlayout.widget.ConstraintHelper;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.R;

import java.util.HashMap;

/**
 * @DoNotShow
 */
public class MotionHelper extends ConstraintHelper implements MotionHelperInterface {

    private boolean mUseOnShow = false;
    private boolean mUseOnHide = false;
    private float mProgress;
    protected View[] views;

    public MotionHelper(Context context) {
        super(context);
    }

    public MotionHelper(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(attrs);
    }

    public MotionHelper(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(attrs);
    }

    /**
     * @DoNotShow
     */
    protected void init(AttributeSet attrs) {
        super.init(attrs);
        if (attrs != null) {
            TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.MotionHelper);
            final int n = a.getIndexCount();
            for (int i = 0; i < n; i++) {
                int attr = a.getIndex(i);
                if (attr == R.styleable.MotionHelper_onShow) {
                    mUseOnShow = a.getBoolean(attr, mUseOnShow);
                } else if (attr == R.styleable.MotionHelper_onHide) {
                    mUseOnHide = a.getBoolean(attr, mUseOnHide);
                }
            }
            a.recycle();
        }
    }

    /**
     *
     * @return
     * @DoNotShow
     */
    @Override
    public boolean isUsedOnShow() {
        return mUseOnShow;
    }

    /**
     *
     * @return
     * @DoNotShow
     */
    @Override
    public boolean isUseOnHide() {
        return mUseOnHide;
    }

    @Override
    public float getProgress() {
        return mProgress;
    }

    @Override
    public void setProgress(float progress) {
        mProgress = progress;
        if (this.mCount > 0) {
            this.views = this.getViews((ConstraintLayout) this.getParent());

            for (int i = 0; i < this.mCount; ++i) {
                View view = this.views[i];
                this.setProgress(view, progress);
            }
        } else {
            ViewGroup group = (ViewGroup) this.getParent();
            int count = group.getChildCount();

            for (int i = 0; i < count; ++i) {
                View view = group.getChildAt(i);
                if (view instanceof MotionHelper) {
                    continue;
                }
                this.setProgress(view, progress);
            }
        }
    }

    /**
     *
     * @param view
     * @param progress
     * @DoNotShow
     */
    public void setProgress(View view, float progress) {

    }

    @Override
    public void onTransitionStarted(MotionLayout motionLayout, int startId, int endId) {
    }

    @Override
    public void onTransitionChange(MotionLayout motionLayout,
                                   int startId,
                                   int endId,
                                   float progress) {
    }

    @Override
    public void onTransitionCompleted(MotionLayout motionLayout, int currentId) {
    }

    @Override
    public void onTransitionTrigger(MotionLayout motionLayout,
                                    int triggerId,
                                    boolean positive,
                                    float progress) {
    }

    @Override
    public boolean isDecorator() {
        return false;
    }

    @Override
    public void onPreDraw(Canvas canvas) {

    }
    @Override
    public void onFinishedMotionScene(MotionLayout motionLayout) {

    }

    @Override
    public void onPostDraw(Canvas canvas) {

    }

    @Override
    public void onPreSetup(MotionLayout motionLayout,
                           HashMap<View, MotionController> controllerMap) {

    }

}