package com.tencent.mm.pluginsdk.ui.tools;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.FrameLayout.LayoutParams;
import android.widget.ImageView;
import android.widget.TextView;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.plugin.sight.decode.ui.AdVideoPlayerLoadingBar;
import com.tencent.mm.pluginsdk.ui.g;
import com.tencent.mm.pointers.PInt;
import com.tencent.mm.sdk.platformtools.ab;

public class VideoPlayerSeekBar extends AdVideoPlayerLoadingBar implements g {
    protected boolean cAW = false;
    private int uck = -1;
    private int ucl = -1;
    private int ucm = -1;
    private PInt vvn = new PInt();

    public VideoPlayerSeekBar(Context context) {
        super(context);
        AppMethodBeat.i(117963);
        AppMethodBeat.o(117963);
    }

    public VideoPlayerSeekBar(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        AppMethodBeat.i(117964);
        AppMethodBeat.o(117964);
    }

    public VideoPlayerSeekBar(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        AppMethodBeat.i(117965);
        AppMethodBeat.o(117965);
    }

    public void init() {
        AppMethodBeat.i(117966);
        this.contentView = View.inflate(getContext(), getLayoutId(), this);
        this.qyl = (ImageView) this.contentView.findViewById(2131821425);
        this.qym = (ImageView) this.contentView.findViewById(2131821423);
        this.qyn = (ImageView) this.contentView.findViewById(2131821426);
        this.qyo = (ImageView) this.contentView.findViewById(2131821279);
        this.qyp = (TextView) this.contentView.findViewById(2131821421);
        this.qyq = (TextView) this.contentView.findViewById(2131821427);
        this.qyn.setOnTouchListener(new 1(this));
        AppMethodBeat.o(117966);
    }

    public int getBarPointWidth() {
        AppMethodBeat.i(117967);
        if (this.uck == -1) {
            this.uck = this.qyn.getWidth();
        }
        int i = this.uck;
        AppMethodBeat.o(117967);
        return i;
    }

    private int getBarPointPaddingLeft() {
        AppMethodBeat.i(117968);
        if (this.ucl == -1) {
            this.ucl = this.qyn.getPaddingLeft();
        }
        int i = this.ucl;
        AppMethodBeat.o(117968);
        return i;
    }

    private int getBarPointPaddingRight() {
        AppMethodBeat.i(117969);
        if (this.ucm == -1) {
            this.ucm = this.qyn.getPaddingRight();
        }
        int i = this.ucm;
        AppMethodBeat.o(117969);
        return i;
    }

    /* Access modifiers changed, original: protected|final */
    public final int gR(int i, int i2) {
        int i3;
        AppMethodBeat.i(117970);
        if (i <= 0) {
            this.qym.getLayoutParams();
            i3 = 0;
        } else if (i >= this.qyr) {
            i3 = i2 - (((getBarPointWidth() - getBarPointPaddingLeft()) - getBarPointPaddingRight()) / 2);
        } else {
            i3 = (int) (((((double) i) * 1.0d) / ((double) this.qyr)) * ((double) i2));
        }
        AppMethodBeat.o(117970);
        return i3;
    }

    public int getLayoutId() {
        return 2130970991;
    }

    public ImageView getPlayBtn() {
        return this.qyo;
    }

    public TextView getPlaytimeTv() {
        return this.qyp;
    }

    public void seek(int i) {
        AppMethodBeat.i(117971);
        ab.d("MicroMsg.VideoPlayerSeekBar", "seek position : ".concat(String.valueOf(i)));
        if (i < 0) {
            i = 0;
        }
        if (i >= this.qyr) {
            i = this.qyr;
        }
        if (this.mPosition != i) {
            this.mPosition = i;
            aFQ();
        }
        AppMethodBeat.o(117971);
    }

    public void setVideoTotalTime(int i) {
        AppMethodBeat.i(117972);
        this.qyr = i;
        this.mPosition = 0;
        this.qyq.setText(oy(this.qyr / 60) + ":" + oy(this.qyr % 60));
        aFQ();
        AppMethodBeat.o(117972);
    }

    public void aFQ() {
        AppMethodBeat.i(117973);
        if (this.qyr == 0) {
            AppMethodBeat.o(117973);
        } else if (this.hOy) {
            AppMethodBeat.o(117973);
        } else if (this.qyn == null) {
            AppMethodBeat.o(117973);
        } else if (getBarLen() == 0) {
            AppMethodBeat.o(117973);
        } else {
            this.qyp.setText(oy(this.mPosition / 60) + ":" + oy(this.mPosition % 60));
            LayoutParams layoutParams = (LayoutParams) this.qyn.getLayoutParams();
            int barLen = getBarLen();
            layoutParams.leftMargin = gR(this.mPosition, barLen);
            this.qyn.setLayoutParams(layoutParams);
            layoutParams = (LayoutParams) this.qyl.getLayoutParams();
            layoutParams.width = (int) (((((double) this.mPosition) * 1.0d) / ((double) this.qyr)) * ((double) barLen));
            this.qyl.setLayoutParams(layoutParams);
            requestLayout();
            AppMethodBeat.o(117973);
        }
    }

    public void setPlayBtnOnClickListener(OnClickListener onClickListener) {
        AppMethodBeat.i(117974);
        if (this.qyo != null) {
            this.qyo.setOnClickListener(onClickListener);
        }
        AppMethodBeat.o(117974);
    }

    public void setIsPlay(boolean z) {
        AppMethodBeat.i(117975);
        this.cAW = z;
        super.setIsPlay(z);
        AppMethodBeat.o(117975);
    }

    public final boolean buH() {
        return this.cAW;
    }

    public final void Dq(int i) {
        AppMethodBeat.i(117976);
        seek(i);
        AppMethodBeat.o(117976);
    }

    public final void nF(boolean z) {
        AppMethodBeat.i(117977);
        setIsPlay(z);
        AppMethodBeat.o(117977);
    }

    static /* synthetic */ int a(VideoPlayerSeekBar videoPlayerSeekBar, int i, PInt pInt) {
        AppMethodBeat.i(117978);
        int barPointPaddingLeft = ((LayoutParams) videoPlayerSeekBar.qym.getLayoutParams()).leftMargin - videoPlayerSeekBar.getBarPointPaddingLeft();
        pInt.value = (int) (((((double) (i - barPointPaddingLeft)) * 1.0d) / ((double) videoPlayerSeekBar.getBarLen())) * ((double) videoPlayerSeekBar.qyr));
        if (pInt.value <= 0) {
            pInt.value = 0;
            if (i - barPointPaddingLeft > barPointPaddingLeft) {
                barPointPaddingLeft = i - barPointPaddingLeft;
            }
        } else if (pInt.value >= videoPlayerSeekBar.qyr) {
            pInt.value = videoPlayerSeekBar.qyr;
            barPointPaddingLeft = videoPlayerSeekBar.getBarLen() - (((videoPlayerSeekBar.getBarPointWidth() - videoPlayerSeekBar.getBarPointPaddingLeft()) - videoPlayerSeekBar.getBarPointPaddingRight()) / 2);
        } else {
            barPointPaddingLeft = i - barPointPaddingLeft;
        }
        AppMethodBeat.o(117978);
        return barPointPaddingLeft;
    }
}
