public void Run() { try { int textLengthNew = Option.TextLength; if (Option.TextLengthType == TypeLine) { if (TextView.Layout.LineCount <= Option.TextLength) { TextView.SetText(Text, TextView.BufferType.Spannable); return; } ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams)TextView.LayoutParameters; string subString = Text.ToString().Substring(TextView.Layout.GetLineStart(0), TextView.Layout.GetLineEnd(Option.TextLength - 1)); textLengthNew = subString.Length - (Option.MoreLabel.Length + 4 + lp.RightMargin / 6); } SpannableStringBuilder spendableStringBuilder = new SpannableStringBuilder(Text.SubSequence(0, textLengthNew)); spendableStringBuilder.Append(" ..."); spendableStringBuilder.Append(Option.MoreLabel); SpannableString ss = SpannableString.ValueOf(spendableStringBuilder); ClickableSpan rclickableSpan = new StRclickableSpan(Option, TextView, Text, StTools.StTypeText.ReadMore); ss.SetSpan(rclickableSpan, ss.Length() - Option.MoreLabel.Length, ss.Length(), SpanTypes.ExclusiveExclusive); switch (Build.VERSION.SdkInt) { case >= BuildVersionCodes.JellyBean when Option.ExpandAnimation: { LayoutTransition layoutTransition = new LayoutTransition(); layoutTransition.EnableTransitionType(LayoutTransitionType.Changing); ((ViewGroup)TextView?.Parent).LayoutTransition = layoutTransition; break; } } //TextView.SetTextFuture(PrecomputedTextCompat.GetTextFuture(ss, TextViewCompat.GetTextMetricsParams(TextView), null)); TextView.SetText(ss, TextView.BufferType.Spannable); TextView.MovementMethod = LinkMovementMethod.Instance; } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
public void AddReadLess(AppCompatTextView textView, ICharSequence text) { try { textView.SetMaxLines(Integer.MaxValue); SpannableStringBuilder spendableStringBuilder = new SpannableStringBuilder(text); spendableStringBuilder.Append(" "); spendableStringBuilder.Append(LessLabel); SpannableString ss = SpannableString.ValueOf(spendableStringBuilder); ClickableSpan rclickableSpan = new StRclickableSpan(this, textView, text, StTools.StTypeText.ReadLess); ss.SetSpan(rclickableSpan, ss.Length() - LessLabel.Length, ss.Length(), SpanTypes.ExclusiveExclusive); // textView.SetTextFuture(PrecomputedTextCompat.GetTextFuture(ss, TextViewCompat.GetTextMetricsParams(textView), null)); textView.SetText(ss, TextView.BufferType.Spannable); textView.MovementMethod = (LinkMovementMethod.Instance); } catch (Exception e) { Console.WriteLine(e); } }