package com.tofly.ghrq_route.common.ui.view;

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

import com.gaoyuan.weixinrecord.manager.AudioManager;
import com.gaoyuan.weixinrecord.manager.AudioRecordButton;
import com.tofly.ghrq_route.common.util.file.FileUtil;

/**
 * Created by Amu on 2017/4/6.
 */

public class MyAudioRecordButton extends AudioRecordButton {
    //水平方向滑动取消的临界距离
    private static final int DISTANCE_X_CANCEL = 200;
    //垂直方向滑动取消的临界距离
    private static final int DISTANCE_Y_CANCEL = 100;

    public MyAudioRecordButton(Context context) {
        this(context, null);
    }

    public MyAudioRecordButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        String fileDir = FileUtil.tempFileDir();
        AudioManager.setAudioDirPath(fileDir);
    }

    private boolean wantToCancel(int x, int y) {
        if (x <  DISTANCE_X_CANCEL || x > getWidth() - DISTANCE_X_CANCEL) {// 判断是否在左边，右边，上边，下边
            return true;
        }
        if (y < -DISTANCE_Y_CANCEL || y > getHeight() + DISTANCE_Y_CANCEL) {
            return true;
        }

        return false;
    }

   /*@Override
    protected void onDraw(Canvas canvas) {
        Drawable[] drawables = getCompoundDrawables();
        if (drawables != null) {
            Drawable drawableLeft = drawables[0];
            if (drawableLeft != null) {
                float textWidth = getPaint().measureText(getText().toString());
                int drawablePadding = getCompoundDrawablePadding();
                int drawableWidth = drawableLeft.getIntrinsicWidth();
                float bodyWidth = textWidth + drawableWidth + drawablePadding;
                int leftPadding = (int)(getWidth() - bodyWidth);
                setPadding(0, 0, leftPadding, 0);
                canvas.translate((getWidth() - bodyWidth) / 2, 0);
            }
        }
        super.onDraw(canvas);
    }*/
}
