Android Question Highlighting Text Editor/Viewer?

andrewj

Active Member
Licensed User
Longtime User
Hi,
Is anyone aware of a library for Android which works as a general-purpose text file viewer (or ideally editor), preferably with syntax highlighting for common coding languages, XML etc.?

I don't think there's anything in our existing B4A library collection, but if there's a good Java library I might be getting brave enough to write a wrapper for it (and share that back to our community).

Any ideas?
Thanks
Andrew
 

ELCHARO

Member
Licensed User
Longtime User
Hi Andrewj:

I write a class to make some highlighting.
Are all in the SourceColor.bas file
In this file you define the color behavior, and have a simple basic coloring system.
In line editing ( like function calc) work well, but in large file are not very response when editing.
(No problem if you call the color function sending the line you change instead full source).


USE:

Dim myclasscolor as SourceColor

myclasscolor.Initalize


MyTextEdit.Text = myclasscolor.Sourcecolor("Any String you wont, and return RichString")


Of course previus in sourcecolor.bas you create a map of WORDS and colors you need


Maps of 10 level colors for parentesis and control basic funcions. (see foto and source)

LCOL.Initialize2(Array As Int (Colors.blue,Colors.RGB(255,128,0),Colors.RGB(180,100,255),Colors......

' Color of numbers and comments.
numcolor = Colors.rgb(204,0,102)
commcolor = Colors.rgb(170,70,0)

' Maps of any words you like , and his color. ALL IN UPPERCASE (or change the source code if you Need OtHer use)
default_map.put("SQRT",Colors.red) 'For calc
default_map.put("ABS",Colors.Cyan)
default_map.put("LOGARITHM",Colors.Green)
default_map.put("SIN",Colors.blue)
default_map.put("COS",Colors.blue)
default_map.put("TAN",Colors.blue)
default_map.put("ASIN",Colors.blue)
default_map.put("ACOS",Colors.blue)
default_map.put("ATAN",Colors.blue)
default_map.put("POWER",Colors.Blue)
default_map.put("EX",Colors.blue)
default_map.put("PI",Colors.RED)
default_map.put("E",Colors.blue)
default_map.put("FLOOR",Colors.blue)
default_map.put("MOD",Colors.blue)


' 3 more maps are for basic behavior
basicopen_map.put("IF",Colors.green)
basicopen_map.put("SELECT",Colors.green)
basicopen_map.put("REGION",Colors.green)
basicopen_map.put("SUB",Colors.green)
basicopen_map.put("FOR",Colors.green)
basicopen_map.put("DO",Colors.green)

' command control body, no color needed, added by source // palabras que forman parte de las desiciones
basicmisc_map.put("CASE",Colors.green)
basicmisc_map.put("THEN",Colors.green)
basicmisc_map.put("ELSE",Colors.green)
basicmisc_map.put("TO",Colors.green)
basicmisc_map.put("WHILE",Colors.green)

' command control enders, no color needed, added by source // palabras que finalizan de las desiciones
basicclose_map.put("END",Colors.green)
basicclose_map.put("NEXT",Colors.green)
basicclose_map.put("LOOP",Colors.green)


Pulse CTROL-B and have to conditionals BASIC and NONBASIC


Basic are a little example of source color. You can change the behavior here for other languages.
( remenber i you need to edit a long lines text make slow the responde, work with lines coloring instead full source)

The call of Richstring functions are the most expensive in time, not this source. I not know other faster way. Any know? Tell me please!!!



Color change if indent parentesis like ((())) , in basic inner desicion functions change color too.

IF (x) THEN
IF (Z) THEN
...

END IF
END IF

THE UNDERLINE IS FOR GENYMOTION EMULATION, IN THE PHONE SEE WELL.

upload_2015-5-1_21-37-58.png



Read and change the code as your needs. Feedback are welcome, español/inglish, if you wont.
BY.
 

Attachments

  • RichSouto.zip
    198.5 KB · Views: 327
Last edited:
Upvote 0
Top