public class

GridReference

extends HelperReference

 java.lang.Object

androidx.constraintlayout.core.state.ConstraintReference

androidx.constraintlayout.core.state.HelperReference

↳androidx.constraintlayout.core.state.helpers.GridReference

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/)

Overview

A HelperReference of a Grid Helper that helps enable Grid in Compose

Summary

Fields
from HelperReferencemHelperState, mReferences
from ConstraintReferencemBottomToBottom, mBottomToTop, mEndToEnd, mEndToStart, mHorizontalBias, mLeftToLeft, mLeftToRight, mMarginBottom, mMarginBottomGone, mMarginEnd, mMarginEndGone, mMarginLeft, mMarginLeftGone, mMarginRight, mMarginRightGone, mMarginStart, mMarginStartGone, mMarginTop, mMarginTopGone, mRightToLeft, mRightToRight, mStartToEnd, mStartToStart, mTopToBottom, mTopToTop, mVerticalBias
Constructors
publicGridReference(State state, State.Helper type)

Methods
public voidapply()

Apply all the attributes to the helper widget (Grid)

public intgetColumnsSet()

Get the number of columns

public java.lang.StringgetColumnWeights()

Get the column weights

public intgetFlags()

Get all the flags of a Grid

public HelperWidgetgetHelperWidget()

Get the helper widget (Grid)

public floatgetHorizontalGaps()

Get the horizontal gaps

public intgetOrientation()

Get the Orientation

public intgetPaddingBottom()

get padding bottom

public intgetPaddingEnd()

get padding right

public intgetPaddingStart()

get padding left

public intgetPaddingTop()

get padding top

public intgetRowsSet()

Get the number of rows

public java.lang.StringgetRowWeights()

Get the row weights

public java.lang.StringgetSkips()

Get the skips

public java.lang.StringgetSpans()

Get the spans

public floatgetVerticalGaps()

Get the vertical gaps

public voidsetColumnsSet(int columnsSet)

Set the number of columns

public voidsetColumnWeights(java.lang.String columnWeights)

Set the column weights

public voidsetFlags(int flags)

Set flags of a Grid

public voidsetFlags(java.lang.String flags)

Set flags of a Grid

public voidsetHelperWidget(HelperWidget widget)

Set the helper widget (Grid)

public voidsetHorizontalGaps(float horizontalGaps)

Set the horizontal gaps

public voidsetOrientation(int orientation)

Set the Orientation

public voidsetPaddingBottom(int paddingBottom)

set padding bottom

public voidsetPaddingEnd(int paddingEnd)

set padding right

public voidsetPaddingStart(int paddingStart)

set padding left

public voidsetPaddingTop(int paddingTop)

set padding top

public voidsetRowsSet(int rowsSet)

Set the number of rows

public voidsetRowWeights(java.lang.String rowWeights)

Set the row weights

public voidsetSkips(java.lang.String skips)

Set the skips

public voidsetSpans(java.lang.String spans)

Set the spans

public voidsetVerticalGaps(float verticalGaps)

Set the vertical gaps

from HelperReferenceadd, applyBase, getConstraintWidget, getType
from ConstraintReferenceaddCustomColor, addCustomFloat, alpha, applyWidgetConstraints, baseline, baselineToBaseline, baselineToBottom, baselineToTop, bias, bottom, bottomToBottom, bottomToTop, centerHorizontally, centerVertically, circularConstraint, clear, clearAll, clearHorizontal, clearVertical, createConstraintWidget, end, endToEnd, endToStart, getAlpha, getFacade, getHeight, getHorizontalChainStyle, getHorizontalChainWeight, getKey, getPivotX, getPivotY, getRotationX, getRotationY, getRotationZ, getScaleX, getScaleY, getTag, getTranslationX, getTranslationY, getTranslationZ, getVerticalChainStyle, getVerticalChainWeight, getView, getWidth, height, horizontalBias, left, leftToLeft, leftToRight, margin, margin, marginGone, marginGone, pivotX, pivotY, right, rightToLeft, rightToRight, rotationX, rotationY, rotationZ, scaleX, scaleY, setConstraintWidget, setFacade, setHeight, setHorizontalChainStyle, setHorizontalChainWeight, setKey, setTag, setVerticalChainStyle, setVerticalChainWeight, setView, setWidth, start, startToEnd, startToStart, top, topToBottom, topToTop, translationX, translationY, translationZ, validate, verticalBias, visibility, width
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public GridReference(State state, State.Helper type)

Methods

public int getPaddingStart()

get padding left

Returns:

padding left

public void setPaddingStart(int paddingStart)

set padding left

Parameters:

paddingStart: padding left to be set

public int getPaddingEnd()

get padding right

Returns:

padding right

public void setPaddingEnd(int paddingEnd)

set padding right

Parameters:

paddingEnd: padding right to be set

public int getPaddingTop()

get padding top

Returns:

padding top

public void setPaddingTop(int paddingTop)

set padding top

Parameters:

paddingTop: padding top to be set

public int getPaddingBottom()

get padding bottom

Returns:

padding bottom

public void setPaddingBottom(int paddingBottom)

set padding bottom

Parameters:

paddingBottom: padding bottom to be set

public int getFlags()

Get all the flags of a Grid

Returns:

an int value containing flag information

public void setFlags(int flags)

Set flags of a Grid

Parameters:

flags: an int value containing flag information

public void setFlags(java.lang.String flags)

Set flags of a Grid

Parameters:

flags: a String containing all the flags

public int getRowsSet()

Get the number of rows

Returns:

the number of rows

public void setRowsSet(int rowsSet)

Set the number of rows

Parameters:

rowsSet: the number of rows

public int getColumnsSet()

Get the number of columns

Returns:

the number of columns

public void setColumnsSet(int columnsSet)

Set the number of columns

Parameters:

columnsSet: the number of columns

public float getHorizontalGaps()

Get the horizontal gaps

Returns:

the horizontal gaps

public void setHorizontalGaps(float horizontalGaps)

Set the horizontal gaps

Parameters:

horizontalGaps: the horizontal gaps

public float getVerticalGaps()

Get the vertical gaps

Returns:

the vertical gaps

public void setVerticalGaps(float verticalGaps)

Set the vertical gaps

Parameters:

verticalGaps: the vertical gaps

public java.lang.String getRowWeights()

Get the row weights

Returns:

the row weights

public void setRowWeights(java.lang.String rowWeights)

Set the row weights

Parameters:

rowWeights: the row weights

public java.lang.String getColumnWeights()

Get the column weights

Returns:

the column weights

public void setColumnWeights(java.lang.String columnWeights)

Set the column weights

Parameters:

columnWeights: the column weights

public java.lang.String getSpans()

Get the spans

Returns:

the spans

public void setSpans(java.lang.String spans)

Set the spans

Parameters:

spans: the spans

public java.lang.String getSkips()

Get the skips

Returns:

the skips

public void setSkips(java.lang.String skips)

Set the skips

Parameters:

skips: the skips

public HelperWidget getHelperWidget()

Get the helper widget (Grid)

Returns:

the helper widget (Grid)

public void setHelperWidget(HelperWidget widget)

Set the helper widget (Grid)

Parameters:

widget: the helper widget (Grid)

public int getOrientation()

Get the Orientation

Returns:

the Orientation

public void setOrientation(int orientation)

Set the Orientation

Parameters:

orientation: the Orientation

public void apply()

Apply all the attributes to the helper widget (Grid)

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.state.helpers;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.core.state.HelperReference;
import androidx.constraintlayout.core.state.State;
import androidx.constraintlayout.core.utils.GridCore;
import androidx.constraintlayout.core.widgets.HelperWidget;

/**
 * A HelperReference of a Grid Helper that helps enable Grid in Compose
 */
public class GridReference extends HelperReference {

    private static final String SPANS_RESPECT_WIDGET_ORDER_STRING = "spansrespectwidgetorder";
    private static final String SUB_GRID_BY_COL_ROW_STRING = "subgridbycolrow";

    public GridReference(@NonNull State state, @NonNull State.Helper type) {
        super(state, type);
        if (type == State.Helper.ROW) {
            this.mRowsSet = 1;
        } else if (type == State.Helper.COLUMN) {
            this.mColumnsSet = 1;
        }
    }

    /**
     * The Grid Object
     */
    private GridCore mGrid;

    /**
     * padding start
     */
    private int mPaddingStart = 0;

    /**
     * padding end
     */
    private int mPaddingEnd = 0;

    /**
     * padding top
     */
    private int mPaddingTop = 0;

    /**
     * padding bottom
     */
    private int mPaddingBottom = 0;

    /**
     * The orientation of the widgets arrangement horizontally or vertically
     */
    private int mOrientation;

    /**
     * Number of rows of the Grid
     */
    private int mRowsSet;

    /**
     * Number of columns of the Grid
     */
    private int mColumnsSet;

    /**
     * The horizontal gaps between widgets
     */
    private float mHorizontalGaps;

    /**
     * The vertical gaps between widgets
     */
    private float mVerticalGaps;

    /**
     * The weight of each widget in a row
     */
    private String mRowWeights;

    /**
     * The weight of each widget in a column
     */
    private String mColumnWeights;

    /**
     * Specify the spanned areas of widgets
     */
    private String mSpans;

    /**
     * Specify the positions to be skipped in the Grid
     */
    private String mSkips;

    /**
     * An int value containing flag information.
     */
    private int mFlags;

    /**
     * get padding left
     * @return padding left
     */
    public int getPaddingStart() {
        return mPaddingStart;
    }

    /**
     * set padding left
     * @param paddingStart padding left to be set
     */
    public void setPaddingStart(int paddingStart) {
        mPaddingStart = paddingStart;
    }

    /**
     * get padding right
     * @return padding right
     */
    public int getPaddingEnd() {
        return mPaddingEnd;
    }

    /**
     * set padding right
     * @param paddingEnd padding right to be set
     */
    public void setPaddingEnd(int paddingEnd) {
        mPaddingEnd = paddingEnd;
    }

    /**
     * get padding top
     * @return padding top
     */
    public int getPaddingTop() {
        return mPaddingTop;
    }

    /**
     * set padding top
     * @param paddingTop padding top to be set
     */
    public void setPaddingTop(int paddingTop) {
        mPaddingTop = paddingTop;
    }

    /**
     * get padding bottom
     * @return padding bottom
     */
    public int getPaddingBottom() {
        return mPaddingBottom;
    }

    /**
     * set padding bottom
     * @param paddingBottom padding bottom to be set
     */
    public void setPaddingBottom(int paddingBottom) {
        mPaddingBottom = paddingBottom;
    }

    /**
     * Get all the flags of a Grid
     * @return an int value containing flag information
     */
    public int getFlags() {
        return mFlags;
    }

    /**
     * Set flags of a Grid
     * @param flags an int value containing flag information
     */
    public void setFlags(int flags) {
        mFlags = flags;
    }

    /**
     * Set flags of a Grid
     * @param flags a String containing all the flags
     */
    public void setFlags(@NonNull String flags) {
        if (flags.isEmpty()) {
            return;
        }

        String[] strArr = flags.split("\\|");
        mFlags = 0;
        for (String str: strArr) {
            switch (str.toLowerCase()) {
                case SUB_GRID_BY_COL_ROW_STRING:
                    mFlags |= 1;
                    break;
                case SPANS_RESPECT_WIDGET_ORDER_STRING:
                    mFlags |= 2;
                    break;
            }
        }
    }

    /**
     * Get the number of rows
     * @return the number of rows
     */
    public int getRowsSet() {
        return mRowsSet;
    }

    /**
     * Set the number of rows
     * @param rowsSet the number of rows
     */
    public void setRowsSet(int rowsSet) {
        if (super.getType() == State.Helper.COLUMN) {
            return;
        }
        mRowsSet = rowsSet;
    }

    /**
     * Get the number of columns
     * @return the number of columns
     */
    public int getColumnsSet() {
        return mColumnsSet;
    }

    /**
     * Set the number of columns
     * @param columnsSet the number of columns
     */
    public void setColumnsSet(int columnsSet) {
        if (super.getType() == State.Helper.ROW) {
            return;
        }
        mColumnsSet = columnsSet;
    }

    /**
     * Get the horizontal gaps
     * @return the horizontal gaps
     */
    public float getHorizontalGaps() {
        return mHorizontalGaps;
    }

    /**
     * Set the horizontal gaps
     * @param horizontalGaps the horizontal gaps
     */
    public void setHorizontalGaps(float horizontalGaps) {
        mHorizontalGaps = horizontalGaps;
    }

    /**
     * Get the vertical gaps
     * @return the vertical gaps
     */
    public float getVerticalGaps() {
        return mVerticalGaps;
    }

    /**
     * Set the vertical gaps
     * @param verticalGaps  the vertical gaps
     */
    public void setVerticalGaps(float verticalGaps) {
        mVerticalGaps = verticalGaps;
    }

    /**
     * Get the row weights
     * @return the row weights
     */
    @Nullable
    public String getRowWeights() {
        return mRowWeights;
    }

    /**
     * Set the row weights
     * @param rowWeights the row weights
     */
    public void setRowWeights(@NonNull String rowWeights) {
        mRowWeights = rowWeights;
    }

    /**
     * Get the column weights
     * @return the column weights
     */
    @Nullable
    public String getColumnWeights() {
        return mColumnWeights;
    }

    /**
     * Set the column weights
     * @param columnWeights the column weights
     */
    public void setColumnWeights(@NonNull String columnWeights) {
        mColumnWeights = columnWeights;
    }

    /**
     * Get the spans
     * @return the spans
     */
    @Nullable
    public String getSpans() {
        return mSpans;
    }

    /**
     * Set the spans
     * @param spans the spans
     */
    public void setSpans(@NonNull String spans) {
        mSpans = spans;
    }

    /**
     * Get the skips
     * @return the skips
     */
    @Nullable
    public String getSkips() {
        return mSkips;
    }

    /**
     * Set the skips
     * @param skips the skips
     */
    public void setSkips(@NonNull String skips) {
        mSkips = skips;
    }

    /**
     * Get the helper widget (Grid)
     * @return the helper widget (Grid)
     */
    @Override
    @NonNull
    public HelperWidget getHelperWidget() {
        if (mGrid == null) {
            mGrid = new GridCore();
        }
        return mGrid;
    }

    /**
     * Set the helper widget (Grid)
     * @param widget the helper widget (Grid)
     */
    @Override
    public void setHelperWidget(@Nullable HelperWidget widget) {
        if (widget instanceof GridCore) {
            mGrid = (GridCore) widget;
        } else {
            mGrid = null;
        }
    }

    /**
     * Get the Orientation
     * @return the Orientation
     */
    public int getOrientation() {
        return mOrientation;
    }

    /**
     * Set the Orientation
     * @param orientation the Orientation
     */
    public void setOrientation(int orientation) {
        mOrientation = orientation;

    }

    /**
     * Apply all the attributes to the helper widget (Grid)
     */
    @Override
    public void apply() {
        getHelperWidget();

        mGrid.setOrientation(mOrientation);

        if (mRowsSet != 0) {
            mGrid.setRows(mRowsSet);
        }

        if (mColumnsSet != 0) {
            mGrid.setColumns(mColumnsSet);
        }

        if (mHorizontalGaps != 0) {
            mGrid.setHorizontalGaps(mHorizontalGaps);
        }

        if (mVerticalGaps != 0) {
            mGrid.setVerticalGaps(mVerticalGaps);
        }

        if (mRowWeights != null && !mRowWeights.isEmpty()) {
            mGrid.setRowWeights(mRowWeights);
        }

        if (mColumnWeights != null && !mColumnWeights.isEmpty()) {
            mGrid.setColumnWeights(mColumnWeights);
        }

        if (mSpans != null && !mSpans.isEmpty()) {
            mGrid.setSpans(mSpans);
        }

        if (mSkips != null && !mSkips.isEmpty()) {
            mGrid.setSkips(mSkips);
        }

        mGrid.setFlags(mFlags);

        mGrid.setPaddingStart(mPaddingStart);
        mGrid.setPaddingEnd(mPaddingEnd);
        mGrid.setPaddingTop(mPaddingTop);
        mGrid.setPaddingBottom(mPaddingBottom);

        // General attributes of a widget
        applyBase();
    }
}