@@ -35,25 +35,26 @@ protected void onCreate(Bundle savedInstanceState) {
3535
3636 binding = ActivityMainBinding .inflate (getLayoutInflater ());
3737 setContentView (binding .getRoot ());
38- configToolbar ();
39- initHighlightExample ();
38+
39+ highlightExample ();
40+ highlightListenerExample ();
4041 }
4142
42- private void configToolbar () {
43+ private void highlightExample () {
4344
4445 Highlight highlight = new Highlight ();
4546
47+ //add scheme
4648 highlight .addScheme (
4749 new StyleScheme (
4850 Pattern .compile ("Highlight" ),
4951 StyleScheme .STYLE .BOLD_ITALIC
50- )
51- );
52-
53- highlight .addScheme (
54- new ColorScheme (
55- Pattern .compile ("light" ),
56- Color .parseColor ("#FF03DAC5" )
52+ ).addScopeScheme (
53+ //add scheme scheme
54+ new ColorScheme (
55+ Pattern .compile ("light" ),
56+ Color .parseColor ("#FF03DAC5" )
57+ )
5758 )
5859 );
5960
@@ -69,7 +70,7 @@ private void configToolbar() {
6970 }
7071
7172
72- private void initHighlightExample () {
73+ private void highlightListenerExample () {
7374 HighlightTextWatcher highlightTextWatcher =
7475 new HighlightTextWatcher ();
7576
@@ -87,73 +88,103 @@ private void initHighlightExample() {
8788 )
8889 );
8990
91+ //StrikethroughSpan custom scheme example
92+ Scheme strikeScheme = new Scheme () {
93+
94+ final Pattern pattern =
95+ Pattern .compile (".+" );
96+
97+ @ Override
98+ public Pattern getRegex () {
99+ return pattern ;
100+ }
101+
102+ @ Override
103+ public Object getSpan (@ NonNull CharSequence text ) {
104+ return new StrikethroughSpan ();
105+ }
106+
107+ @ Override
108+ public boolean getClearOldSpan () {
109+ return false ;
110+ }
111+
112+ @ Override
113+ public Scheme setClearOldSpan (boolean clearOldSpan ) {
114+ return this ;
115+ }
116+ };
90117 highlightTextWatcher .addScheme (
91118 new ColorScheme (
92119 Pattern .compile ("\\ b([Jj])ava([Ss])cript\\ b" ),
93120 Color .parseColor ("#F5E200" )
121+ ).addScopeScheme (
122+ //add in ColorScheme scope
123+ strikeScheme
94124 )
95125 );
96126
127+ //UnderlineSpan custom scheme example
128+ Scheme underlineScheme = new Scheme () {
129+ final Pattern pattern =
130+ Pattern .compile (".+" );
131+
132+ @ Override
133+ public Pattern getRegex () {
134+ return pattern ;
135+ }
136+
137+ @ Override
138+ public Object getSpan (@ NonNull CharSequence text ) {
139+ return new UnderlineSpan ();
140+ }
141+
142+ @ Override
143+ public boolean getClearOldSpan () {
144+ return false ;
145+ }
146+
147+ @ Override
148+ public Scheme setClearOldSpan (boolean clearOldSpan ) {
149+ return this ;
150+ }
151+ };
152+
97153 highlightTextWatcher .addScheme (
98154 new ColorScheme (
99155 Pattern .compile ("\\ b([Aa])ndroid\\ b" ),
100156 Color .parseColor ("#00CA0E" )
157+ ).addScopeScheme (
158+ //add in ColorScheme scope
159+ underlineScheme
101160 )
102161 );
103162
163+ //scheme scope example
104164 highlightTextWatcher .addScheme (
105165 new StyleScheme (
106166 Pattern .compile ("\\ b([Hh])ighlight\\ b" ),
107167 StyleScheme .STYLE .BOLD_ITALIC
168+ ).addScopeScheme (
169+ //add OnClickScheme in StyleScheme scope
170+ new OnClickScheme (
171+ Pattern .compile (".+" ),
172+ (CharSequence text ) -> showToast ()
173+ ),
174+ //add ColorScheme in StyleScheme scope
175+ new ColorScheme (
176+ Pattern .compile ("light" ),
177+ Color .parseColor ("#FF03DAC5" )
178+ ).addScopeScheme (
179+ //add ColorScheme in ColorScheme scope
180+ new ColorScheme (
181+ Pattern .compile ("gh" ),
182+ Color .RED
183+ )
184+ )
108185 )
109186 );
110187
111- //custom example
112- highlightTextWatcher .addScheme (
113- new Scheme () {
114- final Pattern pattern =
115- Pattern .compile ("\\ b([Jj])ava([Ss])cript\\ b" );
116-
117- @ Override
118- public Pattern getRegex () {
119- return pattern ;
120- }
121-
122- @ Override
123- public Object getSpan (@ NonNull CharSequence text ) {
124- return new StrikethroughSpan ();
125- }
126-
127- @ Override
128- public boolean getClearOldSpan () {
129- return false ;
130- }
131- }
132- );
133-
134- //custom example 2
135- highlightTextWatcher .addScheme (
136- new Scheme () {
137- final Pattern pattern =
138- Pattern .compile ("\\ b([Hh])ighlight\\ b" );
139-
140- @ Override
141- public Pattern getRegex () {
142- return pattern ;
143- }
144-
145- @ Override
146- public Object getSpan (@ NonNull CharSequence text ) {
147- return new UnderlineSpan ();
148- }
149-
150- @ Override
151- public boolean getClearOldSpan () {
152- return false ;
153- }
154- }
155- );
156-
157188 highlightTextWatcher .addSpanType (StrikethroughSpan .class );
158189
159190 //add link scheme
@@ -164,16 +195,12 @@ public boolean getClearOldSpan() {
164195
165196 binding .edittext .setMovementMethod (LinkMovementMethod .getInstance ());
166197
167- //add click scheme
168-
169- highlightTextWatcher .addScheme (
170- new OnClickScheme (Pattern .compile ("[hH]ighlight" ), (CharSequence text ) -> showToast ())
171- );
172-
173198 highlightTextWatcher .addScheme (
174199 new OnClickScheme (Pattern .compile ("Irineu A\\ . Silva" ), (CharSequence text ) ->
175200 goToMyGithub ()
176- ).setPainTextColor (Color .GRAY )
201+ ).setPainTextColor (
202+ Color .GREEN
203+ ).setPainTextUnderline (true )
177204 );
178205
179206 binding .edittext .addTextChangedListener (highlightTextWatcher );
0 commit comments