am 83df0123: am 40eefc17: am 1673fbc0: Broadcasting a message for mode changing

* commit '83df01235788b2a820d68b7c8a51f7a0fc5c1d64':
  Broadcasting a message for mode changing
This commit is contained in:
Lifu Tang
2013-10-08 12:01:45 -07:00
committed by Android Git Automerger
2 changed files with 18 additions and 7 deletions

View File

@@ -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);

View File

@@ -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());
}
}