Search in sources :

Example 21 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project KeepScore by nolanlawson.

the class AbstractHistoryTableFragment method createHistoryItemView.

protected View createHistoryItemView(ViewGroup parent, HistoryItem historyItem, int layoutResId, int rowId, boolean weightIsOne, Activity activity) {
    View view = getInflater().inflate(layoutResId, parent, false);
    // alternating colors for the background, from gray to white
    view.setBackgroundColor(getResources().getColor(rowId % 2 == 0 ? android.R.color.background_light : R.color.light_gray));
    TextView textView1 = (TextView) view.findViewById(android.R.id.text1);
    TextView textView2 = (TextView) view.findViewById(android.R.id.text2);
    if (historyItem == null) {
        // null indicates to leave the text views empty
        setDummyTextView(textView1);
        setDummyTextView(textView2);
        return weightIsOne ? setLayoutWeightToOne(view) : view;
    }
    textView2.setVisibility(View.VISIBLE);
    if (historyItem.isHideDelta()) {
        setDummyTextView(textView1);
        // set as gone to ensure that
        textView1.setVisibility(View.GONE);
    // the first line isn't too tall
    // when we use
    // history_item_tall.xml
    } else {
        int delta = historyItem.getDelta();
        SpannableString deltaSpannable = new SpannableString(IntegerUtil.toCharSequenceWithSign(delta));
        int colorResId = delta >= 0 ? (PreferenceHelper.getGreenTextPreference(activity) ? // green
        ColorScheme.Light.getGreenPositiveColorResId() : // blue
        ColorScheme.Light.getPositiveColorResId()) : // red
        ColorScheme.Light.getNegativeColorResId();
        ForegroundColorSpan colorSpan = new ForegroundColorSpan(getResources().getColor(colorResId));
        deltaSpannable.setSpan(colorSpan, 0, deltaSpannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        textView1.setVisibility(View.VISIBLE);
        textView1.setText(deltaSpannable);
    }
    textView2.setText(Long.toString(historyItem.getRunningTotal()));
    return weightIsOne ? setLayoutWeightToOne(view) : view;
}
Also used : SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View)

Example 22 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project plaid by nickbutcher.

the class HomeActivity method setNoFiltersEmptyTextVisibility.

private void setNoFiltersEmptyTextVisibility(int visibility) {
    if (visibility == View.VISIBLE) {
        if (noFiltersEmptyText == null) {
            // create the no filters empty text
            ViewStub stub = (ViewStub) findViewById(R.id.stub_no_filters);
            noFiltersEmptyText = (TextView) stub.inflate();
            String emptyText = getString(R.string.no_filters_selected);
            int filterPlaceholderStart = emptyText.indexOf('ࢴ');
            int altMethodStart = filterPlaceholderStart + 3;
            SpannableStringBuilder ssb = new SpannableStringBuilder(emptyText);
            // show an image of the filter icon
            ssb.setSpan(new ImageSpan(this, R.drawable.ic_filter_small, ImageSpan.ALIGN_BASELINE), filterPlaceholderStart, filterPlaceholderStart + 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);
            noFiltersEmptyText.setText(ssb);
            noFiltersEmptyText.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    drawer.openDrawer(GravityCompat.END);
                }
            });
        }
        noFiltersEmptyText.setVisibility(visibility);
    } else if (noFiltersEmptyText != null) {
        noFiltersEmptyText.setVisibility(visibility);
    }
}
Also used : ViewStub(android.view.ViewStub) ForegroundColorSpan(android.text.style.ForegroundColorSpan) StyleSpan(android.text.style.StyleSpan) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) SpannableStringBuilder(android.text.SpannableStringBuilder) ImageSpan(android.text.style.ImageSpan)

Example 23 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project MarqueeView by sfsheng0322.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    marqueeView = (MarqueeView) findViewById(R.id.marqueeView);
    marqueeView1 = (MarqueeView) findViewById(R.id.marqueeView1);
    marqueeView2 = (MarqueeView) findViewById(R.id.marqueeView2);
    marqueeView3 = (MarqueeView) findViewById(R.id.marqueeView3);
    marqueeView4 = (MarqueeView) findViewById(R.id.marqueeView4);
    List<CharSequence> list = new ArrayList<>();
    SpannableString ss1 = new SpannableString("1、MarqueeView项目");
    ss1.setSpan(new ForegroundColorSpan(Color.RED), 2, 13, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    list.add(ss1);
    SpannableString ss2 = new SpannableString("2、GitHub:sfsheng0322");
    ss2.setSpan(new ForegroundColorSpan(Color.GREEN), 9, 20, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    list.add(ss2);
    SpannableString ss3 = new SpannableString("3、个人博客:sunfusheng.com");
    ss3.setSpan(new URLSpan("http://sunfusheng.com/"), 7, 21, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    list.add(ss3);
    list.add("4、孙福生微博,请粉哦");
    marqueeView.startWithList(list);
    marqueeView1.startWithText(getString(R.string.marquee_texts));
    marqueeView2.startWithText(getString(R.string.marquee_texts));
    marqueeView3.startWithText(getString(R.string.marquee_texts));
    marqueeView4.startWithText(getString(R.string.marquee_text));
    marqueeView.setOnItemClickListener(new MarqueeView.OnItemClickListener() {

        @Override
        public void onItemClick(int position, TextView textView) {
            Toast.makeText(getApplicationContext(), textView.getText() + "", Toast.LENGTH_SHORT).show();
        }
    });
    marqueeView1.setOnItemClickListener(new MarqueeView.OnItemClickListener() {

        @Override
        public void onItemClick(int position, TextView textView) {
            Toast.makeText(getApplicationContext(), String.valueOf(marqueeView1.getPosition()) + ". " + textView.getText(), Toast.LENGTH_SHORT).show();
        }
    });
}
Also used : SpannableString(android.text.SpannableString) MarqueeView(com.sunfusheng.marqueeview.MarqueeView) ForegroundColorSpan(android.text.style.ForegroundColorSpan) ArrayList(java.util.ArrayList) TextView(android.widget.TextView) URLSpan(android.text.style.URLSpan)

Example 24 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project Conversations by siacs.

the class MessageAdapter method displayTextMessage.

private void displayTextMessage(final ViewHolder viewHolder, final Message message, boolean darkBackground, int type) {
    if (viewHolder.download_button != null) {
        viewHolder.download_button.setVisibility(View.GONE);
    }
    viewHolder.image.setVisibility(View.GONE);
    viewHolder.messageBody.setVisibility(View.VISIBLE);
    viewHolder.messageBody.setIncludeFontPadding(true);
    if (message.getBody() != null) {
        final String nick = UIHelper.getMessageDisplayName(message);
        SpannableStringBuilder body = message.getMergedBody();
        boolean hasMeCommand = message.hasMeCommand();
        if (hasMeCommand) {
            body = body.replace(0, Message.ME_COMMAND.length(), nick + " ");
        }
        if (body.length() > Config.MAX_DISPLAY_MESSAGE_CHARS) {
            body = new SpannableStringBuilder(body, 0, Config.MAX_DISPLAY_MESSAGE_CHARS);
            body.append("…");
        }
        Message.MergeSeparator[] mergeSeparators = body.getSpans(0, body.length(), Message.MergeSeparator.class);
        for (Message.MergeSeparator mergeSeparator : mergeSeparators) {
            int start = body.getSpanStart(mergeSeparator);
            int end = body.getSpanEnd(mergeSeparator);
            body.setSpan(new DividerSpan(true), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        boolean startsWithQuote = handleTextQuotes(body, darkBackground);
        if (message.getType() != Message.TYPE_PRIVATE) {
            if (hasMeCommand) {
                body.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, nick.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        } else {
            String privateMarker;
            if (message.getStatus() <= Message.STATUS_RECEIVED) {
                privateMarker = activity.getString(R.string.private_message);
            } else {
                final String to;
                if (message.getCounterpart() != null) {
                    to = message.getCounterpart().getResourcepart();
                } else {
                    to = "";
                }
                privateMarker = activity.getString(R.string.private_message_to, to);
            }
            body.insert(0, privateMarker);
            int privateMarkerIndex = privateMarker.length();
            if (startsWithQuote) {
                body.insert(privateMarkerIndex, "\n\n");
                body.setSpan(new DividerSpan(false), privateMarkerIndex, privateMarkerIndex + 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            } else {
                body.insert(privateMarkerIndex, " ");
            }
            body.setSpan(new ForegroundColorSpan(getMessageTextColor(darkBackground, false)), 0, privateMarkerIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            body.setSpan(new StyleSpan(Typeface.BOLD), 0, privateMarkerIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            if (hasMeCommand) {
                body.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), privateMarkerIndex + 1, privateMarkerIndex + 1 + nick.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
        if (message.getConversation().getMode() == Conversation.MODE_MULTI && message.getStatus() == Message.STATUS_RECEIVED) {
            Pattern pattern = NotificationService.generateNickHighlightPattern(message.getConversation().getMucOptions().getActualNick());
            Matcher matcher = pattern.matcher(body);
            while (matcher.find()) {
                body.setSpan(new StyleSpan(Typeface.BOLD), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
        Linkify.addLinks(body, XMPP_PATTERN, "xmpp");
        Linkify.addLinks(body, Patterns.AUTOLINK_WEB_URL, "http", WEBURL_MATCH_FILTER, WEBURL_TRANSFORM_FILTER);
        Linkify.addLinks(body, GeoHelper.GEO_URI, "geo");
        viewHolder.messageBody.setAutoLinkMask(0);
        viewHolder.messageBody.setText(body);
        viewHolder.messageBody.setTextIsSelectable(true);
        viewHolder.messageBody.setMovementMethod(ClickableMovementMethod.getInstance());
        listSelectionManager.onUpdate(viewHolder.messageBody, message);
    } else {
        viewHolder.messageBody.setText("");
        viewHolder.messageBody.setTextIsSelectable(false);
    }
    viewHolder.messageBody.setTextColor(this.getMessageTextColor(darkBackground, true));
    viewHolder.messageBody.setLinkTextColor(this.getMessageTextColor(darkBackground, true));
    viewHolder.messageBody.setHighlightColor(activity.getResources().getColor(darkBackground ? (type == SENT || !mUseGreenBackground ? R.color.black26 : R.color.grey800) : R.color.grey500));
    viewHolder.messageBody.setTypeface(null, Typeface.NORMAL);
}
Also used : Pattern(java.util.regex.Pattern) Message(eu.siacs.conversations.entities.Message) ForegroundColorSpan(android.text.style.ForegroundColorSpan) Matcher(java.util.regex.Matcher) SpannableString(android.text.SpannableString) StyleSpan(android.text.style.StyleSpan) DividerSpan(eu.siacs.conversations.ui.text.DividerSpan) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 25 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project Conversations by siacs.

the class FormFieldWrapper method createSpannableLabelString.

protected SpannableString createSpannableLabelString(String label, boolean required) {
    SpannableString spannableString = new SpannableString(label + (required ? " *" : ""));
    if (required) {
        int start = label.length();
        int end = label.length() + 2;
        spannableString.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), start, end, 0);
        spannableString.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.accent)), start, end, 0);
    }
    return spannableString;
}
Also used : SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan) StyleSpan(android.text.style.StyleSpan)

Aggregations

ForegroundColorSpan (android.text.style.ForegroundColorSpan)152 SpannableStringBuilder (android.text.SpannableStringBuilder)56 SpannableString (android.text.SpannableString)48 StyleSpan (android.text.style.StyleSpan)25 TextView (android.widget.TextView)24 ImageSpan (android.text.style.ImageSpan)23 RelativeSizeSpan (android.text.style.RelativeSizeSpan)21 View (android.view.View)21 Spannable (android.text.Spannable)20 BackgroundColorSpan (android.text.style.BackgroundColorSpan)18 TypefaceSpan (android.text.style.TypefaceSpan)16 StrikethroughSpan (android.text.style.StrikethroughSpan)14 UnderlineSpan (android.text.style.UnderlineSpan)13 Drawable (android.graphics.drawable.Drawable)12 EditText (android.widget.EditText)11 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)10 CharacterStyle (android.text.style.CharacterStyle)10 SuperscriptSpan (android.text.style.SuperscriptSpan)8 LinearLayout (android.widget.LinearLayout)8 URLSpan (android.text.style.URLSpan)7