Example usage for android.text SpannableStringBuilder setSpan

List of usage examples for android.text SpannableStringBuilder setSpan

Introduction

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

Prototype

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

Source Link

Document

Mark the specified range of text with the specified object.

Usage

From source file:io.development.tymo.adapters.FeedZoomMoreAdapter.java

@Override
public void onBindViewHolder(SimpleViewHolder holder, int position) {
    ActivityServer feedCubeModel;/*from w ww .j  av  a2  s  .  c  o m*/
    FlagServer feedFlagModel;
    holder.adapter = new PersonSmallAdapter(listPeople.get(position), mContext);
    holder.recyclerView.setAdapter(holder.adapter);
    if (mItems.get(position) instanceof ActivityServer) {
        holder.textDescription.setVisibility(View.VISIBLE);
        holder.cubeLowerBox.setVisibility(View.VISIBLE);
        holder.locationBox.setVisibility(View.VISIBLE);
        holder.pieceIcon.setVisibility(View.VISIBLE);
        holder.cubeUpperBoxIcon.setVisibility(View.VISIBLE);
        holder.cubeLowerBoxIcon.setVisibility(View.VISIBLE);

        feedCubeModel = (ActivityServer) mItems.get(position);
        holder.textTitle.setText(feedCubeModel.getTitle());
        holder.textTitle.setTextColor(ContextCompat.getColor(mContext, R.color.grey_900));
        holder.textDescription.setText(feedCubeModel.getTitle());
        if (feedCubeModel.getDescription() != null && !feedCubeModel.getDescription().matches(""))
            holder.textDescription.setText(feedCubeModel.getDescription());
        else
            holder.textDescription.setVisibility(View.GONE);

        holder.cubeLowerBox.setVisibility(View.VISIBLE);
        holder.cubeUpperBoxIcon.setVisibility(View.VISIBLE);
        holder.flagButton.setVisibility(View.GONE);

        holder.cubeUpperBoxIcon.setColorFilter(feedCubeModel.getCubeColorUpper());
        holder.cubeLowerBoxIcon.setColorFilter(feedCubeModel.getCubeColor());

        Glide.clear(holder.pieceIcon);
        Glide.with(mContext).load(feedCubeModel.getCubeIcon()).asBitmap()
                .diskCacheStrategy(DiskCacheStrategy.ALL).into(holder.pieceIcon);

        Calendar calendar = Calendar.getInstance();
        Calendar calendar2 = Calendar.getInstance();
        calendar.set(feedCubeModel.getYearStart(), feedCubeModel.getMonthStart() - 1,
                feedCubeModel.getDayStart());
        calendar2.set(feedCubeModel.getYearEnd(), feedCubeModel.getMonthEnd() - 1, feedCubeModel.getDayEnd());
        String dayOfWeekStart = dateFormat.todayTomorrowYesterdayCheck(calendar.get(Calendar.DAY_OF_WEEK),
                calendar);
        String dayStart = String.format("%02d", feedCubeModel.getDayStart());
        String monthStart = new SimpleDateFormat("MM", mContext.getResources().getConfiguration().locale)
                .format(calendar.getTime().getTime());
        int yearStart = feedCubeModel.getYearStart();
        String hourStart = String.format("%02d", feedCubeModel.getHourStart());
        String minuteStart = String.format("%02d", feedCubeModel.getMinuteStart());
        String dayOfWeekEnd = dateFormat.todayTomorrowYesterdayCheck(calendar2.get(Calendar.DAY_OF_WEEK),
                calendar2);
        String dayEnd = String.format("%02d", feedCubeModel.getDayEnd());
        String monthEnd = new SimpleDateFormat("MM", mContext.getResources().getConfiguration().locale)
                .format(calendar2.getTime().getTime());
        int yearEnd = feedCubeModel.getYearEnd();
        String hourEnd = String.format("%02d", feedCubeModel.getHourEnd());
        String minuteEnd = String.format("%02d", feedCubeModel.getMinuteEnd());

        if (calendar.get(Calendar.DATE) == calendar2.get(Calendar.DATE)) {
            if (hourStart.matches(hourEnd) && minuteStart.matches(minuteEnd)) {
                holder.date.setText(mContext.getResources().getString(R.string.date_format_04, dayOfWeekStart,
                        dayStart, monthStart, yearStart, hourStart, minuteStart));
            } else {
                holder.date.setText(mContext.getResources().getString(R.string.date_format_05, dayOfWeekStart,
                        dayStart, monthStart, yearStart, hourStart, minuteStart, hourEnd, minuteEnd));
            }
        } else {
            holder.date.setText(mContext.getResources().getString(R.string.date_format_06, dayOfWeekStart,
                    dayStart, monthStart, yearStart, hourStart, minuteStart, dayOfWeekEnd, dayEnd, monthEnd,
                    yearEnd, hourEnd, minuteEnd));
        }

        if (!feedCubeModel.getLocation().matches("")) {
            SharedPreferences mSharedPreferences = mContext.getSharedPreferences(Constants.USER_CREDENTIALS,
                    MODE_PRIVATE);
            boolean location = mSharedPreferences.getBoolean(Constants.LOCATION, true);

            if (location) {
                LocationManager manager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);

                if (manager.isProviderEnabled(LocationManager.GPS_PROVIDER) && lat != -500
                        && (feedCubeModel.getLat() != 0 && feedCubeModel.getLng() != 0)) {
                    double distance = Utilities.distance(lat, lng, feedCubeModel.getLat(),
                            feedCubeModel.getLng());
                    if (distance < 1) {
                        distanceText = mContext.getResources().getString(R.string.distance_meters,
                                (int) (distance * 1000)) + " ";
                    } else {
                        distanceText = mContext.getResources().getString(R.string.distance_km, (int) distance)
                                + " ";
                    }
                } else
                    distanceText = "";

            } else
                distanceText = "";

            if (!distanceText.matches("")) {
                final SpannableStringBuilder sb = new SpannableStringBuilder(
                        distanceText + feedCubeModel.getLocation());
                final StyleSpan styleBold = new StyleSpan(Typeface.BOLD);
                sb.setSpan(styleBold, 0, distanceText.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
                holder.location.setText(sb);
            } else {
                holder.location.setText(feedCubeModel.getLocation());
            }

        } else {
            holder.locationBox.setVisibility(View.GONE);
            distanceText = "";
        }

        if (!feedCubeModel.getUser().getPhoto().matches("")) {
            Glide.clear(holder.photoCreator);
            Glide.with(mContext).load(feedCubeModel.getUser().getPhoto()).asBitmap().thumbnail(0.1f)
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .into(new BitmapImageViewTarget(holder.photoCreator) {
                        @Override
                        protected void setResource(Bitmap resource) {
                            RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory
                                    .create(mContext.getResources(), resource);
                            circularBitmapDrawable.setCircular(true);
                            holder.photoCreator.setImageDrawable(circularBitmapDrawable);
                        }
                    });
        } else
            holder.photoCreator.setImageResource(R.drawable.ic_profile_photo_empty);

        if (feedCubeModel.getFavoriteCreator() > 0) {
            holder.photoCreatorRingBox.setVisibility(View.VISIBLE);
            holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_favorite_zoom_more);
        } else if (feedCubeModel.getKnowCreator() > 0) {
            holder.photoCreatorRingBox.setVisibility(View.VISIBLE);
            holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_my_contact_zoom_more);
        } else if (feedCubeModel.getUser().getEmail().equals(email)) {
            holder.photoCreatorRingBox.setVisibility(View.VISIBLE);
            holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_you_zoom_more);
        } else {
            holder.photoCreatorRingBox.setVisibility(View.INVISIBLE);
        }
    } else {
        feedFlagModel = (FlagServer) mItems.get(position);
        holder.textTitle.setText(mContext.getResources().getString(R.string.flag_available));
        holder.textTitle.setTextColor(ContextCompat.getColor(mContext, R.color.flag_available));
        if (feedFlagModel.getTitle().matches("")) {
            holder.textDescription.setVisibility(View.GONE);
        } else {
            holder.textDescription.setText(feedFlagModel.getTitle());
        }
        holder.cubeLowerBox.setVisibility(View.GONE);
        holder.cubeUpperBoxIcon.setVisibility(View.GONE);
        holder.flagButton.setVisibility(View.VISIBLE);
        holder.locationBox.setVisibility(View.GONE);

        Calendar calendar = Calendar.getInstance();
        Calendar calendar2 = Calendar.getInstance();
        calendar.set(feedFlagModel.getYearStart(), feedFlagModel.getMonthStart() - 1,
                feedFlagModel.getDayStart());
        calendar2.set(feedFlagModel.getYearEnd(), feedFlagModel.getMonthEnd() - 1, feedFlagModel.getDayEnd());

        String dayOfWeekStart = dateFormat.todayTomorrowYesterdayCheck(calendar.get(Calendar.DAY_OF_WEEK),
                calendar);
        String dayStart = String.format("%02d", feedFlagModel.getDayStart());
        String monthStart = new SimpleDateFormat("MM", mContext.getResources().getConfiguration().locale)
                .format(calendar.getTime().getTime());
        int yearStart = feedFlagModel.getYearStart();
        String hourStart = String.format("%02d", feedFlagModel.getHourStart());
        String minuteStart = String.format("%02d", feedFlagModel.getMinuteStart());
        String dayOfWeekEnd = dateFormat.todayTomorrowYesterdayCheck(calendar2.get(Calendar.DAY_OF_WEEK),
                calendar2);
        String dayEnd = String.format("%02d", feedFlagModel.getDayEnd());
        String monthEnd = new SimpleDateFormat("MM", mContext.getResources().getConfiguration().locale)
                .format(calendar2.getTime().getTime());
        int yearEnd = feedFlagModel.getYearEnd();
        String hourEnd = String.format("%02d", feedFlagModel.getHourEnd());
        String minuteEnd = String.format("%02d", feedFlagModel.getMinuteEnd());

        if (calendar.get(Calendar.DATE) == calendar2.get(Calendar.DATE)) {
            if (hourStart.matches(hourEnd) && minuteStart.matches(minuteEnd)) {
                holder.date.setText(mContext.getResources().getString(R.string.date_format_04, dayOfWeekStart,
                        dayStart, monthStart, yearStart, hourStart, minuteStart));
            } else {
                holder.date.setText(mContext.getResources().getString(R.string.date_format_05, dayOfWeekStart,
                        dayStart, monthStart, yearStart, hourStart, minuteStart, hourEnd, minuteEnd));
            }
        } else {
            holder.date.setText(mContext.getResources().getString(R.string.date_format_06, dayOfWeekStart,
                    dayStart, monthStart, yearStart, hourStart, minuteStart, dayOfWeekEnd, dayEnd, monthEnd,
                    yearEnd, hourEnd, minuteEnd));
        }

        if (!feedFlagModel.getUser().getPhoto().matches("")) {
            Glide.clear(holder.photoCreator);
            Glide.with(mContext).load(feedFlagModel.getUser().getPhoto()).asBitmap().thumbnail(0.1f)
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .into(new BitmapImageViewTarget(holder.photoCreator) {
                        @Override
                        protected void setResource(Bitmap resource) {
                            RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory
                                    .create(mContext.getResources(), resource);
                            circularBitmapDrawable.setCircular(true);
                            holder.photoCreator.setImageDrawable(circularBitmapDrawable);
                        }
                    });
        } else
            holder.photoCreator.setImageResource(R.drawable.ic_profile_photo_empty);

        if (feedFlagModel.getFavoriteCreator() > 0) {
            holder.photoCreatorRingBox.setVisibility(View.VISIBLE);
            holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_favorite_zoom_more);
        } else if (feedFlagModel.getKnowCreator() > 0) {
            holder.photoCreatorRingBox.setVisibility(View.VISIBLE);
            holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_my_contact_zoom_more);
        } else if (feedFlagModel.getUser().getEmail().equals(email)) {
            holder.photoCreatorRingBox.setVisibility(View.VISIBLE);
            holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_you_zoom_more);
        } else {
            holder.photoCreatorRingBox.setVisibility(View.INVISIBLE);
        }

    }

    if (holder.flagButton.getVisibility() == View.VISIBLE) {
        holder.pieceBox.startAnimation(animation2);
    } else {
        holder.pieceBox.startAnimation(animation2);
    }
    holder.textBox.startAnimation(animation);
    holder.triangle.startAnimation(animation);
}

From source file:tk.wasdennnoch.androidn_ify.utils.NotificationColorUtil.java

/**
 * Inverts all the grayscale colors set by {@link TextAppearanceSpan}s on
 * the text.//from w ww .ja v a  2s  . c  om
 *
 * @param charSequence The text to process.
 * @return The color inverted text.
 */
public CharSequence invertCharSequenceColors(CharSequence charSequence) {
    if (charSequence instanceof Spanned) {
        Spanned ss = (Spanned) charSequence;
        Object[] spans = ss.getSpans(0, ss.length(), Object.class);
        SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString());
        for (Object span : spans) {
            Object resultSpan = span;
            if (span instanceof TextAppearanceSpan) {
                resultSpan = processTextAppearanceSpan((TextAppearanceSpan) span);
            }
            builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), ss.getSpanFlags(span));
        }
        return builder;
    }
    return charSequence;
}

From source file:net.kourlas.voipms_sms.adapters.ConversationsRecyclerViewAdapter.java

@Override
public void onBindViewHolder(ConversationViewHolder conversationViewHolder, int position) {
    Message message = messages.get(position);

    ViewSwitcher viewSwitcher = conversationViewHolder.getViewSwitcher();
    viewSwitcher.setDisplayedChild(isItemChecked(position) ? 1 : 0);

    QuickContactBadge contactBadge = conversationViewHolder.getContactBadge();
    contactBadge.assignContactFromPhone(message.getContact(), true);

    String photoUri = Utils.getContactPhotoUri(applicationContext, message.getContact());
    if (photoUri != null) {
        contactBadge.setImageURI(Uri.parse(photoUri));
    } else {//w w w . j a  v a 2s  .c  om
        contactBadge.setImageToDefault();
    }

    TextView contactTextView = conversationViewHolder.getContactTextView();
    String contactName = Utils.getContactName(applicationContext, message.getContact());
    SpannableStringBuilder contactTextBuilder = new SpannableStringBuilder();
    if (contactName != null) {
        contactTextBuilder.append(contactName);
    } else {
        contactTextBuilder.append(Utils.getFormattedPhoneNumber(message.getContact()));
    }
    if (!filterConstraint.equals("")) {
        int index = contactTextBuilder.toString().toLowerCase().indexOf(filterConstraint.toLowerCase());
        if (index != -1) {
            contactTextBuilder.setSpan(
                    new BackgroundColorSpan(ContextCompat.getColor(applicationContext, R.color.highlight)),
                    index, index + filterConstraint.length(), SpannableString.SPAN_INCLUSIVE_EXCLUSIVE);
        }
    }
    contactTextView.setText(contactTextBuilder);

    final TextView messageTextView = conversationViewHolder.getMessageTextView();
    SpannableStringBuilder messageTextBuilder = new SpannableStringBuilder();

    int index = message.getText().toLowerCase().indexOf(filterConstraint.toLowerCase());
    if (!filterConstraint.equals("") && index != -1) {
        int nonMessageOffset = index;
        if (message.getType() == Message.Type.OUTGOING) {
            messageTextBuilder.insert(0,
                    applicationContext.getString(R.string.conversations_message_you) + " ");
            nonMessageOffset += 5;
        }

        int substringOffset = index - 20;
        if (substringOffset > 0) {
            messageTextBuilder.append("...");
            nonMessageOffset += 3;

            while (message.getText().charAt(substringOffset) != ' ' && substringOffset < index - 1) {
                substringOffset += 1;
            }
            substringOffset += 1;
        } else {
            substringOffset = 0;
        }

        messageTextBuilder.append(message.getText().substring(substringOffset));
        messageTextBuilder.setSpan(
                new BackgroundColorSpan(ContextCompat.getColor(applicationContext, R.color.highlight)),
                nonMessageOffset - substringOffset,
                nonMessageOffset - substringOffset + filterConstraint.length(),
                SpannableString.SPAN_INCLUSIVE_EXCLUSIVE);
    } else {
        if (message.getType() == Message.Type.OUTGOING) {
            messageTextBuilder.append(applicationContext.getString(R.string.conversations_message_you));
            messageTextBuilder.append(" ");
        }
        messageTextBuilder.append(message.getText());
    }
    messageTextView.setText(messageTextBuilder);

    if (message.isUnread()) {
        contactTextView.setTypeface(null, Typeface.BOLD);
        messageTextView.setTypeface(null, Typeface.BOLD);
    } else {
        contactTextView.setTypeface(null, Typeface.NORMAL);
        messageTextView.setTypeface(null, Typeface.NORMAL);
    }

    // Set date line
    TextView dateTextView = conversationViewHolder.getDateTextView();
    if (message.isDraft()) {
        SpannableStringBuilder dateTextBuilder = new SpannableStringBuilder();
        dateTextBuilder.append(applicationContext.getString(R.string.conversations_message_draft));
        dateTextBuilder.setSpan(new StyleSpan(Typeface.ITALIC), 0, dateTextBuilder.length(),
                Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        dateTextView.setText(dateTextBuilder);
    } else if (!message.isDelivered()) {
        if (!message.isDeliveryInProgress()) {
            SpannableStringBuilder dateTextBuilder = new SpannableStringBuilder();
            dateTextBuilder.append(applicationContext.getString(R.string.conversations_message_not_sent));
            dateTextBuilder.setSpan(
                    new ForegroundColorSpan(
                            ContextCompat.getColor(applicationContext, android.R.color.holo_red_dark)),
                    0, dateTextBuilder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
            dateTextView.setText(dateTextBuilder);
        } else {
            dateTextView.setText(applicationContext.getString(R.string.conversations_message_sending));
        }
    } else {
        dateTextView.setText(Utils.getFormattedDate(applicationContext, message.getDate(), true));
    }
}

From source file:org.androidtitlan.estoesgoogle.ui.SessionDetailFragment.java

/**
 * Handle {@link SessionsQuery} {@link Cursor}.
 *///from www  . j av a  2s  . c o  m
private void onSessionQueryComplete(Cursor cursor) {
    try {
        mSessionCursor = true;
        if (!cursor.moveToFirst()) {
            return;
        }

        // Format time block this session occupies
        final long blockStart = cursor.getLong(SessionsQuery.BLOCK_START);
        final long blockEnd = cursor.getLong(SessionsQuery.BLOCK_END);
        final String roomName = cursor.getString(SessionsQuery.ROOM_NAME);
        final String subtitle = UIUtils.formatSessionSubtitle(blockStart, blockEnd, roomName, getActivity());

        mTitleString = cursor.getString(SessionsQuery.TITLE);
        mTitle.setText(mTitleString);
        mSubtitle.setText(subtitle);

        mUrl = cursor.getString(SessionsQuery.URL);
        if (TextUtils.isEmpty(mUrl)) {
            mUrl = "";
        }

        mHashtag = cursor.getString(SessionsQuery.HASHTAG);
        mTagDisplay = (TextView) mRootView.findViewById(R.id.session_tags_button);
        if (!TextUtils.isEmpty(mHashtag)) {
            // Create the button text
            SpannableStringBuilder sb = new SpannableStringBuilder();
            sb.append(getString(R.string.tag_stream) + " ");
            int boldStart = sb.length();
            sb.append(getHashtagsString());
            sb.setSpan(sBoldSpan, boldStart, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

            mTagDisplay.setText(sb);

            mTagDisplay.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    Intent intent = new Intent(getActivity(), TagStreamActivity.class);
                    intent.putExtra(TagStreamFragment.EXTRA_QUERY, getHashtagsString());
                    startActivity(intent);
                }
            });
        } else {
            mTagDisplay.setVisibility(View.GONE);
        }

        mRoomId = cursor.getString(SessionsQuery.ROOM_ID);

        // Unregister around setting checked state to avoid triggering
        // listener since change isn't user generated.
        mStarred.setOnCheckedChangeListener(null);
        mStarred.setChecked(cursor.getInt(SessionsQuery.STARRED) != 0);
        mStarred.setOnCheckedChangeListener(this);

        final String sessionAbstract = cursor.getString(SessionsQuery.ABSTRACT);
        if (!TextUtils.isEmpty(sessionAbstract)) {
            UIUtils.setTextMaybeHtml(mAbstract, sessionAbstract);
            mAbstract.setVisibility(View.VISIBLE);
            mHasSummaryContent = true;
        } else {
            mAbstract.setVisibility(View.GONE);
        }

        final View requirementsBlock = mRootView.findViewById(R.id.session_requirements_block);
        final String sessionRequirements = cursor.getString(SessionsQuery.REQUIREMENTS);
        if (!TextUtils.isEmpty(sessionRequirements)) {
            UIUtils.setTextMaybeHtml(mRequirements, sessionRequirements);
            requirementsBlock.setVisibility(View.VISIBLE);
            mHasSummaryContent = true;
        } else {
            requirementsBlock.setVisibility(View.GONE);
        }

        // Show empty message when all data is loaded, and nothing to show
        if (mSpeakersCursor && !mHasSummaryContent) {
            mRootView.findViewById(android.R.id.empty).setVisibility(View.VISIBLE);
        }

        AnalyticsUtils.getInstance(getActivity()).trackPageView("/Sessions/" + mTitleString);
        updateNotesTab();
        updateLinksTab(cursor);

    } finally {
        cursor.close();
    }
}

From source file:com.google.android.apps.iosched.ui.SessionDetailFragment.java

/**
 * Handle {@link SessionsQuery} {@link Cursor}.
 */// ww w  .j  ava  2s .  co m
private void onSessionQueryComplete(Cursor cursor) {
    try {
        mSessionCursor = true;
        if (!cursor.moveToFirst()) {
            return;
        }

        // Format time block this session occupies
        final long blockStart = cursor.getLong(SessionsQuery.BLOCK_START);
        final long blockEnd = cursor.getLong(SessionsQuery.BLOCK_END);
        final String roomName = cursor.getString(SessionsQuery.ROOM_NAME);
        final String subtitle = UIUtils.formatSessionSubtitle(blockStart, blockEnd, roomName, getActivity());

        mTitleString = cursor.getString(SessionsQuery.TITLE);
        mTitle.setText(mTitleString);
        mSubtitle.setText(subtitle);

        mUrl = cursor.getString(SessionsQuery.URL);
        if (TextUtils.isEmpty(mUrl)) {
            mUrl = "";
        }

        mHashtag = cursor.getString(SessionsQuery.HASHTAG);
        mTagDisplay = (TextView) mRootView.findViewById(R.id.session_tags_button);
        if (!TextUtils.isEmpty(mHashtag)) {
            // Create the button text
            SpannableStringBuilder sb = new SpannableStringBuilder();
            sb.append(getString(R.string.tag_stream) + " ");
            int boldStart = sb.length();
            sb.append(getHashtagsString());
            sb.setSpan(sBoldSpan, boldStart, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

            mTagDisplay.setText(sb);

            mTagDisplay.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    Intent intent = new Intent(getActivity(), TagStreamActivity.class);
                    intent.putExtra(TagStreamFragment.EXTRA_QUERY, getHashtagsString());
                    startActivity(intent);
                }
            });
        } else {
            mTagDisplay.setVisibility(View.GONE);
        }

        mRoomId = cursor.getString(SessionsQuery.ROOM_ID);

        // Unregister around setting checked state to avoid triggering
        // listener since change isn't user generated.
        mStarred.setOnCheckedChangeListener(null);
        mStarred.setChecked(cursor.getInt(SessionsQuery.STARRED) != 0);
        mStarred.setOnCheckedChangeListener(this);

        final String sessionAbstract = cursor.getString(SessionsQuery.ABSTRACT);
        if (!TextUtils.isEmpty(sessionAbstract)) {
            UIUtils.setTextMaybeHtml(mAbstract, sessionAbstract);
            mAbstract.setVisibility(View.VISIBLE);
            mHasSummaryContent = true;
        } else {
            mAbstract.setVisibility(View.GONE);
        }

        final View requirementsBlock = mRootView.findViewById(R.id.session_requirements_block);
        final String sessionRequirements = cursor.getString(SessionsQuery.REQUIREMENTS);
        if (!TextUtils.isEmpty(sessionRequirements)) {
            UIUtils.setTextMaybeHtml(mRequirements, sessionRequirements);
            requirementsBlock.setVisibility(View.VISIBLE);
            mHasSummaryContent = true;
        } else {
            requirementsBlock.setVisibility(View.GONE);
        }

        // Show empty message when all data is loaded, and nothing to show
        if (mSpeakersCursor && !mHasSummaryContent) {
            mRootView.findViewById(android.R.id.empty).setVisibility(View.VISIBLE);
        }

        AnalyticsUtils.getInstance(getActivity()).trackPageView("/Sessions/" + mTitleString);

        updateLinksTab(cursor);
        updateNotesTab();

    } finally {
        cursor.close();
    }
}

From source file:tv.acfun.video.CommentsActivity.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    int count = mAdapter.getCount();
    if (position > count) {
        if (isreload) {
            mFootview.findViewById(R.id.list_footview_progress).setVisibility(View.VISIBLE);
            TextView textview = (TextView) mFootview.findViewById(R.id.list_footview_text);
            textview.setText(R.string.buffering);
            requestData(pageIndex, false);
        }//from  www  .j a  va 2 s.  c  o m
        return;
    }
    //        showBar(); //TODO: show input bar when selected comment
    Object o = parent.getItemAtPosition(position);
    if (o == null || !(o instanceof Comment))
        return;
    Comment c = (Comment) o;
    int quoteCount = getQuoteCount();
    removeQuote(mCommentText.getText());
    if (quoteCount == c.count)
        return; // ?
    String pre = ":#" + c.count;
    mQuoteSpan = new Quote(c.count);
    SpannableStringBuilder sb = SpannableStringBuilder.valueOf(mCommentText.getText());
    TextView tv = TextViewUtils.createBubbleTextView(this, pre);
    BitmapDrawable bd = (BitmapDrawable) TextViewUtils.convertViewToDrawable(tv);
    bd.setBounds(0, 0, bd.getIntrinsicWidth(), bd.getIntrinsicHeight());
    sb.insert(0, pre);
    mQuoteImage = new ImageSpan(bd);
    sb.setSpan(mQuoteImage, 0, pre.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    sb.setSpan(mQuoteSpan, 0, pre.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    sb.append("");
    mCommentText.setText(sb);
    mCommentText.setSelection(mCommentText.getText().length());
}

From source file:com.owncloud.android.ui.adapter.NotificationListAdapter.java

private SpannableStringBuilder makeSpecialPartsBold(Notification notification) {
    String text = notification.getSubjectRich();
    SpannableStringBuilder ssb = new SpannableStringBuilder(text);

    int openingBrace = text.indexOf('{');
    int closingBrace;
    String replaceablePart;/*from ww w. j  a  v a2s .c om*/
    while (openingBrace != -1) {
        closingBrace = text.indexOf('}', openingBrace) + 1;
        replaceablePart = text.substring(openingBrace + 1, closingBrace - 1);

        RichObject richObject = notification.subjectRichParameters.get(replaceablePart);
        if (richObject != null) {
            String name = richObject.getName();
            ssb.replace(openingBrace, closingBrace, name);
            text = ssb.toString();
            closingBrace = openingBrace + name.length();

            ssb.setSpan(styleSpanBold, openingBrace, closingBrace, 0);
            ssb.setSpan(foregroundColorSpanBlack, openingBrace, closingBrace,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        openingBrace = text.indexOf('{', closingBrace);
    }

    return ssb;
}

From source file:com.abcvoipsip.ui.messages.ConverstationsAdapter.java

private CharSequence formatMessage(Cursor cursor) {
    SpannableStringBuilder buf = new SpannableStringBuilder();
    /*/*from  www.j a  v  a  2 s . c o  m*/
    String remoteContact = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM));
    if (remoteContact.equals("SELF")) {
    remoteContact = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_TO));
    buf.append("To: ");
    }
    */
    String remoteContactFull = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM_FULL));
    buf.append(SipUri.getDisplayedSimpleContact(remoteContactFull));

    int counter = cursor.getInt(cursor.getColumnIndex("counter"));
    if (counter > 1) {
        buf.append(" (" + counter + ") ");
    }

    int read = cursor.getInt(cursor.getColumnIndex(SipMessage.FIELD_READ));
    // Unread messages are shown in bold
    if (read == 0) {
        buf.setSpan(STYLE_BOLD, 0, buf.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    }
    return buf;
}

From source file:com.yahala.ui.GroupCreateActivity.java

public XImageSpan createAndPutChipForUser(TLRPC.User user) {
    LayoutInflater lf = (LayoutInflater) parentActivity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    View textView = lf.inflate(R.layout.group_create_bubble, null);
    TextView text = (TextView) textView.findViewById(R.id.bubble_text_view);
    String name = Utilities.formatName(user.first_name, user.last_name);
    if (name.length() == 0 && user.phone != null && user.phone.length() != 0) {
        name = PhoneFormat.getInstance().format("+" + user.phone);
    }//from   w  w w .j av  a 2 s.c o  m
    text.setText(name + ", ");

    int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    textView.measure(spec, spec);
    textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
    Bitmap b = Bitmap.createBitmap(textView.getWidth(), textView.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(b);
    canvas.translate(-textView.getScrollX(), -textView.getScrollY());
    textView.draw(canvas);
    textView.setDrawingCacheEnabled(true);
    Bitmap cacheBmp = textView.getDrawingCache();
    Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
    textView.destroyDrawingCache();

    final BitmapDrawable bmpDrawable = new BitmapDrawable(b);
    bmpDrawable.setBounds(0, 0, b.getWidth(), b.getHeight());

    SpannableStringBuilder ssb = new SpannableStringBuilder("");
    XImageSpan span = new XImageSpan(bmpDrawable, ImageSpan.ALIGN_BASELINE);
    allSpans.add(span);
    selectedContacts.put(user.jid, span);
    for (ImageSpan sp : allSpans) {
        ssb.append("<<");
        ssb.setSpan(sp, ssb.length() - 2, ssb.length(), SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    userSelectEditText.setText(ssb);
    userSelectEditText.setSelection(ssb.length());
    return span;
}

From source file:com.jecelyin.editor.v2.core.text.TextUtils.java

/**
 * Return a new CharSequence in which each of the source strings is
 * replaced by the corresponding element of the destinations.
 *///from w  ww.ja  va2 s .co m
public static CharSequence replace(CharSequence template, String[] sources, CharSequence[] destinations) {
    SpannableStringBuilder tb = new SpannableStringBuilder(template);

    for (int i = 0; i < sources.length; i++) {
        int where = indexOf(tb, sources[i]);

        if (where >= 0)
            tb.setSpan(sources[i], where, where + sources[i].length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    for (int i = 0; i < sources.length; i++) {
        int start = tb.getSpanStart(sources[i]);
        int end = tb.getSpanEnd(sources[i]);

        if (start >= 0) {
            tb.replace(start, end, destinations[i]);
        }
    }

    return tb;
}