Search in sources :

Example 51 with URLSpan

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);
    }
}
Also used : URLSpan(android.text.style.URLSpan) SuppressLint(android.annotation.SuppressLint)

Example 52 with URLSpan

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;
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) URLSpan(android.text.style.URLSpan)

Example 53 with URLSpan

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;
}
Also used : Cursor(android.database.Cursor) URLSpan(android.text.style.URLSpan) Spannable(android.text.Spannable)

Example 54 with URLSpan

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;
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) URLSpan(android.text.style.URLSpan)

Example 55 with URLSpan

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;
}
Also used : TelephonyManager(android.telephony.TelephonyManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) URLSpan(android.text.style.URLSpan)

Aggregations

URLSpan (android.text.style.URLSpan)134 SpannableString (android.text.SpannableString)36 Spannable (android.text.Spannable)22 SpannableStringBuilder (android.text.SpannableStringBuilder)21 TextPaint (android.text.TextPaint)21 Spanned (android.text.Spanned)20 TextView (android.widget.TextView)19 ForegroundColorSpan (android.text.style.ForegroundColorSpan)16 StyleSpan (android.text.style.StyleSpan)16 UnderlineSpan (android.text.style.UnderlineSpan)14 Paint (android.graphics.Paint)13 ImageSpan (android.text.style.ImageSpan)13 StrikethroughSpan (android.text.style.StrikethroughSpan)13 TypefaceSpan (android.text.style.TypefaceSpan)13 View (android.view.View)13 Intent (android.content.Intent)12 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)12 BackgroundColorSpan (android.text.style.BackgroundColorSpan)12 ClickableSpan (android.text.style.ClickableSpan)12 SubscriptSpan (android.text.style.SubscriptSpan)12