package r3;

import android.animation.Animator;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Picture;
import android.graphics.RectF;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.HashMap;

/* JADX INFO: loaded from: classes.dex */
public abstract class y0 extends z {

    /* JADX INFO: renamed from: l0, reason: collision with root package name */
    public static final String[] f32442l0 = {"android:visibility:visibility", "android:visibility:parent"};

    /* JADX INFO: renamed from: k0, reason: collision with root package name */
    public int f32443k0 = 3;

    public static void H(k0 k0Var) {
        int visibility = k0Var.f32401b.getVisibility();
        HashMap map = k0Var.f32400a;
        map.put("android:visibility:visibility", Integer.valueOf(visibility));
        View view = k0Var.f32401b;
        map.put("android:visibility:parent", view.getParent());
        int[] iArr = new int[2];
        view.getLocationOnScreen(iArr);
        map.put("android:visibility:screenLocation", iArr);
    }

    /* JADX WARN: Removed duplicated region for block: B:12:0x0053  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0030  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static xyz.stream.api.q I(k0 k0Var, k0 k0Var2) {
        xyz.stream.api.q qVar = new xyz.stream.api.q(1);
        qVar.f35926a = false;
        qVar.f35927b = false;
        if (k0Var != null) {
            HashMap map = k0Var.f32400a;
            if (map.containsKey("android:visibility:visibility")) {
                qVar.f35928c = ((Integer) map.get("android:visibility:visibility")).intValue();
                qVar.f35930e = (ViewGroup) map.get("android:visibility:parent");
            } else {
                qVar.f35928c = -1;
                qVar.f35930e = null;
            }
        }
        if (k0Var2 != null) {
            HashMap map2 = k0Var2.f32400a;
            if (map2.containsKey("android:visibility:visibility")) {
                qVar.f35929d = ((Integer) map2.get("android:visibility:visibility")).intValue();
                qVar.f35931f = (ViewGroup) map2.get("android:visibility:parent");
            } else {
                qVar.f35929d = -1;
                qVar.f35931f = null;
            }
        }
        if (k0Var != null && k0Var2 != null) {
            int i10 = qVar.f35928c;
            int i11 = qVar.f35929d;
            if (i10 == i11 && ((ViewGroup) qVar.f35930e) == ((ViewGroup) qVar.f35931f)) {
                return qVar;
            }
            if (i10 != i11) {
                if (i10 == 0) {
                    qVar.f35927b = false;
                    qVar.f35926a = true;
                } else if (i11 == 0) {
                    qVar.f35927b = true;
                    qVar.f35926a = true;
                }
            } else if (((ViewGroup) qVar.f35931f) == null) {
                qVar.f35927b = false;
                qVar.f35926a = true;
            } else if (((ViewGroup) qVar.f35930e) == null) {
                qVar.f35927b = true;
                qVar.f35926a = true;
            }
        } else if (k0Var == null && qVar.f35929d == 0) {
            qVar.f35927b = true;
            qVar.f35926a = true;
        } else if (k0Var2 == null && qVar.f35928c == 0) {
            qVar.f35927b = false;
            qVar.f35926a = true;
        }
        return qVar;
    }

    @Override // r3.z
    @Nullable
    public Animator createAnimator(@NonNull ViewGroup viewGroup, @Nullable k0 k0Var, @Nullable k0 k0Var2) {
        xyz.stream.api.q qVarI = I(k0Var, k0Var2);
        if (!qVarI.f35926a) {
            return null;
        }
        if (((ViewGroup) qVarI.f35930e) == null && ((ViewGroup) qVarI.f35931f) == null) {
            return null;
        }
        return qVarI.f35927b ? onAppear(viewGroup, k0Var, qVarI.f35928c, k0Var2, qVarI.f35929d) : onDisappear(viewGroup, k0Var, qVarI.f35928c, k0Var2, qVarI.f35929d);
    }

    @Override // r3.z
    public final void d(k0 k0Var) {
        H(k0Var);
    }

    @Override // r3.z
    @Nullable
    public String[] getTransitionProperties() {
        return f32442l0;
    }

    @Override // r3.z
    public boolean isTransitionRequired(@Nullable k0 k0Var, @Nullable k0 k0Var2) {
        if (k0Var == null && k0Var2 == null) {
            return false;
        }
        if (k0Var != null && k0Var2 != null && k0Var2.f32400a.containsKey("android:visibility:visibility") != k0Var.f32400a.containsKey("android:visibility:visibility")) {
            return false;
        }
        xyz.stream.api.q qVarI = I(k0Var, k0Var2);
        if (qVarI.f35926a) {
            return qVarI.f35928c == 0 || qVarI.f35929d == 0;
        }
        return false;
    }

    public boolean isVisible(@Nullable k0 k0Var) {
        if (k0Var == null) {
            return false;
        }
        HashMap map = k0Var.f32400a;
        return ((Integer) map.get("android:visibility:visibility")).intValue() == 0 && ((View) map.get("android:visibility:parent")) != null;
    }

    @Nullable
    public Animator onAppear(@NonNull ViewGroup viewGroup, @NonNull View view, @Nullable k0 k0Var, @Nullable k0 k0Var2) {
        return null;
    }

    @Nullable
    public Animator onDisappear(@NonNull ViewGroup viewGroup, @NonNull View view, @Nullable k0 k0Var, @Nullable k0 k0Var2) {
        return null;
    }

    @Nullable
    public Animator onAppear(@NonNull ViewGroup viewGroup, @Nullable k0 k0Var, int i10, @Nullable k0 k0Var2, int i11) {
        if ((this.f32443k0 & 1) != 1 || k0Var2 == null) {
            return null;
        }
        View view = k0Var2.f32401b;
        if (k0Var == null) {
            View view2 = (View) view.getParent();
            if (I(o(view2, false), getTransitionValues(view2, false)).f35926a) {
                return null;
            }
        }
        return onAppear(viewGroup, view, k0Var, k0Var2);
    }

    /* JADX WARN: Removed duplicated region for block: B:56:0x0181  */
    /* JADX WARN: Removed duplicated region for block: B:69:0x01c1  */
    @Nullable
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Animator onDisappear(@NonNull ViewGroup viewGroup, @Nullable k0 k0Var, int i10, @Nullable k0 k0Var2, int i11) {
        View view;
        boolean z10;
        int i12;
        View view2;
        int i13;
        ViewGroup viewGroup2;
        Bitmap bitmapCreateBitmap;
        y0 y0Var = this;
        View view3 = null;
        if ((y0Var.f32443k0 & 2) != 2 || k0Var == null) {
            return null;
        }
        View view4 = k0Var2 != null ? k0Var2.f32401b : null;
        int i14 = o.save_overlay_view;
        View view5 = k0Var.f32401b;
        View view6 = (View) view5.getTag(i14);
        boolean z11 = true;
        if (view6 != null) {
            i12 = i14;
        } else {
            if (view4 == null || view4.getParent() == null) {
                if (view4 != null) {
                    view = null;
                    z10 = false;
                }
                view4 = null;
                view = null;
                z10 = true;
            } else {
                if (i11 == 4 || view5 == view4) {
                    view = view4;
                    view4 = null;
                    z10 = false;
                }
                view4 = null;
                view = null;
                z10 = true;
            }
            if (z10) {
                if (view5.getParent() == null) {
                    i12 = i14;
                    view2 = view;
                } else {
                    if (view5.getParent() instanceof View) {
                        View view7 = (View) view5.getParent();
                        if (I(y0Var.getTransitionValues(view7, true), y0Var.o(view7, true)).f35926a) {
                            i12 = i14;
                            view2 = view;
                            int id2 = view7.getId();
                            if (view7.getParent() != null || id2 == -1 || viewGroup.findViewById(id2) == null) {
                                y0Var = this;
                            } else {
                                y0Var = this;
                                if (y0Var.S) {
                                }
                                view3 = view2;
                                z11 = false;
                            }
                        } else {
                            boolean z12 = j0.f32398a;
                            Matrix matrix = new Matrix();
                            matrix.setTranslate(-view7.getScrollX(), -view7.getScrollY());
                            u0 u0Var = m0.f32403a;
                            u0Var.d(view5, matrix);
                            u0Var.e(viewGroup, matrix);
                            RectF rectF = new RectF(0.0f, 0.0f, view5.getWidth(), view5.getHeight());
                            matrix.mapRect(rectF);
                            int iRound = Math.round(rectF.left);
                            int iRound2 = Math.round(rectF.top);
                            int iRound3 = Math.round(rectF.right);
                            int iRound4 = Math.round(rectF.bottom);
                            ImageView imageView = new ImageView(view5.getContext());
                            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                            boolean z13 = !view5.isAttachedToWindow();
                            boolean z14 = viewGroup != null && viewGroup.isAttachedToWindow();
                            if (!z13) {
                                view2 = view;
                                i13 = 0;
                                viewGroup2 = null;
                            } else if (z14) {
                                view2 = view;
                                ViewGroup viewGroup3 = (ViewGroup) view5.getParent();
                                int iIndexOfChild = viewGroup3.indexOfChild(view5);
                                viewGroup.getOverlay().add(view5);
                                i13 = iIndexOfChild;
                                viewGroup2 = viewGroup3;
                            } else {
                                i12 = i14;
                                view2 = view;
                                bitmapCreateBitmap = null;
                                if (bitmapCreateBitmap != null) {
                                    imageView.setImageBitmap(bitmapCreateBitmap);
                                }
                                imageView.measure(View.MeasureSpec.makeMeasureSpec(iRound3 - iRound, 1073741824), View.MeasureSpec.makeMeasureSpec(iRound4 - iRound2, 1073741824));
                                imageView.layout(iRound, iRound2, iRound3, iRound4);
                                y0Var = this;
                                view6 = imageView;
                                view3 = view2;
                                z11 = false;
                            }
                            i12 = i14;
                            int iRound5 = Math.round(rectF.width());
                            int iRound6 = Math.round(rectF.height());
                            if (iRound5 <= 0 || iRound6 <= 0) {
                                bitmapCreateBitmap = null;
                            } else {
                                float fMin = Math.min(1.0f, 1048576.0f / (iRound5 * iRound6));
                                int iRound7 = Math.round(iRound5 * fMin);
                                int iRound8 = Math.round(iRound6 * fMin);
                                matrix.postTranslate(-rectF.left, -rectF.top);
                                matrix.postScale(fMin, fMin);
                                if (j0.f32398a) {
                                    Picture picture = new Picture();
                                    Canvas canvasBeginRecording = picture.beginRecording(iRound7, iRound8);
                                    canvasBeginRecording.concat(matrix);
                                    view5.draw(canvasBeginRecording);
                                    picture.endRecording();
                                    bitmapCreateBitmap = i0.a(picture);
                                } else {
                                    bitmapCreateBitmap = Bitmap.createBitmap(iRound7, iRound8, Bitmap.Config.ARGB_8888);
                                    Canvas canvas = new Canvas(bitmapCreateBitmap);
                                    canvas.concat(matrix);
                                    view5.draw(canvas);
                                }
                            }
                            if (z13) {
                                viewGroup.getOverlay().remove(view5);
                                viewGroup2.addView(view5, i13);
                            }
                            if (bitmapCreateBitmap != null) {
                            }
                            imageView.measure(View.MeasureSpec.makeMeasureSpec(iRound3 - iRound, 1073741824), View.MeasureSpec.makeMeasureSpec(iRound4 - iRound2, 1073741824));
                            imageView.layout(iRound, iRound2, iRound3, iRound4);
                            y0Var = this;
                            view6 = imageView;
                            view3 = view2;
                            z11 = false;
                        }
                    }
                    view6 = view4;
                    view3 = view2;
                    z11 = false;
                }
                view6 = view5;
                view3 = view2;
                z11 = false;
            } else {
                i12 = i14;
                view2 = view;
                view6 = view4;
                view3 = view2;
                z11 = false;
            }
        }
        if (view6 == null) {
            if (view3 == null) {
                return null;
            }
            int visibility = view3.getVisibility();
            m0.b(view3, 0);
            Animator animatorOnDisappear = y0Var.onDisappear(viewGroup, view3, k0Var, k0Var2);
            if (animatorOnDisappear != null) {
                w0 w0Var = new w0(view3, i11);
                animatorOnDisappear.addListener(w0Var);
                q().a(w0Var);
            } else {
                m0.b(view3, visibility);
            }
            return animatorOnDisappear;
        }
        if (!z11) {
            int[] iArr = (int[]) k0Var.f32400a.get("android:visibility:screenLocation");
            int i15 = iArr[0];
            int i16 = iArr[1];
            int[] iArr2 = new int[2];
            viewGroup.getLocationOnScreen(iArr2);
            view6.offsetLeftAndRight((i15 - iArr2[0]) - view6.getLeft());
            view6.offsetTopAndBottom((i16 - iArr2[1]) - view6.getTop());
            viewGroup.getOverlay().add(view6);
        }
        Animator animatorOnDisappear2 = y0Var.onDisappear(viewGroup, view6, k0Var, k0Var2);
        if (!z11) {
            if (animatorOnDisappear2 == null) {
                viewGroup.getOverlay().remove(view6);
            } else {
                view5.setTag(i12, view6);
                x0 x0Var = new x0(y0Var, viewGroup, view6, view5);
                animatorOnDisappear2.addListener(x0Var);
                animatorOnDisappear2.addPauseListener(x0Var);
                q().a(x0Var);
            }
        }
        return animatorOnDisappear2;
    }
}
