Example usage for android.content ContentValues getAsString

List of usage examples for android.content ContentValues getAsString

Introduction

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

Prototype

public String getAsString(String key) 

Source Link

Document

Gets a value and converts it to a String.

Usage

From source file:com.morphoss.acal.service.connector.AcalRequestor.java

/**
 * Adjust the current URI values to align with those in a ContentValues which has been read
 * from a Server row in the database.  The path will be set to the principal-path value
 * so you may need to specify a different path on the actual request(s).
 *
  * Unless you're configuring the server you should probably use AcalRequestor.fromServerValues(serverData) or applyFromServer(serverData).
        /* w w  w. j  ava 2s. c o  m*/
 * @param cvServerData
 * @param simpleSetup true/false whether to use only the 'simple' values to initialise from
 */
public void applyFromServer(ContentValues cvServerData, boolean simpleSetup) {
    if (simpleSetup) {
        protocol = null;
        hostName = null;
        port = 0;
        path = null;
        authType = Servers.AUTH_NONE;
        interpretUriString(cvServerData.getAsString(Servers.SUPPLIED_USER_URL));
    } else {
        setHostName(cvServerData.getAsString(Servers.HOSTNAME));
        setPath(cvServerData.getAsString(Servers.PRINCIPAL_PATH));

        String portString = cvServerData.getAsString(Servers.PORT);
        int tmpPort = 0;
        if (portString != null && portString.length() > 0)
            tmpPort = Integer.parseInt(portString);
        setPortProtocol(tmpPort, cvServerData.getAsInteger(Servers.USE_SSL));

        setAuthType(cvServerData.getAsInteger(Servers.AUTH_TYPE));

    }
    if (hostName == null)
        hostName = "invalid";
    if (path == null)
        path = "/";

    authRequired = (authType != Servers.AUTH_NONE);
    username = cvServerData.getAsString(Servers.USERNAME);
    password = cvServerData.getAsString(Servers.PASSWORD);

    if (!initialised)
        initialise();
}

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

/**
 * Parse a content retrieved from storage.
 * @param values content as returned by the storage.
 * @return content./*from ww w  . jav  a  2  s  .com*/
 * @throws Exception parsing problem, most likely invalid XML.
 */
private EngagementReachContent parseContentFromStorage(ContentValues values) throws Exception {
    /* Parse payload */
    com.microsoft.azure.engagement.reach.CampaignId campaignId = new CampaignId(
            values.getAsString(CAMPAIGN_ID));
    EngagementReachContent content = parseContent(campaignId, values);

    /* Parse state */
    content.setState(values);

    /* Parse local id */
    content.setLocalId(values.getAsLong(OID));
    return content;
}

From source file:at.bitfire.vcard4android.AndroidContact.java

protected void populateNickname(ContentValues row) {
    if (row.containsKey(Nickname.NAME)) {
        ezvcard.property.Nickname nick = new ezvcard.property.Nickname();

        nick.addValue(row.getAsString(Nickname.NAME));

        Integer type = row.getAsInteger(Nickname.TYPE);
        if (type != null)
            switch (type) {
            case Nickname.TYPE_MAIDEN_NAME:
                nick.setType(Contact.NICKNAME_TYPE_MAIDEN_NAME);
                break;
            case Nickname.TYPE_SHORT_NAME:
                nick.setType(Contact.NICKNAME_TYPE_SHORT_NAME);
                break;
            case Nickname.TYPE_INITIALS:
                nick.setType(Contact.NICKNAME_TYPE_INITIALS);
                break;
            case Nickname.TYPE_OTHER_NAME:
                nick.setType(Contact.NICKNAME_TYPE_OTHER_NAME);
                break;
            case Nickname.TYPE_CUSTOM:
                String label = row.getAsString(Nickname.LABEL);
                if (!TextUtils.isEmpty(label))
                    nick.setType(labelToXName(label));
            }// ww  w . j a  v a  2  s  . co  m

        contact.nickName = nick;
    }
}

From source file:org.frc836.database.DB.java

public boolean submitPits(PitStats stats) {
    try {//w  w w.  ja v a2s  .  c  o  m
        ContentValues values;
        synchronized (ScoutingDBHelper.lock) {
            SQLiteDatabase db = ScoutingDBHelper.getInstance().getWritableDatabase();
            values = stats.getValues(this, db);
            ScoutingDBHelper.getInstance().close();
        }

        String[] where = { values.getAsString(PitStats.COLUMN_NAME_TEAM_ID) };

        insertOrUpdate(PitStats.TABLE_NAME, null, values, PitStats.COLUMN_NAME_ID,
                PitStats.COLUMN_NAME_TEAM_ID + "=?", where);

        startSync();
        return true;
    } catch (Exception e) {
        return false;
    }
}

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 w w  .j ava 2s  . c om*/

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

From source file:org.frc836.database.DB.java

public boolean submitMatch(MatchStatsStruct teamData) {
    try {//w  w  w.j  ava2  s. c o  m
        String where = MatchStatsStruct.COLUMN_NAME_EVENT_ID + "=? AND " + MatchStatsStruct.COLUMN_NAME_MATCH_ID
                + "=? AND " + MatchStatsStruct.COLUMN_NAME_TEAM_ID + "=? AND "
                + MatchStatsStruct.COLUMN_NAME_PRACTICE_MATCH + "=?";
        ContentValues values;
        synchronized (ScoutingDBHelper.lock) {
            SQLiteDatabase db = ScoutingDBHelper.getInstance().getReadableDatabase();

            values = teamData.getValues(this, db);

            ScoutingDBHelper.getInstance().close();
        }
        String[] whereArgs = { values.getAsString(MatchStatsStruct.COLUMN_NAME_EVENT_ID),
                values.getAsString(MatchStatsStruct.COLUMN_NAME_MATCH_ID),
                values.getAsString(MatchStatsStruct.COLUMN_NAME_TEAM_ID),
                values.getAsString(MatchStatsStruct.COLUMN_NAME_PRACTICE_MATCH) };

        insertOrUpdate(MatchStatsStruct.TABLE_NAME, null, values, MatchStatsStruct.COLUMN_NAME_ID, where,
                whereArgs);

        startSync();

        return true;

    } catch (Exception e) {
        return false;
    }

}

From source file:org.frc836.database.DBSyncService.java

private void processPits(JSONArray pits) {
    // TODO could be abstracted further
    try {//  ww w.  j  a va2  s  .co m
        for (int i = 0; i < pits.length(); i++) {
            JSONObject row = pits.getJSONObject(i);
            Action action = Action.UPDATE;
            if (row.getInt(PitStats.COLUMN_NAME_INVALID) != 0) {
                action = Action.DELETE;
            }
            ContentValues vals = PitStats.getNewPitStats().jsonToCV(row);

            // check if this entry exists already
            String[] projection = { PitStats.COLUMN_NAME_ID, PitStats.COLUMN_NAME_INVALID };
            String[] where = { vals.getAsString(PitStats.COLUMN_NAME_TEAM_ID) };

            synchronized (ScoutingDBHelper.lock) {

                SQLiteDatabase db = ScoutingDBHelper.getInstance().getWritableDatabase();

                Cursor c = db.query(PitStats.TABLE_NAME, projection, // select
                        PitStats.COLUMN_NAME_TEAM_ID + "=?", where, null, // don't
                        // group
                        null, // don't filter
                        null, // don't order
                        "0,1"); // limit to 1
                try {
                    if (!c.moveToFirst()) {
                        if (action == Action.UPDATE)
                            action = Action.INSERT;
                        else if (action == Action.DELETE)
                            action = Action.NOTHING;
                    } else {
                        int invalid = c.getInt(c.getColumnIndexOrThrow(PitStats.COLUMN_NAME_INVALID));
                        if (invalid > 0) // Current entry has not been sent
                                         // to server, don't overwrite
                            action = Action.NOTHING;
                    }

                    switch (action) {
                    case UPDATE:
                        db.update(PitStats.TABLE_NAME, vals, PitStats.COLUMN_NAME_TEAM_ID + " = ?", where);
                        break;
                    case INSERT:
                        db.insert(PitStats.TABLE_NAME, null, vals);
                        break;
                    case DELETE:
                        db.delete(PitStats.TABLE_NAME, PitStats.COLUMN_NAME_TEAM_ID + " = ?", where);
                        break;
                    default:
                    }
                } finally {
                    if (c != null)
                        c.close();
                    ScoutingDBHelper.getInstance().close();
                }
            }
        }
    } catch (JSONException e) {
        // TODO handle error
    }
}

From source file:org.kontalk.provider.UsersProvider.java

private Uri insertUser(ContentValues values, boolean offline, boolean discardName) {
    SQLiteDatabase db = dbHelper.getWritableDatabase();

    String table = offline ? TABLE_USERS_OFFLINE : TABLE_USERS;
    long id = 0;//from w  w w  .j a va  2 s  .com

    try {
        id = db.insertOrThrow(table, null, values);
    } catch (SQLException e) {
        String jid = values.getAsString(Users.JID);
        if (jid != null) {
            // discard display_name if requested
            if (discardName) {
                values.remove(Users.DISPLAY_NAME);
                values.remove(Users.NUMBER);
            }

            db.update(table, values, Users.JID + "=?", new String[] { jid });
        }
    }

    if (id >= 0)
        return ContentUris.withAppendedId(Users.CONTENT_URI, id);
    return null;
}

From source file:org.opendatakit.common.android.provider.impl.FormsProviderImpl.java

@Override
public synchronized Uri insert(Uri uri, ContentValues initialValues) {
    List<String> segments = uri.getPathSegments();

    if (segments.size() != 1) {
        throw new IllegalArgumentException("Unknown URI (too many segments!) " + uri);
    }//from   w w  w . ja v  a 2 s. c o m

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

    ContentValues values;
    if (initialValues != null) {
        values = new ContentValues(initialValues);
    } else {
        values = new ContentValues();
    }

    // ODK2: require FORM_MEDIA_PATH (different behavior -- ODK1 and
    // required FORM_FILE_PATH)
    if (!values.containsKey(FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH)) {
        throw new IllegalArgumentException(FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH + " must be specified.");
    }

    // Normalize path...
    File mediaPath = ODKFileUtils.asAppFile(appName,
            values.getAsString(FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH));

    // require that the form directory actually exists
    if (!mediaPath.exists()) {
        throw new IllegalArgumentException(FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH
                + " directory does not exist: " + mediaPath.getAbsolutePath());
    }

    patchUpValues(appName, values);

    if (values.containsKey(FormsColumns.DISPLAY_SUBTEXT) == false) {
        Date today = new Date();
        String ts = new SimpleDateFormat(getContext().getString(R.string.added_on_date_at_time),
                Locale.getDefault()).format(today);
        values.put(FormsColumns.DISPLAY_SUBTEXT, ts);
    }

    if (values.containsKey(FormsColumns.DISPLAY_NAME) == false) {
        values.put(FormsColumns.DISPLAY_NAME, mediaPath.getName());
    }

    // first try to see if a record with this filename already exists...
    String[] projection = { FormsColumns.FORM_ID, FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH };
    String[] selectionArgs = { ODKFileUtils.asRelativePath(appName, mediaPath) };
    String selection = FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH + "=?";
    Cursor c = null;

    SQLiteDatabase db = null;
    try {
        db = DatabaseFactory.get().getDatabase(getContext(), appName);
        db.beginTransaction();
        try {
            c = db.query(DatabaseConstants.FORMS_TABLE_NAME, projection, selection, selectionArgs, null, null,
                    null);
            if (c == null) {
                throw new SQLException("FAILED Insert into " + uri
                        + " -- unable to query for existing records: " + mediaPath.getAbsolutePath());
            }
            if (c.getCount() > 0) {
                // already exists
                throw new SQLException("FAILED Insert into " + uri
                        + " -- row already exists for form directory: " + mediaPath.getAbsolutePath());
            }
        } catch (Exception e) {
            log.w(t, "FAILED Insert into " + uri + " -- query for existing row failed: " + e.toString());

            if (e instanceof SQLException) {
                throw (SQLException) e;
            } else {
                throw new SQLException(
                        "FAILED Insert into " + uri + " -- query for existing row failed: " + e.toString());
            }
        } finally {
            if (c != null) {
                c.close();
            }
        }

        try {
            long rowId = db.insert(DatabaseConstants.FORMS_TABLE_NAME, null, values);
            db.setTransactionSuccessful();
            if (rowId > 0) {
                Uri formUri = Uri.withAppendedPath(
                        Uri.withAppendedPath(Uri.parse("content://" + getFormsAuthority()), appName),
                        values.getAsString(FormsColumns.FORM_ID));
                getContext().getContentResolver().notifyChange(formUri, null);
                Uri idUri = Uri.withAppendedPath(
                        Uri.withAppendedPath(Uri.parse("content://" + getFormsAuthority()), appName),
                        Long.toString(rowId));
                getContext().getContentResolver().notifyChange(idUri, null);

                return formUri;
            }
        } catch (Exception e) {
            log.w(t, "FAILED Insert into " + uri + " -- insert of row failed: " + e.toString());

            if (e instanceof SQLException) {
                throw (SQLException) e;
            } else {
                throw new SQLException(
                        "FAILED Insert into " + uri + " -- insert of row failed: " + e.toString());
            }
        }
    } finally {
        if (db != null) {
            db.endTransaction();
            db.close();
        }
    }

    throw new SQLException("Failed to insert row into " + uri);
}

From source file:org.frc836.database.DBSyncService.java

private void processMatches(JSONArray matches) {
    // TODO could be abstracted further
    try {// w  ww  .  ja v a2s  .  c  o  m
        for (int i = 0; i < matches.length(); i++) {
            JSONObject row = matches.getJSONObject(i);
            Action action = Action.UPDATE;
            if (row.getInt(MatchStatsStruct.COLUMN_NAME_INVALID) != 0) {
                action = Action.DELETE;
            }
            ContentValues vals = MatchStatsStruct.getNewMatchStats().jsonToCV(row);

            // check if this entry exists already
            String[] projection = { MatchStatsStruct.COLUMN_NAME_ID, MatchStatsStruct.COLUMN_NAME_INVALID };
            String[] where = { vals.getAsString(MatchStatsStruct.COLUMN_NAME_EVENT_ID),
                    vals.getAsString(MatchStatsStruct.COLUMN_NAME_MATCH_ID),
                    vals.getAsString(MatchStatsStruct.COLUMN_NAME_TEAM_ID),
                    vals.getAsString(MatchStatsStruct.COLUMN_NAME_PRACTICE_MATCH) };

            synchronized (ScoutingDBHelper.lock) {
                SQLiteDatabase db = ScoutingDBHelper.getInstance().getWritableDatabase();

                Cursor c = db.query(MatchStatsStruct.TABLE_NAME, projection, // select
                        MatchStatsStruct.COLUMN_NAME_EVENT_ID + "=? AND "
                                + MatchStatsStruct.COLUMN_NAME_MATCH_ID + "=? AND "
                                + MatchStatsStruct.COLUMN_NAME_TEAM_ID + "=? AND "
                                + MatchStatsStruct.COLUMN_NAME_PRACTICE_MATCH + "=?",
                        where, null, // don't
                        // group
                        null, // don't filter
                        null, // don't order
                        "0,1"); // limit to 1
                try {
                    int id = 0, invalid = 0;
                    if (!c.moveToFirst()) {
                        if (action == Action.UPDATE)
                            action = Action.INSERT;
                        else if (action == Action.DELETE)
                            action = Action.NOTHING;
                    } else {
                        id = c.getInt(c.getColumnIndexOrThrow(MatchStatsStruct.COLUMN_NAME_ID));
                        invalid = c.getInt(c.getColumnIndexOrThrow(MatchStatsStruct.COLUMN_NAME_INVALID));
                        if (invalid > 0) // this field has not been sent to
                                         // server yet.
                            action = Action.NOTHING;
                    }

                    String[] where2 = { String.valueOf(id) };

                    switch (action) {
                    case UPDATE:
                        db.update(MatchStatsStruct.TABLE_NAME, vals, MatchStatsStruct.COLUMN_NAME_ID + " = ?",
                                where2);
                        break;
                    case INSERT:
                        db.insert(MatchStatsStruct.TABLE_NAME, null, vals);
                        break;
                    case DELETE:
                        db.delete(MatchStatsStruct.TABLE_NAME, MatchStatsStruct.COLUMN_NAME_ID + " = ?",
                                where2);
                        break;
                    default:
                    }
                } finally {
                    if (c != null)
                        c.close();
                    ScoutingDBHelper.getInstance().close();
                }
            }
        }
    } catch (JSONException e) {
        // TODO handle error
    }
}