package o;

import android.view.View;
import android.view.ViewTreeObserver;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class UT implements ViewTreeObserver.OnPreDrawListener, View.OnAttachStateChangeListener {
    public final View l;
    public ViewTreeObserver m;
    public final Runnable n;

    public UT(View view, Runnable runnable) {
        this.l = view;
        this.m = view.getViewTreeObserver();
        this.n = runnable;
    }

    public static void a(View view, Runnable runnable) {
        if (view == null) {
            throw new NullPointerException("view == null");
        }
        UT ut = new UT(view, runnable);
        view.getViewTreeObserver().addOnPreDrawListener(ut);
        view.addOnAttachStateChangeListener(ut);
    }

    @Override // android.view.ViewTreeObserver.OnPreDrawListener
    public final boolean onPreDraw() {
        boolean zIsAlive = this.m.isAlive();
        View view = this.l;
        if (zIsAlive) {
            this.m.removeOnPreDrawListener(this);
        } else {
            view.getViewTreeObserver().removeOnPreDrawListener(this);
        }
        view.removeOnAttachStateChangeListener(this);
        this.n.run();
        return true;
    }

    @Override // android.view.View.OnAttachStateChangeListener
    public final void onViewAttachedToWindow(View view) {
        this.m = view.getViewTreeObserver();
    }

    @Override // android.view.View.OnAttachStateChangeListener
    public final void onViewDetachedFromWindow(View view) {
        boolean zIsAlive = this.m.isAlive();
        View view2 = this.l;
        if (zIsAlive) {
            this.m.removeOnPreDrawListener(this);
        } else {
            view2.getViewTreeObserver().removeOnPreDrawListener(this);
        }
        view2.removeOnAttachStateChangeListener(this);
    }
}
