I have to show Java code snippets into my Android APP. What I want: Save te snippet in database in plain String format. Like:
"public class Whatever {public static void main(String[] args) {new Whatever().print(3);}void print (int x){ System.out.println(x); }}"
After I import the snippet from database I have to show it on Android screen well-formated/indented, like here in StackOverflow:
public class Whatever {
public static void main(String[] args) {
new Whatever().print(3);
}
void print (int x){
System.out.println(x);
}
}
Is there a way to do it in Android without create/implement my own Java Code Formatter algorithm?
EDIT
Some more information:
I need only format the code. I don't want a syntax highlighting because I need something that is not dependent of code editor. So I will retrieve the code from database and apply the format and it will run in any simply text editor.
I looked through other questions, but most of then requires to embed some external code or requires some container, like Swing (java-prettify), WebKit (android-codepad, etc). Eclipse have a code formatter, but It depends on a "TextEdit" component. But I will test it and try to extract plain text from it.
I cannot store the source code formatted with spaces/tabs, because most of time I will not touch the code.
I need that it recognize java 8 code blocks.
EDIT
Here are some other options I will try as suggest in the answeres. But most are outdated.
This is exactly what I need, but I need free :\