Search in sources :

Example 6 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project Signal-Android by WhisperSystems.

the class RecipientsEditor method populate.

public void populate(Recipients list) {
    SpannableStringBuilder sb = new SpannableStringBuilder();
    for (Recipient c : list.getRecipientsList()) {
        if (sb.length() != 0) {
            sb.append(", ");
        }
        sb.append(contactToToken(c));
    }
    setText(sb);
}
Also used : Recipient(org.thoughtcrime.securesms.recipients.Recipient) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 7 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project Signal-Android by WhisperSystems.

the class AbstractNotificationBuilder method getStyledMessage.

protected CharSequence getStyledMessage(@NonNull Recipient recipient, @Nullable CharSequence message) {
    SpannableStringBuilder builder = new SpannableStringBuilder();
    builder.append(Util.getBoldedString(recipient.toShortString()));
    builder.append(": ");
    builder.append(message == null ? "" : message);
    return builder;
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 8 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project Signal-Android by WhisperSystems.

the class SingleRecipientNotificationBuilder method setPrimaryMessageBody.

public void setPrimaryMessageBody(@NonNull Recipients threadRecipients, @NonNull Recipient individualRecipient, @NonNull CharSequence message, @Nullable SlideDeck slideDeck) {
    SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
    if (privacy.isDisplayContact() && (threadRecipients.isGroupRecipient() || !threadRecipients.isSingleRecipient())) {
        stringBuilder.append(Util.getBoldedString(individualRecipient.toShortString() + ": "));
    }
    if (privacy.isDisplayMessage()) {
        setContentText(stringBuilder.append(message));
        this.slideDeck = slideDeck;
    } else {
        setContentText(stringBuilder.append(context.getString(R.string.SingleRecipientNotificationBuilder_new_message)));
    }
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 9 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project Signal-Android by WhisperSystems.

the class SingleRecipientNotificationBuilder method getBigText.

private CharSequence getBigText(List<CharSequence> messageBodies) {
    SpannableStringBuilder content = new SpannableStringBuilder();
    for (CharSequence message : messageBodies) {
        content.append(message);
        content.append('\n');
    }
    return content;
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 10 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project SeriesGuide by UweTrottmann.

the class EpisodeDetailsFragment method populateEpisodeData.

private void populateEpisodeData(Cursor cursor) {
    if (cursor == null || !cursor.moveToFirst()) {
        // no data to display
        if (mEpisodeContainer != null) {
            mEpisodeContainer.setVisibility(View.GONE);
        }
        return;
    }
    mShowTvdbId = cursor.getInt(DetailsQuery.SHOW_ID);
    mSeasonNumber = cursor.getInt(DetailsQuery.SEASON);
    mEpisodeNumber = cursor.getInt(DetailsQuery.NUMBER);
    mShowRunTime = cursor.getInt(DetailsQuery.SHOW_RUNTIME);
    mEpisodeReleaseTime = cursor.getLong(DetailsQuery.FIRST_RELEASE_MS);
    // title and description
    mEpisodeFlag = cursor.getInt(DetailsQuery.WATCHED);
    mEpisodeTitle = cursor.getString(DetailsQuery.TITLE);
    boolean hideDetails = EpisodeTools.isUnwatched(mEpisodeFlag) && DisplaySettings.preventSpoilers(getContext());
    if (hideDetails) {
        // just show the episode number "1x02"
        mTitle.setText(TextTools.getEpisodeNumber(getContext(), mSeasonNumber, mEpisodeNumber));
    } else {
        mTitle.setText(mEpisodeTitle);
    }
    String overview = cursor.getString(DetailsQuery.OVERVIEW);
    if (TextUtils.isEmpty(overview)) {
        // no description available, show no translation available message
        mDescription.setText(getString(R.string.no_translation, LanguageTools.getShowLanguageStringFor(getContext(), cursor.getString(DetailsQuery.SHOW_LANGUAGE)), getString(R.string.tvdb)));
    } else {
        if (hideDetails) {
            mDescription.setText(R.string.no_spoilers);
        } else {
            mDescription.setText(overview);
        }
    }
    // show title
    mShowTitle = cursor.getString(DetailsQuery.SHOW_TITLE);
    // release date, also build release time and day
    SpannableStringBuilder timeAndNumbersText = new SpannableStringBuilder();
    if (mEpisodeReleaseTime != -1) {
        Date actualRelease = TimeTools.applyUserOffset(getContext(), mEpisodeReleaseTime);
        mReleaseDate.setText(TimeTools.formatToLocalDateAndDay(getContext(), actualRelease));
        String dateTime;
        if (DisplaySettings.isDisplayExactDate(getContext())) {
            // "31. October 2010"
            dateTime = TimeTools.formatToLocalDate(getContext(), actualRelease);
        } else {
            // "in 15 mins"
            dateTime = TimeTools.formatToLocalRelativeTime(getContext(), actualRelease);
        }
        // append day: "in 15 mins (Fri)"
        timeAndNumbersText.append(getString(R.string.release_date_and_day, dateTime, TimeTools.formatToLocalDay(actualRelease)).toUpperCase(Locale.getDefault()));
        timeAndNumbersText.append("  ");
    } else {
        mReleaseDate.setText(R.string.unknown);
    }
    // absolute number (e.g. relevant for Anime): "ABSOLUTE 142"
    int numberStartIndex = timeAndNumbersText.length();
    int absoluteNumber = cursor.getInt(DetailsQuery.NUMBER_ABSOLUTE);
    if (absoluteNumber > 0) {
        timeAndNumbersText.append(getString(R.string.episode_number_absolute)).append(" ").append(String.valueOf(absoluteNumber));
        // de-emphasize number
        timeAndNumbersText.setSpan(new TextAppearanceSpan(getActivity(), R.style.TextAppearance_Caption_Dim), numberStartIndex, timeAndNumbersText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    mReleaseTime.setText(timeAndNumbersText);
    // guest stars
    Utils.setLabelValueOrHide(mLabelGuestStars, mGuestStars, TextTools.splitAndKitTVDBStrings(cursor.getString(DetailsQuery.GUESTSTARS)));
    // DVD episode number
    Utils.setLabelValueOrHide(mLabelDvd, mDvd, cursor.getDouble(DetailsQuery.NUMBER_DVD));
    // directors
    Utils.setValueOrPlaceholder(mDirectors, TextTools.splitAndKitTVDBStrings(cursor.getString(DetailsQuery.DIRECTORS)));
    // writers
    Utils.setValueOrPlaceholder(mWriters, TextTools.splitAndKitTVDBStrings(cursor.getString(DetailsQuery.WRITERS)));
    // last TVDb edit date
    long lastEditSeconds = cursor.getLong(DetailsQuery.LAST_EDITED);
    if (lastEditSeconds > 0) {
        mLastEdit.setText(DateUtils.formatDateTime(getActivity(), lastEditSeconds * 1000, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME));
    } else {
        mLastEdit.setText(R.string.unknown);
    }
    // ratings
    mRatingsContainer.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            rateEpisode();
        }
    });
    CheatSheet.setup(mRatingsContainer, R.string.action_rate);
    // trakt rating
    mTextRating.setText(TraktTools.buildRatingString(cursor.getDouble(DetailsQuery.RATING_GLOBAL)));
    mTextRatingVotes.setText(TraktTools.buildRatingVotesString(getActivity(), cursor.getInt(DetailsQuery.RATING_VOTES)));
    // user rating
    mTextUserRating.setText(TraktTools.buildUserRatingString(getActivity(), cursor.getInt(DetailsQuery.RATING_USER)));
    loadTraktRatings();
    // episode image
    final String imagePath = cursor.getString(DetailsQuery.IMAGE);
    mImageContainer.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), FullscreenImageActivity.class);
            intent.putExtra(FullscreenImageActivity.EXTRA_IMAGE, TvdbImageTools.fullSizeUrl(imagePath));
            Utils.startActivityWithAnimation(getActivity(), intent, v);
        }
    });
    loadImage(imagePath, hideDetails);
    // check in button
    final int episodeTvdbId = cursor.getInt(DetailsQuery._ID);
    buttonCheckin.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // display a check-in dialog
            CheckInDialogFragment f = CheckInDialogFragment.newInstance(getActivity(), episodeTvdbId);
            if (f != null && isResumed()) {
                f.show(getFragmentManager(), "checkin-dialog");
                Utils.trackAction(getActivity(), TAG, "Check-In");
            }
        }
    });
    CheatSheet.setup(buttonCheckin);
    // hide check-in if not connected to trakt or hexagon is enabled
    boolean isConnectedToTrakt = TraktCredentials.get(getActivity()).hasCredentials();
    boolean displayCheckIn = isConnectedToTrakt && !HexagonSettings.isEnabled(getActivity());
    buttonCheckin.setVisibility(displayCheckIn ? View.VISIBLE : View.GONE);
    dividerEpisodeButtons.setVisibility(displayCheckIn ? View.VISIBLE : View.GONE);
    // watched button
    boolean isWatched = EpisodeTools.isWatched(mEpisodeFlag);
    Utils.setCompoundDrawablesRelativeWithIntrinsicBounds(buttonWatch, 0, isWatched ? Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableWatched) : Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableWatch), 0, 0);
    buttonWatch.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            onToggleWatched();
            Utils.trackAction(getActivity(), TAG, "Toggle watched");
        }
    });
    buttonWatch.setText(isWatched ? R.string.action_unwatched : R.string.action_watched);
    CheatSheet.setup(buttonWatch, isWatched ? R.string.action_unwatched : R.string.action_watched);
    // collected button
    mCollected = cursor.getInt(DetailsQuery.COLLECTED) == 1;
    Utils.setCompoundDrawablesRelativeWithIntrinsicBounds(buttonCollect, 0, mCollected ? R.drawable.ic_collected : Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableCollect), 0, 0);
    buttonCollect.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            onToggleCollected();
            Utils.trackAction(getActivity(), TAG, "Toggle collected");
        }
    });
    buttonCollect.setText(mCollected ? R.string.action_collection_remove : R.string.action_collection_add);
    CheatSheet.setup(buttonCollect, mCollected ? R.string.action_collection_remove : R.string.action_collection_add);
    // skip button
    boolean isSkipped = EpisodeTools.isSkipped(mEpisodeFlag);
    if (isWatched) {
        // if watched do not allow skipping
        buttonSkip.setVisibility(View.INVISIBLE);
    } else {
        buttonSkip.setVisibility(View.VISIBLE);
        Utils.setCompoundDrawablesRelativeWithIntrinsicBounds(buttonSkip, 0, isSkipped ? R.drawable.ic_skipped : Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableSkip), 0, 0);
        buttonSkip.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                onToggleSkipped();
                Utils.trackAction(getActivity(), TAG, "Toggle skipped");
            }
        });
        buttonSkip.setText(isSkipped ? R.string.action_dont_skip : R.string.action_skip);
        CheatSheet.setup(buttonSkip, isSkipped ? R.string.action_dont_skip : R.string.action_skip);
    }
    // service buttons
    ServiceUtils.setUpTraktEpisodeButton(mTraktButton, getEpisodeTvdbId(), TAG);
    // IMDb
    String imdbId = cursor.getString(DetailsQuery.IMDBID);
    if (TextUtils.isEmpty(imdbId)) {
        // fall back to show IMDb id
        imdbId = cursor.getString(DetailsQuery.SHOW_IMDBID);
    }
    ServiceUtils.setUpImdbButton(imdbId, mImdbButton, TAG);
    // TVDb
    final int seasonTvdbId = cursor.getInt(DetailsQuery.SEASON_ID);
    ServiceUtils.setUpTvdbButton(mShowTvdbId, seasonTvdbId, getEpisodeTvdbId(), mTvdbButton, TAG);
    // trakt comments
    mCommentsButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), TraktCommentsActivity.class);
            intent.putExtras(TraktCommentsActivity.createInitBundleEpisode(mEpisodeTitle, getEpisodeTvdbId()));
            Utils.startActivityWithAnimation(getActivity(), intent, v);
            Utils.trackAction(v.getContext(), TAG, "Comments");
        }
    });
    mEpisodeContainer.setVisibility(View.VISIBLE);
}
Also used : TextAppearanceSpan(android.text.style.TextAppearanceSpan) Intent(android.content.Intent) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) Date(java.util.Date) OnClickListener(android.view.View.OnClickListener) SpannableStringBuilder(android.text.SpannableStringBuilder) CheckInDialogFragment(com.battlelancer.seriesguide.ui.dialogs.CheckInDialogFragment)

Aggregations

SpannableStringBuilder (android.text.SpannableStringBuilder)705 TextView (android.widget.TextView)114 ForegroundColorSpan (android.text.style.ForegroundColorSpan)112 View (android.view.View)100 StyleSpan (android.text.style.StyleSpan)85 ImageSpan (android.text.style.ImageSpan)77 Test (org.junit.Test)65 SpannableString (android.text.SpannableString)55 Drawable (android.graphics.drawable.Drawable)44 TextPaint (android.text.TextPaint)43 Intent (android.content.Intent)42 Spanned (android.text.Spanned)38 RelativeSizeSpan (android.text.style.RelativeSizeSpan)38 Paint (android.graphics.Paint)34 Spannable (android.text.Spannable)33 ImageView (android.widget.ImageView)31 ArrayList (java.util.ArrayList)28 Typeface (android.graphics.Typeface)26 Context (android.content.Context)25 SuppressLint (android.annotation.SuppressLint)24