Example usage for android.util Patterns WEB_URL

List of usage examples for android.util Patterns WEB_URL

Introduction

In this page you can find the example usage for android.util Patterns WEB_URL.

Prototype

Pattern WEB_URL

To view the source code for android.util Patterns WEB_URL.

Click Source Link

Document

Regular expression pattern to match most part of RFC 3987 Internationalized URLs, aka IRIs.

Usage

From source file:Main.java

public final static boolean isValidUrl(CharSequence target) {
    return !TextUtils.isEmpty(target) && Patterns.WEB_URL.matcher(target).matches();
}

From source file:Main.java

public final static boolean isValidURL(String url) {
    if (url == null) {
        return false;
    } else {/*  w  w  w .jav a  2  s. c  o m*/
        return Patterns.WEB_URL.matcher(url).matches();
    }
}

From source file:Main.java

public static String firstUrl(String text) {
    if (!TextUtils.isEmpty(text))
        for (String s : text.split("\\s+"))
            if (Patterns.WEB_URL.matcher(s).matches())
                return s;
    return null;//from ww  w  . j a va 2s .c  om
}

From source file:Main.java

/**
 * Validate a web url/* w w  w  .  j a va 2 s.c  o  m*/
 * @param webUrl web url to validate
 * @return return true if url is valid otherwise false
 */
@TargetApi(Build.VERSION_CODES.FROYO)
public static boolean validateWebURLAsPerAndroid(String webUrl) {
    final Pattern pattern = Patterns.WEB_URL;
    return pattern.matcher(webUrl).matches();
}

From source file:Main.java

public static List<String> extractUrl(String text) {
    List<String> urls = new ArrayList<>();
    Matcher matcher = Patterns.WEB_URL.matcher(text);
    while (matcher.find()) {
        int start = matcher.start();
        if (start > 0 && text.charAt(start - 1) == '@') {
            continue;
        }//from w  w w  .j av a  2s .  c o  m
        String url = matcher.group();
        if (!url.startsWith("http")) {
            url = "http://" + url;
        }
        urls.add(url);
    }
    return urls;
}

From source file:Main.java

public static boolean isUrl(String s) {
    return Patterns.WEB_URL.matcher(s).matches();
}

From source file:Main.java

/**
 * Validate an URL with pattern/* www.j  av  a2 s .c  o  m*/
 * http://developer.android.com/reference/android/util/Patterns.html#WEB_URL
 * or #IP_ADDRESS
 * 
 * @param url The URL to validate
 * @return true if the URL matches the pattern, false otherwise
 */
public static boolean isUrlValid(String url) {
    return (url == null) ? false
            : (Patterns.WEB_URL.matcher(url).matches() || Patterns.IP_ADDRESS.matcher(url).matches());
}

From source file:com.google.samples.apps.iosched.nearby.MetadataResolver.java

public static String getURLForDevice(NearbyDevice device) {
    if (!mIsInitialized) {
        Log.e(TAG, "Not initialized.");
        return null;
    }//from   w  w w  .  ja  va  2 s  .c o m

    // If the device name is already a URL, use it.
    String deviceName = device.getName();
    String url = deviceName;
    if (Patterns.WEB_URL.matcher(deviceName).matches()) {
        // TODO: Improve this.
        // For now, if there's no scheme present, add a default http:// scheme.
        if (!url.startsWith("http://") && !url.startsWith("https://")) {
            url = "http://" + url;
        }
    } else {
        // Otherwise, try doing the lookup.
        url = mDeviceUrlMap.get(deviceName);
    }
    return url;
}

From source file:com.google.android.apps.gutenberg.LicensesFragment.java

@NonNull
@Override// w w w  . j av a2  s  . c  o m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    WebView webView = new WebView(getActivity());
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (!TextUtils.isEmpty(url) && Patterns.WEB_URL.matcher(url).matches()) {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                return true;
            } else {
                return false;
            }
        }
    });
    webView.loadUrl("file:///android_asset/licenses.html");
    return new AlertDialog.Builder(getActivity()).setTitle(R.string.licenses).setView(webView)
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.dismiss();
                }
            }).create();
}

From source file:com.schedjoules.eventdiscovery.framework.utils.linkify.HttpUrlLinkified.java

public HttpUrlLinkified(final Spannable input) {
    super(new com.schedjoules.eventdiscovery.framework.utils.factory.Factory<Spannable>() {
        @Override//from  w  ww  . ja va  2s  . c  o m
        public Spannable create() {
            LinkifyCompat.addLinks(input, Patterns.WEB_URL, null, MATCH_FILTER, TRANSFORM_FILTER);
            return input;
        }
    });
}