Added UI widgets for new location settings page
Change-Id: I87eee999a4dd0189609f58d6f3e4ffe517d63a0e
This commit is contained in:
@@ -684,7 +684,7 @@
|
|||||||
<!-- Text shown for title of profile info setting [CHAR LIMIT=20]-->
|
<!-- Text shown for title of profile info setting [CHAR LIMIT=20]-->
|
||||||
<string name="profile_info_settings_title">Profile info</string>
|
<string name="profile_info_settings_title">Profile info</string>
|
||||||
<!-- Main Settings screen setting option title for the item to take you to the location screen -->
|
<!-- Main Settings screen setting option title for the item to take you to the location screen -->
|
||||||
<string name="location_settings_title">Location access</string>
|
<string name="location_settings_title">Location</string>
|
||||||
<!-- Main Settings screen setting option title for the item to take you to the security screen -->
|
<!-- Main Settings screen setting option title for the item to take you to the security screen -->
|
||||||
<string name="security_settings_title">Security</string>
|
<string name="security_settings_title">Security</string>
|
||||||
<!-- Main Settings screen setting option summary text for the item tot ake you to the security and location screen -->
|
<!-- Main Settings screen setting option summary text for the item tot ake you to the security and location screen -->
|
||||||
@@ -2354,6 +2354,27 @@
|
|||||||
|
|
||||||
<!-- Security & location settings screen, section header for settings relating to location -->
|
<!-- Security & location settings screen, section header for settings relating to location -->
|
||||||
<string name="location_title">My Location</string>
|
<string name="location_title">My Location</string>
|
||||||
|
<!-- [CHAR LIMIT=30] Location settings screen, setting preference screen box label for location mode -->
|
||||||
|
<string name="location_mode_title">Mode</string>
|
||||||
|
<!-- [CHAR LIMIT=30] Location settings screen, high accuracy location mode -->
|
||||||
|
<string name="location_mode_high_accuracy_title">High accuracy</string>
|
||||||
|
<!-- [CHAR LIMIT=30] Location settings screen, battery saving location mode -->
|
||||||
|
<string name="location_mode_battery_saving_title">Battery saving</string>
|
||||||
|
<!-- [CHAR LIMIT=30] Location settings screen, device sensors only location mode -->
|
||||||
|
<string name="location_mode_sensors_only_title">Device sensors only</string>
|
||||||
|
<!-- [CHAR LIMIT=30] Location settings screen, sub category for recent location requests -->
|
||||||
|
<string name="location_category_recent_location_requests">Recent location requests</string>
|
||||||
|
<!-- [CHAR LIMIT=30] Location settings screen, sub category for location services -->
|
||||||
|
<string name="location_category_location_services">Location services</string>
|
||||||
|
<!-- [CHAR LIMIT=30] Location mode screen, screen title -->
|
||||||
|
<string name="location_mode_screen_title">Location mode</string>
|
||||||
|
<!-- [CHAR LIMIT=30] Location mode screen, description for high accuracy mode -->
|
||||||
|
<string name="location_mode_high_accuracy_description">Use GPS, Wi\u2011Fi and mobile networks to estimate location </string>
|
||||||
|
<!-- [CHAR LIMIT=30] Location mode screen, description for battery saving mode -->
|
||||||
|
<string name="location_mode_battery_saving_description">Use Wi\u2011Fi and mobile networks to estimate location</string>
|
||||||
|
<!-- [CHAR LIMIT=30] Location mode screen, description for sensors only mode -->
|
||||||
|
<string name="location_mode_sensors_only_description">Use GPS to pinpoint your location</string>
|
||||||
|
|
||||||
<!-- [CHAR LIMIT=30] Security & location settings screen, setting check box label for Google location service (cell ID, wifi, etc.) -->
|
<!-- [CHAR LIMIT=30] Security & location settings screen, setting check box label for Google location service (cell ID, wifi, etc.) -->
|
||||||
<string name="location_network_based">Wi\u2011Fi & mobile network location</string>
|
<string name="location_network_based">Wi\u2011Fi & mobile network location</string>
|
||||||
<!-- [CHAR LIMIT=130] Security & location settings screen, setting summary for Google location service check box-->
|
<!-- [CHAR LIMIT=130] Security & location settings screen, setting summary for Google location service check box-->
|
||||||
@@ -4579,7 +4600,7 @@
|
|||||||
<!-- Restrictions summary for allowing NFC transfers (phone) [CHAR LIMIT=100] -->
|
<!-- Restrictions summary for allowing NFC transfers (phone) [CHAR LIMIT=100] -->
|
||||||
<string name="restriction_nfc_enable_summary" product="default">Allow data exchange when the phone touches another device</string>
|
<string name="restriction_nfc_enable_summary" product="default">Allow data exchange when the phone touches another device</string>
|
||||||
<!-- Restrictions title for allowing location sharing [CHAR LIMIT=35] -->
|
<!-- Restrictions title for allowing location sharing [CHAR LIMIT=35] -->
|
||||||
<string name="restriction_location_enable_title">Location access</string>
|
<string name="restriction_location_enable_title">Location</string>
|
||||||
<!-- Restrictions summary for allowing location sharing [CHAR LIMIT=100] -->
|
<!-- Restrictions summary for allowing location sharing [CHAR LIMIT=100] -->
|
||||||
<string name="restriction_location_enable_summary" >Let apps use your location information</string>
|
<string name="restriction_location_enable_summary" >Let apps use your location information</string>
|
||||||
|
|
||||||
|
36
res/xml/location_mode.xml
Normal file
36
res/xml/location_mode.xml
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2011 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:title="@string/location_mode_screen_title">
|
||||||
|
|
||||||
|
<com.android.settings.location.RadioButtonPreference
|
||||||
|
android:key="high_accuracy"
|
||||||
|
android:title="@string/location_mode_high_accuracy_title"
|
||||||
|
android:summary="@string/location_mode_high_accuracy_description"
|
||||||
|
android:persistent="false" />
|
||||||
|
<com.android.settings.location.RadioButtonPreference
|
||||||
|
android:key="battery_saving"
|
||||||
|
android:title="@string/location_mode_battery_saving_title"
|
||||||
|
android:summary="@string/location_mode_battery_saving_description"
|
||||||
|
android:persistent="false" />
|
||||||
|
<com.android.settings.location.RadioButtonPreference
|
||||||
|
android:key="sensors_only"
|
||||||
|
android:title="@string/location_mode_sensors_only_title"
|
||||||
|
android:summary="@string/location_mode_sensors_only_description"
|
||||||
|
android:persistent="false" />
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
@@ -16,38 +16,20 @@
|
|||||||
|
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:title="@string/location_settings_title">
|
android:title="@string/location_settings_title">
|
||||||
|
<PreferenceScreen
|
||||||
<com.android.settings.location.WrappingSwitchPreference
|
android:title="Under Construction"
|
||||||
android:key="location_toggle"
|
android:summary="This page is under construction and everything here is expected to be broken for a while. Keep calm and carry on!" />
|
||||||
android:title="@string/location_access_title"
|
<PreferenceScreen
|
||||||
android:summary="@string/location_access_summary"
|
android:key="location_mode"
|
||||||
android:persistent="true"/>
|
android:title="@string/location_mode_title"
|
||||||
|
android:summary="@string/location_mode_high_accuracy_title" />
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="location_sources"
|
android:key="recent_location_requests"
|
||||||
android:title="@string/location_sources_heading" />
|
android:title="@string/location_category_recent_location_requests" />
|
||||||
|
|
||||||
<com.android.settings.location.RadioButtonPreference
|
<PreferenceCategory
|
||||||
android:key="location_gps"
|
android:key="location_services"
|
||||||
android:title="@string/location_gps"
|
android:title="@string/location_category_location_services" />
|
||||||
android:summary="@string/location_street_level"
|
|
||||||
android:dependency="location_toggle"
|
|
||||||
android:persistent="false" />
|
|
||||||
|
|
||||||
<com.android.settings.location.RadioButtonPreference
|
|
||||||
android:key="location_network"
|
|
||||||
android:title="@string/location_network_based"
|
|
||||||
android:summary="@string/location_neighborhood_level"
|
|
||||||
android:dependency="location_toggle"
|
|
||||||
android:persistent="false" />
|
|
||||||
|
|
||||||
<!-- Disabled to avoid confusion on devices with no AGPS
|
|
||||||
For Google experience devices we want AGPS on by default (if supported) so we don't really need this.
|
|
||||||
<CheckBoxPreference
|
|
||||||
android:key="assisted_gps"
|
|
||||||
android:title="@string/assisted_gps"
|
|
||||||
android:summaryOn="@string/assisted_gps_enabled"
|
|
||||||
android:summaryOff="@string/assisted_gps_disabled"/>
|
|
||||||
-->
|
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
@@ -482,6 +482,7 @@ public class Settings extends PreferenceActivity
|
|||||||
WifiDisplaySettings.class.getName().equals(fragmentName) ||
|
WifiDisplaySettings.class.getName().equals(fragmentName) ||
|
||||||
BluetoothSettings.class.getName().equals(fragmentName) ||
|
BluetoothSettings.class.getName().equals(fragmentName) ||
|
||||||
DreamSettings.class.getName().equals(fragmentName) ||
|
DreamSettings.class.getName().equals(fragmentName) ||
|
||||||
|
LocationSettings.class.getName().equals(fragmentName) ||
|
||||||
ToggleAccessibilityServicePreferenceFragment.class.getName().equals(fragmentName)) {
|
ToggleAccessibilityServicePreferenceFragment.class.getName().equals(fragmentName)) {
|
||||||
intent.putExtra(EXTRA_UI_OPTIONS, ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW);
|
intent.putExtra(EXTRA_UI_OPTIONS, ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW);
|
||||||
}
|
}
|
||||||
|
76
src/com/android/settings/location/LocationEnabler.java
Normal file
76
src/com/android/settings/location/LocationEnabler.java
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* 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.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
|
import android.widget.Switch;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LocationEnabler is a helper to manage the Location on/off master switch
|
||||||
|
* preference. It turns on/off Location master switch and ensures the summary
|
||||||
|
* of the preference reflects the current state.
|
||||||
|
*/
|
||||||
|
public final class LocationEnabler implements CompoundButton.OnCheckedChangeListener {
|
||||||
|
private final Context mContext;
|
||||||
|
private Switch mSwitch;
|
||||||
|
private boolean mValidListener;
|
||||||
|
|
||||||
|
// TODO(lifu): listens to the system configuration change, and modify the switch state whenever
|
||||||
|
// necessary.
|
||||||
|
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public LocationEnabler(Context context, Switch switch_) {
|
||||||
|
mContext = context;
|
||||||
|
mSwitch = switch_;
|
||||||
|
mValidListener = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resume() {
|
||||||
|
mSwitch.setOnCheckedChangeListener(this);
|
||||||
|
mValidListener = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void pause() {
|
||||||
|
mSwitch.setOnCheckedChangeListener(null);
|
||||||
|
mValidListener = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
|
// TODO(lifu): modify the actual location settings when the user flip the master switch.
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setChecked(boolean isChecked) {
|
||||||
|
if (isChecked != mSwitch.isChecked()) {
|
||||||
|
// set listener to null so that that code below doesn't trigger onCheckedChanged()
|
||||||
|
if (mValidListener) {
|
||||||
|
mSwitch.setOnCheckedChangeListener(null);
|
||||||
|
}
|
||||||
|
mSwitch.setChecked(isChecked);
|
||||||
|
if (mValidListener) {
|
||||||
|
mSwitch.setOnCheckedChangeListener(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
74
src/com/android/settings/location/LocationMode.java
Normal file
74
src/com/android/settings/location/LocationMode.java
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* 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.Intent;
|
||||||
|
import android.preference.Preference;
|
||||||
|
import android.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 SettingsPreferenceFragment
|
||||||
|
implements Preference.OnPreferenceChangeListener {
|
||||||
|
@Override
|
||||||
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
createPreferenceHierarchy();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
|
||||||
|
// Make sure we reload the preference hierarchy since some of these settings
|
||||||
|
// depend on others...
|
||||||
|
createPreferenceHierarchy();
|
||||||
|
}
|
||||||
|
|
||||||
|
private PreferenceScreen createPreferenceHierarchy() {
|
||||||
|
PreferenceScreen root = getPreferenceScreen();
|
||||||
|
if (root != null) {
|
||||||
|
root.removeAll();
|
||||||
|
}
|
||||||
|
addPreferencesFromResource(R.xml.location_mode);
|
||||||
|
root = getPreferenceScreen();
|
||||||
|
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getHelpResource() {
|
||||||
|
return R.string.help_url_location_access;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@@ -16,71 +16,43 @@
|
|||||||
|
|
||||||
package com.android.settings.location;
|
package com.android.settings.location;
|
||||||
|
|
||||||
|
import android.app.ActionBar;
|
||||||
import android.content.ContentQueryMap;
|
import android.app.Activity;
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
|
||||||
import android.location.LocationManager;
|
|
||||||
import android.os.UserManager;
|
|
||||||
import android.preference.CheckBoxPreference;
|
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
|
import android.preference.PreferenceActivity;
|
||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
import android.preference.SwitchPreference;
|
import android.util.Log;
|
||||||
import android.provider.Settings;
|
import android.view.Gravity;
|
||||||
import android.util.AttributeSet;
|
import android.widget.Switch;
|
||||||
import android.view.View;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
|
|
||||||
import java.util.Observable;
|
|
||||||
import java.util.Observer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Location access settings.
|
* Location access settings.
|
||||||
*/
|
*/
|
||||||
public class LocationSettings extends SettingsPreferenceFragment
|
public class LocationSettings extends SettingsPreferenceFragment
|
||||||
implements Preference.OnPreferenceChangeListener {
|
implements Preference.OnPreferenceChangeListener {
|
||||||
|
private static final String TAG = LocationSettings.class.getSimpleName();
|
||||||
|
private static final String KEY_LOCATION_MODE = "location_mode";
|
||||||
|
|
||||||
// Location Settings
|
private PreferenceScreen mLocationMode;
|
||||||
private static final String KEY_LOCATION_TOGGLE = "location_toggle";
|
private LocationEnabler mLocationEnabler;
|
||||||
private static final String KEY_LOCATION_NETWORK = "location_network";
|
|
||||||
private static final String KEY_LOCATION_GPS = "location_gps";
|
|
||||||
private static final String KEY_ASSISTED_GPS = "assisted_gps";
|
|
||||||
|
|
||||||
private CheckBoxPreference mNetwork;
|
|
||||||
private CheckBoxPreference mGps;
|
|
||||||
private CheckBoxPreference mAssistedGps;
|
|
||||||
private SwitchPreference mLocationAccess;
|
|
||||||
|
|
||||||
// These provide support for receiving notification when Location Manager settings change.
|
|
||||||
// This is necessary because the Network Location Provider can change settings
|
|
||||||
// if the user does not confirm enabling the provider.
|
|
||||||
private ContentQueryMap mContentQueryMap;
|
|
||||||
|
|
||||||
private Observer mSettingsObserver;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
super.onStart();
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
// listen for Location Manager settings changes
|
createPreferenceHierarchy();
|
||||||
Cursor settingsCursor = getContentResolver().query(Settings.Secure.CONTENT_URI, null,
|
|
||||||
"(" + Settings.System.NAME + "=?)",
|
|
||||||
new String[]{Settings.Secure.LOCATION_PROVIDERS_ALLOWED},
|
|
||||||
null);
|
|
||||||
mContentQueryMap = new ContentQueryMap(settingsCursor, Settings.System.NAME, true, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onResume() {
|
||||||
super.onStop();
|
super.onResume();
|
||||||
if (mSettingsObserver != null) {
|
|
||||||
mContentQueryMap.deleteObserver(mSettingsObserver);
|
// Make sure we reload the preference hierarchy since some of these settings
|
||||||
}
|
// depend on others...
|
||||||
mContentQueryMap.close();
|
createPreferenceHierarchy();
|
||||||
}
|
}
|
||||||
|
|
||||||
private PreferenceScreen createPreferenceHierarchy() {
|
private PreferenceScreen createPreferenceHierarchy() {
|
||||||
@@ -91,148 +63,56 @@ public class LocationSettings extends SettingsPreferenceFragment
|
|||||||
addPreferencesFromResource(R.xml.location_settings);
|
addPreferencesFromResource(R.xml.location_settings);
|
||||||
root = getPreferenceScreen();
|
root = getPreferenceScreen();
|
||||||
|
|
||||||
mLocationAccess = (SwitchPreference) root.findPreference(KEY_LOCATION_TOGGLE);
|
mLocationMode = (PreferenceScreen) root.findPreference((KEY_LOCATION_MODE));
|
||||||
mNetwork = (CheckBoxPreference) root.findPreference(KEY_LOCATION_NETWORK);
|
mLocationMode.setOnPreferenceClickListener(
|
||||||
mGps = (CheckBoxPreference) root.findPreference(KEY_LOCATION_GPS);
|
new Preference.OnPreferenceClickListener() {
|
||||||
mAssistedGps = (CheckBoxPreference) root.findPreference(KEY_ASSISTED_GPS);
|
@Override
|
||||||
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
|
PreferenceActivity preferenceActivity =
|
||||||
|
(PreferenceActivity) getActivity();
|
||||||
|
preferenceActivity.startPreferencePanel(
|
||||||
|
LocationMode.class.getName(), null,
|
||||||
|
R.string.location_mode_screen_title, null, LocationSettings.this,
|
||||||
|
0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Only enable these controls if this user is allowed to change location
|
Activity activity = getActivity();
|
||||||
// sharing settings.
|
Switch actionBarSwitch = new Switch(activity);
|
||||||
final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
|
|
||||||
boolean isToggleAllowed = !um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION);
|
|
||||||
if (mLocationAccess != null) mLocationAccess.setEnabled(isToggleAllowed);
|
|
||||||
if (mNetwork != null) mNetwork.setEnabled(isToggleAllowed);
|
|
||||||
if (mGps != null) mGps.setEnabled(isToggleAllowed);
|
|
||||||
if (mAssistedGps != null) mAssistedGps.setEnabled(isToggleAllowed);
|
|
||||||
|
|
||||||
mLocationAccess.setOnPreferenceChangeListener(this);
|
if (activity instanceof PreferenceActivity) {
|
||||||
return root;
|
PreferenceActivity preferenceActivity = (PreferenceActivity) activity;
|
||||||
}
|
// Only show the master switch when we're not in multi-pane mode, and not being used as
|
||||||
|
// Setup Wizard.
|
||||||
@Override
|
if (preferenceActivity.onIsHidingHeaders() || !preferenceActivity.onIsMultiPane()) {
|
||||||
public void onResume() {
|
final int padding = activity.getResources().getDimensionPixelSize(
|
||||||
super.onResume();
|
R.dimen.action_bar_switch_padding);
|
||||||
|
actionBarSwitch.setPaddingRelative(0, 0, padding, 0);
|
||||||
// Make sure we reload the preference hierarchy since some of these settings
|
activity.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
|
||||||
// depend on others...
|
ActionBar.DISPLAY_SHOW_CUSTOM);
|
||||||
createPreferenceHierarchy();
|
activity.getActionBar().setCustomView(actionBarSwitch, new ActionBar.LayoutParams(
|
||||||
updateLocationToggles();
|
ActionBar.LayoutParams.WRAP_CONTENT,
|
||||||
|
ActionBar.LayoutParams.WRAP_CONTENT,
|
||||||
if (mSettingsObserver == null) {
|
Gravity.CENTER_VERTICAL | Gravity.END));
|
||||||
mSettingsObserver = new Observer() {
|
|
||||||
@Override
|
|
||||||
public void update(Observable o, Object arg) {
|
|
||||||
updateLocationToggles();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
mContentQueryMap.addObserver(mSettingsObserver);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
|
|
||||||
final ContentResolver cr = getContentResolver();
|
|
||||||
final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
|
|
||||||
if (preference == mNetwork) {
|
|
||||||
if (!um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION)) {
|
|
||||||
Settings.Secure.setLocationProviderEnabled(cr,
|
|
||||||
LocationManager.NETWORK_PROVIDER, mNetwork.isChecked());
|
|
||||||
}
|
}
|
||||||
} else if (preference == mGps) {
|
|
||||||
boolean enabled = mGps.isChecked();
|
|
||||||
if (!um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION)) {
|
|
||||||
Settings.Secure.setLocationProviderEnabled(cr,
|
|
||||||
LocationManager.GPS_PROVIDER, enabled);
|
|
||||||
if (mAssistedGps != null) {
|
|
||||||
mAssistedGps.setEnabled(enabled);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (preference == mAssistedGps) {
|
|
||||||
Settings.Global.putInt(cr, Settings.Global.ASSISTED_GPS_ENABLED,
|
|
||||||
mAssistedGps.isChecked() ? 1 : 0);
|
|
||||||
} else {
|
} else {
|
||||||
// If we didn't handle it, let preferences handle it.
|
Log.wtf(TAG, "Current activity is not an instance of PreferenceActivity!");
|
||||||
return super.onPreferenceTreeClick(preferenceScreen, preference);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
mLocationEnabler = new LocationEnabler(activity, actionBarSwitch);
|
||||||
}
|
setHasOptionsMenu(true);
|
||||||
|
|
||||||
/*
|
return root;
|
||||||
* Creates toggles for each available location provider
|
|
||||||
*/
|
|
||||||
private void updateLocationToggles() {
|
|
||||||
ContentResolver res = getContentResolver();
|
|
||||||
boolean gpsEnabled = Settings.Secure.isLocationProviderEnabled(
|
|
||||||
res, LocationManager.GPS_PROVIDER);
|
|
||||||
boolean networkEnabled = Settings.Secure.isLocationProviderEnabled(
|
|
||||||
res, LocationManager.NETWORK_PROVIDER);
|
|
||||||
mGps.setChecked(gpsEnabled);
|
|
||||||
mNetwork.setChecked(networkEnabled);
|
|
||||||
mLocationAccess.setChecked(gpsEnabled || networkEnabled);
|
|
||||||
if (mAssistedGps != null) {
|
|
||||||
mAssistedGps.setChecked(Settings.Global.getInt(res,
|
|
||||||
Settings.Global.ASSISTED_GPS_ENABLED, 2) == 1);
|
|
||||||
mAssistedGps.setEnabled(gpsEnabled);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* see confirmPatternThenDisableAndClear
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
|
||||||
createPreferenceHierarchy();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Enable or disable all providers when the master toggle is changed. */
|
|
||||||
private void onToggleLocationAccess(boolean checked) {
|
|
||||||
final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
|
|
||||||
if (um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final ContentResolver cr = getContentResolver();
|
|
||||||
Settings.Secure.setLocationProviderEnabled(cr,
|
|
||||||
LocationManager.GPS_PROVIDER, checked);
|
|
||||||
Settings.Secure.setLocationProviderEnabled(cr,
|
|
||||||
LocationManager.NETWORK_PROVIDER, checked);
|
|
||||||
updateLocationToggles();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onPreferenceChange(Preference pref, Object newValue) {
|
|
||||||
if (pref.getKey().equals(KEY_LOCATION_TOGGLE)) {
|
|
||||||
onToggleLocationAccess((Boolean) newValue);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getHelpResource() {
|
public int getHelpResource() {
|
||||||
return R.string.help_url_location_access;
|
return R.string.help_url_location_access;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
class WrappingSwitchPreference extends SwitchPreference {
|
|
||||||
|
|
||||||
public WrappingSwitchPreference(Context context, AttributeSet attrs, int defStyle) {
|
|
||||||
super(context, attrs, defStyle);
|
|
||||||
}
|
|
||||||
|
|
||||||
public WrappingSwitchPreference(Context context, AttributeSet attrs) {
|
|
||||||
super(context, attrs);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onBindView(View view) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
super.onBindView(view);
|
return true;
|
||||||
|
|
||||||
TextView title = (TextView) view.findViewById(android.R.id.title);
|
|
||||||
if (title != null) {
|
|
||||||
title.setSingleLine(false);
|
|
||||||
title.setMaxLines(3);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user