summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/res/drawable/ic_qs_location_battery_saving.xml28
-rw-r--r--packages/SystemUI/res/drawable/ic_qs_location_off.xml28
-rw-r--r--packages/SystemUI/res/layout/qs_detail_items_list.xml7
-rw-r--r--packages/SystemUI/res/layout/qs_settings.xml7
-rw-r--r--packages/SystemUI/res/values/cm_strings.xml38
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/LocationTile.java210
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationController.java3
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationControllerImpl.java63
8 files changed, 358 insertions, 26 deletions
diff --git a/packages/SystemUI/res/drawable/ic_qs_location_battery_saving.xml b/packages/SystemUI/res/drawable/ic_qs_location_battery_saving.xml
new file mode 100644
index 0000000..efd8f16
--- /dev/null
+++ b/packages/SystemUI/res/drawable/ic_qs_location_battery_saving.xml
@@ -0,0 +1,28 @@
+<!--
+Copyright (C) 2014 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.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="64dp"
+ android:height="64dp"
+ android:viewportWidth="48.0"
+ android:viewportHeight="48.0">
+
+ <path
+ android:fillColor="#4DFFFFFF"
+ android:pathData="M24.0,4.0c-7.7,0.0 -14.0,6.3 -14.0,14.0c0.0,10.5 14.0,26.0 14.0,26.0s14.0,-15.5 14.0,-26.0C38.0,10.3 31.7,4.0 24.0,4.0zM24.0,23.0c-2.8,0.0 -5.0,-2.2 -5.0,-5.0s2.2,-5.0 5.0,-5.0c2.8,0.0 5.0,2.2 5.0,5.0S26.8,23.0 24.0,23.0z"/>
+ <path
+ android:pathData="M24.0,4.0c-7.7,0.0 -14.0,6.3 -14.0,14.0c0.0,10.5 14.0,26.0 14.0,26.0l0.0,-21.0 c-2.8,0.0 -5.0,-2.2 -5.0,-5.0s2.2,-5.0 5.0,-5.0l0.0,-9.0z"
+ android:fillColor="#FFFFFFFF"/>
+</vector>
diff --git a/packages/SystemUI/res/drawable/ic_qs_location_off.xml b/packages/SystemUI/res/drawable/ic_qs_location_off.xml
new file mode 100644
index 0000000..e0fe12e
--- /dev/null
+++ b/packages/SystemUI/res/drawable/ic_qs_location_off.xml
@@ -0,0 +1,28 @@
+<!--
+Copyright (C) 2014 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.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="64dp"
+ android:height="64dp"
+ android:viewportWidth="48.0"
+ android:viewportHeight="48.0">
+
+ <path
+ android:fillColor="#4DFFFFFF"
+ android:pathData="M24.0,13.0c2.8,0.0 5.0,2.2 5.0,5.0c0.0,1.5 -0.7,2.8 -1.7,3.7l7.3,7.3c2.0,-3.7 3.4,-7.6 3.4,-11.0c0.0,-7.7 -6.3,-14.0 -14.0,-14.0c-4.0,0.0 -7.5,1.6 -10.1,4.3l6.4,6.4C21.2,13.6 22.5,13.0 24.0,13.0zM32.7,32.2l-9.3,-9.3l-0.2,-0.2L6.5,6.0L4.0,8.5l6.4,6.4c-0.2,1.0 -0.4,2.0 -0.4,3.1c0.0,10.5 14.0,26.0 14.0,26.0s3.3,-3.7 6.8,-8.7l6.7,6.7l2.5,-2.5L32.7,32.2z"/>
+ <path
+ android:pathData="M23.5,22.9l0.0,0.0 -0.20000076,-0.19999886z"
+ android:fillColor="#4DFFFFFF"/>
+</vector>
diff --git a/packages/SystemUI/res/layout/qs_detail_items_list.xml b/packages/SystemUI/res/layout/qs_detail_items_list.xml
index 535f28d..09021f9 100644
--- a/packages/SystemUI/res/layout/qs_detail_items_list.xml
+++ b/packages/SystemUI/res/layout/qs_detail_items_list.xml
@@ -25,16 +25,17 @@
<ListView
android:id="@android:id/list"
+ android:divider="@null"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />
<LinearLayout
android:id="@android:id/empty"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
android:layout_gravity="center"
- android:gravity="center_horizontal"
+ android:gravity="center"
android:orientation="vertical" >
<ImageView
diff --git a/packages/SystemUI/res/layout/qs_settings.xml b/packages/SystemUI/res/layout/qs_settings.xml
index 8f965ea..759275a 100644
--- a/packages/SystemUI/res/layout/qs_settings.xml
+++ b/packages/SystemUI/res/layout/qs_settings.xml
@@ -57,6 +57,13 @@
systemui:defaultValue="1"
systemui:table="cm_secure" />
+ <com.android.systemui.qs.QSBooleanSettingRow
+ style="@style/SettingRow"
+ android:title="@string/quick_settings_title_advanced_location"
+ android:key="qs_location_advanced"
+ systemui:defaultValue="0"
+ systemui:table="cm_secure" />
+
<LinearLayout
android:id="@+id/reset_tiles"
style="@style/SettingRow">
diff --git a/packages/SystemUI/res/values/cm_strings.xml b/packages/SystemUI/res/values/cm_strings.xml
index 014ff47..cfc39c4 100644
--- a/packages/SystemUI/res/values/cm_strings.xml
+++ b/packages/SystemUI/res/values/cm_strings.xml
@@ -198,4 +198,42 @@
<string name="accessibility_quick_settings_live_display_changed_day">LiveDisplay changed to day mode.</string>
<string name="accessibility_quick_settings_live_display_changed_night">LiveDisplay changed to night mode.</string>
<string name="accessibility_quick_settings_live_display_changed_outdoor">LiveDisplay changed to outdoor mode.</string>
+ <string name="quick_settings_title_advanced_location">Tri-state location</string>
+
+ <!-- Content description of the location tile in quick settings when on, battery saving mode (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_quick_settings_location_battery_saving">Location reporting: battery saving mode.</string>
+ <!-- Content description of the location tile in quick settings when on, sensors only mode (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_quick_settings_location_gps_only">Location reporting: sensors only mode.</string>
+ <!-- Content description of the location tile in quick settings when on, high accuracy mode (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_quick_settings_location_high_accuracy">Location reporting: high accuracy mode.</string>
+
+ <!-- QuickSettings: Location (On, low-power) [CHAR LIMIT=NONE] -->
+ <string name="quick_settings_location_battery_saving_label">Battery saving</string>
+ <!-- QuickSettings: Location (On, gps-only) [CHAR LIMIT=NONE] -->
+ <string name="quick_settings_location_gps_only_label">GPS only</string>
+ <!-- QuickSettings: Location (On, high-accuracy) [CHAR LIMIT=NONE] -->
+ <string name="quick_settings_location_high_accuracy_label">High accuracy</string>
+
+ <!-- QuickSettings: Location detail panel title [CHAR LIMIT=NONE] -->
+ <string name="quick_settings_location_detail_title">Location</string>
+ <!-- QuickSettings: Location detail panel menu title [CHAR LIMIT=NONE] -->
+ <string name="quick_settings_location_detail_menu_title">Select mode:</string>
+ <!-- [CHAR LIMIT=30] Location detail panel, high accuracy location mode -->
+ <string name="quick_settings_location_detail_mode_high_accuracy_title">High accuracy</string>
+ <!-- [CHAR LIMIT=30] Location detail panel, battery saving location mode -->
+ <string name="quick_settings_location_detail_mode_battery_saving_title">Battery saving</string>
+ <!-- [CHAR LIMIT=30] Location detail panel, device only location mode -->
+ <string name="quick_settings_location_detail_mode_sensors_only_title">Device only</string>
+ <!-- [CHAR LIMIT=130] Location detail panel, description for high accuracy mode -->
+ <string name="quick_settings_location_detail_mode_high_accuracy_description">Use GPS, Wi\u2011Fi, and cellular networks to determine location </string>
+ <!-- [CHAR LIMIT=130] Location detail panel, description for battery saving mode -->
+ <string name="quick_settings_location_detail_mode_battery_saving_description">Use Wi\u2011Fi and cellular networks to determine location</string>
+ <!-- [CHAR LIMIT=130] Location detail panel, description for sensors only mode -->
+ <string name="quick_settings_location_detail_mode_sensors_only_description">Use GPS to determine your location</string>
+ <!-- Announcement made when the location tile changes to battery saving (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_quick_settings_location_changed_battery_saving">Location reporting changed to battery saving mode.</string>
+ <!-- Announcement made when the location tile changes to sensors only (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_quick_settings_location_changed_gps_only">Location reporting changed to sensors only mode.</string>
+ <!-- Announcement made when the location tile changes to high accuracy (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_quick_settings_location_changed_high_accuracy">Location reporting changed to high accuracy mode.</string>
</resources>
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/LocationTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/LocationTile.java
index 347d079..3598bba 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/LocationTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/LocationTile.java
@@ -17,21 +17,44 @@
package com.android.systemui.qs.tiles;
+import com.android.internal.logging.MetricsConstants;
import com.android.internal.logging.MetricsLogger;
+import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AbsListView;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.CheckedTextView;
+import android.widget.ListView;
import com.android.systemui.R;
+import com.android.systemui.qs.QSDetailItems;
+import com.android.systemui.qs.QSDetailItemsList;
import com.android.systemui.qs.QSTile;
import com.android.systemui.statusbar.policy.KeyguardMonitor;
import com.android.systemui.statusbar.policy.LocationController;
import com.android.systemui.statusbar.policy.LocationController.LocationSettingsChangeCallback;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import cyanogenmod.app.StatusBarPanelCustomTile;
+
/** Quick settings tile: Location **/
public class LocationTile extends QSTile<QSTile.BooleanState> {
- private static final Intent LOCATION_SETTINGS = new Intent(
- Settings.ACTION_LOCATION_SOURCE_SETTINGS);
+ private static final Intent LOCATION_SETTINGS_INTENT
+ = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
+ public static final Integer[] LOCATION_SETTINGS = new Integer[]{
+ Settings.Secure.LOCATION_MODE_BATTERY_SAVING,
+ Settings.Secure.LOCATION_MODE_SENSORS_ONLY,
+ Settings.Secure.LOCATION_MODE_HIGH_ACCURACY
+ };
private final AnimationIcon mEnable =
new AnimationIcon(R.drawable.ic_signal_location_enable_animation);
@@ -39,16 +62,24 @@ public class LocationTile extends QSTile<QSTile.BooleanState> {
new AnimationIcon(R.drawable.ic_signal_location_disable_animation);
private final LocationController mController;
+ private final LocationDetailAdapter mDetailAdapter;
private final KeyguardMonitor mKeyguard;
private final Callback mCallback = new Callback();
+ private final List<Integer> mLocationList = new ArrayList<Integer>();
public LocationTile(Host host) {
super(host);
mController = host.getLocationController();
+ mDetailAdapter = new LocationDetailAdapter();
mKeyguard = host.getKeyguardMonitor();
}
@Override
+ public DetailAdapter getDetailAdapter() {
+ return mDetailAdapter;
+ }
+
+ @Override
protected BooleanState newTileState() {
return new BooleanState();
}
@@ -66,37 +97,74 @@ public class LocationTile extends QSTile<QSTile.BooleanState> {
@Override
protected void handleClick() {
- final boolean wasEnabled = (Boolean) mState.value;
- MetricsLogger.action(mContext, getMetricsCategory(), !wasEnabled);
- mController.setLocationEnabled(!wasEnabled);
+ if(mController.isAdvancedSettingsEnabled()) {
+ showDetail(true);
+ } else {
+ boolean wasEnabled = mController.isLocationEnabled();
+ mController.setLocationEnabled(!wasEnabled);
+ MetricsLogger.action(mContext, getMetricsCategory(), !wasEnabled);
+ refreshState();
+ }
+
mEnable.setAllowAnimation(true);
mDisable.setAllowAnimation(true);
}
@Override
protected void handleLongClick() {
- mHost.startActivityDismissingKeyguard(LOCATION_SETTINGS);
+ mHost.startActivityDismissingKeyguard(LOCATION_SETTINGS_INTENT);
}
@Override
protected void handleUpdateState(BooleanState state, Object arg) {
- final boolean locationEnabled = mController.isLocationEnabled();
+ final int currentState = mController.getLocationCurrentState();
// Work around for bug 15916487: don't show location tile on top of lock screen. After the
// bug is fixed, this should be reverted to only hiding it on secure lock screens:
// state.visible = !(mKeyguard.isSecure() && mKeyguard.isShowing());
state.visible = !mKeyguard.isShowing();
- state.value = locationEnabled;
- if (locationEnabled) {
- state.icon = mEnable;
- state.label = mContext.getString(R.string.quick_settings_location_label);
- state.contentDescription = mContext.getString(
- R.string.accessibility_quick_settings_location_on);
- } else {
- state.icon = mDisable;
- state.label = mContext.getString(R.string.quick_settings_location_label);
- state.contentDescription = mContext.getString(
- R.string.accessibility_quick_settings_location_off);
+ state.label = mContext.getString(getStateLabelRes(currentState));
+
+ switch (currentState) {
+ case Settings.Secure.LOCATION_MODE_OFF:
+ state.contentDescription = mContext.getString(
+ R.string.accessibility_quick_settings_location_off);
+ state.icon = mDisable;
+ break;
+ case Settings.Secure.LOCATION_MODE_BATTERY_SAVING:
+ state.contentDescription = mContext.getString(
+ R.string.accessibility_quick_settings_location_battery_saving);
+ state.icon = ResourceIcon.get(R.drawable.ic_qs_location_battery_saving);
+ break;
+ case Settings.Secure.LOCATION_MODE_SENSORS_ONLY:
+ state.contentDescription = mContext.getString(
+ R.string.accessibility_quick_settings_location_gps_only);
+ state.icon = mEnable;
+ break;
+ case Settings.Secure.LOCATION_MODE_HIGH_ACCURACY:
+ state.contentDescription = mContext.getString(
+ R.string.accessibility_quick_settings_location_high_accuracy);
+ state.icon = mEnable;
+ break;
+ default:
+ state.contentDescription = mContext.getString(
+ R.string.accessibility_quick_settings_location_on);
+ state.icon = mEnable;
+ }
+ }
+
+ private int getStateLabelRes(int currentState) {
+ switch (currentState) {
+ case Settings.Secure.LOCATION_MODE_OFF:
+ return R.string.quick_settings_location_off_label;
+ case Settings.Secure.LOCATION_MODE_BATTERY_SAVING:
+ return R.string.quick_settings_location_battery_saving_label;
+ case Settings.Secure.LOCATION_MODE_SENSORS_ONLY:
+ return R.string.quick_settings_location_gps_only_label;
+ case Settings.Secure.LOCATION_MODE_HIGH_ACCURACY:
+ return R.string.quick_settings_location_high_accuracy_label;
+ default:
+ return R.string.quick_settings_location_label;
}
}
@@ -107,10 +175,22 @@ public class LocationTile extends QSTile<QSTile.BooleanState> {
@Override
protected String composeChangeAnnouncement() {
- if (mState.value) {
- return mContext.getString(R.string.accessibility_quick_settings_location_changed_on);
- } else {
- return mContext.getString(R.string.accessibility_quick_settings_location_changed_off);
+ switch (mController.getLocationCurrentState()) {
+ case Settings.Secure.LOCATION_MODE_OFF:
+ return mContext.getString(
+ R.string.accessibility_quick_settings_location_changed_off);
+ case Settings.Secure.LOCATION_MODE_BATTERY_SAVING:
+ return mContext.getString(
+ R.string.accessibility_quick_settings_location_changed_battery_saving);
+ case Settings.Secure.LOCATION_MODE_SENSORS_ONLY:
+ return mContext.getString(
+ R.string.accessibility_quick_settings_location_changed_gps_only);
+ case Settings.Secure.LOCATION_MODE_HIGH_ACCURACY:
+ return mContext.getString(
+ R.string.accessibility_quick_settings_location_changed_high_accuracy);
+ default:
+ return mContext.getString(
+ R.string.accessibility_quick_settings_location_changed_on);
}
}
@@ -126,4 +206,90 @@ public class LocationTile extends QSTile<QSTile.BooleanState> {
refreshState();
}
};
+
+ private class AdvancedLocationAdapter extends ArrayAdapter<Integer> {
+ public AdvancedLocationAdapter(Context context) {
+ super(context, android.R.layout.simple_list_item_single_choice, mLocationList);
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ LayoutInflater inflater = LayoutInflater.from(mContext);
+ CheckedTextView label = (CheckedTextView) inflater.inflate(
+ android.R.layout.simple_list_item_single_choice, parent, false);
+ label.setText(getStateLabelRes(getItem(position)));
+ return label;
+ }
+ }
+
+ private class LocationDetailAdapter implements DetailAdapter, AdapterView.OnItemClickListener {
+
+ private AdvancedLocationAdapter mAdapter;
+ private QSDetailItemsList mDetails;
+
+ @Override
+ public int getTitle() {
+ return R.string.quick_settings_location_detail_title;
+ }
+
+ @Override
+ public Boolean getToggleState() {
+ boolean state = mController.getLocationCurrentState()
+ != Settings.Secure.LOCATION_MODE_OFF;
+ rebuildLocationList(state);
+ return state;
+ }
+
+ @Override
+ public Intent getSettingsIntent() {
+ return LOCATION_SETTINGS_INTENT;
+ }
+
+ @Override
+ public StatusBarPanelCustomTile getCustomTile() {
+ return null;
+ }
+
+ @Override
+ public void setToggleState(boolean state) {
+ mController.setLocationEnabled(state);
+ rebuildLocationList(state);
+ fireToggleStateChanged(state);
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ return MetricsLogger.QS_LOCATION;
+ }
+
+ @Override
+ public View createDetailView(Context context, View convertView, ViewGroup parent) {
+ mDetails = QSDetailItemsList.convertOrInflate(context, convertView, parent);
+ mDetails.setEmptyState(R.drawable.ic_qs_location_off,
+ R.string.accessibility_quick_settings_location_off);
+ mAdapter = new LocationTile.AdvancedLocationAdapter(context);
+ mDetails.setAdapter(mAdapter);
+
+ final ListView list = mDetails.getListView();
+ list.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
+ list.setOnItemClickListener(this);
+
+ return mDetails;
+ }
+
+ private void rebuildLocationList(boolean populate) {
+ mLocationList.clear();
+ if (populate) {
+ mLocationList.addAll(Arrays.asList(LOCATION_SETTINGS));
+ mDetails.getListView().setItemChecked(mAdapter.getPosition(
+ mController.getLocationCurrentState()), true);
+ }
+ mAdapter.notifyDataSetChanged();
+ }
+
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+ mController.setLocationMode((Integer) parent.getItemAtPosition(position));
+ }
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationController.java
index 29a8981..a88f22d 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationController.java
@@ -19,6 +19,9 @@ package com.android.systemui.statusbar.policy;
public interface LocationController {
boolean isLocationEnabled();
boolean setLocationEnabled(boolean enabled);
+ boolean setLocationMode(int mode);
+ int getLocationCurrentState();
+ boolean isAdvancedSettingsEnabled();
void addSettingsChangedCallback(LocationSettingsChangeCallback cb);
void removeSettingsChangedCallback(LocationSettingsChangeCallback cb);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationControllerImpl.java
index 93a8fd8..e7867b6 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationControllerImpl.java
@@ -37,6 +37,8 @@ import com.android.systemui.R;
import java.util.ArrayList;
import java.util.List;
+import cyanogenmod.providers.CMSettings;
+
/**
* A controller to manage changes of location related states and update the views accordingly.
*/
@@ -55,6 +57,7 @@ public class LocationControllerImpl extends BroadcastReceiver implements Locatio
private StatusBarManager mStatusBarManager;
private boolean mAreActiveLocationRequests;
+ private int mLastActiveMode;
private ArrayList<LocationSettingsChangeCallback> mSettingsChangeCallbacks =
new ArrayList<LocationSettingsChangeCallback>();
@@ -63,6 +66,11 @@ public class LocationControllerImpl extends BroadcastReceiver implements Locatio
public LocationControllerImpl(Context context, Looper bgLooper) {
mContext = context;
+ // Initialize last active mode. If state was off use the default high accuracy mode
+ mLastActiveMode = getLocationCurrentState();
+ if(mLastActiveMode == Settings.Secure.LOCATION_MODE_OFF)
+ mLastActiveMode = Settings.Secure.LOCATION_MODE_HIGH_ACCURACY;
+
// Register to listen for changes in location settings.
IntentFilter filter = new IntentFilter();
filter.addAction(LocationManager.HIGH_POWER_REQUEST_CHANGE_ACTION);
@@ -107,10 +115,17 @@ public class LocationControllerImpl extends BroadcastReceiver implements Locatio
return false;
}
final ContentResolver cr = mContext.getContentResolver();
+
+ // Store last active mode if we are switching off
+ // so we can restore it at the next enable
+ if(!enabled) {
+ mLastActiveMode = getLocationCurrentState();
+ }
+
// When enabling location, a user consent dialog will pop up, and the
// setting won't be fully enabled until the user accepts the agreement.
int mode = enabled
- ? Settings.Secure.LOCATION_MODE_HIGH_ACCURACY : Settings.Secure.LOCATION_MODE_OFF;
+ ? mLastActiveMode : Settings.Secure.LOCATION_MODE_OFF;
// QuickSettings always runs as the owner, so specifically set the settings
// for the current foreground user.
return Settings.Secure
@@ -118,6 +133,44 @@ public class LocationControllerImpl extends BroadcastReceiver implements Locatio
}
/**
+ * Enable or disable location in settings to a specific mode.
+ *
+ * <p>This will attempt to enable/disable every type of location setting
+ * (e.g. high and balanced power).
+ *
+ * <p>If enabling, a user consent dialog will pop up prompting the user to accept.
+ * If the user doesn't accept, network location won't be enabled.
+ *
+ * @return true if attempt to change setting was successful.
+ */
+ public boolean setLocationMode(int mode) {
+ int currentUserId = ActivityManager.getCurrentUser();
+ if (isUserLocationRestricted(currentUserId)) {
+ return false;
+ }
+ final ContentResolver cr = mContext.getContentResolver();
+ // When enabling location, a user consent dialog will pop up, and the
+ // setting won't be fully enabled until the user accepts the agreement.
+ // QuickSettings always runs as the owner, so specifically set the settings
+ // for the current foreground user.
+ return Settings.Secure.putIntForUser(cr, Settings.Secure.LOCATION_MODE,
+ mode, currentUserId);
+ }
+
+ /**
+ * Returns int corresponding to current location mode in settings.
+ */
+ public int getLocationCurrentState() {
+ int currentUserId = ActivityManager.getCurrentUser();
+ if (isUserLocationRestricted(currentUserId)) {
+ return Settings.Secure.LOCATION_MODE_OFF;
+ }
+ final ContentResolver cr = mContext.getContentResolver();
+ return Settings.Secure.getIntForUser(cr, Settings.Secure.LOCATION_MODE,
+ Settings.Secure.LOCATION_MODE_OFF, currentUserId);
+ }
+
+ /**
* Returns true if location isn't disabled in settings.
*/
public boolean isLocationEnabled() {
@@ -130,6 +183,14 @@ public class LocationControllerImpl extends BroadcastReceiver implements Locatio
}
/**
+ * Check if advanced location tile is enabled in settings
+ */
+ public boolean isAdvancedSettingsEnabled() {
+ return CMSettings.Secure.getIntForUser(mContext.getContentResolver(),
+ CMSettings.Secure.QS_LOCATION_ADVANCED, 0, ActivityManager.getCurrentUser()) == 1;
+ }
+
+ /**
* Returns true if the current user is restricted from using location.
*/
private boolean isUserLocationRestricted(int userId) {