summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/notification/OtherSoundSettings.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/settings/notification/OtherSoundSettings.java')
-rw-r--r--src/com/android/settings/notification/OtherSoundSettings.java154
1 files changed, 138 insertions, 16 deletions
diff --git a/src/com/android/settings/notification/OtherSoundSettings.java b/src/com/android/settings/notification/OtherSoundSettings.java
index 969ec90..935aea5 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;
@@ -37,8 +44,10 @@ import com.android.internal.logging.MetricsLogger;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;
+import com.android.settings.hardware.VibratorIntensity;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
+import cyanogenmod.providers.CMSettings;
import java.util.ArrayList;
import java.util.Arrays;
@@ -47,6 +56,7 @@ import java.util.List;
public class OtherSoundSettings extends SettingsPreferenceFragment implements Indexable {
private static final String TAG = "OtherSoundSettings";
+ private static final int DEFAULT_OFF = 0;
private static final int DEFAULT_ON = 1;
private static final int EMERGENCY_TONE_SILENT = 0;
@@ -62,11 +72,23 @@ public class OtherSoundSettings extends SettingsPreferenceFragment implements In
private static final String KEY_SCREEN_LOCKING_SOUNDS = "screen_locking_sounds";
private static final String KEY_CHARGING_SOUNDS = "charging_sounds";
private static final String KEY_DOCKING_SOUNDS = "docking_sounds";
+ private static final String KEY_VOLUME_ADJUST_SOUNDS = "volume_adjust_sounds";
private static final String KEY_TOUCH_SOUNDS = "touch_sounds";
- private static final String KEY_VIBRATE_ON_TOUCH = "vibrate_on_touch";
private static final String KEY_DOCK_AUDIO_MEDIA = "dock_audio_media";
private static final String KEY_EMERGENCY_TONE = "emergency_tone";
+ 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 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
@@ -79,7 +101,7 @@ public class OtherSoundSettings extends SettingsPreferenceFragment implements In
TYPE_SYSTEM, KEY_SCREEN_LOCKING_SOUNDS, System.LOCKSCREEN_SOUNDS_ENABLED, DEFAULT_ON);
private static final SettingPref PREF_CHARGING_SOUNDS = new SettingPref(
- TYPE_GLOBAL, KEY_CHARGING_SOUNDS, Global.CHARGING_SOUNDS_ENABLED, DEFAULT_ON);
+ TYPE_GLOBAL, KEY_CHARGING_SOUNDS, Global.CHARGING_SOUNDS_ENABLED, DEFAULT_OFF);
private static final SettingPref PREF_DOCKING_SOUNDS = new SettingPref(
TYPE_GLOBAL, KEY_DOCKING_SOUNDS, Global.DOCK_SOUNDS_ENABLED, DEFAULT_ON) {
@@ -89,6 +111,15 @@ public class OtherSoundSettings extends SettingsPreferenceFragment implements In
}
};
+ private static final SettingPref PREF_VOLUME_ADJUST_SOUNDS = new SettingPref(
+ TYPE_SYSTEM, KEY_VOLUME_ADJUST_SOUNDS, CMSettings.System.VOLUME_ADJUST_SOUNDS_ENABLED,
+ DEFAULT_ON) {
+ @Override
+ public boolean isApplicable(Context context) {
+ return Utils.hasVolumeRocker(context);
+ }
+ };
+
private static final SettingPref PREF_TOUCH_SOUNDS = new SettingPref(
TYPE_SYSTEM, KEY_TOUCH_SOUNDS, System.SOUND_EFFECTS_ENABLED, DEFAULT_ON) {
@Override
@@ -103,14 +134,6 @@ public class OtherSoundSettings extends SettingsPreferenceFragment implements In
}
};
- private static final SettingPref PREF_VIBRATE_ON_TOUCH = new SettingPref(
- TYPE_SYSTEM, KEY_VIBRATE_ON_TOUCH, System.HAPTIC_FEEDBACK_ENABLED, DEFAULT_ON) {
- @Override
- public boolean isApplicable(Context context) {
- return hasHaptic(context);
- }
- };
-
private static final SettingPref PREF_DOCK_AUDIO_MEDIA = new SettingPref(
TYPE_GLOBAL, KEY_DOCK_AUDIO_MEDIA, Global.DOCK_AUDIO_MEDIA_ENABLED,
DEFAULT_DOCK_AUDIO_MEDIA, DOCK_AUDIO_MEDIA_DISABLED, DOCK_AUDIO_MEDIA_ENABLED) {
@@ -161,8 +184,8 @@ public class OtherSoundSettings extends SettingsPreferenceFragment implements In
PREF_SCREEN_LOCKING_SOUNDS,
PREF_CHARGING_SOUNDS,
PREF_DOCKING_SOUNDS,
+ PREF_VOLUME_ADJUST_SOUNDS,
PREF_TOUCH_SOUNDS,
- PREF_VIBRATE_ON_TOUCH,
PREF_DOCK_AUDIO_MEDIA,
PREF_EMERGENCY_TONE,
};
@@ -189,6 +212,37 @@ public class OtherSoundSettings extends SettingsPreferenceFragment implements In
mContext = getActivity();
+ // power state change notification sounds
+ mPowerSoundsVibrate = (SwitchPreference) findPreference(KEY_POWER_NOTIFICATIONS_VIBRATE);
+ mPowerSoundsVibrate.setChecked(CMSettings.Global.getInt(getContentResolver(),
+ CMSettings.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 = CMSettings.Global.getString(getContentResolver(),
+ CMSettings.Global.POWER_NOTIFICATIONS_RINGTONE);
+
+ // set to default notification if we don't yet have one
+ if (currentPowerRingtonePath == null) {
+ currentPowerRingtonePath = System.DEFAULT_NOTIFICATION_URI.toString();
+ CMSettings.Global.putString(getContentResolver(),
+ CMSettings.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);
}
@@ -206,13 +260,27 @@ public class OtherSoundSettings extends SettingsPreferenceFragment implements In
mSettingsObserver.register(false);
}
- private static boolean hasDockSettings(Context context) {
- return context.getResources().getBoolean(R.bool.has_dock_settings);
+ @Override
+ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
+ if (preference == mPowerSoundsVibrate) {
+ CMSettings.Global.putInt(getContentResolver(),
+ CMSettings.Global.POWER_NOTIFICATIONS_VIBRATE,
+ mPowerSoundsVibrate.isChecked() ? 1 : 0);
+
+ } else if (preference == mPowerSoundsRingtone) {
+ launchNotificationSoundPicker(REQUEST_CODE_POWER_NOTIFICATIONS_RINGTONE,
+ CMSettings.Global.getString(getContentResolver(),
+ CMSettings.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 hasHaptic(Context context) {
- final Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
- return vibrator != null && vibrator.hasVibrator();
+ private static boolean hasDockSettings(Context context) {
+ return context.getResources().getBoolean(R.bool.has_dock_settings);
}
// === Callbacks ===
@@ -267,4 +335,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);
+ CMSettings.Global.putString(getContentResolver(),
+ CMSettings.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;
+ }
+ }
}