private void ProcessAutoLink(ExpandableTextViewTag tag, SpannableStringBuilder ssbPartial) { if (tag.AutoLinkOptions != null && (!tag.AutoLinkOptions.IsLinkUnderline)) { var allURLSpans = tag.FormattedText.GetSpans( 0, tag.FormattedText.Length(), Java.Lang.Class.FromType(typeof(URLSpan))); var partialURLSpans = ssbPartial.GetSpans(0, ssbPartial.Length(), Java.Lang.Class.FromType(typeof(URLSpan))); foreach (var span in partialURLSpans) { int startIndex = ssbPartial.GetSpanStart(span); int endIndex = ssbPartial.GetSpanEnd(span); var foundSpan = FixedTextUtils.FindSpan(tag.FormattedText, allURLSpans, startIndex).JavaCast <URLSpan>(); ssbPartial.RemoveSpan(span); if (foundSpan != null) { ssbPartial.SetSpan(new NoUnderlineURLSpan(foundSpan.URL), startIndex, endIndex, 0); } } } }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { var v = inflater.Inflate(Resource.Layout.settings_contactus_fragment, container, false); var tvPhone = v.FindViewById <TextView>(Resource.Id.tvPhone); var tvTelSupportTime = v.FindViewById <TextView>(Resource.Id.tvTelSupportTime); var tvInternationalCall = v.FindViewById <TextView>(Resource.Id.tvInternationalCall); var tvFax = v.FindViewById <TextView>(Resource.Id.tvFax); var tvEmail = v.FindViewById <TextView>(Resource.Id.tvEmail); var tvLNCustomerRelations = v.FindViewById <TextView>(Resource.Id.tvLNCustomerRelations); var tvPost = v.FindViewById <TextView>(Resource.Id.tvPost); var tvPostToUsTitle = v.FindViewById <TextView>(Resource.Id.tvPostToUsTitle); var tvPostDx = v.FindViewById <TextView>(Resource.Id.tvPostDx); var tvSendByDXTitle = v.FindViewById <TextView>(Resource.Id.tvSendByDXTitle); var contactUs = GlobalAccess.Instance.CurrentUserInfo.Country.ContactUs; tvPhone.Text = contactUs.Phone; tvTelSupportTime.Text = contactUs.WorkingHours; tvInternationalCall.Text = contactUs.InternationalCallers; tvFax.Text = contactUs.Fax; tvEmail.Text = contactUs.Email; if (contactUs.PostToUs == null || string.IsNullOrEmpty(contactUs.PostToUs.Content)) { tvPost.Visibility = ViewStates.Gone; tvPostToUsTitle.Visibility = ViewStates.Gone; } else { if (string.IsNullOrEmpty(contactUs.PostToUs.Title)) { tvLNCustomerRelations.Visibility = ViewStates.Gone; } else { tvLNCustomerRelations.Text = contactUs.PostToUs.Title; } tvPost.Text = contactUs.PostToUs.Content; } if (string.IsNullOrEmpty(contactUs.SendByDX)) { tvPostDx.Visibility = ViewStates.Gone; tvSendByDXTitle.Visibility = ViewStates.Gone; } else { tvPostDx.Text = contactUs.SendByDX; } var ssb = new SpannableStringBuilder(tvEmail.Text); tvEmail.MovementMethod = LinkMovementMethod.Instance; Linkify.AddLinks(ssb, MatchOptions.WebUrls | MatchOptions.EmailAddresses); FixedTextUtils.RemoveLinkUnderline(ssb); tvEmail.TextFormatted = ssb; return(v); }
public void OnGlobalLayout() { var tag = tv.Tag as ExpandableTextViewTag; if (tag == null) { throw new InvalidOperationException("Unable to handle a TextView without Tag."); } ViewTreeObserver obs = tv.ViewTreeObserver; obs.RemoveOnGlobalLayoutListener(this); if (tag.LineCount < 0) { tag.LineCount = tv.LineCount; if (tag.FormattedText == null) { var spanned = tv.TextFormatted as ISpannable; if (spanned != null) { tag.FormattedText = spanned; } if (tag.AutoLinkOptions != null) { SpannableStringBuilder ssb = tag.FormattedText == null ? new SpannableStringBuilder(tv.Text) : new SpannableStringBuilder(tag.FormattedText); Linkify.AddLinks(ssb, tag.AutoLinkOptions.AutoLinkMask); if (!tag.AutoLinkOptions.IsLinkUnderline) { FixedTextUtils.RemoveLinkUnderline(ssb); } tag.FormattedText = ssb; } } } if (tag.IsPartial) { if (tv.LineCount > tag.MaxLines) { int lineStartIndex = tv.Layout.GetLineStart(tag.MaxLines - 1); int lineEndIndex = tv.Layout.GetLineEnd(tag.MaxLines - 1); int remainLineWidth; if (tag.ViewMoreLessOptions == null) { Rect apostropheRect = new Rect(); tv.Paint.GetTextBounds(Apostrophe, 0, Apostrophe.Length, apostropheRect); remainLineWidth = tv.Width - (apostropheRect.Width() * 5 / 3) - tv.TotalPaddingLeft - tv.TotalPaddingRight; } else { Rect viewMoreRect = new Rect(); tv.Paint.GetTextBounds(tag.ViewMoreLessOptions.ViewMore, 0, tag.ViewMoreLessOptions.ViewMore.Length, viewMoreRect); Rect apostropheRect = new Rect(); tv.Paint.GetTextBounds(Apostrophe, 0, Apostrophe.Length, apostropheRect); remainLineWidth = tv.Width - (int)Math.Round(viewMoreRect.Width() * (1.0f + 3.0f / (float)(tag.ViewMoreLessOptions.ViewMore.Length)) * ViewMoreLessProportion) - apostropheRect.Width() - tv.TotalPaddingLeft - tv.TotalPaddingRight; } String test = tv.Text.Substring(lineStartIndex, lineEndIndex - lineStartIndex); int returnIndex = test.IndexOf('\r'); if (returnIndex < 0) { returnIndex = test.IndexOf('\n'); } if (returnIndex >= 0) { test = test.Substring(0, returnIndex); } Rect testRect = new Rect(); while (test.Length > 0) { tv.Paint.GetTextBounds(test, 0, test.Length, testRect); if (testRect.Width() < remainLineWidth) { break; } test = test.Substring(0, test.Length - 1); } if (tag.ViewMoreLessOptions == null) { if (tag.FormattedText == null) { tv.Text = tv.Text.Substring(0, lineStartIndex + test.Length) + Apostrophe; } else { var ssbPartial = new SpannableStringBuilder( tag.FormattedText.SubSequenceFormatted(0, lineStartIndex + test.Length)); ssbPartial.Append(Apostrophe); tv.TextFormatted = ssbPartial; } } else { if (tag.FormattedText == null) { String text = tv.Text.Substring(0, lineStartIndex + test.Length) + Apostrophe + " "; var ssb = new SpannableStringBuilder(text); ssb.Append(StyleViewMoreLess(tag)); tv.TextFormatted = ssb; } else { var ssbPartial = new SpannableStringBuilder( tag.FormattedText.SubSequenceFormatted(0, lineStartIndex + test.Length)); ssbPartial.Append(Apostrophe + " "); ssbPartial.Append(StyleViewMoreLess(tag)); tv.TextFormatted = ssbPartial; } } tv.ScrollTo(0, 0); if (tag.ClickSwitch) { tv.SetOnClickListener(this); } } else if (tag.AutoLinkOptions != null) { tv.TextFormatted = tag.FormattedText; } } else { if (tag.ViewMoreLessOptions == null) { if (tag.FormattedText == null) { tv.Text = tag.Text; } else { tv.TextFormatted = tag.FormattedText; } } else { if (tag.FormattedText == null) { String text = tag.Text + " "; var ssb = new SpannableStringBuilder(text); ssb.Append(StyleViewMoreLess(tag)); tv.TextFormatted = ssb; } else { var ssb = new SpannableStringBuilder(tag.FormattedText); ssb.Append(" "); ssb.Append(StyleViewMoreLess(tag)); tv.TextFormatted = ssb; } } tv.ScrollTo(0, 0); } if (tag.Listerner != null) { tag.Listerner.LineCountDetected(tv); } }