use of android.content.CursorLoader in project iosched by google.
the class VideoLibraryModelTest method createCursorLoader_FilteredVideosQuery_Success.
@Test
public void createCursorLoader_FilteredVideosQuery_Success() {
// Given a mock cursor loader set up for a video query
when(mMockBundle.containsKey(VideoLibraryModel.KEY_TOPIC)).thenReturn(true);
when(mMockBundle.containsKey(VideoLibraryModel.KEY_YEAR)).thenReturn(true);
when(mMockBundle.getString(VideoLibraryModel.KEY_TOPIC)).thenReturn("Android");
when(mMockBundle.getInt(VideoLibraryModel.KEY_YEAR)).thenReturn(2012);
// When ran with the video query
CursorLoader createdCursorLoader = (CursorLoader) mSpyModel.createCursorLoader(VideoLibraryModel.VideoLibraryQueryEnum.VIDEOS, mMockBundle);
// Then the returned cursor loader is the same as the mock one
assertThat(createdCursorLoader, sameInstance(mMockCursorLoader));
}
use of android.content.CursorLoader in project iosched by google.
the class VideoLibraryModelTest method createCursorLoader_FiltersQuery_Success.
@Test
public void createCursorLoader_FiltersQuery_Success() {
// Given a mock cursor loader set up for a video query
// When ran with the video query
CursorLoader createdCursorLoader = (CursorLoader) mSpyModel.createCursorLoader(VideoLibraryModel.VideoLibraryQueryEnum.FILTERS, null);
// Then the returned cursor loader is the same as the mock one
assertThat(createdCursorLoader, sameInstance(mMockCursorLoader));
}
use of android.content.CursorLoader in project Conversations by siacs.
the class PhoneHelper method loadPhoneContacts.
public static void loadPhoneContacts(Context context, final OnPhoneContactsLoadedListener listener) {
final List<Bundle> phoneContacts = new ArrayList<>();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
listener.onPhoneContactsLoaded(phoneContacts);
return;
}
final String[] PROJECTION = new String[] { ContactsContract.Data._ID, ContactsContract.Data.DISPLAY_NAME, ContactsContract.Data.PHOTO_URI, ContactsContract.Data.LOOKUP_KEY, ContactsContract.CommonDataKinds.Im.DATA };
final String SELECTION = "(" + ContactsContract.Data.MIMETYPE + "=\"" + ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE + "\") AND (" + ContactsContract.CommonDataKinds.Im.PROTOCOL + "=\"" + ContactsContract.CommonDataKinds.Im.PROTOCOL_JABBER + "\")";
CursorLoader mCursorLoader = new NotThrowCursorLoader(context, ContactsContract.Data.CONTENT_URI, PROJECTION, SELECTION, null, null);
mCursorLoader.registerListener(0, new OnLoadCompleteListener<Cursor>() {
@Override
public void onLoadComplete(Loader<Cursor> arg0, Cursor cursor) {
if (cursor != null) {
while (cursor.moveToNext()) {
Bundle contact = new Bundle();
contact.putInt("phoneid", cursor.getInt(cursor.getColumnIndex(ContactsContract.Data._ID)));
contact.putString("displayname", cursor.getString(cursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME)));
contact.putString("photouri", cursor.getString(cursor.getColumnIndex(ContactsContract.Data.PHOTO_URI)));
contact.putString("lookup", cursor.getString(cursor.getColumnIndex(ContactsContract.Data.LOOKUP_KEY)));
contact.putString("jid", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA)));
phoneContacts.add(contact);
}
cursor.close();
}
if (listener != null) {
listener.onPhoneContactsLoaded(phoneContacts);
}
}
});
try {
mCursorLoader.startLoading();
} catch (RejectedExecutionException e) {
if (listener != null) {
listener.onPhoneContactsLoaded(phoneContacts);
}
}
}
use of android.content.CursorLoader in project Etar-Calendar by Etar-Group.
the class MonthByWeekFragment method onLoadFinished.
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
synchronized (mUpdateLoader) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Found " + data.getCount() + " cursor entries for uri " + mEventUri);
}
CursorLoader cLoader = (CursorLoader) loader;
if (mEventUri == null) {
mEventUri = cLoader.getUri();
updateLoadedDays();
}
if (cLoader.getUri().compareTo(mEventUri) != 0) {
// result
return;
}
ArrayList<Event> events = new ArrayList<Event>();
Event.buildEventsFromCursor(events, data, mContext, mFirstLoadedJulianDay, mLastLoadedJulianDay);
((MonthByWeekAdapter) mAdapter).setEvents(mFirstLoadedJulianDay, mLastLoadedJulianDay - mFirstLoadedJulianDay + 1, events);
}
}
use of android.content.CursorLoader in project Etar-Calendar by Etar-Group.
the class MonthByWeekFragment method onCreateLoader.
// TODO
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
if (mIsMiniMonth) {
return null;
}
CursorLoader loader;
synchronized (mUpdateLoader) {
mFirstLoadedJulianDay = Time.getJulianDay(mSelectedDay.toMillis(true), mSelectedDay.gmtoff) - (mNumWeeks * 7 / 2);
mEventUri = updateUri();
String where = updateWhere();
loader = new CursorLoader(getActivity(), mEventUri, Event.EVENT_PROJECTION, where, null, /* WHERE_CALENDARS_SELECTED_ARGS */
INSTANCES_SORT_ORDER);
loader.setUpdateThrottle(LOADER_THROTTLE_DELAY);
}
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Returning new loader with uri: " + mEventUri);
}
return loader;
}
Aggregations