Makeup

Additional

Language
N/A
Version
N/A
Created
Nov 27, 2014
Updated
Dec 17, 2018 (Retired)
Owner
Trikke
Activity
N/A
Badge
Generate
Download
Source code

Show card

File (2 KB): Makeup

package trikke.gists;

import android.graphics.Typeface;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.BackgroundColorSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.StrikethroughSpan;
import android.text.style.StyleSpan;
import android.text.style.UnderlineSpan;

public class Makeup
{
	private final Spannable sb;

	public Makeup( String input )
	{
		sb = new SpannableString( input );
	}

	public Makeup strikethrough( int start, int length )
	{
		final StrikethroughSpan span = new StrikethroughSpan();
		sb.setSpan( span, start, start + length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE );
		return this;
	}

	public Makeup underline( int start, int length )
	{
		final UnderlineSpan span = new UnderlineSpan();
		sb.setSpan( span, start, start + length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE );
		return this;
	}

	public Makeup boldify( int start, int length )
	{
		final StyleSpan span = new StyleSpan( android.graphics.Typeface.BOLD );
		sb.setSpan( span, start, start + length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE );
		return this;
	}

	public Makeup italize( int start, int length )
	{
		final StyleSpan span = new StyleSpan( Typeface.ITALIC );
		sb.setSpan( span, start, start + length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE );
		return this;
	}

	public Makeup colorize( int start, int length, int color )
	{
		final ForegroundColorSpan span = new ForegroundColorSpan( color );
		sb.setSpan( span, start, start + length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE );
		return this;
	}

	public Makeup mark( int start, int length, int color )
	{
		final BackgroundColorSpan span = new BackgroundColorSpan( color );
		sb.setSpan( span, start, start + length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE );
		return this;
	}

	public Makeup proportionate( int start, int length, float proportion )
	{
		final RelativeSizeSpan span = new RelativeSizeSpan( proportion );
		sb.setSpan( span, start, start + length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE );
		return this;
	}

	public Spannable apply()
	{
		return sb;
	}
}