package c.a.f.d;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Rect;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;
import c.a.f.d.k;
import c.a.g.b0;
import c.a.g.u;
import com.ifpdos.multiuser.R;
import java.util.Objects;

/* JADX INFO: loaded from: classes.dex */
public final class o extends i implements PopupWindow.OnDismissListener, AdapterView.OnItemClickListener, k, View.OnKeyListener {

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final f f4900d;

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final boolean f4902f;

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

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

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

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final b0 f4906j;
    public PopupWindow.OnDismissListener m;
    public View n;
    public View o;
    public k.a p;
    public ViewTreeObserver q;
    public boolean r;
    public boolean s;
    public int t;
    public boolean v;
    public final ViewTreeObserver.OnGlobalLayoutListener k = new a();
    public final View.OnAttachStateChangeListener l = new b();
    public int u = 0;

    public class a implements ViewTreeObserver.OnGlobalLayoutListener {
        public a() {
        }

        @Override // android.view.ViewTreeObserver.OnGlobalLayoutListener
        public void onGlobalLayout() {
            if (o.this.j()) {
                o oVar = o.this;
                if (oVar.f4906j.B) {
                    return;
                }
                View view = oVar.o;
                if (view == null || !view.isShown()) {
                    o.this.d();
                } else {
                    o.this.f4906j.b();
                }
            }
        }
    }

    public class b implements View.OnAttachStateChangeListener {
        public b() {
        }

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

        @Override // android.view.View.OnAttachStateChangeListener
        public void onViewDetachedFromWindow(View view) {
            ViewTreeObserver viewTreeObserver = o.this.q;
            if (viewTreeObserver != null) {
                if (!viewTreeObserver.isAlive()) {
                    o.this.q = view.getViewTreeObserver();
                }
                o oVar = o.this;
                oVar.q.removeGlobalOnLayoutListener(oVar.k);
            }
            view.removeOnAttachStateChangeListener(this);
        }
    }

    public o(Context context, f fVar, View view, int i2, int i3, boolean z) {
        this.f4899c = context;
        this.f4900d = fVar;
        this.f4902f = z;
        this.f4901e = new e(fVar, LayoutInflater.from(context), z, R.layout.abc_popup_menu_item_layout);
        this.f4904h = i2;
        this.f4905i = i3;
        Resources resources = context.getResources();
        this.f4903g = Math.max(resources.getDisplayMetrics().widthPixels / 2, resources.getDimensionPixelSize(R.dimen.abc_config_prefDialogWidth));
        this.n = view;
        this.f4906j = new b0(context, null, i2, i3);
        fVar.b(this, context);
    }

    @Override // c.a.f.d.k
    public void a(f fVar, boolean z) {
        if (fVar != this.f4900d) {
            return;
        }
        d();
        k.a aVar = this.p;
        if (aVar != null) {
            aVar.a(fVar, z);
        }
    }

    @Override // c.a.f.d.n
    public void b() {
        View view;
        boolean z = true;
        if (!j()) {
            if (this.r || (view = this.n) == null) {
                z = false;
            } else {
                this.o = view;
                this.f4906j.C.setOnDismissListener(this);
                b0 b0Var = this.f4906j;
                b0Var.t = this;
                b0Var.i(true);
                View view2 = this.o;
                boolean z2 = this.q == null;
                ViewTreeObserver viewTreeObserver = view2.getViewTreeObserver();
                this.q = viewTreeObserver;
                if (z2) {
                    viewTreeObserver.addOnGlobalLayoutListener(this.k);
                }
                view2.addOnAttachStateChangeListener(this.l);
                b0 b0Var2 = this.f4906j;
                b0Var2.s = view2;
                b0Var2.o = this.u;
                if (!this.s) {
                    this.t = i.n(this.f4901e, null, this.f4899c, this.f4903g);
                    this.s = true;
                }
                this.f4906j.h(this.t);
                this.f4906j.C.setInputMethodMode(2);
                b0 b0Var3 = this.f4906j;
                Rect rect = this.f4886b;
                Objects.requireNonNull(b0Var3);
                b0Var3.A = rect != null ? new Rect(rect) : null;
                this.f4906j.b();
                u uVar = this.f4906j.f5107f;
                uVar.setOnKeyListener(this);
                if (this.v && this.f4900d.n != null) {
                    FrameLayout frameLayout = (FrameLayout) LayoutInflater.from(this.f4899c).inflate(R.layout.abc_popup_menu_header_item_layout, (ViewGroup) uVar, false);
                    TextView textView = (TextView) frameLayout.findViewById(android.R.id.title);
                    if (textView != null) {
                        textView.setText(this.f4900d.n);
                    }
                    frameLayout.setEnabled(false);
                    uVar.addHeaderView(frameLayout, null, false);
                }
                this.f4906j.g(this.f4901e);
                this.f4906j.b();
            }
        }
        if (!z) {
            throw new IllegalStateException("StandardMenuPopup cannot be used without an anchor");
        }
    }

    @Override // c.a.f.d.n
    public void d() {
        if (j()) {
            this.f4906j.d();
        }
    }

    @Override // c.a.f.d.n
    public ListView e() {
        return this.f4906j.f5107f;
    }

    /* JADX WARN: Removed duplicated region for block: B:23:0x0070  */
    @Override // c.a.f.d.k
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public boolean f(c.a.f.d.p r10) {
        /*
            r9 = this;
            boolean r0 = r10.hasVisibleItems()
            r1 = 0
            if (r0 == 0) goto L78
            c.a.f.d.j r0 = new c.a.f.d.j
            android.content.Context r3 = r9.f4899c
            android.view.View r5 = r9.o
            boolean r6 = r9.f4902f
            int r7 = r9.f4904h
            int r8 = r9.f4905i
            r2 = r0
            r4 = r10
            r2.<init>(r3, r4, r5, r6, r7, r8)
            c.a.f.d.k$a r2 = r9.p
            r0.d(r2)
            boolean r2 = c.a.f.d.i.v(r10)
            r0.f4894h = r2
            c.a.f.d.i r3 = r0.f4896j
            if (r3 == 0) goto L2a
            r3.p(r2)
        L2a:
            android.widget.PopupWindow$OnDismissListener r2 = r9.m
            r0.k = r2
            r2 = 0
            r9.m = r2
            c.a.f.d.f r2 = r9.f4900d
            r2.c(r1)
            c.a.g.b0 r2 = r9.f4906j
            int r3 = r2.f5110i
            boolean r4 = r2.l
            if (r4 != 0) goto L40
            r2 = r1
            goto L42
        L40:
            int r2 = r2.f5111j
        L42:
            int r4 = r9.u
            android.view.View r5 = r9.n
            java.util.WeakHashMap<android.view.View, c.c.i.q> r6 = c.c.i.k.f5288a
            int r5 = r5.getLayoutDirection()
            int r4 = android.view.Gravity.getAbsoluteGravity(r4, r5)
            r4 = r4 & 7
            r5 = 5
            if (r4 != r5) goto L5c
            android.view.View r4 = r9.n
            int r4 = r4.getWidth()
            int r3 = r3 + r4
        L5c:
            boolean r4 = r0.b()
            r5 = 1
            if (r4 == 0) goto L64
            goto L6d
        L64:
            android.view.View r4 = r0.f4892f
            if (r4 != 0) goto L6a
            r0 = r1
            goto L6e
        L6a:
            r0.e(r3, r2, r5, r5)
        L6d:
            r0 = r5
        L6e:
            if (r0 == 0) goto L78
            c.a.f.d.k$a r0 = r9.p
            if (r0 == 0) goto L77
            r0.b(r10)
        L77:
            return r5
        L78:
            return r1
        */
        throw new UnsupportedOperationException("Method not decompiled: c.a.f.d.o.f(c.a.f.d.p):boolean");
    }

    @Override // c.a.f.d.k
    public void g(boolean z) {
        this.s = false;
        e eVar = this.f4901e;
        if (eVar != null) {
            eVar.notifyDataSetChanged();
        }
    }

    @Override // c.a.f.d.k
    public boolean h() {
        return false;
    }

    @Override // c.a.f.d.n
    public boolean j() {
        return !this.r && this.f4906j.j();
    }

    @Override // c.a.f.d.k
    public void l(k.a aVar) {
        this.p = aVar;
    }

    @Override // c.a.f.d.i
    public void m(f fVar) {
    }

    @Override // c.a.f.d.i
    public void o(View view) {
        this.n = view;
    }

    @Override // android.widget.PopupWindow.OnDismissListener
    public void onDismiss() {
        this.r = true;
        this.f4900d.c(true);
        ViewTreeObserver viewTreeObserver = this.q;
        if (viewTreeObserver != null) {
            if (!viewTreeObserver.isAlive()) {
                this.q = this.o.getViewTreeObserver();
            }
            this.q.removeGlobalOnLayoutListener(this.k);
            this.q = null;
        }
        this.o.removeOnAttachStateChangeListener(this.l);
        PopupWindow.OnDismissListener onDismissListener = this.m;
        if (onDismissListener != null) {
            onDismissListener.onDismiss();
        }
    }

    @Override // android.view.View.OnKeyListener
    public boolean onKey(View view, int i2, KeyEvent keyEvent) {
        if (keyEvent.getAction() != 1 || i2 != 82) {
            return false;
        }
        d();
        return true;
    }

    @Override // c.a.f.d.i
    public void p(boolean z) {
        this.f4901e.f4851d = z;
    }

    @Override // c.a.f.d.i
    public void q(int i2) {
        this.u = i2;
    }

    @Override // c.a.f.d.i
    public void r(int i2) {
        this.f4906j.f5110i = i2;
    }

    @Override // c.a.f.d.i
    public void s(PopupWindow.OnDismissListener onDismissListener) {
        this.m = onDismissListener;
    }

    @Override // c.a.f.d.i
    public void t(boolean z) {
        this.v = z;
    }

    @Override // c.a.f.d.i
    public void u(int i2) {
        b0 b0Var = this.f4906j;
        b0Var.f5111j = i2;
        b0Var.l = true;
    }
}
