Example usage for android.text.style StyleSpan StyleSpan

List of usage examples for android.text.style StyleSpan StyleSpan

Introduction

In this page you can find the example usage for android.text.style StyleSpan StyleSpan.

Prototype

public StyleSpan(@NonNull Parcel src) 

Source Link

Document

Creates a StyleSpan from a parcel.

Usage

From source file:com.securecomcode.text.notifications.MessageNotifier.java

private static NotificationState constructNotificationState(Context context, MasterSecret masterSecret,
        Cursor cursor) {/*from w ww.  j a v  a  2s .c o  m*/
    NotificationState notificationState = new NotificationState();
    MessageRecord record;
    MmsSmsDatabase.Reader reader;

    if (masterSecret == null)
        reader = DatabaseFactory.getMmsSmsDatabase(context).readerFor(cursor);
    else
        reader = DatabaseFactory.getMmsSmsDatabase(context).readerFor(cursor, masterSecret);

    while ((record = reader.getNext()) != null) {
        Recipient recipient = record.getIndividualRecipient();
        Recipients recipients = record.getRecipients();
        long threadId = record.getThreadId();
        SpannableString body = record.getDisplayBody();
        Uri image = null;
        Recipients threadRecipients = null;

        if (threadId != -1) {
            threadRecipients = DatabaseFactory.getThreadDatabase(context).getRecipientsForThreadId(threadId);
        }

        // XXXX This is so fucked up.  FIX ME!
        if (body.toString().equals(context.getString(R.string.MessageDisplayHelper_decrypting_please_wait))) {
            body = new SpannableString(context.getString(R.string.MessageNotifier_encrypted_message));
            body.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, body.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        notificationState.addNotification(
                new NotificationItem(recipient, recipients, threadRecipients, threadId, body, image));
    }

    reader.close();
    return notificationState;
}

From source file:im.vector.notifications.NotificationUtils.java

/**
 * Add a text style to a notification when there are several notified rooms.
 *
 * @param context            the context
 * @param builder            the notification builder
 * @param roomsNotifications the rooms notifications
 *//*from   w ww. ja  v a  2 s.  c o m*/
private static void addTextStyleWithSeveralRooms(Context context, NotificationCompat.Builder builder,
        RoomsNotifications roomsNotifications) {
    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();

    for (RoomNotifications roomNotifications : roomsNotifications.mRoomNotifications) {
        SpannableString notifiedLine = new SpannableString(roomNotifications.mMessagesSummary);
        notifiedLine.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0,
                roomNotifications.mMessageHeader.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        inboxStyle.addLine(notifiedLine);
    }

    inboxStyle.setBigContentTitle(context.getString(R.string.riot_app_name));
    inboxStyle.setSummaryText(roomsNotifications.mSummaryText);
    builder.setStyle(inboxStyle);

    TaskStackBuilder stackBuilderTap = TaskStackBuilder.create(context);
    Intent roomIntentTap;

    // add the home page the activity stack
    stackBuilderTap.addNextIntentWithParentStack(new Intent(context, VectorHomeActivity.class));

    if (roomsNotifications.mIsInvitationEvent) {
        // for invitation the room preview must be displayed
        roomIntentTap = CommonActivityUtils.buildIntentPreviewRoom(roomsNotifications.mSessionId,
                roomsNotifications.mRoomId, context, VectorFakeRoomPreviewActivity.class);
    } else {
        roomIntentTap = new Intent(context, VectorRoomActivity.class);
        roomIntentTap.putExtra(VectorRoomActivity.EXTRA_ROOM_ID, roomsNotifications.mRoomId);
    }

    // the action must be unique else the parameters are ignored
    roomIntentTap.setAction(TAP_TO_VIEW_ACTION + ((int) (System.currentTimeMillis())));
    stackBuilderTap.addNextIntent(roomIntentTap);
    builder.setContentIntent(stackBuilderTap.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT));

    // offer to open the rooms list
    {
        Intent openIntentTap = new Intent(context, VectorHomeActivity.class);

        // Recreate the back stack
        TaskStackBuilder viewAllTask = TaskStackBuilder.create(context).addNextIntent(openIntentTap);

        builder.addAction(R.drawable.ic_home_black_24dp, context.getString(R.string.bottom_action_home),
                viewAllTask.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT));
    }
}

From source file:org.mariotaku.twidere.view.holder.ActivityTitleSummaryViewHolder.java

public void displayActivity(ParcelableActivity activity, boolean byFriends) {
    final Context context = adapter.getContext();
    final Resources resources = adapter.getContext().getResources();
    switch (activity.action) {
    case Activity.ACTION_FOLLOW: {
        activityTypeView.setImageResource(R.drawable.ic_activity_action_follow);
        activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_follow),
                Mode.SRC_ATOP);/*w  w  w  . j  a v a 2 s .  co  m*/
        if (byFriends) {
            titleView.setText(getTitleStringByFriends(R.string.activity_by_friends_follow,
                    R.string.activity_by_friends_follow_multi, activity.sources, activity.target_users));
        } else {
            titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_follow,
                    R.string.activity_about_me_follow_multi, activity.sources));
        }
        displayUserProfileImages(activity.sources);
        summaryView.setVisibility(View.GONE);
        break;
    }
    case Activity.ACTION_FAVORITE: {
        if (adapter.shouldUseStarsForLikes()) {
            activityTypeView.setImageResource(R.drawable.ic_activity_action_favorite);
            activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_favorite),
                    Mode.SRC_ATOP);

            if (byFriends) {
                titleView.setText(getTitleStringByFriends(R.string.activity_by_friends_favorite,
                        R.string.activity_by_friends_favorite_multi, activity.sources,
                        activity.target_statuses));
            } else {
                titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_favorite,
                        R.string.activity_about_me_favorite_multi, activity.sources));
            }
        } else {
            activityTypeView.setImageResource(R.drawable.ic_activity_action_like);
            activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_like),
                    Mode.SRC_ATOP);

            if (byFriends) {
                titleView.setText(getTitleStringByFriends(R.string.activity_by_friends_like,
                        R.string.activity_by_friends_like_multi, activity.sources, activity.target_statuses));
            } else {
                titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_like,
                        R.string.activity_about_me_like_multi, activity.sources));
            }
        }
        displayUserProfileImages(activity.sources);
        summaryView.setText(activity.target_statuses[0].text_unescaped);
        summaryView.setVisibility(View.VISIBLE);
        break;
    }
    case Activity.ACTION_RETWEET: {
        activityTypeView.setImageResource(R.drawable.ic_activity_action_retweet);
        activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_retweet),
                Mode.SRC_ATOP);
        if (byFriends) {
            titleView.setText(getTitleStringByFriends(R.string.activity_by_friends_retweet,
                    R.string.activity_by_friends_retweet_multi, activity.sources, activity.target_statuses));
        } else
            titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_retweet,
                    R.string.activity_about_me_retweet_multi, activity.sources));
        displayUserProfileImages(activity.sources);
        summaryView.setText(activity.target_statuses[0].text_unescaped);
        summaryView.setVisibility(View.VISIBLE);
        break;
    }
    case Activity.ACTION_FAVORITED_RETWEET: {
        if (byFriends) {
            showNotSupported();
            return;
        }
        if (adapter.shouldUseStarsForLikes()) {
            activityTypeView.setImageResource(R.drawable.ic_activity_action_favorite);
            activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_favorite),
                    Mode.SRC_ATOP);
            titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_favorited_retweet,
                    R.string.activity_about_me_favorited_retweet_multi, activity.sources));
        } else {
            activityTypeView.setImageResource(R.drawable.ic_activity_action_like);
            activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_like),
                    Mode.SRC_ATOP);
            titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_liked_retweet,
                    R.string.activity_about_me_liked_retweet_multi, activity.sources));
        }
        displayUserProfileImages(activity.sources);
        summaryView.setText(activity.target_statuses[0].text_unescaped);
        summaryView.setVisibility(View.VISIBLE);
        break;
    }
    case Activity.ACTION_RETWEETED_RETWEET: {
        if (byFriends) {
            showNotSupported();
            return;
        }
        activityTypeView.setImageResource(R.drawable.ic_activity_action_retweet);
        activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_retweet),
                Mode.SRC_ATOP);
        titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_retweeted_retweet,
                R.string.activity_about_me_retweeted_retweet_multi, activity.sources));
        displayUserProfileImages(activity.sources);
        summaryView.setText(activity.target_statuses[0].text_unescaped);
        summaryView.setVisibility(View.VISIBLE);
        break;
    }
    case Activity.ACTION_RETWEETED_MENTION: {
        if (byFriends) {
            showNotSupported();
            return;
        }
        activityTypeView.setImageResource(R.drawable.ic_activity_action_retweet);
        activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_retweet),
                Mode.SRC_ATOP);
        titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_retweeted_mention,
                R.string.activity_about_me_retweeted_mention_multi, activity.sources));
        displayUserProfileImages(activity.sources);
        summaryView.setText(activity.target_statuses[0].text_unescaped);
        summaryView.setVisibility(View.VISIBLE);
        break;
    }
    case Activity.ACTION_FAVORITED_MENTION: {
        if (byFriends) {
            showNotSupported();
            return;
        }
        if (adapter.shouldUseStarsForLikes()) {
            activityTypeView.setImageResource(R.drawable.ic_activity_action_favorite);
            activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_favorite),
                    Mode.SRC_ATOP);
            titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_favorited_mention,
                    R.string.activity_about_me_favorited_mention_multi, activity.sources));
        } else {
            activityTypeView.setImageResource(R.drawable.ic_activity_action_like);
            activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_like),
                    Mode.SRC_ATOP);
            titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_liked_mention,
                    R.string.activity_about_me_liked_mention_multi, activity.sources));
        }
        displayUserProfileImages(activity.sources);
        summaryView.setText(activity.target_statuses[0].text_unescaped);
        summaryView.setVisibility(View.VISIBLE);
        break;
    }
    case Activity.ACTION_LIST_CREATED: {
        if (!byFriends) {
            showNotSupported();
            return;
        }
        activityTypeView.setImageResource(R.drawable.ic_activity_action_list_added);
        activityTypeView.setColorFilter(activityTypeView.getDefaultColor(), Mode.SRC_ATOP);
        titleView.setText(getTitleStringByFriends(R.string.activity_by_friends_list_created,
                R.string.activity_by_friends_list_created_multi, activity.sources,
                activity.target_object_user_lists));
        displayUserProfileImages(activity.sources);
        boolean firstLine = true;
        summaryView.setText("");
        for (ParcelableUserList item : activity.target_object_user_lists) {
            if (!firstLine) {
                summaryView.append("\n");
            }
            summaryView.append(item.description);
            firstLine = false;
        }
        summaryView.setVisibility(View.VISIBLE);
        break;
    }
    case Activity.ACTION_LIST_MEMBER_ADDED: {
        if (byFriends) {
            showNotSupported();
            return;
        }
        activityTypeView.setImageResource(R.drawable.ic_activity_action_list_added);
        activityTypeView.setColorFilter(activityTypeView.getDefaultColor(), Mode.SRC_ATOP);
        if (activity.sources.length == 1 && activity.target_object_user_lists != null
                && activity.target_object_user_lists.length == 1) {
            final UserColorNameManager manager = adapter.getUserColorNameManager();
            final SpannableString firstDisplayName = new SpannableString(
                    manager.getDisplayName(activity.sources[0], adapter.isNameFirst(), false));
            final SpannableString listName = new SpannableString(activity.target_object_user_lists[0].name);
            firstDisplayName.setSpan(new StyleSpan(Typeface.BOLD), 0, firstDisplayName.length(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            listName.setSpan(new StyleSpan(Typeface.BOLD), 0, listName.length(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            final String format = context.getString(R.string.activity_about_me_list_member_added_with_name);
            final Configuration configuration = resources.getConfiguration();
            titleView.setText(SpanFormatter.format(configuration.locale, format, firstDisplayName, listName));
        } else {
            titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_list_member_added,
                    R.string.activity_about_me_list_member_added_multi, activity.sources));
        }
        displayUserProfileImages(activity.sources);
        summaryView.setVisibility(View.GONE);
        break;
    }
    }
}

From source file:us.phyxsi.gameshelf.ui.HomeActivity.java

private void setNoResultsEmptyTextVisibility(int visibility) {
    if (visibility == View.VISIBLE) {
        if (noResultsEmptyText == null) {
            // create the no results empty text
            ViewStub stub = (ViewStub) findViewById(R.id.stub_no_results);
            noResultsEmptyText = (TextView) stub.inflate();
            String emptyText = getString(R.string.no_results_found);
            int addPlaceholderStart = emptyText.indexOf('\u08B4');
            int altMethodStart = addPlaceholderStart + 3;
            SpannableStringBuilder ssb = new SpannableStringBuilder(emptyText);
            // show an image of the add icon
            ssb.setSpan(new ImageSpan(this, R.drawable.ic_add_small, ImageSpan.ALIGN_BASELINE),
                    addPlaceholderStart, addPlaceholderStart + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            // make the alt method (swipe from right) less prominent and italic
            ssb.setSpan(new ForegroundColorSpan(ContextCompat.getColor(this, R.color.text_secondary_light)),
                    altMethodStart, emptyText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            ssb.setSpan(new StyleSpan(Typeface.ITALIC), altMethodStart, emptyText.length(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            noResultsEmptyText.setText(ssb);
        }//  ww  w. j  a  va2  s  .  co m

        noResultsEmptyText.setVisibility(visibility);
    } else if (noResultsEmptyText != null) {
        noResultsEmptyText.setVisibility(visibility);
    }
}

From source file:org.kontalk.util.SystemUtils.java

public static CharacterStyle getTypefaceSpan(int typeface) {
    return new StyleSpan(typeface);
}

From source file:au.org.ala.fielddata.mobile.CollectSurveyData.java

public void onSpeciesSelected(Species selectedSpecies) {

    surveyViewModel.speciesSelected(selectedSpecies);
    pager.setCurrentItem(1);/*from ww  w .  j  av a  2  s. c  om*/
    SpannableString title = new SpannableString(selectedSpecies.scientificName);
    title.setSpan(new StyleSpan(Typeface.ITALIC), 0, title.length(), 0);
    getSupportActionBar().setTitle(title);
    getSupportActionBar().setSubtitle(selectedSpecies.commonName);

}

From source file:systems.soapbox.ombuds.client.ui.WalletTransactionsFragment.java

@Override
public void onLoadFinished(final Loader<List<Transaction>> loader, final List<Transaction> transactions) {
    final Direction direction = ((TransactionsLoader) loader).getDirection();

    adapter.replace(transactions);/*  ww  w . j  a v a  2s .  co m*/

    if (transactions.isEmpty()) {
        viewGroup.setDisplayedChild(1);

        final SpannableStringBuilder emptyText = new SpannableStringBuilder("You have no Bitcoin.");
        emptyText.setSpan(new StyleSpan(Typeface.BOLD), 0, emptyText.length(),
                SpannableStringBuilder.SPAN_POINT_MARK);
        emptyText.append("\n\n").append(getString(R.string.profile_email_for_bitcoin));
        emptyView.setText(emptyText);
    } else {
        viewGroup.setDisplayedChild(2);
    }
}

From source file:com.stasbar.knowyourself.Utils.java

/**
 * @param amPmRatio a value between 0 and 1 that is the ratio of the relative size of the
 *                  am/pm string to the time string
 * @return format string for 12 hours mode time
 *//*w  w  w  .  j  a va  2  s.  c o m*/
public static CharSequence get12ModeFormat(float amPmRatio) {
    String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), "hma");
    if (amPmRatio <= 0) {
        pattern = pattern.replaceAll("a", "").trim();
    }

    // Replace spaces with "Hair Space"
    pattern = pattern.replaceAll(" ", "\u200A");
    // Build a spannable so that the am/pm will be formatted
    int amPmPos = pattern.indexOf('a');
    if (amPmPos == -1) {
        return pattern;
    }

    final Spannable sp = new SpannableString(pattern);
    sp.setSpan(new RelativeSizeSpan(amPmRatio), amPmPos, amPmPos + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    sp.setSpan(new StyleSpan(Typeface.NORMAL), amPmPos, amPmPos + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    sp.setSpan(new TypefaceSpan("sans-serif"), amPmPos, amPmPos + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    return sp;
}

From source file:com.limewoodmedia.nsdroid.activities.Region.java

private void doSetup() {
    // Region name
    setTitle(data.name);//from w  ww.  j a  va  2  s  . c om
    regionName.setText(data.name);
    // Flag
    if (data.flagURL != null) {
        imageLoader.displayImage(data.flagURL, flag, options);
    } else {
        flag.setVisibility(View.GONE);
    }
    // WA Delegate
    StyleSpan bold = new StyleSpan(android.graphics.Typeface.BOLD);
    String wadTitle = getResources().getString(R.string.wad);
    String wad = TagParser.idToName(data.delegate);
    if (!wad.equals("0")) {
        wad = wadTitle + ": <a href=\"com.limewoodMedia.nsdroid.nation://" + wad + "\">" + wad + "</a>";
        delegate.setText(Html.fromHtml(wad), TextView.BufferType.SPANNABLE);
    } else {
        delegate.setText(wadTitle + " " + getResources().getString(R.string.no_wad));
    }
    ((Spannable) delegate.getText()).setSpan(bold, 0, wadTitle.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    // Founder
    String found = TagParser.idToName(data.founder);
    if (!found.equals("0")) {
        String fTitle = getResources().getString(R.string.founder);
        found = fTitle + ": <a href=\"com.limewoodMedia.nsdroid.nation://" + found + "\">" + found + "</a>";
        founder.setText(Html.fromHtml(found), TextView.BufferType.SPANNABLE);
        ((Spannable) founder.getText()).setSpan(bold, 0, fTitle.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        founder.setVisibility(View.VISIBLE);
    } else {
        founder.setVisibility(View.GONE);
    }
    text.setText(TagParser.parseTagsFromHtml(data.factbook));
    layout.setVisibility(View.VISIBLE);

    doRMBSetup();

    doOfficersSetup();

    doEmbassiesSetup();
}

From source file:com.androidinspain.deskclock.Utils.java

/**
 * @param amPmRatio      a value between 0 and 1 that is the ratio of the relative size of the
 *                       am/pm string to the time string
 * @param includeSeconds whether or not to include seconds in the time string
 * @return format string for 12 hours mode time, not including seconds
 *///from w  ww  .  ja v a2  s . c  o m
public static CharSequence get12ModeFormat(float amPmRatio, boolean includeSeconds) {
    String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), includeSeconds ? "hmsa" : "hma");
    if (amPmRatio <= 0) {
        pattern = pattern.replaceAll("a", "").trim();
    }

    // Replace spaces with "Hair Space"
    pattern = pattern.replaceAll(" ", "\u200A");
    // Build a spannable so that the am/pm will be formatted
    int amPmPos = pattern.indexOf('a');
    if (amPmPos == -1) {
        return pattern;
    }

    final Spannable sp = new SpannableString(pattern);
    sp.setSpan(new RelativeSizeSpan(amPmRatio), amPmPos, amPmPos + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    sp.setSpan(new StyleSpan(Typeface.NORMAL), amPmPos, amPmPos + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    sp.setSpan(new TypefaceSpan("sans-serif"), amPmPos, amPmPos + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    return sp;
}