List of usage examples for android.text.format DateUtils getRelativeTimeSpanString
public static CharSequence getRelativeTimeSpanString(long startTime)
From source file:dheeraj.com.trafficsolution.PostsFragment.java
private void setupPost(final PostViewHolder postViewHolder, final Post post, final int position, final String inPostKey) { postViewHolder.setPhoto(post.getThumb_url()); postViewHolder.setText(post.getText()); postViewHolder.setTags(post.getTags()); Log.e("Tags", "Tags are" + post.getTags()); postViewHolder.setTimestamp(DateUtils.getRelativeTimeSpanString((long) post.getTimestamp()).toString()); final String postKey; if (mAdapter instanceof FirebaseRecyclerAdapter) { postKey = ((FirebaseRecyclerAdapter) mAdapter).getRef(position).getKey(); } else {/*w ww. j ava2 s . com*/ postKey = inPostKey; } Author author = post.getAuthor(); postViewHolder.setAuthor(author.getFull_name(), author.getUid()); postViewHolder.setIcon(author.getProfile_picture(), author.getUid()); ValueEventListener likeListener = new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { postViewHolder.setNumLikes(dataSnapshot.getChildrenCount()); if (dataSnapshot.hasChild(FirebaseUtil.getCurrentUserId())) { postViewHolder.setLikeStatus(PostViewHolder.LikeStatus.LIKED, getActivity()); } else { postViewHolder.setLikeStatus(PostViewHolder.LikeStatus.NOT_LIKED, getActivity()); } } @Override public void onCancelled(DatabaseError databaseError) { } }; FirebaseUtil.getLikesRef().child(postKey).addValueEventListener(likeListener); postViewHolder.mLikeListener = likeListener; postViewHolder.setPostClickListener(new PostViewHolder.PostClickListener() { @Override public void showComments() { Log.d(TAG, "Comment position: " + position); mListener.onPostComment(postKey); } @Override public void toggleLike() { Log.d(TAG, "Like position: " + position); mListener.onPostLike(postKey); } }); }
From source file:me.jreilly.JamesTweet.TweetView.TweetFragment.java
public void setTweet(RealmResults<TweetRealm> mDataset) { int i = 0;/*from w w w .j a va 2 s . c o m*/ String user_img = mDataset.get(i).getProfileImageUrl(); final String user_screen = mDataset.get(i).getScreename(); String media_url = "null"; Date created = mDataset.get(i).getDate(); boolean retweeted = mDataset.get(i).isRetweetedStatus(); String original = mDataset.get(i).getRetweetedBy(); String username = mDataset.get(i).getName(); String text = mDataset.get(i).getText(); final long tId = mDataset.get(i).getId(); //Load Profile Image Picasso.with(mProfileImage.getContext()).load(user_img).transform(new CircleTransform()) .into(mProfileImage); //Set profile image to go to the users profile mProfileImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mActivity.swapToProfile(user_screen, mProfileImage); } }); final String imageUrl = media_url; ViewGroup.LayoutParams params = mImage.getLayoutParams(); //Set Cropped Media image and zoomImage animation if (!imageUrl.equals("null")) { mImage.getLayoutParams().height = 400; Picasso.with(mImage.getContext()).load(imageUrl).fit().centerCrop().into(mImage); } else { //Media is not need so it is hidden. mImage.setImageDrawable(null); mImage.getLayoutParams().height = 0; } //Set Username Text Field Calendar cal = Calendar.getInstance(); mDate.setText(DateUtils.getRelativeTimeSpanString(created.getTime())); mUser.setText(username); String tweetText = text; //Highlight Profile names/hashtags and their clickable spans ArrayList<int[]> hashtagSpans = getSpans(tweetText, '#'); ArrayList<int[]> profileSpans = getSpans(tweetText, '@'); SpannableString tweetContent = new SpannableString(tweetText); for (int j = 0; j < profileSpans.size(); j++) { int[] span = profileSpans.get(j); int profileStart = span[0]; int profileEnd = span[1]; tweetContent.setSpan(new ProfileLink(mTweet.getContext(), mActivity), profileStart, profileEnd, 0); } mTweet.setMovementMethod(LinkMovementMethod.getInstance()); mTweet.setText(tweetContent); }
From source file:org.catnut.plugin.zhihu.ZhihuItemFragment.java
@Override public void onViewCreated(final View view, final Bundle savedInstanceState) { final TextView title = (TextView) view.findViewById(android.R.id.title); final TextView author = (TextView) view.findViewById(R.id.author); final TextView lastAlterDate = (TextView) view.findViewById(R.id.last_alter_date); registerForContextMenu(title);/*from w w w . j a v a2 s . c o m*/ title.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getActivity().openContextMenu(title); } }); (new Thread(new Runnable() { @Override public void run() { Cursor cursor = getActivity().getContentResolver().query(CatnutProvider.parse(Zhihu.MULTIPLE), PROJECTION, Zhihu.ANSWER_ID + "=" + mAnswerId, null, null); if (cursor.moveToNext()) { mQuestionId = cursor.getLong(cursor.getColumnIndex(Zhihu.QUESTION_ID)); final String _title = cursor.getString(cursor.getColumnIndex(Zhihu.TITLE)); final String _question = cursor.getString(cursor.getColumnIndex(Zhihu.DESCRIPTION)); final String _nick = cursor.getString(cursor.getColumnIndex(Zhihu.NICK)); final String _content = cursor.getString(cursor.getColumnIndex(Zhihu.ANSWER)); final long _lastAlterDate = cursor.getLong(cursor.getColumnIndex(Zhihu.LAST_ALTER_DATE)); cursor.close(); // answer Matcher matcher = HTML_IMG.matcher(_content); final List<String> contentSegment = new ArrayList<String>(); processText(_content, matcher, contentSegment); // question matcher = HTML_IMG.matcher(_question); final List<String> questionSegment = new ArrayList<String>(); processText(_question, matcher, questionSegment); new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { title.setText(_title); getActivity().getActionBar().setSubtitle(_title); // ??? int l = contentSegment.size() > 1 ? contentSegment.size() >> 1 : 0; l += questionSegment.size() > 1 ? questionSegment.size() >> 1 : 0; if (l > 0) { mImageUrls = new ArrayList<Uri>(l); } // ? boolean useCachedImg = CatnutApp.getBoolean(R.string.pref_enable_cache_zhihu_images, R.bool.default_plugin_status); l = 0; // reset for reuse String text; int screenWidth = CatnutUtils.getScreenWidth(getActivity()); int max = getActivity().getResources().getDimensionPixelSize(R.dimen.max_thumb_width); if (screenWidth > max) { screenWidth = max; } LayoutInflater inflater = LayoutInflater.from(getActivity()); if (!TextUtils.isEmpty(_question)) { ViewGroup questionHolder = (ViewGroup) view.findViewById(R.id.question); for (int i = 0; i < questionSegment.size(); i++) { text = questionSegment.get(i); if (!TextUtils.isEmpty(text)) { if ((i & 1) == 0) { TextView section = (TextView) inflater.inflate(R.layout.zhihu_text, null); section.setTextSize(16); section.setTextColor( getResources().getColor(R.color.black50PercentColor)); section.setText(Html.fromHtml(text)); section.setMovementMethod(LinkMovementMethod.getInstance()); CatnutUtils.removeLinkUnderline(section); questionHolder.addView(section); } else { ImageView imageView = getImageView(); Uri uri = useCachedImg ? Zhihu.getCacheImageLocation(getActivity(), Uri.parse(text)) : Uri.parse(text); Picasso.with(getActivity()).load(uri).centerCrop() .resize(screenWidth, (int) (Constants.GOLDEN_RATIO * screenWidth)) .error(R.drawable.error).into(imageView); imageView.setTag(l++); // for click imageView.setOnClickListener(ZhihuItemFragment.this); mImageUrls.add(uri); questionHolder.addView(imageView); } } } } Typeface typeface = CatnutUtils.getTypeface(CatnutApp.getTingtingApp().getPreferences(), getString(R.string.pref_customize_tweet_font), getString(R.string.default_typeface)); ViewGroup answerHolder = (ViewGroup) view.findViewById(R.id.answer); for (int i = 0; i < contentSegment.size(); i++) { text = contentSegment.get(i); if (!TextUtils.isEmpty(text)) { if ((i & 1) == 0) { TextView section = (TextView) inflater.inflate(R.layout.zhihu_text, null); section.setText(Html.fromHtml(text)); CatnutUtils.setTypeface(section, typeface); CatnutUtils.removeLinkUnderline(section); section.setMovementMethod(LinkMovementMethod.getInstance()); answerHolder.addView(section); } else { ImageView image = getImageView(); Uri uri = useCachedImg ? Zhihu.getCacheImageLocation(getActivity(), Uri.parse(text)) : Uri.parse(text); Picasso.with(getActivity()).load(uri).centerCrop() .resize(screenWidth, (int) (Constants.GOLDEN_RATIO * screenWidth)) .error(R.drawable.error).into(image); image.setTag(l++); // image.setOnClickListener(ZhihuItemFragment.this); mImageUrls.add(uri); answerHolder.addView(image); } } } author.setText(_nick); lastAlterDate.setText(DateUtils.getRelativeTimeSpanString(_lastAlterDate)); if (mSwipeRefreshLayout != null) { mSwipeRefreshLayout.setRefreshing(false); } } }); } else { cursor.close(); } } })).start(); }
From source file:com.myapps.upesse.upes_spefest.ui.activity.PostsFragment.java
private void setupPost(final PostViewHolder postViewHolder, final Post post, final int position, final String inPostKey) { if (post != null) { postViewHolder.setPhoto(post.getThumb_url()); postViewHolder.setText(post.getText()); postViewHolder.setTimestamp(DateUtils.getRelativeTimeSpanString((long) post.getTimestamp()).toString()); final String postKey; if (mAdapter instanceof FirebaseRecyclerAdapter) { postKey = ((FirebaseRecyclerAdapter) mAdapter).getRef(position).getKey(); } else {// ww w . j ava2 s . c o m postKey = inPostKey; } Author author = post.getAuthor(); postViewHolder.setAuthor(author.getFull_name(), author.getUid()); if (author.getProfile_picture() == null) { postViewHolder.setIcon("NO_PROFILE_PICTURE", author.getUid()); } else { postViewHolder.setIcon(author.getProfile_picture(), author.getUid()); } ValueEventListener likeListener = new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if (getActivity() != null) { postViewHolder.setNumLikes(dataSnapshot.getChildrenCount()); if (dataSnapshot.hasChild(FirebaseUtil.getCurrentUserId())) { postViewHolder.setLikeStatus(PostViewHolder.LikeStatus.LIKED, getActivity()); } else { postViewHolder.setLikeStatus(PostViewHolder.LikeStatus.NOT_LIKED, getActivity()); } } } @Override public void onCancelled(DatabaseError databaseError) { } }; FirebaseUtil.getLikesRef().child(postKey).addValueEventListener(likeListener); postViewHolder.mLikeListener = likeListener; postViewHolder.btnMore.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mListener.onMoreClick(v, postViewHolder.getAdapterPosition(), post.getThumb_url(), post.getAuthor().getUid(), post, postKey); } }); postViewHolder.setPostClickListener(new PostViewHolder.PostClickListener() { @Override public void showComments() { Log.d(TAG, "Comment position: " + position); mListener.onPostComment(postKey); } @Override public void toggleLike() { Log.d(TAG, "Like position: " + position); mListener.onPostLike(postKey); } }); } }
From source file:org.site_monitor.activity.MainActivity.java
private void scheduleTimer() { if (countDownTimer != null) { countDownTimer.cancel();/* w w w. j a va 2s . co m*/ } final long nextAlarmTime = alarmUtil.getNextAlarmTime(this); final long nextAlarmInterval = alarmUtil.getCountUntilNextAlarmTime(this); if (nextAlarmInterval > 0) { timerBannerView.setVisibility(View.VISIBLE); countDownTimer = new CountDownTimer(nextAlarmInterval, TimeUtil._1_SEC * 5) { public void onTick(long millisUntilFinished) { chronometer.setText(DateUtils.getRelativeTimeSpanString(nextAlarmTime)); chronometer.setText(DateUtils.getRelativeTimeSpanString(nextAlarmTime, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS)); } public void onFinish() { chronometer.setText(R.string.imminent); } }.start(); } else { timerBannerView.setVisibility(View.GONE); } }
From source file:org.catnut.fragment.ProfileFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { // ??*_*?view? String query = CatnutUtils.buildQuery(PROJECTION, User.screen_name + "=" + CatnutUtils.quote(mScreenName), User.TABLE, null, null, null); new AsyncQueryHandler(getActivity().getContentResolver()) { @Override/*from w w w.ja va2s.com*/ protected void onQueryComplete(int token, Object cookie, Cursor cursor) { if (cursor.moveToNext()) { injectProfile(cursor); } else { // fall back to load from network... mApp.getRequestQueue().add(new CatnutRequest(getActivity(), UserAPI.profile(mScreenName), new UserProcessor.UserProfileProcessor(), new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { injectProfile(response); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Toast.makeText(getActivity(), getString(R.string.user_not_found), Toast.LENGTH_SHORT).show(); } })); } cursor.close(); } }.startQuery(0, null, CatnutProvider.parse(User.MULTIPLE), null, query, null, null); // ?? if (mApp.getPreferences().getBoolean(getString(R.string.pref_show_latest_tweet), true)) { String queryLatestTweet = CatnutUtils.buildQuery(new String[] { Status.columnText, // Status.thumbnail_pic, Status.bmiddle_pic, Status.comments_count, Status.reposts_count, Status.retweeted_status, Status.attitudes_count, Status.source, Status.created_at, }, new StringBuilder("uid=(select _id from ").append(User.TABLE).append(" where ") .append(User.screen_name).append("=").append(CatnutUtils.quote(mScreenName)).append(")") .append(" and ").append(Status.TYPE).append(" in(").append(Status.HOME).append(",") .append(Status.RETWEET).append(",").append(Status.OTHERS).append(")").toString(), Status.TABLE, null, BaseColumns._ID + " desc", "1"); new AsyncQueryHandler(getActivity().getContentResolver()) { @Override protected void onQueryComplete(int token, Object cookie, Cursor cursor) { if (cursor.moveToNext()) { mTweetLayout.setOnClickListener(tweetsOnclickListener); ViewStub viewStub = (ViewStub) mTweetLayout.findViewById(R.id.latest_tweet); View tweet = viewStub.inflate(); mRetweetLayout = tweet.findViewById(R.id.retweet); tweet.findViewById(R.id.timeline).setVisibility(View.GONE); tweet.findViewById(R.id.verified).setVisibility(View.GONE); tweet.findViewById(R.id.tweet_overflow).setVisibility(View.GONE); CatnutUtils.setText(tweet, R.id.nick, getString(R.string.latest_statues)) .setTextColor(getResources().getColor(R.color.actionbar_background)); String tweetText = cursor.getString(cursor.getColumnIndex(Status.columnText)); TweetImageSpan tweetImageSpan = new TweetImageSpan(getActivity()); TweetTextView text = (TweetTextView) CatnutUtils.setText(tweet, R.id.text, tweetImageSpan.getImageSpan(tweetText)); CatnutUtils.vividTweet(text, null); CatnutUtils.setTypeface(text, mTypeface); text.setLineSpacing(0, mLineSpacing); String thumbsUrl = cursor.getString(cursor.getColumnIndex(Status.bmiddle_pic)); if (!TextUtils.isEmpty(thumbsUrl)) { View thumbs = tweet.findViewById(R.id.thumbs); Picasso.with(getActivity()).load(thumbsUrl).placeholder(R.drawable.error) .error(R.drawable.error).into((ImageView) thumbs); thumbs.setVisibility(View.VISIBLE); } int replyCount = cursor.getInt(cursor.getColumnIndex(Status.comments_count)); CatnutUtils.setText(tweet, R.id.reply_count, CatnutUtils.approximate(replyCount)); int retweetCount = cursor.getInt(cursor.getColumnIndex(Status.reposts_count)); CatnutUtils.setText(tweet, R.id.reteet_count, CatnutUtils.approximate(retweetCount)); int favoriteCount = cursor.getInt(cursor.getColumnIndex(Status.attitudes_count)); CatnutUtils.setText(tweet, R.id.like_count, CatnutUtils.approximate(favoriteCount)); String source = cursor.getString(cursor.getColumnIndex(Status.source)); CatnutUtils.setText(tweet, R.id.source, Html.fromHtml(source).toString()); String create_at = cursor.getString(cursor.getColumnIndex(Status.created_at)); CatnutUtils .setText(tweet, R.id.create_at, DateUtils.getRelativeTimeSpanString(DateTime.getTimeMills(create_at))) .setVisibility(View.VISIBLE); // retweet final String jsonString = cursor.getString(cursor.getColumnIndex(Status.retweeted_status)); try { JSONObject jsonObject = new JSONObject(jsonString); TweetTextView retweet = (TweetTextView) mRetweetLayout.findViewById(R.id.retweet_text); retweet.setText(jsonObject.optString(Status.text)); CatnutUtils.vividTweet(retweet, tweetImageSpan); CatnutUtils.setTypeface(retweet, mTypeface); retweet.setLineSpacing(0, mLineSpacing); long mills = DateTime.getTimeMills(jsonObject.optString(Status.created_at)); TextView tv = (TextView) mRetweetLayout.findViewById(R.id.retweet_create_at); tv.setText(DateUtils.getRelativeTimeSpanString(mills)); TextView retweetUserScreenName = (TextView) mRetweetLayout .findViewById(R.id.retweet_nick); JSONObject user = jsonObject.optJSONObject(User.SINGLE); if (user == null) { retweetUserScreenName.setText(getString(R.string.unknown_user)); } else { retweetUserScreenName.setText(user.optString(User.screen_name)); mRetweetLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(), TweetActivity.class); intent.putExtra(Constants.JSON, jsonString); startActivity(intent); } }); } } catch (Exception e) { mRetweetLayout.setVisibility(View.GONE); } } cursor.close(); } }.startQuery(0, null, CatnutProvider.parse(Status.MULTIPLE), null, queryLatestTweet, null, null); } }
From source file:com.quarterfull.newsAndroid.NewsDetailFragment.java
@SuppressLint("SimpleDateFormat") public static String getHtmlPage(Context context, RssItem rssItem, boolean showHeader) { String feedTitle = "Undefined"; String favIconUrl = null;// w ww .j a v a 2s .c o m Feed feed = rssItem.getFeed(); int[] colors = ColorHelper.getColorsFromAttributes(context, R.attr.dividerLineColor, R.attr.rssItemListBackground); int feedColor = colors[0]; if (feed != null) { feedTitle = StringEscapeUtils.escapeHtml4(feed.getFeedTitle()); favIconUrl = feed.getFaviconUrl(); if (feed.getAvgColour() != null) feedColor = Integer.parseInt(feed.getAvgColour()); } if (favIconUrl != null) { DiskCache diskCache = ImageLoader.getInstance().getDiskCache(); File file = diskCache.get(favIconUrl); if (file != null) favIconUrl = "file://" + file.getAbsolutePath(); } else { favIconUrl = "file:///android_res/drawable/default_feed_icon_light.png"; } String body_id; if (ThemeChooser.isDarkTheme(context)) { body_id = "darkTheme"; } else body_id = "lightTheme"; boolean isRightToLeft = context.getResources().getBoolean(R.bool.is_right_to_left); String rtlClass = isRightToLeft ? "rtl" : ""; String borderSide = isRightToLeft ? "right" : "left"; StringBuilder builder = new StringBuilder(); builder.append( "<html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=0\" />"); builder.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"web.css\" />"); builder.append("<style type=\"text/css\">"); builder.append(String.format( "#top_section { border-%s: 4px solid %s; border-bottom: 1px solid %s; background: %s }", borderSide, ColorHelper.getCssColor(feedColor), ColorHelper.getCssColor(colors[0]), ColorHelper.getCssColor(colors[1]))); builder.append("</style>"); builder.append(String.format("</head><body id=\"%s\" class=\"%s\">", body_id, rtlClass)); if (showHeader) { builder.append("<div id=\"top_section\">"); builder.append("<div id=\"header\">"); String title = StringEscapeUtils.escapeHtml4(rssItem.getTitle()); String linkToFeed = StringEscapeUtils.escapeHtml4(rssItem.getLink()); builder.append(String.format("<a href=\"%s\">%s</a>", linkToFeed, title)); builder.append("</div>"); String authorOfArticle = StringEscapeUtils.escapeHtml4(rssItem.getAuthor()); if (authorOfArticle != null) if (!authorOfArticle.trim().equals("")) feedTitle += " - " + authorOfArticle.trim(); builder.append("<div id=\"header_small_text\">"); builder.append("<div id=\"subscription\">"); builder.append(String.format("<img id=\"imgFavicon\" src=\"%s\" />", favIconUrl)); builder.append(feedTitle.trim()); builder.append("</div>"); Date date = rssItem.getPubDate(); if (date != null) { String dateString = (String) DateUtils.getRelativeTimeSpanString(date.getTime()); builder.append("<div id=\"datetime\">"); builder.append(dateString); builder.append("</div>"); } builder.append("</div>"); builder.append("</div>"); } String description = rssItem.getBody(); builder.append("<div id=\"content\">"); builder.append(getDescriptionWithCachedImages(description).trim()); builder.append("</div>"); builder.append("</body></html>"); String htmlData = builder.toString().replaceAll("\"//", "\"https://"); return htmlData; }
From source file:org.catnut.fragment.TweetFragment.java
private void loadTweet() { // load tweet from local... String query = CatnutUtils.buildQuery( new String[] { Status.uid, Status.columnText, Status.bmiddle_pic, Status.original_pic, Status.comments_count, Status.reposts_count, Status.attitudes_count, Status.source, Status.favorited, Status.retweeted_status, Status.pic_urls, "s." + Status.created_at, User.screen_name, User.avatar_large, User.remark, User.verified }, "s._id=" + mId, Status.TABLE + " as s", "inner join " + User.TABLE + " as u on s.uid=u._id", null, null);/*from w w w.jav a2s .c o m*/ new AsyncQueryHandler(getActivity().getContentResolver()) { @Override protected void onQueryComplete(int token, Object cookie, Cursor cursor) { if (cursor.moveToNext()) { Picasso.with(getActivity()).load(cursor.getString(cursor.getColumnIndex(User.avatar_large))) .placeholder(R.drawable.error).error(R.drawable.error).into(mAvatar); final long uid = cursor.getLong(cursor.getColumnIndex(Status.uid)); final String screenName = cursor.getString(cursor.getColumnIndex(User.screen_name)); mAvatar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(), ProfileActivity.class); intent.putExtra(Constants.ID, uid); intent.putExtra(User.screen_name, screenName); startActivity(intent); } }); String remark = cursor.getString(cursor.getColumnIndex(User.remark)); mRemark.setText(TextUtils.isEmpty(remark) ? screenName : remark); mScreenName.setText(getString(R.string.mention_text, screenName)); mPlainText = cursor.getString(cursor.getColumnIndex(Status.columnText)); mText.setText(mPlainText); CatnutUtils.vividTweet(mText, mImageSpan); CatnutUtils.setTypeface(mText, mTypeface); mText.setLineSpacing(0, mLineSpacing); int replyCount = cursor.getInt(cursor.getColumnIndex(Status.comments_count)); mReplayCount.setText(CatnutUtils.approximate(replyCount)); int retweetCount = cursor.getInt(cursor.getColumnIndex(Status.reposts_count)); mReteetCount.setText(CatnutUtils.approximate(retweetCount)); int favoriteCount = cursor.getInt(cursor.getColumnIndex(Status.attitudes_count)); mFavoriteCount.setText(CatnutUtils.approximate(favoriteCount)); String source = cursor.getString(cursor.getColumnIndex(Status.source)); mSource.setText(Html.fromHtml(source).toString()); mCreateAt.setText(DateUtils.getRelativeTimeSpanString( DateTime.getTimeMills(cursor.getString(cursor.getColumnIndex(Status.created_at))))); if (CatnutUtils.getBoolean(cursor, User.verified)) { mTweetLayout.findViewById(R.id.verified).setVisibility(View.VISIBLE); } String thumb = cursor.getString(cursor.getColumnIndex(Status.bmiddle_pic)); String url = cursor.getString(cursor.getColumnIndex(Status.original_pic)); loadThumbs(thumb, url, mThumbs, CatnutUtils.optPics(cursor.getString(cursor.getColumnIndex(Status.pic_urls))), mPicsOverflow); // retweet final String jsonString = cursor.getString(cursor.getColumnIndex(Status.retweeted_status)); if (!TextUtils.isEmpty(jsonString)) { View retweet = mRetweetLayout.inflate(); try { JSONObject json = new JSONObject(jsonString); JSONObject user = json.optJSONObject(User.SINGLE); String _remark = user.optString(User.remark); if (TextUtils.isEmpty(_remark)) { _remark = user.optString(User.screen_name); } CatnutUtils.setText(retweet, R.id.retweet_nick, getString(R.string.mention_text, _remark)); long mills = DateTime.getTimeMills(json.optString(Status.created_at)); CatnutUtils.setText(retweet, R.id.retweet_create_at, DateUtils.getRelativeTimeSpanString(mills)); TweetTextView retweetText = (TweetTextView) CatnutUtils.setText(retweet, R.id.retweet_text, json.optString(Status.text)); CatnutUtils.vividTweet(retweetText, mImageSpan); CatnutUtils.setTypeface(retweetText, mTypeface); retweetText.setLineSpacing(0, mLineSpacing); retweet.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(), TweetActivity.class); intent.putExtra(Constants.JSON, jsonString); startActivity(intent); } }); retweet.findViewById(R.id.verified) .setVisibility(user.optBoolean(User.verified) ? View.VISIBLE : View.GONE); if (json.has(Status.thumbnail_pic)) { loadThumbs(json.optString(Status.bmiddle_pic), json.optString(Status.bmiddle_pic), (ImageView) retweet.findViewById(R.id.thumbs), json.optJSONArray(Status.pic_urls), retweet.findViewById(R.id.pics_overflow)); } } catch (JSONException e) { Log.e(TAG, "convert text to string error!", e); retweet.setVisibility(View.GONE); } } // shareAndFavorite&favorite shareAndFavorite(CatnutUtils.getBoolean(cursor, Status.favorited), mPlainText); } cursor.close(); } }.startQuery(0, null, CatnutProvider.parse(Status.MULTIPLE), null, query, null, null); }
From source file:org.mozilla.gecko.fxa.activities.FxAccountStatusFragment.java
private String getLastSyncedString(final long startTime) { if (new Date(startTime).before(EARLIEST_VALID_SYNCED_DATE)) { return getActivity().getString(R.string.fxaccount_status_never_synced); }//from w ww . j a v a 2 s . com final CharSequence relativeTimeSpanString = DateUtils.getRelativeTimeSpanString(startTime); return getActivity().getResources().getString(R.string.fxaccount_status_last_synced, relativeTimeSpanString); }
From source file:org.catnut.fragment.TweetFragment.java
private void loadRetweet() { JSONObject user = mJson.optJSONObject(User.SINGLE); Picasso.with(getActivity()).load(user == null ? Constants.NULL : user.optString(User.avatar_large)) .placeholder(R.drawable.error).error(R.drawable.error).into(mAvatar); final long uid = mJson.optLong(Status.uid); final String screenName = user == null ? getString(R.string.unknown_user) : user.optString(User.screen_name); mAvatar.setOnClickListener(new View.OnClickListener() { @Override/*from w w w. ja v a2 s .c o m*/ public void onClick(View v) { Intent intent = new Intent(getActivity(), ProfileActivity.class); intent.putExtra(Constants.ID, uid); intent.putExtra(User.screen_name, screenName); startActivity(intent); } }); String remark = user.optString(User.remark); mRemark.setText(TextUtils.isEmpty(remark) ? screenName : remark); mScreenName.setText(getString(R.string.mention_text, screenName)); mPlainText = mJson.optString(Status.text); mText.setText(mPlainText); CatnutUtils.vividTweet(mText, mImageSpan); CatnutUtils.setTypeface(mText, mTypeface); mText.setLineSpacing(0, mLineSpacing); int replyCount = mJson.optInt(Status.comments_count); mReplayCount.setText(CatnutUtils.approximate(replyCount)); int retweetCount = mJson.optInt(Status.reposts_count); mReteetCount.setText(CatnutUtils.approximate(retweetCount)); int favoriteCount = mJson.optInt(Status.attitudes_count); mFavoriteCount.setText(CatnutUtils.approximate(favoriteCount)); String source = mJson.optString(Status.source); mSource.setText(Html.fromHtml(source).toString()); mCreateAt.setText( DateUtils.getRelativeTimeSpanString(DateTime.getTimeMills(mJson.optString(Status.created_at)))); if (user.optBoolean(User.verified)) { mTweetLayout.findViewById(R.id.verified).setVisibility(View.VISIBLE); } loadThumbs(mJson.optString(Status.bmiddle_pic), mJson.optString(Status.original_pic), mThumbs, mJson.optJSONArray(Status.pic_urls), mPicsOverflow); shareAndFavorite(mJson.optBoolean(Status.favorited), mJson.optString(Status.text)); if (!mJson.has(Status.retweeted_status)) { //todo: ????? } }