// Path: chat-message-adapter/src/main/java/com/quickblox/ui/kit/chatmessage/adapter/media/recorder/exceptions/MediaRecorderException.java
// public class MediaRecorderException extends Exception {
// 
//     public MediaRecorderException(String s) {
//         super(s);
//     }
// }
// 
// Path: chat-message-adapter/src/main/java/com/quickblox/ui/kit/chatmessage/adapter/media/recorder/listeners/QBMediaRecordListener.java
// public interface QBMediaRecordListener {
// 
//     void onMediaRecorded(File file);
// 
//     void onMediaRecordError(MediaRecorderException e);
// 
//     void onMediaRecordClosed();
// }
// 
// Path: chat-message-adapter/src/main/java/com/quickblox/ui/kit/chatmessage/adapter/media/recorder/model/QBMediaRecorder.java
// public abstract class QBMediaRecorder<T> {
// 
//     public abstract void startRecord();
// 
//     public abstract void stopRecord();
// 
//     public abstract void cancelRecord();
// }


import android.content.Context;
import android.media.MediaRecorder;
import android.util.Log;
import com.quickblox.ui.kit.chatmessage.adapter.media.recorder.exceptions.MediaRecorderException;
import com.quickblox.ui.kit.chatmessage.adapter.media.recorder.listeners.QBMediaRecordListener;
import com.quickblox.ui.kit.chatmessage.adapter.media.recorder.model.QBMediaRecorder;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
package com.quickblox.ui.kit.chatmessage.adapter.media.recorder;






/**
 * Created by roman on 7/26/17.
 */

public class AudioRecorder extends QBMediaRecorder<AudioRecorder> {
    private static final String TAG = AudioRecorder.class.getSimpleName();

    private QBMediaRecordListener recordListener;
    private MediaRecorder recorder = null;
    private RecordState state = RecordState.RECORD_STATE_UNKNOWN;
    private ConfigurationBuilder configurationBuilder;

    private AudioRecorder() {
    }

    public static ConfigurationBuilder newBuilder() {
        return new AudioRecorder().new ConfigurationBuilder();
    }

    @Override
    public void startRecord() {
        setState(RecordState.RECORD_STATE_BEGIN);
        initMediaRecorder();
        prepareStartMediaRecorder();
    }

    @Override
    public void cancelRecord() {
        stopAndReleaseMediaRecorder();
        setState(RecordState.RECORD_STATE_UNKNOWN);
        if (recordListener != null) {
            recordListener.onMediaRecordClosed();
        }
    }

    @Override
    public void stopRecord() {
// Path: chat-message-adapter/src/main/java/com/quickblox/ui/kit/chatmessage/adapter/media/recorder/exceptions/MediaRecorderException.java
// public class MediaRecorderException extends Exception {
// 
//     public MediaRecorderException(String s) {
//         super(s);
//     }
// }
// 
// Path: chat-message-adapter/src/main/java/com/quickblox/ui/kit/chatmessage/adapter/media/recorder/listeners/QBMediaRecordListener.java
// public interface QBMediaRecordListener {
// 
//     void onMediaRecorded(File file);
// 
//     void onMediaRecordError(MediaRecorderException e);
// 
//     void onMediaRecordClosed();
// }
// 
// Path: chat-message-adapter/src/main/java/com/quickblox/ui/kit/chatmessage/adapter/media/recorder/model/QBMediaRecorder.java
// public abstract class QBMediaRecorder<T> {
// 
//     public abstract void startRecord();
// 
//     public abstract void stopRecord();
// 
//     public abstract void cancelRecord();
// }


// Path: chat-message-adapter/src/main/java/com/quickblox/ui/kit/chatmessage/adapter/media/recorder/AudioRecorder.java
import android.content.Context;
import android.media.MediaRecorder;
import android.util.Log;
import com.quickblox.ui.kit.chatmessage.adapter.media.recorder.exceptions.MediaRecorderException;
import com.quickblox.ui.kit.chatmessage.adapter.media.recorder.listeners.QBMediaRecordListener;
import com.quickblox.ui.kit.chatmessage.adapter.media.recorder.model.QBMediaRecorder;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

package com.quickblox.ui.kit.chatmessage.adapter.media.recorder;






/**
 * Created by roman on 7/26/17.
 */

public class AudioRecorder extends QBMediaRecorder<AudioRecorder> {
    private static final String TAG = AudioRecorder.class.getSimpleName();

    private QBMediaRecordListener recordListener;
    private MediaRecorder recorder = null;
    private RecordState state = RecordState.RECORD_STATE_UNKNOWN;
    private ConfigurationBuilder configurationBuilder;

    private AudioRecorder() {
    }

    public static ConfigurationBuilder newBuilder() {
        return new AudioRecorder().new ConfigurationBuilder();
    }

    @Override
    public void startRecord() {
        setState(RecordState.RECORD_STATE_BEGIN);
        initMediaRecorder();
        prepareStartMediaRecorder();
    }

    @Override
    public void cancelRecord() {
        stopAndReleaseMediaRecorder();
        setState(RecordState.RECORD_STATE_UNKNOWN);
        if (recordListener != null) {
            recordListener.onMediaRecordClosed();
        }
    }

    @Override
    public void stopRecord() {
        stopAndReleaseMediaRecorder();