List of usage examples for android.content ContentUris withAppendedId
public static Uri withAppendedId(Uri contentUri, long id)
From source file:com.borqs.browser.combo.BookmarksPageCallbacks.java
@Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { BrowserBookmarksAdapter adapter = getChildAdapter(groupPosition); Cursor cursor = adapter.getItem(childPosition); boolean isFolder = cursor.getInt(BookmarksLoader.COLUMN_INDEX_IS_FOLDER) != 0; if (onBookmarkSelected(cursor, isFolder)) { return true; }/* ww w .jav a 2 s . c o m*/ if (isFolder) { String title = cursor.getString(BookmarksLoader.COLUMN_INDEX_TITLE); Uri uri = ContentUris.withAppendedId(BrowserContract.Bookmarks.CONTENT_URI_DEFAULT_FOLDER, id); BreadCrumbView crumbs = getBreadCrumbs(groupPosition); if (crumbs != null) { // update crumbs crumbs.pushView(title, uri); crumbs.setVisibility(View.VISIBLE); } loadFolder(groupPosition, uri); } return true; }
From source file:org.mythtv.service.dvr.v25.RecordedHelperV25.java
private void processProgramGroups(final Context context, final LocationProfile locationProfile, Program[] programs) throws RemoteException, OperationApplicationException { Log.v(TAG, "processProgramGroups : enter"); if (null == context) throw new RuntimeException("RecordedHelperV25 is not initialized"); Map<String, ProgramGroup> programGroups = new TreeMap<String, ProgramGroup>(); for (Program program : programs) { if (null != program.getRecording()) { if (null != program.getRecording().getRecGroup() && !"livetv".equalsIgnoreCase(program.getRecording().getRecGroup()) && !"deleted".equalsIgnoreCase(program.getRecording().getRecGroup())) { String cleaned = ArticleCleaner.clean(program.getTitle()); if (!programGroups.containsKey(cleaned)) { ProgramGroup programGroup = new ProgramGroup(); programGroup.setTitle(program.getTitle()); programGroup.setCategory(program.getCategory()); programGroup.setInetref(program.getInetref()); programGroup.setSort(0); programGroups.put(cleaned, programGroup); }//from w w w . ja v a 2s. co m } } } int processed = -1; int count = 0; ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); Log.v(TAG, "processProgramGroups : adding 'All' program group in programGroups"); ProgramGroup all = new ProgramGroup(null, "All", "All", "All", "", 1); programGroups.put(all.getProgramGroup(), all); String[] programGroupProjection = new String[] { ProgramGroupConstants._ID }; String programGroupSelection = ProgramGroupConstants.FIELD_PROGRAM_GROUP + " = ?"; programGroupSelection = appendLocationHostname(context, locationProfile, programGroupSelection, null); for (String key : programGroups.keySet()) { Log.v(TAG, "processProgramGroups : processing programGroup '" + key + "'"); ProgramGroup programGroup = programGroups.get(key); ContentValues programValues = convertProgramGroupToContentValues(locationProfile, programGroup); Cursor programGroupCursor = context.getContentResolver().query(ProgramGroupConstants.CONTENT_URI, programGroupProjection, programGroupSelection, new String[] { key }, null); if (programGroupCursor.moveToFirst()) { Long id = programGroupCursor .getLong(programGroupCursor.getColumnIndexOrThrow(ProgramGroupConstants._ID)); ops.add(ContentProviderOperation .newUpdate(ContentUris.withAppendedId(ProgramGroupConstants.CONTENT_URI, id)) .withValues(programValues).withYieldAllowed(true).build()); } else { ops.add(ContentProviderOperation.newInsert(ProgramGroupConstants.CONTENT_URI) .withValues(programValues).withYieldAllowed(true).build()); } programGroupCursor.close(); count++; if (count > 100) { Log.v(TAG, "processProgramGroups : applying batch for '" + count + "' transactions"); processBatch(context, ops, processed, count); } } if (!ops.isEmpty()) { Log.v(TAG, "processProgramGroups : applying batch for '" + count + "' transactions"); processBatch(context, ops, processed, count); } Log.v(TAG, "processProgramGroups : remove deleted program groups"); ops = new ArrayList<ContentProviderOperation>(); DateTime lastModified = new DateTime(); lastModified = lastModified.minusHours(1); String deleteProgramGroupSelection = ProgramGroupConstants.FIELD_LAST_MODIFIED_DATE + " < ?"; String[] deleteProgramGroupArgs = new String[] { String.valueOf(lastModified.getMillis()) }; deleteProgramGroupSelection = appendLocationHostname(context, locationProfile, deleteProgramGroupSelection, ProgramGroupConstants.TABLE_NAME); ops.add(ContentProviderOperation.newDelete(ProgramGroupConstants.CONTENT_URI) .withSelection(deleteProgramGroupSelection, deleteProgramGroupArgs).withYieldAllowed(true).build()); if (!ops.isEmpty()) { Log.v(TAG, "processProgramGroups : applying batch for '" + count + "' transactions"); processBatch(context, ops, processed, count); } Log.v(TAG, "processProgramGroups : exit"); }
From source file:com.example.mydemos.view.RingtonePickerActivity.java
private int getRingtonePosition(Uri ringtoneUri, int tabName, String were) { if (ringtoneUri == null) return -1; final Cursor cursor = getCursor(tabName, were); final int cursorCount = cursor.getCount(); final String musicId = MediaStore.Audio.Media._ID; if (!cursor.moveToFirst()) { Log.e("zxw", "getRingtonePosition 1"); return -1; }// ww w .ja v a2 s . com // Only create Uri objects when the actual URI changes Uri BaseUri = null; Uri currentUri = null; String previousUriString = null; if (tabName == SYSTEM_TONE) { BaseUri = MediaStore.Audio.Media.INTERNAL_CONTENT_URI; } else { BaseUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } for (int i = 0; i < cursorCount; i++) { int position = cursor.getInt(cursor.getColumnIndex(musicId)); currentUri = ContentUris.withAppendedId(BaseUri, position); //if( position == mSelectedId) { if (ringtoneUri.equals(currentUri)) { Log.e("zxw", "getRingtonePosition i" + i); cursor.close(); return i; } // String uriString = cursor.getString(URI_COLUMN_INDEX); // if (currentUri == null || !uriString.equals(previousUriString)) { // currentUri = Uri.parse(uriString); // } // if (ringtoneUri.equals(ContentUris.withAppendedId(currentUri, cursor // .getLong(ID_COLUMN_INDEX)))) { // Log.e("zxw","getRingtonePosition i" + i); // return i; // } cursor.move(1); // previousUriString = uriString; } cursor.close(); Log.e("zxw", "getRingtonePosition 2"); return -1; }
From source file:com.granita.tasks.EditTaskFragment.java
@Override public void onContentLoaded(ContentSet contentSet) { if (contentSet.containsKey(Tasks.ACCOUNT_TYPE)) { mListColor = TaskFieldAdapters.LIST_COLOR.get(contentSet); updateColor((float) mRootView.getScrollY() / mTaskListBar.getMeasuredHeight()); if (mAppForEdit) { Sources.loadModelAsync(mAppContext, contentSet.getAsString(Tasks.ACCOUNT_TYPE), EditTaskFragment.this); }/*from ww w . j a va 2 s . com*/ /* * Don't start the model loader here, let onItemSelected do that. */ setListUri( mAppForEdit ? ContentUris.withAppendedId(TaskLists.getContentUri(mAuthority), contentSet.getAsLong(Tasks.LIST_ID)) : TaskLists.getContentUri(mAuthority), mAppForEdit ? LIST_LOADER_VISIBLE_LISTS_FILTER : null); } }
From source file:com.android.mms.ui.MessageUtils.java
private static String getMultimediaMessageDetails(Context context, MessageItem msgItem) { if (msgItem.mMessageType == PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND) { return getNotificationIndDetails(context, msgItem); }/* ww w .j a v a2s.com*/ StringBuilder details = new StringBuilder(); Resources res = context.getResources(); // / M: Code analyze 027, new feature, to improve the performance of // Mms. @{ Uri uri = ContentUris.withAppendedId(Mms.CONTENT_URI, msgItem.mMsgId); /// @} MultimediaMessagePdu msg; try { msg = (MultimediaMessagePdu) PduPersister.getPduPersister(context).load(uri); } catch (MmsException e) { Log.e(TAG, "Failed to load the message: " + uri, e); return context.getResources().getString(R.string.cannot_get_details); } // Message Type: Text message. initializeMsgDetails(context, details, res, msg); // SentDate: *** if (msg.getDateSent() > 0 && msgItem.mBoxId == Mms.MESSAGE_BOX_INBOX) { details.append('\n'); details.append(res.getString(R.string.sent_label)); String dateStr = formatDateAndTimeStampString(context, 0, msg.getDateSent() * 1000L, true); details.append(dateStr); } // Date: *** details.append('\n'); // / M: Code analyze 027, new feature, to improve the performance of // Mms. @{ int msgBox = msgItem.mBoxId; /// @} if (msgBox == Mms.MESSAGE_BOX_DRAFTS) { details.append(res.getString(R.string.saved_label)); } else if (msgBox == Mms.MESSAGE_BOX_INBOX) { details.append(res.getString(R.string.received_label)); } else { details.append(res.getString(R.string.sent_label)); } String dateStr = formatDateAndTimeStampString(context, 0, msg.getDate() * 1000L, true); details.append(dateStr); // Subject: *** details.append('\n'); details.append(res.getString(R.string.subject_label)); // / M: Code analyze 027, new feature, to improve the performance of // Mms. @{ int size = msgItem.mMessageSize; /// @} EncodedStringValue subject = msg.getSubject(); if (subject != null) { String subStr = subject.getString(); // Message size should include size of subject. // Modify ALPS00427926. Because message size has // include PDU header, so it should not add this size here //size += subStr.length(); details.append(subStr); } // Priority: High/Normal/Low return formatDetails(details, context, msg, size, res); }
From source file:com.android.calendar.event.EditEventFragment.java
private void saveReminders() { ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(3); boolean changed = EditEventHelper.saveReminders(ops, mModel.mId, mModel.mReminders, mOriginalModel.mReminders, false /* no force save */); if (!changed) { return;//from ww w . j av a2 s. c om } AsyncQueryService service = new AsyncQueryService(getActivity()); service.startBatch(0, null, Calendars.CONTENT_URI.getAuthority(), ops, 0); // Update the "hasAlarm" field for the event Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, mModel.mId); int len = mModel.mReminders.size(); boolean hasAlarm = len > 0; if (hasAlarm != mOriginalModel.mHasAlarm) { ContentValues values = new ContentValues(); values.put(Events.HAS_ALARM, hasAlarm ? 1 : 0); service.startUpdate(0, null, uri, values, null, null, 0); } Toast.makeText(mContext, R.string.saving_event, Toast.LENGTH_SHORT).show(); }
From source file:org.mythtv.service.content.v25.LiveStreamHelperV25.java
private int load(final Context context, final LocationProfile locationProfile, LiveStreamInfo[] liveStreams) throws RemoteException, OperationApplicationException { Log.d(TAG, "load : enter"); if (null == context) { throw new RuntimeException("LiveStreamHelperV25 is not initialized"); }/* w ww. ja v a 2s . c o m*/ DateTime lastModified = new DateTime(DateTimeZone.UTC); int processed = -1; int count = 0; ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); for (LiveStreamInfo liveStream : liveStreams) { ContentValues values = convertLiveStreamInfoToContentValues(locationProfile, liveStream, lastModified, -1, null); String[] projection = new String[] { LiveStreamConstants.TABLE_NAME + "_" + LiveStreamConstants._ID }; String selection = LiveStreamConstants.FIELD_ID + " = ?"; String[] selectionArgs = new String[] { String.valueOf(liveStream.getId()) }; selection = appendLocationHostname(context, locationProfile, selection, LiveStreamConstants.TABLE_NAME); Cursor cursor = context.getContentResolver().query(LiveStreamConstants.CONTENT_URI, projection, selection, selectionArgs, null); if (cursor.moveToFirst()) { Log.v(TAG, "load : updating existing liveStream info"); long id = cursor.getLong(cursor .getColumnIndexOrThrow(LiveStreamConstants.TABLE_NAME + "_" + LiveStreamConstants._ID)); context.getContentResolver().update(ContentUris.withAppendedId(LiveStreamConstants.CONTENT_URI, id), values, null, null); } cursor.close(); count++; if (count > BATCH_COUNT_LIMIT) { Log.i(TAG, "load : applying batch for '" + count + "' transactions, processing programs"); processBatch(context, ops, processed, count); count = 0; } } processBatch(context, ops, processed, count); Log.v(TAG, "load : remove deleted liveStreams"); String deletedSelection = LiveStreamConstants.TABLE_NAME + "." + LiveStreamConstants.FIELD_LAST_MODIFIED + " < ?"; String[] deletedSelectionArgs = new String[] { String.valueOf(lastModified.getMillis()) }; deletedSelection = appendLocationHostname(context, locationProfile, deletedSelection, LiveStreamConstants.TABLE_NAME); ops.add(ContentProviderOperation.newDelete(LiveStreamConstants.CONTENT_URI) .withSelection(deletedSelection, deletedSelectionArgs).withYieldAllowed(true).build()); processBatch(context, ops, processed, count); Intent progressIntent = new Intent(LiveStreamService.ACTION_PROGRESS); context.sendBroadcast(progressIntent); if (countLiveStreamsNotComplete(context, locationProfile) > 0) { Log.d(TAG, "load : further updates are required"); try { Thread.sleep(15000); } catch (InterruptedException e) { Log.e(TAG, "load : error", e); } processed = load(context, locationProfile); } Log.d(TAG, "load : exit"); return processed; }
From source file:org.mythtv.service.content.v26.LiveStreamHelperV26.java
private int load(final Context context, final LocationProfile locationProfile, LiveStreamInfo[] liveStreams) throws RemoteException, OperationApplicationException { Log.d(TAG, "load : enter"); if (null == context) { throw new RuntimeException("LiveStreamHelperV26 is not initialized"); }//w w w.ja v a2s . c o m DateTime lastModified = new DateTime(DateTimeZone.UTC); int processed = -1; int count = 0; ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); for (LiveStreamInfo liveStream : liveStreams) { ContentValues values = convertLiveStreamInfoToContentValues(locationProfile, liveStream, lastModified, -1, null); String[] projection = new String[] { LiveStreamConstants.TABLE_NAME + "_" + LiveStreamConstants._ID }; String selection = LiveStreamConstants.FIELD_ID + " = ?"; String[] selectionArgs = new String[] { String.valueOf(liveStream.getId()) }; selection = appendLocationHostname(context, locationProfile, selection, LiveStreamConstants.TABLE_NAME); Cursor cursor = context.getContentResolver().query(LiveStreamConstants.CONTENT_URI, projection, selection, selectionArgs, null); if (cursor.moveToFirst()) { Log.v(TAG, "load : updating existing liveStream info"); long id = cursor.getLong(cursor .getColumnIndexOrThrow(LiveStreamConstants.TABLE_NAME + "_" + LiveStreamConstants._ID)); context.getContentResolver().update(ContentUris.withAppendedId(LiveStreamConstants.CONTENT_URI, id), values, null, null); } cursor.close(); count++; if (count > BATCH_COUNT_LIMIT) { Log.i(TAG, "load : applying batch for '" + count + "' transactions, processing programs"); processBatch(context, ops, processed, count); count = 0; } } processBatch(context, ops, processed, count); Log.v(TAG, "load : remove deleted liveStreams"); String deletedSelection = LiveStreamConstants.TABLE_NAME + "." + LiveStreamConstants.FIELD_LAST_MODIFIED + " < ?"; String[] deletedSelectionArgs = new String[] { String.valueOf(lastModified.getMillis()) }; deletedSelection = appendLocationHostname(context, locationProfile, deletedSelection, LiveStreamConstants.TABLE_NAME); ops.add(ContentProviderOperation.newDelete(LiveStreamConstants.CONTENT_URI) .withSelection(deletedSelection, deletedSelectionArgs).withYieldAllowed(true).build()); processBatch(context, ops, processed, count); Intent progressIntent = new Intent(LiveStreamService.ACTION_PROGRESS); context.sendBroadcast(progressIntent); if (countLiveStreamsNotComplete(context, locationProfile) > 0) { Log.d(TAG, "load : further updates are required"); try { Thread.sleep(15000); } catch (InterruptedException e) { Log.e(TAG, "load : error", e); } processed = load(context, locationProfile); } Log.d(TAG, "load : exit"); return processed; }
From source file:org.mythtv.service.content.v27.LiveStreamHelperV27.java
private int load(final Context context, final LocationProfile locationProfile, LiveStreamInfo[] liveStreams) throws RemoteException, OperationApplicationException { Log.d(TAG, "load : enter"); if (null == context) { throw new RuntimeException("LiveStreamHelperV27 is not initialized"); }/*from w w w . j av a 2 s . c om*/ DateTime lastModified = new DateTime(DateTimeZone.UTC); int processed = -1; int count = 0; ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); for (LiveStreamInfo liveStream : liveStreams) { ContentValues values = convertLiveStreamInfoToContentValues(locationProfile, liveStream, lastModified, -1, null); String[] projection = new String[] { LiveStreamConstants.TABLE_NAME + "_" + LiveStreamConstants._ID }; String selection = LiveStreamConstants.FIELD_ID + " = ?"; String[] selectionArgs = new String[] { String.valueOf(liveStream.getId()) }; selection = appendLocationHostname(context, locationProfile, selection, LiveStreamConstants.TABLE_NAME); Cursor cursor = context.getContentResolver().query(LiveStreamConstants.CONTENT_URI, projection, selection, selectionArgs, null); if (cursor.moveToFirst()) { Log.v(TAG, "save : updating existing liveStream info"); long id = cursor.getLong(cursor .getColumnIndexOrThrow(LiveStreamConstants.TABLE_NAME + "_" + LiveStreamConstants._ID)); context.getContentResolver().update(ContentUris.withAppendedId(LiveStreamConstants.CONTENT_URI, id), values, null, null); } cursor.close(); count++; if (count > BATCH_COUNT_LIMIT) { Log.i(TAG, "load : applying batch for '" + count + "' transactions, processing programs"); processBatch(context, ops, processed, count); count = 0; } } processBatch(context, ops, processed, count); Log.v(TAG, "load : remove deleted liveStreams"); String deletedSelection = LiveStreamConstants.TABLE_NAME + "." + LiveStreamConstants.FIELD_LAST_MODIFIED + " < ?"; String[] deletedSelectionArgs = new String[] { String.valueOf(lastModified.getMillis()) }; deletedSelection = appendLocationHostname(context, locationProfile, deletedSelection, LiveStreamConstants.TABLE_NAME); ops.add(ContentProviderOperation.newDelete(LiveStreamConstants.CONTENT_URI) .withSelection(deletedSelection, deletedSelectionArgs).withYieldAllowed(true).build()); processBatch(context, ops, processed, count); Intent progressIntent = new Intent(LiveStreamService.ACTION_PROGRESS); context.sendBroadcast(progressIntent); if (countLiveStreamsNotComplete(context, locationProfile) > 0) { Log.d(TAG, "load : further updates are required"); try { Thread.sleep(15000); } catch (InterruptedException e) { Log.e(TAG, "load : error", e); } processed = load(context, locationProfile); } Log.d(TAG, "load : exit"); return processed; }
From source file:com.appsimobile.appsii.module.home.HomeAdapter.java
private void fixHomeItemRows(List<HomeItem> homeItems) { int lastRowPosition = -1; int newRowIdx = 0; int N = homeItems.size(); ArrayList<ContentProviderOperation> ops = new ArrayList<>(8); boolean done; for (int i = 0; i < N; i++) { HomeItem item = homeItems.get(i); done = false;//from w w w . j a va2 s.co m if (lastRowPosition == -1 || lastRowPosition != item.mRowPosition) { lastRowPosition = item.mRowPosition; Uri uri = ContentUris.withAppendedId(HomeContract.Rows.CONTENT_URI, item.mRowId); ops.add(ContentProviderOperation.newUpdate(uri).withValue(HomeContract.Rows.POSITION, newRowIdx) .build()); newRowIdx++; done = true; } // handle the last row if (i == mHomeItems.size() - 1 && !done) { Uri uri = ContentUris.withAppendedId(HomeContract.Rows.CONTENT_URI, item.mRowId); ops.add(ContentProviderOperation.newUpdate(uri).withValue(HomeContract.Rows.POSITION, newRowIdx) .build()); } } try { mContext.getContentResolver().applyBatch(HomeContract.AUTHORITY, ops); } catch (RemoteException | OperationApplicationException e) { Log.w("HomeAdapter", "error fixing bad row numbers", e); } }