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.enadein.carlogbook.ui.AddUpdateLogActivity.java

@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
    return new CursorLoader(this, ProviderDescriptor.DataValue.CONTENT_URI, null, "TYPE = ?",
            new String[] { String.valueOf(ProviderDescriptor.DataValue.Type.OTHERS) }, null);
}

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

/**
 * Called by the {@link android.support.v4.app.LoaderManagerImpl} when a new Loader needs to be
 * created. This Activity only uses one loader, so we don't necessarily NEED to check the
 * loaderId, but this is certainly best practice.
 *
 * @param loaderId The loader ID for which we need to create a loader
 * @param bundle   Any arguments supplied by the caller
 * @return A new Loader instance that is ready to start loading.
 *//*w  w  w  .jav  a  2 s  . co m*/
@Override
public Loader<Cursor> onCreateLoader(int loaderId, Bundle bundle) {

    switch (loaderId) {

    case ID_FORECAST_LOADER:
        /* URI for all rows of weather data in our weather table */
        Uri forecastQueryUri = WeatherContract.WeatherEntry.CONTENT_URI;
        /* Sort order: Ascending by date */
        String sortOrder = WeatherContract.WeatherEntry.COLUMN_DATE + " ASC";
        /*
         * A SELECTION in SQL declares which rows you'd like to return. In our case, we
         * want all weather data from today onwards that is stored in our weather table.
         * We created a handy method to do that in our WeatherEntry class.
         */
        String selection = WeatherContract.WeatherEntry.getSqlSelectForTodayOnwards();

        return new CursorLoader(this, forecastQueryUri, MAIN_FORECAST_PROJECTION, selection, null, sortOrder);

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

From source file:com.chrismorais.android.sunshine.app.ForecastFragment.java

@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
    String sortOrder = WeatherContract.WeatherEntry.COLUMN_DATE + " ASC";

    String locationSetting = Utility.getPreferredLocation(getActivity());
    Uri weatherForLocationUri = WeatherContract.WeatherEntry.buildWeatherLocationWithStartDate(locationSetting,
            System.currentTimeMillis());

    return new CursorLoader(getActivity(), weatherForLocationUri, FORECAST_COLUMNS, null, null, sortOrder);
}

From source file:ch.berta.fabio.popularmovies.data.repositories.MovieRepositoryImpl.java

@Override
public CursorLoader getIsFavLoader(@NonNull Context context, int movieDbId) {
    return new CursorLoader(context, MovieContract.Movie.buildMovieByDbIdUri(movieDbId),
            new String[] { MovieContract.Movie._ID }, null, null, MovieContract.Movie.SORT_DEFAULT);
}

From source file:com.example.user.lstapp.CreatePlaceFragment.java

private String getRealPathFromURI(Context mContext, Uri contentUri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    CursorLoader loader = new CursorLoader(mContext, contentUri, proj, null, null, null);
    Cursor cursor = loader.loadInBackground();
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();/*from   w  w w. jav  a 2  s. c  om*/
    return cursor.getString(column_index);
}

From source file:br.com.bioscada.apps.biotracks.MarkerListActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    myTracksProviderUtils = MyTracksProviderUtils.Factory.get(this);
    sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
    long trackId = getIntent().getLongExtra(EXTRA_TRACK_ID, -1L);
    if (trackId == -1L) {
        Log.d(TAG, "invalid track id");
        finish();//from w  w w . j  ava 2 s .co m
        return;
    }
    track = myTracksProviderUtils.getTrack(trackId);

    setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);

    listView = (ListView) findViewById(R.id.marker_list);
    listView.setEmptyView(findViewById(R.id.marker_list_empty));
    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent = IntentUtils.newIntent(MarkerListActivity.this, MarkerDetailActivity.class)
                    .putExtra(MarkerDetailActivity.EXTRA_MARKER_ID, id);
            startActivity(intent);
        }
    });
    resourceCursorAdapter = new ResourceCursorAdapter(this, R.layout.list_item, null, 0) {
        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            int typeIndex = cursor.getColumnIndex(WaypointsColumns.TYPE);
            int nameIndex = cursor.getColumnIndex(WaypointsColumns.NAME);
            int timeIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.TIME);
            int categoryIndex = cursor.getColumnIndex(WaypointsColumns.CATEGORY);
            int descriptionIndex = cursor.getColumnIndex(WaypointsColumns.DESCRIPTION);
            int photoUrlIndex = cursor.getColumnIndex(WaypointsColumns.PHOTOURL);

            boolean statistics = Waypoint.WaypointType.values()[cursor
                    .getInt(typeIndex)] == Waypoint.WaypointType.STATISTICS;
            int iconId = statistics ? R.drawable.ic_marker_yellow_pushpin : R.drawable.ic_marker_blue_pushpin;
            String name = cursor.getString(nameIndex);
            long time = cursor.getLong(timeIndex);
            String category = statistics ? null : cursor.getString(categoryIndex);
            String description = statistics ? null : cursor.getString(descriptionIndex);
            String photoUrl = cursor.getString(photoUrlIndex);

            ListItemUtils.setListItem(MarkerListActivity.this, view, false, true, iconId, R.string.image_marker,
                    name, null, null, null, 0, time, false, category, description, photoUrl);
        }
    };
    listView.setAdapter(resourceCursorAdapter);
    ApiAdapterFactory.getApiAdapter().configureListViewContextualMenu(this, listView,
            contextualActionModeCallback);

    final long firstWaypointId = myTracksProviderUtils.getFirstWaypointId(trackId);
    getSupportLoaderManager().initLoader(0, null, new LoaderCallbacks<Cursor>() {
        @Override
        public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
            return new CursorLoader(MarkerListActivity.this, WaypointsColumns.CONTENT_URI, PROJECTION,
                    WaypointsColumns.TRACKID + "=? AND " + WaypointsColumns._ID + "!=?",
                    new String[] { String.valueOf(track.getId()), String.valueOf(firstWaypointId) }, null);
        }

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

        @Override
        public void onLoaderReset(Loader<Cursor> loader) {
            resourceCursorAdapter.swapCursor(null);
        }
    });
}

From source file:com.jbirdvegas.mgerrit.database.UserChanges.java

/**
 * Helper method for change list search queries
 * @param context Context for database access
 * @param status The change status to search for
 * @param builder A string builder to help form the where query
 * @param bindArgs Any bind arguments to be bound to the SQL query
 * @return A CursorLoader//from   w  w  w. j  a va  2  s  .  co m
 */
private static CursorLoader findCommits(Context context, String status, StringBuilder builder,
        List<String> bindArgs) {
    if (builder.length() > 0)
        builder.append(" AND ");

    StringBuilder where = builder.append(C_STATUS).append(" = ?").append(" AND ").append(Changes.TABLE)
            .append(".").append(C_OWNER).append(" = ").append(Users.TABLE).append(".").append(C_USER_ID);

    status = JSONCommit.Status.getStatusString(status);
    bindArgs.add(status);

    String valuesArray[] = new String[bindArgs.size()];

    return new CursorLoader(context, CONTENT_URI, CHANGE_LIST_PROJECTION, where.toString(),
            bindArgs.toArray(valuesArray), SORT_BY);
}

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

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    Builder toLoadUriBuilder = SipMessage.THREAD_ID_URI_BASE.buildUpon().appendEncodedPath(remoteFrom);
    return new CursorLoader(getActivity(), toLoadUriBuilder.build(), null, null, null,
            SipMessage.FIELD_DATE + " ASC");
}

From source file:com.jackie.sunshine.app.ForecastFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {

    String locationSetting = Utility.getPreferredLocation(getActivity());

    // Sort order: Ascending, by date
    String sortOrder = WeatherContract.WeatherEntry.COLUMN_DATE + " ASC";
    Uri weatherForLocationUri = WeatherContract.WeatherEntry.buildWeatherLocationWithStartDate(locationSetting,
            System.currentTimeMillis());
    return new CursorLoader(getContext(), weatherForLocationUri, FORECAST_COLUMNS, null, null, sortOrder);
}

From source file:com.example.amit.tellymoviebuzzz.PopularFragment.java

@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
    // String locationSetting = Utility.getPreferredLocation(getActivity());
    String movie = "thisyear";
    //  Utility.getPreferredMovie(getActivity());
    // Sort order:  Ascending, by date.
    // String sortOrder = WeatherContract.WeatherEntry.COLUMN_DATE + " ASC";
    // Uri weatherForLocationUri = WeatherContract.WeatherEntry.buildWeatherLocationWithStartDate(
    //       locationSetting, System.currentTimeMillis());

    Uri movieForMovieIdUri = MovieContract.MovieNumberEntry.buildMovieType(movie);
    String sortOrder = null;//  w ww  .  j  a  va2 s. c om

    String sMovieTypeWithMovieID = MovieContract.MovieNumberEntry.TABLE_NAME + "."
            + MovieContract.MovieNumberEntry.COLUMN_MOVIE_TYPE + " = ? AND "
            + MovieContract.MovieNumberEntry.COLUMN_MOVIE_CATEGORY + " = ? ";

    return new CursorLoader(getActivity(), MovieContract.MovieNumberEntry.CONTENT_URI, FORECAST_MOVIE_COLUMNS,
            sMovieTypeWithMovieID, new String[] { movie, "popular" }, sortOrder);
}