List of usage examples for android.util Patterns WEB_URL
Pattern WEB_URL
To view the source code for android.util Patterns WEB_URL.
Click Source Link
From source file:org.jraf.android.downloadandshareimage.app.downloadandshare.DownloadAndShareActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mUrl = getIntent().getStringExtra(Intent.EXTRA_TEXT); Log.d("mUrl=" + mUrl); // Check for valid URL boolean isUrl = mUrl != null && Patterns.WEB_URL.matcher(mUrl).matches(); if (!isUrl) { Log.w("invalid valid URL " + mUrl); Toast.makeText(this, R.string.error_invalidUrl, Toast.LENGTH_LONG).show(); finish();/*ww w . j a va2 s.c o m*/ return; } startDownload(); }
From source file:at.metalab.donarsson.screeninvader.InvadeScreen.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService( Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (networkInfo.isConnected()) { //TODO: Check if we know a ScreenInvader on this network Intent intent = getIntent();/*from w ww . j a v a 2s. c o m*/ String type = intent.getType(); if (type.startsWith("text/")) { String text = intent.getStringExtra(Intent.EXTRA_TEXT); Pattern pattern = Patterns.WEB_URL; Matcher matcher = pattern.matcher(text); while (matcher.find()) { String url = matcher.group(); new PostUrlTask().execute(url); } } //TODO: Add support for other types (file upload) } else { //TODO: Display a prompt to connect to a WiFi Toast.makeText(getApplicationContext(), getString(R.string.no_wifi_toast), Toast.LENGTH_LONG).show(); } finish(); }
From source file:org.sufficientlysecure.keychain.ui.linked.LinkedIdCreateHttpsStep1Fragment.java
private static boolean checkUri(String uri) { return Patterns.WEB_URL.matcher(uri).matches(); }
From source file:com.google.samples.apps.ourstreets.view.ViewUtils.java
/** * Sets a text on a {@link TextView}, provided via viewResId, within a parent view. * If there's a web url in the tag the text will be converted from Html, respecting tags. * * @param parent The view's parent.//from w w w . ja v a 2 s. c o m * @param viewResId The resource to resolve. * @param text The text to set. */ public static void setTextOn(@NonNull View parent, @IdRes int viewResId, @Nullable CharSequence text) { if (TextUtils.isEmpty(text)) { text = ""; } View view = parent.findViewById(viewResId); if (view instanceof TextView) { TextView textView = (TextView) view; // Only perform Html conversion if there's actually an Url in the text. if (Patterns.WEB_URL.matcher(text).find()) { textView.setText(Html.fromHtml(text.toString())); textView.setMovementMethod(LinkMovementMethod.getInstance()); } else { textView.setText(text); } } }
From source file:com.daiv.android.twitter.services.SendQueue.java
public int getCount(String text) { if (!text.contains("http")) { // no links, normal tweet return text.length(); } else {//ww w . ja v a 2s .co m int count = text.length(); Matcher m = Patterns.WEB_URL.matcher(text); while (m.find()) { String url = m.group(); count -= url.length(); // take out the length of the url count += 23; // add 23 for the shortened url } return count; } }
From source file:me.philio.ghost.ui.LoginUrlFragment.java
@OnClick(R.id.btn_validate) @Override// w ww .ja v a2s . c om public void onClick(final View v) { switch (v.getId()) { case R.id.btn_validate: // Make sure URL is all lower case and remove trailing slashes String url = mEditUrl.getText().toString().trim().toLowerCase(); while (url.endsWith("/")) { url = url.substring(0, url.length() - 1); } mEditUrl.setText(url); // Check that the URL looks valid if (mEditUrl.getText().toString().isEmpty()) { mEditUrl.setError(getString(R.string.error_field_required)); } else if (!Patterns.WEB_URL.matcher(mEditUrl.getText().toString()).matches()) { mEditUrl.setError(getString(R.string.error_invalid_url)); } else { mEditUrl.setError(null); mBtnValidate.setEnabled(false); ((LoginActivity) getActivity()).setToolbarProgressBarVisibility(true); // Try and check for a valid ghost install at the URL // We're expecting a 401 with a JSON response mBlogUrl = mSpinnerScheme.getSelectedItem().toString() + mEditUrl.getText().toString(); // Run discovery test GhostClient client = new GhostClient(mBlogUrl); Discovery discovery = client.createDiscovery(); discovery.test(this); } break; } }
From source file:com.heske.alexandria.activities.BookDetailFragment.java
public void displayBook(String ean) { mBook = DbUtils.dbLookupBook(mActivity, ean); if (mBook == null) return;/*from w w w. j a v a 2 s .c om*/ if (mShareActionProvider != null) mShareActionProvider.setShareIntent(getShareIntent()); String bookSubTitle = mBook.getSubtitle(); if (bookSubTitle.isEmpty()) tvBookTitle.setText(mBook.getTitle()); else tvBookTitle.setText(mBook.getTitle() + ": " + mBook.getSubtitle()); tvBookDesc.setText(mBook.getDescription()); String authors = mBook.getAuthors().get(0); tvAuthors.setText(authors); StringBuilder strISBN = new StringBuilder(mBook.getBookId()); strISBN.insert(3, "-"); tvISBN.setText("ISBN-13: " + strISBN); tvCategories.setText(mBook.getCategories().get(0)); String imgUrl = mBook.getThumbnail(); if (Patterns.WEB_URL.matcher(imgUrl).matches()) { Picasso.with(getActivity()).load(imgUrl).placeholder(R.mipmap.ic_launcher).error(R.mipmap.ic_launcher) .into(imgBookCover); imgBookCover.setVisibility(View.VISIBLE); } }
From source file:com.wit.android.support.content.intent.WebIntent.java
/** *///from w ww .j a va 2s. c om @Nullable @Override public Intent buildIntent() { if (TextUtils.isEmpty(mUrl)) { Log.e(TAG, "Can not to create a WEB intent. No URL specified."); return null; } else if (!Patterns.WEB_URL.matcher(mUrl).matches()) { Log.e(TAG, "Can not to create a WEB intent. Invalid URL('" + mUrl + "')."); return null; } /** * Build and start the intent. */ return new Intent(Intent.ACTION_VIEW, Uri.parse(mUrl)); }
From source file:com.jpventura.alexandria.BookDetail.java
@Override public void onLoadFinished(android.support.v4.content.Loader<Cursor> loader, Cursor data) { if (!data.moveToFirst()) { return;// www .j av a2 s . co m } bookTitle = data.getString(data.getColumnIndex(AlexandriaContract.BookEntry.TITLE)); ((TextView) rootView.findViewById(R.id.fullBookTitle)).setText(bookTitle); Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); shareIntent.setType("text/plain"); shareIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_text) + bookTitle); shareActionProvider.setShareIntent(shareIntent); String bookSubTitle = data.getString(data.getColumnIndex(AlexandriaContract.BookEntry.SUBTITLE)); ((TextView) rootView.findViewById(R.id.fullBookSubTitle)).setText(bookSubTitle); String desc = data.getString(data.getColumnIndex(AlexandriaContract.BookEntry.DESC)); ((TextView) rootView.findViewById(R.id.fullBookDesc)).setText(desc); String authors = data.getString(data.getColumnIndex(AlexandriaContract.AuthorEntry.AUTHOR)); String[] authorsArr = authors.split(","); ((TextView) rootView.findViewById(R.id.authors)).setLines(authorsArr.length); ((TextView) rootView.findViewById(R.id.authors)).setText(authors.replace(",", "\n")); String imgUrl = data.getString(data.getColumnIndex(AlexandriaContract.BookEntry.IMAGE_URL)); if (Patterns.WEB_URL.matcher(imgUrl).matches()) { new DownloadImage((ImageView) rootView.findViewById(R.id.fullBookCover)).execute(imgUrl); rootView.findViewById(R.id.fullBookCover).setVisibility(View.VISIBLE); } String categories = data.getString(data.getColumnIndex(AlexandriaContract.CategoryEntry.CATEGORY)); ((TextView) rootView.findViewById(R.id.categories)).setText(categories); if (rootView.findViewById(R.id.right_container) != null) { rootView.findViewById(R.id.backButton).setVisibility(View.INVISIBLE); } }
From source file:com.nbplus.vbroadlistener.gcm.MyGcmListenerService.java
/** * Called when message is received./*from w ww .ja va 2s . com*/ * * @param from SenderID of the sender. * @param data Data bundle containing message data as key/value pairs. * For Set of keys use data.keySet(). */ // [START receive_message] @Override public void onMessageReceived(String from, Bundle data) { Log.d(TAG, "From: " + from); String alert = data.getString(Constants.GCM_DATA_KEY_ALERT); Log.d(TAG, "Alert: " + alert); String messageId = data.getString(Constants.GCM_DATA_KEY_MESSAGE_ID); Log.d(TAG, "MessagID: " + messageId); String payload = data.getString(Constants.GCM_DATA_KEY_PAYLOAD); Intent pi = null; String moveUrl = null; int notificationId = 0; PushPayloadData payloadData = null; try { Gson gson = new GsonBuilder().create(); payloadData = gson.fromJson(payload, new TypeToken<PushPayloadData>() { }.getType()); } catch (Exception e) { e.printStackTrace(); } if (payloadData == null) { Log.d(TAG, "empty push message data !!"); return; } String type = payloadData.getServiceType(); payloadData.setAlertMessage(alert); payloadData.setMessageId(messageId); /** * 2014. 08. 08 * ? + ? ? ?? * Notification? ?. */ switch (type) { // case Constants.PUSH_PAYLOAD_TYPE_REALTIME_BROADCAST: case Constants.PUSH_PAYLOAD_TYPE_NORMAL_BROADCAST: case Constants.PUSH_PAYLOAD_TYPE_TEXT_BROADCAST: pi = new Intent(this, BroadcastWebViewActivity.class); pi.setAction(Constants.ACTION_SHOW_NOTIFICATION_CONTENTS); if (!StringUtils.isEmptyString(payloadData.getMessage()) && Patterns.WEB_URL.matcher(payloadData.getMessage()).matches()) { moveUrl = payloadData.getMessage(); } else { VBroadcastServer server = LauncherSettings.getInstance(this).getServerInformation(); if (server == null || StringUtils.isEmptyString(server.getDocServer())) { moveUrl = LauncherSettings.getInstance(this).getRegisterAddress(); } else { moveUrl = server.getDocServer() + Constants.BROADCAST_LIST_CONTEXT_PATH; } } Log.d(TAG, ">>> Broadcast noti push url = " + moveUrl); pi.putExtra(Constants.EXTRA_SHOW_NOTIFICATION_CONTENTS, moveUrl); //notificationId = Constants.BROADCAST_EVENT_NOTIFICATION_ID; try { notificationId += Integer.parseInt(payloadData.getMessageId()); } catch (NumberFormatException e) { e.printStackTrace(); notificationId = Constants.BROADCAST_EVENT_NOTIFICATION_ID; } Log.d(TAG, ">>> notificationId = " + notificationId); pi.putExtra("messageId", notificationId); showNotification(this, notificationId, R.drawable.ic_notification_radio, PackageUtils.getApplicationName(this), payloadData.getAlertMessage(), null, pi); break; // case Constants.PUSH_PAYLOAD_TYPE_EMERGENCY_CALL: Log.d(TAG, ">> Constants.PUSH_PAYLOAD_TYPE_EMERGENCY_CALL = " + payloadData.getAlertMessage()); final String lat = payloadData.getLatitude(); final String lon = payloadData.getLongitude(); if (!StringUtils.isEmptyString(lat) && !StringUtils.isEmptyString(lon)) { Log.d(TAG, ">> Emergency geocode lat = " + lat + ", lon = " + lon); pi = new Intent(this, BroadcastWebViewActivity.class); pi.setAction(Constants.ACTION_SHOW_NOTIFICATION_EMERGENCY_CALL); pi.putExtra(Constants.EXTRA_SHOW_NOTIFICATION_EMERGENCY_LAT, lat); pi.putExtra(Constants.EXTRA_SHOW_NOTIFICATION_EMERGENCY_LON, lon); } pi.putExtra(Constants.EXTRA_SHOW_NOTIFICATION_CONTENTS, moveUrl); //notificationId = Constants.EMERGENCY_CALL_EVENT_NOTIFICATION_ID; try { notificationId += Integer.parseInt(payloadData.getMessageId()); } catch (NumberFormatException e) { e.printStackTrace(); notificationId = Constants.EMERGENCY_CALL_EVENT_NOTIFICATION_ID; } if (StringUtils.isEmptyString(payloadData.getMessage())) { showNotification(this, notificationId, R.drawable.ic_notification_noti, PackageUtils.getApplicationName(this), payloadData.getAlertMessage(), null, pi); } else { // bigText Log.d(TAG, ">> Constants.PUSH_PAYLOAD_TYPE_EMERGENCY_CALL bigText = " + payloadData.getMessage()); showNotification(this, notificationId, R.drawable.ic_notification_noti, PackageUtils.getApplicationName(this), payloadData.getAlertMessage(), PackageUtils.getApplicationName(this), payloadData.getMessage(), null, null, pi); } break; // case Constants.PUSH_PAYLOAD_TYPE_INHABITANTS_POLL: pi = new Intent(this, BroadcastWebViewActivity.class); pi.setAction(Constants.ACTION_SHOW_NOTIFICATION_CONTENTS); if (!StringUtils.isEmptyString(payloadData.getMessage()) && Patterns.WEB_URL.matcher(payloadData.getMessage()).matches()) { moveUrl = payloadData.getMessage(); } else { VBroadcastServer server = LauncherSettings.getInstance(this).getServerInformation(); if (server == null || StringUtils.isEmptyString(server.getDocServer())) { moveUrl = LauncherSettings.getInstance(this).getRegisterAddress(); } else { moveUrl = server.getDocServer() + Constants.INHABITANT_POLL_LIST_CONTEXT_PATH; } } //notificationId = Constants.INHABITANT_POLL_EVENT_NOTIFICATION_ID; try { notificationId += Integer.parseInt(payloadData.getMessageId()); } catch (NumberFormatException e) { e.printStackTrace(); notificationId = Constants.INHABITANT_POLL_EVENT_NOTIFICATION_ID; } pi.putExtra(Constants.EXTRA_SHOW_NOTIFICATION_CONTENTS, moveUrl); showNotification(this, notificationId, R.drawable.ic_notification_noti, PackageUtils.getApplicationName(this), payloadData.getAlertMessage(), null, pi); break; // ? case Constants.PUSH_PAYLOAD_TYPE_COOPERATIVE_BUYING: pi = new Intent(this, BroadcastWebViewActivity.class); pi.setAction(Constants.ACTION_SHOW_NOTIFICATION_CONTENTS); if (!StringUtils.isEmptyString(payloadData.getMessage()) && Patterns.WEB_URL.matcher(payloadData.getMessage()).matches()) { moveUrl = payloadData.getMessage(); } else { VBroadcastServer server = LauncherSettings.getInstance(this).getServerInformation(); if (server == null || StringUtils.isEmptyString(server.getDocServer())) { moveUrl = LauncherSettings.getInstance(this).getRegisterAddress(); } else { moveUrl = server.getDocServer() + Constants.COOPERATIVE_BUYING_LIST_CONTEXT_PATH; } } pi.putExtra(Constants.EXTRA_SHOW_NOTIFICATION_CONTENTS, moveUrl); //notificationId = Constants.COOPERATIVE_BUYING_EVENT_NOTIFICATION_ID; try { notificationId += Integer.parseInt(payloadData.getMessageId()); } catch (NumberFormatException e) { e.printStackTrace(); notificationId = Constants.COOPERATIVE_BUYING_EVENT_NOTIFICATION_ID; } showNotification(this, notificationId, R.drawable.ic_notification_noti, PackageUtils.getApplicationName(this), payloadData.getAlertMessage(), null, pi); break; // IOT DEVICE ( ) case Constants.PUSH_PAYLOAD_TYPE_IOT_DEVICE_CONTROL: // ?. break; // ??. case Constants.PUSH_PAYLOAD_TYPE_PUSH_NOTIFICATION: // ?... // pi = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(payloadData.getMessage())); // showNotification(context, Constants.SYSTEM_ADMIN_NOTIFICATION_ID, PackageUtils.getApplicationName(context), payloadData.getAlertMessage(), null, pi); pi.putExtra(Constants.EXTRA_SHOW_NOTIFICATION_CONTENTS, moveUrl); //notificationId = Constants.SYSTEM_ADMIN_NOTIFICATION_ID; try { notificationId += Integer.parseInt(payloadData.getMessageId()); } catch (NumberFormatException e) { e.printStackTrace(); notificationId = Constants.SYSTEM_ADMIN_NOTIFICATION_ID; } // bigText showNotification(this, notificationId, R.drawable.ic_notification_noti, PackageUtils.getApplicationName(this), payloadData.getAlertMessage(), PackageUtils.getApplicationName(this), payloadData.getMessage(), null, null, null); break; // case Constants.PUSH_PAYLOAD_TYPE_FIND_PASSWORD: pi = new Intent(this, BroadcastWebViewActivity.class); pi.setAction(Constants.ACTION_SHOW_NOTIFICATION_CONTENTS); if (!StringUtils.isEmptyString(payloadData.getMessage()) && Patterns.WEB_URL.matcher(payloadData.getMessage()).matches()) { moveUrl = payloadData.getMessage(); } else { Log.e(TAG, "wrong password find .... url "); } pi.putExtra(Constants.EXTRA_SHOW_NOTIFICATION_CONTENTS, moveUrl); showNotification(this, Constants.PW_FIND_NOTIFICATION_ID, R.drawable.ic_notification_noti, PackageUtils.getApplicationName(this), payloadData.getAlertMessage(), null, pi); break; default: Log.d(TAG, "Unknown push payload type !!!"); break; } VBroadcastServer server = LauncherSettings.getInstance(this).getServerInformation(); if (server != null && !StringUtils.isEmptyString(server.getApiServer())) { SendGcmResultTask task = new SendGcmResultTask(); if (task != null) { task.setSendGcmResultData(this, server.getApiServer() + Constants.API_GCM_SEND_RESULT_CONTEXT_PATH, payloadData.getMessageId()); task.execute(); } } }