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.core.view.ViewCompat; import java.util.ArrayList; /* loaded from: classes.dex */ class ViewOverlayApi14 implements ViewOverlayImpl { protected OverlayViewGroup a; ViewOverlayApi14(Context context, ViewGroup viewGroup, View view) { this.a = new OverlayViewGroup(context, viewGroup, view, this); } static ViewOverlayApi14 c(View view) { ViewGroup d = d(view); if (d == null) { return null; } int childCount = d.getChildCount(); for (int i = 0; i < childCount; i++) { View childAt = d.getChildAt(i); if (childAt instanceof OverlayViewGroup) { return ((OverlayViewGroup) childAt).d; } } return new ViewGroupOverlayApi14(d.getContext(), d, view); } static ViewGroup d(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 a(Drawable drawable) { this.a.a(drawable); } @Override // androidx.transition.ViewOverlayImpl public void b(Drawable drawable) { this.a.b(drawable); } static class OverlayViewGroup extends ViewGroup { ViewGroup a; View b; ArrayList c; ViewOverlayApi14 d; static { try { ViewGroup.class.getDeclaredMethod("invalidateChildInParentFast", Integer.TYPE, Integer.TYPE, Rect.class); } catch (NoSuchMethodException unused) { } } OverlayViewGroup(Context context, ViewGroup viewGroup, View view, ViewOverlayApi14 viewOverlayApi14) { super(context); this.c = null; this.a = viewGroup; this.b = view; setRight(viewGroup.getWidth()); setBottom(viewGroup.getHeight()); viewGroup.addView(this); this.d = viewOverlayApi14; } public void a(Drawable drawable) { if (this.c == null) { this.c = new ArrayList<>(); } if (this.c.contains(drawable)) { return; } this.c.add(drawable); invalidate(drawable.getBounds()); drawable.setCallback(this); } public void b(Drawable drawable) { ArrayList arrayList = this.c; if (arrayList != null) { arrayList.remove(drawable); invalidate(drawable.getBounds()); drawable.setCallback(null); } } @Override // android.view.ViewGroup, android.view.View protected void dispatchDraw(Canvas canvas) { this.a.getLocationOnScreen(new int[2]); this.b.getLocationOnScreen(new int[2]); canvas.translate(r0[0] - r1[0], r0[1] - r1[1]); canvas.clipRect(new Rect(0, 0, this.b.getWidth(), this.b.getHeight())); super.dispatchDraw(canvas); ArrayList arrayList = this.c; int size = arrayList == null ? 0 : arrayList.size(); for (int i = 0; i < size; i++) { this.c.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.a == null) { return null; } rect.offset(iArr[0], iArr[1]); if (!(this.a instanceof ViewGroup)) { invalidate(rect); return null; } iArr[0] = 0; iArr[1] = 0; int[] iArr2 = new int[2]; a(iArr2); rect.offset(iArr2[0], iArr2[1]); return super.invalidateChildInParent(iArr, rect); } @Override // android.view.View, android.graphics.drawable.Drawable.Callback public void invalidateDrawable(Drawable drawable) { invalidate(drawable.getBounds()); } @Override // android.view.ViewGroup, android.view.View protected void onLayout(boolean z, int i, int i2, int i3, int i4) { } @Override // android.view.View protected boolean verifyDrawable(Drawable drawable) { ArrayList arrayList; return super.verifyDrawable(drawable) || ((arrayList = this.c) != null && arrayList.contains(drawable)); } public void b(View view) { super.removeView(view); if (a()) { this.a.removeView(this); } } public void a(View view) { if (view.getParent() instanceof ViewGroup) { ViewGroup viewGroup = (ViewGroup) view.getParent(); if (viewGroup != this.a && viewGroup.getParent() != null && ViewCompat.w(viewGroup)) { int[] iArr = new int[2]; int[] iArr2 = new int[2]; viewGroup.getLocationOnScreen(iArr); this.a.getLocationOnScreen(iArr2); ViewCompat.c(view, iArr[0] - iArr2[0]); ViewCompat.d(view, iArr[1] - iArr2[1]); } viewGroup.removeView(view); if (view.getParent() != null) { viewGroup.removeView(view); } } super.addView(view, getChildCount() - 1); } boolean a() { ArrayList arrayList; return getChildCount() == 0 && ((arrayList = this.c) == null || arrayList.size() == 0); } private void a(int[] iArr) { int[] iArr2 = new int[2]; int[] iArr3 = new int[2]; this.a.getLocationOnScreen(iArr2); this.b.getLocationOnScreen(iArr3); iArr[0] = iArr3[0] - iArr2[0]; iArr[1] = iArr3[1] - iArr2[1]; } } }