Search in sources :

Example 11 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project actor-platform by actorapp.

the class BaseAuthFragment method setTosAndPrivacy.

protected void setTosAndPrivacy(TextView tv) {
    ActorSDK actorSDK = ActorSDK.sharedActor();
    String tosUrl = actorSDK.getTosUrl();
    String tosText = actorSDK.getTosText();
    boolean tosUrlAvailable = tosUrl != null && !tosUrl.isEmpty();
    boolean tosTextAvailable = tosText != null && !tosText.isEmpty();
    boolean tosAvailable = tosUrlAvailable || tosTextAvailable;
    String privacyUrl = actorSDK.getPrivacyUrl();
    String privacyText = actorSDK.getPrivacyText();
    boolean privacyUrlAvailable = privacyUrl != null && !privacyUrl.isEmpty();
    boolean privacyTextAvailable = privacyText != null && !privacyText.isEmpty();
    boolean ppAvailable = privacyUrlAvailable || privacyTextAvailable;
    boolean tosOrPrivacyAvailable = tosAvailable || ppAvailable;
    if (!tosOrPrivacyAvailable) {
        tv.setVisibility(View.GONE);
        return;
    }
    String text;
    SpannableStringBuilder builder;
    if (tosAvailable && ppAvailable) {
        text = getString(R.string.auth_tos_privacy);
        builder = new SpannableStringBuilder(text);
        findAndHilightTos(builder, text, tosUrlAvailable);
        findAndHilightPrivacy(builder, text, privacyUrlAvailable);
    } else if (tosAvailable) {
        text = getString(R.string.auth_tos);
        builder = new SpannableStringBuilder(text);
        findAndHilightTos(builder, text, tosUrlAvailable);
    } else {
        text = getString(R.string.auth_privacy);
        builder = new SpannableStringBuilder(text);
        tv.setText(getString(R.string.auth_privacy));
        findAndHilightPrivacy(builder, text, privacyUrlAvailable);
    }
    builder.append(" ".concat(getString(R.string.auth_find_by_diclamer)));
    tv.setText(builder);
    tv.setMovementMethod(LinkMovementMethod.getInstance());
}
Also used : ActorSDK(im.actor.sdk.ActorSDK) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 12 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project actor-platform by actorapp.

the class ActorBinder method bind.

public void bind(final TextView textView, final View titleContainer, final GroupVM value) {
    bind(value.getPresence(), value.getMembersCount(), value.isMember(), (online, onlineModel, membersCount, membersModel, isMember, isMemberModel) -> {
        if (isMember) {
            titleContainer.setVisibility(View.VISIBLE);
            if (online <= 0) {
                SpannableStringBuilder builder = new SpannableStringBuilder(messenger().getFormatter().formatGroupMembers(membersCount));
                builder.setSpan(new ForegroundColorSpan(0xB7ffffff), 0, builder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
                textView.setText(builder);
            } else {
                SpannableStringBuilder builder = new SpannableStringBuilder(messenger().getFormatter().formatGroupMembers(membersCount) + ", ");
                builder.setSpan(new ForegroundColorSpan(0xB7ffffff), 0, builder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
                builder.append(messenger().getFormatter().formatGroupOnline(online));
                textView.setText(builder);
            }
        } else {
            titleContainer.setVisibility(View.GONE);
        }
    });
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 13 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project actor-platform by actorapp.

the class MessageHolder method setTimeAndReactions.

protected void setTimeAndReactions(TextView time) {
    Spannable timeWithReactions = null;
    if (reactions != null) {
        SpannableStringBuilder builder = new SpannableStringBuilder(reactions);
        timeWithReactions = builder.append(DateFormatting.formatTime(currentMessage.getDate()));
    }
    time.setText(timeWithReactions != null ? timeWithReactions : DateFormatting.formatTime(currentMessage.getDate()));
    time.setMovementMethod(LinkMovementMethod.getInstance());
}
Also used : Spannable(android.text.Spannable) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 14 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project actor-platform by actorapp.

the class AndroidNotifications method getNotificationTextFull.

private CharSequence getNotificationTextFull(Notification notification, Messenger messenger) {
    SpannableStringBuilder res = new SpannableStringBuilder();
    if (!messenger.getFormatter().isLargeDialogMessage(notification.getContentDescription().getContentType())) {
        res.append(getNotificationSender(notification));
        res.append(": ");
        res.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, res.length(), 0);
    }
    res.append(messenger.getFormatter().formatNotificationText(notification));
    return res;
}
Also used : StyleSpan(android.text.style.StyleSpan) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 15 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project actor-platform by actorapp.

the class AndroidMarkdown method processText.

private static Spannable processText(String markdown, int mode) {
    MDDocument doc = new MarkdownParser(mode).processDocument(markdown);
    SpannableStringBuilder builder = new SpannableStringBuilder();
    boolean isFirst = true;
    for (MDSection s : doc.getSections()) {
        if (isFirst) {
            isFirst = false;
        } else {
            builder.append("\n");
        }
        if (s.getType() == MDSection.TYPE_CODE) {
            int start = builder.length();
            builder.append("View Source Code");
            final String text = s.getCode().getCode();
            builder.setSpan(new RelativeSizeSpan(1.1f), start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            builder.setSpan(new ForegroundColorSpan(Color.RED), start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            builder.setSpan(new ClickableSpan() {

                @Override
                public void onClick(View view) {
                    AndroidContext.getContext().startActivity(new Intent(AndroidContext.getContext(), CodePreviewActivity.class).putExtra("source_code", text).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
                }
            }, start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        } else if (s.getType() == MDSection.TYPE_TEXT) {
            writeText(s.getText(), builder);
        } else {
            throw new RuntimeException("Unknown section type: " + s.getType());
        }
    }
    return builder;
}
Also used : MDSection(im.actor.runtime.markdown.MDSection) ForegroundColorSpan(android.text.style.ForegroundColorSpan) MDDocument(im.actor.runtime.markdown.MDDocument) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) RelativeSizeSpan(android.text.style.RelativeSizeSpan) ClickableSpan(android.text.style.ClickableSpan) View(android.view.View) MarkdownParser(im.actor.runtime.markdown.MarkdownParser) SpannableStringBuilder(android.text.SpannableStringBuilder)

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