Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.