List of usage examples for android.content ContentValues containsKey
public boolean containsKey(String key)
From source file:org.mozilla.labs.Soup.provider.AppsProvider.java
@Override public Uri insert(Uri uri, ContentValues initialValues) { // Validate the requested uri if (sUriMatcher.match(uri) != APPS) { throw new IllegalArgumentException("Unknown URI " + uri); }//from w ww . j a va 2 s . c o m ContentValues values; if (initialValues != null) { values = new ContentValues(initialValues); } else { values = new ContentValues(); } Long now = Long.valueOf(System.currentTimeMillis()); // Make sure that the fields are all set if (values.containsKey(AppsContract.Apps.CREATED_DATE) == false) { values.put(AppsContract.Apps.CREATED_DATE, now); } if (values.containsKey(AppsContract.Apps.MODIFIED_DATE) == false) { values.put(AppsContract.Apps.MODIFIED_DATE, now); } if (values.containsKey(AppsContract.Apps.INSTALL_TIME) == false) { values.put(AppsContract.Apps.INSTALL_TIME, now); } if (values.containsKey(AppsContract.Apps.NAME) == false) { Resources r = Resources.getSystem(); values.put(AppsContract.Apps.NAME, r.getString(android.R.string.untitled)); } if (values.containsKey(AppsContract.Apps.DESCRIPTION) == false) { values.put(AppsContract.Apps.DESCRIPTION, ""); } if (values.containsKey(AppsContract.Apps.MANIFEST) == false) { values.put(AppsContract.Apps.MANIFEST, new JSONObject().toString()); } if (values.containsKey(AppsContract.Apps.MANIFEST_URL) == false) { values.put(AppsContract.Apps.MANIFEST_URL, ""); } if (values.containsKey(AppsContract.Apps.INSTALL_DATA) == false) { values.put(AppsContract.Apps.INSTALL_DATA, new JSONObject().toString()); } if (values.containsKey(AppsContract.Apps.STATUS) == false) { values.put(AppsContract.Apps.STATUS, 0); } SQLiteDatabase db = mOpenHelper.getWritableDatabase(); long rowId = db.insert(APPS_TABLE_NAME, null, values); if (rowId > 0) { Uri appUri = ContentUris.withAppendedId(AppsContract.Apps.CONTENT_URI, rowId); getContext().getContentResolver().notifyChange(appUri, null); return appUri; } throw new SQLException("Failed to insert row into " + uri); }
From source file:com.jasonmheim.rollout.station.CoreContentProvider.java
@Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { // TODO: this is silly. Disambiguate by using different URIs for data, location, action, etc if (values.containsKey(Constants.UPDATE_KEY_LOCATION)) { Log.i("Rollout", "Updating location"); internalUpdate();/*from w ww .j av a2s. co m*/ } else if (values.containsKey(Constants.UPDATE_KEY_ACTION)) { // TODO: Do this in the ActionManager. It's ridiculous to do this here. int action = actionManager.getAction(); Log.i("Rollout", "Updating action to " + action); switch (action) { case Constants.ACTION_SEARCH: Log.i("Rollout", "Active search action"); // Medium location speed locationManager.setLocationUpdateInterval(1, PRIORITY_HIGH_ACCURACY); // Fast periodic sync setSyncPeriod(1); break; case Constants.ACTION_RIDE: Log.i("Rollout", "Riding action"); // Fast location speed locationManager.setLocationUpdateInterval(0.5, PRIORITY_HIGH_ACCURACY); // Fast periodic sync setSyncPeriod(1); break; case Constants.ACTION_IDLE: Log.i("Rollout", "Passive search action"); // Slow location speed locationManager.setLocationUpdateInterval(10, PRIORITY_BALANCED_POWER_ACCURACY); // Slow periodic sync setSyncPeriod(5); break; case Constants.ACTION_SILENCE: Log.i("Rollout", "Muted action"); // Extra slow location speed locationManager.setLocationUpdateInterval(60, PRIORITY_BALANCED_POWER_ACCURACY); // Extra slow periodic sync setSyncPeriod(20); } internalUpdate(); } return 0; }
From source file:org.blanco.techmun.android.cproviders.ComentariosFetcher.java
public boolean publishComentario(ContentValues values) { HttpPost request = new HttpPost("http://tec-ch-mun-2011.herokuapp.com/application/publicarcomentario"); HttpResponse response = null;//from w w w. j av a2 s . c o m try { //prepare the entity for the request List<BasicNameValuePair> parameters = new ArrayList<BasicNameValuePair>(); parameters.add(new BasicNameValuePair("comentario.evento.id", values.getAsString("eventoId"))); parameters.add(new BasicNameValuePair("comentario.comentario", values.getAsString("comentario"))); if (values.containsKey("autor")) { parameters.add(new BasicNameValuePair("comentario.autor", values.getAsString("autor"))); } if (values.containsKey("contacto")) { parameters.add(new BasicNameValuePair("comentario.contacto", values.getAsString("contacto"))); } UrlEncodedFormEntity entity = new UrlEncodedFormEntity(parameters); request.setEntity(entity); response = httpClient.execute(request); if (response.getStatusLine().getStatusCode() == 200) { return true; } } catch (Exception ex) { Log.e("techmun", "Error publishComentario. Comment not sent", ex); } return false; }
From source file:at.bitfire.ical4android.AndroidTask.java
protected void populateTask(ContentValues values) throws FileNotFoundException, RemoteException, ParseException { task.uid = values.getAsString(Tasks._UID); task.summary = values.getAsString(Tasks.TITLE); task.location = values.getAsString(Tasks.LOCATION); if (values.containsKey(Tasks.GEO)) { String geo = values.getAsString(Tasks.GEO); if (geo != null) task.geoPosition = new Geo(geo); }/*www.ja v a 2 s . c o m*/ ; task.description = StringUtils.stripToNull(values.getAsString(Tasks.DESCRIPTION)); task.url = StringUtils.stripToNull(values.getAsString(Tasks.URL)); String organizer = values.getAsString(Tasks.ORGANIZER); if (!TextUtils.isEmpty(organizer)) try { task.organizer = new Organizer("mailto:" + values.getAsString(Tasks.ORGANIZER)); } catch (URISyntaxException e) { Log.w(TAG, "Invalid ORGANIZER email", e); } Integer priority = values.getAsInteger(Tasks.PRIORITY); if (priority != null) task.priority = priority; Integer classification = values.getAsInteger(Tasks.CLASSIFICATION); if (classification != null) switch (classification) { case Tasks.CLASSIFICATION_PUBLIC: task.classification = Clazz.PUBLIC; break; case Tasks.CLASSIFICATION_CONFIDENTIAL: task.classification = Clazz.CONFIDENTIAL; break; default: task.classification = Clazz.PRIVATE; } Long completed = values.getAsLong(Tasks.COMPLETED); if (completed != null) // COMPLETED must always be a DATE-TIME task.completedAt = new Completed(new DateTime(completed)); Integer percentComplete = values.getAsInteger(Tasks.PERCENT_COMPLETE); if (percentComplete != null) task.percentComplete = percentComplete; Integer status = values.getAsInteger(Tasks.STATUS); if (status != null) switch (status) { case Tasks.STATUS_IN_PROCESS: task.status = Status.VTODO_IN_PROCESS; break; case Tasks.STATUS_COMPLETED: task.status = Status.VTODO_COMPLETED; break; case Tasks.STATUS_CANCELLED: task.status = Status.VTODO_CANCELLED; break; default: task.status = Status.VTODO_NEEDS_ACTION; } boolean allDay = false; if (values.getAsInteger(Tasks.IS_ALLDAY) != null) allDay = values.getAsInteger(Tasks.IS_ALLDAY) != 0; String tzID = values.getAsString(Tasks.TZ); TimeZone tz = (tzID != null) ? DateUtils.tzRegistry.getTimeZone(tzID) : null; Long createdAt = values.getAsLong(Tasks.CREATED); if (createdAt != null) task.createdAt = createdAt; Long lastModified = values.getAsLong(Tasks.LAST_MODIFIED); if (lastModified != null) task.lastModified = lastModified; Long dtStart = values.getAsLong(Tasks.DTSTART); if (dtStart != null) { long ts = dtStart; Date dt; if (allDay) dt = new Date(ts); else { dt = new DateTime(ts); if (tz != null) ((DateTime) dt).setTimeZone(tz); } task.dtStart = new DtStart(dt); } Long due = values.getAsLong(Tasks.DUE); if (due != null) { long ts = due; Date dt; if (allDay) dt = new Date(ts); else { dt = new DateTime(ts); if (tz != null) ((DateTime) dt).setTimeZone(tz); } task.due = new Due(dt); } String duration = values.getAsString(Tasks.DURATION); if (duration != null) task.duration = new Duration(new Dur(duration)); String rDate = values.getAsString(Tasks.RDATE); if (rDate != null) task.getRDates().add((RDate) DateUtils.androidStringToRecurrenceSet(rDate, RDate.class, allDay)); String exDate = values.getAsString(Tasks.EXDATE); if (exDate != null) task.getExDates().add((ExDate) DateUtils.androidStringToRecurrenceSet(exDate, ExDate.class, allDay)); String rRule = values.getAsString(Tasks.RRULE); if (rRule != null) task.rRule = new RRule(rRule); }
From source file:com.roamprocess1.roaming4world.ui.favorites.FavAdapter.java
@Override public void bindView(View view, final Context context, Cursor cursor) { ContentValues cv = new ContentValues(); DatabaseUtils.cursorRowToContentValues(cursor, cv); int type = ContactsWrapper.TYPE_CONTACT; if (cv.containsKey(ContactsWrapper.FIELD_TYPE)) { type = cv.getAsInteger(ContactsWrapper.FIELD_TYPE); }// w ww . ja v a 2 s .c o m showViewForType(view, type); if (type == ContactsWrapper.TYPE_GROUP) { // Get views TextView tv = (TextView) view.findViewById(R.id.header_text); ImageView icon = (ImageView) view.findViewById(R.id.header_icon); // PresenceStatusSpinner presSpinner = (PresenceStatusSpinner) view.findViewById(R.id.header_presence_spinner); // Get datas SipProfile acc = new SipProfile(cursor); final Long profileId = cv.getAsLong(BaseColumns._ID); final String groupName = acc.android_group; final String displayName = acc.display_name; final String wizard = acc.wizard; final boolean publishedEnabled = (acc.publish_enabled == 1); final String domain = acc.getDefaultDomain(); // Bind datas to view //tv.setText(displayName); //Commented by Esstel Softwares tv.setText("Starred Android Contacts"); icon.setImageResource(WizardUtils.getWizardIconRes(wizard)); // presSpinner.setProfileId(profileId); // Extra menu view if not already set ViewGroup menuViewWrapper = (ViewGroup) view.findViewById(R.id.header_cfg_spinner); MenuCallback newMcb = new MenuCallback(context, profileId, groupName, domain, publishedEnabled); MenuBuilder menuBuilder; if (menuViewWrapper.getTag() == null) { final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); ActionMenuPresenter mActionMenuPresenter = new ActionMenuPresenter(mContext); mActionMenuPresenter.setReserveOverflow(true); menuBuilder = new MenuBuilder(context); menuBuilder.setCallback(newMcb); MenuInflater inflater = new MenuInflater(context); inflater.inflate(R.menu.fav_menu_new, menuBuilder); menuBuilder.addMenuPresenter(mActionMenuPresenter); ActionMenuView menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(menuViewWrapper); UtilityWrapper.getInstance().setBackgroundDrawable(menuView, null); menuViewWrapper.addView(menuView, layoutParams); menuViewWrapper.setTag(menuBuilder); } else { menuBuilder = (MenuBuilder) menuViewWrapper.getTag(); menuBuilder.setCallback(newMcb); } // menuBuilder.findItem(R.id.share_presence).setTitle(publishedEnabled ? R.string.deactivate_presence_sharing : R.string.activate_presence_sharing); // menuBuilder.findItem(R.id.set_sip_data).setVisible(!TextUtils.isEmpty(groupName)); } else if (type == ContactsWrapper.TYPE_CONTACT) { ContactInfo ci = ContactsWrapper.getInstance().getContactInfo(context, cursor); ci.userData = cursor.getPosition(); // Get views TextView tv = (TextView) view.findViewById(R.id.contact_name); QuickContactBadge badge = (QuickContactBadge) view.findViewById(R.id.quick_contact_photo); TextView statusText = (TextView) view.findViewById(R.id.status_text); ImageView statusImage = (ImageView) view.findViewById(R.id.status_icon); // Bind if (ci.contactId != null) { tv.setText(ci.displayName); badge.assignContactUri(ci.callerInfo.contactContentUri); ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(context, badge.getImageView(), ci.callerInfo, R.drawable.ic_contact_picture_holo_dark); statusText.setVisibility(ci.hasPresence ? View.VISIBLE : View.GONE); statusText.setText(ci.status); statusImage.setVisibility(ci.hasPresence ? View.VISIBLE : View.GONE); statusImage.setImageResource(ContactsWrapper.getInstance().getPresenceIconResourceId(ci.presence)); } View v; v = view.findViewById(R.id.contact_view); v.setTag(ci); v.setOnClickListener(mPrimaryActionListener); v = view.findViewById(R.id.secondary_action_icon); v.setTag(ci); v.setOnClickListener(mSecondaryActionListener); } else if (type == ContactsWrapper.TYPE_CONFIGURE) { // We only bind if it's the correct type // View v = view.findViewById(R.id.configure_view); //v.setOnClickListener(this); //ConfigureObj cfg = new ConfigureObj(); // cfg.profileId = cv.getAsLong(BaseColumns._ID); // v.setTag(cfg); } }
From source file:com.partypoker.poker.engagement.reach.EngagementReachContent.java
/** * Parse a campaign./*w w w. ja va 2 s.c o m*/ * @param campaignId already parsed campaign id. * @param values content data. * @throws JSONException if payload parsing failure. */ EngagementReachContent(com.microsoft.azure.engagement.reach.CampaignId campaignId, ContentValues values) throws JSONException { /* Parse base fields */ mCampaignId = campaignId; mDlc = values.getAsInteger(DLC); mDlcId = values.getAsString(DLC_ID); mCategory = values.getAsString(CATEGORY); Long expiry = values.getAsLong(TTL); if (expiry != null) { expiry *= 1000L; if (parseBoolean(values, USER_TIME_ZONE)) expiry -= TimeZone.getDefault().getOffset(expiry); } mExpiry = expiry; if (values.containsKey(PAYLOAD)) setPayload(new JSONObject(values.getAsString(PAYLOAD))); }
From source file:com.android.talkback.labeling.LabelProvider.java
/** * Inserts a label in the labels database. * * @param uri The content URI for labels. * @param values The values to insert for the new label. * @return The URI of the newly inserted label, * or {@code null} if the insert failed. *///from w w w . j av a 2 s .c om @Override public Uri insert(Uri uri, ContentValues values) { if (uri == null) { LogUtils.log(this, Log.WARN, NULL_URI_FORMAT_STRING); return null; } if (!UserManagerCompat.isUserUnlocked(getContext())) { return null; } switch (sUriMatcher.match(uri)) { case LABELS: initializeDatabaseIfNull(); if (values == null) { return null; } if (values.containsKey(LabelsTable.KEY_ID)) { LogUtils.log(this, Log.WARN, "Label ID must be assigned by the database."); return null; } long rowId = mDatabase.insert(LabelsTable.TABLE_NAME, null, values); if (rowId < 0) { LogUtils.log(this, Log.WARN, "Failed to insert label."); return null; } else { return ContentUris.withAppendedId(LABELS_CONTENT_URI, rowId); } default: LogUtils.log(this, Log.WARN, UNKNOWN_URI_FORMAT_STRING, uri); return null; } }
From source file:id.ridon.keude.UpdateService.java
private ContentProviderOperation updateExistingApp(App app) { Uri uri = AppProvider.getContentUri(app); ContentValues values = app.toContentValues(); for (String toIgnore : APP_FIELDS_TO_IGNORE) { if (values.containsKey(toIgnore)) { values.remove(toIgnore);// w w w . j av a 2s.c om } } return ContentProviderOperation.newUpdate(uri).withValues(values).build(); }
From source file:org.opendatakit.common.android.provider.impl.FormsProviderImpl.java
private void patchUpValues(String appName, ContentValues values) { // don't let users put in a manual FORM_FILE_PATH if (values.containsKey(FormsColumns.APP_RELATIVE_FORM_FILE_PATH)) { values.remove(FormsColumns.APP_RELATIVE_FORM_FILE_PATH); }//www.j a va2s .com // don't let users put in a manual FORM_PATH if (values.containsKey(FormsColumns.FORM_PATH)) { values.remove(FormsColumns.FORM_PATH); } // don't let users put in a manual DATE if (values.containsKey(FormsColumns.DATE)) { values.remove(FormsColumns.DATE); } // don't let users put in a manual md5 hash if (values.containsKey(FormsColumns.MD5_HASH)) { values.remove(FormsColumns.MD5_HASH); } // don't let users put in a manual json md5 hash if (values.containsKey(FormsColumns.JSON_MD5_HASH)) { values.remove(FormsColumns.JSON_MD5_HASH); } // if we are not updating FORM_MEDIA_PATH, we don't need to recalc any // of the above if (!values.containsKey(FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH)) { return; } // Normalize path... // First, construct the full file path... String path = values.getAsString(FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH); File mediaPath; if (path.startsWith(File.separator)) { mediaPath = new File(path); } else { mediaPath = ODKFileUtils.asAppFile(appName, 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()); } if (!ODKFileUtils.isPathUnderAppName(appName, mediaPath)) { throw new IllegalArgumentException( "Form definition is not contained within the application: " + appName); } values.put(FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH, ODKFileUtils.asRelativePath(appName, mediaPath)); // require that it contain a formDef file File formDefFile = new File(mediaPath, ODKFileUtils.FORMDEF_JSON_FILENAME); if (!formDefFile.exists()) { throw new IllegalArgumentException( ODKFileUtils.FORMDEF_JSON_FILENAME + " does not exist in: " + mediaPath.getAbsolutePath()); } // date is the last modification date of the formDef file Long now = formDefFile.lastModified(); values.put(FormsColumns.DATE, now); // ODK2: FILENAME_XFORMS_XML may not exist if non-ODK1 fetch path... File xformsFile = new File(mediaPath, ODKFileUtils.FILENAME_XFORMS_XML); if (xformsFile.exists()) { values.put(FormsColumns.APP_RELATIVE_FORM_FILE_PATH, ODKFileUtils.asRelativePath(appName, xformsFile)); } // compute FORM_PATH... String formPath = ODKFileUtils.getRelativeFormPath(appName, formDefFile); values.put(FormsColumns.FORM_PATH, formPath); String md5; if (xformsFile.exists()) { md5 = ODKFileUtils.getMd5Hash(appName, xformsFile); } else { md5 = "-none-"; } values.put(FormsColumns.MD5_HASH, md5); md5 = ODKFileUtils.getMd5Hash(appName, formDefFile); values.put(FormsColumns.JSON_MD5_HASH, md5); }
From source file:org.runnerup.export.FacebookSynchronizer.java
@Override public void init(ContentValues config) { String authConfig = config.getAsString(DB.ACCOUNT.AUTH_CONFIG); if (authConfig != null) { try {/*from ww w .j av a 2 s . c o m*/ JSONObject tmp = new JSONObject(authConfig); access_token = tmp.optString("access_token", null); token_now = tmp.optLong("token_now"); expire_time = tmp.optLong("expire_time"); } catch (Exception e) { e.printStackTrace(); } } id = config.getAsLong("_id"); if (config.containsKey(DB.ACCOUNT.FLAGS)) { long flags = config.getAsLong(DB.ACCOUNT.FLAGS); if (Bitfield.test(flags, DB.ACCOUNT.FLAG_SKIP_MAP)) { skipMapInPost = true; } } }