|
| 1 | +/* |
| 2 | + * Copyright 2016 Google Inc. All rights reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.google.android.flexbox; |
| 18 | + |
| 19 | +import java.util.ArrayList; |
| 20 | +import java.util.List; |
| 21 | + |
| 22 | +/** |
| 23 | + * Holds properties related to a single flex line. This class is not expected to be changed outside |
| 24 | + * of the {@link FlexboxLayout}, thus only exposing the getter methods that may be useful for |
| 25 | + * other classes using the {@link FlexboxLayout}. |
| 26 | + */ |
| 27 | +public class FlexLine { |
| 28 | + |
| 29 | + FlexLine() { |
| 30 | + } |
| 31 | + |
| 32 | + /** @see {@link #getLeft()} */ |
| 33 | + int mLeft = Integer.MAX_VALUE; |
| 34 | + |
| 35 | + /** @see {@link #getTop()} */ |
| 36 | + int mTop = Integer.MAX_VALUE; |
| 37 | + |
| 38 | + /** @see {@link #getRight()} */ |
| 39 | + int mRight = Integer.MIN_VALUE; |
| 40 | + |
| 41 | + /** @see {@link #getBottom()} */ |
| 42 | + int mBottom = Integer.MIN_VALUE; |
| 43 | + |
| 44 | + /** @see {@link #getMainSize()} */ |
| 45 | + int mMainSize; |
| 46 | + |
| 47 | + /** |
| 48 | + * The sum of the lengths of dividers along the main axis. This value should be lower or |
| 49 | + * than than the value of {@link #mMainSize}. |
| 50 | + */ |
| 51 | + int mDividerLengthInMainSize; |
| 52 | + |
| 53 | + /** @see {@link #getCrossSize()} */ |
| 54 | + int mCrossSize; |
| 55 | + |
| 56 | + /** @see {@link #getItemCount()} */ |
| 57 | + int mItemCount; |
| 58 | + |
| 59 | + /** @see {@link #getTotalFlexGrow()} */ |
| 60 | + float mTotalFlexGrow; |
| 61 | + |
| 62 | + /** @see {@link #getTotalFlexShrink()} */ |
| 63 | + float mTotalFlexShrink; |
| 64 | + |
| 65 | + /** |
| 66 | + * The largest value of the individual child's baseline (obtained by View#getBaseline() |
| 67 | + * if the {@link FlexboxLayout#mAlignItems} value is not {@link FlexboxLayout#ALIGN_ITEMS_BASELINE} |
| 68 | + * or the flex direction is vertical, this value is not used. |
| 69 | + * If the alignment direction is from the bottom to top, |
| 70 | + * (e.g. flexWrap == FLEX_WRAP_WRAP_REVERSE and flexDirection == FLEX_DIRECTION_ROW) |
| 71 | + * store this value from the distance from the bottom of the view minus baseline. |
| 72 | + * (Calculated as view.getMeasuredHeight() - view.getBaseline - LayoutParams.bottomMargin) |
| 73 | + */ |
| 74 | + int mMaxBaseline; |
| 75 | + |
| 76 | + /** |
| 77 | + * Store the indices of the children views whose alignSelf property is stretch. |
| 78 | + * The stored indices are the absolute indices including all children in the Flexbox, |
| 79 | + * not the relative indices in this flex line. |
| 80 | + */ |
| 81 | + List<Integer> mIndicesAlignSelfStretch = new ArrayList<>(); |
| 82 | + |
| 83 | + /** |
| 84 | + * @return the distance in pixels from the top edge of this view's parent |
| 85 | + * to the top edge of this FlexLine. |
| 86 | + */ |
| 87 | + public int getLeft() { |
| 88 | + return mLeft; |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * @return the distance in pixels from the top edge of this view's parent |
| 93 | + * to the top edge of this FlexLine. |
| 94 | + */ |
| 95 | + public int getTop() { |
| 96 | + return mTop; |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * @return the distance in pixels from the right edge of this view's parent |
| 101 | + * to the right edge of this FlexLine. |
| 102 | + */ |
| 103 | + public int getRight() { |
| 104 | + return mRight; |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * @return the distance in pixels from the bottom edge of this view's parent |
| 109 | + * to the bottom edge of this FlexLine. |
| 110 | + */ |
| 111 | + public int getBottom() { |
| 112 | + return mBottom; |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * @return the size of the flex line in pixels along the main axis of the flex container. |
| 117 | + */ |
| 118 | + public int getMainSize() { |
| 119 | + return mMainSize; |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * @return the size of the flex line in pixels along the cross axis of the flex container. |
| 124 | + */ |
| 125 | + public int getCrossSize() { |
| 126 | + return mCrossSize; |
| 127 | + } |
| 128 | + |
| 129 | + /** |
| 130 | + * @return the count of the views contained in this flex line. |
| 131 | + */ |
| 132 | + public int getItemCount() { |
| 133 | + return mItemCount; |
| 134 | + } |
| 135 | + |
| 136 | + /** |
| 137 | + * @return the sum of the flexGrow properties of the children included in this flex line |
| 138 | + */ |
| 139 | + public float getTotalFlexGrow() { |
| 140 | + return mTotalFlexGrow; |
| 141 | + } |
| 142 | + |
| 143 | + /** |
| 144 | + * @return the sum of the flexShrink properties of the children included in this flex line |
| 145 | + */ |
| 146 | + public float getTotalFlexShrink() { |
| 147 | + return mTotalFlexShrink; |
| 148 | + } |
| 149 | +} |
0 commit comments