コード例 #1
0
        public override bool OnTouchEvent(TextView widget, ISpannable buffer, MotionEvent e)
        {
            switch (e.Action)
            {
            case MotionEventActions.Down:
                _pressedSpan = GetTouchableSpan(widget, buffer, e);
                if (_pressedSpan != null)
                {
                    _pressedSpan.Pressed = true;
                    Selection.SetSelection(buffer, buffer.GetSpanStart(_pressedSpan), buffer.GetSpanEnd(_pressedSpan));
                }
                break;

            case MotionEventActions.Move:
                var _pressedSpanM = GetTouchableSpan(widget, buffer, e);
                if (_pressedSpan != null && _pressedSpanM != _pressedSpan)
                {
                    _pressedSpan.Pressed = false;
                    _pressedSpan         = null;
                    Selection.RemoveSelection(buffer);
                }
                break;

            default:
                if (_pressedSpan != null)
                {
                    _pressedSpan.Pressed = false;
                    base.OnTouchEvent(widget, buffer, e);
                }
                _pressedSpan = null;
                Selection.RemoveSelection(buffer);
                break;
            }
            return(true);
        }
コード例 #2
0
        public bool AddSmiles(Context context, ISpannable spannable)
        {
            var hasChanges = false;

            foreach (var entry in Emoticons)
            {
                var smiley      = entry.Key;
                var smileyImage = entry.Value;
                var indices     = spannable.ToString().IndexesOf(smiley);
                foreach (var index in indices)
                {
                    var set = true;
                    foreach (ImageSpan span in spannable.GetSpans(index, index + smiley.Length, Java.Lang.Class.FromType(typeof(ImageSpan))))
                    {
                        if (spannable.GetSpanStart(span) >= index && spannable.GetSpanEnd(span) <= index + smiley.Length)
                        {
                            spannable.RemoveSpan(span);
                        }
                        else
                        {
                            set = false;
                            break;
                        }
                    }
                    if (set)
                    {
                        hasChanges = true;
                        spannable.SetSpan(new ImageSpan(context, smileyImage), index, index + smiley.Length, SpanTypes.ExclusiveExclusive);
                    }
                }
            }
            return(hasChanges);
        }
コード例 #3
0
ファイル: HtmlLabelRenderer.cs プロジェクト: dorisoy/Wesley
        private void MakeLinkClickable(ISpannable strBuilder, URLSpan span)
        {
            var start     = strBuilder.GetSpanStart(span);
            var end       = strBuilder.GetSpanEnd(span);
            var flags     = strBuilder.GetSpanFlags(span);
            var clickable = new MyClickableSpan((HtmlLabel)Element, span);

            strBuilder.SetSpan(clickable, start, end, flags);
            strBuilder.RemoveSpan(span);
        }
コード例 #4
0
        private static void MakeLinkClickable(ISpannable spannable, URLSpan span)
        {
            var start         = spannable.GetSpanStart(span);
            var end           = spannable.GetSpanEnd(span);
            var flags         = spannable.GetSpanFlags(span);
            var clickableLink = new ClickableLinkSpan(span.URL);

            spannable.SetSpan(clickableLink, start, end, flags);
            spannable.RemoveSpan(span);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        /**
         * Adds a highlight background color span to the TextView.
         */
        protected void HighlightUrl(TextView textView, ClickableSpanWithText spanWithText, ISpannable text)
        {
            if (_isUrlHighlighted)
            {
                return;
            }

            _isUrlHighlighted = true;

            var spanStart = text.GetSpanStart(spanWithText.Span);
            var spanEnd   = text.GetSpanEnd(spanWithText.Span);

            text.SetSpan(new BackgroundColorSpan(textView.HighlightColor), spanStart, spanEnd, SpanTypes.InclusiveInclusive);
            textView.SetText(text, TextView.BufferType.Spannable);

            Selection.SetSelection(text, spanStart, spanEnd);
        }
コード例 #7
0
        public override bool OnTouchEvent(TextView widget, ISpannable buffer, MotionEvent e)
        {
            var action = e.ActionMasked;

            if (action == MotionEventActions.Up || action == MotionEventActions.Down)
            {
                var x = e.GetX();
                var y = e.GetY();
                x -= widget.TotalPaddingLeft;
                y -= widget.TotalPaddingTop;
                x += widget.ScrollX;
                y += widget.ScrollY;

                var layout = widget.Layout;
                var line   = layout.GetLineForVertical((int)y);
                var off    = layout.GetOffsetForHorizontal(line, x);

                var link = buffer.GetSpans(off, off, Java.Lang.Class.FromType(typeof(ClickableSpan)));
                if (link.Length > 0)
                {
                    if (action == MotionEventActions.Up)
                    {
                        (link[0] as ClickableSpan).OnClick(widget);
                    }
                    else
                    {
                        Selection.SetSelection(buffer, buffer.GetSpanStart(link[0]), buffer.GetSpanEnd(link[0]));
                    }
                    return(true);
                }
                else
                {
                    Selection.RemoveSelection(buffer);
                }
            }

            return(false);
        }
コード例 #8
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);
        }
コード例 #9
0
ファイル: SpannableTools.cs プロジェクト: kishoredbn/Android
		// Taken from https://gist.githubusercontent.com/Cheesebaron/5034440/raw/f962c41c95f8d94457ef9a60e19fe7efa2a50d61/SpannableTools.cs
		public static bool AddSmiles(Context context, ISpannable spannable)
		{
			var hasChanges = false;
			foreach (var entry in Emoticons)
			{
				var smiley = entry.Key;
				var smileyImage = entry.Value;
				var indices = spannable.ToString().IndexesOf(smiley);
				var index = 0;
				foreach (var token in spannable.ToString().Split(' '))
				{
					if (token.Equals (smiley)) {
						var set = true;
						foreach (ImageSpan span in spannable.GetSpans(index, index + smiley.Length, Java.Lang.Class.FromType(typeof(ImageSpan)))) {
							if (spannable.GetSpanStart (span) >= index && spannable.GetSpanEnd (span) <= index + smiley.Length)
								spannable.RemoveSpan (span);
							else {
								set = false;
								break;
							}
						}
						if (set) {
							hasChanges = true;
							spannable.SetSpan (new ImageSpan (context, smileyImage), index, index + smiley.Length, SpanTypes.ExclusiveExclusive);
						}
					}
					index += token.Length + 1;
				}
			}
			return hasChanges;
		}