Permalink
Browse files

Settings: HeadsUp snooze function [2/2]

5.1 introduced a snooze feature which activates when swiping up.
Default snooze time is 1 minute. Let's make it configurable!

Change-Id: Ied9e3874bffa6818a155aab635a518b6b403068d
  • Loading branch information...
Nick0703 authored and xlxfoxxlx committed Apr 12, 2015
1 parent e33cbbd commit 968a3dbf4d0a2a7d4e7aadfcb5a885b873cdcdca
View
@@ -616,5 +616,26 @@ limitations under the License.
<item>10000</item>
</string-array>
<!-- Heads up snooze -->
<string-array name="heads_up_snooze_entries">
<item>@string/disabled</item>
<item>@string/heads_up_snooze_1min</item>
<item>@string/heads_up_snooze_3min</item>
<item>@string/heads_up_snooze_5min</item>
<item>@string/heads_up_snooze_10min</item>
<item>@string/heads_up_snooze_15min</item>
<item>@string/heads_up_snooze_20min</item>
</string-array>
<string-array name="heads_up_snooze_values" translatable="false">
<item>0</item>
<item>60000</item>
<item>180000</item>
<item>300000</item>
<item>600000</item>
<item>900000</item>
<item>1200000</item>
</string-array>
</resources>
View
@@ -215,6 +215,18 @@
<string name="heads_up_time_out_8sec">8 seconds</string>
<string name="heads_up_time_out_10sec">10 seconds</string>
<!-- Heads up snooze -->
<string name="heads_up_snooze_title">Snooze timer</string>
<string name="heads_up_snooze_summary_one_minute">Swiping up on peeking notifications will snooze heads up from that application for 1 minute</string>
<string name="heads_up_snooze_summary">Swiping up on peeking notifications will snooze heads up from that application for <xliff:g id="number">%d</xliff:g> minutes</string>
<string name="heads_up_snooze_disabled_summary">Snooze timer is disabled</string>
<string name="heads_up_snooze_1min">1 minute</string>
<string name="heads_up_snooze_3min">3 minutes</string>
<string name="heads_up_snooze_5min">5 minutes</string>
<string name="heads_up_snooze_10min">10 minutes</string>
<string name="heads_up_snooze_15min">15 minutes</string>
<string name="heads_up_snooze_20min">20 minutes</string>
<!-- Power notification controls -->
<string name="power_notification_title">Power notification controls</string>
<string name="power_notification_summary">Advanced notification controls and information</string>
@@ -39,5 +39,12 @@
android:entryValues="@array/heads_up_time_out_values"
android:persistent="false" />
<ListPreference
android:key="heads_up_snooze_time"
android:title="@string/heads_up_snooze_title"
android:entries="@array/heads_up_snooze_entries"
android:entryValues="@array/heads_up_snooze_values"
android:persistent="false" />
</PreferenceScreen>
@@ -38,6 +38,12 @@
OnPreferenceChangeListener {
private static final String TAG = "HeadsUpCategory";
private static final String PREF_HEADS_UP_TIME_OUT = "heads_up_time_out";
private static final String PREF_HEADS_UP_SNOOZE_TIME = "heads_up_snooze_time";
private ListPreference mHeadsUpTimeOut;
private ListPreference mHeadsUpSnoozeTime;
@Override
protected int getMetricsCategory() {
return MetricsEvent.OWLSNEST;
@@ -68,6 +74,15 @@ public void onCreate(Bundle savedInstanceState) {
mHeadsUpTimeOut.setValue(String.valueOf(headsUpTimeOut));
updateHeadsUpTimeOutSummary(headsUpTimeOut);
int defaultSnooze = systemUiResources.getInteger(systemUiResources.getIdentifier(
"com.android.systemui:integer/heads_up_default_snooze_length_ms", null, null));
mHeadsUpSnoozeTime = (ListPreference) findPreference(PREF_HEADS_UP_SNOOZE_TIME);
mHeadsUpSnoozeTime.setOnPreferenceChangeListener(this);
int headsUpSnooze = Settings.System.getInt(getContentResolver(),
Settings.System.HEADS_UP_NOTIFICATION_SNOOZE, defaultSnooze);
mHeadsUpSnoozeTime.setValue(String.valueOf(headsUpSnooze));
updateHeadsUpSnoozeTimeSummary(headsUpSnooze);
}
@Override
@@ -83,6 +98,13 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
headsUpTimeOut);
updateHeadsUpTimeOutSummary(headsUpTimeOut);
return true;
} else if (preference == mHeadsUpSnoozeTime) {
int headsUpSnooze = Integer.valueOf((String) newValue);
Settings.System.putInt(getContentResolver(),
Settings.System.HEADS_UP_NOTIFICATION_SNOOZE,
headsUpSnooze);
updateHeadsUpSnoozeTimeSummary(headsUpSnooze);
return true;
}
return false;
}
@@ -92,5 +114,16 @@ private void updateHeadsUpTimeOutSummary(int value) {
value / 1000);
mHeadsUpTimeOut.setSummary(summary);
}
private void updateHeadsUpSnoozeTimeSummary(int value) {
if (value == 0) {
mHeadsUpSnoozeTime.setSummary(getResources().getString(R.string.heads_up_snooze_disabled_summary));
} else if (value == 60000) {
mHeadsUpSnoozeTime.setSummary(getResources().getString(R.string.heads_up_snooze_summary_one_minute));
} else {
String summary = getResources().getString(R.string.heads_up_snooze_summary, value / 60 / 1000);
mHeadsUpSnoozeTime.setSummary(summary);
}
}
}

0 comments on commit 968a3db

Please sign in to comment.