List of usage examples for android.content ContentUris withAppendedId
public static Uri withAppendedId(Uri contentUri, long id)
From source file:com.android.contacts.ContactSaveService.java
private void deleteGroup(Intent intent) { long groupId = intent.getLongExtra(EXTRA_GROUP_ID, -1); if (groupId == -1) { Log.e(TAG, "Invalid arguments for deleteGroup request"); return;/*from w ww. j a va 2 s.c o m*/ } final Uri groupUri = ContentUris.withAppendedId(Groups.CONTENT_URI, groupId); final Intent callbackIntent = new Intent(BROADCAST_GROUP_DELETED); final Bundle undoData = mGroupsDao.captureDeletionUndoData(groupUri); callbackIntent.putExtra(EXTRA_UNDO_ACTION, ACTION_DELETE_GROUP); callbackIntent.putExtra(EXTRA_UNDO_DATA, undoData); mGroupsDao.delete(groupUri); LocalBroadcastManager.getInstance(this).sendBroadcast(callbackIntent); }
From source file:com.android.exchange.ExchangeService.java
/** * Register a specific Calendar's data observer; we need to recognize when the SYNC_EVENTS * column has changed (when sync has turned off or on) * @param account the Account whose Calendar we're observing *//* w w w . java 2 s . c om*/ private void registerCalendarObserver(Account account) { // Get a new observer CalendarObserver observer = new CalendarObserver(mHandler, account); if (observer.mCalendarId != 0) { // If we find the Calendar (and we'd better) register it and store it in the map mCalendarObservers.put(account.mId, observer); mResolver.registerContentObserver( ContentUris.withAppendedId(Calendars.CONTENT_URI, observer.mCalendarId), false, observer); } }
From source file:com.android.contacts.ContactSaveService.java
private void updateGroup(Intent intent) { long groupId = intent.getLongExtra(EXTRA_GROUP_ID, -1); String label = intent.getStringExtra(EXTRA_GROUP_LABEL); long[] rawContactsToAdd = intent.getLongArrayExtra(EXTRA_RAW_CONTACTS_TO_ADD); long[] rawContactsToRemove = intent.getLongArrayExtra(EXTRA_RAW_CONTACTS_TO_REMOVE); if (groupId == -1) { Log.e(TAG, "Invalid arguments for updateGroup request"); return;/*from w w w .ja v a2 s .c o m*/ } final ContentResolver resolver = getContentResolver(); final Uri groupUri = ContentUris.withAppendedId(Groups.CONTENT_URI, groupId); // Update group name if necessary if (label != null) { ContentValues values = new ContentValues(); values.put(Groups.TITLE, label); resolver.update(groupUri, values, null, null); } // Add and remove members if necessary addMembersToGroup(resolver, rawContactsToAdd, groupId); removeMembersFromGroup(resolver, rawContactsToRemove, groupId); Intent callbackIntent = intent.getParcelableExtra(EXTRA_CALLBACK_INTENT); callbackIntent.setData(groupUri); deliverCallback(callbackIntent); }
From source file:com.android.calendar.EventInfoFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (savedInstanceState != null) { mIsDialog = savedInstanceState.getBoolean(BUNDLE_KEY_IS_DIALOG, false); mWindowStyle = savedInstanceState.getInt(BUNDLE_KEY_WINDOW_STYLE, DIALOG_WINDOW_STYLE); mDeleteDialogVisible = savedInstanceState.getBoolean(BUNDLE_KEY_DELETE_DIALOG_VISIBLE, false); mDeleteDialogChoice = savedInstanceState.getInt(BUNDLE_KEY_DELETE_DIALOG_CHOICE, -1); mCalendarColor = savedInstanceState.getInt(BUNDLE_KEY_CALENDAR_COLOR); mCalendarColorInitialized = savedInstanceState.getBoolean(BUNDLE_KEY_CALENDAR_COLOR_INIT); mOriginalColor = savedInstanceState.getInt(BUNDLE_KEY_ORIGINAL_COLOR); mOriginalColorInitialized = savedInstanceState.getBoolean(BUNDLE_KEY_ORIGINAL_COLOR_INIT); mCurrentColor = savedInstanceState.getInt(BUNDLE_KEY_CURRENT_COLOR); mCurrentColorInitialized = savedInstanceState.getBoolean(BUNDLE_KEY_CURRENT_COLOR_INIT); mCurrentColorKey = savedInstanceState.getInt(BUNDLE_KEY_CURRENT_COLOR_KEY); mTentativeUserSetResponse = savedInstanceState.getInt(BUNDLE_KEY_TENTATIVE_USER_RESPONSE, Attendees.ATTENDEE_STATUS_NONE); if (mTentativeUserSetResponse != Attendees.ATTENDEE_STATUS_NONE && mEditResponseHelper != null) { // If the edit response helper dialog is open, we'll need to // know if either of the choices were selected. mEditResponseHelper.setWhichEvents(savedInstanceState.getInt(BUNDLE_KEY_RESPONSE_WHICH_EVENTS, -1)); }// w ww. j av a2 s. c o m mUserSetResponse = savedInstanceState.getInt(BUNDLE_KEY_USER_SET_ATTENDEE_RESPONSE, Attendees.ATTENDEE_STATUS_NONE); if (mUserSetResponse != Attendees.ATTENDEE_STATUS_NONE) { // If the response was set by the user before a configuration // change, we'll need to know which choice was selected. mWhichEvents = savedInstanceState.getInt(BUNDLE_KEY_RESPONSE_WHICH_EVENTS, -1); } mReminders = Utils.readRemindersFromBundle(savedInstanceState); } if (mWindowStyle == DIALOG_WINDOW_STYLE) { mView = inflater.inflate(R.layout.event_info_dialog, container, false); } else { mView = inflater.inflate(R.layout.event_info, container, false); } mScrollView = (ScrollView) mView.findViewById(R.id.event_info_scroll_view); mLoadingMsgView = mView.findViewById(R.id.event_info_loading_msg); mErrorMsgView = mView.findViewById(R.id.event_info_error_msg); mTitle = (TextView) mView.findViewById(R.id.title); mWhenDateTime = (TextView) mView.findViewById(R.id.when_datetime); mWhere = (TextView) mView.findViewById(R.id.where); mDesc = (ExpandableTextView) mView.findViewById(R.id.description); mHeadlines = mView.findViewById(R.id.event_info_headline); mLongAttendees = (AttendeesView) mView.findViewById(R.id.long_attendee_list); mResponseRadioGroup = (RadioGroup) mView.findViewById(R.id.response_value); if (mUri == null) { // restore event ID from bundle mEventId = savedInstanceState.getLong(BUNDLE_KEY_EVENT_ID); mUri = ContentUris.withAppendedId(Events.CONTENT_URI, mEventId); mStartMillis = savedInstanceState.getLong(BUNDLE_KEY_START_MILLIS); mEndMillis = savedInstanceState.getLong(BUNDLE_KEY_END_MILLIS); } mAnimateAlpha = ObjectAnimator.ofFloat(mScrollView, "Alpha", 0, 1); mAnimateAlpha.setDuration(FADE_IN_TIME); mAnimateAlpha.addListener(new AnimatorListenerAdapter() { int defLayerType; @Override public void onAnimationStart(Animator animation) { // Use hardware layer for better performance during animation defLayerType = mScrollView.getLayerType(); mScrollView.setLayerType(View.LAYER_TYPE_HARDWARE, null); // Ensure that the loading message is gone before showing the // event info mLoadingMsgView.removeCallbacks(mLoadingMsgAlphaUpdater); mLoadingMsgView.setVisibility(View.GONE); } @Override public void onAnimationCancel(Animator animation) { mScrollView.setLayerType(defLayerType, null); } @Override public void onAnimationEnd(Animator animation) { mScrollView.setLayerType(defLayerType, null); // Do not cross fade after the first time mNoCrossFade = true; } }); mLoadingMsgView.setAlpha(0); mScrollView.setAlpha(0); mErrorMsgView.setVisibility(View.INVISIBLE); mLoadingMsgView.postDelayed(mLoadingMsgAlphaUpdater, LOADING_MSG_DELAY); // start loading the data mHandler.startQuery(TOKEN_QUERY_EVENT, null, mUri, EVENT_PROJECTION, null, null, null); View b = mView.findViewById(R.id.delete); b.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (!mCanModifyCalendar) { return; } mDeleteHelper = new DeleteEventHelper(mContext, mActivity, !mIsDialog && !mIsTabletConfig /* exitWhenDone */); mDeleteHelper.setDeleteNotificationListener(EventInfoFragment.this); mDeleteHelper.setOnDismissListener(createDeleteOnDismissListener()); mDeleteDialogVisible = true; mDeleteHelper.delete(mStartMillis, mEndMillis, mEventId, -1, onDeleteRunnable); } }); b = mView.findViewById(R.id.change_color); b.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (!mCanModifyCalendar) { return; } showEventColorPickerDialog(); } }); // Hide Edit/Delete buttons if in full screen mode on a phone if (!mIsDialog && !mIsTabletConfig || mWindowStyle == EventInfoFragment.FULL_WINDOW_STYLE) { mView.findViewById(R.id.event_info_buttons_container).setVisibility(View.GONE); } // Create a listener for the email guests button emailAttendeesButton = (Button) mView.findViewById(R.id.email_attendees_button); if (emailAttendeesButton != null) { emailAttendeesButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { emailAttendees(); } }); } // Create a listener for the add reminder button View reminderAddButton = mView.findViewById(R.id.reminder_add); View.OnClickListener addReminderOnClickListener = new View.OnClickListener() { @Override public void onClick(View v) { addReminder(); mUserModifiedReminders = true; } }; reminderAddButton.setOnClickListener(addReminderOnClickListener); // Set reminders variables SharedPreferences prefs = GeneralPreferences.getSharedPreferences(mActivity); String defaultReminderString = prefs.getString(GeneralPreferences.KEY_DEFAULT_REMINDER, GeneralPreferences.NO_REMINDER_STRING); mDefaultReminderMinutes = Integer.parseInt(defaultReminderString); prepareReminders(); return mView; }
From source file:com.remobile.contacts.ContactAccessorSdk5.java
/** * Create a ContactField JSONObject//from www.j a va 2 s . co m * @param contactId * @return a JSONObject representing a ContactField */ private JSONObject photoQuery(Cursor cursor, String contactId) { JSONObject photo = new JSONObject(); try { photo.put("id", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Photo._ID))); photo.put("pref", false); photo.put("type", "url"); Uri person = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, (Long.valueOf(contactId))); Uri photoUri = Uri.withAppendedPath(person, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY); photo.put("value", photoUri.toString()); // Query photo existance Cursor photoCursor = mApp.getActivity().getContentResolver().query(photoUri, new String[] { ContactsContract.Contacts.Photo.PHOTO }, null, null, null); if (photoCursor == null) { return null; } else { if (!photoCursor.moveToFirst()) { photoCursor.close(); return null; } } } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); } return photo; }
From source file:com.android.contacts.list.DefaultContactBrowseListFragment.java
/** * Share all contacts that are currently selected. This method is pretty inefficient for * handling large numbers of contacts. I don't expect this to be a problem. *///from ww w.j a v a2 s . com private void shareSelectedContacts() { final StringBuilder uriListBuilder = new StringBuilder(); for (Long contactId : getSelectedContactIds()) { final Uri contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId); final Uri lookupUri = ContactsContract.Contacts.getLookupUri(getContext().getContentResolver(), contactUri); if (lookupUri == null) { continue; } final List<String> pathSegments = lookupUri.getPathSegments(); if (pathSegments.size() < 2) { continue; } final String lookupKey = pathSegments.get(pathSegments.size() - 2); if (uriListBuilder.length() > 0) { uriListBuilder.append(':'); } uriListBuilder.append(Uri.encode(lookupKey)); } if (uriListBuilder.length() == 0) { return; } final Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_MULTI_VCARD_URI, Uri.encode(uriListBuilder.toString())); final Intent intent = new Intent(Intent.ACTION_SEND); intent.setType(ContactsContract.Contacts.CONTENT_VCARD_TYPE); intent.putExtra(Intent.EXTRA_STREAM, uri); try { startActivityForResult(Intent.createChooser(intent, getResources() .getQuantityString(R.plurals.title_share_via, /* quantity */ getSelectedContactIds().size())), ACTIVITY_REQUEST_CODE_SHARE); } catch (final ActivityNotFoundException ex) { Toast.makeText(getContext(), R.string.share_error, Toast.LENGTH_SHORT).show(); } }
From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java
/** * Limit the number of cached files per art source to {@link #MAX_CACHE_SIZE}. * @see #MAX_CACHE_SIZE/*w w w . j a v a 2 s . co m*/ */ private void cleanupCachedFiles() { Context context = getContext(); if (context == null) { return; } Cursor sources = querySource(MuzeiContract.Sources.CONTENT_URI, new String[] { MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME }, null, null, null); if (sources == null) { return; } // Access to certain artwork can be persisted through MuzeiDocumentsProvider // We never want to delete these artwork as that would break other apps Set<Uri> persistedUris = MuzeiDocumentsProvider.getPersistedArtworkUris(context); // Loop through each source, cleaning up old artwork while (sources.moveToNext()) { String componentName = sources.getString(0); // Now use that ComponentName to look through the past artwork from that source Cursor artworkBySource = queryArtwork(MuzeiContract.Artwork.CONTENT_URI, new String[] { BaseColumns._ID, MuzeiContract.Artwork.COLUMN_NAME_IMAGE_URI, MuzeiContract.Artwork.COLUMN_NAME_TOKEN }, MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME + "=?", new String[] { componentName }, MuzeiContract.Artwork.COLUMN_NAME_DATE_ADDED + " DESC"); if (artworkBySource == null) { continue; } List<String> artworkIdsToKeep = new ArrayList<>(); List<String> artworkToKeep = new ArrayList<>(); // First find all of the persisted artwork from this source and mark them as artwork to keep while (artworkBySource.moveToNext()) { long id = artworkBySource.getLong(0); Uri uri = ContentUris.withAppendedId(MuzeiContract.Artwork.CONTENT_URI, id); String artworkUri = artworkBySource.getString(1); String artworkToken = artworkBySource.getString(2); String unique = !TextUtils.isEmpty(artworkUri) ? artworkUri : artworkToken; if (persistedUris.contains(uri)) { // Always keep artwork that is persisted artworkIdsToKeep.add(Long.toString(id)); artworkToKeep.add(unique); } } // Now go through the artwork from this source and find the most recent artwork // and mark them as artwork to keep int count = 0; artworkBySource.moveToPosition(-1); while (artworkBySource.moveToNext()) { // BaseColumns._ID is a long, but we need it as a String later anyways String id = artworkBySource.getString(0); String artworkUri = artworkBySource.getString(1); String artworkToken = artworkBySource.getString(2); String unique = !TextUtils.isEmpty(artworkUri) ? artworkUri : artworkToken; if (artworkToKeep.contains(unique)) { // This ensures we are double counting the same artwork in our count artworkIdsToKeep.add(id); continue; } if (count++ < MAX_CACHE_SIZE) { // Keep artwork below the MAX_CACHE_SIZE artworkIdsToKeep.add(id); artworkToKeep.add(unique); } } // Now delete all artwork not in the keep list int numDeleted = deleteArtwork(MuzeiContract.Artwork.CONTENT_URI, MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME + "=?" + " AND " + MuzeiContract.Artwork.TABLE_NAME + "." + BaseColumns._ID + " NOT IN (" + TextUtils.join(",", artworkIdsToKeep) + ")", new String[] { componentName }); if (numDeleted > 0) { Log.d(TAG, "For " + componentName + " kept " + artworkToKeep.size() + " artwork, deleted " + numDeleted); } artworkBySource.close(); } sources.close(); }
From source file:com.akop.bach.parser.XboxLiveParser.java
private void parseUpdateProfile(XboxLiveAccount account, String motto, String name, String location, String bio) throws ParserException, IOException { long started = System.currentTimeMillis(); String url = String.format(URL_EDIT_PROFILE, mLocale); String page = getResponse(url); if (App.getConfig().logToConsole()) started = displayTimeTaken("Profile load", started); List<NameValuePair> inputs = new ArrayList<NameValuePair>(10); getInputs(page, inputs, null);// w w w . j a v a 2s . c o m setValue(inputs, "Motto", motto); setValue(inputs, "RealName", name); setValue(inputs, "Location", location); setValue(inputs, "Bio", bio); try { submitRequest(url, inputs); // This shouldn't happen - user was not redirected throw new ParserException(mContext, R.string.error_updating_profile); } catch (ClientProtocolException e) { // This is normal; user is redirected to his overview page } if (App.getConfig().logToConsole()) started = displayTimeTaken("Profile update", started); // Update local information ContentResolver cr = mContext.getContentResolver(); ContentValues cv = new ContentValues(10); cv.put(Profiles.MOTTO, motto); cv.put(Profiles.NAME, name); cv.put(Profiles.LOCATION, location); cv.put(Profiles.BIO, bio); Uri uri = ContentUris.withAppendedId(Profiles.CONTENT_URI, account.getId()); cr.update(uri, cv, null, null); account.setLastSummaryUpdate(System.currentTimeMillis()); account.save(Preferences.get(mContext)); cr.notifyChange(uri, null); }
From source file:com.android.contacts.activities.PeopleActivity.java
/** * Share all contacts that are currently selected in mAllFragment. This method is pretty * inefficient for handling large numbers of contacts. I don't expect this to be a problem. *//*from ww w. j av a 2 s .co m*/ private void shareSelectedContacts() { final StringBuilder uriListBuilder = new StringBuilder(); for (Long contactId : mAllFragment.getSelectedContactIds()) { final Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId); final Uri lookupUri = Contacts.getLookupUri(getContentResolver(), contactUri); if (lookupUri == null) { continue; } final List<String> pathSegments = lookupUri.getPathSegments(); if (pathSegments.size() < 2) { continue; } final String lookupKey = pathSegments.get(pathSegments.size() - 2); if (uriListBuilder.length() > 0) { uriListBuilder.append(':'); } uriListBuilder.append(Uri.encode(lookupKey)); } if (uriListBuilder.length() == 0) { return; } final Uri uri = Uri.withAppendedPath(Contacts.CONTENT_MULTI_VCARD_URI, Uri.encode(uriListBuilder.toString())); final Intent intent = new Intent(Intent.ACTION_SEND); intent.setType(Contacts.CONTENT_VCARD_TYPE); intent.putExtra(Intent.EXTRA_STREAM, uri); ImplicitIntentsUtil.startActivityOutsideApp(this, intent); }
From source file:at.bitfire.vcard4android.AndroidContact.java
protected Uri rawContactSyncURI() { if (id == null) throw new IllegalStateException("Contact hasn't been saved yet"); return addressBook.syncAdapterURI(ContentUris.withAppendedId(ContactsContract.RawContacts.CONTENT_URI, id)); }