Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Add system notification as a possible notification sound #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
<string name="notification">Benachrichtigung</string>
<string name="notification_sound">Benachrichtigungston</string>
<string name="notification_sound_desc">Der Ton der Benachrichtigung.</string>

<string name="notification_default">System-Benachrichtigung</string>
<string name="notification_no_sound">Kein Ton</string>

<string name="notification_vibrate">Vibration bei Benachrichtigung</string>
<string name="notification_vibrate_desc">Soll der der Timer vibrieren?</string>

Expand Down
2 changes: 2 additions & 0 deletions res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
<string name="notification">Notification</string>
<string name="notification_sound">Avertissement sonore</string>
<string name="notification_sound_desc">Effet sonore de la notification.</string>
<string name="notification_default">Avertissement standard</string>
<string name="notification_no_sound">Silence</string>

<string name="notification_vibrate">Notification vibrante</string>
<string name="notification_vibrate_desc">Faire vibrer le téléphone pour la notification.</string>
Expand Down
9 changes: 6 additions & 3 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<string name="Notification">Tea time!</string>
<string name="InputTitle">Hour:Min:Sec</string>

<string name="warning_text">The phone is in silent mode! Notification vibration and sound will be supressed.</string>
<string name="warning_text">The phone is in silent mode! Notification vibration and sound will be suppressed.</string>
<string name="warning_title">Warning</string>
<string name="warning_button">Ok</string>

Expand All @@ -19,7 +19,9 @@
<string name="notification">Notification</string>
<string name="notification_sound">Notification Diddy</string>
<string name="notification_sound_desc">The notification\'s sound effects.</string>

<string name="notification_default">System default</string>
<string name="notification_no_sound">No sound</string>

<string name="notification_vibrate">Notification Vibrate</string>
<string name="notification_vibrate_desc">Should the timer notification Vibrate.</string>

Expand Down Expand Up @@ -54,7 +56,8 @@
<string name="about_details_licence">TeaTimer is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.</string>
<string name="about_details_url">http://www.gnu.org/licenses/gpl.html</string>
<string name="about_site">Get the latest version of the source code on Github.</string>
<string name="about_site_url">https://github.com/ralphleon/TeaTimer</string>
<string name="about_site_url">https://github.com/ralphleon/TeaTimer</string>




Expand Down
21 changes: 12 additions & 9 deletions src/goo/TeaTimer/TimerPrefActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import android.preference.ListPreference;
import android.preference.PreferenceActivity;
import android.provider.MediaStore;
import android.util.Log;
//import android.util.Log;

public class TimerPrefActivity extends PreferenceActivity
{
Expand Down Expand Up @@ -49,15 +49,18 @@ protected void onCreate(Bundle savedInstanceState) {
i++;
}

cursor.close();
cursor.close();
}

CharSequence [] entries = {"No Sound","Big Ben"};
CharSequence [] entryValues = {"","android.resource://goo.TeaTimer/" + R.raw.big_ben};

//Default value
if(tone.getValue() == null) tone.setValue((String)entryValues[1]);

CharSequence [] entries = { getResources().getText(R.string.notification_no_sound),
getResources().getText(R.string.notification_default),
"Big Ben"};
CharSequence [] entryValues = {"", "SYSTEM_DEFAULT", "android.resource://goo.TeaTimer/" + R.raw.big_ben};

//Default value
if (tone.getValue() == null){
tone.setValue((String)entryValues[2]);
}
if( items != null && items.length > 0){
tone.setEntries(concat(entries,items));
tone.setEntryValues(concat(entryValues,itemUris));
Expand All @@ -75,4 +78,4 @@ protected void onCreate(Bundle savedInstanceState) {

return C;
}
}
}
26 changes: 18 additions & 8 deletions src/goo/TeaTimer/TimerReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,24 @@ public void onReceive(Context context, Intent pintent)
}

// Play a sound!
if(notificationUri != ""){
Uri uri = Uri.parse(notificationUri);
notification.sound = uri;
if(!notificationUri.toString().equals("")){
if (notificationUri.toString().equals("SYSTEM_DEFAULT")){
Log.v(TAG, "Using default sound for notification");
notification.defaults |= Notification.DEFAULT_SOUND;
}
else{
Log.v(TAG, "Using sound " + notificationUri.toString() + " for notification");
Uri uri = Uri.parse(notificationUri);
notification.sound = uri;
}
}

else{
Log.v(TAG, "No sound is played");
}

notification.flags |= Notification.FLAG_AUTO_CANCEL;
Intent intent = new Intent(context,TimerActivity.class);

Intent intent = new Intent(context,TimerActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,intent, Intent.FLAG_ACTIVITY_NEW_TASK);

notification.setLatestEventInfo(context, text,
Expand Down Expand Up @@ -117,6 +127,6 @@ public void onReceive(Context context, Intent pintent)

// Show notification
mNM.notify(0, notification);
}
}

}
}