Example usage for android.content Loader getId

List of usage examples for android.content Loader getId

Introduction

In this page you can find the example usage for android.content Loader getId.

Prototype

public int getId() 

Source Link

Usage

From source file:com.jawnnypoo.geotune.activity.MainActivity.java

@Override
public void onLoadFinished(Loader<ArrayList<GeoTune>> loader, ArrayList<GeoTune> data) {
    switch (loader.getId()) {
    case LOADER_GEOTUNES:
        if (data != null && mGeoTuneAdapter != null) {
            Timber.d("onLoadFinished");
            mGeoTuneAdapter.setGeofences(data);
        }/*from  w w w .  ja v a  2s  .  co  m*/
        adapterDataChanged();
        break;
    }
}

From source file:com.teinproductions.tein.papyrosprogress.MainActivity.java

@Override
public void onLoadFinished(Loader<MilestoneLoader.Result> loader, MilestoneLoader.Result data) {
    if (loader.getId() == LOADER_ID) {
        srLayout.setRefreshing(false);/*from  w ww. jav a  2  s  . com*/
        switch (data.getError()) {
        case MilestoneLoader.Result.NO_ERROR:
            if (data.getData() != null)
                adapter.setMilestones(data.getData());
            if (data.getStrData() != null)
                IOUtils.saveFile(this, data.getStrData(), Constants.MILESTONES_CACHE_FILE);
            break;
        case MilestoneLoader.Result.SOCKET_TIMEOUT:
        case MilestoneLoader.Result.UNKNOWN_ERROR:
        case MilestoneLoader.Result.JSON_PARSE_ERROR:
            // TODO show special snackbar?
        case MilestoneLoader.Result.NO_INTERNET_CONNECTION:
            showSnackbar(getString(R.string.offline_snackbar));
            break;
        case MilestoneLoader.Result.ERROR_CODE:
            if (data.getErrorCode() == 403) {
                showSnackbar(getString(R.string.error403));
            } else {
                showSnackbar(getString(R.string.error404, data.getErrorCode()));
            }
            break;
        }
    }
}

From source file:com.zhaojian.jolly.fragment.UserPhotosFragment.java

public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    switch (loader.getId()) {
    case LOADER_USER_PHOTOS_EXTERNAL:
        mPhotoAdapter.swapCursor(data);//from  ww w  .j  a va 2s  .c o m
        mPhotoGrid.setSelection(0);
        break;
    }
}

From source file:de.msal.shoutemo.fragments.ChatFragment.java

@Override
public void onLoadFinished(Loader<Cursor> objectLoader, Cursor data) {
    switch (objectLoader.getId()) {
    case LOADER_ID_MESSAGES:
        boolean wasAtBottom = mLayoutManager
                .findLastCompletelyVisibleItemPosition() == mListAdapter.getItemCount() - 1;

        data.moveToFirst();//w  ww.j  av  a  2  s  .  com
        List<Post> posts = new ArrayList<>(data.getCount());
        while (data.moveToNext()) {
            Post post = Post.fromCursor(data);
            posts.add(post);
        }
        // don't close cursor, as it won't fire CursorLoader any more!
        if (mListAdapter.swap(posts) && wasAtBottom) {
            mLayoutManager.scrollToPosition(mListAdapter.getItemCount() - 1);
        }
        break;
    }
}

From source file:com.aengbee.android.leanback.ui.MainFragment.java

@Override
public void onLoaderReset(Loader<Cursor> loader) {
    int loaderId = loader.getId();
    if (loaderId != CATEGORY_LOADER) {
        mVideoCursorAdapters.get(loaderId).changeCursor(null);
    } else {/*from  w  w w.  jav a  2  s  .  c  o  m*/
        mCategoryRowAdapter.clear();
    }
}

From source file:com.antew.redditinpictures.library.ui.RedditImageAdapterViewFragment.java

/**
 * Called when a previously created loader is being reset, and thus
 * making its data unavailable.  The application should at this point
 * remove any references it has to the Loader's data.
 *
 * @param loader/*ww w.  j a va2  s  . c o  m*/
 *     The Loader that is being reset.
 */
@Override
public void onLoaderReset(Loader<Cursor> loader) {
    switch (loader.getId()) {
    case Constants.Loader.LOADER_REDDIT:
        break;
    case Constants.Loader.LOADER_POSTS:
        produceRequestCompletedEvent();
        mAdapter.swapCursor(null);
        break;
    default:
        break;
    }
}

From source file:com.antew.redditinpictures.library.ui.RedditImageAdapterViewFragment.java

/**
 * Called when a previously created loader has finished its load.  Note
 * that normally an application is <em>not</em> allowed to commit fragment
 * transactions while in this call, since it can happen after an
 * activity's state is saved.  See {@link android.support.v4.app.FragmentManager#beginTransaction()
 * FragmentManager.openTransaction()} for further discussion on this.
 * <p/>//from  w w  w  .  j av a  2s . c om
 * <p>This function is guaranteed to be called prior to the release of
 * the last data that was supplied for this Loader.  At this point
 * you should remove all use of the old data (since it will be released
 * soon), but should not do your own release of the data since its Loader
 * owns it and will take care of that.  The Loader will take care of
 * management of its data so you don't have to.  In particular:
 * <p/>
 * <ul>
 * <li> <p>The Loader will monitor for changes to the data, and report
 * them to you through new calls here.  You should not monitor the
 * data yourself.  For example, if the data is a {@link android.database.Cursor}
 * and you place it in a {@link android.widget.CursorAdapter}, use
 * the {@link android.widget.CursorAdapter#CursorAdapter(android.content.Context,
 * android.database.Cursor, int)} constructor <em>without</em> passing
 * in either {@link android.widget.CursorAdapter#FLAG_AUTO_REQUERY}
 * or {@link android.widget.CursorAdapter#FLAG_REGISTER_CONTENT_OBSERVER}
 * (that is, use 0 for the flags argument).  This prevents the CursorAdapter
 * from doing its own observing of the Cursor, which is not needed since
 * when a change happens you will get a new Cursor throw another call
 * here.
 * <li> The Loader will release the data once it knows the application
 * is no longer using it.  For example, if the data is
 * a {@link android.database.Cursor} from a {@link android.content.CursorLoader},
 * you should not call close() on it yourself.  If the Cursor is being placed in a
 * {@link android.widget.CursorAdapter}, you should use the
 * {@link android.widget.CursorAdapter#swapCursor(android.database.Cursor)}
 * method so that the old Cursor is not closed.
 * </ul>
 *
 * @param loader
 *     The Loader that has finished.
 * @param data
 *     The data generated by the Loader.
 */
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    switch (loader.getId()) {
    case Constants.Loader.LOADER_REDDIT:
        if (data != null && data.moveToFirst()) {
            mAfter = data.getString(data.getColumnIndex(RedditContract.RedditData.AFTER));
        }
        break;
    case Constants.Loader.LOADER_POSTS:
        mAdapter.swapCursor(data);

        if (data.getCount() == 0 && !mRequestInProgress) {
            mNoImages.setVisibility(View.VISIBLE);
            mProgress.setVisibility(View.GONE);
        } else if (data.getCount() == 0 && mRequestInProgress) {
            mProgress.setVisibility(View.VISIBLE);
        } else {
            if (mNoImages.getVisibility() == View.VISIBLE) {
                mNoImages.setVisibility(View.GONE);
            }
            mProgress.setVisibility(View.GONE);
            produceRequestCompletedEvent();
            onPostsLoaded();
        }
        break;
    default:
        break;
    }
}

From source file:com.google.samples.apps.iosched.explore.ExploreSessionsActivity.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    switch (loader.getId()) {
    case TAG_METADATA_TOKEN:
        mTagMetadata = new TagMetadata(cursor);
        onTagMetadataLoaded();//from ww w.  j a va  2 s . c om
        break;
    default:
        cursor.close();
    }
}

From source file:com.example.android.tvleanback.ui.MainFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    if (data != null && data.moveToFirst()) {
        final int loaderId = loader.getId();

        if (loaderId == CATEGORY_LOADER) {

            // Every time we have to re-get the category loader, we must re-create the sidebar.
            mCategoryRowAdapter.clear();

            // Iterate through each category entry and add it to the ArrayAdapter.
            while (!data.isAfterLast()) {

                int categoryIndex = data.getColumnIndex(VideoContract.VideoEntry.COLUMN_CATEGORY);
                String category = data.getString(categoryIndex);

                // Create header for this category.
                HeaderItem header = new HeaderItem(category);

                int videoLoaderId = category.hashCode(); // Create unique int from category.
                CursorObjectAdapter existingAdapter = mVideoCursorAdapters.get(videoLoaderId);
                if (existingAdapter == null) {

                    // Map video results from the database to Video objects.
                    CursorObjectAdapter videoCursorAdapter = new CursorObjectAdapter(new CardPresenter());
                    videoCursorAdapter.setMapper(new VideoCursorMapper());
                    mVideoCursorAdapters.put(videoLoaderId, videoCursorAdapter);

                    ListRow row = new ListRow(header, videoCursorAdapter);
                    mCategoryRowAdapter.add(row);

                    // Start loading the videos from the database for a particular category.
                    Bundle args = new Bundle();
                    args.putString(VideoContract.VideoEntry.COLUMN_CATEGORY, category);
                    getLoaderManager().initLoader(videoLoaderId, args, this);
                } else {
                    ListRow row = new ListRow(header, existingAdapter);
                    mCategoryRowAdapter.add(row);
                }// w w w. j  a v a 2s .  c o m

                data.moveToNext();
            }

            // Create a row for this special case with more samples.
            HeaderItem gridHeader = new HeaderItem(getString(R.string.more_samples));
            GridItemPresenter gridPresenter = new GridItemPresenter(this);
            ArrayObjectAdapter gridRowAdapter = new ArrayObjectAdapter(gridPresenter);
            gridRowAdapter.add(getString(R.string.grid_view));
            gridRowAdapter.add(getString(R.string.guidedstep_first_title));
            gridRowAdapter.add(getString(R.string.error_fragment));
            gridRowAdapter.add(getString(R.string.personal_settings));
            ListRow row = new ListRow(gridHeader, gridRowAdapter);
            mCategoryRowAdapter.add(row);

            startEntranceTransition(); // TODO: Move startEntranceTransition to after all
            // cursors have loaded.
        } else {
            // The CursorAdapter contains a Cursor pointing to all videos.
            mVideoCursorAdapters.get(loaderId).changeCursor(data);
        }
    } else {
        // Start an Intent to fetch the videos.
        Intent serviceIntent = new Intent(getActivity(), FetchVideoService.class);
        getActivity().startService(serviceIntent);
    }
}

From source file:com.google.samples.apps.iosched.map.MapInfoFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    if (getActivity() == null) {
        return;// w w w .j a v a2  s .co  m
    }
    switch (loader.getId()) {
    case QUERY_TOKEN_SESSION_ROOM: {
        SessionLoader sessionLoader = (SessionLoader) loader;
        showSessionList(sessionLoader.getRoomTitle(), sessionLoader.getRoomType(), cursor);
        break;
    }
    case QUERY_TOKEN_SUBTITLE: {
        SessionLoader sessionLoader = (SessionLoader) loader;
        showSessionSubtitle(sessionLoader.getRoomTitle(), sessionLoader.getRoomType(), cursor);
    }
    }
}