package com.bytedance.adsdk.ugeno.ajl;

import android.content.Context;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Interpolator;
import android.widget.FrameLayout;
import android.widget.Scroller;
import com.bytedance.adsdk.ugeno.wu.lb;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import tv.danmaku.ijk.media.player.IjkEventListener;

/* JADX INFO: loaded from: classes.dex */
public abstract class fm<T> extends FrameLayout implements lb.yz {
    private static final Interpolator ai = new Interpolator() { // from class: com.bytedance.adsdk.ugeno.ajl.fm.1
        @Override // android.animation.TimeInterpolator
        public float getInterpolation(float f10) {
            float f11 = f10 - 1.0f;
            return (f11 * f11 * f11 * f11 * f11) + 1.0f;
        }
    };
    private int ajl;
    private boolean dsz;
    private float duv;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    private int f6303ef;
    private boolean fhx;
    protected List<T> fm;
    private boolean gof;
    private int gqi;
    private boolean gzf;
    private C0012fm hi;
    private com.bytedance.adsdk.ugeno.ajl.fm.fm hlt;
    private boolean irt;
    private int jnr;
    private String ku;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    protected Context f6304lb;
    private FrameLayout lse;
    private int maa;
    private Scroller mq;
    private com.bytedance.adsdk.ugeno.ajl.lb nt;
    private final Runnable ol;
    private boolean onz;
    private boolean qhl;
    protected com.bytedance.adsdk.ugeno.wu.lb ro;
    private int sds;
    private int vt;
    private final Runnable wbw;
    private int wey;
    private int wsy;
    private int wu;
    private int yz;

    /* JADX INFO: renamed from: com.bytedance.adsdk.ugeno.ajl.fm$fm, reason: collision with other inner class name */
    public class C0012fm extends com.bytedance.adsdk.ugeno.wu.ro {
        public C0012fm() {
        }

        @Override // com.bytedance.adsdk.ugeno.wu.ro
        public int fm(Object obj) {
            return -2;
        }

        @Override // com.bytedance.adsdk.ugeno.wu.ro
        public boolean fm(View view, Object obj) {
            return view == obj;
        }

        @Override // com.bytedance.adsdk.ugeno.wu.ro
        public int fm() {
            if (fm.this.fhx) {
                return 1024;
            }
            return fm.this.fm.size();
        }

        @Override // com.bytedance.adsdk.ugeno.wu.ro
        public Object fm(ViewGroup viewGroup, int i10) {
            View viewFm = fm.this.fm(i10, yz.fm(fm.this.fhx, i10, fm.this.fm.size()));
            viewGroup.addView(viewFm);
            return viewFm;
        }

        @Override // com.bytedance.adsdk.ugeno.wu.ro
        public void fm(ViewGroup viewGroup, int i10, Object obj) {
            viewGroup.removeView((View) obj);
        }

        @Override // com.bytedance.adsdk.ugeno.wu.ro
        public float fm(int i10) {
            if (fm.this.duv <= 0.0f) {
                return 1.0f;
            }
            return 1.0f / fm.this.duv;
        }
    }

    public class lb extends com.bytedance.adsdk.ugeno.wu.lb {
        public lb(Context context) {
            super(context);
        }

        private MotionEvent fm(MotionEvent motionEvent) {
            float width = getWidth();
            float height = getHeight();
            motionEvent.setLocation((motionEvent.getY() / height) * width, (motionEvent.getX() / width) * height);
            return motionEvent;
        }

        @Override // com.bytedance.adsdk.ugeno.wu.lb, android.view.ViewGroup
        public boolean onInterceptTouchEvent(MotionEvent motionEvent) {
            if (!fm.this.irt) {
                return false;
            }
            try {
                if (fm.this.maa != 1) {
                    return super.onInterceptTouchEvent(motionEvent);
                }
                boolean zOnInterceptTouchEvent = super.onInterceptTouchEvent(fm(motionEvent));
                fm(motionEvent);
                return zOnInterceptTouchEvent;
            } catch (IllegalArgumentException unused) {
                return false;
            }
        }

        @Override // com.bytedance.adsdk.ugeno.wu.lb, android.view.View
        public boolean onTouchEvent(MotionEvent motionEvent) {
            if (!fm.this.irt) {
                return false;
            }
            try {
                return fm.this.maa == 1 ? super.onTouchEvent(fm(motionEvent)) : super.onTouchEvent(motionEvent);
            } catch (IllegalArgumentException unused) {
                return false;
            }
        }
    }

    public class ro extends Scroller {
        public ro(Context context, Interpolator interpolator) {
            super(context, interpolator);
        }

        @Override // android.widget.Scroller
        public void startScroll(int i10, int i11, int i12, int i13, int i14) {
            super.startScroll(i10, i11, i12, i13, fm.this.wsy);
        }

        @Override // android.widget.Scroller
        public void startScroll(int i10, int i11, int i12, int i13) {
            super.startScroll(i10, i11, i12, i13, fm.this.wsy);
        }
    }

    public fm(Context context) {
        super(context);
        this.fm = new CopyOnWriteArrayList();
        this.yz = -1;
        this.jnr = 2000;
        this.ajl = IjkEventListener.BUFFERING_START;
        this.wsy = IjkEventListener.BUFFERING_START;
        this.wu = 0;
        this.f6303ef = -1;
        this.vt = -1;
        this.ku = "normal";
        this.duv = 1.0f;
        this.dsz = true;
        this.onz = true;
        this.fhx = true;
        this.irt = true;
        this.gqi = 0;
        this.wey = 0;
        this.sds = 0;
        this.maa = 0;
        this.gzf = true;
        this.ol = new Runnable() { // from class: com.bytedance.adsdk.ugeno.ajl.fm.2
            @Override // java.lang.Runnable
            public void run() {
                int currentItem = fm.this.ro.getCurrentItem() + 1;
                if (fm.this.fhx) {
                    if (currentItem >= 1024) {
                        fm.this.ro.fm(512, false);
                        return;
                    } else {
                        fm.this.ro.fm(currentItem, true);
                        return;
                    }
                }
                com.bytedance.adsdk.ugeno.wu.ro adapter = fm.this.ro.getAdapter();
                if (adapter != null) {
                    if (currentItem >= adapter.fm()) {
                        fm.this.ro.fm(0, false);
                    } else {
                        fm.this.ro.fm(currentItem, true);
                    }
                }
            }
        };
        this.wbw = new Runnable() { // from class: com.bytedance.adsdk.ugeno.ajl.fm.3
            @Override // java.lang.Runnable
            public void run() {
                if (fm.this.onz) {
                    fm.this.gzf = false;
                    int currentItem = fm.this.ro.getCurrentItem() + 1;
                    if (fm.this.fhx) {
                        if (currentItem >= 1024) {
                            fm.this.ro.fm(512, false);
                        } else {
                            fm.this.ro.fm(currentItem, true);
                        }
                        fm fmVar = fm.this;
                        fmVar.postDelayed(fmVar.wbw, fm.this.jnr);
                        return;
                    }
                    com.bytedance.adsdk.ugeno.wu.ro adapter = fm.this.ro.getAdapter();
                    if (adapter != null) {
                        if (currentItem >= adapter.fm()) {
                            fm.this.ro.fm(0, false);
                            fm fmVar2 = fm.this;
                            fmVar2.postDelayed(fmVar2.wbw, fm.this.jnr);
                        } else {
                            fm.this.ro.fm(currentItem, true);
                            fm fmVar3 = fm.this;
                            fmVar3.postDelayed(fmVar3.wbw, fm.this.jnr);
                        }
                    }
                }
            }
        };
        this.f6304lb = context;
        this.lse = new FrameLayout(context);
        this.ro = fm();
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(-1, -1);
        layoutParams.gravity = 17;
        this.lse.addView(this.ro, layoutParams);
        addView(this.lse);
    }

    @Override // android.view.ViewGroup, android.view.View
    public boolean dispatchTouchEvent(MotionEvent motionEvent) {
        if (this.onz) {
            int action = motionEvent.getAction();
            if (action == 1 || action == 3 || action == 4) {
                if (!this.qhl) {
                    jnr();
                }
            } else if (action == 0) {
                ajl();
            }
        }
        return super.dispatchTouchEvent(motionEvent);
    }

    @Override // com.bytedance.adsdk.ugeno.wu.lb.yz
    public void dsz(int i10) {
        if (i10 == 1 && this.qhl) {
            ajl();
        }
        com.bytedance.adsdk.ugeno.ajl.lb lbVar = this.nt;
        if (lbVar != null) {
            lbVar.fm(this.fhx, i10);
        }
    }

    @Override // com.bytedance.adsdk.ugeno.wu.lb.yz
    public void duv(int i10) {
        if (this.nt != null) {
            int iFm = yz.fm(this.fhx, i10, this.fm.size());
            this.nt.fm(this.fhx, iFm, i10, iFm == 0, iFm == this.fm.size() - 1);
        }
        if (this.dsz) {
            this.hlt.fm(i10);
        }
    }

    public fm<T> ef(int i10) {
        this.f6303ef = i10;
        fm(this.ku, this.wu, i10, this.vt, true);
        return this;
    }

    public fm fm(int i10) {
        this.maa = i10;
        return this;
    }

    public com.bytedance.adsdk.ugeno.wu.ro getAdapter() {
        return this.ro.getAdapter();
    }

    public int getCurrentItem() {
        return this.ro.getCurrentItem();
    }

    public com.bytedance.adsdk.ugeno.wu.lb getViewPager() {
        return this.ro;
    }

    public fm jnr(float f10) {
        this.duv = f10;
        return this;
    }

    public abstract View ku(int i10);

    public fm lb(boolean z10) {
        this.dsz = z10;
        return this;
    }

    public void onz(int i10) {
        fm(this.ku, this.wu, this.f6303ef, this.vt, true);
        if (this.hi == null) {
            this.hi = new C0012fm();
            this.ro.fm((lb.yz) this);
            this.ro.setAdapter(this.hi);
        }
        if (this.fhx) {
            if (i10 >= 1024) {
                this.ro.fm(512, false);
                return;
            } else {
                this.ro.fm(i10, true);
                return;
            }
        }
        if (i10 < 0 || i10 >= this.fm.size()) {
            return;
        }
        this.ro.fm(i10, true);
    }

    public fm ro(int i10) {
        this.ajl = i10;
        return this;
    }

    public void setOnPageChangeListener(com.bytedance.adsdk.ugeno.ajl.lb lbVar) {
        this.nt = lbVar;
    }

    public void setTwoItems(boolean z10) {
        this.gof = z10;
    }

    public fm vt(int i10) {
        this.vt = i10;
        fm(this.ku, this.wu, this.f6303ef, i10, true);
        return this;
    }

    public fm ajl(int i10) {
        this.hlt.setSelectedColor(i10);
        return this;
    }

    public fm jnr(boolean z10) {
        this.qhl = z10;
        return this;
    }

    public fm ro(boolean z10) {
        this.irt = z10;
        return this;
    }

    public fm wsy(int i10) {
        this.hlt.setUnSelectedColor(i10);
        return this;
    }

    public fm wu(int i10) {
        this.wu = i10;
        fm(this.ku, i10, this.f6303ef, this.vt, true);
        return this;
    }

    public fm yz(float f10) {
        this.hlt.setIndicatorY(f10);
        return this;
    }

    private boolean wsy() {
        return this.fm.size() <= 2 && this.fhx;
    }

    public void ajl() {
        removeCallbacks(this.wbw);
    }

    public fm lb(float f10) {
        this.hlt.setIndicatorX(f10);
        return this;
    }

    public fm yz(int i10) {
        this.jnr = i10;
        jnr();
        return this;
    }

    public com.bytedance.adsdk.ugeno.wu.lb fm() {
        return new lb(getContext());
    }

    public fm jnr(int i10) {
        if (i10 < 0) {
            i10 = this.jnr;
        }
        this.yz = i10;
        jnr();
        return this;
    }

    public fm lb(int i10) {
        this.wsy = i10;
        if (this.mq == null) {
            this.mq = new ro(this.f6304lb, ai);
        }
        this.ro.setScroller(this.mq);
        return this;
    }

    public fm ro(float f10) {
        this.hlt.setIndicatorHeight((int) f10);
        return this;
    }

    public fm yz(boolean z10) {
        this.hlt.setLoop(z10);
        if (this.fhx != z10) {
            int iFm = yz.fm(z10, this.ro.getCurrentItem(), this.fm.size());
            this.fhx = z10;
            C0012fm c0012fm = this.hi;
            if (c0012fm != null) {
                c0012fm.lb();
                this.ro.setCurrentItem(iFm);
            }
        }
        return this;
    }

    public fm fm(String str) {
        if (TextUtils.equals(str, "rectangle")) {
            this.hlt = new com.bytedance.adsdk.ugeno.ajl.fm.lb(this.f6304lb);
        } else {
            this.hlt = new com.bytedance.adsdk.ugeno.ajl.fm.ro(this.f6304lb);
        }
        addView(this.hlt, new FrameLayout.LayoutParams(-2, -2));
        return this;
    }

    public void jnr() {
        int i10;
        removeCallbacks(this.wbw);
        int i11 = this.jnr;
        if (this.gzf && (i10 = this.yz) > 0) {
            i11 = i10;
        }
        postDelayed(this.wbw, i11);
    }

    public fm ro() {
        this.hlt.fm();
        return this;
    }

    public fm lb(String str) {
        this.ku = str;
        fm(str, this.wu, this.f6303ef, this.vt, true);
        return this;
    }

    public fm ro(String str) {
        this.hlt.setIndicatorDirection(str);
        return this;
    }

    public void lb() {
        fm(this.ku, this.wu, this.f6303ef, this.vt, true);
        if (this.hi == null) {
            this.hi = new C0012fm();
            this.ro.fm((lb.yz) this);
            this.ro.setAdapter(this.hi);
        }
        int i10 = this.gqi;
        if (i10 < 0 || i10 >= this.fm.size()) {
            this.gqi = 0;
        }
        int i11 = this.fhx ? this.gqi + 512 : this.gqi;
        this.ro.fm(i11, true);
        if (!this.fhx) {
            duv(i11);
        }
        if (this.onz) {
            jnr();
        }
    }

    public void yz() {
        ajl();
        if (this.hi != null) {
            this.ro.ro((lb.yz) this);
            this.ro.setAdapter(null);
            this.hi = null;
            this.ro.removeAllViews();
            this.fm.clear();
            this.hlt.lb();
        }
    }

    public fm fm(float f10) {
        this.hlt.setIndicatorWidth((int) f10);
        return this;
    }

    public fm fm(boolean z10) {
        this.onz = z10;
        jnr();
        return this;
    }

    public void fm(String str, int i10, int i11, int i12, boolean z10) {
        C0012fm c0012fm = this.hi;
        if (c0012fm != null) {
            c0012fm.lb();
        }
        this.ro.setPageMargin(i10);
        if (i11 > 0 || i12 > 0) {
            if (this.maa == 1) {
                this.ro.setPadding(0, i11 + i10, 0, i12 + i10);
            } else {
                this.ro.setPadding(i11 + i10, 0, i12 + i10, 0);
            }
            this.lse.setClipChildren(false);
            this.ro.setClipChildren(false);
            this.ro.setClipToPadding(false);
        }
        if (this.maa == 1) {
            com.bytedance.adsdk.ugeno.ajl.ro.yz yzVar = new com.bytedance.adsdk.ugeno.ajl.ro.yz();
            yzVar.fm(str);
            this.ro.fm(true, (lb.jnr) yzVar);
            this.ro.setOverScrollMode(2);
        } else if (TextUtils.equals(str, "linear")) {
            this.ro.fm(false, (lb.jnr) new com.bytedance.adsdk.ugeno.ajl.ro.lb());
        } else if (TextUtils.equals(str, "cube")) {
            this.ro.fm(false, (lb.jnr) new com.bytedance.adsdk.ugeno.ajl.ro.fm());
        } else if (TextUtils.equals(str, "fade")) {
            this.ro.fm(false, (lb.jnr) new com.bytedance.adsdk.ugeno.ajl.ro.ro());
        } else {
            this.ro.fm(false, (lb.jnr) null);
        }
        this.ro.setOffscreenPageLimit((int) this.duv);
    }

    public View fm(int i10, int i11) {
        if (this.fm.size() == 0) {
            return new View(getContext());
        }
        View viewKu = ku(i11);
        FrameLayout frameLayout = new FrameLayout(getContext());
        if (viewKu instanceof ViewGroup) {
            frameLayout.setClipChildren(true);
        }
        if (wsy()) {
            viewKu.setTag("two_items_tag");
        }
        if (viewKu.getParent() instanceof ViewGroup) {
            ((ViewGroup) viewKu.getParent()).removeView(viewKu);
        }
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(-1, -1);
        layoutParams.gravity = 17;
        frameLayout.addView(viewKu, layoutParams);
        frameLayout.addView(new View(getContext()), new FrameLayout.LayoutParams(-1, -1));
        if (wsy()) {
            frameLayout.setTag(Integer.valueOf(i10));
        }
        return frameLayout;
    }

    public fm<T> fm(T t10) {
        if (t10 != null) {
            this.fm.add(t10);
            if (this.dsz) {
                this.hlt.ro();
            }
        }
        C0012fm c0012fm = this.hi;
        if (c0012fm != null) {
            c0012fm.lb();
            this.hlt.fm(this.gqi, this.ro.getCurrentItem());
        }
        return this;
    }

    @Override // com.bytedance.adsdk.ugeno.wu.lb.yz
    public void fm(int i10, float f10, int i11) {
        com.bytedance.adsdk.ugeno.ajl.lb lbVar = this.nt;
        if (lbVar != null) {
            boolean z10 = this.fhx;
            lbVar.fm(z10, yz.fm(z10, i10, this.fm.size()), f10, i11);
        }
        if (wsy()) {
            fm(i10, findViewWithTag(Integer.valueOf(i10)));
            if (f10 > 0.0f) {
                int i12 = i10 + 1;
                fm(i12, findViewWithTag(Integer.valueOf(i12)));
            }
        }
    }

    private void fm(int i10, View view) {
        View viewFindViewWithTag;
        if ((view instanceof ViewGroup) && (viewFindViewWithTag = view.findViewWithTag("two_items_tag")) == null) {
            T t10 = this.fm.get(yz.fm(true, i10, this.fm.size()));
            if (t10 == null) {
                return;
            }
            if (t10 instanceof com.bytedance.adsdk.ugeno.ro.lb) {
                viewFindViewWithTag = ((com.bytedance.adsdk.ugeno.ro.lb) t10).ku();
            } else if (t10 instanceof View) {
                viewFindViewWithTag = (View) t10;
            }
            if (viewFindViewWithTag == null) {
                return;
            }
            if (viewFindViewWithTag.getParent() instanceof ViewGroup) {
                ((ViewGroup) viewFindViewWithTag.getParent()).removeView(viewFindViewWithTag);
            }
            ((ViewGroup) view).addView(viewFindViewWithTag);
        }
    }
}
