当前位置: 首页>>代码示例>>Java>>正文


Java Editable.getSpans方法代码示例

本文整理汇总了Java中android.text.Editable.getSpans方法的典型用法代码示例。如果您正苦于以下问题:Java Editable.getSpans方法的具体用法?Java Editable.getSpans怎么用?Java Editable.getSpans使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.text.Editable的用法示例。


在下文中一共展示了Editable.getSpans方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onTouchEvent

import android.text.Editable; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
    int action = event.getActionMasked();
    Editable text = getText();

    if (text != null && action == MotionEvent.ACTION_UP) {
        int offset = getOffsetForPosition(event.getX(), event.getY());

        if (offset != -1) {
            TokenImageSpan[] links = text.getSpans(offset, offset, RecipientTokenSpan.class);
            if (links.length > 0) {
                showAlternates(links[0].getToken());
                return true;
            }
        }
    }

    return super.onTouchEvent(event);
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:20,代码来源:RecipientSelectView.java

示例2: handleTag

import android.text.Editable; //导入方法依赖的package包/类
@Override
public void handleTag(boolean opening, String tag, Editable output,
		XMLReader xmlReader) {
	// TODO Auto-generated method stub

	// �����ǩ<img>
	if (tag.toLowerCase().equals("img")) {
		// ��ȡ����
		int len = output.length();
		// ��ȡͼƬ��ַ
		ImageSpan[] images = output.getSpans(len-1, len, ImageSpan.class);
		String imgURL = images[0].getSource();
		
		// ʹͼƬ�ɵ������������¼�
		output.setSpan(new ImageClick(context, imgURL), len-1, len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
	}
}
 
开发者ID:didikee,项目名称:cnBetaGeek,代码行数:18,代码来源:MyTagHandler.java

示例3: getTokenViewForRecipient

import android.text.Editable; //导入方法依赖的package包/类
/**
 * Find the token view tied to a given recipient. This method relies on spans to
 * be of the RecipientTokenSpan class, as created by the buildSpanForObject method.
 */
private View getTokenViewForRecipient(Recipient currentRecipient) {
    Editable text = getText();
    if (text == null) {
        return null;
    }

    RecipientTokenSpan[] recipientSpans = text.getSpans(0, text.length(), RecipientTokenSpan.class);
    for (RecipientTokenSpan recipientSpan : recipientSpans) {
        if (recipientSpan.getToken().equals(currentRecipient)) {
            return recipientSpan.view;
        }
    }

    return null;
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:20,代码来源:RecipientSelectView.java

示例4: setItalic

import android.text.Editable; //导入方法依赖的package包/类
void setItalic(boolean isItalic) {
    int index = getSelectionIndex();
    if (index >= 0 && index < mSections.size()) {
        mSections.get(index).setItalic(isItalic);
    }
    Editable edit = getEditableText();
    int star = getSectionStart();
    int end = getSectionEnd();
    if (isItalic) {
        edit.setSpan(new StyleSpan(Typeface.ITALIC),
                star,
                end,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    } else {
        StyleSpan[] styleSpans = edit.getSpans(star,
                end, StyleSpan.class);
        for (CharacterStyle span : styleSpans) {
            if (span instanceof StyleSpan && ((StyleSpan) span).getStyle() == Typeface.ITALIC)
                edit.removeSpan(span);
        }
    }
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:23,代码来源:RichEditText.java

示例5: undo

import android.text.Editable; //导入方法依赖的package包/类
public void undo() {
    EditItem edit = mEditHistory.getPrevious();
    if (edit == null) {
        return;
    }

    Editable editable = mTextView.getEditableText();
    int start = edit.start;
    int end = start + (edit.after != null ? edit.after.length() : 0);

    mIsUndoOrRedo = true;
    editable.replace(start, end, edit.before);
    mIsUndoOrRedo = false;

    for (Object o : editable.getSpans(0, editable.length(), UnderlineSpan.class)) {
        editable.removeSpan(o);
    }

    Selection.setSelection(editable, edit.before == null ? start : (start + edit.before.length()));
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:21,代码来源:UndoRedoSupportEditText.java

示例6: setMidLine

import android.text.Editable; //导入方法依赖的package包/类
/**
 * 中横线,即删除线
 *
 * @param isMidLine isMidLine
 */
void setMidLine(boolean isMidLine, int index) {
    if (index >= 0 && index < mSections.size()) {
        mSections.get(index).setMidLine(isMidLine);
    }
    Editable edit = getEditableText();
    int star = getSectionStart();
    int end = getSectionEnd();
    if (isMidLine) {
        edit.setSpan(new StrikethroughSpan(),
                star,
                end,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    } else {
        StrikethroughSpan[] styleSpans = edit.getSpans(star,
                end, StrikethroughSpan.class);
        for (StrikethroughSpan span : styleSpans) {
            edit.removeSpan(span);
        }
    }
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:26,代码来源:RichEditText.java

示例7: getOpeningAnnotation

import android.text.Editable; //导入方法依赖的package包/类
/**
 * Fetch the matching opening Annotation object and verify that it's the one added by QMail.
 * @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]) == Spannable.SPAN_MARK_MARK
                && span.getKey().equals(IGNORED_ANNOTATION_KEY)
                && span.getValue().equals(IGNORED_ANNOTATION_VALUE)) {
            return objs[i];
        }
    }
    return null;
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:18,代码来源:HtmlConverter.java

示例8: redrawAllTokens

import android.text.Editable; //导入方法依赖的package包/类
private void redrawAllTokens() {
    Editable text = getText();
    if (text == null) {
        return;
    }

    RecipientTokenSpan[] recipientSpans = text.getSpans(0, text.length(), RecipientTokenSpan.class);
    for (RecipientTokenSpan recipientSpan : recipientSpans) {
        bindObjectView(recipientSpan.getToken(), recipientSpan.view);
    }

    invalidate();
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:14,代码来源:RecipientSelectView.java

示例9: removeSpans

import android.text.Editable; //导入方法依赖的package包/类
/**
 * Helper function to remove all spans of a certain type from an {@link Editable}.
 */
private <T> void removeSpans(Editable text, Class<T> clazz) {
    T[] spans = text.getSpans(0, text.length(), clazz);
    for (T span : spans) {
        text.removeSpan(span);
    }
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:10,代码来源:CategoryTextWatcher.java

示例10: setColorSpan

import android.text.Editable; //导入方法依赖的package包/类
void setColorSpan(int color) {
    Editable edit = getEditableText();
    int star = getSectionStart();
    int end = getSectionEnd();
    ForegroundColorSpan[] styleSpans = edit.getSpans(star, end, ForegroundColorSpan.class);
    for (ForegroundColorSpan span : styleSpans) {
        edit.removeSpan(span);
    }
    edit.setSpan(new ForegroundColorSpan(color), star, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:11,代码来源:RichEditText.java

示例11: replaceLastChar

import android.text.Editable; //导入方法依赖的package包/类
private void replaceLastChar(@NonNull String chr, SpannableString spannable) {
    Editable msg = getText();
    int selStart = getSelectionStart();
    int selEnd = getSelectionEnd();

    int selStartBefore = selStart - 1;
    if (selStart == selEnd && selStart > 0
            && chr.equals(msg.subSequence(selStartBefore, selEnd).toString())
            && msg.getSpans(selStartBefore, selEnd, RichEditText.TagSpan.class).length == 0) {
        selStart = selStartBefore;
    }

    msg.replace(selStart >= 0 ? selStart : 0, selEnd >= 0 ? selEnd : 0, spannable);
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:15,代码来源:RichEditText.java

示例12: getLast

import android.text.Editable; //导入方法依赖的package包/类
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;
    }
}
 
开发者ID:afiqiqmal,项目名称:My-Android-Base-Code,代码行数:14,代码来源:HtmlTagHandler.java

示例13: setTextSizeSpan

import android.text.Editable; //导入方法依赖的package包/类
private void setTextSizeSpan(int textSize) {
    Editable edit = getEditableText();
    int star = getSectionStart();
    int end = getSectionEnd();
    if (star >= end)
        return;
    AbsoluteSizeSpan[] styleSpans = edit.getSpans(star, end, AbsoluteSizeSpan.class);
    for (AbsoluteSizeSpan span : styleSpans) {
        edit.removeSpan(span);
    }
    edit.setSpan(new AbsoluteSizeSpan(UI.dipToPx(getContext(), textSize)), star, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:13,代码来源:RichEditText.java

示例14: onTopicKeyArrived

import android.text.Editable; //导入方法依赖的package包/类
@Override
public boolean onTopicKeyArrived(RichEditText editText) {
    Editable msg = editText.getText();
    String msgStr = msg.toString();
    int selStartIndex = editText.getSelectionStart();
    int selEndIndex = editText.getSelectionEnd();

    if (TextUtils.isEmpty(msgStr.trim()) || selStartIndex <= 0) {
        skipTopic(editText);
        return true;
    }

    int startIndex = 0;
    RichEditText.TagSpan[] spans = msg.getSpans(0, selStartIndex, RichEditText.TagSpan.class);
    if (spans.length > 0) {
        startIndex = msg.getSpanEnd(spans[spans.length - 1]);
    }

    boolean isMatcher = false;
    String tagStr = msgStr.substring(startIndex, selStartIndex) + "#";
    Pattern pattern = Pattern.compile(RichEditText.MATCH_TOPIC);
    Matcher matcher = pattern.matcher(tagStr);
    while (matcher.find()) {
        String str = matcher.group();
        int matcherStart = matcher.start() + startIndex;
        int matcherEnd = matcher.end() + startIndex;
        if (matcherEnd == selStartIndex + 1)
            msg.replace(selStartIndex, selEndIndex, "#");
        msg.setSpan(new RichEditText.TagSpan(str), matcherStart, matcherEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        isMatcher = true;
    }
    if (isMatcher) {
        editText.setSelection(selEndIndex);
        return false;
    }

    skipTopic(editText);
    return true;
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:40,代码来源:OnKeyArrivedListenerAdapter.java

示例15: find

import android.text.Editable; //导入方法依赖的package包/类
/**
 * highlight find word
 *
 * @param what     - input
 * @param regex    - is java regex
 * @param wordOnly - find word only
 */
public void find(String what, boolean regex, boolean wordOnly, boolean matchCase) {
    Pattern pattern;
    if (regex) {
        if (matchCase) {
            pattern = Pattern.compile(what);
        } else {
            pattern = Pattern.compile(what, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
        }
    } else {
        if (wordOnly) {
            if (matchCase) {
                pattern = Pattern.compile("\\s" + what + "\\s");
            } else {
                pattern = Pattern.compile("\\s" + Pattern.quote(what) + "\\s", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
            }
        } else {
            if (matchCase) {
                pattern = Pattern.compile(Pattern.quote(what));
            } else {
                pattern = Pattern.compile(Pattern.quote(what), Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
            }
        }
    }
    Editable e = getEditableText();
    //remove all span
    BackgroundColorSpan spans[] = e.getSpans(0, e.length(), BackgroundColorSpan.class);
    for (int n = spans.length; n-- > 0; )
        e.removeSpan(spans[n]);
    //set span

    for (Matcher m = pattern.matcher(e); m.find(); ) {
        e.setSpan(new BackgroundColorSpan(codeTheme.getErrorColor()),
                m.start(),
                m.end(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:45,代码来源:HighlightEditor.java


注:本文中的android.text.Editable.getSpans方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。