Under "recent location requests", add "See all"
Under Settings -> Security & Location -> Location, add "See all" button under recent location requests On location settings page, display at most 3 recent location requests. If there are more than 3, show a "see all" button. When user clicks "See all", take them to a new fragment with all recent location requests. Test: Robo Test: Manual Bug: 70350519 Change-Id: Id1f9a8da1593814a8f30f8e6ec8ac75fb10f6672
This commit is contained in:
@@ -70,8 +70,10 @@ public class LocationSettings extends DashboardFragment {
|
||||
public int getInitialExpandedChildCount() {
|
||||
final RecentLocationApps recentLocationApps = new RecentLocationApps(getActivity());
|
||||
final int locationRequestsApps = recentLocationApps.getAppList().size();
|
||||
final int locationRequestsPrefs = locationRequestsApps == 0 ? 1 : locationRequestsApps;
|
||||
return locationRequestsPrefs + 2;
|
||||
final int locationRequestsPrefs =
|
||||
locationRequestsApps == 0
|
||||
? 1 : (locationRequestsApps > 3 ? 4 : locationRequestsApps);
|
||||
return locationRequestsPrefs + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -20,32 +20,33 @@ import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceCategory;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.applications.appinfo.AppInfoDashboardFragment;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.widget.AppPreference;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.location.RecentLocationApps;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RecentLocationRequestPreferenceController extends LocationBasePreferenceController {
|
||||
|
||||
/** Key for preference category "Recent location requests" */
|
||||
private static final String KEY_RECENT_LOCATION_REQUESTS = "recent_location_requests";
|
||||
@VisibleForTesting
|
||||
static final String KEY_SEE_ALL = "recent_location_requests_see_all";
|
||||
private final LocationSettings mFragment;
|
||||
private final RecentLocationApps mRecentLocationApps;
|
||||
private PreferenceCategory mCategoryRecentLocationRequests;
|
||||
private Preference mSeeAllButton;
|
||||
|
||||
@VisibleForTesting
|
||||
/** Used in this class and {@link RecentLocationRequestSeeAllPreferenceController}*/
|
||||
static class PackageEntryClickedListener implements Preference.OnPreferenceClickListener {
|
||||
private final LocationSettings mFragment;
|
||||
private final DashboardFragment mFragment;
|
||||
private final String mPackage;
|
||||
private final UserHandle mUserHandle;
|
||||
|
||||
public PackageEntryClickedListener(LocationSettings fragment, String packageName,
|
||||
public PackageEntryClickedListener(DashboardFragment fragment, String packageName,
|
||||
UserHandle userHandle) {
|
||||
mFragment = fragment;
|
||||
mPackage = packageName;
|
||||
@@ -92,24 +93,32 @@ public class RecentLocationRequestPreferenceController extends LocationBasePrefe
|
||||
super.displayPreference(screen);
|
||||
mCategoryRecentLocationRequests =
|
||||
(PreferenceCategory) screen.findPreference(KEY_RECENT_LOCATION_REQUESTS);
|
||||
mSeeAllButton = screen.findPreference(KEY_SEE_ALL);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
mCategoryRecentLocationRequests.removeAll();
|
||||
mSeeAllButton.setVisible(false);
|
||||
|
||||
final Context prefContext = preference.getContext();
|
||||
final List<RecentLocationApps.Request> recentLocationRequests =
|
||||
mRecentLocationApps.getAppListSorted();
|
||||
|
||||
final List<Preference> recentLocationPrefs = new ArrayList<>(recentLocationRequests.size());
|
||||
for (final RecentLocationApps.Request request : recentLocationRequests) {
|
||||
recentLocationPrefs.add(createAppPreference(prefContext, request));
|
||||
}
|
||||
if (recentLocationRequests.size() > 0) {
|
||||
if (recentLocationRequests.size() > 3) {
|
||||
// Display the top 3 preferences to container in original order.
|
||||
for (int i = 0; i < 3; i ++) {
|
||||
mCategoryRecentLocationRequests.addPreference(
|
||||
createAppPreference(prefContext, recentLocationRequests.get(i)));
|
||||
}
|
||||
// Display a button to list all requests
|
||||
mSeeAllButton.setVisible(true);
|
||||
} else if (recentLocationRequests.size() > 0) {
|
||||
// Add preferences to container in original order (already sorted by recency).
|
||||
for (Preference entry : recentLocationPrefs) {
|
||||
mCategoryRecentLocationRequests.addPreference(entry);
|
||||
for (RecentLocationApps.Request request : recentLocationRequests) {
|
||||
mCategoryRecentLocationRequests.addPreference(
|
||||
createAppPreference(prefContext, request));
|
||||
}
|
||||
} else {
|
||||
// If there's no item to display, add a "No recent apps" item.
|
||||
@@ -132,7 +141,7 @@ public class RecentLocationRequestPreferenceController extends LocationBasePrefe
|
||||
|
||||
@VisibleForTesting
|
||||
AppPreference createAppPreference(Context prefContext, RecentLocationApps.Request request) {
|
||||
final AppPreference pref = createAppPreference(prefContext);
|
||||
final AppPreference pref = createAppPreference(prefContext);
|
||||
pref.setSummary(request.contentDescription);
|
||||
pref.setIcon(request.icon);
|
||||
pref.setTitle(request.label);
|
||||
|
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.location;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/** Dashboard Fragment to display all recent location requests, sorted by recency. */
|
||||
public class RecentLocationRequestSeeAllFragment extends DashboardFragment {
|
||||
|
||||
private static final String TAG = "RecentLocationReqAll";
|
||||
|
||||
public static final String PATH =
|
||||
"com.android.settings.location.RecentLocationRequestSeeAllFragment";
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.RECENT_LOCATION_REQUESTS_ALL;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.location_recent_requests_see_all;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||
return buildPreferenceControllers(context, getLifecycle(), this);
|
||||
}
|
||||
|
||||
private static List<AbstractPreferenceController> buildPreferenceControllers(
|
||||
Context context, Lifecycle lifecycle, RecentLocationRequestSeeAllFragment fragment) {
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(
|
||||
new RecentLocationRequestSeeAllPreferenceController(context, lifecycle, fragment));
|
||||
return controllers;
|
||||
}
|
||||
|
||||
/**
|
||||
* For Search.
|
||||
*/
|
||||
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(
|
||||
Context context, boolean enabled) {
|
||||
final SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.location_recent_requests_see_all;
|
||||
return Arrays.asList(sir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AbstractPreferenceController> getPreferenceControllers(Context
|
||||
context) {
|
||||
return buildPreferenceControllers(
|
||||
context, /* lifecycle = */ null, /* fragment = */ null);
|
||||
}
|
||||
};
|
||||
}
|
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.location;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceCategory;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import com.android.settings.widget.AppPreference;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.location.RecentLocationApps;
|
||||
import java.util.List;
|
||||
|
||||
/** Preference controller for preference category displaying all recent location requests. */
|
||||
public class RecentLocationRequestSeeAllPreferenceController
|
||||
extends LocationBasePreferenceController {
|
||||
|
||||
/** Key for preference category "All recent location requests" */
|
||||
private static final String KEY_ALL_RECENT_LOCATION_REQUESTS = "all_recent_location_requests";
|
||||
private final RecentLocationRequestSeeAllFragment mFragment;
|
||||
private PreferenceCategory mCategoryAllRecentLocationRequests;
|
||||
private RecentLocationApps mRecentLocationApps;
|
||||
|
||||
public RecentLocationRequestSeeAllPreferenceController(
|
||||
Context context, Lifecycle lifecycle, RecentLocationRequestSeeAllFragment fragment) {
|
||||
this(context, lifecycle, fragment, new RecentLocationApps(context));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
RecentLocationRequestSeeAllPreferenceController(
|
||||
Context context,
|
||||
Lifecycle lifecycle,
|
||||
RecentLocationRequestSeeAllFragment fragment,
|
||||
RecentLocationApps recentLocationApps) {
|
||||
super(context, lifecycle);
|
||||
mFragment = fragment;
|
||||
mRecentLocationApps = recentLocationApps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_ALL_RECENT_LOCATION_REQUESTS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationModeChanged(int mode, boolean restricted) {
|
||||
mCategoryAllRecentLocationRequests.setEnabled(mLocationEnabler.isEnabled(mode));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mCategoryAllRecentLocationRequests =
|
||||
(PreferenceCategory) screen.findPreference(KEY_ALL_RECENT_LOCATION_REQUESTS);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
mCategoryAllRecentLocationRequests.removeAll();
|
||||
List<RecentLocationApps.Request> requests = mRecentLocationApps.getAppListSorted();
|
||||
for (RecentLocationApps.Request request : requests) {
|
||||
Preference appPreference = createAppPreference(preference.getContext(), request);
|
||||
mCategoryAllRecentLocationRequests.addPreference(appPreference);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
AppPreference createAppPreference(
|
||||
Context prefContext, RecentLocationApps.Request request) {
|
||||
final AppPreference pref = new AppPreference(prefContext);
|
||||
pref.setSummary(request.contentDescription);
|
||||
pref.setIcon(request.icon);
|
||||
pref.setTitle(request.label);
|
||||
pref.setOnPreferenceClickListener(
|
||||
new RecentLocationRequestPreferenceController.PackageEntryClickedListener(
|
||||
mFragment, request.packageName, request.userHandle));
|
||||
return pref;
|
||||
}
|
||||
}
|
@@ -65,6 +65,7 @@ import com.android.settings.inputmethod.PhysicalKeyboardFragment;
|
||||
import com.android.settings.inputmethod.VirtualKeyboardFragment;
|
||||
import com.android.settings.language.LanguageAndInputSettings;
|
||||
import com.android.settings.location.LocationSettings;
|
||||
import com.android.settings.location.RecentLocationRequestSeeAllFragment;
|
||||
import com.android.settings.location.ScanningSettings;
|
||||
import com.android.settings.network.NetworkDashboardFragment;
|
||||
import com.android.settings.nfc.PaymentSettings;
|
||||
@@ -177,6 +178,7 @@ public class SearchIndexableResourcesImpl implements SearchIndexableResources {
|
||||
addIndex(SmartBatterySettings.class);
|
||||
addIndex(MyDeviceInfoFragment.class);
|
||||
addIndex(VibrationSettings.class);
|
||||
addIndex(RecentLocationRequestSeeAllFragment.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user