@Override protected Void doInBackground(String... arg0) { String packagePath = arg0[0]; if (URLUtil.isValidUrl(packagePath)) { packagePath = downloadPackage(packagePath); } installPackage(packagePath); return null; }
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; } }
/** * 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 protected boolean isValid(TextView view) { return URLUtil.isValidUrl(view.getText().toString()); }
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 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; }
private Uri getMedia(String mediaName) { if (URLUtil.isValidUrl(mediaName)) { // Media name is an external URL. return Uri.parse(mediaName); } else { // Media name is a raw resource embedded in the app. return Uri.parse("android.resource://" + getPackageName() + "/raw/" + mediaName); } } }
String url = mSearch.getText().toString(); if (URLUtil.isValidUrl(url)) { mLoader.load(url, new HNativeEngine.OnHNViewLoaded() { @Override
@Override public void onClick(View v) { if (URLUtil.isValidUrl(radioUrlEditText.getText().toString())) { onSoundChosen(new SoundData(getString(R.string.title_radio), radioUrlEditText.getText().toString())); } } });
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; } } }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.layout_example: Intent i = new Intent(this, ExampleListActivity.class); startActivity(i); break; case R.id.about: Intent ii = new Intent(this, TestActivity.class); startActivity(ii); break; case R.id.main_in_webview: String url = mSearch.getText().toString(); if (URLUtil.isValidUrl(url)) { Intent intent = new Intent(this, WebViewActivity.class); intent.putExtra(EXTAL_URL, url); startActivity(intent); } else { Toast.makeText(this, "not valid url", Toast.LENGTH_LONG).show(); } break; } return super.onOptionsItemSelected(item); }
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; } } }
/** * If the given URL is a WebLite URL and should be overridden because the Data * Reduction Proxy is on, the user is in the Lo-Fi previews experiment, and the scheme of the * lite_url param is HTTP, returns the URL contained in the lite_url param. Otherwise returns * the given URL. * * @param url The URL to evaluate. * @return The URL to be used. Returns null if the URL param is null. */ public String maybeRewriteWebliteUrl(String url) { if (url == null || !URLUtil.isValidUrl(url) || !areLoFiPreviewsEnabled() || !isDataReductionProxyEnabled()) { return url; } String rewritten = extractUrlFromWebliteQueryParams(url); if (rewritten == null || !TextUtils.equals(Uri.parse(rewritten).getScheme(), "http")) { return url; } return rewritten; }
private void handleScanResult() { BarcodeRecognizer.Result result = mBarcodeRecognizer.getResult(); //do what you want with the result if (URLUtil.isValidUrl(result.getStringData())) { openScanResultInBrowser(result); } else { shareScanResult(result); } }
@Override protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_update); super.onCreate(savedInstanceState); // Get current user. user = new Accounts(this).getCurrentUser(); url = findViewById(R.id.url); postStatus = findViewById(R.id.postStatus); title = findViewById(R.id.title); body = findViewById(R.id.body); Bundle extras = getIntent().getExtras(); if (extras != null) { String incomingText = extras.getString("incomingText"); if (incomingText != null && incomingText.length() > 0) { if (URLUtil.isValidUrl(incomingText)) { url.setText(incomingText); } else { body.setText(incomingText); } } } }
@Override public boolean onPreferenceChange(Preference preference, Object newValue) { String value = (String) newValue; if (URLUtil.isValidUrl(value)) { WeakReference<Activity> weakContext = new WeakReference<Activity>( SettingsActivity.this); ServerChecker serverChecker = new ServerChecker(weakContext, SettingsActivity.this.getApplicationContext(), SettingsActivity.this, true, true, false); serverChecker.execute( new Server(value, SettingsActivity.this.getApplicationContext())); return true; } Toast.makeText(SettingsActivity.this.getApplicationContext(), SettingsActivity.this.getApplicationContext().getResources() .getString(R.string.settings_menu_custom_server_url_description_error_url), Toast.LENGTH_SHORT ) .show(); customServerURL .setSummary(getResources().getString(R.string.settings_menu_custom_server_url_description_error_url)); setResult(RESULT_OK, returnIntent); return false; } });
private void handleScanResultIntent(Intent data) { // updates bundled recognizers with results that have arrived mRecognizerBundle.loadFromIntent(data); // after calling mRecognizerBundle.loadFromIntent, results are stored in mBarcodeRecognizer BarcodeRecognizer.Result result = mBarcodeRecognizer.getResult(); //do what you want with the result if (URLUtil.isValidUrl(result.getStringData())) { openScanResultInBrowser(result); } else { shareScanResult(result); } }
public List<String> parseImageList(Content content) { String readerUrl = content.getReaderUrl(); List<String> imgUrls = Collections.emptyList(); if (!URLUtil.isValidUrl(readerUrl)) { Timber.e("Invalid gallery URL : %s", readerUrl); return imgUrls; } Timber.d("Gallery URL: %s", readerUrl); try { imgUrls = parseImages(content); } catch (IOException e) { Timber.e(e, "I/O Error while attempting to connect to: %s", readerUrl); } catch (Exception e) { Timber.e(e, "Unexpected Error while attempting to connect to: %s", readerUrl); } Timber.d("%s", imgUrls); return imgUrls; }
if (URLUtil.isValidUrl(urlJ)) { HNativeEngine.getHttpClient().send(new HttpRequest(urlJ, HttpRequest .Method.POST, paramsJ, null), new RequestCallback() {
if (URLUtil.isValidUrl(urlJ)) {