use of android.text.style.URLSpan in project Conversations by siacs.
the class FixedURLSpan method fix.
public static void fix(final Editable editable) {
for (final URLSpan urlspan : editable.getSpans(0, editable.length() - 1, URLSpan.class)) {
final int start = editable.getSpanStart(urlspan);
final int end = editable.getSpanEnd(urlspan);
editable.removeSpan(urlspan);
editable.setSpan(new FixedURLSpan(urlspan.getURL()), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
use of android.text.style.URLSpan in project Etar-Calendar by Etar-Group.
the class AlertReceiver method createMapActivityIntent.
/**
* Create an intent to take the user to maps, using the first map link available.
* If no links are found, return null.
*/
private static Intent createMapActivityIntent(Context context, URLSpan[] urlSpans) {
for (int span_i = 0; span_i < urlSpans.length; span_i++) {
URLSpan urlSpan = urlSpans[span_i];
String urlString = urlSpan.getURL();
if (urlString.startsWith(GEO_PREFIX)) {
Intent geoIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlString));
geoIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return geoIntent;
}
}
// No geo link was found, so return null;
return null;
}
use of android.text.style.URLSpan in project Etar-Calendar by Etar-Group.
the class AlertReceiver method getURLSpans.
/**
* Using the linkify magic, get a list of URLs from the event's location. If no such links
* are found, we should end up with a single geo link of the entire string.
*/
private static URLSpan[] getURLSpans(Context context, long eventId) {
Cursor locationCursor = getLocationCursor(context, eventId);
// Default to empty list
URLSpan[] urlSpans = new URLSpan[0];
if (locationCursor != null && locationCursor.moveToFirst()) {
// Only one item in this cursor.
String location = locationCursor.getString(0);
if (location != null && !location.isEmpty()) {
Spannable text = Utils.extendedLinkify(location, true);
// The linkify method should have found at least one link, at the very least.
// If no smart links were found, it should have set the whole string as a geo link.
urlSpans = text.getSpans(0, text.length(), URLSpan.class);
}
locationCursor.close();
}
return urlSpans;
}
use of android.text.style.URLSpan in project Etar-Calendar by Etar-Group.
the class AlertReceiver method createMapBroadcastIntent.
/**
* Create a pending intent to send ourself a broadcast to start maps, using the first map
* link available.
* If no links or resolved applications are found, return null.
*/
private static PendingIntent createMapBroadcastIntent(Context context, URLSpan[] urlSpans, long eventId) {
for (int span_i = 0; span_i < urlSpans.length; span_i++) {
URLSpan urlSpan = urlSpans[span_i];
String urlString = urlSpan.getURL();
if (urlString.startsWith(GEO_PREFIX)) {
Intent geoIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlString));
geoIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// If this intent cannot be handled, do not create the map action
if (isResolveIntent(context, geoIntent)) {
Intent broadcastIntent = new Intent(MAP_ACTION);
broadcastIntent.setClass(context, AlertReceiver.class);
broadcastIntent.putExtra(EXTRA_EVENT_ID, eventId);
return PendingIntent.getBroadcast(context, Long.valueOf(eventId).hashCode(), broadcastIntent, PendingIntent.FLAG_CANCEL_CURRENT | Utils.PI_FLAG_IMMUTABLE);
}
}
}
// No geo link was found, so return null;
return null;
}
use of android.text.style.URLSpan in project Etar-Calendar by Etar-Group.
the class AlertReceiver method createCallBroadcastIntent.
/**
* Create a pending intent to send ourself a broadcast to take the user to dialer, or any other
* app capable of making phone calls. Use the first phone number available. If no phone number
* is found, or if the device is not capable of making phone calls (i.e. a tablet), return null.
*/
private static PendingIntent createCallBroadcastIntent(Context context, URLSpan[] urlSpans, long eventId) {
// Return null if the device is unable to make phone calls.
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (tm.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE) {
return null;
}
for (int span_i = 0; span_i < urlSpans.length; span_i++) {
URLSpan urlSpan = urlSpans[span_i];
String urlString = urlSpan.getURL();
if (urlString.startsWith(TEL_PREFIX)) {
Intent broadcastIntent = new Intent(CALL_ACTION);
broadcastIntent.setClass(context, AlertReceiver.class);
broadcastIntent.putExtra(EXTRA_EVENT_ID, eventId);
return PendingIntent.getBroadcast(context, Long.valueOf(eventId).hashCode(), broadcastIntent, PendingIntent.FLAG_CANCEL_CURRENT | Utils.PI_FLAG_IMMUTABLE);
}
}
// No tel link was found, so return null;
return null;
}
Aggregations