mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2024-12-28 18:12:31 -06:00
302 lines
13 KiB
Java
302 lines
13 KiB
Java
package androidx.constraintlayout.widget;
|
|
|
|
import android.content.Context;
|
|
import android.content.res.TypedArray;
|
|
import android.content.res.XmlResourceParser;
|
|
import android.util.Log;
|
|
import android.util.SparseArray;
|
|
import android.util.Xml;
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import org.xmlpull.v1.XmlPullParser;
|
|
import org.xmlpull.v1.XmlPullParserException;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class ConstraintLayoutStates {
|
|
private static final boolean DEBUG = false;
|
|
public static final String TAG = "ConstraintLayoutStates";
|
|
private final ConstraintLayout mConstraintLayout;
|
|
ConstraintSet mDefaultConstraintSet;
|
|
int mCurrentStateId = -1;
|
|
int mCurrentConstraintNumber = -1;
|
|
private SparseArray<State> mStateList = new SparseArray<>();
|
|
private SparseArray<ConstraintSet> mConstraintSetMap = new SparseArray<>();
|
|
private ConstraintsChangedListener mConstraintsChangedListener = null;
|
|
|
|
public void setOnConstraintsChanged(ConstraintsChangedListener constraintsChangedListener) {
|
|
this.mConstraintsChangedListener = constraintsChangedListener;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public ConstraintLayoutStates(Context context, ConstraintLayout constraintLayout, int i) {
|
|
this.mConstraintLayout = constraintLayout;
|
|
load(context, i);
|
|
}
|
|
|
|
public boolean needsToChange(int i, float f, float f2) {
|
|
int i2 = this.mCurrentStateId;
|
|
if (i2 != i) {
|
|
return true;
|
|
}
|
|
State valueAt = i == -1 ? this.mStateList.valueAt(0) : this.mStateList.get(i2);
|
|
return (this.mCurrentConstraintNumber == -1 || !valueAt.mVariants.get(this.mCurrentConstraintNumber).match(f, f2)) && this.mCurrentConstraintNumber != valueAt.findMatch(f, f2);
|
|
}
|
|
|
|
public void updateConstraints(int i, float f, float f2) {
|
|
ConstraintSet constraintSet;
|
|
int i2;
|
|
State state;
|
|
int findMatch;
|
|
int i3;
|
|
int i4 = this.mCurrentStateId;
|
|
if (i4 == i) {
|
|
if (i == -1) {
|
|
state = this.mStateList.valueAt(0);
|
|
} else {
|
|
state = this.mStateList.get(i4);
|
|
}
|
|
if ((this.mCurrentConstraintNumber == -1 || !state.mVariants.get(this.mCurrentConstraintNumber).match(f, f2)) && this.mCurrentConstraintNumber != (findMatch = state.findMatch(f, f2))) {
|
|
ConstraintSet constraintSet2 = findMatch == -1 ? this.mDefaultConstraintSet : state.mVariants.get(findMatch).mConstraintSet;
|
|
if (findMatch == -1) {
|
|
i3 = state.mConstraintID;
|
|
} else {
|
|
i3 = state.mVariants.get(findMatch).mConstraintID;
|
|
}
|
|
if (constraintSet2 == null) {
|
|
return;
|
|
}
|
|
this.mCurrentConstraintNumber = findMatch;
|
|
ConstraintsChangedListener constraintsChangedListener = this.mConstraintsChangedListener;
|
|
if (constraintsChangedListener != null) {
|
|
constraintsChangedListener.preLayoutChange(-1, i3);
|
|
}
|
|
constraintSet2.applyTo(this.mConstraintLayout);
|
|
ConstraintsChangedListener constraintsChangedListener2 = this.mConstraintsChangedListener;
|
|
if (constraintsChangedListener2 != null) {
|
|
constraintsChangedListener2.postLayoutChange(-1, i3);
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
this.mCurrentStateId = i;
|
|
State state2 = this.mStateList.get(i);
|
|
int findMatch2 = state2.findMatch(f, f2);
|
|
if (findMatch2 == -1) {
|
|
constraintSet = state2.mConstraintSet;
|
|
} else {
|
|
constraintSet = state2.mVariants.get(findMatch2).mConstraintSet;
|
|
}
|
|
if (findMatch2 == -1) {
|
|
i2 = state2.mConstraintID;
|
|
} else {
|
|
i2 = state2.mVariants.get(findMatch2).mConstraintID;
|
|
}
|
|
if (constraintSet == null) {
|
|
Log.v("ConstraintLayoutStates", "NO Constraint set found ! id=" + i + ", dim =" + f + ", " + f2);
|
|
return;
|
|
}
|
|
this.mCurrentConstraintNumber = findMatch2;
|
|
ConstraintsChangedListener constraintsChangedListener3 = this.mConstraintsChangedListener;
|
|
if (constraintsChangedListener3 != null) {
|
|
constraintsChangedListener3.preLayoutChange(i, i2);
|
|
}
|
|
constraintSet.applyTo(this.mConstraintLayout);
|
|
ConstraintsChangedListener constraintsChangedListener4 = this.mConstraintsChangedListener;
|
|
if (constraintsChangedListener4 != null) {
|
|
constraintsChangedListener4.postLayoutChange(i, i2);
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* loaded from: classes.dex */
|
|
public static class State {
|
|
int mConstraintID;
|
|
ConstraintSet mConstraintSet;
|
|
int mId;
|
|
ArrayList<Variant> mVariants = new ArrayList<>();
|
|
|
|
public State(Context context, XmlPullParser xmlPullParser) {
|
|
this.mConstraintID = -1;
|
|
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)) {
|
|
ConstraintSet constraintSet = new ConstraintSet();
|
|
this.mConstraintSet = constraintSet;
|
|
constraintSet.clone(context, this.mConstraintID);
|
|
}
|
|
}
|
|
}
|
|
obtainStyledAttributes.recycle();
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* loaded from: classes.dex */
|
|
public static class Variant {
|
|
int mConstraintID;
|
|
ConstraintSet mConstraintSet;
|
|
int mId;
|
|
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;
|
|
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)) {
|
|
ConstraintSet constraintSet = new ConstraintSet();
|
|
this.mConstraintSet = constraintSet;
|
|
constraintSet.clone(context, this.mConstraintID);
|
|
}
|
|
} 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);
|
|
} else {
|
|
Log.v("ConstraintLayoutStates", "Unknown tag");
|
|
}
|
|
}
|
|
obtainStyledAttributes.recycle();
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
private void load(Context context, int i) {
|
|
char c;
|
|
XmlResourceParser xml = context.getResources().getXml(i);
|
|
try {
|
|
State state = null;
|
|
for (int eventType = xml.getEventType(); eventType != 1; eventType = xml.next()) {
|
|
if (eventType == 0) {
|
|
xml.getName();
|
|
} else if (eventType == 2) {
|
|
String name = xml.getName();
|
|
switch (name.hashCode()) {
|
|
case -1349929691:
|
|
if (name.equals("ConstraintSet")) {
|
|
c = 4;
|
|
break;
|
|
}
|
|
break;
|
|
case 80204913:
|
|
if (name.equals("State")) {
|
|
c = 2;
|
|
break;
|
|
}
|
|
break;
|
|
case 1382829617:
|
|
if (name.equals("StateSet")) {
|
|
c = 1;
|
|
break;
|
|
}
|
|
break;
|
|
case 1657696882:
|
|
if (name.equals("layoutDescription")) {
|
|
c = 0;
|
|
break;
|
|
}
|
|
break;
|
|
case 1901439077:
|
|
if (name.equals("Variant")) {
|
|
c = 3;
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
c = 65535;
|
|
if (c != 0 && c != 1) {
|
|
if (c == 2) {
|
|
state = new State(context, xml);
|
|
this.mStateList.put(state.mId, state);
|
|
} else if (c == 3) {
|
|
Variant variant = new Variant(context, xml);
|
|
if (state != null) {
|
|
state.add(variant);
|
|
}
|
|
} else if (c == 4) {
|
|
parseConstraintSet(context, xml);
|
|
} else {
|
|
Log.v("ConstraintLayoutStates", "unknown tag " + name);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
} catch (XmlPullParserException e2) {
|
|
e2.printStackTrace();
|
|
}
|
|
}
|
|
|
|
private void parseConstraintSet(Context context, XmlPullParser xmlPullParser) {
|
|
ConstraintSet constraintSet = new ConstraintSet();
|
|
int attributeCount = xmlPullParser.getAttributeCount();
|
|
for (int i = 0; i < attributeCount; i++) {
|
|
if ("id".equals(xmlPullParser.getAttributeName(i))) {
|
|
String attributeValue = xmlPullParser.getAttributeValue(i);
|
|
int identifier = attributeValue.contains("/") ? context.getResources().getIdentifier(attributeValue.substring(attributeValue.indexOf(47) + 1), "id", context.getPackageName()) : -1;
|
|
if (identifier == -1) {
|
|
if (attributeValue != null && attributeValue.length() > 1) {
|
|
identifier = Integer.parseInt(attributeValue.substring(1));
|
|
} else {
|
|
Log.e("ConstraintLayoutStates", "error in parsing id");
|
|
}
|
|
}
|
|
constraintSet.load(context, xmlPullParser);
|
|
this.mConstraintSetMap.put(identifier, constraintSet);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|