Search in sources :

Example 26 with CursorLoader

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));
}
Also used : CursorLoader(android.content.CursorLoader) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test)

Example 27 with CursorLoader

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));
}
Also used : CursorLoader(android.content.CursorLoader) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test)

Example 28 with CursorLoader

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);
        }
    }
}
Also used : CursorLoader(android.content.CursorLoader) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 29 with CursorLoader

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);
    }
}
Also used : CursorLoader(android.content.CursorLoader) ArrayList(java.util.ArrayList) MotionEvent(android.view.MotionEvent) Event(com.android.calendar.Event)

Example 30 with CursorLoader

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;
}
Also used : CursorLoader(android.content.CursorLoader)

Aggregations

CursorLoader (android.content.CursorLoader)30 Cursor (android.database.Cursor)12 Uri (android.net.Uri)11 SmallTest (android.test.suitebuilder.annotation.SmallTest)9 Test (org.junit.Test)9 TagMetadataTest (com.google.samples.apps.iosched.model.TagMetadataTest)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Context (android.content.Context)4 ArrayList (java.util.ArrayList)4 Matchers.anyString (org.mockito.Matchers.anyString)4 SettingsMockContext (com.google.samples.apps.iosched.testutils.SettingsMockContext)3 SuppressLint (android.annotation.SuppressLint)1 Loader (android.content.Loader)1 Bundle (android.os.Bundle)1 MotionEvent (android.view.MotionEvent)1 View (android.view.View)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 GridView (android.widget.GridView)1 ImageView (android.widget.ImageView)1