List of usage examples for android.net Uri getPathSegments
public abstract List<String> getPathSegments();
From source file:org.cdmckay.android.provider.MediaWikiProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { final List<String> segments = uri.getPathSegments(); switch (mUriMatcher.match(uri)) { case SEARCH:/* w w w . jav a 2s. c o m*/ return search(convertPathSegmentToApiUrl(segments.get(0)), uri.getLastPathSegment()); case PAGE_BY_TITLE: return getPageByTitle(convertPathSegmentToApiUrl(segments.get(0)), uri.getLastPathSegment()); case PAGE_BY_ID: return getPageById(convertPathSegmentToApiUrl(segments.get(0)), Long.valueOf(uri.getLastPathSegment())); case SECTIONS_BY_TITLE: return getSectionsByTitle(convertPathSegmentToApiUrl(segments.get(0)), segments.get(3)); default: throw new IllegalArgumentException("Unknown URI: " + uri); } }
From source file:br.com.oromar.dev.android.sunshine.FetchWeatherTask.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param locationSetting The location string used to request updates from the server. * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city * @param lon the longitude of the city * @return the row ID of the added location. *//*from w w w . j a v a 2 s . c o m*/ public long addLocation(String locationSetting, String cityName, double lat, double lon) { long id = 0; // Students: First, check if the location with this city name exists in the db Cursor cursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, // Uri null, //projection WeatherContract.LocationEntry.CITY_NAME + " = ?", //selection new String[] { cityName }, //selectionArgs null);//sortBy // If it exists, return the current ID if (cursor.moveToFirst()) { id = cursor.getInt(cursor.getColumnIndex("_id")); // Otherwise, insert it using the content resolver and the base URI } else { ContentValues contentValues = new ContentValues(); contentValues.put(WeatherContract.LocationEntry.LOCATION_SETTING, locationSetting); contentValues.put(WeatherContract.LocationEntry.CITY_NAME, cityName); contentValues.put(WeatherContract.LocationEntry.COORD_LAT, lat); contentValues.put(WeatherContract.LocationEntry.COORD_LONG, lon); Uri uri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, contentValues); id = Integer.valueOf(uri.getPathSegments().get(1)); } return id; }
From source file:com.manning.androidhacks.hack043.provider.BatchNumbersContentProvider.java
@Override public int delete(Uri uri, String selection, String[] selectionArgs) { SQLiteDatabase db = dbHelper.getWritableDatabase(); int count;//from ww w.j av a 2 s . c om switch (sUriMatcher.match(uri)) { case ITEM: count = db.delete(TABLE_NAME, selection, selectionArgs); break; case ITEM_ID: String id = uri.getPathSegments().get(1); count = db.delete(TABLE_NAME, COLUMN_ID + "=" + id + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ")" : ""), selectionArgs); break; default: throw new RuntimeException("Unkown URI: " + uri); } getContext().getContentResolver().notifyChange(uri, null); return count; }
From source file:com.manning.androidhacks.hack043.provider.MySQLContentProvider.java
@Override protected int updateInTransaction(Uri uri, ContentValues values, String selection, String[] selectionArgs) { int count = 0; switch (sUriMatcher.match(uri)) { case ITEM:/*from www.j a v a2 s .com*/ count = mDb.update(TABLE_NAME, values, selection, selectionArgs); break; case ITEM_ID: count = mDb.update(TABLE_NAME, values, COLUMN_ID + "=" + uri.getPathSegments().get(1) + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ")" : ""), selectionArgs); break; default: throw new RuntimeException("Unknown URI " + uri); } return count; }
From source file:com.manning.androidhacks.hack023.provider.TodoContentProvider.java
@Override public int delete(Uri uri, String selection, String[] selectionArgs) { SQLiteDatabase db = dbHelper.getWritableDatabase(); int count;//from w w w . jav a 2 s .co m switch (sUriMatcher.match(uri)) { case TODO: count = db.delete(TODO_TABLE_NAME, selection, selectionArgs); break; case TODO_ID: String id = uri.getPathSegments().get(1); count = db.delete(TODO_TABLE_NAME, COLUMN_ID + "=" + id + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ")" : ""), selectionArgs); break; default: throw new RuntimeException("Unkown URI: " + uri); } getContext().getContentResolver().notifyChange(uri, null); return count; }
From source file:com.androidquery.simplefeed.fragments.NotificationFragment.java
private String getPostId(FeedItem item, String link, Uri uri) { List<String> paths = uri.getPathSegments(); AQUtility.debug("paths", paths); if (paths.size() < 3) return null; if (!"posts".equals(paths.get(paths.size() - 2))) return null; String last = ParseUtility.resolveId(paths.get(0)) + "_" + paths.get(paths.size() - 1); return last;//from w w w .jav a 2 s . c o m }
From source file:com.androidquery.simplefeed.fragments.NotificationFragment.java
private String getNoteId(FeedItem item, String link, Uri uri) { List<String> paths = uri.getPathSegments(); AQUtility.debug("paths", paths); if (paths.size() < 3) return null; if (!"notes".equals(paths.get(0))) return null; String last = paths.get(paths.size() - 1); return last;/*from ww w . j av a 2s . com*/ }
From source file:com.androidquery.simplefeed.fragments.NotificationFragment.java
private String getEventId(String link, Uri uri) { List<String> paths = uri.getPathSegments(); AQUtility.debug(paths);/*from w w w . j a v a 2 s .c o m*/ String eid = uri.getQueryParameter("eid"); if (eid != null) { return eid; } if (paths.size() < 2) return null; if ("events".equals(paths.get(0))) { return paths.get(1); } return null; }
From source file:com.hivewallet.androidclient.wallet.AddressBookProvider.java
@Override public Uri insert(final Uri uri, final ContentValues values) { if (uri.getPathSegments().size() != 1) throw new IllegalArgumentException(uri.toString()); final String address = uri.getLastPathSegment(); values.put(KEY_ADDRESS, address);/*from w ww .j a va2s .c om*/ long rowId = helper.getWritableDatabase().insertOrThrow(DATABASE_TABLE, null, values); final Uri rowUri = contentUri(getContext().getPackageName()).buildUpon().appendPath(address) .appendPath(Long.toString(rowId)).build(); String photo = values.getAsString(KEY_PHOTO); if (photo != null) helper.setPhotoAssetAsPermanent(photo, true); getContext().getContentResolver().notifyChange(rowUri, null); return rowUri; }
From source file:org.opensilk.music.artwork.provider.ArtworkProvider.java
@Override //@DebugLog//from w w w .ja v a 2s . c om public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException { if (!"r".equals(mode)) { throw new FileNotFoundException("Provider is read only"); } switch (mUriMatcher.match(uri)) { case ArtworkUris.MATCH.ARTWORK: { //Fullscreen final List<String> seg = uri.getPathSegments(); if (seg == null || seg.size() < 2) { break; } final ArtInfo artInfo = new ArtInfo(seg.get(seg.size() - 2), seg.get(seg.size() - 1), null); final ParcelFileDescriptor pfd = getArtwork(uri, artInfo); if (pfd != null) { return pfd; } break; } case ArtworkUris.MATCH.THUMBNAIL: { //Thumbnail final List<String> seg = uri.getPathSegments(); if (seg == null || seg.size() < 2) { break; } final ArtInfo artInfo = new ArtInfo(seg.get(seg.size() - 2), seg.get(seg.size() - 1), null); final ParcelFileDescriptor pfd = getArtworkThumbnail(uri, artInfo); if (pfd != null) { return pfd; } break; } case ArtworkUris.MATCH.ALBUM_REQ: case ArtworkUris.MATCH.ARTIST_REQ: { final String q = uri.getQueryParameter("q"); final String t = uri.getQueryParameter("t"); if (q != null) { final ArtInfo artInfo = UtilsArt.artInfoFromBase64EncodedJson(mGson, q); ArtworkType artworkType = ArtworkType.THUMBNAIL; if (t != null) { artworkType = ArtworkType.valueOf(t); } final ParcelFileDescriptor pfd; switch (artworkType) { case LARGE: pfd = getArtwork(uri, artInfo); break; default: pfd = getArtworkThumbnail(uri, artInfo); break; } if (pfd != null) { return pfd; } } break; } } throw new FileNotFoundException("Could not obtain image from cache"); }