Search in sources :

Example 6 with CursorLoader

use of android.support.v4.content.CursorLoader in project Camera-Roll-Android-App by kollerlukas.

the class MediaStoreRetriever method loadAlbums.

@Override
void loadAlbums(final Activity context, boolean hiddenFolders) {
    final long startTime = System.currentTimeMillis();
    final ArrayList<Album> albums = new ArrayList<>();
    // Return only video and image metadata.
    String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "=" + MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE + " OR " + MediaStore.Files.FileColumns.MEDIA_TYPE + "=" + MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO;
    Uri queryUri = MediaStore.Files.getContentUri("external");
    CursorLoader cursorLoader = new CursorLoader(context, queryUri, projection, selection, // Selection args (none).
    null, MediaStore.Files.FileColumns.DATE_ADDED);
    final Cursor cursor = cursorLoader.loadInBackground();
    if (cursor == null) {
        return;
    }
    // search hiddenFolders
    if (hiddenFolders) {
        ArrayList<Album> hiddenAlbums = checkHiddenFolders(context);
        albums.addAll(hiddenAlbums);
    }
    AsyncTask.execute(new Runnable() {

        @Override
        public void run() {
            if (cursor.moveToFirst()) {
                String path;
                long dateTaken, id;
                int pathColumn = cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA);
                int idColumn = cursor.getColumnIndex(BaseColumns._ID);
                do {
                    path = cursor.getString(pathColumn);
                    AlbumItem albumItem = AlbumItem.getInstance(context, path);
                    if (albumItem != null) {
                        // set dateTaken
                        int dateTakenColumn = cursor.getColumnIndex(!(albumItem instanceof Video) ? MediaStore.Images.ImageColumns.DATE_TAKEN : MediaStore.Video.VideoColumns.DATE_TAKEN);
                        dateTaken = cursor.getLong(dateTakenColumn);
                        albumItem.setDate(dateTaken);
                        id = cursor.getLong(idColumn);
                        Uri uri = ContentUris.withAppendedId(MediaStore.Files.getContentUri("external"), id);
                        albumItem.setUri(uri);
                        // search bucket
                        boolean foundBucket = false;
                        for (int i = 0; i < albums.size(); i++) {
                            if (albums.get(i).getPath().equals(FileOperation.Util.getParentPath(path))) {
                                albums.get(i).getAlbumItems().add(0, albumItem);
                                foundBucket = true;
                                break;
                            }
                        }
                        if (!foundBucket) {
                            // no bucket found
                            String bucketPath = FileOperation.Util.getParentPath(path);
                            if (bucketPath != null) {
                                albums.add(new Album().setPath(bucketPath));
                                albums.get(albums.size() - 1).getAlbumItems().add(0, albumItem);
                            }
                        }
                    }
                } while (cursor.moveToNext());
            }
            cursor.close();
            // done loading media with content resolver
            MediaProvider.OnMediaLoadedCallback callback = getCallback();
            if (callback != null) {
                callback.onMediaLoaded(albums);
            }
            Log.d("MediaStoreRetriever", "onMediaLoaded(): " + String.valueOf(System.currentTimeMillis() - startTime) + " ms");
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Album(us.koller.cameraroll.data.models.Album) AlbumItem(us.koller.cameraroll.data.models.AlbumItem) Cursor(android.database.Cursor) Uri(android.net.Uri) CursorLoader(android.support.v4.content.CursorLoader) Video(us.koller.cameraroll.data.models.Video)

Example 7 with CursorLoader

use of android.support.v4.content.CursorLoader in project keepass2android by PhilippC.

the class FragmentFiles method onCreateLoader.

// onDestroy()
/*
     * LOADERMANAGER.LOADERCALLBACKS
     */
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    mLoading = true;
    mNewLoader = true;
    mViewGroupFiles.setVisibility(View.GONE);
    mViewLoadingHandler.postDelayed(new Runnable() {

        @Override
        public void run() {
            mViewLoading.setVisibility(View.VISIBLE);
        }
    }, DisplayPrefs.DELAY_TIME_FOR_SHORT_ANIMATION);
    getActivity().supportInvalidateOptionsMenu();
    final Uri path = ((Uri) args.getParcelable(PATH));
    buildAddressBar(path);
    String positiveRegex = getArguments().getString(FileChooserActivity.EXTRA_POSITIVE_REGEX_FILTER);
    String negativeRegex = getArguments().getString(FileChooserActivity.EXTRA_NEGATIVE_REGEX_FILTER);
    if (BuildConfig.DEBUG)
        Log.d(CLASSNAME, "onCreateLoader() >> path = " + path);
    return new CursorLoader(getActivity(), BaseFile.genContentUriBase(path.getAuthority()).buildUpon().appendPath(path.getLastPathSegment()).appendQueryParameter(BaseFile.PARAM_TASK_ID, Integer.toString(mIdLoaderData)).appendQueryParameter(BaseFile.PARAM_SHOW_HIDDEN_FILES, Boolean.toString(getArguments().getBoolean(FileChooserActivity.EXTRA_DISPLAY_HIDDEN_FILES))).appendQueryParameter(BaseFile.PARAM_FILTER_MODE, Integer.toString(mFilterMode)).appendQueryParameter(BaseFile.PARAM_SORT_BY, Integer.toString(DisplayPrefs.getSortType(getActivity()))).appendQueryParameter(BaseFile.PARAM_SORT_ASCENDING, Boolean.toString(DisplayPrefs.isSortAscending(getActivity()))).appendQueryParameter(BaseFile.PARAM_LIMIT, Integer.toString(mMaxFileCount)).appendQueryParameter(BaseFile.PARAM_POSITIVE_REGEX_FILTER, TextUtils.isEmpty(positiveRegex) ? "" : positiveRegex).appendQueryParameter(BaseFile.PARAM_NEGATIVE_REGEX_FILTER, TextUtils.isEmpty(negativeRegex) ? "" : negativeRegex).build(), null, null, null, null);
}
Also used : CursorLoader(android.support.v4.content.CursorLoader) Uri(android.net.Uri)

Example 8 with CursorLoader

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

the class SessionDetailModel method createCursorLoader.

@Override
public Loader<Cursor> createCursorLoader(SessionDetailQueryEnum query, Bundle args) {
    CursorLoader loader = null;
    if (query == null) {
        return loader;
    }
    switch(query) {
        case SESSIONS:
            loader = getCursorLoaderInstance(mContext, mSessionUri, SessionDetailQueryEnum.SESSIONS.getProjection(), null, null, null);
            break;
        case SPEAKERS:
            Uri speakersUri = getSpeakersDirUri(mSessionId);
            loader = getCursorLoaderInstance(mContext, speakersUri, SessionDetailQueryEnum.SPEAKERS.getProjection(), null, null, ScheduleContract.Speakers.DEFAULT_SORT);
            break;
        case FEEDBACK:
            Uri feedbackUri = getFeedbackUri(mSessionId);
            loader = getCursorLoaderInstance(mContext, feedbackUri, SessionDetailQueryEnum.FEEDBACK.getProjection(), null, null, null);
            break;
        case TAG_METADATA:
            loader = getTagMetadataLoader();
            break;
        case MY_VIEWED_VIDEOS:
            Uri myPlayedVideoUri = ScheduleContract.MyViewedVideos.buildMyViewedVideosUri(AccountUtils.getActiveAccountName(mContext));
            loader = getCursorLoaderInstance(mContext, myPlayedVideoUri, SessionDetailQueryEnum.MY_VIEWED_VIDEOS.getProjection(), null, null, null);
            break;
        case RELATED:
            Uri relatedSessionsUri = Sessions.buildRelatedSessionsDirUri(mSessionId);
            loader = getCursorLoaderInstance(mContext, relatedSessionsUri, SessionDetailQueryEnum.RELATED.getProjection(), null, null, null);
            break;
    }
    return loader;
}
Also used : CursorLoader(android.support.v4.content.CursorLoader) Uri(android.net.Uri)

Example 9 with CursorLoader

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

the class StarredSessionFeedbackModelTest method createCursorLoader_SessionQuery_Success.

@Test
public void createCursorLoader_SessionQuery_Success() {
    // Given a mock cursor loader set up for a session query
    CursorLoader mockCursorLoaderSession = mock(CursorLoader.class);
    SessionFeedbackModel spyModel = spy(new SessionFeedbackModel(mMockLoaderManager, mMockUri, mMockContext, mMockFeedbackHelper));
    doReturn(mockCursorLoaderSession).when(spyModel).getCursorLoaderInstance(any(Context.class), any(Uri.class), any(String[].class), any(String.class), any(String[].class), any(String.class));
    // When ran with the session query
    CursorLoader createdCursorLoader1 = (CursorLoader) spyModel.createCursorLoader(SessionFeedbackModel.SessionFeedbackQueryEnum.SESSION, null);
    // Then the returned cursor loader is the same as the mock one
    assertThat(createdCursorLoader1, sameInstance(mockCursorLoaderSession));
}
Also used : CursorLoader(android.support.v4.content.CursorLoader) Context(android.content.Context) Matchers.anyString(org.mockito.Matchers.anyString) Uri(android.net.Uri) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test)

Example 10 with CursorLoader

use of android.support.v4.content.CursorLoader in project Zom-Android by zom.

the class AccountsFragment method initProviderCursor.

private void initProviderCursor() {
    final Uri uri = Imps.Provider.CONTENT_URI_WITH_ACCOUNT;
    mAdapter = new AccountAdapter(mActivity, new ProviderListItemFactory(), mAccountLayoutView);
    setListAdapter(mAdapter);
    mActivity.getSupportLoaderManager().initLoader(ACCOUNT_LOADER_ID, null, new LoaderCallbacks<Cursor>() {

        @Override
        public Loader<Cursor> onCreateLoader(int id, Bundle args) {
            CursorLoader loader = new CursorLoader(mActivity, uri, PROVIDER_PROJECTION, Imps.Provider.CATEGORY + "=?" + " AND " + Imps.Provider.ACTIVE_ACCOUNT_USERNAME + " NOT NULL", /* selection */
            new String[] { ImApp.IMPS_CATEGORY }, /* selection args */
            Imps.Provider.DEFAULT_SORT_ORDER);
            loader.setUpdateThrottle(100l);
            return loader;
        }

        @Override
        public void onLoadFinished(Loader<Cursor> loader, Cursor newCursor) {
            mAdapter.swapCursor(newCursor);
        }

        @Override
        public void onLoaderReset(Loader<Cursor> loader) {
            mAdapter.swapCursor(null);
        }
    });
}
Also used : CursorLoader(android.support.v4.content.CursorLoader) Bundle(android.os.Bundle) Loader(android.support.v4.content.Loader) CursorLoader(android.support.v4.content.CursorLoader) Cursor(android.database.Cursor) Uri(android.net.Uri)

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