List of usage examples for android.content ContentValues containsKey
public boolean containsKey(String key)
From source file:at.bitfire.ical4android.AndroidCalendar.java
protected void populate(ContentValues info) { name = info.getAsString(Calendars.NAME); displayName = info.getAsString(Calendars.CALENDAR_DISPLAY_NAME); if (info.containsKey(Calendars.CALENDAR_COLOR)) color = info.getAsInteger(Calendars.CALENDAR_COLOR); isSynced = info.getAsInteger(Calendars.SYNC_EVENTS) != 0; isVisible = info.getAsInteger(Calendars.VISIBLE) != 0; }
From source file:com.google.android.apps.gutenberg.provider.SyncAdapter.java
private ContentValues[] parseAttendees(String eventId, JSONArray attendees) throws JSONException { int length = attendees.length(); ContentValues[] array = new ContentValues[length]; HashMap<String, String> imageUrls = new HashMap<>(); for (int i = 0; i < length; ++i) { JSONObject attendee = attendees.getJSONObject(i); array[i] = new ContentValues(); array[i].put(Table.Attendee.EVENT_ID, eventId); array[i].put(Table.Attendee.NAME, attendee.getString("name")); array[i].put(Table.Attendee.ID, attendee.getString("id")); array[i].put(Table.Attendee.EMAIL, attendee.getString("email")); String plusid = attendee.getString("plusid"); if (!TextUtils.isEmpty(plusid)) { array[i].put(Table.Attendee.PLUSID, plusid); imageUrls.put(plusid, "null"); }//from w w w. ja va 2s. c om long checkinTime = attendee.getLong("checkinTime"); if (0 == checkinTime) { array[i].putNull(Table.Attendee.CHECKIN); } else { array[i].put(Table.Attendee.CHECKIN, checkinTime); } array[i].putNull(Table.Attendee.IMAGE_URL); } // Fetch all the Google+ Image URLs at once if necessary if (mApiClient != null && mApiClient.isConnected() && !imageUrls.isEmpty()) { People.LoadPeopleResult result = Plus.PeopleApi.load(mApiClient, imageUrls.keySet()).await(); PersonBuffer personBuffer = result.getPersonBuffer(); if (personBuffer != null) { // Copy URLs into the HashMap for (Person person : personBuffer) { if (person.hasImage()) { imageUrls.put(extractId(person.getUrl()), person.getImage().getUrl()); } } // Fill the missing URLs in the array of ContentValues for (ContentValues values : array) { if (values.containsKey(Table.Attendee.PLUSID)) { String plusId = values.getAsString(Table.Attendee.PLUSID); String imageUrl = imageUrls.get(plusId); if (!TextUtils.isEmpty(imageUrl)) { values.put(Table.Attendee.IMAGE_URL, imageUrl); } } } } } return array; }
From source file:bander.notepad.NoteEditAppCompat.java
@Override protected void onPause() { super.onPause(); if (mUri != null) { String bodyText = mBodyText.getText().toString(); int length = bodyText.length(); if ((mState == STATE_INSERT) && isFinishing() && (length == 0)) { // If inserting and finishing and no text then delete the note. setResult(RESULT_CANCELED);/*from w w w .j a v a 2 s.c o m*/ deleteNote(); } else { ContentValues values = mOriginalNote.getContentValues(); if (values.containsKey(Note._ID)) values.remove(Note._ID); if (mState == STATE_INSERT) { String[] lines = bodyText.split("[\n\\.]"); String title = (lines.length > 0) ? lines[0] : getString(android.R.string.untitled); if (title.length() > 30) { int lastSpace = title.lastIndexOf(' '); if (lastSpace > 0) { title = title.substring(0, lastSpace); } } values.put(Note.TITLE, title); } values.put(Note.BODY, bodyText); values.put(Note.CURSOR, mBodyText.getSelectionStart()); values.put(Note.SCROLL_Y, mBodyText.getScrollY()); getContentResolver().update(mUri, values, null, null); } } }
From source file:org.barbon.mangaget.fragments.MangaDetails.java
private void reload() { DB db = DB.getInstance(getActivity()); ContentValues manga = db.getManga(currentManga); ContentValues metadata = db.getMangaMetadata(currentManga); List<Integer> missingList = new ArrayList<Integer>(); int lastChapter = Utils.mangaChapterInfo(getActivity(), currentManga, missingList); title.setText(manga.getAsString(DB.MANGA_TITLE)); if (metadata.size() != 0) { setInProgress(false);//from ww w . ja v a 2 s . c o m if (metadata.containsKey("genres")) genres.setText(metadata.getAsString("genres")); else genres.setText(R.string.not_available); if (metadata.containsKey("summary")) summary.setText(metadata.getAsString("summary")); else summary.setText(R.string.not_available); last.setText(Utils.formatChapterNumber(lastChapter)); if (missingList.size() > 0) { missing.setVisibility(View.VISIBLE); missing_label.setVisibility(View.VISIBLE); missing.setText(Utils.formatMissingChapters(missingList)); } else { missing.setVisibility(View.GONE); missing_label.setVisibility(View.GONE); } } else { Download.startMangaUpdate(getActivity(), currentManga); } }
From source file:org.coocood.vcontentprovider.VContentProvider.java
/** * This implementation do not accept primary key value. If you want to * insert a record with a primary key, call update instead, it will be * inserted automatically if not exists. * /*from www . j ava 2s. c om*/ * @see android.content.ContentProvider#insert(android.net.Uri, * android.content.ContentValues) */ @Override public Uri insert(Uri uri, ContentValues values) { String tableName = getTableName(uri); String idPath = getIdPath(uri); if (idPath != null) throw new IllegalArgumentException("Unknown URI " + uri); if (values.containsKey("_id")) throw new IllegalArgumentException("insert method do not accept primary key, call update instead."); db = mOpenHelper.getWritableDatabase(); long id = db.insert(tableName, null, values); if (id != -1) { notifyChange(uri, 1); return ContentUris.withAppendedId(uri, id); } return null; }
From source file:com.odoo.support.provider.OContentProvider.java
private HashMap<String, List<Integer>> getManyToManyRecords(ContentValues values) { HashMap<String, List<Integer>> ids = new HashMap<String, List<Integer>>(); for (OColumn col : model.getRelationColumns()) { if (col.getRelationType() == RelationType.ManyToMany) { if (values.containsKey(col.getName())) { List<Integer> record_ids = new ArrayList<Integer>(); try { record_ids.addAll(/*from w w w . j a v a2s. co m*/ JSONUtils.<Integer>toList(new JSONArray(values.get(col.getName()).toString()))); } catch (Exception e) { e.printStackTrace(); } ids.put(col.getName(), record_ids); values.remove(col.getName()); } } } return ids; }
From source file:com.concentricsky.android.khanacademy.data.remote.LibraryUpdaterTask.java
private ChildArrayResults parseChildArray(JsonParser parser, SQLiteDatabase tempDb, String parentTopic_id) throws JsonParseException, IOException { ChildArrayResults result = new ChildArrayResults(); int seq = 0;/*from www. ja v a 2s .c o m*/ JsonToken currentToken = parser.getCurrentToken(); if (currentToken == JsonToken.START_ARRAY) { while (parser.nextValue() == JsonToken.START_OBJECT) { // Otherwise, we will be at END_ARRAY here. ContentValues values = parseObject(parser, tempDb, parentTopic_id, seq++); if (values != null && values.containsKey("kind")) { String kind = values.getAsString("kind"); if ("Topic".equals(kind) && values.containsKey("_id")) { result.childKind = kind; result.childIds.add(values.getAsString("_id")); result.videoCount += values.getAsInteger("video_count"); if (result.thumbId == null && values.containsKey("thumb_id")) { // Return the first available thumb id as this topic's thumb id. result.thumbId = values.getAsString("thumb_id"); } } else if ("Video".equals(kind) && values.containsKey("readable_id")) { result.childKind = kind; result.childIds.add(values.getAsString("readable_id")); result.videoCount += 1; if (result.thumbId == null && values.containsKey("pngurl")) { // Return youtube_id of first video with a thumbnail as this topic's thumbnail id. result.thumbId = values.getAsString("youtube_id"); } } } } } return result; }
From source file:com.example.android.notepad.CMNotesProvider.java
@Override public Uri insert(Uri uri, ContentValues initialValues) { // Validate the requested uri if (sUriMatcher.match(uri) != NOTES) { throw new IllegalArgumentException("Unknown URI " + uri); }/*from w w w . java2 s. co 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(NotePad.Notes.CREATED_DATE) == false) { values.put(NotePad.Notes.CREATED_DATE, now); } if (values.containsKey(NotePad.Notes.MODIFIED_DATE) == false) { values.put(NotePad.Notes.MODIFIED_DATE, now); } if (values.containsKey(NotePad.Notes.TITLE) == false) { Resources r = Resources.getSystem(); values.put(NotePad.Notes.TITLE, r.getString(android.R.string.untitled)); } if (values.containsKey(NotePad.Notes.NOTE) == false) { values.put(NotePad.Notes.NOTE, ""); } CMAdapter cmadapter = new CMAdapter(); // for the moment, use time for the key String key = System.currentTimeMillis() + ""; String new_key = cmadapter.updateValue(key, values); if (new_key != null) { System.out.println("Set key: " + key + ", got key: " + new_key); Uri noteUri = ContentUris.withAppendedId(NotePad.Notes.CONTENT_URI, Long.parseLong(new_key)); getContext().getContentResolver().notifyChange(noteUri, null); return noteUri; } // SQLiteDatabase db = mOpenHelper.getWritableDatabase(); // long rowId = db.insert(NOTES_TABLE_NAME, Notes.NOTE, values); // if (rowId > 0) { // Uri noteUri = ContentUris.withAppendedId(NotePad.Notes.CONTENT_URI, rowId); // getContext().getContentResolver().notifyChange(noteUri, null); // return noteUri; // } throw new SQLException("Failed to insert row into " + uri); }
From source file:com.csipsimple.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); }//from ww w . ja va2 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); 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, 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.fututel.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); }/*from ww w .j a v a2s. 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); 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, 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_light); 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); } }