List of usage examples for android.net Uri getLastPathSegment
@Nullable public abstract String getLastPathSegment();
From source file:stepic.stepic.MapsActivity.java
private String getPath(final Uri uri) { final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; if (isKitKat) { // MediaStore (and general) return getForApi19(uri); } else if ("content".equalsIgnoreCase(uri.getScheme())) { // Return the remote address if (isGooglePhotosUri(uri)) return uri.getLastPathSegment(); return getDataColumn(uri, null, null); }//from w w w.ja v a 2s . c om // File else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; }
From source file:com.viktorrudometkin.burramys.fragment.EntryFragment.java
public void setData(Uri uri) { mCurrentPagerPos = -1;/* w w w.j a va 2 s. c om*/ mBaseUri = FeedData.EntryColumns.PARENT_URI(uri.getPath()); try { mInitialEntryId = Long.parseLong(uri.getLastPathSegment()); } catch (Exception unused) { mInitialEntryId = -1; } if (mBaseUri != null) { String entriesOrder = PrefUtils.getBoolean(PrefUtils.DISPLAY_OLDEST_FIRST, false) ? Constants.DB_ASC : Constants.DB_DESC; // Load the entriesIds list. Should be in a loader... but I was too lazy to do so Cursor entriesCursor = MainApplication.getContext().getContentResolver().query(mBaseUri, EntryColumns.PROJECTION_ID, null, null, EntryColumns.DATE + entriesOrder); if (entriesCursor != null && entriesCursor.getCount() > 0) { mEntriesIds = new long[entriesCursor.getCount()]; int i = 0; while (entriesCursor.moveToNext()) { mEntriesIds[i] = entriesCursor.getLong(0); if (mEntriesIds[i] == mInitialEntryId) { mCurrentPagerPos = i; // To immediately display the good entry } i++; } entriesCursor.close(); } } else { mEntriesIds = null; } mEntryPagerAdapter.notifyDataSetChanged(); if (mCurrentPagerPos != -1) { mEntryPager.setCurrentItem(mCurrentPagerPos); } }
From source file:com.odoo.support.provider.OContentProvider.java
@Override public int delete(Uri uri, String where, String[] whereArgs) { reInitModel();/* www . j a va2 s . co m*/ final SQLiteDatabase db = model.getWritableDatabase(); assert db != null; final int match = matcher.match(uri); int count = 0; SelectionBuilder builder = new SelectionBuilder(); switch (match) { case COLLECTION: count = builder.table(model.getTableName()).where(where, whereArgs).delete(db); break; case SINGLE_ROW: String id = uri.getLastPathSegment(); count = builder.table(model.getTableName()).where(OColumn.ROW_ID + "=?", id).where(where, whereArgs) .delete(db); break; default: throw new UnsupportedOperationException("Unknown uri: " + uri); } // Send broadcast to registered ContentObservers, to refresh UI. Context ctx = getContext(); assert ctx != null; ctx.getContentResolver().notifyChange(uri, null, false); return count; }
From source file:mobisocial.socialkit.musubi.Musubi.java
public DbIdentity userForGlobalId(Uri feedUri, String personId) { byte[] idHash = MusubiUtil.convertToByteArray(personId); long shortHash = MusubiUtil.shortHash(idHash); Uri uri = new Uri.Builder().scheme("content").authority(Musubi.AUTHORITY) .appendPath(DbThing.MEMBER.toString()).appendPath(feedUri.getLastPathSegment()).build(); String selection = DbIdentity.COL_ID_SHORT_HASH + " = ?"; String[] selectionArgs = new String[] { Long.toString(shortHash) }; String sortOrder = null;//w ww . j av a2s . c o m Cursor c = mContext.getContentResolver().query(uri, DbIdentity.COLUMNS, selection, selectionArgs, sortOrder); try { while (c != null && c.moveToNext()) { DbIdentity mate = DbIdentity.fromStandardCursor(mContext, c); if (mate.getId().equals(personId)) { return mate; } } Log.e(TAG, "id not found #" + shortHash); return null; } finally { if (c != null) { c.close(); } } }
From source file:com.studyjams.mdvideo.PlayerModule.ExoPlayerV2.PlayerActivityV2.java
private MediaSource buildMediaSource(Uri uri, String overrideExtension) { int type = Util.inferContentType( !TextUtils.isEmpty(overrideExtension) ? "." + overrideExtension : uri.getLastPathSegment()); switch (type) { case TYPE_SS: return new SsMediaSource(uri, buildDataSourceFactory(false), new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mainHandler, eventLogger); case C.TYPE_DASH: return new DashMediaSource(uri, buildDataSourceFactory(false), new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mainHandler, eventLogger); case C.TYPE_HLS: return new HlsMediaSource(uri, mediaDataSourceFactory, mainHandler, eventLogger); case C.TYPE_OTHER: MediaSource mediaSource = new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(), mainHandler, eventLogger); if (mSubtitleUri != null) { Log.d(TAG, "========buildMediaSource: "); return TextSubtitle(mSubtitleUri, mediaSource); } else {/*from ww w. j av a 2 s. c o m*/ return mediaSource; } default: { throw new IllegalStateException("Unsupported type: " + type); } } }
From source file:com.flym.dennikn.fragment.EntryFragment.java
public void setData(Uri uri) { mCurrentPagerPos = -1;//from ww w. ja v a 2 s . c o m mBaseUri = FeedData.EntryColumns.PARENT_URI(uri.getPath()); try { mInitialEntryId = Long.parseLong(uri.getLastPathSegment()); } catch (Exception unused) { mInitialEntryId = -1; } if (mBaseUri != null) { Bundle b = getActivity().getIntent().getExtras(); String whereClause = FeedData.shouldShowReadEntries(mBaseUri) || (b != null && b.getBoolean(Constants.INTENT_FROM_WIDGET, false)) ? null : EntryColumns.WHERE_UNREAD; String entriesOrder = PrefUtils.getBoolean(PrefUtils.DISPLAY_OLDEST_FIRST, false) ? Constants.DB_ASC : Constants.DB_DESC; // Load the entriesIds list. Should be in a loader... but I was too lazy to do so Cursor entriesCursor = MainApplication.getContext().getContentResolver().query(mBaseUri, EntryColumns.PROJECTION_ID, whereClause, null, EntryColumns.DATE + entriesOrder); if (entriesCursor != null && entriesCursor.getCount() > 0) { mEntriesIds = new long[entriesCursor.getCount()]; int i = 0; while (entriesCursor.moveToNext()) { mEntriesIds[i] = entriesCursor.getLong(0); if (mEntriesIds[i] == mInitialEntryId) { mCurrentPagerPos = i; // To immediately display the good entry } i++; } entriesCursor.close(); } } else { mEntriesIds = null; } mEntryPagerAdapter.notifyDataSetChanged(); if (mCurrentPagerPos != -1) { mEntryPager.setCurrentItem(mCurrentPagerPos); } }
From source file:com.example.android.sampletvinput.PlaybackOverlayFragment.java
private VideoPlayer.RendererBuilder getRendererBuilder() { String userAgent = Util.getUserAgent(getActivity(), "ExoVideoPlayer"); Uri contentUri = Uri.parse(mSelectedVideo.videoUrl); int contentType = Util.inferContentType(contentUri.getLastPathSegment()); switch (contentType) { case Util.TYPE_OTHER: { return new ExtractorRendererBuilder(getActivity(), userAgent, contentUri); }// www. java 2s. c om case Util.TYPE_DASH: { // Implement your own DRM callback here. MediaDrmCallback drmCallback = new WidevineTestMediaDrmCallback(null, null); return new DashRendererBuilder(getActivity(), userAgent, contentUri.toString(), drmCallback); } case Util.TYPE_HLS: { return new HlsRendererBuilder(getActivity(), userAgent, contentUri.toString()); } default: { throw new IllegalStateException("Unsupported type: " + contentType); } } }
From source file:com.apptentive.android.sdk.model.FileMessage.java
public boolean createStoredFile(Context context, String uriString) { Uri uri = Uri.parse(uriString); ContentResolver resolver = context.getContentResolver(); String mimeType = resolver.getType(uri); MimeTypeMap mime = MimeTypeMap.getSingleton(); String extension = mime.getExtensionFromMimeType(mimeType); // If we can't get the mime type from the uri, try getting it from the extension. if (extension == null) { extension = MimeTypeMap.getFileExtensionFromUrl(uriString); }/*from w ww.ja va 2 s . c om*/ if (mimeType == null && extension != null) { mimeType = mime.getMimeTypeFromExtension(extension); } setFileName(uri.getLastPathSegment() + "." + extension); setMimeType(mimeType); InputStream is = null; try { is = new BufferedInputStream(context.getContentResolver().openInputStream(uri)); return createStoredFile(context, is, mimeType); } catch (FileNotFoundException e) { Log.e("File not found while storing file.", e); } catch (IOException e) { Log.a("Error storing image.", e); } finally { Util.ensureClosed(is); } return false; }
From source file:com.ichi2.anki.tests.ContentProviderTest.java
/** * Check that inserting a new model works as expected *///from w ww. j av a 2 s . c o m public void testInsertAndUpdateModel() throws Exception { final ContentResolver cr = getContext().getContentResolver(); ContentValues cv = new ContentValues(); // Insert a new model cv.put(FlashCardsContract.Model.NAME, TEST_MODEL_NAME); cv.put(FlashCardsContract.Model.FIELD_NAMES, Utils.joinFields(TEST_MODEL_FIELDS)); cv.put(FlashCardsContract.Model.NUM_CARDS, TEST_MODEL_CARDS.length); cv.put(FlashCardsContract.Model.CSS, TEST_MODEL_CSS); Uri modelUri = cr.insert(FlashCardsContract.Model.CONTENT_URI, cv); assertNotNull("Check inserted model isn't null", modelUri); long mid = Long.parseLong(modelUri.getLastPathSegment()); final Collection col = CollectionHelper.getInstance().getCol(getContext()); try { JSONObject model = col.getModels().get(mid); assertEquals("Check model name", TEST_MODEL_NAME, model.getString("name")); assertEquals("Check css", TEST_MODEL_CSS, model.getString("css")); assertEquals("Check templates length", TEST_MODEL_CARDS.length, model.getJSONArray("tmpls").length()); assertEquals("Check field length", TEST_MODEL_FIELDS.length, model.getJSONArray("flds").length()); JSONArray flds = model.getJSONArray("flds"); for (int i = 0; i < flds.length(); i++) { assertEquals("Check name of fields", flds.getJSONObject(i).getString("name"), TEST_MODEL_FIELDS[i]); } // Update each of the templates in the model for (int i = 0; i < TEST_MODEL_CARDS.length; i++) { cv = new ContentValues(); cv.put(FlashCardsContract.CardTemplate.NAME, TEST_MODEL_CARDS[i]); cv.put(FlashCardsContract.CardTemplate.QUESTION_FORMAT, TEST_MODEL_QFMT[i]); cv.put(FlashCardsContract.CardTemplate.ANSWER_FORMAT, TEST_MODEL_AFMT[i]); cv.put(FlashCardsContract.CardTemplate.BROWSER_QUESTION_FORMAT, TEST_MODEL_QFMT[i]); cv.put(FlashCardsContract.CardTemplate.BROWSER_ANSWER_FORMAT, TEST_MODEL_AFMT[i]); Uri tmplUri = Uri.withAppendedPath(Uri.withAppendedPath(modelUri, "templates"), Integer.toString(i)); assertTrue("Update rows", cr.update(tmplUri, cv, null, null) > 0); JSONObject template = col.getModels().get(mid).getJSONArray("tmpls").getJSONObject(i); assertEquals("Check template name", TEST_MODEL_CARDS[i], template.getString("name")); assertEquals("Check qfmt", TEST_MODEL_QFMT[i], template.getString("qfmt")); assertEquals("Check afmt", TEST_MODEL_AFMT[i], template.getString("afmt")); assertEquals("Check bqfmt", TEST_MODEL_QFMT[i], template.getString("bqfmt")); assertEquals("Check bafmt", TEST_MODEL_AFMT[i], template.getString("bafmt")); } } finally { // Delete the model (this will force a full-sync) try { col.modSchema(false); col.getModels().rem(col.getModels().get(mid)); } catch (ConfirmModSchemaException e) { // This will never happen throw new IllegalStateException("Unexpected ConfirmModSchemaException trying to remove model"); } } }
From source file:com.carlrice.reader.fragment.EntryFragment.java
public void setData(Uri uri) { mCurrentPagerPos = -1;/*from w ww .j a v a 2 s.c om*/ mBaseUri = FeedData.EntryColumns.PARENT_URI(uri.getPath()); try { mInitialEntryId = Long.parseLong(uri.getLastPathSegment()); } catch (Exception unused) { mInitialEntryId = -1; } if (mBaseUri != null) { Bundle b = getActivity().getIntent().getExtras(); String whereClause = FeedData.shouldShowReadEntries(mBaseUri) || (b != null && b.getBoolean(Constants.INTENT_FROM_WIDGET, false)) ? null : EntryColumns.WHERE_UNREAD; String entriesOrder = PrefUtils.getBoolean(PrefUtils.DISPLAY_OLDEST_FIRST, false) ? Constants.DB_ASC : Constants.DB_DESC; // Load the entriesIds list. Should be in a loader... but I was too lazy to do so Cursor entriesCursor = Application.context().getContentResolver().query(mBaseUri, EntryColumns.PROJECTION_ID, whereClause, null, EntryColumns.DATE + entriesOrder); if (entriesCursor != null && entriesCursor.getCount() > 0) { mEntriesIds = new long[entriesCursor.getCount()]; int i = 0; while (entriesCursor.moveToNext()) { mEntriesIds[i] = entriesCursor.getLong(0); if (mEntriesIds[i] == mInitialEntryId) { mCurrentPagerPos = i; // To immediately display the good entry } i++; } entriesCursor.close(); } } else { mEntriesIds = null; } mEntryPagerAdapter.notifyDataSetChanged(); if (mCurrentPagerPos != -1) { mEntryPager.setCurrentItem(mCurrentPagerPos); } }