mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-13 17:37:16 +01:00
161 lines
5.7 KiB
Java
161 lines
5.7 KiB
Java
package com.google.android.material.carousel;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.annotation.RestrictTo;
|
|
import androidx.biometric.ErrorUtils$$ExternalSyntheticOutline0;
|
|
import androidx.core.math.MathUtils;
|
|
import com.amazon.alexa.ra.core.ui.markdown.parser.formatter.MarkdownConstants;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP})
|
|
/* loaded from: classes7.dex */
|
|
public final class Arrangement {
|
|
private static final float MEDIUM_ITEM_FLEX_PERCENTAGE = 0.1f;
|
|
final float cost;
|
|
final int largeCount;
|
|
float largeSize;
|
|
int mediumCount;
|
|
float mediumSize;
|
|
final int priority;
|
|
int smallCount;
|
|
float smallSize;
|
|
|
|
public Arrangement(int i, float f, float f2, float f3, int i2, float f4, int i3, float f5, int i4, float f6) {
|
|
this.priority = i;
|
|
this.smallSize = MathUtils.clamp(f, f2, f3);
|
|
this.smallCount = i2;
|
|
this.mediumSize = f4;
|
|
this.mediumCount = i3;
|
|
this.largeSize = f5;
|
|
this.largeCount = i4;
|
|
fit(f6, f2, f3, f5);
|
|
this.cost = cost(f5);
|
|
}
|
|
|
|
private float calculateLargeSize(float f, int i, float f2, int i2, int i3) {
|
|
if (i <= 0) {
|
|
f2 = 0.0f;
|
|
}
|
|
float f3 = i;
|
|
float f4 = i2 / 2.0f;
|
|
return (f - ((f3 + f4) * f2)) / (i3 + f4);
|
|
}
|
|
|
|
private float cost(float f) {
|
|
if (isValid()) {
|
|
return Math.abs(f - this.largeSize) * this.priority;
|
|
}
|
|
return Float.MAX_VALUE;
|
|
}
|
|
|
|
@Nullable
|
|
public static Arrangement findLowestCostArrangement(float f, float f2, float f3, float f4, @NonNull int[] iArr, float f5, @NonNull int[] iArr2, float f6, @NonNull int[] iArr3) {
|
|
Arrangement arrangement = null;
|
|
int i = 1;
|
|
for (int i2 : iArr3) {
|
|
int length = iArr2.length;
|
|
int i3 = 0;
|
|
while (i3 < length) {
|
|
int i4 = iArr2[i3];
|
|
int length2 = iArr.length;
|
|
int i5 = 0;
|
|
while (i5 < length2) {
|
|
int i6 = length;
|
|
int i7 = i3;
|
|
int i8 = i;
|
|
int i9 = length2;
|
|
int i10 = i5;
|
|
Arrangement arrangement2 = new Arrangement(i8, f2, f3, f4, iArr[i5], f5, i4, f6, i2, f);
|
|
if (arrangement == null || arrangement2.cost < arrangement.cost) {
|
|
if (arrangement2.cost == 0.0f) {
|
|
return arrangement2;
|
|
}
|
|
arrangement = arrangement2;
|
|
}
|
|
int i11 = i8 + 1;
|
|
i5 = i10 + 1;
|
|
i3 = i7;
|
|
i = i11;
|
|
length = i6;
|
|
length2 = i9;
|
|
}
|
|
i3++;
|
|
i = i;
|
|
length = length;
|
|
}
|
|
}
|
|
return arrangement;
|
|
}
|
|
|
|
private void fit(float f, float f2, float f3, float f4) {
|
|
float space = f - getSpace();
|
|
int i = this.smallCount;
|
|
if (i > 0 && space > 0.0f) {
|
|
float f5 = this.smallSize;
|
|
this.smallSize = Math.min(space / i, f3 - f5) + f5;
|
|
} else if (i > 0 && space < 0.0f) {
|
|
float f6 = this.smallSize;
|
|
this.smallSize = Math.max(space / i, f2 - f6) + f6;
|
|
}
|
|
int i2 = this.smallCount;
|
|
float f7 = i2 > 0 ? this.smallSize : 0.0f;
|
|
this.smallSize = f7;
|
|
float calculateLargeSize = calculateLargeSize(f, i2, f7, this.mediumCount, this.largeCount);
|
|
this.largeSize = calculateLargeSize;
|
|
float f8 = (this.smallSize + calculateLargeSize) / 2.0f;
|
|
this.mediumSize = f8;
|
|
int i3 = this.mediumCount;
|
|
if (i3 <= 0 || calculateLargeSize == f4) {
|
|
return;
|
|
}
|
|
float f9 = (f4 - calculateLargeSize) * this.largeCount;
|
|
float min = Math.min(Math.abs(f9), f8 * 0.1f * i3);
|
|
float f10 = this.mediumSize;
|
|
if (f9 > 0.0f) {
|
|
this.mediumSize = f10 - (min / this.mediumCount);
|
|
this.largeSize = (min / this.largeCount) + this.largeSize;
|
|
} else {
|
|
this.mediumSize = (min / this.mediumCount) + f10;
|
|
this.largeSize -= min / this.largeCount;
|
|
}
|
|
}
|
|
|
|
private float getSpace() {
|
|
return (this.smallSize * this.smallCount) + (this.mediumSize * this.mediumCount) + (this.largeSize * this.largeCount);
|
|
}
|
|
|
|
private boolean isValid() {
|
|
int i = this.largeCount;
|
|
if (i <= 0 || this.smallCount <= 0 || this.mediumCount <= 0) {
|
|
return i <= 0 || this.smallCount <= 0 || this.largeSize > this.smallSize;
|
|
}
|
|
float f = this.largeSize;
|
|
float f2 = this.mediumSize;
|
|
return f > f2 && f2 > this.smallSize;
|
|
}
|
|
|
|
public int getItemCount() {
|
|
return this.smallCount + this.mediumCount + this.largeCount;
|
|
}
|
|
|
|
@NonNull
|
|
public String toString() {
|
|
StringBuilder sb = new StringBuilder("Arrangement [priority=");
|
|
sb.append(this.priority);
|
|
sb.append(", smallCount=");
|
|
sb.append(this.smallCount);
|
|
sb.append(", smallSize=");
|
|
sb.append(this.smallSize);
|
|
sb.append(", mediumCount=");
|
|
sb.append(this.mediumCount);
|
|
sb.append(", mediumSize=");
|
|
sb.append(this.mediumSize);
|
|
sb.append(", largeCount=");
|
|
sb.append(this.largeCount);
|
|
sb.append(", largeSize=");
|
|
sb.append(this.largeSize);
|
|
sb.append(", cost=");
|
|
return ErrorUtils$$ExternalSyntheticOutline0.m(sb, MarkdownConstants.RIGHT_BRACKET, this.cost);
|
|
}
|
|
}
|