package ῲ.ῲ.㴹;

import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.Resources;
import android.graphics.Rect;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityManager;
import androidx.appcompat.R$dimen;
import ῲ.ᨨ.ᨨ.C1729;
import ῲ.ᨨ.ᨨ.C1739;

/* renamed from: ῲ.ῲ.㴹.ಯ  reason: contains not printable characters */
/* compiled from: TooltipCompatHandler */
public class View$OnLongClickListenerC2005 implements View.OnLongClickListener, View.OnHoverListener, View.OnAttachStateChangeListener {

    /* renamed from: ᕣ  reason: contains not printable characters */
    public static View$OnLongClickListenerC2005 f6808;

    /* renamed from: 㑃  reason: contains not printable characters */
    public static View$OnLongClickListenerC2005 f6809;

    /* renamed from: ʬ  reason: contains not printable characters */
    public final CharSequence f6810;

    /* renamed from: ඓ  reason: contains not printable characters */
    public final Runnable f6811 = new RunnableC2007();

    /* renamed from: ᨨ  reason: contains not printable characters */
    public C2011 f6812;

    /* renamed from: ῲ  reason: contains not printable characters */
    public final View f6813;

    /* renamed from: ⁱ  reason: contains not printable characters */
    public int f6814;

    /* renamed from: 㳳  reason: contains not printable characters */
    public boolean f6815;

    /* renamed from: 㴹  reason: contains not printable characters */
    public final Runnable f6816 = new RunnableC2006();

    /* renamed from: 㸾  reason: contains not printable characters */
    public final int f6817;

    /* renamed from: 㿎  reason: contains not printable characters */
    public int f6818;

    /* renamed from: ῲ.ῲ.㴹.ಯ$ῲ  reason: contains not printable characters */
    /* compiled from: TooltipCompatHandler */
    public class RunnableC2006 implements Runnable {
        public RunnableC2006() {
        }

        public void run() {
            View$OnLongClickListenerC2005.this.m5194();
        }
    }

    /* renamed from: ῲ.ῲ.㴹.ಯ$K  reason: contains not printable characters */
    /* compiled from: TooltipCompatHandler */
    public class RunnableC2007 implements Runnable {
        public RunnableC2007() {
        }

        public void run() {
            View$OnLongClickListenerC2005.this.m5196(false);
        }
    }

    public View$OnLongClickListenerC2005(View view, CharSequence charSequence) {
        this.f6813 = view;
        this.f6810 = charSequence;
        this.f6817 = C1739.m4539(ViewConfiguration.get(this.f6813.getContext()));
        m5195();
        this.f6813.setOnLongClickListener(this);
        this.f6813.setOnHoverListener(this);
    }

    public boolean onHover(View view, MotionEvent motionEvent) {
        boolean z;
        if (this.f6812 != null && this.f6815) {
            return false;
        }
        AccessibilityManager accessibilityManager = (AccessibilityManager) this.f6813.getContext().getSystemService("accessibility");
        if (accessibilityManager.isEnabled() && accessibilityManager.isTouchExplorationEnabled()) {
            return false;
        }
        int action = motionEvent.getAction();
        if (action != 7) {
            if (action == 10) {
                m5195();
                m5194();
            }
        } else if (this.f6813.isEnabled() && this.f6812 == null) {
            int x = (int) motionEvent.getX();
            int y = (int) motionEvent.getY();
            if (Math.abs(x - this.f6814) > this.f6817 || Math.abs(y - this.f6818) > this.f6817) {
                this.f6814 = x;
                this.f6818 = y;
                z = true;
            } else {
                z = false;
            }
            if (z) {
                m5193(this);
            }
        }
        return false;
    }

    public boolean onLongClick(View view) {
        this.f6814 = view.getWidth() / 2;
        this.f6818 = view.getHeight() / 2;
        m5196(true);
        return true;
    }

    public void onViewAttachedToWindow(View view) {
    }

    public void onViewDetachedFromWindow(View view) {
        m5194();
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public void m5194() {
        if (f6809 == this) {
            f6809 = null;
            C2011 r0 = this.f6812;
            if (r0 != null) {
                r0.m5201();
                this.f6812 = null;
                m5195();
                this.f6813.removeOnAttachStateChangeListener(this);
            } else {
                Log.e("TooltipCompatHandler", "sActiveHandler.mPopup == null");
            }
        }
        if (f6808 == this) {
            m5193((View$OnLongClickListenerC2005) null);
        }
        this.f6813.removeCallbacks(this.f6816);
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m5196(boolean z) {
        int i;
        int i2;
        long j;
        int i3;
        long j2;
        if (C1729.m4498(this.f6813)) {
            m5193((View$OnLongClickListenerC2005) null);
            View$OnLongClickListenerC2005 r1 = f6809;
            if (r1 != null) {
                r1.m5194();
            }
            f6809 = this;
            this.f6815 = z;
            this.f6812 = new C2011(this.f6813.getContext());
            C2011 r12 = this.f6812;
            View view = this.f6813;
            int i4 = this.f6814;
            int i5 = this.f6818;
            boolean z2 = this.f6815;
            CharSequence charSequence = this.f6810;
            if (r12.m5200()) {
                r12.m5201();
            }
            r12.f6828.setText(charSequence);
            WindowManager.LayoutParams layoutParams = r12.f6834;
            layoutParams.token = view.getApplicationWindowToken();
            int dimensionPixelOffset = r12.f6832.getResources().getDimensionPixelOffset(R$dimen.tooltip_precise_anchor_threshold);
            if (view.getWidth() < dimensionPixelOffset) {
                i4 = view.getWidth() / 2;
            }
            if (view.getHeight() >= dimensionPixelOffset) {
                int dimensionPixelOffset2 = r12.f6832.getResources().getDimensionPixelOffset(R$dimen.tooltip_precise_anchor_extra_offset);
                i = i5 + dimensionPixelOffset2;
                i2 = i5 - dimensionPixelOffset2;
            } else {
                i = view.getHeight();
                i2 = 0;
            }
            layoutParams.gravity = 49;
            int dimensionPixelOffset3 = r12.f6832.getResources().getDimensionPixelOffset(z2 ? R$dimen.tooltip_y_offset_touch : R$dimen.tooltip_y_offset_non_touch);
            View rootView = view.getRootView();
            ViewGroup.LayoutParams layoutParams2 = rootView.getLayoutParams();
            if (!(layoutParams2 instanceof WindowManager.LayoutParams) || ((WindowManager.LayoutParams) layoutParams2).type != 2) {
                Context context = view.getContext();
                while (true) {
                    if (!(context instanceof ContextWrapper)) {
                        break;
                    } else if (context instanceof Activity) {
                        rootView = ((Activity) context).getWindow().getDecorView();
                        break;
                    } else {
                        context = ((ContextWrapper) context).getBaseContext();
                    }
                }
            }
            if (rootView == null) {
                Log.e("TooltipPopup", "Cannot find app view");
            } else {
                rootView.getWindowVisibleDisplayFrame(r12.f6829);
                Rect rect = r12.f6829;
                if (rect.left < 0 && rect.top < 0) {
                    Resources resources = r12.f6832.getResources();
                    int identifier = resources.getIdentifier("status_bar_height", "dimen", "android");
                    int dimensionPixelSize = identifier != 0 ? resources.getDimensionPixelSize(identifier) : 0;
                    DisplayMetrics displayMetrics = resources.getDisplayMetrics();
                    r12.f6829.set(0, dimensionPixelSize, displayMetrics.widthPixels, displayMetrics.heightPixels);
                }
                rootView.getLocationOnScreen(r12.f6831);
                view.getLocationOnScreen(r12.f6833);
                int[] iArr = r12.f6833;
                int i6 = iArr[0];
                int[] iArr2 = r12.f6831;
                iArr[0] = i6 - iArr2[0];
                iArr[1] = iArr[1] - iArr2[1];
                layoutParams.x = (iArr[0] + i4) - (rootView.getWidth() / 2);
                int makeMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, 0);
                r12.f6830.measure(makeMeasureSpec, makeMeasureSpec);
                int measuredHeight = r12.f6830.getMeasuredHeight();
                int[] iArr3 = r12.f6833;
                int i7 = ((iArr3[1] + i2) - dimensionPixelOffset3) - measuredHeight;
                int i8 = iArr3[1] + i + dimensionPixelOffset3;
                if (z2) {
                    if (i7 >= 0) {
                        layoutParams.y = i7;
                    } else {
                        layoutParams.y = i8;
                    }
                } else if (measuredHeight + i8 <= r12.f6829.height()) {
                    layoutParams.y = i8;
                } else {
                    layoutParams.y = i7;
                }
            }
            ((WindowManager) r12.f6832.getSystemService("window")).addView(r12.f6830, r12.f6834);
            this.f6813.addOnAttachStateChangeListener(this);
            if (this.f6815) {
                j = 2500;
            } else {
                if ((C1729.m4452(this.f6813) & 1) == 1) {
                    j2 = 3000;
                    i3 = ViewConfiguration.getLongPressTimeout();
                } else {
                    j2 = 15000;
                    i3 = ViewConfiguration.getLongPressTimeout();
                }
                j = j2 - ((long) i3);
            }
            this.f6813.removeCallbacks(this.f6816);
            this.f6813.postDelayed(this.f6816, j);
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public static void m5193(View$OnLongClickListenerC2005 r3) {
        View$OnLongClickListenerC2005 r0 = f6808;
        if (r0 != null) {
            r0.f6813.removeCallbacks(r0.f6811);
        }
        f6808 = r3;
        View$OnLongClickListenerC2005 r32 = f6808;
        if (r32 != null) {
            r32.f6813.postDelayed(r32.f6811, (long) ViewConfiguration.getLongPressTimeout());
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public final void m5195() {
        this.f6814 = Integer.MAX_VALUE;
        this.f6818 = Integer.MAX_VALUE;
    }
}
