Set initialExpandedChildrenCount dynamically in location settings

In location settings, we want "Advanced" button show up right after "App
level permissions". But with different numbers of "recent location requests" apps,
the Preferences hidden under Advanced could change.

To fix this issue, we fetch the list of apps with "recent location
requests" in LocationSettings.onCreate(), and set
initialExpandedChildrenCount for location PreferenceScreen to the apps
count.

Bug: 70350519
Test: Manual
Change-Id: I4c4b6bdfa916213494a29e8ae8b5f33476411c88
This commit is contained in:
Maggie
2017-12-19 17:02:20 -08:00
parent 8a05bef170
commit 3220c46bcc
2 changed files with 25 additions and 16 deletions

View File

@@ -20,19 +20,9 @@
android:title="@string/location_settings_title"
settings:keywords="@string/keywords_location">
<Preference
android:key="location_mode"
android:title="@string/location_mode_title"
settings:keywords="@string/keywords_location_mode"
android:summary="@string/summary_placeholder" />
<!-- This preference category gets removed if there is no managed profile -->
<com.android.settingslib.RestrictedSwitchPreference
android:key="managed_profile_location_switch"
android:title="@string/managed_profile_location_switch_title"
settings:useAdminDisabledSummary="true"
android:enabled="false"
android:selectable="true" />
<PreferenceCategory
android:key="recent_location_requests"
android:title="@string/location_category_recent_location_requests"/>
<!-- This preference category gets removed if new_recent_location_ui is disabled -->
<Preference
@@ -49,12 +39,21 @@
android:title="@string/location_scanning_screen_title"
android:fragment="com.android.settings.location.ScanningSettings"/>
<PreferenceCategory
android:key="recent_location_requests"
android:title="@string/location_category_recent_location_requests" />
<!-- This preference category gets removed if there is no managed profile -->
<com.android.settingslib.RestrictedSwitchPreference
android:key="managed_profile_location_switch"
android:title="@string/managed_profile_location_switch_title"
settings:useAdminDisabledSummary="true"
android:enabled="false"
android:selectable="true" />
<PreferenceCategory
android:key="location_services"
android:title="@string/location_category_location_services" />
<Preference
android:key="location_mode"
android:title="@string/location_mode_title"
settings:keywords="@string/keywords_location_mode"
android:summary="@string/summary_placeholder" />
</PreferenceScreen>

View File

@@ -72,6 +72,16 @@ public class LocationSettings extends DashboardFragment {
private LocationSwitchBarController mSwitchBarController;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
final RecentLocationApps recentLocationApps = new RecentLocationApps(getActivity());
int locationRequestsApps = recentLocationApps.getAppList().size();
int locationRequestsPrefs = locationRequestsApps == 0 ? 1 : locationRequestsApps;
getPreferenceScreen().setInitialExpandedChildrenCount(locationRequestsPrefs + 2);
}
@Override
public int getMetricsCategory() {
return MetricsEvent.LOCATION;