Switch location Settings and Power widget to use new Settings api.
Change-Id: I06b7a2e21876a18d9ad42fda2a6c6d4c7b6add48
This commit is contained in:
@@ -20,10 +20,8 @@ import android.content.ContentQueryMap;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.location.LocationManager;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
|
||||
@@ -35,17 +33,6 @@ import java.util.Observer;
|
||||
* settings.
|
||||
*/
|
||||
public abstract class LocationSettingsBase extends SettingsPreferenceFragment {
|
||||
private static final String TAG = LocationSettingsBase.class.getSimpleName();
|
||||
|
||||
/** Location disabled */
|
||||
public static final int MODE_LOCATION_OFF = 0;
|
||||
/** GPS-only */
|
||||
public static final int MODE_SENSORS_ONLY = 1;
|
||||
/** Network location only */
|
||||
public static final int MODE_BATTERY_SAVING = 2;
|
||||
/** GPS and network location */
|
||||
public static final int MODE_HIGH_ACCURACY = 3;
|
||||
|
||||
private ContentQueryMap mContentQueryMap;
|
||||
private Observer mSettingsObserver;
|
||||
|
||||
@@ -88,51 +75,17 @@ public abstract class LocationSettingsBase extends SettingsPreferenceFragment {
|
||||
public abstract void onModeChanged(int mode);
|
||||
|
||||
public void setLocationMode(int mode) {
|
||||
boolean gps = false;
|
||||
boolean network = false;
|
||||
switch (mode) {
|
||||
case MODE_LOCATION_OFF:
|
||||
break;
|
||||
case MODE_SENSORS_ONLY:
|
||||
gps = true;
|
||||
break;
|
||||
case MODE_BATTERY_SAVING:
|
||||
network = true;
|
||||
break;
|
||||
case MODE_HIGH_ACCURACY:
|
||||
gps = true;
|
||||
network = true;
|
||||
break;
|
||||
default:
|
||||
Log.wtf(TAG, "Invalid location mode: " + mode);
|
||||
}
|
||||
final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
|
||||
if (um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION)) {
|
||||
return;
|
||||
}
|
||||
// TODO(lifu): use new atomic API to change location mode.
|
||||
Settings.Secure.setLocationProviderEnabled(
|
||||
getContentResolver(), LocationManager.GPS_PROVIDER, gps);
|
||||
Settings.Secure.setLocationProviderEnabled(
|
||||
getContentResolver(), LocationManager.NETWORK_PROVIDER, network);
|
||||
Settings.Secure.setLocationMode(getContentResolver(), mode);
|
||||
refreshLocationMode();
|
||||
}
|
||||
|
||||
public void refreshLocationMode() {
|
||||
ContentResolver res = getContentResolver();
|
||||
boolean gpsEnabled = Settings.Secure.isLocationProviderEnabled(
|
||||
res, LocationManager.GPS_PROVIDER);
|
||||
boolean networkEnabled = Settings.Secure.isLocationProviderEnabled(
|
||||
res, LocationManager.NETWORK_PROVIDER);
|
||||
boolean enabled = gpsEnabled || networkEnabled;
|
||||
if (!enabled) {
|
||||
onModeChanged(MODE_LOCATION_OFF);
|
||||
} else if (gpsEnabled && !networkEnabled) {
|
||||
onModeChanged(MODE_SENSORS_ONLY);
|
||||
} else if (!gpsEnabled && networkEnabled) {
|
||||
onModeChanged(MODE_BATTERY_SAVING);
|
||||
} else {
|
||||
onModeChanged(MODE_HIGH_ACCURACY);
|
||||
}
|
||||
int mode = Settings.Secure.getLocationMode(getContentResolver());
|
||||
onModeChanged(mode);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user