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:android.com.example.contactslist.ui.ContactsListFragment.java

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

    // If this is the loader for finding contacts in the Contacts Provider
    // (the only one supported)
    if (id == ContactsQuery.QUERY_ID) {
        Uri contentUri;/*w  w  w.ja  va 2  s  .  co  m*/

        // There are two types of searches, one which displays all contacts and
        // one which filters contacts by a search query. If mSearchTerm is set
        // then a search query has been entered and the latter should be used.

        if (mSearchTerm == null) {
            // Since there's no search string, use the content URI that searches the entire
            // Contacts table
            contentUri = ContactsQuery.CONTENT_URI;
        } else {
            // Since there's a search string, use the special content Uri that searches the
            // Contacts table. The URI consists of a base Uri and the search string.
            contentUri = Uri.withAppendedPath(ContactsQuery.FILTER_URI, Uri.encode(mSearchTerm));
        }

        // Returns a new CursorLoader for querying the Contacts table. No arguments are used
        // for the selection clause. The search string is either encoded onto the content URI,
        // or no contacts search string is used. The other search criteria are constants. See
        // the ContactsQuery interface.
        return new CursorLoader(getActivity(), contentUri, ContactsQuery.PROJECTION, ContactsQuery.SELECTION,
                null, ContactsQuery.SORT_ORDER);
    }

    Log.e(TAG, "onCreateLoader - incorrect ID provided (" + id + ")");
    return null;
}

From source file:com.gdgdevfest.android.apps.devfestbcn.ui.SessionLivestreamActivity.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    switch (id) {
    case SessionSummaryQuery._TOKEN:
        return new CursorLoader(this, Sessions.buildWithTracksUri(mSessionId), SessionSummaryQuery.PROJECTION,
                null, null, null);/*from  ww  w .j  a  v a  2 s .c o  m*/
    case SessionsQuery._TOKEN:
        boolean futureSessions = false;
        if (args != null) {
            futureSessions = args.getBoolean(LOADER_SESSIONS_ARG, false);
        }
        final long currentTime = UIUtils.getCurrentTime(this);
        String selection = Sessions.LIVESTREAM_SELECTION + " and ";
        String[] selectionArgs;
        if (!futureSessions) {
            selection += Sessions.AT_TIME_SELECTION;
            selectionArgs = Sessions.buildAtTimeSelectionArgs(currentTime);
        } else {
            selection += Sessions.UPCOMING_SELECTION;
            selectionArgs = Sessions.buildUpcomingSelectionArgs(currentTime);
        }
        return new CursorLoader(this, Sessions.buildWithTracksUri(), SessionsQuery.PROJECTION, selection,
                selectionArgs, null);
    }
    return null;
}

From source file:com.pindroid.platform.BookmarkManager.java

public static CursorLoader SearchBookmarks(String query, String tagname, boolean unread, String username,
        Context context) {/*from  w w  w  .  j  a va 2  s.  c  om*/
    final String[] projection = new String[] { Bookmark._ID, Bookmark.Url, Bookmark.Description, Bookmark.Hash,
            Bookmark.Meta, Bookmark.Tags, Bookmark.Shared, Bookmark.ToRead, Bookmark.Synced, Bookmark.Deleted };
    String selection = null;

    final String sortorder = Bookmark.Description + " ASC";

    final String[] queryBookmarks = query.split(" ");

    final ArrayList<String> queryList = new ArrayList<String>();
    final ArrayList<String> selectionlist = new ArrayList<String>();

    if (query != null && query != "" && (tagname == null || tagname == "")) {

        for (String s : queryBookmarks) {
            queryList.add("(" + Bookmark.Tags + " LIKE ? OR " + Bookmark.Description + " LIKE ? OR "
                    + Bookmark.Notes + " LIKE ?)");
            selectionlist.add("%" + s + "%");
            selectionlist.add("%" + s + "%");
            selectionlist.add("%" + s + "%");
        }
        selectionlist.add(username);

        selection = TextUtils.join(" AND ", queryList) + " AND " + Bookmark.Account + "=?";
    } else if (query != null && query != "") {
        for (String s : queryBookmarks) {
            queryList.add("(" + Bookmark.Description + " LIKE ? OR " + Bookmark.Notes + " LIKE ?)");

            selectionlist.add("%" + s + "%");
            selectionlist.add("%" + s + "%");
        }

        selection = TextUtils.join(" AND ", queryList) + " AND " + Bookmark.Account + "=? AND " + "("
                + Bookmark.Tags + " LIKE ? OR " + Bookmark.Tags + " LIKE ? OR " + Bookmark.Tags + " LIKE ? OR "
                + Bookmark.Tags + " = ?)";

        selectionlist.add(username);
        selectionlist.add("% " + tagname + " %");
        selectionlist.add("% " + tagname);
        selectionlist.add(tagname + " %");
        selectionlist.add(tagname);
    } else {
        selectionlist.add(username);
        selection = Bookmark.Account + "=?";
    }

    if (unread) {
        selection += " AND " + Bookmark.ToRead + "=1";
    }

    selection += " AND " + Bookmark.Deleted + "=0";

    return new CursorLoader(context, Bookmark.CONTENT_URI, projection, selection,
            selectionlist.toArray(new String[] {}), sortorder);
}

From source file:com.example.linhdq.test.documents.viewing.grid.DocumentGridActivity.java

@Override
public Loader<Cursor> onCreateLoader(final int documentId, final Bundle bundle) {
    final Uri uri = Uri.withAppendedPath(DocumentContentProvider.CONTENT_URI, String.valueOf(documentId));
    return new CursorLoader(this, uri,
            new String[] { DocumentContentProvider.Columns.TITLE, DocumentContentProvider.Columns.ID }, null,
            null, "created ASC");
}

From source file:com.odoo.addons.calendar.CalendarDashboard.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle data) {
    List<String> args = new ArrayList<>();
    String where = "";
    args.add(mFilterDate);/*  www  .j  a  va2s.  c  o  m*/
    CalendarEvent event = (CalendarEvent) db();
    Uri uri = event.agendaUri();
    switch (mFilterType) {
    case PhoneCalls:
        CRMPhoneCalls phoneCalls = new CRMPhoneCalls(getActivity(), db().getUser());
        uri = phoneCalls.uri();
        where = "date(date) >=  ? and date(date) <= ? and (state = ? or state = ?)";
        args.add(mFilterDate);
        args.add("open");
        args.add("pending");
        if (mFilter != null) {
            where += " and (name like ? or description like ?)";
            args.add("%" + mFilter + "%");
        }
        break;
    case Opportunities:
        CRMLead leads = new CRMLead(getActivity(), db().getUser());
        uri = leads.uri();
        where = "(date(date_deadline) >= ? and date(date_deadline) <= ? or "
                + "date(date_action) >= ? and date(date_action) <= ?) and type = ?";
        args.add(mFilterDate);
        args.add(mFilterDate);
        args.add(mFilterDate);
        args.add("opportunity");
        if (mFilter != null) {
            where += " and (name like ? or description like ?)";
            args.add("%" + mFilter + "%");
        }
        break;
    case Meetings:
        uri = db().uri();
        where = "(date(date_start) <= ? and date(date_end) >= ? )";
        args.add(mFilterDate);
        if (mFilter != null) {
            where += " and name like ?";
        }
        break;
    }
    if (mFilter != null) {
        args.add("%" + mFilter + "%");
    }
    return new CursorLoader(getActivity(), uri, null, where, args.toArray(new String[args.size()]), null);
}

From source file:com.example.contactslist.ui.ContactsListFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    // If this is the loader for finding contacts in the Contacts Provider
    // (the only one supported)
    if (id == ContactsQuery.QUERY_ID) {
        Uri contentUri;//from   ww w  .  j a v a2 s. c o m

        // There are two types of searches, one which displays all contacts and
        // one which filters contacts by a search query. If mSearchTerm is set
        // then a search query has been entered and the latter should be used.

        if (mSearchTerm == null) {
            // Since there's no search string, use the content URI that searches the entire
            // Contacts table
            contentUri = ContactsQuery.CONTENT_URI;
        } else {
            // Since there's a search string, use the special content Uri that searches the
            // Contacts table. The URI consists of a base Uri and the search string.
            contentUri = Uri.withAppendedPath(ContactsQuery.FILTER_URI, Uri.encode(mSearchTerm));
        }

        // Returns a new CursorLoader for querying the Contacts table. No arguments are used
        // for the selection clause. The search string is either encoded onto the content URI,
        // or no contacts search string is used. The other search criteria are constants. See
        // the ContactsQuery interface.

        return new CursorLoader(getActivity(), contentUri, ContactsQuery.PROJECTION, null, null,
                ContactsQuery.SORT_ORDER);
    }

    Log.e(TAG, "onCreateLoader - incorrect ID provided (" + id + ")");
    return null;
}

From source file:com.hangulo.powercontact.MainActivity.java

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

    LatLng currentLatLng = getCurrentLatLng();

    String[] projection = { PowerContactContract.PowerContactEntry.COLUMN_CONTACT_ID,
            PowerContactContract.PowerContactEntry.COLUMN_DATA_ID,
            PowerContactContract.PowerContactEntry.COLUMN_LOOKUP_KEY,
            PowerContactContract.PowerContactEntry.COLUMN_NAME,
            PowerContactContract.PowerContactEntry.COLUMN_ADDR,
            PowerContactContract.PowerContactEntry.COLUMN_TYPE,
            PowerContactContract.PowerContactEntry.COLUMN_LABEL,
            PowerContactContract.PowerContactEntry.COLUMN_PHOTO,
            PowerContactContract.PowerContactEntry.COLUMN_LAT,
            PowerContactContract.PowerContactEntry.COLUMN_LNG,
            PowerContactContract.PowerContactEntry.COLUMN_SIN_LAT,
            PowerContactContract.PowerContactEntry.COLUMN_SIN_LNG,
            PowerContactContract.PowerContactEntry.COLUMN_COS_LAT,
            PowerContactContract.PowerContactEntry.COLUMN_COS_LNG, };

    Log.v(LOG_TAG, "LOADER:MainActivity/onCreateLoader : distance " + mPowerContactSettings.getDistance());

    int mode;//from  w  ww . j av a 2  s .co m

    mode = (mPowerContactSettings.isDemoMode()) ? PowerContactContract.PowerContactEntry.POWERCONTACT_MODE_DEMO
            : PowerContactContract.PowerContactEntry.POWERCONTACT_MODE_NORMAL;

    Log.v(LOG_TAG, "LOADER:MainActivity/onCreateLoader: DEMOMODE" + mode);

    return new CursorLoader(this,
            PowerContactContract.PowerContactEntry.buildLocationByDistance(currentLatLng.latitude,
                    currentLatLng.longitude, mPowerContactSettings.getDistance(), mode),
            projection, // projection // only works
            null, // cols for "where" clause // ignored  ?
            null, // values for "where" clause // ignored  ?
            PowerContactContract.PowerContactEntry.COLUMN_AS_DISTANCE + " DESC"); // sort order --> distance);
}

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

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle data) {
    CursorLoader loader = null;/*from w  ww . jav  a 2  s.c om*/
    if (id == SessionsQuery._TOKEN) {
        loader = new CursorLoader(getActivity(), mSessionUri, SessionsQuery.PROJECTION, null, null, null);
    } else if (id == SpeakersQuery._TOKEN && mSessionUri != null) {
        Uri speakersUri = ScheduleContract.Sessions.buildSpeakersDirUri(mSessionId);
        loader = new CursorLoader(getActivity(), speakersUri, SpeakersQuery.PROJECTION, null, null, null);
    }
    return loader;
}

From source file:com.ht.app.RestaurantsActivity.java

/**
 *   Cursor loader for search/*from   w  w w .  j ava2  s .  com*/
 */
@Override
public android.support.v4.content.Loader<Cursor> onCreateLoader(int loaderId, Bundle bundle) {

    CursorLoader cLoader = null;
    if (loaderId == 0)
        cLoader = new CursorLoader(getBaseContext(), PlaceProvider.SEARCH_URI, null, null,
                new String[] { bundle.getString("query") }, null);
    else if (loaderId == 1)
        cLoader = new CursorLoader(getBaseContext(), PlaceProvider.DETAILS_URI, null, null,
                new String[] { bundle.getString("query") }, null);
    return cLoader;
}

From source file:com.gdgdevfest.android.apps.devfestbcn.ui.MapFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle data) {
    switch (id) {
    case MarkerQuery._TOKEN: {
        Uri uri = ScheduleContract.MapMarkers.buildMarkerUri();
        return new CursorLoader(getActivity(), uri, MarkerQuery.PROJECTION, null, null, null);
    }//  w w  w .j a  v a 2 s.c  o m
    case OverlayQuery._TOKEN: {
        Uri uri = ScheduleContract.MapTiles.buildUri();
        return new CursorLoader(getActivity(), uri, OverlayQuery.PROJECTION, null, null, null);
    }
    case TracksQuery._TOKEN: {
        Uri uri = ScheduleContract.Tracks.CONTENT_URI;
        return new CursorLoader(getActivity(), uri, TracksQuery.PROJECTION, null, null, null);
    }

    }
    return null;
}