Merge "Remove location mode menu from location settings"
This commit is contained in:
committed by
Android (Google) Code Review
commit
7ccd083f7b
@@ -1,108 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 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;
|
||||
|
||||
/**
|
||||
* A page with 3 radio buttons to choose the location mode.
|
||||
*
|
||||
* There are 3 location modes when location access is enabled:
|
||||
*
|
||||
* High accuracy: use both GPS and network location.
|
||||
*
|
||||
* Battery saving: use network location only to reduce the power consumption.
|
||||
*
|
||||
* Sensors only: use GPS location only.
|
||||
*/
|
||||
public class LocationMode extends DashboardFragment {
|
||||
|
||||
private static final String TAG = "LocationMode";
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.LOCATION_MODE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.location_mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
|
||||
return buildPreferenceControllers(context, getLifecycle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHelpResource() {
|
||||
return R.string.help_url_location_access;
|
||||
}
|
||||
|
||||
private static List<AbstractPreferenceController> buildPreferenceControllers(
|
||||
Context context, Lifecycle lifecycle) {
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new LocationModeHighAccuracyPreferenceController(context, lifecycle));
|
||||
controllers.add(
|
||||
new LocationModeBatterySavingPreferenceController(context, lifecycle));
|
||||
controllers.add(new LocationModeSensorsOnlyPreferenceController(context, lifecycle));
|
||||
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_mode;
|
||||
return Arrays.asList(sir);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isPageSearchEnabled(Context context) {
|
||||
return context.getResources().getBoolean(R.bool.config_location_mode_available);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AbstractPreferenceController> getPreferenceControllers(Context
|
||||
context) {
|
||||
return buildPreferenceControllers(context, null /* lifecycle */);
|
||||
}
|
||||
};
|
||||
}
|
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.Settings;
|
||||
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
public class LocationModeBatterySavingPreferenceController
|
||||
extends LocationModeRadioButtonPreferenceController {
|
||||
|
||||
private static final String KEY_BATTERY_SAVING = "battery_saving";
|
||||
|
||||
public LocationModeBatterySavingPreferenceController(Context context,
|
||||
Lifecycle lifecycle) {
|
||||
super(context, lifecycle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_BATTERY_SAVING;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLocationMode() {
|
||||
return Settings.Secure.LOCATION_MODE_BATTERY_SAVING;
|
||||
}
|
||||
}
|
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.Settings;
|
||||
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
public class LocationModeHighAccuracyPreferenceController
|
||||
extends LocationModeRadioButtonPreferenceController {
|
||||
|
||||
private static final String KEY_HIGH_ACCURACY = "high_accuracy";
|
||||
|
||||
public LocationModeHighAccuracyPreferenceController(Context context,
|
||||
Lifecycle lifecycle) {
|
||||
super(context, lifecycle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_HIGH_ACCURACY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLocationMode() {
|
||||
return Settings.Secure.LOCATION_MODE_HIGH_ACCURACY;
|
||||
}
|
||||
}
|
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
public class LocationModePreferenceController extends LocationBasePreferenceController {
|
||||
|
||||
/** Key for preference screen "Mode" */
|
||||
private static final String KEY_LOCATION_MODE = "location_mode";
|
||||
|
||||
private final LocationSettings mParentFragment;
|
||||
private Preference mPreference;
|
||||
|
||||
public LocationModePreferenceController(Context context, LocationSettings parent,
|
||||
Lifecycle lifecycle) {
|
||||
super(context, lifecycle);
|
||||
mParentFragment = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_LOCATION_MODE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return mContext.getResources().getBoolean(R.bool.config_location_mode_available);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(KEY_LOCATION_MODE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (KEY_LOCATION_MODE.equals(preference.getKey())) {
|
||||
final SettingsActivity activity = (SettingsActivity) mParentFragment.getActivity();
|
||||
activity.startPreferencePanel(mParentFragment, LocationMode.class.getName(), null,
|
||||
R.string.location_mode_screen_title, null, mParentFragment, 0);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationModeChanged(int mode, boolean restricted) {
|
||||
final int modeDescription = LocationPreferenceController.getLocationString(mode);
|
||||
if (modeDescription != 0) {
|
||||
mPreference.setSummary(modeDescription);
|
||||
}
|
||||
// Restricted user can't change the location mode, so disable the master switch. But in some
|
||||
// corner cases, the location might still be enabled. In such case the master switch should
|
||||
// be disabled but checked.
|
||||
mPreference.setEnabled(mLocationEnabler.isEnabled(mode));
|
||||
}
|
||||
}
|
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.widget.RadioButtonPreference;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
public abstract class LocationModeRadioButtonPreferenceController
|
||||
extends LocationBasePreferenceController
|
||||
implements RadioButtonPreference.OnClickListener {
|
||||
|
||||
protected RadioButtonPreference mPreference;
|
||||
|
||||
public LocationModeRadioButtonPreferenceController(Context context, Lifecycle lifecycle) {
|
||||
super(context, lifecycle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = (RadioButtonPreference) screen.findPreference(getPreferenceKey());
|
||||
mPreference.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRadioButtonClicked(RadioButtonPreference emiter) {
|
||||
mLocationEnabler.setLocationMode(getLocationMode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationModeChanged(int mode, boolean restricted) {
|
||||
mPreference.setChecked(mode == getLocationMode());
|
||||
mPreference.setEnabled(mLocationEnabler.isEnabled(mode));
|
||||
}
|
||||
|
||||
/** Gets the location mode that this controller monitors. */
|
||||
protected abstract int getLocationMode();
|
||||
|
||||
}
|
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.Settings;
|
||||
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
public class LocationModeSensorsOnlyPreferenceController
|
||||
extends LocationModeRadioButtonPreferenceController {
|
||||
|
||||
private static final String KEY_SENSORS_ONLY = "sensors_only";
|
||||
|
||||
public LocationModeSensorsOnlyPreferenceController(Context context,
|
||||
Lifecycle lifecycle) {
|
||||
super(context, lifecycle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_SENSORS_ONLY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLocationMode() {
|
||||
return Settings.Secure.LOCATION_MODE_SENSORS_ONLY;
|
||||
}
|
||||
}
|
@@ -105,26 +105,11 @@ public class LocationPreferenceController extends AbstractPreferenceController
|
||||
int mode = Secure.getInt(context.getContentResolver(),
|
||||
Secure.LOCATION_MODE, Secure.LOCATION_MODE_OFF);
|
||||
if (mode != Secure.LOCATION_MODE_OFF) {
|
||||
return context.getString(R.string.location_on_summary,
|
||||
context.getString(getLocationString(mode)));
|
||||
return context.getString(R.string.location_on_summary);
|
||||
}
|
||||
return context.getString(R.string.location_off_summary);
|
||||
}
|
||||
|
||||
public static int getLocationString(int mode) {
|
||||
switch (mode) {
|
||||
case Secure.LOCATION_MODE_OFF:
|
||||
return R.string.location_mode_location_off_title;
|
||||
case Secure.LOCATION_MODE_SENSORS_ONLY:
|
||||
return R.string.location_mode_sensors_only_title;
|
||||
case Secure.LOCATION_MODE_BATTERY_SAVING:
|
||||
return R.string.location_mode_battery_saving_title;
|
||||
case Secure.LOCATION_MODE_HIGH_ACCURACY:
|
||||
return R.string.location_mode_high_accuracy_title;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultPayload getResultPayload() {
|
||||
final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(mContext,
|
||||
|
@@ -127,7 +127,6 @@ public class LocationSettings extends DashboardFragment {
|
||||
private static List<AbstractPreferenceController> buildPreferenceControllers(
|
||||
Context context, LocationSettings fragment, Lifecycle lifecycle) {
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new LocationModePreferenceController(context, fragment, lifecycle));
|
||||
controllers.add(new AppLocationPermissionPreferenceController(context));
|
||||
controllers.add(new LocationForWorkPreferenceController(context, lifecycle));
|
||||
controllers.add(
|
||||
|
@@ -62,7 +62,6 @@ import com.android.settings.inputmethod.AvailableVirtualKeyboardFragment;
|
||||
import com.android.settings.inputmethod.PhysicalKeyboardFragment;
|
||||
import com.android.settings.inputmethod.VirtualKeyboardFragment;
|
||||
import com.android.settings.language.LanguageAndInputSettings;
|
||||
import com.android.settings.location.LocationMode;
|
||||
import com.android.settings.location.LocationSettings;
|
||||
import com.android.settings.location.ScanningSettings;
|
||||
import com.android.settings.network.NetworkDashboardFragment;
|
||||
@@ -132,7 +131,6 @@ public class SearchIndexableResourcesImpl implements SearchIndexableResources {
|
||||
addIndex(GestureSettings.class);
|
||||
addIndex(LanguageAndInputSettings.class);
|
||||
addIndex(LocationSettings.class);
|
||||
addIndex(LocationMode.class);
|
||||
addIndex(ScanningSettings.class);
|
||||
addIndex(SecuritySettingsV2.class);
|
||||
addIndex(ScreenLockSettings.class);
|
||||
|
Reference in New Issue
Block a user