Example usage for android.content ContentValues containsKey

List of usage examples for android.content ContentValues containsKey

Introduction

In this page you can find the example usage for android.content ContentValues containsKey.

Prototype

public boolean containsKey(String key) 

Source Link

Document

Returns true if this object has the named value.

Usage

From source file:export.UploadManager.java

@SuppressWarnings("null")
public Uploader add(ContentValues config) {
    if (config == null) {
        System.err.println("Add null!");
        //assert (false);
        return null;
    }/*w ww  .  j a v  a  2 s .c  o m*/

    String uploaderName = config.getAsString(Constants.DB.ACCOUNT.NAME);
    if (uploaderName == null) {
        System.err.println("name not found!");
        return null;
    }
    if (uploaders.containsKey(uploaderName)) {
        return uploaders.get(uploaderName);
    }
    Uploader uploader = null;
    //if (uploaderName.contentEquals(RunKeeperUploader.NAME)) {
    //   uploader = new RunKeeperUploader(this);
    if (uploaderName.contentEquals(GarminUploader.NAME)) {
        uploader = new GarminUploader(this);
        //} else if (uploaderName.contentEquals(FunBeatUploader.NAME)) {
        //  uploader = new FunBeatUploader(this);
    } else if (uploaderName.contentEquals(MapMyRunUploader.NAME)) {
        uploader = new MapMyRunUploader(this);
    } else if (uploaderName.contentEquals(NikePlus.NAME)) {
        uploader = new NikePlus(this);
        //} else if (uploaderName.contentEquals(JoggSE.NAME)) {
        //  uploader = new JoggSE(this);
        // } else if (uploaderName.contentEquals(Endomondo.NAME)) {
        //   uploader = new Endomondo(this);
        //} else if (uploaderName.contentEquals(RunningAHEAD.NAME)) {
        //   uploader = new RunningAHEAD(this);
        //} else if (uploaderName.contentEquals(RunnerUpLive.NAME)) {
        //  uploader = new RunnerUpLive(this);
        // } else if (uploaderName.contentEquals(DigifitUploader.NAME)) {
        //   uploader = new DigifitUploader(this);
    } else if (uploaderName.contentEquals(Strava.NAME)) {
        uploader = new Strava(this);
    } else if (uploaderName.contentEquals(Facebook.NAME)) {
        uploader = new Facebook(context, this);
    } else if (uploaderName.contentEquals(GooglePlus.NAME)) {
        uploader = new GooglePlus(this);
    }

    if (uploader != null) {
        if (!config.containsKey(Constants.DB.ACCOUNT.FLAGS)) {
            if (BuildConfig.DEBUG) {
                String s = null;
                s.charAt(3);
            }
        }
        uploader.init(config);
        uploaders.put(uploaderName, uploader);
        uploadersById.put(uploader.getId(), uploader);
    }
    return uploader;
}

From source file:com.android.mail.browse.ConversationCursor.java

/**
 * Reset the cursor; this involves clearing out our cache map and resetting our various counts
 * The cursor should be reset whenever we get fresh data from the underlying cursor. The cache
 * is locked during the reset, which will block the UI, but for only a very short time
 * (estimated at a few ms, but we can profile this; remember that the cache will usually
 * be empty or have a few entries)//  ww  w .  ja  v  a2s  .  c o  m
 */
private void resetCursor(UnderlyingCursorWrapper newCursorWrapper) {
    synchronized (mCacheMapLock) {
        // Walk through the cache
        final Iterator<Map.Entry<String, ContentValues>> iter = mCacheMap.entrySet().iterator();
        final long now = System.currentTimeMillis();
        while (iter.hasNext()) {
            Map.Entry<String, ContentValues> entry = iter.next();
            final ContentValues values = entry.getValue();
            final String key = entry.getKey();
            boolean withinTimeWindow = false;
            boolean removed = false;
            if (values != null) {
                Long updateTime = values.getAsLong(UPDATE_TIME_COLUMN);
                if (updateTime != null && ((now - updateTime) < REQUERY_ALLOWANCE_TIME)) {
                    LogUtils.d(LOG_TAG, "IN resetCursor, keep recent changes to %s", key);
                    withinTimeWindow = true;
                } else if (updateTime == null) {
                    LogUtils.e(LOG_TAG, "null updateTime from mCacheMap for key: %s", key);
                }
                if (values.containsKey(DELETED_COLUMN)) {
                    // Item is deleted locally AND deleted in the new cursor.
                    if (!newCursorWrapper.contains(key)) {
                        // Keep the deleted count up-to-date; remove the
                        // cache entry
                        mDeletedCount--;
                        removed = true;
                        LogUtils.i(LOG_TAG, "IN resetCursor, sDeletedCount decremented to: %d by %s",
                                mDeletedCount,
                                (LogUtils.isLoggable(LOG_TAG, LogUtils.DEBUG)) ? key : "[redacted]");
                    }
                }
            } else {
                LogUtils.e(LOG_TAG, "null ContentValues from mCacheMap for key: %s", key);
            }
            // Remove the entry if it was time for an update or the item was deleted by the user.
            if (!withinTimeWindow || removed) {
                iter.remove();
            }
        }

        // Swap cursor
        if (mUnderlyingCursor != null) {
            close();
        }
        mUnderlyingCursor = newCursorWrapper;

        mPosition = -1;
        mUnderlyingCursor.moveToPosition(mPosition);
        if (!mCursorObserverRegistered) {
            mUnderlyingCursor.registerContentObserver(mCursorObserver);
            mCursorObserverRegistered = true;

        }
        mRefreshRequired = false;

        // If the underlying cursor has received an update before we have gotten to this
        // point, we will want to make sure to refresh
        final boolean underlyingCursorUpdated = mUnderlyingCursor.isDataUpdated();
        mUnderlyingCursor.disableUpdateNotifications();
        if (underlyingCursorUpdated) {
            underlyingChanged();
        }
    }
    if (DEBUG)
        LogUtils.i(LOG_TAG, "OUT resetCursor, this=%s", this);
}

From source file:at.bitfire.ical4android.AndroidEvent.java

protected void populateEvent(ContentValues values) {
    event.summary = values.getAsString(Events.TITLE);
    event.location = values.getAsString(Events.EVENT_LOCATION);
    event.description = values.getAsString(Events.DESCRIPTION);

    final boolean allDay = values.getAsInteger(Events.ALL_DAY) != 0;
    final long tsStart = values.getAsLong(Events.DTSTART);
    final String duration = values.getAsString(Events.DURATION);

    String tzId;//from   w w  w . jav a2  s  .  c o  m
    Long tsEnd = values.getAsLong(Events.DTEND);
    if (allDay) {
        event.setDtStart(tsStart, null);
        if (tsEnd == null) {
            Dur dur = new Dur(duration);
            java.util.Date dEnd = dur.getTime(new java.util.Date(tsStart));
            tsEnd = dEnd.getTime();
        }
        event.setDtEnd(tsEnd, null);

    } else {
        // use the start time zone for the end time, too
        // because apps like Samsung Planner allow the user to change "the" time zone but change the start time zone only
        tzId = values.getAsString(Events.EVENT_TIMEZONE);
        event.setDtStart(tsStart, tzId);
        if (tsEnd != null)
            event.setDtEnd(tsEnd, tzId);
        else if (!StringUtils.isEmpty(duration))
            event.duration = new Duration(new Dur(duration));
    }

    // recurrence
    try {
        String strRRule = values.getAsString(Events.RRULE);
        if (!StringUtils.isEmpty(strRRule))
            event.rRule = new RRule(strRRule);

        String strRDate = values.getAsString(Events.RDATE);
        if (!StringUtils.isEmpty(strRDate)) {
            RDate rDate = (RDate) DateUtils.androidStringToRecurrenceSet(strRDate, RDate.class, allDay);
            event.getRDates().add(rDate);
        }

        String strExRule = values.getAsString(Events.EXRULE);
        if (!StringUtils.isEmpty(strExRule)) {
            ExRule exRule = new ExRule();
            exRule.setValue(strExRule);
            event.exRule = exRule;
        }

        String strExDate = values.getAsString(Events.EXDATE);
        if (!StringUtils.isEmpty(strExDate)) {
            ExDate exDate = (ExDate) DateUtils.androidStringToRecurrenceSet(strExDate, ExDate.class, allDay);
            event.getExDates().add(exDate);
        }
    } catch (ParseException ex) {
        Log.w(TAG, "Couldn't parse recurrence rules, ignoring", ex);
    } catch (IllegalArgumentException ex) {
        Log.w(TAG, "Invalid recurrence rules, ignoring", ex);
    }

    if (values.containsKey(Events.ORIGINAL_INSTANCE_TIME)) {
        // this event is an exception of a recurring event
        long originalInstanceTime = values.getAsLong(Events.ORIGINAL_INSTANCE_TIME);

        boolean originalAllDay = false;
        if (values.containsKey(Events.ORIGINAL_ALL_DAY))
            originalAllDay = values.getAsInteger(Events.ORIGINAL_ALL_DAY) != 0;

        Date originalDate = originalAllDay ? new Date(originalInstanceTime)
                : new DateTime(originalInstanceTime);
        if (originalDate instanceof DateTime)
            ((DateTime) originalDate).setUtc(true);
        event.recurrenceId = new RecurrenceId(originalDate);
    }

    // status
    if (values.containsKey(Events.STATUS))
        switch (values.getAsInteger(Events.STATUS)) {
        case Events.STATUS_CONFIRMED:
            event.status = Status.VEVENT_CONFIRMED;
            break;
        case Events.STATUS_TENTATIVE:
            event.status = Status.VEVENT_TENTATIVE;
            break;
        case Events.STATUS_CANCELED:
            event.status = Status.VEVENT_CANCELLED;
        }

    // availability
    event.opaque = values.getAsInteger(Events.AVAILABILITY) != Events.AVAILABILITY_FREE;

    // set ORGANIZER if there's attendee data
    if (values.getAsInteger(Events.HAS_ATTENDEE_DATA) != 0 && values.containsKey(Events.ORGANIZER))
        try {
            event.organizer = new Organizer(new URI("mailto", values.getAsString(Events.ORGANIZER), null));
        } catch (URISyntaxException ex) {
            Log.e(TAG, "Error when creating ORGANIZER mailto URI, ignoring", ex);
        }

    // classification
    switch (values.getAsInteger(Events.ACCESS_LEVEL)) {
    case Events.ACCESS_CONFIDENTIAL:
    case Events.ACCESS_PRIVATE:
        event.forPublic = false;
        break;
    case Events.ACCESS_PUBLIC:
        event.forPublic = true;
    }
}

From source file:org.runnerup.export.UploadManager.java

@SuppressWarnings("null")
public Uploader add(ContentValues config) {
    if (config == null) {
        System.err.println("Add null!");
        assert (false);
        return null;
    }//w  ww  .  java 2  s . c  o  m

    String uploaderName = config.getAsString(DB.ACCOUNT.NAME);
    if (uploaderName == null) {
        System.err.println("name not found!");
        return null;
    }
    if (uploaders.containsKey(uploaderName)) {
        return uploaders.get(uploaderName);
    }
    Uploader uploader = null;
    if (uploaderName.contentEquals(RunKeeperUploader.NAME)) {
        uploader = new RunKeeperUploader(this);
    } else if (uploaderName.contentEquals(GarminUploader.NAME)) {
        uploader = new GarminUploader(this);
    } else if (uploaderName.contentEquals(FunBeatUploader.NAME)) {
        uploader = new FunBeatUploader(this);
    } else if (uploaderName.contentEquals(MapMyRunUploader.NAME)) {
        uploader = new MapMyRunUploader(this);
    } else if (uploaderName.contentEquals(NikePlus.NAME)) {
        uploader = new NikePlus(this);
    } else if (uploaderName.contentEquals(JoggSE.NAME)) {
        uploader = new JoggSE(this);
    } else if (uploaderName.contentEquals(Endomondo.NAME)) {
        uploader = new Endomondo(this);
    } else if (uploaderName.contentEquals(RunningAHEAD.NAME)) {
        uploader = new RunningAHEAD(this);
    } else if (uploaderName.contentEquals(RunnerUpLive.NAME)) {
        uploader = new RunnerUpLive(context);
    } else if (uploaderName.contentEquals(DigifitUploader.NAME)) {
        uploader = new DigifitUploader(this);
    } else if (uploaderName.contentEquals(Strava.NAME)) {
        uploader = new Strava(this);
    } else if (uploaderName.contentEquals(Facebook.NAME)) {
        uploader = new Facebook(context, this);
    } else if (uploaderName.contentEquals(GooglePlus.NAME)) {
        uploader = new GooglePlus(this);
    } else if (uploaderName.contentEquals(RuntasticUploader.NAME)) {
        uploader = new RuntasticUploader(this);
    } else if (uploaderName.contentEquals(GoogleFitUploader.NAME)) {
        uploader = new GoogleFitUploader(context, this);
    }

    if (uploader != null) {
        if (!config.containsKey(DB.ACCOUNT.FLAGS)) {
            if (BuildConfig.DEBUG) {
                String s = null;
                s.charAt(3);
            }
        }
        uploader.init(config);
        uploaders.put(uploaderName, uploader);
        uploadersById.put(uploader.getId(), uploader);
    }
    return uploader;
}

From source file:org.opendatakit.services.instance.provider.InstanceProvider.java

@Override
public synchronized int update(@NonNull Uri uri, ContentValues cv, String where, String[] whereArgs) {
    possiblyWaitForContentProviderDebugger();

    List<String> segments = uri.getPathSegments();

    if (segments.size() != 3) {
        throw new SQLException("Unknown URI (does not specify instance!) " + uri);
    }//from   w  ww .j a v a 2s  .c  om

    String appName = segments.get(0);
    ODKFileUtils.verifyExternalStorageAvailability();
    ODKFileUtils.assertDirectoryStructure(appName);

    String tableId = segments.get(1);
    // _ID in UPLOADS_TABLE_NAME
    String instanceId = segments.get(2);

    DbHandle dbHandleName = OdkConnectionFactorySingleton.getOdkConnectionFactoryInterface()
            .generateInternalUseDbHandle();
    OdkConnectionInterface db = null;
    int count = 0;
    try {
        // +1 referenceCount if db is returned (non-null)
        db = OdkConnectionFactorySingleton.getOdkConnectionFactoryInterface().getConnection(appName,
                dbHandleName);
        db.beginTransactionNonExclusive();

        boolean success = false;
        try {
            success = ODKDatabaseImplUtils.get().hasTableId(db, tableId);
        } catch (Exception e) {
            WebLogger.getLogger(appName).printStackTrace(e);
            throw new SQLException("Unknown URI (exception testing for tableId) " + uri);
        }
        if (!success) {
            throw new SQLException("Unknown URI (missing data table for tableId) " + uri);
        }

        internalUpdate(db, uri, appName, tableId);

        // run the query to get all the ids...
        List<IdStruct> idStructs = new ArrayList<IdStruct>();
        Cursor ref = null;
        try {
            // use this provider's query interface to get the set of ids that
            // match (if any)
            ref = internalQuery(db, uri, appName, tableId, instanceId, null, where, whereArgs, null);
            ref.moveToFirst();
            if (ref.getCount() != 0) {
                do {
                    String iId = CursorUtils.getIndexAsString(ref, ref.getColumnIndex(InstanceColumns._ID));
                    String iIdDataTable = CursorUtils.getIndexAsString(ref,
                            ref.getColumnIndex(InstanceColumns.DATA_INSTANCE_ID));
                    idStructs.add(new IdStruct(iId, iIdDataTable));
                } while (ref.moveToNext());
            }
        } finally {
            if (ref != null) {
                ref.close();
            }
        }

        // update the values string...
        if (cv.containsKey(InstanceColumns.XML_PUBLISH_STATUS)) {
            Date xmlPublishDate = new Date();
            cv.put(InstanceColumns.XML_PUBLISH_TIMESTAMP,
                    TableConstants.nanoSecondsFromMillis(xmlPublishDate.getTime()));
            String xmlPublishStatus = cv.getAsString(InstanceColumns.XML_PUBLISH_STATUS);
            if (!cv.containsKey(InstanceColumns.DISPLAY_SUBTEXT)) {
                String text = getDisplaySubtext(xmlPublishStatus, xmlPublishDate);
                cv.put(InstanceColumns.DISPLAY_SUBTEXT, text);
            }
        }

        Map<String, Object> values = new HashMap<String, Object>();
        for (String key : cv.keySet()) {
            values.put(key, cv.get(key));
        }

        Object[] args = new String[1];
        for (IdStruct idStruct : idStructs) {
            args[0] = idStruct.idUploadsTable;
            count += db.update(DatabaseConstants.UPLOADS_TABLE_NAME, values, InstanceColumns._ID + "=?", args);
        }
        db.setTransactionSuccessful();
    } finally {
        if (db != null) {
            try {
                if (db.inTransaction()) {
                    db.endTransaction();
                }
            } finally {
                try {
                    db.releaseReference();
                } finally {
                    // this closes the connection
                    OdkConnectionFactorySingleton.getOdkConnectionFactoryInterface().removeConnection(appName,
                            dbHandleName);
                }
            }
        }
    }
    getContext().getContentResolver().notifyChange(uri, null);
    return count;
}

From source file:at.bitfire.davdroid.resource.LocalCalendar.java

protected void populateEvent(Event e, ContentValues values) {
    e.setUid(values.getAsString(entryColumnUID()));

    e.summary = values.getAsString(Events.TITLE);
    e.location = values.getAsString(Events.EVENT_LOCATION);
    e.description = values.getAsString(Events.DESCRIPTION);

    final boolean allDay = values.getAsInteger(Events.ALL_DAY) != 0;
    final long tsStart = values.getAsLong(Events.DTSTART);
    final String duration = values.getAsString(Events.DURATION);

    String tzId;/*from   www  .  j av  a2  s. c  o  m*/
    Long tsEnd = values.getAsLong(Events.DTEND);
    if (allDay) {
        e.setDtStart(tsStart, null);
        if (tsEnd == null) {
            Dur dur = new Dur(duration);
            java.util.Date dEnd = dur.getTime(new java.util.Date(tsStart));
            tsEnd = dEnd.getTime();
        }
        e.setDtEnd(tsEnd, null);

    } else {
        // use the start time zone for the end time, too
        // because apps like Samsung Planner allow the user to change "the" time zone but change the start time zone only
        tzId = values.getAsString(Events.EVENT_TIMEZONE);
        e.setDtStart(tsStart, tzId);
        if (tsEnd != null)
            e.setDtEnd(tsEnd, tzId);
        else if (!StringUtils.isEmpty(duration))
            e.duration = new Duration(new Dur(duration));
    }

    // recurrence
    try {
        String strRRule = values.getAsString(Events.RRULE);
        if (!StringUtils.isEmpty(strRRule))
            e.rrule = new RRule(strRRule);

        String strRDate = values.getAsString(Events.RDATE);
        if (!StringUtils.isEmpty(strRDate)) {
            RDate rDate = (RDate) DateUtils.androidStringToRecurrenceSet(strRDate, RDate.class, allDay);
            e.getRdates().add(rDate);
        }

        String strExRule = values.getAsString(Events.EXRULE);
        if (!StringUtils.isEmpty(strExRule)) {
            ExRule exRule = new ExRule();
            exRule.setValue(strExRule);
            e.exrule = exRule;
        }

        String strExDate = values.getAsString(Events.EXDATE);
        if (!StringUtils.isEmpty(strExDate)) {
            ExDate exDate = (ExDate) DateUtils.androidStringToRecurrenceSet(strExDate, ExDate.class, allDay);
            e.getExdates().add(exDate);
        }
    } catch (ParseException ex) {
        Log.w(TAG, "Couldn't parse recurrence rules, ignoring", ex);
    } catch (IllegalArgumentException ex) {
        Log.w(TAG, "Invalid recurrence rules, ignoring", ex);
    }

    if (values.containsKey(Events.ORIGINAL_INSTANCE_TIME)) {
        // this event is an exception of a recurring event
        long originalInstanceTime = values.getAsLong(Events.ORIGINAL_INSTANCE_TIME);

        boolean originalAllDay = false;
        if (values.containsKey(Events.ORIGINAL_ALL_DAY))
            originalAllDay = values.getAsInteger(Events.ORIGINAL_ALL_DAY) != 0;

        Date originalDate = originalAllDay ? new Date(originalInstanceTime)
                : new DateTime(originalInstanceTime);
        if (originalDate instanceof DateTime)
            ((DateTime) originalDate).setUtc(true);
        e.recurrenceId = new RecurrenceId(originalDate);
    }

    // status
    if (values.containsKey(Events.STATUS))
        switch (values.getAsInteger(Events.STATUS)) {
        case Events.STATUS_CONFIRMED:
            e.status = Status.VEVENT_CONFIRMED;
            break;
        case Events.STATUS_TENTATIVE:
            e.status = Status.VEVENT_TENTATIVE;
            break;
        case Events.STATUS_CANCELED:
            e.status = Status.VEVENT_CANCELLED;
        }

    // availability
    e.opaque = values.getAsInteger(Events.AVAILABILITY) != Events.AVAILABILITY_FREE;

    // set ORGANIZER if there's attendee data
    if (values.getAsInteger(Events.HAS_ATTENDEE_DATA) != 0)
        try {
            e.organizer = new Organizer(new URI("mailto", values.getAsString(Events.ORGANIZER), null));
        } catch (URISyntaxException ex) {
            Log.e(TAG, "Error when creating ORGANIZER mailto URI, ignoring", ex);
        }

    // classification
    switch (values.getAsInteger(Events.ACCESS_LEVEL)) {
    case Events.ACCESS_CONFIDENTIAL:
    case Events.ACCESS_PRIVATE:
        e.forPublic = false;
        break;
    case Events.ACCESS_PUBLIC:
        e.forPublic = true;
    }
}

From source file:com.granita.icloudcalsync.resource.LocalCalendar.java

protected void populateEvent(Event e, ContentValues values) {
    e.setUid(values.getAsString(entryColumnUID()));

    e.setSummary(values.getAsString(Events.TITLE));
    e.setLocation(values.getAsString(Events.EVENT_LOCATION));
    e.setDescription(values.getAsString(Events.DESCRIPTION));

    final boolean allDay = values.getAsInteger(Events.ALL_DAY) != 0;
    final long tsStart = values.getAsLong(Events.DTSTART);
    final String duration = values.getAsString(Events.DURATION);

    String tzId = null;//from  w w w  . j  a va2 s .c om
    Long tsEnd = values.getAsLong(Events.DTEND);
    if (allDay) {
        e.setDtStart(tsStart, null);
        if (tsEnd == null) {
            Dur dur = new Dur(duration);
            java.util.Date dEnd = dur.getTime(new java.util.Date(tsStart));
            tsEnd = dEnd.getTime();
        }
        e.setDtEnd(tsEnd, null);

    } else {
        // use the start time zone for the end time, too
        // because apps like Samsung Planner allow the user to change "the" time zone but change the start time zone only
        tzId = values.getAsString(Events.EVENT_TIMEZONE);
        e.setDtStart(tsStart, tzId);
        if (tsEnd != null)
            e.setDtEnd(tsEnd, tzId);
        else if (!StringUtils.isEmpty(duration))
            e.setDuration(new Duration(new Dur(duration)));
    }

    // recurrence
    try {
        String strRRule = values.getAsString(Events.RRULE);
        if (!StringUtils.isEmpty(strRRule))
            e.setRrule(new RRule(strRRule));

        String strRDate = values.getAsString(Events.RDATE);
        if (!StringUtils.isEmpty(strRDate)) {
            RDate rDate = new RDate();
            rDate.setValue(strRDate);
            e.getRdates().add(rDate);
        }

        String strExRule = values.getAsString(Events.EXRULE);
        if (!StringUtils.isEmpty(strExRule)) {
            ExRule exRule = new ExRule();
            exRule.setValue(strExRule);
            e.setExrule(exRule);
        }

        String strExDate = values.getAsString(Events.EXDATE);
        if (!StringUtils.isEmpty(strExDate)) {
            // always empty, see https://code.google.com/p/android/issues/detail?id=172411
            ExDate exDate = new ExDate();
            exDate.setValue(strExDate);
            e.getExdates().add(exDate);
        }
    } catch (ParseException ex) {
        Log.w(TAG, "Couldn't parse recurrence rules, ignoring", ex);
    } catch (IllegalArgumentException ex) {
        Log.w(TAG, "Invalid recurrence rules, ignoring", ex);
    }

    if (values.containsKey(Events.ORIGINAL_INSTANCE_TIME)) {
        // this event is an exception of a recurring event
        long originalInstanceTime = values.getAsLong(Events.ORIGINAL_INSTANCE_TIME);
        boolean originalAllDay = values.getAsInteger(Events.ORIGINAL_ALL_DAY) != 0;
        Date originalDate = originalAllDay ? new Date(originalInstanceTime)
                : new DateTime(originalInstanceTime);
        if (originalDate instanceof DateTime)
            ((DateTime) originalDate).setUtc(true);
        e.setRecurrenceId(new RecurrenceId(originalDate));
    }

    // status
    if (values.containsKey(Events.STATUS))
        switch (values.getAsInteger(Events.STATUS)) {
        case Events.STATUS_CONFIRMED:
            e.setStatus(Status.VEVENT_CONFIRMED);
            break;
        case Events.STATUS_TENTATIVE:
            e.setStatus(Status.VEVENT_TENTATIVE);
            break;
        case Events.STATUS_CANCELED:
            e.setStatus(Status.VEVENT_CANCELLED);
        }

    // availability
    e.setOpaque(values.getAsInteger(Events.AVAILABILITY) != Events.AVAILABILITY_FREE);

    // set ORGANIZER only when there are attendees
    if (values.getAsInteger(Events.HAS_ATTENDEE_DATA) != 0 && values.containsKey(Events.ORGANIZER))
        try {
            e.setOrganizer(new Organizer(new URI("mailto", values.getAsString(Events.ORGANIZER), null)));
        } catch (URISyntaxException ex) {
            Log.e(TAG, "Error when creating ORGANIZER URI, ignoring", ex);
        }

    // classification
    switch (values.getAsInteger(Events.ACCESS_LEVEL)) {
    case Events.ACCESS_CONFIDENTIAL:
    case Events.ACCESS_PRIVATE:
        e.setForPublic(false);
        break;
    case Events.ACCESS_PUBLIC:
        e.setForPublic(true);
    }
}

From source file:org.opendatakit.sensors.manager.WorkerThread.java

private void parseSensorDataAndInsertIntoTable(ODKSensor aSensor, String strTableDef, Bundle dataBundle) {
    JSONObject jsonTableDef = null;/*from   w  ww  .  j  av a 2  s.  c  o m*/
    ContentValues tablesValues = new ContentValues();

    SQLiteDatabase db = null;
    try {
        db = DatabaseFactory.get().getDatabase(serviceContext, aSensor.getAppNameForDatabase());

        jsonTableDef = new JSONObject(strTableDef);

        String tableId = jsonTableDef.getJSONObject(ODKJsonNames.jsonTableStr)
                .getString(ODKJsonNames.jsonTableIdStr);

        if (tableId == null) {
            return;
        }

        boolean success;

        success = false;
        try {
            success = ODKDatabaseUtils.get().hasTableId(db, tableId);
        } catch (Exception e) {
            e.printStackTrace();
            throw new SQLException("Exception testing for tableId " + tableId);
        }
        if (!success) {
            sensorManager.parseDriverTableDefintionAndCreateTable(aSensor.getSensorID(),
                    aSensor.getAppNameForDatabase(), db);
        }

        success = false;
        try {
            success = ODKDatabaseUtils.get().hasTableId(db, tableId);
        } catch (Exception e) {
            e.printStackTrace();
            throw new SQLException("Exception testing for tableId " + tableId);
        }
        if (!success) {
            throw new SQLException("Unable to create tableId " + tableId);
        }

        ArrayList<ColumnDefinition> orderedDefs = TableUtil.get().getColumnDefinitions(db,
                aSensor.getAppNameForDatabase(), tableId);

        // Create the columns for the driver table
        for (ColumnDefinition col : orderedDefs) {
            if (!col.isUnitOfRetention()) {
                continue;
            }

            String colName = col.getElementKey();
            ElementType type = col.getType();

            if (colName.equals(DataSeries.SENSOR_ID)) {

                // special treatment
                tablesValues.put(colName, aSensor.getSensorID());

            } else if (type.getDataType() == ElementDataType.bool) {

                Boolean boolColData = dataBundle.containsKey(colName) ? dataBundle.getBoolean(colName) : null;
                Integer colData = (boolColData == null) ? null : (boolColData ? 1 : 0);
                tablesValues.put(colName, colData);

            } else if (type.getDataType() == ElementDataType.integer) {

                Integer colData = dataBundle.containsKey(colName) ? dataBundle.getInt(colName) : null;
                tablesValues.put(colName, colData);

            } else if (type.getDataType() == ElementDataType.number) {

                Double colData = dataBundle.containsKey(colName) ? dataBundle.getDouble(colName) : null;
                tablesValues.put(colName, colData);

            } else {
                // everything else is a string value coming across the wire...
                String colData = dataBundle.containsKey(colName) ? dataBundle.getString(colName) : null;
                tablesValues.put(colName, colData);
            }
        }

        if (tablesValues.size() > 0) {
            Log.i(TAG, "Writing db values for sensor:" + aSensor.getSensorID());
            String rowId = tablesValues.containsKey(DataTableColumns.ID)
                    ? tablesValues.getAsString(DataTableColumns.ID)
                    : null;
            if (rowId == null) {
                rowId = ODKDataUtils.genUUID();
            }
            ODKDatabaseUtils.get().insertDataIntoExistingDBTableWithId(db, tableId, orderedDefs, tablesValues,
                    rowId);
        }

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (db != null) {
            db.close();
        }
    }
}

From source file:com.fututel.db.DBProvider.java

@Override
public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    int count;/*from  w  ww. j  a  va  2  s  .  c  o  m*/
    String finalWhere;
    int matched = URI_MATCHER.match(uri);

    switch (matched) {
    case ACCOUNTS:
        count = db.update(SipProfile.ACCOUNTS_TABLE_NAME, values, where, whereArgs);
        break;
    case ACCOUNTS_ID:
        finalWhere = DatabaseUtilsCompat
                .concatenateWhere(SipProfile.FIELD_ID + " = " + ContentUris.parseId(uri), where);
        count = db.update(SipProfile.ACCOUNTS_TABLE_NAME, values, finalWhere, whereArgs);
        break;
    case CALLLOGS:
        count = db.update(SipManager.CALLLOGS_TABLE_NAME, values, where, whereArgs);
        break;
    case CALLLOGS_ID:
        finalWhere = DatabaseUtilsCompat.concatenateWhere(CallLog.Calls._ID + " = " + ContentUris.parseId(uri),
                where);
        count = db.update(SipManager.CALLLOGS_TABLE_NAME, values, finalWhere, whereArgs);
        break;
    case FILTERS:
        count = db.update(SipManager.FILTERS_TABLE_NAME, values, where, whereArgs);
        break;
    case FILTERS_ID:
        finalWhere = DatabaseUtilsCompat.concatenateWhere(Filter._ID + " = " + ContentUris.parseId(uri), where);
        count = db.update(SipManager.FILTERS_TABLE_NAME, values, finalWhere, whereArgs);
        break;
    case MESSAGES:
        count = db.update(SipMessage.MESSAGES_TABLE_NAME, values, where, whereArgs);
        break;
    case MESSAGES_ID:
        finalWhere = DatabaseUtilsCompat
                .concatenateWhere(SipMessage.FIELD_ID + " = " + ContentUris.parseId(uri), where);
        count = db.update(SipMessage.MESSAGES_TABLE_NAME, values, where, whereArgs);
        break;
    case ACCOUNTS_STATUS_ID:
        long id = ContentUris.parseId(uri);
        synchronized (profilesStatus) {
            SipProfileState ps = new SipProfileState();
            if (profilesStatus.containsKey(id)) {
                ContentValues currentValues = profilesStatus.get(id);
                ps.createFromContentValue(currentValues);
            }
            ps.createFromContentValue(values);
            ContentValues cv = ps.getAsContentValue();
            cv.put(SipProfileState.ACCOUNT_ID, id);
            profilesStatus.put(id, cv);
            Log.d(THIS_FILE, "Updated " + cv);
        }
        count = 1;
        break;
    default:
        throw new IllegalArgumentException(UNKNOWN_URI_LOG + uri);
    }

    getContext().getContentResolver().notifyChange(uri, null);

    long rowId = -1;
    if (matched == ACCOUNTS_ID || matched == ACCOUNTS_STATUS_ID) {
        rowId = ContentUris.parseId(uri);
    }
    if (rowId >= 0) {
        if (matched == ACCOUNTS_ID) {
            // Don't broadcast if we only changed wizard or only changed priority
            boolean doBroadcast = true;
            if (values.size() == 1) {
                if (values.containsKey(SipProfile.FIELD_WIZARD)) {
                    doBroadcast = false;
                } else if (values.containsKey(SipProfile.FIELD_PRIORITY)) {
                    doBroadcast = false;
                }
            }
            if (doBroadcast) {
                broadcastAccountChange(rowId);
            }
        } else if (matched == ACCOUNTS_STATUS_ID) {
            broadcastRegistrationChange(rowId);
        }
    }
    if (matched == FILTERS || matched == FILTERS_ID) {
        Filter.resetCache();
    }

    return count;
}

From source file:org.runnerup.export.SyncManager.java

@SuppressWarnings("null")
public Synchronizer add(ContentValues config) {
    if (config == null) {
        Log.e(getClass().getName(), "Add null!");
        assert (false);
        return null;
    }/*from w ww .j a v  a2  s .  c  o m*/

    String synchronizerName = config.getAsString(DB.ACCOUNT.NAME);
    if (synchronizerName == null) {
        Log.e(getClass().getName(), "name not found!");
        return null;
    }
    if (synchronizers.containsKey(synchronizerName)) {
        return synchronizers.get(synchronizerName);
    }
    Synchronizer synchronizer = null;
    if (synchronizerName.contentEquals(RunKeeperSynchronizer.NAME)) {
        synchronizer = new RunKeeperSynchronizer(this);
    } else if (synchronizerName.contentEquals(GarminSynchronizer.NAME)) {
        synchronizer = new GarminSynchronizer(this);
    } else if (synchronizerName.contentEquals(FunBeatSynchronizer.NAME)) {
        synchronizer = new FunBeatSynchronizer(this);
    } else if (synchronizerName.contentEquals(MapMyRunSynchronizer.NAME)) {
        synchronizer = new MapMyRunSynchronizer(this);
    } else if (synchronizerName.contentEquals(NikePlusSynchronizer.NAME)) {
        synchronizer = new NikePlusSynchronizer(this);
    } else if (synchronizerName.contentEquals(JoggSESynchronizer.NAME)) {
        synchronizer = new JoggSESynchronizer(this);
    } else if (synchronizerName.contentEquals(EndomondoSynchronizer.NAME)) {
        synchronizer = new EndomondoSynchronizer(this);
    } else if (synchronizerName.contentEquals(RunningAHEADSynchronizer.NAME)) {
        synchronizer = new RunningAHEADSynchronizer(this);
    } else if (synchronizerName.contentEquals(RunnerUpLiveSynchronizer.NAME)) {
        synchronizer = new RunnerUpLiveSynchronizer(mContext);
    } else if (synchronizerName.contentEquals(DigifitSynchronizer.NAME)) {
        synchronizer = new DigifitSynchronizer(this);
    } else if (synchronizerName.contentEquals(StravaSynchronizer.NAME)) {
        synchronizer = new StravaSynchronizer(this);
    } else if (synchronizerName.contentEquals(FacebookSynchronizer.NAME)) {
        synchronizer = new FacebookSynchronizer(mContext, this);
    } else if (synchronizerName.contentEquals(GooglePlusSynchronizer.NAME)) {
        synchronizer = new GooglePlusSynchronizer(this);
    } else if (synchronizerName.contentEquals(RuntasticSynchronizer.NAME)) {
        synchronizer = new RuntasticSynchronizer(this);
    } else if (synchronizerName.contentEquals(GoogleFitSynchronizer.NAME)) {
        synchronizer = new GoogleFitSynchronizer(mContext, this);
    } else if (synchronizerName.contentEquals(RunningFreeOnlineSynchronizer.NAME)) {
        synchronizer = new RunningFreeOnlineSynchronizer();
    }

    if (synchronizer != null) {
        if (!config.containsKey(DB.ACCOUNT.FLAGS)) {
            if (BuildConfig.DEBUG) {
                String s = null;
                s.charAt(3);
            }
        }
        synchronizer.init(config);
        synchronizer.setAuthNotice(config.getAsInteger(Constants.DB.ACCOUNT.AUTH_NOTICE));
        synchronizers.put(synchronizerName, synchronizer);
        synchronizersById.put(synchronizer.getId(), synchronizer);
    }
    return synchronizer;
}