package com.bytedance.adsdk.ugeno.core.ro;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.view.MotionEvent;
import com.bytedance.adsdk.ugeno.core.dsz;
import com.bytedance.adsdk.ugeno.core.fhx;
import com.bytedance.adsdk.ugeno.wsy.wu;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;

/* JADX INFO: loaded from: classes.dex */
public class jnr {
    private boolean dsz;
    private Context duv;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    private dsz f6319ef;
    private boolean fhx;
    private fm irt;
    private String ku;
    private boolean onz;
    private dsz vt;
    private int fm = 0;
    private int ro = Integer.MAX_VALUE;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private int f6320lb = Integer.MAX_VALUE;
    private AtomicBoolean yz = new AtomicBoolean(true);
    private float jnr = Float.MIN_VALUE;
    private float ajl = Float.MIN_VALUE;
    private Map<Integer, Float> wsy = new HashMap();
    private Map<Integer, Float> wu = new HashMap();

    public jnr(Context context, dsz dszVar, boolean z10, boolean z11, boolean z12) {
        this.duv = context;
        this.f6319ef = dszVar;
        this.dsz = z10;
        this.onz = z11;
        this.fhx = z12;
        lb();
    }

    private void lb() {
        if (this.onz) {
            this.irt = new fm();
        }
        dsz dszVar = this.f6319ef;
        if (dszVar == null) {
            return;
        }
        this.fm = dszVar.lb().optInt("slideThreshold");
        this.ku = this.f6319ef.lb().optString("slideDirection");
        this.ro = this.f6319ef.lb().optInt("frequency", Integer.MAX_VALUE);
        this.f6320lb = this.f6319ef.lb().optInt("effectiveDuration", Integer.MAX_VALUE);
        this.yz.get();
    }

    public void ro() {
        this.jnr = Float.MIN_VALUE;
        this.ajl = Float.MIN_VALUE;
        this.wsy.clear();
        this.wu.clear();
    }

    public void fm() {
        if (this.f6320lb == Integer.MAX_VALUE) {
            return;
        }
        new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { // from class: com.bytedance.adsdk.ugeno.core.ro.jnr.1
            @Override // java.lang.Runnable
            public void run() {
                jnr.this.yz.set(false);
            }
        }, this.f6320lb);
    }

    /* JADX WARN: Removed duplicated region for block: B:23:0x0050  */
    /* JADX WARN: Removed duplicated region for block: B:62:0x0138  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private boolean ro(fhx fhxVar, com.bytedance.adsdk.ugeno.ro.lb lbVar, MotionEvent motionEvent, boolean z10) {
        int actionMasked = motionEvent.getActionMasked();
        int actionIndex = motionEvent.getActionIndex();
        int pointerId = motionEvent.getPointerId(actionIndex);
        if (actionMasked == 0) {
            this.wsy.put(Integer.valueOf(pointerId), Float.valueOf(motionEvent.getX(actionIndex)));
            this.wu.put(Integer.valueOf(pointerId), Float.valueOf(motionEvent.getY(actionIndex)));
            Objects.toString(this.wsy.get(Integer.valueOf(pointerId)));
            Objects.toString(this.wu.get(Integer.valueOf(pointerId)));
        } else {
            if (actionMasked == 1) {
                if (this.wsy.containsKey(Integer.valueOf(pointerId)) && this.wu.containsKey(Integer.valueOf(pointerId))) {
                    float fFloatValue = this.wsy.get(Integer.valueOf(pointerId)).floatValue();
                    float fFloatValue2 = this.wu.get(Integer.valueOf(pointerId)).floatValue();
                    float x10 = motionEvent.getX(actionIndex);
                    float y10 = motionEvent.getY(actionIndex);
                    if (this.dsz && Math.abs(x10 - fFloatValue) <= 10.0f && Math.abs(y10 - fFloatValue2) <= 10.0f && fhxVar != null) {
                        fm(pointerId);
                        fhxVar.fm(this.vt, lbVar, lbVar);
                        return true;
                    }
                    if (this.fm == 0 && fhxVar != null) {
                        fm(pointerId);
                        fm(fhxVar, this.f6319ef, lbVar);
                        return true;
                    }
                    int iRo = wu.ro(this.duv, x10 - fFloatValue);
                    int iRo2 = wu.ro(this.duv, y10 - fFloatValue2);
                    if (TextUtils.equals(this.ku, "up")) {
                        iRo = -iRo2;
                    } else if (TextUtils.equals(this.ku, "down")) {
                        iRo = iRo2;
                    } else if (TextUtils.equals(this.ku, "left")) {
                        iRo = -iRo;
                    } else if (!TextUtils.equals(this.ku, "right")) {
                        iRo = (int) Math.abs(Math.sqrt(Math.pow(iRo2, 2.0d) + Math.pow(iRo, 2.0d)));
                    }
                    if (iRo < this.fm) {
                        fm(pointerId);
                        "Non-slide event for pointer ".concat(String.valueOf(pointerId));
                        fm(lbVar);
                    } else if (fhxVar != null) {
                        fm(pointerId);
                        fm(fhxVar, this.f6319ef, lbVar);
                        return true;
                    }
                }
                return false;
            }
            if (actionMasked == 3) {
                for (int i10 = 0; i10 < motionEvent.getPointerCount(); i10++) {
                    int pointerId2 = motionEvent.getPointerId(i10);
                    if (this.wsy.containsKey(Integer.valueOf(pointerId2)) && this.wu.containsKey(Integer.valueOf(pointerId2))) {
                        "ACTION_CANCEL for pointer ".concat(String.valueOf(pointerId2));
                        fm(pointerId2);
                    }
                }
                return false;
            }
            if (actionMasked != 5) {
                if (actionMasked == 6) {
                }
            }
        }
        return true;
    }

    private void fm(int i10) {
        this.wsy.remove(Integer.valueOf(i10));
        this.wu.remove(Integer.valueOf(i10));
    }

    public jnr(Context context, dsz dszVar, dsz dszVar2, boolean z10, boolean z11, boolean z12) {
        this.duv = context;
        this.f6319ef = dszVar;
        this.vt = dszVar2;
        this.dsz = z10;
        this.onz = z11;
        this.fhx = z12;
        lb();
    }

    public boolean fm(fhx fhxVar, com.bytedance.adsdk.ugeno.ro.lb lbVar, MotionEvent motionEvent, boolean z10) {
        fm fmVar = this.irt;
        if (fmVar != null) {
            if (fmVar.fm(motionEvent)) {
                return false;
            }
            this.irt.fm(lbVar, motionEvent);
        }
        if (this.fhx) {
            return ro(fhxVar, lbVar, motionEvent, z10);
        }
        return lb(fhxVar, lbVar, motionEvent, z10);
    }

    /* JADX WARN: Removed duplicated region for block: B:30:0x0079  */
    /* JADX WARN: Removed duplicated region for block: B:31:0x007b  */
    /* JADX WARN: Removed duplicated region for block: B:43:0x00b8  */
    /* JADX WARN: Removed duplicated region for block: B:47:0x00c7  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private boolean lb(fhx fhxVar, com.bytedance.adsdk.ugeno.ro.lb lbVar, MotionEvent motionEvent, boolean z10) {
        float x10;
        float y10;
        int iRo;
        int action = motionEvent.getAction();
        if (action == 0) {
            this.jnr = motionEvent.getX();
            this.ajl = motionEvent.getY();
        } else if (action == 1) {
            x10 = motionEvent.getX();
            y10 = motionEvent.getY();
            if (!this.dsz && Math.abs(x10 - this.jnr) <= 10.0f && Math.abs(y10 - this.ajl) <= 10.0f && fhxVar != null) {
                ro();
                fhxVar.fm(this.vt, lbVar, lbVar);
                return true;
            }
            if (this.fm != 0 && fhxVar != null) {
                ro();
                fm(fhxVar, this.f6319ef, lbVar);
                return true;
            }
            iRo = wu.ro(this.duv, x10 - this.jnr);
            int iRo2 = wu.ro(this.duv, y10 - this.ajl);
            if (!TextUtils.equals(this.ku, "up")) {
                iRo = -iRo2;
            } else if (TextUtils.equals(this.ku, "down")) {
                iRo = iRo2;
            } else if (TextUtils.equals(this.ku, "left")) {
                iRo = -iRo;
            } else if (!TextUtils.equals(this.ku, "right")) {
                iRo = (int) Math.abs(Math.sqrt(Math.pow(iRo2, 2.0d) + Math.pow(iRo, 2.0d)));
            }
            if (iRo >= this.fm) {
                ro();
                fm(lbVar);
                return false;
            }
            if (fhxVar != null) {
                ro();
                fm(fhxVar, this.f6319ef, lbVar);
                return true;
            }
            ro();
        } else if (action == 3) {
            if (this.jnr == Float.MIN_VALUE || this.ajl == Float.MIN_VALUE) {
                return false;
            }
            x10 = motionEvent.getX();
            y10 = motionEvent.getY();
            if (!this.dsz) {
            }
            if (this.fm != 0) {
            }
            iRo = wu.ro(this.duv, x10 - this.jnr);
            int iRo22 = wu.ro(this.duv, y10 - this.ajl);
            if (!TextUtils.equals(this.ku, "up")) {
            }
            if (iRo >= this.fm) {
            }
        }
        return true;
    }

    private void fm(com.bytedance.adsdk.ugeno.ro.lb lbVar) {
        fm fmVar = this.irt;
        if (fmVar != null) {
            fmVar.fm(lbVar);
        }
    }

    private void fm(fhx fhxVar, dsz dszVar, com.bytedance.adsdk.ugeno.ro.lb lbVar) {
        if (this.ro <= 0) {
            fm(lbVar);
            return;
        }
        if (!this.yz.get()) {
            fm(lbVar);
            return;
        }
        fhxVar.fm(dszVar, lbVar, lbVar);
        int i10 = this.ro;
        if (i10 != Integer.MAX_VALUE) {
            this.ro = i10 - 1;
        }
    }
}
