Java Code Examples for android.text.style.ImageSpan

The following examples show how to use android.text.style.ImageSpan. These examples are extracted from open source projects. 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 Project: FlyWoo   Source File: EmoticonsTextView.java    License: Apache License 2.0 6 votes vote down vote up
private CharSequence replace(String text) {
	try {
		SpannableString spannableString = new SpannableString(text);
		int start = 0;
		Pattern pattern = buildPattern();
		Matcher matcher = pattern.matcher(text);
		while (matcher.find()) {
			String faceText = matcher.group();
			String key = faceText.substring(1);
			BitmapFactory.Options options = new BitmapFactory.Options();
			Bitmap bitmap = BitmapFactory.decodeResource(getContext().getResources(),
					getContext().getResources().getIdentifier(key, "drawable", getContext().getPackageName()), options);
			ImageSpan imageSpan = new ImageSpan(getContext(), bitmap);
			int startIndex = text.indexOf(faceText, start);
			int endIndex = startIndex + faceText.length();
			if (startIndex >= 0)
				spannableString.setSpan(imageSpan, startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			start = (endIndex - 1);
		}
		return spannableString;
	} catch (Exception e) {
		return text;
	}
}
 
Example 2
Source Project: android_9.0.0_r45   Source File: Html.java    License: Apache License 2.0 6 votes vote down vote up
private static void startImg(Editable text, Attributes attributes, Html.ImageGetter img) {
    String src = attributes.getValue("", "src");
    Drawable d = null;

    if (img != null) {
        d = img.getDrawable(src);
    }

    if (d == null) {
        d = Resources.getSystem().
                getDrawable(com.android.internal.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);
}
 
Example 3
Source Project: NIM_Android_UIKit   Source File: MoonUtil.java    License: MIT License 6 votes vote down vote up
private static SpannableString replaceEmoticons(Context context, String value, float scale, int align) {
    if (TextUtils.isEmpty(value)) {
        value = "";
    }

    SpannableString mSpannableString = new SpannableString(value);
    Matcher matcher = EmojiManager.getPattern().matcher(value);
    while (matcher.find()) {
        int start = matcher.start();
        int end = matcher.end();
        String emot = value.substring(start, end);
        Drawable d = getEmotDrawable(context, emot, scale);
        if (d != null) {
            ImageSpan span = new ImageSpan(d, align);
            mSpannableString.setSpan(span, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    return mSpannableString;
}
 
Example 4
Source Project: tysq-android   Source File: Html.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void startAudio(SpannableStringBuilder text,
                        Attributes attributes,
                        Html.ImageGetter imageGetter) {
    AudioInfo audioInfo = (AudioInfo) DECODE_MAP.get(MediaType.AUDIO).getData();

    Drawable coverDrawable = null;

    if (imageGetter instanceof JerryImageGetter) {
        JerryImageGetter jerryImageGetter = (JerryImageGetter) imageGetter;
        jerryImageGetter.setType(MediaType.AUDIO);
        jerryImageGetter.setFileName(audioInfo.getTitle());
        coverDrawable = jerryImageGetter.getDrawable("");
    }

    ImageSpan imageSpan = new JerryAudioSpan(coverDrawable, audioInfo);
    int len = text.length();
    text.append("\uFFFC");

    text.setSpan(imageSpan, len, text.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
 
Example 5
Source Project: styT   Source File: DemoAdapter.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 替换表情
 *
 * @param str
 * @param context
 * @return
 */
private SpannableString getSpannableString(String str, Context context) {
    SpannableString spannableString = new SpannableString(str);
    String s = "\\[(.+?)\\]";
    Pattern pattern = Pattern.compile(s, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(spannableString);
    while (matcher.find()) {
        String key = matcher.group();
        int id = Expression.getIdAsName(key);
        if (id != 0) {
            Drawable drawable = context.getResources().getDrawable(id);
            drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
            ImageSpan imageSpan = new ImageSpan(drawable);
            spannableString.setSpan(imageSpan, matcher.start(), matcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    return spannableString;
}
 
Example 6
Source Project: MVPAndroidBootstrap   Source File: EditTextUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
     * Sets the edittext's hint icon and text.
     *
     * @param editText
     * @param drawableResource
     * @param hintText
     */
    public static void setSearchHintWithColorIcon(EditText editText, int drawableResource, int textColor, String hintText) {
        try {

            SpannableStringBuilder stopHint = new SpannableStringBuilder("   ");
            stopHint.append(hintText);

// Add the icon as an spannable
            Drawable searchIcon = editText.getContext().getResources().getDrawable(drawableResource);
            Float rawTextSize = editText.getTextSize();
            int textSize = (int) (rawTextSize * 1.25);
            searchIcon.setBounds(0, 0, textSize, textSize);
            stopHint.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

            // Set the new hint text
            editText.setHint(stopHint);
            //searchBox.setTextColor(Color.WHITE);
            editText.setHintTextColor(textColor);

        } catch (Exception e) {
            Log.e("EditTextUtil", e.getMessage(), e);
        }
    }
 
Example 7
Source Project: styT   Source File: ExpressionUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 替换表情
 *
 * @param context
 * @param str
 * @return
 */
public static SpannableString getSpannableString(Context context, String str) {
    SpannableString spannableString = new SpannableString(str);
    String s = "\\[(.+?)\\]";
    Pattern pattern = Pattern.compile(s, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(spannableString);
    while (matcher.find()) {
        String key = matcher.group();
        int id = Expression.getIdAsName(key);
        if (id != 0) {
            Drawable drawable = context.getResources().getDrawable(id);
            drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
            ImageSpan imageSpan = new ImageSpan(drawable);
            spannableString.setSpan(imageSpan, matcher.start(), matcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    return spannableString;
}
 
Example 8
Source Project: UETool   Source File: Util.java    License: MIT License 6 votes vote down vote up
private static List<Pair<String, Bitmap>> getTextViewImageSpanBitmap(TextView textView) {
    List<Pair<String, Bitmap>> bitmaps = new ArrayList<>();
    try {
        CharSequence text = textView.getText();
        if (text instanceof SpannedString) {
            Field mSpansField = Class.forName("android.text.SpannableStringInternal").getDeclaredField("mSpans");
            mSpansField.setAccessible(true);
            Object[] spans = (Object[]) mSpansField.get(text);
            for (Object span : spans) {
                if (span instanceof ImageSpan) {
                    bitmaps.add(new Pair<>("SpanBitmap", getDrawableBitmap(((ImageSpan) span).getDrawable())));
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return bitmaps;
}
 
Example 9
Source Project: RichEditText   Source File: RichEditText.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param bitmap
 * @param filePath
 * @param start
 * @param end
 */
public void addDefaultImage(String filePath,int start,int end) {
	Log.i("imgpath", filePath);
	String pathTag = "<img src=\"" + filePath + "\"/>";
	SpannableString spanString = new SpannableString(pathTag);
	// 获取屏幕的宽高
	Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.default_img);
	int paddingLeft = getPaddingLeft();
	int paddingRight = getPaddingRight();
	int bmWidth = bitmap.getWidth();//图片高度
	int bmHeight = bitmap.getHeight();//图片宽度
	int zoomWidth = getWidth() - (paddingLeft + paddingRight);
	int zoomHeight = (int) (((float)zoomWidth / (float)bmWidth) * bmHeight);
	Bitmap newBitmap = zoomImage(bitmap, zoomWidth,zoomHeight);
	ImageSpan imgSpan = new ImageSpan(mContext, newBitmap);
	spanString.setSpan(imgSpan, 0, pathTag.length(),
			Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
	if(mEditable==null){
		mEditable = this.getText(); // 获取edittext内容
	}
	mEditable.delete(start, end);//删除
	mEditable.insert(start, spanString); // 设置spanString要添加的位置
}
 
Example 10
@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 11
Source Project: NewFastFrame   Source File: CommentListActivity.java    License: Apache License 2.0 6 votes vote down vote up
private SpannableStringBuilder getText(PublicPostBean bean) {
    SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
    SpannableString spannableString = new SpannableString(".");
    spannableString.setSpan(new ImageSpan(this, R.drawable.ic_location, DynamicDrawableSpan.ALIGN_BASELINE), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    String location = "";
    if (bean.getLocation() != null) {
        LocationEvent mLocationEvent = BaseApplication.getAppComponent().getGson().fromJson(bean.getLocation(), LocationEvent.class);
        if (mLocationEvent.getCity().equals(mLocationEvent.getTitle())) {
            location = mLocationEvent.getTitle();
        } else {
            location = mLocationEvent.getCity() + "." + mLocationEvent.getTitle();
        }
    }
    spannableStringBuilder.append(TimeUtil.getRealTime(bean.getCreatedAt() == null ? bean.getUpdatedAt() :
            bean.getCreatedAt())).append("   ").append(spannableString).append(location);
    return spannableStringBuilder;
}
 
Example 12
Source Project: Study_Android_Demo   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void startImg(SpannableStringBuilder text, String src, Html.ImageGetter img) {
    Drawable d = null;

    if (img != null) {
        d = img.getDrawable(src);
    }
    if (d == null) {
        d = getResources().getDrawable(R.mipmap.ic_launcher);
        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);
}
 
Example 13
Source Project: chatui   Source File: GifTextView.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 对静态图片进行解析:
 * 创建一个SpanInfo对象,帧数设为1,按照下面的参数设置,最后不要忘记将SpanInfo对象添加进spanInfoList中, 否则不会显示
 *
 * @param resourceId
 * @param start
 * @param end
 */
@SuppressWarnings("unused")
private void parseBmp(int resourceId, int start, int end) {
    Bitmap bitmap = BitmapFactory.decodeResource(getContext()
            .getResources(), resourceId);
    ImageSpan imageSpan = new ImageSpan(getContext(), bitmap);
    SpanInfo spanInfo = new SpanInfo();
    spanInfo.currentFrameIndex = 0;
    spanInfo.frameCount = 1;
    spanInfo.start = start;
    spanInfo.end = end;
    spanInfo.delay = 100;
    spanInfo.mapList.add(bitmap);
    spanInfoList.add(spanInfo);

}
 
Example 14
Source Project: cathode   Source File: SearchView.java    License: Apache License 2.0 6 votes vote down vote up
@Override protected void onFinishInflate() {
  super.onFinishInflate();
  inputView = findViewById(R.id.search_input);
  clearView = findViewById(R.id.search_clear);

  inputView.setOnKeyListener(inputKeyListener);
  inputView.addTextChangedListener(inputListener);

  SpannableStringBuilder ssb = new SpannableStringBuilder("   ");
  ssb.append(getResources().getString(R.string.action_search));
  Drawable searchIcon = ContextCompat.getDrawable(getContext(), R.drawable.ic_action_search_24dp);
  int textSize = (int) (inputView.getTextSize() * 1.25);
  searchIcon.setBounds(0, 0, textSize, textSize);
  ssb.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  inputView.setHint(ssb);

  clearView.setOnClickListener(clearListener);
  clearView.setVisibility(inputView.getText().toString().isEmpty() ? INVISIBLE : VISIBLE);
}
 
Example 15
Source Project: NIM_Android_UIKit   Source File: MoonUtil.java    License: MIT License 6 votes vote down vote up
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 16
Source Project: LLApp   Source File: VIPCountDownTimer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 重写父类的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 17
Source Project: HtmlCompat   Source File: HtmlToSpannedConverter.java    License: Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 18
Source Project: FlyWoo   Source File: EmoticonsEditText.java    License: Apache License 2.0 6 votes vote down vote up
private CharSequence replace(String text) {
	try {
		SpannableString spannableString = new SpannableString(text);
		int start = 0;
		Pattern pattern = buildPattern();
		Matcher matcher = pattern.matcher(text);
		while (matcher.find()) {
			String faceText = matcher.group();
			String key = faceText.substring(1);
			BitmapFactory.Options options = new BitmapFactory.Options();
			Bitmap bitmap = BitmapFactory.decodeResource(getContext().getResources(),
					getContext().getResources().getIdentifier(key, "drawable", getContext().getPackageName()), options);
			ImageSpan imageSpan = new ImageSpan(getContext(), bitmap);
			int startIndex = text.indexOf(faceText, start);
			int endIndex = startIndex + faceText.length();
			if (startIndex >= 0)
				spannableString.setSpan(imageSpan, startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			start = (endIndex - 1);
		}
		return spannableString;
	} catch (Exception e) {
		return text;
	}
}
 
Example 19
Source Project: RxAndroidBootstrap   Source File: EditTextUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
     * Sets the edittext's hint icon and text.
     *
     * @param editText
     * @param drawableResource
     * @param hintText
     */
    public static void setSearchHintWithColorIcon(EditText editText, int drawableResource, int textColor, String hintText) {
        try {

            SpannableStringBuilder stopHint = new SpannableStringBuilder("   ");
            stopHint.append(hintText);

// Add the icon as an spannable
            Drawable searchIcon = editText.getContext().getResources().getDrawable(drawableResource);
            Float rawTextSize = editText.getTextSize();
            int textSize = (int) (rawTextSize * 1.25);
            searchIcon.setBounds(0, 0, textSize, textSize);
            stopHint.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

            // Set the new hint text
            editText.setHint(stopHint);
            //searchBox.setTextColor(Color.WHITE);
            editText.setHintTextColor(textColor);

        } catch (Exception e) {
            Log.e("EditTextUtil", e.getMessage(), e);
        }
    }
 
Example 20
Source Project: AcDisplay   Source File: SmileyParser.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Adds ImageSpans to a CharSequence that replace textual emoticons such
 * as :-) with a graphical version.
 *
 * @param text A CharSequence possibly containing emoticons
 * @return A CharSequence annotated with ImageSpans covering any
 * recognized emoticons.
 */
public CharSequence addSmileySpans(@Nullable CharSequence text) {
    if (text == null) return null;

    SpannableStringBuilder builder = new SpannableStringBuilder(text);

    Matcher matcher = mPattern.matcher(text);
    while (matcher.find()) {
        int resId = mSmileyToRes.get(matcher.group());
        int start = matcher.start();
        int end = matcher.end();
        Check.getInstance().isTrue(end > start);
        builder.setSpan(new ImageSpan(mContext, resId), start, end,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    return builder;
}
 
Example 21
Source Project: android_9.0.0_r45   Source File: SearchView.java    License: Apache License 2.0 5 votes vote down vote up
private CharSequence getDecoratedHint(CharSequence hintText) {
    // If the field is always expanded or we don't have a search hint icon,
    // then don't add the search icon to the hint.
    if (!mIconifiedByDefault || mSearchHintIcon == null) {
        return hintText;
    }

    final int textSize = (int) (mSearchSrcTextView.getTextSize() * 1.25);
    mSearchHintIcon.setBounds(0, 0, textSize, textSize);

    final SpannableStringBuilder ssb = new SpannableStringBuilder("   ");
    ssb.setSpan(new ImageSpan(mSearchHintIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    ssb.append(hintText);
    return ssb;
}
 
Example 22
Source Project: zom-android-matrix   Source File: StickerManager.java    License: Apache License 2.0 5 votes vote down vote up
public boolean addEmoji(Context context, Spannable spannable) throws IOException {
	boolean hasChanges = false;
	for (Entry<Pattern, Sticker> entry : emoticons.entrySet())
	{
		Matcher matcher = entry.getKey().matcher(spannable);
		while (matcher.find()) {
			boolean 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) {
			    hasChanges = true;
			    
			    Sticker emoji = entry.getValue();
			    spannable.setSpan(new ImageSpan(context, BitmapFactory.decodeStream(emoji.res.getAssets().open(emoji.assetUri.getPath()))),
			            matcher.start(), matcher.end(),
			            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			}
		}
	}
	return hasChanges;
}
 
Example 23
private void markPro(MenuItem menu, String sku) {
    if (sku == null || !IAB.isPurchased(sku, this)) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        boolean dark = prefs.getBoolean("dark_theme", false);
        SpannableStringBuilder ssb = new SpannableStringBuilder("  " + menu.getTitle());
        ssb.setSpan(new ImageSpan(this, dark ? R.drawable.ic_shopping_cart_white_24dp : R.drawable.ic_shopping_cart_black_24dp), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        menu.setTitle(ssb);
    }
}
 
Example 24
Source Project: KlyphMessenger   Source File: EmojiUtil.java    License: MIT License 5 votes vote down vote up
public static Spannable getSpannableForText(Context context, String text, boolean addLinks)
{
	SpannableStringBuilder ssb = new SpannableStringBuilder(text);
	
	Linkify.addLinks(ssb, Linkify.WEB_URLS);

	for (String key : EMOJIS.keySet())
	{
		int index = text.indexOf(key);
		while (index != -1)
		{
			if (ssb.getSpans(index, index + 1, Object.class).length == 0/* && ssb.getSpans(index, index + 1, URLSpan.class).length == 0*/)
				ssb.setSpan(new ImageSpan(context, EMOJIS.get(key)), index, index + key.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			
			index = text.indexOf(key, index + key.length());
		}
	}
	
	if (!addLinks)
	{
		URLSpan[] spans = ssb.getSpans(0, text.length() - 1, URLSpan.class);
		for (URLSpan urlSpan : spans)
		{
			ssb.removeSpan(urlSpan);
		}
	}

	return ssb;
}
 
Example 25
Source Project: talk-android   Source File: TextChipsEditView.java    License: MIT License 5 votes vote down vote up
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 26
Source Project: lttrs-android   Source File: BindingAdapters.java    License: Apache License 2.0 5 votes vote down vote up
@BindingAdapter("android:text")
public static void setText(TextView text, SubjectWithImportance subjectWithImportance) {
    if (subjectWithImportance == null || subjectWithImportance.subject == null) {
        text.setText(null);
        return;
    }
    if (subjectWithImportance.important) {
        SpannableStringBuilder header = new SpannableStringBuilder(subjectWithImportance.subject);
        header.append("\u2004\u00bb"); // 1/3 em - 1/2 em would be 2002
        header.setSpan(new ImageSpan(text.getContext(), R.drawable.ic_important_amber_22sp, DynamicDrawableSpan.ALIGN_BASELINE), header.length() - 1, header.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        text.setText(header);
    } else {
        text.setText(subjectWithImportance.subject);
    }
}
 
Example 27
Source Project: EhViewer   Source File: GalleryListScene.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public CharSequence getText(float textSize) {
    Drawable bookImage = DrawableManager.getVectorDrawable(getContext2(), R.drawable.v_book_open_x24);
    SpannableStringBuilder ssb = new SpannableStringBuilder("    ");
    ssb.append(getResources2().getString(R.string.gallery_list_search_bar_open_gallery));
    int imageSize = (int) (textSize * 1.25);
    if (bookImage != null) {
        bookImage.setBounds(0, 0, imageSize, imageSize);
        ssb.setSpan(new ImageSpan(bookImage), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    return ssb;
}
 
Example 28
Source Project: msdkui-android   Source File: RouteUtil.java    License: Apache License 2.0 5 votes vote down vote up
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 29
Source Project: msdkui-android   Source File: RouteDescriptionHandler.java    License: Apache License 2.0 5 votes vote down vote up
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 30
private void updateExtrasLabel(@NonNull Context context, int stringResID, long offset)
{
    SuntimesUtils.TimeDisplayText dstSavings = utils.timeDeltaLongDisplayString(0L, offset, false, false, true);
    ImageSpan dstIcon = SuntimesUtils.createDstSpan(context, 24, 24);
    String dstString = (dstSavings.getRawValue() < 0 ? "-" : "+") + dstSavings.getValue();
    String extrasString = getString(stringResID, dstString);

    SpannableStringBuilder extrasSpan = SuntimesUtils.createSpan(context, extrasString, SuntimesUtils.SPANTAG_DST, dstIcon);
    SpannableString boldedExtrasSpan = SuntimesUtils.createBoldSpan(SpannableString.valueOf(extrasSpan), extrasString, dstString);
    label_tzExtras0.setText(boldedExtrasSpan);
    layout_timezoneExtras.setVisibility(View.VISIBLE);
}