summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
authorSam Mortimer <sam@mortimer.me.uk>2013-03-18 16:13:25 -0700
committerSam Mortimer <sam@mortimer.me.uk>2013-04-15 19:37:59 -0700
commitb608d71ea4d0e65d32bf1ce6fd5e34dc37040b51 (patch)
tree17d1dc321730960a6c4401b2311715a61072a937 /src/com/android
parent67f59560ec70f1d492994e5b0d5b4d30a5ee5df3 (diff)
downloadpackages_apps_settings-b608d71ea4d0e65d32bf1ce6fd5e34dc37040b51.zip
packages_apps_settings-b608d71ea4d0e65d32bf1ce6fd5e34dc37040b51.tar.gz
packages_apps_settings-b608d71ea4d0e65d32bf1ce6fd5e34dc37040b51.tar.bz2
[2/2] Power connect/disconnect notification support
part 1/2: frameworks/base PowerUI and Settings http://review.cyanogenmod.org/#/c/35241/ part 2/2: packages/apps/Settings Sound settings http://review.cyanogenmod.org/#/c/35242/ patchset 3: set settings persistence and dependencies in xml resource file shrink long lines add the default notification tone to the ringtone picker and remove the now redundant "use default" checkbox move values/strings.xml content to the cyanogenmod section improve (mostly delete) wording in values/strings.xml remove tab whitespace patchset 5: move strings to cm_strings patchset 6: make vibrate optional (default on) change heading text: power notifications -> power sounds patchset 7: hide vibrate option if hw capability doesn't exist patchset 8: change vibrate to default to off Change-Id: I7ddd8a47ae4f9a62c586023d151ac42bbe8424c7
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/settings/SoundSettings.java115
1 files changed, 115 insertions, 0 deletions
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) {