コード例 #1
0
  public void displaySampleStatus() {
    final boolean profileImageEnabled = adapter.isProfileImageEnabled();
    profileImageView.setVisibility(profileImageEnabled ? View.VISIBLE : View.GONE);
    if (profileImageSpace != null) {
      profileImageSpace.setVisibility(profileImageEnabled ? View.VISIBLE : View.GONE);
    }
    if (statusInfoSpace != null) {
      statusInfoSpace.setVisibility(profileImageEnabled ? View.VISIBLE : View.GONE);
    }
    if (statusContentUpperSpace != null) {
      statusContentUpperSpace.setVisibility(View.VISIBLE);
    }

    profileImageView.setImageResource(R.mipmap.ic_launcher);
    nameView.setName(TWIDERE_PREVIEW_NAME);
    nameView.setScreenName("@" + TWIDERE_PREVIEW_SCREEN_NAME);
    nameView.updateText(adapter.getBidiFormatter());
    if (adapter.getLinkHighlightingStyle() == VALUE_LINK_HIGHLIGHT_OPTION_CODE_NONE) {
      final TwidereLinkify linkify = adapter.getTwidereLinkify();
      final Spannable text = HtmlSpanBuilder.fromHtml(TWIDERE_PREVIEW_TEXT_HTML);
      linkify.applyAllLinks(text, null, -1, false, adapter.getLinkHighlightingStyle(), true);
      textView.setText(text);
    } else {
      textView.setText(toPlainText(TWIDERE_PREVIEW_TEXT_HTML));
    }
    timeView.setTime(System.currentTimeMillis());
    final boolean showCardActions = isCardActionsShown();
    if (adapter.isMediaPreviewEnabled()) {
      mediaPreview.setVisibility(View.VISIBLE);
      if (textMediaSpace != null) {
        textMediaSpace.setVisibility(View.GONE);
      }
    } else {
      mediaPreview.setVisibility(View.GONE);
      if (textMediaSpace != null) {
        textMediaSpace.setVisibility(showCardActions ? View.GONE : View.VISIBLE);
      }
    }
    actionButtons.setVisibility(showCardActions ? View.VISIBLE : View.GONE);
    itemMenu.setVisibility(showCardActions ? View.VISIBLE : View.GONE);
    if (statusContentLowerSpace != null) {
      statusContentLowerSpace.setVisibility(showCardActions ? View.GONE : View.VISIBLE);
    }
    quoteMediaPreview.setVisibility(View.GONE);
    if (quotedTextMediaSpace != null) {
      quotedTextMediaSpace.setVisibility(View.GONE);
    }
    mediaPreview.displayMedia(R.drawable.nyan_stars_background);
    extraTypeView.setImageResource(R.drawable.ic_action_gallery);
  }
コード例 #2
0
 public NameView(final Context context, final AttributeSet attrs, final int defStyleAttr) {
   super(context, attrs, defStyleAttr);
   setEllipsize(TextUtils.TruncateAt.END);
   final TypedArray a =
       context.obtainStyledAttributes(attrs, R.styleable.NameView, defStyleAttr, 0);
   setPrimaryTextColor(a.getColor(R.styleable.NameView_nv_primaryTextColor, 0));
   setSecondaryTextColor(a.getColor(R.styleable.NameView_nv_secondaryTextColor, 0));
   if (mTwoLine = a.getBoolean(R.styleable.NameView_nv_twoLine, false)) {
     setSingleLine(false);
     setMaxLines(2);
   } else {
     setSingleLine(true);
   }
   mPrimaryTextStyle = new StyleSpan(a.getInt(R.styleable.NameView_nv_primaryTextStyle, 0));
   mSecondaryTextStyle = new StyleSpan(a.getInt(R.styleable.NameView_nv_secondaryTextStyle, 0));
   a.recycle();
   setNameFirst(true);
   if (isInEditMode()) {
     setName("Name");
     setScreenName("@screenname");
     updateText();
   }
 }
コード例 #3
0
  @Override
  public void displayStatus(
      @NonNull final ParcelableStatus status,
      final boolean displayInReplyTo,
      final boolean shouldDisplayExtraType) {

    final MediaLoaderWrapper loader = adapter.getMediaLoader();
    final AsyncTwitterWrapper twitter = adapter.getTwitterWrapper();
    final TwidereLinkify linkify = adapter.getTwidereLinkify();
    final BidiFormatter formatter = adapter.getBidiFormatter();
    final Context context = adapter.getContext();
    final boolean nameFirst = adapter.isNameFirst();
    final boolean showCardActions = isCardActionsShown();

    actionButtons.setVisibility(showCardActions ? View.VISIBLE : View.GONE);
    itemMenu.setVisibility(showCardActions ? View.VISIBLE : View.GONE);
    if (statusContentLowerSpace != null) {
      statusContentLowerSpace.setVisibility(showCardActions ? View.GONE : View.VISIBLE);
    }

    final long replyCount = status.reply_count;
    final long retweetCount;
    final long favoriteCount;

    if (TwitterCardUtils.isPoll(status)) {
      statusInfoLabel.setText(R.string.label_poll);
      statusInfoIcon.setImageResource(R.drawable.ic_activity_action_poll);
      statusInfoLabel.setVisibility(View.VISIBLE);
      statusInfoIcon.setVisibility(View.VISIBLE);

      if (statusContentUpperSpace != null) {
        statusContentUpperSpace.setVisibility(View.GONE);
      }
    } else if (status.retweet_id != null) {
      final String retweetedBy =
          UserColorNameManager.decideDisplayName(
              status.retweet_user_nickname,
              status.retweeted_by_user_name,
              status.retweeted_by_user_screen_name,
              nameFirst);
      statusInfoLabel.setText(
          context.getString(R.string.name_retweeted, formatter.unicodeWrap(retweetedBy)));
      statusInfoIcon.setImageResource(R.drawable.ic_activity_action_retweet);
      statusInfoLabel.setVisibility(View.VISIBLE);
      statusInfoIcon.setVisibility(View.VISIBLE);

      if (statusContentUpperSpace != null) {
        statusContentUpperSpace.setVisibility(View.GONE);
      }
    } else if (status.in_reply_to_status_id != null
        && status.in_reply_to_user_id != null
        && displayInReplyTo) {
      final String inReplyTo =
          UserColorNameManager.decideDisplayName(
              status.in_reply_to_user_nickname,
              status.in_reply_to_name,
              status.in_reply_to_screen_name,
              nameFirst);
      statusInfoLabel.setText(
          context.getString(R.string.in_reply_to_name, formatter.unicodeWrap(inReplyTo)));
      statusInfoIcon.setImageResource(R.drawable.ic_activity_action_reply);
      statusInfoLabel.setVisibility(View.VISIBLE);
      statusInfoIcon.setVisibility(View.VISIBLE);

      if (statusContentUpperSpace != null) {
        statusContentUpperSpace.setVisibility(View.GONE);
      }
    } else {
      statusInfoLabel.setVisibility(View.GONE);
      statusInfoIcon.setVisibility(View.GONE);

      if (statusContentUpperSpace != null) {
        statusContentUpperSpace.setVisibility(View.VISIBLE);
      }
    }

    boolean skipLinksInText = status.extras != null && status.extras.support_entities;
    if (status.is_quote) {

      quotedNameView.setVisibility(View.VISIBLE);
      quotedTextView.setVisibility(View.VISIBLE);
      quoteIndicator.setVisibility(View.VISIBLE);

      quotedNameView.setName(
          UserColorNameManager.decideNickname(
              status.quoted_user_nickname, status.quoted_user_name));
      quotedNameView.setScreenName("@" + status.quoted_user_screen_name);

      if (adapter.getLinkHighlightingStyle() != VALUE_LINK_HIGHLIGHT_OPTION_CODE_NONE) {
        final SpannableStringBuilder text =
            SpannableStringBuilder.valueOf(status.quoted_text_unescaped);
        ParcelableStatusUtils.applySpans(text, status.quoted_spans);
        linkify.applyAllLinks(
            text,
            status.account_key,
            getLayoutPosition(),
            status.is_possibly_sensitive,
            adapter.getLinkHighlightingStyle(),
            skipLinksInText);
        quotedTextView.setText(text);
      } else {
        final String text = status.quoted_text_unescaped;
        quotedTextView.setText(text);
      }

      quoteIndicator.setColor(status.quoted_user_color);
      itemContent.drawStart(status.user_color);
    } else {

      quotedNameView.setVisibility(View.GONE);
      quotedTextView.setVisibility(View.GONE);
      quoteIndicator.setVisibility(View.GONE);

      if (status.is_retweet) {
        final int retweetUserColor = status.retweet_user_color;
        final int userColor = status.user_color;
        if (retweetUserColor == 0) {
          itemContent.drawStart(userColor);
        } else if (userColor == 0) {
          itemContent.drawStart(retweetUserColor);
        } else {
          itemContent.drawStart(retweetUserColor, userColor);
        }
      } else {
        itemContent.drawStart(status.user_color);
      }
    }

    if (status.is_retweet) {
      timeView.setTime(status.retweet_timestamp);
    } else {
      timeView.setTime(status.timestamp);
    }
    nameView.setName(UserColorNameManager.decideNickname(status.user_nickname, status.user_name));
    nameView.setScreenName("@" + status.user_screen_name);

    if (statusInfoSpace != null) {
      statusInfoSpace.setVisibility(View.VISIBLE);
    }

    if (adapter.isProfileImageEnabled()) {
      profileImageView.setVisibility(View.VISIBLE);
      if (profileImageSpace != null) {
        profileImageSpace.setVisibility(View.VISIBLE);
      }
      loader.displayProfileImage(profileImageView, status);

      profileTypeView.setImageResource(
          getUserTypeIconRes(status.user_is_verified, status.user_is_protected));
      profileTypeView.setVisibility(View.VISIBLE);
    } else {
      profileTypeView.setVisibility(View.GONE);
      profileImageView.setVisibility(View.GONE);
      if (profileImageSpace != null) {
        profileImageSpace.setVisibility(View.GONE);
      }

      loader.cancelDisplayTask(profileImageView);

      profileTypeView.setImageDrawable(null);
      profileTypeView.setVisibility(View.GONE);
    }

    if (adapter.shouldShowAccountsColor()) {
      itemContent.drawEnd(status.account_color);
    } else {
      itemContent.drawEnd();
    }

    if (adapter.isMediaPreviewEnabled()
        && (adapter.isSensitiveContentEnabled() || !status.is_possibly_sensitive)) {
      mediaPreview.setStyle(adapter.getMediaPreviewStyle());
      quoteMediaPreview.setStyle(adapter.getMediaPreviewStyle());

      final boolean showQuotedMedia = !ArrayUtils.isEmpty(status.quoted_media);
      final boolean showMedia = !showQuotedMedia && !ArrayUtils.isEmpty(status.media);

      mediaPreview.setVisibility(showMedia ? View.VISIBLE : View.GONE);
      if (textMediaSpace != null) {
        textMediaSpace.setVisibility(
            !status.is_quote && (showMedia || showCardActions) ? View.GONE : View.VISIBLE);
      }
      quoteMediaPreview.setVisibility(showQuotedMedia ? View.VISIBLE : View.GONE);
      if (quotedTextMediaSpace != null) {
        quotedTextMediaSpace.setVisibility(
            !status.is_quote || showQuotedMedia ? View.GONE : View.VISIBLE);
      }

      mediaPreview.displayMedia(
          status.media, loader, status.account_key, -1, this, adapter.getMediaLoadingHandler());
      quoteMediaPreview.displayMedia(
          status.quoted_media,
          loader,
          status.account_key,
          -1,
          this,
          adapter.getMediaLoadingHandler());
    } else {
      mediaPreview.setVisibility(View.GONE);
      quoteMediaPreview.setVisibility(View.GONE);
      if (textMediaSpace != null) {
        textMediaSpace.setVisibility(
            showCardActions && !status.is_quote ? View.GONE : View.VISIBLE);
      }
      if (quotedTextMediaSpace != null) {
        quotedTextMediaSpace.setVisibility(status.is_quote ? View.VISIBLE : View.GONE);
      }
    }

    if (adapter.getLinkHighlightingStyle() != VALUE_LINK_HIGHLIGHT_OPTION_CODE_NONE) {
      final SpannableStringBuilder text = SpannableStringBuilder.valueOf(status.text_unescaped);
      ParcelableStatusUtils.applySpans(text, status.spans);
      linkify.applyAllLinks(
          text,
          status.account_key,
          getLayoutPosition(),
          status.is_possibly_sensitive,
          adapter.getLinkHighlightingStyle(),
          skipLinksInText);
      textView.setText(text);
    } else {
      textView.setText(status.text_unescaped);
    }

    if (replyCount > 0) {
      replyCountView.setText(UnitConvertUtils.calculateProperCount(replyCount));
      replyCountView.setVisibility(View.VISIBLE);
    } else {
      replyCountView.setText(null);
      replyCountView.setVisibility(View.GONE);
    }

    if (twitter.isDestroyingStatus(status.account_key, status.my_retweet_id)) {
      retweetIconView.setActivated(false);
      retweetCount = Math.max(0, status.retweet_count - 1);
    } else {
      final boolean creatingRetweet = twitter.isCreatingRetweet(status.account_key, status.id);
      retweetIconView.setActivated(
          creatingRetweet
              || status.retweeted
              || Utils.isMyRetweet(
                  status.account_key, status.retweeted_by_user_key, status.my_retweet_id));
      retweetCount = status.retweet_count + (creatingRetweet ? 1 : 0);
    }

    if (retweetCount > 0) {
      retweetCountView.setText(UnitConvertUtils.calculateProperCount(retweetCount));
      retweetCountView.setVisibility(View.VISIBLE);
    } else {
      retweetCountView.setText(null);
      retweetCountView.setVisibility(View.GONE);
    }
    if (twitter.isDestroyingFavorite(status.account_key, status.id)) {
      favoriteIconView.setActivated(false);
      favoriteCount = Math.max(0, status.favorite_count - 1);
    } else {
      final boolean creatingFavorite = twitter.isCreatingFavorite(status.account_key, status.id);
      favoriteIconView.setActivated(creatingFavorite || status.is_favorite);
      favoriteCount = status.favorite_count + (creatingFavorite ? 1 : 0);
    }
    if (favoriteCount > 0) {
      favoriteCountView.setText(UnitConvertUtils.calculateProperCount(favoriteCount));
      favoriteCountView.setVisibility(View.VISIBLE);
    } else {
      favoriteCountView.setText(null);
      favoriteCountView.setVisibility(View.GONE);
    }
    if (shouldDisplayExtraType) {
      displayExtraTypeIcon(
          status.card_name,
          status.media,
          status.location,
          status.place_full_name,
          status.is_possibly_sensitive);
    } else {
      extraTypeView.setVisibility(View.GONE);
    }

    nameView.updateText(formatter);
    quotedNameView.updateText(formatter);
  }
コード例 #4
0
 public void updateText() {
   updateText(null);
 }