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); } } }
protected virtual IMarkSpan GetLastMarkSpan(IEditable text) { var markSpanType = CreateStartMarkSpan().GetType(); var markSpans = text.GetSpans(0, text.Length(), JClass.FromType(markSpanType)).ToList(); var lastMarkSpan = markSpans.LastOrDefault(); return(lastMarkSpan as IMarkSpan); }
private void ClearSpanType(IEditable e, Java.Lang.Class spanType) { CharacterStyle[] spans = (CharacterStyle[])e.GetSpans(0, e.Length(), spanType); for (int n = spans.Length; n-- > 0;) { e.RemoveSpan(spans[n]); } }
/** * Get last marked position of a specific tag kind (private class) */ private static Java.Lang.Object GetLast(IEditable text, Type kind) { Java.Lang.Object[] objs = text.GetSpans(0, text.Length(), Java.Lang.Class.FromType(kind)); // TODO: LOl will this work? if (objs.Length == 0) { return(null); } else { for (int i = objs.Length; i > 0; i--) { if (text.GetSpanFlags(objs[i - 1]) == SpanTypes.MarkMark) { return(objs[i - 1]); } } return(null); } }
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); }
/** * Get last marked position of a specific tag kind (private class) */ private static Java.Lang.Object getLast(IEditable Text, Type kind) { Java.Lang.Object[] objs = Text.GetSpans(0, Text.Length(), Java.Lang.Class.FromType(kind)); // TODO: LOl will this work? if (objs.Length == 0) { return null; } else { for (int i = objs.Length; i > 0; i--) { if (Text.GetSpanFlags(objs[i - 1]) == SpanTypes.MarkMark) { return objs[i - 1]; } } return null; } }