Permalink
Browse files

Made a custom notification sound and vibration pattern to help distin…

…guish tweets from other notifications.
  • Loading branch information...
jjc1138
jjc1138 committed Dec 5, 2008
1 parent 0840328 commit 197722125962873519fb6c244c7082b0bd58229e
Binary file not shown.
View
Binary file not shown.
View
@@ -0,0 +1,4 @@
35indigobunting.mp3 is a public domain recording of an Indigo Bunting. It was made by the U.S. Fish & Wildlife Service and was downloaded from:
http://www.fws.gov/video/sound.htm
Background noise was removed using Audacity 1.2.4's Noise Removal effect and the nicest tweet was trimmed out. That was compressed to Ogg Vorbis using OggEnc 2.85 with default parameters.
View
Binary file not shown.
@@ -3,7 +3,9 @@
import static org.apache.commons.lang.StringEscapeUtils.unescapeHtml;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URI;
@@ -54,6 +56,7 @@
import android.app.Service;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Handler;
import android.os.IBinder;
@@ -66,12 +69,14 @@
public class Fetcher extends Service {
final static String LOG_TAG = "nanoTweeter";
final static String LAST_TWEET_ID_FILENAME = "lasttweets";
final static int FILTER_NONE = 0;
final static int FILTER_WHITELIST = 1;
final static int FILTER_BLACKLIST = 2;
final static String LAST_TWEET_ID_FILENAME = "lasttweets";
final static String TWEET_SOUND_FILENAME = "tweet.ogg";
final static long[] VIBRATION_PATTERN = new long[] { 0, 100, 60, 100 };
private SharedPreferences prefs;
private FetcherThread fetcherThread;
@@ -624,6 +629,39 @@ public int compare(Tweet t1, Tweet t2) {
final NotificationManager nm =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
final boolean sound = prefs.getBoolean("sound", false);
Uri notificationSound = null;
if (sound) {
notificationSound = Uri.fromFile(
getFileStreamPath(TWEET_SOUND_FILENAME));
boolean exists = false;
for (String i : fileList()) {
if (i.equals(TWEET_SOUND_FILENAME)) {
exists = true;
break;
}
}
if (!exists) {
// This should only ever have to be done once per
// installation. If the file is ever changed then the
// filename must be changed ("tweet2.ogg" or whatever), and
// you must delete the files from old versions here.
try {
InputStream ris = getResources().openRawResource(
R.raw.tweet);
FileOutputStream fos = openFileOutput(
TWEET_SOUND_FILENAME, MODE_WORLD_READABLE);
byte[] buffer = new byte[8192];
int read;
while ((read = ris.read(buffer)) > 0) {
fos.write(buffer, 0, read);
}
ris.close();
fos.close();
} catch (IOException e) {
deleteFile(TWEET_SOUND_FILENAME);
}
}
}
final boolean vibrate = prefs.getBoolean("vibrate", false);
final boolean lights = prefs.getBoolean("lights", false);
@@ -653,9 +691,13 @@ public int compare(Tweet t1, Tweet t2) {
n.contentView = v;
n.when = d.getTime();
n.defaults =
(sound ? Notification.DEFAULT_SOUND : 0) |
(vibrate ? Notification.DEFAULT_VIBRATE : 0);
if (sound) {
n.audioStreamType = AudioManager.STREAM_RING;
n.sound = notificationSound;
}
if (vibrate) {
n.vibrate = VIBRATION_PATTERN;
}
if (lights) {
n.flags |= Notification.FLAG_SHOW_LIGHTS;
n.ledOnMS = 1000;
@@ -702,8 +744,9 @@ public void run() {
} catch (DownloadException e) {
Log.v(LOG_TAG, "A download failed.");
} finally {
// This is in a finally because if stopIfIdle() isn't called
// then the wake lock would be held forever. That would suck.
// This is in a finally because if there was an unexpected
// runtime exception and stopIfIdle() wasn't called then the
// wake lock would be held forever. That would suck.
inProgress = false;
handler.post(new Runnable() {
@Override
View
Binary file not shown.

0 comments on commit 1977221

Please sign in to comment.