package com.bytedance.creativex.recorder.gesture;

import X.0CB;
import X.0CH;
import X.0CN;
import X.6Is;
import X.C4519NyM;
import X.C4520NyN;
import X.C4521NyO;
import X.O75;
import X.TXs;
import X.TXt;
import X.TXw;
import android.content.Context;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.View;
import android.view.ViewConfiguration;
import com.bytedance.covode.number.Covode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class DefaultGesturePresenter implements TXt, 6Is {
    public boolean LIZ = true;
    public float LIZIZ = 0.0f;
    public boolean LIZJ;
    public boolean LIZLLL = true;
    public List<O75> LJ = new ArrayList();
    public Map<Integer, Integer> LJFF = new HashMap();
    public TXs LJI;
    public C4520NyN LJII;
    public int LJIIIIZZ;

    static {
        Covode.recordClassIndex(25549);
    }

    public void onStateChanged(0CH r2, 0CB r3) {
        if (r3 == 0CB.ON_DESTROY) {
            disAttachView();
        }
    }

    public final boolean LIZ(MotionEvent motionEvent, MotionEvent motionEvent2, float f, float f2) {
        C4520NyN nyN;
        if (LJI()) {
            return false;
        }
        for (C4519NyM next : this.LJ) {
            if (next != null && next.LIZ(motionEvent, motionEvent2, f, f2)) {
                return true;
            }
        }
        int abs = (int) Math.abs(motionEvent.getX() - motionEvent2.getX());
        int abs2 = (int) Math.abs(motionEvent.getY() - motionEvent2.getY());
        if (abs > this.LJIIIIZZ && abs > abs2 && !this.LIZJ) {
            float width = this.LIZIZ + (f / ((float) this.LJI.getWidth()));
            this.LIZIZ = width;
            float min = Math.min(width, 1.0f);
            this.LIZIZ = min;
            float max = Math.max(min, -1.0f);
            this.LIZIZ = max;
            C4520NyN nyN2 = this.LJII;
            if (nyN2 == null || !nyN2.LIZ(max)) {
                return false;
            }
            return true;
        } else if (abs >= abs2 || (nyN = this.LJII) == null || !nyN.LIZIZ(f2)) {
            return false;
        } else {
            return true;
        }
    }

    public final boolean LIZ(ScaleGestureDetector scaleGestureDetector) {
        if (LJI()) {
            return false;
        }
        for (C4519NyM next : this.LJ) {
            if (next != null && next.LIZ(scaleGestureDetector)) {
                return true;
            }
        }
        C4520NyN nyN = this.LJII;
        if (nyN != null) {
            return nyN.LIZJ();
        }
        return false;
    }

    private boolean LJI() {
        if (!this.LIZ) {
            return true;
        }
        return false;
    }

    @0CN(LIZ = 0CB.ON_DESTROY)
    public void disAttachView() {
        this.LJI.setOnGestureListener((TXt) null);
    }

    public final void LJ() {
        if (!LJI()) {
            Iterator<O75> it = this.LJ.iterator();
            while (it.hasNext()) {
                it.next();
            }
        }
    }

    public final void LJFF() {
        if (!LJI()) {
            Iterator<O75> it = this.LJ.iterator();
            while (it.hasNext()) {
                it.next();
            }
        }
    }

    public final boolean LIZIZ() {
        if (LJI()) {
            return false;
        }
        for (C4519NyM next : this.LJ) {
            if (next != null && next.LIZIZ()) {
                return true;
            }
        }
        return false;
    }

    public final boolean LIZJ() {
        if (LJI()) {
            return false;
        }
        Iterator<O75> it = this.LJ.iterator();
        while (it.hasNext()) {
            it.next();
        }
        return false;
    }

    public final boolean LIZLLL() {
        if (LJI()) {
            return false;
        }
        Iterator<O75> it = this.LJ.iterator();
        while (it.hasNext()) {
            it.next();
        }
        return false;
    }

    public final boolean LIZ() {
        if (LJI()) {
            return false;
        }
        for (C4519NyM next : this.LJ) {
            if (next != null && next.LIZ()) {
                return true;
            }
        }
        return false;
    }

    public final void LIZ(O75 o75) {
        LIZ(1, o75);
    }

    public final void LIZ(View view) {
        if (view instanceof TXs) {
            TXs tXs = (TXs) view;
            this.LJI = tXs;
            tXs.setOnGestureListener(this);
        }
    }

    public final O75 LIZ(int i) {
        Integer num = this.LJFF.get(Integer.valueOf(i));
        if (num == null) {
            return null;
        }
        return this.LJ.get(num.intValue());
    }

    private boolean LJI(MotionEvent motionEvent) {
        for (C4519NyM next : this.LJ) {
            if (next != null && next.LIZJ(motionEvent)) {
                return true;
            }
        }
        C4520NyN nyN = this.LJII;
        if (nyN == null || !nyN.LIZ()) {
            return false;
        }
        return true;
    }

    public final void LJFF(MotionEvent motionEvent) {
        if (!LJI()) {
            for (O75 next : this.LJ) {
                if (next != null) {
                    next.LIZ(motionEvent, 0);
                }
            }
        }
    }

    public final boolean LIZIZ(float f) {
        if (LJI()) {
            return false;
        }
        for (C4519NyM next : this.LJ) {
            if (next != null && next.LIZIZ(f)) {
                return true;
            }
        }
        return false;
    }

    public final boolean LIZJ(float f) {
        if (LJI()) {
            return false;
        }
        for (C4519NyM next : this.LJ) {
            if (next != null && next.LIZJ(f)) {
                return true;
            }
        }
        return false;
    }

    public final boolean LIZLLL(MotionEvent motionEvent) {
        if (LJI()) {
            return false;
        }
        for (C4519NyM next : this.LJ) {
            if (next != null && next.LIZLLL(motionEvent)) {
                return true;
            }
        }
        return false;
    }

    public final boolean LJ(MotionEvent motionEvent) {
        if (LJI()) {
            return false;
        }
        for (C4519NyM next : this.LJ) {
            if (next != null && next.LJ(motionEvent)) {
                return true;
            }
        }
        return false;
    }

    public final boolean LIZIZ(MotionEvent motionEvent) {
        if (LJI()) {
            return false;
        }
        for (C4519NyM next : this.LJ) {
            if (next != null && next.LIZIZ(motionEvent)) {
                return true;
            }
        }
        return false;
    }

    public final boolean LIZJ(MotionEvent motionEvent) {
        if (LJI() || !this.LIZLLL) {
            return false;
        }
        this.LIZLLL = false;
        new Handler().postDelayed(new C4521NyO(this), 300);
        return LJI(motionEvent);
    }

    public final boolean LIZ(float f) {
        if (LJI()) {
            return false;
        }
        C4520NyN nyN = this.LJII;
        if (nyN != null) {
            nyN.LIZLLL();
        }
        for (C4519NyM next : this.LJ) {
            if (next != null && next.LIZ(f)) {
                return true;
            }
        }
        return false;
    }

    public final boolean LIZ(TXw tXw) {
        if (LJI()) {
            return false;
        }
        for (C4519NyM next : this.LJ) {
            if (next != null && next.LIZ(tXw)) {
                return true;
            }
        }
        return false;
    }

    public final boolean LIZIZ(ScaleGestureDetector scaleGestureDetector) {
        if (LJI()) {
            return false;
        }
        for (C4519NyM next : this.LJ) {
            if (next != null && next.LIZIZ(scaleGestureDetector)) {
                return true;
            }
        }
        C4520NyN nyN = this.LJII;
        if (nyN != null) {
            scaleGestureDetector.getScaleFactor();
            if (nyN.LIZIZ()) {
                return true;
            }
        }
        C4520NyN nyN2 = this.LJII;
        if (nyN2 != null) {
            return nyN2.LIZ(scaleGestureDetector);
        }
        return false;
    }

    public final boolean LIZ(MotionEvent motionEvent) {
        if (LJI()) {
            return false;
        }
        Iterator<O75> it = this.LJ.iterator();
        while (it.hasNext()) {
            it.next();
        }
        C4520NyN nyN = this.LJII;
        if (nyN == null || !nyN.LIZ(motionEvent)) {
            return false;
        }
        return true;
    }

    public final void LIZIZ(MotionEvent motionEvent, int[] iArr) {
        if (!LJI()) {
            for (C4519NyM next : this.LJ) {
                if (next != null) {
                    next.LIZIZ(motionEvent, iArr);
                }
            }
        }
    }

    public final void LIZJ(MotionEvent motionEvent, int[] iArr) {
        if (!LJI()) {
            for (C4519NyM next : this.LJ) {
                if (next != null) {
                    next.LIZJ(motionEvent, iArr);
                }
            }
        }
    }

    public final void LIZLLL(MotionEvent motionEvent, int[] iArr) {
        if (!LJI()) {
            for (C4519NyM next : this.LJ) {
                if (next != null) {
                    next.LIZLLL(motionEvent, iArr);
                }
            }
        }
    }

    public final void LIZ(int i, O75 o75) {
        Integer num = this.LJFF.get(Integer.valueOf(i));
        if (num != null) {
            this.LJ.set(num.intValue(), o75);
            return;
        }
        this.LJ.add(o75);
        this.LJFF.put(Integer.valueOf(i), Integer.valueOf(this.LJ.size() - 1));
    }

    public final void LJ(MotionEvent motionEvent, int[] iArr) {
        if (!LJI()) {
            for (C4519NyM next : this.LJ) {
                if (next != null) {
                    next.LJ(motionEvent, iArr);
                }
            }
        }
    }

    public final void LIZ(MotionEvent motionEvent, int[] iArr) {
        if (!LJI()) {
            for (C4519NyM next : this.LJ) {
                if (next != null) {
                    next.LIZ(motionEvent, iArr);
                }
            }
        }
    }

    public DefaultGesturePresenter(Context context, 0CH r4, C4520NyN nyN, View view) {
        this.LJII = nyN;
        LIZ(view);
        r4.getLifecycle().LIZ(this);
        this.LJIIIIZZ = ViewConfiguration.get(context).getScaledPagingTouchSlop();
    }

    public final boolean LIZIZ(MotionEvent motionEvent, MotionEvent motionEvent2, float f, float f2) {
        boolean z = false;
        if (LJI()) {
            return false;
        }
        for (C4519NyM next : this.LJ) {
            if (next != null && next.LIZIZ(motionEvent, motionEvent2, f, f2)) {
                return true;
            }
        }
        if (!this.LIZJ && Math.abs(motionEvent.getX() - motionEvent2.getX()) > Math.abs(motionEvent.getY() - motionEvent2.getY())) {
            C4520NyN nyN = this.LJII;
            if (nyN != null && nyN.LIZ(f, this.LIZIZ)) {
                z = true;
            }
            this.LIZIZ = 0.0f;
        }
        return z;
    }
}
