Merge "Replaced ContentQueryMap with CursorLoader" into klp-dev
This commit is contained in:
@@ -16,60 +16,32 @@
|
|||||||
|
|
||||||
package com.android.settings.location;
|
package com.android.settings.location;
|
||||||
|
|
||||||
import android.content.ContentQueryMap;
|
import android.app.LoaderManager.LoaderCallbacks;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.CursorLoader;
|
||||||
|
import android.content.Loader;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
|
||||||
|
|
||||||
import java.util.Observable;
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
import java.util.Observer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A base class that listens to location settings change and modifies location
|
* A base class that listens to location settings change and modifies location
|
||||||
* settings.
|
* settings.
|
||||||
*/
|
*/
|
||||||
public abstract class LocationSettingsBase extends SettingsPreferenceFragment {
|
public abstract class LocationSettingsBase extends SettingsPreferenceFragment
|
||||||
|
implements LoaderCallbacks<Cursor> {
|
||||||
private static final String TAG = "LocationSettingsBase";
|
private static final String TAG = "LocationSettingsBase";
|
||||||
private ContentQueryMap mContentQueryMap;
|
|
||||||
private Observer mSettingsObserver;
|
private static final int LOADER_ID_LOCATION_MODE = 1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onCreate(Bundle icicle) {
|
||||||
super.onStart();
|
super.onCreate(icicle);
|
||||||
// listen for Location Manager settings changes
|
getLoaderManager().initLoader(LOADER_ID_LOCATION_MODE, null, this);
|
||||||
Cursor settingsCursor = getContentResolver().query(Settings.Secure.CONTENT_URI, null,
|
|
||||||
"(" + Settings.System.NAME + "=?)",
|
|
||||||
new String[] { Settings.Secure.LOCATION_PROVIDERS_ALLOWED },
|
|
||||||
null);
|
|
||||||
mContentQueryMap = new ContentQueryMap(settingsCursor, Settings.System.NAME, true, null);
|
|
||||||
mSettingsObserver = new Observer() {
|
|
||||||
@Override
|
|
||||||
public void update(Observable o, Object arg) {
|
|
||||||
refreshLocationMode();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
mContentQueryMap.addObserver(mSettingsObserver);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
mContentQueryMap.deleteObserver(mSettingsObserver);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStop() {
|
|
||||||
super.onStop();
|
|
||||||
mContentQueryMap.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Called when location mode has changed. */
|
/** Called when location mode has changed. */
|
||||||
@@ -101,4 +73,26 @@ public abstract class LocationSettingsBase extends SettingsPreferenceFragment {
|
|||||||
Settings.Secure.LOCATION_MODE_OFF);
|
Settings.Secure.LOCATION_MODE_OFF);
|
||||||
onModeChanged(mode, isRestricted());
|
onModeChanged(mode, isRestricted());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
||||||
|
switch (id) {
|
||||||
|
case LOADER_ID_LOCATION_MODE:
|
||||||
|
return new CursorLoader(getActivity(), Settings.Secure.CONTENT_URI, null,
|
||||||
|
"(" + Settings.System.NAME + "=?)",
|
||||||
|
new String[] { Settings.Secure.LOCATION_MODE }, null);
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
|
||||||
|
refreshLocationMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoaderReset(Loader<Cursor> loader) {
|
||||||
|
// Nothing to do here.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -322,7 +322,7 @@ class SettingsInjector {
|
|||||||
Log.wtf(TAG, "Unexpected what: " + msg);
|
Log.wtf(TAG, "Unexpected what: " + msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decide whether to load addiitonal settings based on the new state. Start by seeing
|
// Decide whether to load additional settings based on the new state. Start by seeing
|
||||||
// if we have headroom to load another setting.
|
// if we have headroom to load another setting.
|
||||||
if (mSettingsBeingLoaded.size() > 0 || mTimedOutSettings.size() > 1) {
|
if (mSettingsBeingLoaded.size() > 0 || mTimedOutSettings.size() > 1) {
|
||||||
// Don't load any more settings until one of the pending settings has completed.
|
// Don't load any more settings until one of the pending settings has completed.
|
||||||
|
Reference in New Issue
Block a user