am ae95da41: Merge "Switch location Settings and Power widget to use new Settings api." into klp-dev

* commit 'ae95da417ce5c88127ae806994491a49885066ab':
  Switch location Settings and Power widget to use new Settings api.
This commit is contained in:
David Christie
2013-08-21 10:45:08 -07:00
committed by Android Git Automerger
4 changed files with 28 additions and 69 deletions

View File

@@ -20,6 +20,7 @@ import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.provider.Settings;
import com.android.settings.R; import com.android.settings.R;
@@ -97,13 +98,13 @@ public class LocationMode extends LocationSettingsBase
@Override @Override
public void onRadioButtonClicked(RadioButtonPreference emiter) { public void onRadioButtonClicked(RadioButtonPreference emiter) {
int mode = LocationSettingsBase.MODE_LOCATION_OFF; int mode = Settings.Secure.LOCATION_MODE_OFF;
if (emiter == mHighAccuracy) { if (emiter == mHighAccuracy) {
mode = LocationSettingsBase.MODE_HIGH_ACCURACY; mode = Settings.Secure.LOCATION_MODE_HIGH_ACCURACY;
} else if (emiter == mBatterySaving) { } else if (emiter == mBatterySaving) {
mode = LocationSettingsBase.MODE_BATTERY_SAVING; mode = Settings.Secure.LOCATION_MODE_BATTERY_SAVING;
} else if (emiter == mSensorsOnly) { } else if (emiter == mSensorsOnly) {
mode = LocationSettingsBase.MODE_SENSORS_ONLY; mode = Settings.Secure.LOCATION_MODE_SENSORS_ONLY;
} }
setLocationMode(mode); setLocationMode(mode);
} }
@@ -111,24 +112,24 @@ public class LocationMode extends LocationSettingsBase
@Override @Override
public void onModeChanged(int mode) { public void onModeChanged(int mode) {
switch (mode) { switch (mode) {
case MODE_LOCATION_OFF: case Settings.Secure.LOCATION_MODE_OFF:
Intent intent = new Intent(); Intent intent = new Intent();
PreferenceActivity pa = (PreferenceActivity) getActivity(); PreferenceActivity pa = (PreferenceActivity) getActivity();
pa.finishPreferencePanel(LocationMode.this, Activity.RESULT_OK, intent); pa.finishPreferencePanel(LocationMode.this, Activity.RESULT_OK, intent);
break; break;
case MODE_SENSORS_ONLY: case Settings.Secure.LOCATION_MODE_SENSORS_ONLY:
updateRadioButtons(mSensorsOnly); updateRadioButtons(mSensorsOnly);
break; break;
case MODE_BATTERY_SAVING: case Settings.Secure.LOCATION_MODE_BATTERY_SAVING:
updateRadioButtons(mBatterySaving); updateRadioButtons(mBatterySaving);
break; break;
case MODE_HIGH_ACCURACY: case Settings.Secure.LOCATION_MODE_HIGH_ACCURACY:
updateRadioButtons(mHighAccuracy); updateRadioButtons(mHighAccuracy);
break; break;
default: default:
break; break;
} }
boolean enabled = (mode != MODE_LOCATION_OFF); boolean enabled = (mode != Settings.Secure.LOCATION_MODE_OFF);
mHighAccuracy.setEnabled(enabled); mHighAccuracy.setEnabled(enabled);
mBatterySaving.setEnabled(enabled); mBatterySaving.setEnabled(enabled);
mSensorsOnly.setEnabled(enabled); mSensorsOnly.setEnabled(enabled);

View File

@@ -24,6 +24,7 @@ import android.preference.Preference;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory; import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.provider.Settings;
import android.view.Gravity; import android.view.Gravity;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.Switch; import android.widget.Switch;
@@ -155,23 +156,23 @@ public class LocationSettings extends LocationSettingsBase
@Override @Override
public void onModeChanged(int mode) { public void onModeChanged(int mode) {
switch (mode) { switch (mode) {
case MODE_LOCATION_OFF: case Settings.Secure.LOCATION_MODE_OFF:
mLocationMode.setSummary(R.string.location_mode_location_off_title); mLocationMode.setSummary(R.string.location_mode_location_off_title);
break; break;
case MODE_SENSORS_ONLY: case Settings.Secure.LOCATION_MODE_SENSORS_ONLY:
mLocationMode.setSummary(R.string.location_mode_sensors_only_title); mLocationMode.setSummary(R.string.location_mode_sensors_only_title);
break; break;
case MODE_BATTERY_SAVING: case Settings.Secure.LOCATION_MODE_BATTERY_SAVING:
mLocationMode.setSummary(R.string.location_mode_battery_saving_title); mLocationMode.setSummary(R.string.location_mode_battery_saving_title);
break; break;
case MODE_HIGH_ACCURACY: case Settings.Secure.LOCATION_MODE_HIGH_ACCURACY:
mLocationMode.setSummary(R.string.location_mode_high_accuracy_title); mLocationMode.setSummary(R.string.location_mode_high_accuracy_title);
break; break;
default: default:
break; break;
} }
boolean enabled = (mode != MODE_LOCATION_OFF); boolean enabled = (mode != Settings.Secure.LOCATION_MODE_OFF);
mLocationMode.setEnabled(enabled); mLocationMode.setEnabled(enabled);
mRecentLocationRequests.setEnabled(enabled); mRecentLocationRequests.setEnabled(enabled);
mLocationServices.setEnabled(enabled); mLocationServices.setEnabled(enabled);
@@ -194,9 +195,9 @@ public class LocationSettings extends LocationSettingsBase
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) { if (isChecked) {
setLocationMode(MODE_HIGH_ACCURACY); setLocationMode(Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);
} else { } else {
setLocationMode(MODE_LOCATION_OFF); setLocationMode(Settings.Secure.LOCATION_MODE_OFF);
} }
} }
} }

View File

@@ -20,10 +20,8 @@ import android.content.ContentQueryMap;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.location.LocationManager;
import android.os.UserManager; import android.os.UserManager;
import android.provider.Settings; import android.provider.Settings;
import android.util.Log;
import com.android.settings.SettingsPreferenceFragment; import com.android.settings.SettingsPreferenceFragment;
@@ -35,17 +33,6 @@ import java.util.Observer;
* settings. * settings.
*/ */
public abstract class LocationSettingsBase extends SettingsPreferenceFragment { 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 ContentQueryMap mContentQueryMap;
private Observer mSettingsObserver; private Observer mSettingsObserver;
@@ -88,51 +75,17 @@ public abstract class LocationSettingsBase extends SettingsPreferenceFragment {
public abstract void onModeChanged(int mode); public abstract void onModeChanged(int mode);
public void setLocationMode(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); final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
if (um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION)) { if (um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION)) {
return; return;
} }
// TODO(lifu): use new atomic API to change location mode. Settings.Secure.setLocationMode(getContentResolver(), mode);
Settings.Secure.setLocationProviderEnabled(
getContentResolver(), LocationManager.GPS_PROVIDER, gps);
Settings.Secure.setLocationProviderEnabled(
getContentResolver(), LocationManager.NETWORK_PROVIDER, network);
refreshLocationMode(); refreshLocationMode();
} }
public void refreshLocationMode() { public void refreshLocationMode() {
ContentResolver res = getContentResolver(); ContentResolver res = getContentResolver();
boolean gpsEnabled = Settings.Secure.isLocationProviderEnabled( int mode = Settings.Secure.getLocationMode(getContentResolver());
res, LocationManager.GPS_PROVIDER); onModeChanged(mode);
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);
}
} }
} }

View File

@@ -521,7 +521,7 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider {
@Override @Override
public int getActualState(Context context) { public int getActualState(Context context) {
ContentResolver resolver = context.getContentResolver(); ContentResolver resolver = context.getContentResolver();
return Settings.Secure.isLocationMasterSwitchEnabled(resolver) return Settings.Secure.getLocationMode(resolver) != Settings.Secure.LOCATION_MODE_OFF
? STATE_ENABLED : STATE_DISABLED; ? STATE_ENABLED : STATE_DISABLED;
} }
@@ -541,11 +541,15 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider {
final UserManager um = final UserManager um =
(UserManager) context.getSystemService(Context.USER_SERVICE); (UserManager) context.getSystemService(Context.USER_SERVICE);
if (!um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION)) { if (!um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION)) {
Settings.Secure.setLocationMasterSwitchEnabled(resolver, desiredState); int mode = desiredState
? Settings.Secure.LOCATION_MODE_HIGH_ACCURACY
: Settings.Secure.LOCATION_MODE_OFF;
Settings.Secure.setLocationMode(resolver, mode);
return desiredState; return desiredState;
} }
return Settings.Secure.isLocationMasterSwitchEnabled(resolver); return Settings.Secure.getLocationMode(resolver)
!= Settings.Secure.LOCATION_MODE_OFF;
} }
@Override @Override