2021-06-27 20:44:35 +00:00
|
|
|
package androidx.constraintlayout.widget;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.content.res.TypedArray;
|
|
|
|
import android.graphics.Canvas;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.util.SparseArray;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.ViewParent;
|
|
|
|
import androidx.constraintlayout.solver.widgets.ConstraintWidget;
|
|
|
|
import androidx.constraintlayout.solver.widgets.ConstraintWidgetContainer;
|
|
|
|
import androidx.constraintlayout.solver.widgets.Helper;
|
|
|
|
import androidx.constraintlayout.solver.widgets.HelperWidget;
|
|
|
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
|
|
|
import androidx.constraintlayout.widget.ConstraintSet;
|
|
|
|
import androidx.constraintlayout.widget.R;
|
2021-12-21 23:37:30 +00:00
|
|
|
import b.d.b.a.a;
|
2021-08-09 22:50:01 +00:00
|
|
|
import com.discord.models.domain.ModelAuditLogEntry;
|
2021-06-27 20:44:35 +00:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.HashMap;
|
|
|
|
public abstract class ConstraintHelper extends View {
|
|
|
|
public int mCount;
|
|
|
|
public Helper mHelperWidget;
|
|
|
|
public int[] mIds;
|
|
|
|
private HashMap<Integer, String> mMap;
|
|
|
|
public String mReferenceIds;
|
|
|
|
public String mReferenceTags;
|
|
|
|
public boolean mUseViewMeasure;
|
|
|
|
private View[] mViews;
|
|
|
|
public Context myContext;
|
|
|
|
|
|
|
|
public ConstraintHelper(Context context) {
|
|
|
|
super(context);
|
|
|
|
this.mIds = new int[32];
|
|
|
|
this.mUseViewMeasure = false;
|
|
|
|
this.mViews = null;
|
|
|
|
this.mMap = new HashMap<>();
|
|
|
|
this.myContext = context;
|
|
|
|
init(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ConstraintHelper(Context context, AttributeSet attributeSet) {
|
|
|
|
super(context, attributeSet);
|
|
|
|
this.mIds = new int[32];
|
|
|
|
this.mUseViewMeasure = false;
|
|
|
|
this.mViews = null;
|
|
|
|
this.mMap = new HashMap<>();
|
|
|
|
this.myContext = context;
|
|
|
|
init(attributeSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ConstraintHelper(Context context, AttributeSet attributeSet, int i) {
|
|
|
|
super(context, attributeSet, i);
|
|
|
|
this.mIds = new int[32];
|
|
|
|
this.mUseViewMeasure = false;
|
|
|
|
this.mViews = null;
|
|
|
|
this.mMap = new HashMap<>();
|
|
|
|
this.myContext = context;
|
|
|
|
init(attributeSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void addID(String str) {
|
|
|
|
if (str != null && str.length() != 0 && this.myContext != null) {
|
|
|
|
String trim = str.trim();
|
|
|
|
if (getParent() instanceof ConstraintLayout) {
|
|
|
|
ConstraintLayout constraintLayout = (ConstraintLayout) getParent();
|
|
|
|
}
|
|
|
|
int findId = findId(trim);
|
|
|
|
if (findId != 0) {
|
|
|
|
this.mMap.put(Integer.valueOf(findId), trim);
|
|
|
|
addRscID(findId);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Log.w("ConstraintHelper", "Could not find id of \"" + trim + "\"");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void addRscID(int i) {
|
|
|
|
if (i != getId()) {
|
|
|
|
int i2 = this.mCount + 1;
|
|
|
|
int[] iArr = this.mIds;
|
|
|
|
if (i2 > iArr.length) {
|
|
|
|
this.mIds = Arrays.copyOf(iArr, iArr.length * 2);
|
|
|
|
}
|
|
|
|
int[] iArr2 = this.mIds;
|
|
|
|
int i3 = this.mCount;
|
|
|
|
iArr2[i3] = i;
|
|
|
|
this.mCount = i3 + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void addTag(String str) {
|
|
|
|
if (!(str == null || str.length() == 0 || this.myContext == null)) {
|
|
|
|
String trim = str.trim();
|
|
|
|
ConstraintLayout constraintLayout = null;
|
|
|
|
if (getParent() instanceof ConstraintLayout) {
|
|
|
|
constraintLayout = (ConstraintLayout) getParent();
|
|
|
|
}
|
|
|
|
if (constraintLayout == null) {
|
|
|
|
Log.w("ConstraintHelper", "Parent not a ConstraintLayout");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int childCount = constraintLayout.getChildCount();
|
|
|
|
for (int i = 0; i < childCount; i++) {
|
|
|
|
View childAt = constraintLayout.getChildAt(i);
|
|
|
|
ViewGroup.LayoutParams layoutParams = childAt.getLayoutParams();
|
|
|
|
if ((layoutParams instanceof ConstraintLayout.LayoutParams) && trim.equals(((ConstraintLayout.LayoutParams) layoutParams).constraintTag)) {
|
|
|
|
if (childAt.getId() == -1) {
|
2021-11-08 18:25:28 +00:00
|
|
|
StringBuilder R = a.R("to use ConstraintTag view ");
|
|
|
|
R.append(childAt.getClass().getSimpleName());
|
|
|
|
R.append(" must have an ID");
|
|
|
|
Log.w("ConstraintHelper", R.toString());
|
2021-06-27 20:44:35 +00:00
|
|
|
} else {
|
|
|
|
addRscID(childAt.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private int[] convertReferenceString(View view, String str) {
|
|
|
|
String[] split = str.split(",");
|
|
|
|
view.getContext();
|
|
|
|
int[] iArr = new int[split.length];
|
|
|
|
int i = 0;
|
|
|
|
for (String str2 : split) {
|
|
|
|
int findId = findId(str2.trim());
|
|
|
|
if (findId != 0) {
|
|
|
|
iArr[i] = findId;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i != split.length ? Arrays.copyOf(iArr, i) : iArr;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int findId(ConstraintLayout constraintLayout, String str) {
|
|
|
|
Resources resources;
|
|
|
|
if (str == null || constraintLayout == null || (resources = this.myContext.getResources()) == null) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int childCount = constraintLayout.getChildCount();
|
|
|
|
for (int i = 0; i < childCount; i++) {
|
|
|
|
View childAt = constraintLayout.getChildAt(i);
|
|
|
|
if (childAt.getId() != -1) {
|
|
|
|
String str2 = null;
|
|
|
|
try {
|
|
|
|
str2 = resources.getResourceEntryName(childAt.getId());
|
|
|
|
} catch (Resources.NotFoundException unused) {
|
|
|
|
}
|
|
|
|
if (str.equals(str2)) {
|
|
|
|
return childAt.getId();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int findId(String str) {
|
|
|
|
ConstraintLayout constraintLayout = getParent() instanceof ConstraintLayout ? (ConstraintLayout) getParent() : null;
|
|
|
|
int i = 0;
|
|
|
|
if (isInEditMode() && constraintLayout != null) {
|
|
|
|
Object designInformation = constraintLayout.getDesignInformation(0, str);
|
|
|
|
if (designInformation instanceof Integer) {
|
|
|
|
i = ((Integer) designInformation).intValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == 0 && constraintLayout != null) {
|
|
|
|
i = findId(constraintLayout, str);
|
|
|
|
}
|
|
|
|
if (i == 0) {
|
|
|
|
try {
|
|
|
|
i = R.id.class.getField(str).getInt(null);
|
|
|
|
} catch (Exception unused) {
|
|
|
|
}
|
|
|
|
}
|
2021-08-09 22:50:01 +00:00
|
|
|
return i == 0 ? this.myContext.getResources().getIdentifier(str, ModelAuditLogEntry.CHANGE_KEY_ID, this.myContext.getPackageName()) : i;
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void addView(View view) {
|
|
|
|
if (view != this) {
|
|
|
|
if (view.getId() == -1) {
|
|
|
|
Log.e("ConstraintHelper", "Views added to a ConstraintHelper need to have an id");
|
|
|
|
} else if (view.getParent() == null) {
|
|
|
|
Log.e("ConstraintHelper", "Views added to a ConstraintHelper need to have a parent");
|
|
|
|
} else {
|
|
|
|
this.mReferenceIds = null;
|
|
|
|
addRscID(view.getId());
|
|
|
|
requestLayout();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void applyLayoutFeatures() {
|
|
|
|
ViewParent parent = getParent();
|
|
|
|
if (parent != null && (parent instanceof ConstraintLayout)) {
|
|
|
|
applyLayoutFeatures((ConstraintLayout) parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void applyLayoutFeatures(ConstraintLayout constraintLayout) {
|
|
|
|
int visibility = getVisibility();
|
|
|
|
float elevation = getElevation();
|
|
|
|
for (int i = 0; i < this.mCount; i++) {
|
|
|
|
View viewById = constraintLayout.getViewById(this.mIds[i]);
|
|
|
|
if (viewById != null) {
|
|
|
|
viewById.setVisibility(visibility);
|
|
|
|
if (elevation > 0.0f) {
|
|
|
|
viewById.setTranslationZ(viewById.getTranslationZ() + elevation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int[] getReferencedIds() {
|
|
|
|
return Arrays.copyOf(this.mIds, this.mCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
public View[] getViews(ConstraintLayout constraintLayout) {
|
|
|
|
View[] viewArr = this.mViews;
|
|
|
|
if (viewArr == null || viewArr.length != this.mCount) {
|
|
|
|
this.mViews = new View[this.mCount];
|
|
|
|
}
|
|
|
|
for (int i = 0; i < this.mCount; i++) {
|
|
|
|
this.mViews[i] = constraintLayout.getViewById(this.mIds[i]);
|
|
|
|
}
|
|
|
|
return this.mViews;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void init(AttributeSet attributeSet) {
|
|
|
|
if (attributeSet != null) {
|
|
|
|
TypedArray obtainStyledAttributes = getContext().obtainStyledAttributes(attributeSet, R.styleable.ConstraintLayout_Layout);
|
|
|
|
int indexCount = obtainStyledAttributes.getIndexCount();
|
|
|
|
for (int i = 0; i < indexCount; i++) {
|
|
|
|
int index = obtainStyledAttributes.getIndex(i);
|
|
|
|
if (index == R.styleable.ConstraintLayout_Layout_constraint_referenced_ids) {
|
|
|
|
String string = obtainStyledAttributes.getString(index);
|
|
|
|
this.mReferenceIds = string;
|
|
|
|
setIds(string);
|
|
|
|
} else if (index == R.styleable.ConstraintLayout_Layout_constraint_referenced_tags) {
|
|
|
|
String string2 = obtainStyledAttributes.getString(index);
|
|
|
|
this.mReferenceTags = string2;
|
|
|
|
setReferenceTags(string2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
obtainStyledAttributes.recycle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void loadParameters(ConstraintSet.Constraint constraint, HelperWidget helperWidget, ConstraintLayout.LayoutParams layoutParams, SparseArray<ConstraintWidget> sparseArray) {
|
|
|
|
ConstraintSet.Layout layout = constraint.layout;
|
|
|
|
int[] iArr = layout.mReferenceIds;
|
|
|
|
if (iArr != null) {
|
|
|
|
setReferencedIds(iArr);
|
|
|
|
} else {
|
|
|
|
String str = layout.mReferenceIdString;
|
|
|
|
if (str != null && str.length() > 0) {
|
|
|
|
ConstraintSet.Layout layout2 = constraint.layout;
|
|
|
|
layout2.mReferenceIds = convertReferenceString(this, layout2.mReferenceIdString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
helperWidget.removeAllIds();
|
|
|
|
if (constraint.layout.mReferenceIds != null) {
|
|
|
|
int i = 0;
|
|
|
|
while (true) {
|
|
|
|
int[] iArr2 = constraint.layout.mReferenceIds;
|
|
|
|
if (i < iArr2.length) {
|
|
|
|
ConstraintWidget constraintWidget = sparseArray.get(iArr2[i]);
|
|
|
|
if (constraintWidget != null) {
|
|
|
|
helperWidget.add(constraintWidget);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // android.view.View
|
|
|
|
public void onAttachedToWindow() {
|
|
|
|
super.onAttachedToWindow();
|
|
|
|
String str = this.mReferenceIds;
|
|
|
|
if (str != null) {
|
|
|
|
setIds(str);
|
|
|
|
}
|
|
|
|
String str2 = this.mReferenceTags;
|
|
|
|
if (str2 != null) {
|
|
|
|
setReferenceTags(str2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // android.view.View
|
|
|
|
public void onDraw(Canvas canvas) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // android.view.View
|
|
|
|
public void onMeasure(int i, int i2) {
|
|
|
|
if (this.mUseViewMeasure) {
|
|
|
|
super.onMeasure(i, i2);
|
|
|
|
} else {
|
|
|
|
setMeasuredDimension(0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void removeView(View view) {
|
|
|
|
int i;
|
|
|
|
int id2 = view.getId();
|
|
|
|
if (id2 != -1) {
|
|
|
|
this.mReferenceIds = null;
|
|
|
|
int i2 = 0;
|
|
|
|
while (true) {
|
|
|
|
if (i2 >= this.mCount) {
|
|
|
|
break;
|
|
|
|
} else if (this.mIds[i2] == id2) {
|
|
|
|
while (true) {
|
|
|
|
i = this.mCount;
|
|
|
|
if (i2 >= i - 1) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
int[] iArr = this.mIds;
|
|
|
|
int i3 = i2 + 1;
|
|
|
|
iArr[i2] = iArr[i3];
|
|
|
|
i2 = i3;
|
|
|
|
}
|
|
|
|
this.mIds[i - 1] = 0;
|
|
|
|
this.mCount = i - 1;
|
|
|
|
} else {
|
|
|
|
i2++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
requestLayout();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void resolveRtl(ConstraintWidget constraintWidget, boolean z2) {
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setIds(String str) {
|
|
|
|
this.mReferenceIds = str;
|
|
|
|
if (str != null) {
|
|
|
|
int i = 0;
|
|
|
|
this.mCount = 0;
|
|
|
|
while (true) {
|
|
|
|
int indexOf = str.indexOf(44, i);
|
|
|
|
if (indexOf == -1) {
|
|
|
|
addID(str.substring(i));
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
addID(str.substring(i, indexOf));
|
|
|
|
i = indexOf + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setReferenceTags(String str) {
|
|
|
|
this.mReferenceTags = str;
|
|
|
|
if (str != null) {
|
|
|
|
int i = 0;
|
|
|
|
this.mCount = 0;
|
|
|
|
while (true) {
|
|
|
|
int indexOf = str.indexOf(44, i);
|
|
|
|
if (indexOf == -1) {
|
|
|
|
addTag(str.substring(i));
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
addTag(str.substring(i, indexOf));
|
|
|
|
i = indexOf + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setReferencedIds(int[] iArr) {
|
|
|
|
this.mReferenceIds = null;
|
|
|
|
this.mCount = 0;
|
|
|
|
for (int i : iArr) {
|
|
|
|
addRscID(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // android.view.View
|
|
|
|
public void setTag(int i, Object obj) {
|
|
|
|
super.setTag(i, obj);
|
|
|
|
if (obj == null && this.mReferenceIds == null) {
|
|
|
|
addRscID(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updatePostConstraints(ConstraintLayout constraintLayout) {
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updatePostLayout(ConstraintLayout constraintLayout) {
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updatePostMeasure(ConstraintLayout constraintLayout) {
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updatePreDraw(ConstraintLayout constraintLayout) {
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updatePreLayout(ConstraintWidgetContainer constraintWidgetContainer, Helper helper, SparseArray<ConstraintWidget> sparseArray) {
|
|
|
|
helper.removeAllIds();
|
|
|
|
for (int i = 0; i < this.mCount; i++) {
|
|
|
|
helper.add(sparseArray.get(this.mIds[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updatePreLayout(ConstraintLayout constraintLayout) {
|
|
|
|
String str;
|
|
|
|
int findId;
|
|
|
|
if (isInEditMode()) {
|
|
|
|
setIds(this.mReferenceIds);
|
|
|
|
}
|
|
|
|
Helper helper = this.mHelperWidget;
|
|
|
|
if (helper != null) {
|
|
|
|
helper.removeAllIds();
|
|
|
|
for (int i = 0; i < this.mCount; i++) {
|
|
|
|
int i2 = this.mIds[i];
|
|
|
|
View viewById = constraintLayout.getViewById(i2);
|
|
|
|
if (viewById == null && (findId = findId(constraintLayout, (str = this.mMap.get(Integer.valueOf(i2))))) != 0) {
|
|
|
|
this.mIds[i] = findId;
|
|
|
|
this.mMap.put(Integer.valueOf(findId), str);
|
|
|
|
viewById = constraintLayout.getViewById(findId);
|
|
|
|
}
|
|
|
|
if (viewById != null) {
|
|
|
|
this.mHelperWidget.add(constraintLayout.getViewWidget(viewById));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.mHelperWidget.updateConstraints(constraintLayout.mLayoutWidget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void validateParams() {
|
|
|
|
if (this.mHelperWidget != null) {
|
|
|
|
ViewGroup.LayoutParams layoutParams = getLayoutParams();
|
|
|
|
if (layoutParams instanceof ConstraintLayout.LayoutParams) {
|
|
|
|
((ConstraintLayout.LayoutParams) layoutParams).widget = (ConstraintWidget) this.mHelperWidget;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|