@Override protected Void doInBackground(String... arg0) { String packagePath = arg0[0]; if (URLUtil.isValidUrl(packagePath)) { packagePath = downloadPackage(packagePath); } installPackage(packagePath); return null; }
@Override public void onDownloadStart(final String url, final String userAgent, final String contentDisposition, final String mimeType, final long contentLength) { final String suggestedFilename = URLUtil.guessFileName(url, contentDisposition, mimeType); if (mListener != null) { mListener.onDownloadRequested(url, suggestedFilename, mimeType, contentLength, contentDisposition, userAgent); } }
private void setAlbumart() { playlistTitleView.setText(playlistName); if(albumPath == null){ albumArtSmall.setImageResource(R.drawable.placeholder_disk_210); }else { albumArtSmall.setImageURI(Uri.parse(albumPath)); } try { if (isLocalPlaylist && !URLUtil.isNetworkUrl(albumPath)) { new setBlurredAlbumArt().execute(ImageUtils.getArtworkQuick(PlaylistActivity.this, Uri.parse(albumPath), 300, 300)); L.D(d, TAG, "albumpath = " + albumPath); } else { //drawable = Drawable.createFromStream( new URL(albumPath).openStream(),"src"); ImageRequest imageRequest = ImageRequest.fromUri(albumPath); CacheKey cacheKey = DefaultCacheKeyFactory.getInstance() .getEncodedCacheKey(imageRequest); BinaryResource resource = ImagePipelineFactory.getInstance() .getMainDiskStorageCache().getResource(cacheKey); File file = ((FileBinaryResource) resource).getFile(); if (file != null) new setBlurredAlbumArt().execute(ImageUtils.getArtworkQuick(file, 300, 300)); } } catch (Exception e) { e.printStackTrace(); } }
private ArrayList<Pojo> getResults(String query) { ArrayList<Pojo> records = new ArrayList<>(); for (SearchPojo pojo : pojos) { // Set the id, otherwise the result will be boosted since KISS will assume "we've selected this search provider multiple times before" pojo.id = "search://" + query; pojo.query = query; records.add(pojo); } // Open URLs directly (if I type http://something.com for instance) Matcher m = urlPattern.matcher(query); if (m.find()) { String guessedUrl = URLUtil.guessUrl(query); if (URLUtil.isValidUrl(guessedUrl)) { SearchPojo pojo = new SearchPojo("", guessedUrl, SearchPojo.URL_QUERY); pojo.relevance = 50; pojo.setName(guessedUrl, false); records.add(pojo); } } return records; } }
public static boolean isConfigUrlValid(){ if (OpenTokConfig.CHAT_SERVER_URL == null) { configErrorMessage = "CHAT_SERVER_URL in OpenTokConfig.java must not be null"; return false; } else if ( !( URLUtil.isHttpsUrl(OpenTokConfig.CHAT_SERVER_URL) || URLUtil.isHttpUrl(OpenTokConfig.CHAT_SERVER_URL)) ) { configErrorMessage = "CHAT_SERVER_URL in OpenTokConfig.java must be specified as either http or https"; return false; } else if ( !URLUtil.isValidUrl(OpenTokConfig.CHAT_SERVER_URL) ) { configErrorMessage = "CHAT_SERVER_URL in OpenTokConfig.java is not a valid URL"; return false; } else { return true; } } }
private boolean validateUrl(String url) { if (URLUtil.isHttpsUrl(url) || URLUtil.isHttpUrl(url)) { return true; } 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; }
public static boolean isWebServerConfigUrlValid(){ if (OpenTokConfig.CHAT_SERVER_URL == null || OpenTokConfig.CHAT_SERVER_URL.isEmpty()) { webServerConfigErrorMessage = "CHAT_SERVER_URL in OpenTokConfig.java must not be null or empty"; return false; } else if ( !( URLUtil.isHttpsUrl(OpenTokConfig.CHAT_SERVER_URL) || URLUtil.isHttpUrl(OpenTokConfig.CHAT_SERVER_URL)) ) { webServerConfigErrorMessage = "CHAT_SERVER_URL in OpenTokConfig.java must be specified as either http or https"; return false; } else if ( !URLUtil.isValidUrl(OpenTokConfig.CHAT_SERVER_URL) ) { webServerConfigErrorMessage = "CHAT_SERVER_URL in OpenTokConfig.java is not a valid URL"; return false; } else { return true; } } }
/** * delete cache by key * * @param key key * @return is */ public synchronized boolean remove(String key) { if (URLUtil.isHttpUrl(key) || URLUtil.isHttpsUrl(key)) { return fromImage().remove(key); } else { return fromObj().remove(key); } }
/** * Check if a string is an url * TODO : unit test on this, I'm not quite sure it is perfect... */ public static boolean isUrl(String url) { return URLUtil.isValidUrl(url) && !"http://".equals(url); }
@Override public void validateUrl(final String url) { if (URLUtil.isValidUrl(url)) { mView.loadUrl(url); } else { if (!TextUtils.isEmpty(url)) { String tempUrl = url; if (!URLUtil.isHttpUrl(url) && !URLUtil.isHttpsUrl(url)) { tempUrl = "http://" + url; if (URLUtil.isValidUrl(tempUrl)) { mView.loadUrl(tempUrl); mView.setToolbarTitle(host);
protected String doInBackground(String... urls) { URL url; String filename = null; try { url = new URL(urls[0]); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.connect(); conn.setInstanceFollowRedirects(false); String depo = conn.getHeaderField("Content-Disposition"); if (depo != null) filename = depo.replaceFirst("(?i)^.*filename=\"?([^\"]+)\"?.*$", "$1"); else filename = URLUtil.guessFileName(urls[0], null, null); } catch (MalformedURLException e1) { e1.printStackTrace(); } catch (IOException e) { } return filename; }
String location = responseHeaders.getLocation(); if (!URLUtil.isNetworkUrl(location)) { String oldUrl = oldRequest.url(); try {
if(URLUtil.isHttpUrl(largeIconResourceId) || URLUtil.isHttpsUrl(largeIconResourceId)) { intent.putExtra("pictureUrl", largeIconResourceId);
@Override protected boolean isValid(TextView view) { return URLUtil.isValidUrl(view.getText().toString()); }
@Override public void onDownloadStart(final String url, final String userAgent, final String contentDisposition, final String mimeType, final long contentLength) { final String suggestedFilename = URLUtil.guessFileName(url, contentDisposition, mimeType); if (mListener != null) { mListener.onDownloadRequested(url, suggestedFilename, mimeType, contentLength, contentDisposition, userAgent); } }
if (TextUtils.isEmpty(location)) return null; if (URLUtil.isNetworkUrl(location)) { return newBuilder(location).build();
private void validate(String url, long folderId) { if (url == null || url.isEmpty() || !URLUtil.isValidUrl(url)) { throw new IllegalArgumentException("Invalid url"); } else if (folderId < 0) { throw new IllegalArgumentException("Invalid folderId"); } }
public void downloadFile() { URL url = null; String file = ""; try { //url = new URL ("http://www.cs.uwyo.edu/~seker/courses/4730/example/pic.jpg"); //for a bigger file: http://www.nasa.gov/images/content/206402main_jsc2007e113280_hires.jpg //for reason I don't understand, I can't download it from nasa on the phone... weird... // url = new URL("http://www.nasa.gov/images/content/206402main_jsc2007e113280_hires.jpg"); url = new URL ("http://www.cs.uwyo.edu/~seker/courses/4730/example/206402main_jsc2007e113280_hires.jpg"); //yes, I could write the file name, but this means I don't have think it about if I change files. file = URLUtil.guessFileName(url.getFile(), null, null); } catch (MalformedURLException e) { e.printStackTrace(); } //setup intent and send it. Intent getfile = new Intent(getActivity().getBaseContext(), fileDlService.class); getfile.putExtra("FILE", file); getfile.putExtra("URL", url); getActivity().startService(getfile); }
private void interceptLink(TextView view) { view.setMovementMethod(LinkMovementMethod.getInstance()); CharSequence text = view.getText(); if (text instanceof Spannable) { Spannable spannable = (Spannable) text; URLSpan[] spans = spannable.getSpans(0, text.length(), URLSpan.class); if (spans.length == 0) { return; } SpannableStringBuilder ssb = new SpannableStringBuilder(text); for (URLSpan urlSpan : spans) { final String url = urlSpan.getURL(); if (URLUtil.isNetworkUrl(url)) { ClickableSpan clickableSpan = new ClickableSpan() { @Override public void onClick(View widget) { WebActivity.startActivity(getActivity(), url); } }; ssb.setSpan(clickableSpan, spannable.getSpanStart(urlSpan) , spannable.getSpanEnd(urlSpan), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); } } view.setText(ssb); } }
public static String getUrl(Context context) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); // validate URL is valid String URL = sharedPref.getString("pref_api_base", context.getResources().getString(R.string.pref_default_api_base_url)); if (!URLUtil.isValidUrl(URL)) { return "http://invalid"; } return URL; }