package com.daya.live_teaching.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

import com.herewhite.sdk.WhiteboardView;

/**
 * Description:
 * Copyright  : Copyright (c) 2019
 * Company    : 大雅乐盟
 * Author     : r
 * Date       : 2020/6/22 17:57
 */
public class MyWhiteBoardView extends WhiteboardView {

    public MyWhiteBoardView(Context context) {
        super(context);
    }

    public MyWhiteBoardView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    float DownX = 0;
    float DownY = 0;
    float moveX = 0;
    float moveY = 0;
    long currentMS = 0;

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                DownX = event.getX();//float DownX
                DownY = event.getY();//float DownY
                moveX = 0;
                moveY = 0;
                currentMS = System.currentTimeMillis();//long currentMS     获取系统时间
                break;
            case MotionEvent.ACTION_MOVE:
                moveX += Math.abs(event.getX() - DownX);//X轴距离
                moveY += Math.abs(event.getY() - DownY);//y轴距离
                DownX = event.getX();
                DownY = event.getY();
                break;
            case MotionEvent.ACTION_UP:
                long moveTime = System.currentTimeMillis() - currentMS;//移动时间
                //判断是否继续传递信号
                if (listener != null&&moveTime < 100 && (moveX < 50 || moveY <50)) {
                        listener.onClick();
                }
        }
        return super.onTouchEvent(event);
    }

    private onWhiteBoardClickListener listener;

    /**
     * 设置 Button 点击监听
     * @param listener
     */
    public void setWhiteBoardClickListener(onWhiteBoardClickListener listener) {
        this.listener = listener;
    }

    /**
     * Button 点击监听
     */
    public interface onWhiteBoardClickListener {


        /**
         * 点击事件
         */
        void onClick();

    }
}
