本文整理匯總了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;
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
}
示例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());
}
}
示例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;
}
示例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);
}
示例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;
}