Beispiel #1
0
            private void HandleIgnoredTag(bool opening, IEditable output)
            {
                const string IGNORED_ANNOTATION_KEY   = "DUMMY_KEY";
                const string IGNORED_ANNOTATION_VALUE = "DUMMY_VALUE";

                var len = output.Length();

                if (opening)
                {
                    output.SetSpan(new Annotation(IGNORED_ANNOTATION_KEY, IGNORED_ANNOTATION_VALUE), len, len, SpanTypes.MarkMark);
                }
                else
                {
                    var start =
                        output.GetSpans(0, output.Length(), Java.Lang.Class.FromType(typeof(Annotation)))
                        .Cast <Annotation>()
                        .Where(a => output.GetSpanFlags(a) == SpanTypes.MarkMark)
                        .Where(a => a.Key == IGNORED_ANNOTATION_KEY)
                        .Where(a => a.Value == IGNORED_ANNOTATION_VALUE)
                        .FirstOrDefault();
                    if (start != null)
                    {
                        var where = output.GetSpanStart(start);
                        output.RemoveSpan(start);
                        output.Delete(where, len);
                    }
                }
            }
Beispiel #2
0
        /**
         * Modified from {@link Android.Text.Html}
         */
        private void End(IEditable output, Type kind, bool paragraphStyle, params Java.Lang.Object[] replaces)
        {
            Java.Lang.Object obj = GetLast(output, kind);

            // start of the tag
            int where = output.GetSpanStart(obj);

            // end of the tag
            int len = output.Length();

            output.RemoveSpan(obj);

            if (where != len)
            {
                int thisLen = len;

                // paragraph styles like AlignmentSpan need to end with a new line!
                if (paragraphStyle)
                {
                    output.Append("\n");
                    thisLen++;
                }
                foreach (Java.Lang.Object replace in replaces)
                {
                    output.SetSpan(replace, where, thisLen, SpanTypes.ExclusiveExclusive);
                }

                // if (HtmlTextView.DEBUG) {
                //     Log.d(HtmlTextView.TAG, "where: " + where);
                //     Log.d(HtmlTextView.TAG, "thisLen: " + thisLen);
                // }
            }
        }
        protected virtual void SetSpanFromMarkSpan(IEditable text)
        {
            var markSpan = GetLastMarkSpan(text);

            if (markSpan == null)
            {
                return;
            }

            var styleSpan         = markSpan.CreateStyleSpan();
            var markStartLocation = text.GetSpanStart((JObject)markSpan);
            var markEndLocation   = text.Length();

            text.RemoveSpan((JObject)markSpan);

            if (markStartLocation == markEndLocation)
            {
                return;
            }

            text.SetSpan(styleSpan, markStartLocation, markEndLocation, SpanTypes.ExclusiveExclusive);
        }
        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);
        }
        void UpdateStyleSpans(TypefaceStyle flagStyle)
        {
            var  selectionStart = Control.SelectionStart;
            var  selectionEnd   = Control.SelectionEnd;
            var  styleSpans     = EditableText.GetSpans(selectionStart, selectionEnd, Java.Lang.Class.FromType(typeof(StyleSpan)));
            bool hasFlag        = false;
            var  spanType       = SpanTypes.InclusiveInclusive;

            foreach (StyleSpan span in styleSpans)
            {
                var spanStart    = EditableText.GetSpanStart(span);
                var spanEnd      = EditableText.GetSpanEnd(span);
                var newStart     = spanStart;
                var newEnd       = spanEnd;
                var startsBefore = false;
                var endsAfter    = false;

                if (spanStart < selectionStart)
                {
                    newStart     = selectionStart;
                    startsBefore = true;
                }
                if (spanEnd > selectionEnd)
                {
                    newEnd    = selectionEnd;
                    endsAfter = true;
                }

                if (span.Style == flagStyle)
                {
                    hasFlag = true;
                    EditableText.RemoveSpan(span);
                    EditableText.SetSpan(new StyleSpan(TypefaceStyle.Normal), newStart, newEnd, spanType);
                }
                else if (span.Style == TypefaceStyle.BoldItalic)
                {
                    hasFlag = true;
                    EditableText.RemoveSpan(span);
                    var flagLeft = TypefaceStyle.Bold;
                    if (flagStyle == TypefaceStyle.Bold)
                    {
                        flagLeft = TypefaceStyle.Italic;
                    }
                    EditableText.SetSpan(new StyleSpan(flagLeft), newStart, newEnd, spanType);
                }

                if (startsBefore)
                {
                    EditableText.SetSpan(new StyleSpan(span.Style), spanStart, newStart, SpanTypes.ExclusiveExclusive);
                }
                if (endsAfter)
                {
                    EditableText.SetSpan(new StyleSpan(span.Style), newEnd, spanEnd, SpanTypes.ExclusiveExclusive);
                }
            }
            if (!hasFlag)
            {
                EditableText.SetSpan(new StyleSpan(flagStyle), selectionStart, selectionEnd, spanType);
            }

            SaveChanges(selectionStart, selectionEnd);
        }
Beispiel #6
0
        /**
         * Modified from {@link Android.Text.Html}
         */
        private void end(IEditable output, Type kind, Boolean paragraphStyle, params Java.Lang.Object[] replaces)
        {
            Java.Lang.Object obj = getLast(output, kind);
            // start of the tag
            int where = output.GetSpanStart(obj);
            // end of the tag
            int len = output.Length();

            output.RemoveSpan(obj);

            if (where != len) {
                int thisLen = len;
                // paragraph styles like AlignmentSpan need to end with a new line!
                if (paragraphStyle) {
                    output.Append("\n");
                    thisLen++;
                }
                foreach (Java.Lang.Object replace in replaces) {
                    output.SetSpan(replace, where, thisLen, SpanTypes.ExclusiveExclusive);
                }

                //          if (HtmlTextView.DEBUG) {
                //              Log.d(HtmlTextView.TAG, "where: " + where);
                //              Log.d(HtmlTextView.TAG, "thisLen: " + thisLen);
                //          }
            }
        }