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);
}
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());
}
}
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());
}
}
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());
}
}
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();
}
Aggregations