List of usage examples for android.webkit URLUtil isHttpUrl
public static boolean isHttpUrl(String url)
From source file:Main.java
public static boolean isHttpUrl(String text) { return URLUtil.isHttpUrl(text) || URLUtil.isHttpsUrl(text); }
From source file:com.github.dfa.diaspora_android.web.WebHelper.java
public static String replaceUrlWithMarkdown(String url) { if (url != null && URLUtil.isHttpUrl(url) || URLUtil.isHttpsUrl(url)) { return "<" + url + ">"; }/*from w w w . j a v a 2s . com*/ return url; }
From source file:com.mobileacuity.android.cloudmvsdemo.Result.java
public Result(String raw, String result, float score, float cx, float cy) { this.raw = raw; this.result = result; if (URLUtil.isHttpUrl(result) || URLUtil.isHttpsUrl(result)) uri = Uri.parse(result);// w w w . j av a 2s. co m this.score = score; this.cx = cx; this.cy = cy; }
From source file:com.tfc.webviewer.presenter.WebViewPresenterImpl.java
@Override public void validateUrl(final String url) { if (URLUtil.isValidUrl(url)) { mView.loadUrl(url);/*from w w w . j a va 2 s . co 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:project.cs.lisa.application.html.NetInfWebViewClient.java
@Override public WebResourceResponse shouldInterceptRequest(WebView view, String url) { Intent intent = new Intent(MainApplicationActivity.SEARCH_TRANSMISSION); MainApplicationActivity.getActivity().sendBroadcast(intent); if (!URLUtil.isHttpUrl(url)) { super.shouldInterceptRequest(view, url); return null; } else if (URLUtil.isHttpUrl(url)) { WebObject resource = null;/*w ww .jav a 2 s . c o m*/ File file = null; String contentType = null; String hash = null; // Get and publish resource try { // Search for url NetInfSearchResponse searchResponse = search(url); // Get url data hash = selectHash(searchResponse); NetInfRetrieveResponse retrieveResponse = retrieve(hash); file = retrieveResponse.getFile(); contentType = retrieveResponse.getContentType(); } catch (Exception e1) { Log.e(TAG, "Request for resource failed. Downloading from uplink."); resource = downloadResource(url); if (resource == null) { return null; } file = resource.getFile(); contentType = resource.getContentType(); hash = resource.getHash(); } // Publish try { if (shouldPublish()) { publish(file, new URL(url), hash, contentType); } } catch (MalformedURLException e1) { Log.e(TAG, "Malformed url. Can't publish file."); } // Creating the resource that will be used by the webview WebResourceResponse response = null; try { response = new WebResourceResponse(contentType, "base64", FileUtils.openInputStream(file)); } catch (IOException e) { Log.e("TAG", "Could not open file"); } System.gc(); return response; } else { Log.e(TAG, "Unexpected url while intercepting resources."); return super.shouldInterceptRequest(view, url); } }
From source file:com.jbirdvegas.mgerrit.GerritSwitcher.java
@Contract("null -> false") private boolean isUrlValid(String url) { return (url != null) && (URLUtil.isHttpUrl(url) || URLUtil.isHttpsUrl(url) && url.contains(".")); }
From source file:com.shinymayhem.radiopresets.ServiceAudioFormat.java
private String getUrlFromM3u(String url) throws IOException, StreamHttpException { if (LOCAL_LOGD) log("Get URL from M3U", "d"); if (mStream == null) { getInputStream(url);/*ww w . j a va 2 s .c o m*/ } String newUrl = url; BufferedReader reader = new BufferedReader(new InputStreamReader(mStream)); String line; while ((line = reader.readLine()) != null) { if (LOCAL_LOGV) log("read line:" + line, "v"); if (!line.startsWith("#") && URLUtil.isHttpUrl(line) || URLUtil.isHttpsUrl(line)) { newUrl = line; break; } } return newUrl; }
From source file:org.traccar.client.MainFragment.java
private boolean validateServerURL(String userUrl) { int port = Uri.parse(userUrl).getPort(); if (URLUtil.isValidUrl(userUrl) && (port == -1 || (port > 0 && port <= 65535)) && (URLUtil.isHttpUrl(userUrl) || URLUtil.isHttpsUrl(userUrl))) { return true; }//from w w w . ja va2 s .c om Toast.makeText(getActivity(), R.string.error_msg_invalid_url, Toast.LENGTH_LONG).show(); return false; }
From source file:com.ardnezar.lookapp.ConnectActivity.java
private boolean validateUrl(String url) { if (URLUtil.isHttpsUrl(url) || URLUtil.isHttpUrl(url)) { return true; }/* w w w . ja v a 2 s. c o m*/ new AlertDialog.Builder(this).setTitle(getText(R.string.invalid_url_title)) .setMessage(getString(R.string.invalid_url_text, url)).setCancelable(false) .setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }).create().show(); return false; }
From source file:org.ohmage.authenticator.AuthenticatorActivity.java
/** * Ensures that the server url provided is valid. Once it is made valid, it * is set as the server url.// w w w . ja v a 2s . co m * * @return */ private boolean ensureServerUrl() { String text = mServerEdit.getText().toString(); if (TextUtils.isEmpty(text)) return false; // Assume they want https by default URI uri = URI.create(text.split(" ")[0]); if (uri.getScheme() == null) { text = "https://" + text; } text = URLUtil.guessUrl(text); if (URLUtil.isHttpsUrl(text) || URLUtil.isHttpUrl(text)) { mServerEdit.setText(text); return true; } return false; }