mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-18 11:57:18 +01:00
197 lines
7.4 KiB
Java
197 lines
7.4 KiB
Java
package com.google.android.material.internal;
|
|
|
|
import android.content.Context;
|
|
import android.content.res.TypedArray;
|
|
import android.util.AttributeSet;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.annotation.RestrictTo;
|
|
import com.google.android.material.R;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP})
|
|
/* loaded from: classes7.dex */
|
|
public class FlowLayout extends ViewGroup {
|
|
private int itemSpacing;
|
|
private int lineSpacing;
|
|
private int rowCount;
|
|
private boolean singleLine;
|
|
|
|
public FlowLayout(@NonNull Context context, @Nullable AttributeSet attributeSet, int i) {
|
|
super(context, attributeSet, i);
|
|
this.singleLine = false;
|
|
loadFromAttributes(context, attributeSet);
|
|
}
|
|
|
|
private static int getMeasuredDimension(int i, int i2, int i3) {
|
|
return i2 != Integer.MIN_VALUE ? i2 != 1073741824 ? i3 : i : Math.min(i3, i);
|
|
}
|
|
|
|
private void loadFromAttributes(@NonNull Context context, @Nullable AttributeSet attributeSet) {
|
|
TypedArray obtainStyledAttributes = context.getTheme().obtainStyledAttributes(attributeSet, R.styleable.FlowLayout, 0, 0);
|
|
this.lineSpacing = obtainStyledAttributes.getDimensionPixelSize(R.styleable.FlowLayout_lineSpacing, 0);
|
|
this.itemSpacing = obtainStyledAttributes.getDimensionPixelSize(R.styleable.FlowLayout_horizontalItemSpacing, 0);
|
|
obtainStyledAttributes.recycle();
|
|
}
|
|
|
|
public int getItemSpacing() {
|
|
return this.itemSpacing;
|
|
}
|
|
|
|
public int getLineSpacing() {
|
|
return this.lineSpacing;
|
|
}
|
|
|
|
public int getRowCount() {
|
|
return this.rowCount;
|
|
}
|
|
|
|
public int getRowIndex(@NonNull View view) {
|
|
Object tag = view.getTag(R.id.row_index_key);
|
|
if (tag instanceof Integer) {
|
|
return ((Integer) tag).intValue();
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
public boolean isSingleLine() {
|
|
return this.singleLine;
|
|
}
|
|
|
|
@Override // android.view.ViewGroup, android.view.View
|
|
public void onLayout(boolean z, int i, int i2, int i3, int i4) {
|
|
int i5;
|
|
int i6;
|
|
boolean z2;
|
|
if (getChildCount() == 0) {
|
|
this.rowCount = 0;
|
|
return;
|
|
}
|
|
boolean z3 = true;
|
|
this.rowCount = 1;
|
|
boolean z4 = getLayoutDirection() == 1;
|
|
int paddingRight = z4 ? getPaddingRight() : getPaddingLeft();
|
|
int paddingLeft = z4 ? getPaddingLeft() : getPaddingRight();
|
|
int paddingTop = getPaddingTop();
|
|
int i7 = 0;
|
|
int i8 = paddingRight;
|
|
int i9 = paddingTop;
|
|
while (i7 < getChildCount()) {
|
|
View childAt = getChildAt(i7);
|
|
if (childAt.getVisibility() == 8) {
|
|
childAt.setTag(R.id.row_index_key, -1);
|
|
z2 = z3;
|
|
} else {
|
|
ViewGroup.LayoutParams layoutParams = childAt.getLayoutParams();
|
|
if (layoutParams instanceof ViewGroup.MarginLayoutParams) {
|
|
ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) layoutParams;
|
|
i6 = marginLayoutParams.getMarginStart();
|
|
i5 = marginLayoutParams.getMarginEnd();
|
|
} else {
|
|
i5 = 0;
|
|
i6 = 0;
|
|
}
|
|
int measuredWidth = childAt.getMeasuredWidth() + i8 + i6;
|
|
int i10 = i3 - i;
|
|
int i11 = i10 - paddingLeft;
|
|
z2 = z3;
|
|
if (!this.singleLine && measuredWidth > i11) {
|
|
measuredWidth = childAt.getMeasuredWidth() + paddingRight + i6;
|
|
i9 = paddingTop + this.lineSpacing;
|
|
this.rowCount++;
|
|
i8 = paddingRight;
|
|
}
|
|
childAt.setTag(R.id.row_index_key, Integer.valueOf(this.rowCount - 1));
|
|
int measuredHeight = childAt.getMeasuredHeight() + i9;
|
|
if (z4) {
|
|
childAt.layout(i10 - measuredWidth, i9, (i10 - i8) - i6, measuredHeight);
|
|
} else {
|
|
childAt.layout(i8 + i6, i9, measuredWidth, measuredHeight);
|
|
}
|
|
i8 += childAt.getMeasuredWidth() + i6 + i5 + this.itemSpacing;
|
|
paddingTop = measuredHeight;
|
|
}
|
|
i7++;
|
|
z3 = z2;
|
|
}
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public void onMeasure(int i, int i2) {
|
|
int i3;
|
|
int i4;
|
|
int i5;
|
|
int size = View.MeasureSpec.getSize(i);
|
|
int mode = View.MeasureSpec.getMode(i);
|
|
int size2 = View.MeasureSpec.getSize(i2);
|
|
int mode2 = View.MeasureSpec.getMode(i2);
|
|
int i6 = (mode == Integer.MIN_VALUE || mode == 1073741824) ? size : Integer.MAX_VALUE;
|
|
int paddingLeft = getPaddingLeft();
|
|
int paddingTop = getPaddingTop();
|
|
int paddingRight = i6 - getPaddingRight();
|
|
int i7 = paddingTop;
|
|
int i8 = 0;
|
|
for (int i9 = 0; i9 < getChildCount(); i9++) {
|
|
View childAt = getChildAt(i9);
|
|
if (childAt.getVisibility() != 8) {
|
|
measureChild(childAt, i, i2);
|
|
ViewGroup.LayoutParams layoutParams = childAt.getLayoutParams();
|
|
if (layoutParams instanceof ViewGroup.MarginLayoutParams) {
|
|
ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) layoutParams;
|
|
i3 = marginLayoutParams.leftMargin;
|
|
i4 = marginLayoutParams.rightMargin;
|
|
} else {
|
|
i3 = 0;
|
|
i4 = 0;
|
|
}
|
|
int i10 = paddingLeft;
|
|
if (childAt.getMeasuredWidth() + paddingLeft + i3 <= paddingRight || isSingleLine()) {
|
|
i5 = i10;
|
|
} else {
|
|
i5 = getPaddingLeft();
|
|
i7 = this.lineSpacing + paddingTop;
|
|
}
|
|
int measuredWidth = childAt.getMeasuredWidth() + i5 + i3;
|
|
int measuredHeight = childAt.getMeasuredHeight() + i7;
|
|
if (measuredWidth > i8) {
|
|
i8 = measuredWidth;
|
|
}
|
|
int measuredWidth2 = childAt.getMeasuredWidth() + i3 + i4 + this.itemSpacing + i5;
|
|
if (i9 == getChildCount() - 1) {
|
|
i8 += i4;
|
|
}
|
|
paddingLeft = measuredWidth2;
|
|
paddingTop = measuredHeight;
|
|
}
|
|
}
|
|
setMeasuredDimension(getMeasuredDimension(size, mode, getPaddingRight() + i8), getMeasuredDimension(size2, mode2, getPaddingBottom() + paddingTop));
|
|
}
|
|
|
|
public void setItemSpacing(int i) {
|
|
this.itemSpacing = i;
|
|
}
|
|
|
|
public void setLineSpacing(int i) {
|
|
this.lineSpacing = i;
|
|
}
|
|
|
|
public void setSingleLine(boolean z) {
|
|
this.singleLine = z;
|
|
}
|
|
|
|
public FlowLayout(@NonNull Context context, @Nullable AttributeSet attributeSet) {
|
|
this(context, attributeSet, 0);
|
|
}
|
|
|
|
public FlowLayout(@NonNull Context context) {
|
|
this(context, null);
|
|
}
|
|
|
|
public FlowLayout(@NonNull Context context, @Nullable AttributeSet attributeSet, int i, int i2) {
|
|
super(context, attributeSet, i, i2);
|
|
this.singleLine = false;
|
|
loadFromAttributes(context, attributeSet);
|
|
}
|
|
}
|