diff options
author | Sam Mortimer <sam@mortimer.me.uk> | 2013-03-18 16:13:25 -0700 |
---|---|---|
committer | Adnan Begovic <adnan@cyngn.com> | 2015-10-29 17:36:32 -0700 |
commit | 6cdb128c3713a61c973cdfd38add37a5b77bc451 (patch) | |
tree | 716324c78edc4262af0ad56e5ab0e199ac9c189a | |
parent | 090c727e9fea698aee8a2712cc8ee488c5e2f2c2 (diff) | |
download | packages_apps_Settings-6cdb128c3713a61c973cdfd38add37a5b77bc451.zip packages_apps_Settings-6cdb128c3713a61c973cdfd38add37a5b77bc451.tar.gz packages_apps_Settings-6cdb128c3713a61c973cdfd38add37a5b77bc451.tar.bz2 |
[2/2] Forward port power connect/disconnect notification support
Original commit info:
[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/
Change-Id: I7ddd8a47ae4f9a62c586023d151ac42bbe8424c7
Power sound notifications: fix ringtone picker title
Change-Id: Ied0a08ec1607b778324e69a7b40bac056235bebf
Settings: Rename 'Power sounds' to 'Charging sounds' and add summary
VOld_Change-Id: I1cb872917e2d03f0a1c77c25c27f2a0496f9bc05
Old_Change-Id: Ibde52fcd6fd0fabc9eeefc7e6f5a3971527285d7
Change-Id: If247c184c5ea2a1e13dd22ef121cbc9d5d542fd5
Signed-off-by: STELIX <ssspinni@gmail.com>
-rw-r--r-- | res/values/cm_strings.xml | 17 | ||||
-rw-r--r-- | res/xml/other_sound_settings.xml | 23 | ||||
-rw-r--r-- | src/com/android/settings/notification/OtherSoundSettings.java | 133 |
3 files changed, 173 insertions, 0 deletions
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml index 12fabd3..255f1df 100644 --- a/res/values/cm_strings.xml +++ b/res/values/cm_strings.xml @@ -563,4 +563,21 @@ <string name="volume_keys_control_ring_stream_title">Volume keys control ringtone volume</string> <string name="volume_keys_control_ring_stream_summary">If on, volume keys control ringtone volume. If off, volume keys control media volume.</string> + + <string name="category_calibration">Calibration</string> + <string name="display_and_lights">Display & lights</string> + + <!-- Category title for Charging sounds (Power state change) specific Settings. + [CHAR LIMIT=40] --> + <string name="power_notifications_category_title">Charging sounds</string> + + <!-- Sound settings, Charging sounds enable/disable, setting check box label --> + <string name="power_notifications_enable_title">Enable</string> + <string name="power_notifications_enable_summary">Play a sound when connecting or disconnecting the charger</string> + <!-- Sound settings, Charging sounds vibrate enable/disable, setting check box label --> + <string name="power_notifications_vibrate_title">Vibrate</string> + <!-- Sound settings, Charging sounds ringtone selection, preference label --> + <string name="power_notifications_ringtone_title">Notification sound</string> + <!-- Sound settings, charging sounds label for ringtone == none --> + <string name="power_notifications_ringtone_silent">Silent</string> </resources> diff --git a/res/xml/other_sound_settings.xml b/res/xml/other_sound_settings.xml index 115a8ea..834c1ff 100644 --- a/res/xml/other_sound_settings.xml +++ b/res/xml/other_sound_settings.xml @@ -82,4 +82,27 @@ android:title="@string/emergency_tone_title" android:persistent="false" /> + <PreferenceCategory + android:title="@string/power_notifications_category_title"/> + + <SwitchPreference + android:key="power_notifications" + android:title="@string/power_notifications_enable_title" + android:summary="@string/power_notifications_enable_summary" + android:defaultValue="false" + android:persistent="false" /> + + <SwitchPreference + 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/notification/OtherSoundSettings.java b/src/com/android/settings/notification/OtherSoundSettings.java index a41f6f2..a4b5605 100644 --- a/src/com/android/settings/notification/OtherSoundSettings.java +++ b/src/com/android/settings/notification/OtherSoundSettings.java @@ -19,15 +19,22 @@ package com.android.settings.notification; import static com.android.settings.notification.SettingPref.TYPE_GLOBAL; import static com.android.settings.notification.SettingPref.TYPE_SYSTEM; +import android.app.Activity; import android.content.ContentResolver; import android.content.Context; +import android.content.Intent; import android.content.res.Resources; import android.database.ContentObserver; import android.media.AudioManager; +import android.media.Ringtone; +import android.media.RingtoneManager; import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.os.Vibrator; +import android.preference.Preference; +import android.preference.PreferenceScreen; +import android.preference.SwitchPreference; import android.provider.SearchIndexableResource; import android.provider.Settings.Global; import android.provider.Settings.System; @@ -70,6 +77,20 @@ public class OtherSoundSettings extends SettingsPreferenceFragment implements In private static final String KEY_EMERGENCY_TONE = "emergency_tone"; private static final String KEY_VIBRATION_INTENSITY = "vibration_intensity"; + 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"; + + // 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 SwitchPreference mPowerSounds; + private SwitchPreference mPowerSoundsVibrate; + private Preference mPowerSoundsRingtone; + private static final SettingPref PREF_DIAL_PAD_TONES = new SettingPref( TYPE_SYSTEM, KEY_DIAL_PAD_TONES, System.DTMF_TONE_WHEN_DIALING, DEFAULT_ON) { @Override @@ -212,6 +233,40 @@ public class OtherSoundSettings extends SettingsPreferenceFragment implements In mContext = getActivity(); + // power state change notification sounds + mPowerSounds = (SwitchPreference) findPreference(KEY_POWER_NOTIFICATIONS); + mPowerSounds.setChecked(Global.getInt(getContentResolver(), + Global.POWER_NOTIFICATIONS_ENABLED, 0) != 0); + mPowerSoundsVibrate = (SwitchPreference) findPreference(KEY_POWER_NOTIFICATIONS_VIBRATE); + mPowerSoundsVibrate.setChecked(Global.getInt(getContentResolver(), + Global.POWER_NOTIFICATIONS_VIBRATE, 0) != 0); + Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); + if (vibrator == null || !vibrator.hasVibrator()) { + removePreference(KEY_POWER_NOTIFICATIONS_VIBRATE); + } + + mPowerSoundsRingtone = findPreference(KEY_POWER_NOTIFICATIONS_RINGTONE); + String currentPowerRingtonePath = + Global.getString(getContentResolver(), Global.POWER_NOTIFICATIONS_RINGTONE); + + // set to default notification if we don't yet have one + if (currentPowerRingtonePath == null) { + currentPowerRingtonePath = System.DEFAULT_NOTIFICATION_URI.toString(); + Global.putString(getContentResolver(), + 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())); + } + } + for (SettingPref pref : PREFS) { pref.init(this); } @@ -229,6 +284,30 @@ public class OtherSoundSettings extends SettingsPreferenceFragment implements In mSettingsObserver.register(false); } + @Override + public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { + if (preference == mPowerSounds) { + Global.putInt(getContentResolver(), + Global.POWER_NOTIFICATIONS_ENABLED, + mPowerSounds.isChecked() ? 1 : 0); + + } else if (preference == mPowerSoundsVibrate) { + Global.putInt(getContentResolver(), + Global.POWER_NOTIFICATIONS_VIBRATE, + mPowerSoundsVibrate.isChecked() ? 1 : 0); + + } else if (preference == mPowerSoundsRingtone) { + launchNotificationSoundPicker(REQUEST_CODE_POWER_NOTIFICATIONS_RINGTONE, + Global.getString(getContentResolver(), + Global.POWER_NOTIFICATIONS_RINGTONE)); + } else { + // If we didn't handle it, let preferences handle it. + return super.onPreferenceTreeClick(preferenceScreen, preference); + } + + return true; + } + private static boolean hasDockSettings(Context context) { return context.getResources().getBoolean(R.bool.has_dock_settings); } @@ -290,4 +369,58 @@ public class OtherSoundSettings extends SettingsPreferenceFragment implements In return rt; } }; + + private void launchNotificationSoundPicker(int code, String currentPowerRingtonePath) { + final Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); + + intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, + getString(R.string.power_notifications_ringtone_title)); + intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, + RingtoneManager.TYPE_NOTIFICATION); + intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, + 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); + Global.putString(getContentResolver(), + 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; + } + } } |