Search in sources :

Example 11 with ImageSpan

use of android.text.style.ImageSpan in project cw-omnibus by commonsguy.

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)

Example 12 with ImageSpan

use of android.text.style.ImageSpan in project Android-Iconics by mikepenz.

the class PlaygroundActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_playground);
    //Show how to style the text of an existing TextView
    TextView tv1 = (TextView) findViewById(R.id.test1);
    new Iconics.IconicsBuilder().ctx(this).style(new ForegroundColorSpan(Color.WHITE), new BackgroundColorSpan(Color.BLACK), new RelativeSizeSpan(2f)).styleFor("faw-adjust", new BackgroundColorSpan(Color.RED), new ForegroundColorSpan(Color.parseColor("#33000000")), new RelativeSizeSpan(2f)).on(tv1).build();
    //You can also do some advanced stuff like setting an image within a text
    TextView tv2 = (TextView) findViewById(R.id.test5);
    SpannableString sb = new SpannableString(tv2.getText());
    IconicsDrawable d = new IconicsDrawable(this, FontAwesome.Icon.faw_android).sizeDp(48).paddingDp(4);
    sb.setSpan(new ImageSpan(d, DynamicDrawableSpan.ALIGN_BOTTOM), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    tv2.setText(sb);
    //Set the icon of an ImageView (or something else) as drawable
    ImageView iv2 = (ImageView) findViewById(R.id.test2);
    iv2.setImageDrawable(new IconicsDrawable(this, FontAwesome.Icon.faw_thumbs_o_up).sizeDp(48).color(Color.parseColor("#aaFF0000")).contourWidthDp(1));
    //Set the icon of an ImageView (or something else) as bitmap
    ImageView iv3 = (ImageView) findViewById(R.id.test3);
    iv3.setImageBitmap(new IconicsDrawable(this, FontAwesome.Icon.faw_android).sizeDpX(48).sizeDpY(32).paddingDp(4).roundedCornersDp(8).color(Color.parseColor("#deFF0000")).toBitmap());
    //Show how to style the text of an existing button
    Button b4 = (Button) findViewById(R.id.test4);
    new Iconics.IconicsBuilder().ctx(this).style(new BackgroundColorSpan(Color.BLACK)).style(new RelativeSizeSpan(2f)).style(new ForegroundColorSpan(Color.WHITE)).on(b4).build();
    //Show how to style the text of an existing button
    ImageButton b6 = (ImageButton) findViewById(R.id.test6);
    StateListDrawable iconStateListDrawable = new StateListDrawable();
    iconStateListDrawable.addState(new int[] { android.R.attr.state_pressed }, new IconicsDrawable(this, FontAwesome.Icon.faw_thumbs_o_up).sizeDp(48).color(Color.parseColor("#aaFF0000")).contourWidthDp(1));
    iconStateListDrawable.addState(new int[] {}, new IconicsDrawable(this, FontAwesome.Icon.faw_thumbs_o_up).sizeDp(48).color(Color.parseColor("#aa00FF00")).contourWidthDp(2));
    b6.setImageDrawable(iconStateListDrawable);
    ListView listView = (ListView) findViewById(R.id.list);
    IconicsDrawable iconicsDrawableBase = new IconicsDrawable(this).actionBar().color(Color.GREEN).backgroundColor(Color.RED);
    IconicsDrawable[] array = new IconicsArrayBuilder(iconicsDrawableBase).add(FontAwesome.Icon.faw_android).add(Octicons.Icon.oct_octoface).add("Hallo").add('A').add(";)").build();
    listView.setAdapter(new IconsAdapter(this, array));
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) Iconics(com.mikepenz.iconics.Iconics) RelativeSizeSpan(android.text.style.RelativeSizeSpan) StateListDrawable(android.graphics.drawable.StateListDrawable) SpannableString(android.text.SpannableString) ImageButton(android.widget.ImageButton) ListView(android.widget.ListView) ImageButton(android.widget.ImageButton) Button(android.widget.Button) IconicsArrayBuilder(com.mikepenz.iconics.IconicsArrayBuilder) TextView(android.widget.TextView) ImageView(android.widget.ImageView) IconicsDrawable(com.mikepenz.iconics.IconicsDrawable) BackgroundColorSpan(android.text.style.BackgroundColorSpan) ImageSpan(android.text.style.ImageSpan)

Example 13 with ImageSpan

use of android.text.style.ImageSpan in project AndroidTraining by mixi-inc.

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)

Example 14 with ImageSpan

use of android.text.style.ImageSpan in project KJFrameForAndroid by kymjs.

the class InputHelper method displayEmoji.

/**
     * 
     */
public static Spannable displayEmoji(Resources res, CharSequence s, String flagStart, String flagEnd) {
    String str = s.toString();
    Spannable spannable = null;
    if (s instanceof Spannable) {
        spannable = (Spannable) s;
    } else {
        // 构建文字span
        spannable = new SpannableString(str);
    }
    for (int i = 0; i < str.length(); i++) {
        int index1 = str.indexOf(flagStart, i);
        int length1 = str.indexOf(flagEnd, index1 + 1);
        int bound = (int) res.getDimension(R.dimen.space_19);
        try {
            String emojiStr = str.substring(index1, length1 + flagEnd.length());
            int resId = getEmojiResId(emojiStr);
            if (resId > 0) {
                // 构建图片span
                Drawable drawable = res.getDrawable(resId);
                drawable.setBounds(0, 20, bound, bound + 20);
                ImageSpan span = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
                spannable.setSpan(span, index1, length1 + flagEnd.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
            }
        } catch (Exception e) {
        }
    }
    return spannable;
}
Also used : SpannableString(android.text.SpannableString) Drawable(android.graphics.drawable.Drawable) SpannableString(android.text.SpannableString) Spannable(android.text.Spannable) ImageSpan(android.text.style.ImageSpan)

Example 15 with ImageSpan

use of android.text.style.ImageSpan in project Klyph by jonathangerbaud.

the class CommentAdapter method mergeViewWithData.

@Override
protected void mergeViewWithData(View view, GraphObject data) {
    super.mergeViewWithData(view, data);
    Comment comment = (Comment) data;
    final CommentHolder holder = (CommentHolder) getHolder(view);
    holder.getDepthBar().setVisibility(comment.hasParentComment() ? View.VISIBLE : View.GONE);
    holder.getAuthorName().setAutoLinkMask(0);
    holder.getAuthorName().setText("");
    String name = comment.getFrom().getName();
    String time = DateUtil.timeAgoInWords(getContext(view), comment.getCreated_time());
    String text = name + "  " + time + "  ";
    holder.getAuthorName().setText(text);
    TextViewUtil.setElementClickable(getContext(view), holder.getAuthorName(), comment.getFrom().getName(), comment.getFrom().getId(), "user", false);
    Spannable styledText = new SpannableString(holder.getAuthorName().getText());
    TextAppearanceSpan span1 = new TextAppearanceSpan(getContext(holder.getAuthorName()), R.style.Klyph_CommentTextName);
    TextAppearanceSpan span2 = new TextAppearanceSpan(getContext(holder.getAuthorName()), R.style.Klyph_CommentTextTime);
    if (Android.isMinAPI(11))
        styledText.setSpan(span1, 0, name.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    styledText.setSpan(span2, name.length() + 2, name.length() + 2 + time.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    holder.getAuthorName().setText(styledText);
    String commentText = comment.getMessage();
    int numLikes = comment.getLike_count();
    if (numLikes > 0) {
        if (commentText.length() > 0)
            commentText += "  ";
        commentText += numLikes + "  ";
    }
    final SpannableStringBuilder sb = new SpannableStringBuilder();
    sb.append(commentText);
    if (numLikes > 0) {
        ImageSpan span3 = new ImageSpan(getContext(holder.getAuthorName()), AttrUtil.getResourceId(getContext(holder.getAuthorName()), comment.getUser_likes() ? R.attr.userLikeSmallIcon : R.attr.likeIconSmall), DynamicDrawableSpan.ALIGN_BASELINE);
        TextAppearanceSpan span4 = new TextAppearanceSpan(getContext(holder.getAuthorName()), R.style.Klyph_CommentTextTime);
        int likesLength = String.valueOf(numLikes).length();
        sb.setSpan(span3, commentText.length() - 2, commentText.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        sb.setSpan(span4, commentText.length() - (likesLength + 2), commentText.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    holder.getCommentText().setText(sb);
    if (placeHolder == -1)
        placeHolder = KlyphUtil.getPlaceHolder(view.getContext());
    if (profilePlaceHolder == -1)
        profilePlaceHolder = KlyphUtil.getProfilePlaceHolder(view.getContext());
    ((ProfileImageView) holder.getAuthorPicture()).disableBorder();
    String url = comment.getFrom().getPicture().getUrl();
    loadImage(holder.getAuthorPicture(), url, profilePlaceHolder, data);
    holder.getCommentImage().setOnClickListener(null);
    holder.getCommentLinkImage().setOnClickListener(null);
    if (comment.getAttachment().isPhoto() || comment.getAttachment().isVideoShare()) {
        Image image = comment.getAttachment().getMedia().getImage();
        RatioImageView rImageview = (RatioImageView) holder.getCommentImage();
        rImageview.setImageSize(image.getWidth(), image.getHeight());
        int parentWidth = ((ViewGroup) holder.getCommentImage().getParent()).getWidth();
        if (parentWidth > 0) {
            LayoutParams params = holder.getCommentImage().getLayoutParams();
            params.width = Math.min(parentWidth, image.getWidth());
            holder.getCommentImage().setLayoutParams(params);
        }
        loadImage(holder.getCommentImage(), image.getSrc(), placeHolder, data);
        final Target target = comment.getAttachment().getTarget();
        holder.getCommentLinkImage().setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getContext(holder.getCommentImage()), ImageActivity.class);
                intent.putExtra(KlyphBundleExtras.PHOTO_ID, target.getId());
                getContext(holder.getCommentLinkImage()).startActivity(intent);
            }
        });
    } else if (comment.getAttachment().isShare()) {
        final Attachment att = comment.getAttachment();
        Image image = comment.getAttachment().getMedia().getImage();
        holder.getCommentLinkImageBackground().setColorFilter(colorFilter, PorterDuff.Mode.SRC_OVER);
        loadImage(holder.getCommentLinkImage(), image.getSrc(), placeHolder, data);
        loadImage(holder.getCommentLinkImageBackground(), image.getSrc(), placeHolder, data);
        holder.getCommentLinkName().setText(att.getTitle());
        holder.getCommentLinkUrl().setText(att.getUrl());
        holder.getCommentLinkDescription().setText(att.getDescription());
        holder.getCommentLinkImage().setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                PhoneUtil.openURL(getContext(holder.getCommentLinkImage()), att.getUrl());
            }
        });
    }
    if (comment.getAttachment().isVideoShare())
        holder.getCommentImagePlay().setVisibility(View.VISIBLE);
    else
        holder.getCommentImagePlay().setVisibility(View.GONE);
    ((View) holder.getCommentImage().getParent()).setVisibility(comment.getAttachment().isPhoto() || comment.getAttachment().isVideoShare() ? View.VISIBLE : View.GONE);
    ((View) holder.getCommentLinkImage().getParent()).setVisibility(comment.getAttachment().isShare() ? View.VISIBLE : View.GONE);
}
Also used : Comment(com.abewy.android.apps.klyph.core.graph.Comment) ProfileImageView(com.abewy.android.apps.klyph.widget.ProfileImageView) TextAppearanceSpan(android.text.style.TextAppearanceSpan) LayoutParams(android.view.ViewGroup.LayoutParams) ViewGroup(android.view.ViewGroup) Intent(android.content.Intent) Attachment(com.abewy.android.apps.klyph.core.graph.Comment.Attachment) SpannableString(android.text.SpannableString) Image(com.abewy.android.apps.klyph.core.graph.Comment.Attachment.Media.Image) ImageView(android.widget.ImageView) View(android.view.View) ProfileImageView(com.abewy.android.apps.klyph.widget.ProfileImageView) TextView(android.widget.TextView) RatioImageView(com.abewy.android.extended.widget.RatioImageView) SpannableString(android.text.SpannableString) ImageActivity(com.abewy.android.apps.klyph.app.ImageActivity) Target(com.abewy.android.apps.klyph.core.graph.Comment.Attachment.Target) RatioImageView(com.abewy.android.extended.widget.RatioImageView) CommentHolder(com.abewy.android.apps.klyph.adapter.holder.CommentHolder) Spannable(android.text.Spannable) 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