Merge "Move "scanning" from location setting actionbar to pref xml"

This commit is contained in:
TreeHugger Robot
2017-03-23 16:02:01 +00:00
committed by Android (Google) Code Review
5 changed files with 17 additions and 43 deletions

View File

@@ -3101,9 +3101,6 @@
<string name="location_mode_battery_saving_description">Use Wi\u2011Fi, Bluetooth, or mobile networks to determine location</string> <string name="location_mode_battery_saving_description">Use Wi\u2011Fi, Bluetooth, or mobile networks to determine location</string>
<!-- [CHAR LIMIT=130] Location mode screen, description for sensors only mode --> <!-- [CHAR LIMIT=130] Location mode screen, description for sensors only mode -->
<string name="location_mode_sensors_only_description">Use GPS to determine location</string> <string name="location_mode_sensors_only_description">Use GPS to determine location</string>
<!-- Help menu label [CHAR LIMIT=20] Location settings screen, overflow menu that takes the user
to scanning settings activity -->
<string name="location_menu_scanning">Scanning</string>
<!-- [CHAR LIMIT=30] Wireless background scanning settings screen, screen title --> <!-- [CHAR LIMIT=30] Wireless background scanning settings screen, screen title -->
<string name="location_scanning_screen_title">Scanning</string> <string name="location_scanning_screen_title">Scanning</string>
<!-- [CHAR LIMIT=130] Preference title for Wi-Fi always scanning --> <!-- [CHAR LIMIT=130] Preference title for Wi-Fi always scanning -->

View File

@@ -44,6 +44,11 @@
</intent> </intent>
</Preference> </Preference>
<Preference
android:key="location_scanning"
android:title="@string/location_scanning_screen_title"
android:fragment="com.android.settings.location.ScanningSettings"/>
<PreferenceCategory <PreferenceCategory
android:key="recent_location_requests" android:key="recent_location_requests"
android:title="@string/location_category_recent_location_requests" /> android:title="@string/location_category_recent_location_requests" />

View File

@@ -22,8 +22,8 @@
<Preference <Preference
android:key="location" android:key="location"
android:title="@string/location_settings_title"> android:title="@string/location_settings_title"
<intent android:action="android.settings.LOCATION_SOURCE_SETTINGS"/> android:fragment="com.android.settings.location.LocationSettings">
</Preference> </Preference>
<SwitchPreference <SwitchPreference

View File

@@ -17,9 +17,7 @@
package com.android.settings.location; package com.android.settings.location;
import android.app.Activity; import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
@@ -27,16 +25,13 @@ import android.location.SettingInjectorService;
import android.os.Bundle; import android.os.Bundle;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
import android.provider.Settings;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceCategory; import android.support.v7.preference.PreferenceCategory;
import android.support.v7.preference.PreferenceGroup; import android.support.v7.preference.PreferenceGroup;
import android.support.v7.preference.PreferenceScreen; import android.support.v7.preference.PreferenceScreen;
import android.util.Log; import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Switch; import android.widget.Switch;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.DimmableIconPreference; import com.android.settings.DimmableIconPreference;
import com.android.settings.R; import com.android.settings.R;
@@ -98,8 +93,6 @@ public class LocationSettings extends LocationSettingsBase
/** Key for preference category "Location services" */ /** Key for preference category "Location services" */
private static final String KEY_LOCATION_SERVICES = "location_services"; private static final String KEY_LOCATION_SERVICES = "location_services";
private static final int MENU_SCANNING = Menu.FIRST;
private SwitchBar mSwitchBar; private SwitchBar mSwitchBar;
private Switch mSwitch; private Switch mSwitch;
private boolean mValidListener = false; private boolean mValidListener = false;
@@ -311,8 +304,9 @@ public class LocationSettings extends LocationSettingsBase
injector = new SettingsInjector(context); injector = new SettingsInjector(context);
// If location access is locked down by device policy then we only show injected settings // If location access is locked down by device policy then we only show injected settings
// for the primary profile. // for the primary profile.
List<Preference> locationServices = injector.getInjectedSettings(lockdownOnLocationAccess ? final Context prefContext = categoryLocationServices.getContext();
UserHandle.myUserId() : UserHandle.USER_CURRENT); final List<Preference> locationServices = injector.getInjectedSettings(prefContext,
lockdownOnLocationAccess ? UserHandle.myUserId() : UserHandle.USER_CURRENT);
mReceiver = new BroadcastReceiver() { mReceiver = new BroadcastReceiver() {
@Override @Override
@@ -336,29 +330,6 @@ public class LocationSettings extends LocationSettingsBase
} }
} }
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.add(0, MENU_SCANNING, 0, R.string.location_menu_scanning);
// The super class adds "Help & Feedback" menu item.
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
final SettingsActivity activity = (SettingsActivity) getActivity();
switch (item.getItemId()) {
case MENU_SCANNING:
activity.startPreferencePanel(
this,
ScanningSettings.class.getName(), null,
R.string.location_scanning_screen_title, null, LocationSettings.this,
0);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override @Override
public int getHelpResource() { public int getHelpResource() {
return R.string.help_url_location_access; return R.string.help_url_location_access;

View File

@@ -231,17 +231,17 @@ class SettingsInjector {
* @param profileId Identifier of the user/profile to obtain the injected settings for or * @param profileId Identifier of the user/profile to obtain the injected settings for or
* UserHandle.USER_CURRENT for all profiles associated with current user. * UserHandle.USER_CURRENT for all profiles associated with current user.
*/ */
public List<Preference> getInjectedSettings(final int profileId) { public List<Preference> getInjectedSettings(Context prefContext, final int profileId) {
final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE); final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
final List<UserHandle> profiles = um.getUserProfiles(); final List<UserHandle> profiles = um.getUserProfiles();
ArrayList<Preference> prefs = new ArrayList<Preference>(); ArrayList<Preference> prefs = new ArrayList<>();
final int profileCount = profiles.size(); final int profileCount = profiles.size();
for (int i = 0; i < profileCount; ++i) { for (int i = 0; i < profileCount; ++i) {
final UserHandle userHandle = profiles.get(i); final UserHandle userHandle = profiles.get(i);
if (profileId == UserHandle.USER_CURRENT || profileId == userHandle.getIdentifier()) { if (profileId == UserHandle.USER_CURRENT || profileId == userHandle.getIdentifier()) {
Iterable<InjectedSetting> settings = getSettings(userHandle); Iterable<InjectedSetting> settings = getSettings(userHandle);
for (InjectedSetting setting : settings) { for (InjectedSetting setting : settings) {
Preference pref = addServiceSetting(prefs, setting); Preference pref = addServiceSetting(prefContext, prefs, setting);
mSettings.add(new Setting(setting, pref)); mSettings.add(new Setting(setting, pref));
} }
} }
@@ -265,7 +265,8 @@ class SettingsInjector {
/** /**
* Adds an injected setting to the root. * Adds an injected setting to the root.
*/ */
private Preference addServiceSetting(List<Preference> prefs, InjectedSetting info) { private Preference addServiceSetting(Context prefContext, List<Preference> prefs,
InjectedSetting info) {
PackageManager pm = mContext.getPackageManager(); PackageManager pm = mContext.getPackageManager();
Drawable appIcon = pm.getDrawable(info.packageName, info.iconId, null); Drawable appIcon = pm.getDrawable(info.packageName, info.iconId, null);
Drawable icon = pm.getUserBadgedIcon(appIcon, info.mUserHandle); Drawable icon = pm.getUserBadgedIcon(appIcon, info.mUserHandle);
@@ -275,7 +276,7 @@ class SettingsInjector {
// a separate content description. // a separate content description.
badgedAppLabel = null; badgedAppLabel = null;
} }
Preference pref = new DimmableIconPreference(mContext, badgedAppLabel); Preference pref = new DimmableIconPreference(prefContext, badgedAppLabel);
pref.setTitle(info.title); pref.setTitle(info.title);
pref.setSummary(null); pref.setSummary(null);
pref.setIcon(icon); pref.setIcon(icon);