public class ConstraintAnchor


Model a constraint relation. Widgets contains anchors, and a constraint relation between two widgets is made by connecting one anchor to another. The anchor will contains a pointer to the target anchor if it is connected.

Summary

Nested types

Define the type of anchor

Public constructors

Constructor

Public methods

boolean
connect(ConstraintAnchor toAnchor, int margin)

Connects this anchor to another one.

boolean
connect(
    ConstraintAnchor toAnchor,
    int margin,
    int goneMargin,
    boolean forceConnection
)

Connects this anchor to another one.

void
void
findDependents(
    int orientation,
    ArrayList<WidgetGroup> list,
    WidgetGroup group
)
HashSet<ConstraintAnchor>
int
int

Return the connection's margin from this anchor to its target.

final ConstraintAnchor

Returns the opposite anchor to this one

ConstraintWidget

Return the anchor's owner

SolverVariable

Return the solver variable for this anchor

ConstraintAnchor

Return the connection's target (null if not connected)

ConstraintAnchor.Type

Return the type of the anchor

boolean
boolean
boolean
boolean

Returns the connection status of this anchor

boolean

Return true if we can connect this anchor to this target.

boolean

Return true if we can connect this anchor to this target.

boolean

Return true if this anchor is a side anchor

boolean

Return true if the connection to the given anchor is in the same dimension (horizontal or vertical)

boolean

Checks if the connection to a given anchor is valid.

boolean

Utility function returning true if this anchor is a vertical one.

void

Resets the anchor's connection.

void
void

Reset the solver variable

void
setFinalValue(int finalValue)
void
setGoneMargin(int margin)

Set the gone margin of the connection (if there's one)

void
setMargin(int margin)

Set the margin of the connection (if there's one)

String

Return a string representation of this anchor

Public fields

mMargin

Added in 1.1.0
public int mMargin

mOwner

Added in 1.1.0
public final ConstraintWidget mOwner

mTarget

Added in 1.1.0
public ConstraintAnchor mTarget

mType

Added in 1.1.0
public final ConstraintAnchor.Type mType

Public constructors

ConstraintAnchor

Added in 1.1.0
public ConstraintAnchor(ConstraintWidget owner, ConstraintAnchor.Type type)

Constructor

Parameters
ConstraintWidget owner

the widget owner of this anchor.

ConstraintAnchor.Type type

the anchor type.

Public methods

connect

Added in 1.1.0
public boolean connect(ConstraintAnchor toAnchor, int margin)

Connects this anchor to another one.

Returns
boolean

true if the connection succeeds.

connect

Added in 1.1.0
public boolean connect(
    ConstraintAnchor toAnchor,
    int margin,
    int goneMargin,
    boolean forceConnection
)

Connects this anchor to another one.

Returns
boolean

true if the connection succeeds.

copyFrom

Added in 1.1.0
public void copyFrom(
    ConstraintAnchor source,
    HashMap<ConstraintWidgetConstraintWidget> map
)

findDependents

Added in 1.1.0
public void findDependents(
    int orientation,
    ArrayList<WidgetGroup> list,
    WidgetGroup group
)

getDependents

Added in 1.1.0
public HashSet<ConstraintAnchorgetDependents()

getFinalValue

Added in 1.1.0
public int getFinalValue()

getMargin

Added in 1.1.0
public int getMargin()

Return the connection's margin from this anchor to its target.

Returns
int

the margin value. 0 if not connected.

getOpposite

Added in 1.1.0
public final ConstraintAnchor getOpposite()

Returns the opposite anchor to this one

Returns
ConstraintAnchor

opposite anchor

getOwner

Added in 1.1.0
public ConstraintWidget getOwner()

Return the anchor's owner

Returns
ConstraintWidget

the Widget owning the anchor

getSolverVariable

Added in 1.1.0
public SolverVariable getSolverVariable()

Return the solver variable for this anchor

getTarget

Added in 1.1.0
public ConstraintAnchor getTarget()

Return the connection's target (null if not connected)

Returns
ConstraintAnchor

the ConstraintAnchor target

getType

Added in 1.1.0
public ConstraintAnchor.Type getType()

Return the type of the anchor

Returns
ConstraintAnchor.Type

type of the anchor.

hasCenteredDependents

Added in 1.1.0
public boolean hasCenteredDependents()

hasDependents

Added in 1.1.0
public boolean hasDependents()

hasFinalValue

Added in 1.1.0
public boolean hasFinalValue()

isConnected

Added in 1.1.0
public boolean isConnected()

Returns the connection status of this anchor

Returns
boolean

true if the anchor is connected to another one.

isConnectionAllowed

Added in 1.1.0
public boolean isConnectionAllowed(ConstraintWidget target)

Return true if we can connect this anchor to this target. We recursively follow connections in order to detect eventual cycles; if we do we disallow the connection. We also only allow connections to direct parent, siblings, and descendants.

Parameters
ConstraintWidget target

the ConstraintWidget we are trying to connect to

Returns
boolean

true if the connection is allowed, false otherwise

isConnectionAllowed

Added in 1.1.0
public boolean isConnectionAllowed(ConstraintWidget target, ConstraintAnchor anchor)

Return true if we can connect this anchor to this target. We recursively follow connections in order to detect eventual cycles; if we do we disallow the connection. We also only allow connections to direct parent, siblings, and descendants.

Parameters
ConstraintWidget target

the ConstraintWidget we are trying to connect to

ConstraintAnchor anchor

Allow anchor if it loops back to me directly

Returns
boolean

if the connection is allowed, false otherwise

isSideAnchor

Added in 1.1.0
public boolean isSideAnchor()

Return true if this anchor is a side anchor

Returns
boolean

true if side anchor

isSimilarDimensionConnection

Added in 1.1.0
public boolean isSimilarDimensionConnection(ConstraintAnchor anchor)

Return true if the connection to the given anchor is in the same dimension (horizontal or vertical)

Parameters
ConstraintAnchor anchor

the anchor we want to connect to

Returns
boolean

true if it's an anchor on the same dimension

isValidConnection

Added in 1.1.0
public boolean isValidConnection(ConstraintAnchor anchor)

Checks if the connection to a given anchor is valid.

Parameters
ConstraintAnchor anchor

the anchor we want to connect to

Returns
boolean

true if it's a compatible anchor

isVerticalAnchor

Added in 1.1.0
public boolean isVerticalAnchor()

Utility function returning true if this anchor is a vertical one.

Returns
boolean

true if vertical anchor, false otherwise

reset

Added in 1.1.0
public void reset()

Resets the anchor's connection.

resetFinalResolution

Added in 1.1.0
public void resetFinalResolution()

resetSolverVariable

Added in 1.1.0
public void resetSolverVariable(Cache cache)

Reset the solver variable

setFinalValue

Added in 1.1.0
public void setFinalValue(int finalValue)

setGoneMargin

Added in 1.1.0
public void setGoneMargin(int margin)

Set the gone margin of the connection (if there's one)

Parameters
int margin

the new margin of the connection

setMargin

Added in 1.1.0
public void setMargin(int margin)

Set the margin of the connection (if there's one)

Parameters
int margin

the new margin of the connection

toString

public String toString()

Return a string representation of this anchor

Returns
String

string representation of the anchor