Example usage for android.webkit URLUtil isValidUrl

List of usage examples for android.webkit URLUtil isValidUrl

Introduction

In this page you can find the example usage for android.webkit URLUtil isValidUrl.

Prototype

public static boolean isValidUrl(String url) 

Source Link

Usage

From source file:Main.java

public static boolean isVaildUrl(String url) {
    if (url == null || url.trim().equals("")) {
        return false;
    }/*from  ww w.j  a va 2s .  c om*/
    return URLUtil.isValidUrl(url.trim());
}

From source file:Main.java

public static void startURLActivity(Activity context, String strURL) {

    if (strURL == null)
        return;/*ww  w  . j a v a 2  s  . c  o  m*/

    if (URLUtil.isValidUrl(strURL) == false)
        return;

    Uri url = Uri.parse(strURL);

    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(url);
    context.startActivity(i);
}

From source file:Main.java

/**
 * Just a wrapper//ww  w  . j  a v  a2s .  c o  m
 *
 * @param input
 * @return
 */
static public boolean isValidUrl(String input) {
    return URLUtil.isValidUrl(input);
}

From source file:de.dala.simplenews.utilities.UIUtils.java

public static boolean isValideUrl(String url) {
    return URLUtil.isValidUrl(url);
}

From source file:self.philbrown.droidQuery.AsyncImageGetter.java

/**
 * Gets the drawable from the given URL resource, or from the local file path.
 * @param source the URL of the drawable, or the local file path to the image.
 *//*  w w  w . j  ava 2s.  c o m*/
public Drawable getDrawable(String source) {

    if (URLUtil.isValidUrl(source)) {
        //need to download image
        URLDrawable urlDrawable = new URLDrawable();

        // get the actual source
        ImageGetterAsyncTask asyncTask = new ImageGetterAsyncTask(urlDrawable);

        asyncTask.execute(source);

        // return reference to URLDrawable where I will change with actual image from
        // the src tag
        return urlDrawable;
    } else {
        //must be a local reference
        Drawable drawFromPath;
        int path = c.getResources().getIdentifier(source, "drawable", c.getApplicationInfo().packageName);
        if (path == 0) {
            return new TextDrawable("Could not set image");
        }
        drawFromPath = (Drawable) c.getResources().getDrawable(path);
        drawFromPath.setBounds(0, 0, drawFromPath.getIntrinsicWidth(), drawFromPath.getIntrinsicHeight());
        return drawFromPath;
    }

}

From source file:org.mariotaku.twidere.util.StatusActionModeCallback.java

@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
    final int start = textView.getSelectionStart(), end = textView.getSelectionEnd();
    final SpannableString string = SpannableString.valueOf(textView.getText());
    final URLSpan[] spans = string.getSpans(start, end, URLSpan.class);
    final boolean avail = spans.length == 1 && URLUtil.isValidUrl(spans[0].getURL());
    MenuUtils.setMenuItemAvailability(menu, android.R.id.copyUrl, avail);
    MenuUtils.setMenuItemShowAsActionFlags(menu, android.R.id.copyUrl, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
    return true;/* ww  w . j a v  a2 s .  c om*/
}

From source file:com.tfc.webviewer.presenter.WebViewPresenterImpl.java

@Override
public void validateUrl(final String url) {
    if (URLUtil.isValidUrl(url)) {
        mView.loadUrl(url);/*  ww w  .  j a  va2s  .  c  o  m*/
    } else {
        if (!TextUtils.isEmpty(url)) {
            String tempUrl = url;
            if (!URLUtil.isHttpUrl(url) && !URLUtil.isHttpsUrl(url)) {
                tempUrl = "http://" + url;
            }
            String host = "";
            try {
                host = UrlUtils.getHost(tempUrl);
            } catch (MalformedURLException e) {
                mView.setToolbarUrl(mContext.getString(R.string.loading));
            }

            if (URLUtil.isValidUrl(tempUrl)) {
                mView.loadUrl(tempUrl);
                mView.setToolbarTitle(host);
            } else
                try {
                    tempUrl = "http://www.google.com/search?q=" + URLEncoder.encode(url, "UTF-8");
                    tempUrl = UrlUtils.getHost(tempUrl);

                    mView.loadUrl(tempUrl);
                    mView.setToolbarTitle(tempUrl);
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();

                    mView.showToast(makeToast(mContext.getString(R.string.message_invalid_url)));
                    mView.close();
                } catch (MalformedURLException e) {
                    mView.setToolbarUrl(mContext.getString(R.string.loading));
                }
        } else {
            mView.showToast(makeToast(mContext.getString(R.string.message_invalid_url)));
            mView.close();
        }
    }
}

From source file:com.amazonaws.devicefarm.android.referenceapp.Fragments.WebViewFragment.java

/**
 * loads a custom url from the url bar/* w w w.j a  va 2s . c o  m*/
 * @param v
 * @param actionId
 * @return
 */
@OnEditorAction(R.id.website_input)
boolean onEditorAction(TextView v, int actionId) {

    if (URLUtil.isValidUrl(v.getText().toString()))
        webView.loadUrl(v.getText().toString());
    else
        Toast.makeText(getActivity(), getString(R.string.web_error_toast), Toast.LENGTH_SHORT).show();
    Util.hideKeyboard(websiteInput, getActivity());
    return true;
}

From source file:org.ormma.controller.OrmmaDisplayController.java

/**
 * Open a browser/* www . java 2 s  .  c o  m*/
 *
 * @param url the url
 * @param back show the back button
 * @param forward show the forward button
 * @param refresh show the refresh button
 */
public void open(String url, boolean back, boolean forward, boolean refresh) {
    Log.d(LOG_TAG, "open: url: " + url + " back: " + back + " forward: " + forward + " refresh: " + refresh);
    if (!URLUtil.isValidUrl(url)) {
        mOrmmaView.raiseError("Invalid url", "open");
    } else {
        mOrmmaView.open(url, back, forward, refresh);
    }

}

From source file:com.dm.material.dashboard.candybar.adapters.CreditsAdapter.java

@Override
public View getView(int position, View view, ViewGroup viewGroup) {
    ViewHolder holder;/*from   w  w  w.  j av a  2  s .c om*/
    if (view == null) {
        view = View.inflate(mContext, R.layout.fragment_credits_item_list, null);
        holder = new ViewHolder(view);
        view.setTag(holder);
    } else {
        holder = (ViewHolder) view.getTag();
    }

    Credit credit = mCredits.get(position);
    holder.title.setText(credit.getName());
    holder.subtitle.setText(credit.getContribution());
    holder.container.setOnClickListener(view1 -> {
        String link = credit.getLink();
        if (URLUtil.isValidUrl(link)) {
            try {
                mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(link)));
            } catch (ActivityNotFoundException e) {
                LogUtil.e(Log.getStackTraceString(e));
            }
        }
    });

    if (credit.getContribution().length() == 0) {
        holder.subtitle.setVisibility(View.GONE);
    } else {
        holder.subtitle.setVisibility(View.VISIBLE);
    }

    ImageLoader.getInstance().displayImage(credit.getImage(), new ImageViewAware(holder.image),
            mOptions.build(), new ImageSize(144, 144), null, null);
    return view;
}