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);
}
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)
}
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;
}
}
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;
}
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;
}
Aggregations