List of usage examples for android.webkit URLUtil isNetworkUrl
public static boolean isNetworkUrl(String url)
From source file:org.appcelerator.titanium.view.TiDrawableReference.java
public boolean isNetworkUrl() { return (type == DrawableReferenceType.URL && url != null && URLUtil.isNetworkUrl(this.url)); }
From source file:com.jaspersoft.android.jaspermobile.activities.profile.ServerProfileActivity.java
private boolean isFormValid() { Map<EditText, String> valueMap = Maps.newHashMap(); valueMap.put(aliasEdit, alias);//from w w w . j av a2 s. c o m valueMap.put(serverUrlEdit, serverUrl); valueMap.put(usernameEdit, username); if (!askPasswordCheckBox.isChecked()) { valueMap.put(passwordEdit, password); } boolean isFieldValid; boolean formValid = true; for (Map.Entry<EditText, String> entry : valueMap.entrySet()) { isFieldValid = !TextUtils.isEmpty(entry.getValue()) && !TextUtils.isEmpty(entry.getValue().trim()); if (!isFieldValid) { entry.getKey().setError(getString(R.string.sp_error_field_required)); entry.getKey().requestFocus(); } formValid &= isFieldValid; } if (!TextUtils.isEmpty(serverUrl)) { String url = trimUrl(serverUrl); if (!URLUtil.isNetworkUrl(url)) { serverUrlEdit.setError(getString(R.string.sp_error_url_not_valid)); serverUrlEdit.requestFocus(); formValid &= false; } } return formValid; }
From source file:com.jaspersoft.android.jaspermobile.activities.profile.ServerProfileActivity.java
private void setSubmitActionState() { List<String> values = Lists.newArrayList(alias, serverUrl, username); if (!askPasswordCheckBox.isChecked()) { values.add(password);//from w w w .j a v a2s.c o m } boolean enabled = true; for (String value : values) { enabled &= !TextUtils.isEmpty(value) && !TextUtils.isEmpty(value.trim()); } if (!TextUtils.isEmpty(serverUrl)) { String url = trimUrl(serverUrl); enabled &= URLUtil.isNetworkUrl(url); } if (saveAction != null) { saveAction.setIcon(enabled ? R.drawable.ic_action_submit : R.drawable.ic_action_submit_disabled); } }
From source file:com.tfg.sawan.bsecure.beacon.UriBeaconDiscoveryService.java
private PendingIntent createNavigateToUrlPendingIntent(String url) { String urlToNavigateTo = url; // If this url has metadata if (mUrlToUrlMetadata.get(url) != null) { String siteUrl = mUrlToUrlMetadata.get(url).siteUrl; // If this metadata has a siteUrl if (siteUrl != null) { urlToNavigateTo = siteUrl;//from ww w.j a v a 2s .c om } } if (!URLUtil.isNetworkUrl(urlToNavigateTo)) { urlToNavigateTo = "http://" + urlToNavigateTo; } urlToNavigateTo = PwsClient.getInstance(this).createUrlProxyGoLink(urlToNavigateTo); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(urlToNavigateTo)); int requestID = (int) System.currentTimeMillis(); PendingIntent pendingIntent = PendingIntent.getActivity(this, requestID, intent, 0); return pendingIntent; }
From source file:org.physical_web.physicalweb.BeaconConfigFragment.java
/** * This is called when the user taps the write-to-beacon button. *//*from w w w .j av a 2 s. c om*/ private void saveEditCardUrlToBeacon() { // Update the status text mScanningStatus.setText(R.string.config_writing_to_beacon_text); // Remove the focus from the url edit text field mEditCard.clearFocus(); // Get the current text in the url edit text field. String url = mEditCardUrl.getText().toString(); // Ensure an http prefix exists in the url if (!URLUtil.isNetworkUrl(url)) { url = "http://" + url; } // Create the callback object to set the url PwsClient.ShortenUrlCallback urlSetter = new PwsClient.ShortenUrlCallback() { @Override public void onUrlShortened(String newUrl) { setUriBeaconUrl(newUrl); } @Override public void onError(String oldUrl) { Toast.makeText(getActivity(), R.string.url_shortening_error, Toast.LENGTH_SHORT).show(); } }; // Shorten the url if necessary if (ConfigUriBeacon.uriLength(url) > ConfigUriBeacon.MAX_URI_LENGTH) { PwsClient.getInstance(getActivity()).shortenUrl(url, urlSetter, TAG); } else { setUriBeaconUrl(url); } }
From source file:com.cw.litenote.util.video.UtilVideo.java
public static String getVideoDataSource(String path) throws IOException { if (!URLUtil.isNetworkUrl(path)) { return path; } else {//from ww w. j a va2s.c om URL url = new URL(path); URLConnection cn = url.openConnection(); cn.connect(); InputStream stream = cn.getInputStream(); if (stream == null) throw new RuntimeException("stream is null"); File temp = File.createTempFile("mediaplayertmp", "dat"); temp.deleteOnExit(); String tempPath = temp.getAbsolutePath(); FileOutputStream out = new FileOutputStream(temp); byte buf[] = new byte[128]; do { System.setProperty("http.keepAlive", "false");//??? need this? int numread = stream.read(buf); if (numread <= 0) break; out.write(buf, 0, numread); } while (true); try { stream.close(); out.close(); } catch (IOException ex) { Log.e(TAG_VIDEO, "error: " + ex.getMessage(), ex); } System.out.println("UtilVideo / _getVideoDataSource / tempPath " + tempPath); return tempPath; } }
From source file:com.karma.konnect.BeaconConfigFragment.java
/** * This is called when the user taps the write-to-beacon button. *///from w ww . jav a2 s . c o m private void saveEditCardUrlToBeacon() { // Update the status text mScanningStatus.setText(R.string.config_writing_to_beacon_text); // Remove the focus from the url edit text field mEditCard.clearFocus(); // Get the current text in the url edit text field. String url = mEditCardUrl.getText().toString(); // Ensure an http prefix exists in the url if (!URLUtil.isNetworkUrl(url)) { url = "http://" + url; } // Create the callback object to set the url PwsClient.ShortenUrlCallback urlSetter = new PwsClient.ShortenUrlCallback() { @Override public void onUrlShortened(String newUrl) { setUriBeaconUrl(newUrl); } @Override public void onError(String oldUrl) { // Avoid showing a "URL too long" error if we shortened due to non-ASCII chars in url int errorMessageStringId = R.string.url_shortening_error; if (hasValidUrlLength(oldUrl) && !isAsciiUrl(oldUrl)) { errorMessageStringId = R.string.url_charset_error; } Toast.makeText(getActivity(), errorMessageStringId, Toast.LENGTH_SHORT).show(); } }; if (hasValidUrlLength(url) && isAsciiUrl(url)) { // Set the url if we can setUriBeaconUrl(url); } else { // Shorten the url if necessary PwsClient.getInstance(getActivity()).shortenUrl(url, urlSetter, TAG); } }
From source file:gsoc.google.com.byop.utils.PW.BeaconConfigFragment.java
/** * This is called when the user taps the write-to-beacon button. *///from w w w. j a va 2 s . c o m private void saveEditCardUrlToBeacon() { // Update the status text mScanningStatus.setText(R.string.config_writing_to_beacon_text); // Remove the focus from the url edit text field mEditCard.clearFocus(); // Get the current text in the url edit text field. String url = mEditCardUrl.getText().toString(); // Ensure an http prefix exists in the url if (!URLUtil.isNetworkUrl(url)) { url = "http://" + url; } // Create the callback object to set the url UrlShortenerClient.ShortenUrlCallback urlSetter = new UrlShortenerClient.ShortenUrlCallback() { @Override public void onUrlShortened(String newUrl) { setUriBeaconUrl(newUrl); } @Override public void onError(String oldUrl) { // Avoid showing a "URL too long" error if we shortened due to non-ASCII chars in url int errorMessageStringId = R.string.url_shortening_error; if (hasValidUrlLength(oldUrl) && !isAsciiUrl(oldUrl)) { errorMessageStringId = R.string.url_charset_error; } Toast.makeText(getActivity(), errorMessageStringId, Toast.LENGTH_SHORT).show(); } }; if (hasValidUrlLength(url) && isAsciiUrl(url)) { // Set the url if we can setUriBeaconUrl(url); } else { // Shorten the url if necessary UrlShortenerClient.getInstance(getActivity()).shortenUrl(url, urlSetter, TAG); } }
From source file:org.physical_web.physicalweb.UriBeaconDiscoveryService.java
private PendingIntent createNavigateToUrlPendingIntent(String url) { String urlToNavigateTo = url; // If this url has metadata if (mUrlToUrlMetadata.get(url) != null) { String siteUrl = mUrlToUrlMetadata.get(url).siteUrl; // If this metadata has a siteUrl if (siteUrl != null) { urlToNavigateTo = siteUrl;/* w w w . ja v a 2s . c o m*/ } } if (!URLUtil.isNetworkUrl(urlToNavigateTo)) { urlToNavigateTo = "http://" + urlToNavigateTo; } urlToNavigateTo = MetadataResolver.createUrlProxyGoLink(urlToNavigateTo); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(urlToNavigateTo)); int requestID = (int) System.currentTimeMillis(); PendingIntent pendingIntent = PendingIntent.getActivity(this, requestID, intent, 0); return pendingIntent; }
From source file:android.webkit.LoadListener.java
private void doRedirect() { // as cancel() can cancel the load before doRedirect() is // called through handleMessage, needs to check to see if we // are canceled before proceed if (mCancelled) { return;//from ww w . j av a 2 s. co m } String redirectTo = mHeaders.getLocation(); if (redirectTo != null) { int nativeResponse = createNativeResponse(); redirectTo = nativeRedirectedToUrl(mUrl, redirectTo, nativeResponse); // nativeRedirectedToUrl() may call cancel(), e.g. when redirect // from a https site to a http site, check mCancelled again if (mCancelled) { return; } if (redirectTo == null) { Log.d(LOGTAG, "Redirection failed for " + mHeaders.getLocation()); cancel(); return; } else if (!URLUtil.isNetworkUrl(redirectTo)) { final String text = mContext.getString(com.android.internal.R.string.open_permission_deny) + "\n" + redirectTo; nativeAddData(text.getBytes(), text.length()); nativeFinished(); clearNativeLoader(); return; } if (mOriginalUrl == null) { mOriginalUrl = mUrl; } // Cache the redirect response if (mCacheResult != null) { if (getErrorID() == OK) { CacheManager.saveCacheFile(mUrl, mCacheResult); } mCacheResult = null; } setUrl(redirectTo); // Redirect may be in the cache if (mRequestHeaders == null) { mRequestHeaders = new HashMap<String, String>(); } if (!checkCache(mRequestHeaders)) { // mRequestHandle can be null when the request was satisfied // by the cache, and the cache returned a redirect if (mRequestHandle != null) { mRequestHandle.setupRedirect(redirectTo, mStatusCode, mRequestHeaders); } else { String method = mMethod; if (method == null) { return; } Network network = Network.getInstance(getContext()); network.requestURL(method, mRequestHeaders, mPostData, this, mIsHighPriority); } } } else { cancel(); } if (Config.LOGV) { Log.v(LOGTAG, "LoadListener.onRedirect(): redirect to: " + redirectTo); } }