271 lines
12 KiB
Java
271 lines
12 KiB
Java
package androidx.constraintlayout.solver.widgets;
|
|
|
|
import androidx.constraintlayout.solver.LinearSystem;
|
|
import androidx.constraintlayout.solver.SolverVariable;
|
|
import androidx.constraintlayout.solver.widgets.ConstraintAnchor;
|
|
import androidx.constraintlayout.solver.widgets.ConstraintWidget;
|
|
import b.d.b.a.a;
|
|
import java.util.HashMap;
|
|
public class Barrier extends HelperWidget {
|
|
public static final int BOTTOM = 3;
|
|
public static final int LEFT = 0;
|
|
public static final int RIGHT = 1;
|
|
public static final int TOP = 2;
|
|
private static final boolean USE_RELAX_GONE = false;
|
|
private static final boolean USE_RESOLUTION = true;
|
|
private boolean mAllowsGoneWidget = true;
|
|
private int mBarrierType = 0;
|
|
private int mMargin = 0;
|
|
public boolean resolved = false;
|
|
|
|
public Barrier() {
|
|
}
|
|
|
|
public Barrier(String str) {
|
|
setDebugName(str);
|
|
}
|
|
|
|
@Override // androidx.constraintlayout.solver.widgets.ConstraintWidget
|
|
public void addToSolver(LinearSystem linearSystem, boolean z2) {
|
|
Object[] objArr;
|
|
boolean z3;
|
|
int i;
|
|
int i2;
|
|
int i3;
|
|
ConstraintAnchor[] constraintAnchorArr = this.mListAnchors;
|
|
constraintAnchorArr[0] = this.mLeft;
|
|
constraintAnchorArr[2] = this.mTop;
|
|
constraintAnchorArr[1] = this.mRight;
|
|
constraintAnchorArr[3] = this.mBottom;
|
|
int i4 = 0;
|
|
while (true) {
|
|
objArr = this.mListAnchors;
|
|
if (i4 >= objArr.length) {
|
|
break;
|
|
}
|
|
objArr[i4].mSolverVariable = linearSystem.createObjectVariable(objArr[i4]);
|
|
i4++;
|
|
}
|
|
int i5 = this.mBarrierType;
|
|
if (i5 >= 0 && i5 < 4) {
|
|
ConstraintAnchor constraintAnchor = objArr[i5];
|
|
if (!this.resolved) {
|
|
allSolved();
|
|
}
|
|
if (this.resolved) {
|
|
this.resolved = false;
|
|
int i6 = this.mBarrierType;
|
|
if (i6 == 0 || i6 == 1) {
|
|
linearSystem.addEquality(this.mLeft.mSolverVariable, this.mX);
|
|
linearSystem.addEquality(this.mRight.mSolverVariable, this.mX);
|
|
} else if (i6 == 2 || i6 == 3) {
|
|
linearSystem.addEquality(this.mTop.mSolverVariable, this.mY);
|
|
linearSystem.addEquality(this.mBottom.mSolverVariable, this.mY);
|
|
}
|
|
} else {
|
|
int i7 = 0;
|
|
while (true) {
|
|
if (i7 >= this.mWidgetsCount) {
|
|
z3 = false;
|
|
break;
|
|
}
|
|
ConstraintWidget constraintWidget = this.mWidgets[i7];
|
|
if ((this.mAllowsGoneWidget || constraintWidget.allowedInBarrier()) && ((((i2 = this.mBarrierType) == 0 || i2 == 1) && constraintWidget.getHorizontalDimensionBehaviour() == ConstraintWidget.DimensionBehaviour.MATCH_CONSTRAINT && constraintWidget.mLeft.mTarget != null && constraintWidget.mRight.mTarget != null) || (((i3 = this.mBarrierType) == 2 || i3 == 3) && constraintWidget.getVerticalDimensionBehaviour() == ConstraintWidget.DimensionBehaviour.MATCH_CONSTRAINT && constraintWidget.mTop.mTarget != null && constraintWidget.mBottom.mTarget != null))) {
|
|
break;
|
|
}
|
|
i7++;
|
|
}
|
|
z3 = true;
|
|
boolean z4 = this.mLeft.hasCenteredDependents() || this.mRight.hasCenteredDependents();
|
|
boolean z5 = this.mTop.hasCenteredDependents() || this.mBottom.hasCenteredDependents();
|
|
boolean z6 = !z3 && (((i = this.mBarrierType) == 0 && z4) || ((i == 2 && z5) || ((i == 1 && z4) || (i == 3 && z5))));
|
|
int i8 = 5;
|
|
if (!z6) {
|
|
i8 = 4;
|
|
}
|
|
for (int i9 = 0; i9 < this.mWidgetsCount; i9++) {
|
|
ConstraintWidget constraintWidget2 = this.mWidgets[i9];
|
|
if (this.mAllowsGoneWidget || constraintWidget2.allowedInBarrier()) {
|
|
SolverVariable createObjectVariable = linearSystem.createObjectVariable(constraintWidget2.mListAnchors[this.mBarrierType]);
|
|
ConstraintAnchor[] constraintAnchorArr2 = constraintWidget2.mListAnchors;
|
|
int i10 = this.mBarrierType;
|
|
constraintAnchorArr2[i10].mSolverVariable = createObjectVariable;
|
|
int i11 = (constraintAnchorArr2[i10].mTarget == null || constraintAnchorArr2[i10].mTarget.mOwner != this) ? 0 : constraintAnchorArr2[i10].mMargin + 0;
|
|
if (i10 == 0 || i10 == 2) {
|
|
linearSystem.addLowerBarrier(constraintAnchor.mSolverVariable, createObjectVariable, this.mMargin - i11, z3);
|
|
} else {
|
|
linearSystem.addGreaterBarrier(constraintAnchor.mSolverVariable, createObjectVariable, this.mMargin + i11, z3);
|
|
}
|
|
linearSystem.addEquality(constraintAnchor.mSolverVariable, createObjectVariable, this.mMargin + i11, i8);
|
|
}
|
|
}
|
|
int i12 = this.mBarrierType;
|
|
if (i12 == 0) {
|
|
linearSystem.addEquality(this.mRight.mSolverVariable, this.mLeft.mSolverVariable, 0, 8);
|
|
linearSystem.addEquality(this.mLeft.mSolverVariable, this.mParent.mRight.mSolverVariable, 0, 4);
|
|
linearSystem.addEquality(this.mLeft.mSolverVariable, this.mParent.mLeft.mSolverVariable, 0, 0);
|
|
} else if (i12 == 1) {
|
|
linearSystem.addEquality(this.mLeft.mSolverVariable, this.mRight.mSolverVariable, 0, 8);
|
|
linearSystem.addEquality(this.mLeft.mSolverVariable, this.mParent.mLeft.mSolverVariable, 0, 4);
|
|
linearSystem.addEquality(this.mLeft.mSolverVariable, this.mParent.mRight.mSolverVariable, 0, 0);
|
|
} else if (i12 == 2) {
|
|
linearSystem.addEquality(this.mBottom.mSolverVariable, this.mTop.mSolverVariable, 0, 8);
|
|
linearSystem.addEquality(this.mTop.mSolverVariable, this.mParent.mBottom.mSolverVariable, 0, 4);
|
|
linearSystem.addEquality(this.mTop.mSolverVariable, this.mParent.mTop.mSolverVariable, 0, 0);
|
|
} else if (i12 == 3) {
|
|
linearSystem.addEquality(this.mTop.mSolverVariable, this.mBottom.mSolverVariable, 0, 8);
|
|
linearSystem.addEquality(this.mTop.mSolverVariable, this.mParent.mTop.mSolverVariable, 0, 4);
|
|
linearSystem.addEquality(this.mTop.mSolverVariable, this.mParent.mBottom.mSolverVariable, 0, 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public boolean allSolved() {
|
|
int i;
|
|
int i2;
|
|
int i3;
|
|
int i4 = 0;
|
|
boolean z2 = true;
|
|
while (true) {
|
|
i = this.mWidgetsCount;
|
|
if (i4 >= i) {
|
|
break;
|
|
}
|
|
ConstraintWidget constraintWidget = this.mWidgets[i4];
|
|
if ((this.mAllowsGoneWidget || constraintWidget.allowedInBarrier()) && ((((i2 = this.mBarrierType) == 0 || i2 == 1) && !constraintWidget.isResolvedHorizontally()) || (((i3 = this.mBarrierType) == 2 || i3 == 3) && !constraintWidget.isResolvedVertically()))) {
|
|
z2 = false;
|
|
}
|
|
i4++;
|
|
}
|
|
if (!z2 || i <= 0) {
|
|
return false;
|
|
}
|
|
int i5 = 0;
|
|
boolean z3 = false;
|
|
for (int i6 = 0; i6 < this.mWidgetsCount; i6++) {
|
|
ConstraintWidget constraintWidget2 = this.mWidgets[i6];
|
|
if (this.mAllowsGoneWidget || constraintWidget2.allowedInBarrier()) {
|
|
if (!z3) {
|
|
int i7 = this.mBarrierType;
|
|
if (i7 == 0) {
|
|
i5 = constraintWidget2.getAnchor(ConstraintAnchor.Type.LEFT).getFinalValue();
|
|
} else if (i7 == 1) {
|
|
i5 = constraintWidget2.getAnchor(ConstraintAnchor.Type.RIGHT).getFinalValue();
|
|
} else if (i7 == 2) {
|
|
i5 = constraintWidget2.getAnchor(ConstraintAnchor.Type.TOP).getFinalValue();
|
|
} else if (i7 == 3) {
|
|
i5 = constraintWidget2.getAnchor(ConstraintAnchor.Type.BOTTOM).getFinalValue();
|
|
}
|
|
z3 = true;
|
|
}
|
|
int i8 = this.mBarrierType;
|
|
if (i8 == 0) {
|
|
i5 = Math.min(i5, constraintWidget2.getAnchor(ConstraintAnchor.Type.LEFT).getFinalValue());
|
|
} else if (i8 == 1) {
|
|
i5 = Math.max(i5, constraintWidget2.getAnchor(ConstraintAnchor.Type.RIGHT).getFinalValue());
|
|
} else if (i8 == 2) {
|
|
i5 = Math.min(i5, constraintWidget2.getAnchor(ConstraintAnchor.Type.TOP).getFinalValue());
|
|
} else if (i8 == 3) {
|
|
i5 = Math.max(i5, constraintWidget2.getAnchor(ConstraintAnchor.Type.BOTTOM).getFinalValue());
|
|
}
|
|
}
|
|
}
|
|
int i9 = i5 + this.mMargin;
|
|
int i10 = this.mBarrierType;
|
|
if (i10 == 0 || i10 == 1) {
|
|
setFinalHorizontal(i9, i9);
|
|
} else {
|
|
setFinalVertical(i9, i9);
|
|
}
|
|
this.resolved = true;
|
|
return true;
|
|
}
|
|
|
|
@Override // androidx.constraintlayout.solver.widgets.ConstraintWidget
|
|
public boolean allowedInBarrier() {
|
|
return true;
|
|
}
|
|
|
|
public boolean allowsGoneWidget() {
|
|
return this.mAllowsGoneWidget;
|
|
}
|
|
|
|
@Override // androidx.constraintlayout.solver.widgets.HelperWidget, androidx.constraintlayout.solver.widgets.ConstraintWidget
|
|
public void copy(ConstraintWidget constraintWidget, HashMap<ConstraintWidget, ConstraintWidget> hashMap) {
|
|
super.copy(constraintWidget, hashMap);
|
|
Barrier barrier = (Barrier) constraintWidget;
|
|
this.mBarrierType = barrier.mBarrierType;
|
|
this.mAllowsGoneWidget = barrier.mAllowsGoneWidget;
|
|
this.mMargin = barrier.mMargin;
|
|
}
|
|
|
|
public int getBarrierType() {
|
|
return this.mBarrierType;
|
|
}
|
|
|
|
public int getMargin() {
|
|
return this.mMargin;
|
|
}
|
|
|
|
public int getOrientation() {
|
|
int i = this.mBarrierType;
|
|
if (i == 0 || i == 1) {
|
|
return 0;
|
|
}
|
|
return (i == 2 || i == 3) ? 1 : -1;
|
|
}
|
|
|
|
@Override // androidx.constraintlayout.solver.widgets.ConstraintWidget
|
|
public boolean isResolvedHorizontally() {
|
|
return this.resolved;
|
|
}
|
|
|
|
@Override // androidx.constraintlayout.solver.widgets.ConstraintWidget
|
|
public boolean isResolvedVertically() {
|
|
return this.resolved;
|
|
}
|
|
|
|
public void markWidgets() {
|
|
for (int i = 0; i < this.mWidgetsCount; i++) {
|
|
ConstraintWidget constraintWidget = this.mWidgets[i];
|
|
int i2 = this.mBarrierType;
|
|
if (i2 == 0 || i2 == 1) {
|
|
constraintWidget.setInBarrier(0, true);
|
|
} else if (i2 == 2 || i2 == 3) {
|
|
constraintWidget.setInBarrier(1, true);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void setAllowsGoneWidget(boolean z2) {
|
|
this.mAllowsGoneWidget = z2;
|
|
}
|
|
|
|
public void setBarrierType(int i) {
|
|
this.mBarrierType = i;
|
|
}
|
|
|
|
public void setMargin(int i) {
|
|
this.mMargin = i;
|
|
}
|
|
|
|
@Override // androidx.constraintlayout.solver.widgets.ConstraintWidget
|
|
public String toString() {
|
|
StringBuilder R = a.R("[Barrier] ");
|
|
R.append(getDebugName());
|
|
R.append(" {");
|
|
String sb = R.toString();
|
|
for (int i = 0; i < this.mWidgetsCount; i++) {
|
|
ConstraintWidget constraintWidget = this.mWidgets[i];
|
|
if (i > 0) {
|
|
sb = a.v(sb, ", ");
|
|
}
|
|
StringBuilder R2 = a.R(sb);
|
|
R2.append(constraintWidget.getDebugName());
|
|
sb = R2.toString();
|
|
}
|
|
return a.v(sb, "}");
|
|
}
|
|
}
|