Example usage for android.net Uri isAbsolute

List of usage examples for android.net Uri isAbsolute

Introduction

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

Prototype

public boolean isAbsolute() 

Source Link

Document

Returns true if this URI is absolute, i.e. if it contains an explicit scheme.

Usage

From source file:com.portol.common.utils.Util.java

/**
 * Merges a uri and a string to produce a new uri.
 * <p>//w w  w .j  ava 2s  . co  m
 * The uri is built according to the following rules:
 * <ul>
 * <li>If {@code baseUri} is null or if {@code stringUri} is absolute, then {@code baseUri} is
 * ignored and the uri consists solely of {@code stringUri}.
 * <li>If {@code stringUri} is null, then the uri consists solely of {@code baseUrl}.
 * <li>Otherwise, the uri consists of the concatenation of {@code baseUri} and {@code stringUri}.
 * </ul>
 *
 * @param baseUri A uri that can form the base of the merged uri.
 * @param stringUri A relative or absolute uri in string form.
 * @return The merged uri.
 */
public static Uri getMergedUri(Uri baseUri, String stringUri) {
    if (stringUri == null) {
        return baseUri;
    }
    if (baseUri == null) {
        return Uri.parse(stringUri);
    }
    if (stringUri.startsWith("/")) {
        stringUri = stringUri.substring(1);
        return new Uri.Builder().scheme(baseUri.getScheme()).authority(baseUri.getAuthority())
                .appendEncodedPath(stringUri).build();
    }
    Uri uri = Uri.parse(stringUri);
    if (uri.isAbsolute()) {
        return uri;
    }
    return Uri.withAppendedPath(baseUri, stringUri);
}

From source file:com.scvngr.levelup.core.net.AbstractRequest.java

/**
 * Returns the portion of an absolute URL before the query string. E.g.
 * {@code http://example.com/search?q=kittens} would return {@code "http://example.com/search"}.
 *
 * @param url the URL to strip./*from w w  w .j a  va  2s  .  co  m*/
 * @return the URL stripped of any query parameters, including the '?'.
 * @throws IllegalArgumentException if the URI passed in isn't an absolute URL.
 */
@NonNull
private static String stripQueryParameters(final Uri url) throws IllegalArgumentException {
    if (!url.isAbsolute() || !url.isHierarchical()) {
        throw new IllegalArgumentException("Request URI must be an absolute URL");
    }

    return NullUtils.nonNullContract(url.buildUpon().query(null).build().toString());
}

From source file:cgeo.geocaching.connector.oc.OkapiClient.java

private static String absoluteUrl(final String url, final String geocode) {
    final Uri uri = Uri.parse(url);

    if (!uri.isAbsolute()) {
        final IConnector connector = ConnectorFactory.getConnector(geocode);
        final String host = connector.getHost();
        if (StringUtils.isNotBlank(host)) {
            return "http://" + host + "/" + url;
        }//from  ww w.ja  v  a 2  s . c o m
    }
    return url;
}

From source file:com.example.androidx.media.VideoViewTest.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //Remove title bar
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.video_activity);

    mVideoView = findViewById(R.id.video_view);

    String errorString = null;/*from www  .  j a v a 2  s  . com*/
    Intent intent = getIntent();
    Uri contentUri;
    if (intent == null || (contentUri = intent.getData()) == null || !contentUri.isAbsolute()) {
        errorString = "Invalid intent";
    } else {
        mUseTextureView = intent.getBooleanExtra(USE_TEXTURE_VIEW_EXTRA_NAME, false);
        if (mUseTextureView) {
            mVideoView.setViewType(VideoView2.VIEW_TYPE_TEXTUREVIEW);
        }

        mVideoView.setFullScreenRequestListener(new FullScreenRequestListener());
        mVideoView.setVideoUri(contentUri);

        mMediaControlView = new MediaControlView2(this);
        mVideoView.setMediaControlView2(mMediaControlView, 2000);
    }
    if (errorString != null) {
        showErrorDialog(errorString);
    }
}

From source file:net.openid.appauthdemo.Configuration.java

@NonNull
Uri getRequiredConfigUri(String propName) throws InvalidConfigurationException {
    String uriStr = getRequiredConfigString(propName);
    Uri uri;
    try {//  ww w . j  av a  2  s .  c  o m
        uri = Uri.parse(uriStr);
    } catch (Throwable ex) {
        throw new InvalidConfigurationException(propName + " could not be parsed", ex);
    }

    if (!uri.isHierarchical() || !uri.isAbsolute()) {
        throw new InvalidConfigurationException(propName + " must be hierarchical and absolute");
    }

    if (!TextUtils.isEmpty(uri.getEncodedUserInfo())) {
        throw new InvalidConfigurationException(propName + " must not have user info");
    }

    if (!TextUtils.isEmpty(uri.getEncodedQuery())) {
        throw new InvalidConfigurationException(propName + " must not have query parameters");
    }

    if (!TextUtils.isEmpty(uri.getEncodedFragment())) {
        throw new InvalidConfigurationException(propName + " must not have a fragment");
    }

    return uri;
}

From source file:com.microsoft.live.ApiRequest.java

/**
 * Constructs a new instance of an ApiRequest and initializes its member variables
 *
 * @param session that contains the access_token
 * @param client to make Http Requests on
 * @param responseHandler to handle the response
 * @param path of the request. it can be relative or absolute.
 *///from   ww  w .j a  va2s  .com
public ApiRequest(LiveConnectSession session, HttpClient client, ResponseHandler<ResponseType> responseHandler,
        String path, ResponseCodes responseCodes, Redirects redirects) {
    assert session != null;
    assert client != null;
    assert responseHandler != null;
    assert !TextUtils.isEmpty(path);

    this.session = session;
    this.client = client;
    this.observers = new ArrayList<Observer>();
    this.responseHandler = responseHandler;
    this.path = path;
    this.pathUri = Uri.parse(path);

    final int queryStart = path.indexOf("?");
    final String pathWithoutQuery = path.substring(0, queryStart != -1 ? queryStart : path.length());
    final Uri uriWithoutQuery = Uri.parse(pathWithoutQuery);
    final String query;
    if (queryStart != -1) {
        query = path.substring(queryStart + 1, path.length());
    } else {
        query = "";
    }

    UriBuilder builder;

    if (uriWithoutQuery.isAbsolute()) {
        // if the path is absolute we will just use that entire path
        builder = UriBuilder.newInstance(uriWithoutQuery).query(query);
    } else {
        // if it is a relative path then we should use the config's API URI,
        // which is usually something like https://apis.live.net/v5.0
        builder = UriBuilder.newInstance(Config.INSTANCE.getApiUri())
                .appendToPath(uriWithoutQuery.getEncodedPath()).query(query);
    }

    responseCodes.setQueryParameterOn(builder);
    redirects.setQueryParameterOn(builder);

    this.requestUri = builder;
}

From source file:com.native5.plugins.ActionBarPlugin.java

private Drawable getDrawableForURI(String uri_string) {
    Uri uri = Uri.parse(uri_string);
    Activity ctx = (Activity) cordova;//w ww .j  a va2s .c  om

    // Special case - TrueType fonts
    if (uri_string.endsWith(".ttf")) {
        /*for(String base: bases)
        {
           String path = base + uri;
                   
           // TODO: Font load / glyph rendering ("/blah/fontawesome.ttf:\f1234")
        }*/
    }
    // General bitmap
    else {
        if (uri.isAbsolute()) {
            if (uri.getScheme().startsWith("http")) {
                try {
                    URL url = new URL(uri_string);
                    InputStream stream = url.openConnection().getInputStream();
                    return new BitmapDrawable(ctx.getResources(), stream);
                } catch (MalformedURLException e) {
                    return null;
                } catch (IOException e) {
                    return null;
                } catch (Exception e) {
                    return null;
                }
            } else {
                try {
                    InputStream stream = ctx.getContentResolver().openInputStream(uri);
                    return new BitmapDrawable(ctx.getResources(), stream);
                } catch (FileNotFoundException e) {
                    return null;
                }
            }
        } else {
            for (String base : bases) {
                String path = base + uri;

                // Asset
                if (base.startsWith("file:///android_asset/")) {
                    path = path.substring(22);

                    try {
                        InputStream stream = ctx.getAssets().open(path);
                        return new BitmapDrawable(ctx.getResources(), stream);
                    } catch (IOException e) {
                        continue;
                    }
                }
                // General URI
                else {
                    try {
                        InputStream stream = ctx.getContentResolver().openInputStream(Uri.parse(path));
                        return new BitmapDrawable(ctx.getResources(), stream);
                    } catch (FileNotFoundException e) {
                        continue;
                    }
                }
            }
        }
    }

    return null;
}

From source file:com.polychrom.cordova.actionbar.ActionBarSherlock.java

private Drawable getDrawableForURI(String uri_string) {
    Uri uri = Uri.parse(uri_string);
    Context ctx = ((SherlockActivity) cordova);

    // Special case - TrueType fonts
    if (uri_string.endsWith(".ttf")) {
        /*for(String base: bases)
        {/*w  w  w  .ja v a 2 s  . c  o m*/
           String path = base + uri;
                
           // TODO: Font load / glyph rendering ("/blah/fontawesome.ttf:\f1234")
        }*/
    } else if (uri_string.startsWith("R.drawable")) {
        String[] array = uri_string.split("\\.");
        String name = array[2];
        int resourceId = ctx.getResources().getIdentifier(name, "drawable", ctx.getPackageName());
        Drawable drawable = ctx.getResources().getDrawable(resourceId);
        return drawable;
    }
    // General bitmap
    else {
        if (uri.isAbsolute()) {
            if (uri.getScheme().startsWith("http")) {
                try {
                    URL url = new URL(uri_string);
                    InputStream stream = url.openConnection().getInputStream();
                    return new BitmapDrawable(ctx.getResources(), stream);
                } catch (MalformedURLException e) {
                    return null;
                } catch (IOException e) {
                    return null;
                } catch (Exception e) {
                    return null;
                }
            } else {
                try {
                    InputStream stream = ctx.getContentResolver().openInputStream(uri);
                    return new BitmapDrawable(ctx.getResources(), stream);
                } catch (FileNotFoundException e) {
                    return null;
                }
            }
        } else {
            for (String base : bases) {
                String path = base + uri;

                // Asset
                if (base.startsWith("file:///android_asset/")) {
                    path = path.substring(22);

                    try {
                        InputStream stream = ctx.getAssets().open(path);
                        return new BitmapDrawable(ctx.getResources(), stream);
                    } catch (IOException e) {
                        continue;
                    }
                }
                // General URI
                else {
                    try {
                        InputStream stream = ctx.getContentResolver().openInputStream(Uri.parse(path));
                        return new BitmapDrawable(ctx.getResources(), stream);
                    } catch (FileNotFoundException e) {
                        continue;
                    }
                }
            }
        }
    }

    return null;
}