// Path: app/src/mixedbit/speechtrainer/model/AudioBufferInfo.java
// public interface AudioBufferInfo {
//     /**
//      * @return Unique, increasing with time id of the recorded buffer.
//      */
//     public int getAudioBufferId();
// 
//     /**
//      * @return Sound level of the recorded buffer.
//      */
//     public double getSoundLevel();
// 
//     /**
//      * @return Should this buffer be marked as played? Only the most recently
//      *         played buffers are marked.
//      */
//     public boolean isPlayed();
// }
// 
// Path: app/src/mixedbit/speechtrainer/model/AudioEventHistory.java
// public interface AudioEventHistory {
// 
//     /**
//      * @return The minimum sound level of all recorded buffers. Along with
//      *         getMaxSoundLevel() allows to scale the plot of sound levels.
//      */
//     public double getMinSoundLevel();
// 
//     /**
//      * @return The maximum sound level of all recorded buffers.
//      */
//     public double getMaxSoundLevel();
// 
//     /**
//      * 
//      * @param plotWidth
//      *            How many events can fit on the plot.
//      * @return An iterator pointing at the first event to be plotted. If playing
//      *         is in progress and the first played buffer is outside of the plot
//      *         of recently recorded buffers, the iterator is positioned in such
//      *         a way that the most recently played buffer is in the middle of
//      *         the plot. In all other cases, the iterator points at the most
//      *         recently recorded buffer. The iterator remains valid until the
//      *         next call to the getIteratorOverAudioEventsToPlot.
//      */
//     public Iterator<AudioBufferInfo> getIteratorOverAudioEventsToPlot(int plotWidth);
// 
//     /**
//      * Clears the history of recorded and played buffers. Resets min and max
//      * sound levels.
//      */
//     public void resetHistory();
// }


import java.util.Iterator;
import mixedbit.speechtrainer.model.AudioBufferInfo;
import mixedbit.speechtrainer.model.AudioEventHistory;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.ImageButton;
/**
 * This file is part of Speech Trainer.
 * Copyright (C) 2011 Jan Wrobel <wrr@mixedbit.org>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package mixedbit.speechtrainer.view;



/**
 * Draws a plot with sound levels of recently recorded or played buffers. The
 * data to be plotted is obtained from the AudioEventHistory.
 * 
 * The creator of the AudioEventView must set AudioEventHistory.
 */
public class AudioEventView extends ImageButton {
    private static final int RECORDED_BUFFER_COLOR = 0xffd00000;
    private static final int PLAYED_BUFFER_COLOR = 0xff990000;
    private final Paint recordedBufferPaint;
    private final Paint playedBufferPaint;
    private AudioEventHistory audioEventHistory;

    public AudioEventView(Context context, AttributeSet attrs) {
        super(context, attrs);
        recordedBufferPaint = new Paint();
        recordedBufferPaint.setColor(RECORDED_BUFFER_COLOR);
        playedBufferPaint = new Paint();
        playedBufferPaint.setColor(PLAYED_BUFFER_COLOR);
    }

    /**
     * Must be called before recording or playing is started for the first time.
     * 
     * @param audioEventHistory
     *            Provides a data to be plotted. Not null.
     */
// Path: app/src/mixedbit/speechtrainer/model/AudioBufferInfo.java
// public interface AudioBufferInfo {
//     /**
//      * @return Unique, increasing with time id of the recorded buffer.
//      */
//     public int getAudioBufferId();
// 
//     /**
//      * @return Sound level of the recorded buffer.
//      */
//     public double getSoundLevel();
// 
//     /**
//      * @return Should this buffer be marked as played? Only the most recently
//      *         played buffers are marked.
//      */
//     public boolean isPlayed();
// }
// 
// Path: app/src/mixedbit/speechtrainer/model/AudioEventHistory.java
// public interface AudioEventHistory {
// 
//     /**
//      * @return The minimum sound level of all recorded buffers. Along with
//      *         getMaxSoundLevel() allows to scale the plot of sound levels.
//      */
//     public double getMinSoundLevel();
// 
//     /**
//      * @return The maximum sound level of all recorded buffers.
//      */
//     public double getMaxSoundLevel();
// 
//     /**
//      * 
//      * @param plotWidth
//      *            How many events can fit on the plot.
//      * @return An iterator pointing at the first event to be plotted. If playing
//      *         is in progress and the first played buffer is outside of the plot
//      *         of recently recorded buffers, the iterator is positioned in such
//      *         a way that the most recently played buffer is in the middle of
//      *         the plot. In all other cases, the iterator points at the most
//      *         recently recorded buffer. The iterator remains valid until the
//      *         next call to the getIteratorOverAudioEventsToPlot.
//      */
//     public Iterator<AudioBufferInfo> getIteratorOverAudioEventsToPlot(int plotWidth);
// 
//     /**
//      * Clears the history of recorded and played buffers. Resets min and max
//      * sound levels.
//      */
//     public void resetHistory();
// }


// Path: app/src/mixedbit/speechtrainer/view/AudioEventView.java
import java.util.Iterator;
import mixedbit.speechtrainer.model.AudioBufferInfo;
import mixedbit.speechtrainer.model.AudioEventHistory;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.ImageButton;

/**
 * This file is part of Speech Trainer.
 * Copyright (C) 2011 Jan Wrobel <wrr@mixedbit.org>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package mixedbit.speechtrainer.view;



/**
 * Draws a plot with sound levels of recently recorded or played buffers. The
 * data to be plotted is obtained from the AudioEventHistory.
 * 
 * The creator of the AudioEventView must set AudioEventHistory.
 */
public class AudioEventView extends ImageButton {
    private static final int RECORDED_BUFFER_COLOR = 0xffd00000;
    private static final int PLAYED_BUFFER_COLOR = 0xff990000;
    private final Paint recordedBufferPaint;
    private final Paint playedBufferPaint;
    private AudioEventHistory audioEventHistory;

    public AudioEventView(Context context, AttributeSet attrs) {
        super(context, attrs);
        recordedBufferPaint = new Paint();
        recordedBufferPaint.setColor(RECORDED_BUFFER_COLOR);
        playedBufferPaint = new Paint();
        playedBufferPaint.setColor(PLAYED_BUFFER_COLOR);
    }

    /**
     * Must be called before recording or playing is started for the first time.
     * 
     * @param audioEventHistory
     *            Provides a data to be plotted. Not null.
     */
    public void setAudioEventHistory(AudioEventHistory audioEventHistory) {