java - Optimize EditText Syntax Highlighting ( Spannable ) -


im developing android code editor, when apply syntax highlighting it, laggy, there way optimize it?

here code:

 protected void oncreate(bundle savedinstancestate) {       scripteditor.addtextchangedlistener(new textwatcher() {               @              override              public void aftertextchanged(editable s) {                  applysyntax(s);              }          };      }      public void applysyntax(spannable spannable) {          matchz = wordpat.matcher(spannable);          while (matchz.find()) {              integer color = null;              if (stringkeyword.contains(matchz.group())) {                  color = integer.valueof(keycolor);                  type = "keyword";              }              if (stringkeyword2.contains(matchz.group())) {                  color = integer.valueof(keycolor2);                  type = "keyword";              }              if (stringkeyword3.contains(matchz.group())) {                  color = integer.valueof(keycolor3);                  type = "keyword";              }              if (color != null) {                  spannable.setspan(new foregroundcolorspan(color.intvalue()), matchz.start(), matchz.end(), 0);                  color = null;              } else {                  spannable.setspan(new foregroundcolorspan(color.white), matchz.start(), matchz.end(), 0);              }          }      }  } 

you can use syntax highlighting code in project: https://github.com/vmihalachi/turbo-editor

(see "editor" class in mainactivity.java)

you should highlight only visible part, not text @ once.

(p.s apologize if there errors in text, i bad know english)


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -