From eeb74b4c61892bc7cf57f9bb6fa309f845c0c976 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Sun, 15 Mar 2015 21:36:39 +0100 Subject: [PATCH] Preferences: "Generic Notification Support" is no longer a checkbox - it now opens the Android Notificaion Permission Dialog If the permission is not granted we wont get notfifications, an extra preference for Gadgetbridge is pointless, so I removed it. --- .../gadgetbridge/NotificationListener.java | 3 --- .../gadgetbridge/SettingsActivity.java | 25 +++++++++++++++--- app/src/main/res/xml/pref_notification.xml | 26 +++++++++---------- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/NotificationListener.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/NotificationListener.java index 25613927..f1d936ce 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/NotificationListener.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/NotificationListener.java @@ -31,9 +31,6 @@ public class NotificationListener extends NotificationListenerService { Log.i(TAG, source); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); - if (!sharedPrefs.getBoolean("notifications_generic", true)) { - return; - } if (!sharedPrefs.getBoolean("notifications_generic_whenscreenon", false)) { PowerManager powermanager = (PowerManager) getSystemService(POWER_SERVICE); if (powermanager.isScreenOn()) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/SettingsActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/SettingsActivity.java index d4f194c2..67c0df9b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/SettingsActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/SettingsActivity.java @@ -2,6 +2,7 @@ package nodomain.freeyourgadget.gadgetbridge; import android.annotation.TargetApi; import android.content.Context; +import android.content.Intent; import android.content.res.Configuration; import android.os.Build; import android.os.Bundle; @@ -65,6 +66,14 @@ public class SettingsActivity extends PreferenceActivity { getPreferenceScreen().addPreference(fakeHeader); addPreferencesFromResource(R.xml.pref_notification); + Preference pref = (Preference) findPreference("notifications_generic"); + pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + public boolean onPreferenceClick(Preference preference) { + Intent enableIntent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"); + startActivity(enableIntent); + return true; + } + }); // Bind the summaries of EditText/List/Dialog/Ringtone preferences to // their values. When their values change, their summaries are updated @@ -135,7 +144,6 @@ public class SettingsActivity extends PreferenceActivity { ? listPreference.getEntries()[index] : null); - } else { // For all other preferences, set the summary to the value's // simple string representation. @@ -181,8 +189,8 @@ public class SettingsActivity extends PreferenceActivity { // to their values. When their values change, their summaries are // updated to reflect the new value, per the Android Design // guidelines. - bindPreferenceSummaryToValue(findPreference("example_text")); - bindPreferenceSummaryToValue(findPreference("example_list")); + //bindPreferenceSummaryToValue(findPreference("example_text")); + //bindPreferenceSummaryToValue(findPreference("example_list")); } } @@ -197,11 +205,20 @@ public class SettingsActivity extends PreferenceActivity { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.pref_notification); + Preference pref = (Preference) findPreference("notifications_generic"); + pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + public boolean onPreferenceClick(Preference preference) { + Intent enableIntent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"); + startActivity(enableIntent); + return true; + } + }); + // Bind the summaries of EditText/List/Dialog/Ringtone preferences // to their values. When their values change, their summaries are // updated to reflect the new value, per the Android Design // guidelines. - bindPreferenceSummaryToValue(findPreference("notifications_new_message_ringtone")); + //bindPreferenceSummaryToValue(findPreference("notifications_new_message_ringtone")); } } } diff --git a/app/src/main/res/xml/pref_notification.xml b/app/src/main/res/xml/pref_notification.xml index 7a6dd2ca..5bee5ea6 100644 --- a/app/src/main/res/xml/pref_notification.xml +++ b/app/src/main/res/xml/pref_notification.xml @@ -3,43 +3,41 @@ + android:title="@string/pref_title_notifications_sms" /> + android:title="@string/pref_title_whenscreenon" /> + android:title="@string/pref_title_notifications_k9mail" /> + android:title="@string/pref_title_whenscreenon" /> - + android:title="@string/pref_title_notifications_generic" /> + android:title="@string/pref_title_whenscreenon" />