Example usage for android.net Uri getHost

List of usage examples for android.net Uri getHost

Introduction

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

Prototype

@Nullable
public abstract String getHost();

Source Link

Document

Gets the encoded host from the authority for this URI.

Usage

From source file:eu.e43.impeller.Utils.java

public static String getProxyUrl(Context ctx, Account acct, JSONObject obj) {
    if (obj.has("pump_io")) {
        JSONObject pump_io = obj.optJSONObject("pump_io");
        String url = pump_io.optString("proxyURL", null);

        // If the hosts mismatch between the proxyURL and the Account ID, assume we have a
        // "leakage" issue
        Uri uri = Uri.parse(url);
        Uri userUri = Uri.parse(AccountManager.get(ctx).getUserData(acct, "id"));
        if (!uri.getHost().equalsIgnoreCase(userUri.getHost())) {
            Log.w("Utils.getProxyUrl",
                    "Discarding proxyURL " + url + " due to host mismatch with user " + userUri.toString());
            return null;
        }//from   w ww.java  2 s. c o  m

        if (url == null || url.length() == 0)
            return null;
        return url;
    } else
        return null;
}

From source file:com.androidzeitgeist.dashwatch.common.IOUtil.java

public static String getCacheFilenameForUri(Uri uri) {
    StringBuilder filename = new StringBuilder();
    filename.append(uri.getScheme()).append("_").append(uri.getHost()).append("_");
    String encodedPath = uri.getEncodedPath();
    if (!TextUtils.isEmpty(encodedPath)) {
        int length = encodedPath.length();
        if (length > 60) {
            encodedPath = encodedPath.substring(length - 60);
        }//from   w  w  w.  j ava2s.com
        encodedPath = encodedPath.replace('/', '_');
        filename.append(encodedPath).append("_");
    }
    try {
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(uri.toString().getBytes("UTF-8"));
        byte[] digest = md.digest();
        for (byte b : digest) {
            if ((0xff & b) < 0x10) {
                filename.append("0").append(Integer.toHexString((0xFF & b)));
            } else {
                filename.append(Integer.toHexString(0xFF & b));
            }
        }
    } catch (NoSuchAlgorithmException e) {
        filename.append(uri.toString().hashCode());
    } catch (UnsupportedEncodingException e) {
        filename.append(uri.toString().hashCode());
    }

    return filename.toString();
}

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;
        }/*w  ww . j  av a  2s.  c om*/
        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:com.gdgdevfest.android.apps.devfestbcn.ui.PlusStreamRowViewBinder.java

public static void bindActivityView(final View rootView, Activity activity, ImageLoader imageLoader,
        boolean singleSourceMode) {
    // Prepare view holder.
    ViewHolder tempViews = (ViewHolder) rootView.getTag();
    final ViewHolder views;
    if (tempViews != null) {
        views = tempViews;//from w  w w .j  a  va2s .c  o  m
    } else {
        views = new ViewHolder();
        rootView.setTag(views);

        // Author and metadata box
        views.authorContainer = rootView.findViewById(R.id.stream_author_container);
        views.userImage = (ImageView) rootView.findViewById(R.id.stream_user_image);
        views.userName = (TextView) rootView.findViewById(R.id.stream_user_name);
        views.time = (TextView) rootView.findViewById(R.id.stream_time);

        // Author's content
        views.content = (TextView) rootView.findViewById(R.id.stream_content);

        // Original share box
        views.originalContainer = rootView.findViewById(R.id.stream_original_container);
        views.originalAuthor = (TextView) rootView.findViewById(R.id.stream_original_author);
        views.originalContent = (TextView) rootView.findViewById(R.id.stream_original_content);

        // Media box
        views.mediaContainer = rootView.findViewById(R.id.stream_media_container);
        views.mediaBackground = (ImageView) rootView.findViewById(R.id.stream_media_background);
        views.mediaOverlay = (ImageView) rootView.findViewById(R.id.stream_media_overlay);
        views.mediaTitle = (TextView) rootView.findViewById(R.id.stream_media_title);
        views.mediaSubtitle = (TextView) rootView.findViewById(R.id.stream_media_subtitle);

        // Interactions box
        views.interactionsContainer = rootView.findViewById(R.id.stream_interactions_container);
        views.plusOnes = (TextView) rootView.findViewById(R.id.stream_plus_ones);
        views.shares = (TextView) rootView.findViewById(R.id.stream_shares);
        views.comments = (TextView) rootView.findViewById(R.id.stream_comments);
    }

    final Context context = rootView.getContext();
    final Resources res = context.getResources();

    // Determine if this is a reshare (affects how activity fields are to be interpreted).
    Activity.PlusObject.Actor originalAuthor = activity.getObject().getActor();
    boolean isReshare = "share".equals(activity.getVerb()) && originalAuthor != null;

    // Author and metadata box
    views.authorContainer.setVisibility(singleSourceMode ? View.GONE : View.VISIBLE);
    views.userName.setText(activity.getActor().getDisplayName());

    // Find user profile image url
    String userImageUrl = null;
    if (activity.getActor().getImage() != null) {
        userImageUrl = activity.getActor().getImage().getUrl();
    }

    // Load image from network in background thread using Volley library
    imageLoader.get(userImageUrl, views.userImage, PLACEHOLDER_USER_IMAGE);

    long thenUTC = activity.getUpdated().getValue() + activity.getUpdated().getTimeZoneShift() * 60000;
    views.time.setText(DateUtils.getRelativeTimeSpanString(thenUTC, System.currentTimeMillis(),
            DateUtils.SECOND_IN_MILLIS, DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_ABBREV_RELATIVE));

    // Author's additional content
    String selfContent = isReshare ? activity.getAnnotation() : activity.getObject().getContent();
    views.content.setMaxLines(singleSourceMode ? 1000 : 5);
    if (!TextUtils.isEmpty(selfContent)) {
        views.content.setVisibility(View.VISIBLE);
        views.content.setText(Html.fromHtml(selfContent));
    } else {
        views.content.setVisibility(View.GONE);
    }

    // Original share box
    if (isReshare) {
        views.originalContainer.setVisibility(View.VISIBLE);

        // Set original author text, highlight author name
        final String author = res.getString(R.string.stream_originally_shared, originalAuthor.getDisplayName());
        final SpannableStringBuilder spannableAuthor = new SpannableStringBuilder(author);
        spannableAuthor.setSpan(new StyleSpan(Typeface.BOLD),
                author.length() - originalAuthor.getDisplayName().length(), author.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        views.originalAuthor.setText(spannableAuthor, TextView.BufferType.SPANNABLE);

        String originalContent = activity.getObject().getContent();
        views.originalContent.setMaxLines(singleSourceMode ? 1000 : 3);
        if (!TextUtils.isEmpty(originalContent)) {
            views.originalContent.setVisibility(View.VISIBLE);
            views.originalContent.setText(Html.fromHtml(originalContent));
        } else {
            views.originalContent.setVisibility(View.GONE);
        }
    } else {
        views.originalContainer.setVisibility(View.GONE);
    }

    // Media box

    // Set media content.
    List<Activity.PlusObject.Attachments> attachments = activity.getObject().getAttachments();
    if (attachments != null && attachments.size() > 0) {
        Activity.PlusObject.Attachments attachment = attachments.get(0);
        String objectType = attachment.getObjectType();
        String imageUrl = attachment.getImage() != null ? attachment.getImage().getUrl() : null;
        if (imageUrl == null && attachment.getThumbnails() != null && attachment.getThumbnails().size() > 0) {
            Thumbnails thumb = attachment.getThumbnails().get(0);
            imageUrl = thumb.getImage() != null ? thumb.getImage().getUrl() : null;
        }

        // Load image from network in background thread using Volley library
        imageLoader.get(imageUrl, views.mediaBackground, PLACEHOLDER_MEDIA_IMAGE);

        boolean overlayStyle = false;

        views.mediaOverlay.setImageDrawable(null);
        if (("photo".equals(objectType) || "video".equals(objectType) || "album".equals(objectType))
                && !TextUtils.isEmpty(imageUrl)) {
            overlayStyle = true;
            views.mediaOverlay
                    .setImageResource("video".equals(objectType) ? R.drawable.ic_stream_media_overlay_video
                            : R.drawable.ic_stream_media_overlay_photo);

        } else if ("article".equals(objectType) || "event".equals(objectType)) {
            overlayStyle = false;
            views.mediaTitle.setText(attachment.getDisplayName());
            if (!TextUtils.isEmpty(attachment.getUrl())) {
                Uri uri = Uri.parse(attachment.getUrl());
                views.mediaSubtitle.setText(uri.getHost());
            } else {
                views.mediaSubtitle.setText("");
            }
        }

        views.mediaContainer.setVisibility(View.VISIBLE);
        views.mediaContainer.setBackgroundResource(
                overlayStyle ? R.color.plus_stream_media_background : android.R.color.black);
        if (overlayStyle) {
            views.mediaBackground.clearColorFilter();
        } else {
            views.mediaBackground.setColorFilter(res.getColor(R.color.plus_media_item_tint));
        }
        views.mediaOverlay.setVisibility(overlayStyle ? View.VISIBLE : View.GONE);
        views.mediaTitle.setVisibility(overlayStyle ? View.GONE : View.VISIBLE);
        views.mediaSubtitle.setVisibility(overlayStyle ? View.GONE : View.VISIBLE);
    } else {
        views.mediaContainer.setVisibility(View.GONE);
        views.mediaBackground.setImageDrawable(null);
        views.mediaOverlay.setImageDrawable(null);
    }

    // Interactions box
    final int plusOneCount = (activity.getObject().getPlusoners() != null)
            ? activity.getObject().getPlusoners().getTotalItems().intValue()
            : 0;
    if (plusOneCount > 0) {
        views.plusOnes.setVisibility(View.VISIBLE);
        views.plusOnes.setText(getPlusOneString(plusOneCount));
    } else {
        views.plusOnes.setVisibility(View.GONE);
    }

    final int commentCount = (activity.getObject().getReplies() != null)
            ? activity.getObject().getReplies().getTotalItems().intValue()
            : 0;
    if (commentCount > 0) {
        views.comments.setVisibility(View.VISIBLE);
        views.comments.setText(Integer.toString(commentCount));
    } else {
        views.comments.setVisibility(View.GONE);
    }

    final int resharerCount = (activity.getObject().getResharers() != null)
            ? activity.getObject().getResharers().getTotalItems().intValue()
            : 0;
    if (resharerCount > 0) {
        views.shares.setVisibility(View.VISIBLE);
        views.shares.setText(Integer.toString(resharerCount));
    } else {
        views.shares.setVisibility(View.GONE);
    }

    views.interactionsContainer.setVisibility(
            (plusOneCount > 0 || commentCount > 0 || resharerCount > 0) ? View.VISIBLE : View.GONE);
}

From source file:com.andrewshu.android.reddit.common.util.Util.java

public static boolean isRedditUri(Uri uri) {
    if (uri == null)
        return false;
    String host = uri.getHost();
    return host != null && (host.equals("reddit.com") || host.endsWith(".reddit.com"));
}

From source file:com.andrewshu.android.reddit.common.util.Util.java

public static boolean isRedditShortenedUri(Uri uri) {
    if (uri == null)
        return false;
    String host = uri.getHost();
    return host != null && host.equals("redd.it");
}

From source file:com.andrewshu.android.reddit.common.util.Util.java

public static boolean isYoutubeUri(Uri uri) {
    if (uri == null)
        return false;
    String host = uri.getHost();
    return host != null && (host.endsWith(".youtube.com") || host.equals("youtu.be"));
}

From source file:com.andrewshu.android.reddit.common.util.Util.java

public static boolean isAndroidMarketUri(Uri uri) {
    if (uri == null)
        return false;
    String host = uri.getHost();
    return host != null && host.equals("market.android.com");
}

From source file:com.andrewshu.android.reddit.common.util.Util.java

/**
 * @return if uri points to a non-mobile wikpedia uri.
 *//*  ww w .j ava 2 s. c om*/
static boolean isNonMobileWikipediaUri(Uri uri) {
    if (uri == null)
        return false;
    String host = uri.getHost();
    return host != null && host.endsWith(".wikipedia.org") && !host.contains(".m.wikipedia.org");
}

From source file:org.fdroid.fdroid.net.DownloaderService.java

/**
 * Get a prepared {@link IntentFilter} for use for matching this service's action events.
 *
 * @param urlString The full file URL to match.
 * @param action    {@link Downloader#ACTION_STARTED}, {@link Downloader#ACTION_PROGRESS},
 *                  {@link Downloader#ACTION_INTERRUPTED}, or {@link Downloader#ACTION_COMPLETE},
 * @return//from  w  w  w  . j  a  v  a 2  s.c  om
 */
public static IntentFilter getIntentFilter(String urlString, String action) {
    Uri uri = Uri.parse(urlString);
    IntentFilter intentFilter = new IntentFilter(action);
    intentFilter.addDataScheme(uri.getScheme());
    intentFilter.addDataAuthority(uri.getHost(), String.valueOf(uri.getPort()));
    intentFilter.addDataPath(uri.getPath(), PatternMatcher.PATTERN_LITERAL);
    return intentFilter;
}