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:export.GooglePlus.java

@Override
public void init(ContentValues config) {
    String authConfig = config.getAsString(DB.ACCOUNT.AUTH_CONFIG);
    if (authConfig != null) {
        try {/*from w  w  w . ja  va 2s.  c  om*/
            JSONObject tmp = new JSONObject(authConfig);
            access_token = tmp.optString("access_token", null);
            refresh_token = tmp.optString("refresh_token", null);
            token_now = tmp.optLong("token_now");
            expire_time = tmp.optLong("expire_time");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    id = config.getAsLong("_id");
}

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:org.anhonesteffort.flock.sync.addressbook.ContactFactory.java

protected static void addWebsite(String path, VCard vCard, ContentValues websiteValues)
        throws InvalidComponentException {
    String urlText = websiteValues.getAsString(ContactsContract.CommonDataKinds.Website.URL);

    if (urlText != null) {
        Url url = new Url(urlText);
        vCard.addUrl(url);/*from   w w w.ja  va 2 s  .  co  m*/
    } else {
        Log.e(TAG, "url is null, not adding anything");
        throw new InvalidComponentException("url is null", false, CardDavConstants.CARDDAV_NAMESPACE, path);
    }
}

From source file:com.germainz.identiconizer.xposed.XposedMod.java

@Override
public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {
    if ("com.android.providers.contacts".equals(lpparam.packageName)) {
        try {/*from  w w  w .j a  va 2  s  .  co m*/
            findAndHookMethod("com.android.providers.contacts.DataRowHandlerForStructuredName",
                    lpparam.classLoader, "insert", SQLiteDatabase.class,
                    "com.android.providers.contacts.TransactionContext", long.class, ContentValues.class,
                    new XC_MethodHook() {

                        @Override
                        protected void beforeHookedMethod(XC_MethodHook.MethodHookParam param)
                                throws Throwable {
                            CONFIG.reload();
                            if (CONFIG.isEnabled()) {
                                ContentValues values = (ContentValues) param.args[3];
                                String name = values.getAsString(
                                        ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME);

                                if (!TextUtils.isEmpty(name)) {
                                    long rawContactId = ((Number) param.args[2]).longValue();
                                    SQLiteDatabase db = (SQLiteDatabase) param.args[0];
                                    Identicon identicon = IdenticonFactory.makeIdenticon(
                                            CONFIG.getIdenticonStyle(), CONFIG.getIdenticonSize(),
                                            CONFIG.getIdenticonBgColor());

                                    ContentValues identiconValues = new ContentValues();
                                    identiconValues.put("mimetype_id", 10);
                                    identiconValues.put(ContactsContract.Data.RAW_CONTACT_ID, rawContactId);
                                    identiconValues.put(ContactsContract.CommonDataKinds.Photo.PHOTO,
                                            identicon.generateIdenticonByteArray(name));
                                    identiconValues.put(ContactsContract.Data.IS_PRIMARY, 1);
                                    identiconValues.put(ContactsContract.Data.IS_SUPER_PRIMARY, 1);

                                    db.insert(ContactsContract.Contacts.Data.CONTENT_DIRECTORY, null,
                                            identiconValues);
                                }
                            }
                        }
                    });
        } catch (Throwable e) {
            Context systemContext = (Context) getStaticObjectField(
                    findClass("android.app.ActivityThread", null), "mSystemContext");
            if (systemContext == null) {
                Object activityThread = callStaticMethod(findClass("android.app.ActivityThread", null),
                        "currentActivityThread");
                systemContext = (Context) callMethod(activityThread, "getSystemContext");
            }

            Context contactsProviderContext = systemContext
                    .createPackageContext("com.android.providers.contacts", Context.CONTEXT_IGNORE_SECURITY);
            Context identiconizerContext = systemContext.createPackageContext(Config.PACKAGE_NAME,
                    Context.CONTEXT_IGNORE_SECURITY);

            String contentText = identiconizerContext.getString(R.string.xposed_error_text);
            Notification notice = new NotificationCompat.Builder(contactsProviderContext)
                    .setSmallIcon(NOTIF_ICON_RES_ID)
                    .setContentTitle(identiconizerContext.getString(R.string.xposed_error_title))
                    .setContentText(contentText)
                    .setStyle(new NotificationCompat.BigTextStyle().bigText(contentText)).build();
            NotificationManager nm = (NotificationManager) contactsProviderContext
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            nm.notify(1, notice);
        }
    }

    if (Config.PACKAGE_NAME.equals(lpparam.packageName)) {
        findAndHookMethod(Config.PACKAGE_NAME + ".Config", lpparam.classLoader, "isXposedModActive",
                XC_MethodReplacement.returnConstant(true));
    }
}

From source file:org.anhonesteffort.flock.sync.addressbook.ContactFactory.java

protected static void addStructuredName(VCard vCard, ContentValues structuredNameValues) {
    String displayName = structuredNameValues
            .getAsString(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME);
    String givenName = structuredNameValues
            .getAsString(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME);
    String familyName = structuredNameValues
            .getAsString(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME);
    String prefix = structuredNameValues.getAsString(ContactsContract.CommonDataKinds.StructuredName.PREFIX);
    String middleName = structuredNameValues
            .getAsString(ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME);
    String suffix = structuredNameValues.getAsString(ContactsContract.CommonDataKinds.StructuredName.SUFFIX);
    String phoneticGivenName = structuredNameValues
            .getAsString(ContactsContract.CommonDataKinds.StructuredName.PHONETIC_GIVEN_NAME);
    String phoneticMiddleName = structuredNameValues
            .getAsString(ContactsContract.CommonDataKinds.StructuredName.PHONETIC_MIDDLE_NAME);
    String phoneticFamilyName = structuredNameValues
            .getAsString(ContactsContract.CommonDataKinds.StructuredName.PHONETIC_FAMILY_NAME);

    if (displayName != null) {
        FormattedName formattedName = new FormattedName(displayName);
        vCard.addFormattedName(formattedName);

        StructuredName structuredName = new StructuredName();

        if (givenName != null)
            structuredName.setGiven(givenName);

        if (familyName != null)
            structuredName.setFamily(familyName);

        if (prefix != null)
            structuredName.addPrefix(prefix);

        if (middleName != null)
            structuredName.addAdditional(middleName);

        if (suffix != null)
            structuredName.addSuffix(suffix);

        vCard.setStructuredName(structuredName);

        if (phoneticGivenName != null)
            vCard.addExtendedProperty(PROPERTY_PHONETIC_GIVEN_NAME, phoneticGivenName);

        if (phoneticMiddleName != null)
            vCard.addExtendedProperty(PROPERTY_PHONETIC_MIDDLE_NAME, phoneticMiddleName);

        if (phoneticFamilyName != null)
            vCard.addExtendedProperty(PROPERTY_PHONETIC_FAMILY_NAME, phoneticFamilyName);
    } else/*from  ww w .ja  va2  s .c  om*/
        Log.w(TAG, "display name missing, nothing to add");
}

From source file:com.wheelly.activity.FilterDialog.java

private void updatePeriodFromFilter(ContentValues filter) {
    String s = filter.getAsString(F.PERIOD);
    if (s != null) {
        String[] tokens = s.split(",");
        PeriodType type = PeriodType.valueOf(tokens[0]);
        if (type == PeriodType.CUSTOM) {
            long periodFrom = Long.valueOf(tokens[1]);
            long periodTo = Long.valueOf(tokens[2]);
            c.period.setText(df.format(new Date(periodFrom)) + "-" + df.format(new Date(periodTo)));
        } else {/* w w  w.  j a v  a2 s  .c  o m*/
            c.period.setText(type.titleId);
        }
    } else {
        c.period.setText(R.string.no_filter);
    }
}

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

@Override
public void init(ContentValues config) {
    String authConfig = config.getAsString(DB.ACCOUNT.AUTH_CONFIG);
    if (authConfig != null) {
        try {/*from w  w  w  .  ja  v a2s .  com*/
            JSONObject tmp = new JSONObject(authConfig);
            access_token = tmp.optString("access_token", null);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    id = config.getAsLong("_id");
}

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 w  ww .j a v  a2 s .co  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.wheelly.activity.FilterDialog.java

private void updateLocationFromFilter(ContentValues filter, final Cursor locationCursor) {
    long locationId = filter.containsKey(F.LOCATION) ? filter.getAsLong(F.LOCATION) : 0;
    if (locationId > 0 && Utils.moveCursor(locationCursor, BaseColumns._ID, locationId) != -1) {
        final ContentValues location = LocationBroker.deserialize(locationCursor);
        c.location.setText(location != null ? location.getAsString("name") : filterValueNotFound);
    } else {//from   w  ww.ja  va  2  s  .c o m
        c.location.setText(R.string.no_filter);
    }
}

From source file:org.most.persistence.DBAdapter.java

/**
 * Flushes all currently buffered data to the database. This method
 * <em>does not</em> require to acquire the DB lock beforehand.
 *///from ww  w  .  j a  v a 2 s. c o  m
public void flushData() {
    Log.d(TAG, "Flushing MoST db.");
    logger.info("Flushing MoST db.");
    _runningDump.set(true);
    long start = System.currentTimeMillis();
    if (open() == null) {
        Log.e(TAG, "Unable to write data to db.");
        logger.error("Unable to write data to db.");
        _runningDump.set(false);
        return;
    }
    updateList();
    int linesCount = 0;
    _db.beginTransaction();
    try {
        LinkedBlockingQueue<ContentValues> list;
        while ((list = _dataToDump.poll()) != null) {
            for (ContentValues data : list) {
                String tableName = data.getAsString(FLD_TABLE);
                data.remove(FLD_TABLE);
                _db.insert(tableName, null, data);
                linesCount++;
            }
        }
        // commit on successful write
        _db.setTransactionSuccessful();
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        _db.endTransaction();
        close();
        start = System.currentTimeMillis() - start;
        Log.i(TAG, "DB write time: " + start + "ms for " + linesCount + " entries.");
        _runningDump.set(false);
    }
}