Java Code Examples for android.text.style.ImageSpan#ALIGN_BOTTOM
The following examples show how to use
android.text.style.ImageSpan#ALIGN_BOTTOM .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MoonUtil.java From NIM_Android_UIKit with MIT License | 6 votes |
public static void replaceEmoticons(Context context, Editable editable, int start, int count) { if (count <= 0 || editable.length() < start + count) return; CharSequence s = editable.subSequence(start, start + count); Matcher matcher = EmojiManager.getPattern().matcher(s); while (matcher.find()) { int from = start + matcher.start(); int to = start + matcher.end(); String emot = editable.subSequence(from, to).toString(); Drawable d = getEmotDrawable(context, emot, SMALL_SCALE); if (d != null) { ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BOTTOM); editable.setSpan(span, from, to, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } }
Example 2
Source File: MoonUtil.java From RxZhihuDaily with MIT License | 6 votes |
public static void replaceEmoticons(Context context, Editable editable, int start, int count) { if (count <= 0 || editable.length() < start + count) return; CharSequence s = editable.subSequence(start, start + count); Matcher matcher = EmoUtil.getPattern().matcher(s); while (matcher.find()) { int from = start + matcher.start(); int to = start + matcher.end(); String emot = editable.subSequence(from, to).toString(); Drawable d = getEmotDrawable(context, emot, DEF_SCALE); if (d != null) { ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BOTTOM); editable.setSpan(span, from, to, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } }
Example 3
Source File: PlatformPagerAdapter.java From citra_android with GNU General Public License v3.0 | 6 votes |
@Override public CharSequence getPageTitle(int position) { // Hax from https://guides.codepath.com/android/Google-Play-Style-Tabs-using-TabLayout#design-support-library // Apparently a workaround for TabLayout not supporting icons. // TODO This workaround will eventually not be necessary; switch to more legit methods when that is the case // TODO Also remove additional hax from styles.xml Drawable drawable = mContext.getResources().getDrawable(TAB_ICONS[position]); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); ImageSpan imageSpan = new ImageSpan(drawable, ImageSpan.ALIGN_BOTTOM); SpannableString sb = new SpannableString(" "); sb.setSpan(imageSpan, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return sb; }
Example 4
Source File: InputPanel.java From Android with MIT License | 6 votes |
public void replaceEmoticons(Editable editable, int start, int count) { if (count <= 0 || editable.length() < start + count) return; CharSequence s = editable.subSequence(start, start + count); Matcher matcher = Pattern.compile("\\[[^\\[]+\\]").matcher(s); while (matcher.find()) { int from = start + matcher.start(); int to = start + matcher.end(); String emot = editable.subSequence(from, to).toString(); emot = emot.substring(1, emot.length() - 1) + ".png"; String key = StickerCategory.emojiMaps.get(emot); if (!TextUtils.isEmpty(key)) { emot = key; } Drawable d = ResourceUtil.getEmotDrawable(emot); if (d != null) { ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BOTTOM); editable.setSpan(span, from, to, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } }
Example 5
Source File: VIPCountDownTimer.java From LLApp with Apache License 2.0 | 6 votes |
/** * 重写父类的initSpanData方法 * 通过number数组得到每块数值对应的自定义MikyouBackgroundSpan对象 * 然后通过MikyouBackgroundSpan对象定义每块数值的样式包括背景,边框,边框圆角样式,然后将这些对象加入到集合中去 * 通过nonNumber数组得到每个间隔的ForegroundColorSpan对象 * 然后通过这些对象就可以定义每个间隔块的样式,因为只定义了ForegroundColorSpan所以只能定义 * 每个间隔块的字体颜色,setmGapSpanColor方式也是供外部自由定制每个间隔的样式 * 实际上还可以定义其他的Span,同理实现也是很简单的。 * */ @Override public void initSpanData(String timeStr) { super.initSpanData(timeStr); vipNumbers = TimerUtils.getNumInTimerStr(timeStr);//得到每个数字注意不是每块数值,并加入数组 vipNonNumbers = TimerUtils.getNonNumInTimerStr(timeStr);//得到每个间隔字符,并加入到数组 for (int i=0;i<vipNumbers.length;i++){ for (int j=0;j<vipNumbers[i].toCharArray().length;j++){//因为需要得到每个数字所以还得遍历每块数值中的每个数字,所以需要二层循环 MikyouBackgroundSpan mSpan = new MikyouBackgroundSpan(mContext.getDrawable(mDrawableId), ImageSpan.ALIGN_BOTTOM); initBackSpanStyle(mSpan); mSpanList.add(mSpan); } } for (int i= 0; i<vipNonNumbers.length;i++){ ForegroundColorSpan mGapSpan = new ForegroundColorSpan(mGapSpanColor); mTextColorSpanList.add(mGapSpan); } }
Example 6
Source File: RouteDescriptionHandler.java From msdkui-android with Apache License 2.0 | 5 votes |
private void appendDrawable(final SpannableStringBuilder builder, final int drawable, int tint) { final Drawable divider = AppCompatResources.getDrawable(mContext, drawable) .mutate(); final int color = (tint == -1) ? R.attr.colorForegroundSecondaryLight : tint; divider.setColorFilter(ThemeUtil.getColor(mContext, color), PorterDuff.Mode.SRC_ATOP); divider.setBounds(0, 0, divider.getIntrinsicWidth(), divider.getIntrinsicHeight()); final ImageSpan span = new ImageSpan(divider, ImageSpan.ALIGN_BOTTOM); builder.setSpan(span, builder.length() - 1, builder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); }
Example 7
Source File: MainActivity.java From HeartBeat with Apache License 2.0 | 5 votes |
public CharSequence getPageIcon(int position, int filterColor) { Drawable image = ResourcesCompat.getDrawable(getResources(), mFragmentIconList.get(position), null); image.setColorFilter(filterColor, PorterDuff.Mode.MULTIPLY); image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight()); SpannableString sb = new SpannableString(" "); ImageSpan imageSpan = new ImageSpan(image, ImageSpan.ALIGN_BOTTOM); sb.setSpan(imageSpan, 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return sb; }
Example 8
Source File: JDCountDownTimer.java From LLApp with Apache License 2.0 | 5 votes |
/** * 重写父类的initSpanData方法 * 通过number数组得到每块数值对应的自定义MikyouBackgroundSpan对象 * 然后通过MikyouBackgroundSpan对象定义每块数值的样式包括背景,边框,边框圆角样式,然后将这些对象加入到集合中去 * 通过nonNumber数组得到每个间隔的ForegroundColorSpan对象 * 然后通过这些对象就可以定义每个间隔块的样式,因为只定义了ForegroundColorSpan所以只能定义 * 每个间隔块的字体颜色,setmGapSpanColor方式也是供外部自由定制每个间隔的样式 * 实际上还可以定义其他的Span,同理实现也是很简单的。 * */ @Override public void initSpanData(String timeStr) { super.initSpanData(timeStr); for (int i = 0; i<numbers.length;i++){ MikyouBackgroundSpan mBackSpan = new MikyouBackgroundSpan(mContext.getDrawable(mDrawableId), ImageSpan.ALIGN_BOTTOM); initBackSpanStyle(mBackSpan); mBackSpanList.add(mBackSpan); } for (int i= 0; i<nonNumbers.length;i++){ ForegroundColorSpan mGapSpan = new ForegroundColorSpan(mGapSpanColor); mTextColorSpanList.add(mGapSpan); } }
Example 9
Source File: TextChipsEditView.java From talk-android with MIT License | 5 votes |
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; } }
Example 10
Source File: RecipientEditTextView.java From talk-android with MIT License | 5 votes |
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; } }
Example 11
Source File: SubnotionListActivity.java From intra42 with Apache License 2.0 | 5 votes |
private SpannableString getSpannableIcon(int icon, String replacement) { SpannableString spannableIcon = new SpannableString(replacement); try { Drawable image = ContextCompat.getDrawable(this, icon); if (image != null) { image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight()); ImageSpan imageSpan = new ImageSpan(image, ImageSpan.ALIGN_BOTTOM); spannableIcon.setSpan(imageSpan, 0, replacement.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } catch (Resources.NotFoundException e) { e.printStackTrace(); } return spannableIcon; }
Example 12
Source File: BindingAdapters.java From FirefoxReality with Mozilla Public License 2.0 | 5 votes |
@BindingAdapter(value={"textDrawable", "textString"}) public static void setSpannableString(@NonNull TextView textView, @NonNull Drawable drawable, String text) { SpannableString spannableString = new SpannableString(text); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); ImageSpan span = new ImageSpan(drawable, ImageSpan.ALIGN_BOTTOM); spannableString.setSpan(span, spannableString.toString().indexOf("@"), spannableString.toString().indexOf("@")+1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); textView.setText(spannableString); }
Example 13
Source File: DataSetSectionAdapter.java From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public CharSequence getPageTitle(int position) { SpannableString sb = new SpannableString(sections.get(position) + " "); if (fragments.size() > position && (fragments.get(position).currentNumTables() > 1)) { Drawable image = context.getResources().getDrawable(R.drawable.ic_arrow_down_white); image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight()); ImageSpan imageSpan = new ImageSpan(image, ImageSpan.ALIGN_BOTTOM); sb.setSpan(imageSpan, sb.length() - 1, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } return sb; }
Example 14
Source File: RouteUtil.java From msdkui-android with Apache License 2.0 | 5 votes |
private static void appendDrawable(final Context context, final SpannableStringBuilder builder, final int drawable, int tint) { final Drawable divider = AppCompatResources.getDrawable(context, drawable) .mutate(); final int color = (tint == -1) ? R.attr.colorForegroundSecondaryLight : tint; divider.setColorFilter(ThemeUtil.getColor(context, color), PorterDuff.Mode.SRC_ATOP); divider.setBounds(0, 0, divider.getIntrinsicWidth(), divider.getIntrinsicHeight()); final ImageSpan span = new ImageSpan(divider, ImageSpan.ALIGN_BOTTOM); builder.setSpan(span, builder.length() - 1, builder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); }
Example 15
Source File: VerticalImageSpan.java From ChatKeyboard-master with BSD 3-Clause "New" or "Revised" License | 4 votes |
public VerticalImageSpan(Drawable drawable) { super(drawable, ImageSpan.ALIGN_BOTTOM); }
Example 16
Source File: VerticalImageSpan.java From ChatKeyboard with Apache License 2.0 | 4 votes |
public VerticalImageSpan(Drawable drawable) { super(drawable, ImageSpan.ALIGN_BOTTOM); }
Example 17
Source File: IconTextView.java From bitmask_android with GNU General Public License v3.0 | 3 votes |
/** * Create an ImageSpan for the given icon drawable. This also sets the image size and colour. * Works best with a white, square icon because of the colouring and resizing. * * @param context The Android Context. * @param drawableResId A drawable resource Id. * @param size The desired size (i.e. width and height) of the image icon in pixels. * Use the lineHeight of the TextView to make the image inline with the * surrounding text. * @param colour The colour (careful: NOT a resource Id) to apply to the image. * @return An ImageSpan, aligned with the bottom of the text. */ private ImageSpan makeImageSpan(Context context, int drawableResId, int size, int colour) { final Drawable drawable = context.getResources().getDrawable(drawableResId); drawable.mutate(); drawable.setColorFilter(colour, PorterDuff.Mode.MULTIPLY); drawable.setBounds(0, 0, size, size); return new ImageSpan(drawable, ImageSpan.ALIGN_BOTTOM); }