HeadsUp: add timeout option (2/2)

Forward ported to marshmallow/nougat By: @BeansTown106
removed the none option as we now have a headsup minimum time of 2seconds
added 5sec option as that is the new default in marshmallow

Signed-off-by: Arghya Chanda <arghyac35@gmail.com>
Change-Id: I6af7fef23f1cdb62390bd4bf8b81b5ca9bdb2a8d
Signed-off-by: SagarMakhar <sagarmakhar@gmail.com>
Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
Lars Greiss
2016-11-03 15:02:19 +08:00
committed by Hưng Phan
parent cc455a06ed
commit 5ddc665991
4 changed files with 75 additions and 1 deletions

View File

@@ -24,4 +24,22 @@
<item>1</item>
<item>2</item>
</string-array>
<!-- Heads up timeout -->
<string-array name="heads_up_time_out_entries" translatable="false">
<item>@string/heads_up_time_out_2sec</item>
<item>@string/heads_up_time_out_4sec</item>
<item>@string/heads_up_time_out_5sec</item>
<item>@string/heads_up_time_out_6sec</item>
<item>@string/heads_up_time_out_8sec</item>
<item>@string/heads_up_time_out_10sec</item>
</string-array>
<string-array name="heads_up_time_out_values" translatable="false">
<item>2000</item>
<item>4000</item>
<item>5000</item>
<item>6000</item>
<item>8000</item>
<item>10000</item>
</string-array>
</resources>

View File

@@ -204,4 +204,14 @@
<string name="dialog_delete_title">Delete</string>
<string name="dialog_delete_message">Remove selected item?</string>
<!-- Heads up timeout -->
<string name="heads_up_time_out_title">Time out</string>
<string name="heads_up_time_out_summary">Peeking notifications will show for <xliff:g id="number">%d</xliff:g> seconds</string>
<string name="heads_up_time_out_2sec">2 seconds</string>
<string name="heads_up_time_out_4sec">4 seconds</string>
<string name="heads_up_time_out_5sec">5 seconds</string>
<string name="heads_up_time_out_6sec">6 seconds</string>
<string name="heads_up_time_out_8sec">8 seconds</string>
<string name="heads_up_time_out_10sec">10 seconds</string>
</resources>

View File

@@ -22,6 +22,13 @@
android:summaryOff="@string/summary_heads_up_disabled"
android:defaultValue="true" />
<ListPreference
android:key="heads_up_time_out"
android:title="@string/heads_up_time_out_title"
android:entries="@array/heads_up_time_out_entries"
android:entryValues="@array/heads_up_time_out_values"
android:persistent="false" />
<PreferenceCategory
android:title="@string/heads_up_stoplist_title"
android:key="stoplist_applications"

View File

@@ -22,7 +22,9 @@ import android.content.DialogInterface;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.os.Bundle;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceGroup;
import androidx.preference.PreferenceScreen;
@@ -48,10 +50,11 @@ import java.util.List;
import java.util.Map;
public class HeadsUpSettings extends SettingsPreferenceFragment
implements Preference.OnPreferenceClickListener {
implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener {
private static final int DIALOG_STOPLIST_APPS = 0;
private static final int DIALOG_BLACKLIST_APPS = 1;
private static final String PREF_HEADS_UP_TIME_OUT = "heads_up_time_out";
private PackageListAdapter mPackageAdapter;
private PackageManager mPackageManager;
@@ -59,6 +62,7 @@ public class HeadsUpSettings extends SettingsPreferenceFragment
private PreferenceGroup mBlacklistPrefList;
private Preference mAddStoplistPref;
private Preference mAddBlacklistPref;
private ListPreference mHeadsUpTimeOut;
private String mStoplistPackageList;
private String mBlacklistPackageList;
@@ -87,6 +91,41 @@ public class HeadsUpSettings extends SettingsPreferenceFragment
mAddStoplistPref.setOnPreferenceClickListener(this);
mAddBlacklistPref.setOnPreferenceClickListener(this);
Resources systemUiResources;
try {
systemUiResources = getPackageManager().getResourcesForApplication("com.android.systemui");
} catch (Exception e) {
return;
}
int defaultTimeOut = systemUiResources.getInteger(systemUiResources.getIdentifier(
"com.android.systemui:integer/heads_up_notification_decay", null, null));
mHeadsUpTimeOut = (ListPreference) findPreference(PREF_HEADS_UP_TIME_OUT);
mHeadsUpTimeOut.setOnPreferenceChangeListener(this);
int headsUpTimeOut = Settings.System.getInt(getContentResolver(),
Settings.System.HEADS_UP_TIMEOUT, defaultTimeOut);
mHeadsUpTimeOut.setValue(String.valueOf(headsUpTimeOut));
updateHeadsUpTimeOutSummary(headsUpTimeOut);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference == mHeadsUpTimeOut) {
int headsUpTimeOut = Integer.valueOf((String) newValue);
Settings.System.putInt(getContentResolver(),
Settings.System.HEADS_UP_TIMEOUT,
headsUpTimeOut);
updateHeadsUpTimeOutSummary(headsUpTimeOut);
return true;
}
return false;
}
private void updateHeadsUpTimeOutSummary(int value) {
String summary = getResources().getString(R.string.heads_up_time_out_summary,
value / 1000);
mHeadsUpTimeOut.setSummary(summary);
}
@Override