Java Code Examples for android.text.Editable#getSpanFlags()

The following examples show how to use android.text.Editable#getSpanFlags() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MetaKeyKeyListener.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void release(Editable content, Object what, KeyEvent event) {
    int current = content.getSpanFlags(what);

    switch (event.getKeyCharacterMap().getModifierBehavior()) {
        case KeyCharacterMap.MODIFIER_BEHAVIOR_CHORDED_OR_TOGGLED:
            if (current == USED)
                content.removeSpan(what);
            else if (current == PRESSED)
                content.setSpan(what, 0, 0, RELEASED);
            break;

        default:
            content.removeSpan(what);
            break;
    }
}
 
Example 2
Source File: MetaKeyKeyListener.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void press(Editable content, Object what) {
    int state = content.getSpanFlags(what);

    if (state == PRESSED)
        ; // repeat before use
    else if (state == RELEASED)
        content.setSpan(what, 0, 0, LOCKED);
    else if (state == USED)
        ; // repeat after use
    else if (state == LOCKED)
        content.removeSpan(what);
    else
        content.setSpan(what, 0, 0, PRESSED);
}
 
Example 3
Source File: RichUtils.java    From RichEditor with MIT License 5 votes vote down vote up
/**
 * 处理行内样式各个按钮的状态(点亮或置灰)
 *
 * @param type 样式类型
 */
private boolean handleInlineStyleButtonStatus(@RichTypeEnum String type) {
    Editable editable = mRichEditText.getEditableText();
    int cursorPos = mRichEditText.getSelectionEnd();
    IInlineSpan[] inlineSpans = (IInlineSpan[]) editable.getSpans(cursorPos, cursorPos, getSpanClassFromType(type));
    if (inlineSpans.length <= 0) {
        return false;
    }

    boolean isLight = false; //是否点亮

    for (IInlineSpan span : inlineSpans) {
        int spanStart = editable.getSpanStart(span);
        int spanEnd = editable.getSpanEnd(span);
        int spanFlag = editable.getSpanFlags(span);
        if (spanStart < cursorPos && spanEnd > cursorPos) {
            isLight = true;
        } else if (spanStart == cursorPos
                && (spanFlag == Spanned.SPAN_INCLUSIVE_INCLUSIVE || spanFlag == Spanned.SPAN_INCLUSIVE_EXCLUSIVE)) {
            isLight = true;
        } else if (spanEnd == cursorPos
                && (spanFlag == Spanned.SPAN_INCLUSIVE_INCLUSIVE || spanFlag == Spanned.SPAN_EXCLUSIVE_INCLUSIVE)) {
            isLight = true;
        }
    }

    return isLight;
}
 
Example 4
Source File: TextFormatBar.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
public void updateFormattingAtCursor() {
    if (mEditText == null)
        return;
    Editable text = mEditText.getText();
    int start = mEditText.getSelectionStart();
    int end = mEditText.getSelectionEnd();
    Object[] spans = text.getSpans(start, end, Object.class);

    mBoldButton.setSelected(false);
    mItalicButton.setSelected(false);
    mUnderlineButton.setSelected(false);

    int fgColor = -1;
    int bgColor = -1;

    for (Object span : spans) {
        if (!SpannableStringHelper.checkSpanInclude(text, span, start, end) ||
                (text.getSpanFlags(span) & Spanned.SPAN_COMPOSING) != 0)
            continue;
        if (span instanceof StyleSpan) {
            int style = ((StyleSpan) span).getStyle();
            if (style == Typeface.BOLD)
                mBoldButton.setSelected(true);
            else if (style == Typeface.ITALIC)
                mItalicButton.setSelected(true);
        } else if (span instanceof UnderlineSpan) {
            mUnderlineButton.setSelected(true);
        } else if (span instanceof ForegroundColorSpan) {
            fgColor = ((ForegroundColorSpan) span).getForegroundColor();
        } else if (span instanceof BackgroundColorSpan) {
            bgColor = ((BackgroundColorSpan) span).getBackgroundColor();
        }
    }

    ImageViewCompat.setImageTintList(mTextColorValue, fgColor != -1
            ? ColorStateList.valueOf(fgColor) : mTextColorValueDefault);
    ImageViewCompat.setImageTintList(mFillColorValue, bgColor != -1
            ? ColorStateList.valueOf(bgColor) : mFillColorValueDefault);
}
 
Example 5
Source File: ConverterHtmlToText.java    From memoir with Apache License 2.0 5 votes vote down vote up
/**
 * Fetch the matching opening Annotation object and verify that it's the one added by us.
 *
 * @param output Spannable string we're working with.
 * @return Starting Annotation object.
 */
private Object getOpeningAnnotation(Editable output) {
    Object[] objs = output.getSpans(0, output.length(), Annotation.class);
    for (int i = objs.length - 1; i >= 0; i--) {
        Annotation span = (Annotation) objs[i];
        if (output.getSpanFlags(objs[i]) == Spanned.SPAN_MARK_MARK
                && span.getKey().equals(IGNORED_ANNOTATION_KEY)
                && span.getValue().equals(IGNORED_ANNOTATION_VALUE)) {
            return objs[i];
        }
    }
    return null;
}
 
Example 6
Source File: ConverterHtmlToText.java    From memoir with Apache License 2.0 5 votes vote down vote up
/**
 * Fetch the matching opening Annotation object and verify that it's the one added by us.
 *
 * @param output Spannable string we're working with.
 * @return Starting Annotation object.
 */
private Object getOpeningAnnotation(Editable output) {
    Object[] objs = output.getSpans(0, output.length(), Annotation.class);
    for (int i = objs.length - 1; i >= 0; i--) {
        Annotation span = (Annotation) objs[i];
        if (output.getSpanFlags(objs[i]) == Spanned.SPAN_MARK_MARK
                && span.getKey().equals(IGNORED_ANNOTATION_KEY)
                && span.getValue().equals(IGNORED_ANNOTATION_VALUE)) {
            return objs[i];
        }
    }
    return null;
}
 
Example 7
Source File: MyHtmlTagHandler.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
private Object getLast(Editable text, Class kind) {
    Object[] objs = text.getSpans(0, text.length(), kind);

    if (objs.length == 0) {
        return null;
    } else {
        for(int i = objs.length;i>0;i--) {
            if(text.getSpanFlags(objs[i-1]) == Spannable.SPAN_MARK_MARK) {
                return objs[i-1];
            }
        }
        return null;
    }
}
 
Example 8
Source File: ConverterHtmlToText.java    From Android-RTEditor with Apache License 2.0 5 votes vote down vote up
/**
 * Fetch the matching opening Annotation object and verify that it's the one added by us.
 *
 * @param output Spannable string we're working with.
 * @return Starting Annotation object.
 */
private Object getOpeningAnnotation(Editable output) {
    Object[] objs = output.getSpans(0, output.length(), Annotation.class);
    for (int i = objs.length - 1; i >= 0; i--) {
        Annotation span = (Annotation) objs[i];
        if (output.getSpanFlags(objs[i]) == Spanned.SPAN_MARK_MARK
                && span.getKey().equals(IGNORED_ANNOTATION_KEY)
                && span.getValue().equals(IGNORED_ANNOTATION_VALUE)) {
            return objs[i];
        }
    }
    return null;
}
 
Example 9
Source File: HTMLCodeTagHandler.java    From Hews with MIT License 5 votes vote down vote up
private Object getLast(Editable text, Class kind) {
    Object[] objs = text.getSpans(0, text.length(), kind);
    if (objs.length == 0) {
        return null;
    } else {
        for (int i = objs.length; i > 0; i--) {
            if (text.getSpanFlags(objs[i - 1]) == Spannable.SPAN_MARK_MARK) {
                return objs[i - 1];
            }
        }
        return null;
    }
}
 
Example 10
Source File: KnifeTagHandler.java    From Knife with Apache License 2.0 5 votes vote down vote up
private static Object getLast(Editable text, Class kind) {
    Object[] spans = text.getSpans(0, text.length(), kind);

    if (spans.length == 0) {
        return null;
    } else {
        for (int i = spans.length; i > 0; i--) {
            if (text.getSpanFlags(spans[i - 1]) == Spannable.SPAN_MARK_MARK) {
                return spans[i - 1];
            }
        }

        return null;
    }
}
 
Example 11
Source File: HiHtmlTagHandler.java    From hipda with GNU General Public License v2.0 5 votes vote down vote up
private Object getLast(Editable text, Class kind) {
    Object[] objs = text.getSpans(0, text.length(), kind);

    if (objs.length == 0) {
        return null;
    } else {
        for (int i = objs.length; i > 0; i--) {
            if (text.getSpanFlags(objs[i - 1]) == Spannable.SPAN_MARK_MARK) {
                return objs[i - 1];
            }
        }
        return null;
    }
}
 
Example 12
Source File: FractionActivity.java    From advanced-textview with Apache License 2.0 5 votes vote down vote up
private Object getLast(Editable text, Class kind) {
  Object[] objs = text.getSpans(0, text.length(), kind);

  if (objs.length == 0) {
    return null;
  } else {
    for (int i = objs.length - 1; i >= 0; --i) {
      if(text.getSpanFlags(objs[i]) == Spannable.SPAN_MARK_MARK) {
        return objs[i];
      }
    }
    return null;
  }
}
 
Example 13
Source File: HtmlTagHandler.java    From v2ex with Apache License 2.0 5 votes vote down vote up
/**
 * Get last marked position of a specific tag kind (private class)
 *
 * @param text
 * @param kind
 * @return
 */
private Object getLast(Editable text, Class kind) {
    Object[] objs = text.getSpans(0, text.length(), kind);
    if (objs.length == 0) {
        return null;
    } else {
        for (int i = objs.length; i > 0; i--) {
            if (text.getSpanFlags(objs[i - 1]) == Spannable.SPAN_MARK_MARK) {
                return objs[i - 1];
            }
        }
        return null;
    }
}
 
Example 14
Source File: HtmlTagHandler.java    From html-textview with Apache License 2.0 5 votes vote down vote up
/**
 * Get last marked position of a specific tag kind (private class)
 */
private static Object getLast(Editable text, Class kind) {
    Object[] objs = text.getSpans(0, text.length(), kind);
    if (objs.length == 0) {
        return null;
    } else {
        for (int i = objs.length; i > 0; i--) {
            if (text.getSpanFlags(objs[i - 1]) == Spannable.SPAN_MARK_MARK) {
                return objs[i - 1];
            }
        }
        return null;
    }
}