當前位置: 首頁>>代碼示例>>Java>>正文


Java ImageSpan類代碼示例

本文整理匯總了Java中android.text.style.ImageSpan的典型用法代碼示例。如果您正苦於以下問題:Java ImageSpan類的具體用法?Java ImageSpan怎麽用?Java ImageSpan使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ImageSpan類屬於android.text.style包,在下文中一共展示了ImageSpan類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: replace

import android.text.style.ImageSpan; //導入依賴的package包/類
boolean replace(ImageSpan by) {
    int start = builder.getSpanStart(span);
    int end = builder.getSpanEnd(span);

    if (start == -1)
        return true;

    builder.removeSpan(span);
    builder.setSpan(
            by,
            start,
            end,
            Spanned.SPAN_INCLUSIVE_EXCLUSIVE
    );
    target.setText(builder);
    return true;
}
 
開發者ID:cab404,項目名稱:maud,代碼行數:18,代碼來源:SpanImageListener.java

示例2: setText

import android.text.style.ImageSpan; //導入依賴的package包/類
/** 顯示文本和表情 */
public static void setText(TextView textView, String text) {
    Context context = textView.getContext();
    Resources resources = context.getResources();
    SpannableString ss = new SpannableString(text);

    // 正則表達式: [高興]
    Pattern p = Pattern.compile("\\[([A-Za-z\u4E00-\u9FA5]+)\\]");
    Matcher matcher = p.matcher(ss);
    while (matcher.find()) {
        // 匹配到一個表情字符串
        String emoji = matcher.group();
        // 過濾非表情符,比如: [xxx]
        if (EMOJI_DATAS.containsKey(emoji)) {   // 是表情才處理
            // System.out.println("----------" + emoji);
            // 指定了一張圖片
            Bitmap bitmap = BitmapFactory.decodeResource(resources, EMOJI_DATAS.get(emoji));
            bitmap = Global.createBitmap(bitmap, Global.dp2px(20));     // 圖片的寬高為20dp
            ImageSpan span = new ImageSpan(context, bitmap, ImageSpan.ALIGN_BOTTOM);
            int start = matcher.start();
            int end = matcher.end();
            ss.setSpan(span, start, end, 0);
        }
    }
    textView.setText(ss);
}
 
開發者ID:JackChan1999,項目名稱:WeChatDemo,代碼行數:27,代碼來源:EmojiUtil.java

示例3: handleTag

import android.text.style.ImageSpan; //導入依賴的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

示例4: emoticonDisplay

import android.text.style.ImageSpan; //導入依賴的package包/類
public static void emoticonDisplay(Context context, Spannable spannable, String emoticonName, int fontSize, int start, int end) {
    Drawable drawable = getDrawableFromAssets(context, emoticonName);
    if (drawable != null) {
        int itemHeight;
        int itemWidth;
        if (fontSize == WRAP_DRAWABLE) {
            itemHeight = drawable.getIntrinsicHeight();
            itemWidth = drawable.getIntrinsicWidth();
        } else {
            itemHeight = fontSize;
            itemWidth = fontSize;
        }

        drawable.setBounds(0, 0, itemHeight, itemWidth);
        ImageSpan imageSpan = new ImageSpan(drawable);
        spannable.setSpan(imageSpan, start, end, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:XhsFilter.java

示例5: createAndPutChipForUser

import android.text.style.ImageSpan; //導入依賴的package包/類
private ChipSpan createAndPutChipForUser(TLRPC.User user) {
    LayoutInflater lf = (LayoutInflater) ApplicationLoader.applicationContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    View textView = lf.inflate(R.layout.group_create_bubble, null);
    TextView text = (TextView)textView.findViewById(R.id.bubble_text_view);
    String name = UserObject.getUserName(user);
    if (name.length() == 0 && user.phone != null && user.phone.length() != 0) {
        name = PhoneFormat.getInstance().format("+" + user.phone);
    }
    text.setText(name + ", ");

    int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    textView.measure(spec, spec);
    textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
    Bitmap b = Bitmap.createBitmap(textView.getWidth(), textView.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(b);
    canvas.translate(-textView.getScrollX(), -textView.getScrollY());
    textView.draw(canvas);
    textView.setDrawingCacheEnabled(true);
    Bitmap cacheBmp = textView.getDrawingCache();
    Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
    textView.destroyDrawingCache();

    final BitmapDrawable bmpDrawable = new BitmapDrawable(b);
    bmpDrawable.setBounds(0, 0, b.getWidth(), b.getHeight());

    SpannableStringBuilder ssb = new SpannableStringBuilder("");
    ChipSpan span = new ChipSpan(bmpDrawable, ImageSpan.ALIGN_BASELINE);
    allSpans.add(span);
    selectedContacts.put(user.id, span);
    for (ImageSpan sp : allSpans) {
        ssb.append("<<");
        ssb.setSpan(sp, ssb.length() - 2, ssb.length(), SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    userSelectEditText.setText(ssb);
    userSelectEditText.setSelection(ssb.length());
    return span;
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:38,代碼來源:GroupCreateActivity.java

示例6: getTextWithBackground

import android.text.style.ImageSpan; //導入依賴的package包/類
public static ImageSpan getTextWithBackground(Drawable background, final int textSize
        , final int padding, final int color){
    return new ImageSpan(background){
        @Override
        public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
            paint.setTextSize(textSize + padding);
            int len = Math.round(paint.measureText(text, start, end));
            getDrawable().setBounds(0, 0, len, (int)  (1.5f * getTextMaxHeight(paint,textSize)));

            Drawable b = getDrawable();
            canvas.save();
            int transY = ((bottom-top) - b.getBounds().bottom)/2+top;
            canvas.translate(x , transY);
            b.draw(canvas);
            canvas.restore();

            paint.setColor(color);
            paint.setTextSize(textSize);
            canvas.drawText(text.subSequence(start, end).toString(), x+ padding ,y, paint);
        }
    };
}
 
開發者ID:zuoweitan,項目名稱:Hitalk,代碼行數:23,代碼來源:TextSpanUtils.java

示例7: replace

import android.text.style.ImageSpan; //導入依賴的package包/類
private CharSequence replace(CharSequence text) {
	try {
		SpannableStringBuilder builder = new SpannableStringBuilder(text);
		Pattern pattern = buildPattern();
		Matcher matcher = pattern.matcher(text);
		while (matcher.find()) {
			if (BaseApplication.mEmoticonsId.containsKey(matcher.group())) {
				int id = BaseApplication.mEmoticonsId.get(matcher.group());
				Bitmap bitmap = BitmapFactory.decodeResource(
						getResources(), id);
				if (bitmap != null) {
					ImageSpan span = new ImageSpan(getContext(), bitmap);
					builder.setSpan(span, matcher.start(), matcher.end(),
							Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
				}
			}
		}
		return builder;
	} catch (Exception e) {
		return text;
	}
}
 
開發者ID:qizhenghao,項目名稱:HiBangClient,代碼行數:23,代碼來源:EmoticonsTextView.java

示例8: handleTagNode

import android.text.style.ImageSpan; //導入依賴的package包/類
@Override
public void handleTagNode(TagNode node, SpannableStringBuilder builder,
		int start, int end, SpanStack stack) {
	String src = node.getAttributeByName("src");

	builder.append("\uFFFC");

	Bitmap bitmap = loadBitmap(src);

	if (bitmap != null) {
		Drawable drawable = new BitmapDrawable(bitmap);
		drawable.setBounds(0, 0, bitmap.getWidth() - 1,
				bitmap.getHeight() - 1);

           stack.pushSpan( new ImageSpan(drawable), start, builder.length() );
	}
}
 
開發者ID:SysdataSpA,項目名稱:SDHtmlTextView,代碼行數:18,代碼來源:ImageHandler.java

示例9: getSpannable

import android.text.style.ImageSpan; //導入依賴的package包/類
@NonNull
  private SpannableStringBuilder getSpannable() {
    SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(getResources().getString(R.string.content_cn));
    Drawable drawable = getResources().getDrawable(R.mipmap.ic_launcher);
    drawable.setBounds(0, 0, 35, 35);

    spannableStringBuilder.setSpan(new ImageSpan(drawable)
        , 36, 37, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);

    spannableStringBuilder.setSpan(new ImageSpan(drawable)
        , 37, 38, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);

    spannableStringBuilder.setSpan(new ImageSpan(drawable)
        , 38, 39, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);

    spannableStringBuilder.setSpan(new ImageSpan(drawable)
        , 39, 40, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
//    ItalicReplacementSpan italicSpan = new ItalicReplacementSpan(-0.25f);
//    StrokeSpan strokeSpan = new StrokeSpan(Color.BLUE, Color.YELLOW, 20);
//    spannableStringBuilder.setSpan(strokeSpan, 0, spannableStringBuilder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    return spannableStringBuilder;
  }
 
開發者ID:lsjwzh,項目名稱:FastTextView,代碼行數:23,代碼來源:EllipseFragment.java

示例10: parseEmoji

import android.text.style.ImageSpan; //導入依賴的package包/類
public static  SpannableStringBuilder parseEmoji(Context context,String content){
	int size = UIUtils.dip2Px(25,context);
	//裏[smiley_00]ff[smiley_78]
	SpannableStringBuilder builder = new SpannableStringBuilder(content);
	//正則表達式
	Pattern pattern = Pattern.compile("\\[smiley_(.*?)\\]");
	Matcher matcher = pattern.matcher(content);
	while(matcher.find()){
		String emo = matcher.group();//[smiley_00]
			emo = emo.substring(1, emo.length()-1);
		//獲取表情的id
		int id = context.getResources().getIdentifier(emo, "drawable", context.getPackageName());
		if(id != 0 ){
			Drawable drawable = context.getResources().getDrawable(id);
			// 必須設置圖片大小
			drawable.setBounds(0, 0, size, size);
			// 包裝一下圖片
			ImageSpan span = new ImageSpan(drawable);
			// 把文字替換成圖片
			builder.setSpan(span, matcher.start(), matcher.end(),
					Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		}
	}
	return builder;
}
 
開發者ID:JackChan1999,項目名稱:WeChatDemo,代碼行數:26,代碼來源:EmojiParser.java

示例11: render

import android.text.style.ImageSpan; //導入依賴的package包/類
public void render(final TextView textView, final Context context, String line)
{
    final Handler handler = new Handler(Looper.getMainLooper());
    final SpannableString text = new SpannableString("  " + line + "\n");

    handler.post(new Runnable()
    {
        @Override
        public void run()
        {
            //set the image tag behind (left of) the text
            text.setSpan(new ImageSpan(context, IMAGE_TAG), 0, 1, 0);
            textView.append(text);
        }
    });
}
 
開發者ID:afonsotrepa,項目名稱:PocketGopher,代碼行數:17,代碼來源:UnknownPage.java

示例12: getEmotionText

import android.text.style.ImageSpan; //導入依賴的package包/類
public static SpannableString getEmotionText(Context context, String source, int
        emotionSizeDp) {
    SpannableString spannableString = new SpannableString(source);
    Matcher matcher = Pattern.compile(REGEX_GROUP).matcher(spannableString);
    if (matcher.find()) {
        matcher.reset();
    }
    while (matcher.find()) {
        String emojiStr = matcher.group(1);
        if (emojiStr != null) {
            ImageSpan imageSpan = getImageSpan(context, emojiStr, emotionSizeDp);
            if (imageSpan != null) {
                int start = matcher.start(1);
                spannableString.setSpan(imageSpan, start, emojiStr.length() + start, 33);
            }
        }
    }
    return spannableString;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:20,代碼來源:MQEmotionUtil.java

示例13: startImg

import android.text.style.ImageSpan; //導入依賴的package包/類
private void startImg(Editable text, Attributes attributes, HtmlCompat.ImageGetter img) {
    String src = attributes.getValue("", "src");
    Drawable d = null;
    if (img != null) {
        d = img.getDrawable(src, attributes);
    }
    if (d == null) {
        Resources res = mContext.getResources();
        d = res.getDrawable(R.drawable.unknown_image);
        d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
    }
    int len = text.length();
    text.append("\uFFFC");
    text.setSpan(new ImageSpan(d, src), len, text.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
 
開發者ID:Pixplicity,項目名稱:HtmlCompat,代碼行數:17,代碼來源:HtmlToSpannedConverter.java

示例14: getFace

import android.text.style.ImageSpan; //導入依賴的package包/類
public SpannableStringBuilder getFace(Context mContext, String content) {
    SpannableStringBuilder sb = new SpannableStringBuilder();
    try {
        /**
         * 經過測試,雖然這裏tempText被替換為png顯示,但是但我單擊發送按鈕時,獲取到輸入框的內容是tempText的值而不是png
         * 所以這裏對這個tempText值做特殊處理
         * 格式:[face/png/f_static_000.png],以方便判斷當前圖片是哪一個
         * */
        String tempText = "[" + content + "]";
        sb.append(tempText);
        sb.setSpan(
                new ImageSpan(mContext, BitmapFactory.decodeStream(mContext.getAssets().open(content))),
                sb.length() - tempText.length(),
                sb.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    } catch (Exception e) {
        e.printStackTrace();
    }

    return sb;
}
 
開發者ID:DyncKathline,項目名稱:LiveGiftLayout,代碼行數:23,代碼來源:ExpressionUtil.java

示例15: bindContentView

import android.text.style.ImageSpan; //導入依賴的package包/類
@Override
protected void bindContentView() {
    layoutDirection();

    TextView bodyTextView = findViewById(R.id.nim_message_item_text_body);
    bodyTextView.setTextColor(isReceivedMessage() ? Color.BLACK : Color.WHITE);
    bodyTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onItemClick();
        }
    });
    MoonUtil.identifyFaceExpression(NimUIKit.getContext(), bodyTextView, getDisplayText(), ImageSpan.ALIGN_BOTTOM);
    bodyTextView.setMovementMethod(LinkMovementMethod.getInstance());
    bodyTextView.setOnLongClickListener(longClickListener);
}
 
開發者ID:newDeepLearing,項目名稱:decoy,代碼行數:17,代碼來源:ChatRoomMsgViewHolderBaseText.java


注:本文中的android.text.style.ImageSpan類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。