use of android.text.Spannable in project KJFrameForAndroid by kymjs.
the class TweetRecordFragment method initWidget.
@Override
protected void initWidget(View view) {
super.initWidget(view);
RelativeLayout.LayoutParams params = (LayoutParams) mBtnRecort.getLayoutParams();
params.width = DensityUtils.getScreenW(getActivity());
params.height = (int) (DensityUtils.getScreenH(getActivity()) * 0.4);
mBtnRecort.setLayoutParams(params);
mBtnRecort.setOnFinishedRecordListener(new OnFinishedRecordListener() {
@Override
public void onFinishedRecord(String audioPath, int recordTime) {
mLayout.setVisibility(View.VISIBLE);
if (recordTime < 10) {
mTvTime.setText("0" + recordTime + "\"");
} else {
mTvTime.setText(recordTime + "\"");
}
mImgAdd.setVisibility(View.GONE);
filePath = null;
}
@Override
public void onCancleRecord() {
mLayout.setVisibility(View.GONE);
}
});
drawable = (AnimationDrawable) mImgVolume.getBackground();
mBtnRecort.getAudioUtil().setOnPlayListener(new OnPlayListener() {
@Override
public void stopPlay() {
drawable.stop();
mImgVolume.setBackgroundDrawable(drawable.getFrame(0));
}
@Override
public void starPlay() {
mImgVolume.setBackgroundDrawable(drawable);
drawable.start();
}
});
mEtSpeech.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.length() > MAX_LEN) {
mTvInputLen.setText("已达到最大长度");
} else {
mTvInputLen.setText("你还可以输入" + (MAX_LEN - s.length()) + "个字");
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
if (s.length() > MAX_LEN) {
mEtSpeech.setText(s.subSequence(0, MAX_LEN));
CharSequence text = mEtSpeech.getText();
if (text instanceof Spannable) {
Selection.setSelection((Spannable) text, MAX_LEN);
}
}
}
});
}
use of android.text.Spannable in project Talon-for-Twitter by klinker24.
the class ActivityCursorAdapter method bindView.
@Override
public void bindView(final View view, Context mContext, final Cursor cursor) {
final ViewHolder holder = (ViewHolder) view.getTag();
final String title = cursor.getString(TITLE_COL);
final long id = cursor.getLong(TWEET_COL);
holder.tweetId = id;
final String profilePic = cursor.getString(PRO_PIC_COL);
holder.proPicUrl = profilePic;
final String tweetText = cursor.getString(TEXT_COL);
final String name = cursor.getString(NAME_COL);
final String screenname = cursor.getString(SCREEN_NAME_COL);
final String picUrl = cursor.getString(PIC_COL);
holder.picUrl = picUrl;
final long longTime = cursor.getLong(TIME_COL);
final String otherUrl = cursor.getString(URL_COL);
final String users = cursor.getString(USER_COL);
final String hashtags = cursor.getString(HASHTAG_COL);
holder.gifUrl = cursor.getString(GIF_COL);
String retweeter;
try {
retweeter = cursor.getString(RETWEETER_COL);
} catch (Exception e) {
retweeter = "";
}
if (retweeter == null) {
retweeter = "";
}
holder.name.setSingleLine(true);
int type = cursor.getInt(TYPE_COL);
switch(type) {
case ActivityDataSource.TYPE_NEW_FOLLOWER:
holder.background.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String[] userArray = users.split(" ");
if (userArray.length == 1) {
Intent viewProfile = new Intent(context, ProfilePager.class);
viewProfile.putExtra("screenname", userArray[0].replace("@", "").replace(" ", ""));
context.startActivity(viewProfile);
} else {
displayUserDialog(userArray);
}
}
});
break;
case ActivityDataSource.TYPE_MENTION:
final String fRetweeter = retweeter;
holder.background.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (holder.preventNextClick) {
holder.preventNextClick = false;
return;
}
String link = "";
boolean displayPic = !holder.picUrl.equals("") && !holder.picUrl.contains("youtube");
if (displayPic) {
link = holder.picUrl;
} else {
link = otherUrl.split(" ")[0];
}
Intent viewTweet = new Intent(context, TweetPager.class);
viewTweet.putExtra("name", name);
viewTweet.putExtra("screenname", screenname);
viewTweet.putExtra("time", longTime);
viewTweet.putExtra("tweet", tweetText);
viewTweet.putExtra("retweeter", fRetweeter);
viewTweet.putExtra("webpage", link);
viewTweet.putExtra("picture", displayPic);
viewTweet.putExtra("other_links", otherUrl);
viewTweet.putExtra("tweetid", holder.tweetId);
viewTweet.putExtra("proPic", profilePic);
viewTweet.putExtra("users", users);
viewTweet.putExtra("hashtags", hashtags);
viewTweet.putExtra("animated_gif", holder.gifUrl);
context.startActivity(viewTweet);
}
});
break;
case ActivityDataSource.TYPE_FAVORITES:
case ActivityDataSource.TYPE_RETWEETS:
holder.background.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent retweeters = new Intent(context, ViewUsersPopup.class);
retweeters.putExtra("id", id);
context.startActivity(retweeters);
}
});
break;
}
holder.profilePic.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent viewProfile = new Intent(context, ProfilePager.class);
if (screenname == null) {
String[] userArray = users.split(" ");
viewProfile.putExtra("screenname", userArray[0].replace("@", "").replace(" ", ""));
} else if (screenname.contains(" ")) {
holder.background.performClick();
} else {
viewProfile.putExtra("screenname", screenname);
}
context.startActivity(viewProfile);
}
});
holder.name.setText(title);
holder.tweet.setText(tweetText);
CacheableBitmapDrawable wrapper2 = mCache.getFromMemoryCache(holder.proPicUrl);
final boolean gotProPic;
if (wrapper2 == null) {
gotProPic = false;
if (holder.profilePic.getDrawable() != null) {
holder.profilePic.setImageDrawable(null);
}
} else {
gotProPic = true;
holder.profilePic.setImageDrawable(wrapper2);
}
mHandlers[currHandler].postDelayed(new Runnable() {
@Override
public void run() {
if (holder.tweetId == id) {
if (!gotProPic) {
loadProPic(context, holder, holder.proPicUrl, mCache, id);
}
if (settings.useEmoji && (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT || EmojiUtils.ios)) {
String text = holder.tweet.getText().toString();
if (EmojiUtils.emojiPattern.matcher(text).find()) {
final Spannable span = EmojiUtils.getSmiledText(context, Html.fromHtml(tweetText));
holder.tweet.setText(span);
}
}
holder.tweet.setSoundEffectsEnabled(false);
holder.tweet.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!TouchableMovementMethod.touched) {
// absorbs the click on the background
if (!holder.preventNextClick) {
holder.background.getBackground().setState(new int[] { android.R.attr.state_pressed });
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
holder.background.getBackground().setState(new int[] { android.R.attr.state_empty });
}
}, 25);
}
holder.background.performClick();
}
}
});
holder.tweet.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
if (!TouchableMovementMethod.touched) {
holder.background.performLongClick();
holder.preventNextClick = true;
}
return false;
}
});
TextUtils.linkifyText(context, holder.tweet, holder.background, true, otherUrl, false);
TextUtils.linkifyText(context, holder.retweeter, holder.background, true, "", false);
}
}
}, 400);
currHandler++;
if (currHandler == 10) {
currHandler = 0;
}
}
use of android.text.Spannable 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.Spannable 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);
}
use of android.text.Spannable 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_name();
String time = DateUtil.timeAgoInWords(getContext(view), comment.getTime());
String text = name + " " + time + " ";
holder.getAuthorName().setText(text);
TextViewUtil.setElementClickable(getContext(view), holder.getAuthorName(), comment.getFrom_name(), comment.getFromid(), comment.getFrom_type(), true);
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.getText();
int numLikes = comment.getLikes();
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 = AttrUtil.getResourceId(getContext(holder.getAuthorName()), R.attr.squarePlaceHolderIcon);
if (profilePlaceHolder == -1)
profilePlaceHolder = AttrUtil.getResourceId(getContext(holder.getAuthorName()), R.attr.circlePlaceHolderIcon);
String url = comment.getFrom_pic();
loadImage(holder.getAuthorPicture(), "http://www.google.com/abc/9.jpg", profilePlaceHolder, data);
holder.getCommentImage().setOnClickListener(null);
holder.getCommentLinkImage().setOnClickListener(null);
if (comment.getAttachment().isPhoto()) {
Image image = comment.getAttachment().getMedia().getImage();
RatioImageView rImageView = (RatioImageView) holder.getCommentImage();
rImageView.setImageSize(image.getWidth(), image.getHeight());
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());
}
});
}
holder.getCommentImage().setVisibility(comment.getAttachment().isPhoto() ? View.VISIBLE : View.GONE);
((View) holder.getCommentLinkImage().getParent()).setVisibility(comment.getAttachment().isShare() ? View.VISIBLE : View.GONE);
}
Aggregations