Search in sources :

Example 56 with ImageSpan

use of android.text.style.ImageSpan in project Talon-for-Twitter by klinker24.

the class EmojiUtils method addSmiles.

public static boolean addSmiles(Context context, Spannable spannable) {
    boolean hasChanges = false;
    for (Map.Entry<Pattern, Integer> 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;
                int scale = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, textSize + 2, context.getResources().getDisplayMetrics());
                try {
                    Bitmap bitmap = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(res, entry.getValue()), scale, scale, true);
                    spannable.setSpan(new ImageSpan(context, bitmap, ImageSpan.ALIGN_BOTTOM), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                } catch (OutOfMemoryError e) {
                    return false;
                }
            }
        }
    }
    return hasChanges;
}
Also used : Pattern(java.util.regex.Pattern) Bitmap(android.graphics.Bitmap) Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap) Map(java.util.Map) ImageSpan(android.text.style.ImageSpan)

Example 57 with ImageSpan

use of android.text.style.ImageSpan in project remusic by aa112901.

the class PlaylistActivity method setHeaderView.

private void setHeaderView() {
    albumArt = (ImageView) findViewById(R.id.album_art);
    playlistTitleView = (TextView) findViewById(R.id.album_title);
    playlistDetailView = (TextView) findViewById(R.id.album_details);
    albumArtSmall = (SimpleDraweeView) findViewById(R.id.playlist_art);
    SpannableString spanString;
    Bitmap b = BitmapFactory.decodeResource(getResources(), R.mipmap.index_icn_earphone);
    ImageSpan imgSpan = new ImageSpan(this, b, ImageSpan.ALIGN_BASELINE);
    spanString = new SpannableString("icon");
    spanString.setSpan(imgSpan, 0, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    playlistCountView = (TextView) findViewById(R.id.playlist_listen_count);
    playlistCountView.setText(spanString);
    if (playlistCount == null) {
        playlistCount = "0";
    }
    int count = Integer.parseInt(playlistCount);
    if (count > 10000) {
        count = count / 10000;
        playlistCountView.append(" " + count + "万");
    } else {
        playlistCountView.append(" " + playlistCount);
    }
    LinearLayout downAll = (LinearLayout) headerViewContent.findViewById(R.id.playlist_down);
    downAll.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new LoadAllDownInfos((Activity) mContext, mList).execute();
        }
    });
    final LinearLayout addToplaylist = (LinearLayout) headerViewContent.findViewById(R.id.playlist_collect);
    addToplaylist.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!mCollected) {
                collectText.setText("已收藏");
                new AsyncTask<Void, Void, Void>() {

                    @Override
                    protected Void doInBackground(Void... params) {
                        String albumart = null;
                        for (MusicInfo info : adapterList) {
                            albumart = info.albumData;
                            if (!TextUtils.isEmpty(albumart)) {
                                break;
                            }
                        }
                        PlaylistInfo.getInstance(mContext).addPlaylist(Long.parseLong(playlsitId), playlistName, adapterList.size(), albumart, "net");
                        PlaylistsManager.getInstance(mContext).insertLists(mContext, Long.parseLong(playlsitId), adapterList);
                        Intent intent = new Intent(IConstants.PLAYLIST_COUNT_CHANGED);
                        MainApplication.context.sendBroadcast(intent);
                        mCollected = true;
                        return null;
                    }
                }.execute();
            } else {
                collectText.setText("收藏");
                PlaylistInfo.getInstance(mContext).deletePlaylist(Long.parseLong(playlsitId));
                mCollected = false;
            }
        }
    });
    share.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("http://music.baidu.com/songlist/" + playlsitId));
            shareIntent.setType("html/*");
            startActivity(Intent.createChooser(shareIntent, getResources().getString(R.string.shared_to)));
        }
    });
    if (!isLocalPlaylist)
        headerDetail.setVisibility(View.GONE);
    tryAgain.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            loadAllLists();
        }
    });
    if (Integer.parseInt(playlsitId) == IConstants.FAV_PLAYLIST) {
        favLayout.setVisibility(View.VISIBLE);
    }
}
Also used : AsyncTask(android.os.AsyncTask) Intent(android.content.Intent) SpannableString(android.text.SpannableString) ImageView(android.widget.ImageView) ObservableRecyclerView(com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView) SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) View(android.view.View) TextView(android.widget.TextView) TintImageView(com.bilibili.magicasakura.widgets.TintImageView) RecyclerView(android.support.v7.widget.RecyclerView) SpannableString(android.text.SpannableString) Bitmap(android.graphics.Bitmap) LoadAllDownInfos(com.wm.remusic.dialog.LoadAllDownInfos) MusicInfo(com.wm.remusic.info.MusicInfo) LinearLayout(android.widget.LinearLayout) ImageSpan(android.text.style.ImageSpan)

Example 58 with ImageSpan

use of android.text.style.ImageSpan in project platform_frameworks_base by android.

the class SearchView method getDecoratedHint.

private CharSequence getDecoratedHint(CharSequence hintText) {
    // 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;
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) ImageSpan(android.text.style.ImageSpan)

Example 59 with ImageSpan

use of android.text.style.ImageSpan in project CircleDemo by Naoki2015.

the class PraiseListView method setImageSpan.

private SpannableString setImageSpan() {
    String text = "  ";
    SpannableString imgSpanText = new SpannableString(text);
    imgSpanText.setSpan(new ImageSpan(MyApplication.getContext(), R.drawable.icon_praise, DynamicDrawableSpan.ALIGN_BASELINE), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return imgSpanText;
}
Also used : SpannableString(android.text.SpannableString) SpannableString(android.text.SpannableString) ImageSpan(android.text.style.ImageSpan)

Example 60 with ImageSpan

use of android.text.style.ImageSpan in project ActionBarSherlock by JakeWharton.

the class SearchView method getDecoratedHint.

private CharSequence getDecoratedHint(CharSequence hintText) {
    // If the field is always expanded, then don't add the search icon to the hint
    if (!mIconifiedByDefault)
        return hintText;
    // for the icon
    SpannableStringBuilder ssb = new SpannableStringBuilder("   ");
    ssb.append(hintText);
    Drawable searchIcon = getContext().getResources().getDrawable(getSearchIconId());
    int textSize = (int) (mQueryTextView.getTextSize() * 1.25);
    searchIcon.setBounds(0, 0, textSize, textSize);
    ssb.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return ssb;
}
Also used : Drawable(android.graphics.drawable.Drawable) SpannableStringBuilder(android.text.SpannableStringBuilder) ImageSpan(android.text.style.ImageSpan)

Aggregations

ImageSpan (android.text.style.ImageSpan)98 SpannableStringBuilder (android.text.SpannableStringBuilder)53 Drawable (android.graphics.drawable.Drawable)29 ForegroundColorSpan (android.text.style.ForegroundColorSpan)23 BackgroundColorSpan (android.text.style.BackgroundColorSpan)14 TextView (android.widget.TextView)14 SpannableString (android.text.SpannableString)12 View (android.view.View)11 UnderlineSpan (android.text.style.UnderlineSpan)10 RelativeSizeSpan (android.text.style.RelativeSizeSpan)7 StyleSpan (android.text.style.StyleSpan)7 Bitmap (android.graphics.Bitmap)6 LinearLayout (android.widget.LinearLayout)6 Application (android.app.Application)5 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)5 CharacterStyle (android.text.style.CharacterStyle)5 SuggestionSpan (android.text.style.SuggestionSpan)5 URLSpan (android.text.style.URLSpan)5 MenuItem (android.view.MenuItem)5 Button (android.widget.Button)5