Settings: Add config to display Now Playing

* Disabled by default as most devices dont support it.

Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
This commit is contained in:
Pranav Vashi
2024-11-21 06:31:15 +05:30
committed by Joey
parent b45269eb32
commit 184131faec
3 changed files with 47 additions and 1 deletions

View File

@@ -37,4 +37,7 @@
<!-- Whether to show min refresh rate in display settings -->
<bool name="config_show_min_refresh_rate_switch">false</bool>
<!-- Show Now Playing -->
<bool name="config_show_now_playing">false</bool>
</resources>

View File

@@ -34,6 +34,7 @@ import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.RingtonePreference;
@@ -63,6 +64,7 @@ public class SoundSettings extends DashboardFragment implements OnActivityResult
private static final String EXTRA_OPEN_PHONE_RINGTONE_PICKER =
"EXTRA_OPEN_PHONE_RINGTONE_PICKER";
private static final String KEY_NOW_PLAYING = "dashboard_tile_pref_com.google.intelligence.sense.ambientmusic.AmbientMusicSettingsActivity";
@VisibleForTesting
static final int STOP_SAMPLE = 1;
@@ -120,6 +122,19 @@ public class SoundSettings extends DashboardFragment implements OnActivityResult
}
return null;
});
updateAmbientMusicPref();
}
private void updateAmbientMusicPref() {
final PreferenceScreen screen = getPreferenceScreen();
if (getContext().getResources().getBoolean(R.bool.config_show_now_playing) || screen == null) {
return;
}
final Preference preference = screen.findPreference(KEY_NOW_PLAYING);
if (preference != null) {
screen.removePreference(preference);
}
}
@Override
@@ -306,6 +321,17 @@ public class SoundSettings extends DashboardFragment implements OnActivityResult
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.sound_settings) {
@Override
public List<String> getNonIndexableKeys(Context context) {
List<String> keys = super.getNonIndexableKeys(context);
if (!context.getResources().getBoolean(R.bool.config_show_now_playing)) {
keys.add(KEY_NOW_PLAYING);
}
return keys;
}
@Override
public List<AbstractPreferenceController> createPreferenceControllers(
Context context) {

View File

@@ -32,6 +32,8 @@ import android.provider.Settings;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
@@ -69,7 +71,7 @@ public class LockscreenDashboardFragment extends DashboardFragment
@VisibleForTesting
static final String KEY_ADD_USER_FROM_LOCK_SCREEN =
"security_lockscreen_add_users_when_locked";
private static final String KEY_NOW_PLAYING = "dashboard_tile_pref_com.google.intelligence.sense.ambientmusic.AmbientMusicNotificationsSettingsActivity";
private AmbientDisplayConfiguration mConfig;
private OwnerInfoPreferenceController mOwnerInfoPreferenceController;
@@ -94,6 +96,18 @@ public class LockscreenDashboardFragment extends DashboardFragment
R.string.locked_work_profile_notification_title);
replaceEnterpriseStringTitle("security_setting_lock_screen_notif_work_header",
WORK_PROFILE_NOTIFICATIONS_SECTION_HEADER, R.string.profile_section_header);
updateAmbientMusicPref();
}
private void updateAmbientMusicPref() {
final PreferenceScreen screen = getPreferenceScreen();
if (getContext().getResources().getBoolean(R.bool.config_show_now_playing) || screen == null) {
return;
}
final Preference preference = screen.findPreference(KEY_NOW_PLAYING);
if (preference != null) {
screen.removePreference(preference);
}
}
@Override
@@ -191,6 +205,9 @@ public class LockscreenDashboardFragment extends DashboardFragment
public List<String> getNonIndexableKeys(Context context) {
final List<String> niks = super.getNonIndexableKeys(context);
niks.add(KEY_ADD_USER_FROM_LOCK_SCREEN);
if (!context.getResources().getBoolean(R.bool.config_show_now_playing)) {
niks.add(KEY_NOW_PLAYING);
}
return niks;
}