Example usage for android.net Uri getLastPathSegment

List of usage examples for android.net Uri getLastPathSegment

Introduction

In this page you can find the example usage for android.net Uri getLastPathSegment.

Prototype

@Nullable
public abstract String getLastPathSegment();

Source Link

Document

Gets the decoded last segment in the path.

Usage

From source file:org.sanpra.minion.share.MediaShareActivity.java

/**
 * The purpose of this method is to create a string containing a list of the IDs of external media
 * Content URIs. This can be used to fetch information regarding these URIs from the Android OS.
 * This method accepts a list of URIs, and creates a String containing the last path segments
 * of the URIs.//  ww  w  .j  a v a 2  s . c  om
 * The order of the segments in the String is not guaranteed to be the same as the order of URIs
 * in the list.
 * @param imageUriList Input list of URIs. Will not be modified in any way.
 *
 * @return  A string containing a bracketed list of the last path segments of the input URIs
 * in the following format:
 *      ( URIOneLastPathSegment, URITwoLastPathSegment, URIThreeLastPathSegment, ..... )
 *
 *      Returns empty string when imageUriList is null or empty
 */
static String constructIdListString(final Collection<Uri> imageUriList) {
    if (imageUriList == null || imageUriList.isEmpty())
        return "()";

    final StringBuilder idListBuilder = new StringBuilder();

    //add opening bracket
    idListBuilder.append("( ");
    for (Uri imageUri : imageUriList) {
        idListBuilder.append(imageUri.getLastPathSegment()).append(",");
    }
    //remove last , and then add closing bracket
    idListBuilder.deleteCharAt(idListBuilder.length() - 1).append(" )");

    return idListBuilder.toString();
}

From source file:org.peterbaldwin.vlcremote.fragment.ArtFragment.java

private static boolean isJamendoImage(Uri uri) {
    return "imgjam.com".equals(uri.getAuthority()) && uri.getPathSegments().size() != 0
            && uri.getLastPathSegment().matches("1\\.\\d+\\.jpg");
}

From source file:org.totschnig.myexpenses.model.Category.java

/**
 * inserts a new category if id = 0, or alters an existing one if id != 0
 * @param id 0 if a new instance, database id otherwise
 * @param label/*from  w w w.  j a va 2  s.  co m*/
 * @param parentId a new instance is created under this parent, ignored for existing instances
 * @return id of new record, or -1, if it already exists
 */
public static long write(long id, String label, Long parentId) {
    Uri uri = new Category(id, label, parentId).save();
    return uri == null ? -1 : Integer.valueOf(uri.getLastPathSegment());
}

From source file:edu.stanford.mobisocial.dungbeetle.model.Feed.java

/**
 * Returns the personId of the remote friend associated with this feed
 *///from   w  ww .j a  v  a 2  s  .  com
public static String friendIdForFeed(Uri friendFeed) {
    if (typeOf(friendFeed) != FeedType.FRIEND) {
        return null;
    }
    String feedName = friendFeed.getLastPathSegment();
    int sep = feedName.lastIndexOf(':');
    if (sep > 0) {
        feedName = feedName.substring(0, sep);
    }
    String[] parts = feedName.split("\\^");
    if (parts.length != 3) {
        Log.w(TAG, "Bad format for friend feed: " + friendFeed);
        return null;
    }
    if (parts[1].equals(App.instance().getLocalPersonId())) {
        return parts[2];
    } else {
        return parts[1];
    }
}

From source file:Main.java

public static void IcsMakeNewCalendarEntry(String title, String description, String location, long startTime,
        long endTime, int allDay, int hasAlarm, int calendarId, int selectedReminderValue) {

    ContentResolver cr = activityObj.getContentResolver();
    ContentValues values = new ContentValues();
    values.put(Events.DTSTART, startTime);
    values.put(Events.DTEND, endTime);//from  w  w w. j  a va  2  s .  c  o m
    values.put(Events.TITLE, title);
    values.put(Events.DESCRIPTION, description);
    values.put(Events.CALENDAR_ID, calendarId);

    if (allDay == 1) {
        values.put(Events.ALL_DAY, true);
    }

    if (hasAlarm == 1) {
        values.put(Events.HAS_ALARM, true);
    }

    //Get current timezone
    values.put(Events.EVENT_TIMEZONE, TimeZone.getDefault().getID());
    Log.i(DEBUG_TAG, "Timezone retrieved=>" + TimeZone.getDefault().getID());
    Uri uri = cr.insert(Events.CONTENT_URI, values);
    Log.i(DEBUG_TAG, "Uri returned=>" + uri.toString());
    // get the event ID that is the last element in the Uri
    long eventID = Long.parseLong(uri.getLastPathSegment());

    if (hasAlarm == 1) {
        ContentValues reminders = new ContentValues();
        reminders.put(Reminders.EVENT_ID, eventID);
        reminders.put(Reminders.METHOD, Reminders.METHOD_ALERT);
        reminders.put(Reminders.MINUTES, selectedReminderValue);

        Uri uri2 = cr.insert(Reminders.CONTENT_URI, reminders);
    }

}

From source file:edu.stanford.mobisocial.dungbeetle.social.FriendRequest.java

public static long acceptFriendRequest(Context c, Uri friendRequest, boolean requireCapability) {
    String email = friendRequest.getQueryParameter("email");
    String name = friendRequest.getQueryParameter("name");
    if (name == null) {
        name = email;//w w w  .  j a v a  2 s .co m
    }

    String pubKeyStr = friendRequest.getQueryParameter("publicKey");
    RSACrypto.publicKeyFromString(pubKeyStr); // may throw exception
    String cap = friendRequest.getQueryParameter("cap");
    if (requireCapability) {
        if (cap == null) {
            Log.w(TAG, "Unapproved friend request");
            return -1;
        }
        SharedPreferences p = c.getSharedPreferences("main", 0);
        String myCap = p.getString(PREF_FRIEND_CAPABILITY, null);
        if (myCap == null) {
            Log.w(TAG, "No capability available");
            return -1;
        }
        if (!cap.equals(myCap)) {
            Log.w(TAG, "Capability mismatch");
            return -1;
        }
    }

    Uri uri = Helpers.insertContact(c, pubKeyStr, name, email);
    long contactId = Long.valueOf(uri.getLastPathSegment());
    Helpers.insertSubscriber(c, contactId, "friend");
    return contactId;
}

From source file:org.catnut.plugin.zhihu.Zhihu.java

/**
 * ??/*w  w w  .j  a  v  a 2s .  co  m*/
 *
 * @param context
 * @param uri
 * @return
 */
public static Uri getCacheImageLocation(Context context, Uri uri) {
    File img = new File(context.getExternalCacheDir() + File.separator + CACHE_IMAGE_LOCATION + File.separator
            + uri.getLastPathSegment());
    return Uri.fromFile(img);
}

From source file:org.fdroid.fdroid.installer.ApkCache.java

/**
 * Get the full path for where an APK URL will be downloaded into.
 *///from   ww  w  . j  ava 2s.  c o  m
public static SanitizedFile getApkDownloadPath(Context context, Uri uri) {
    File dir = new File(getApkCacheDir(context), uri.getHost() + "-" + uri.getPort());
    if (!dir.exists()) {
        dir.mkdirs();
    }
    return new SanitizedFile(dir, uri.getLastPathSegment());
}

From source file:com.oakesville.mythling.media.PlaybackOptions.java

public static boolean isHls(Uri videoUri) {
    String lastPathSeg = videoUri.getLastPathSegment();
    if (lastPathSeg != null) {
        int lastDot = lastPathSeg.lastIndexOf('.');
        if (lastDot > 0)
            return "m3u8".equals(lastPathSeg.substring(lastDot + 1));
    }//from   w ww. j  ava2  s  .co  m
    return false;
}

From source file:com.google.android.exoplayer.demo.player.SimplePlayer.java

/**
 * Makes a best guess to infer the type from a media {@link Uri} and an optional overriding file
 * extension./*ww  w. j a  v  a 2  s. c o m*/
 *
 * @param uri           The {@link Uri} of the media.
 * @param fileExtension An overriding file extension.
 * @return The inferred type.
 */
private static int inferContentType(Uri uri, String fileExtension) {
    String lastPathSegment = !TextUtils.isEmpty(fileExtension) ? "." + fileExtension : uri.getLastPathSegment();
    return Util.inferContentType(lastPathSegment);
}