Search in sources :

Example 11 with CursorLoader

use of android.content.CursorLoader in project k-9 by k9mail.

the class MessageListFragment method onCreateLoader.

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    String accountUuid = accountUuids[id];
    Account account = preferences.getAccount(accountUuid);
    String threadId = getThreadId(search);
    Uri uri;
    String[] projection;
    boolean needConditions;
    if (threadId != null) {
        uri = Uri.withAppendedPath(EmailProvider.CONTENT_URI, "account/" + accountUuid + "/thread/" + threadId);
        projection = PROJECTION;
        needConditions = false;
    } else if (showingThreadedList) {
        uri = Uri.withAppendedPath(EmailProvider.CONTENT_URI, "account/" + accountUuid + "/messages/threaded");
        projection = THREADED_PROJECTION;
        needConditions = true;
    } else {
        uri = Uri.withAppendedPath(EmailProvider.CONTENT_URI, "account/" + accountUuid + "/messages");
        projection = PROJECTION;
        needConditions = true;
    }
    StringBuilder query = new StringBuilder();
    List<String> queryArgs = new ArrayList<>();
    if (needConditions) {
        boolean selectActive = activeMessage != null && activeMessage.getAccountUuid().equals(accountUuid);
        if (selectActive) {
            query.append("(" + MessageColumns.UID + " = ? AND " + SpecialColumns.FOLDER_NAME + " = ?) OR (");
            queryArgs.add(activeMessage.getUid());
            queryArgs.add(activeMessage.getFolderName());
        }
        SqlQueryBuilder.buildWhereClause(account, search.getConditions(), query, queryArgs);
        if (selectActive) {
            query.append(')');
        }
    }
    String selection = query.toString();
    String[] selectionArgs = queryArgs.toArray(new String[0]);
    String sortOrder = buildSortOrder();
    return new CursorLoader(getActivity(), uri, projection, selection, selectionArgs, sortOrder);
}
Also used : CursorLoader(android.content.CursorLoader) Account(com.fsck.k9.Account) ArrayList(java.util.ArrayList) Uri(android.net.Uri)

Example 12 with CursorLoader

use of android.content.CursorLoader in project Android-Developers-Samples by johnjohndoe.

the class ContactablesLoaderCallbacks method onCreateLoader.

@Override
public Loader<Cursor> onCreateLoader(int loaderIndex, Bundle args) {
    // Where the Contactables table excels is matching text queries,
    // not just data dumps from Contacts db.  One search term is used to query
    // display name, email address and phone number.  In this case, the query was extracted
    // from an incoming intent in the handleIntent() method, via the
    // intent.getStringExtra() method.
    // BEGIN_INCLUDE(uri_with_query)
    String query = args.getString(QUERY_KEY);
    Uri uri = Uri.withAppendedPath(CommonDataKinds.Contactables.CONTENT_FILTER_URI, query);
    // END_INCLUDE(uri_with_query)
    // BEGIN_INCLUDE(cursor_loader)
    // Easy way to limit the query to contacts with phone numbers.
    String selection = CommonDataKinds.Contactables.HAS_PHONE_NUMBER + " = " + 1;
    // Sort results such that rows for the same contact stay together.
    String sortBy = CommonDataKinds.Contactables.LOOKUP_KEY;
    return new CursorLoader(// Context
    mContext, // URI representing the table/resource to be queried
    uri, // projection - the list of columns to return.  Null means "all"
    null, // selection - Which rows to return (condition rows must match)
    selection, // selection args - can be provided separately and subbed into selection.
    null, // string specifying sort order
    sortBy);
// END_INCLUDE(cursor_loader)
}
Also used : CursorLoader(android.content.CursorLoader) Uri(android.net.Uri)

Example 13 with CursorLoader

use of android.content.CursorLoader in project android-demos by novoda.

the class ContactSelector method onActivityResult.

@Override
public void onActivityResult(int reqCode, int resultCode, Intent data) {
    super.onActivityResult(reqCode, resultCode, data);
    switch(reqCode) {
        case (PICK_CONTACT):
            if (resultCode == Activity.RESULT_OK) {
                Uri contactData = data.getData();
                CursorLoader loader = new CursorLoader(this, contactData, null, null, null, null);
                loader.registerListener(LOADER_ID_CONTACT, new Loader.OnLoadCompleteListener<Cursor>() {

                    @Override
                    public void onLoadComplete(final Loader<Cursor> loader, final Cursor data) {
                        if (data.moveToFirst()) {
                            int nameColumnIndex = data.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME_PRIMARY);
                            String name = data.getString(nameColumnIndex);
                            txtContacts.setText(name);
                        }
                    }
                });
                loader.startLoading();
            }
            break;
    }
}
Also used : CursorLoader(android.content.CursorLoader) Loader(android.content.Loader) CursorLoader(android.content.CursorLoader) Cursor(android.database.Cursor) Uri(android.net.Uri)

Example 14 with CursorLoader

use of android.content.CursorLoader in project Luban by Curzibn.

the class PathUtils method getAbsoluteUriPath.

/**
 * <b>BuildTime:</b> 2014年10月23日<br>
 * <b>Description:</b> Use the uri to get the file path<br>
 *
 * @param c
 * @param uri
 *
 * @return
 */
public static String getAbsoluteUriPath(Context c, Uri uri) {
    String imgPath = "";
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = new CursorLoader(c, uri, proj, null, null, null).loadInBackground();
    if (cursor != null) {
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        if (cursor.getCount() > 0 && cursor.moveToFirst()) {
            imgPath = cursor.getString(column_index);
        }
    }
    return imgPath;
}
Also used : CursorLoader(android.content.CursorLoader) Cursor(android.database.Cursor)

Example 15 with CursorLoader

use of android.content.CursorLoader in project cardslib by gabrielemariotti.

the class NativeListCursorCardFragment method onCreateLoader.

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    Loader<Cursor> loader = null;
    loader = new CursorLoader(getActivity(), CardCursorContract.CardCursor.CONTENT_URI, CardCursorContract.CardCursor.ALL_PROJECTION, null, null, CardCursorContract.CardCursor.DEFAULT_SORT);
    return loader;
}
Also used : CursorLoader(android.content.CursorLoader) Cursor(android.database.Cursor)

Aggregations

CursorLoader (android.content.CursorLoader)30 Cursor (android.database.Cursor)12 Uri (android.net.Uri)11 SmallTest (android.test.suitebuilder.annotation.SmallTest)9 Test (org.junit.Test)9 TagMetadataTest (com.google.samples.apps.iosched.model.TagMetadataTest)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Context (android.content.Context)4 ArrayList (java.util.ArrayList)4 Matchers.anyString (org.mockito.Matchers.anyString)4 SettingsMockContext (com.google.samples.apps.iosched.testutils.SettingsMockContext)3 SuppressLint (android.annotation.SuppressLint)1 Loader (android.content.Loader)1 Bundle (android.os.Bundle)1 MotionEvent (android.view.MotionEvent)1 View (android.view.View)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 GridView (android.widget.GridView)1 ImageView (android.widget.ImageView)1