use of android.database.Cursor in project AndroidSyncProviderDemo by c99koder.
the class ContactsSyncAdapterService method performSync.
private static void performSync(Context context, Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) throws OperationCanceledException {
HashMap<String, SyncEntry> localContacts = new HashMap<String, SyncEntry>();
mContentResolver = context.getContentResolver();
Log.i(TAG, "performSync: " + account.toString());
// Load the local contacts
Uri rawContactUri = RawContacts.CONTENT_URI.buildUpon().appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name).appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type).build();
Cursor c1 = mContentResolver.query(rawContactUri, new String[] { BaseColumns._ID, UsernameColumn, PhotoTimestampColumn }, null, null, null);
while (c1.moveToNext()) {
SyncEntry entry = new SyncEntry();
entry.raw_id = c1.getLong(c1.getColumnIndex(BaseColumns._ID));
entry.photo_timestamp = c1.getLong(c1.getColumnIndex(PhotoTimestampColumn));
localContacts.put(c1.getString(1), entry);
}
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
try {
// status message
if (localContacts.get("efudd") == null) {
addContact(account, "Elmer Fudd", "efudd");
} else {
if (localContacts.get("efudd").photo_timestamp == null || System.currentTimeMillis() > (localContacts.get("efudd").photo_timestamp + 604800000L)) {
//You would probably download an image file and just pass the bytes, but this sample doesn't use network so we'll decode and re-compress the icon resource to get the bytes
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon);
icon.compress(CompressFormat.PNG, 0, stream);
updateContactPhoto(operationList, localContacts.get("efudd").raw_id, stream.toByteArray());
}
updateContactStatus(operationList, localContacts.get("efudd").raw_id, "hunting wabbits");
}
if (operationList.size() > 0)
mContentResolver.applyBatch(ContactsContract.AUTHORITY, operationList);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
use of android.database.Cursor in project AndroidSyncProviderDemo by c99koder.
the class ProfileActivity method onCreate.
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.profile);
if (getIntent().getData() != null) {
Cursor cursor = managedQuery(getIntent().getData(), null, null, null, null);
if (cursor.moveToNext()) {
String username = cursor.getString(cursor.getColumnIndex("DATA1"));
TextView tv = (TextView) findViewById(R.id.profiletext);
tv.setText("This is the profile for " + username);
}
} else {
// How did we get here without data?
finish();
}
}
use of android.database.Cursor in project photo-picker-plus-android by chute.
the class AppUtil method getPath.
public static String getPath(Context context, Uri uri) throws NullPointerException {
final String[] projection = { MediaColumns.DATA };
final Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null);
final int column_index = cursor.getColumnIndexOrThrow(MediaColumns.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
use of android.database.Cursor in project photo-picker-plus-android by chute.
the class CursorRecyclerViewAdapter method swapCursor.
/**
* Swap in a new Cursor, returning the old Cursor. Unlike
* {@link #changeCursor(Cursor)}, the returned old Cursor is <em>not</em>
* closed.
*/
public Cursor swapCursor(Cursor newCursor) {
if (newCursor == mCursor) {
return null;
}
final Cursor oldCursor = mCursor;
if (oldCursor != null && mDataSetObserver != null) {
oldCursor.unregisterDataSetObserver(mDataSetObserver);
}
mCursor = newCursor;
if (mCursor != null) {
if (mDataSetObserver != null) {
mCursor.registerDataSetObserver(mDataSetObserver);
}
mRowIdColumn = newCursor.getColumnIndexOrThrow("_id");
mDataValid = true;
notifyDataSetChanged();
} else {
mRowIdColumn = -1;
mDataValid = false;
notifyDataSetChanged();
//There is no notifyDataSetInvalidated() method in RecyclerView.Adapter
}
return oldCursor;
}
use of android.database.Cursor in project photo-picker-plus-android by chute.
the class GridAdapter method resolveImageOrientation.
public int resolveImageOrientation(AssetModel assetModel) {
int rotation = -1;
if (TextUtils.isEmpty(assetModel.getId())) {
return rotation;
}
if (MediaType.VIDEO.name().equalsIgnoreCase(assetModel.getType())) {
return rotation;
}
if (assetModel.getUrl().startsWith("file:") == false) {
return rotation;
}
Cursor mediaCursor = context.getContentResolver().query(Uri.parse(assetModel.getId()), new String[] { MediaStore.Images.ImageColumns.ORIENTATION, MediaStore.MediaColumns.SIZE }, null, null, null);
if (mediaCursor != null && mediaCursor.getCount() != 0) {
while (mediaCursor.moveToNext()) {
long size = mediaCursor.getLong(1);
Log.d(TAG, "Media Size " + size);
//Extra check to make sure that we are getting the orientation from the proper file
rotation = mediaCursor.getInt(0);
}
}
Log.d(TAG, "Media Rotation " + rotation);
return rotation;
}
Aggregations