Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 512183ea authored by David Christie's avatar David Christie
Browse files

Switch location Settings and Power widget to use new Settings api.

Change-Id: I06b7a2e21876a18d9ad42fda2a6c6d4c7b6add48
parent 0f5578ce
Loading
Loading
Loading
Loading
+10 −9
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.app.Activity;
import android.content.Intent;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.provider.Settings;

import com.android.settings.R;

@@ -97,13 +98,13 @@ public class LocationMode extends LocationSettingsBase

    @Override
    public void onRadioButtonClicked(RadioButtonPreference emiter) {
        int mode = LocationSettingsBase.MODE_LOCATION_OFF;
        int mode = Settings.Secure.LOCATION_MODE_OFF;
        if (emiter == mHighAccuracy) {
            mode = LocationSettingsBase.MODE_HIGH_ACCURACY;
            mode = Settings.Secure.LOCATION_MODE_HIGH_ACCURACY;
        } else if (emiter == mBatterySaving) {
            mode = LocationSettingsBase.MODE_BATTERY_SAVING;
            mode = Settings.Secure.LOCATION_MODE_BATTERY_SAVING;
        } else if (emiter == mSensorsOnly) {
            mode = LocationSettingsBase.MODE_SENSORS_ONLY;
            mode = Settings.Secure.LOCATION_MODE_SENSORS_ONLY;
        }
        setLocationMode(mode);
    }
@@ -111,24 +112,24 @@ public class LocationMode extends LocationSettingsBase
    @Override
    public void onModeChanged(int mode) {
        switch (mode) {
            case MODE_LOCATION_OFF:
            case Settings.Secure.LOCATION_MODE_OFF:
                Intent intent = new Intent();
                PreferenceActivity pa = (PreferenceActivity) getActivity();
                pa.finishPreferencePanel(LocationMode.this, Activity.RESULT_OK, intent);
                break;
            case MODE_SENSORS_ONLY:
            case Settings.Secure.LOCATION_MODE_SENSORS_ONLY:
                updateRadioButtons(mSensorsOnly);
                break;
            case MODE_BATTERY_SAVING:
            case Settings.Secure.LOCATION_MODE_BATTERY_SAVING:
                updateRadioButtons(mBatterySaving);
                break;
            case MODE_HIGH_ACCURACY:
            case Settings.Secure.LOCATION_MODE_HIGH_ACCURACY:
                updateRadioButtons(mHighAccuracy);
                break;
            default:
                break;
        }
        boolean enabled = (mode != MODE_LOCATION_OFF);
        boolean enabled = (mode != Settings.Secure.LOCATION_MODE_OFF);
        mHighAccuracy.setEnabled(enabled);
        mBatterySaving.setEnabled(enabled);
        mSensorsOnly.setEnabled(enabled);
+8 −7
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;
import android.provider.Settings;
import android.view.Gravity;
import android.widget.CompoundButton;
import android.widget.Switch;
@@ -155,23 +156,23 @@ public class LocationSettings extends LocationSettingsBase
    @Override
    public void onModeChanged(int mode) {
        switch (mode) {
            case MODE_LOCATION_OFF:
            case Settings.Secure.LOCATION_MODE_OFF:
                mLocationMode.setSummary(R.string.location_mode_location_off_title);
                break;
            case MODE_SENSORS_ONLY:
            case Settings.Secure.LOCATION_MODE_SENSORS_ONLY:
                mLocationMode.setSummary(R.string.location_mode_sensors_only_title);
                break;
            case MODE_BATTERY_SAVING:
            case Settings.Secure.LOCATION_MODE_BATTERY_SAVING:
                mLocationMode.setSummary(R.string.location_mode_battery_saving_title);
                break;
            case MODE_HIGH_ACCURACY:
            case Settings.Secure.LOCATION_MODE_HIGH_ACCURACY:
                mLocationMode.setSummary(R.string.location_mode_high_accuracy_title);
                break;
            default:
                break;
        }

        boolean enabled = (mode != MODE_LOCATION_OFF);
        boolean enabled = (mode != Settings.Secure.LOCATION_MODE_OFF);
        mLocationMode.setEnabled(enabled);
        mRecentLocationRequests.setEnabled(enabled);
        mLocationServices.setEnabled(enabled);
@@ -194,9 +195,9 @@ public class LocationSettings extends LocationSettingsBase
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (isChecked) {
            setLocationMode(MODE_HIGH_ACCURACY);
            setLocationMode(Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);
        } else {
            setLocationMode(MODE_LOCATION_OFF);
            setLocationMode(Settings.Secure.LOCATION_MODE_OFF);
        }
    }
}
+3 −50
Original line number Diff line number Diff line
@@ -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);
    }
}
+7 −3
Original line number Diff line number Diff line
@@ -521,7 +521,7 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider {
        @Override
        public int getActualState(Context context) {
            ContentResolver resolver = context.getContentResolver();
            return Settings.Secure.isLocationMasterSwitchEnabled(resolver)
            return Settings.Secure.getLocationMode(resolver) != Settings.Secure.LOCATION_MODE_OFF
                    ? STATE_ENABLED : STATE_DISABLED;
        }

@@ -541,11 +541,15 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider {
                    final UserManager um =
                            (UserManager) context.getSystemService(Context.USER_SERVICE);
                    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 Settings.Secure.isLocationMasterSwitchEnabled(resolver);
                    return Settings.Secure.getLocationMode(resolver)
                            != Settings.Secure.LOCATION_MODE_OFF;
                }

                @Override