Example #1
0
        private TouchableSpan GetTouchableSpan(TextView textView, ISpannable span, MotionEvent e)
        {
            var x = (int)e.GetX();
            var y = (int)e.GetY();

            x -= textView.TotalPaddingLeft;
            y -= textView.TotalPaddingTop;

            x += textView.ScrollX;
            y += textView.ScrollY;

            var touchedLine = textView.Layout.GetLineForVertical(y);
            var touchOffset = textView.Layout.GetOffsetForHorizontal(touchedLine, x);

            _touchBounds.Left   = textView.Layout.GetLineLeft(touchedLine);
            _touchBounds.Top    = textView.Layout.GetLineTop(touchedLine);
            _touchBounds.Right  = textView.Layout.GetLineRight(touchedLine);
            _touchBounds.Bottom = textView.Layout.GetLineBottom(touchedLine);

            TouchableSpan touchableSpan = null;

            if (_touchBounds.Contains(x, y))
            {
                var spans = span.GetSpans(touchOffset, touchOffset, Java.Lang.Class.FromType(typeof(TouchableSpan)));
                touchableSpan = spans.Length > 0 ? (TouchableSpan)spans[0] : null;
            }
            return(touchableSpan);
        }
Example #2
0
 void setImages(ICursor cursor)
 {
     if (cursor.MoveToFirst())
     {
         string path;
         long   id;
         long   start;
         long   end;
         Bitmap bitmap = null;
         do
         {
             id     = cursor.GetLong(0);
             path   = cursor.GetString(1);
             start  = cursor.GetLong(2);
             end    = cursor.GetLong(3);
             bitmap = SqlHelper.ReturnDrawableBase(id, path);
             path   = '[' + path + ']';
             var        imageSpan = new ImageSpan(this, bitmap);
             ISpannable spann     = SpannableFactory.Instance.NewSpannable(path);
             spann.SetSpan(imageSpan, 0, path.Length, SpanTypes.ExclusiveExclusive);
             textWatcher.Editing = false;
             EditText.EditableText.Replace((int)start, (int)end, spann);
         }while (cursor.MoveToNext());
     }
 } //SetImages in Text
        private XTouchableSpan GetPressedSpan(TextView textView, ISpannable spannable, MotionEvent e)
        {
            try
            {
                int x = (int)e.GetX();
                int y = (int)e.GetY();

                x -= textView.TotalPaddingLeft;
                y -= textView.TotalPaddingTop;

                x += textView.ScrollX;
                y += textView.ScrollY;

                Layout layout           = textView.Layout;
                int    verticalLine     = layout.GetLineForVertical(y);
                int    horizontalOffset = layout.GetOffsetForHorizontal(verticalLine, x);

                var link = spannable.GetSpans(horizontalOffset, horizontalOffset, Class.FromType(typeof(XTouchableSpan)));

                if (link?.Length > 0)
                {
                    var sdfs = (XTouchableSpan)link[0];
                    return(sdfs);
                }
            }
            catch (Exception exception)
            {
                Methods.DisplayReportResultTrack(exception);
            }

            return(null !);
        }
Example #4
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);
        }
Example #5
0
        protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data) //setimage on text view
        {
            base.OnActivityResult(requestCode, resultCode, data);
            Bitmap bitmap = null;

            switch (requestCode)
            {
            case GALLERY_REQUEST:
                if (resultCode == Result.Ok)
                {
                    Android.Net.Uri selectedImage = data.Data;
                    string          Tag           = '[' + selectedImage.LastPathSegment + ']';
                    bitmap = Multitools.decodeSampledBitmapFromUri(this, selectedImage, 2000, 2000);
                    bitmap = Multitools.getResizedBitmap(bitmap, Resources.DisplayMetrics.WidthPixels - 100, Resources.DisplayMetrics.WidthPixels - 100);

                    var        imageSpan = new ImageSpan(this, bitmap); //Find your drawable.
                    int        selStart  = EditText.SelectionEnd;
                    var        span      = EditText.EditableText.GetSpans(0, EditText.Length(), Java.Lang.Class.FromType(typeof(ImageSpan)));
                    ISpannable spann     = SpannableFactory.Instance.NewSpannable(Tag);
                    spann.SetSpan(imageSpan, 0, Tag.Length, SpanTypes.ExclusiveExclusive);
                    if (selStart != 0)
                    {
                        EditText.EditableText.Insert(selStart, "\n");
                    }
                    selStart = EditText.SelectionEnd;
                    EditText.EditableText.Insert(selStart, spann);
                    textWatcher.Editing = false;
                    EditText.EditableText.Insert(selStart + Tag.Length, "\n");
                    textWatcher.Editing = true;
                }
                break;
            }
        }
Example #6
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);
        }
 public DrawableTarget(ISpannable spannable, int start, int end, int width, Drawable playIcon = null)
 {
     _spannable = spannable;
     _start     = start;
     _end       = end;
     _width     = width;
     _playIcon  = playIcon;
 }
            public SpanShardedList(ShardedList <T> parent, ISpannable <T> impl)
            {
                this.Impl = impl;

                this.Parent       = parent;
                this.GlobalOffset =
                    new ShardedListAddress(() => parent.LocateRegion_(this));
            }
Example #9
0
 private static void HandleRuns(
     IAttributedText target,
     ISpannable spannableString)
 {
     foreach (var run in target.Runs)
     {
         HandleFormatRun(spannableString, run);
     }
 }
Example #10
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);
        }
Example #11
0
        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);
        }
Example #12
0
        public override bool OnTouchEvent(TextView widget, ISpannable buffer, MotionEvent e)
        {
            if (e.Action == MotionEventActions.Up)
            {
                int touchX = (int)e.GetX();
                int touchY = (int)e.GetY();

                var layout = widget.Layout;

                int touchedLine = widget.Layout.GetLineForVertical(touchY);
                int touchOffset = widget.Layout.GetOffsetForHorizontal(touchedLine, touchX);

                _touchedLineBounds.Left   = layout.GetLineLeft(touchedLine);
                _touchedLineBounds.Top    = layout.GetLineTop(touchedLine);
                _touchedLineBounds.Right  = layout.GetLineWidth(touchedLine) + _touchedLineBounds.Left;
                _touchedLineBounds.Bottom = layout.GetLineBottom(touchedLine);

                if (_touchedLineBounds.Contains(touchX, touchY))
                {
                    object[] spans = buffer.GetSpans(touchOffset, touchOffset, Java.Lang.Class.FromType(typeof(ClickableSpan)));
                    foreach (object span in spans)
                    {
                        if (span is URLSpan)
                        {
                            var spanTarget = (URLSpan)span;
                            if (LinkClicked != null)
                            {
                                switch (spanTarget.URL.Split(':')[0])
                                {
                                case "taxonid":
                                    LinkClicked(widget, new TaxonLinkClickedEventArgs()
                                    {
                                        TaxonId = int.Parse(spanTarget.URL.Replace("taxonid://", ""))
                                    });
                                    break;

                                case "http":
                                case "https":
                                    Launcher.OpenAsync(new Uri(spanTarget.URL));
                                    break;
                                }
                                return(true);
                            }
                        }
                    }
                }

                return(base.OnTouchEvent(widget, buffer, e));
            }
            else
            {
                return(false);
            }
        }
                public override bool OnTouchEvent(TextView widget, ISpannable buffer, MotionEvent e)
                {
                    bool result = false;

                    if (!MessagesListAdapter.isSelectionModeEnabled)
                    {
                        result = base.OnTouchEvent(widget, buffer, e);
                    }
                    widget.OnTouchEvent(e);
                    return(result);
                }
Example #14
0
            public Span(ISpannable <T> parent, int offset, int length)
            {
                Asserts.Assert(offset >= 0, "Spanned with a negative offset!");
                Asserts.Assert(length >= 0, "Spanned with a negative length!");
                Asserts.Assert(offset + length <= parent.Length,
                               "Spanned beyond the length of the parent!");

                this.parent_ = parent;
                this.Offset  = offset;
                this.Length  = length;
            }
Example #15
0
        /// <summary>
        /// Since they are several over write of the Test property during layout we have to set this field as long as it is not definitly set
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void nativeBtn_AfterTextChanged(object sender, AfterTextChangedEventArgs e)
        {
            ISpannable spannable = e.Editable;
            var        indice    = spannable.ToString().IndexOf(_iconButton.Icon);
            var        spans     = spannable.GetSpans(indice, indice + _iconButton.Icon.Length, Java.Lang.Class.FromType(typeof(TypefaceSpan))).ToList();

            if (spans.Count == 0)
            {
                _nativeBtn.SetText(_iconSpan, TextView.BufferType.Spannable);
            }
        }
        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);
        }
        public override bool OnTouchEvent(TextView view, ISpannable buffer, MotionEvent e)
        {
            if (_activeTextViewHashcode != view.GetHashCode())
            {
                // Bug workaround: TextView stops calling onTouchEvent() once any URL is highlighted.
                // A hacky solution is to reset any "autoLink" property set in XML. But we also want
                // to do this once per TextView.
                _activeTextViewHashcode = view.GetHashCode();
                view.AutoLinkMask       = 0;
            }

            var touchedClickableSpan = FindClickableSpanUnderTouch(view, buffer, e);

            // Toggle highlight
            if (touchedClickableSpan != null)
            {
                HighlightUrl(view, touchedClickableSpan, buffer);
            }
            else
            {
                RemoveUrlHighlightColor(view);
            }

            switch (e.Action)
            {
            case MotionEventActions.Down:
                _touchStartedOverLink = touchedClickableSpan != null;
                return(_touchStartedOverLink);

            case MotionEventActions.Up:
                // Register a click only if the touch started on an URL. That is, the touch did not start
                // elsewhere and ended up on an URL.
                if (touchedClickableSpan != null && _touchStartedOverLink)
                {
                    DispatchUrlClick(view, touchedClickableSpan);
                    RemoveUrlHighlightColor(view);
                }
                var didTouchStartOverLink = _touchStartedOverLink;
                _touchStartedOverLink = false;

                // Consume this event even if we could not find any spans. Android's TextView implementation
                // has a bug where links get clicked even when there is no more text next to the link and the
                // touch lies outside its bounds in the same direction.
                return(didTouchStartOverLink);

            case MotionEventActions.Move:
                return(_touchStartedOverLink);

            default:
                return(false);
            }
        }
            public override void BindView(Android.Views.View view, Context context, ICursor cursor)
            {
                view.FindViewById <TextView> (Resource.Id.vendor_name).Text = cursor.GetString(SearchQuery.NAME);

                string     snippet       = cursor.GetString(SearchQuery.SEARCH_SNIPPET);
                ISpannable styledSnippet = UIUtils.BuildStyledSnippet(new Java.Lang.String(snippet));

                view.FindViewById <TextView> (Resource.Id.vendor_location).TextFormatted = styledSnippet;

                bool starred = cursor.GetInt(VendorsQuery.STARRED) != 0;

                view.FindViewById(Resource.Id.star_button).Visibility = starred ? ViewStates.Visible : ViewStates.Invisible;
            }
        public static AttributedText AsAttributedText(this ISpannable target)
        {
            if (target != null)
            {
                using (var textWriter = new StringWriter())
                {
                    var runs = CreateRuns(target, textWriter);
                    return(new AttributedText(textWriter.ToString(), runs));
                }
            }

            return(null);
        }
        private static void FormatImages(Context context, ISpannable spannable)
        {
            var text = spannable?.ToString();

            if (string.IsNullOrWhiteSpace(text))
            {
                return;
            }

            var matches = ImageRegex.Matches(text);

            foreach (var match in matches.ToList())
            {
                var drawable = ContextCompat.GetDrawable(context, PlaceholderImage);
                drawable.SetBounds(0, 0, drawable.IntrinsicWidth, drawable.IntrinsicHeight);

                var imageSpan = new ImageSpan(drawable, SpanAlign.Baseline);

                var clickSpan = new CustomClickableSpan();
                clickSpan.Click += (sender, e) =>
                {
                    var intent = new Intent(Intent.ActionView,
                                            Android.Net.Uri.Parse(match.Groups[2].Value));
                    context.StartActivity(intent);
                };

                spannable.SetSpan(clickSpan, match.Index, match.Index + match.Length,
                                  SpanTypes.InclusiveExclusive);

                spannable.SetSpan(imageSpan, match.Index, match.Index + match.Length,
                                  SpanTypes.InclusiveExclusive);

                if (!int.TryParse(match.Groups[1].Value, out var width))
                {
                    width = 250;
                }

                width = Math.Min(width, MaxImageWidth);

                Picasso.With(context).Load(match.Groups[2].Value)
                .Into(new DrawableTarget(spannable, match.Index, match.Index + match.Length, (int)(width * context.Resources.DisplayMetrics.Density)));
            }
        }
        private static List <AttributedTextRun> CreateRuns(
            ISpannable target,
            TextWriter writer)
        {
            var runs = new List <AttributedTextRun>();

            var spans = target.GetSpans(0, target.Length(), null);

            if (spans != null)
            {
                foreach (var span in spans)
                {
                    System.Console.WriteLine(span);
                }
            }

            writer.Write(target.ToString());
            return(runs);
        }
        public override bool OnTouchEvent(TextView widget, ISpannable buffer, MotionEvent e)
        {
            var action = e.Action;

            if (action == MotionEventActions.Up || action == MotionEventActions.Down)
            {
                int x      = (int)e.GetX() - widget.TotalPaddingLeft + widget.ScrollX;
                int y      = (int)e.GetY() - widget.TotalPaddingTop + widget.ScrollY;
                var layout = widget.Layout;
                int line   = layout.GetLineForVertical(y);
                int off    = layout.GetOffsetForHorizontal(line, x);

                var span = buffer.GetSpans(off, off, Java.Lang.Class.FromType(typeof(CommandableSpan))).OfType <CommandableSpan>().FirstOrDefault();

                if (span != null)
                {
                    if (action == MotionEventActions.Up)
                    {
                        span.OnClick(widget);
                        span.IsHighlight = false;
                    }
                    else if (action == MotionEventActions.Down)
                    {
                        span.IsHighlight = true;
                    }
                    widget.Invalidate();
                    currentSpan = span;
                    return(true);
                }
                else
                {
                    if (currentSpan != null)
                    {
                        currentSpan.IsHighlight = false;
                        currentSpan             = null;
                        widget.Invalidate();
                    }
                }
            }
            base.OnTouchEvent(widget, buffer, e);
            return(false);
        }
        private static void FormatYoutube(Context context, ISpannable spannable)
        {
            var text = spannable?.ToString();

            if (string.IsNullOrWhiteSpace(text))
            {
                return;
            }

            var matches = YoutubeRegex.Matches(text);

            var playIcon = ContextCompat.GetDrawable(context, Resource.Drawable.svg_play);

            playIcon.SetColorFilter(Color.White, PorterDuff.Mode.SrcIn);
            playIcon.SetAlpha(150);

            foreach (var match in matches.ToList())
            {
                var drawable = ContextCompat.GetDrawable(context, PlaceholderImage);
                drawable.SetBounds(0, 0, drawable.IntrinsicWidth, drawable.IntrinsicHeight);

                var imageSpan = new ImageSpan(drawable, SpanAlign.Baseline);

                var clickSpan = new CustomClickableSpan();
                clickSpan.Click += (sender, e) =>
                {
                    var intent = new Intent(Intent.ActionView,
                                            Android.Net.Uri.Parse(string.Format(YoutubeLinkUrl, match.Groups[1].Value)));
                    context.StartActivity(intent);
                };

                spannable.SetSpan(clickSpan, match.Index, match.Index + match.Length,
                                  SpanTypes.InclusiveExclusive);

                spannable.SetSpan(imageSpan, match.Index, match.Index + match.Length,
                                  SpanTypes.InclusiveExclusive);

                Picasso.With(context).Load(string.Format(YoutubeThumbnailUrl, match.Groups[1].Value))
                .Into(new DrawableTarget(spannable, match.Index, match.Index + match.Length,
                                         (int)(250 * context.Resources.DisplayMetrics.Density), playIcon));
            }
        }
Example #24
0
        private ShardedList(
            ShardedList <T>?parent,
            ISpannable <T> ts
            )
        {
            this.parent_ = parent;
            this.regions_.Add(new SpanShardedList(this, ts));

            this.UpdateLength_();

            if (parent != null)
            {
                this.GlobalOffset = new ShardedListAddress(
                    () => parent.LocateRegion_(this));
            }
            else
            {
                this.GlobalOffset = new NullShardedListAddress();
            }
        }
Example #25
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);
        }
Example #26
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);
        }
Example #27
0
		// 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;
		}
 public ResultDialogBuilder SetText(ISpannable resultText)
 {
     _textView.SetText(resultText, TextView.BufferType.Normal);
     return(this);
 }
Example #29
0
        /**
         * Convert emoji characters of the given Spannable to the according emojicon.
         *
         * @param context
         * @param text
         * @param emojiSize
         * @param index
         * @param length
         */
        public static void AddEmojis(Context context, ISpannable text, int emojiSize, int index, int length)
        {
            int textLength = text.Length();
            int textLengthToProcessMax = textLength - index;
            int textLengthToProcess = length < 0 || length >= textLengthToProcessMax ? textLength : (length+index);

            // remove spans throughout all text
            //EmojiconSpan[]
            var oldSpans = text.GetSpans(0, textLength,Java.Lang.Class.FromType(typeof(EmojiconSpan)));
            for (int i = 0; i < oldSpans.Length; i++) {
            text.RemoveSpan(oldSpans[i]);
            }

            int skip;
            for (int i = index; i < textLengthToProcess; i += skip)
            {
            skip = 0;
            int icon = 0;
            char c = text.CharAt(i);
            if (IsSoftBankEmoji(c))
            {
                icon = GetSoftbankEmojiResource(c);
                skip = icon == 0 ? 0 : 1;
            }

            if (icon == 0)
            {
                int unicode = Character.CodePointAt(text, i);
                skip = Character.CharCount(unicode);

                if (unicode > 0xff)
                {
                    icon = GetEmojiResource(context, unicode);
                }

                if (icon == 0 && i + skip < textLengthToProcess)
                {
                    int followUnicode = Character.CodePointAt(text, i + skip);
                    if (followUnicode == 0x20e3)
                    {
                        int followSkip = Character.CharCount(followUnicode);
                        switch (unicode)
                        {
                            case 0x0031:
                                icon = Resource.Drawable.emoji_0031;
                                break;
                            case 0x0032:
                                icon = Resource.Drawable.emoji_0032;
                                break;
                            case 0x0033:
                                icon = Resource.Drawable.emoji_0033;
                                break;
                            case 0x0034:
                                icon = Resource.Drawable.emoji_0034;
                                break;
                            case 0x0035:
                                icon = Resource.Drawable.emoji_0035;
                                break;
                            case 0x0036:
                                icon = Resource.Drawable.emoji_0036;
                                break;
                            case 0x0037:
                                icon = Resource.Drawable.emoji_0037;
                                break;
                            case 0x0038:
                                icon = Resource.Drawable.emoji_0038;
                                break;
                            case 0x0039:
                                icon = Resource.Drawable.emoji_0039;
                                break;
                            case 0x0030:
                                icon = Resource.Drawable.emoji_0030;
                                break;
                            case 0x0023:
                                icon = Resource.Drawable.emoji_0023;
                                break;
                            default:
                                followSkip = 0;
                                break;
                        }
                        skip += followSkip;
                    }
                    else
                    {
                        int followSkip = Character.CharCount(followUnicode);
                        switch (unicode)
                        {
                            case 0x1f1ef:
                                icon = (followUnicode == 0x1f1f5) ? Resource.Drawable.emoji_1f1ef_1f1f5 : 0;
                                break;
                            case 0x1f1fa:
                                icon = (followUnicode == 0x1f1f8) ? Resource.Drawable.emoji_1f1fa_1f1f8 : 0;
                                break;
                            case 0x1f1eb:
                                icon = (followUnicode == 0x1f1f7) ? Resource.Drawable.emoji_1f1eb_1f1f7 : 0;
                                break;
                            case 0x1f1e9:
                                icon = (followUnicode == 0x1f1ea) ? Resource.Drawable.emoji_1f1e9_1f1ea : 0;
                                break;
                            case 0x1f1ee:
                                icon = (followUnicode == 0x1f1f9) ? Resource.Drawable.emoji_1f1ee_1f1f9 : 0;
                                break;
                            case 0x1f1ec:
                                icon = (followUnicode == 0x1f1e7) ? Resource.Drawable.emoji_1f1ec_1f1e7 : 0;
                                break;
                            case 0x1f1ea:
                                icon = (followUnicode == 0x1f1f8) ? Resource.Drawable.emoji_1f1ea_1f1f8 : 0;
                                break;
                            case 0x1f1f7:
                                icon = (followUnicode == 0x1f1fa) ? Resource.Drawable.emoji_1f1f7_1f1fa : 0;
                                break;
                            case 0x1f1e8:
                                icon = (followUnicode == 0x1f1f3) ? Resource.Drawable.emoji_1f1e8_1f1f3 : 0;
                                break;
                            case 0x1f1f0:
                                icon = (followUnicode == 0x1f1f7) ? Resource.Drawable.emoji_1f1f0_1f1f7 : 0;
                                break;
                            default:
                                followSkip = 0;
                                break;
                        }
                        skip += followSkip;
                    }
                }
            }

            if (icon > 0)
            {
                text.SetSpan(new EmojiconSpan(context, icon, emojiSize), i, i + skip, SpanTypes.ExclusiveExclusive);
            }
            }
        }
Example #30
0
 /**
  * Convert emoji characters of the given Spannable to the according emojicon.
  *
  * @param context
  * @param text
  * @param emojiSize
  */
 public static void AddEmojis(Context context, ISpannable text, int emojiSize)
 {
     AddEmojis(context, text, emojiSize, 0, -1);
 }
Example #31
0
 public override void Initialize(TextView widget, ISpannable text)
 {
     Selection.RemoveSelection(text);
 }
Example #32
0
        public long SaveText(IEditable Text, Bundle args)
        {
            long   NoteNumber = 0;
            string date       = DateTime.Now.ToString("dd MMM yyyyг. HH:mm");

            ContentValues    cv       = new ContentValues();
            SpannableFactory a        = new SpannableFactory();
            ISpannable       saveText = a.NewSpannable(Text);



            Java.Lang.Object[] span = saveText.GetSpans(0, saveText.Length(), Java.Lang.Class.FromType(typeof(ImageSpan)));
            if (span != null)
            {
                for (int i = 0; i < span.Length; i++)
                {
                    saveText.RemoveSpan(span[i]);
                }
            }
            if (Build.VERSION.SdkInt >= BuildVersionCodes.N)
            {
                cv.Put(COLUMN_TEXT, Html.ToHtml(saveText, ToHtmlOptions.ParagraphLinesIndividual));
            }
            else
            {
                cv.Put(COLUMN_TEXT, Html.ToHtml(saveText));
            }
            cv.Put(COLUMN_EDITINGTIME, date);
            if (args != null)
            {
                WritableDatabase.Update(TEXTTABLE, cv, "_id == ?", new string[] { args.GetString(Databasehelper.COLUMN_ID) });
                WritableDatabase.ExecSQL("DELETE from " + CONTENTTABLE + " Where _id == " + args.GetString(Databasehelper.COLUMN_ID)); //Delete old image
                NoteNumber = Convert.ToInt32(args.GetString(COLUMN_ID));
            }
            else
            {
                long id = 1;
                cursor = WritableDatabase.RawQuery("Select _id from " + Databasehelper.TEXTTABLE + " ORDER BY _id DESC LIMIT 1", null);
                if (cursor.MoveToFirst())
                {
                    id = cursor.GetLong(cursor.GetColumnIndex("_id"));
                    cursor.Close();
                    id++;
                }
                cv.Put(COLUMN_ID, id);
                WritableDatabase.Insert(TEXTTABLE, null, cv);
                NoteNumber = id;
            }
            Java.Lang.Object[] spans = Text.GetSpans(0, Text.Length(), Java.Lang.Class.FromType(typeof(ImageSpan)));
            //Insert Image in Database
            if (spans != null)
            {
                for (int i = 0; i < spans.Length; i++)
                {
                    int    start = Text.GetSpanStart(spans[i]);
                    int    end   = Text.GetSpanEnd(spans[i]);
                    string source;

                    source = Text.ToString().Substring(start + 1, end - start - 2);


                    SaveBitmapBase(NoteNumber, source, start, end, ((BitmapDrawable)((ImageSpan)spans[i]).Drawable).Bitmap);
                }
            }
            return(NoteNumber);
        }
        /**
         * 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);
        }