Commit 1c9acd0e authored by Oliver Adams's avatar Oliver Adams

Merge branch 'checkstyle'

parents 54ab5320 1368c1ce
......@@ -11,11 +11,13 @@
<property name="scope" value="public"/>
<property name="authorFormat" value="\S"/>
</module>
<!--
<module name="JavadocMethod">
<property name="scope" value="private"/>
<property name="scope" value="protected"/>
<property name="allowMissingPropertyJavadoc" value="true"/>
</module>
<module name="JavadocVariable">
<property name="scope" value="protected"/>
</module>
-->
<module name="AvoidStarImport"/>
<module name="ConstantName"/>
<!--
......
<?xml version="1.0" encoding="UTF-8"?>
<project name="custom_rules">
<taskdef resource="checkstyletask.properties"
classpath="checkstyle/checkstyle-5.6-all.jar"/>
<checkstyle config="checkstyle/checks.xml">
<fileset dir="src/" includes="**/*.java"/>
</checkstyle>
<target name="checkstyle">
<taskdef resource="checkstyletask.properties"
classpath="checkstyle/checkstyle-5.6-all.jar"/>
<checkstyle config="checkstyle/checks.xml">
<fileset dir="src/" includes="**/*.java"/>
</checkstyle>
</target>
</project>
......@@ -68,16 +68,6 @@
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
<!--
<ToggleButton
android:id="@+id/phoneRespeaking"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:textOn="Phone respeak on"
android:textOff="Phone respeak off"
android:onClick="onPhoneRespeakingToggle"
/> -->
<Button
android:id="@+id/thumbRespeaking"
android:text="@string/thumb_respeaking"
......
......@@ -9,7 +9,6 @@
android:layout_width="wrap_content"
android:layout_height="32dp"
android:src="@drawable/play"
android:onClick="play"
android:background="@null"
/>
<view class="org.lp20.aikuma.ui.InterleavedSeekBar"
......
......@@ -27,16 +27,27 @@ public class Aikuma extends android.app.Application {
private static Aikuma instance;
private static List<Language> languages;
/**
* The constructor.
*/
public Aikuma() {
instance = this;
}
/**
* Static method that provides a context when needed by code not bound to
* any meaningful context.
*
* @return A Context
*/
public static Context getContext() {
return instance;
}
/**
* Gets the android ID of the phone.
*
* @return The android ID as a String.
*/
public static String getAndroidID() {
return Secure.getString(
......@@ -79,6 +90,10 @@ public class Aikuma extends android.app.Application {
}
}
/**
* The thread used to load the language codes without interrupting the
* main thread.
*/
public static Thread loadLangCodesThread;
}
......
......@@ -57,7 +57,6 @@ import org.lp20.aikuma.model.WaveFile;
*/
public class MainActivity extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
......@@ -93,10 +92,6 @@ public class MainActivity extends ListActivity {
setListAdapter(adapter);
}
/**
* When a recording item in the list is clicked, start the ListenActivity
* and send the relevant UUID through.
*/
@Override
public void onListItemClick(ListView l, View v, int position, long id){
Recording recording = (Recording) getListAdapter().getItem(position);
......@@ -116,7 +111,7 @@ public class MainActivity extends ListActivity {
/**
* Called when the import button is pressed; starts the import process.
*
* @param view the audio import button.
* @param _view the audio import button.
*/
public void audioImport(View _view) {
mPath = Environment.getExternalStorageDirectory();
......
......@@ -17,29 +17,48 @@ import android.media.AudioManager;
* @author Florian Hanke <florian.hanke@gmail.com>
*/
public class Audio {
/**
* Resets the activity playing through the main speakers.
*
* @param activity The activity in question.
*/
public static void reset(Activity activity) {
playThroughSpeaker(activity);
}
/**
* Plays the audio through the earpiece, like a phone call.
*
* @param activity The activity that this method governs.
* @param toSetMode True if the Audiomanager needs to be set to call mode.
*/
public static void playThroughEarpiece(Activity activity, boolean toSetMode) {
AudioManager audioManager = getAudioManager(activity);
if (toSetMode) {
audioManager.setMode(AudioManager.MODE_IN_CALL);
}
Log.i("speaker", "setting it off");
audioManager.setSpeakerphoneOn(false);
Log.i("speaker", "set it off. isSpeakerphoneOn: " + audioManager.isSpeakerphoneOn());
}
/**
* Plays the audio through the main speaker (not the earpiece as a phone
* call would)
*
* @param activity The activity that this method governs.
*/
public static void playThroughSpeaker(Activity activity) {
AudioManager audioManager = getAudioManager(activity);
audioManager.setMode(AudioManager.MODE_NORMAL);
Log.i("speaker", "setting it on");
audioManager.setSpeakerphoneOn(true);
Log.i("speaker", "set it on. isSpeakerphoneOn: " + audioManager.isSpeakerphoneOn());
}
/**
* Gets the audio manager for the given activity.
*
* @param activity The activity whose AudioManager is needed.
* @return The audiomanager.
*/
protected static AudioManager getAudioManager(Activity activity) {
return (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
}
......
......@@ -26,50 +26,89 @@ public class Beeper {
private MediaPlayer beep;
private MediaPlayer beepBeep;
/**
* Constructor
*
* @param context The context that the Beeper should beep in.
*/
public Beeper(Context context) {
this.context = context;
}
/**
* Plays one beep.
*/
public void beep() { beep(null); }
/**
* Plays one beep.
*
* @param listener The callback to play when the beep is complete.
*/
public void beep(OnCompletionListener listener) {
getBeep(listener).start();
}
/**
* Plays two beeps in succession.
*/
public void beepBeep() { beepBeep(null); }
/**
* Plays two beeps in succession.
*
* @param listener The callback to play when the beep is complete.
*/
public void beepBeep(OnCompletionListener listener) {
getBeepBeep(listener).start();
}
/** Static convenience methods */
/**
* Plays one beep.
*
* @param context The context to play the beep in
* @param listener The callback to play when the beep is complete.
*/
public static void beep(Context context, OnCompletionListener listener) {
start(context, listener, R.raw.beep);
}
/**
* Plays two beeps in succession.
*
* @param context The context to play the beep in
* @param listener The callback to play when the beep is complete.
*/
public static void beepBeep(Context context, OnCompletionListener listener) {
start(context, listener, R.raw.beeps2);
}
/**
* Plays a long beep.
*
* @param context The context to play the beep in
* @param listener The callback to play when the beep is complete.
*/
public static void longBeep(Context context, OnCompletionListener listener) {
start(context, listener, R.raw.longbeep);
}
// Starts playing the given audio resource.
private static void start(Context context, final OnCompletionListener listener, int resource) {
new Beeper(context).create(listener, resource).start();
}
/** Private methods */
// Gets a mediaplayer that plays a beep.
private MediaPlayer getBeep(final OnCompletionListener listener) {
return create(listener, R.raw.beep);
}
// Gets a mediaplayer that plays two beeps in succession
private MediaPlayer getBeepBeep(final OnCompletionListener listener) {
Log.i("beep", "beepin");
return create(listener, R.raw.beeps2);
}
// Creates a mediaplayer to play the beeps with.
private MediaPlayer create(final OnCompletionListener listener, int resource) {
final MediaPlayer beeper = MediaPlayer.create(context, resource);
if (listener != null) {
......
......@@ -28,6 +28,7 @@ public class InterleavedPlayer extends Player {
* original
*
* @param recording The metadata of the recording to play.
* @throws IOException If there is an issue reading the recordings.
*/
public InterleavedPlayer(Recording recording) throws IOException {
setRecording(recording);
......@@ -46,6 +47,9 @@ public class InterleavedPlayer extends Player {
completedOnce = false;
}
// Initializes the completion listeners for the original and respeaking,
// such that when one of them completes the InterleavedPlayer's
// onCompletionListener is run, only once.
private void initializeCompletionListeners() {
Player.OnCompletionListener bothCompletedListener = new
Player.OnCompletionListener() {
......@@ -67,10 +71,17 @@ public class InterleavedPlayer extends Player {
respeaking.setOnCompletionListener(bothCompletedListener);
}
/**
* Resumes playing the interleaved recording, from the original segment
* where it was last paused.
*/
public void play() {
playOriginal();
}
/**
* Resets the player to the beginning.
*/
public void reset() {
originalSegmentIterator = null;
currentOriginalSegment = null;
......@@ -78,7 +89,11 @@ public class InterleavedPlayer extends Player {
respeaking.seekToSample(0l);
}
/** Indicates whether the recording is currently being played. */
/**
* Indicates whether the recording is currently being played.
*
* @return true if the recording is currently playing; false otherwise.
*/
public boolean isPlaying() {
return original.isPlaying() || respeaking.isPlaying();
}
......@@ -93,12 +108,20 @@ public class InterleavedPlayer extends Player {
}
}
/** Get current point in the recording in milliseconds. */
/**
* Get current point in the recording in milliseconds.
*
* @return The current point in the recording in milliseconds as an int.
*/
public int getCurrentMsec() {
return original.getCurrentMsec();
}
/** Get the duration of the recording in milliseconds. */
/**
* Get the duration of the recording in milliseconds.
*
* @return The duration of the recording in milliseconds as an int.
*/
public int getDurationMsec() {
return original.getDurationMsec();
}
......@@ -109,6 +132,7 @@ public class InterleavedPlayer extends Player {
respeaking.release();
}
// Plays the current original segment.
private void playOriginal() {
playSegment(getCurrentOriginalSegment(), original);
}
......@@ -120,6 +144,7 @@ public class InterleavedPlayer extends Player {
return currentOriginalSegment;
}
// Plays the current respeaking segment.
private void playRespeaking() {
playSegment(getCurrentRespeakingSegment(), respeaking);
}
......@@ -128,6 +153,7 @@ public class InterleavedPlayer extends Player {
return segments.getRespeakingSegment(getCurrentOriginalSegment());
}
// Plays the specified segment in the specified player.
private void playSegment(Segment segment, MarkedPlayer player) {
if (segment != null) {
player.seekTo(segment);
......@@ -136,6 +162,7 @@ public class InterleavedPlayer extends Player {
}
}
// Moves forward to the next original segment in the recording.
private void advanceOriginalSegment() {
if (getOriginalSegmentIterator().hasNext()) {
currentOriginalSegment = getOriginalSegmentIterator().next();
......@@ -150,6 +177,7 @@ public class InterleavedPlayer extends Player {
}
}
// Gets an iterator over the segments of the original recording.
private Iterator<Segment> getOriginalSegmentIterator() {
if (originalSegmentIterator == null) {
originalSegmentIterator = segments.getOriginalSegmentIterator();
......@@ -204,6 +232,11 @@ public class InterleavedPlayer extends Player {
}
}
/**
* Gets the sample rate of this player.
*
* @return The sample rate of the player as a long.
*/
public long getSampleRate() {
//If the sample rate is less than zero, then this indicates that there
//wasn't a sample rate found in the metadata file.
......@@ -218,6 +251,12 @@ public class InterleavedPlayer extends Player {
this.sampleRate = sampleRate;
}
/**
* Converts samples to milliseconds assuming this players sample rate
*
* @param sample A sample value to be converted
* @return The value in milliseconds as an int.
*/
public int sampleToMsec(long sample) {
long msec = sample / (getSampleRate() / 1000);
if (msec > Integer.MAX_VALUE) {
......@@ -226,19 +265,25 @@ public class InterleavedPlayer extends Player {
return (int) msec;
}
private static boolean completedOnce = false;
private long sampleRate;
//////////////////////////////////////////////////////////////////////////
/** Seek to a given point in the recording in milliseconds. */
/**
* Seek to a given point in the recording in milliseconds.
*
* @param msec The point in the recording to seek to in milliseconds.
*/
public void seekToMsec(int msec) {
original.seekToMsec(msec);
}
/** Set the callback to be run when the recording completes playing. */
/**
* Set the callback to be run when the recording completes playing.
*
* @param listener The callback to call when playing is complete.
*/
public void setOnCompletionListener(
final Player.OnCompletionListener listener) {
this.onCompletionListener = listener;
}
private static boolean completedOnce = false;
private long sampleRate;
}
......@@ -18,6 +18,15 @@ import org.lp20.aikuma.model.Segments.Segment;
*/
public class MarkedPlayer extends SimplePlayer {
/**
* Constructor
*
* @param recording The metadata of the recording to be played.
* @param listener The callback to call when a marker is reached.
* @param playThroughSpeaker True if the audio is to be played through the main
* speaker; false if through the ear piece (ie the private phone call style)
* @throws IOException If there is an issue reading from the data source.
*/
public MarkedPlayer(Recording recording, OnMarkerReachedListener listener,
boolean playThroughSpeaker) throws IOException {
super(recording, playThroughSpeaker);
......@@ -47,21 +56,34 @@ public class MarkedPlayer extends SimplePlayer {
this.notificationMarkerPosition = notificationMarkerPosition;
}
/** Sets the notification marker to be at the end of the supplied segment */
/**
* Sets the notification marker to be at the end of the supplied segment
*
* @param segment The segment whose end is to be marked.
*/
public void setNotificationMarkerPosition(Segment segment) {
setNotificationMarkerPositionMsec(
sampleToMsec(segment.getEndSample()));
}
/**
* Removes the marker if it has been set.
*/
public void unsetNotificationMarkerPosition() {
setNotificationMarkerPositionMsec(-1);
}
@Override
public void release() {
super.release();
stopNotificationMarkerLoop();
}
/**
* Seeks to the beginning of the given segment.
*
* @param segment The segment to seek to.
*/
public void seekTo(Segment segment) {
super.seekToSample(segment.getStartSample());
}
......@@ -71,9 +93,15 @@ public class MarkedPlayer extends SimplePlayer {
* reached.
*/
public static abstract class OnMarkerReachedListener {
/**
* The method to be called when the set marker is reached.
*
* @param p The marked player whose marker has been reached.
*/
public abstract void onMarkerReached(MarkedPlayer p);
}
@Override
public void setOnCompletionListener(final OnCompletionListener listener) {
super.setOnCompletionListener(
new Player.OnCompletionListener() {
......@@ -100,6 +128,7 @@ public class MarkedPlayer extends SimplePlayer {
/** The listener that is notified when a set marker is reached */
private OnMarkerReachedListener onMarkerReachedListener;
// Stops the notification marker loop.
private void stopNotificationMarkerLoop() {
if (notificationMarkerLoop != null) {
notificationMarkerLoop.interrupt();
......
......@@ -12,23 +12,47 @@ package org.lp20.aikuma.audio;
*/
public abstract class Player {
/** The class that is to be implemented that is given to a Player and has
/**
* The class that is to be implemented that is given to a Player and has
* it's onCompletion method run when the player completes playing a
* recording. */
* recording.
*/
public static abstract class OnCompletionListener {
/**
* The method called when the player gets to completion.
*
* @param player The player
*/
public abstract void onCompletion(Player player);
}
/** Set the callback to be run when the recording completes playing. */
/**
* Set the callback to be run when the recording completes playing.
*
* @param listener The callback to be invoked
*/
public abstract void setOnCompletionListener(OnCompletionListener listener);
/** Get the duration of the recording in milliseconds. */
/**
* Get the duration of the recording in milliseconds.
*
* @return The duration of the recording in milliseconds.
**/
public abstract int getDurationMsec();
/** Seek to a given point in the recording in milliseconds. */
/**
* Seek to a given point in the recording in milliseconds.
*
* @param msec The point in the recording to seek to (milliseconds).
*/
public abstract void seekToMsec(int msec);
/** Indicates whether the recording is currently being played. */
/**
* Indicates whether the recording is currently being played.
*
* @return true if recording is being played; false otherwise.
*/
public abstract boolean isPlaying();
/** Pauses the playback. */
......@@ -37,12 +61,24 @@ public abstract class Player {
/** Starts or resumes playback of the recording. */
public abstract void play();
/** Get current point in the recording in milliseconds. */
/**
* Get current point in the recording in milliseconds.
*
* @return The current position in milliseconds as an integer.
*/
public abstract int getCurrentMsec();
/** Releases resources associated with the player */
/**
* Releases resources associated with the player
*/
public abstract void release();
/**
* Converts a sample to milliseconds.
*
* @param sample The sample.
* @return The milliseconds as an integer.
*/
public abstract int sampleToMsec(long sample);
}
......@@ -12,11 +12,12 @@ package org.lp20.aikuma.audio;
* @author Oliver Adams <oliver.adams@gmail.com>
*/
public class Processor {
/** Evaluates the average amplitude.
*
* @return Average amplitude of the buffer.
*/
/** Evaluates the average amplitude.
*
* @param buffer The buffer containing the audio data.
* @return Average amplitude of the buffer.
*/
public int getAverage(short[] buffer) {
int sum = 0;
int amount = 0;
......
......@@ -28,6 +28,13 @@ public class Segments {
private Segment finalOriginalSegment;
private UUID respeakingUUID;
/**
* Creates a Segment mapping based on what it finds in the mapping file
* corresponding to the supplied UUID.
*
* @param respeakingUUID The UUID of the respeaking whose mapping is to
* be read.
*/
public Segments(UUID respeakingUUID) {
this();
this.respeakingUUID = respeakingUUID;
......@@ -39,14 +46,32 @@ public class Segments {
//Issue with reading mapping. Maybe throw an exception?
}
}
/**
* Constructor; creates an empty Segments.
*/
public Segments() {
segmentMap = new LinkedHashMap<Segment, Segment>();
}
/**
* Gets the respeaking segment that corresponds to the given original
* segment.
*
* @param originalSegment The segment of the original whose corresponding
* respeaking segment is required.
* @return The corresponding respeaking segment.
*/
public Segment getRespeakingSegment(Segment originalSegment) {
return segmentMap.get(originalSegment);
}
/**
* Adds a segment pair to the segments.
*
* @param originalSegment A segment from the original audio source.
* @param respeakingSegment A segment from the respeaking audio source.
*/
public void put(Segment originalSegment,
Segment respeakingSegment) {
segmentMap.put(originalSegment, respeakingSegment);
......@@ -56,7 +81,14 @@ public class Segments {