@@ -147,156 +147,64 @@ void removeSpans(Editable e, Class<? extends CharacterStyle> type) {
147147 });
148148
149149 }
150-
151-
152-
153- //the user will be able to change color of the view as he wishes
154- public void setBgColor (String color ) throws Error {
155-
150+ //check string's type is color
151+ public void checkColor (String color )throws Error {
156152 color = color .trim ();
157153
158154 if (!color .contains ("#" )) {
159155 throw new Error ("SyntaxView Error : Invalid Color" );
160156 }
161157 if (TextUtils .isEmpty (color )) {
162158 throw new Error ("SyntaxView Error : Empty Color String" );
163-
164159 }
165160 if (color .length () != 7 ) {
166161 throw new Error ("SyntaxView Error : Unknown Color" );
167-
168162 }
169- code .setBackgroundColor (Color .parseColor (color ));
170163 }
171164
172- public void setKeywordsColor (String color ) throws Error {
173- color = color .trim ();
174-
175- if (!color .contains ("#" )) {
176- throw new Error ("SyntaxView Error : Invalid Color" );
177- }
178- if (TextUtils .isEmpty (color )) {
179- throw new Error ("SyntaxView Error : Empty Color String" );
180-
181- }
182- if (color .length () != 7 ) {
183- throw new Error ("SyntaxView Error : Unknown Color" );
165+ //the user will be able to change color of the view as he wishes
166+ public void setBgColor (String color ) {
167+ checkColor (color );
168+ code .setBackgroundColor (Color .parseColor (color ));
169+ }
184170
185- }
171+ public void setKeywordsColor (String color ) {
172+ checkColor (color );
186173 keywords .setColor (color );
187174 }
188175
189- public void setNumbersColor (String color ) throws Error {
190- color = color .trim ();
191-
192- if (!color .contains ("#" )) {
193- throw new Error ("SyntaxView Error : Invalid Color" );
194- }
195- if (TextUtils .isEmpty (color )) {
196- throw new Error ("SyntaxView Error : Empty Color String" );
197-
198- }
199- if (color .length () != 7 ) {
200- throw new Error ("SyntaxView Error : Unknown Color" );
201-
202- }
176+ public void setNumbersColor (String color ) {
177+ checkColor (color );
203178 numbers .setColor (color );
204179 }
205180
206- public void setSpecialCharsColor (String color ) throws Error {
207- color = color .trim ();
208-
209- if (!color .contains ("#" )) {
210- throw new Error ("SyntaxView Error : Invalid Color" );
211- }
212- if (TextUtils .isEmpty (color )) {
213- throw new Error ("SyntaxView Error : Empty Color String" );
214-
215- }
216- if (color .length () != 7 ) {
217- throw new Error ("SyntaxView Error : Unknown Color" );
218- }
181+ public void setSpecialCharsColor (String color ) {
182+ checkColor (color );
219183 special .setColor (color );
220184 }
221185
222- public void setCodeTextColor (String color ) throws Error {
223- color = color .trim ();
224-
225- if (!color .contains ("#" )) {
226- throw new Error ("SyntaxView Error : Invalid Color" );
227- }
228- if (TextUtils .isEmpty (color )) {
229- throw new Error ("SyntaxView Error : Empty Color String" );
230-
231- }
232- if (color .length () != 7 ) {
233- throw new Error ("SyntaxView Error : Unknown Color" );
234- }
186+ public void setCodeTextColor (String color ) {
187+ checkColor (color );
235188 code .setTextColor (Color .parseColor (color ));
236189 }
237190
238- public void setAnnotationsColor (String color ) throws Error {
239- color = color .trim ();
240-
241- if (!color .contains ("#" )) {
242- throw new Error ("SyntaxView Error : Invalid Color" );
243- }
244- if (TextUtils .isEmpty (color )) {
245- throw new Error ("SyntaxView Error : Empty Color String" );
246-
247- }
248- if (color .length () != 7 ) {
249- throw new Error ("SyntaxView Error : Unknown Color" );
250- }
191+ public void setAnnotationsColor (String color ) {
192+ checkColor (color );
251193 annotations .setColor (color );
252-
253194 }
254195
255- public void setPrintStatmentsColor (String color ) throws Error {
256- color = color .trim ();
257-
258- if (!color .contains ("#" )) {
259- throw new Error ("SyntaxView Error : Invalid Color" );
260- }
261- if (TextUtils .isEmpty (color )) {
262- throw new Error ("SyntaxView Error : Empty Color String" );
263-
264- }
265- if (color .length () != 7 ) {
266- throw new Error ("SyntaxView Error : Unknown Color" );
267- }
196+ public void setPrintStatmentsColor (String color ) {
197+ checkColor (color );
268198 printStatments .setColor (color );
269199 }
270200
271- public void setRowNumbersColor (String color ) throws Error {
272- color = color .trim ();
273-
274- if (!color .contains ("#" )) {
275- throw new Error ("SyntaxView Error : Invalid Color" );
276- }
277- if (TextUtils .isEmpty (color )) {
278- throw new Error ("SyntaxView Error : Empty Color String" );
279-
280- }
281- if (color .length () != 7 ) {
282- throw new Error ("SyntaxView Error : Unknown Color" );
283- }
201+ public void setRowNumbersColor (String color ) {
202+ checkColor (color );
284203 rows .setTextColor (Color .parseColor (color ));
285204 }
286205
287- public void setRowNumbersBgColor (String color ) throws Error {
288- color = color .trim ();
289-
290- if (!color .contains ("#" )) {
291- throw new Error ("SyntaxView Error : Invalid Color" );
292- }
293- if (TextUtils .isEmpty (color )) {
294- throw new Error ("SyntaxView Error : Empty Color String" );
295-
296- }
297- if (color .length () != 7 ) {
298- throw new Error ("SyntaxView Error : Unknown Color" );
299- }
206+ public void setRowNumbersBgColor (String color ) {
207+ checkColor (color );
300208 rows .setBackgroundColor (Color .parseColor (color ));
301209 }
302210
0 commit comments