discord-jadx/app/src/main/java/androidx/transition/ViewOverlayApi14.java

232 lines
8.7 KiB
Java

package androidx.transition;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import androidx.annotation.NonNull;
import androidx.annotation.RestrictTo;
import androidx.core.view.ViewCompat;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
public class ViewOverlayApi14 implements ViewOverlayImpl {
public OverlayViewGroup mOverlayViewGroup;
public static class OverlayViewGroup extends ViewGroup {
public static Method sInvalidateChildInParentFastMethod;
private boolean mDisposed;
public ArrayList<Drawable> mDrawables = null;
public ViewGroup mHostView;
public View mRequestingView;
public ViewOverlayApi14 mViewOverlay;
static {
try {
Class cls = Integer.TYPE;
sInvalidateChildInParentFastMethod = ViewGroup.class.getDeclaredMethod("invalidateChildInParentFast", cls, cls, Rect.class);
} catch (NoSuchMethodException unused) {
}
}
public OverlayViewGroup(Context context, ViewGroup viewGroup, View view, ViewOverlayApi14 viewOverlayApi14) {
super(context);
this.mHostView = viewGroup;
this.mRequestingView = view;
setRight(viewGroup.getWidth());
setBottom(viewGroup.getHeight());
viewGroup.addView(this);
this.mViewOverlay = viewOverlayApi14;
}
private void assertNotDisposed() {
if (this.mDisposed) {
throw new IllegalStateException("This overlay was disposed already. Please use a new one via ViewGroupUtils.getOverlay()");
}
}
private void disposeIfEmpty() {
if (getChildCount() == 0) {
ArrayList<Drawable> arrayList = this.mDrawables;
if (arrayList == null || arrayList.size() == 0) {
this.mDisposed = true;
this.mHostView.removeView(this);
}
}
}
private void getOffset(int[] iArr) {
int[] iArr2 = new int[2];
int[] iArr3 = new int[2];
this.mHostView.getLocationOnScreen(iArr2);
this.mRequestingView.getLocationOnScreen(iArr3);
iArr[0] = iArr3[0] - iArr2[0];
iArr[1] = iArr3[1] - iArr2[1];
}
public void add(Drawable drawable) {
assertNotDisposed();
if (this.mDrawables == null) {
this.mDrawables = new ArrayList<>();
}
if (!this.mDrawables.contains(drawable)) {
this.mDrawables.add(drawable);
invalidate(drawable.getBounds());
drawable.setCallback(this);
}
}
public void add(View view) {
assertNotDisposed();
if (view.getParent() instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) view.getParent();
if (!(viewGroup == this.mHostView || viewGroup.getParent() == null || !ViewCompat.isAttachedToWindow(viewGroup))) {
int[] iArr = new int[2];
int[] iArr2 = new int[2];
viewGroup.getLocationOnScreen(iArr);
this.mHostView.getLocationOnScreen(iArr2);
ViewCompat.offsetLeftAndRight(view, iArr[0] - iArr2[0]);
ViewCompat.offsetTopAndBottom(view, iArr[1] - iArr2[1]);
}
viewGroup.removeView(view);
if (view.getParent() != null) {
viewGroup.removeView(view);
}
}
super.addView(view);
}
@Override // android.view.ViewGroup, android.view.View
public void dispatchDraw(Canvas canvas) {
int[] iArr = new int[2];
int[] iArr2 = new int[2];
this.mHostView.getLocationOnScreen(iArr);
this.mRequestingView.getLocationOnScreen(iArr2);
canvas.translate((float) (iArr2[0] - iArr[0]), (float) (iArr2[1] - iArr[1]));
canvas.clipRect(new Rect(0, 0, this.mRequestingView.getWidth(), this.mRequestingView.getHeight()));
super.dispatchDraw(canvas);
ArrayList<Drawable> arrayList = this.mDrawables;
int size = arrayList == null ? 0 : arrayList.size();
for (int i = 0; i < size; i++) {
this.mDrawables.get(i).draw(canvas);
}
}
@Override // android.view.ViewGroup, android.view.View
public boolean dispatchTouchEvent(MotionEvent motionEvent) {
return false;
}
@Override // android.view.ViewGroup, android.view.ViewParent
public ViewParent invalidateChildInParent(int[] iArr, Rect rect) {
if (this.mHostView == null) {
return null;
}
rect.offset(iArr[0], iArr[1]);
if (this.mHostView instanceof ViewGroup) {
iArr[0] = 0;
iArr[1] = 0;
int[] iArr2 = new int[2];
getOffset(iArr2);
rect.offset(iArr2[0], iArr2[1]);
return super.invalidateChildInParent(iArr, rect);
}
invalidate(rect);
return null;
}
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
public ViewParent invalidateChildInParentFast(int i, int i2, Rect rect) {
if (!(this.mHostView instanceof ViewGroup) || sInvalidateChildInParentFastMethod == null) {
return null;
}
try {
getOffset(new int[2]);
sInvalidateChildInParentFastMethod.invoke(this.mHostView, Integer.valueOf(i), Integer.valueOf(i2), rect);
return null;
} catch (IllegalAccessException e) {
e.printStackTrace();
return null;
} catch (InvocationTargetException e2) {
e2.printStackTrace();
return null;
}
}
@Override // android.graphics.drawable.Drawable.Callback, android.view.View
public void invalidateDrawable(@NonNull Drawable drawable) {
invalidate(drawable.getBounds());
}
@Override // android.view.ViewGroup, android.view.View
public void onLayout(boolean z2, int i, int i2, int i3, int i4) {
}
public void remove(Drawable drawable) {
ArrayList<Drawable> arrayList = this.mDrawables;
if (arrayList != null) {
arrayList.remove(drawable);
invalidate(drawable.getBounds());
drawable.setCallback(null);
disposeIfEmpty();
}
}
public void remove(View view) {
super.removeView(view);
disposeIfEmpty();
}
@Override // android.view.View
public boolean verifyDrawable(@NonNull Drawable drawable) {
ArrayList<Drawable> arrayList;
return super.verifyDrawable(drawable) || ((arrayList = this.mDrawables) != null && arrayList.contains(drawable));
}
}
public ViewOverlayApi14(Context context, ViewGroup viewGroup, View view) {
this.mOverlayViewGroup = new OverlayViewGroup(context, viewGroup, view, this);
}
public static ViewOverlayApi14 createFrom(View view) {
ViewGroup contentView = getContentView(view);
if (contentView == null) {
return null;
}
int childCount = contentView.getChildCount();
for (int i = 0; i < childCount; i++) {
View childAt = contentView.getChildAt(i);
if (childAt instanceof OverlayViewGroup) {
return ((OverlayViewGroup) childAt).mViewOverlay;
}
}
return new ViewGroupOverlayApi14(contentView.getContext(), contentView, view);
}
public static ViewGroup getContentView(View view) {
while (view != null) {
if (view.getId() == 16908290 && (view instanceof ViewGroup)) {
return (ViewGroup) view;
}
if (view.getParent() instanceof ViewGroup) {
view = (ViewGroup) view.getParent();
}
}
return null;
}
@Override // androidx.transition.ViewOverlayImpl
public void add(@NonNull Drawable drawable) {
this.mOverlayViewGroup.add(drawable);
}
@Override // androidx.transition.ViewOverlayImpl
public void remove(@NonNull Drawable drawable) {
this.mOverlayViewGroup.remove(drawable);
}
}