Example #1
0
        private SpannableString MakeSpannAbleString(ICharSequence text)
        {
            try
            {
                SpannableString spendableString = new SpannableString(text);

                List <StTools.XAutoLinkItem> autoLinkItems = MatchedRanges(text);

                foreach (StTools.XAutoLinkItem autoLinkItem in autoLinkItems)
                {
                    Color          currentColor  = GetColorByMode(autoLinkItem.GetAutoLinkMode());
                    XTouchableSpan clickAbleSpan = new XTouchableSpan(this, autoLinkItem, currentColor, DefaultSelectedColor, IsUnderLineEnabled);

                    spendableString.SetSpan(clickAbleSpan, autoLinkItem.GetStartPoint(), autoLinkItem.GetEndPoint(), SpanTypes.ExclusiveExclusive);

                    // check if we should make this auto link item bold
                    if (MBoldAutoLinkModes != null && MBoldAutoLinkModes.Contains(autoLinkItem.GetAutoLinkMode()))
                    {
                        // make the auto link item bold
                        spendableString.SetSpan(new StyleSpan(TypefaceStyle.Bold), autoLinkItem.GetStartPoint(), autoLinkItem.GetEndPoint(), SpanTypes.ExclusiveExclusive);
                    }
                }
                return(spendableString);
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
                SpannableString spendableString = new SpannableString(text);
                return(spendableString);
            }
        }
        public override bool OnTouchEvent(TextView textView, ISpannable spannable, MotionEvent e)
        {
            try
            {
                var action = e.Action;
                switch (action)
                {
                case MotionEventActions.Down:
                {
                    PressedSpan = GetPressedSpan(textView, spannable, e);
                    if (PressedSpan != null)
                    {
                        PressedSpan.SetPressed(true);
                        Selection.SetSelection(spannable, spannable.GetSpanStart(PressedSpan), spannable.GetSpanEnd(PressedSpan));
                    }

                    break;
                }

                case MotionEventActions.Move:
                {
                    XTouchableSpan touchedSpan = GetPressedSpan(textView, spannable, e);
                    if (PressedSpan != null && touchedSpan != PressedSpan)
                    {
                        PressedSpan.SetPressed(false);
                        PressedSpan = null !;
                        Selection.RemoveSelection(spannable);
                    }

                    break;
                }

                default:
                {
                    if (PressedSpan != null)
                    {
                        PressedSpan.SetPressed(false);
                        base.OnTouchEvent(textView, spannable, e);
                    }

                    PressedSpan = null !;
                    Selection.RemoveSelection(spannable);
                    break;
                }
                }
            }
            catch (Exception exception)
            {
                Methods.DisplayReportResultTrack(exception);
            }

            return(true);
        }
Example #3
0
        public override bool OnTouchEvent(TextView textView, ISpannable spannable, MotionEvent e)
        {
            var action = e.Action;

            if (action == MotionEventActions.Down)
            {
                PressedSpan = GetPressedSpan(textView, spannable, e);
                if (PressedSpan != null)
                {
                    PressedSpan.SetPressed(true);
                    Selection.SetSelection(spannable, spannable.GetSpanStart(PressedSpan), spannable.GetSpanEnd(PressedSpan));
                }
            }
            else if (action == MotionEventActions.Move)
            {
                XTouchableSpan touchedSpan = GetPressedSpan(textView, spannable, e);
                if (PressedSpan != null && touchedSpan != PressedSpan)
                {
                    PressedSpan.SetPressed(false);
                    PressedSpan = null;
                    Selection.RemoveSelection(spannable);
                }
            }
            else
            {
                if (PressedSpan != null)
                {
                    PressedSpan.SetPressed(false);
                    base.OnTouchEvent(textView, spannable, e);
                }

                PressedSpan = null;
                Selection.RemoveSelection(spannable);
            }

            return(true);
        }