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;
}
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));
}
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;
}
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;
}
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);
}
Aggregations