package com.fxy.common;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.fxy.R;
import com.fxy.base.BasePopupWindow;
import com.fxy.utils.ProgressTextUtils;

/**
 * Created by MarioStudio on 2016/5/12.
 */

public class AudioRecoderDialog extends BasePopupWindow {

    private ImageView imageView;
    private TextView textView;

    public AudioRecoderDialog(Context context) {
        super(context);
        View contentView = LayoutInflater.from(context).inflate(R.layout.audio_recoder_dialog, null);
        imageView = (ImageView) contentView.findViewById(android.R.id.progress);
        textView = (TextView) contentView.findViewById(android.R.id.text1);
        setContentView(contentView);
    }

    public void setLevel(int level) {
        Drawable drawable = imageView.getDrawable();
        drawable.setLevel(3000 + 6000 * level / 100);
    }

    public void setTime(long time) {
        textView.setText(ProgressTextUtils.getProgressText(time));
    }


    @Override
    public void dismiss() {

        // 通过接口对象传上传状态
        if (callbackListener!=null){
            callbackListener.closeResult();
        }

    }
    // 持有一个接口对象
    AudioRecoderDialog.CallbackListener callbackListener;

    // 状态变化监听
    public interface CallbackListener {
        // 回调方法 可以多个
        void closeResult();
    }
    // 提供注册事件监听的方法
    public void setOnCallbackListener(AudioRecoderDialog.CallbackListener callbackListener) {
        this.callbackListener = callbackListener;
    }
}
