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.fbartnitzek.tasteemall.mainpager.LocationPagerFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    switch (id) {
    case LOCATION_LOADER_ID:
        if (this.jsonUri == null) {
            Log.v(LOG_TAG, "onCreateLoader before jsonCreation, hashCode=" + this.hashCode() + ", " + "id = ["
                    + id + "], args = [" + args + "]");

            String pattern = ((MainActivity) getActivity()).getSearchPattern();

            // Location.FORMATTED_ADDRESS + " LIKE ? OR " + Location.INPUT + " LIKE ? OR "
            // + Location.COUNTRY + " LIKE ? OR " + Location.DESCRIPTION + " LIKE ?",
            try {
                String encodedValue = DatabaseContract.encodeValue(pattern);
                if (jsonTextFilter == null) {
                    jsonTextFilter = new JSONObject().put(Location.ENTITY,
                            new JSONObject().put(DatabaseContract.OR,
                                    new JSONObject().put(Location.ENTITY,
                                            new JSONObject().put(Location.FORMATTED_ADDRESS, new JSONObject())
                                                    .put(Location.INPUT, new JSONObject())
                                                    .put(Location.COUNTRY, new JSONObject())
                                                    .put(Location.DESCRIPTION, new JSONObject()))));
                }/*  w w w .j a  v  a 2 s .  co  m*/

                JSONObject location = jsonTextFilter.getJSONObject(Location.ENTITY)
                        .getJSONObject(DatabaseContract.OR).getJSONObject(Location.ENTITY);
                location.getJSONObject(Location.FORMATTED_ADDRESS).put(DatabaseContract.Operations.CONTAINS,
                        encodedValue);
                location.getJSONObject(Location.INPUT).put(DatabaseContract.Operations.CONTAINS, encodedValue);
                location.getJSONObject(Location.COUNTRY).put(DatabaseContract.Operations.CONTAINS,
                        encodedValue);
                location.getJSONObject(Location.DESCRIPTION).put(DatabaseContract.Operations.CONTAINS,
                        encodedValue);
                jsonTextFilter.getJSONObject(Location.ENTITY).getJSONObject(DatabaseContract.OR)
                        .put(Location.ENTITY, location);

                jsonUri = DatabaseContract.buildUriWithJson(jsonTextFilter);
            } catch (JSONException | UnsupportedEncodingException e) {
                e.printStackTrace();
                Log.e(LOG_TAG, "onCreateLoader building jsonUri failed, hashCode=" + this.hashCode() + ", "
                        + "pattern= [" + pattern + "]");
                throw new RuntimeException("building jsonUri failed");
            }
            Log.v(LOG_TAG, "onCreateLoader after jsonCreation, hashCode=" + this.hashCode() + ", " + "id = ["
                    + id + "], args = [" + args + "]");

        }

        return new CursorLoader(getActivity(),
                jsonUri != null ? jsonUri
                        : DatabaseContract.LocationEntry.buildUriWithPatternOrDescription(
                                ((MainActivity) getActivity()).getSearchPattern()),
                QueryColumns.MainFragment.LocationQuery.COLUMNS, null, null,
                Location.COUNTRY + ", " + Location.FORMATTED_ADDRESS);
    default:
        throw new RuntimeException("wrong loader_id in " + this.getClass().getSimpleName() + "...");
    }
}

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

@Override
public CursorLoader getFavMovieDetailsLoader(@NonNull Context context, long movieRowId) {
    return new CursorLoader(context, MovieContract.Movie.buildMovieWithReviewsAndTrailersUri(movieRowId),
            FAV_MOVIE_DETAILS_COLUMNS, null, null, MovieContract.Movie.SORT_DEFAULT);
}

From source file:com.example.houcem.sunshine.ForecastFragment.java

@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
    String locationSetting = com.example.houcem.sunshine.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(getActivity(), weatherForLocationUri, FORECAST_COLUMNS, null, null, sortOrder);
}

From source file:com.conferenceengineer.android.iosched.ui.SessionFeedbackFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle data) {
    return new CursorLoader(getActivity(), mSessionUri, SessionsQuery.PROJECTION, null, null, null);
}

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

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    switch (id) {
    case PRODUCER_LOADER_ID:
        if (this.jsonUri == null) {
            Log.v(LOG_TAG, "onCreateLoader before jsonCreation, hashCode=" + this.hashCode() + ", " + "id = ["
                    + id + "], args = [" + args + "]");

            String pattern = ((MainActivity) getActivity()).getSearchPattern();
            try {
                String encodedValue = DatabaseContract.encodeValue(pattern);

                if (jsonTextFilter == null) {
                    jsonTextFilter = new JSONObject().put(Producer.ENTITY,
                            new JSONObject().put(DatabaseContract.OR,
                                    new JSONObject().put(Producer.ENTITY,
                                            new JSONObject().put(Producer.NAME, new JSONObject())
                                                    .put(Producer.FORMATTED_ADDRESS, new JSONObject())
                                                    .put(Producer.COUNTRY, new JSONObject()))));
                }/*  w  ww  .  ja v a  2s  .c  o  m*/

                JSONObject producer = jsonTextFilter.getJSONObject(Producer.ENTITY)
                        .getJSONObject(DatabaseContract.OR).getJSONObject(Producer.ENTITY);
                producer.getJSONObject(Producer.NAME).put(DatabaseContract.Operations.CONTAINS, encodedValue);
                producer.getJSONObject(Producer.FORMATTED_ADDRESS).put(DatabaseContract.Operations.CONTAINS,
                        encodedValue);
                producer.getJSONObject(Producer.COUNTRY).put(DatabaseContract.Operations.CONTAINS,
                        encodedValue);
                jsonTextFilter.getJSONObject(Producer.ENTITY).getJSONObject(DatabaseContract.OR)
                        .put(Producer.ENTITY, producer);

                jsonUri = DatabaseContract.buildUriWithJson(jsonTextFilter);
            } catch (JSONException | UnsupportedEncodingException e) {
                e.printStackTrace();
                Log.e(LOG_TAG, "onCreateLoader building jsonUri failed, hashCode=" + this.hashCode() + ", "
                        + "pattern= [" + pattern + "]");
                throw new RuntimeException("building jsonUri failed");
            }
            Log.v(LOG_TAG, "onCreateLoader after jsonCreation, hashCode=" + this.hashCode() + ", " + "id = ["
                    + id + "], args = [" + args + "]");

        }

        return new CursorLoader(getActivity(), jsonUri, QueryColumns.MainFragment.ProducerQuery.COLUMNS, null,
                null, Producer.NAME);
    default:
        throw new RuntimeException("wrong loader_id in " + this.getClass().getSimpleName() + "...");
    }
}

From source file:com.misczak.joinmybridge.EventFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    Uri baseUri = CalendarContract.Events.CONTENT_URI;

    //Set the before boundary for events to select bridges from.
    Date cDate = new Date();
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(cDate);/*w w w. j  a v a 2s .  com*/
    long nowTime = calendar.getTimeInMillis();

    return new CursorLoader(getActivity(), baseUri, EVENTS_SUMMARY_PROJECTION,
            "calendar_id=" + mCalendarId + " AND (dtstart >=" + nowTime + " OR rdate >=" + nowTime + ")", null,
            CalendarContract.Events.DTSTART + " COLLATE LOCALIZED ASC");

}

From source file:br.com.dgimenes.sunshine.DetailFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    if (null != mUri) {
        // Now create and return a CursorLoader that will take care of
        // creating a Cursor for the data being displayed.
        return new CursorLoader(getActivity(), mUri, DETAIL_COLUMNS, null, null, null);
    }//from   w  w w  .j a  va 2s .c  om
    return null;
}

From source file:com.paranoid.gerrit.database.UserChanges.java

/**
 * List the commits that start with the given change id
 * @param context Context for database access
 * @param changeID//from  w w w  .  ja  v  a  2  s  .  c  o  m
 * @return
 */
public static CursorLoader findCommitWithChangeID(Context context, String changeID) {

    if (changeID == null)
        return null;

    StringBuilder where = new StringBuilder().append(Changes.TABLE).append(".").append(C_OWNER).append(" = ")
            .append(Users.TABLE).append(".").append(C_USER_ID).append(" AND ").append(C_CHANGE_ID)
            .append(" LIKE ?");

    return new CursorLoader(context, CONTENT_URI, CHANGE_LIST_PROJECTION, where.toString(),
            new String[] { changeID + "%" }, SORT_BY);
}

From source file:com.nogago.android.tracks.MarkerListActivity.java

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

    trackId = getIntent().getLongExtra(EXTRA_TRACK_ID, -1L);
    if (trackId == -1L) {
        Log.d(TAG, "invalid track id");
        finish();//  w w w.  ja v a  2 s.c o m
        return;
    }

    setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
    setContentView(R.layout.marker_list);

    getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE)
            .registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);

    ListView 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 nameIndex = cursor.getColumnIndex(WaypointsColumns.NAME);
            int descriptionIndex = cursor.getColumnIndex(WaypointsColumns.DESCRIPTION);
            int categoryIndex = cursor.getColumnIndex(WaypointsColumns.CATEGORY);
            int typeIndex = cursor.getColumnIndex(WaypointsColumns.TYPE);
            int timeIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.TIME);

            boolean statistics = cursor.getInt(typeIndex) == Waypoint.TYPE_STATISTICS;
            String name = cursor.getString(nameIndex);
            int iconId = statistics ? R.drawable.yellow_pushpin : R.drawable.blue_pushpin;
            String contentDescription = getString(R.string.icon_marker);
            String category = statistics ? null : cursor.getString(categoryIndex);
            long time = cursor.getLong(timeIndex);
            String description = statistics ? null : cursor.getString(descriptionIndex);
            ListItemUtils.setListItem(MarkerListActivity.this, view, name, iconId, contentDescription, category,
                    null, null, time, description);
        }
    };
    listView.setAdapter(resourceCursorAdapter);
    ApiAdapterFactory.getApiAdapter().configureListViewContextualMenu(this, listView,
            contextualActionModeCallback);

    final long firstWaypointId = MyTracksProviderUtils.Factory.get(this).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(trackId), 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.developers.pnp.lilly.app.PlacesFragment.java

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

    LatLng latlngLocation = ((myLatLngProvider) getActivity()).getCurrentLocation();
    Uri placesForLocationUri;//  w w  w .  j a  va  2s  .c o m
    if (latlngLocation != null) {
        placesForLocationUri = PlacesContract.PlaceEntry.buildPlacesFromLocation(latlngLocation);
    } else {
        placesForLocationUri = PlacesContract.PlaceEntry.buildPlaces();
    }

    return new CursorLoader(getActivity(), placesForLocationUri, PLACES_COLUMNS, null, null, null);
}