Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/data/CustomAsyncQueryHandler.java
- This file was added.
package it.reyboz.bustorino.data; | |||||
import android.content.AsyncQueryHandler; | |||||
import android.content.ContentResolver; | |||||
import android.database.Cursor; | |||||
import java.lang.ref.WeakReference; | |||||
public class CustomAsyncQueryHandler extends AsyncQueryHandler { | |||||
private WeakReference<AsyncQueryListener> mListener; | |||||
public interface AsyncQueryListener { | |||||
void onQueryComplete(int token, Object cookie, Cursor cursor); | |||||
} | |||||
public CustomAsyncQueryHandler(ContentResolver cr, AsyncQueryListener listener) { | |||||
super(cr); | |||||
mListener = new WeakReference<AsyncQueryListener>(listener); | |||||
} | |||||
public CustomAsyncQueryHandler(ContentResolver cr) { | |||||
super(cr); | |||||
} | |||||
/** | |||||
* Assign the given {@link AsyncQueryListener} to receive query events from | |||||
* asynchronous calls. Will replace any existing listener. | |||||
*/ | |||||
public void setQueryListener(AsyncQueryListener listener) { | |||||
mListener = new WeakReference<AsyncQueryListener>(listener); | |||||
} | |||||
/** {@inheritDoc} */ | |||||
@Override | |||||
protected void onQueryComplete(int token, Object cookie, Cursor cursor) { | |||||
final AsyncQueryListener listener = mListener.get(); | |||||
if (listener != null) { | |||||
listener.onQueryComplete(token, cookie, cursor); | |||||
} else if (cursor != null) { | |||||
cursor.close(); | |||||
} | |||||
} | |||||
} |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register