Example usage for android.text SpannableString setSpan

List of usage examples for android.text SpannableString setSpan

Introduction

In this page you can find the example usage for android.text SpannableString setSpan.

Prototype

public void setSpan(Object what, int start, int end, int flags) 

Source Link

Usage

From source file:org.awesomeapp.messenger.ui.ContactListItem.java

public void bind(Cursor cursor, String underLineText, boolean showChatMsg, boolean scrolling) {

    ViewHolder holder = (ViewHolder) getTag();

    if (holder == null) {
        holder = new ViewHolder();
        holder.mLine1 = (TextView) findViewById(R.id.line1);
        holder.mLine2 = (TextView) findViewById(R.id.line2);

        holder.mAvatar = (ImageView) findViewById(R.id.avatar);
        holder.mStatusIcon = (ImageView) findViewById(R.id.statusIcon);
        holder.mStatusText = (TextView) findViewById(R.id.statusText);
        //holder.mEncryptionIcon = (ImageView)view.findViewById(R.id.encryptionIcon);

        holder.mContainer = findViewById(R.id.message_container);

        // holder.mMediaThumb = (ImageView)findViewById(R.id.media_thumbnail);
        setTag(holder);//from  ww  w .  j  a  va 2 s  .c  om
    }

    final long providerId = cursor.getLong(COLUMN_CONTACT_PROVIDER);
    final String address = cursor.getString(COLUMN_CONTACT_USERNAME);

    final String displayName = cursor.getString(COLUMN_CONTACT_NICKNAME);

    final int type = cursor.getInt(COLUMN_CONTACT_TYPE);
    final String lastMsg = cursor.getString(COLUMN_LAST_MESSAGE);

    long lastMsgDate = cursor.getLong(COLUMN_LAST_MESSAGE_DATE);
    final int presence = cursor.getInt(COLUMN_CONTACT_PRESENCE_STATUS);

    final int subType = cursor.getInt(COLUMN_SUBSCRIPTION_TYPE);
    final int subStatus = cursor.getInt(COLUMN_SUBSCRIPTION_STATUS);

    String statusText = cursor.getString(COLUMN_CONTACT_CUSTOM_STATUS);

    String nickname = displayName;

    if (nickname == null) {
        nickname = address.split("@")[0];
    } else if (nickname.indexOf('@') != -1) {
        nickname = nickname.split("@")[0];
    }

    if (!TextUtils.isEmpty(underLineText)) {
        // highlight/underline the word being searched 
        String lowercase = nickname.toLowerCase();
        int start = lowercase.indexOf(underLineText.toLowerCase());
        if (start >= 0) {
            int end = start + underLineText.length();
            SpannableString str = new SpannableString(nickname);
            str.setSpan(new UnderlineSpan(), start, end, Spannable.SPAN_INCLUSIVE_INCLUSIVE);

            holder.mLine1.setText(str);

        } else
            holder.mLine1.setText(nickname);

    } else
        holder.mLine1.setText(nickname);

    /*
    if (holder.mStatusIcon != null)
    {
    Drawable statusIcon = brandingRes.getDrawable(PresenceUtils.getStatusIconId(presence));
    //statusIcon.setBounds(0, 0, statusIcon.getIntrinsicWidth(),
      //      statusIcon.getIntrinsicHeight());
    holder.mStatusIcon.setImageDrawable(statusIcon);address
    }*/

    holder.mStatusIcon.setVisibility(View.GONE);

    if (holder.mAvatar != null) {
        if (Imps.Contacts.TYPE_GROUP == type) {

            holder.mAvatar.setVisibility(View.VISIBLE);

            if (AVATAR_DEFAULT_GROUP == null)
                AVATAR_DEFAULT_GROUP = new RoundedAvatarDrawable(
                        BitmapFactory.decodeResource(getResources(), R.drawable.group_chat));

            holder.mAvatar.setImageDrawable(AVATAR_DEFAULT_GROUP);

        } else if (cursor.getColumnIndex(Imps.Contacts.AVATAR_DATA) != -1) {

            RoundedAvatarDrawable avatar = null;

            try {
                avatar = DatabaseUtils.getAvatarFromCursor(cursor, COLUMN_AVATAR_DATA, ImApp.SMALL_AVATAR_WIDTH,
                        ImApp.SMALL_AVATAR_HEIGHT);
            } catch (Exception e) {
                //problem decoding avatar
                Log.e(ImApp.LOG_TAG, "error decoding avatar", e);
            }

            try {
                if (avatar != null) {
                    setAvatarBorder(presence, avatar);
                    holder.mAvatar.setImageDrawable(avatar);
                } else {
                    String letterString = null;

                    if (nickname.length() > 0)
                        letterString = nickname.substring(0, 1).toUpperCase();
                    else
                        letterString = "?"; //the unknown name!

                    int color = getAvatarBorder(presence);
                    int padding = 24;
                    LetterAvatar lavatar = new LetterAvatar(getContext(), color, letterString, padding);

                    holder.mAvatar.setImageDrawable(lavatar);

                }

                holder.mAvatar.setVisibility(View.VISIBLE);
            } catch (OutOfMemoryError ome) {
                //this seems to happen now and then even on tiny images; let's catch it and just not set an avatar
            }

        } else {
            //holder.mAvatar.setImageDrawable(getContext().getResources().getDrawable(R.drawable.avatar_unknown));
            holder.mAvatar.setVisibility(View.GONE);

        }
    }

    holder.mStatusText.setText("");

    statusText = address;
    holder.mLine2.setText(statusText);

    if (subType == Imps.ContactsColumns.SUBSCRIPTION_TYPE_INVITATIONS) {
        //    if (holder.mLine2 != null)
        //      holder.mLine2.setText("Contact List Request");
    }

    holder.mLine1.setVisibility(View.VISIBLE);

}

From source file:edu.berkeley.boinc.ProjectDetailsFragment.java

private void populateLayout() {

    if (project == null) {
        retryLayout = true;//from ww w .jav a2s  . c  o m
        return; // if data not available yet, return. frequently retrys with onReceive
    }

    retryLayout = false;
    View v = root;

    updateChangingItems(v);

    slideshowWrapper = (HorizontalScrollView) v.findViewById(R.id.slideshow_wrapper);
    slideshowHook = (LinearLayout) v.findViewById(R.id.slideshow_hook);
    slideshowLoading = (ProgressBar) v.findViewById(R.id.slideshow_loading);

    // set website
    TextView website = (TextView) v.findViewById(R.id.project_url);
    SpannableString content = new SpannableString(project.master_url);
    content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
    website.setText(content);
    website.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(project.master_url));
            startActivity(i);
        }
    });

    // set general area
    if (projectInfo != null && projectInfo.generalArea != null) {
        TextView generalArea = (TextView) v.findViewById(R.id.general_area);
        generalArea.setText(projectInfo.generalArea);
    } else {
        LinearLayout wrapper = (LinearLayout) v.findViewById(R.id.general_area_wrapper);
        wrapper.setVisibility(View.GONE);
    }

    // set specific area
    if (projectInfo != null && projectInfo.specificArea != null) {
        TextView specificArea = (TextView) v.findViewById(R.id.specific_area);
        specificArea.setText(projectInfo.specificArea);
    } else {
        LinearLayout wrapper = (LinearLayout) v.findViewById(R.id.specific_area_wrapper);
        wrapper.setVisibility(View.GONE);
    }

    // set description
    if (projectInfo != null && projectInfo.description != null) {
        TextView description = (TextView) v.findViewById(R.id.description);
        description.setText(projectInfo.description);
    } else {
        LinearLayout wrapper = (LinearLayout) v.findViewById(R.id.description_wrapper);
        wrapper.setVisibility(View.GONE);
    }

    // set home
    if (projectInfo != null && projectInfo.home != null) {
        TextView home = (TextView) v.findViewById(R.id.based_at);
        home.setText(projectInfo.home);
    } else {
        LinearLayout wrapper = (LinearLayout) v.findViewById(R.id.based_at_wrapper);
        wrapper.setVisibility(View.GONE);
    }

    // load slideshow
    new UpdateSlideshowImagesAsync().execute();
}

From source file:it.gulch.linuxday.android.adapters.EventsAdapter.java

private void bindView(ViewHolder viewHolder, Event event) {
    viewHolder.event = event;/*  ww  w.ja  v a  2 s .  c  om*/

    String eventTitle = event.getTitle();
    SpannableString spannableString;
    if (CollectionUtils.isEmpty(event.getPeople())) {
        spannableString = new SpannableString(eventTitle);
    } else {
        String personsSummary = StringUtils.join(event.getPeople(), ", ");
        spannableString = new SpannableString(String.format("%1$s\n%2$s", eventTitle, personsSummary));
    }

    spannableString.setSpan(viewHolder.titleSizeSpan, 0, eventTitle.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    viewHolder.title.setText(spannableString);
    int bookmarkDrawable = event.isBookmarked() ? R.drawable.ic_small_starred : 0;
    viewHolder.title.setCompoundDrawablesWithIntrinsicBounds(0, 0, bookmarkDrawable, 0);

    viewHolder.trackName.setText(event.getTrack().getTitle());

    Date startTime = event.getStartDate();
    Date endTime = event.getEndDate();

    String startTimeString = (startTime != null) ? TIME_DATE_FORMAT.format(startTime) : "?";
    String endTimeString = (endTime != null) ? TIME_DATE_FORMAT.format(endTime) : "?";
    String details;

    String roomName = event.getTrack().getRoom().getName();
    if (showDay) {
        details = String.format("%1$s, %2$s  %3$s  |  %4$s", event.getTrack().getDay().getName(),
                startTimeString, endTimeString, roomName);
    } else {
        details = String.format("%1$s  %2$s  |  %3$s", startTimeString, endTimeString, roomName);
    }
    viewHolder.details.setText(details);
}

From source file:org.thoughtcrime.securesms.components.webrtc.WebRtcCallScreen.java

public void setUntrustedIdentity(Recipient personInfo, IdentityKey untrustedIdentity) {
    String name = recipient.toShortString();
    String introduction = String.format(getContext().getString(R.string.WebRtcCallScreen_new_safety_numbers),
            name, name);//from   ww  w.j ava2s  . c  om
    SpannableString spannableString = new SpannableString(introduction + " "
            + getContext().getString(R.string.WebRtcCallScreen_you_may_wish_to_verify_this_contact));

    spannableString.setSpan(new VerifySpan(getContext(), personInfo.getRecipientId(), untrustedIdentity),
            introduction.length() + 1, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    setPersonInfo(personInfo);

    this.incomingCallOverlay.setActiveCall();
    this.status.setText(R.string.WebRtcCallScreen_new_safety_numbers_title);
    this.untrustedIdentityContainer.setVisibility(View.VISIBLE);
    this.untrustedIdentityExplanation.setText(spannableString);
    this.untrustedIdentityExplanation.setMovementMethod(LinkMovementMethod.getInstance());

    this.endCallButton.setVisibility(View.INVISIBLE);
}

From source file:org.thoughtcrime.securesms.PassphrasePromptActivity.java

private void initializeResources() {

    ImageButton okButton = findViewById(R.id.ok_button);
    Toolbar toolbar = findViewById(R.id.toolbar);

    showButton = findViewById(R.id.passphrase_visibility);
    hideButton = findViewById(R.id.passphrase_visibility_off);
    visibilityToggle = findViewById(R.id.button_toggle);
    passphraseText = findViewById(R.id.passphrase_edit);
    passphraseAuthContainer = findViewById(R.id.password_auth_container);
    fingerprintPrompt = findViewById(R.id.fingerprint_auth_container);
    lockScreenButton = findViewById(R.id.lock_screen_auth_container);
    fingerprintManager = FingerprintManagerCompat.from(this);
    fingerprintCancellationSignal = new CancellationSignal();
    fingerprintListener = new FingerprintListener();

    setSupportActionBar(toolbar);//from   w  ww  . j a  va2 s .  com
    getSupportActionBar().setTitle("");

    SpannableString hint = new SpannableString(
            "  " + getString(R.string.PassphrasePromptActivity_enter_passphrase));
    hint.setSpan(new RelativeSizeSpan(0.9f), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    hint.setSpan(new TypefaceSpan("sans-serif"), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);

    passphraseText.setHint(hint);
    okButton.setOnClickListener(new OkButtonClickListener());
    showButton.setOnClickListener(new ShowButtonOnClickListener());
    hideButton.setOnClickListener(new HideButtonOnClickListener());
    passphraseText.setOnEditorActionListener(new PassphraseActionListener());
    passphraseText.setImeActionLabel(getString(R.string.prompt_passphrase_activity__unlock),
            EditorInfo.IME_ACTION_DONE);

    fingerprintPrompt.setImageResource(R.drawable.ic_fingerprint_white_48dp);
    fingerprintPrompt.getBackground().setColorFilter(getResources().getColor(R.color.signal_primary),
            PorterDuff.Mode.SRC_IN);

    lockScreenButton.setOnClickListener(v -> resumeScreenLock());
}

From source file:com.android.messaging.datamodel.MessageNotificationState.java

public static Notification buildConversationPageForWearable(final String conversationId, int participantCount) {
    final Context context = Factory.get().getApplicationContext();

    // Limit the number of messages to show. We just want enough to provide context for the
    // notification. Fetch one more than we need, so we can tell if there are more messages
    // before the one we're showing.
    // TODO: in the query, a multipart message will contain a row for each part.
    // We might need a smarter GROUP_BY. On the other hand, we might want to show each of the
    // parts as separate messages on the wearable.
    final int limit = MAX_MESSAGES_IN_WEARABLE_PAGE + 1;

    final List<CharSequence> messages = Lists.newArrayList();
    boolean hasSeenMessagesBeforeNotification = false;
    Cursor convMessageCursor = null;
    try {/*from  ww  w .  j  ava2  s.  co  m*/
        final DatabaseWrapper db = DataModel.get().getDatabase();

        final String[] queryArgs = { conversationId };
        final String convPageSql = ConversationMessageData.getWearableQuerySql() + " LIMIT " + limit;
        convMessageCursor = db.rawQuery(convPageSql, queryArgs);

        if (convMessageCursor == null || !convMessageCursor.moveToFirst()) {
            return null;
        }
        final ConversationMessageData convMessageData = new ConversationMessageData();

        final HashMap<String, Integer> firstNames = scanFirstNames(conversationId);
        do {
            convMessageData.bind(convMessageCursor);

            final String authorFullName = convMessageData.getSenderFullName();
            final String authorFirstName = convMessageData.getSenderFirstName();
            String text = convMessageData.getText();

            final boolean isSmsPushNotification = convMessageData.getIsMmsNotification();

            // if auto-download was off to show a message to tap to download the message. We
            // might need to get that working again.
            if (isSmsPushNotification && text != null) {
                text = convertHtmlAndStripUrls(text).toString();
            }
            // Skip messages without any content
            if (TextUtils.isEmpty(text) && !convMessageData.hasAttachments()) {
                continue;
            }
            // Track whether there are messages prior to the one(s) shown in the notification.
            if (convMessageData.getIsSeen()) {
                hasSeenMessagesBeforeNotification = true;
            }

            final boolean usedMoreThanOnce = firstNameUsedMoreThanOnce(firstNames, authorFirstName);
            String displayName = usedMoreThanOnce ? authorFullName : authorFirstName;
            if (TextUtils.isEmpty(displayName)) {
                if (convMessageData.getIsIncoming()) {
                    displayName = convMessageData.getSenderDisplayDestination();
                    if (TextUtils.isEmpty(displayName)) {
                        displayName = context.getString(R.string.unknown_sender);
                    }
                } else {
                    displayName = context.getString(R.string.unknown_self_participant);
                }
            }

            Uri attachmentUri = null;
            String attachmentType = null;
            final List<MessagePartData> attachments = convMessageData.getAttachments();
            for (final MessagePartData messagePartData : attachments) {
                // Look for the first attachment that's not the text piece.
                if (!messagePartData.isText()) {
                    attachmentUri = messagePartData.getContentUri();
                    attachmentType = messagePartData.getContentType();
                    break;
                }
            }

            final CharSequence message = BugleNotifications.buildSpaceSeparatedMessage(displayName, text,
                    attachmentUri, attachmentType);
            messages.add(message);

        } while (convMessageCursor.moveToNext());
    } finally {
        if (convMessageCursor != null) {
            convMessageCursor.close();
        }
    }

    // If there is no conversation history prior to what is already visible in the main
    // notification, there's no need to include the conversation log, too.
    final int maxMessagesInNotification = getMaxMessagesInConversationNotification();
    if (!hasSeenMessagesBeforeNotification && messages.size() <= maxMessagesInNotification) {
        return null;
    }

    final SpannableStringBuilder bigText = new SpannableStringBuilder();
    // There is at least 1 message prior to the first one that we're going to show.
    // Indicate this by inserting an ellipsis at the beginning of the conversation log.
    if (convMessageCursor.getCount() == limit) {
        bigText.append(context.getString(R.string.ellipsis) + "\n\n");
        if (messages.size() > MAX_MESSAGES_IN_WEARABLE_PAGE) {
            messages.remove(messages.size() - 1);
        }
    }
    // Messages are sorted in descending timestamp order, so iterate backwards
    // to get them back in ascending order for display purposes.
    for (int i = messages.size() - 1; i >= 0; --i) {
        bigText.append(messages.get(i));
        if (i > 0) {
            bigText.append("\n\n");
        }
    }
    ++participantCount; // Add in myself

    if (participantCount > 2) {
        final SpannableString statusText = new SpannableString(context.getResources()
                .getQuantityString(R.plurals.wearable_participant_count, participantCount, participantCount));
        statusText.setSpan(
                new ForegroundColorSpan(
                        context.getResources().getColor(R.color.wearable_notification_participants_count)),
                0, statusText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        bigText.append("\n\n").append(statusText);
    }

    final NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context);
    final NotificationCompat.Style notifStyle = new NotificationCompat.BigTextStyle(notifBuilder)
            .bigText(bigText);
    notifBuilder.setStyle(notifStyle);

    final WearableExtender wearableExtender = new WearableExtender();
    wearableExtender.setStartScrollBottom(true);
    notifBuilder.extend(wearableExtender);

    return notifBuilder.build();
}

From source file:org.jraf.android.dcn.handheld.app.geofencing.GeofencingService.java

private void showEnteredNotification(AddressInfo addressInfo) {
    Log.d("addressInfo=" + addressInfo);

    String titleShort = getNotificationTitle(addressInfo, false);
    String titleLong = getNotificationTitle(addressInfo, true);
    String textShort = getNotificationText(addressInfo, false);
    String textLong = getNotificationText(addressInfo, true);

    NotificationCompat.Builder mainNotifBuilder = new NotificationCompat.Builder(this);

    // Small icon
    mainNotifBuilder.setSmallIcon(R.drawable.ic_stat_entered);

    // Make a bigger title
    SpannableString titleSpannable = new SpannableString(titleShort);
    Object span = new TextAppearanceSpan(this, R.style.NotificationContentTitleTextAppearance);
    titleSpannable.setSpan(span, 0, titleShort.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    // Title/*from ww  w.  j av  a 2  s. com*/
    mainNotifBuilder.setContentTitle(titleSpannable);

    // Ticker
    mainNotifBuilder.setTicker(titleShort);

    // Text (short)
    mainNotifBuilder.setContentText(textShort);

    // Text (long)
    mainNotifBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(textLong));

    // Misc
    mainNotifBuilder.setPriority(NotificationCompat.PRIORITY_HIGH); // Time sensitive, try to appear on top
    mainNotifBuilder.setCategory(NotificationCompat.CATEGORY_STATUS); // Not sure if this category is really the most appropriate
    mainNotifBuilder.setLights(0, 0, 0); // No light
    mainNotifBuilder.setShowWhen(false); // No date
    mainNotifBuilder.addPerson(addressInfo.contactInfo.contentLookupUri.toString());

    // Contact photo
    Bitmap contactPhoto = addressInfo.getContactPhoto(this);
    if (contactPhoto != null)
        mainNotifBuilder.setLargeIcon(contactPhoto);

    // Dismiss intent
    Intent dismissIntent = new Intent(ACTION_DISMISS_NOTIFICATION, null, this, getClass());
    PendingIntent dismissPendingIntent = PendingIntent.getService(this, 0, dismissIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mainNotifBuilder.setDeleteIntent(dismissPendingIntent);

    // Main action (click on the notification itself)
    Intent mainIntent = new Intent(Intent.ACTION_VIEW);
    mainIntent.setData(addressInfo.contactInfo.contentLookupUri);
    PendingIntent mainPendingIntent = PendingIntent.getActivity(this, 0, mainIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mainNotifBuilder.setContentIntent(mainPendingIntent);

    String phoneNumber = addressInfo.getContactPhoneNumber(this);
    if (phoneNumber != null) {
        // Call action
        Intent callIntent = new Intent(Intent.ACTION_DIAL);
        callIntent.setData(Uri.parse("tel:" + phoneNumber));
        PendingIntent callPendingIntent = PendingIntent.getActivity(this, 0, callIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        String callText = getString(R.string.notification_action_call);
        mainNotifBuilder.addAction(R.drawable.ic_action_call, callText, callPendingIntent);

        // Sms action
        Intent smsIntent = new Intent(Intent.ACTION_VIEW);
        smsIntent.setData(Uri.parse("sms:" + phoneNumber));
        smsIntent.putExtra("sms_body", getString(R.string.notification_action_sms_body));
        PendingIntent smsPendingIntent = PendingIntent.getActivity(this, 0, smsIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        String smsText = getString(R.string.notification_action_sms);
        mainNotifBuilder.addAction(R.drawable.ic_action_sms, smsText, smsPendingIntent);
    }

    // Since we have a specific Wear notification, show this one only on handheld
    mainNotifBuilder.setLocalOnly(true);

    // Show it
    Notification notification = mainNotifBuilder.build();
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID, notification);

    // Show a Wear notification
    // Blocking
    mWearHelper.connect(this);
    mWearHelper.putNotification(titleLong, textShort, textLong, contactPhoto,
            addressInfo.contactInfo.contentLookupUri, phoneNumber);
}

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

private Spanned getTitleStringAboutMe(int stringRes, int stringResMulti, ParcelableUser[] sources) {
    if (sources == null || sources.length == 0)
        return null;
    final Context context = adapter.getContext();
    final boolean nameFirst = adapter.isNameFirst();
    final UserColorNameManager manager = adapter.getUserColorNameManager();
    final Resources resources = context.getResources();
    final Configuration configuration = resources.getConfiguration();
    final SpannableString firstDisplayName = new SpannableString(
            manager.getDisplayName(sources[0], nameFirst, false));
    firstDisplayName.setSpan(new StyleSpan(Typeface.BOLD), 0, firstDisplayName.length(),
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    if (sources.length == 1) {
        final String format = context.getString(stringRes);
        return SpanFormatter.format(configuration.locale, format, firstDisplayName);
    } else if (sources.length == 2) {
        final String format = context.getString(stringResMulti);
        final SpannableString secondDisplayName = new SpannableString(
                manager.getDisplayName(sources[1], nameFirst, false));
        secondDisplayName.setSpan(new StyleSpan(Typeface.BOLD), 0, secondDisplayName.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return SpanFormatter.format(configuration.locale, format, firstDisplayName, secondDisplayName);
    } else {/*  w w w  .ja v  a  2 s  .co  m*/
        final int othersCount = sources.length - 1;
        final SpannableString nOthers = new SpannableString(
                resources.getQuantityString(R.plurals.N_others, othersCount, othersCount));
        nOthers.setSpan(new StyleSpan(Typeface.BOLD), 0, nOthers.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        final String format = context.getString(stringResMulti);
        return SpanFormatter.format(configuration.locale, format, firstDisplayName, nOthers);
    }
}

From source file:org.awesomeapp.messenger.ui.GalleryListItem.java

private SpannableString formatTimeStamp(Date date, int messageType, DateFormat format,
        GalleryListItem.DeliveryState delivery, EncryptionState encryptionState) {

    StringBuilder deliveryText = new StringBuilder();
    deliveryText.append(format.format(date));
    deliveryText.append(' ');

    if (delivery != null) {
        //this is for delivery
        if (delivery == DeliveryState.DELIVERED) {

            deliveryText.append(DELIVERED_SUCCESS);

        } else if (delivery == DeliveryState.UNDELIVERED) {

            deliveryText.append(DELIVERED_FAIL);
        }/*from  w ww.j  a  v  a  2 s .c o m*/
    }

    if (messageType != Imps.MessageType.POSTPONED)
        deliveryText.append(DELIVERED_SUCCESS);//this is for sent, so we know show 2 checks like WhatsApp!

    SpannableString spanText = null;

    if (encryptionState == EncryptionState.ENCRYPTED) {
        deliveryText.append('X');
        spanText = new SpannableString(deliveryText.toString());
        int len = spanText.length();

        spanText.setSpan(new ImageSpan(getContext(), R.drawable.ic_lock_outline_black_18dp), len - 1, len,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    } else if (encryptionState == EncryptionState.ENCRYPTED_AND_VERIFIED) {
        deliveryText.append('X');
        spanText = new SpannableString(deliveryText.toString());
        int len = spanText.length();

        spanText.setSpan(new ImageSpan(getContext(), R.drawable.ic_lock_outline_black_18dp), len - 1, len,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    } else {
        spanText = new SpannableString(deliveryText.toString());
        int len = spanText.length();

    }

    //   spanText.setSpan(new StyleSpan(Typeface.SANS_SERIF), 0, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    // spanText.setSpan(new RelativeSizeSpan(0.8f), 0, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    //    spanText.setSpan(new ForegroundColorSpan(R.color.soft_grey),
    //        0, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    return spanText;
}

From source file:com.directsiding.android.WebActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.activity_web);

    // Le ponemos la font Signika al titulo del Action Bar
    SpannableString s = new SpannableString(getString(R.string.app_name));
    s.setSpan(new TypefaceSpan(this, LoginActivity.PATH_SIGNIKA_FONT), 0, s.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    // Agregamos lo necesario al Action Bar
    ActionBar actionBar = getSupportActionBar();
    actionBar.setTitle(s);//from  w w  w .  j  ava 2  s .co  m
    actionBar.setDisplayShowHomeEnabled(true);
    actionBar.setHomeButtonEnabled(true);

    // Obtenemos la url a la que el usuario va a ingresar
    String url = getIntent().getExtras().getString(LoginActivity.EXTRA_URL);

    // Obtenemos la cookie y la agregamos al webview
    Cookie sessionCookie = LoginOpActivity.cookie;
    CookieSyncManager.createInstance(this);
    CookieManager cookieManager = CookieManager.getInstance();
    if (sessionCookie != null) {
        //cookieManager.removeSessionCookie();
        String cookieString = sessionCookie.getName() + "=" + sessionCookie.getValue() + "; domain="
                + sessionCookie.getDomain();
        cookieManager.setCookie(LoginActivity.POST_URL, cookieString);
        CookieSyncManager.getInstance().sync();
    }

    mProgressBar = (ProgressBar) findViewById(R.id.progressBar_webView);
    webView = (WebView) findViewById(R.id.webView_ing);

    webViewConfig();
    webView.loadUrl(url);
    //webView.loadUrl("http://www.google.com");

    // guardamos el tiempo en el que se creo la actividad
    lastTimeStamp = SystemClock.elapsedRealtime();

}