public class

Barrier

extends Helper

 java.lang.Object

androidx.constraintlayout.core.dsl.Helper

↳androidx.constraintlayout.core.dsl.Barrier

Gradle dependencies

compile group: 'androidx.constraintlayout', name: 'constraintlayout-core', version: '1.1.0-beta01'

  • groupId: androidx.constraintlayout
  • artifactId: constraintlayout-core
  • version: 1.1.0-beta01

Artifact androidx.constraintlayout:constraintlayout-core:1.1.0-beta01 it located at Google repository (https://maven.google.com/)

Summary

Fields
from Helperconfig, configMap, name, sideMap, type, typeMap
Constructors
publicBarrier(java.lang.String name)

publicBarrier(java.lang.String name, java.lang.String config)

Methods
public BarrieraddReference(Ref ref)

Add a new reference

public BarrieraddReference(java.lang.String ref)

Add a new reference

public Constraint.SidegetDirection()

Get the direction of the Barrier

public intgetMargin()

Get the margin of the Barrier

public java.lang.StringreferencesToString()

Convert references into a String representation

public voidsetDirection(Constraint.Side direction)

Set the direction of the Barrier

public voidsetMargin(int margin)

Set the margin of the Barrier

from Helperappend, convertConfigToMap, getConfig, getId, getType, main, toString
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Constructors

public Barrier(java.lang.String name)

public Barrier(java.lang.String name, java.lang.String config)

Methods

public Constraint.Side getDirection()

Get the direction of the Barrier

Returns:

direction

public void setDirection(Constraint.Side direction)

Set the direction of the Barrier

Parameters:

direction:

public int getMargin()

Get the margin of the Barrier

Returns:

margin

public void setMargin(int margin)

Set the margin of the Barrier

Parameters:

margin:

public java.lang.String referencesToString()

Convert references into a String representation

Returns:

a String representation of references

public Barrier addReference(Ref ref)

Add a new reference

Parameters:

ref: reference

Returns:

Barrier

public Barrier addReference(java.lang.String ref)

Add a new reference

Parameters:

ref: reference in a String representation

Returns:

Chain

Source

/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.constraintlayout.core.dsl;

import java.util.ArrayList;

public class Barrier extends Helper {
    private Constraint.Side mDirection = null;
    private int mMargin = Integer.MIN_VALUE;
    private ArrayList<Ref> references = new ArrayList<>();

    public Barrier(String name) {
        super(name, new HelperType(typeMap.get(Type.BARRIER)));
    }

    public Barrier(String name, String config) {
        super(name, new HelperType(typeMap.get(Type.BARRIER)), config);
        configMap = convertConfigToMap();
        if (configMap.containsKey("contains")) {
            Ref.addStringToReferences(configMap.get("contains"), references);
        }
    }

    /**
     * Get the direction of the Barrier
     *
     * @return direction
     */
    public Constraint.Side getDirection() {
        return mDirection;
    }

    /**
     * Set the direction of the Barrier
     *
     * @param direction
     */
    public void setDirection(Constraint.Side direction) {
        mDirection = direction;
        configMap.put("direction", sideMap.get(direction));
    }

    /**
     * Get the margin of the Barrier
     *
     * @return margin
     */
    public int getMargin() {
        return mMargin;
    }

    /**
     * Set the margin of the Barrier
     *
     * @param margin
     */
    public void setMargin(int margin) {
        mMargin = margin;
        configMap.put("margin", String.valueOf(margin));
    }

    /**
     * Convert references into a String representation
     *
     * @return a String representation of references
     */
    public String referencesToString() {
        if (references.isEmpty()) {
            return "";
        }

        StringBuilder builder = new StringBuilder("[");
        for (Ref ref : references) {
            builder.append(ref.toString());
        }
        builder.append("]");
        return builder.toString();
    }

    /**
     * Add a new reference
     *
     * @param ref reference
     * @return Barrier
     */
    public Barrier addReference(Ref ref) {
        references.add(ref);
        configMap.put("contains", referencesToString());
        return this;
    }

    /**
     * Add a new reference
     *
     * @param ref reference in a String representation
     * @return Chain
     */
    public Barrier addReference(String ref) {
        return addReference(Ref.parseStringToRef(ref));
    }
}