-
-
Save devrath/060e80f4b113dfc07e7b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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