List of usage examples for android.support.v4.content CursorLoader CursorLoader
public CursorLoader(Context context, Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder)
From source file:com.dwdesign.tweetings.fragment.TrendsFragment.java
@Override public Loader<Cursor> onCreateLoader(final int id, final Bundle args) { Uri uri = TweetStore.NULL_CONTENT_URI; //if (mTrendsCategoriesAdapter != null && mTrendsSpinner != null) { //final TrendsCategory tc = mTrendsCategoriesAdapter.getItem(mTrendsSpinner.getSelectedItemPosition()); //if (tc != null) { uri = getTrendsQueryUri(TRENDS_TYPE_LOCAL); //}//from www. ja v a 2s .c o m //} final String table = getTableNameForContentUri(uri); final String where = table != null ? CachedTrends.TIMESTAMP + " = " + "(SELECT " + CachedTrends.TIMESTAMP + " FROM " + table + " ORDER BY " + CachedTrends.TIMESTAMP + " DESC LIMIT 1)" : null; return new CursorLoader(getActivity(), uri, CachedTrends.COLUMNS, where, null, null); }
From source file:com.loltimeline.m1miage.app.fragment.MatchDetailFragment.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { // Sort order: Ascending, by date. String sortOrder = MatchEntry.COLUMN_MATCH_CREATION + " ASC"; Uri matchUri = MatchEntry.buildMatchUri(12233); // Now create and return a CursorLoader that will take care of // creating a Cursor for the data being displayed. return new CursorLoader(getActivity(), matchUri, FORECAST_COLUMNS, null, null, sortOrder); }
From source file:com.foxykeep.datadroidpoc.ui.ws.PersonListActivity.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { ProviderCriteria criteria = new ProviderCriteria(); criteria.addSortOrder(DbPerson.Columns.LAST_NAME, true); return new CursorLoader(this, DbPerson.CONTENT_URI, DbPerson.PROJECTION, null, null, criteria.getOrderClause());//from w ww . ja v a 2 s . com }
From source file:com.dwdesign.tweetings.fragment.CursorStatusesListFragment.java
@Override public Loader<Cursor> onCreateLoader(final int id, final Bundle args) { final String[] cols = new String[] { Statuses._ID, Statuses.ACCOUNT_ID, Statuses.STATUS_ID, Statuses.USER_ID, Statuses.STATUS_TIMESTAMP, Statuses.TEXT, Statuses.NAME, Statuses.SCREEN_NAME, Statuses.PROFILE_IMAGE_URL, Statuses.IN_REPLY_TO_SCREEN_NAME, Statuses.IN_REPLY_TO_STATUS_ID, Statuses.LOCATION, Statuses.IS_RETWEET, Statuses.RETWEET_COUNT, Statuses.RETWEET_ID, Statuses.RETWEETED_BY_NAME, Statuses.RETWEETED_BY_SCREEN_NAME, Statuses.IS_FAVORITE, Statuses.IS_PROTECTED, Statuses.IS_VERIFIED, Statuses.IS_GAP, Statuses.IS_POSSIBLY_SENSITIVE }; final Uri uri = getContentUri(); final String sort_by = getSharedPreferences().getBoolean(PREFERENCE_KEY_SORT_TIMELINE_BY_TIME, false) ? Statuses.SORT_ORDER_TIMESTAMP_DESC : Statuses.SORT_ORDER_STATUS_ID_DESC; String where = buildActivatedStatsWhereClause(getActivity(), null); if (getSharedPreferences().getBoolean(PREFERENCE_KEY_ENABLE_FILTER, false)) { final String table = getTableNameForContentUri(uri); where = buildFilterWhereClause(table, where); }/*from w ww.ja va2 s. c o m*/ return new CursorLoader(getActivity(), uri, cols, where, null, sort_by); }
From source file:com.granita.tasks.utils.ExpandableChildDescriptor.java
/** * Get a new {@link CursorLoader} and update it's selection arguments with the values in {@code cursor} as defined by {@code selectionColumns} in * {@link #ExpandableChildDescriptor(Uri, String[], String, String, int...)}. Also applies any selection defined by <code>filter</code>. * //from w w w . ja va2s. co m * @param context * A {@link Context}. * @param cursor * The {@link Cursor} containing the selection. * @param filter * An additional {@link AbstractFilter} to apply to the selection of the cursor. * @return A new {@link CursorLoader} instance. */ public CursorLoader getCursorLoader(Context context, Cursor cursor, AbstractFilter filter) { String[] selectionArgs = null; String selection = mSelection; if (mSelectionColumns != null && mSelectionColumns.length > 0) { /* * The columns in cursor may be null, but the selection arguments for the CursorLoader must be non-null. * * To fix that we scan the selection string for question marks and replace them by "null" if the corresponding selection argument is null. */ int pos = 0; int newPos; // a StringBuilder to build the new selection string StringBuilder selectionBuilder = new StringBuilder(mSelection.length() + 20); selectionBuilder.append("("); // temporary array list for the selection arguments List<String> selectionArgList = new ArrayList<String>(); // for every selection argument for (int i = 0; i < mSelectionColumns.length; ++i) { // find next "?" newPos = mSelection.indexOf('?', pos == 0 ? pos : pos + 1); selectionBuilder.append(mSelection.substring(pos, newPos)); // get the argument String arg = cursor.getString(mSelectionColumns[i]); if (arg == null) { // insert null selectionBuilder.append("null"); // skip the "?" newPos++; } else { // add argument to argument list selectionArgList.add(arg); } pos = newPos; } if (filter != null) { filter.getSelectionArgs(selectionArgList); } selectionArgs = selectionArgList.toArray(new String[selectionArgList.size()]); selectionBuilder.append(mSelection.substring(pos)); if (filter != null) { selectionBuilder.append(") and ("); filter.getSelection(selectionBuilder); selectionBuilder.append(")"); } else { selectionBuilder.append(")"); } selection = selectionBuilder.toString(); } else { if (filter != null) { // temporary array list for the selection arguments List<String> selectionArgList = new ArrayList<String>(); if (filter != null) { filter.getSelectionArgs(selectionArgList); } selectionArgs = selectionArgList.toArray(new String[selectionArgList.size()]); StringBuilder selectionBuilder = new StringBuilder(120); { selectionBuilder.append("("); filter.getSelection(selectionBuilder); selectionBuilder.append(")"); } selection = selectionBuilder.toString(); } } String selectionString = null; if (selection != null) { selectionString = selection.toString(); } return new CursorLoader(context, mUri, mProjection, selectionString, selectionArgs, mSortOrder); }
From source file:com.gvccracing.android.tttimer.Tabs.RaceInfoTab.java
public Loader<Cursor> onCreateLoader(int id, Bundle args) { Log.i(LOG_TAG(), "onCreateLoader start: id=" + Integer.toString(id)); CursorLoader loader = null;//from w w w .j a v a2 s .c om String[] projection; String selection; String[] selectionArgs = null; String sortOrder; switch (id) { case RACE_INFO_LOADER: projection = new String[] { Race.Instance().getTableName() + "." + Race._ID + " as _id", Race.RaceDate, RaceLocation.CourseName, Race.RaceType, Race.StartInterval, RaceLocation.Distance, Race.NumLaps }; selection = Race.Instance().getTableName() + "." + Race._ID + "=" + AppSettings.Instance().getParameterSql(AppSettings.AppSetting_RaceID_Name); selectionArgs = null; sortOrder = Race.Instance().getTableName() + "." + Race._ID; loader = new CursorLoader(getActivity(), RaceInfoView.Instance().CONTENT_URI, projection, selection, selectionArgs, sortOrder); break; case APP_SETTINGS_LOADER_RACEINFO: projection = new String[] { AppSettings.AppSettingName, AppSettings.AppSettingValue }; selection = null; sortOrder = null; selectionArgs = null; loader = new CursorLoader(getActivity(), AppSettings.Instance().CONTENT_URI, projection, selection, selectionArgs, sortOrder); break; case COURSE_RECORD_LOADER: projection = new String[] { RaceResults.Instance().getTableName() + "." + RaceResults._ID + " as _id", RaceResults.ElapsedTime }; selection = Race.Instance().getTableName() + "." + Race.RaceLocation_ID + " in (" + SQLiteQueryBuilder.buildQueryString(true, RaceInfoView.Instance().getTableName(), new String[] { Race.RaceLocation_ID }, Race.Instance().getTableName() + "." + Race._ID + "=" + AppSettings.Instance().getParameterSql(AppSettings.AppSetting_RaceID_Name), null, null, Race.Instance().getTableName() + "." + Race._ID, "1") + ")"; selectionArgs = null; sortOrder = RaceResults.Instance().getTableName() + "." + RaceResults.ElapsedTime; loader = new CursorLoader(getActivity(), RaceInfoResultsView.Instance().CONTENT_URI, projection, selection, selectionArgs, sortOrder); break; } Log.i(LOG_TAG(), "onCreateLoader complete: id=" + Integer.toString(id)); return loader; }
From source file:com.google.android.apps.iosched.ui.MyScheduleFragment.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle data) { return new CursorLoader(getActivity(), ScheduleContract.Blocks.CONTENT_URI, BlocksQuery.PROJECTION, null, null, ScheduleContract.Blocks.DEFAULT_SORT); }
From source file:com.example.droidcodin.popularmdb.MovieFragment.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { switch (preferredSortBy) { case "popularity.desc": return new CursorLoader(getActivity(), MovieContentProvider.Movie.CONTENT_URI, null, null, null, MovieColumns.COLUMN_POPULARITY + " DESC"); case "vote_count.desc": return new CursorLoader(getActivity(), MovieContentProvider.Movie.CONTENT_URI, null, null, null, MovieColumns.COLUMN_VOTECOUNT + " DESC"); case "favorited": return new CursorLoader(getActivity(), MovieContentProvider.Movie.CONTENT_URI, null, MovieColumns.COLUMN_FAVFLAG + " = ?", new String[] { "1" }, null); default://w ww . j a v a 2s . c o m return null; } }
From source file:barqsoft.footballscores.Fragments.DetailFragment.java
public Loader<Cursor> onCreateLoader(int id, Bundle args) { if (mMatch_Id != null || mMatch_Id.length() > 0) { //Log.v(LOG_TAG, mUri.toString()); // Now create and return a CursorLoader that will take care of // creating a Cursor for the data being displayed. return new CursorLoader(getActivity(), DatabaseContract.scores_table.buildScoreWithId(), null, null, fragment_match_id, null); }/*from w ww .ja va 2 s . c om*/ return null; }
From source file:com.jwork.dhammapada.ChapterFragment.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { log.v(this, "onCreateLoader(id:" + id + ")"); Uri baseUri;/*from w w w. j a v a2 s . co m*/ baseUri = DhammapadaContentProvider.getChapterUri(); return new CursorLoader(getActivity(), baseUri, LOADER_CHAPTER_PROJECTION, null, null, null); }