mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-17 03:17:17 +01:00
250 lines
11 KiB
Java
250 lines
11 KiB
Java
package androidx.constraintlayout.widget;
|
|
|
|
import android.content.Context;
|
|
import android.content.res.TypedArray;
|
|
import android.util.Log;
|
|
import android.util.SparseArray;
|
|
import android.util.Xml;
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import org.xmlpull.v1.XmlPullParser;
|
|
import org.xmlpull.v1.XmlPullParserException;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
/* loaded from: classes13.dex */
|
|
public class StateSet {
|
|
private static final boolean DEBUG = false;
|
|
public static final String TAG = "ConstraintLayoutStates";
|
|
int mDefaultState = -1;
|
|
int mCurrentStateId = -1;
|
|
int mCurrentConstraintNumber = -1;
|
|
private SparseArray<State> mStateList = new SparseArray<>();
|
|
private ConstraintsChangedListener mConstraintsChangedListener = null;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
public static class State {
|
|
int mConstraintID;
|
|
int mId;
|
|
boolean mIsLayout;
|
|
ArrayList<Variant> mVariants = new ArrayList<>();
|
|
|
|
public State(Context context, XmlPullParser xmlPullParser) {
|
|
this.mConstraintID = -1;
|
|
this.mIsLayout = false;
|
|
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(Xml.asAttributeSet(xmlPullParser), R.styleable.State);
|
|
int indexCount = obtainStyledAttributes.getIndexCount();
|
|
for (int i = 0; i < indexCount; i++) {
|
|
int index = obtainStyledAttributes.getIndex(i);
|
|
if (index == R.styleable.State_android_id) {
|
|
this.mId = obtainStyledAttributes.getResourceId(index, this.mId);
|
|
} else if (index == R.styleable.State_constraints) {
|
|
this.mConstraintID = obtainStyledAttributes.getResourceId(index, this.mConstraintID);
|
|
String resourceTypeName = context.getResources().getResourceTypeName(this.mConstraintID);
|
|
context.getResources().getResourceName(this.mConstraintID);
|
|
if ("layout".equals(resourceTypeName)) {
|
|
this.mIsLayout = true;
|
|
}
|
|
}
|
|
}
|
|
obtainStyledAttributes.recycle();
|
|
}
|
|
|
|
public void add(Variant variant) {
|
|
this.mVariants.add(variant);
|
|
}
|
|
|
|
public int findMatch(float f, float f2) {
|
|
for (int i = 0; i < this.mVariants.size(); i++) {
|
|
if (this.mVariants.get(i).match(f, f2)) {
|
|
return i;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
public static class Variant {
|
|
int mConstraintID;
|
|
int mId;
|
|
boolean mIsLayout;
|
|
float mMaxHeight;
|
|
float mMaxWidth;
|
|
float mMinHeight;
|
|
float mMinWidth;
|
|
|
|
public Variant(Context context, XmlPullParser xmlPullParser) {
|
|
this.mMinWidth = Float.NaN;
|
|
this.mMinHeight = Float.NaN;
|
|
this.mMaxWidth = Float.NaN;
|
|
this.mMaxHeight = Float.NaN;
|
|
this.mConstraintID = -1;
|
|
this.mIsLayout = false;
|
|
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(Xml.asAttributeSet(xmlPullParser), R.styleable.Variant);
|
|
int indexCount = obtainStyledAttributes.getIndexCount();
|
|
for (int i = 0; i < indexCount; i++) {
|
|
int index = obtainStyledAttributes.getIndex(i);
|
|
if (index == R.styleable.Variant_constraints) {
|
|
this.mConstraintID = obtainStyledAttributes.getResourceId(index, this.mConstraintID);
|
|
String resourceTypeName = context.getResources().getResourceTypeName(this.mConstraintID);
|
|
context.getResources().getResourceName(this.mConstraintID);
|
|
if ("layout".equals(resourceTypeName)) {
|
|
this.mIsLayout = true;
|
|
}
|
|
} else if (index == R.styleable.Variant_region_heightLessThan) {
|
|
this.mMaxHeight = obtainStyledAttributes.getDimension(index, this.mMaxHeight);
|
|
} else if (index == R.styleable.Variant_region_heightMoreThan) {
|
|
this.mMinHeight = obtainStyledAttributes.getDimension(index, this.mMinHeight);
|
|
} else if (index == R.styleable.Variant_region_widthLessThan) {
|
|
this.mMaxWidth = obtainStyledAttributes.getDimension(index, this.mMaxWidth);
|
|
} else if (index == R.styleable.Variant_region_widthMoreThan) {
|
|
this.mMinWidth = obtainStyledAttributes.getDimension(index, this.mMinWidth);
|
|
}
|
|
}
|
|
obtainStyledAttributes.recycle();
|
|
}
|
|
|
|
public boolean match(float f, float f2) {
|
|
if (!Float.isNaN(this.mMinWidth) && f < this.mMinWidth) {
|
|
return false;
|
|
}
|
|
if (!Float.isNaN(this.mMinHeight) && f2 < this.mMinHeight) {
|
|
return false;
|
|
}
|
|
if (Float.isNaN(this.mMaxWidth) || f <= this.mMaxWidth) {
|
|
return Float.isNaN(this.mMaxHeight) || f2 <= this.mMaxHeight;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public StateSet(Context context, XmlPullParser xmlPullParser) {
|
|
load(context, xmlPullParser);
|
|
}
|
|
|
|
/* JADX WARN: Failed to restore switch over string. Please report as a decompilation issue */
|
|
private void load(Context context, XmlPullParser xmlPullParser) {
|
|
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(Xml.asAttributeSet(xmlPullParser), R.styleable.StateSet);
|
|
int indexCount = obtainStyledAttributes.getIndexCount();
|
|
for (int i = 0; i < indexCount; i++) {
|
|
int index = obtainStyledAttributes.getIndex(i);
|
|
if (index == R.styleable.StateSet_defaultState) {
|
|
this.mDefaultState = obtainStyledAttributes.getResourceId(index, this.mDefaultState);
|
|
}
|
|
}
|
|
obtainStyledAttributes.recycle();
|
|
try {
|
|
int eventType = xmlPullParser.getEventType();
|
|
State state = null;
|
|
while (eventType != 1) {
|
|
if (eventType == 2) {
|
|
String name = xmlPullParser.getName();
|
|
switch (name.hashCode()) {
|
|
case 80204913:
|
|
if (name.equals("State")) {
|
|
state = new State(context, xmlPullParser);
|
|
this.mStateList.put(state.mId, state);
|
|
break;
|
|
} else {
|
|
break;
|
|
}
|
|
case 1301459538:
|
|
name.equals("LayoutDescription");
|
|
break;
|
|
case 1382829617:
|
|
name.equals("StateSet");
|
|
break;
|
|
case 1901439077:
|
|
if (name.equals("Variant")) {
|
|
Variant variant = new Variant(context, xmlPullParser);
|
|
if (state != null) {
|
|
state.add(variant);
|
|
break;
|
|
} else {
|
|
break;
|
|
}
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
} else if (eventType != 3) {
|
|
continue;
|
|
} else if ("StateSet".equals(xmlPullParser.getName())) {
|
|
return;
|
|
}
|
|
eventType = xmlPullParser.next();
|
|
}
|
|
} catch (IOException e) {
|
|
Log.e("ConstraintLayoutStates", "Error parsing XML resource", e);
|
|
} catch (XmlPullParserException e2) {
|
|
Log.e("ConstraintLayoutStates", "Error parsing XML resource", e2);
|
|
}
|
|
}
|
|
|
|
public int convertToConstraintSet(int i, int i2, float f, float f2) {
|
|
State state = this.mStateList.get(i2);
|
|
if (state == null) {
|
|
return i2;
|
|
}
|
|
if (f != -1.0f && f2 != -1.0f) {
|
|
Iterator<Variant> it2 = state.mVariants.iterator();
|
|
Variant variant = null;
|
|
while (it2.hasNext()) {
|
|
Variant next = it2.next();
|
|
if (next.match(f, f2)) {
|
|
if (i != next.mConstraintID) {
|
|
variant = next;
|
|
}
|
|
}
|
|
}
|
|
return variant != null ? variant.mConstraintID : state.mConstraintID;
|
|
}
|
|
if (state.mConstraintID != i) {
|
|
Iterator<Variant> it3 = state.mVariants.iterator();
|
|
while (it3.hasNext()) {
|
|
if (i == it3.next().mConstraintID) {
|
|
}
|
|
}
|
|
return state.mConstraintID;
|
|
}
|
|
return i;
|
|
}
|
|
|
|
public boolean needsToChange(int i, float f, float f2) {
|
|
int i2 = this.mCurrentStateId;
|
|
if (i2 != i) {
|
|
return true;
|
|
}
|
|
SparseArray<State> sparseArray = this.mStateList;
|
|
State valueAt = i == -1 ? sparseArray.valueAt(0) : sparseArray.get(i2);
|
|
int i3 = this.mCurrentConstraintNumber;
|
|
return (i3 == -1 || !valueAt.mVariants.get(i3).match(f, f2)) && this.mCurrentConstraintNumber != valueAt.findMatch(f, f2);
|
|
}
|
|
|
|
public void setOnConstraintsChanged(ConstraintsChangedListener constraintsChangedListener) {
|
|
this.mConstraintsChangedListener = constraintsChangedListener;
|
|
}
|
|
|
|
public int stateGetConstraintID(int i, int i2, int i3) {
|
|
return updateConstraints(-1, i, i2, i3);
|
|
}
|
|
|
|
public int updateConstraints(int i, int i2, float f, float f2) {
|
|
int findMatch;
|
|
if (i == i2) {
|
|
SparseArray<State> sparseArray = this.mStateList;
|
|
State valueAt = i2 == -1 ? sparseArray.valueAt(0) : sparseArray.get(this.mCurrentStateId);
|
|
if (valueAt == null) {
|
|
return -1;
|
|
}
|
|
return ((this.mCurrentConstraintNumber == -1 || !valueAt.mVariants.get(i).match(f, f2)) && i != (findMatch = valueAt.findMatch(f, f2))) ? findMatch == -1 ? valueAt.mConstraintID : valueAt.mVariants.get(findMatch).mConstraintID : i;
|
|
}
|
|
State state = this.mStateList.get(i2);
|
|
if (state == null) {
|
|
return -1;
|
|
}
|
|
int findMatch2 = state.findMatch(f, f2);
|
|
return findMatch2 == -1 ? state.mConstraintID : state.mVariants.get(findMatch2).mConstraintID;
|
|
}
|
|
}
|