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:com.bt.download.android.gui.Librarian.java
/** * //from w ww . j av a 2 s .c o m * @param fileType * @param onlyShared - If false, forces getting all files, shared or unshared. * @return */ public int getNumFiles(byte fileType, boolean onlyShared) { TableFetcher fetcher = TableFetchers.getFetcher(fileType); if (cache[fileType].cacheValid(onlyShared)) { return cache[fileType].getCount(onlyShared); } Cursor c = null; int result = 0; int numFiles = 0; try { ContentResolver cr = context.getContentResolver(); c = cr.query(fetcher.getContentUri(), new String[] { BaseColumns._ID }, null, null, null); numFiles = c != null ? c.getCount() : 0; } catch (Exception e) { Log.e(TAG, "Failed to get num of files", e); } finally { if (c != null) { c.close(); } } result = onlyShared ? (getSharedFiles(fileType).size()) : numFiles; updateCacheNumFiles(fileType, result, onlyShared); return result; }
From source file:pl.ipebk.tabi.infrastructure.daos.SearchHistoryDao.java
private Pair<String, String[]> getHistoryPlacesSql(Integer limit, int type) { String columnsF1 = getAliasedColumnsForPlaceListItems("f1"); String columnsF2 = getAliasedColumnsForPlaceListItems("f2").replace("f2." + PlacesTable.COLUMN_PLACE_TYPE, "f2.type"); String plateChangeAlias = PlacesTable.COLUMN_PLATE + " AS " + PlacesTable.COLUMN_PLATE; String columnsF1Inside = placesTable.getQualifiedColumnsCommaSeparated("p") .replace("p." + plateChangeAlias, "s." + plateChangeAlias) .replace("p." + PlacesTable.COLUMN_PLATE_END, "null"); String columnsF2Inside = placesTable.getQualifiedColumnsCommaSeparated(null) .replace(PlacesTable.COLUMN_PLACE_TYPE, "6 as type"); if (standardPlacesWithPlateCount == 0) { standardPlacesWithPlateCount = getStandardPlacesWithPlateCount(); }//from w w w . j a v a 2 s. c o m if (placesCount == 0) { placesCount = getPlacesCount(); } String limitSql = ""; if (limit != null && limit > 0) { limitSql = " LIMIT " + Integer.toString(limit - 1); } String selectPlacesFromHistory = " SELECT " + columnsF1Inside + " FROM " + SearchHistoryTable.TABLE_NAME + " s left join " + PlacesTable.TABLE_NAME + " p on s." + SearchHistoryTable.COLUMN_PLACE_ID + " = p." + BaseColumns._ID + " WHERE s." + SearchHistoryTable.COLUMN_SEARCH_TYPE + " = " + Integer.toString(type) + " ORDER BY s." + SearchHistoryTable.COLUMN_TIME_SEARCHED + " DESC " + limitSql; String selectRandom = " SELECT " + columnsF2Inside + " FROM " + PlacesTable.TABLE_NAME; String limitRandomTemplate = " LIMIT 1 OFFSET ABS(RANDOM() %% %d"; if (type == SearchType.LICENSE_PLATE.ordinal()) { String whereClause = " WHERE " + PlacesTable.COLUMN_PLACE_TYPE + " < %s AND " + PlacesTable.COLUMN_HAS_OWN_PLATE + " = %s "; String[] whereArgs = { Integer.toString(PlaceType.SPECIAL.ordinal()), Integer.toString(1) }; selectRandom += String.format(whereClause, whereArgs) + String.format(limitRandomTemplate, standardPlacesWithPlateCount); } else if (type == SearchType.PLACE.ordinal()) { selectRandom += String.format(limitRandomTemplate, placesCount); } String sql = " SELECT " + columnsF1 + " FROM (" + selectPlacesFromHistory + ") AS f1 " + " UNION ALL " + " SELECT " + columnsF2 + " FROM (" + selectRandom + ")) as f2"; return new Pair<>(sql, null); }
From source file:com.google.android.apps.muzei.gallery.GalleryArtSource.java
private void publishNextArtwork(Uri forceUri) { // schedule next scheduleNext();//from ww w . jav a2s .c om Cursor chosenUris = getContentResolver().query(GalleryContract.ChosenPhotos.CONTENT_URI, new String[] { BaseColumns._ID }, null, null, null); int numChosenUris = (chosenUris != null) ? chosenUris.getCount() : 0; Artwork currentArtwork = getCurrentArtwork(); String lastToken = (currentArtwork != null) ? currentArtwork.getToken() : null; Uri imageUri; Random random = new Random(); if (forceUri != null) { imageUri = forceUri; } else if (numChosenUris > 0) { while (true) { chosenUris.moveToPosition(random.nextInt(chosenUris.getCount())); imageUri = ContentUris.withAppendedId(GalleryContract.ChosenPhotos.CONTENT_URI, chosenUris.getLong(chosenUris.getColumnIndex(BaseColumns._ID))); if (numChosenUris <= 1 || !imageUri.toString().equals(lastToken)) { break; } } } else { if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { Log.w(TAG, "Missing read external storage permission."); return; } Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[] { MediaStore.MediaColumns._ID }, MediaStore.Images.Media.BUCKET_DISPLAY_NAME + " NOT LIKE '%Screenshots%'", null, null); if (cursor == null) { Log.w(TAG, "Empty cursor."); return; } int count = cursor.getCount(); if (count == 0) { Log.e(TAG, "No photos in the gallery."); return; } while (true) { cursor.moveToPosition(random.nextInt(count)); imageUri = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, cursor.getLong(0)); if (!imageUri.toString().equals(lastToken)) { break; } } cursor.close(); } if (chosenUris != null) { chosenUris.close(); } String token = imageUri.toString(); // Retrieve metadata for item ensureMetadataExists(imageUri); String[] projection = { GalleryContract.MetadataCache.COLUMN_NAME_DATETIME, GalleryContract.MetadataCache.COLUMN_NAME_LOCATION }; Cursor metadata = getContentResolver().query(GalleryContract.MetadataCache.CONTENT_URI, projection, GalleryContract.MetadataCache.COLUMN_NAME_URI + "=?", new String[] { imageUri.toString() }, null); long datetime = 0; String location = null; if (metadata != null && metadata.moveToFirst()) { datetime = metadata .getLong(metadata.getColumnIndex(GalleryContract.MetadataCache.COLUMN_NAME_DATETIME)); location = metadata .getString(metadata.getColumnIndex(GalleryContract.MetadataCache.COLUMN_NAME_LOCATION)); } if (metadata != null) { metadata.close(); } // Publish the actual artwork String title; if (datetime > 0) { title = DateUtils.formatDateTime(this, datetime, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_WEEKDAY); } else { title = getString(R.string.gallery_from_gallery); } String byline; if (!TextUtils.isEmpty(location)) { byline = location; } else { byline = getString(R.string.gallery_touch_to_view); } publishArtwork(new Artwork.Builder().imageUri(imageUri).title(title).byline(byline).token(token) .viewIntent(new Intent(Intent.ACTION_VIEW).setDataAndType(imageUri, "image/jpeg")).build()); }
From source file:ja.ohac.wallet.ExchangeRatesProvider.java
@Override public Cursor query(final Uri uri, final String[] projection, final String selection, final String[] selectionArgs, final String sortOrder) { final long now = System.currentTimeMillis(); if (lastUpdated == 0 || now - lastUpdated > UPDATE_FREQ_MS) { Map<String, ExchangeRate> newExchangeRates = null; if (newExchangeRates == null) newExchangeRates = requestExchangeRates(BITCOINAVERAGE_URL, userAgent, BITCOINAVERAGE_SOURCE, BITCOINAVERAGE_FIELDS); if (newExchangeRates == null) newExchangeRates = requestExchangeRates(BLOCKCHAININFO_URL, userAgent, BLOCKCHAININFO_SOURCE, BLOCKCHAININFO_FIELDS); if (newExchangeRates != null) { exchangeRates = newExchangeRates; lastUpdated = now;//from ww w. j ava2 s .c om final ExchangeRate exchangeRateToCache = bestExchangeRate(config.getExchangeCurrencyCode()); if (exchangeRateToCache != null) config.setCachedExchangeRate(exchangeRateToCache); } } if (exchangeRates == null) return null; final MatrixCursor cursor = new MatrixCursor( new String[] { BaseColumns._ID, KEY_CURRENCY_CODE, KEY_RATE, KEY_SOURCE }); if (selection == null) { for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) { final ExchangeRate rate = entry.getValue(); cursor.newRow().add(rate.currencyCode.hashCode()).add(rate.currencyCode).add(rate.rate.longValue()) .add(rate.source); } } else if (selection.equals(QUERY_PARAM_Q)) { final String selectionArg = selectionArgs[0].toLowerCase(Locale.US); for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) { final ExchangeRate rate = entry.getValue(); final String currencyCode = rate.currencyCode; final String currencySymbol = GenericUtils.currencySymbol(currencyCode); if (currencyCode.toLowerCase(Locale.US).contains(selectionArg) || currencySymbol.toLowerCase(Locale.US).contains(selectionArg)) cursor.newRow().add(currencyCode.hashCode()).add(currencyCode).add(rate.rate.longValue()) .add(rate.source); } } else if (selection.equals(KEY_CURRENCY_CODE)) { final String selectionArg = selectionArgs[0]; final ExchangeRate rate = bestExchangeRate(selectionArg); if (rate != null) cursor.newRow().add(rate.currencyCode.hashCode()).add(rate.currencyCode).add(rate.rate.longValue()) .add(rate.source); } return cursor; }
From source file:com.cannabiscoin.wallet.ExchangeRatesProvider.java
@Override public Cursor query(final Uri uri, final String[] projection, final String selection, final String[] selectionArgs, final String sortOrder) { final long now = System.currentTimeMillis(); if (lastUpdated == 0 || now - lastUpdated > UPDATE_FREQ_MS) { Map<String, ExchangeRate> newExchangeRates = null; if (newExchangeRates == null) newExchangeRates = requestExchangeRates(BITCOINAVERAGE_URL, userAgent, BITCOINAVERAGE_FIELDS); if (newExchangeRates == null) newExchangeRates = requestExchangeRates(BLOCKCHAININFO_URL, userAgent, BLOCKCHAININFO_FIELDS); if (newExchangeRates != null) { exchangeRates = newExchangeRates; lastUpdated = now;// w ww .ja v a 2 s.c o m final ExchangeRate exchangeRateToCache = bestExchangeRate(config.getExchangeCurrencyCode()); if (exchangeRateToCache != null) config.setCachedExchangeRate(exchangeRateToCache); } } if (exchangeRates == null) return null; final MatrixCursor cursor = new MatrixCursor( new String[] { BaseColumns._ID, KEY_CURRENCY_CODE, KEY_RATE, KEY_SOURCE }); if (selection == null) { for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) { final ExchangeRate rate = entry.getValue(); cursor.newRow().add(rate.currencyCode.hashCode()).add(rate.currencyCode).add(rate.rate.longValue()) .add(rate.source); } } else if (selection.equals(QUERY_PARAM_Q)) { final String selectionArg = selectionArgs[0].toLowerCase(Locale.US); for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) { final ExchangeRate rate = entry.getValue(); final String currencyCode = rate.currencyCode; final String currencySymbol = GenericUtils.currencySymbol(currencyCode); if (currencyCode.toLowerCase(Locale.US).contains(selectionArg) || currencySymbol.toLowerCase(Locale.US).contains(selectionArg)) cursor.newRow().add(currencyCode.hashCode()).add(currencyCode).add(rate.rate.longValue()) .add(rate.source); } } else if (selection.equals(KEY_CURRENCY_CODE)) { final String selectionArg = selectionArgs[0]; final ExchangeRate rate = bestExchangeRate(selectionArg); if (rate != null) cursor.newRow().add(rate.currencyCode.hashCode()).add(rate.currencyCode).add(rate.rate.longValue()) .add(rate.source); } return cursor; }
From source file:com.deliciousdroid.platform.BookmarkManager.java
public static Bookmark GetById(int id, Context context) throws ContentNotFoundException { final String[] projection = new String[] { Bookmark.Account, Bookmark.Url, Bookmark.Description, Bookmark.Notes, Bookmark.Time, Bookmark.Tags, Bookmark.Hash, Bookmark.Meta, Bookmark.Shared, Bookmark.Synced, Bookmark.Deleted }; String selection = BaseColumns._ID + "=?"; final String[] selectionargs = new String[] { Integer.toString(id) }; selection += " AND " + Bookmark.Deleted + "=0"; Cursor c = context.getContentResolver().query(Bookmark.CONTENT_URI, projection, selection, selectionargs, null);/* w w w . ja v a2 s . co m*/ if (c.moveToFirst()) { final int accountColumn = c.getColumnIndex(Bookmark.Account); final int urlColumn = c.getColumnIndex(Bookmark.Url); final int descriptionColumn = c.getColumnIndex(Bookmark.Description); final int notesColumn = c.getColumnIndex(Bookmark.Notes); final int tagsColumn = c.getColumnIndex(Bookmark.Tags); final int hashColumn = c.getColumnIndex(Bookmark.Hash); final int metaColumn = c.getColumnIndex(Bookmark.Meta); final int timeColumn = c.getColumnIndex(Bookmark.Time); final int shareColumn = c.getColumnIndex(Bookmark.Shared); final int syncedColumn = c.getColumnIndex(Bookmark.Synced); final int deletedColumn = c.getColumnIndex(Bookmark.Deleted); final boolean share = c.getInt(shareColumn) == 0 ? false : true; final boolean synced = c.getInt(syncedColumn) == 0 ? false : true; final boolean deleted = c.getInt(deletedColumn) == 0 ? false : true; Bookmark b = new Bookmark(id, c.getString(accountColumn), c.getString(urlColumn), c.getString(descriptionColumn), c.getString(notesColumn), c.getString(tagsColumn), c.getString(hashColumn), c.getString(metaColumn), c.getLong(timeColumn), share, synced, deleted); c.close(); return b; } else { c.close(); throw new ContentNotFoundException(); } }
From source file:com.vedant.hereami.chatfolder.MyFirebaseMessagingService.java
public String getContactDisplayNameByNumber(String number) { Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)); String name = "?"; ContentResolver contentResolver = getContentResolver(); Cursor contactLookup = contentResolver.query(uri, new String[] { BaseColumns._ID, ContactsContract.PhoneLookup.DISPLAY_NAME }, null, null, null); try {//from w w w .ja va 2s . com if (contactLookup != null && contactLookup.getCount() > 0) { contactLookup.moveToNext(); name = contactLookup.getString(contactLookup.getColumnIndex(ContactsContract.Data.DISPLAY_NAME)); //String contactId = contactLookup.getString(contactLookup.getColumnIndex(BaseColumns._ID)); hashMap.put(name, number); } } finally { if (contactLookup != null) { contactLookup.close(); } } return name; }
From source file:es.jpv.android.examples.loadersexample.MainActivityFragment.java
/** * <p>Endless RecyclerView page loader</p> * * When a RecyclerView is scrolled until its end this method is invoked to load more rows *//*from www.j a v a 2 s. c o m*/ @Override public void loadMore() { Bundle loaderArgs = new Bundle(); loaderArgs.putString("Table", DataProviderContract.ITEMS_TABLE_NAME); loaderArgs.putStringArray("Projection", PROJECTION); loaderArgs.putString("Order", BaseColumns._ID); loaderArgs.putLong("Limit", lastLimitLoaded); getLoaderManager().restartLoader(LOADER_ID, loaderArgs, new DBSelectLoader()); }
From source file:com.github.longkai.zhihu.util.Utils.java
/** * ???ContentValues?// w ww . ja v a2 s . c o m * @param jsonArray data * @return itemstopicscontent values map */ public static Map<String, ContentValues[]> process(JSONArray jsonArray) { ContentValues[] items = new ContentValues[jsonArray.length()]; List<ContentValues> topics = new ArrayList<ContentValues>(); ContentValues item; ContentValues topic; // ?? JSONArray array; JSONArray user; JSONArray question; JSONArray _topics; JSONArray _topic; // ??id??(? // ??= =)123,321,456, StringBuilder topicIds = new StringBuilder(); // ??item??? long millis = System.currentTimeMillis(); for (int i = 0; i < items.length; i++) { array = jsonArray.optJSONArray(i); item = new ContentValues(); item.put(BaseColumns._ID, millis--); // item.put(STATUS, array.optString(1)); item.put(ANSWER, array.optString(2)); item.put(VOTE, array.optInt(3)); item.put(LAST_ALTER_DATE, array.optLong(4) * 1000); item.put(ANSWER_ID, array.optLong(5)); // user = array.optJSONArray(6); if (user != null) { item.put(NICK, user.optString(0)); item.put(UID, user.optString(1)); item.put(AVATAR, user.optString(2)); } // question = array.optJSONArray(7); if (question != null) { item.put(TITLE, question.optString(1, null)); item.put(DESCRIPTION, question.optString(2)); item.put(QUESTION_ID, question.optLong(3)); item.put(STARRED, question.optLong(5)); item.put(VIEWED, question.optLong(6)); } // ? topicIds.setLength(0); if (!question.isNull(7)) { _topics = question.optJSONArray(7); for (int j = 0; j < _topics.length(); j++) { _topic = _topics.optJSONArray(j); topic = new ContentValues(4); topic.put(TOPIC_NAME, _topic.optString(1, null)); topic.put(TOPIC_DESCRIPTION, _topic.optString(2)); topic.put(TOPIC_AVATAR, _topic.optString(3)); topic.put(TOPIC_ID, _topic.optLong(4)); // todo ?????replace? // ????????? topics.add(topic); // ?item? topicIds.append(_topic.optLong(4)).append(","); } } item.put(TOPICS, topicIds.toString()); // ?json item.put(VOTERS, array.isNull(8) ? null : array.optJSONArray(8).toString()); items[i] = item; } Map<String, ContentValues[]> map = new HashMap<String, ContentValues[]>(2); map.put(ITEMS, items); map.put(TOPICS, topics.toArray(new ContentValues[0])); return map; }
From source file:org.musicmod.android.app.QueryFragment.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { String filter = ""; if (args != null) { filter = args.getString(INTENT_KEY_FILTER) != null ? args.getString(INTENT_KEY_FILTER) : ""; }//from w w w .ja v a2 s . c o m StringBuilder where = new StringBuilder(); where.append(Audio.Media.IS_MUSIC + "=1"); where.append(" AND " + Audio.Media.TITLE + " != ''"); String[] cols = new String[] { BaseColumns._ID, Audio.Media.MIME_TYPE, Audio.Artists.ARTIST, Audio.Albums.ALBUM, Audio.Media.TITLE, "data1", "data2" }; Uri uri = Uri.parse("content://media/external/audio/search/fancy/" + Uri.encode(filter)); // Now create and return a CursorLoader that will take care of // creating a Cursor for the data being displayed. return new CursorLoader(getActivity(), uri, cols, where.toString(), null, null); }