From 01f78b505db0090125c34b9b8ec6f77ad8750df4 Mon Sep 17 00:00:00 2001 From: sigotron Date: Fri, 22 May 2015 11:39:07 -0700 Subject: [PATCH 01/15] fixed bug where shouldn't try to play all when record and no previous tracks exist --- .../sloths/speedy/shortsounds/controller/ModelControl.java | 6 ++++-- .../com/sloths/speedy/shortsounds/model/AudioPlayer.java | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/sloths/speedy/shortsounds/controller/ModelControl.java b/app/src/main/java/com/sloths/speedy/shortsounds/controller/ModelControl.java index f102679..9014bcf 100644 --- a/app/src/main/java/com/sloths/speedy/shortsounds/controller/ModelControl.java +++ b/app/src/main/java/com/sloths/speedy/shortsounds/controller/ModelControl.java @@ -60,8 +60,10 @@ public boolean onPlayToggle() { @Override public void onRecordStart() { // main.onRecordStart(); - if (mAudioPlayer != null) - mAudioPlayer.playAll( 0 ); // Play from the beginning + if (mAudioPlayer != null) { + Log.d("Debug", "onRecordStart() playALL!!!"); + mAudioPlayer.playAll(0); // Play from the beginning + } // Setup the MediaRecorder mAudioRecorder.start(); } diff --git a/app/src/main/java/com/sloths/speedy/shortsounds/model/AudioPlayer.java b/app/src/main/java/com/sloths/speedy/shortsounds/model/AudioPlayer.java index 3ca9376..3d2bcee 100644 --- a/app/src/main/java/com/sloths/speedy/shortsounds/model/AudioPlayer.java +++ b/app/src/main/java/com/sloths/speedy/shortsounds/model/AudioPlayer.java @@ -80,6 +80,7 @@ public void playAll( int position ) { entry.getValue().stop(); if (position == 0) { + Log.d(DEBUG_TAG,"play position 0"); entry.getValue().play(position); } else { ShortSoundTrack currentTrack = entry.getKey(); From 0b09a4fb1ccac6376a1d144859b716c059fc4d76 Mon Sep 17 00:00:00 2001 From: sigotron Date: Fri, 22 May 2015 11:49:21 -0700 Subject: [PATCH 02/15] disable seekbar while recording --- .../java/com/sloths/speedy/shortsounds/view/MainActivity.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/com/sloths/speedy/shortsounds/view/MainActivity.java b/app/src/main/java/com/sloths/speedy/shortsounds/view/MainActivity.java index ea3d304..9341c64 100644 --- a/app/src/main/java/com/sloths/speedy/shortsounds/view/MainActivity.java +++ b/app/src/main/java/com/sloths/speedy/shortsounds/view/MainActivity.java @@ -182,9 +182,11 @@ public void onCheckedChanged(FloatingActionButton fabView, boolean isChecked) { if ( !isChecked ) { endRecording(); setPlayerVisibility(View.VISIBLE); + mGlobalSeekBar.setEnabled(true); } else { mGlobalPlayButton.setEnabled(false); modelControl.onRecordStart(); + mGlobalSeekBar.setEnabled(false); } } }); From 7c323d9a998f5a145d19c2b092667032d779896a Mon Sep 17 00:00:00 2001 From: sigotron Date: Fri, 22 May 2015 11:54:32 -0700 Subject: [PATCH 03/15] will just pause when people update seekbar for now --- .../speedy/shortsounds/controller/ModelControl.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/sloths/speedy/shortsounds/controller/ModelControl.java b/app/src/main/java/com/sloths/speedy/shortsounds/controller/ModelControl.java index 9014bcf..7e51786 100644 --- a/app/src/main/java/com/sloths/speedy/shortsounds/controller/ModelControl.java +++ b/app/src/main/java/com/sloths/speedy/shortsounds/controller/ModelControl.java @@ -101,12 +101,12 @@ public void updateCurrentPosition(int position) { if (!mAudioRecorder.isRecording()) { mAudioPlayer.stopAll(); } - boolean isOkToPlayAllWithNewPosition = mAudioPlayer.isPlayingAll() && !mAudioRecorder.isRecording(); - if (isOkToPlayAllWithNewPosition) { - // TODO: This scenario is super buggy - //mAudioPlayer.stopAll(); - //mAudioPlayer.playAll(this.seekBarPosition); - } +// boolean isOkToPlayAllWithNewPosition = mAudioPlayer.isPlayingAll() && !mAudioRecorder.isRecording(); +// if (isOkToPlayAllWithNewPosition) { +// // TODO: This scenario is super buggy +// mAudioPlayer.stopAll(); +// mAudioPlayer.playAll(this.seekBarPosition); +// } } } From 0f05b5999a56d16f2e5cb37123264be8974063db Mon Sep 17 00:00:00 2001 From: Neil Date: Fri, 22 May 2015 12:45:28 -0700 Subject: [PATCH 04/15] added mattie's fix for the sharing --- .../speedy/shortsounds/model/AudioMixer.java | 2 +- .../speedy/shortsounds/view/MainActivity.java | 24 ++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/sloths/speedy/shortsounds/model/AudioMixer.java b/app/src/main/java/com/sloths/speedy/shortsounds/model/AudioMixer.java index debf513..a594caa 100644 --- a/app/src/main/java/com/sloths/speedy/shortsounds/model/AudioMixer.java +++ b/app/src/main/java/com/sloths/speedy/shortsounds/model/AudioMixer.java @@ -71,7 +71,7 @@ private byte[] mixByteArrays(List chunksToMix) { for (int i = 0; i < 1024; i++) { long mixedByte = 0; for (int j = 0; j < chunksToMix.size(); j++) { - mixedByte+= chunksToMix.get(i)[j]; + mixedByte+= chunksToMix.get(j)[i]; } // Hard cap if ( mixedByte > Byte.MAX_VALUE ) diff --git a/app/src/main/java/com/sloths/speedy/shortsounds/view/MainActivity.java b/app/src/main/java/com/sloths/speedy/shortsounds/view/MainActivity.java index ea3d304..d2e6f23 100644 --- a/app/src/main/java/com/sloths/speedy/shortsounds/view/MainActivity.java +++ b/app/src/main/java/com/sloths/speedy/shortsounds/view/MainActivity.java @@ -42,6 +42,7 @@ import com.sloths.speedy.shortsounds.model.ShortSound; import com.sloths.speedy.shortsounds.model.ShortSoundTrack; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -437,6 +438,11 @@ private void selectShortSoundFromDrawer(int position) { } // selected mix is already loaded so close the drawer + try { + mShareActionProvider.setShareIntent(createShareIntent()); + } catch (IOException e) { + mShareActionProvider.setShareIntent(null); + } mDrawerLayout.closeDrawer(mDrawerList); } @@ -608,7 +614,6 @@ public boolean onCreateOptionsMenu(Menu menu) { MenuItem shareItem = menu.findItem(R.id.action_share); // Fetch and store ShareActionProvider mShareActionProvider = (ShareActionProvider) shareItem.getActionProvider(); - mShareActionProvider.setShareIntent(createShareIntent()); return true; } @@ -616,17 +621,20 @@ public boolean onCreateOptionsMenu(Menu menu) { * Specifies the share intent * @return the share Intent */ - private Intent createShareIntent() { + private Intent createShareIntent() throws IOException { + if (mActiveShortSound == null) { + return null; + } Intent shareIntent = new Intent(Intent.ACTION_SEND); - File absolutePath = new File(getFilesDir(), "ss1-track1.mp3"); + File absolutePath = mActiveShortSound.generateAudioFile(); + Uri contentURI = FileProvider.getUriForFile(MainActivity.this, "com.sloths.speedy.shortsounds.fileprovider", absolutePath); if (contentURI != null) { shareIntent.putExtra(Intent.EXTRA_STREAM, contentURI); - shareIntent.setType("audio/mpeg3"); + shareIntent.setType("audio/wav"); shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } - return shareIntent; } @@ -733,11 +741,15 @@ private void endRecording() { R.layout.drawer_list_item, mShortSoundsTitles)); // Select the new ShortSound to be active. selectShortSoundFromDrawer(sounds.size() - 1); - } else { // Update the existing fragment manager to add new track to list TrackView tv = ((TrackView) findViewById(R.id.track_list)); tv.notifyTrackAdded(mActiveShortSound.getTracks().size() - 1); + try { + mShareActionProvider.setShareIntent(createShareIntent()); + } catch (IOException e) { + mShareActionProvider.setShareIntent(null); + } } } From 583d4a2749569a75e4bee2b173c14157f3563ffd Mon Sep 17 00:00:00 2001 From: jbuscher Date: Fri, 22 May 2015 12:50:04 -0700 Subject: [PATCH 05/15] Updating tests, namely audioPlayerTest --- app/build.gradle | 1 + .../shortsounds/tests/AudioMixerTest.java | 20 ++++++++++ .../shortsounds/tests/AudioPlayerTest.java | 37 +++++++++++++++++-- .../speedy/shortsounds/tests/EffectTest.java | 23 ++++++++++-- ...Test.java => MainActivityContentTest.java} | 26 ++++++++++--- .../tests/ShortSoundTrackTest.java | 2 +- .../speedy/shortsounds/model/AudioMixer.java | 9 +++++ 7 files changed, 105 insertions(+), 13 deletions(-) create mode 100644 app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/AudioMixerTest.java rename app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/{MainActivityTest.java => MainActivityContentTest.java} (57%) diff --git a/app/build.gradle b/app/build.gradle index 83fed11..6aac934 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -39,6 +39,7 @@ dependencies { compile 'com.jjoe64:graphview:4.0.1' // Set this dependency to build and run Espresso tests //androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1' + //androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.0' //androidTestCompile 'com.android.support.test:testing-support-lib:0.1' // Set this dependency to build and run UI Automator tests //androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.0' diff --git a/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/AudioMixerTest.java b/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/AudioMixerTest.java new file mode 100644 index 0000000..cbfe07d --- /dev/null +++ b/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/AudioMixerTest.java @@ -0,0 +1,20 @@ +package com.sloths.speedy.shortsounds.tests; + +import com.sloths.speedy.shortsounds.model.AudioMixer; +import com.sloths.speedy.shortsounds.model.ShortSound; + +import junit.framework.TestCase; + +/** + * Created by jbusc_000 on 5/21/2015. + */ +public class AudioMixerTest extends TestCase { + + public void testConstructor() { + ShortSound ss = new ShortSound(); + AudioMixer am = new AudioMixer(ss); + assertNotNull("AudioMixer Constructor fail", am); + assertEquals("AudioMixer constructor made wrong" + + "ShortSound", ss, am.getShortSound()); + } +} diff --git a/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/AudioPlayerTest.java b/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/AudioPlayerTest.java index 0c2fe64..16e6c36 100644 --- a/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/AudioPlayerTest.java +++ b/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/AudioPlayerTest.java @@ -1,20 +1,26 @@ package com.sloths.speedy.shortsounds.tests; import android.test.suitebuilder.annotation.SmallTest; +import android.util.Log; import com.sloths.speedy.shortsounds.model.AudioPlayer; import com.sloths.speedy.shortsounds.model.ShortSound; import com.sloths.speedy.shortsounds.model.ShortSoundTrack; +import com.sloths.speedy.shortsounds.view.ShortSoundsApplication; import junit.framework.TestCase; +import java.io.File; + /** * Created by jbusc_000 on 5/15/2015. * Tests general Functionality of the Audio Player Class */ public class AudioPlayerTest extends TestCase { - private String TAG = "AudioPlayerTest"; + private static final String TAG = "AudioPlayerTest"; + private static final String TEST_TITLE = "TestTrack"; + private static final String TEST_FILE_NAME = "test-file-modified"; /* Helper method, returns constructed player. Reduces redundent calls @@ -25,6 +31,19 @@ private AudioPlayer constructEmptyPlayer() { return new AudioPlayer(ss); } + private AudioPlayer constructPlayerWithTracks() { + ShortSound ss = new ShortSound(); + ShortSoundTrack sst = newSSTrack(); + ss.addTrack(sst); + return new AudioPlayer(ss); + } + + private ShortSoundTrack newSSTrack() { + + ShortSoundTrack sst = new ShortSoundTrack(ShortSoundTrackTest.makeTestValues()); + return sst; + } + /////////////////////////////////////////////////////////////////////////// // Constructor Test @@ -41,6 +60,11 @@ public void testConstructor() { assertEquals("Constructor Failure, Audio player in incorrect state after construction", AudioPlayer.PlayerState.STOPPED_ALL, player.getPlayerState()); } + + AudioPlayer player2 = constructPlayerWithTracks(); + assertEquals("Constructor Failure, Incorrect number of tracks after constructing with " + + "premade short sound", + 1, player2.getCurrentShortSound().getTracks().size()); } /////////////////////////////////////////////////////////////////////////// @@ -53,9 +77,17 @@ public void testPlayAllChangesState() { // test that state is properly changed AudioPlayer player = constructEmptyPlayer(); player.playAll(0); - assertTrue("playAll Failure, not changing players state.", + assertTrue("playAll Failure, State should remain stopped if no tracks contained.", + !player.isPlayingAll()); + + //TODO Make tests capable of playing fake tracks to confirm behavior + // AudioPlayer player2 = constructPlayerWithTracks(); + player.playAll(0); + assertTrue("playAll Failure, State should change to Playing when play all is called" + + "with non-null tracks in the audio player.", player.isPlayingAll()); + } /////////////////////////////////////////////////////////////////////////// @@ -102,7 +134,6 @@ public void testPauseAllChangesState() { // Tests that tracks can be added, played, paused, and stopped /////////////////////////////////////////////////////////////////////////// public void testTrackFunctionality() { - } } diff --git a/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/EffectTest.java b/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/EffectTest.java index 7ae08cc..0c8964e 100644 --- a/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/EffectTest.java +++ b/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/EffectTest.java @@ -11,17 +11,34 @@ */ public class EffectTest extends TestCase { - /** - * Tests to insure the constructor is working properly. - */ + /////////////////////////////////////////////////////////////////////////// + // + /////////////////////////////////////////////////////////////////////////// public void testEQConstructor() { Effect e = new EqEffect(); assertNotNull("Effect Constructor made a null object", e); } + /////////////////////////////////////////////////////////////////////////// + // + /////////////////////////////////////////////////////////////////////////// public void testReverbConstructor() { Effect e = new ReverbEffect(); assertNotNull("Effect Constructor made a null object", e); } + /////////////////////////////////////////////////////////////////////////// + // + /////////////////////////////////////////////////////////////////////////// + public void testTitles() { + Effect eq = new EqEffect(); + Effect rv = new ReverbEffect(); + assertEquals("EQ effect title wrong", eq.getTitleString(), "Equalizer"); + assertEquals("Reverb effect title wrong", rv.getTitleString(), "Reverb"); + } + + /////////////////////////////////////////////////////////////////////////// + // + /////////////////////////////////////////////////////////////////////////// + } diff --git a/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/MainActivityTest.java b/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/MainActivityContentTest.java similarity index 57% rename from app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/MainActivityTest.java rename to app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/MainActivityContentTest.java index b13d7a8..50e3caa 100644 --- a/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/MainActivityTest.java +++ b/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/MainActivityContentTest.java @@ -1,22 +1,29 @@ package com.sloths.speedy.shortsounds.tests; import android.test.ActivityInstrumentationTestCase2; +import android.test.TouchUtils; import android.test.suitebuilder.annotation.SmallTest; +import android.util.Log; import android.view.View; +import android.widget.ImageButton; import android.widget.ViewAnimator; import com.sloths.speedy.shortsounds.*; import com.sloths.speedy.shortsounds.R; import com.sloths.speedy.shortsounds.view.MainActivity; +import java.util.List; + /** * Created by jbusc_000 on 5/15/2015. * System test for the main activity and system interaction with other ui elements. */ -public class MainActivityTest extends ActivityInstrumentationTestCase2 { - MainActivity mMainActivity; - View mAnimator; - public MainActivityTest() { +public class MainActivityContentTest extends ActivityInstrumentationTestCase2 { + private MainActivity mMainActivity; + private View mAnimator; + private static final String TAG = "MAIN ACTIVITy TEST"; + + public MainActivityContentTest() { super(MainActivity.class); } @@ -26,7 +33,9 @@ public MainActivityTest() { */ @Override protected void setUp() throws Exception { + Log.d(TAG, "Set-Up"); super.setUp(); + setActivityInitialTouchMode(true); mMainActivity = getActivity(); mAnimator = mMainActivity.findViewById(R.id.view_animator); } @@ -40,10 +49,15 @@ public void testMainActivityNotNull() { } /** - * Test to insure that the views within the main activity are non-null. + * Test to ensure that the views within the main activity are non-null. */ @SmallTest public void testMainActivityHasContent() { - assertNotNull("Animator is non-null", mAnimator); + + assertNotNull("Animator null", mAnimator); + assertNotNull("SeekBar is null", mMainActivity.findViewById(R.id.seekBar)); + assertNotNull("Record button is null", mMainActivity.findViewById(R.id.imageButtonPlay)); + assertNotNull("DrawerLayout is null", mMainActivity.findViewById(R.id.drawer_layout)); } + } diff --git a/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/ShortSoundTrackTest.java b/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/ShortSoundTrackTest.java index 38441cc..35b9533 100644 --- a/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/ShortSoundTrackTest.java +++ b/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/ShortSoundTrackTest.java @@ -256,7 +256,7 @@ public void testGetIdFromSQL() { * * @return HashMap representing sample data stored by the database for ShortSoundTracks. */ - private HashMap makeTestValues() { + public static HashMap makeTestValues() { HashMap testValues = new HashMap(); testValues.put(ShortSoundSQLHelper.KEY_ID, "1"); diff --git a/app/src/main/java/com/sloths/speedy/shortsounds/model/AudioMixer.java b/app/src/main/java/com/sloths/speedy/shortsounds/model/AudioMixer.java index a594caa..9e12226 100644 --- a/app/src/main/java/com/sloths/speedy/shortsounds/model/AudioMixer.java +++ b/app/src/main/java/com/sloths/speedy/shortsounds/model/AudioMixer.java @@ -83,6 +83,15 @@ else if ( mixedByte < Byte.MIN_VALUE ) return mixedBuf; } + /** + * Method for testing purposes. + * Getter for shorsound + * @return ShortSound this.shortsound + */ + public ShortSound getShortSound() { + return this.shortSound; + } + private File writeWavHeader( File fileToConvert ) throws IOException { // Constants used in the .wav header long mySubChunk1Size = 16; // 16bit PCM From 16c75bcb6c1e9917ef6588558cb9500e84a21dfd Mon Sep 17 00:00:00 2001 From: sigotron Date: Fri, 22 May 2015 12:58:24 -0700 Subject: [PATCH 06/15] no message --- .../speedy/shortsounds/controller/ModelControl.java | 9 ++++++++- .../com/sloths/speedy/shortsounds/view/MainActivity.java | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/sloths/speedy/shortsounds/controller/ModelControl.java b/app/src/main/java/com/sloths/speedy/shortsounds/controller/ModelControl.java index 7e51786..7fd824a 100644 --- a/app/src/main/java/com/sloths/speedy/shortsounds/controller/ModelControl.java +++ b/app/src/main/java/com/sloths/speedy/shortsounds/controller/ModelControl.java @@ -1,8 +1,11 @@ package com.sloths.speedy.shortsounds.controller; import android.util.Log; +import android.widget.Button; +import android.widget.ImageButton; import android.widget.SeekBar; +import com.sloths.speedy.shortsounds.R; import com.sloths.speedy.shortsounds.model.AudioPlayer; import com.sloths.speedy.shortsounds.model.AudioRecorder; import com.sloths.speedy.shortsounds.model.Effect; @@ -26,6 +29,7 @@ public class ModelControl implements PlaybackListener { private int seekBarPosition; private static ModelControl instance = null; private SeekBar mGlobalSeekBar; + private ImageButton mGlobalPlayButton; /** @@ -165,7 +169,10 @@ public void soloTrack(int track) { public void endOfTrack() { seekBarPosition = 0; mGlobalSeekBar.setProgress(0); - onPlayToggle(); // TODO: Update Play Button } + + public void setGlobalPlayButton(ImageButton mGlobalPlayButton) { + this.mGlobalPlayButton = mGlobalPlayButton; + } } diff --git a/app/src/main/java/com/sloths/speedy/shortsounds/view/MainActivity.java b/app/src/main/java/com/sloths/speedy/shortsounds/view/MainActivity.java index 9341c64..0b4e990 100644 --- a/app/src/main/java/com/sloths/speedy/shortsounds/view/MainActivity.java +++ b/app/src/main/java/com/sloths/speedy/shortsounds/view/MainActivity.java @@ -144,6 +144,7 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { modelControl.setGlobalSeekBar(mGlobalSeekBar); mGlobalPlayButton = (ImageButton)findViewById(R.id.imageButtonPlay); + modelControl.setGlobalPlayButton(mGlobalPlayButton); mGlobalPlayButton.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_play)); Log.d("DEBUG", "Found the global play button! " + mGlobalPlayButton); mGlobalPlayButton.setOnClickListener(new View.OnClickListener() { From 1a700c3c12247480905b1ce0f6536916444ba837 Mon Sep 17 00:00:00 2001 From: sigotron Date: Fri, 22 May 2015 13:42:08 -0700 Subject: [PATCH 07/15] end of track toggles pause icon to play --- .../speedy/shortsounds/controller/ModelControl.java | 13 +++---------- .../speedy/shortsounds/model/AudioPlayer.java | 12 ------------ .../speedy/shortsounds/view/MainActivity.java | 12 ++++++++++-- 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/sloths/speedy/shortsounds/controller/ModelControl.java b/app/src/main/java/com/sloths/speedy/shortsounds/controller/ModelControl.java index 7fd824a..4f1a5e0 100644 --- a/app/src/main/java/com/sloths/speedy/shortsounds/controller/ModelControl.java +++ b/app/src/main/java/com/sloths/speedy/shortsounds/controller/ModelControl.java @@ -1,5 +1,7 @@ package com.sloths.speedy.shortsounds.controller; +import android.app.Activity; +import android.content.Context; import android.util.Log; import android.widget.Button; import android.widget.ImageButton; @@ -30,6 +32,7 @@ public class ModelControl implements PlaybackListener { private static ModelControl instance = null; private SeekBar mGlobalSeekBar; private ImageButton mGlobalPlayButton; + private Context mMainContext; /** @@ -165,14 +168,4 @@ public void soloTrack(int track) { } public void volumeChanged(int track, float volume) { mAudioPlayer.volumeChanged(track, volume); } - - public void endOfTrack() { - seekBarPosition = 0; - mGlobalSeekBar.setProgress(0); - // TODO: Update Play Button - } - - public void setGlobalPlayButton(ImageButton mGlobalPlayButton) { - this.mGlobalPlayButton = mGlobalPlayButton; - } } diff --git a/app/src/main/java/com/sloths/speedy/shortsounds/model/AudioPlayer.java b/app/src/main/java/com/sloths/speedy/shortsounds/model/AudioPlayer.java index 3d2bcee..8820d8b 100644 --- a/app/src/main/java/com/sloths/speedy/shortsounds/model/AudioPlayer.java +++ b/app/src/main/java/com/sloths/speedy/shortsounds/model/AudioPlayer.java @@ -98,12 +98,6 @@ public void playAll( int position ) { playerState = PlayerState.PLAYING_ALL; } - private void notifyEndOfTrack(TrackPlayer notifier) { - if (notifier == mLongestTrackPlayer) { - mModelControl.endOfTrack(); - } - } - public void notifyModelControlOfTrackPosition(TrackPlayer notifier, int position) { if (notifier == mLongestTrackPlayer) { @@ -442,8 +436,6 @@ public void run() { // We reached the end of the track Log.d(DEBUG_TAG, "Reached end of track["+track.getId()+"]"); stop(); - // TODO notify the audio player that we have finished playback on this track. - notifyAudioPlayerEndOfTrack(); } } catch (IOException e) { e.printStackTrace(); @@ -451,10 +443,6 @@ public void run() { } } - private void notifyAudioPlayerEndOfTrack() { - mAudioPlayerListener.notifyEndOfTrack(this); - } - private void notifyAudioPlayerOfPosition() { int currentPos = getCurrentTrackPosition(); mAudioPlayerListener.notifyModelControlOfTrackPosition(this,currentPos); diff --git a/app/src/main/java/com/sloths/speedy/shortsounds/view/MainActivity.java b/app/src/main/java/com/sloths/speedy/shortsounds/view/MainActivity.java index 0b4e990..73ce001 100644 --- a/app/src/main/java/com/sloths/speedy/shortsounds/view/MainActivity.java +++ b/app/src/main/java/com/sloths/speedy/shortsounds/view/MainActivity.java @@ -116,6 +116,7 @@ protected void onCreate(Bundle savedInstanceState) { private void setUpControllerView() { mGlobalSeekBar = (SeekBar) findViewById(R.id.seekBar); mGlobalSeekBar.setMax(100); // Set the max value (0-100) + SeekBar.OnSeekBarChangeListener seekBarChangeListener = new SeekBar.OnSeekBarChangeListener() { @Override @@ -137,14 +138,21 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if(fromUser) { Log.d("DB_TEST", "SeekBar Progress Changed By User to " + progress); modelControl.updateCurrentPosition(progress); + } else { + if(progress == 100) { + mGlobalPlayButton.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_play)); + mGlobalSeekBar.setProgress(0); + modelControl.updateCurrentPosition(0); + } } } }; + + mGlobalSeekBar.setOnSeekBarChangeListener(seekBarChangeListener); modelControl.setGlobalSeekBar(mGlobalSeekBar); - mGlobalPlayButton = (ImageButton)findViewById(R.id.imageButtonPlay); - modelControl.setGlobalPlayButton(mGlobalPlayButton); + mGlobalPlayButton.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_play)); Log.d("DEBUG", "Found the global play button! " + mGlobalPlayButton); mGlobalPlayButton.setOnClickListener(new View.OnClickListener() { From 080ef73064414118454e3b46b7a68c7420553945 Mon Sep 17 00:00:00 2001 From: sigotron Date: Fri, 22 May 2015 13:48:05 -0700 Subject: [PATCH 08/15] selecting short sound from drawer makes button play button --- .../java/com/sloths/speedy/shortsounds/view/MainActivity.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/com/sloths/speedy/shortsounds/view/MainActivity.java b/app/src/main/java/com/sloths/speedy/shortsounds/view/MainActivity.java index 73ce001..c5a612e 100644 --- a/app/src/main/java/com/sloths/speedy/shortsounds/view/MainActivity.java +++ b/app/src/main/java/com/sloths/speedy/shortsounds/view/MainActivity.java @@ -410,6 +410,7 @@ private void setUpAnimatorViews() { private void selectShortSoundFromDrawer(int position) { modelControl.stopAllFromPlaying(); resetSeekBarToZero(); + mGlobalPlayButton.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_play)); if (position != -1) { mActiveShortSound = sounds.get(position); // Set the currently active ShortSound. modelControl.setmAudioPlayer(new AudioPlayer(mActiveShortSound)); // Setup the new AudioPlayer for this SS. @@ -445,6 +446,7 @@ private void selectShortSoundFromDrawer(int position) { invalidateOptionsMenu(); resetSeekBarToZero(); + mGlobalPlayButton.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_play)); } // selected mix is already loaded so close the drawer From 437c78b9909d8bb76b76f1763f4bb88fdc0f076d Mon Sep 17 00:00:00 2001 From: sigotron Date: Fri, 22 May 2015 15:47:04 -0700 Subject: [PATCH 09/15] Added a record timer. --- .../speedy/shortsounds/view/MainActivity.java | 57 +++++++++++++++++++ app/src/main/res/layout-v21/activity_main.xml | 11 ++++ 2 files changed, 68 insertions(+) diff --git a/app/src/main/java/com/sloths/speedy/shortsounds/view/MainActivity.java b/app/src/main/java/com/sloths/speedy/shortsounds/view/MainActivity.java index 521737b..0c23cda 100644 --- a/app/src/main/java/com/sloths/speedy/shortsounds/view/MainActivity.java +++ b/app/src/main/java/com/sloths/speedy/shortsounds/view/MainActivity.java @@ -8,6 +8,8 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.os.Handler; +import android.os.Message; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentTransaction; import android.support.v4.content.FileProvider; @@ -47,6 +49,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Timer; +import java.util.TimerTask; /** * The MainActivity for the application. Contains setup for the framework of the UI. @@ -77,6 +81,9 @@ public class MainActivity extends FragmentActivity implements NoticeDialogFragme private SeekBar mGlobalSeekBar; private int position; private ModelControl modelControl; + private Timer mRecordTimer; + private boolean mTimerIsRunning; + private int mElapsedTime; /** * Sets up MainActivity @@ -88,6 +95,8 @@ protected void onCreate(Bundle savedInstanceState) { Log.d("DB_TEST", "MainActivity:onCreate()"); sounds = ShortSound.getAll(); Log.d("DB_TEST", sounds.toString()); + mTimerIsRunning = false; + mElapsedTime = 0; mShortSoundsTitles = getShortSoundTitles(sounds); modelControl = ModelControl.instance(); final AudioRecorder mAudioRecorder = new AudioRecorder( getCacheDir() ); @@ -193,10 +202,12 @@ public void onCheckedChanged(FloatingActionButton fabView, boolean isChecked) { endRecording(); setPlayerVisibility(View.VISIBLE); mGlobalSeekBar.setEnabled(true); + stopTimer(); } else { mGlobalPlayButton.setEnabled(false); modelControl.onRecordStart(); mGlobalSeekBar.setEnabled(false); + startTimer(); } } }); @@ -208,9 +219,11 @@ public void onClick(View v) { if (modelControl.isRecording()) { endRecording(); setPlayerVisibility(View.VISIBLE); + mGlobalSeekBar.setEnabled(true); } else { mGlobalPlayButton.setEnabled(false); modelControl.onRecordStart(); + mGlobalSeekBar.setEnabled(false);; } } }); @@ -613,6 +626,50 @@ public void setTitle(CharSequence title) { getActionBar().setTitle(mTitle); } + /** + * Start a timer that times the how long a track is recording for + */ + private void startTimer() { + mRecordTimer = new Timer(); + mTimerIsRunning = true; + TextView timerTextView = (TextView)findViewById(R.id.timerView); + timerTextView.setVisibility(View.VISIBLE); + mRecordTimer.scheduleAtFixedRate(new TimerTask() { + public void run() { + mElapsedTime += 1; //increase every sec + mTimeHandler.obtainMessage(1).sendToTarget(); + + } + }, 0, 1000); + } + + /** + * Used by startTimer(). Updates the textview associated with the record timer. + */ + private Handler mTimeHandler = new Handler() { + public void handleMessage(Message msg) { + TextView timerTextView = (TextView)findViewById(R.id.timerView); + int minutes = mElapsedTime / 60; + int seconds = mElapsedTime - (60 * minutes); + String z = ""; + if (seconds < 10) z = "0"; + String time = "0" + minutes + ":" + z + seconds; + timerTextView.setText(time); + } + }; + + /** + * stops the timer associated with track recording. + */ + private void stopTimer() { + mRecordTimer.cancel(); + TextView timerTextView = (TextView)findViewById(R.id.timerView); + timerTextView.setVisibility(View.INVISIBLE); + timerTextView.setText("00:00"); + mElapsedTime = 0; + mTimerIsRunning = false; + } + /** * Creates the Action Bar Options Menu * @param menu The Action Bar menu diff --git a/app/src/main/res/layout-v21/activity_main.xml b/app/src/main/res/layout-v21/activity_main.xml index 1a23192..705eedf 100644 --- a/app/src/main/res/layout-v21/activity_main.xml +++ b/app/src/main/res/layout-v21/activity_main.xml @@ -58,6 +58,17 @@ android:layout_gravity="left|center_vertical" style="@android:style/Widget.Material.ActionButton" /> + + Date: Fri, 22 May 2015 17:30:28 -0700 Subject: [PATCH 10/15] More test cases for ShortSoundTest. --- .../shortsounds/tests/ShortSoundTest.java | 127 ++++++++++++++++++ 1 file changed, 127 insertions(+) diff --git a/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/ShortSoundTest.java b/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/ShortSoundTest.java index 82c51d0..d2eac50 100644 --- a/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/ShortSoundTest.java +++ b/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/ShortSoundTest.java @@ -2,10 +2,12 @@ import com.sloths.speedy.shortsounds.model.ShortSound; import com.sloths.speedy.shortsounds.model.ShortSoundSQLHelper; +import com.sloths.speedy.shortsounds.model.ShortSoundTrack; import junit.framework.TestCase; import java.util.HashMap; +import java.util.List; /** * Created by jbusc_000 on 5/15/2015. @@ -27,6 +29,9 @@ public void testConstructor() { ShortSound ss = new ShortSound(); assertNotNull(ss); assertEquals(0, ss.getTracks().size()); + + // So that the fact that ss is inserted into the database doesn't affect the other tests. + ShortSoundSQLHelper.getInstance().removeShortSound(ss); } /** @@ -85,6 +90,128 @@ public void testConstructorWithMap() { assertEquals(0, ss.getTracks().size()); } + /** + * Tests that constructing with a map with all fields and an extra one results in the same + * result as the test with a map of both fields. + */ + public void testConstructorWithMapWithExtraValues() { + HashMap testMap = makeTestMap(); + testMap.put("Random key", "Random value"); + ShortSound ss = new ShortSound(testMap); + + assertNotNull(ss); + assertEquals(TEST_TITLE, ss.getTitle()); + assertEquals(0, ss.getTracks().size()); + } + + /* + * getAll + */ + + /** + * Tests that getAll returns an empty List when no ShortSounds have been constructed. + */ + public void testGetAllWithNoShortSounds() { + List shortSounds = ShortSound.getAll(); + + assertNotNull(shortSounds); + assertEquals(0, shortSounds.size()); + } + + /** + * Tests that getAll returns a List with the proper number of ShortSounds when 1 ShortSound + * has been constructed and that it is the same as the constructed ShortSound. + */ + public void testGetAllWithOneShortSound() { + ShortSound ss = new ShortSound(); + List shortSounds = ShortSound.getAll(); + + assertNotNull(shortSounds); + assertEquals(1, shortSounds.size()); + + ShortSound retreivedSS = shortSounds.get(0); + assertEquals(ss.getTitle(), retreivedSS.getTitle()); + assertEquals(ss.getTracks().size(), retreivedSS.getTracks().size()); + assertEquals(ss.getId(), retreivedSS.getId()); + + ShortSoundSQLHelper.getInstance().removeShortSound(ss); + } + + /* + * getById + */ + + /** + * Tests that calling getById with an ID that doesn't exist returns null. + */ + public void testGetByIdWithNoMatchingId() { + assertNull(ShortSound.getById(-1)); + } + + /** + * Tests that calling getById with an ID that exists returns the correct ShortSound. + */ + public void testGetByIdWithMatchingId() { + ShortSound ss = new ShortSound(); + ShortSound retreivedSS = ShortSound.getById(ss.getId()); + + assertNotNull(retreivedSS); + assertEquals(ss.getTitle(), retreivedSS.getTitle()); + assertEquals(ss.getTracks().size(), retreivedSS.getTracks().size()); + assertEquals(ss.getId(), retreivedSS.getId()); + + ShortSoundSQLHelper.getInstance().removeShortSound(ss); + } + + /* + * getLongestTrack + */ + + /** + * Tests that the returned track is null if there are no tracks + */ + public void testLongestTrackWhenThereAreNoTracksIsNull() { + ShortSound ss = new ShortSound(); + assertNull(ss.getLongestTrack()); + + ShortSoundSQLHelper.getInstance().removeShortSound(ss); + } + + /** + * Tests that when the ShortSound has only one track that getLongestTrack returns the one track. + */ + public void testLongestTrackWithOneTrackReturnsTheOneTrack() { + ShortSound ss = new ShortSound(); + HashMap shortSoundTrackTestMap = ShortSoundTrackTest.makeTestValues(); + ShortSoundTrack sst = new ShortSoundTrack(shortSoundTrackTestMap); + ss.addTrack(sst); + + ShortSoundTrack retreivedTrack = ss.getLongestTrack(); + assertNotNull(retreivedTrack); + assertTrue(sst == retreivedTrack); + + ShortSoundSQLHelper.getInstance().removeShortSound(ss); + } + + /** + * Tests that when the ShortSound has two tracks, getLongestTrack picks the longer of the two. + */ + public void testLongestTrackBetweenTwoTracksIsTheCorrectOne() { + ShortSound ss = new ShortSound(); + HashMap shortSoundTrackTestMap = ShortSoundTrackTest.makeTestValues(); + ShortSoundTrack shortTrack = new ShortSoundTrack(shortSoundTrackTestMap); + shortSoundTrackTestMap.put(ShortSoundSQLHelper.TRACK_LENGTH, "10"); + ShortSoundTrack longTrack = new ShortSoundTrack(shortSoundTrackTestMap); + ss.addTrack(shortTrack); + ss.addTrack(longTrack); + ShortSoundTrack returnedTrack = ss.getLongestTrack(); + + assertNotNull(returnedTrack); + assertTrue(longTrack == returnedTrack); + + ShortSoundSQLHelper.getInstance().removeShortSound(ss); + } + /** * Produce a default HashMap of values for testing purposes. * From 04dd3ae3404a5c8f1f8cdb5dbafa3bfe8fceb7d4 Mon Sep 17 00:00:00 2001 From: Justin Yoon Date: Fri, 22 May 2015 17:37:21 -0700 Subject: [PATCH 11/15] Commented out two tests because they don't work when you run it with the other tests (works by itself though). --- .../sloths/speedy/shortsounds/tests/ShortSoundTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/ShortSoundTest.java b/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/ShortSoundTest.java index d2eac50..353dad2 100644 --- a/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/ShortSoundTest.java +++ b/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/ShortSoundTest.java @@ -111,18 +111,18 @@ public void testConstructorWithMapWithExtraValues() { /** * Tests that getAll returns an empty List when no ShortSounds have been constructed. */ - public void testGetAllWithNoShortSounds() { +/* public void testGetAllWithNoShortSounds() { List shortSounds = ShortSound.getAll(); assertNotNull(shortSounds); assertEquals(0, shortSounds.size()); } - +*/ /** * Tests that getAll returns a List with the proper number of ShortSounds when 1 ShortSound * has been constructed and that it is the same as the constructed ShortSound. */ - public void testGetAllWithOneShortSound() { +/* public void testGetAllWithOneShortSound() { ShortSound ss = new ShortSound(); List shortSounds = ShortSound.getAll(); @@ -136,7 +136,7 @@ public void testGetAllWithOneShortSound() { ShortSoundSQLHelper.getInstance().removeShortSound(ss); } - +*/ /* * getById */ From 4971acd3b5666db5d49b5bc45384a6cb23433788 Mon Sep 17 00:00:00 2001 From: Mattie Date: Fri, 22 May 2015 19:34:54 -0700 Subject: [PATCH 12/15] Fixed bug with delete --- .../com/sloths/speedy/shortsounds/view/MainActivity.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/sloths/speedy/shortsounds/view/MainActivity.java b/app/src/main/java/com/sloths/speedy/shortsounds/view/MainActivity.java index 0c23cda..f989863 100644 --- a/app/src/main/java/com/sloths/speedy/shortsounds/view/MainActivity.java +++ b/app/src/main/java/com/sloths/speedy/shortsounds/view/MainActivity.java @@ -740,10 +740,7 @@ public boolean onOptionsItemSelected(MenuItem item) { /** * Deletes the current ShortSound from the library. - * If there are other ShortSounds in the library, opens the first - * ShortSound. - * If there are no ShortSounds in the library, creates and opens a new - * ShortSound + * And returns the user to a blank start recording screen. */ private void deleteShortSound() { if (mActiveShortSound != null) { @@ -752,6 +749,7 @@ private void deleteShortSound() { sounds.remove(mActiveShortSound); Log.d("CHECK", "" + sounds.size()); mActiveShortSound.delete(); + mShortSoundsTitles = getShortSoundTitles(ShortSound.getAll()); createNew(); } } From 8ef3da494aba70d5c9fd05423e1871bc1f3a6d4b Mon Sep 17 00:00:00 2001 From: Mattie Date: Fri, 22 May 2015 21:34:58 -0700 Subject: [PATCH 13/15] Added basic test for generateAudioFile --- .../shortsounds/tests/AudioMixerTest.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/AudioMixerTest.java b/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/AudioMixerTest.java index cbfe07d..67ff4fc 100644 --- a/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/AudioMixerTest.java +++ b/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/AudioMixerTest.java @@ -5,11 +5,21 @@ import junit.framework.TestCase; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + /** - * Created by jbusc_000 on 5/21/2015. + * Test for AudioMixer class, the class that mixes tracks together + * into a single file. */ public class AudioMixerTest extends TestCase { + /* + * Tests the constructor to verify that it creates + * a valid AudioMixer + */ public void testConstructor() { ShortSound ss = new ShortSound(); AudioMixer am = new AudioMixer(ss); @@ -17,4 +27,20 @@ public void testConstructor() { assertEquals("AudioMixer constructor made wrong" + "ShortSound", ss, am.getShortSound()); } + + /* + * Tests the generateAudioFile method from AudioMixer + * to make sure it generates a file properly. + */ + public void testGenerateAudioFile() { + ShortSound ss = new ShortSound(); + AudioMixer am = new AudioMixer(ss); + File collection; + try { + collection = am.generateAudioFile(); + } catch (IOException e) { + collection = null; + } + assertNotNull("GenerateAudioFile fail", collection); + } } From 69f8e1357122911a8cb7198e3734d43ecad79e38 Mon Sep 17 00:00:00 2001 From: Mattie Date: Fri, 22 May 2015 21:36:49 -0700 Subject: [PATCH 14/15] Added basic test for generateAudioFile --- .../com/sloths/speedy/shortsounds/tests/AudioMixerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/AudioMixerTest.java b/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/AudioMixerTest.java index 67ff4fc..650503d 100644 --- a/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/AudioMixerTest.java +++ b/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/AudioMixerTest.java @@ -30,7 +30,7 @@ public void testConstructor() { /* * Tests the generateAudioFile method from AudioMixer - * to make sure it generates a file properly. + * to make sure it generates a non null file properly. */ public void testGenerateAudioFile() { ShortSound ss = new ShortSound(); From d6a219cdd9969d9724415fcf0eb38e7babe849c7 Mon Sep 17 00:00:00 2001 From: Justin Yoon Date: Fri, 22 May 2015 21:45:47 -0700 Subject: [PATCH 15/15] More ShortSound tests. --- .../shortsounds/tests/ShortSoundTest.java | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/ShortSoundTest.java b/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/ShortSoundTest.java index 353dad2..0258ffd 100644 --- a/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/ShortSoundTest.java +++ b/app/src/androidTest/java/com/sloths/speedy/shortsounds/tests/ShortSoundTest.java @@ -6,6 +6,7 @@ import junit.framework.TestCase; +import java.io.File; import java.util.HashMap; import java.util.List; @@ -212,6 +213,125 @@ public void testLongestTrackBetweenTwoTracksIsTheCorrectOne() { ShortSoundSQLHelper.getInstance().removeShortSound(ss); } + /* + * getTracks + */ + + /** + * Tests that getTracks returns an empty List when the ShortSound has no tracks. + */ + public void testGetTracksWithNoTracks() { + ShortSound ss = new ShortSound(); + List ssTracks = ss.getTracks(); + + assertNotNull(ssTracks); + assertEquals(0, ssTracks.size()); + + ShortSoundSQLHelper.getInstance().removeShortSound(ss); + } + + /** + * Tests that getTracks returns a List with one track when the ShortSound has one track. + * Also makes sure that the track returned in the List refers to the same track as the one + * in the ShortSound. + */ + public void testGetTracksWithOneTrack() { + ShortSound ss = new ShortSound(); + ShortSoundTrack sst = new ShortSoundTrack(new File(""), 1); + ss.addTrack(sst); + List ssTracks = ss.getTracks(); + + assertNotNull(ssTracks); + assertEquals(1, ssTracks.size()); + assertTrue(sst == ssTracks.get(0)); + + ShortSoundSQLHelper.getInstance().removeShortSound(ss); + } + + /* + * addTrack + */ + + /** + * Tests that adding a track to a track list with one track appends the bew track to the end. + */ + public void testAddTrackToListWithOneTrack() { + ShortSound ss = new ShortSound(); + ShortSoundTrack firstTrack = new ShortSoundTrack(new File(""), 1); + ss.addTrack(firstTrack); + ShortSoundTrack secondTrack = new ShortSoundTrack(new File(""), 1); + ss.addTrack(secondTrack); + List ssTracks = ss.getTracks(); + + assertNotNull(ssTracks); + assertEquals(2, ssTracks.size()); + assertTrue(firstTrack == ssTracks.get(0)); + assertTrue(secondTrack == ssTracks.get(1)); + + ShortSoundSQLHelper.getInstance().removeShortSound(ss); + } + + /* + * removeTrack + */ + + /** + * Tests that removing a ShortSoundTrack that is not in the ShortSound causes no change to the + * ShortSound. + */ + public void testRemoveTrackWhenTrackIsNotInShortSound() { + HashMap testMap = makeTestMap(); + ShortSound ss = new ShortSound(testMap); + ShortSoundTrack shortSoundTrack = new ShortSoundTrack(new File(""), 1); + ShortSoundTrack trackToTryToRemove = new ShortSoundTrack(new File(""), 1); + ss.addTrack(shortSoundTrack); + + ss.removeTrack(trackToTryToRemove); + List shortSoundTracks = ss.getTracks(); + + assertNotNull(shortSoundTracks); + assertEquals(1, shortSoundTracks.size()); + assertTrue(shortSoundTrack == shortSoundTracks.get(0)); + } + + /** + * Tests that removing a ShortSoundTrack that is in the ShortSound removes it from the + * ShortSound. + */ + public void testRemoveTrackWhenTrackIsInShortSoundAndThereIsOnlyOneTrack() { + ShortSound ss = new ShortSound(); + ShortSoundTrack shortSoundTrack = new ShortSoundTrack(new File(""), 0); + ss.addTrack(shortSoundTrack); + + ss.removeTrack(shortSoundTrack); + List shortSoundTracks = ss.getTracks(); + + assertNotNull(shortSoundTracks); + assertEquals(0, shortSoundTracks.size()); + + ShortSoundSQLHelper.getInstance().removeShortSound(ss); + } + + /** + * Tests that removing a ShortSoundTrack that is in a ShortSound with multiple tracks + * only removes the ShortSoundTrack passed in. + */ + public void testRemoveTrackWhenTrackIsInShortSoundAndThereAreMultipleTracks() { + HashMap testMap = makeTestMap(); + ShortSound ss = new ShortSound(testMap); + ShortSoundTrack shortSoundTrack = new ShortSoundTrack(new File(""), 1); + ShortSoundTrack trackToTryToRemove = new ShortSoundTrack(new File(""), 1); + ss.addTrack(shortSoundTrack); + ss.addTrack(trackToTryToRemove); + + ss.removeTrack(trackToTryToRemove); + List shortSoundTracks = ss.getTracks(); + + assertNotNull(shortSoundTracks); + assertEquals(1, shortSoundTracks.size()); + assertTrue(shortSoundTrack == shortSoundTracks.get(0)); + } + /** * Produce a default HashMap of values for testing purposes. *