diff options
author | Chris Wren <cwren@android.com> | 2015-11-15 23:36:18 -0500 |
---|---|---|
committer | Chris Wren <cwren@android.com> | 2015-11-15 23:36:18 -0500 |
commit | 7257342de1639de10f8d3ea0a92b223daf18f1da (patch) | |
tree | 9b0b4b356cd6d251f3b78d8fdf8dee1e96bf091e | |
parent | 20f6c51ab018c45347bc99ccccb17f45cbfb9fc0 (diff) | |
download | experimental-7257342de1639de10f8d3ea0a92b223daf18f1da.tar.gz |
more showcase improvements
add ringtone preference
improve fader alarm code
default text to true, even if prefs are empty
Change-Id: I21c39b35a8713f2eeffa45d6166da74cbc9a950c
4 files changed, 28 insertions, 8 deletions
diff --git a/NotificationShowcase/res/values/strings.xml b/NotificationShowcase/res/values/strings.xml index c05b87d..965308e 100644 --- a/NotificationShowcase/res/values/strings.xml +++ b/NotificationShowcase/res/values/strings.xml @@ -70,6 +70,7 @@ <string name="pref_title_sms">SMS Example</string> <string name="pref_summary_sms_enable">Enable the SMS example</string> + <string name="pref_title_sms_sound">Ringtone</string> <string name="pref_title_sms_noisy">Noise</string> <string name="pref_summary_sms_noisy">Allow the SMS example to be noisy</string> <string name="pref_title_sms_buzzy">Vibration</string> diff --git a/NotificationShowcase/res/xml/preferences.xml b/NotificationShowcase/res/xml/preferences.xml index ac938dc..4d0efe2 100644 --- a/NotificationShowcase/res/xml/preferences.xml +++ b/NotificationShowcase/res/xml/preferences.xml @@ -41,6 +41,12 @@ android:summary="@string/pref_summary_sms_noisy" android:title="@string/pref_title_sms_noisy" android:defaultValue="true" /> + <RingtonePreference + android:persistent="true" + android:key="pref_key_sms_sound" + android:dependency="pref_key_sms_enable" + android:ringtoneType="notification" + android:title="@string/pref_title_sms_sound" /> <CheckBoxPreference android:persistent="true" android:key="pref_key_sms_buzzy" diff --git a/NotificationShowcase/src/com/android/example/notificationshowcase/NotificationService.java b/NotificationShowcase/src/com/android/example/notificationshowcase/NotificationService.java index 14594f5..2c21a7e 100644 --- a/NotificationShowcase/src/com/android/example/notificationshowcase/NotificationService.java +++ b/NotificationShowcase/src/com/android/example/notificationshowcase/NotificationService.java @@ -42,6 +42,8 @@ import android.text.TextUtils; import android.text.style.StyleSpan; import android.util.Log; +import com.android.example.notificationshowcase.R; + import java.util.ArrayList; public class NotificationService extends IntentService { @@ -66,7 +68,7 @@ public class NotificationService extends IntentService { intent.setComponent(new ComponentName(context, NotificationService.class)); return PendingIntent.getService( context, 0, intent, - PendingIntent.FLAG_CANCEL_CURRENT); + PendingIntent.FLAG_UPDATE_CURRENT); } private static Bitmap getBitmap(Context context, int resId) { @@ -151,8 +153,13 @@ public class NotificationService extends IntentService { } int defaults = 0; - if(sharedPref.getBoolean(SettingsActivity.KEY_SMS_NOISY, false)) { - defaults |= Notification.DEFAULT_SOUND; + if(sharedPref.getBoolean(SettingsActivity.KEY_SMS_NOISY, true)) { + String uri = sharedPref.getString(SettingsActivity.KEY_SMS_SOUND, null); + if(uri == null) { + defaults |= Notification.DEFAULT_SOUND; + } else { + bigText.setSound(Uri.parse(uri)); + } } if(sharedPref.getBoolean(SettingsActivity.KEY_SMS_BUZZY, false)) { defaults |= Notification.DEFAULT_VIBRATE; @@ -188,7 +195,7 @@ public class NotificationService extends IntentService { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); ArrayList<Notification> mNotifications = new ArrayList<Notification>(); - if(sharedPref.getBoolean(SettingsActivity.KEY_SMS_ENABLE, false)) { + if(sharedPref.getBoolean(SettingsActivity.KEY_SMS_ENABLE, true)) { final int id = mNotifications.size(); mNotifications.add(makeSmsNotification(this, 2, id, System.currentTimeMillis())); } @@ -216,7 +223,7 @@ public class NotificationService extends IntentService { .setCategory(NotificationCompat.CATEGORY_CALL) .setContentIntent(fullscreen) .addAction(R.drawable.ic_dial_action_call, getString(R.string.call_answer), ans) - .addAction(R.drawable.ic_end_call, getString(R.string.call_ignore), ign) + .addAction(R.drawable.ic_end_call, getString(R.string.call_ignore), ign) .setOngoing(true); if(sharedPref.getBoolean(SettingsActivity.KEY_PHONE_FULLSCREEN, false)) { @@ -228,7 +235,9 @@ public class NotificationService extends IntentService { } if (sharedPref.getBoolean(SettingsActivity.KEY_PHONE_PERSON, false)) { - phoneCall.addPerson(Uri.fromParts("tel", "1 (617) 555-1212", null).toString()); + phoneCall.addPerson(Uri.fromParts("tel", + "1 (617) 555-1212", null) + .toString()); } mNotifications.add(phoneCall.build()); } @@ -317,10 +326,11 @@ public class NotificationService extends IntentService { noMa.notify(NOTIFICATION_ID + i, mNotifications.get(i)); } - // always create the pending intent, to cancel any previous intent + // always cancel any previous alarm PendingIntent pendingCancel = makeCancelAllIntent(this); + AlarmManager alMa = (AlarmManager) getSystemService(Context.ALARM_SERVICE); + alMa.cancel(pendingCancel); if(sharedPref.getBoolean(SettingsActivity.KEY_GLOBAL_FADE, false)) { - AlarmManager alMa = (AlarmManager) getSystemService(Context.ALARM_SERVICE); long t = SystemClock.elapsedRealtime() + FADE_TIME_MILLIS; alMa.set(AlarmManager.ELAPSED_REALTIME, t, pendingCancel); } diff --git a/NotificationShowcase/src/com/android/example/notificationshowcase/SettingsActivity.java b/NotificationShowcase/src/com/android/example/notificationshowcase/SettingsActivity.java index 90613a9..5697f77 100644 --- a/NotificationShowcase/src/com/android/example/notificationshowcase/SettingsActivity.java +++ b/NotificationShowcase/src/com/android/example/notificationshowcase/SettingsActivity.java @@ -24,6 +24,7 @@ public class SettingsActivity extends Activity { public static final String KEY_GLOBAL_FADE = "pref_key_global_fade"; public static final String KEY_SMS_ENABLE = "pref_key_sms_enable"; public static final String KEY_SMS_NOISY = "pref_key_sms_noisy"; + public static final String KEY_SMS_SOUND = "pref_key_sms_sound"; public static final String KEY_SMS_BUZZY = "pref_key_sms_buzzy"; public static final String KEY_SMS_PRIORITY = "pref_key_sms_priority"; public static final String KEY_SMS_PERSON = "pref_key_sms_person"; @@ -44,6 +45,8 @@ public class SettingsActivity extends Activity { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); } + + public SettingsFragment() {} } @Override |