Search in sources :

Example 26 with CursorLoader

use of android.support.v4.content.CursorLoader in project musicbrainz-android by jdamcd.

the class SuggestionHelper method getMatchingEntries.

private Cursor getMatchingEntries(String constraint) {
    if (constraint == null) {
        return null;
    }
    String where = COLUMN + " LIKE ?";
    String[] args = { constraint.trim() + "%" };
    CursorLoader cursorLoader = new CursorLoader(context, Uri.parse(URI), null, where, args, COLUMN + " ASC");
    Cursor cursor = cursorLoader.loadInBackground();
    if (cursor != null) {
        cursor.moveToFirst();
    }
    return cursor;
}
Also used : CursorLoader(android.support.v4.content.CursorLoader) Cursor(android.database.Cursor)

Example 27 with CursorLoader

use of android.support.v4.content.CursorLoader in project MultiImageChooser by derosa.

the class MultiImageChooserActivity method onCreateLoader.

@Override
public Loader<Cursor> onCreateLoader(int cursorID, Bundle arg1) {
    CursorLoader cl = null;
    ArrayList<String> img = new ArrayList<String>();
    switch(cursorID) {
        case CURSORLOADER_THUMBS:
            img.add(MediaStore.Images.Media._ID);
            break;
        case CURSORLOADER_REAL:
            img.add(MediaStore.Images.Thumbnails.DATA);
            break;
        default:
            break;
    }
    cl = new CursorLoader(MultiImageChooserActivity.this, MediaStore.Images.Media.EXTERNAL_CONTENT_URI, img.toArray(new String[img.size()]), null, null, null);
    return cl;
}
Also used : CursorLoader(android.support.v4.content.CursorLoader) ArrayList(java.util.ArrayList)

Example 28 with CursorLoader

use of android.support.v4.content.CursorLoader in project iosched by google.

the class StarredSessionDetailModelTest method createCursorLoader_SessionQuery_ReturnsCursorLoader.

@Test
public void createCursorLoader_SessionQuery_ReturnsCursorLoader() {
    // Given a mock uri and mock cursor loader
    SessionDetailModel spyModel = spy(new SessionDetailModel(mMockUri, mMockContext, mMockSessionsHelper, mMockLoaderManager));
    doReturn(FAKE_ID).when(spyModel).extractSessionId(mMockUri);
    doReturn(mMockCursorLoader).when(spyModel).getCursorLoaderInstance(any(Context.class), any(Uri.class), any(String[].class), any(String.class), any(String[].class), any(String.class));
    // When ran with mock uri and session query loader id
    CursorLoader createdCursorLoader = (CursorLoader) spyModel.createCursorLoader(SessionDetailModel.SessionDetailQueryEnum.SESSIONS, null);
    // Then the returned cursor loader is the mock cursor loader
    assertThat(createdCursorLoader, sameInstance(mMockCursorLoader));
}
Also used : Context(android.content.Context) SettingsMockContext(com.google.samples.apps.iosched.testutils.SettingsMockContext) CursorLoader(android.support.v4.content.CursorLoader) Matchers.anyString(org.mockito.Matchers.anyString) Uri(android.net.Uri) SmallTest(android.test.suitebuilder.annotation.SmallTest) TagMetadataTest(com.google.samples.apps.iosched.model.TagMetadataTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 29 with CursorLoader

use of android.support.v4.content.CursorLoader in project iosched by google.

the class StarredSessionDetailModelTest method createCursorLoader_NullQuery_ReturnsNullCursor.

@Test
public void createCursorLoader_NullQuery_ReturnsNullCursor() {
    // When ran with mock uri and null query loader id
    CursorLoader createdCursorLoader = (CursorLoader) mSessionDetailModel.createCursorLoader(null, null);
    // Then the returned cursor loader is null
    assertThat(createdCursorLoader, nullValue());
}
Also used : CursorLoader(android.support.v4.content.CursorLoader) SmallTest(android.test.suitebuilder.annotation.SmallTest) TagMetadataTest(com.google.samples.apps.iosched.model.TagMetadataTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 30 with CursorLoader

use of android.support.v4.content.CursorLoader in project iosched by google.

the class StarredSessionDetailModelTest method createCursorLoader_SpeakersQuery_ReturnsCursor.

@Test
public void createCursorLoader_SpeakersQuery_ReturnsCursor() {
    // Given a mock uri and mock cursor loader
    SessionDetailModel spyModel = spy(new SessionDetailModel(mMockUri, mMockContext, mMockSessionsHelper, mMockLoaderManager));
    doReturn(mMockUri).when(spyModel).getSpeakersDirUri(any(String.class));
    doReturn(mMockCursorLoader).when(spyModel).getCursorLoaderInstance(any(Context.class), any(Uri.class), any(String[].class), any(String.class), any(String[].class), any(String.class));
    // When ran with mock uri and speakers query loader id
    CursorLoader createdCursorLoader = (CursorLoader) spyModel.createCursorLoader(SessionDetailModel.SessionDetailQueryEnum.SPEAKERS, null);
    // Then the returned cursor loader is the mock cursor loader
    assertThat(createdCursorLoader, sameInstance(mMockCursorLoader));
}
Also used : Context(android.content.Context) SettingsMockContext(com.google.samples.apps.iosched.testutils.SettingsMockContext) CursorLoader(android.support.v4.content.CursorLoader) Matchers.anyString(org.mockito.Matchers.anyString) Uri(android.net.Uri) SmallTest(android.test.suitebuilder.annotation.SmallTest) TagMetadataTest(com.google.samples.apps.iosched.model.TagMetadataTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

CursorLoader (android.support.v4.content.CursorLoader)36 Uri (android.net.Uri)18 Cursor (android.database.Cursor)13 Test (org.junit.Test)8 SmallTest (android.test.suitebuilder.annotation.SmallTest)6 SpannableString (android.text.SpannableString)5 TagMetadataTest (com.google.samples.apps.iosched.model.TagMetadataTest)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Context (android.content.Context)4 Matchers.anyString (org.mockito.Matchers.anyString)4 SettingsMockContext (com.google.samples.apps.iosched.testutils.SettingsMockContext)3 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 ArrayList (java.util.ArrayList)2 SuppressLint (android.annotation.SuppressLint)1 SharedPreferences (android.content.SharedPreferences)1 Bundle (android.os.Bundle)1 Loader (android.support.v4.content.Loader)1 SimpleCursorAdapter (android.support.v4.widget.SimpleCursorAdapter)1 CloudEntry (com.amaze.filemanager.database.models.CloudEntry)1 CloudPluginException (com.amaze.filemanager.exceptions.CloudPluginException)1