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


Java Factory类代码示例

本文整理汇总了Java中android.text.Spannable.Factory的典型用法代码示例。如果您正苦于以下问题:Java Factory类的具体用法?Java Factory怎么用?Java Factory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: setText

import android.text.Spannable.Factory; //导入依赖的package包/类
public void setText(CharSequence text, boolean detect_links){
	this.text = text;
	if(detect_links){
		Spannable s = null;
		if(this.text instanceof Spannable){
			s = (Spannable)this.text;
		}else{
			s = Factory.getInstance().newSpannable(this.text);
		}
		Linkify.addLinks(s, Linkify.WEB_URLS);
		this.text = s;
	}
	//relayout();
	invalidate();
}
 
开发者ID:zilgam,项目名称:Bimoid-IM-Android,代码行数:16,代码来源:MyTextView.java

示例2: replaceTextsWithImages

import android.text.Spannable.Factory; //导入依赖的package包/类
/**
 * Replaces the given texts with the given image (as a `Spannable`) in the specified `EditText` instance
 *
 * @param context a context reference
 * @param editText the `EditText` instance to operate on
 * @param searchTexts the texts to replace
 * @param replacementImages the resource IDs of the images to insert
 */
public static void replaceTextsWithImages(final Context context, final EditText editText, final String[] searchTexts, final int[] replacementImages) {
	if (searchTexts.length != replacementImages.length) {
		throw new RuntimeException("Number of search texts must match the number of replacement images");
	}

	final int oldCursorPosition = editText.getSelectionStart();
	final Factory spannableFactory = Spannable.Factory.getInstance();
	final Spannable spannable = spannableFactory.newSpannable(editText.getText().toString());

	for (int i = 0; i < searchTexts.length; i++) {
		final Pattern pattern = Pattern.compile(Pattern.quote(searchTexts[i]));
		final Matcher matcher = pattern.matcher(spannable);

		boolean set;
		while (matcher.find()) {
			set = true;
			for (ImageSpan span : spannable.getSpans(matcher.start(), matcher.end(), ImageSpan.class)) {
				if (spannable.getSpanStart(span) >= matcher.start() && spannable.getSpanEnd(span) <= matcher.end()) {
					spannable.removeSpan(span);
				}
				else {
					set = false;
					break;
				}
			}

			if (set) {
				spannable.setSpan(new ImageSpan(context, replacementImages[i]), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			}
		}
	}

	editText.setText(spannable);

	if (oldCursorPosition >= 0) {
		editText.setSelection(oldCursorPosition);
	}
}
 
开发者ID:delight-im,项目名称:Android-Commons,代码行数:47,代码来源:UI.java


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