Java Code Examples for android.net.Uri#getEncodedFragment()

The following examples show how to use android.net.Uri#getEncodedFragment() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PrettifyWebView.java    From mvvm-template with GNU General Public License v3.0 5 votes vote down vote up
public static String[] getLineNo(@Nullable String url) {
    String lineNo[] = null;
    if (url != null) {
        try {
            Uri uri = Uri.parse(url);
            String lineNumber = uri.getEncodedFragment();
            if (lineNumber != null) {
                lineNo = lineNumber.replaceAll("L", "").split("-");
            }
        } catch (Exception ignored) {}
    }
    return lineNo;
}
 
Example 2
Source File: LinkParserHelper.java    From mvvm-template with GNU General Public License v3.0 5 votes vote down vote up
@NonNull static Uri getBlobBuilder(@NonNull Uri uri) {
    boolean isSvg = "svg".equalsIgnoreCase(MimeTypeMap.getFileExtensionFromUrl(uri.toString()));
    List<String> segments = uri.getPathSegments();
    if (isSvg) {
        Uri svgBlob = Uri.parse(uri.toString().replace("blob/", ""));
        return svgBlob.buildUpon().authority(RAW_AUTHORITY).build();
    }
    Uri.Builder urlBuilder = new Uri.Builder();
    String owner = segments.get(0);
    String repo = segments.get(1);
    String branch = segments.get(3);
    urlBuilder.scheme("https")
            .authority(API_AUTHORITY)
            .appendPath("repos")
            .appendPath(owner)
            .appendPath(repo)
            .appendPath("contents");
    for (int i = 4; i < segments.size(); i++) {
        urlBuilder.appendPath(segments.get(i));
    }
    if (uri.getQueryParameterNames() != null) {
        for (String query : uri.getQueryParameterNames()) {
            urlBuilder.appendQueryParameter(query, uri.getQueryParameter(query));
        }
    }
    if (uri.getEncodedFragment() != null) {
        urlBuilder.encodedFragment(uri.getEncodedFragment());
    }
    urlBuilder.appendQueryParameter("ref", branch);
    return urlBuilder.build();
}
 
Example 3
Source File: ShuttleProvider.java    From island with Apache License 2.0 5 votes vote down vote up
private static Uri replaceAuthorityInUri(final Uri uri, final String authority) {
	final Uri.Builder builder = new Uri.Builder().scheme(uri.getScheme()).authority(authority).encodedPath(uri.getEncodedPath());
	final String query = uri.getEncodedQuery();
	if (query != null) builder.encodedQuery(query);
	final String fragment = uri.getEncodedFragment();
	if (fragment != null) builder.encodedFragment(fragment);
	return builder.build();
}
 
Example 4
Source File: ExternalStorageProviderProxy.java    From island with Apache License 2.0 5 votes vote down vote up
private static Uri replaceAuthorityInUri(final Uri uri, final String authority) {
	final Uri.Builder builder = new Uri.Builder().scheme(uri.getScheme()).authority(authority).encodedPath(uri.getEncodedPath());
	final String query = uri.getEncodedQuery();
	if (query != null) builder.encodedQuery(query);
	final String fragment = uri.getEncodedFragment();
	if (fragment != null) builder.encodedFragment(fragment);
	return builder.build();
}
 
Example 5
Source File: SchemeParser.java    From mvvm-template with GNU General Public License v3.0 4 votes vote down vote up
@Nullable private static Intent getPullRequestIntent(@NonNull Context context, @NonNull Uri uri, boolean showRepoBtn) {
        List<String> segments = uri.getPathSegments();
        if (segments == null || segments.size() < 3) return null;
        String owner = null;
        String repo = null;
        String number = null;
        String fragment = uri.getEncodedFragment();//#issuecomment-332236665
        Long commentId = null;
        if (!InputHelper.isEmpty(fragment) && fragment.split("-").length > 1) {
            fragment = fragment.split("-")[1];
            if (!InputHelper.isEmpty(fragment)) {
                try {
                    commentId = Long.parseLong(fragment);
                } catch (Exception ignored) {}
            }
        }
        if (segments.size() > 3) {
            if (("pull".equals(segments.get(2)) || "pulls".equals(segments.get(2)))) {
                owner = segments.get(0);
                repo = segments.get(1);
                number = segments.get(3);
            } else if (("pull".equals(segments.get(3)) || "pulls".equals(segments.get(3))) && segments.size() > 4) {
                owner = segments.get(1);
                repo = segments.get(2);
                number = segments.get(4);
            } else {
                return null;
            }
        }
        if (InputHelper.isEmpty(number)) return null;
        int issueNumber;
        try {
            issueNumber = Integer.parseInt(number);
        } catch (NumberFormatException nfe) {
            return null;
        }
        if (issueNumber < 1) return null;
        return null; // TODO: 10/30/17 return PullRequest activity
//        return PullRequestPagerActivity.createIntent(context, repo, owner, issueNumber, showRepoBtn,
//                LinkParserHelper.isEnterprise(uri.toString()), commentId == null ? 0 : commentId);
    }
 
Example 6
Source File: SchemeParser.java    From mvvm-template with GNU General Public License v3.0 4 votes vote down vote up
@Nullable private static Intent getIssueIntent(@NonNull Context context, @NonNull Uri uri, boolean showRepoBtn) {
        List<String> segments = uri.getPathSegments();
        if (segments == null || segments.size() < 3) return null;
        String owner = null;
        String repo = null;
        String number = null;
        String fragment = uri.getEncodedFragment();//#issuecomment-332236665
        Long commentId = null;
        if (!InputHelper.isEmpty(fragment) && fragment.split("-").length > 1) {
            fragment = fragment.split("-")[1];
            if (!InputHelper.isEmpty(fragment)) {
                try {
                    commentId = Long.parseLong(fragment);
                } catch (Exception ignored) {}
            }
        }
        if (segments.size() > 3) {
            if (segments.get(2).equalsIgnoreCase("issues")) {
                owner = segments.get(0);
                repo = segments.get(1);
                number = segments.get(3);
            } else if (segments.get(3).equalsIgnoreCase("issues") && segments.size() > 4) {
                owner = segments.get(1);
                repo = segments.get(2);
                number = segments.get(4);
            } else {
                return null;
            }
        }
        if (InputHelper.isEmpty(number))
            return null;
        int issueNumber;
        try {
            issueNumber = Integer.parseInt(number);
        } catch (NumberFormatException nfe) {
            return null;
        }
        if (issueNumber < 1) return null;
        Logger.e(commentId);
        return null; // TODO: 10/30/17 return issue pager activity
//        return IssuePagerActivity.createIntent(context, repo, owner, issueNumber, showRepoBtn,
//                LinkParserHelper.isEnterprise(uri.toString()), commentId == null ? 0 : commentId);
    }
 
Example 7
Source File: AuthenticatorActivity.java    From android-java-connect-rest-sample with MIT License 4 votes vote down vote up
/**
 * Tries to handle errors on the given URI. Authorization errors are handled when the URI
 * contains a "error" parameter.
 *
 * @param uri URI to handle.
 * @return Whether the URI had an error to handle.
 */
private boolean handleAuthorizationErrors(String uri){
    Uri parsedUri = Uri.parse(uri);

    Set<String> parameterNames;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        parameterNames = CompatUri.getQueryParameterNames(parsedUri);
    } else {
        parameterNames = parsedUri.getQueryParameterNames();
    }

    // We need to check if the error is not in the fragment (for Implicit/Hybrid Flow)
    if (parameterNames.isEmpty()) {
        String extractedFragment = parsedUri.getEncodedFragment();
        if (!TextUtils.isEmpty(extractedFragment)) {
            parsedUri = new Uri.Builder().encodedQuery(extractedFragment).build();
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
                parameterNames = CompatUri.getQueryParameterNames(parsedUri);
            }
            else {
                parameterNames = parsedUri.getQueryParameterNames();
            }
        }
    }


    if (parameterNames.contains("error")) {
        // In case of an error, the `error` parameter contains an ASCII identifier, e.g.
        // "temporarily_unavailable" and the `error_description` *may* contain a
        // human-readable description of the error.
        //
        // For a list of the error identifiers, see
        // http://tools.ietf.org/html/rfc6749#section-4.1.2.1
        String error = parsedUri.getQueryParameter("error");
        String errorDescription = parsedUri.getQueryParameter("error_description");

        // If the user declines to authorise the app, there's no need to show an error message.
        if (error.equals("access_denied")) {
            Log.i(TAG, String.format("User declines to authorise the app : %s", errorDescription));
        }
        else {
            showErrorDialog("Error code: %s\n\n%s", error, errorDescription);
        }

        return true;
    }
    else {
        return false;
    }
}