package o;

import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.Resources;
import android.graphics.Rect;
import android.os.Build;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.TextView;
import com.google.android.gms.common.R;
import java.lang.reflect.Method;
import java.util.WeakHashMap;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class Yf0 implements View.OnLongClickListener, View.OnHoverListener, View.OnAttachStateChangeListener {
    public static Yf0 v;
    public static Yf0 w;
    public final View l;
    public final CharSequence m;
    public final int n;

    /* renamed from: o, reason: collision with root package name */
    public final Xf0 f426o;
    public final Xf0 p;
    public int q;
    public int r;
    public Zf0 s;
    public boolean t;
    public boolean u;

    /* JADX WARN: Type inference failed for: r0v0, types: [o.Xf0] */
    /* JADX WARN: Type inference failed for: r0v1, types: [o.Xf0] */
    public Yf0(View view, CharSequence charSequence) {
        final int i = 0;
        this.f426o = new Runnable(this) { // from class: o.Xf0
            public final /* synthetic */ Yf0 m;

            {
                this.m = this;
            }

            @Override // java.lang.Runnable
            public final void run() throws Resources.NotFoundException {
                switch (i) {
                    case 0:
                        this.m.c(false);
                        break;
                    default:
                        this.m.a();
                        break;
                }
            }
        };
        final int i2 = 1;
        this.p = new Runnable(this) { // from class: o.Xf0
            public final /* synthetic */ Yf0 m;

            {
                this.m = this;
            }

            @Override // java.lang.Runnable
            public final void run() throws Resources.NotFoundException {
                switch (i2) {
                    case 0:
                        this.m.c(false);
                        break;
                    default:
                        this.m.a();
                        break;
                }
            }
        };
        this.l = view;
        this.m = charSequence;
        ViewConfiguration viewConfiguration = ViewConfiguration.get(view.getContext());
        Method method = Rj0.a;
        this.n = Build.VERSION.SDK_INT >= 28 ? AbstractC0094Dq.l(viewConfiguration) : viewConfiguration.getScaledTouchSlop() / 2;
        this.u = true;
        view.setOnLongClickListener(this);
        view.setOnHoverListener(this);
    }

    public static void b(Yf0 yf0) {
        Yf0 yf02 = v;
        if (yf02 != null) {
            yf02.l.removeCallbacks(yf02.f426o);
        }
        v = yf0;
        if (yf0 != null) {
            yf0.l.postDelayed(yf0.f426o, ViewConfiguration.getLongPressTimeout());
        }
    }

    public final void a() {
        Yf0 yf0 = w;
        View view = this.l;
        if (yf0 == this) {
            w = null;
            Zf0 zf0 = this.s;
            if (zf0 != null) {
                View view2 = (View) zf0.b;
                if (view2.getParent() != null) {
                    ((WindowManager) ((Context) zf0.a).getSystemService("window")).removeView(view2);
                }
                this.s = null;
                this.u = true;
                view.removeOnAttachStateChangeListener(this);
            }
        }
        if (v == this) {
            b(null);
        }
        view.removeCallbacks(this.p);
    }

    public final void c(boolean z) throws Resources.NotFoundException {
        int height;
        int i;
        int i2;
        boolean z2;
        int i3;
        int i4;
        long longPressTimeout;
        long j;
        long j2;
        View view = this.l;
        if (view.isAttachedToWindow()) {
            b(null);
            Yf0 yf0 = w;
            if (yf0 != null) {
                yf0.a();
            }
            w = this;
            this.t = z;
            Zf0 zf0 = new Zf0(view.getContext());
            View view2 = (View) zf0.b;
            Context context = (Context) zf0.a;
            this.s = zf0;
            int width = this.q;
            int i5 = this.r;
            boolean z3 = this.t;
            WindowManager.LayoutParams layoutParams = (WindowManager.LayoutParams) zf0.d;
            if (view2.getParent() != null && view2.getParent() != null) {
                ((WindowManager) context.getSystemService("window")).removeView(view2);
            }
            ((TextView) zf0.c).setText(this.m);
            int[] iArr = (int[]) zf0.g;
            int[] iArr2 = (int[]) zf0.f;
            Rect rect = (Rect) zf0.e;
            layoutParams.token = view.getApplicationWindowToken();
            int dimensionPixelOffset = context.getResources().getDimensionPixelOffset(R.dimen.tooltip_precise_anchor_threshold);
            if (view.getWidth() < dimensionPixelOffset) {
                width = view.getWidth() / 2;
            }
            if (view.getHeight() >= dimensionPixelOffset) {
                int dimensionPixelOffset2 = context.getResources().getDimensionPixelOffset(R.dimen.tooltip_precise_anchor_extra_offset);
                height = i5 + dimensionPixelOffset2;
                i = i5 - dimensionPixelOffset2;
            } else {
                height = view.getHeight();
                i = 0;
            }
            layoutParams.gravity = 49;
            int dimensionPixelOffset3 = context.getResources().getDimensionPixelOffset(z3 ? R.dimen.tooltip_y_offset_touch : R.dimen.tooltip_y_offset_non_touch);
            View rootView = view.getRootView();
            ViewGroup.LayoutParams layoutParams2 = rootView.getLayoutParams();
            int i6 = width;
            if (!(layoutParams2 instanceof WindowManager.LayoutParams) || ((WindowManager.LayoutParams) layoutParams2).type != 2) {
                Context context2 = view.getContext();
                while (true) {
                    if (!(context2 instanceof ContextWrapper)) {
                        break;
                    }
                    if (context2 instanceof Activity) {
                        rootView = ((Activity) context2).getWindow().getDecorView();
                        break;
                    }
                    context2 = ((ContextWrapper) context2).getBaseContext();
                }
            }
            if (rootView == null) {
                i4 = 1;
            } else {
                rootView.getWindowVisibleDisplayFrame(rect);
                if (rect.left >= 0 || rect.top >= 0) {
                    i2 = i;
                    z2 = z3;
                    i3 = 0;
                    i4 = 1;
                } else {
                    Resources resources = context.getResources();
                    i4 = 1;
                    i2 = i;
                    z2 = z3;
                    int identifier = resources.getIdentifier("status_bar_height", "dimen", "android");
                    int dimensionPixelSize = identifier != 0 ? resources.getDimensionPixelSize(identifier) : 0;
                    DisplayMetrics displayMetrics = resources.getDisplayMetrics();
                    i3 = 0;
                    rect.set(0, dimensionPixelSize, displayMetrics.widthPixels, displayMetrics.heightPixels);
                }
                rootView.getLocationOnScreen(iArr);
                view.getLocationOnScreen(iArr2);
                int i7 = iArr2[i3] - iArr[i3];
                iArr2[i3] = i7;
                iArr2[i4] = iArr2[i4] - iArr[i4];
                layoutParams.x = (i7 + i6) - (rootView.getWidth() / 2);
                int iMakeMeasureSpec = View.MeasureSpec.makeMeasureSpec(i3, i3);
                view2.measure(iMakeMeasureSpec, iMakeMeasureSpec);
                int measuredHeight = view2.getMeasuredHeight();
                int i8 = iArr2[i4];
                int i9 = ((i8 + i2) - dimensionPixelOffset3) - measuredHeight;
                int i10 = i8 + height + dimensionPixelOffset3;
                if (z2) {
                    if (i9 >= 0) {
                        layoutParams.y = i9;
                    } else {
                        layoutParams.y = i10;
                    }
                } else if (measuredHeight + i10 <= rect.height()) {
                    layoutParams.y = i10;
                } else {
                    layoutParams.y = i9;
                }
            }
            ((WindowManager) context.getSystemService("window")).addView(view2, layoutParams);
            view.addOnAttachStateChangeListener(this);
            if (this.t) {
                j2 = 2500;
            } else {
                WeakHashMap weakHashMap = Oj0.a;
                if ((view.getWindowSystemUiVisibility() & 1) == i4) {
                    longPressTimeout = ViewConfiguration.getLongPressTimeout();
                    j = 3000;
                } else {
                    longPressTimeout = ViewConfiguration.getLongPressTimeout();
                    j = 15000;
                }
                j2 = j - longPressTimeout;
            }
            Xf0 xf0 = this.p;
            view.removeCallbacks(xf0);
            view.postDelayed(xf0, j2);
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:29:0x0066  */
    @Override // android.view.View.OnHoverListener
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final boolean onHover(android.view.View r4, android.view.MotionEvent r5) {
        /*
            r3 = this;
            o.Zf0 r4 = r3.s
            r0 = 0
            if (r4 == 0) goto La
            boolean r4 = r3.t
            if (r4 == 0) goto La
            goto L6f
        La:
            android.view.View r4 = r3.l
            android.content.Context r1 = r4.getContext()
            java.lang.String r2 = "accessibility"
            java.lang.Object r1 = r1.getSystemService(r2)
            android.view.accessibility.AccessibilityManager r1 = (android.view.accessibility.AccessibilityManager) r1
            boolean r2 = r1.isEnabled()
            if (r2 == 0) goto L25
            boolean r1 = r1.isTouchExplorationEnabled()
            if (r1 == 0) goto L25
            goto L6f
        L25:
            int r1 = r5.getAction()
            r2 = 7
            if (r1 == r2) goto L38
            r4 = 10
            if (r1 == r4) goto L31
            goto L6f
        L31:
            r4 = 1
            r3.u = r4
            r3.a()
            return r0
        L38:
            boolean r4 = r4.isEnabled()
            if (r4 == 0) goto L6f
            o.Zf0 r4 = r3.s
            if (r4 != 0) goto L6f
            float r4 = r5.getX()
            int r4 = (int) r4
            float r5 = r5.getY()
            int r5 = (int) r5
            boolean r1 = r3.u
            if (r1 != 0) goto L66
            int r1 = r3.q
            int r1 = r4 - r1
            int r1 = java.lang.Math.abs(r1)
            int r2 = r3.n
            if (r1 > r2) goto L66
            int r1 = r3.r
            int r1 = r5 - r1
            int r1 = java.lang.Math.abs(r1)
            if (r1 <= r2) goto L6f
        L66:
            r3.q = r4
            r3.r = r5
            r3.u = r0
            b(r3)
        L6f:
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: o.Yf0.onHover(android.view.View, android.view.MotionEvent):boolean");
    }

    @Override // android.view.View.OnLongClickListener
    public final boolean onLongClick(View view) throws Resources.NotFoundException {
        this.q = view.getWidth() / 2;
        this.r = view.getHeight() / 2;
        c(true);
        return true;
    }

    @Override // android.view.View.OnAttachStateChangeListener
    public final void onViewDetachedFromWindow(View view) {
        a();
    }

    @Override // android.view.View.OnAttachStateChangeListener
    public final void onViewAttachedToWindow(View view) {
    }
}
