List of usage examples for android.webkit URLUtil isValidUrl
public static boolean isValidUrl(String url)
From source file:uk.ac.ucl.excites.sapelli.relay.BackgroundService.java
/** * Method to POST a SmsObject to the Server * /*from ww w. j a v a2s . c o m*/ */ private String postSmsObject(SmsObject smsObject) { HttpClient httpClient = new DefaultHttpClient(); // Check the validity of the URL HttpPost httpPost = null; if (SERVER_URL == null) { Debug.d("URL is null!"); return null; } Debug.d("URL: " + SERVER_URL); if (URLUtil.isValidUrl(SERVER_URL)) { httpPost = new HttpPost(SERVER_URL); // Log.i(Constants.TAG, "--!-- SERVER_URL: " + SERVER_URL); } else { Debug.d("--!-- SERVER_URL ERROR --!--"); return null; } // Set the POST parameters List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>(); nameValuePairList.add(new BasicNameValuePair("smsID", String.valueOf(smsObject.getId()))); nameValuePairList.add(new BasicNameValuePair("smsPhoneNumber", smsObject.getTelephoneNumber())); nameValuePairList .add(new BasicNameValuePair("smsTimestamp", String.valueOf(smsObject.getMessageTimestamp()))); String data = smsObject.getMessageData(); nameValuePairList.add(new BasicNameValuePair("smsData", data)); // POST them try { // UrlEncodedFormEntity is an entity composed of a list of // url-encoded pairs. // This is typically useful while sending an HTTP POST request. UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(nameValuePairList); // setEntity() hands the entity (here it is urlEncodedFormEntity) to // the request. httpPost.setEntity(urlEncodedFormEntity); try { // HttpResponse is an interface just like HttpPost. // Therefore we can't initialise them HttpResponse httpResponse = httpClient.execute(httpPost); // According to the JAVA API, InputStream constructor do // nothing. // So we can't initialise InputStream although it is not an // interface InputStream inputStream = httpResponse.getEntity().getContent(); InputStreamReader inputStreamReader = new InputStreamReader(inputStream); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); StringBuilder stringBuilder = new StringBuilder(); String bufferedStrChunk = null; while ((bufferedStrChunk = bufferedReader.readLine()) != null) { stringBuilder.append(bufferedStrChunk); } return stringBuilder.toString(); } catch (ClientProtocolException e) { Debug.e(e); } catch (IOException e) { Debug.e(e); } } catch (UnsupportedEncodingException e) { Debug.e(e); } return null; }
From source file:com.optimusinfo.elasticpath.cortex.purchase.PurchaseFragment.java
/** * This method gets the order details/*w w w.j ava 2 s .c om*/ * * @param urlOrder */ public void getOrderDetails(String urlOrder) { mOrderDetailsListener = new ListenerOrderDetails() { @Override public void onTaskSuccessful(OrderModel response) { mObjOrder = response; getActivity().runOnUiThread(new Runnable() { @Override public void run() { showProgressDialog(false); setUpViews(); } }); } @Override public void onTaskFailed(final int errorCode) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { showProgressDialog(false); // TODO - For Future Req NotificationUtils.showErrorToast(getActivity(), errorCode); } }); } @Override public void onAuthenticationFailed() { getActivity().runOnUiThread(new Runnable() { @Override public void run() { showProgressDialog(false); // TODO For Future Req NotificationUtils.showErrorToast(getActivity(), Constants.ErrorCodes.ERROR_SERVER); } }); } }; showProgressDialog(true); mLayout.setVisibility(View.INVISIBLE); if (!TextUtils.isEmpty(urlOrder) && URLUtil.isValidUrl(urlOrder)) { OrderModel.getOrderDetails(getActivity(), urlOrder, getUserAuthenticationToken(), mOrderDetailsListener); } }
From source file:com.dm.material.dashboard.candybar.fragments.dialog.AboutFragment.java
private void initProfileImage() { String url = getActivity().getResources().getString(R.string.about_profile_image); if (URLUtil.isValidUrl(url)) { ImageLoader.getInstance().displayImage(url, mProfile, ImageConfig.getImageOptions(true, Preferences.getPreferences(getActivity()).isCacheAllowed())); } else {//from w ww. j a v a 2s . co m int res = DrawableHelper.getResourceId(getActivity(), url); if (res > 0) mProfile.setImageDrawable(ContextCompat.getDrawable(getActivity(), res)); } }
From source file:org.qeo.android.security.OtcDialog.java
/** * validInputData helper methods to check when Authenticate Button can be enabled. * /*from w w w.j av a2s . c om*/ * @param otcText * @param urlText * @return boolean true if otcText and urlText are valid as input data */ private InputValidationResult validateInputData(String otcText, String urlText) { if (null == otcText || null == urlText || TextUtils.isEmpty(otcText) || TextUtils.isEmpty(urlText)) { return InputValidationResult.INPUT_NOK; } if (!URLUtil.isValidUrl(urlText)) { return InputValidationResult.INPUT_NOK; } return InputValidationResult.INPUT_OK; }
From source file:com.remdo.app.EditDeviceActivity.java
/** * Check if fields match defined rules and if deviceName or url already exist * @return//from ww w. j a v a 2 s . c o m */ public boolean checkFields() { mDeviceName = mDeviceNameView.getText().toString(); mHost = mHostView.getText().toString(); mUser = mUserView.getText().toString(); mPassword = mPasswordView.getText().toString(); boolean cancel = false; View focusView = null; // check device name field if (TextUtils.isEmpty(mDeviceName)) { mDeviceNameView.setError(getString(R.string.error_required_field)); focusView = mDeviceNameView; cancel = true; } if (EditMode == false && dh.DeviceExists(mDeviceName, "name")) { mHostView.setError(getString(R.string.error_existing_device)); if (!cancel) { focusView = mDeviceNameView; cancel = true; } } // check server field if (TextUtils.isEmpty(mHost)) { mHostView.setError(getString(R.string.error_required_field)); if (!cancel) { focusView = mHostView; cancel = true; } } if (!URLUtil.isValidUrl(mHost)) { mHostView.setError(getString(R.string.error_invalid_url)); focusView = mHostView; cancel = true; } if (EditMode == false && dh.DeviceExists(mHost, "url")) { mHostView.setError(getString(R.string.error_existing_device)); if (!cancel) { focusView = mHostView; cancel = true; } } // check user field if (TextUtils.isEmpty(mUser)) { mUserView.setError(getString(R.string.error_required_field)); if (!cancel) { focusView = mUserView; cancel = true; } } // check password field if (TextUtils.isEmpty(mPassword)) { mPasswordView.setError(getString(R.string.error_required_field)); if (!cancel) { focusView = mPasswordView; cancel = true; } } if (cancel) { // on error do not save the device focusView.requestFocus(); return false; } else { return true; } }
From source file:fr.alecanu.samplerssreader.RssReaderActivity.java
private void changeURL() { AlertDialog.Builder builder = new AlertDialog.Builder(this); final EditText input = new EditText(this); builder.setTitle(getString(R.string.title_change_url)).setMessage(getString(R.string.message_change_url)) .setView(input).setCancelable(false) .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { if (Patterns.WEB_URL.matcher(input.getText().toString()).matches()) { if (URLUtil.isValidUrl(input.getText().toString())) { url = input.getText().toString(); } else { url = HTTP + input.getText().toString(); }//ww w. j av a2s .c om SharedPreferences.Editor edit = PreferenceManager .getDefaultSharedPreferences(getApplicationContext()).edit(); edit.putBoolean(PREFERENCE_SETUP, true); edit.putString(PREFERENCE_URL, url); edit.commit(); refreshList(); } else { new AlertDialog.Builder(RssReaderActivity.this).setCancelable(false) .setMessage(getString(R.string.fail_url)) .setNeutralButton(getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { arg0.dismiss(); changeURL(); } }) .create().show(); } } }).setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { if (!PreferenceManager.getDefaultSharedPreferences(getApplicationContext()) .getBoolean(PREFERENCE_SETUP, false)) { finish(); } else { dialog.dismiss(); } } }); builder.create().show(); }
From source file:com.sayar.requests.RequestArguments.java
/** * @param url/*from ww w . j a v a2s . co m*/ * @return */ private boolean validUrl(final String url) { return !TextUtils.isEmpty(url) && URLUtil.isValidUrl(url); }
From source file:de.electricdynamite.pasty.ClipboardFragment.java
@Override public void onLoadFinished(Loader<PastyLoader.PastyResponse> loader, PastyLoader.PastyResponse response) { ProgressBar pbLoading = (ProgressBar) getSherlockActivity().findViewById(R.id.progressbar_downloading); pbLoading.setVisibility(View.GONE); pbLoading = null;/*from w w w . ja v a 2 s . c o m*/ mHelpTextBig.setTextColor(getResources().getColor(R.color.abs__primary_text_holo_light)); mHelpTextBig.setBackgroundDrawable(mBackground); if (response.isFinal) { getSherlockActivity().setSupportProgressBarIndeterminateVisibility(Boolean.FALSE); if (response.getResultSource() == PastyResponse.SOURCE_CACHE) { Toast.makeText(getSherlockActivity().getApplicationContext(), getString(R.string.warning_no_network_short), Toast.LENGTH_SHORT).show(); } } if (response.hasException) { if (LOCAL_LOG) Log.v(TAG, "onLoadFinished(): Loader delivered exception; calling handleException()"); // an error occured getSherlockActivity().setSupportProgressBarIndeterminateVisibility(Boolean.FALSE); PastyException mException = response.getException(); handleException(mException); } else { switch (loader.getId()) { case PastyLoader.TASK_CLIPBOARD_FETCH: JSONArray Clipboard = response.getClipboard(); mItems.clear(); mAdapter.notifyDataSetChanged(); getListView().invalidateViews(); try { if (Clipboard.length() == 0) { //Clipboard is empty mHelpTextBig.setText(R.string.helptext_PastyActivity_clipboard_empty); mHelpTextSmall.setText(R.string.helptext_PastyActivity_how_to_add); } else { for (int i = 0; i < Clipboard.length(); i++) { JSONObject Item = Clipboard.getJSONObject(i); ClipboardItem cbItem = new ClipboardItem(Item.getString("_id"), Item.getString("item")); this.mItems.add(cbItem); } mHelpTextBig.setText(R.string.helptext_PastyActivity_copy); mHelpTextSmall.setText(R.string.helptext_PastyActivity_options); //Assign adapter to ListView ListView listView = (ListView) getSherlockActivity().findViewById(R.id.listItems); listView.setAdapter(mAdapter); listView.setItemsCanFocus(false); listView.setOnItemClickListener(new OnItemClickListener() { @SuppressLint("NewApi") @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ClipboardItem Item = mItems.get(position); // get a ClipboardItem from the clicked position if (Item.isLinkified() && prefs.getClickableLinks()) { /* If the clicked item was originally linkified and prefs.getClickableLinks() is true, we manually * fire an ACTION_VIEW intent to simulate Linkify() behavior */ String url = Item.getText(); if (!URLUtil.isValidUrl(url)) url = "http://" + url; Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); } else { /* Else we copy the item to the systems clipboard, * show a Toast and finish() the activity */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { android.content.ClipboardManager sysClipboard = (android.content.ClipboardManager) getSherlockActivity() .getSystemService(Context.CLIPBOARD_SERVICE); Item.copyToClipboard(sysClipboard); sysClipboard = null; } else { ClipboardManager sysClipboard = (ClipboardManager) getSherlockActivity() .getSystemService(Context.CLIPBOARD_SERVICE); Item.copyToClipboard(sysClipboard); sysClipboard = null; } Toast.makeText(getSherlockActivity().getApplicationContext(), getString(R.string.item_copied), Toast.LENGTH_LONG).show(); getSherlockActivity().finish(); } } }); registerForContextMenu(listView); } } catch (Exception e) { e.printStackTrace(); } break; default: break; } } }
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 ww . j ava 2 s. c o m*/ Toast.makeText(getActivity(), R.string.error_msg_invalid_url, Toast.LENGTH_LONG).show(); return false; }
From source file:com.teinproductions.tein.papyrosprogress.MainActivity.java
public static void openWebPage(MainActivity activity, String URL) { if (URLUtil.isValidUrl(URL)) { if (PreferenceManager.getDefaultSharedPreferences(activity).getBoolean("use_custom_tabs", true)) { activity.tabsHelper.openURL(activity, URL); } else {//from w ww . ja v a2s. c o m Uri webPage = Uri.parse(URL); Intent intent = new Intent(Intent.ACTION_VIEW, webPage); PackageManager packageManager = activity.getPackageManager(); List activities = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (activities.size() > 0) { activity.startActivity(intent); } } } }