Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        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);
        }