22
33[ ![ Android Arsenal] ( https://img.shields.io/badge/Android%20Arsenal-codeview--android-green.svg?style=true )] ( https://android-arsenal.com/details/1/4216 )
44[ ![ Release] ( https://jitpack.io/v/softwee/codeview-android.svg )] ( https://jitpack.io/#softwee/codeview-android )
5+ [ ![ Build Status] ( https://travis-ci.org/Softwee/codeview-android.svg?branch=master )] ( https://travis-ci.org/Softwee/codeview-android )
56
67CodeView helps to show code content with syntax highlighting in native way.
78
@@ -27,7 +28,7 @@ allprojects {
2728
2829Add the dependency:
2930``` groovy
30- compile 'com.github.softwee:codeview-android:1.3.0 '
31+ compile 'com.github.softwee:codeview-android:1.1.2 '
3132```
3233
3334## Usage
@@ -42,106 +43,100 @@ Add view for your layout:
4243<io .github.kbiakov.codeview.CodeView
4344 android:id=" @+id/code_view"
4445 android:layout_width=" wrap_content"
45- android:layout_height=" wrap_content"
46- app:animateOnStart=" true" />
46+ android:layout_height=" wrap_content" />
4747```
4848
4949Use chaining syntax when build view:
5050``` java
5151CodeView codeView = (CodeView ) findViewById(R . id. code_view);
5252
53- new Highlighter (this )
54- .theme(ColorTheme . SOLARIZED_LIGHT. withBgContent(myColor))
55- .code(R . string. listing_js)
56- .language(" js" )
57- .highlight(codeView);
53+ codeView. highlightCode(" js" )
54+ .setColorTheme(ColorTheme . SOLARIZED_LIGHT. withBgContent(myColor))
55+ .setCodeContent(getString(R . string. listing_js));
5856```
59- or
60- ``` java
61- Highlighter h = new Highlighter (this )
62- .code(R . string. listing_java)
63- .shortcut(true )
64- .maxLines(10 )
65- .shortcutNote(" Show all" )
66- .language(" java" );
6757
68- codeView. init(h);
58+ And perform actions sequentially when view built:
59+ ``` java
60+ codeView. setCodeContent(getString(R . string. listing_java));
61+ codeView. highlightCode(" java" );
6962```
7063
71- Use CodeView.init() or use Highlighter. highlight(codeView) to init adapter and start highlighting .
64+ You can use both forms for build & built view, but note: ``` setCodeContent(String) ``` is final step when you build your view, otherwise not. If you firstly highlight and then set code content, code will not be highlighted if view was not built yet. Instructions above helps you to avoid errors. View has state to handle this behavior .
7265
7366## Customizing
67+ Use implicit form to code highlighting:
68+ ``` java
69+ codeView. highlightCode();
70+ ```
71+ or eplixit (see available extensions below):
7472``` java
75- .language(" js" ) // it will work fast!
76- .code(content)
77- .theme(ColorTheme . DEFAULT )
78- .shortcut(true )
79- .maxLines(6 )
80- .shortcutNote(" Show All" )
81- .lineClickListener(new OnCodeLineClickListener (){})
82- .shadows(true )
73+ codeView. highlightCode(" js" ); // it will work fast!
8374```
8475
85- Extend default color theme:
76+ Use default color theme:
77+ ``` java
78+ codeView. setColorTheme(ColorTheme . SOLARIZED_LIGHT );
79+ ```
80+ or extend default:
8681``` java
87- int myColor = ContextCompat . getColor(this , R . color. code_content_background );
88- .theme (ColorTheme . SOLARIZED_LIGHT . withBgContent(myColor));
82+ int myColor = ContextCompat . getColor(this , R . color. my_color );
83+ codeView . setColorTheme (ColorTheme . MONOKAI . withBgContent(myColor));
8984```
9085or provide your own (don't forget to open PR with this stuff!)
9186``` java
92- .theme (new ColorThemeData (new SyntaxColors (... ), ... ));
87+ codeView . setColorTheme (new ColorThemeData (new SyntaxColors (... ), ... ));
9388```
9489
9590Handle user clicks on code lines:
9691``` java
97- .lineClickListener (new OnCodeLineClickListener () {
92+ codeView . setCodeListener (new OnCodeLineClickListener () {
9893 @Override
99- public void onLineClicked (int n , @NotNull String line ) {
94+ public void onCodeLineClicked (int n , @NotNull String line ) {
10095 Log . i(" ListingsActivity" , " On " + (n + 1 ) + " line clicked" );
10196 }
10297});
10398```
10499
105- Enable shadows to hide scrolled code :
100+ Enable shadows to hide scrolled content :
106101``` java
107- .shadows (true );
102+ codeView . setShadowsEnabled (true );
108103```
109104
110105## Adapter customization
111106Sometimes you may want to add some content under line. You can create your own implementation as follows:
112107
1131081 . Create your model to store data, for example some ``` MyModel ``` class.<br >
114- 2 . Extend ``` CodeAdapter <MyModel>``` typed by your model class.<br >
115- 3 . Implement necessary methods in obtained ``` MyCodeAdapter<MyModel> ``` :
109+ 2 . Extend ``` AbstractCodeAdapter <MyModel>``` typed by your model class.<br >
110+ 3 . Implement necessary methods in obtained ``` MyCodeAdapter ``` :
116111``` kotlin
117112// Kotlin
118- class MyCodeAdapter : CodeAdapter <MyModel > {
119- constructor (context: Context , code : String , theme : ColorThemeData ) : super (context, code, theme )
113+ class MyCodeAdapter : AbstractCodeAdapter <MyModel > {
114+ constructor (context: Context , content : String ) : super (context, content )
120115
121116 override fun createFooter (context : Context , entity : MyModel , isFirst : Boolean ) =
122117 /* init & return your view here */
123118}
124119```
125120``` java
126121// Java
127- public class MyCodeAdapter extends CodeAdapter <MyModel > {
128- public CustomAdapter (@NotNull Context context , @NotNull String code , @NotNull ColorThemeData theme ) {
129- // @see params in CodeAdapter
130- super (context, code, theme , true , 10 , context. getString(R . string. show_all), null );
122+ public class MyCodeAdapter extends AbstractCodeAdapter <MyModel > {
123+ public CustomAdapter (@NotNull Context context , @NotNull String content ) {
124+ // @see params in AbstractCodeAdapter
125+ super (context, content , true , 10 , context. getString(R . string. show_all), null );
131126 }
132127
133128 @NotNull
134129 @Override
135130 public View createFooter (@NotNull Context context , CustomModel entity , boolean isFirst ) {
136- return /* init your view here */ ;
131+ return /* your initialized view here */ ;
137132 }
138133}
139134```
140135<br >
1411364 . Set custom adapter to your code view:
142137``` java
143- final MyCodeAdapter adapter = new MyCodeAdapter (this , getString(R . string. listing_py), ColorTheme . SOLARIZED_LIGHT . theme() );
144- codeView. init (diffsAdapter);
138+ final MyCodeAdapter adapter = new MyCodeAdapter (this , getString(R . string. listing_py));
139+ codeView. setAdapter (diffsAdapter);
145140```
146141<br >
1471425 . Init footer entities to provide mapper from your view to model:
@@ -154,7 +149,7 @@ adapter.addFooterEntity(11, new MyModel(getString(R.string.py_deletion_11), fals
154149<br >
1551506 . You can also add a multiple diff entities:
156151``` java
157- CodeAdapter <MyModel >. addFooterEntities(HashMap<Int , List<MyModel > > myEntities)
152+ AbstractCodeAdapter <MyModel >. addFooterEntities(HashMap<Int , List<MyModel > > myEntities)
158153```
159154Here you must provide a map from code line numbers (started from 0) to list of line entities. It will be mapped by adapter to specified footer views.
160155<br >
@@ -169,9 +164,9 @@ See <a href="https://github.com/Softwee/codeview-android/blob/master/example/src
169164[ ![ CodeView_Android_Default] ( https://s10.postimg.org/u2meb8o6x/Screen_Shot_2016_08_31_at_18_49_33.png )] ( https://s10.postimg.org/u2meb8o6x/Screen_Shot_2016_08_31_at_18_49_33.png )
170165
171166## List of available languages & their extensions
172- C/C++/Objective-C (```"c"```, ```"cc"```, ```"cpp"```, ```"cxx"```, ```"cyc"```, ```"m"```), C# (```"cs"```), Java (```"java"```),Bash (```"bash"```, ```"bsh"```, ```"csh"```, ```"sh"```), Python (```"cv"```, ```"py"```, ```"python"```), Perl (```"perl"```, ```"pl"```, ```"pm"```), Ruby (```"rb"```, ```"ruby"```), JavaScript (```"javascript"```, ```"js"```), CoffeeScript (```"coffee"```), Rust (```"rc"```, ```"rs"```, ```"rust"```), Appollo (```"apollo"```, ```"agc"```, ```"aea"```), Basic (```"basic"```, ```"cbm"```), Clojure (```"clj"```), Css (```"css"```), Dart (```"dart"```), Erlang (```"erlang"```, ```"erl"```), Go (```"go"```), Haskell (```"hs"```), Lisp (```"cl"```, ```"el"```, ```"lisp"```, ```"lsp"```, ```"scm"```, ```"ss"```, ```"rkt"```), Llvm (```"llvm"```, ```"ll"```), Lua (```"lua"```), Matlab (```"matlab"```), ML (OCaml, SML, F#, etc) (```"fs"```, ```"ml"```), Mumps (```"mumps"```), N (```"n"```, ```"nemerle"```), Pascal (```"pascal"```), R (```"r"```, ```"s"```, ```"R"```, ```"S"```, ```"Splus"```), Rd (```"Rd"```, ```"rd"```), Scala (```"scala"```), SQL (```"sql"```), Tex (```"latex"```, ```"tex"```), VB (```"vb"```, ```"vbs"```), VHDL (```"vhdl"```, ```"vhd"```), Tcl (```"tcl"```), Wiki (```"wiki.meta"```), XQuery (```"xq"```, ```"xquery"```), YAML (```"yaml"```, ```"yml"```), Markdown (```"md"```, ```"markdown"```), formats (```"json"```, ```"xml"```, ```"proto"```), ```"regex"```
167+ C/C++/Objective-C (```"c"```, ```"cc"```, ```"cpp"```, ```"cxx"```, ```"cyc"```, ```"m"```), C# (```"cs"```), Java (```"java"```), Bash (```"bash"```, ```"bsh"```, ```"csh"```, ```"sh"```), Python (```"cv"```, ```"py"```, ```"python"```), Perl (```"perl"```, ```"pl"```, ```"pm"```), Ruby (```"rb"```, ```"ruby"```), JavaScript (```"javascript"```, ```"js"```), CoffeeScript (```"coffee"```), Rust (```"rc"```, ```"rs"```, ```"rust"```), Appollo (```"apollo"```, ```"agc"```, ```"aea"```), Basic (```"basic"```, ```"cbm"```), Clojure (```"clj"```), Css (```"css"```), Dart (```"dart"```), Erlang (```"erlang"```, ```"erl"```), Go (```"go"```), Haskell (```"hs"```), Lisp (```"cl"```, ```"el"```, ```"lisp"```, ```"lsp"```, ```"scm"```, ```"ss"```, ```"rkt"```), Llvm (```"llvm"```, ```"ll"```), Lua (```"lua"```), Matlab (```"matlab"```), ML (OCaml, SML, F#, etc) (```"fs"```, ```"ml"```), Mumps (```"mumps"```), N (```"n"```, ```"nemerle"```), Pascal (```"pascal"```), R (```"r"```, ```"s"```, ```"R"```, ```"S"```, ```"Splus"```), Rd (```"Rd"```, ```"rd"```), Scala (```"scala"```), SQL (```"sql"```), Tex (```"latex"```, ```"tex"```), VB (```"vb"```, ```"vbs"```), VHDL (```"vhdl"```, ```"vhd"```), Tcl (```"tcl"```), Wiki (```"wiki.meta"```), XQuery (```"xq"```, ```"xquery"```), YAML (```"yaml"```, ```"yml"```), Markdown (```"md"```, ```"markdown"```), formats (```"json"```, ```"xml"```, ```"proto"```), ```"regex"```
173168
174- Didn't found yours? Please, open issue to show your interest & I try to add this language in next releases.
169+ Didn't found yours? Please, open issue to show your interest & I'll try to add this language in next releases.
175170
176171## List of available themes
1771721 . Default (simple light theme)
0 commit comments