-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
328 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...ayout/core/src/main/java/androidx/constraintlayout/core/state/helpers/SplitReference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package androidx.constraintlayout.core.state.helpers; | ||
|
||
import androidx.constraintlayout.core.state.HelperReference; | ||
import androidx.constraintlayout.core.state.State; | ||
import androidx.constraintlayout.core.utils.Split; | ||
import androidx.constraintlayout.core.widgets.ConstraintWidget; | ||
import androidx.constraintlayout.core.widgets.Flow; | ||
import androidx.constraintlayout.core.widgets.HelperWidget; | ||
|
||
public class SplitReference extends HelperReference { | ||
|
||
public SplitReference(State state, State.Helper type) { | ||
super(state, type); | ||
} | ||
|
||
protected Split mSplit; | ||
|
||
protected ConstraintWidget mLeft; | ||
|
||
protected ConstraintWidget mRight; | ||
|
||
protected int mOrientation; | ||
|
||
public ConstraintWidget getLeft() { | ||
return mLeft; | ||
} | ||
|
||
public void setLeft(ConstraintWidget mLeft) { | ||
this.mLeft = mLeft; | ||
} | ||
|
||
public ConstraintWidget getRight() { | ||
return mRight; | ||
} | ||
|
||
public void setRight(ConstraintWidget mRight) { | ||
this.mRight = mRight; | ||
} | ||
|
||
@Override | ||
public HelperWidget getHelperWidget() { | ||
if (mSplit == null) { | ||
mSplit = new Split(); | ||
} | ||
return mSplit; | ||
} | ||
|
||
@Override | ||
public void setHelperWidget(HelperWidget widget) { | ||
if (widget instanceof Flow) { | ||
mSplit = (Split) widget; | ||
} else { | ||
mSplit = null; | ||
} | ||
} | ||
|
||
public int getOrientation() { | ||
return mOrientation; | ||
} | ||
|
||
public void setOrientation(int orientation) { | ||
mOrientation = orientation; | ||
|
||
} | ||
|
||
@Override | ||
public void apply() { | ||
if (mLeft != null) { | ||
mSplit.setFirst(mLeft); | ||
} | ||
|
||
if (mRight != null) { | ||
mSplit.setSecond(mRight); | ||
} | ||
|
||
mSplit.setOrientation(mOrientation); | ||
|
||
// General attributes of a widget | ||
applyBase(); | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
constraintlayout/core/src/main/java/androidx/constraintlayout/core/utils/Split.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package androidx.constraintlayout.core.utils; | ||
|
||
import androidx.constraintlayout.core.LinearSystem; | ||
import androidx.constraintlayout.core.widgets.ConstraintWidget; | ||
import androidx.constraintlayout.core.widgets.ConstraintWidgetContainer; | ||
import androidx.constraintlayout.core.widgets.VirtualLayout; | ||
|
||
public class Split extends VirtualLayout { | ||
|
||
ConstraintWidget splitBar; | ||
|
||
ConstraintWidget first; | ||
ConstraintWidget second; | ||
ConstraintWidgetContainer mContainer; | ||
int orientation; | ||
|
||
public Split() { | ||
splitBar = new ConstraintWidget(); | ||
first = new ConstraintWidget(); | ||
second = new ConstraintWidget(); | ||
} | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
public void setFirst(ConstraintWidget a) { | ||
first = a; | ||
} | ||
|
||
public void setSecond(ConstraintWidget b) { | ||
second = b; | ||
} | ||
|
||
public void setSplitBar(ConstraintWidget splitBar) { | ||
this.splitBar = splitBar; | ||
} | ||
|
||
public ConstraintWidget getFirst() { | ||
return first; | ||
} | ||
|
||
public ConstraintWidget getSecond() { | ||
return second; | ||
} | ||
|
||
public ConstraintWidget getSplitBar() { | ||
return splitBar; | ||
} | ||
|
||
public ConstraintWidgetContainer getContainer() { | ||
return mContainer; | ||
} | ||
|
||
public void setContainer(ConstraintWidgetContainer container) { | ||
mContainer = container; | ||
} | ||
|
||
public int getOrientation() { | ||
return orientation; | ||
} | ||
|
||
public void setOrientation(int orientation) { | ||
this.orientation = orientation; | ||
} | ||
|
||
@Override | ||
public void measure(int widthMode, int widthSize, int heightMode, int heightSize) { | ||
super.measure(widthMode, widthSize, heightMode, heightSize); | ||
for (int i = 0; i < mWidgetsCount; i++) { | ||
if (i == 0) { | ||
setFirst(mWidgets[i]); | ||
} else if (i == 1) { | ||
setSecond(mWidgets[i]); | ||
} else if (i == 2) { | ||
setSplitBar(mWidgets[i]); | ||
} | ||
} | ||
splitBar.stringId = String.valueOf(splitBar.hashCode()); | ||
first.stringId = String.valueOf(first.hashCode()); | ||
second.stringId = String.valueOf(second.hashCode()); | ||
mContainer = (ConstraintWidgetContainer) getParent(); | ||
This comment has been minimized.
Sorry, something went wrong.
jafu888
Collaborator
|
||
mContainer.add(splitBar); | ||
} | ||
|
||
@Override | ||
public void addToSolver(LinearSystem system, boolean optimize) { | ||
this.mTop.connect(getParent().mTop, 0); | ||
this.mLeft.connect(getParent().mLeft, 0); | ||
this.mRight.connect(getParent().mRight, 0); | ||
this.mBottom.connect(getParent().mBottom, 0); | ||
|
||
splitBar.mTop.connect(mTop, 0); | ||
splitBar.mBottom.connect(mBottom, 0); | ||
splitBar.mLeft.connect(mLeft, 0); | ||
splitBar.mRight.connect(mRight, 0); | ||
|
||
if (orientation == 0) { | ||
first.mLeft.connect(mLeft, 0); | ||
first.mRight.connect(splitBar.mLeft, 0); | ||
first.mTop.connect(mTop, 0); | ||
first.mBottom.connect(mBottom, 0); | ||
|
||
This comment has been minimized.
Sorry, something went wrong.
jafu888
Collaborator
|
||
second.mLeft.connect(splitBar.mRight, 0); | ||
second.mRight.connect(mRight, 0); | ||
second.mTop.connect(mTop, 0); | ||
second.mBottom.connect(mBottom, 0); | ||
} else { | ||
first.mLeft.connect(mLeft, 0); | ||
first.mRight.connect(mRight, 0); | ||
first.mTop.connect(mTop, 0); | ||
first.mBottom.connect(splitBar.mTop, 0); | ||
|
||
second.mLeft.connect(mLeft, 0); | ||
second.mRight.connect(mRight, 0); | ||
second.mTop.connect(splitBar.mBottom, 0); | ||
second.mBottom.connect(mBottom, 0); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You should only have to create splitBar not create first and second