Java Code Examples for android.webkit.URLUtil#isValidUrl()
The following examples show how to use
android.webkit.URLUtil#isValidUrl() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utility.java From ETSMobile-Android2 with Apache License 2.0 | 6 votes |
public static void openChromeCustomTabs(Context context, String url, boolean showTitle) { if (!URLUtil.isValidUrl(url)) { Log.w("Utility", "Url not valid!"); Log.w("Utility", url); return; } Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); Bundle extras = new Bundle(); // Something needs to be done about the min SDK... if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { extras.putBinder(Constants.EXTRA_CUSTOM_TABS_SESSION, null); extras.putInt(Constants.EXTRA_CUSTOM_TABS_TOOLBAR_COLOR, ContextCompat.getColor(context, R.color.ets_red_fonce)); if (showTitle) { extras.putInt(Constants.EXTRA_CUSTOM_TABS_TITLE_VISIBILITY_STATE, Constants.EXTRA_CUSTOM_TABS_SHOW_TITLE); } } intent.putExtras(extras); context.startActivity(intent); }
Example 2
Source File: TermsAndConditionsActivity.java From px-android with MIT License | 6 votes |
private void showMPTermsAndConditions() { mProgressLayout.setVisibility(View.VISIBLE); mTermsAndConditionsWebView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(final WebView view, final String url) { mProgressLayout.setVisibility(View.GONE); mMPTermsAndConditionsView.setVisibility(View.VISIBLE); } }); if (URLUtil.isValidUrl(data)) { mTermsAndConditionsWebView.getSettings().setUserAgentString("MercadoLibre-Android/"+ BuildConfig.VERSION_NAME); mTermsAndConditionsWebView.loadUrl(data); } else { mTermsAndConditionsWebView.loadData(data, "text/html", "UTF-8"); } }
Example 3
Source File: Playlist.java From intent_radio with MIT License | 5 votes |
protected String doInBackground(Void... args) { String url = start_url; int ttl = max_ttl; int type = NONE; if ( url != null && url.length() != 0 && URLUtil.isValidUrl(url) ) type = playlist_type(url); else url = null; if ( 0 < ttl && url != null && type != NONE ) { ttl -= 1; log("Playlist url: ", url); log("Playlist type: ", ""+type); url = select_url_from_playlist(url,type); if ( url != null && url.length() != 0 && URLUtil.isValidUrl(url) ) type = playlist_type(url); else url = null; } if ( url == null ) { log("Playlist: failed to extract url." ); } if ( ttl == 0 ) { log("Playlist: too many playlists (TTL)." ); url = null; } if ( url != null ) { log("Playlist final url: ", url ); } return url; }
Example 4
Source File: UrlHelper.java From wallpaperboard with Apache License 2.0 | 5 votes |
public static Type getType(String url) { if (url == null) return Type.INVALID; if (!URLUtil.isValidUrl(url)) { if (Patterns.EMAIL_ADDRESS.matcher(url).matches()) { return Type.EMAIL; } return Type.INVALID; } if (url.contains("behance.")) { return Type.BEHANCE; } else if (url.contains("dribbble.")) { return Type.DRIBBBLE; } else if (url.contains("facebook.")) { return Type.FACEBOOK; } else if (url.contains("github.")) { return Type.GITHUB; } else if (url.contains("plus.google.")) { return Type.GOOGLE_PLUS; } else if (url.contains("instagram.")) { return Type.INSTAGRAM; } else if (url.contains("pinterest.")) { return Type.PINTEREST; } else if (url.contains("twitter.")) { return Type.TWITTER; } else { return Type.UNKNOWN; } }
Example 5
Source File: WebViewCourseInfoFragment.java From edx-app-android with Apache License 2.0 | 5 votes |
@NonNull protected String getInitialUrl() { if (URLUtil.isValidUrl(binding.webview.getUrl())) { return binding.webview.getUrl(); } else if (getArguments() != null) { final String pathId = getArguments().getString(EXTRA_PATH_ID); return environment.getConfig().getDiscoveryConfig().getCourseDiscoveryConfig() .getInfoUrlTemplate() .replace("{" + EXTRA_PATH_ID + "}", pathId); } return environment.getConfig().getDiscoveryConfig().getCourseDiscoveryConfig().getBaseUrl(); }
Example 6
Source File: UrlHelper.java From candybar-library with Apache License 2.0 | 5 votes |
public static Type getType(String url) { if (url == null) return Type.INVALID; if (!URLUtil.isValidUrl(url)) { if (Patterns.EMAIL_ADDRESS.matcher(url).matches()) { return Type.EMAIL; } return Type.INVALID; } if (url.contains("behance.")) { return Type.BEHANCE; } else if (url.contains("dribbble.")) { return Type.DRIBBBLE; } else if (url.contains("facebook.")) { return Type.FACEBOOK; } else if (url.contains("github.")) { return Type.GITHUB; } else if (url.contains("plus.google.")) { return Type.GOOGLE_PLUS; } else if (url.contains("instagram.")) { return Type.INSTAGRAM; } else if (url.contains("pinterest.")) { return Type.PINTEREST; } else if (url.contains("twitter.")) { return Type.TWITTER; } else { return Type.UNKNOWN; } }
Example 7
Source File: ResourceManager.java From react-native-tensorflow with Apache License 2.0 | 5 votes |
public byte[] loadResource(String resource) { if(resource.startsWith("file://")) { return loadFromLocal(resource.substring(7)); } else if(URLUtil.isValidUrl(resource)) { return loadFromUrl(resource); } else { return loadFromLocal(resource); } }
Example 8
Source File: PBPreferenceFragment.java From client-android with GNU General Public License v2.0 | 5 votes |
private boolean validatePreferences() { String serverUrl = preferences.getString(PBServerPreferenceFragment.PREF_SERVER_URL, ""); if (!URLUtil.isValidUrl(serverUrl) || serverUrl.isEmpty()) { Toast.makeText(getActivity(), R.string.toast_urisyntaxexception, Toast.LENGTH_LONG).show(); return false; } String serverPassHash = preferences.getString(PBServerPreferenceFragment.PREF_SERVER_PASS_HASH, ""); if (serverPassHash.isEmpty()) { Toast.makeText(getActivity(), R.string.toast_serverpassempty, Toast.LENGTH_LONG).show(); return false; } return true; }
Example 9
Source File: MainActivity.java From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 | 5 votes |
public void getSourceCode(View view) { InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); if (inputMethodManager != null){ inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } String queryString = mURLEditText.getText().toString(); // check connectivity before executing query ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = null; if (connectivityManager != null){ networkInfo = connectivityManager.getActiveNetworkInfo(); } if (networkInfo != null && networkInfo.isConnected() && (queryString.length() != 0)){ Bundle queryBundle = new Bundle(); queryBundle.putString(QUERY, queryString); queryBundle.putString(PROTOCOL, mSpinnerValue); getSupportLoaderManager().restartLoader(0, queryBundle, this); mSourceCodeTextView.setText(R.string.loading); } else{ if (queryString.length() == 0){ Toast.makeText(this, R.string.no_url, Toast.LENGTH_LONG).show(); } else if(!URLUtil.isValidUrl(queryString)){ Toast.makeText(this, R.string.invalid_url, Toast.LENGTH_LONG).show(); } else{ Toast.makeText(this, R.string.no_connection, Toast.LENGTH_LONG).show(); } } }
Example 10
Source File: IntentPlayer.java From intent_radio with MIT License | 5 votes |
public int play_launch(String url) { log("Launching: ", url); launch_url = null; if ( ! URLUtil.isValidUrl(url) ) { toast("Invalid URL."); return stop(); } launch_url = url; // Note: Because of the way we handle network connectivity, the player // always stops and then restarts as we move between network types. // Therefore, stop() and start() are always called. So we always have // the WiFi lock if we're on WiFi and we need it, and don't otherwise. // // Here, we could be holding a WiFi lock because the playlist URL was a // network URL, but perhaps now the launch URL is not. Or the other way // around. So release the WiFi lock (if it's being held) and reaquire // it, if necessary. WifiLocker.unlock(); if ( isNetworkUrl(url) ) WifiLocker.lock(context, app_name_long); try { player.setVolume(1.0f, 1.0f); player.setDataSource(context, Uri.parse(url)); player.prepareAsync(); } catch (Exception e) { return stop(); } start_buffering(); return done(State.STATE_BUFFER); }
Example 11
Source File: OpenTokConfig.java From opentok-android-sdk-samples with MIT License | 5 votes |
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; } }
Example 12
Source File: AirConUtils.java From aircon with MIT License | 5 votes |
public static boolean isValidUrl(final String url) { final boolean validUrl = URLUtil.isValidUrl(url); if (!validUrl) { log().e("Got invalid url: " + url); } return validUrl; }
Example 13
Source File: WebViewFragment.java From aws-device-farm-sample-app-for-android with Apache License 2.0 | 5 votes |
/** * loads a custom url from the url bar * @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; }
Example 14
Source File: AboutAdapter.java From candybar with Apache License 2.0 | 5 votes |
@Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if (holder.getItemViewType() == TYPE_HEADER) { HeaderViewHolder headerViewHolder = (HeaderViewHolder) holder; String imageUri = mContext.getString(R.string.about_image); if (ColorHelper.isValidColor(imageUri)) { headerViewHolder.image.setBackgroundColor(Color.parseColor(imageUri)); } else if (!URLUtil.isValidUrl(imageUri)) { imageUri = "drawable://" + DrawableHelper.getResourceId(mContext, imageUri); ImageLoader.getInstance().displayImage(imageUri, headerViewHolder.image, ImageConfig.getDefaultImageOptions(true)); } else { ImageLoader.getInstance().displayImage(imageUri, headerViewHolder.image, ImageConfig.getDefaultImageOptions(true)); } String profileUri = mContext.getResources().getString(R.string.about_profile_image); if (!URLUtil.isValidUrl(profileUri)) { profileUri = "drawable://" + DrawableHelper.getResourceId(mContext, profileUri); } ImageLoader.getInstance().displayImage(profileUri, headerViewHolder.profile, ImageConfig.getDefaultImageOptions(true)); } }
Example 15
Source File: AboutAdapter.java From candybar-library with Apache License 2.0 | 5 votes |
@Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if (holder.getItemViewType() == TYPE_HEADER) { HeaderViewHolder headerViewHolder = (HeaderViewHolder) holder; String imageUri = mContext.getString(R.string.about_image); if (ColorHelper.isValidColor(imageUri)) { headerViewHolder.image.setBackgroundColor(Color.parseColor(imageUri)); } else if (!URLUtil.isValidUrl(imageUri)) { imageUri = "drawable://" + DrawableHelper.getResourceId(mContext, imageUri); ImageLoader.getInstance().displayImage(imageUri, headerViewHolder.image, ImageConfig.getDefaultImageOptions(true)); } else { ImageLoader.getInstance().displayImage(imageUri, headerViewHolder.image, ImageConfig.getDefaultImageOptions(true)); } String profileUri = mContext.getResources().getString(R.string.about_profile_image); if (!URLUtil.isValidUrl(profileUri)) { profileUri = "drawable://" + DrawableHelper.getResourceId(mContext, profileUri); } ImageLoader.getInstance().displayImage(profileUri, headerViewHolder.profile, ImageConfig.getDefaultImageOptions(true)); } }
Example 16
Source File: CandyBarMainActivity.java From candybar-library with Apache License 2.0 | 4 votes |
private void initNavigationViewHeader() { if (CandyBarApplication.getConfiguration().getNavigationViewHeader() == CandyBarApplication.NavigationViewHeader.NONE) { mNavigationView.removeHeaderView(mNavigationView.getHeaderView(0)); return; } String imageUrl = getResources().getString(R.string.navigation_view_header); String titleText = getResources().getString(R.string.navigation_view_header_title); View header = mNavigationView.getHeaderView(0); HeaderView image = header.findViewById(R.id.header_image); LinearLayout container = header.findViewById(R.id.header_title_container); TextView title = header.findViewById(R.id.header_title); TextView version = header.findViewById(R.id.header_version); if (CandyBarApplication.getConfiguration().getNavigationViewHeader() == CandyBarApplication.NavigationViewHeader.MINI) { image.setRatio(16, 9); } if (titleText.length() == 0) { container.setVisibility(View.GONE); } else { title.setText(titleText); try { String versionText = "v" + getPackageManager() .getPackageInfo(getPackageName(), 0).versionName; version.setText(versionText); } catch (Exception ignored) {} } if (ColorHelper.isValidColor(imageUrl)) { image.setBackgroundColor(Color.parseColor(imageUrl)); return; } if (!URLUtil.isValidUrl(imageUrl)) { imageUrl = "drawable://" + DrawableHelper.getResourceId(this, imageUrl); } ImageLoader.getInstance().displayImage(imageUrl, new ImageViewAware(image), ImageConfig.getDefaultImageOptions(true), new ImageSize(720, 720), null, null); }
Example 17
Source File: MainActivity.java From SimplicityBrowser with MIT License | 4 votes |
public void loadUrlFromTextBox() { String unUrlCleaner = mSearchView.getText().toString(); if (unUrlCleaner.startsWith("www") || URLUtil.isValidUrl(unUrlCleaner)) { if (!URLUtil.isValidUrl(unUrlCleaner)) unUrlCleaner = URLUtil.guessUrl(unUrlCleaner); mWebView.loadUrl(unUrlCleaner); } else if (unUrlCleaner.endsWith(".com") || URLUtil.isValidUrl(unUrlCleaner)) { if (!URLUtil.isValidUrl(unUrlCleaner)) unUrlCleaner = URLUtil.guessUrl(unUrlCleaner); mWebView.loadUrl(unUrlCleaner); } else if (unUrlCleaner.endsWith(".gov") || URLUtil.isValidUrl(unUrlCleaner)) { if (!URLUtil.isValidUrl(unUrlCleaner)) unUrlCleaner = URLUtil.guessUrl(unUrlCleaner); mWebView.loadUrl(unUrlCleaner); } else if (unUrlCleaner.endsWith(".net") || URLUtil.isValidUrl(unUrlCleaner)) { if (!URLUtil.isValidUrl(unUrlCleaner)) unUrlCleaner = URLUtil.guessUrl(unUrlCleaner); mWebView.loadUrl(unUrlCleaner); } else if (unUrlCleaner.endsWith(".org") || URLUtil.isValidUrl(unUrlCleaner)) { if (!URLUtil.isValidUrl(unUrlCleaner)) unUrlCleaner = URLUtil.guessUrl(unUrlCleaner); mWebView.loadUrl(unUrlCleaner); } else if (unUrlCleaner.endsWith(".mil") || URLUtil.isValidUrl(unUrlCleaner)) { if (!URLUtil.isValidUrl(unUrlCleaner)) unUrlCleaner = URLUtil.guessUrl(unUrlCleaner); mWebView.loadUrl(unUrlCleaner); } else if (unUrlCleaner.endsWith(".edu") || URLUtil.isValidUrl(unUrlCleaner)) { if (!URLUtil.isValidUrl(unUrlCleaner)) unUrlCleaner = URLUtil.guessUrl(unUrlCleaner); mWebView.loadUrl(unUrlCleaner); } else if (unUrlCleaner.endsWith(".int") || URLUtil.isValidUrl(unUrlCleaner)) { if (!URLUtil.isValidUrl(unUrlCleaner)) unUrlCleaner = URLUtil.guessUrl(unUrlCleaner); mWebView.loadUrl(unUrlCleaner); } else if (unUrlCleaner.endsWith(".ly") || URLUtil.isValidUrl(unUrlCleaner)) { if (!URLUtil.isValidUrl(unUrlCleaner)) unUrlCleaner = URLUtil.guessUrl(unUrlCleaner); mWebView.loadUrl(unUrlCleaner); } else if (unUrlCleaner.endsWith(".de") || URLUtil.isValidUrl(unUrlCleaner)) { if (!URLUtil.isValidUrl(unUrlCleaner)) unUrlCleaner = URLUtil.guessUrl(unUrlCleaner); mWebView.loadUrl(unUrlCleaner); } else if (unUrlCleaner.endsWith(".uk") || URLUtil.isValidUrl(unUrlCleaner)) { if (!URLUtil.isValidUrl(unUrlCleaner)) unUrlCleaner = URLUtil.guessUrl(unUrlCleaner); mWebView.loadUrl(unUrlCleaner); } else if (unUrlCleaner.endsWith(".it") || URLUtil.isValidUrl(unUrlCleaner)) { if (!URLUtil.isValidUrl(unUrlCleaner)) unUrlCleaner = URLUtil.guessUrl(unUrlCleaner); mWebView.loadUrl(unUrlCleaner); } else if (unUrlCleaner.endsWith(".jp") || URLUtil.isValidUrl(unUrlCleaner)) { if (!URLUtil.isValidUrl(unUrlCleaner)) unUrlCleaner = URLUtil.guessUrl(unUrlCleaner); mWebView.loadUrl(unUrlCleaner); } else if (unUrlCleaner.endsWith(".ru") || URLUtil.isValidUrl(unUrlCleaner)) { if (!URLUtil.isValidUrl(unUrlCleaner)) unUrlCleaner = URLUtil.guessUrl(unUrlCleaner); mWebView.loadUrl(unUrlCleaner); } else if (unUrlCleaner.endsWith(".gl") || URLUtil.isValidUrl(unUrlCleaner)) { if (!URLUtil.isValidUrl(unUrlCleaner)) unUrlCleaner = URLUtil.guessUrl(unUrlCleaner); mWebView.loadUrl(unUrlCleaner); } else if (unUrlCleaner.endsWith(".me") || URLUtil.isValidUrl(unUrlCleaner)) { if (!URLUtil.isValidUrl(unUrlCleaner)) unUrlCleaner = URLUtil.guessUrl(unUrlCleaner); mWebView.loadUrl(unUrlCleaner); } else if (unUrlCleaner.contains(".") && !unUrlCleaner.contains(" ") || URLUtil.isValidUrl(unUrlCleaner)) { if (!URLUtil.isValidUrl(unUrlCleaner)) unUrlCleaner = URLUtil.guessUrl(unUrlCleaner); mWebView.loadUrl(unUrlCleaner); } else { mWebView.loadUrl(defaultSearch + unUrlCleaner); } }
Example 18
Source File: CandyBarArtWorker.java From candybar with Apache License 2.0 | 4 votes |
@Override @NonNull public Result doWork() { LogUtil.d("Executing doWork() for Muzei"); if (!URLUtil.isValidUrl(mContext.getString(R.string.wallpaper_json))) { LogUtil.e("Not a valid Wallpaper JSON URL"); return Result.failure(); } List<Wallpaper> wallpapers = Database.get(mContext).getWallpapers(); ProviderClient providerClient = ProviderContract.getProviderClient(getApplicationContext(), WORKER_TAG); if (Preferences.get(getApplicationContext()).isConnectedAsPreferred()) { ArrayList artworks = new ArrayList<Artwork>(); for (Wallpaper wallpaper : wallpapers) { if (wallpaper != null) { Uri uri = Uri.parse(wallpaper.getURL()); Artwork artwork = new Artwork.Builder() .title(wallpaper.getName()) .byline(wallpaper.getAuthor()) .persistentUri(uri) .build(); if (!artworks.contains(artwork)) { artworks.add(artwork); } else { LogUtil.d("Already Contains Artwork" + wallpaper.getName()); } } else { LogUtil.d("Wallpaper is Null"); } } LogUtil.d("Closing Database - Muzei"); Database.get(mContext).closeDatabase(); providerClient.setArtwork(artworks); return Result.success(); } return Result.failure(); }
Example 19
Source File: CandyBarMainActivity.java From candybar with Apache License 2.0 | 4 votes |
private void initNavigationViewHeader() { if (CandyBarApplication.getConfiguration().getNavigationViewHeader() == CandyBarApplication.NavigationViewHeader.NONE) { mNavigationView.removeHeaderView(mNavigationView.getHeaderView(0)); return; } String imageUrl = getResources().getString(R.string.navigation_view_header); String titleText = getResources().getString(R.string.navigation_view_header_title); View header = mNavigationView.getHeaderView(0); HeaderView image = header.findViewById(R.id.header_image); LinearLayout container = header.findViewById(R.id.header_title_container); TextView title = header.findViewById(R.id.header_title); TextView version = header.findViewById(R.id.header_version); if (CandyBarApplication.getConfiguration().getNavigationViewHeader() == CandyBarApplication.NavigationViewHeader.MINI) { image.setRatio(16, 9); } if (titleText.length() == 0) { container.setVisibility(View.GONE); } else { title.setText(titleText); try { String versionText = "v" + getPackageManager() .getPackageInfo(getPackageName(), 0).versionName; version.setText(versionText); } catch (Exception ignored) { } } if (ColorHelper.isValidColor(imageUrl)) { image.setBackgroundColor(Color.parseColor(imageUrl)); return; } if (!URLUtil.isValidUrl(imageUrl)) { imageUrl = "drawable://" + DrawableHelper.getResourceId(this, imageUrl); } ImageLoader.getInstance().displayImage(imageUrl, new ImageViewAware(image), ImageConfig.getDefaultImageOptions(true), new ImageSize(720, 720), null, null); }
Example 20
Source File: NetworkUtils.java From Shaarlier with GNU General Public License v3.0 | 2 votes |
/** * 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); }