SleepMe! Android Application
You’ve probably seen those nature sound generating machines somewhere. My daughter wanted to make one to run on the rooted Nook Color we have. She did the artwork with the Wacom tablet and took dictation from me for most of the coding. It’s fun explaining encapsulation to a twelve year old.
The code itself is nothing too complex. To keep track of sounds, image switching, etc, we created a ButtonSoundManager class, which contains an array of button sound value objects (hold the ids of the associated volume control, MediaPlayer, etc). ButtonSoundManager handles the UI events from clicks and slider repositioning. For example, with the slider repositioning, it just finds the ButtonSound object associated with the clicked SeekBar’s id, then changes the volume:
public void handleSeekBarClick(int id, Float vol) {
for (ButtonSound b : this.sounds) {
if (b.seekBarId == id && b.isPlaying == true) {
float v = this.scaleVolume(vol);
b.mediaPlayer.setVolume(v, v);
}
}
}
So, after a bit of coding and twiddling, here we are. Nature sounds AND volume controls:
Installed via ADB wireless with no problems, other than that our snazzy logo doesn’t yet show on the app.
Source code (eclipse project) is here if you’d like to download.
