List of usage examples for android.content ContentUris withAppendedId
public static Uri withAppendedId(Uri contentUri, long id)
From source file:com.markupartist.sthlmtraveling.FavoritesFragment.java
private void updateListPosition(long id, boolean increase) { Uri uri = ContentUris.withAppendedId(Journeys.CONTENT_URI, id); Cursor cursor = getActivity().managedQuery(uri, PROJECTION, null, null, null); cursor.moveToFirst();/*w w w. j a v a 2 s.c o m*/ int position = cursor.getInt(COLUMN_INDEX_POSITION); if (increase) { position = position + 1; } else { position = position - 1; } ContentValues values = new ContentValues(); values.put(Journeys.POSITION, position); getActivity().getContentResolver().update(uri, values, null, null); }
From source file:com.grokkingandroid.sampleapp.samples.data.contentprovider.lentitems.LentItemFormFragment.java
@Override public Loader<Cursor> onCreateLoader(int loaderId, Bundle args) { Uri loaderUri = ContentUris.withAppendedId(ItemEntities.CONTENT_URI, mItemId); return new CursorLoader(getActivity(), loaderUri, ItemEntities.PROJECTION_ALL, null, null, null); }
From source file:com.ferid.app.frequentcontacts.selectnumber.SelectNumberActivity.java
/** * Retrieve photo of the given contact with contact ID * @param contactId/*w w w. ja v a2 s . c o m*/ * @return */ private String retrievePhoto(int contactId) { Uri contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId); Uri photoUri = Uri.withAppendedPath(contactUri, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY); Cursor cursor = getContentResolver().query(photoUri, new String[] { ContactsContract.Contacts.Photo.PHOTO }, null, null, null); if (cursor == null) { return ""; } try { if (cursor.moveToFirst()) { byte[] data = cursor.getBlob(0); if (data != null) { //byte[] to String convertion return Base64.encodeToString(data, Base64.DEFAULT); } } } finally { cursor.close(); } return ""; }
From source file:com.fututel.ui.filters.AccountFiltersListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Use custom drag and drop view -- reuse the one of accounts_edit_list View v = inflater.inflate(R.layout.accounts_edit_list, container, false); final DragnDropListView lv = (DragnDropListView) v.findViewById(android.R.id.list); lv.setGrabberId(R.id.grabber);/*w w w . j a v a 2 s .com*/ // Setup the drop listener lv.setOnDropListener(new DropListener() { @Override public void drop(int from, int to) { Log.d(THIS_FILE, "Drop from " + from + " to " + to); int hvC = lv.getHeaderViewsCount(); from = Math.max(0, from - hvC); to = Math.max(0, to - hvC); int i; // First of all, compute what we get before move ArrayList<Long> orderedList = new ArrayList<Long>(); CursorAdapter ad = (CursorAdapter) getListAdapter(); for (i = 0; i < ad.getCount(); i++) { orderedList.add(ad.getItemId(i)); } // Then, invert in the current list the two items ids Long moved = orderedList.remove(from); orderedList.add(to, moved); // Finally save that in db ContentResolver cr = getActivity().getContentResolver(); for (i = 0; i < orderedList.size(); i++) { Uri uri = ContentUris.withAppendedId(SipManager.FILTER_ID_URI_BASE, orderedList.get(i)); ContentValues cv = new ContentValues(); cv.put(Filter.FIELD_PRIORITY, i); cr.update(uri, cv, null, null); } } }); OnClickListener addClickButtonListener = new OnClickListener() { @Override public void onClick(View v) { onClickAddFilter(); } }; // Header view mHeaderView = inflater.inflate(R.layout.generic_add_header_list, container, false); mHeaderView.setOnClickListener(addClickButtonListener); //rangdong ((TextView) mHeaderView.findViewById(R.id.text)).setText(R.string.add_filter); // Empty view Button bt = (Button) v.findViewById(android.R.id.empty); bt.setText(R.string.add_filter); bt.setOnClickListener(addClickButtonListener); return v; }
From source file:com.appsimobile.appsii.module.apps.AppsProvider.java
@Override public Uri insert(Uri uri, ContentValues initialValues) { SqlArguments args = new SqlArguments(uri); SQLiteDatabase db = mOpenHelper.getWritableDatabase(); final long rowId = db.insert(args.table, null, initialValues); if (rowId <= 0) return null; uri = ContentUris.withAppendedId(uri, rowId); sendNotify(uri);//from www .jav a 2 s.c om return uri; }
From source file:com.frostwire.android.gui.fragments.ImageViewerFragment.java
public void updateData(final FileDescriptor fd, int position) { this.fd = fd; this.position = position; async(this, ImageViewerFragment::loadSurroundingFileDescriptors); if (actionModeCallback == null) { actionModeCallback = new ImageViewerActionModeCallback(this.fd, position); startActionMode(actionModeCallback); }/*from w w w . j a va2 s . c o m*/ actionModeCallback.getActionMode().setTitle(FilenameUtils.getName(fd.filePath)); fileUri = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, fd.id); progressBar.setVisibility(View.VISIBLE); highResLoaded = false; // under the assumption that the main image view to render the // picture will cover the main screen, or even go to full screen, // then using the display size as a target is a good idea Point size = displaySize(); // load high res version ImageLoader.Params params = new ImageLoader.Params(); params.targetWidth = size.x; params.targetHeight = size.y; params.placeholderResId = R.drawable.picture_placeholder; params.centerInside = true; params.noCache = true; params.callback = new LoadImageCallback(this); imageLoader.load(fileUri, imageViewHighRes, params); }
From source file:com.csipsimple.ui.filters.AccountFiltersListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Use custom drag and drop view -- reuse the one of accounts_edit_list View v = inflater.inflate(R.layout.accounts_edit_list, container, false); final DragnDropListView lv = (DragnDropListView) v.findViewById(android.R.id.list); lv.setGrabberId(R.id.grabber);//ww w . j a v a2s .c o m // Setup the drop listener lv.setOnDropListener(new DropListener() { @Override public void drop(int from, int to) { Log.d(THIS_FILE, "Drop from " + from + " to " + to); int hvC = lv.getHeaderViewsCount(); from = Math.max(0, from - hvC); to = Math.max(0, to - hvC); int i; // First of all, compute what we get before move ArrayList<Long> orderedList = new ArrayList<Long>(); CursorAdapter ad = (CursorAdapter) getListAdapter(); for (i = 0; i < ad.getCount(); i++) { orderedList.add(ad.getItemId(i)); } // Then, invert in the current list the two items ids Long moved = orderedList.remove(from); orderedList.add(to, moved); // Finally save that in db ContentResolver cr = getActivity().getContentResolver(); for (i = 0; i < orderedList.size(); i++) { Uri uri = ContentUris.withAppendedId(SipManager.FILTER_ID_URI_BASE, orderedList.get(i)); ContentValues cv = new ContentValues(); cv.put(Filter.FIELD_PRIORITY, i); cr.update(uri, cv, null, null); } } }); OnClickListener addClickButtonListener = new OnClickListener() { @Override public void onClick(View v) { onClickAddFilter(); } }; // Header view mHeaderView = inflater.inflate(R.layout.generic_add_header_list, container, false); mHeaderView.setOnClickListener(addClickButtonListener); ((TextView) mHeaderView.findViewById(R.id.text)).setText(R.string.add_filter); // Empty view Button bt = (Button) v.findViewById(android.R.id.empty); bt.setText(R.string.add_filter); bt.setOnClickListener(addClickButtonListener); return v; }
From source file:cm.android.download.providers.downloads.DownloadNotifier.java
private void updateWithLocked(Collection<DownloadInfo> downloads) { final Resources res = mContext.getResources(); // Cluster downloads together final Multimap<String, DownloadInfo> clustered = ArrayListMultimap.create(); for (DownloadInfo info : downloads) { final String tag = buildNotificationTag(info); if (tag != null) { clustered.put(tag, info);/*from w w w. j a v a 2s . c o m*/ } } // Build notification for each cluster for (String tag : clustered.keySet()) { final int type = getNotificationTagType(tag); final Collection<DownloadInfo> cluster = clustered.get(tag); final NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext); // Use time when cluster was first shown to avoid shuffling final long firstShown; if (mActiveNotifs.containsKey(tag)) { firstShown = mActiveNotifs.get(tag); } else { firstShown = System.currentTimeMillis(); mActiveNotifs.put(tag, firstShown); } builder.setWhen(firstShown); // Show relevant icon if (type == TYPE_ACTIVE) { builder.setSmallIcon(android.R.drawable.stat_sys_download); } else if (type == TYPE_WAITING) { builder.setSmallIcon(android.R.drawable.stat_sys_warning); } else if (type == TYPE_COMPLETE) { builder.setSmallIcon(android.R.drawable.stat_sys_download_done); } // Build action intents if (type == TYPE_ACTIVE || type == TYPE_WAITING) { // build a synthetic uri for intent identification purposes final Uri uri = new Uri.Builder().scheme("active-dl").appendPath(tag).build(); final Intent intent = new Intent(Constants.ACTION_LIST, uri, mContext, DownloadReceiver.class); intent.putExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS, getDownloadIds(cluster)); builder.setContentIntent( PendingIntent.getBroadcast(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)); builder.setOngoing(true); } else if (type == TYPE_COMPLETE) { final DownloadInfo info = cluster.iterator().next(); final Uri uri = ContentUris.withAppendedId(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, info.mId); builder.setAutoCancel(true); final String action; if (Downloads.Impl.isStatusError(info.mStatus)) { action = Constants.ACTION_LIST; } else { if (info.mDestination != Downloads.Impl.DESTINATION_SYSTEMCACHE_PARTITION) { action = Constants.ACTION_OPEN; } else { action = Constants.ACTION_LIST; } } final Intent intent = new Intent(action, uri, mContext, DownloadReceiver.class); intent.putExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS, getDownloadIds(cluster)); builder.setContentIntent( PendingIntent.getBroadcast(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)); final Intent hideIntent = new Intent(Constants.ACTION_HIDE, uri, mContext, DownloadReceiver.class); builder.setDeleteIntent(PendingIntent.getBroadcast(mContext, 0, hideIntent, 0)); } // Calculate and show progress String remainingText = null; String percentText = null; if (type == TYPE_ACTIVE) { long current = 0; long total = 0; long speed = 0; synchronized (mDownloadSpeed) { for (DownloadInfo info : cluster) { if (info.mTotalBytes != -1) { current += info.mCurrentBytes; total += info.mTotalBytes; Long l = mDownloadSpeed.get(info.mId); if (l == null) { l = 0L; } speed += l; } } } if (total > 0) { final int percent = (int) ((current * 100) / total); percentText = res.getString(R.string.download_percent, percent); if (speed > 0) { final long remainingMillis = ((total - current) * 1000) / speed; remainingText = res.getString(R.string.download_remaining, // DateUtils.formatDuration(remainingMillis)); // // FIXME "" + Helpers.formatDuration(mContext, remainingMillis)); } builder.setProgress(100, percent, false); } else { builder.setProgress(100, 0, true); } } // Build titles and description final Notification notif; if (cluster.size() == 1) { final DownloadInfo info = cluster.iterator().next(); builder.setContentTitle(getDownloadTitle(res, info)); if (type == TYPE_ACTIVE) { if (!TextUtils.isEmpty(info.mDescription)) { builder.setContentText(info.mDescription); } else { builder.setContentText(remainingText); } builder.setContentInfo(percentText); } else if (type == TYPE_WAITING) { builder.setContentText(res.getString(R.string.notification_need_wifi_for_size)); } else if (type == TYPE_COMPLETE) { if (Downloads.Impl.isStatusError(info.mStatus)) { builder.setContentText(res.getText(R.string.notification_download_failed)); } else if (Downloads.Impl.isStatusSuccess(info.mStatus)) { builder.setContentText(res.getText(R.string.notification_download_complete)); } } notif = builder.build(); } else { final NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(builder); for (DownloadInfo info : cluster) { inboxStyle.addLine(getDownloadTitle(res, info)); } if (type == TYPE_ACTIVE) { builder.setContentTitle( res.getQuantityString(R.plurals.notif_summary_active, cluster.size(), cluster.size())); builder.setContentText(remainingText); builder.setContentInfo(percentText); inboxStyle.setSummaryText(remainingText); } else if (type == TYPE_WAITING) { builder.setContentTitle( res.getQuantityString(R.plurals.notif_summary_waiting, cluster.size(), cluster.size())); builder.setContentText(res.getString(R.string.notification_need_wifi_for_size)); inboxStyle.setSummaryText(res.getString(R.string.notification_need_wifi_for_size)); } notif = inboxStyle.build(); } mNotifManager.notify(tag, 0, notif); } // Remove stale tags that weren't renewed final Iterator<String> it = mActiveNotifs.keySet().iterator(); while (it.hasNext()) { final String tag = it.next(); if (!clustered.containsKey(tag)) { mNotifManager.cancel(tag, 0); it.remove(); } } }
From source file:com.kyakujin.android.tagnotepad.ui.NoteListFragment.java
@Override public void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); openNote(ContentUris.withAppendedId(Notes.CONTENT_URI, id)); }
From source file:com.smarthome.deskclock.Alarms.java
/** * Return an Alarm object representing the alarm id in the database. * Returns null if no alarm exists.//from w w w . java 2 s . c om */ public static Alarm getAlarm(ContentResolver contentResolver, int alarmId) { Cursor cursor = contentResolver.query(ContentUris.withAppendedId(Alarm.Columns.CONTENT_URI, alarmId), Alarm.Columns.ALARM_QUERY_COLUMNS, null, null, null); Alarm alarm = null; if (cursor != null) { if (cursor.moveToFirst()) { alarm = new Alarm(cursor); } cursor.close(); } return alarm; }