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.akop.bach.parser.PsnEuParser.java

@SuppressLint("DefaultLocale")
@Override//from  w  w  w  .  j a v  a2 s.  c o  m
protected void parseGames(PsnAccount account) throws ParserException, IOException {
    long started = System.currentTimeMillis();
    boolean keepGoing = true;
    List<ContentValues> cvList = new ArrayList<ContentValues>();

    for (int startIndex = 0; keepGoing; startIndex += 16) {
        String url = String.format(URL_GAMES, startIndex);
        String page = getResponse(url);

        keepGoing = parseGamePage(startIndex, page, cvList);
    }

    final long accountId = account.getId();
    ContentResolver cr = mContext.getContentResolver();
    String[] queryParams = new String[1];
    Cursor c;
    long updated = System.currentTimeMillis();
    List<ContentValues> newCvs = new ArrayList<ContentValues>(100);

    // Check to see if we already have a record of this game
    for (ContentValues cv : cvList) {
        queryParams[0] = cv.getAsString(Games.UID);
        c = cr.query(Games.CONTENT_URI, GAMES_PROJECTION,
                Games.ACCOUNT_ID + "=" + accountId + " AND " + Games.UID + "=?", queryParams, null);

        try {
            if (c == null || !c.moveToFirst()) // New game
            {
                cv.put(Games.ACCOUNT_ID, accountId);
                cv.put(Games.TROPHIES_DIRTY, 1);
                cv.put(Games.LAST_UPDATED, updated);

                newCvs.add(cv);
            } else // Existing game
            {
                boolean isDirty = false;
                long gameId = c.getLong(COLUMN_GAME_ID);

                if (c.getInt(COLUMN_GAME_PROGRESS) != cv.getAsInteger(Games.PROGRESS))
                    isDirty = true;
                if (c.getInt(COLUMN_GAME_BRONZE) != cv.getAsInteger(Games.UNLOCKED_BRONZE))
                    isDirty = true;
                if (c.getInt(COLUMN_GAME_SILVER) != cv.getAsInteger(Games.UNLOCKED_SILVER))
                    isDirty = true;
                if (c.getInt(COLUMN_GAME_GOLD) != cv.getAsInteger(Games.UNLOCKED_GOLD))
                    isDirty = true;
                if (c.getInt(COLUMN_GAME_PLATINUM) != cv.getAsInteger(Games.UNLOCKED_PLATINUM))
                    isDirty = true;

                if (isDirty)
                    cv.put(Games.TROPHIES_DIRTY, 1);

                cv.put(Games.LAST_UPDATED, updated);

                cr.update(Games.CONTENT_URI, cv, Games._ID + "=" + gameId, null);
            }
        } finally {
            if (c != null)
                c.close();
        }
    }

    if (App.getConfig().logToConsole())
        started = displayTimeTaken("Game page processing", started);

    if (newCvs.size() > 0) {
        ContentValues[] cvs = new ContentValues[newCvs.size()];
        newCvs.toArray(cvs);

        cr.bulkInsert(Games.CONTENT_URI, cvs);

        if (App.getConfig().logToConsole())
            displayTimeTaken("Game page insertion", started);
    }

    account.refresh(Preferences.get(mContext));
    account.setLastGameUpdate(System.currentTimeMillis());
    account.save(Preferences.get(mContext));

    cr.notifyChange(Games.CONTENT_URI, null);
}

From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java

private Uri insertArtwork(@NonNull final Uri uri, final ContentValues values) {
    Context context = getContext();
    if (context == null) {
        return null;
    }/*from  www  .  j a  va 2 s. co m*/
    if (values == null) {
        throw new IllegalArgumentException("Invalid ContentValues: must not be null");
    }
    if (!values.containsKey(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME)
            || TextUtils.isEmpty(values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME))) {
        throw new IllegalArgumentException("Initial values must contain component name: " + values);
    }

    // Check to make sure the component name is valid
    ComponentName componentName = ComponentName
            .unflattenFromString(values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME));
    if (componentName == null) {
        throw new IllegalArgumentException("Invalid component name: "
                + values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME));
    }
    // Make sure they are using the short string format
    values.put(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME, componentName.flattenToShortString());

    // Ensure the app inserting the artwork is either Muzei or the same app as the source
    String callingPackageName = getCallingPackage();
    if (!context.getPackageName().equals(callingPackageName)
            && !TextUtils.equals(callingPackageName, componentName.getPackageName())) {
        throw new IllegalArgumentException("Calling package name (" + callingPackageName
                + ") must match the source's package name (" + componentName.getPackageName() + ")");
    }

    if (values.containsKey(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT)) {
        String viewIntentString = values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT);
        Intent viewIntent;
        try {
            if (!TextUtils.isEmpty(viewIntentString)) {
                // Make sure it is a valid Intent URI
                viewIntent = Intent.parseUri(viewIntentString, Intent.URI_INTENT_SCHEME);
                // Make sure we can construct a PendingIntent for the Intent
                PendingIntent.getActivity(context, 0, viewIntent, PendingIntent.FLAG_UPDATE_CURRENT);
            }
        } catch (URISyntaxException e) {
            Log.w(TAG, "Removing invalid View Intent: " + viewIntentString, e);
            values.remove(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT);
        } catch (RuntimeException e) {
            // This is actually meant to catch a FileUriExposedException, but you can't
            // have catch statements for exceptions that don't exist at your minSdkVersion
            Log.w(TAG, "Removing invalid View Intent that contains a file:// URI: " + viewIntentString, e);
            values.remove(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT);
        }
    }

    // Ensure the related source has been added to the database.
    // This should be true in 99.9% of cases, but the insert will fail if this isn't true
    Cursor sourceQuery = querySource(MuzeiContract.Sources.CONTENT_URI, new String[] { BaseColumns._ID },
            MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME + "=?",
            new String[] { componentName.flattenToShortString() }, null);
    if (sourceQuery == null || sourceQuery.getCount() == 0) {
        ContentValues initialValues = new ContentValues();
        initialValues.put(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME,
                componentName.flattenToShortString());
        insertSource(MuzeiContract.Sources.CONTENT_URI, initialValues);
    }
    if (sourceQuery != null) {
        sourceQuery.close();
    }

    values.put(MuzeiContract.Artwork.COLUMN_NAME_DATE_ADDED, System.currentTimeMillis());
    final SQLiteDatabase db = databaseHelper.getWritableDatabase();
    long rowId = db.insert(MuzeiContract.Artwork.TABLE_NAME, MuzeiContract.Artwork.COLUMN_NAME_IMAGE_URI,
            values);
    // If the insert succeeded, the row ID exists.
    if (rowId > 0) {
        // Creates a URI with the artwork ID pattern and the new row ID appended to it.
        final Uri artworkUri = ContentUris.withAppendedId(MuzeiContract.Artwork.CONTENT_URI, rowId);
        File artwork = getCacheFileForArtworkUri(artworkUri);
        if (artwork != null && artwork.exists()) {
            // The image already exists so we'll notifyChange() to say the new artwork is ready
            // Otherwise, this will be called when the file is written with openFile()
            // using this Uri and the actual artwork is written successfully
            notifyChange(artworkUri);
        }
        return artworkUri;
    }
    // If the insert didn't succeed, then the rowID is <= 0
    throw new SQLException("Failed to insert row into " + uri);
}

From source file:com.csipsimple.service.SipNotifications.java

public void showNotificationForMissedCall(ContentValues callLog) {
    int icon = android.R.drawable.stat_notify_missed_call;
    CharSequence tickerText = context.getText(R.string.missed_call);
    long when = System.currentTimeMillis();

    if (missedCallNotification == null) {
        missedCallNotification = new NotificationCompat.Builder(context);
        missedCallNotification.setSmallIcon(icon);
        missedCallNotification.setTicker(tickerText);
        missedCallNotification.setWhen(when);
        missedCallNotification.setOnlyAlertOnce(true);
        missedCallNotification.setAutoCancel(true);
        missedCallNotification.setDefaults(Notification.DEFAULT_ALL);
    }/*w  w  w.  j  ava 2  s  . c  o m*/

    Intent notificationIntent = new Intent(SipManager.ACTION_SIP_CALLLOG);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    String remoteContact = callLog.getAsString(CallLog.Calls.NUMBER);
    long accId = callLog.getAsLong(SipManager.CALLLOG_PROFILE_ID_FIELD);
    missedCallNotification.setContentTitle(formatNotificationTitle(R.string.missed_call, accId));
    missedCallNotification.setContentText(formatRemoteContactString(remoteContact));
    missedCallNotification.setContentIntent(contentIntent);

    notificationManager.notify(CALLLOG_NOTIF_ID, missedCallNotification.build());
}

From source file:org.wheelmap.android.fragment.POIDetailEditableFragment.java

public void save() {
    ContentValues values = retrieveContentValues();
    if (values == null) {
        return;//from   w w  w .  j  av  a 2s.  c  o m
    }
    if (!values.containsKey(POIs.NODETYPE_ID)) {
        showErrorMessage(getString(R.string.error_category_missing_title),
                getString(R.string.error_category_missing_message), Extra.UNKNOWN);
        return;
    } else if (mWheelchairFilterState == WheelchairFilterState.UNKNOWN) {
        showErrorMessage(getString(R.string.error_wheelchairstate_missing_title),
                getString(R.string.error_wheelchairstate_missing_message), Extra.UNKNOWN);
        return;
    }

    if (values.containsKey(POIs.WEBSITE)) {
        String website = values.getAsString(POIs.WEBSITE);
        website = website.toLowerCase(Locale.US);
        if (!website.startsWith("http://") && !website.startsWith("https://")) {
            website = "http://" + website;
        }

        if (!android.util.Patterns.WEB_URL.matcher(website).matches()) {
            showErrorMessage(null, getString(android.R.string.httpErrorBadUrl), -1);
            return;
        }

        values.put(POIs.WEBSITE, website);
    }
    values.put(POIs.DIRTY, POIs.DIRTY_ALL);
    PrepareDatabaseHelper.editCopy(getActivity().getContentResolver(), poiID, values);
    RestServiceHelper.executeUpdateServer(getActivity(), mReceiver);
}

From source file:com.akop.bach.parser.PsnParser.java

private void parseAccountSummary(PsnAccount account) throws ParserException, IOException {
    ContentValues cv = parseSummaryData(account);
    ContentResolver cr = mContext.getContentResolver();

    long accountId = account.getId();
    boolean newRecord = true;

    long started = System.currentTimeMillis();
    Cursor c = cr.query(Profiles.CONTENT_URI, new String[] { Profiles._ID },
            Profiles.ACCOUNT_ID + "=" + accountId, null, null);

    if (c != null) {
        if (c.moveToFirst())
            newRecord = false;//from w w  w.  ja  v  a  2  s .c om
        c.close();
    }

    if (newRecord) {
        cv.put(Profiles.ACCOUNT_ID, account.getId());
        cv.put(Profiles.UUID, account.getUuid());

        cr.insert(Profiles.CONTENT_URI, cv);
    } else {
        cr.update(Profiles.CONTENT_URI, cv, Profiles.ACCOUNT_ID + "=" + accountId, null);
    }

    cr.notifyChange(Profiles.CONTENT_URI, null);

    if (App.getConfig().logToConsole())
        displayTimeTaken("Summary update", started);

    account.refresh(Preferences.get(mContext));
    account.setOnlineId(cv.getAsString(Profiles.ONLINE_ID));
    account.setIconUrl(cv.getAsString(Profiles.ICON_URL));
    account.setLastSummaryUpdate(System.currentTimeMillis());
    account.save(Preferences.get(mContext));
}

From source file:com.sonetel.service.SipNotifications.java

public void showNotificationForMissedCall(ContentValues callLog) {
    int icon = android.R.drawable.stat_notify_missed_call;
    CharSequence tickerText = context.getText(R.string.missed_call);
    long when = System.currentTimeMillis();

    if (missedCallNotification == null) {
        missedCallNotification = new NotificationCompat.Builder(context);
        missedCallNotification.setSmallIcon(icon);
        missedCallNotification.setTicker(tickerText);
        missedCallNotification.setWhen(when);
        missedCallNotification.setOnlyAlertOnce(true);
        missedCallNotification.setAutoCancel(true);
        missedCallNotification.setDefaults(Notification.DEFAULT_ALL);
    }/*from  ww w  . ja va 2s  . c  o  m*/

    Intent notificationIntent = new Intent(SipManager.ACTION_SIP_CALLLOG);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    String remoteContact = callLog.getAsString(CallLog.Calls.NUMBER);
    long accId = callLog.getAsLong(SipManager.CALLLOG_PROFILE_ID_FIELD);
    missedCallNotification.setContentTitle(formatNotificationTitle(R.string.missed_call, accId));
    missedCallNotification.setContentText(formatRemoteContactString(remoteContact));
    missedCallNotification.setContentIntent(contentIntent);

    notificationManager.notify(CALLLOG_NOTIF_ID, missedCallNotification.getNotification());
}

From source file:com.newcell.calltext.service.SipNotifications.java

public void showNotificationForMissedCall(ContentValues callLog) {
    int icon = android.R.drawable.stat_notify_missed_call;
    CharSequence tickerText = context.getText(R.string.missed_call);
    long when = System.currentTimeMillis();

    if (missedCallNotification == null) {
        missedCallNotification = new NotificationCompat.Builder(context);
        missedCallNotification.setSmallIcon(icon);
        missedCallNotification.setTicker(tickerText);
        missedCallNotification.setWhen(when);
        missedCallNotification.setOnlyAlertOnce(true);
        missedCallNotification.setAutoCancel(true);
        missedCallNotification.setDefaults(Notification.DEFAULT_ALL);
    }/*from  w  w  w.  jav a2s  .  c om*/

    Intent notificationIntent = new Intent(SipManager.ACTION_SIP_CALLLOG);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    String remoteNumber = SipUri.getPhoneNumberFromApiSipString(callLog.getAsString(CallLog.Calls.NUMBER));
    String remoteName = callLog.getAsString(CallLog.Calls.CACHED_NAME);
    /*
       * 6/11/2014 Change missed call notification
       * 
       */
    missedCallNotification.setContentTitle(context.getText(R.string.missed_call));

    missedCallNotification.setContentText(remoteNumber);
    if (remoteName != null) {
        missedCallNotification.setContentText(remoteName);
    }
    /*
     * 
     */

    missedCallNotification.setContentIntent(contentIntent);

    notificationManager.notify(CALLLOG_NOTIF_ID, missedCallNotification.build());
}

From source file:com.ichi2.anki.provider.CardContentProvider.java

@Override
public Uri insert(Uri uri, ContentValues values) {
    Timber.d("CardContentProvider.insert");
    Collection col = CollectionHelper.getInstance().getCol(getContext());
    if (col == null) {
        return null;
    }// ww  w  . ja va2s. c o m

    // Find out what data the user is requesting
    int match = sUriMatcher.match(uri);

    switch (match) {
    case NOTES: {
        /* Insert new note with specified fields and tags
         */
        Long modelId = values.getAsLong(FlashCardsContract.Note.MID);
        String flds = values.getAsString(FlashCardsContract.Note.FLDS);
        String tags = values.getAsString(FlashCardsContract.Note.TAGS);
        // Create empty note
        com.ichi2.libanki.Note newNote = new com.ichi2.libanki.Note(col, col.getModels().get(modelId));
        // Set fields
        String[] fldsArray = Utils.splitFields(flds);
        // Check that correct number of flds specified
        if (fldsArray.length != newNote.getFields().length) {
            throw new IllegalArgumentException("Incorrect flds argument : " + flds);
        }
        for (int idx = 0; idx < fldsArray.length; idx++) {
            newNote.setField(idx, fldsArray[idx]);
        }
        // Set tags
        if (tags != null) {
            newNote.setTagsFromStr(tags);
        }
        // Add to collection
        col.addNote(newNote);
        return Uri.withAppendedPath(FlashCardsContract.Note.CONTENT_URI, Long.toString(newNote.getId()));
    }
    case NOTES_ID:
        // Note ID is generated automatically by libanki
        throw new IllegalArgumentException("Not possible to insert note with specific ID");
    case NOTES_ID_CARDS:
        // Cards are generated automatically by libanki
        throw new IllegalArgumentException("Not possible to insert cards directly (only through NOTES)");
    case NOTES_ID_CARDS_ORD:
        // Cards are generated automatically by libanki
        throw new IllegalArgumentException("Not possible to insert cards directly (only through NOTES)");
    case MODELS:
        // Get input arguments
        String modelName = values.getAsString(FlashCardsContract.Model.NAME);
        String css = values.getAsString(FlashCardsContract.Model.CSS);
        Long did = values.getAsLong(FlashCardsContract.Model.DECK_ID);
        String fieldNames = values.getAsString(FlashCardsContract.Model.FIELD_NAMES);
        Integer numCards = values.getAsInteger(FlashCardsContract.Model.NUM_CARDS);
        // Throw exception if required fields empty
        if (modelName == null || fieldNames == null || numCards == null) {
            throw new IllegalArgumentException("Model name, field_names, and num_cards can't be empty");
        }
        // Create a new model
        Models mm = col.getModels();
        JSONObject newModel = mm.newModel(modelName);
        try {
            // Add the fields
            String[] allFields = Utils.splitFields(fieldNames);
            for (String f : allFields) {
                mm.addField(newModel, mm.newField(f));
            }
            // Add some empty card templates
            for (int idx = 0; idx < numCards; idx++) {
                JSONObject t = mm.newTemplate("Card " + (idx + 1));
                t.put("qfmt", String.format("{{%s}}", allFields[0]));
                String answerField = allFields[0];
                if (allFields.length > 1) {
                    answerField = allFields[1];
                }
                t.put("afmt", String.format("{{FrontSide}}\\n\\n<hr id=answer>\\n\\n{{%s}}", answerField));
                mm.addTemplate(newModel, t);
            }
            // Add the CSS if specified
            if (css != null) {
                newModel.put("css", css);
            }
            // Add the did if specified
            if (did != null) {
                newModel.put("did", did);
            }
            // Add the model to collection (from this point on edits will require a full-sync)
            mm.add(newModel);
            mm.save(newModel); // TODO: is this necessary?
            // Get the mid and return a URI
            String mid = Long.toString(newModel.getLong("id"));
            return Uri.withAppendedPath(FlashCardsContract.Model.CONTENT_URI, mid);
        } catch (ConfirmModSchemaException e) {
            // This exception should never be thrown when inserting new models
            Timber.e(e, "Unexpected ConfirmModSchema exception adding new model %s", modelName);
            throw new IllegalArgumentException("ConfirmModSchema exception adding new model " + modelName);
        } catch (JSONException e) {
            Timber.e(e, "Could not set a field of new model %s", modelName);
            return null;
        }
    case MODELS_ID:
        // Model ID is generated automatically by libanki
        throw new IllegalArgumentException("Not possible to insert model with specific ID");
    case MODELS_ID_TEMPLATES:
        // Adding new templates after the model is created could require a full-sync
        throw new IllegalArgumentException("Templates can only be added at the time of model insertion");
    case MODELS_ID_TEMPLATES_ID:
        // Adding new templates after the model is created could require a full-sync
        throw new IllegalArgumentException("Templates can only be added at the time of model insertion");
    case SCHEDULE:
        // Doesn't make sense to insert an object into the schedule table
        throw new IllegalArgumentException("Not possible to perform insert operation on schedule");
    case DECKS:
        // Insert new deck with specified name
        String deckName = values.getAsString(FlashCardsContract.Deck.DECK_NAME);
        did = col.getDecks().id(deckName);
        return Uri.withAppendedPath(FlashCardsContract.Deck.CONTENT_ALL_URI, Long.toString(did));
    case DECK_SELECTED:
        // Can't have more than one selected deck
        throw new IllegalArgumentException("Selected deck can only be queried and updated");
    case DECKS_ID:
        // Deck ID is generated automatically by libanki
        throw new IllegalArgumentException("Not possible to insert deck with specific ID");
    default:
        // Unknown URI type
        throw new IllegalArgumentException("uri " + uri + " is not supported");
    }
}

From source file:org.runnerup.view.DetailActivity.java

void requery() {
    {/*w  ww.  ja  v a  2 s . c o m*/
        /**
         * Laps
         */
        String[] from = new String[] { "_id", DB.LAP.LAP, DB.LAP.INTENSITY, DB.LAP.TIME, DB.LAP.DISTANCE,
                DB.LAP.PLANNED_TIME, DB.LAP.PLANNED_DISTANCE, DB.LAP.PLANNED_PACE, DB.LAP.AVG_HR };

        Cursor c = mDB.query(DB.LAP.TABLE, from, DB.LAP.ACTIVITY + " == " + mID, null, null, null, "_id", null);

        laps = DBHelper.toArray(c);
        c.close();
        lapHrPresent = false;
        for (ContentValues v : laps) {
            if (v.containsKey(DB.LAP.AVG_HR) && v.getAsInteger(DB.LAP.AVG_HR) > 0) {
                lapHrPresent = true;
                break;
            }
        }
    }

    {
        /**
         * Accounts/reports
         */
        String sql = new String("SELECT DISTINCT " + "  acc._id, " // 0
                + ("  acc." + DB.ACCOUNT.NAME + ", ") + ("  acc." + DB.ACCOUNT.DESCRIPTION + ", ")
                + ("  acc." + DB.ACCOUNT.FLAGS + ", ") + ("  acc." + DB.ACCOUNT.AUTH_METHOD + ", ")
                + ("  acc." + DB.ACCOUNT.AUTH_CONFIG + ", ") + ("  acc." + DB.ACCOUNT.ENABLED + ", ")
                + ("  rep._id as repid, ") + ("  rep." + DB.EXPORT.ACCOUNT + ", ")
                + ("  rep." + DB.EXPORT.ACTIVITY + ", ") + ("  rep." + DB.EXPORT.STATUS)
                + (" FROM " + DB.ACCOUNT.TABLE + " acc ") + (" LEFT OUTER JOIN " + DB.EXPORT.TABLE + " rep ")
                + (" ON ( acc._id = rep." + DB.EXPORT.ACCOUNT)
                + ("     AND rep." + DB.EXPORT.ACTIVITY + " = " + mID + " )")
                + (" WHERE acc." + DB.ACCOUNT.ENABLED + " != 0 ")
                + ("   AND acc." + DB.ACCOUNT.AUTH_CONFIG + " is not null"));

        Cursor c = mDB.rawQuery(sql, null);
        alreadyUploadedUploaders.clear();
        pendingUploaders.clear();
        reports.clear();
        if (c.moveToFirst()) {
            do {
                ContentValues tmp = DBHelper.get(c);
                Uploader uploader = uploadManager.add(tmp);
                if (!uploader.checkSupport(Feature.UPLOAD)) {
                    continue;
                }

                reports.add(tmp);
                if (tmp.containsKey("repid")) {
                    alreadyUploadedUploaders.add(tmp.getAsString(DB.ACCOUNT.NAME));
                } else if (tmp.containsKey(DB.ACCOUNT.FLAGS)
                        && Bitfield.test(tmp.getAsLong(DB.ACCOUNT.FLAGS), DB.ACCOUNT.FLAG_UPLOAD)) {
                    pendingUploaders.add(tmp.getAsString(DB.ACCOUNT.NAME));
                }
            } while (c.moveToNext());
        }
        c.close();
    }

    if (mode == MODE_DETAILS) {
        if (pendingUploaders.isEmpty()) {
            uploadButton.setVisibility(View.GONE);
        } else {
            uploadButton.setVisibility(View.VISIBLE);
        }
    }

    for (BaseAdapter a : adapters) {
        a.notifyDataSetChanged();
    }
}

From source file:jen.jobs.application.UpdateJobSeeking.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int clickedItem = item.getItemId();
    if (clickedItem == R.id.save) {
        if (isOnline) {
            ArrayList<String> errors = new ArrayList<>();
            if (selectedJobSeekingStatusValues == null) {
                errors.add("Please select jobseeking status!");
            }//from   w ww .  j  av a  2s.  c  o m

            if (selectedAvailability.length() == 0 && selectedAvailabilityUnit.length() == 0) {
                errors.add("Please select your notice period!");
            }

            if (selectedCountryValues == null) {
                errors.add("Please select the country!");
            } else {
                if (selectedCountryValues.id == 127) {
                    if (selectedMalaysiaStateValues == null) {
                        errors.add("Please select the state!");
                    }
                }
            }

            if (errors.size() == 0) {
                JSONObject obj = new JSONObject();

                // TODO - save to profile, local db
                ContentValues cv = new ContentValues();
                cv.put("js_jobseek_status_id", selectedJobSeekingStatusValues.id);
                cv.put("driving_license", cbLicense.isChecked() ? 1 : 0);
                cv.put("transport", cbTransport.isChecked() ? 1 : 0);
                cv.put("availability", selectedAvailability);
                cv.put("availability_unit", selectedAvailabilityUnit.substring(0, 1));
                tableProfile.updateProfile(cv, profileId);

                // TODO - save to address, add address to parameter
                ContentValues cv2 = new ContentValues();
                if (selectedMalaysiaStateValues != null) {
                    cv2.put("state_id", selectedMalaysiaStateValues.id);
                    cv2.put("state_name", selectedMalaysiaStateValues.name);
                } else {
                    cv2.put("state_id", 0);
                    cv2.put("state_name", "");
                }
                cv2.put("country_id", selectedCountryValues.id);
                cv2.put("updated_at", Jenjobs.date(null, "yyyy-MM-dd", null));
                tableAddress.updateAddress(cv2);

                // update POST data
                try {
                    obj.put("js_jobseek_status_id", cv.getAsString("js_jobseek_status_id"));
                    obj.put("driving_license", cv.getAsString("driving_license"));
                    obj.put("transport", cv.getAsString("transport"));
                    obj.put("availability", cv.getAsString("availability"));
                    obj.put("availability_unit", cv.getAsString("availability_unit"));

                    obj.put("state_id", cv.getAsString("state_id"));
                    obj.put("country_id", cv.getAsString("country_id"));
                } catch (JSONException e) {
                    Log.e("err", e.getMessage());
                }

                // TODO - change cv to ArrayList -> String, post to server
                String accessToken = sharedPref.getString("access_token", null);
                PostRequest p = new PostRequest();
                p.setResultListener(new PostRequest.ResultListener() {
                    @Override
                    public void processResult(JSONObject success) {
                        if (success != null) {
                            try {
                                success.get("status_code");
                            } catch (JSONException e) {
                                Log.e("test", e.getMessage());
                            }
                        }
                    }
                });

                String[] s = { Jenjobs.JOBSEEKING_INFO + "?access-token=" + accessToken, obj.toString() };
                p.execute(s);

                Intent intent = new Intent();
                intent.putExtra("summary", selectedJobSeekingStatusValues.name);
                setResult(Activity.RESULT_OK, intent);
                finish();
            } else {
                Toast.makeText(getApplicationContext(), TextUtils.join(", ", errors), Toast.LENGTH_LONG).show();
            }
        } else {
            Toast.makeText(getApplicationContext(), R.string.network_error, Toast.LENGTH_LONG).show();
        }
    }
    return true;
}