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

Commit 1673fbc0 authored by Lifu Tang's avatar Lifu Tang
Browse files

Broadcasting a message for mode changing

- Fix b/10974059

Change-Id: I219ea35e65a36af9f041a487dd8039bb5e2f048b
parent 1955bf1b
Loading
Loading
Loading
Loading
+6 −7
Original line number Diff line number Diff line
@@ -16,9 +16,6 @@

package com.android.settings.location;

import android.app.Activity;
import android.content.Intent;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.provider.Settings;

@@ -75,7 +72,11 @@ public class LocationMode extends LocationSettingsBase
    }

    private void updateRadioButtons(RadioButtonPreference activated) {
        if (activated == mHighAccuracy) {
        if (activated == null) {
            mHighAccuracy.setChecked(false);
            mBatterySaving.setChecked(false);
            mSensorsOnly.setChecked(false);
        } else if (activated == mHighAccuracy) {
            mHighAccuracy.setChecked(true);
            mBatterySaving.setChecked(false);
            mSensorsOnly.setChecked(false);
@@ -107,9 +108,7 @@ public class LocationMode extends LocationSettingsBase
    public void onModeChanged(int mode, boolean restricted) {
        switch (mode) {
            case Settings.Secure.LOCATION_MODE_OFF:
                Intent intent = new Intent();
                PreferenceActivity pa = (PreferenceActivity) getActivity();
                pa.finishPreferencePanel(LocationMode.this, Activity.RESULT_OK, intent);
                updateRadioButtons(null);
                break;
            case Settings.Secure.LOCATION_MODE_SENSORS_ONLY:
                updateRadioButtons(mSensorsOnly);
+12 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.settings.location;
import android.app.LoaderManager.LoaderCallbacks;
import android.content.Context;
import android.content.CursorLoader;
import android.content.Intent;
import android.content.Loader;
import android.database.Cursor;
import android.os.Bundle;
@@ -35,8 +36,14 @@ import com.android.settings.SettingsPreferenceFragment;
public abstract class LocationSettingsBase extends SettingsPreferenceFragment
        implements LoaderCallbacks<Cursor> {
    private static final String TAG = "LocationSettingsBase";
    /** Broadcast intent action when the location mode is about to change. */
    private static final String MODE_CHANGING_ACTION =
            "com.android.settings.location.MODE_CHANGING";
    private static final String CURRENT_MODE_KEY = "CURRENT_MODE";
    private static final String NEW_MODE_KEY = "NEW_MODE";

    private static final int LOADER_ID_LOCATION_MODE = 1;
    private int mCurrentMode;

    /**
     * Whether the fragment is actively running.
@@ -83,6 +90,10 @@ public abstract class LocationSettingsBase extends SettingsPreferenceFragment
            }
            return;
        }
        Intent intent = new Intent(MODE_CHANGING_ACTION);
        intent.putExtra(CURRENT_MODE_KEY, mCurrentMode);
        intent.putExtra(NEW_MODE_KEY, mode);
        getActivity().sendBroadcast(intent);
        Settings.Secure.putInt(getContentResolver(), Settings.Secure.LOCATION_MODE, mode);
        refreshLocationMode();
    }
@@ -91,6 +102,7 @@ public abstract class LocationSettingsBase extends SettingsPreferenceFragment
        if (mActive) {
            int mode = Settings.Secure.getInt(getContentResolver(), Settings.Secure.LOCATION_MODE,
                    Settings.Secure.LOCATION_MODE_OFF);
            mCurrentMode = mode;
            onModeChanged(mode, isRestricted());
        }
    }