Example usage for android.net Uri getPathSegments

List of usage examples for android.net Uri getPathSegments

Introduction

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

Prototype

public abstract List<String> getPathSegments();

Source Link

Document

Gets the decoded path segments.

Usage

From source file:Main.java

public static String getGfycatId(String in) {

    Uri uri = Uri.parse(in);

    final String host = uri.getHost();

    if (TextUtils.isEmpty(host) == false && host.endsWith("gfycat.com") == true) {
        List<String> paths = uri.getPathSegments();
        if (paths.size() == 1) {
            return paths.get(0);
        } else if (paths.size() == 2) {
            return paths.get(1);
        }/* ww w .  j  av  a 2 s  . c  om*/
    }

    return null;
}

From source file:dev.nick.app.screencast.camera.MediaScratchFileProvider.java

public static boolean isMediaScratchSpaceUri(final Uri uri) {
    if (uri == null) {
        return false;
    }//  w  ww .j  a  va 2  s.  co m

    final List<String> segments = uri.getPathSegments();
    return (TextUtils.equals(uri.getScheme(), ContentResolver.SCHEME_CONTENT)
            && TextUtils.equals(uri.getAuthority(), AUTHORITY) && segments.size() == 1
            && isValidFileId(segments.get(0)));
}

From source file:com.android.messaging.datamodel.MediaScratchFileProvider.java

public static boolean isMediaScratchSpaceUri(final Uri uri) {
    if (uri == null) {
        return false;
    }/*  w ww  .ja  va 2  s.co  m*/

    final List<String> segments = uri.getPathSegments();
    return (TextUtils.equals(uri.getScheme(), ContentResolver.SCHEME_CONTENT)
            && TextUtils.equals(uri.getAuthority(), AUTHORITY) && segments.size() == 1
            && FileProvider.isValidFileId(segments.get(0)));
}

From source file:com.frostwire.android.gui.StoragePicker.java

/**
 * Extract the via {@link Document#COLUMN_DOCUMENT_ID} from the given URI.
 *//*  w w  w. j  a v  a2s. co m*/
public static String getTreeDocumentId(Uri documentUri) {
    final List<String> paths = documentUri.getPathSegments();
    if (paths.size() >= 2 && PATH_TREE.equals(paths.get(0))) {
        return paths.get(1);
    }
    throw new IllegalArgumentException("Invalid URI: " + documentUri);
}

From source file:com.tonyodev.fetch.request.Request.java

private static String generateFilePath(String parentDir, String fileName) {

    Uri uri = Uri.parse(fileName);

    if (uri.getPathSegments().size() == 1) {
        return parentDir + "/" + fileName;
    }//from w  w w .j  av a  2s.c om

    return fileName;
}

From source file:com.taobao.weex.utils.ImgURIUtil.java

public static Drawable getDrawableFromLoaclSrc(Context context, Uri rewrited) {
    Resources resources = context.getResources();
    List<String> segments = rewrited.getPathSegments();
    if (segments.size() != 1) {
        WXLogUtils.e("Local src format is invalid.");
        return null;
    }//from   w  ww . java2  s .  c  o  m
    int id = resources.getIdentifier(segments.get(0), "drawable", context.getPackageName());
    return id == 0 ? null : ResourcesCompat.getDrawable(resources, id, null);
}

From source file:Main.java

/**
 * Return the position of the host in MASK_HOSTS, or -1 if it isn't a known URL masker
 *///www.j a  v a 2s.c o  m
public static int getMaskedId(Uri uri) {
    String host = uri.getHost();
    for (int i = 0; i < MASK_HOSTS.length; i++) {
        if (host.endsWith(MASK_HOSTS[i])) {
            if (MASK_HOSTS_SEG[i] == null) {
                return i;
            } else {
                List pathSegments = uri.getPathSegments();
                if (pathSegments == null)
                    return -1;
                if (pathSegments.size() > 0 && MASK_HOSTS_SEG[i].equals(pathSegments.get(0)))
                    return i;
            }
        }
    }
    return -1;
}

From source file:org.coocood.vcontentprovider.VContentProvider.java

private static String getTableName(Uri uri) {
    List<String> paths = uri.getPathSegments();
    if (paths == null || paths.size() == 0)
        throw new IllegalArgumentException("Unknown URI " + uri);
    String tableName = paths.get(0);
    if (tableMap.keySet().contains(tableName) || viewTablesMap.keySet().contains(tableName)) {
        return tableName;
    } else {//from   w w  w .ja  v  a2  s .c om
        throw new IllegalArgumentException("Unknown URI " + uri);
    }
}

From source file:org.mobiledeeplinking.android.DeeplinkMatcher.java

static Map<String, String> matchPathParameters(String route, JSONObject routeOptions, Uri deeplink,
        Map<String, String> results) {
    List<String> routeComponents = new LinkedList<String>(Arrays.asList(route.split("/")));
    List<String> deeplinkComponents = new LinkedList<String>(deeplink.getPathSegments());

    if (!route.startsWith("/")) {
        String host = deeplink.getHost();
        if (!routeComponents.get(0).equals(host)) {
            return null;
        }//from   w w  w .  j  a  v a  2s .  co  m
        routeComponents.remove(0);
    }

    if (routeComponents.size() != deeplinkComponents.size()) {
        return null;
    }

    String routeComponent;
    String deeplinkComponent;

    for (int i = 0; i < routeComponents.size(); i++) {
        routeComponent = routeComponents.get(i);
        deeplinkComponent = deeplinkComponents.get(i);
        if (!routeComponent.equals(deeplinkComponent)) {
            if (routeComponent.startsWith(":")) {
                String routeComponentName = routeComponent.substring(1);
                if (validateRouteComponent(routeComponentName, deeplinkComponent, routeOptions)) {
                    results.put(routeComponentName, deeplinkComponent);
                } else {
                    return null;
                }
            } else {
                return null;
            }
        }

    }

    return results;
}

From source file:Main.java

/**
 * Unmask the URI and return it// w w  w  . j a  v  a 2  s. co m
 */
public static Uri unmaskLink(Uri uri, int i) {
    String s = null;
    List pathSegments;
    if (MASK_HOSTS_SEG[i] == null) {
        // The host always masks, no need to determine if it's the right segment
        s = uri.getQueryParameter(MASK_HOSTS_PAR[i]);
    } else {
        // Only a certain segment is used to mask URLs. Determine if this is it.
        pathSegments = uri.getPathSegments();
        if (pathSegments == null)
            return uri;
        // If it is, unmask the URL.
        if (pathSegments.size() > 0 && MASK_HOSTS_SEG[i].equals(pathSegments.get(0)))
            s = uri.getQueryParameter(MASK_HOSTS_PAR[i]);
    }

    if (s == null)
        return uri;

    // Resolve link if it's relative
    try {
        if (!new URI(s).isAbsolute())
            s = new URI(uri.toString()).resolve(s).toString();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    try {
        return Uri.parse(URLDecoder.decode(s, "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        return uri;
    }
}