Search in sources :

Example 31 with CursorLoader

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

the class StarredSessionDetailModelTest method createCursorLoader_FeedbackQuery_ReturnsCursor.

@Test
public void createCursorLoader_FeedbackQuery_ReturnsCursor() {
    // Given a mock uri and mock cursor loader
    SessionDetailModel spyModel = spy(new SessionDetailModel(mMockUri, mMockContext, mMockSessionsHelper, mMockLoaderManager));
    doReturn(mMockUri).when(spyModel).getFeedbackUri(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 feedback query loader id
    CursorLoader createdCursorLoader = (CursorLoader) spyModel.createCursorLoader(SessionDetailModel.SessionDetailQueryEnum.FEEDBACK, 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 32 with CursorLoader

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

the class StarredSessionDetailModelTest method createCursorLoader_TagMetadaQuery_ReturnsCursorLoader.

@Test
public void createCursorLoader_TagMetadaQuery_ReturnsCursorLoader() {
    // Given a mock uri and mock cursor loader
    SessionDetailModel spyModel = spy(new SessionDetailModel(mMockUri, mMockContext, mMockSessionsHelper, mMockLoaderManager));
    doReturn(mMockCursorLoader).when(spyModel).getTagMetadataLoader();
    // When ran with mock uri and tag metadata query loader id
    CursorLoader createdCursorLoader = (CursorLoader) spyModel.createCursorLoader(SessionDetailModel.SessionDetailQueryEnum.TAG_METADATA, null);
    // Then the returned cursor loader is the mock cursor loader
    assertThat(createdCursorLoader, sameInstance(mMockCursorLoader));
}
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 33 with CursorLoader

use of android.support.v4.content.CursorLoader in project android-ui-design-pattern by MathieuCalba.

the class FeedListFragment method onCreateLoader.

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle b) {
    final int realId = id - mFeedId * 100 - mCategoryId;
    if (realId == LOADER_ID_BASE_FEED_LIST) {
        if (b != null) {
            final int feedId = b.getInt(EXTRA_FEED_ID, -1);
            if (feedId != -1) {
                final int categoryId = b.getInt(EXTRA_CATEGORY_ID, -1);
                Uri uri = null;
                if (categoryId == -1) {
                    uri = YANAContract.ArticleTable.buildUriWithFeedId(feedId);
                } else {
                    uri = YANAContract.ArticleTable.buildUriWithFeedIdAndCategoryId(feedId, categoryId);
                }
                return new CursorLoader(getActivity(), uri, YANAContract.ArticleTable.PROJ_LIST.COLS, null, null, YANAContract.ArticleTable.DEFAULT_SORT);
            }
        }
    }
    return null;
}
Also used : CursorLoader(android.support.v4.content.CursorLoader) Uri(android.net.Uri)

Example 34 with CursorLoader

use of android.support.v4.content.CursorLoader in project chuck by jgilfelt.

the class TransactionListFragment method onCreateLoader.

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    CursorLoader loader = new CursorLoader(getContext());
    loader.setUri(ChuckContentProvider.TRANSACTION_URI);
    if (!TextUtils.isEmpty(currentFilter)) {
        if (TextUtils.isDigitsOnly(currentFilter)) {
            loader.setSelection("responseCode LIKE ?");
            loader.setSelectionArgs(new String[] { currentFilter + "%" });
        } else {
            loader.setSelection("path LIKE ?");
            loader.setSelectionArgs(new String[] { "%" + currentFilter + "%" });
        }
    }
    loader.setProjection(HttpTransaction.PARTIAL_PROJECTION);
    loader.setSortOrder("requestDate DESC");
    return loader;
}
Also used : CursorLoader(android.support.v4.content.CursorLoader)

Example 35 with CursorLoader

use of android.support.v4.content.CursorLoader in project AgentWebX5 by Justson.

the class AgentWebX5Utils method getRealPathBelowVersion.

private static String getRealPathBelowVersion(Context context, Uri uri) {
    String filePath = null;
    String[] projection = { MediaStore.Images.Media.DATA };
    CursorLoader loader = new CursorLoader(context, uri, projection, null, null, null);
    Cursor cursor = loader.loadInBackground();
    if (cursor != null) {
        cursor.moveToFirst();
        filePath = cursor.getString(cursor.getColumnIndex(projection[0]));
        cursor.close();
    }
    return filePath;
}
Also used : CursorLoader(android.support.v4.content.CursorLoader) SpannableString(android.text.SpannableString) Cursor(android.database.Cursor)

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