Search in sources :

Example 16 with LinkMovementMethod

use of android.text.method.LinkMovementMethod in project android_frameworks_base by DirtyUnicorns.

the class LinkifyTest method testUnclickable.

@SmallTest
public void testUnclickable() throws Exception {
    TextView tv;
    tv = new TextView(getContext());
    tv.setAutoLinkMask(Linkify.ALL);
    tv.setLinksClickable(false);
    tv.setText("Hey, foo@google.com, call 415-555-1212.");
    assertFalse(tv.getMovementMethod() instanceof LinkMovementMethod);
    assertTrue(tv.getUrls().length == 2);
}
Also used : LinkMovementMethod(android.text.method.LinkMovementMethod) TextView(android.widget.TextView) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 17 with LinkMovementMethod

use of android.text.method.LinkMovementMethod in project android_packages_apps_Settings by omnirom.

the class LinkablePreference method onBindViewHolder.

@Override
public void onBindViewHolder(PreferenceViewHolder view) {
    super.onBindViewHolder(view);
    TextView textView = (TextView) view.findViewById(android.R.id.title);
    if (textView == null) {
        return;
    }
    textView.setSingleLine(false);
    if (mContentTitle == null || mClickListener == null) {
        return;
    }
    StringBuilder contentBuilder = new StringBuilder().append(mContentTitle);
    if (mContentDescription != null) {
        contentBuilder.append("\n\n");
        contentBuilder.append(mContentDescription);
    }
    boolean linked = LinkifyUtils.linkify(textView, contentBuilder, mClickListener);
    if (linked && mContentTitle != null) {
        // Embolden and enlarge the title.
        Spannable boldSpan = (Spannable) textView.getText();
        boldSpan.setSpan(new TextAppearanceSpan(getContext(), android.R.style.TextAppearance_Medium), 0, mContentTitle.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
        textView.setText(boldSpan);
        textView.setMovementMethod(new LinkMovementMethod());
    }
}
Also used : TextAppearanceSpan(android.text.style.TextAppearanceSpan) LinkMovementMethod(android.text.method.LinkMovementMethod) TextView(android.widget.TextView) Spannable(android.text.Spannable)

Example 18 with LinkMovementMethod

use of android.text.method.LinkMovementMethod in project android_packages_apps_Settings by crdroidandroid.

the class LinkablePreference method onBindViewHolder.

@Override
public void onBindViewHolder(PreferenceViewHolder view) {
    super.onBindViewHolder(view);
    TextView textView = (TextView) view.findViewById(android.R.id.title);
    if (textView == null) {
        return;
    }
    textView.setSingleLine(false);
    if (mContentTitle == null || mClickListener == null) {
        return;
    }
    StringBuilder contentBuilder = new StringBuilder().append(mContentTitle);
    if (mContentDescription != null) {
        contentBuilder.append("\n\n");
        contentBuilder.append(mContentDescription);
    }
    boolean linked = LinkifyUtils.linkify(textView, contentBuilder, mClickListener);
    if (linked && mContentTitle != null) {
        // Embolden and enlarge the title.
        Spannable boldSpan = (Spannable) textView.getText();
        boldSpan.setSpan(new TextAppearanceSpan(getContext(), android.R.style.TextAppearance_Medium), 0, mContentTitle.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
        textView.setText(boldSpan);
        textView.setMovementMethod(new LinkMovementMethod());
    }
}
Also used : TextAppearanceSpan(android.text.style.TextAppearanceSpan) LinkMovementMethod(android.text.method.LinkMovementMethod) TextView(android.widget.TextView) Spannable(android.text.Spannable)

Example 19 with LinkMovementMethod

use of android.text.method.LinkMovementMethod in project iNaturalistAndroid by inaturalist.

the class UserActivitiesAdapter method clickify.

public void clickify(TextView view, final String clickableText, final OnClickListener listener) {
    CharSequence text = view.getText();
    String string = text.toString();
    ClickSpan span = new ClickSpan(listener);
    int start = string.indexOf(clickableText);
    int end = start + clickableText.length();
    if (start == -1)
        return;
    if (text instanceof Spannable) {
        ((Spannable) text).setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    } else {
        SpannableString s = SpannableString.valueOf(text);
        s.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        view.setText(s);
    }
    MovementMethod m = view.getMovementMethod();
    if ((m == null) || !(m instanceof LinkMovementMethod)) {
        view.setMovementMethod(LinkMovementMethod.getInstance());
    }
}
Also used : SpannableString(android.text.SpannableString) LinkMovementMethod(android.text.method.LinkMovementMethod) MovementMethod(android.text.method.MovementMethod) LinkMovementMethod(android.text.method.LinkMovementMethod) SpannableString(android.text.SpannableString) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) Spannable(android.text.Spannable)

Example 20 with LinkMovementMethod

use of android.text.method.LinkMovementMethod in project Etar-Calendar by Etar-Group.

the class EventInfoFragment method updateEvent.

private void updateEvent(View view) {
    if (mEventCursor == null || view == null) {
        return;
    }
    Context context = view.getContext();
    if (context == null) {
        return;
    }
    String eventName = mEventCursor.getString(EVENT_INDEX_TITLE);
    if (eventName == null || eventName.length() == 0) {
        eventName = getActivity().getString(R.string.no_title_label);
    }
    // Events.CONTENT_URI intent.  Update these with values read from the db.
    if (mStartMillis == 0 && mEndMillis == 0) {
        mStartMillis = mEventCursor.getLong(EVENT_INDEX_DTSTART);
        mEndMillis = mEventCursor.getLong(EVENT_INDEX_DTEND);
        if (mEndMillis == 0) {
            String duration = mEventCursor.getString(EVENT_INDEX_DURATION);
            if (!TextUtils.isEmpty(duration)) {
                try {
                    Duration d = new Duration();
                    d.parse(duration);
                    long endMillis = mStartMillis + d.getMillis();
                    if (endMillis >= mStartMillis) {
                        mEndMillis = endMillis;
                    } else {
                        Log.d(TAG, "Invalid duration string: " + duration);
                    }
                } catch (DateException e) {
                    Log.d(TAG, "Error parsing duration string " + duration, e);
                }
            }
            if (mEndMillis == 0) {
                mEndMillis = mStartMillis;
            }
        }
    }
    mAllDay = mEventCursor.getInt(EVENT_INDEX_ALL_DAY) != 0;
    String location = mEventCursor.getString(EVENT_INDEX_EVENT_LOCATION);
    String description = mEventCursor.getString(EVENT_INDEX_DESCRIPTION);
    String rRule = mEventCursor.getString(EVENT_INDEX_RRULE);
    String eventTimezone = mEventCursor.getString(EVENT_INDEX_EVENT_TIMEZONE);
    mHeadlines.setBackgroundColor(mCurrentColor);
    // What
    if (eventName != null) {
        setTextCommon(view, R.id.title, eventName);
    }
    Integer status = mEventCursor.getInt(EVENT_INDEX_STATUS);
    if (status == Events.STATUS_CANCELED) {
        TextView textView = (TextView) view.findViewById(R.id.title);
        textView.setPaintFlags(textView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
    }
    // When
    // Set the date and repeats (if any)
    String localTimezone = Utils.getTimeZone(mActivity, mTZUpdater);
    Resources resources = context.getResources();
    String displayedDatetime = Utils.getDisplayedDatetime(mStartMillis, mEndMillis, System.currentTimeMillis(), localTimezone, mAllDay, context);
    String displayedTimezone = null;
    if (!mAllDay) {
        displayedTimezone = Utils.getDisplayedTimezone(mStartMillis, localTimezone, eventTimezone);
    }
    // Display the datetime.  Make the timezone (if any) transparent.
    if (displayedTimezone == null) {
        setTextCommon(view, R.id.when_datetime, displayedDatetime);
    } else {
        int timezoneIndex = displayedDatetime.length();
        displayedDatetime += "  " + displayedTimezone;
        SpannableStringBuilder sb = new SpannableStringBuilder(displayedDatetime);
        ForegroundColorSpan transparentColorSpan = new ForegroundColorSpan(resources.getColor(R.color.event_info_headline_transparent_color));
        sb.setSpan(transparentColorSpan, timezoneIndex, displayedDatetime.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
        setTextCommon(view, R.id.when_datetime, sb);
    }
    // Display the repeat string (if any)
    String repeatString = null;
    if (!TextUtils.isEmpty(rRule)) {
        EventRecurrence eventRecurrence = new EventRecurrence();
        eventRecurrence.parse(rRule);
        Time date = new Time(localTimezone);
        date.set(mStartMillis);
        if (mAllDay) {
            date.timezone = Time.TIMEZONE_UTC;
        }
        eventRecurrence.setStartDate(date);
        repeatString = EventRecurrenceFormatter.getRepeatString(mContext, resources, eventRecurrence, true);
    }
    if (repeatString == null) {
        view.findViewById(R.id.when_repeat).setVisibility(View.GONE);
    } else {
        setTextCommon(view, R.id.when_repeat, repeatString);
    }
    // Where
    if (location == null || location.trim().length() == 0) {
        setVisibilityCommon(view, R.id.where, View.GONE);
    } else {
        final TextView textView = mWhere;
        if (textView != null) {
            textView.setAutoLinkMask(0);
            textView.setText(location.trim());
            try {
                textView.setText(Utils.extendedLinkify(textView.getText().toString(), true));
                // Linkify.addLinks() sets the TextView movement method if it finds any links.
                // We must do the same here, in case linkify by itself did not find any.
                // (This is cloned from Linkify.addLinkMovementMethod().)
                MovementMethod mm = textView.getMovementMethod();
                if ((mm == null) || !(mm instanceof LinkMovementMethod)) {
                    if (textView.getLinksClickable()) {
                        textView.setMovementMethod(LinkMovementMethod.getInstance());
                    }
                }
            } catch (Exception ex) {
                // unexpected
                Log.e(TAG, "Linkification failed", ex);
            }
            textView.setOnTouchListener(new OnTouchListener() {

                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    try {
                        return v.onTouchEvent(event);
                    } catch (ActivityNotFoundException e) {
                        // ignore
                        return true;
                    }
                }
            });
        }
    }
    // Description
    if (description != null && description.length() != 0) {
        mDesc.setText(description);
    }
    // Launch Custom App
    updateCustomAppButton();
}
Also used : Context(android.content.Context) OnTouchListener(android.view.View.OnTouchListener) ForegroundColorSpan(android.text.style.ForegroundColorSpan) LinkMovementMethod(android.text.method.LinkMovementMethod) Duration(com.android.calendarcommon2.Duration) Time(android.text.format.Time) ScrollView(android.widget.ScrollView) View(android.view.View) AdapterView(android.widget.AdapterView) AttendeesView(com.android.calendar.event.AttendeesView) TextView(android.widget.TextView) Paint(android.graphics.Paint) IOException(java.io.IOException) ActivityNotFoundException(android.content.ActivityNotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) DateException(com.android.calendarcommon2.DateException) MotionEvent(android.view.MotionEvent) EventRecurrence(com.android.calendarcommon2.EventRecurrence) ActivityNotFoundException(android.content.ActivityNotFoundException) LinkMovementMethod(android.text.method.LinkMovementMethod) MovementMethod(android.text.method.MovementMethod) DateException(com.android.calendarcommon2.DateException) TextView(android.widget.TextView) Resources(android.content.res.Resources) SpannableStringBuilder(android.text.SpannableStringBuilder)

Aggregations

LinkMovementMethod (android.text.method.LinkMovementMethod)50 TextView (android.widget.TextView)40 SmallTest (android.test.suitebuilder.annotation.SmallTest)18 View (android.view.View)12 Spannable (android.text.Spannable)8 TextAppearanceSpan (android.text.style.TextAppearanceSpan)7 ImageView (android.widget.ImageView)7 SpannableStringBuilder (android.text.SpannableStringBuilder)6 SpannableString (android.text.SpannableString)4 ActivityNotFoundException (android.content.ActivityNotFoundException)3 Context (android.content.Context)3 ViewGroup (android.view.ViewGroup)3 SystemUIDialog (com.android.systemui.statusbar.phone.SystemUIDialog)3 Intent (android.content.Intent)2 PackageManager (android.content.pm.PackageManager)2 Resources (android.content.res.Resources)2 Paint (android.graphics.Paint)2 Bundle (android.os.Bundle)2 ActionBar (android.support.v7.app.ActionBar)2 AlertDialog (android.support.v7.app.AlertDialog)2