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


Java ImageSpan.ALIGN_BASELINE属性代码示例

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


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

示例1: createAndPutChipForUser

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,代码行数:37,代码来源:GroupCreateActivity.java

示例2: insert

public void insert(SpannableString message) {

        for (String emoji : emojiList) {
            Matcher matcher = getEmojiParser(message.toString(), emoji);
            Bitmap emojiBitmap = null;
            while (matcher.find()) {
                if (emojiBitmap == null) {
                    Resources resources = context.getResources();
                    int resourceId = resources.getIdentifier(String.format("%1s_%2s", emojiResourcePrefix, emoji), EMOJI_TYPE, context.getPackageName());

                    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId);
                    emojiBitmap = Bitmap.createScaledBitmap(bitmap, textSize, textSize, true);
                    bitmap.recycle();
                }
                ImageSpan span = new ImageSpan(context, emojiBitmap, ImageSpan.ALIGN_BASELINE);
                message.setSpan(span, matcher.start(), matcher.end(), 0);
            }
        }

    }
 
开发者ID:charafau,项目名称:TurboChat,代码行数:20,代码来源:EmojiParser.java

示例3: fromStringToEmoji

/**
 * 讲带emoji表情的字符串解析成带表情的文本
 *
 * @param text
 * @return
 */
public static CharSequence fromStringToEmoji(CharSequence text, Context context) {
    SpannableStringBuilder builder = new SpannableStringBuilder(text);
    Pattern mPattern = Pattern.compile(":(\\S+?):");
    Matcher matcher = mPattern.matcher(text);
    Integer resId = null;
    while (matcher.find()) {
        resId = EmojiTranslate.emojiSrcMap.get(matcher.group(0));
        if (resId != null && resId > 0) {
            Drawable drawable = context.getResources().getDrawable(resId);
            int w = (int) (drawable.getIntrinsicWidth() * 0.32);
            int h = (int) (drawable.getIntrinsicHeight() * 0.32);
            drawable.setBounds(0, 0, w, h);//这里设置图片的大小
            ImageSpan imageSpan = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
            builder.setSpan(imageSpan, matcher.start(),
                    matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    return builder;
}
 
开发者ID:LegendKe,项目名称:MyTravelingDiary,代码行数:25,代码来源:EmojiUtils.java

示例4: fromStringToEmoji1

/**
 * 讲带emoji表情的字符串解析成带表情的文本
 *
 * @param text
 * @return
 */

public static CharSequence fromStringToEmoji1(CharSequence text, Context context) {
    SpannableStringBuilder builder = new SpannableStringBuilder(text);
    Pattern mPattern = Pattern.compile(":(\\S+?):");
    Matcher matcher = mPattern.matcher(text);
    Integer resId = null;
    while (matcher.find()) {
        resId = EmojiTranslate.emojiSrcMap.get(matcher.group(0));
        if (resId != null && resId > 0) {
            Drawable drawable = context.getResources().getDrawable(resId);
            int w = (int) (drawable.getIntrinsicWidth() * 0.38);
            int h = (int) (drawable.getIntrinsicHeight() * 0.38);
            drawable.setBounds(0, 0, w, h);//这里设置图片的大小
            ImageSpan imageSpan = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
            builder.setSpan(imageSpan, matcher.start(),
                    matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    return builder;
}
 
开发者ID:LegendKe,项目名称:MyTravelingDiary,代码行数:26,代码来源:EmojiUtils.java

示例5: text2Emotion

/**
 * 微博文字转表情
 *
 * @param boundPx the icon' s rectangle bound, if zero, use the default
 */
public static SpannableString text2Emotion(Context context, String key, int boundPx) {
	SpannableString spannable = new SpannableString(key);
	InputStream inputStream = null;
	Drawable drawable = null;
	try {
		inputStream = context.getAssets().open(TweetImageSpan.EMOTIONS_DIR + TweetImageSpan.EMOTIONS.get(key));
		drawable = Drawable.createFromStream(inputStream, null);
	} catch (IOException e) {
		Log.e(TAG, "load emotion error!", e);
	} finally {
		closeIO(inputStream);
	}
	if (drawable != null) {
		if (boundPx == 0) {
			drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
		} else {
			drawable.setBounds(0, 0, boundPx, boundPx);
		}
		ImageSpan span = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
		spannable.setSpan(span, 0, key.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
	}
	return spannable;
}
 
开发者ID:missmisslonely,项目名称:fakeweibo,代码行数:28,代码来源:CatnutUtils.java

示例6: getEmotionContent

public static SpannableString getEmotionContent(int emotion_map_type, final Context context, final TextView tv, String source) {
        SpannableString spannableString = new SpannableString(source);
        Resources res = context.getResources();

        String regexEmotion = "\\[([\u4e00-\u9fa5\\w])+\\]";
        Pattern patternEmotion = Pattern.compile(regexEmotion);
        Matcher matcherEmotion = patternEmotion.matcher(spannableString);

        while (matcherEmotion.find()) {
            // 获取匹配到的具体字符
            String key = matcherEmotion.group();
            // 匹配字符串的开始位置
            int start = matcherEmotion.start();
            // 利用表情名字获取到对应的图片
            Integer imgRes = EmotionUtils.getImgByName(emotion_map_type, key);
            if (imgRes != -1) {//-1代表纯文本,没有图片
                // 压缩表情图片
                int size = (int) tv.getTextSize() * 13 / 10;
                Bitmap bitmap = BitmapFactory.decodeResource(res, imgRes);
                Bitmap scaleBitmap = Bitmap.createScaledBitmap(bitmap, size, size, true);

//				ImageSpan span = new ImageSpan(context, scaleBitmap);
                final CenterAlignImageSpan span = new CenterAlignImageSpan(context, scaleBitmap, ImageSpan.ALIGN_BASELINE);
                spannableString.setSpan(span, start, start + key.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
        return spannableString;
    }
 
开发者ID:SiberiaDante,项目名称:EmotionApp,代码行数:28,代码来源:SpanStringUtils.java

示例7: createAndPutChipForUser

private ChipSpan createAndPutChipForUser(TLRPC.User user) {
    try {
        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);
        }
        nameTextView.setText(ssb);
        nameTextView.setSelection(ssb.length());
        return span;
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
    return null;
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:42,代码来源:ChannelCreateActivity.java

示例8: createAndPutChipForUser

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:pooyafaroka,项目名称:PlusGram,代码行数:37,代码来源:DeleteBySelectContacts.java

示例9: addImage

/**
 * 添加图片,更多图片样式请使用setSpan方法
 *
 * @param d Drawable
 * @return SuperTextView
 */
public SuperTextView addImage(Drawable d) {
    SpannableString spanString = new SpannableString(" ");
    d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
    ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
    spanString.setSpan(span, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    append(spanString);
    return this;
}
 
开发者ID:nesror,项目名称:SuperTextView,代码行数:14,代码来源:SuperTextView.java

示例10: getImageSpan

private static ImageSpan getImageSpan(Drawable d,int alignType) {
    switch (alignType){
        case ALIGN_TYPE_BOTTOM :
            return new ImageSpan(d, ImageSpan.ALIGN_BOTTOM);
        case ALIGN_TYPE_BASELINE :
            return new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
        case ALIGN_TYPE_CENTER :
        default:
            return new CenterImageSpan(d);
    }
}
 
开发者ID:LightSun,项目名称:android-common-util-light,代码行数:11,代码来源:StyledText.java

示例11: getImageSpanAlignment

private int getImageSpanAlignment() {
    switch (mImageSpanAlignment) {
        case IMAGE_SPAN_ALIGNMENT_BASELINE:
            return ImageSpan.ALIGN_BASELINE;
        case IMAGE_SPAN_ALIGNMENT_BOTTOM:
            return ImageSpan.ALIGN_BOTTOM;
        default:
            return ImageSpan.ALIGN_BOTTOM;
    }
}
 
开发者ID:jianliaoim,项目名称:talk-android,代码行数:10,代码来源:RecipientEditTextView.java

示例12: emojiEditTextDisplay

/**
 * EditText 表情显示
 * @param context
 * @param editText
 * @param text
 */
public static void emojiEditTextDisplay(Context context,
		EditText editText, String text, int wh) {
	int select = editText.getSelectionStart();
	Editable edit = editText.getEditableText();
	if (text != null && text.startsWith(EMOJI_START)) {
		SpannableString spannable = new SpannableString(text);
		if (text.endsWith(EMOJI_END)) {
			int lastIndex = text.indexOf("]");
			if(lastIndex > 0){
				String emojiName = text.substring(1, lastIndex)+ Constants.IMAGE_SUFFIXES_ENCRYPT;
				String filePath = Config.CACHE_PATH_EMOJI + "base/" + emojiName;
				if (new File(filePath).exists()) {
					ImageSpan span = new ImageSpan(getDiskBitmap(filePath, wh),
							ImageSpan.ALIGN_BASELINE);
					// 开始替换,注意第2和第3个参数表示从哪里开始替换到哪里替换结束(start和end)
					// 最后一个参数类似数学中的集合,[5,12)表示从5到12,包括5但不包括12
					try {
						spannable.setSpan(span, 0, text.length(),
								Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
					}catch (Exception e){

					}
					edit.insert(select, spannable);
					editText.setSelection(select + text.length());
				}
			} else {
				editText.setText(editText.getText().toString() + text);
				editText.setSelection(select + text.length());
			}
		} else {
			editText.setText(editText.getText().toString() + text);
			editText.setSelection(select + text.length());
		}
	} else {
		editText.setText(editText.getText().toString() + text);
		editText.setSelection(select + text.length());
	}
}
 
开发者ID:yun2win,项目名称:yun2win-sdk-android,代码行数:44,代码来源:Expression.java

示例13: insertEtn

/**
 * 表情输入至文字中
 * @param resources
 * @param emotion
 * @return
 */
@SuppressWarnings("all")
public static Spannable insertEtn(Context context, EmotionRules emotion) {
    String remote = emotion.getRemote();
    Spannable spannable = new SpannableString(remote);
    Drawable d = context.getResources().getDrawable(emotion.getMResId());
    d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
    ImageSpan iSpan = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
    //Spanned.SPAN_EXCLUSIVE_EXCLUSIVE 前后输入的字符都不应用这种Spannable
    spannable.setSpan(iSpan, 0, remote.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannable;
}
 
开发者ID:caifeile,项目名称:FlowGeek,代码行数:17,代码来源:InputHelper.java

示例14: insertIcon

public void insertIcon(int id) {

		SpannableString ss = new SpannableString(getText().toString()
				+ "/wx");
		Drawable d = getResources().getDrawable(id);
		d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
		ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
		ss.setSpan(span, getText().length(),
				getText().length() + "/wx".length(),
				Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
		System.out.println("sssssss: " + ss);
		setText(ss);
	}
 
开发者ID:BigAppOS,项目名称:BigApp_Discuz_Android,代码行数:13,代码来源:SmiliesEditText.java

示例15: addDrawableToTextAtFirstSpace

public static SpannableStringBuilder addDrawableToTextAtFirstSpace(String text, Drawable drawable) {
    final int index = text.indexOf(' ');
    final ImageSpan imageSpan = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
    final SpannableStringBuilder builder = new SpannableStringBuilder();
    builder.append(text.substring(0, index + 1))
            .append(" ");
    final int chars = builder.length();
    builder.setSpan(imageSpan, chars - 1, chars, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    builder.append(text.substring(index));

    return builder;
}
 
开发者ID:netguru,项目名称:inbbbox-android,代码行数:12,代码来源:TextFormatterUtil.java


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