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.awesome.byunghwa.app.mytvapplication.fragment.MainFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {

    switch (loader.getId()) {
    case MY_LOADER_ID_MOVIE_LIST_POPULARITY:
        LogUtil.log_i(TAG, "onLoadFinished pop entry gets called...");
        LogUtil.log_i(TAG, "cursor id: " + cursor.toString());
        LogUtil.log_i(TAG, "cursor row count pop entry: " + cursor.getCount());

        if (cursor.moveToFirst()) {
            LogUtil.log_i(TAG, "load pop rows gets called!");

            mCardPresenter = new CardPresenter();

            ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(mCardPresenter);

            for (int j = 0; j < cursor.getCount(); j++) {
                cursor.moveToPosition(j);
                mMovie = new Movie();
                mMovie.setTitle(cursor.getString(MoviesLoader.Query.ORIGINAL_TITLE));

                String urlNotComplete = cursor.getString(MoviesLoader.Query.POSTER_THUMBNAIL);
                String urlComplete = "http://image.tmdb.org/t/p/w185/" + urlNotComplete;

                mMovie.setCardImageUrl(urlComplete);
                mMovie.setDescription(cursor.getString(MoviesLoader.Query.OVERVIEW));
                mMovie.setBackgroundImageUrl(urlComplete);
                mMovie.setId(cursor.getLong(MoviesLoader.Query.MOVIE_ID));
                listRowAdapter.add(mMovie);
            }//from w w w  .  j  ava  2  s . c  om

            long headerId = 0;

            HeaderItem header = new HeaderItem(headerId, sortOrderArrayList[((int) headerId)]);
            mRowsAdapter.add(new ListRow(header, listRowAdapter));

            setAdapter(mRowsAdapter);
        }
        getLoaderManager().destroyLoader(loader.getId());
        break;
    case MY_LOADER_ID_MOVIE_LIST_VOTE_AVERAGE:
        LogUtil.log_i(TAG, "onLoadFinished top rated entry gets called...");
        LogUtil.log_i(TAG, "cursor id: " + cursor.toString());
        LogUtil.log_i(TAG, "cursor row count top rated entry: " + cursor.getCount());

        if (cursor.moveToFirst()) {
            LogUtil.log_i(TAG, "load top rated rows gets called!");

            mCardPresenter = new CardPresenter();

            ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(mCardPresenter);

            for (int j = 0; j < cursor.getCount(); j++) {
                cursor.moveToPosition(j);
                mMovie = new Movie();
                mMovie.setTitle(cursor.getString(MoviesLoader.Query.ORIGINAL_TITLE));

                String urlNotComplete = cursor.getString(MoviesLoader.Query.POSTER_THUMBNAIL);
                String urlComplete = "http://image.tmdb.org/t/p/w185/" + urlNotComplete;

                mMovie.setCardImageUrl(urlComplete);
                mMovie.setDescription(cursor.getString(MoviesLoader.Query.OVERVIEW));
                mMovie.setBackgroundImageUrl(urlComplete);
                mMovie.setId(cursor.getLong(MoviesLoader.Query.MOVIE_ID));
                listRowAdapter.add(mMovie);
            }

            long headerId = 1;

            HeaderItem header = new HeaderItem(headerId, sortOrderArrayList[((int) headerId)]);
            mRowsAdapter.add(new ListRow(header, listRowAdapter));

            setAdapter(mRowsAdapter);
        }
        getLoaderManager().destroyLoader(loader.getId());
        break;
    case MY_LOADER_ID_MOVIE_LIST_FAVORITES:
        LogUtil.log_i(TAG, "onLoadFinished favorites entry gets called...");
        LogUtil.log_i(TAG, "cursor id: " + cursor.toString());
        LogUtil.log_i(TAG, "cursor row count fav entry: " + cursor.getCount());

        if (cursor.moveToFirst()) {
            LogUtil.log_i(TAG, "load fav rated rows gets called!");

            mCardPresenter = new CardPresenter();

            ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(mCardPresenter);

            for (int j = 0; j < cursor.getCount(); j++) {
                cursor.moveToPosition(j);
                mMovie = new Movie();
                mMovie.setTitle(cursor.getString(MoviesLoader.Query.ORIGINAL_TITLE));

                String urlNotComplete = cursor.getString(MoviesLoader.Query.POSTER_THUMBNAIL);
                String urlComplete = "http://image.tmdb.org/t/p/w185/" + urlNotComplete;

                mMovie.setCardImageUrl(urlComplete);
                mMovie.setDescription(cursor.getString(MoviesLoader.Query.OVERVIEW));
                mMovie.setBackgroundImageUrl(urlComplete);
                mMovie.setId(cursor.getLong(MoviesLoader.Query.MOVIE_ID));
                listRowAdapter.add(mMovie);
            }

            long headerId = 2;

            HeaderItem header = new HeaderItem(headerId, sortOrderArrayList[((int) headerId)]);
            mRowsAdapter.add(new ListRow(header, listRowAdapter));

            setAdapter(mRowsAdapter);

        }
        getLoaderManager().destroyLoader(loader.getId());
        break;

    }
}

From source file:com.example.android.sampletvinput.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);
                }//from   w w  w .j  a  va  2 s . 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:it.polimi.spf.app.fragments.profile.ProfileFragment.java

@Override
public void onLoadFinished(Loader<ProfileFieldContainer> loader, ProfileFieldContainer data) {
    switch (loader.getId()) {
    case LOAD_PROFILE_LOADER_ID:
        mContainer = data;/*w ww.  ja va 2 s.  com*/
        onProfileDataAvailable();
        break;
    case SAVE_PROFILE_LOADER_ID:
        mContainer.clearModified();
        mModifiedAtLeastOnce = true;
        getActivity().finish();
        break;
    }
}

From source file:com.antew.redditinpictures.library.ui.base.BaseFragmentActivityWithMenu.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/*w w  w . java 2  s .c om*/
 *     The Loader that is being reset.
 */
@Override
public void onLoaderReset(Loader<Cursor> loader) {
    switch (loader.getId()) {
    case Constants.Loader.LOADER_SUBREDDITS:
        mSubredditAdapter.swapCursor(null);
        break;
    }
}

From source file:com.android.ex.photo.PhotoViewActivity.java

@Override
public void onLoadFinished(final Loader<Cursor> loader, final Cursor data) {
    final int id = loader.getId();
    if (id == LOADER_PHOTO_LIST) {
        if (data == null || data.getCount() == 0) {
            mIsEmpty = true;//from  w  ww.ja v a2 s  . c  om
        } else {
            mAlbumCount = data.getCount();

            // We're paused; don't do anything now, we'll get re-invoked
            // when the activity becomes active again
            // TODO(pwestbro): This shouldn't be necessary, as the loader manager should
            // restart the loader
            if (mIsPaused) {
                mRestartLoader = true;
                return;
            }
            mIsEmpty = false;

            // set the selected photo
            int itemIndex = mPhotoIndex;

            // Use an index of 0 if the index wasn't specified or couldn't be found
            if (itemIndex < 0) {
                itemIndex = 0;
            }

            mAdapter.swapCursor(data);
            notifyCursorListeners(data);

            mViewPager.setCurrentItem(itemIndex, false);
            setViewActivated();
        }
        // Update the any action items
        updateActionItems();
    }
}

From source file:com.antew.redditinpictures.library.ui.base.BaseFragmentActivityWithMenu.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/>/*w  ww .  j  a  v a 2 s . c  o m*/
 * <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_SUBREDDITS:
        mSubredditAdapter.swapCursor(data);
        break;
    }
}

From source file:com.aengbee.android.leanback.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);
                }/*from   www  .  j  a  v a2s  .com*/

                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.personal_settings));
            /*
            SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
            try {
            JSONObject serverJson = new JSONObject(sharedPreferences.getString("serverList", "NULL"));
            if(serverJson!=null && !serverJson.equals("{}")) {
                if( serverJson.getString(serverJson.names().getString(0)).contains("http://fytoz.asuscomm.com/android-tv/ky.json")||serverJson.getString(serverJson.names().getString(0)).contains("http://fytoz.asuscomm.com/android-tv/tj.json")) {
                    gridRowAdapter.add("Showcase");
                    gridRowAdapter.add(getString(R.string.grid_view));
                    gridRowAdapter.add(getString(R.string.guidedstep_first_title));
                    gridRowAdapter.add(getString(R.string.error_fragment));
                }
                    
            }
            } catch (JSONException ex) {
            ex.printStackTrace();
            }
                    
                    
            gridRowAdapter.add("Showcase");
            gridRowAdapter.add(getString(R.string.grid_view));
            gridRowAdapter.add(getString(R.string.guidedstep_first_title));
            gridRowAdapter.add(getString(R.string.error_fragment));
            */
            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 {
        if (isOnline()) {
            Intent serviceIntent = new Intent(getActivity(), FetchVideoService.class);
            //serviceIntent.putExtra("data_url", getResources().getString(R.string.catalog_url) );
            serviceIntent.putExtra("data_url", "http://fytoz.asuscomm.com/android-tv/tjweb.json");
            getActivity().startService(serviceIntent);
        } else {
            Intent serviceIntent = new Intent(getActivity(), FetchVideoService.class);
            //serviceIntent.putExtra("data_url", getResources().getString(R.string.catalog_url) );
            serviceIntent.putExtra("data_url", resourceToUri(getActivity(), R.raw.sample).toString());
            getActivity().startService(serviceIntent);
        }
    }
}

From source file:com.android.browser.BookmarksPageCallbacks.java

@Override
public void onLoaderReset(Loader<Cursor> loader) {
    if (loader.getId() >= LOADER_BOOKMARKS) {
        BrowserBookmarksAdapter adapter = mBookmarkAdapters.get(loader.getId());
        adapter.changeCursor(null);/* w w w . ja  va 2s  .co  m*/
    }
}

From source file:com.app.uafeed.fragment.EntryFragment.java

@Override
public void onLoaderReset(Loader<Cursor> loader) {
    mEntryPagerAdapter.setUpdatedCursor(loader.getId(), null);
}

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

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    switch (loader.getId()) {
    case Constants.Loader.LOADER_LOGIN:
        if (cursor != null) {
            if (cursor.moveToFirst()) {
                String username = cursor.getString(cursor.getColumnIndex(RedditContract.Login.USERNAME));
                String cookie = cursor.getString(cursor.getColumnIndex(RedditContract.Login.COOKIE));
                String modhash = cursor.getString(cursor.getColumnIndex(RedditContract.Login.MODHASH));

                LoginData data = new LoginData(username, modhash, cookie);
                if (!data.equals(RedditLoginInformation.getLoginData())) {
                    RedditLoginInformation.setLoginData(data);
                }//from  w  ww .j  a  va  2  s  .c  om

                invalidateOptionsMenu();
                new SubredditUtil.SetDefaultSubredditsTask(this).execute();
                forceRefreshCurrentSubreddit();
            }
        }
        break;
    default:
        super.onLoadFinished(loader, cursor);
        break;
    }
}