summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--res/values/cm_strings.xml13
-rw-r--r--res/xml/sound_settings.xml22
-rw-r--r--src/com/android/settings/SoundSettings.java115
3 files changed, 150 insertions, 0 deletions
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml
index f37b094..2e0254e 100644
--- a/res/values/cm_strings.xml
+++ b/res/values/cm_strings.xml
@@ -884,4 +884,17 @@
<string name="wifi_ibss_freq_title">Channel / Frequency</string>
<string name="wifi_channel">Channel</string>
<string name="wifi_mhz">MHz</string>
+
+ <!-- Category title for power sound notification specific Settings.
+ [CHAR LIMIT=40] -->
+ <string name="power_notifications_category_title">Power sounds</string>
+
+ <!-- Sound settings, power notifications enable/disable, setting check box label -->
+ <string name="power_notifications_enable_title">Enable</string>
+ <!-- Sound settings, power notifications vibrate enable/disable, setting check box label -->
+ <string name="power_notifications_vibrate_title">Vibrate</string>
+ <!-- Sound settings, power notifications ringtone selection, preference label -->
+ <string name="power_notifications_ringtone_title">Notification sound</string>
+ <!-- Sound settings, power notifications label for ringtone == none -->
+ <string name="power_notifications_ringtone_silent">Silent</string>
</resources>
diff --git a/res/xml/sound_settings.xml b/res/xml/sound_settings.xml
index 58750ee..af5df86 100644
--- a/res/xml/sound_settings.xml
+++ b/res/xml/sound_settings.xml
@@ -164,4 +164,26 @@
android:summary="@string/safe_headset_volume_summary"
android:defaultValue="true" />
+ <PreferenceCategory
+ android:title="@string/power_notifications_category_title"/>
+
+ <CheckBoxPreference
+ android:key="power_notifications"
+ android:title="@string/power_notifications_enable_title"
+ android:defaultValue="false"
+ android:persistent="false" />
+
+ <CheckBoxPreference
+ android:key="power_notifications_vibrate"
+ android:title="@string/power_notifications_vibrate_title"
+ android:defaultValue="false"
+ android:dependency="power_notifications"
+ android:persistent="false" />
+
+ <Preference
+ android:key="power_notifications_ringtone"
+ android:title="@string/power_notifications_ringtone_title"
+ android:dependency="power_notifications"
+ android:persistent="false" />
+
</PreferenceScreen>
diff --git a/src/com/android/settings/SoundSettings.java b/src/com/android/settings/SoundSettings.java
index a9a1071..8cc6e6f 100644
--- a/src/com/android/settings/SoundSettings.java
+++ b/src/com/android/settings/SoundSettings.java
@@ -19,6 +19,7 @@ package com.android.settings;
import com.android.settings.bluetooth.DockEventReceiver;
import com.android.settings.Utils;
+import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.bluetooth.BluetoothDevice;
@@ -33,6 +34,7 @@ import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import android.media.AudioManager;
+import android.media.Ringtone;
import android.media.RingtoneManager;
import android.media.audiofx.AudioEffect;
import android.net.Uri;
@@ -90,6 +92,9 @@ public class SoundSettings extends SettingsPreferenceFragment implements
private static final String KEY_CONVERT_SOUND_TO_VIBRATE = "notification_convert_sound_to_vibration";
private static final String KEY_SAFE_HEADSET_VOLUME = "safe_headset_volume";
private static final String KEY_VOLUME_ADJUST_SOUNDS = "volume_adjust_sounds";
+ private static final String KEY_POWER_NOTIFICATIONS = "power_notifications";
+ private static final String KEY_POWER_NOTIFICATIONS_VIBRATE = "power_notifications_vibrate";
+ private static final String KEY_POWER_NOTIFICATIONS_RINGTONE = "power_notifications_ringtone";
private static final String RING_MODE_NORMAL = "normal";
private static final String RING_MODE_VIBRATE = "vibrate";
@@ -103,6 +108,12 @@ public class SoundSettings extends SettingsPreferenceFragment implements
private static final int MSG_UPDATE_RINGTONE_SUMMARY = 1;
private static final int MSG_UPDATE_NOTIFICATION_SUMMARY = 2;
+ // Request code for power notification ringtone picker
+ private static final int REQUEST_CODE_POWER_NOTIFICATIONS_RINGTONE = 1;
+
+ // Used for power notification uri string if set to silent
+ private static final String POWER_NOTIFICATIONS_SILENT_URI = "silent";
+
private CheckBoxPreference mVibrateWhenRinging;
private ListPreference mVolumeOverlay;
private ListPreference mRingMode;
@@ -129,6 +140,10 @@ public class SoundSettings extends SettingsPreferenceFragment implements
private Intent mDockIntent;
private CheckBoxPreference mDockAudioMediaEnabled;
+ private CheckBoxPreference mPowerSounds;
+ private CheckBoxPreference mPowerSoundsVibrate;
+ private Preference mPowerSoundsRingtone;
+
// To track whether a confirmation dialog was clicked.
private boolean mDialogClicked;
private Dialog mWaiverDialog;
@@ -312,6 +327,40 @@ public class SoundSettings extends SettingsPreferenceFragment implements
};
initDockSettings();
+
+ // power state change notification sounds
+ mPowerSounds = (CheckBoxPreference) findPreference(KEY_POWER_NOTIFICATIONS);
+ mPowerSounds.setChecked(Settings.Global.getInt(resolver,
+ Settings.Global.POWER_NOTIFICATIONS_ENABLED, 0) != 0);
+ mPowerSoundsVibrate = (CheckBoxPreference) findPreference(KEY_POWER_NOTIFICATIONS_VIBRATE);
+ mPowerSoundsVibrate.setChecked(Settings.Global.getInt(resolver,
+ Settings.Global.POWER_NOTIFICATIONS_VIBRATE, 0) != 0);
+ if (vibrator == null || !vibrator.hasVibrator()) {
+ removePreference(KEY_POWER_NOTIFICATIONS_VIBRATE);
+ }
+
+ mPowerSoundsRingtone = findPreference(KEY_POWER_NOTIFICATIONS_RINGTONE);
+ String currentPowerRingtonePath =
+ Settings.Global.getString(resolver, Settings.Global.POWER_NOTIFICATIONS_RINGTONE);
+
+ // set to default notification if we don't yet have one
+ if (currentPowerRingtonePath == null) {
+ currentPowerRingtonePath = Settings.System.DEFAULT_NOTIFICATION_URI.toString();
+ Settings.Global.putString(getContentResolver(),
+ Settings.Global.POWER_NOTIFICATIONS_RINGTONE, currentPowerRingtonePath);
+ }
+ // is it silent ?
+ if (currentPowerRingtonePath.equals(POWER_NOTIFICATIONS_SILENT_URI)) {
+ mPowerSoundsRingtone.setSummary(
+ getString(R.string.power_notifications_ringtone_silent));
+ } else {
+ final Ringtone ringtone =
+ RingtoneManager.getRingtone(getActivity(), Uri.parse(currentPowerRingtonePath));
+ if (ringtone != null) {
+ mPowerSoundsRingtone.setSummary(ringtone.getTitle(getActivity()));
+ }
+ }
+
}
@Override
@@ -505,6 +554,20 @@ public class SoundSettings extends SettingsPreferenceFragment implements
Settings.System.putInt(getContentResolver(), Settings.System.SAFE_HEADSET_VOLUME, 1);
}
+ } else if (preference == mPowerSounds) {
+ Settings.Global.putInt(getContentResolver(),
+ Settings.Global.POWER_NOTIFICATIONS_ENABLED,
+ mPowerSounds.isChecked() ? 1 : 0);
+
+ } else if (preference == mPowerSoundsVibrate) {
+ Settings.Global.putInt(getContentResolver(),
+ Settings.Global.POWER_NOTIFICATIONS_VIBRATE,
+ mPowerSoundsVibrate.isChecked() ? 1 : 0);
+
+ } else if (preference == mPowerSoundsRingtone) {
+ launchNotificationSoundPicker(REQUEST_CODE_POWER_NOTIFICATIONS_RINGTONE,
+ Settings.Global.getString(getContentResolver(),
+ Settings.Global.POWER_NOTIFICATIONS_RINGTONE));
} else {
// If we didn't handle it, let preferences handle it.
return super.onPreferenceTreeClick(preferenceScreen, preference);
@@ -625,6 +688,58 @@ public class SoundSettings extends SettingsPreferenceFragment implements
}
}
+ private void launchNotificationSoundPicker(int code, String currentPowerRingtonePath) {
+ final Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
+
+ intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,
+ RingtoneManager.TYPE_NOTIFICATION);
+ intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI,
+ Settings.System.DEFAULT_NOTIFICATION_URI);
+ if (currentPowerRingtonePath != null &&
+ !currentPowerRingtonePath.equals(POWER_NOTIFICATIONS_SILENT_URI)) {
+ Uri uri = Uri.parse(currentPowerRingtonePath);
+ if (uri != null) {
+ intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, uri);
+ }
+ }
+ startActivityForResult(intent, code);
+ }
+
+ private void setPowerNotificationRingtone(Intent intent) {
+ final Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
+
+ final String toneName;
+ final String toneUriPath;
+
+ if ( uri != null ) {
+ final Ringtone ringtone = RingtoneManager.getRingtone(getActivity(), uri);
+ toneName = ringtone.getTitle(getActivity());
+ toneUriPath = uri.toString();
+ } else {
+ // silent
+ toneName = getString(R.string.power_notifications_ringtone_silent);
+ toneUriPath = POWER_NOTIFICATIONS_SILENT_URI;
+ }
+
+ mPowerSoundsRingtone.setSummary(toneName);
+ Settings.Global.putString(getContentResolver(),
+ Settings.Global.POWER_NOTIFICATIONS_RINGTONE, toneUriPath);
+ }
+
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ switch (requestCode) {
+ case REQUEST_CODE_POWER_NOTIFICATIONS_RINGTONE:
+ if (resultCode == Activity.RESULT_OK) {
+ setPowerNotificationRingtone(data);
+ }
+ break;
+ default:
+ super.onActivityResult(requestCode, resultCode, data);
+ break;
+ }
+ }
+
@Override
public Dialog onCreateDialog(int id) {
if (id == DIALOG_NOT_DOCKED) {