Example usage for android.support.v4.content CursorLoader CursorLoader

List of usage examples for android.support.v4.content CursorLoader CursorLoader

Introduction

In this page you can find the example usage for android.support.v4.content CursorLoader CursorLoader.

Prototype

public CursorLoader(Context context, Uri uri, String[] projection, String selection, String[] selectionArgs,
        String sortOrder) 

Source Link

Document

Creates a fully-specified CursorLoader.

Usage

From source file:com.beesham.popularmovies.DiscoveryFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    String[] projection = { MoviesEntry._ID, MoviesEntry.COLUMN_MOVIE_TITLE, MoviesEntry.COLUMN_MOVIE_SYNOPSIS,
            MoviesEntry.COLUMN_MOVIE_POSTER, MoviesEntry.COLUMN_MOVIE_RELEASE_DATE,
            MoviesEntry.COLUMN_MOVIE_USER_RATING };

    CursorLoader loader = null;//from  w  ww . ja  va 2s  .  c  o m
    switch (id) {
    case 1:
        Log.v(LOG_TAG, "Loading from movies");
        loader = new CursorLoader(getActivity(), MoviesEntry.CONTENT_URI, projection, null, null, null);
        break;

    case 2:
        Log.v(LOG_TAG, "Loading from movies favorite");
        loader = new CursorLoader(getActivity(), MoviesFavoriteEntry.CONTENT_URI, projection, null, null, null);
        break;
    }
    return loader;
}

From source file:com.example.android.smssample.MainActivity.java

@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
    if (i == SmsQuery.TOKEN) {
        // This will fetch all SMS messages in the inbox, ordered by date desc
        return new CursorLoader(this, SmsQuery.CONTENT_URI, SmsQuery.PROJECTION, null, null,
                SmsQuery.SORT_ORDER);//from  w  w w  .ja va  2 s .c o  m
    }
    return null;
}

From source file:com.election.US.basicsyncadapter.EntryListFragment.java

/**
 * Query the content provider for data.//from   w  w  w  . j av  a2 s .c  o  m
 *
 * <p>Loaders do queries in a background thread. They also provide a ContentObserver that is
 * triggered when data in the content provider changes. When the sync adapter updates the
 * content provider, the ContentObserver responds by resetting the loader and then reloading
 * it.
 */
@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
    // We only have one loader, so we can ignore the value of i.
    // (It'll be '0', as set in onCreate().)
    return new CursorLoader(getActivity(), // Context
            FeedContract.Entry.CONTENT_URI, // URI
            PROJECTION, // Projection
            null, // Selection
            null, // Selection args
            FeedContract.Entry.COLUMN_NAME_PUBLISHED + " desc"); // Sort
}

From source file:com.abcvoipsip.ui.messages.ConversationsListFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    return new CursorLoader(getActivity(), SipMessage.THREAD_URI, null, null, null, null);
}

From source file:com.game.simple.Game3.java

public String getRealPathFromURI(Uri contentUri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    CursorLoader loader = new CursorLoader(self, contentUri, proj, null, null, null);
    Cursor cursor = loader.loadInBackground();
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();//from   w w w . ja  v  a2s . c om
    return cursor.getString(column_index);
}

From source file:com.example.tony.popularmovie.MainActivityFragment.java

@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
    SharedPreferences settings = getActivity().getSharedPreferences(PREFS_NAME, 0);
    String sortBy = settings.getString(PREFS_NAME, "popularity.desc");

    Loader loader = null;/*ww w  .j av a2  s.co m*/
    switch (sortBy) {
    case "popularity.desc":
        loader = new CursorLoader(getActivity(), MovieContract.PopularEntry.CONTENT_URI, POP_COLUMNS, null,
                null, null);
        break;
    case "vote_average.desc":
        loader = new CursorLoader(getActivity(), MovieContract.RatingEntry.CONTENT_URI, RATING_COLUMNS, null,
                null, null);
        break;
    case "Favorite":
        loader = new CursorLoader(getActivity(), MovieContract.FavoriteEntry.CONTENT_URI, FAVORITE_COLUMNS,
                null, null, null);
        break;
    default:
        break;
    }
    return loader;
}

From source file:com.fbartnitzek.tasteemall.mainpager.ReviewPagerFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    //        Log.v(LOG_TAG, "onCreateLoader, hashCode=" + this.hashCode() + ", " + "id = [" + id + "], args = [" + args + "]");
    switch (id) {
    case REVIEW_LOADER_ID:
        if (this.jsonUri == null) { // explicitly nulled by activity before (and set searchpattern)
            Log.v(LOG_TAG, "onCreateLoader before jsonCreation, hashCode=" + this.hashCode() + ", " + "id = ["
                    + id + "], args = [" + args + "]");

            String pattern = ((MainActivity) getActivity()).getSearchPattern();
            String drinkType = Utils.getDrinkTypeFromSharedPrefs(getActivity(), true);
            try {
                // private static final String REVIEWS_DRINKS_OR_PRODUCERS_BY_NAME_AND_TYPE_SELECTION =
                //                        "(" + DA + "." + Drink.NAME + " LIKE ? OR " + PA + "." + Producer.NAME + " LIKE ?)" +
                //                                " AND " + DA + "." + Drink.TYPE + " = ?";
                String encodedValue = DatabaseContract.encodeValue(pattern);
                if (jsonTextFilter == null) {
                    jsonTextFilter = new JSONObject().put(Review.ENTITY,
                            new JSONObject().put(DatabaseContract.OR,
                                    new JSONObject().put(Review.ENTITY, new JSONObject().put(Drink.ENTITY,
                                            new JSONObject().put(Drink.NAME, new JSONObject()).put(
                                                    Producer.ENTITY,
                                                    new JSONObject().put(Producer.NAME, new JSONObject()))))));
                }/* w  ww  .ja  v  a  2  s. com*/
                JSONObject drink = jsonTextFilter.getJSONObject(Review.ENTITY)
                        .getJSONObject(DatabaseContract.OR).getJSONObject(Review.ENTITY)
                        .getJSONObject(Drink.ENTITY);
                drink.getJSONObject(Drink.NAME).put(DatabaseContract.Operations.CONTAINS, encodedValue);
                drink.getJSONObject(Producer.ENTITY).getJSONObject(Producer.NAME)
                        .put(DatabaseContract.Operations.CONTAINS, encodedValue);
                jsonTextFilter.getJSONObject(Review.ENTITY).getJSONObject(DatabaseContract.OR)
                        .getJSONObject(Review.ENTITY).put(Drink.ENTITY, drink);

                if (Drink.TYPE_ALL.equals(drinkType)) {
                    jsonTextFilter.getJSONObject(Review.ENTITY).remove(Drink.ENTITY);
                } else {
                    jsonTextFilter.getJSONObject(Review.ENTITY).put(Drink.ENTITY,
                            new JSONObject().put(Drink.TYPE, new JSONObject().put(
                                    DatabaseContract.Operations.IS, DatabaseContract.encodeValue(drinkType))));
                }

                jsonUri = DatabaseContract.buildUriWithJson(jsonTextFilter);
                Log.v(LOG_TAG, "onCreateLoader after jsonCreation, hashCode=" + this.hashCode() + ", "
                        + "id = [" + id + "], args = [" + args + "]");

            } catch (JSONException | UnsupportedEncodingException e) {
                e.printStackTrace();
                Log.e(LOG_TAG, "onCreateLoader building jsonUri failed, hashCode=" + this.hashCode() + ", "
                        + "pattern= [" + pattern + "], drinkType= [" + drinkType + "]");
                throw new RuntimeException("building jsonUri failed");
            }
        }

        return new CursorLoader(getActivity(), jsonUri, QueryColumns.MainFragment.ReviewAllQuery.COLUMNS, null,
                null, DatabaseContract.ReviewEntry.ALIAS + "." + Review.READABLE_DATE + " DESC");
    default:
        throw new RuntimeException("wrong loader_id in ReviewPagerFragment...");
    }
}

From source file:com.mysmallcornerstudios.tempus.ui.MainActivity.java

@Override
public Loader<Cursor> onCreateLoader(int loaderId, Bundle bundle) {

    CursorLoader cursorLoader = null;//from   w  w w  .j av a2 s. c  o m

    switch (loaderId) {
    case TIMER_LOADER:
        cursorLoader = new CursorLoader(this, TimerProvider.CONTENT_URI, TimerSQLiteHelper.COLUMNS, null, null,
                null);
        break;
    }

    return cursorLoader;
}

From source file:com.earthblood.tictactoe.activity.GameActivity.java

/**
 * LoaderManager Callbacks/* w ww .j  av  a2s . c  o m*/
 */
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    String[] projection = { GameDatabaseHelper.COLUMN_ID, GameDatabaseHelper.COLUMN_GAME_BOX_ID,
            GameDatabaseHelper.COLUMN_GAME_SYMBOL_ID };
    CursorLoader cursorLoader = new CursorLoader(this, GameContentProvider.CONTENT_URI, projection, null, null,
            GameDatabaseHelper.COLUMN_GAME_BOX_ID + GameDatabaseHelper.SORT_DIRECTION);
    return cursorLoader;

}

From source file:com.example.android.diegobaldi.sunshine.DetailActivity.java

/**
 * Creates and returns a CursorLoader that loads the data for our URI and stores it in a Cursor.
 *
 * @param loaderId The loader ID for which we need to create a loader
 * @param loaderArgs Any arguments supplied by the caller
 *
 * @return A new Loader instance that is ready to start loading.
 *///from www . ja v  a  2  s .c om
@Override
public Loader<Cursor> onCreateLoader(int loaderId, Bundle loaderArgs) {

    switch (loaderId) {

    case ID_DETAIL_LOADER:

        return new CursorLoader(this, mUri, WEATHER_DETAIL_PROJECTION, null, null, null);

    default:
        throw new RuntimeException("Loader Not Implemented: " + loaderId);
    }
}