NotificationLightSettings: reposition + button
Follow other similar pages that have an app selection.
Change-Id: Ifd9f79776192964cd507ec8fd2f645d994636452
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 7d489dd..9d88587 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -112,7 +112,7 @@
<!-- Lights settings, LED notification -->
<string name="led_notification_title">Light settings</string>
<string name="led_notification_text">LED light enabled by settings</string>
- <string name="notification_light_no_apps_summary">To add per app control, activate \'%1$s\' and press \'\u002b\' on the menu bar</string>
+ <string name="notification_light_add_apps_empty_summary">To add per app control, activate \'%1$s\' and press \'Add\'</string>
<!-- LiveDisplay -->
<string name="live_display_summary">Optimize your screen based on time of day and ambient conditions to improve readability and reduce eyestrain</string>
diff --git a/res/xml/notification_light_settings.xml b/res/xml/notification_light_settings.xml
index 59af8e0..ba9cf86 100644
--- a/res/xml/notification_light_settings.xml
+++ b/res/xml/notification_light_settings.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016 The CyanogenMod Project
- 2017-2018,2021 The LineageOS Project
+ 2017-2018,2021-2022 The LineageOS Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -97,6 +97,12 @@
android:key="applications_list"
android:title="@string/notification_light_applist_title"
android:dependency="notification_light_pulse_custom_enable" >
+
+ <Preference
+ android:key="custom_apps_add"
+ android:title="@string/add"
+ android:icon="@drawable/ic_add_24dp" />
+
</PreferenceCategory>
</PreferenceScreen>
diff --git a/src/org/lineageos/lineageparts/notificationlight/NotificationLightSettings.java b/src/org/lineageos/lineageparts/notificationlight/NotificationLightSettings.java
index eff0e76..f0af664 100644
--- a/src/org/lineageos/lineageparts/notificationlight/NotificationLightSettings.java
+++ b/src/org/lineageos/lineageparts/notificationlight/NotificationLightSettings.java
@@ -31,9 +31,6 @@
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
@@ -73,6 +70,7 @@
private static final String DEFAULT_PREF = "default";
private static final String MISSED_CALL_PREF = "missed_call";
private static final String VOICEMAIL_PREF = "voicemail";
+ private static final String ADD_APPS = "custom_apps_add";
public static final int ACTION_TEST = 0;
public static final int ACTION_DELETE = 1;
@@ -91,8 +89,6 @@
private ApplicationLightPreference mDefaultPref;
private ApplicationLightPreference mCallPref;
private ApplicationLightPreference mVoicemailPref;
- private Menu mMenu;
- private MenuItem mAddItem;
private PackageListAdapter mPackageAdapter;
private String mPackageList;
private Map<String, Package> mPackages;
@@ -188,7 +184,6 @@
mPackageAdapter = new PackageListAdapter(getActivity());
mPackages = new HashMap<String, Package>();
- setHasOptionsMenu(true);
if (!mMultiColorLed) {
resetColors();
@@ -199,6 +194,12 @@
}
watch(Settings.System.getUriFor(Settings.System.NOTIFICATION_LIGHT_PULSE));
+
+ Preference addPreference = prefSet.findPreference(ADD_APPS);
+ addPreference.setOnPreferenceClickListener(preference -> {
+ showDialog(DIALOG_APPS);
+ return true;
+ });
}
@Override
@@ -288,7 +289,15 @@
// Add the Application Preferences
if (mApplicationPrefList != null) {
- mApplicationPrefList.removeAll();
+ for (int i = 0; i < mApplicationPrefList.getPreferenceCount();) {
+ Preference pref = mApplicationPrefList.getPreference(i);
+ if (ADD_APPS.equals(pref.getKey())) {
+ i++;
+ continue;
+ }
+
+ mApplicationPrefList.removePreference(pref);
+ }
for (Package pkg : mPackages.values()) {
try {
@@ -317,9 +326,9 @@
private void maybeDisplayApplicationHint(Context context)
{
/* Display a pref explaining how to add apps */
- if (mApplicationPrefList != null && mApplicationPrefList.getPreferenceCount() == 0) {
+ if (mApplicationPrefList != null && mApplicationPrefList.getPreferenceCount() == 1) {
String summary = getResources().getString(
- R.string.notification_light_no_apps_summary);
+ R.string.notification_light_add_apps_empty_summary);
String useCustom = getResources().getString(
R.string.notification_light_use_custom);
Preference pref = new Preference(context);
@@ -489,29 +498,6 @@
return true;
}
- @Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
- mMenu = menu;
- mAddItem = mMenu.add(R.string.add)
- .setIcon(R.drawable.ic_menu_add)
- .setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
- }
-
- @Override
- public void onPrepareOptionsMenu(Menu menu) {
- boolean enableAddButton = mEnabledPref.isChecked() && mCustomEnabledPref.isChecked();
- mAddItem.setVisible(enableAddButton);
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if (item == mAddItem) {
- showDialog(DIALOG_APPS);
- return true;
- }
- return false;
- }
-
/**
* Utility classes and supporting methods
*/