List of usage examples for android.database Cursor isNull
boolean isNull(int columnIndex);
true
if the value in the indicated column is null. From source file:edu.mit.mobile.android.locast.data.CastMedia.java
/** * Returns the uri for the media. It will return, in order, the local uri if it's present, the * low-res uri (if {@link #shouldShowLowQuality(Context)} says so), or the full-res URI. * * @param context/* www. ja v a2 s . c o m*/ * @param c * @return null or a url pointing to the media */ public static Uri getMedia(Context context, Cursor c) { Uri media; final int mediaLocalCol = c.getColumnIndexOrThrow(_LOCAL_URI); final int mediaCol = c.getColumnIndexOrThrow(_MEDIA_URL); if (!c.isNull(mediaLocalCol)) { media = Uri.parse(c.getString(mediaLocalCol)); } else if (shouldShowLowQuality(context)) { final int mediaLowResCol = c.getColumnIndexOrThrow(_LOW_BITRATE_URL); media = Uri.parse(c.getString(mediaLowResCol)); } else if (!c.isNull(mediaCol)) { media = Uri.parse(c.getString(mediaCol)); } else { media = null; } return media; }
From source file:org.c99.SyncProviderDemo.ContactsSyncAdapterService.java
private static void updateContactStatus(ArrayList<ContentProviderOperation> operationList, long rawContactId, String status) {/*from w ww . j ava 2s. c o m*/ Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId); Uri entityUri = Uri.withAppendedPath(rawContactUri, Entity.CONTENT_DIRECTORY); Cursor c = mContentResolver.query(entityUri, new String[] { RawContacts.SOURCE_ID, Entity.DATA_ID, Entity.MIMETYPE, Entity.DATA1 }, null, null, null); try { while (c.moveToNext()) { if (!c.isNull(1)) { String mimeType = c.getString(2); if (mimeType.equals("vnd.android.cursor.item/vnd.org.c99.SyncProviderDemo.profile")) { ContentProviderOperation.Builder builder = ContentProviderOperation .newInsert(ContactsContract.StatusUpdates.CONTENT_URI); builder.withValue(ContactsContract.StatusUpdates.DATA_ID, c.getLong(1)); builder.withValue(ContactsContract.StatusUpdates.STATUS, status); builder.withValue(ContactsContract.StatusUpdates.STATUS_RES_PACKAGE, "org.c99.SyncProviderDemo"); builder.withValue(ContactsContract.StatusUpdates.STATUS_LABEL, R.string.app_name); builder.withValue(ContactsContract.StatusUpdates.STATUS_ICON, R.drawable.logo); builder.withValue(ContactsContract.StatusUpdates.STATUS_TIMESTAMP, System.currentTimeMillis()); operationList.add(builder.build()); //Only change the text of our custom entry to the status message pre-Honeycomb, as the newer contacts app shows //statuses elsewhere if (Integer.decode(Build.VERSION.SDK) < 11) { builder = ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI); builder.withSelection(BaseColumns._ID + " = '" + c.getLong(1) + "'", null); builder.withValue(ContactsContract.Data.DATA3, status); operationList.add(builder.build()); } } } } } finally { c.close(); } }
From source file:com.appsimobile.appsii.module.HotspotLoader.java
public static CircularArray<HotspotItem> loadHotspots(Context c) { ContentResolver r = c.getContentResolver(); Cursor cursor = r.query(HomeContract.Hotspots.CONTENT_URI, HotspotQuery.PROJECTION, null, null, null); if (cursor != null) { CircularArray<HotspotItem> result = new CircularArray<>(cursor.getCount()); try {/*from w w w . j a v a 2 s. co m*/ while (cursor.moveToNext()) { long id = cursor.getLong(HotspotQuery.ID); float height = cursor.getFloat(HotspotQuery.HEIGHT); float ypos = cursor.getFloat(HotspotQuery.Y_POSITION); boolean left = cursor.getInt(HotspotQuery.LEFT_BORDER) == 1; boolean needsConfiguration = cursor.getInt(HotspotQuery.NEEDS_CONFIGURATION) == 1; long defaultPageId = cursor.isNull(HotspotQuery._DEFAULT_PAGE) ? -1L : cursor.getLong(HotspotQuery._DEFAULT_PAGE); String name = cursor.getString(HotspotQuery.NAME); HotspotItem conf = new HotspotItem(); conf.init(id, name, height, ypos, left, needsConfiguration, defaultPageId); result.addLast(conf); } } finally { cursor.close(); } return result; } return CollectionUtils.emptyArray(); }
From source file:com.silentcorp.autotracker.db.VehicleDB.java
/** * Get primary and secondary fuel of this vehicle * // w w w .j a v a 2 s.com * @param contentResolver * @param vehicleID */ public static String[] getVehicleFuels(Context context, Long vehicleID) { if (vehicleID == null) { return new String[] {}; } // get primary and secondary Uri uri = Uri.parse(DBContentProvider.VEHICLES_URI + "/" + vehicleID); Cursor c = context.getContentResolver().query(uri, FUEL_COLUMNS, null, null, null); if (!c.moveToFirst()) { // This is unexpected TODO return new String[] {}; } String primary = c.getString(c.getColumnIndex(COL_PRIMARY_FUEL)); String secondary = null; int secInd = c.getColumnIndex(COL_SECONDARY_FUEL); if (!c.isNull(secInd)) { secondary = c.getString(secInd); } // Do not forget to close c.close(); if (secondary == null) { return new String[] { primary }; } return new String[] { primary, secondary }; }
From source file:com.github.chenxiaolong.dualbootpatcher.FileUtils.java
public static UriMetadata[] queryUriMetadata(ContentResolver cr, Uri... uris) { ThreadUtils.enforceExecutionOnNonMainThread(); UriMetadata[] metadatas = new UriMetadata[uris.length]; for (int i = 0; i < metadatas.length; i++) { UriMetadata metadata = new UriMetadata(); metadatas[i] = metadata;//w w w .ja v a 2 s . c o m metadata.uri = uris[i]; metadata.mimeType = cr.getType(metadata.uri); if (SAF_SCHEME.equals(metadata.uri.getScheme())) { Cursor cursor = cr.query(metadata.uri, null, null, null, null, null); try { if (cursor != null && cursor.moveToFirst()) { int nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME); int sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE); metadata.displayName = cursor.getString(nameIndex); if (cursor.isNull(sizeIndex)) { metadata.size = -1; } else { metadata.size = cursor.getLong(sizeIndex); } } } finally { IOUtils.closeQuietly(cursor); } } else if (FILE_SCHEME.equals(metadata.uri.getScheme())) { metadata.displayName = metadata.uri.getLastPathSegment(); metadata.size = new File(metadata.uri.getPath()).length(); } else { throw new IllegalArgumentException("Cannot handle URI: " + metadata.uri); } } return metadatas; }
From source file:org.codarama.haxsync.services.ContactsSyncAdapterService.java
private static void updateContactStatus(long rawContactId, String status, long timeStamp) { if (status != null && timeStamp != 0) { ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>(); Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId); Uri entityUri = Uri.withAppendedPath(rawContactUri, Entity.CONTENT_DIRECTORY); Cursor c = mContentResolver.query(entityUri, new String[] { RawContacts.SOURCE_ID, Entity.DATA_ID, Entity.MIMETYPE, Entity.DATA1 }, null, null, null);/* w w w . j a va 2 s.co m*/ try { while (c.moveToNext()) { if (!c.isNull(1)) { String mimeType = c.getString(2); if (mimeType.equals("vnd.android.cursor.item/vnd.org.codarama.haxsync.profile")) { ContentProviderOperation.Builder builder = ContentProviderOperation .newInsert(ContactsContract.StatusUpdates.CONTENT_URI); builder.withValue(ContactsContract.StatusUpdates.DATA_ID, c.getLong(1)); builder.withValue(ContactsContract.StatusUpdates.STATUS, status); builder.withValue(ContactsContract.StatusUpdates.STATUS_RES_PACKAGE, "org.codarama.haxsync"); builder.withValue(ContactsContract.StatusUpdates.STATUS_LABEL, R.string.app_name); builder.withValue(ContactsContract.StatusUpdates.STATUS_ICON, R.drawable.icon); builder.withValue(ContactsContract.StatusUpdates.STATUS_TIMESTAMP, timeStamp); operationList.add(builder.build()); } } } } finally { c.close(); } try { mContentResolver.applyBatch(ContactsContract.AUTHORITY, operationList); } catch (RemoteException e) { Log.e("Error", e.getLocalizedMessage()); } catch (OperationApplicationException e) { Log.e("Error", e.getLocalizedMessage()); } } }
From source file:pro.dbro.iburn_2012.OpenStreetMapFragment.java
public static ArrayList<OverlayItem> generateOverlayItems() { final ArrayList<OverlayItem> items = new ArrayList<OverlayItem>(); String[] projection = new String[] { CampTable.COLUMN_NAME, CampTable.COLUMN_LATITUDE, CampTable.COLUMN_LONGITUDE, CampTable.COLUMN_ID }; Cursor camps = FragmentTabsPager.app.getContentResolver().query(PlayaContentProvider.CAMP_URI, projection, null, null, CampTable.COLUMN_LATITUDE + " ASC"); if (camps.moveToFirst()) { Drawable base_pin = FragmentTabsPager.app.getResources().getDrawable(R.drawable.red_pin); OverlayItem item;/* w w w . jav a 2 s. c o m*/ do { if (!camps.isNull(camps.getColumnIndex(CampTable.COLUMN_LATITUDE))) { item = new OverlayItem(camps.getString(camps.getColumnIndex(CampTable.COLUMN_NAME)), camps.getString(camps.getColumnIndex(CampTable.COLUMN_ID)), new GeoPoint(camps.getDouble(camps.getColumnIndex(CampTable.COLUMN_LATITUDE)), camps.getDouble(camps.getColumnIndex(CampTable.COLUMN_LONGITUDE)))); item.setMarker(base_pin); items.add(item); //Log.d("Camp Location added", String.valueOf(camps.getDouble(camps.getColumnIndex(CampTable.COLUMN_LATITUDE))) + " : " + camps.getDouble(camps.getColumnIndex(CampTable.COLUMN_LONGITUDE))); } } while (camps.moveToNext()); } camps.close(); return items; }
From source file:org.codarama.haxsync.services.ContactsSyncAdapterService.java
private static void updateContactPhoto(long rawContactId, long timestamp, int maxSize, boolean square, String imgUrl, boolean faceDetect, boolean force, boolean root, int rootsize, File cacheDir, boolean google, boolean primary) { if (imgUrl != null) { String where = ContactsContract.Data.RAW_CONTACT_ID + " = '" + rawContactId + "' AND " + ContactsContract.Data.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE + "'"; //getting the old timestamp String oldurl = ""; boolean newpic = force; if (!newpic) { Cursor c1 = mContentResolver.query(ContactsContract.Data.CONTENT_URI, new String[] { ContactsContract.Data.SYNC3 }, where, null, null); if (c1.getCount() > 0) { c1.moveToLast();// w ww . j a va 2s .c o m if (!c1.isNull(c1.getColumnIndex(ContactsContract.Data.SYNC3))) { oldurl = c1.getString(c1.getColumnIndex(ContactsContract.Data.SYNC3)); //Log.i(TAG, "read old timestamp: " + oldTimestamp); } } c1.close(); //Log.i(TAG, "Old Timestamp " +String.valueOf(oldTimestamp) + "new timestamp: " + String.valueOf(timestamp)); if (!oldurl.equals(imgUrl)) { Log.i(TAG, "OLD URL: " + oldurl); Log.i(TAG, "NEW URL: " + imgUrl); newpic = true; } } if (newpic) { Log.i(TAG, "getting new image, " + imgUrl); // Log.i(TAG, "Old Timestamp " +String.valueOf(oldTimestamp) + "new timestamp: " + String.valueOf(timestamp)); byte[] photo = WebUtil.download(imgUrl); byte[] origPhoto = photo; /*if(square) photo = BitmapUtil.resize(photo, maxSize, faceDetect);*/ ContactUtil.Photo photoi = new Photo(); photoi.data = photo; photoi.timestamp = timestamp; photoi.url = imgUrl; ContactUtil.updateContactPhoto(mContentResolver, rawContactId, photoi, primary); if (root) { Cursor c1 = mContentResolver.query(ContactsContract.Data.CONTENT_URI, new String[] { ContactsContract.CommonDataKinds.Photo.PHOTO_FILE_ID }, where, null, null); if (c1.getCount() > 0) { c1.moveToLast(); String photoID = c1 .getString(c1.getColumnIndex(ContactsContract.CommonDataKinds.Photo.PHOTO_FILE_ID)); c1.close(); if (photoID != null) { photo = BitmapUtil.resize(origPhoto, rootsize, faceDetect); String picpath = DeviceUtil.saveBytes(photo, cacheDir); try { String newpath = RootUtil.movePic(picpath, photoID); RootUtil.changeOwner(newpath); } catch (Exception e) { Log.e("ROOT EXCEPTION", e.getMessage()); // TODO: handle exception } } } } Log.i("google photo sync", String.valueOf(google)); if (google) { for (long raw : ContactUtil.getRawContacts(mContentResolver, rawContactId, "com.google")) { Log.i("google rawid", String.valueOf(raw)); ContactUtil.updateContactPhoto(mContentResolver, raw, photoi, false); } } } } }
From source file:org.anhonesteffort.flock.sync.calendar.EventFactory.java
protected static ContentValues getValuesForReminder(String path, Cursor cursor) throws InvalidComponentException { if (!cursor.isNull(0) && !cursor.isNull(1)) { ContentValues values = new ContentValues(3); values.put(CalendarContract.Reminders.EVENT_ID, cursor.getLong(0)); values.put(CalendarContract.Reminders.MINUTES, cursor.getInt(1)); values.put(CalendarContract.Reminders.METHOD, cursor.getInt(2)); return values; }/*from w ww . ja v a 2s .c om*/ Log.e(TAG, "reminder event id or minutes is null"); throw new InvalidComponentException("reminder event id or minutes is null", false, CalDavConstants.CALDAV_NAMESPACE, path); }
From source file:com.android.calendar.Event.java
/** * @param cEvents Cursor pointing at event * @return An event created from the cursor */// w w w. j a va 2 s . co m private static Event generateEventFromCursor(Cursor cEvents) { Event e = new Event(); e.id = cEvents.getLong(PROJECTION_EVENT_ID_INDEX); e.title = cEvents.getString(PROJECTION_TITLE_INDEX); e.location = cEvents.getString(PROJECTION_LOCATION_INDEX); e.allDay = cEvents.getInt(PROJECTION_ALL_DAY_INDEX) != 0; e.organizer = cEvents.getString(PROJECTION_ORGANIZER_INDEX); e.guestsCanModify = cEvents.getInt(PROJECTION_GUESTS_CAN_INVITE_OTHERS_INDEX) != 0; if (e.title == null || e.title.length() == 0) { e.title = mNoTitleString; } if (!cEvents.isNull(PROJECTION_COLOR_INDEX)) { // Read the color from the database e.color = Utils.getDisplayColorFromColor(cEvents.getInt(PROJECTION_COLOR_INDEX)); } else { e.color = mNoColorColor; } long eStart = cEvents.getLong(PROJECTION_BEGIN_INDEX); long eEnd = cEvents.getLong(PROJECTION_END_INDEX); e.startMillis = eStart; e.startTime = cEvents.getInt(PROJECTION_START_MINUTE_INDEX); e.startDay = cEvents.getInt(PROJECTION_START_DAY_INDEX); e.endMillis = eEnd; e.endTime = cEvents.getInt(PROJECTION_END_MINUTE_INDEX); e.endDay = cEvents.getInt(PROJECTION_END_DAY_INDEX); e.hasAlarm = cEvents.getInt(PROJECTION_HAS_ALARM_INDEX) != 0; // Check if this is a repeating event String rrule = cEvents.getString(PROJECTION_RRULE_INDEX); String rdate = cEvents.getString(PROJECTION_RDATE_INDEX); if (!TextUtils.isEmpty(rrule) || !TextUtils.isEmpty(rdate)) { e.isRepeating = true; } else { e.isRepeating = false; } e.selfAttendeeStatus = cEvents.getInt(PROJECTION_SELF_ATTENDEE_STATUS_INDEX); return e; }