Permalink
Browse files

[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

PureNexus Edits: Remove AOSP charging sound toggle
  • Loading branch information...
sam3000 authored and xlxfoxxlx committed Mar 18, 2013
1 parent 1d640ff commit 5b125db76014f8b26d8abf7e6281f625222ad68b
@@ -266,4 +266,15 @@
<!-- Development Settings summary-->
<string name="adb_enabled">ADB Enabled</string>
<string name="adb_disabled">ADB Disabled</string>
<!-- Category title for Charging sounds -->
<string name="power_notifications_category_title">Charging sounds</string>
<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>
@@ -34,11 +34,6 @@
android:key="screen_locking_sounds"
android:title="@string/screen_locking_sounds_title" />
<!-- Charging sounds -->
<SwitchPreference
android:key="charging_sounds"
android:title="@string/charging_sounds_title" />
<!-- Docking sounds -->
<SwitchPreference
android:key="docking_sounds"
@@ -78,4 +73,24 @@
android:title="@string/emergency_tone_title"
android:summary="%s" />
<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" />
<SwitchPreference
android:key="power_notifications_vibrate"
android:title="@string/power_notifications_vibrate_title"
android:defaultValue="false"
android:dependency="power_notifications" />
<Preference
android:key="power_notifications_ringtone"
android:title="@string/power_notifications_ringtone_title"
android:dependency="power_notifications" />
</PreferenceScreen>
@@ -16,8 +16,10 @@
package com.android.settings.notification;
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;
@@ -66,7 +68,6 @@
private static final String KEY_DIAL_PAD_TONES = "dial_pad_tones";
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";
@@ -78,6 +79,20 @@
private static final String KEY_BOOT_SOUNDS = "boot_sounds";
private static final String PROPERTY_BOOT_SOUNDS = "persist.sys.bootanim.play_sound";
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
@@ -89,9 +104,6 @@ public boolean isApplicable(Context context) {
private static final SettingPref PREF_SCREEN_LOCKING_SOUNDS = new SettingPref(
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);
private static final SettingPref PREF_DOCKING_SOUNDS = new SettingPref(
TYPE_GLOBAL, KEY_DOCKING_SOUNDS, Global.DOCK_SOUNDS_ENABLED, DEFAULT_ON) {
@Override
@@ -181,7 +193,6 @@ protected String getCaption(Resources res, int value) {
private static final SettingPref[] PREFS = {
PREF_DIAL_PAD_TONES,
PREF_SCREEN_LOCKING_SOUNDS,
PREF_CHARGING_SOUNDS,
PREF_DOCKING_SOUNDS,
PREF_VOLUME_ADJUST_SOUNDS,
PREF_TOUCH_SOUNDS,
@@ -214,6 +225,40 @@ public void onCreate(Bundle savedInstanceState) {
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);
}
@@ -243,6 +288,21 @@ public boolean onPreferenceTreeClick(Preference preference) {
if (mBootSounds != null && preference == mBootSounds) {
SystemProperties.set(PROPERTY_BOOT_SOUNDS, mBootSounds.isChecked() ? "1" : "0");
return false;
} else if (preference == mPowerSounds) {
Global.putInt(getContentResolver(),
Global.POWER_NOTIFICATIONS_ENABLED,
mPowerSounds.isChecked() ? 1 : 0);
return false;
} else if (preference == mPowerSoundsVibrate) {
Global.putInt(getContentResolver(),
Global.POWER_NOTIFICATIONS_VIBRATE,
mPowerSoundsVibrate.isChecked() ? 1 : 0);
return false;
} else if (preference == mPowerSoundsRingtone) {
launchNotificationSoundPicker(REQUEST_CODE_POWER_NOTIFICATIONS_RINGTONE,
Global.getString(getContentResolver(),
Global.POWER_NOTIFICATIONS_RINGTONE));
return false;
} else {
return super.onPreferenceTreeClick(preference);
}
@@ -309,4 +369,58 @@ public void onChange(boolean selfChange, Uri uri) {
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;
}
}
}

0 comments on commit 5b125db

Please sign in to comment.