package androidx.constraintlayout.motion.widget; import android.util.Pair; import android.view.View; import android.view.ViewGroup; import androidx.constraintlayout.widget.ConstraintSet; import java.io.PrintStream; import java.util.HashMap; public class DesignTool implements ProxyInterface { private static final boolean DEBUG = false; private static final String TAG = "DesignTool"; public static final HashMap, String> allAttributes; public static final HashMap allMargins; private String mLastEndState = null; private int mLastEndStateId = -1; private String mLastStartState = null; private int mLastStartStateId = -1; private final MotionLayout mMotionLayout; private MotionScene mSceneCache; static { HashMap, String> hashMap = new HashMap<>(); allAttributes = hashMap; HashMap hashMap2 = new HashMap<>(); allMargins = hashMap2; hashMap.put(Pair.create(4, 4), "layout_constraintBottom_toBottomOf"); hashMap.put(Pair.create(4, 3), "layout_constraintBottom_toTopOf"); hashMap.put(Pair.create(3, 4), "layout_constraintTop_toBottomOf"); hashMap.put(Pair.create(3, 3), "layout_constraintTop_toTopOf"); hashMap.put(Pair.create(6, 6), "layout_constraintStart_toStartOf"); hashMap.put(Pair.create(6, 7), "layout_constraintStart_toEndOf"); hashMap.put(Pair.create(7, 6), "layout_constraintEnd_toStartOf"); hashMap.put(Pair.create(7, 7), "layout_constraintEnd_toEndOf"); hashMap.put(Pair.create(1, 1), "layout_constraintLeft_toLeftOf"); hashMap.put(Pair.create(1, 2), "layout_constraintLeft_toRightOf"); hashMap.put(Pair.create(2, 2), "layout_constraintRight_toRightOf"); hashMap.put(Pair.create(2, 1), "layout_constraintRight_toLeftOf"); hashMap.put(Pair.create(5, 5), "layout_constraintBaseline_toBaselineOf"); hashMap2.put("layout_constraintBottom_toBottomOf", "layout_marginBottom"); hashMap2.put("layout_constraintBottom_toTopOf", "layout_marginBottom"); hashMap2.put("layout_constraintTop_toBottomOf", "layout_marginTop"); hashMap2.put("layout_constraintTop_toTopOf", "layout_marginTop"); hashMap2.put("layout_constraintStart_toStartOf", "layout_marginStart"); hashMap2.put("layout_constraintStart_toEndOf", "layout_marginStart"); hashMap2.put("layout_constraintEnd_toStartOf", "layout_marginEnd"); hashMap2.put("layout_constraintEnd_toEndOf", "layout_marginEnd"); hashMap2.put("layout_constraintLeft_toLeftOf", "layout_marginLeft"); hashMap2.put("layout_constraintLeft_toRightOf", "layout_marginLeft"); hashMap2.put("layout_constraintRight_toRightOf", "layout_marginRight"); hashMap2.put("layout_constraintRight_toLeftOf", "layout_marginRight"); } public DesignTool(MotionLayout motionLayout) { this.mMotionLayout = motionLayout; } private static void Connect(int i, ConstraintSet constraintSet, View view, HashMap hashMap, int i2, int i3) { String str = allAttributes.get(Pair.create(Integer.valueOf(i2), Integer.valueOf(i3))); String str2 = hashMap.get(str); if (str2 != null) { String str3 = allMargins.get(str); constraintSet.connect(view.getId(), i2, Integer.parseInt(str2), i3, str3 != null ? GetPxFromDp(i, hashMap.get(str3)) : 0); } } private static int GetPxFromDp(int i, String str) { int indexOf; if (str == null || (indexOf = str.indexOf(100)) == -1) { return 0; } return (int) (((float) (Integer.valueOf(str.substring(0, indexOf)).intValue() * i)) / 160.0f); } private static void SetAbsolutePositions(int i, ConstraintSet constraintSet, View view, HashMap hashMap) { String str = hashMap.get("layout_editor_absoluteX"); if (str != null) { constraintSet.setEditorAbsoluteX(view.getId(), GetPxFromDp(i, str)); } String str2 = hashMap.get("layout_editor_absoluteY"); if (str2 != null) { constraintSet.setEditorAbsoluteY(view.getId(), GetPxFromDp(i, str2)); } } private static void SetBias(ConstraintSet constraintSet, View view, HashMap hashMap, int i) { String str = hashMap.get(i == 1 ? "layout_constraintVertical_bias" : "layout_constraintHorizontal_bias"); if (str == null) { return; } if (i == 0) { constraintSet.setHorizontalBias(view.getId(), Float.parseFloat(str)); } else if (i == 1) { constraintSet.setVerticalBias(view.getId(), Float.parseFloat(str)); } } private static void SetDimensions(int i, ConstraintSet constraintSet, View view, HashMap hashMap, int i2) { String str = hashMap.get(i2 == 1 ? "layout_height" : "layout_width"); if (str != null) { int i3 = -2; if (!str.equalsIgnoreCase("wrap_content")) { i3 = GetPxFromDp(i, str); } if (i2 == 0) { constraintSet.constrainWidth(view.getId(), i3); } else { constraintSet.constrainHeight(view.getId(), i3); } } } @Override // androidx.constraintlayout.motion.widget.ProxyInterface public int designAccess(int i, String str, Object obj, float[] fArr, int i2, float[] fArr2, int i3) { MotionController motionController; View view = (View) obj; if (i != 0) { MotionLayout motionLayout = this.mMotionLayout; if (motionLayout.mScene == null || view == null || (motionController = motionLayout.mFrameArrayList.get(view)) == null) { return -1; } } else { motionController = null; } if (i == 0) { return 1; } if (i == 1) { int duration = this.mMotionLayout.mScene.getDuration() / 16; motionController.buildPath(fArr2, duration); return duration; } else if (i == 2) { int duration2 = this.mMotionLayout.mScene.getDuration() / 16; motionController.buildKeyFrames(fArr2, null); return duration2; } else if (i != 3) { return -1; } else { int duration3 = this.mMotionLayout.mScene.getDuration() / 16; return motionController.getAttributeValues(str, fArr2, i3); } } public void disableAutoTransition(boolean z2) { this.mMotionLayout.disableAutoTransition(z2); } public void dumpConstraintSet(String str) { MotionLayout motionLayout = this.mMotionLayout; if (motionLayout.mScene == null) { motionLayout.mScene = this.mSceneCache; } int lookUpConstraintId = motionLayout.lookUpConstraintId(str); PrintStream printStream = System.out; printStream.println(" dumping " + str + " (" + lookUpConstraintId + ")"); try { this.mMotionLayout.mScene.getConstraintSet(lookUpConstraintId).dump(this.mMotionLayout.mScene, new int[0]); } catch (Exception e) { e.printStackTrace(); } } public int getAnimationKeyFrames(Object obj, float[] fArr) { MotionScene motionScene = this.mMotionLayout.mScene; if (motionScene == null) { return -1; } int duration = motionScene.getDuration() / 16; MotionController motionController = this.mMotionLayout.mFrameArrayList.get(obj); if (motionController == null) { return 0; } motionController.buildKeyFrames(fArr, null); return duration; } public int getAnimationPath(Object obj, float[] fArr, int i) { MotionLayout motionLayout = this.mMotionLayout; if (motionLayout.mScene == null) { return -1; } MotionController motionController = motionLayout.mFrameArrayList.get(obj); if (motionController == null) { return 0; } motionController.buildPath(fArr, i); return i; } public void getAnimationRectangles(Object obj, float[] fArr) { MotionScene motionScene = this.mMotionLayout.mScene; if (motionScene != null) { int duration = motionScene.getDuration() / 16; MotionController motionController = this.mMotionLayout.mFrameArrayList.get(obj); if (motionController != null) { motionController.buildRectangles(fArr, duration); } } } public String getEndState() { int endState = this.mMotionLayout.getEndState(); if (this.mLastEndStateId == endState) { return this.mLastEndState; } String constraintSetNames = this.mMotionLayout.getConstraintSetNames(endState); if (constraintSetNames != null) { this.mLastEndState = constraintSetNames; this.mLastEndStateId = endState; } return constraintSetNames; } public int getKeyFrameInfo(Object obj, int i, int[] iArr) { MotionController motionController = this.mMotionLayout.mFrameArrayList.get((View) obj); if (motionController == null) { return 0; } return motionController.getKeyFrameInfo(i, iArr); } @Override // androidx.constraintlayout.motion.widget.ProxyInterface public float getKeyFramePosition(Object obj, int i, float f, float f2) { return this.mMotionLayout.mFrameArrayList.get((View) obj).getKeyFrameParameter(i, f, f2); } public int getKeyFramePositions(Object obj, int[] iArr, float[] fArr) { MotionController motionController = this.mMotionLayout.mFrameArrayList.get((View) obj); if (motionController == null) { return 0; } return motionController.getkeyFramePositions(iArr, fArr); } public Object getKeyframe(int i, int i2, int i3) { MotionLayout motionLayout = this.mMotionLayout; MotionScene motionScene = motionLayout.mScene; if (motionScene == null) { return null; } return motionScene.getKeyFrame(motionLayout.getContext(), i, i2, i3); } public Object getKeyframe(Object obj, int i, int i2) { if (this.mMotionLayout.mScene == null) { return null; } int id2 = ((View) obj).getId(); MotionLayout motionLayout = this.mMotionLayout; return motionLayout.mScene.getKeyFrame(motionLayout.getContext(), i, id2, i2); } @Override // androidx.constraintlayout.motion.widget.ProxyInterface public Object getKeyframeAtLocation(Object obj, float f, float f2) { MotionController motionController; View view = (View) obj; MotionLayout motionLayout = this.mMotionLayout; if (motionLayout.mScene == null) { return -1; } if (view == null || (motionController = motionLayout.mFrameArrayList.get(view)) == null) { return null; } ViewGroup viewGroup = (ViewGroup) view.getParent(); return motionController.getPositionKeyframe(viewGroup.getWidth(), viewGroup.getHeight(), f, f2); } @Override // androidx.constraintlayout.motion.widget.ProxyInterface public Boolean getPositionKeyframe(Object obj, Object obj2, float f, float f2, String[] strArr, float[] fArr) { if (!(obj instanceof KeyPositionBase)) { return Boolean.FALSE; } View view = (View) obj2; this.mMotionLayout.mFrameArrayList.get(view).positionKeyframe(view, (KeyPositionBase) obj, f, f2, strArr, fArr); this.mMotionLayout.rebuildScene(); this.mMotionLayout.mInTransition = true; return Boolean.TRUE; } public float getProgress() { return this.mMotionLayout.getProgress(); } public String getStartState() { int startState = this.mMotionLayout.getStartState(); if (this.mLastStartStateId == startState) { return this.mLastStartState; } String constraintSetNames = this.mMotionLayout.getConstraintSetNames(startState); if (constraintSetNames != null) { this.mLastStartState = constraintSetNames; this.mLastStartStateId = startState; } return this.mMotionLayout.getConstraintSetNames(startState); } public String getState() { if (!(this.mLastStartState == null || this.mLastEndState == null)) { float progress = getProgress(); if (progress <= 0.01f) { return this.mLastStartState; } if (progress >= 0.99f) { return this.mLastEndState; } } return this.mLastStartState; } @Override // androidx.constraintlayout.motion.widget.ProxyInterface public long getTransitionTimeMs() { return this.mMotionLayout.getTransitionTimeMs(); } public boolean isInTransition() { return (this.mLastStartState == null || this.mLastEndState == null) ? false : true; } @Override // androidx.constraintlayout.motion.widget.ProxyInterface public void setAttributes(int i, String str, Object obj, Object obj2) { View view = (View) obj; HashMap hashMap = (HashMap) obj2; int lookUpConstraintId = this.mMotionLayout.lookUpConstraintId(str); ConstraintSet constraintSet = this.mMotionLayout.mScene.getConstraintSet(lookUpConstraintId); if (constraintSet != null) { constraintSet.clear(view.getId()); SetDimensions(i, constraintSet, view, hashMap, 0); SetDimensions(i, constraintSet, view, hashMap, 1); Connect(i, constraintSet, view, hashMap, 6, 6); Connect(i, constraintSet, view, hashMap, 6, 7); Connect(i, constraintSet, view, hashMap, 7, 7); Connect(i, constraintSet, view, hashMap, 7, 6); Connect(i, constraintSet, view, hashMap, 1, 1); Connect(i, constraintSet, view, hashMap, 1, 2); Connect(i, constraintSet, view, hashMap, 2, 2); Connect(i, constraintSet, view, hashMap, 2, 1); Connect(i, constraintSet, view, hashMap, 3, 3); Connect(i, constraintSet, view, hashMap, 3, 4); Connect(i, constraintSet, view, hashMap, 4, 3); Connect(i, constraintSet, view, hashMap, 4, 4); Connect(i, constraintSet, view, hashMap, 5, 5); SetBias(constraintSet, view, hashMap, 0); SetBias(constraintSet, view, hashMap, 1); SetAbsolutePositions(i, constraintSet, view, hashMap); this.mMotionLayout.updateState(lookUpConstraintId, constraintSet); this.mMotionLayout.requestLayout(); } } @Override // androidx.constraintlayout.motion.widget.ProxyInterface public void setKeyFrame(Object obj, int i, String str, Object obj2) { MotionScene motionScene = this.mMotionLayout.mScene; if (motionScene != null) { motionScene.setKeyframe((View) obj, i, str, obj2); MotionLayout motionLayout = this.mMotionLayout; motionLayout.mTransitionGoalPosition = ((float) i) / 100.0f; motionLayout.mTransitionLastPosition = 0.0f; motionLayout.rebuildScene(); this.mMotionLayout.evaluate(true); } } @Override // androidx.constraintlayout.motion.widget.ProxyInterface public boolean setKeyFramePosition(Object obj, int i, int i2, float f, float f2) { MotionLayout motionLayout = this.mMotionLayout; if (motionLayout.mScene == null) { return false; } MotionController motionController = motionLayout.mFrameArrayList.get(obj); MotionLayout motionLayout2 = this.mMotionLayout; int i3 = (int) (motionLayout2.mTransitionPosition * 100.0f); if (motionController == null) { return false; } View view = (View) obj; if (!motionLayout2.mScene.hasKeyFramePosition(view, i3)) { return false; } float keyFrameParameter = motionController.getKeyFrameParameter(2, f, f2); float keyFrameParameter2 = motionController.getKeyFrameParameter(5, f, f2); this.mMotionLayout.mScene.setKeyframe(view, i3, "motion:percentX", Float.valueOf(keyFrameParameter)); this.mMotionLayout.mScene.setKeyframe(view, i3, "motion:percentY", Float.valueOf(keyFrameParameter2)); this.mMotionLayout.rebuildScene(); this.mMotionLayout.evaluate(true); this.mMotionLayout.invalidate(); return true; } public void setKeyframe(Object obj, String str, Object obj2) { if (obj instanceof Key) { ((Key) obj).setValue(str, obj2); this.mMotionLayout.rebuildScene(); this.mMotionLayout.mInTransition = true; } } public void setState(String str) { if (str == null) { str = "motion_base"; } if (this.mLastStartState != str) { this.mLastStartState = str; this.mLastEndState = null; MotionLayout motionLayout = this.mMotionLayout; if (motionLayout.mScene == null) { motionLayout.mScene = this.mSceneCache; } int lookUpConstraintId = motionLayout.lookUpConstraintId(str); this.mLastStartStateId = lookUpConstraintId; if (lookUpConstraintId != 0) { if (lookUpConstraintId == this.mMotionLayout.getStartState()) { this.mMotionLayout.setProgress(0.0f); } else if (lookUpConstraintId == this.mMotionLayout.getEndState()) { this.mMotionLayout.setProgress(1.0f); } else { this.mMotionLayout.transitionToState(lookUpConstraintId); this.mMotionLayout.setProgress(1.0f); } } this.mMotionLayout.requestLayout(); } } @Override // androidx.constraintlayout.motion.widget.ProxyInterface public void setToolPosition(float f) { MotionLayout motionLayout = this.mMotionLayout; if (motionLayout.mScene == null) { motionLayout.mScene = this.mSceneCache; } motionLayout.setProgress(f); this.mMotionLayout.evaluate(true); this.mMotionLayout.requestLayout(); this.mMotionLayout.invalidate(); } public void setTransition(String str, String str2) { MotionLayout motionLayout = this.mMotionLayout; if (motionLayout.mScene == null) { motionLayout.mScene = this.mSceneCache; } int lookUpConstraintId = motionLayout.lookUpConstraintId(str); int lookUpConstraintId2 = this.mMotionLayout.lookUpConstraintId(str2); this.mMotionLayout.setTransition(lookUpConstraintId, lookUpConstraintId2); this.mLastStartStateId = lookUpConstraintId; this.mLastEndStateId = lookUpConstraintId2; this.mLastStartState = str; this.mLastEndState = str2; } public void setViewDebug(Object obj, int i) { MotionController motionController = this.mMotionLayout.mFrameArrayList.get(obj); if (motionController != null) { motionController.setDrawPath(i); this.mMotionLayout.invalidate(); } } }