package androidx.constraintlayout.solver.widgets.analyzer; import androidx.constraintlayout.solver.widgets.Barrier; import androidx.constraintlayout.solver.widgets.ConstraintWidget; import androidx.constraintlayout.solver.widgets.ConstraintWidgetContainer; import androidx.constraintlayout.solver.widgets.Guideline; import androidx.constraintlayout.solver.widgets.HelperWidget; import androidx.constraintlayout.solver.widgets.analyzer.BasicMeasure; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; /* loaded from: classes.dex */ public class DependencyGraph { private static final boolean USE_GROUPS = true; private ConstraintWidgetContainer container; private ConstraintWidgetContainer mContainer; private boolean mNeedBuildGraph = true; private boolean mNeedRedoMeasures = true; private ArrayList mRuns = new ArrayList<>(); private ArrayList runGroups = new ArrayList<>(); private BasicMeasure.Measurer mMeasurer = null; private BasicMeasure.Measure mMeasure = new BasicMeasure.Measure(); ArrayList mGroups = new ArrayList<>(); public void invalidateGraph() { this.mNeedBuildGraph = true; } public void invalidateMeasures() { this.mNeedRedoMeasures = true; } public void setMeasurer(BasicMeasure.Measurer measurer) { this.mMeasurer = measurer; } public DependencyGraph(ConstraintWidgetContainer constraintWidgetContainer) { this.container = constraintWidgetContainer; this.mContainer = constraintWidgetContainer; } private int computeWrap(ConstraintWidgetContainer constraintWidgetContainer, int i) { int size = this.mGroups.size(); long j = 0; for (int i2 = 0; i2 < size; i2++) { j = Math.max(j, this.mGroups.get(i2).computeWrapSize(constraintWidgetContainer, i)); } return (int) j; } public void defineTerminalWidgets(ConstraintWidget.DimensionBehaviour dimensionBehaviour, ConstraintWidget.DimensionBehaviour dimensionBehaviour2) { if (this.mNeedBuildGraph) { buildGraph(); Iterator it = this.container.mChildren.iterator(); boolean z = false; while (it.hasNext()) { ConstraintWidget next = it.next(); next.isTerminalWidget[0] = true; next.isTerminalWidget[1] = true; if (next instanceof Barrier) { z = true; } } if (z) { return; } Iterator it2 = this.mGroups.iterator(); while (it2.hasNext()) { it2.next().defineTerminalWidgets(dimensionBehaviour == ConstraintWidget.DimensionBehaviour.WRAP_CONTENT, dimensionBehaviour2 == ConstraintWidget.DimensionBehaviour.WRAP_CONTENT); } } } public boolean directMeasure(boolean z) { boolean z2; boolean z3 = true; boolean z4 = z & true; if (this.mNeedBuildGraph || this.mNeedRedoMeasures) { Iterator it = this.container.mChildren.iterator(); while (it.hasNext()) { ConstraintWidget next = it.next(); next.measured = false; next.horizontalRun.reset(); next.verticalRun.reset(); } this.container.measured = false; this.container.horizontalRun.reset(); this.container.verticalRun.reset(); this.mNeedRedoMeasures = false; } if (basicMeasureWidgets(this.mContainer)) { return false; } this.container.setX(0); this.container.setY(0); ConstraintWidget.DimensionBehaviour dimensionBehaviour = this.container.getDimensionBehaviour(0); ConstraintWidget.DimensionBehaviour dimensionBehaviour2 = this.container.getDimensionBehaviour(1); if (this.mNeedBuildGraph) { buildGraph(); } int x = this.container.getX(); int y = this.container.getY(); this.container.horizontalRun.start.resolve(x); this.container.verticalRun.start.resolve(y); measureWidgets(); if (dimensionBehaviour == ConstraintWidget.DimensionBehaviour.WRAP_CONTENT || dimensionBehaviour2 == ConstraintWidget.DimensionBehaviour.WRAP_CONTENT) { if (z4) { Iterator it2 = this.mRuns.iterator(); while (true) { if (!it2.hasNext()) { break; } if (!it2.next().supportsWrapComputation()) { z4 = false; break; } } } if (z4 && dimensionBehaviour == ConstraintWidget.DimensionBehaviour.WRAP_CONTENT) { this.container.setHorizontalDimensionBehaviour(ConstraintWidget.DimensionBehaviour.FIXED); ConstraintWidgetContainer constraintWidgetContainer = this.container; constraintWidgetContainer.setWidth(computeWrap(constraintWidgetContainer, 0)); this.container.horizontalRun.dimension.resolve(this.container.getWidth()); } if (z4 && dimensionBehaviour2 == ConstraintWidget.DimensionBehaviour.WRAP_CONTENT) { this.container.setVerticalDimensionBehaviour(ConstraintWidget.DimensionBehaviour.FIXED); ConstraintWidgetContainer constraintWidgetContainer2 = this.container; constraintWidgetContainer2.setHeight(computeWrap(constraintWidgetContainer2, 1)); this.container.verticalRun.dimension.resolve(this.container.getHeight()); } } if (this.container.mListDimensionBehaviors[0] == ConstraintWidget.DimensionBehaviour.FIXED || this.container.mListDimensionBehaviors[0] == ConstraintWidget.DimensionBehaviour.MATCH_PARENT) { int width = this.container.getWidth() + x; this.container.horizontalRun.end.resolve(width); this.container.horizontalRun.dimension.resolve(width - x); measureWidgets(); if (this.container.mListDimensionBehaviors[1] == ConstraintWidget.DimensionBehaviour.FIXED || this.container.mListDimensionBehaviors[1] == ConstraintWidget.DimensionBehaviour.MATCH_PARENT) { int height = this.container.getHeight() + y; this.container.verticalRun.end.resolve(height); this.container.verticalRun.dimension.resolve(height - y); } measureWidgets(); z2 = true; } else { z2 = false; } Iterator it3 = this.mRuns.iterator(); while (it3.hasNext()) { WidgetRun next2 = it3.next(); if (next2.widget != this.container || next2.resolved) { next2.applyToWidget(); } } Iterator it4 = this.mRuns.iterator(); while (it4.hasNext()) { WidgetRun next3 = it4.next(); if (z2 || next3.widget != this.container) { if (!next3.start.resolved || ((!next3.end.resolved && !(next3 instanceof GuidelineReference)) || (!next3.dimension.resolved && !(next3 instanceof ChainRun) && !(next3 instanceof GuidelineReference)))) { z3 = false; break; } } } this.container.setHorizontalDimensionBehaviour(dimensionBehaviour); this.container.setVerticalDimensionBehaviour(dimensionBehaviour2); return z3; } public boolean directMeasureSetup(boolean z) { if (this.mNeedBuildGraph) { Iterator it = this.container.mChildren.iterator(); while (it.hasNext()) { ConstraintWidget next = it.next(); next.measured = false; next.horizontalRun.dimension.resolved = false; next.horizontalRun.resolved = false; next.horizontalRun.reset(); next.verticalRun.dimension.resolved = false; next.verticalRun.resolved = false; next.verticalRun.reset(); } this.container.measured = false; this.container.horizontalRun.dimension.resolved = false; this.container.horizontalRun.resolved = false; this.container.horizontalRun.reset(); this.container.verticalRun.dimension.resolved = false; this.container.verticalRun.resolved = false; this.container.verticalRun.reset(); buildGraph(); } if (basicMeasureWidgets(this.mContainer)) { return false; } this.container.setX(0); this.container.setY(0); this.container.horizontalRun.start.resolve(0); this.container.verticalRun.start.resolve(0); return true; } public boolean directMeasureWithOrientation(boolean z, int i) { boolean z2; boolean z3 = true; boolean z4 = z & true; ConstraintWidget.DimensionBehaviour dimensionBehaviour = this.container.getDimensionBehaviour(0); ConstraintWidget.DimensionBehaviour dimensionBehaviour2 = this.container.getDimensionBehaviour(1); int x = this.container.getX(); int y = this.container.getY(); if (z4 && (dimensionBehaviour == ConstraintWidget.DimensionBehaviour.WRAP_CONTENT || dimensionBehaviour2 == ConstraintWidget.DimensionBehaviour.WRAP_CONTENT)) { Iterator it = this.mRuns.iterator(); while (true) { if (!it.hasNext()) { break; } WidgetRun next = it.next(); if (next.orientation == i && !next.supportsWrapComputation()) { z4 = false; break; } } if (i == 0) { if (z4 && dimensionBehaviour == ConstraintWidget.DimensionBehaviour.WRAP_CONTENT) { this.container.setHorizontalDimensionBehaviour(ConstraintWidget.DimensionBehaviour.FIXED); ConstraintWidgetContainer constraintWidgetContainer = this.container; constraintWidgetContainer.setWidth(computeWrap(constraintWidgetContainer, 0)); this.container.horizontalRun.dimension.resolve(this.container.getWidth()); } } else if (z4 && dimensionBehaviour2 == ConstraintWidget.DimensionBehaviour.WRAP_CONTENT) { this.container.setVerticalDimensionBehaviour(ConstraintWidget.DimensionBehaviour.FIXED); ConstraintWidgetContainer constraintWidgetContainer2 = this.container; constraintWidgetContainer2.setHeight(computeWrap(constraintWidgetContainer2, 1)); this.container.verticalRun.dimension.resolve(this.container.getHeight()); } } if (i == 0) { if (this.container.mListDimensionBehaviors[0] == ConstraintWidget.DimensionBehaviour.FIXED || this.container.mListDimensionBehaviors[0] == ConstraintWidget.DimensionBehaviour.MATCH_PARENT) { int width = this.container.getWidth() + x; this.container.horizontalRun.end.resolve(width); this.container.horizontalRun.dimension.resolve(width - x); z2 = true; } z2 = false; } else { if (this.container.mListDimensionBehaviors[1] == ConstraintWidget.DimensionBehaviour.FIXED || this.container.mListDimensionBehaviors[1] == ConstraintWidget.DimensionBehaviour.MATCH_PARENT) { int height = this.container.getHeight() + y; this.container.verticalRun.end.resolve(height); this.container.verticalRun.dimension.resolve(height - y); z2 = true; } z2 = false; } measureWidgets(); Iterator it2 = this.mRuns.iterator(); while (it2.hasNext()) { WidgetRun next2 = it2.next(); if (next2.orientation == i && (next2.widget != this.container || next2.resolved)) { next2.applyToWidget(); } } Iterator it3 = this.mRuns.iterator(); while (it3.hasNext()) { WidgetRun next3 = it3.next(); if (next3.orientation == i && (z2 || next3.widget != this.container)) { if (!next3.start.resolved || !next3.end.resolved || (!(next3 instanceof ChainRun) && !next3.dimension.resolved)) { z3 = false; break; } } } this.container.setHorizontalDimensionBehaviour(dimensionBehaviour); this.container.setVerticalDimensionBehaviour(dimensionBehaviour2); return z3; } private void measure(ConstraintWidget constraintWidget, ConstraintWidget.DimensionBehaviour dimensionBehaviour, int i, ConstraintWidget.DimensionBehaviour dimensionBehaviour2, int i2) { this.mMeasure.horizontalBehavior = dimensionBehaviour; this.mMeasure.verticalBehavior = dimensionBehaviour2; this.mMeasure.horizontalDimension = i; this.mMeasure.verticalDimension = i2; this.mMeasurer.measure(constraintWidget, this.mMeasure); constraintWidget.setWidth(this.mMeasure.measuredWidth); constraintWidget.setHeight(this.mMeasure.measuredHeight); constraintWidget.setHasBaseline(this.mMeasure.measuredHasBaseline); constraintWidget.setBaselineDistance(this.mMeasure.measuredBaseline); } private boolean basicMeasureWidgets(ConstraintWidgetContainer constraintWidgetContainer) { int i; ConstraintWidget.DimensionBehaviour dimensionBehaviour; int i2; Iterator it = constraintWidgetContainer.mChildren.iterator(); while (it.hasNext()) { ConstraintWidget next = it.next(); ConstraintWidget.DimensionBehaviour dimensionBehaviour2 = next.mListDimensionBehaviors[0]; ConstraintWidget.DimensionBehaviour dimensionBehaviour3 = next.mListDimensionBehaviors[1]; if (next.getVisibility() == 8) { next.measured = true; } else { if (next.mMatchConstraintPercentWidth < 1.0f && dimensionBehaviour2 == ConstraintWidget.DimensionBehaviour.MATCH_CONSTRAINT) { next.mMatchConstraintDefaultWidth = 2; } if (next.mMatchConstraintPercentHeight < 1.0f && dimensionBehaviour3 == ConstraintWidget.DimensionBehaviour.MATCH_CONSTRAINT) { next.mMatchConstraintDefaultHeight = 2; } if (next.getDimensionRatio() > 0.0f) { if (dimensionBehaviour2 == ConstraintWidget.DimensionBehaviour.MATCH_CONSTRAINT && (dimensionBehaviour3 == ConstraintWidget.DimensionBehaviour.WRAP_CONTENT || dimensionBehaviour3 == ConstraintWidget.DimensionBehaviour.FIXED)) { next.mMatchConstraintDefaultWidth = 3; } else if (dimensionBehaviour3 == ConstraintWidget.DimensionBehaviour.MATCH_CONSTRAINT && (dimensionBehaviour2 == ConstraintWidget.DimensionBehaviour.WRAP_CONTENT || dimensionBehaviour2 == ConstraintWidget.DimensionBehaviour.FIXED)) { next.mMatchConstraintDefaultHeight = 3; } else if (dimensionBehaviour2 == ConstraintWidget.DimensionBehaviour.MATCH_CONSTRAINT && dimensionBehaviour3 == ConstraintWidget.DimensionBehaviour.MATCH_CONSTRAINT) { if (next.mMatchConstraintDefaultWidth == 0) { next.mMatchConstraintDefaultWidth = 3; } if (next.mMatchConstraintDefaultHeight == 0) { next.mMatchConstraintDefaultHeight = 3; } } } if (dimensionBehaviour2 == ConstraintWidget.DimensionBehaviour.MATCH_CONSTRAINT && next.mMatchConstraintDefaultWidth == 1 && (next.mLeft.mTarget == null || next.mRight.mTarget == null)) { dimensionBehaviour2 = ConstraintWidget.DimensionBehaviour.WRAP_CONTENT; } ConstraintWidget.DimensionBehaviour dimensionBehaviour4 = dimensionBehaviour2; ConstraintWidget.DimensionBehaviour dimensionBehaviour5 = (dimensionBehaviour3 == ConstraintWidget.DimensionBehaviour.MATCH_CONSTRAINT && next.mMatchConstraintDefaultHeight == 1 && (next.mTop.mTarget == null || next.mBottom.mTarget == null)) ? ConstraintWidget.DimensionBehaviour.WRAP_CONTENT : dimensionBehaviour3; next.horizontalRun.dimensionBehavior = dimensionBehaviour4; next.horizontalRun.matchConstraintsType = next.mMatchConstraintDefaultWidth; next.verticalRun.dimensionBehavior = dimensionBehaviour5; next.verticalRun.matchConstraintsType = next.mMatchConstraintDefaultHeight; if ((dimensionBehaviour4 == ConstraintWidget.DimensionBehaviour.MATCH_PARENT || dimensionBehaviour4 == ConstraintWidget.DimensionBehaviour.FIXED || dimensionBehaviour4 == ConstraintWidget.DimensionBehaviour.WRAP_CONTENT) && (dimensionBehaviour5 == ConstraintWidget.DimensionBehaviour.MATCH_PARENT || dimensionBehaviour5 == ConstraintWidget.DimensionBehaviour.FIXED || dimensionBehaviour5 == ConstraintWidget.DimensionBehaviour.WRAP_CONTENT)) { int width = next.getWidth(); if (dimensionBehaviour4 == ConstraintWidget.DimensionBehaviour.MATCH_PARENT) { i = (constraintWidgetContainer.getWidth() - next.mLeft.mMargin) - next.mRight.mMargin; dimensionBehaviour4 = ConstraintWidget.DimensionBehaviour.FIXED; } else { i = width; } int height = next.getHeight(); if (dimensionBehaviour5 == ConstraintWidget.DimensionBehaviour.MATCH_PARENT) { i2 = (constraintWidgetContainer.getHeight() - next.mTop.mMargin) - next.mBottom.mMargin; dimensionBehaviour = ConstraintWidget.DimensionBehaviour.FIXED; } else { dimensionBehaviour = dimensionBehaviour5; i2 = height; } measure(next, dimensionBehaviour4, i, dimensionBehaviour, i2); next.horizontalRun.dimension.resolve(next.getWidth()); next.verticalRun.dimension.resolve(next.getHeight()); next.measured = true; } else { if (dimensionBehaviour4 == ConstraintWidget.DimensionBehaviour.MATCH_CONSTRAINT && (dimensionBehaviour5 == ConstraintWidget.DimensionBehaviour.WRAP_CONTENT || dimensionBehaviour5 == ConstraintWidget.DimensionBehaviour.FIXED)) { if (next.mMatchConstraintDefaultWidth == 3) { if (dimensionBehaviour5 == ConstraintWidget.DimensionBehaviour.WRAP_CONTENT) { measure(next, ConstraintWidget.DimensionBehaviour.WRAP_CONTENT, 0, ConstraintWidget.DimensionBehaviour.WRAP_CONTENT, 0); } int height2 = next.getHeight(); measure(next, ConstraintWidget.DimensionBehaviour.FIXED, (int) ((height2 * next.mDimensionRatio) + 0.5f), ConstraintWidget.DimensionBehaviour.FIXED, height2); next.horizontalRun.dimension.resolve(next.getWidth()); next.verticalRun.dimension.resolve(next.getHeight()); next.measured = true; } else if (next.mMatchConstraintDefaultWidth == 1) { measure(next, ConstraintWidget.DimensionBehaviour.WRAP_CONTENT, 0, dimensionBehaviour5, 0); next.horizontalRun.dimension.wrapValue = next.getWidth(); } else if (next.mMatchConstraintDefaultWidth == 2) { if (constraintWidgetContainer.mListDimensionBehaviors[0] == ConstraintWidget.DimensionBehaviour.FIXED || constraintWidgetContainer.mListDimensionBehaviors[0] == ConstraintWidget.DimensionBehaviour.MATCH_PARENT) { measure(next, ConstraintWidget.DimensionBehaviour.FIXED, (int) ((next.mMatchConstraintPercentWidth * constraintWidgetContainer.getWidth()) + 0.5f), dimensionBehaviour5, next.getHeight()); next.horizontalRun.dimension.resolve(next.getWidth()); next.verticalRun.dimension.resolve(next.getHeight()); next.measured = true; } } else if (next.mListAnchors[0].mTarget == null || next.mListAnchors[1].mTarget == null) { measure(next, ConstraintWidget.DimensionBehaviour.WRAP_CONTENT, 0, dimensionBehaviour5, 0); next.horizontalRun.dimension.resolve(next.getWidth()); next.verticalRun.dimension.resolve(next.getHeight()); next.measured = true; } } if (dimensionBehaviour5 == ConstraintWidget.DimensionBehaviour.MATCH_CONSTRAINT && (dimensionBehaviour4 == ConstraintWidget.DimensionBehaviour.WRAP_CONTENT || dimensionBehaviour4 == ConstraintWidget.DimensionBehaviour.FIXED)) { if (next.mMatchConstraintDefaultHeight == 3) { if (dimensionBehaviour4 == ConstraintWidget.DimensionBehaviour.WRAP_CONTENT) { measure(next, ConstraintWidget.DimensionBehaviour.WRAP_CONTENT, 0, ConstraintWidget.DimensionBehaviour.WRAP_CONTENT, 0); } int width2 = next.getWidth(); float f = next.mDimensionRatio; if (next.getDimensionRatioSide() == -1) { f = 1.0f / f; } measure(next, ConstraintWidget.DimensionBehaviour.FIXED, width2, ConstraintWidget.DimensionBehaviour.FIXED, (int) ((width2 * f) + 0.5f)); next.horizontalRun.dimension.resolve(next.getWidth()); next.verticalRun.dimension.resolve(next.getHeight()); next.measured = true; } else if (next.mMatchConstraintDefaultHeight == 1) { measure(next, dimensionBehaviour4, 0, ConstraintWidget.DimensionBehaviour.WRAP_CONTENT, 0); next.verticalRun.dimension.wrapValue = next.getHeight(); } else if (next.mMatchConstraintDefaultHeight == 2) { if (constraintWidgetContainer.mListDimensionBehaviors[1] == ConstraintWidget.DimensionBehaviour.FIXED || constraintWidgetContainer.mListDimensionBehaviors[1] == ConstraintWidget.DimensionBehaviour.MATCH_PARENT) { measure(next, dimensionBehaviour4, next.getWidth(), ConstraintWidget.DimensionBehaviour.FIXED, (int) ((next.mMatchConstraintPercentHeight * constraintWidgetContainer.getHeight()) + 0.5f)); next.horizontalRun.dimension.resolve(next.getWidth()); next.verticalRun.dimension.resolve(next.getHeight()); next.measured = true; } } else if (next.mListAnchors[2].mTarget == null || next.mListAnchors[3].mTarget == null) { measure(next, ConstraintWidget.DimensionBehaviour.WRAP_CONTENT, 0, dimensionBehaviour5, 0); next.horizontalRun.dimension.resolve(next.getWidth()); next.verticalRun.dimension.resolve(next.getHeight()); next.measured = true; } } if (dimensionBehaviour4 == ConstraintWidget.DimensionBehaviour.MATCH_CONSTRAINT && dimensionBehaviour5 == ConstraintWidget.DimensionBehaviour.MATCH_CONSTRAINT) { if (next.mMatchConstraintDefaultWidth == 1 || next.mMatchConstraintDefaultHeight == 1) { measure(next, ConstraintWidget.DimensionBehaviour.WRAP_CONTENT, 0, ConstraintWidget.DimensionBehaviour.WRAP_CONTENT, 0); next.horizontalRun.dimension.wrapValue = next.getWidth(); next.verticalRun.dimension.wrapValue = next.getHeight(); } else if (next.mMatchConstraintDefaultHeight == 2 && next.mMatchConstraintDefaultWidth == 2 && (constraintWidgetContainer.mListDimensionBehaviors[0] == ConstraintWidget.DimensionBehaviour.FIXED || constraintWidgetContainer.mListDimensionBehaviors[0] == ConstraintWidget.DimensionBehaviour.FIXED)) { if (constraintWidgetContainer.mListDimensionBehaviors[1] == ConstraintWidget.DimensionBehaviour.FIXED || constraintWidgetContainer.mListDimensionBehaviors[1] == ConstraintWidget.DimensionBehaviour.FIXED) { measure(next, ConstraintWidget.DimensionBehaviour.FIXED, (int) ((next.mMatchConstraintPercentWidth * constraintWidgetContainer.getWidth()) + 0.5f), ConstraintWidget.DimensionBehaviour.FIXED, (int) ((next.mMatchConstraintPercentHeight * constraintWidgetContainer.getHeight()) + 0.5f)); next.horizontalRun.dimension.resolve(next.getWidth()); next.verticalRun.dimension.resolve(next.getHeight()); next.measured = true; } } } } } } return false; } public void measureWidgets() { Iterator it = this.container.mChildren.iterator(); while (it.hasNext()) { ConstraintWidget next = it.next(); if (!next.measured) { boolean z = false; ConstraintWidget.DimensionBehaviour dimensionBehaviour = next.mListDimensionBehaviors[0]; ConstraintWidget.DimensionBehaviour dimensionBehaviour2 = next.mListDimensionBehaviors[1]; int i = next.mMatchConstraintDefaultWidth; int i2 = next.mMatchConstraintDefaultHeight; boolean z2 = dimensionBehaviour == ConstraintWidget.DimensionBehaviour.WRAP_CONTENT || (dimensionBehaviour == ConstraintWidget.DimensionBehaviour.MATCH_CONSTRAINT && i == 1); if (dimensionBehaviour2 == ConstraintWidget.DimensionBehaviour.WRAP_CONTENT || (dimensionBehaviour2 == ConstraintWidget.DimensionBehaviour.MATCH_CONSTRAINT && i2 == 1)) { z = true; } boolean z3 = next.horizontalRun.dimension.resolved; boolean z4 = next.verticalRun.dimension.resolved; if (z3 && z4) { measure(next, ConstraintWidget.DimensionBehaviour.FIXED, next.horizontalRun.dimension.value, ConstraintWidget.DimensionBehaviour.FIXED, next.verticalRun.dimension.value); next.measured = true; } else if (z3 && z) { measure(next, ConstraintWidget.DimensionBehaviour.FIXED, next.horizontalRun.dimension.value, ConstraintWidget.DimensionBehaviour.WRAP_CONTENT, next.verticalRun.dimension.value); if (dimensionBehaviour2 == ConstraintWidget.DimensionBehaviour.MATCH_CONSTRAINT) { next.verticalRun.dimension.wrapValue = next.getHeight(); } else { next.verticalRun.dimension.resolve(next.getHeight()); next.measured = true; } } else if (z4 && z2) { measure(next, ConstraintWidget.DimensionBehaviour.WRAP_CONTENT, next.horizontalRun.dimension.value, ConstraintWidget.DimensionBehaviour.FIXED, next.verticalRun.dimension.value); if (dimensionBehaviour == ConstraintWidget.DimensionBehaviour.MATCH_CONSTRAINT) { next.horizontalRun.dimension.wrapValue = next.getWidth(); } else { next.horizontalRun.dimension.resolve(next.getWidth()); next.measured = true; } } if (next.measured && next.verticalRun.baselineDimension != null) { next.verticalRun.baselineDimension.resolve(next.getBaselineDistance()); } } } } public void buildGraph() { buildGraph(this.mRuns); this.mGroups.clear(); RunGroup.index = 0; findGroup(this.container.horizontalRun, 0, this.mGroups); findGroup(this.container.verticalRun, 1, this.mGroups); this.mNeedBuildGraph = false; } public void buildGraph(ArrayList arrayList) { arrayList.clear(); this.mContainer.horizontalRun.clear(); this.mContainer.verticalRun.clear(); arrayList.add(this.mContainer.horizontalRun); arrayList.add(this.mContainer.verticalRun); Iterator it = this.mContainer.mChildren.iterator(); HashSet hashSet = null; while (it.hasNext()) { ConstraintWidget next = it.next(); if (next instanceof Guideline) { arrayList.add(new GuidelineReference(next)); } else { if (next.isInHorizontalChain()) { if (next.horizontalChainRun == null) { next.horizontalChainRun = new ChainRun(next, 0); } if (hashSet == null) { hashSet = new HashSet(); } hashSet.add(next.horizontalChainRun); } else { arrayList.add(next.horizontalRun); } if (next.isInVerticalChain()) { if (next.verticalChainRun == null) { next.verticalChainRun = new ChainRun(next, 1); } if (hashSet == null) { hashSet = new HashSet(); } hashSet.add(next.verticalChainRun); } else { arrayList.add(next.verticalRun); } if (next instanceof HelperWidget) { arrayList.add(new HelperReferences(next)); } } } if (hashSet != null) { arrayList.addAll(hashSet); } Iterator it2 = arrayList.iterator(); while (it2.hasNext()) { it2.next().clear(); } Iterator it3 = arrayList.iterator(); while (it3.hasNext()) { WidgetRun next2 = it3.next(); if (next2.widget != this.mContainer) { next2.apply(); } } } private void displayGraph() { Iterator it = this.mRuns.iterator(); String str = "digraph {\n"; while (it.hasNext()) { str = generateDisplayGraph(it.next(), str); } System.out.println("content:<<\n" + (str + "\n}\n") + "\n>>"); } private void applyGroup(DependencyNode dependencyNode, int i, int i2, DependencyNode dependencyNode2, ArrayList arrayList, RunGroup runGroup) { WidgetRun widgetRun = dependencyNode.run; if (widgetRun.runGroup != null || widgetRun == this.container.horizontalRun || widgetRun == this.container.verticalRun) { return; } if (runGroup == null) { runGroup = new RunGroup(widgetRun, i2); arrayList.add(runGroup); } widgetRun.runGroup = runGroup; runGroup.add(widgetRun); for (Dependency dependency : widgetRun.start.dependencies) { if (dependency instanceof DependencyNode) { applyGroup((DependencyNode) dependency, i, 0, dependencyNode2, arrayList, runGroup); } } for (Dependency dependency2 : widgetRun.end.dependencies) { if (dependency2 instanceof DependencyNode) { applyGroup((DependencyNode) dependency2, i, 1, dependencyNode2, arrayList, runGroup); } } if (i == 1 && (widgetRun instanceof VerticalWidgetRun)) { for (Dependency dependency3 : ((VerticalWidgetRun) widgetRun).baseline.dependencies) { if (dependency3 instanceof DependencyNode) { applyGroup((DependencyNode) dependency3, i, 2, dependencyNode2, arrayList, runGroup); } } } for (DependencyNode dependencyNode3 : widgetRun.start.targets) { if (dependencyNode3 == dependencyNode2) { runGroup.dual = true; } applyGroup(dependencyNode3, i, 0, dependencyNode2, arrayList, runGroup); } for (DependencyNode dependencyNode4 : widgetRun.end.targets) { if (dependencyNode4 == dependencyNode2) { runGroup.dual = true; } applyGroup(dependencyNode4, i, 1, dependencyNode2, arrayList, runGroup); } if (i == 1 && (widgetRun instanceof VerticalWidgetRun)) { Iterator it = ((VerticalWidgetRun) widgetRun).baseline.targets.iterator(); while (it.hasNext()) { applyGroup(it.next(), i, 2, dependencyNode2, arrayList, runGroup); } } } private void findGroup(WidgetRun widgetRun, int i, ArrayList arrayList) { for (Dependency dependency : widgetRun.start.dependencies) { if (dependency instanceof DependencyNode) { applyGroup((DependencyNode) dependency, i, 0, widgetRun.end, arrayList, null); } else if (dependency instanceof WidgetRun) { applyGroup(((WidgetRun) dependency).start, i, 0, widgetRun.end, arrayList, null); } } for (Dependency dependency2 : widgetRun.end.dependencies) { if (dependency2 instanceof DependencyNode) { applyGroup((DependencyNode) dependency2, i, 1, widgetRun.start, arrayList, null); } else if (dependency2 instanceof WidgetRun) { applyGroup(((WidgetRun) dependency2).end, i, 1, widgetRun.start, arrayList, null); } } if (i == 1) { for (Dependency dependency3 : ((VerticalWidgetRun) widgetRun).baseline.dependencies) { if (dependency3 instanceof DependencyNode) { applyGroup((DependencyNode) dependency3, i, 2, null, arrayList, null); } } } } private String generateDisplayNode(DependencyNode dependencyNode, boolean z, String str) { Iterator it = dependencyNode.targets.iterator(); while (it.hasNext()) { String str2 = ("\n" + dependencyNode.name()) + " -> " + it.next().name(); if (dependencyNode.margin > 0 || z || (dependencyNode.run instanceof HelperReferences)) { String str3 = str2 + "["; if (dependencyNode.margin > 0) { str3 = str3 + "label=\"" + dependencyNode.margin + "\""; if (z) { str3 = str3 + ","; } } if (z) { str3 = str3 + " style=dashed "; } if (dependencyNode.run instanceof HelperReferences) { str3 = str3 + " style=bold,color=gray "; } str2 = str3 + "]"; } str = str + (str2 + "\n"); } return str; } private String nodeDefinition(WidgetRun widgetRun) { String str; String str2; String str3; boolean z = widgetRun instanceof VerticalWidgetRun; String debugName = widgetRun.widget.getDebugName(); ConstraintWidget constraintWidget = widgetRun.widget; ConstraintWidget.DimensionBehaviour horizontalDimensionBehaviour = !z ? constraintWidget.getHorizontalDimensionBehaviour() : constraintWidget.getVerticalDimensionBehaviour(); RunGroup runGroup = widgetRun.runGroup; if (!z) { str = debugName + "_HORIZONTAL"; } else { str = debugName + "_VERTICAL"; } String str4 = ((str + " [shape=none, label=<") + "") + " "; if (!z) { String str5 = str4 + " "; } else { String str6 = str4 + " "; } String str7 = str2 + " "; if (!z) { String str9 = str8 + " "; } else { String str10 = str8 + " ") + " "; } return (str3 + "
LT" + debugName + (runGroup != null ? " [" + (runGroup.groupIndex + 1) + "/" + RunGroup.index + "]" : "") + " RbB
") + ">];\n"; } private String generateChainDisplayGraph(ChainRun chainRun, String str) { String str2; String str3; int i = chainRun.orientation; String str4 = "cluster_" + chainRun.widget.getDebugName(); if (i == 0) { str2 = str4 + "_h"; } else { str2 = str4 + "_v"; } String str5 = "subgraph " + str2 + " {\n"; Iterator it = chainRun.widgets.iterator(); String str6 = ""; while (it.hasNext()) { WidgetRun next = it.next(); String debugName = next.widget.getDebugName(); if (i == 0) { str3 = debugName + "_HORIZONTAL"; } else { str3 = debugName + "_VERTICAL"; } str5 = str5 + str3 + ";\n"; str6 = generateDisplayGraph(next, str6); } return str + str6 + (str5 + "}\n"); } private boolean isCenteredConnection(DependencyNode dependencyNode, DependencyNode dependencyNode2) { Iterator it = dependencyNode.targets.iterator(); int i = 0; while (it.hasNext()) { if (it.next() != dependencyNode2) { i++; } } Iterator it2 = dependencyNode2.targets.iterator(); int i2 = 0; while (it2.hasNext()) { if (it2.next() != dependencyNode) { i2++; } } return i > 0 && i2 > 0; } private String generateDisplayGraph(WidgetRun widgetRun, String str) { boolean z; DependencyNode dependencyNode = widgetRun.start; DependencyNode dependencyNode2 = widgetRun.end; if (!(widgetRun instanceof HelperReferences) && dependencyNode.dependencies.isEmpty() && (dependencyNode2.dependencies.isEmpty() && dependencyNode.targets.isEmpty()) && dependencyNode2.targets.isEmpty()) { return str; } String str2 = str + nodeDefinition(widgetRun); boolean isCenteredConnection = isCenteredConnection(dependencyNode, dependencyNode2); String generateDisplayNode = generateDisplayNode(dependencyNode2, isCenteredConnection, generateDisplayNode(dependencyNode, isCenteredConnection, str2)); boolean z2 = widgetRun instanceof VerticalWidgetRun; if (z2) { generateDisplayNode = generateDisplayNode(((VerticalWidgetRun) widgetRun).baseline, isCenteredConnection, generateDisplayNode); } if ((widgetRun instanceof HorizontalWidgetRun) || (((z = widgetRun instanceof ChainRun)) && ((ChainRun) widgetRun).orientation == 0)) { ConstraintWidget.DimensionBehaviour horizontalDimensionBehaviour = widgetRun.widget.getHorizontalDimensionBehaviour(); if (horizontalDimensionBehaviour == ConstraintWidget.DimensionBehaviour.FIXED || horizontalDimensionBehaviour == ConstraintWidget.DimensionBehaviour.WRAP_CONTENT) { if (!dependencyNode.targets.isEmpty() && dependencyNode2.targets.isEmpty()) { generateDisplayNode = generateDisplayNode + ("\n" + dependencyNode2.name() + " -> " + dependencyNode.name() + "\n"); } else if (dependencyNode.targets.isEmpty() && !dependencyNode2.targets.isEmpty()) { generateDisplayNode = generateDisplayNode + ("\n" + dependencyNode.name() + " -> " + dependencyNode2.name() + "\n"); } } else if (horizontalDimensionBehaviour == ConstraintWidget.DimensionBehaviour.MATCH_CONSTRAINT && widgetRun.widget.getDimensionRatio() > 0.0f) { String debugName = widgetRun.widget.getDebugName(); String str3 = "\n" + debugName + "_HORIZONTAL -> " + debugName + "_VERTICAL;\n"; } } else if (z2 || (z && ((ChainRun) widgetRun).orientation == 1)) { ConstraintWidget.DimensionBehaviour verticalDimensionBehaviour = widgetRun.widget.getVerticalDimensionBehaviour(); if (verticalDimensionBehaviour == ConstraintWidget.DimensionBehaviour.FIXED || verticalDimensionBehaviour == ConstraintWidget.DimensionBehaviour.WRAP_CONTENT) { if (!dependencyNode.targets.isEmpty() && dependencyNode2.targets.isEmpty()) { generateDisplayNode = generateDisplayNode + ("\n" + dependencyNode2.name() + " -> " + dependencyNode.name() + "\n"); } else if (dependencyNode.targets.isEmpty() && !dependencyNode2.targets.isEmpty()) { generateDisplayNode = generateDisplayNode + ("\n" + dependencyNode.name() + " -> " + dependencyNode2.name() + "\n"); } } else if (verticalDimensionBehaviour == ConstraintWidget.DimensionBehaviour.MATCH_CONSTRAINT && widgetRun.widget.getDimensionRatio() > 0.0f) { String debugName2 = widgetRun.widget.getDebugName(); String str4 = "\n" + debugName2 + "_VERTICAL -> " + debugName2 + "_HORIZONTAL;\n"; } } return widgetRun instanceof ChainRun ? generateChainDisplayGraph((ChainRun) widgetRun, generateDisplayNode) : generateDisplayNode; } }