package p7;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.PointF;
import android.net.Uri;
import android.os.Handler;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.ViewConfiguration;
import android.view.WindowManager;
import androidx.annotation.Nullable;
import com.google.android.gms.internal.ads.a30;
import com.google.android.gms.internal.ads.ao;
import com.google.android.gms.internal.ads.b30;
import com.google.android.gms.internal.ads.dv1;
import com.google.android.gms.internal.ads.ps0;
import com.google.android.gms.internal.ads.zzebb;
import java.util.ArrayList;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/* JADX INFO: loaded from: classes2.dex */
public final class i {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Context f31683a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final ps0 f31684b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public String f31685c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public String f31686d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public String f31687e;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final int f31689g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public PointF f31690h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public PointF f31691i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final Handler f31692j;

    @Nullable
    private String zzf;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public int f31688f = 0;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final c f31693k = new c(this, 6);

    public i(Context context) {
        this.f31683a = context;
        this.f31689g = ViewConfiguration.get(context).getScaledTouchSlop();
        m7.n nVar = m7.n.C;
        nVar.f30481t.e();
        this.f31692j = (Handler) nVar.f30481t.f913d;
        this.f31684b = nVar.f30476o.f31721g;
    }

    public static final int g(String str, ArrayList arrayList, boolean z10) {
        if (!z10) {
            return -1;
        }
        arrayList.add(str);
        return arrayList.size() - 1;
    }

    public final void a(MotionEvent motionEvent) {
        int actionMasked = motionEvent.getActionMasked();
        int historySize = motionEvent.getHistorySize();
        int pointerCount = motionEvent.getPointerCount();
        if (actionMasked == 0) {
            this.f31688f = 0;
            this.f31690h = new PointF(motionEvent.getX(0), motionEvent.getY(0));
            return;
        }
        int i10 = this.f31688f;
        if (i10 == -1) {
            return;
        }
        c cVar = this.f31693k;
        Handler handler = this.f31692j;
        if (i10 == 0) {
            if (actionMasked == 5) {
                this.f31688f = 5;
                this.f31691i = new PointF(motionEvent.getX(1), motionEvent.getY(1));
                handler.postDelayed(cVar, ((Long) n7.y.f31093e.f31096c.b(ao.H5)).longValue());
                return;
            }
            return;
        }
        if (i10 == 5) {
            if (pointerCount == 2) {
                if (actionMasked != 2) {
                    return;
                }
                boolean z10 = false;
                for (int i11 = 0; i11 < historySize; i11++) {
                    z10 |= !e(motionEvent.getHistoricalX(0, i11), motionEvent.getHistoricalY(0, i11), motionEvent.getHistoricalX(1, i11), motionEvent.getHistoricalY(1, i11));
                }
                if (e(motionEvent.getX(), motionEvent.getY(), motionEvent.getX(1), motionEvent.getY(1)) && !z10) {
                    return;
                }
            }
            this.f31688f = -1;
            handler.removeCallbacks(cVar);
        }
    }

    public final void b() {
        String str;
        try {
            Context context = this.f31683a;
            if (!(context instanceof Activity)) {
                q7.j.c("Can not create dialog without Activity Context");
                return;
            }
            m7.n nVar = m7.n.C;
            l lVar = nVar.f30476o;
            synchronized (lVar.f31715a) {
                str = lVar.f31717c;
            }
            String str2 = "Creative preview (enabled)";
            if (true == TextUtils.isEmpty(str)) {
                str2 = "Creative preview";
            }
            String str3 = true != nVar.f30476o.h() ? "Troubleshooting" : "Troubleshooting (enabled)";
            ArrayList arrayList = new ArrayList();
            final int iG = g("Ad information", arrayList, true);
            final int iG2 = g(str2, arrayList, true);
            final int iG3 = g(str3, arrayList, true);
            boolean zBooleanValue = ((Boolean) n7.y.f31093e.f31096c.b(ao.f9104ua)).booleanValue();
            final int iG4 = g("Open ad inspector", arrayList, zBooleanValue);
            final int iG5 = g("Ad inspector settings", arrayList, zBooleanValue);
            AlertDialog.Builder builderJ = r0.j(context);
            builderJ.setTitle("Select a debug mode").setItems((CharSequence[]) arrayList.toArray(new String[0]), new DialogInterface.OnClickListener() { // from class: p7.b
                @Override // android.content.DialogInterface.OnClickListener
                public final void onClick(DialogInterface dialogInterface, int i10) {
                    final i iVar = this.f31647a;
                    iVar.getClass();
                    if (i10 != iG) {
                        final int i11 = 1;
                        if (i10 == iG2) {
                            q7.j.a("Debug mode [Creative Preview] selected.");
                            b30.f9359a.execute(new c(iVar, i11));
                            return;
                        }
                        if (i10 == iG3) {
                            q7.j.a("Debug mode [Troubleshooting] selected.");
                            b30.f9359a.execute(new c(iVar, 2));
                            return;
                        }
                        int i12 = iG4;
                        final int i13 = 0;
                        ps0 ps0Var = iVar.f31684b;
                        if (i10 == i12) {
                            final a30 a30Var = b30.f9364f;
                            a30 a30Var2 = b30.f9359a;
                            if (ps0Var.f()) {
                                a30Var.execute(new c(iVar, 5));
                                return;
                            } else {
                                a30Var2.execute(new Runnable() { // from class: p7.h
                                    @Override // java.lang.Runnable
                                    public final void run() {
                                        int i14 = i13;
                                        dv1 dv1Var = a30Var;
                                        i iVar2 = iVar;
                                        switch (i14) {
                                            case 0:
                                                iVar2.getClass();
                                                m7.n nVar2 = m7.n.C;
                                                l lVar2 = nVar2.f30476o;
                                                String str4 = iVar2.f31686d;
                                                String str5 = iVar2.f31687e;
                                                Context context2 = iVar2.f31683a;
                                                if (!lVar2.b(context2, str4, str5)) {
                                                    nVar2.f30476o.c(context2, iVar2.f31686d, iVar2.f31687e);
                                                } else {
                                                    ((a30) dv1Var).execute(new c(iVar2, 4));
                                                }
                                                break;
                                            default:
                                                iVar2.getClass();
                                                m7.n nVar3 = m7.n.C;
                                                l lVar3 = nVar3.f30476o;
                                                String str6 = iVar2.f31686d;
                                                String str7 = iVar2.f31687e;
                                                Context context3 = iVar2.f31683a;
                                                if (!lVar3.b(context3, str6, str7)) {
                                                    nVar3.f30476o.c(context3, iVar2.f31686d, iVar2.f31687e);
                                                } else {
                                                    ((a30) dv1Var).execute(new c(iVar2, 3));
                                                }
                                                break;
                                        }
                                    }
                                });
                                return;
                            }
                        }
                        if (i10 == iG5) {
                            final a30 a30Var3 = b30.f9364f;
                            a30 a30Var4 = b30.f9359a;
                            if (ps0Var.f()) {
                                a30Var3.execute(new c(iVar, i13));
                                return;
                            } else {
                                a30Var4.execute(new Runnable() { // from class: p7.h
                                    @Override // java.lang.Runnable
                                    public final void run() {
                                        int i14 = i11;
                                        dv1 dv1Var = a30Var3;
                                        i iVar2 = iVar;
                                        switch (i14) {
                                            case 0:
                                                iVar2.getClass();
                                                m7.n nVar2 = m7.n.C;
                                                l lVar2 = nVar2.f30476o;
                                                String str4 = iVar2.f31686d;
                                                String str5 = iVar2.f31687e;
                                                Context context2 = iVar2.f31683a;
                                                if (!lVar2.b(context2, str4, str5)) {
                                                    nVar2.f30476o.c(context2, iVar2.f31686d, iVar2.f31687e);
                                                } else {
                                                    ((a30) dv1Var).execute(new c(iVar2, 4));
                                                }
                                                break;
                                            default:
                                                iVar2.getClass();
                                                m7.n nVar3 = m7.n.C;
                                                l lVar3 = nVar3.f30476o;
                                                String str6 = iVar2.f31686d;
                                                String str7 = iVar2.f31687e;
                                                Context context3 = iVar2.f31683a;
                                                if (!lVar3.b(context3, str6, str7)) {
                                                    nVar3.f30476o.c(context3, iVar2.f31686d, iVar2.f31687e);
                                                } else {
                                                    ((a30) dv1Var).execute(new c(iVar2, 3));
                                                }
                                                break;
                                        }
                                    }
                                });
                                return;
                            }
                        }
                        return;
                    }
                    Context context2 = iVar.f31683a;
                    if (!(context2 instanceof Activity)) {
                        q7.j.c("Can not create dialog without Activity Context");
                        return;
                    }
                    String str4 = iVar.f31685c;
                    final String str5 = "No debug information";
                    if (!TextUtils.isEmpty(str4)) {
                        Uri uriBuild = new Uri.Builder().encodedQuery(str4.replaceAll("\\+", "%20")).build();
                        StringBuilder sb = new StringBuilder();
                        r0 r0Var = m7.n.C.f30464c;
                        Map mapZzV = r0.zzV(uriBuild);
                        for (String str6 : mapZzV.keySet()) {
                            sb.append(str6);
                            sb.append(" = ");
                            sb.append((String) mapZzV.get(str6));
                            sb.append("\n\n");
                        }
                        String strTrim = sb.toString().trim();
                        if (!TextUtils.isEmpty(strTrim)) {
                            str5 = strTrim;
                        }
                    }
                    r0 r0Var2 = m7.n.C.f30464c;
                    AlertDialog.Builder builderJ2 = r0.j(context2);
                    builderJ2.setMessage(str5);
                    builderJ2.setTitle("Ad Information");
                    builderJ2.setPositiveButton("Share", new DialogInterface.OnClickListener() { // from class: p7.f
                        @Override // android.content.DialogInterface.OnClickListener
                        public final void onClick(DialogInterface dialogInterface2, int i14) {
                            i iVar2 = iVar;
                            iVar2.getClass();
                            r0 r0Var3 = m7.n.C.f30464c;
                            r0.q(iVar2.f31683a, Intent.createChooser(new Intent("android.intent.action.SEND").setType("text/plain").putExtra("android.intent.extra.TEXT", str5), "Share via"));
                        }
                    });
                    builderJ2.setNegativeButton("Close", g.f31674a);
                    builderJ2.create().show();
                }
            });
            builderJ.create().show();
        } catch (WindowManager.BadTokenException unused) {
            l0.h();
        }
    }

    public final void c(String str) {
        this.zzf = str;
    }

    public final void d() {
        l lVar = m7.n.C.f30476o;
        String str = this.f31686d;
        String str2 = this.f31687e;
        String str3 = this.zzf;
        boolean zH = lVar.h();
        Context context = this.f31683a;
        boolean zB = lVar.b(context, str, str2);
        synchronized (lVar.f31715a) {
            lVar.f31718d = zB;
        }
        if (!lVar.h()) {
            lVar.c(context, str, str2);
            return;
        }
        if (!zH && !TextUtils.isEmpty(str3)) {
            lVar.e(context, str2, str3, str);
        }
        q7.j.a("Device is linked for debug signals.");
        lVar.i("The device is successfully linked for troubleshooting.", context, false, true);
    }

    public final boolean e(float f10, float f11, float f12, float f13) {
        float fAbs = Math.abs(this.f31690h.x - f10);
        int i10 = this.f31689g;
        return fAbs < ((float) i10) && Math.abs(this.f31690h.y - f11) < ((float) i10) && Math.abs(this.f31691i.x - f12) < ((float) i10) && Math.abs(this.f31691i.y - f13) < ((float) i10);
    }

    public final void f(Context context) {
        ArrayList arrayList = new ArrayList();
        int i10 = 1;
        int iG = g("None", arrayList, true);
        final int iG2 = g("Shake", arrayList, true);
        final int iG3 = g("Flick", arrayList, true);
        int iOrdinal = this.f31684b.f15519r.ordinal();
        int i11 = 2;
        final int i12 = iOrdinal != 1 ? iOrdinal != 2 ? iG : iG3 : iG2;
        r0 r0Var = m7.n.C.f30464c;
        AlertDialog.Builder builderJ = r0.j(context);
        final AtomicInteger atomicInteger = new AtomicInteger(i12);
        builderJ.setTitle("Setup gesture");
        builderJ.setSingleChoiceItems((CharSequence[]) arrayList.toArray(new String[0]), i12, new a3.i(atomicInteger, i10));
        builderJ.setNegativeButton("Dismiss", new a3.i(this, i11));
        builderJ.setPositiveButton("Save", new DialogInterface.OnClickListener() { // from class: p7.d
            @Override // android.content.DialogInterface.OnClickListener
            public final void onClick(DialogInterface dialogInterface, int i13) {
                i iVar = this.f31660a;
                iVar.getClass();
                AtomicInteger atomicInteger2 = atomicInteger;
                if (atomicInteger2.get() != i12) {
                    int i14 = atomicInteger2.get();
                    int i15 = iG2;
                    ps0 ps0Var = iVar.f31684b;
                    if (i14 == i15) {
                        ps0Var.h(zzebb.f19663b, true);
                    } else if (atomicInteger2.get() == iG3) {
                        ps0Var.h(zzebb.f19664c, true);
                    } else {
                        ps0Var.h(zzebb.f19662a, true);
                    }
                }
                iVar.b();
            }
        });
        builderJ.setOnCancelListener(new DialogInterface.OnCancelListener() { // from class: p7.e
            @Override // android.content.DialogInterface.OnCancelListener
            public final /* synthetic */ void onCancel(DialogInterface dialogInterface) {
                this.f31666a.b();
            }
        });
        builderJ.create().show();
    }

    public final String toString() {
        StringBuilder sb = new StringBuilder(100);
        sb.append("{Dialog: ");
        sb.append(this.f31685c);
        sb.append(",DebugSignal: ");
        sb.append(this.zzf);
        sb.append(",AFMA Version: ");
        sb.append(this.f31687e);
        sb.append(",Ad Unit ID: ");
        return defpackage.e.o(sb, this.f31686d, "}");
    }
}
