List of usage examples for android.net Uri getLastPathSegment
@Nullable public abstract String getLastPathSegment();
From source file:Main.java
/** * Returns a name for a new dictionary based on import URI. */// w w w . j av a 2s .c o m static String generateDictionaryNameByUri(Uri importUri, List<String> dictionaryNameList) { String name = importUri.getLastPathSegment(); // Strip extension { int index = name.lastIndexOf('.'); if (index > 0) { // Keep file path beginning with '.'. name = name.substring(0, index); } } if (!dictionaryNameList.contains(name)) { // No-dupped dictionary name. return name; } // The names extracted from uri is dupped. So look for alternative names by adding // number suffix, such as "pathname (1)". int suffix = 1; while (true) { String candidate = name + " (" + suffix + ")"; if (!dictionaryNameList.contains(candidate)) { return candidate; } // The limit of the number of dictionaries is much smaller than Integer.MAX_VALUE, // so this while loop should stop eventually. ++suffix; } }
From source file:Main.java
public static List<String> getAllTables(Uri uri) { List<String> result = new ArrayList<String>(); String mainTable = uri.getLastPathSegment(); result.add(mainTable);/*w ww .j av a 2s . c o m*/ Set<String> queryParameterNames = getQueryParameterNames(uri); Iterator<String> iterator = queryParameterNames.iterator(); while (iterator.hasNext()) { String table = iterator.next(); if (table.startsWith(TABLE)) { result.add(table.replaceFirst(TABLE, "")); } } return result; }
From source file:Main.java
public static int inferContentType(Uri uri, String fileExtension) { String lastPathSegment = !TextUtils.isEmpty(fileExtension) ? "." + fileExtension : uri.getLastPathSegment(); if (lastPathSegment == null) { return TYPE_OTHER; } else if (lastPathSegment.endsWith(EXT_DASH)) { return TYPE_DASH; } else if (lastPathSegment.endsWith(EXT_SS)) { return TYPE_SS; } else if (lastPathSegment.endsWith(EXT_HLS)) { return TYPE_HLS; } else {/*from ww w . jav a2 s .c o m*/ return TYPE_OTHER; } }
From source file:com.google.imageplayground.util.ScaledBitmapCache.java
public static ThumbnailLocator createFixedDirectoryLocator(final String thumbnailDirectory) { return new ThumbnailLocator() { public File thumbnailFileForUri(Uri imageUri) { String filename = imageUri.getLastPathSegment(); return new File(thumbnailDirectory + File.separator + filename); }// w w w . j a v a2 s . c om }; }
From source file:Main.java
/** * @param context The {@link Context} to use. * @param name The name of the new playlist. * @return A new playlist ID.//from w ww . j a v a2 s. co m */ public static final long createPlaylist(final Context context, final String name) { if (name != null && name.length() > 0) { final ContentResolver resolver = context.getContentResolver(); final String[] projection = new String[] { PlaylistsColumns.NAME }; final String selection = PlaylistsColumns.NAME + " = '" + name + "'"; Cursor cursor = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, projection, selection, null, null); if (cursor.getCount() <= 0) { final ContentValues values = new ContentValues(1); values.put(PlaylistsColumns.NAME, name); final Uri uri = resolver.insert(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, values); return Long.parseLong(uri.getLastPathSegment()); } if (cursor != null) { cursor.close(); cursor = null; } return -1; } return -1; }
From source file:Main.java
/** * Query the server app to get the file's display name. *///from w ww . j ava 2s . c o m public static String getUriFileName(Context context, Uri uri) { if (uri == null) { return null; } if (uri.getScheme().equals("file")) { return uri.getLastPathSegment(); } if (uri.getScheme().equals("content")) { Cursor returnCursor = context.getContentResolver().query(uri, null, null, null, null); //Get the column index of the data in the Cursor, //move to the first row in the Cursor, get the data, and display it. int name_index = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME); //int size_index = returnCursor.getColumnIndex(OpenableColumns.SIZE); if (name_index < 0) { return null; } returnCursor.moveToFirst(); //return returnCursor.getLong(size_index) return returnCursor.getString(name_index); } return null; }
From source file:Main.java
/** * Checks to see if URL is DuckDuckGo SERP * Returns the query if it's a SERP, otherwise null * // w ww.j a va 2s.c om * @param url * @return */ static public String getQueryIfSerp(String url) { if (!isSerpUrl(url)) { return null; } Uri uri = Uri.parse(url); String query = uri.getQueryParameter("q"); if (query != null) return query; String lastPath = uri.getLastPathSegment(); if (lastPath == null) return null; if (!lastPath.contains(".html")) { return lastPath.replace("_", " "); } return null; }
From source file:edu.stanford.mobisocial.dungbeetle.model.AppState.java
@Deprecated public static AppState fromIntent(Intent intent) { String arg = intent.getStringExtra(EXTRA_APPLICATION_ARGUMENT); String pkg = intent.getStringExtra(EXTRA_APPLICATION_PACKAGE); String state = intent.getStringExtra(EXTRA_APPLICATION_STATE); String thumbImg = intent.getStringExtra(EXTRA_APPLICATION_IMG); String thumbText = intent.getStringExtra(EXTRA_APPLICATION_TEXT); Uri feedUri = (Uri) intent.getParcelableExtra(EXTRA_FEED_URI); return new AppState(pkg, arg, state, thumbImg, thumbText, feedUri.getLastPathSegment(), null); }
From source file:org.peterbaldwin.vlcremote.fragment.ArtFragment.java
private static Uri resizeJamendoImage(Uri uri) { String path = uri.getPath();//from ww w .ja va2s . c o m path = path.replace("/" + uri.getLastPathSegment(), "/1.400.jpg"); return uri.buildUpon().path(path).build(); }
From source file:Main.java
/** * Return the filename from a uri./*from www. ja va 2s . co m*/ */ public static String getFilename(Context c, Uri uri) { try { String scheme = uri.getScheme(); if (scheme.equals("file")) { return uri.getLastPathSegment(); } else if (scheme.equals("content")) { String[] proj = { MediaStore.Files.FileColumns.DISPLAY_NAME }; Cursor cursor = c.getContentResolver().query(uri, proj, null, null, null); if (cursor != null && cursor.getCount() != 0) { int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.DISPLAY_NAME); cursor.moveToFirst(); return cursor.getString(columnIndex); } } } catch (Exception e) { e.printStackTrace(); } return null; }