Example usage for android.content ContentValues getAsLong

List of usage examples for android.content ContentValues getAsLong

Introduction

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

Prototype

public Long getAsLong(String key) 

Source Link

Document

Gets a value and converts it to a Long.

Usage

From source file:org.anhonesteffort.flock.sync.calendar.EventFactory.java

private static void handleAddPropertiesForDeletionExceptionToRecurring(String path, ContentValues eventValues,
        VEvent vEvent) throws InvalidComponentException {
    Log.w(TAG, "gonna try and export deletion exception from androids recurrence model...");
    vEvent.getProperties().add(Status.VEVENT_CANCELLED);

    Long originalLocalId = eventValues.getAsLong(CalendarContract.Events.ORIGINAL_ID);
    String originalSyncId = eventValues.getAsString(CalendarContract.Events.ORIGINAL_SYNC_ID);
    String syncId = eventValues.getAsString(CalendarContract.Events._SYNC_ID);

    if (TextUtils.isEmpty(originalSyncId))
        throw new InvalidComponentException("original sync id required on recurring event deletion exceptions",
                false, CalDavConstants.CALDAV_NAMESPACE, path);

    if (originalLocalId == null || originalLocalId < 1)
        throw new InvalidComponentException("original local id required on recurring event deletion exceptions",
                false, CalDavConstants.CALDAV_NAMESPACE, path);

    if (vEvent.getUid() == null)
        vEvent.getProperties().add(new Uid(syncId));
    else if (vEvent.getUid().getValue() == null)
        vEvent.getUid().setValue(syncId);

    XProperty originalSyncIdProp = new XProperty(PROPERTY_NAME_FLOCK_ORIGINAL_SYNC_ID, originalSyncId);
    vEvent.getProperties().add(originalSyncIdProp);
}

From source file:com.goliathonline.android.kegbot.io.RemoteUserHandler.java

/** {@inheritDoc} */
@Override// w  ww .j a v a2 s. co  m
public ArrayList<ContentProviderOperation> parse(JSONObject parser, ContentResolver resolver)
        throws JSONException, IOException {
    final ArrayList<ContentProviderOperation> batch = Lists.newArrayList();

    // Walk document, parsing any incoming entries
    if (!parser.has("result"))
        return batch;
    JSONObject result = parser.getJSONObject("result");
    JSONObject keg = result.getJSONObject("user");

    final String userId = sanitizeId(keg.getString("username"));
    final Uri userUri = Users.buildUserUri(userId);

    // Check for existing details, only update when changed
    final ContentValues values = queryUserDetails(userUri, resolver);
    final long localUpdated = values.getAsLong(SyncColumns.UPDATED);
    final long serverUpdated = 500; //entry.getUpdated();
    if (Log.isLoggable(TAG, Log.VERBOSE)) {
        Log.v(TAG, "found user " + userId);
        Log.v(TAG, "found localUpdated=" + localUpdated + ", server=" + serverUpdated);
    }

    // Clear any existing values for this session, treating the
    // incoming details as authoritative.
    batch.add(ContentProviderOperation.newDelete(userUri).build());

    final ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(Users.CONTENT_URI);

    builder.withValue(SyncColumns.UPDATED, serverUpdated);
    builder.withValue(Users.USER_ID, userId);

    if (keg.has("image")) {
        JSONObject image = keg.getJSONObject("image");
        if (image.has("url"))
            builder.withValue(Users.USER_IMAGE_URL, image.getString("url"));
    }

    // Normal session details ready, write to provider
    batch.add(builder.build());

    return batch;
}

From source file:export.RunnerUpLive.java

@Override
public void init(ContentValues config) {
    id = config.getAsLong("_id");
    String auth = config.getAsString(DB.ACCOUNT.AUTH_CONFIG);
    if (auth != null) {
        try {//from  www.j  av a2  s  . c  o  m
            JSONObject tmp = new JSONObject(auth);
            username = tmp.optString("username", null);
            password = tmp.optString("password", null);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.goliathonline.android.kegbot.io.RemoteKegHandler.java

/** {@inheritDoc} */
@Override//w ww  .ja va 2  s  .  c  om
public ArrayList<ContentProviderOperation> parse(JSONObject parser, ContentResolver resolver)
        throws JSONException, IOException {
    final ArrayList<ContentProviderOperation> batch = Lists.newArrayList();

    // Walk document, parsing any incoming entries
    JSONObject result = parser.getJSONObject("result");
    JSONObject keg = result.getJSONObject("keg");
    JSONObject type = result.getJSONObject("type");
    JSONObject image = type.getJSONObject("image");

    final String kegId = sanitizeId(keg.getString("id"));
    final Uri kegUri = Kegs.buildKegUri(kegId);

    // Check for existing details, only update when changed
    final ContentValues values = queryKegDetails(kegUri, resolver);
    final long localUpdated = values.getAsLong(SyncColumns.UPDATED);
    final long serverUpdated = 500; //entry.getUpdated();
    if (Log.isLoggable(TAG, Log.VERBOSE)) {
        Log.v(TAG, "found keg " + kegId);
        Log.v(TAG, "found localUpdated=" + localUpdated + ", server=" + serverUpdated);
    }

    // Clear any existing values for this session, treating the
    // incoming details as authoritative.
    batch.add(ContentProviderOperation.newDelete(kegUri).build());

    final ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(Kegs.CONTENT_URI);

    builder.withValue(SyncColumns.UPDATED, serverUpdated);
    builder.withValue(Kegs.KEG_ID, kegId);

    // Inherit starred value from previous row
    if (values.containsKey(Kegs.KEG_STARRED)) {
        builder.withValue(Kegs.KEG_STARRED, values.getAsInteger(Kegs.KEG_STARRED));
    }

    if (keg.has("status"))
        builder.withValue(Kegs.STATUS, keg.getString("status"));

    if (keg.has("volume_ml_remain"))
        builder.withValue(Kegs.VOLUME_REMAIN, keg.getDouble("volume_ml_remain"));

    if (keg.has("description"))
        builder.withValue(Kegs.DESCRIPTION, keg.getString("description"));

    if (keg.has("type_id"))
        builder.withValue(Kegs.TYPE_ID, keg.getString("type_id"));

    if (keg.has("size_id"))
        builder.withValue(Kegs.SIZE_ID, keg.getInt("size_id"));

    if (keg.has("percent_full"))
        builder.withValue(Kegs.PERCENT_FULL, keg.getDouble("percent_full"));

    if (keg.has("size_name"))
        builder.withValue(Kegs.SIZE_NAME, keg.getString("size_name"));

    if (keg.has("spilled_ml"))
        builder.withValue(Kegs.VOLUME_SPILL, keg.getDouble("spilled_ml"));

    if (keg.has("size_volume_ml"))
        builder.withValue(Kegs.VOLUME_SIZE, keg.getDouble("size_volume_ml"));

    if (type.has("name"))
        builder.withValue(Kegs.KEG_NAME, type.getString("name"));

    if (type.has("abv"))
        builder.withValue(Kegs.KEG_ABV, type.getDouble("abv"));

    if (image.has("url"))
        builder.withValue(Kegs.IMAGE_URL, image.getString("url"));

    // Normal keg details ready, write to provider
    batch.add(builder.build());

    return batch;
}

From source file:com.goliathonline.android.kegbot.io.RemoteTapHandler.java

/** {@inheritDoc} */
@Override//from   w  ww .j a  v  a 2 s  .  c  o m
public ArrayList<ContentProviderOperation> parse(JSONObject parser, ContentResolver resolver)
        throws JSONException, IOException {
    final ArrayList<ContentProviderOperation> batch = Lists.newArrayList();

    if (parser.has("result")) {
        JSONObject events = parser.getJSONObject("result");
        JSONArray resultArray = events.getJSONArray("taps");
        int numKegs = resultArray.length();

        JSONObject taps;
        for (int i = 0; i < numKegs; i++) {
            taps = resultArray.getJSONObject(i);

            JSONObject keg = taps.getJSONObject("keg");
            JSONObject tap = taps.getJSONObject("tap");
            JSONObject beer = taps.getJSONObject("beer_type");
            JSONObject image = beer.getJSONObject("image");

            final String tapId = sanitizeId(tap.getString("id"));
            final Uri tapUri = Taps.buildTapUri(tapId);

            // Check for existing details, only update when changed
            final ContentValues values = queryTapDetails(tapUri, resolver);
            final long localUpdated = values.getAsLong(SyncColumns.UPDATED);
            final long serverUpdated = 500; //entry.getUpdated();
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                Log.v(TAG, "found tap " + tapId);
                Log.v(TAG, "found localUpdated=" + localUpdated + ", server=" + serverUpdated);
            }

            // Clear any existing values for this session, treating the
            // incoming details as authoritative.
            batch.add(ContentProviderOperation.newDelete(tapUri).build());

            final ContentProviderOperation.Builder builder = ContentProviderOperation
                    .newInsert(Taps.CONTENT_URI);

            builder.withValue(SyncColumns.UPDATED, serverUpdated);
            builder.withValue(Taps.TAP_ID, tapId);

            if (tap.has("name"))
                builder.withValue(Taps.TAP_NAME, tap.getString("name"));

            if (tap.has("current_keg_id"))
                builder.withValue(Taps.KEG_ID, tap.getDouble("current_keg_id"));

            if (keg.has("status"))
                builder.withValue(Taps.STATUS, keg.getString("status"));

            if (keg.has("percent_full"))
                builder.withValue(Taps.PERCENT_FULL, keg.getString("percent_full"));

            if (keg.has("size_name"))
                builder.withValue(Taps.SIZE_NAME, keg.getString("size_name"));

            if (keg.has("volume_ml_remain"))
                builder.withValue(Taps.VOL_REMAIN, keg.getDouble("volume_ml_remain"));

            if (keg.has("size_volume_ml"))
                builder.withValue(Taps.VOL_SIZE, keg.getDouble("size_volume_ml"));

            if (beer.has("name"))
                builder.withValue(Taps.BEER_NAME, beer.getString("name"));

            if (keg.has("description"))
                builder.withValue(Taps.DESCRIPTION, keg.getString("description"));

            JSONObject last_temp = tap.getJSONObject("last_temperature");

            if (last_temp.has("temperature_c"))
                builder.withValue(Taps.LAST_TEMP, last_temp.getString("temperature_c"));

            if (last_temp.has("record_time"))
                builder.withValue(Taps.LAST_TEMP_TIME, last_temp.getString("record_time"));

            if (image.has("url"))
                builder.withValue(Taps.IMAGE_URL, image.getString("url"));

            // Normal tap details ready, write to provider
            batch.add(builder.build());
        }
    }

    return batch;
}

From source file:com.goliathonline.android.kegbot.io.RemoteDrinksHandler.java

/** {@inheritDoc} */
@Override/* w w w .j  av a 2 s . c  o  m*/
public ArrayList<ContentProviderOperation> parse(JSONObject parser, ContentResolver resolver)
        throws JSONException, IOException {
    final ArrayList<ContentProviderOperation> batch = Lists.newArrayList();

    // Walk document, parsing any incoming entries
    int drink_id = 0;
    JSONObject result = parser.getJSONObject("result");
    JSONArray drinks = result.getJSONArray("drinks");
    JSONObject drink;
    for (int i = 0; i < drinks.length(); i++) {
        if (drink_id == 0) { // && ENTRY.equals(parser.getName()
            // Process single spreadsheet row at a time
            drink = drinks.getJSONObject(i);
            final String drinkId = sanitizeId(drink.getString("id"));
            final Uri drinkUri = Drinks.buildDrinkUri(drinkId);

            // Check for existing details, only update when changed
            final ContentValues values = queryDrinkDetails(drinkUri, resolver);
            final long localUpdated = values.getAsLong(SyncColumns.UPDATED);
            final long serverUpdated = 500; //entry.getUpdated();
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                Log.v(TAG, "found drink " + drinkId);
                Log.v(TAG, "found localUpdated=" + localUpdated + ", server=" + serverUpdated);
            }
            if (localUpdated != KegbotContract.UPDATED_NEVER)
                continue;

            final Uri drinkKegUri = Drinks.buildKegUri(drinkId);
            final Uri drinkUserUri = Drinks.buildUserUri(drinkId);

            // Clear any existing values for this session, treating the
            // incoming details as authoritative.
            batch.add(ContentProviderOperation.newDelete(drinkUri).build());
            batch.add(ContentProviderOperation.newDelete(drinkKegUri).build());

            final ContentProviderOperation.Builder builder = ContentProviderOperation
                    .newInsert(Drinks.CONTENT_URI);

            builder.withValue(SyncColumns.UPDATED, serverUpdated);
            builder.withValue(Drinks.DRINK_ID, drinkId);

            // Inherit starred value from previous row
            if (values.containsKey(Drinks.DRINK_STARRED)) {
                builder.withValue(Drinks.DRINK_STARRED, values.getAsInteger(Drinks.DRINK_STARRED));
            }

            if (drink.has("session_id"))
                builder.withValue(Drinks.SESSION_ID, drink.getInt("session_id"));
            if (drink.has("status"))
                builder.withValue(Drinks.STATUS, drink.getString("status"));
            if (drink.has("user_id"))
                builder.withValue(Drinks.USER_ID, drink.getString("user_id"));
            if (drink.has("keg_id"))
                builder.withValue(Drinks.KEG_ID, drink.getInt("keg_id"));
            if (drink.has("volume_ml"))
                builder.withValue(Drinks.VOLUME, drink.getDouble("volume_ml"));
            if (drink.has("pour_time"))
                builder.withValue(Drinks.POUR_TIME, drink.getString("pour_time"));

            // Normal session details ready, write to provider
            batch.add(builder.build());

            // Assign kegs
            final int kegId = drink.getInt("keg_id");
            batch.add(ContentProviderOperation.newInsert(drinkKegUri).withValue(DrinksKeg.DRINK_ID, drinkId)
                    .withValue(DrinksKeg.KEG_ID, kegId).build());

            // Assign users
            if (drink.has("user_id")) {
                final String userId = drink.getString("user_id");
                batch.add(ContentProviderOperation.newInsert(drinkUserUri)
                        .withValue(DrinksUser.DRINK_ID, drinkId).withValue(DrinksUser.USER_ID, userId).build());
            }
        }
    }

    return batch;
}

From source file:com.partypoker.poker.engagement.reach.EngagementReachContent.java

/**
 * Set content status./*from  ww  w  .  j ava2  s.c om*/
 * @param values values from storage.
 */
void setState(ContentValues values) {
    mDownloadId = values.getAsLong(com.microsoft.azure.engagement.reach.ContentStorage.DOWNLOAD_ID);
}

From source file:export.MapMyRunUploader.java

@Override
public void init(ContentValues config) {
    id = config.getAsLong("_id");
    String authToken = config.getAsString(DB.ACCOUNT.AUTH_CONFIG);
    if (authToken != null) {
        try {//  w  ww .  j  a  v  a  2s. co  m
            JSONObject tmp = new JSONObject(authToken);
            username = tmp.optString("username", null);
            password = tmp.optString("password", null);
            md5pass = tmp.optString("md5pass", null);
            user_id = tmp.optString("user_id", null);
            user_key = tmp.optString("user_key", null);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}

From source file:net.eledge.android.toolkit.db.abstracts.Dao.java

public long store(E entity) {
    String idField = SQLBuilder.getIdField(clazz);
    ContentValues values = mapToContentValues(entity);
    if (values.get(idField) == null) {
        return db.insert(getTableName(), null, values);
    } else {/*  w w  w .  ja v a  2 s  . co  m*/
        long id = values.getAsLong(idField);
        StringBuilder sb = new StringBuilder("WHERE ");
        sb.append(SQLBuilder.getIdField(clazz)).append(" = ?");
        db.update(getTableName(), values, sb.toString(), new String[] { String.valueOf(id) });
        return id;
    }
}

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

@Override
public void init(final ContentValues config) {
    id = config.getAsLong("_id");
    final String authToken = config.getAsString(DB.ACCOUNT.AUTH_CONFIG);
    if (authToken != null) {
        try {//w  ww .  j a  v a 2  s  .c  om
            JSONObject tmp = new JSONObject(authToken);
            username = tmp.optString("username", null);
            password = tmp.optString("password", null);
        } catch (final JSONException e) {
            e.printStackTrace();
        }
    }
}