Permalink
Browse files

Settings: add safe headset volume and less annoying sound notification

Add settings for both features.

Change-Id: I8ab4f4b9ec320238b05ac51fb76ac24b93c37d37
  • Loading branch information...
kufikugel authored and akhilnarang committed Nov 15, 2014
1 parent bc8d5b9 commit 0ec8a0ceed307040332d16fb5f9d5f28deb34d8e
@@ -12,6 +12,33 @@
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Less Notifications -->
<string-array name="less_notification_sounds_entries">
<item>@string/less_notification_sounds_default</item>
<item>@string/less_notification_sounds_3s</item>
<item>@string/less_notification_sounds_5s</item>
<item>@string/less_notification_sounds_10s</item>
<item>@string/less_notification_sounds_15s</item>
<item>@string/less_notification_sounds_30s</item>
<item>@string/less_notification_sounds_45s</item>
<item>@string/less_notification_sounds_1m</item>
<item>@string/less_notification_sounds_2m</item>
<item>@string/less_notification_sounds_5m</item>
</string-array>
<string-array name="less_notification_sounds_values" translatable="false">
<item>0</item>
<item>3000</item>
<item>5000</item>
<item>10000</item>
<item>15000</item>
<item>30000</item>
<item>45000</item>
<item>60000</item>
<item>120000</item>
<item>300000</item>
</string-array>
<!-- Titles for window animation scale preference. [CHAR LIMIT=35] -->
<string-array name="window_animation_scale_entries_aosp">
<item>Animation off</item>
@@ -221,4 +221,28 @@
<string name="adb_over_network_summary">Enable TCP/IP debugging over network interfaces (Wi\u2011Fi, USB networks). This setting is reset on reboot</string>
<string name="adb_over_network_warning">WARNING: When ADB over network is enabled, your phone is open for intrusions on all connected networks!\n\nOnly use this feature when you are connected on trusted networks.\n\nDo you really want to enable this function?</string>
<!-- Sound settings -->
<string name="advanced_sound_title">Advanced options</string>
<string name="sound_title">Sound</string>
<!-- Safe headset volume restore checkbox -->
<string name="safe_headset_volume_title">Safe headset volume</string>
<string name="safe_headset_volume_summary">Prevent loud volume levels when headset is first plugged in</string>
<string name="safe_headset_volume_warning_dialog_text">Listening at high volume for long periods may damage your hearing. Disable it with caution.</string>
<!-- Less Notification sounds -->
<string name="notifications_category_title">Notifications</string>
<string name="less_notification_sounds_title">Less frequent notification sounds</string>
<string name="less_notification_sounds_summary">Limit the notification sounds of each app to only play once per set time period</string>
<string name="less_notification_sounds_default">Default Behaviour</string>
<string name="less_notification_sounds_3s">3 seconds</string>
<string name="less_notification_sounds_5s">5 seconds</string>
<string name="less_notification_sounds_10s">10 seconds</string>
<string name="less_notification_sounds_15s">15 seconds</string>
<string name="less_notification_sounds_30s">30 seconds</string>
<string name="less_notification_sounds_45s">45 seconds</string>
<string name="less_notification_sounds_1m">1 minute</string>
<string name="less_notification_sounds_2m">2 minutes</string>
<string name="less_notification_sounds_5m">5 minutes</string>
</resources>
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 SlimRoms Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/sound_title"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
<SwitchPreference
android:key="safe_headset_volume"
android:title="@string/safe_headset_volume_title"
android:summary="@string/safe_headset_volume_summary"
android:persistent="false"
android:defaultValue="true" />
<PreferenceCategory
android:title="@string/notifications_category_title" />
<ListPreference
android:key="less_notification_sounds"
android:title="@string/less_notification_sounds_title"
android:summary="@string/less_notification_sounds_summary"
android:entries="@array/less_notification_sounds_entries"
android:entryValues="@array/less_notification_sounds_values"
android:persistent="false" />
</PreferenceScreen>
@@ -110,6 +110,13 @@
android:persistent="false"
android:fragment="com.android.settings.notification.OtherSoundSettings" />
<!-- Advanced options -->
<PreferenceScreen
android:key="advanced_sound_settings"
android:title="@string/advanced_sound_title"
android:persistent="false"
android:fragment="com.android.settings.aosip.SoundSettings" />
<!-- Cast -->
<PreferenceScreen
android:key="wifi_display"
@@ -31,6 +31,7 @@
public abstract class InstrumentedFragment extends PreferenceFragment {
// Declare new temporary categories here, starting after this value.
public static final int UNDECLARED = 100000;
public static final int ADVANCED = 100002;
// Used by PreferenceActivity for the dummy fragment it adds, no useful data here.
public static final int PREFERENCE_ACTIVITY_FRAGMENT = UNDECLARED + 1;
@@ -0,0 +1,155 @@
/*
* Copyright (C) 2013 SlimRoms Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.aosip;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
import android.provider.Settings;
import android.util.Log;
import com.android.settings.InstrumentedFragment;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
public class SoundSettings extends SettingsPreferenceFragment implements
Preference.OnPreferenceChangeListener {
private static final String TAG = "SoundSettings";
private static final int DLG_SAFE_HEADSET_VOLUME = 0;
private static final String KEY_SAFE_HEADSET_VOLUME = "safe_headset_volume";
private static final String PREF_LESS_NOTIFICATION_SOUNDS = "less_notification_sounds";
private SwitchPreference mSafeHeadsetVolume;
private ListPreference mAnnoyingNotifications;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.slim_sound_settings);
mSafeHeadsetVolume = (SwitchPreference) findPreference(KEY_SAFE_HEADSET_VOLUME);
mSafeHeadsetVolume.setChecked(Settings.System.getInt(getContentResolver(),
Settings.System.SAFE_HEADSET_VOLUME, 1) != 0);
mSafeHeadsetVolume.setOnPreferenceChangeListener(this);
mAnnoyingNotifications = (ListPreference) findPreference(PREF_LESS_NOTIFICATION_SOUNDS);
int notificationThreshold = Settings.System.getInt(getContentResolver(),
Settings.System.MUTE_ANNOYING_NOTIFICATIONS_THRESHOLD,
0);
mAnnoyingNotifications.setValue(Integer.toString(notificationThreshold));
mAnnoyingNotifications.setOnPreferenceChangeListener(this);
}
@Override
public void onResume() {
super.onResume();
}
public boolean onPreferenceChange(Preference preference, Object objValue) {
final String key = preference.getKey();
if (KEY_SAFE_HEADSET_VOLUME.equals(key)) {
if ((Boolean) objValue) {
Settings.System.putInt(getContentResolver(),
Settings.System.SAFE_HEADSET_VOLUME, 1);
} else {
showDialogInner(DLG_SAFE_HEADSET_VOLUME);
}
}
if (PREF_LESS_NOTIFICATION_SOUNDS.equals(key)) {
final int val = Integer.valueOf((String) objValue);
Settings.System.putInt(getContentResolver(),
Settings.System.MUTE_ANNOYING_NOTIFICATIONS_THRESHOLD, val);
}
return true;
}
private void showDialogInner(int id) {
DialogFragment newFragment = MyAlertDialogFragment.newInstance(id);
newFragment.setTargetFragment(this, 0);
newFragment.show(getFragmentManager(), "dialog " + id);
}
public static class MyAlertDialogFragment extends DialogFragment {
public static MyAlertDialogFragment newInstance(int id) {
MyAlertDialogFragment frag = new MyAlertDialogFragment();
Bundle args = new Bundle();
args.putInt("id", id);
frag.setArguments(args);
return frag;
}
SoundSettings getOwner() {
return (SoundSettings) getTargetFragment();
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
int id = getArguments().getInt("id");
switch (id) {
case DLG_SAFE_HEADSET_VOLUME:
return new AlertDialog.Builder(getActivity())
.setTitle(R.string.attention)
.setMessage(R.string.safe_headset_volume_warning_dialog_text)
.setPositiveButton(R.string.dlg_ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Settings.System.putInt(getOwner().getContentResolver(),
Settings.System.SAFE_HEADSET_VOLUME, 0);
}
})
.setNegativeButton(R.string.dlg_cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
})
.create();
}
throw new IllegalArgumentException("unknown id " + id);
}
@Override
public void onCancel(DialogInterface dialog) {
int id = getArguments().getInt("id");
switch (id) {
case DLG_SAFE_HEADSET_VOLUME:
getOwner().mSafeHeadsetVolume.setChecked(true);
break;
}
}
}
@Override
protected int getMetricsCategory() {
return InstrumentedFragment.ADVANCED;
}
}

0 comments on commit 0ec8a0c

Please sign in to comment.