Commit 1368c1ce authored by Oliver Adams's avatar Oliver Adams

Finished with documentation for private methods.

parent 63938632
......@@ -92,22 +92,23 @@ public class Beeper {
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) {
......
......@@ -47,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() {
......@@ -129,6 +132,7 @@ public class InterleavedPlayer extends Player {
respeaking.release();
}
// Plays the current original segment.
private void playOriginal() {
playSegment(getCurrentOriginalSegment(), original);
}
......@@ -140,6 +144,7 @@ public class InterleavedPlayer extends Player {
return currentOriginalSegment;
}
// Plays the current respeaking segment.
private void playRespeaking() {
playSegment(getCurrentRespeakingSegment(), respeaking);
}
......@@ -148,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);
......@@ -156,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();
......@@ -170,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();
......
......@@ -128,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();
......
......@@ -80,6 +80,7 @@ public class PhoneRespeaker implements
new AverageRecognizer(threshold, threshold));
}
// Prepares the player of the original.
private void setUpPlayer(Recording original) throws IOException {
this.player = new SimplePlayer(original, false);
}
......@@ -127,6 +128,7 @@ public class PhoneRespeaker implements
file.close();
}
// Stops the microphone
private void stopMic() {
try {
microphone.stop();
......@@ -143,11 +145,13 @@ public class PhoneRespeaker implements
file.write(buffer);
}
// Switches from playing to recording
private void switchToRecord() {
player.pause();
mapper.markRespeaking(player, file);
}
// Switches from recording to playing
private void switchToPlay() {
player.play();
}
......
......@@ -107,6 +107,7 @@ public class Recorder implements AudioHandler, MicrophoneListener, Sampler {
return sampleToMsec(getCurrentSample());
}
// Converts a sample value to milliseconds.
private int sampleToMsec(long sample) {
long msec = sample / (microphone.getSampleRate() / 1000);
if (msec > Integer.MAX_VALUE) {
......
......@@ -30,16 +30,10 @@ public class Language implements Parcelable {
*/
private String code;
/**
* Name mutator
*/
private void setName(String name) {
this.name = name;
}
/**
* Code mutator
*/
private void setCode(String code) {
this.code = code;
}
......
......@@ -475,10 +475,7 @@ public class Recording {
.isEquals();
}
/**
* UUID mutator.
*/
// Sets the UUID; it cannot be null.
private void setUUID(UUID uuid) {
if (uuid == null) {
throw new IllegalArgumentException(
......@@ -494,9 +491,7 @@ public class Recording {
this.name = name;
}
/**
* Date mutator.
*/
// Sets the date; the date cannot be null.
private void setDate(Date date) {
if (date == null) {
throw new IllegalArgumentException(
......@@ -505,9 +500,7 @@ public class Recording {
this.date = date;
}
/**
* languages mutator.
*/
// Sets the languages
private void setLanguages(List<Language> languages) {
if (languages == null) {
throw new IllegalArgumentException(
......@@ -531,9 +524,8 @@ public class Recording {
this.languages.add(language);
}
/**
* Speakers mutator.
*/
// Sets the speakers UUID, but won't accept a null list (empty lists are
// fine).
private void setSpeakersUUIDs(List<UUID> speakersUUIDs) {
if (speakersUUIDs == null) {
throw new IllegalArgumentException(
......@@ -557,9 +549,7 @@ public class Recording {
this.speakersUUIDs.add(speaker.getUUID());
}
/**
* androidID mutator
*/
// Sets the android ID but won't accept a null string.
private void setAndroidID(String androidID) {
if (androidID == null) {
throw new IllegalArgumentException(
......@@ -568,23 +558,14 @@ public class Recording {
this.androidID = androidID;
}
/**
* originalUUID mutator.
*/
private void setOriginalUUID(UUID originalUUID) {
this.originalUUID = originalUUID;
}
/**
* sampleRate mutator.
*/
private void setSampleRate(long sampleRate) {
this.sampleRate = sampleRate;
}
/**
* durationMsec mutator.
*/
private void setDurationMsec(int durationMsec) {
this.durationMsec = durationMsec;
}
......
......@@ -69,6 +69,7 @@ public class ServerCredentials {
ipAddress, username, password, syncActivated);
}
// Encodes the server credentials as a JSON object.
private JSONObject encode() {
JSONObject encodedServerCredentials = new JSONObject();
encodedServerCredentials.put("ipAddress", getIPAddress());
......@@ -90,6 +91,7 @@ public class ServerCredentials {
return password;
}
//Sets the IP address but will only accept valid IPv4 addresses.
private void setIPAddress(String ipAddress) {
Pattern pattern = Pattern.compile(IP_ADDRESS_PATTERN);
Matcher matcher = pattern.matcher(ipAddress);
......@@ -100,6 +102,7 @@ public class ServerCredentials {
}
}
// Sets the username, but will not accept empty strings.
private void setUsername(String username) {
if (username.compareTo("") != 0) {
this.username = username;
......
......@@ -268,6 +268,7 @@ public class Speaker implements Parcelable{
* Sets the UUID of the Speaker.
*
* @param uuid A UUID object representing the Speaker's UUID.
* @throws IllegalArgumentException If the speaker UUID is null.
*/
private void setUUID(UUID uuid) throws IllegalArgumentException {
if (uuid == null) {
......@@ -290,6 +291,7 @@ public class Speaker implements Parcelable{
*
* @param languages A List<Language> object representing the languages
* associated with the Speaker.
* @throws IllegalArgumentException If the language list is null
*/
private void setLanguages(List<Language> languages) throws
IllegalArgumentException {
......
......@@ -86,6 +86,7 @@ public class WaveFile {
mFile = file;
}
// Reads the header from the wave file.
private void readHeader() throws IOException {
BufferedInputStream in = new
BufferedInputStream(new FileInputStream(mFile), 44);
......@@ -99,6 +100,7 @@ public class WaveFile {
mHeader = out.toByteArray();
}
// Reads the sample rate from the wave file
private void readSampleRate() {
byte[] sampleRateBytes = Arrays.copyOfRange(mHeader, 24, 28);
ByteBuffer bb = ByteBuffer.wrap(sampleRateBytes);
......@@ -106,6 +108,7 @@ public class WaveFile {
mSampleRate = bb.getInt();
}
// Reads the bits per sample from the wave file
private void readBitsPerSample() {
byte[] bpsBytes = Arrays.copyOfRange(mHeader, 34, 36);
ByteBuffer bb = ByteBuffer.wrap(bpsBytes);
......@@ -113,6 +116,7 @@ public class WaveFile {
mBitsPerSample = bb.getShort();
}
// Reads the number of channels from the wave file
private void readNumChannels() {
byte[] ncBytes = Arrays.copyOfRange(mHeader, 22, 24);
ByteBuffer bb = ByteBuffer.wrap(ncBytes);
......
......@@ -41,19 +41,17 @@ class InterleavedSeekBar extends SeekBar {
paint.setStrokeWidth(2);
paint.setColor(Color.rgb(204, 0, 0));
//lines = new ArrayList<Float>();
//addLine(0.0f);
//addLine(50.0f);
//addLine(100.0f);
drawLines(canvas, paint);
}
// Draws all the lines on the given canvas with the given paint.
private void drawLines(Canvas canvas, Paint paint) {
for(Float line : lines) {
drawLine(line, canvas, paint);
}
}
// Draws a line on the canvas with the given paint
private void drawLine(Float line, Canvas canvas, Paint paint) {
Rect bounds = canvas.getClipBounds();
int barWidth = (bounds.right-16) - (bounds.left+16);
......@@ -62,6 +60,11 @@ class InterleavedSeekBar extends SeekBar {
canvas.drawLine(pixel+16, 0f, pixel+16, 32f, paint);
}
/**
* Adds a line at the specified point in the seek bar.
*
* @param x The place to put the line, as a percentage of the seekbar.
*/
public void addLine(Float x) {
if (x < 0 || x > 100) {
throw new IllegalArgumentException(
......
......@@ -58,6 +58,7 @@ public class ListenActivity extends AikumaActivity {
setUpRecordingInfo();
}
// Prepares the recording
private void setUpRecording() {
Intent intent = getIntent();
UUID recordingUUID = UUID.fromString(
......@@ -74,6 +75,7 @@ public class ListenActivity extends AikumaActivity {
}
}
// Prepares the information pertaining to the recording
private void setUpRecordingInfo() {
setUpRecordingName();
LinearLayout recordingInfoView = (LinearLayout)
......@@ -85,6 +87,8 @@ public class ListenActivity extends AikumaActivity {
}
}
// Prepares the displayed name for the recording (including other things
// such as duration and date.
private void setUpRecordingName() {
TextView nameView = (TextView) findViewById(R.id.recordingName);
TextView dateDurationView =
......@@ -102,6 +106,7 @@ public class ListenActivity extends AikumaActivity {
}
}
// Makes the imageview for a given speaker
private ImageView makeSpeakerImageView(UUID speakerUUID) {
ImageView speakerImage = new ImageView(this);
speakerImage.setAdjustViewBounds(true);
......@@ -116,6 +121,7 @@ public class ListenActivity extends AikumaActivity {
return speakerImage;
}
// Set up the player
private void setUpPlayer() {
try {
if (recording.isOriginal()) {
......@@ -138,6 +144,7 @@ public class ListenActivity extends AikumaActivity {
}
}
// Prepares the iimages for the respeakings.
private void setUpRespeakingImages() {
List<Recording> respeakings;
if (recording.isOriginal()) {
......
......@@ -127,17 +127,20 @@ public class PhoneRespeakFragment extends Fragment {
Log.i("yo", "onDestroy 2");
}
// A safer way to interrupt threads.
private void stopThread(Thread thread) {
if (thread != null) {
thread.interrupt();
}
}
// Pauses the respaking process
private void haltRespeaking() {
respeaker.halt();
stopThread(seekBarThread);
}
// Resumes the respeeaking process.
private void resumeRespeaking() {
respeaker.resume();
seekBarThread = new Thread(new Runnable() {
......
......@@ -72,6 +72,7 @@ public class RecordingArrayAdapter extends ArrayAdapter<Recording> {
* Creates the view for a given speaker.
*
* @param speakerUUID The UUID of the speaker.
* @return The image view for the speaker.
*/
private ImageView makeSpeakerImageView(UUID speakerUUID) {
ImageView speakerImage = new ImageView(context);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment