From 9ec232bda43eebc9fad16d8b2c45116876749b53 Mon Sep 17 00:00:00 2001 From: Lars Greiss Date: Sat, 23 May 2020 14:02:11 +0530 Subject: [PATCH] Cherish: 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 Change-Id: I6fe5aa72ce68f28ee9c57520e36d4800a9263546 --- res/values-vi/cherish_strings.xml | 13 +++++- res/values/cherish_arrays.xml | 19 +++++++++ res/values/cherish_strings.xml | 10 +++++ res/xml/heads_up_settings.xml | 7 ++++ .../cherish/settings/fragments/HeadsUp.java | 41 ++++++++++++++++++- 5 files changed, 87 insertions(+), 3 deletions(-) diff --git a/res/values-vi/cherish_strings.xml b/res/values-vi/cherish_strings.xml index ed01fc6..52f0bdf 100644 --- a/res/values-vi/cherish_strings.xml +++ b/res/values-vi/cherish_strings.xml @@ -123,8 +123,8 @@ Bình thường Nhỏ Ẩn - Hiển thị giây - Hiển thị giây trong đồng hồ trên thanh trạng thái + Hiển thị giây + Hiển thị giây trong đồng hồ trên thanh trạng thái Ngày Hiển thị ngày tùy chỉnh trước đồng hồ Ẩn @@ -435,4 +435,13 @@ Chọn ứng dụng Xóa Xóa mục đã chọn? + + Hết giờ + Thông báo nhìn nhanh sẽ hiển thị cho %d giây + 2 giây + 4 giây + 5 giây + 6 giây + 8 giây + 10 giây diff --git a/res/values/cherish_arrays.xml b/res/values/cherish_arrays.xml index 36fc5fe..e09ec67 100644 --- a/res/values/cherish_arrays.xml +++ b/res/values/cherish_arrays.xml @@ -400,4 +400,23 @@ 2 3 + + + + @string/heads_up_time_out_2sec + @string/heads_up_time_out_4sec + @string/heads_up_time_out_5sec + @string/heads_up_time_out_6sec + @string/heads_up_time_out_8sec + @string/heads_up_time_out_10sec + + + + 2000 + 4000 + 5000 + 6000 + 8000 + 10000 + diff --git a/res/values/cherish_strings.xml b/res/values/cherish_strings.xml index b33874e..a6303b4 100644 --- a/res/values/cherish_strings.xml +++ b/res/values/cherish_strings.xml @@ -476,6 +476,16 @@ Dynamic mode Try detecting and adding gaming apps automatically + + Time out + Peeking notifications will show for %d seconds + 2 seconds + 4 seconds + 5 seconds + 6 seconds + 8 seconds + 10 seconds + Heads Up Pop up statusbar notifications diff --git a/res/xml/heads_up_settings.xml b/res/xml/heads_up_settings.xml index 901190d..c0020a9 100644 --- a/res/xml/heads_up_settings.xml +++ b/res/xml/heads_up_settings.xml @@ -16,6 +16,13 @@ + + diff --git a/src/com/cherish/settings/fragments/HeadsUp.java b/src/com/cherish/settings/fragments/HeadsUp.java index 3b55294..bf93b2c 100644 --- a/src/com/cherish/settings/fragments/HeadsUp.java +++ b/src/com/cherish/settings/fragments/HeadsUp.java @@ -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 HeadsUp 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 HeadsUp 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 HeadsUp 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