List of usage examples for android.provider BaseColumns _ID
String _ID
To view the source code for android.provider BaseColumns _ID.
Click Source Link
From source file:de.vanita5.twittnuker.util.Utils.java
public static synchronized void cleanDatabasesByItemLimit(final Context context) { if (context == null) return;//from w ww . j ava2 s. c o m final ContentResolver resolver = context.getContentResolver(); final int itemLimit = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE) .getInt(KEY_DATABASE_ITEM_LIMIT, DEFAULT_DATABASE_ITEM_LIMIT); for (final long account_id : getAccountIds(context)) { // Clean statuses. for (final Uri uri : STATUSES_URIS) { if (CachedStatuses.CONTENT_URI.equals(uri)) { continue; } final String table = getTableNameByUri(uri); final Where account_where = new Where(Statuses.ACCOUNT_ID + " = " + account_id); final SQLSelectQuery.Builder qb = new SQLSelectQuery.Builder(); qb.select(new Column(Statuses._ID)).from(new Tables(table)); qb.where(new Where(Statuses.ACCOUNT_ID + " = " + account_id)); qb.orderBy(new OrderBy(Statuses.STATUS_ID + " DESC")); qb.limit(itemLimit); final Where where = Where.and(Where.notIn(new Column(Statuses._ID), qb.build()), account_where); resolver.delete(uri, where.getSQL(), null); } for (final Uri uri : DIRECT_MESSAGES_URIS) { final String table = getTableNameByUri(uri); final Where account_where = new Where(DirectMessages.ACCOUNT_ID + " = " + account_id); final SQLSelectQuery.Builder qb = new SQLSelectQuery.Builder(); qb.select(new Column(DirectMessages._ID)).from(new Tables(table)); qb.where(new Where(DirectMessages.ACCOUNT_ID + " = " + account_id)); qb.orderBy(new OrderBy(DirectMessages.MESSAGE_ID + " DESC")); qb.limit(itemLimit); final Where where = Where.and(Where.notIn(new Column(DirectMessages._ID), qb.build()), account_where); resolver.delete(uri, where.getSQL(), null); } } // Clean cached values. for (final Uri uri : CACHE_URIS) { final String table = getTableNameByUri(uri); final SQLSelectQuery.Builder qb = new SQLSelectQuery.Builder(); qb.select(new Column(BaseColumns._ID)); qb.from(new Tables(table)); qb.orderBy(new OrderBy(BaseColumns._ID + " DESC")); qb.limit(itemLimit * 20); final Where where = Where.notIn(new Column(BaseColumns._ID), qb.build()); resolver.delete(uri, where.getSQL(), null); } }
From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java
private Cursor queryArtwork(@NonNull final Uri uri, final String[] projection, final String selection, final String[] selectionArgs, final String sortOrder) { ContentResolver contentResolver = getContext() != null ? getContext().getContentResolver() : null; if (contentResolver == null) { return null; }/*from w w w .j ava 2 s. c om*/ final SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(MuzeiContract.Artwork.TABLE_NAME + " INNER JOIN " + MuzeiContract.Sources.TABLE_NAME + " ON " + MuzeiContract.Artwork.TABLE_NAME + "." + MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME + "=" + MuzeiContract.Sources.TABLE_NAME + "." + MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME); qb.setProjectionMap(allArtworkColumnProjectionMap); final SQLiteDatabase db = databaseHelper.getReadableDatabase(); if (MuzeiProvider.uriMatcher.match(uri) == ARTWORK_ID) { // If the incoming URI is for a single source identified by its ID, appends "_ID = <artworkId>" // to the where clause, so that it selects that single piece of artwork qb.appendWhere( MuzeiContract.Artwork.TABLE_NAME + "." + BaseColumns._ID + "=" + uri.getLastPathSegment()); } String orderBy; if (TextUtils.isEmpty(sortOrder)) orderBy = MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED + " DESC, " + MuzeiContract.Artwork.DEFAULT_SORT_ORDER; else orderBy = sortOrder; final Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy, null); c.setNotificationUri(contentResolver, uri); return c; }
From source file:com.android.bluetooth.map.BluetoothMapContent.java
private void setRecipientAddressing(BluetoothMapMessageListingElement e, Cursor c, FilterInfo fi, BluetoothMapAppParams ap) {/*from www . jav a 2 s . c om*/ if ((ap.getParameterMask() & MASK_RECIPIENT_ADDRESSING) != 0) { String address = ""; if (fi.msgType == FilterInfo.TYPE_SMS) { int msgType = c.getInt(c.getColumnIndex(Sms.TYPE)); if (msgType == 1) { address = fi.phoneNum; } else { address = c.getString(c.getColumnIndex(Sms.ADDRESS)); } if ((address == null) && msgListingFolder.equalsIgnoreCase("draft")) { int threadIdInd = c.getColumnIndex("thread_id"); String threadIdStr = c.getString(threadIdInd); address = getMessageSmsRecipientAddress(Integer.valueOf(threadIdStr)); if (V) Log.v(TAG, "threadId = " + threadIdStr + " adress:" + address + "\n"); } } else if (fi.msgType == FilterInfo.TYPE_MMS) { long id = c.getLong(c.getColumnIndex(BaseColumns._ID)); address = getAddressMms(mResolver, id, MMS_TO); } else { int toIndex = c.getColumnIndex(MessageColumns.TO_LIST); address = c.getString(toIndex); if (address != null && address.contains("")) { String[] recepientAddrStr = address.split(""); if (recepientAddrStr != null && recepientAddrStr.length > 0) { if (V) { Log.v(TAG, " ::Recepient addressing split String 0:: " + recepientAddrStr[0] + "::Recepient addressing split String 1:: " + recepientAddrStr[1]); } e.setRecipientAddressing(recepientAddrStr[0].trim()); } } else { if (D) Log.d(TAG, "setRecipientAddressing: " + address); e.setRecipientAddressing(address); } return; } if (D) Log.d(TAG, "setRecipientAddressing: " + address); e.setRecipientAddressing(address); } }
From source file:org.opendatakit.tables.utils.CollectUtil.java
/** * Insert the values existing in the file specified by * {@link DATA_FILE_PATH_AND_NAME} into the form specified by params. * <p>//from w w w . j av a 2 s . co m * If the display name is not defined in the {@code params} parameter then the * string resource is used. * <p> * The inserted row is marked as INCOMPLETE. * <p> * PRECONDITION: in order to be populated with data, the data file containing * the row's data must have been written, most likely by calling * writeRowDataToBeEdited(). * <p> * PRECONDITION: previous instances should already have been deleted by now, * or the passed in file names should be uniqued by adding timestamps, or * something. * * @param params * the identifying parameters for the form. Should be the same object * used to write the instance file. * @param rowNum * the row number of the row being edited * @param resolver * the ContentResolver of the activity making the request. * @return */ /* * This is based on the code at: http://code.google.com/p/opendatakit/source/ * browse/src/org/odk/collect/android/tasks/SaveToDiskTask.java?repo=collect * in the method updateInstanceDatabase(). */ private static Uri getUriForCollectInstanceForRowData(Context context, String appName, String tableId, CollectFormParameters params, String rowId, boolean shouldUpdate) { String instanceFilePath = getEditRowFormFile(appName, tableId, rowId).getAbsolutePath(); ContentValues values = new ContentValues(); // First we need to fill the values with various little things. values.put(COLLECT_KEY_STATUS, COLLECT_KEY_STATUS_INCOMPLETE); values.put(COLLECT_KEY_CAN_EDIT_WHEN_COMPLETE, Boolean.toString(true)); values.put(COLLECT_KEY_INSTANCE_FILE_PATH, instanceFilePath); values.put(COLLECT_KEY_JR_FORM_ID, params.getFormId()); values.put(COLLECT_KEY_DISPLAY_NAME, params.getRowDisplayName() + "_" + WebUtils.get().iso8601Date(new Date())); // only add the version if it exists (ie not null) if (params.getFormVersion() != null) { values.put(COLLECT_KEY_JR_VERSION, params.getFormVersion()); } ContentResolver resolver = context.getContentResolver(); Uri uriOfForm; if (shouldUpdate) { int count = resolver.update(CONTENT_INSTANCE_URI, values, COLLECT_KEY_INSTANCE_FILE_PATH + "=?", new String[] { instanceFilePath }); if (count == 0) { uriOfForm = resolver.insert(CONTENT_INSTANCE_URI, values); } else { Cursor c = null; try { c = resolver.query(CONTENT_INSTANCE_URI, null, COLLECT_KEY_INSTANCE_FILE_PATH + "=?", new String[] { instanceFilePath }, COLLECT_INSTANCE_ORDER_BY); if (c.moveToFirst()) { // we got a result, meaning that the form exists in collect. // so we just need to set the URI. int collectInstanceKey; // this is the primary key of the form in // Collect's // database. collectInstanceKey = ODKDatabaseUtils.get().getIndexAsType(c, Integer.class, c.getColumnIndexOrThrow(BaseColumns._ID)); uriOfForm = (Uri.parse(CONTENT_INSTANCE_URI + "/" + collectInstanceKey)); c.close(); } else { c.close(); throw new IllegalStateException("it was updated we should have found the record!"); } } finally { if (c != null && !c.isClosed()) { c.close(); } } } } else { // now we want to get the uri for the insertion. uriOfForm = resolver.insert(CONTENT_INSTANCE_URI, values); } return uriOfForm; }
From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java
private Cursor querySource(@NonNull final Uri uri, final String[] projection, final String selection, final String[] selectionArgs, final String sortOrder) { ContentResolver contentResolver = getContext() != null ? getContext().getContentResolver() : null; if (contentResolver == null) { return null; }/* w ww . j a v a 2s. com*/ final SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(MuzeiContract.Sources.TABLE_NAME); qb.setProjectionMap(allSourcesColumnProjectionMap); final SQLiteDatabase db = databaseHelper.getReadableDatabase(); if (MuzeiProvider.uriMatcher.match(uri) == SOURCE_ID) { // If the incoming URI is for a single source identified by its ID, appends "_ID = <sourceId>" // to the where clause, so that it selects that single source qb.appendWhere(BaseColumns._ID + "=" + uri.getLastPathSegment()); } String orderBy; if (TextUtils.isEmpty(sortOrder)) orderBy = MuzeiContract.Sources.DEFAULT_SORT_ORDER; else orderBy = sortOrder; final Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy, null); c.setNotificationUri(contentResolver, uri); return c; }
From source file:com.andrew.apollo.utils.MusicUtils.java
/** * @param context The {@link Context} to use * @param id The song ID.// w w w. j a v a 2s.co m */ public static void setRingtone(final Context context, final long id) { final ContentResolver resolver = context.getContentResolver(); final Uri uri = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, id); try { final ContentValues values = new ContentValues(2); values.put(AudioColumns.IS_RINGTONE, "1"); values.put(AudioColumns.IS_ALARM, "1"); resolver.update(uri, values, null, null); } catch (final UnsupportedOperationException ignored) { return; } final String[] projection = new String[] { BaseColumns._ID, MediaColumns.DATA, MediaColumns.TITLE }; final String selection = BaseColumns._ID + "=" + id; Cursor cursor = resolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, selection, null, null); try { if (cursor != null && cursor.getCount() == 1) { cursor.moveToFirst(); RingtoneManager.setActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE, uri); final String message = context.getString(R.string.set_as_ringtone, cursor.getString(2)); AppMsg.makeText(context, message, AppMsg.STYLE_CONFIRM).show(); } } catch (Throwable ignored) { UIUtils.showLongMessage(context, R.string.ringtone_not_set); } finally { if (cursor != null) { cursor.close(); } } }
From source file:org.catnut.fragment.TweetFragment.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { int limit = args.getInt(TAG, getFetchSize()); return CatnutUtils.getCursorLoader(getActivity(), CatnutProvider.parse(Status.MULTIPLE), PROJECTION, mSelection, null, Status.TABLE + " as s", "inner join " + User.TABLE + " as u on s.uid=u._id", "s." + BaseColumns._ID + " desc", String.valueOf(limit)); }
From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java
private ParcelFileDescriptor openFileArtwork(@NonNull final Uri uri, @NonNull final String mode) throws FileNotFoundException { String[] projection = { BaseColumns._ID, MuzeiContract.Artwork.COLUMN_NAME_IMAGE_URI }; final boolean isWriteOperation = mode.contains("w"); final File file; if (!UserManagerCompat.isUserUnlocked(getContext())) { if (isWriteOperation) { Log.w(TAG, "Wallpaper is read only until the user is unlocked"); return null; }/*from ww w. ja v a2 s . c o m*/ file = DirectBootCacheJobService.getCachedArtwork(getContext()); } else if (!isWriteOperation && MuzeiProvider.uriMatcher.match(uri) == MuzeiProvider.ARTWORK) { // If it isn't a write operation, then we should attempt to find the latest artwork // that does have a cached artwork file. This prevents race conditions where // an external app attempts to load the latest artwork while an art source is inserting a // new artwork Cursor data = queryArtwork(MuzeiContract.Artwork.CONTENT_URI, projection, null, null, null); if (data == null) { return null; } if (!data.moveToFirst()) { if (!getContext().getPackageName().equals(getCallingPackage())) { Log.w(TAG, "You must insert at least one row to read or write artwork"); } return null; } File foundFile = null; while (!data.isAfterLast()) { Uri possibleArtworkUri = ContentUris.withAppendedId(MuzeiContract.Artwork.CONTENT_URI, data.getLong(0)); File possibleFile = getCacheFileForArtworkUri(possibleArtworkUri); if (possibleFile != null && possibleFile.exists()) { foundFile = possibleFile; break; } data.moveToNext(); } file = foundFile; } else { file = getCacheFileForArtworkUri(uri); } if (file == null) { throw new FileNotFoundException("Could not create artwork file"); } if (file.exists() && file.length() > 0 && isWriteOperation) { Context context = getContext(); if (context == null) { return null; } if (!context.getPackageName().equals(getCallingPackage())) { Log.w(TAG, "Writing to an existing artwork file is not allowed: insert a new row"); } cleanupCachedFiles(); return null; } try { return ParcelFileDescriptor.open(file, ParcelFileDescriptor.parseMode(mode), openFileHandler, new ParcelFileDescriptor.OnCloseListener() { @Override public void onClose(final IOException e) { if (isWriteOperation) { if (e != null) { Log.e(TAG, "Error closing " + file + " for " + uri, e); if (file.exists()) { if (!file.delete()) { Log.w(TAG, "Unable to delete " + file); } } } else { // The file was successfully written, notify listeners of the new artwork notifyChange(uri); cleanupCachedFiles(); } } } }); } catch (IOException e) { Log.e(TAG, "Error opening artwork " + uri, e); throw new FileNotFoundException("Error opening artwork " + uri); } }
From source file:com.android.bluetooth.map.BluetoothMapContent.java
private void setRecipientName(BluetoothMapMessageListingElement e, Cursor c, FilterInfo fi, BluetoothMapAppParams ap) {/*w w w . ja v a2 s .co m*/ if ((ap.getParameterMask() & MASK_RECIPIENT_NAME) != 0) { String name = ""; String firstRecipient = null; if (fi.msgType == FilterInfo.TYPE_SMS) { int msgType = c.getInt(c.getColumnIndex(Sms.TYPE)); if (msgType != 1) { String phone = c.getString(c.getColumnIndex(Sms.ADDRESS)); name = getContactNameFromPhone(phone); } else { name = fi.phoneAlphaTag; } if ((name == null) && msgListingFolder.equalsIgnoreCase("draft")) { int threadIdInd = c.getColumnIndex("thread_id"); String threadIdStr = c.getString(threadIdInd); firstRecipient = getMessageSmsRecipientAddress(Integer.valueOf(threadIdStr)); if (V) Log.v(TAG, "threadId = " + threadIdStr + " address:" + firstRecipient + "\n"); if (firstRecipient != null) { // Get first Recipient Name for multiple recipient addressing if (firstRecipient.contains(";")) { firstRecipient = firstRecipient.split(";")[0]; } else if (firstRecipient.contains(",")) { firstRecipient = firstRecipient.split(",")[0]; } name = getContactNameFromPhone(firstRecipient); } } } else if (fi.msgType == FilterInfo.TYPE_MMS) { long id = c.getLong(c.getColumnIndex(BaseColumns._ID)); String phone = getAddressMms(mResolver, id, MMS_TO); name = getContactNameFromPhone(phone); } else { int toIndex = c.getColumnIndex(MessageColumns.TO_LIST); if (D) Log.d(TAG, "setRecipientName: " + c.getString(toIndex)); name = c.getString(toIndex); } if (D) Log.d(TAG, "setRecipientName: " + name); e.setRecipientName(name); } }