@@ -27,7 +27,7 @@ allprojects {
2727
2828Add the dependency:
2929``` groovy
30- compile 'com.github.softwee:codeview-android:1.2 .0'
30+ compile 'com.github.softwee:codeview-android:1.3 .0'
3131```
3232
3333## Usage
@@ -42,84 +42,92 @@ Add view for your layout:
4242<io .github.kbiakov.codeview.CodeView
4343 android:id=" @+id/code_view"
4444 android:layout_width=" wrap_content"
45- android:layout_height=" wrap_content" />
45+ android:layout_height=" wrap_content"
46+ app:animateOnStart=" true" />
4647```
4748
4849Use chaining syntax when build view:
4950``` java
5051CodeView codeView = (CodeView ) findViewById(R . id. code_view);
5152
52- codeView. colorTheme(ColorTheme . SOLARIZED_LIGHT. withBgContent(myColor))
53- .codeContent(getString(R . string. listing_js))
54- .highlight(" js" );
53+ new Highlighter (this )
54+ .theme(ColorTheme . SOLARIZED_LIGHT. withBgContent(myColor))
55+ .code(R . string. listing_js)
56+ .language(" js" )
57+ .highlight(codeView);
5558```
56-
57- And perform actions sequentially when view built:
59+ or
5860``` java
59- codeView. codeContent(getString(R . string. listing_java));
60- codeView. highlight(" java" );
61- ```
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" );
6267
63- Please firstly set adapter or use codeView.codeContent().
64- And finally you must call highlight() to process highlighting.
68+ codeView. init(h);
69+ ```
6570
71+ Use CodeView.init() or use Highlighter.highlight(codeView) to init adapter and start highlighting.
6672
6773## Customizing
68- Use implicit form to code highlighting:
69- ``` java
70- codeView. highlight();
71- ```
72- or eplixit (see available extensions below):
7374``` java
74- codeView. highlight(" js" ); // it will work fast!
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 )
7583```
7684
7785Extend default color theme:
7886``` java
7987int myColor = ContextCompat . getColor(this , R . color. code_content_background);
80- codeView . colorTheme (ColorTheme . SOLARIZED_LIGHT. withBgContent(myColor));
88+ .theme (ColorTheme . SOLARIZED_LIGHT. withBgContent(myColor));
8189```
8290or provide your own (don't forget to open PR with this stuff!)
8391``` java
84- codeView . colorTheme (new ColorThemeData (new SyntaxColors (... ), ... ));
92+ .theme (new ColorThemeData (new SyntaxColors (... ), ... ));
8593```
8694
8795Handle user clicks on code lines:
8896``` java
89- codeView . codeListener (new OnCodeLineClickListener () {
97+ .lineClickListener (new OnCodeLineClickListener () {
9098 @Override
91- public void onCodeLineClicked (int n , @NotNull String line ) {
99+ public void onLineClicked (int n , @NotNull String line ) {
92100 Log . i(" ListingsActivity" , " On " + (n + 1 ) + " line clicked" );
93101 }
94102});
95103```
96104
97- Enable shadows to hide scrolled content :
105+ Enable shadows to hide scrolled code :
98106``` java
99- codeView . setShadowsEnabled (true );
107+ .shadows (true );
100108```
101109
102110## Adapter customization
103111Sometimes you may want to add some content under line. You can create your own implementation as follows:
104112
1051131 . Create your model to store data, for example some ``` MyModel ``` class.<br >
106- 2 . Extend ``` AbstractCodeAdapter <MyModel>``` typed by your model class.<br >
114+ 2 . Extend ``` CodeAdapter <MyModel>``` typed by your model class.<br >
1071153 . Implement necessary methods in obtained ``` MyCodeAdapter<MyModel> ``` :
108116``` kotlin
109117// Kotlin
110- class MyCodeAdapter : AbstractCodeAdapter <MyModel > {
111- constructor (context: Context , content : String , colorTheme : ColorThemeData ) : super (context, content, colorTheme )
118+ class MyCodeAdapter : CodeAdapter <MyModel > {
119+ constructor (context: Context , code : String , theme : ColorThemeData ) : super (context, code, theme )
112120
113121 override fun createFooter (context : Context , entity : MyModel , isFirst : Boolean ) =
114122 /* init & return your view here */
115123}
116124```
117125``` java
118126// Java
119- public class MyCodeAdapter extends AbstractCodeAdapter <MyModel > {
120- public CustomAdapter (@NotNull Context context , @NotNull String content , @NotNull ColorThemeData colorTheme ) {
121- // @see params in AbstractCodeAdapter
122- super (context, content, colorTheme , true , 10 , context. getString(R . string. show_all), null );
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 );
123131 }
124132
125133 @NotNull
@@ -133,7 +141,7 @@ public class MyCodeAdapter extends AbstractCodeAdapter<MyModel> {
1331414 . Set custom adapter to your code view:
134142``` java
135143final MyCodeAdapter adapter = new MyCodeAdapter (this , getString(R . string. listing_py), ColorTheme . SOLARIZED_LIGHT. theme());
136- codeView. setAdapter (diffsAdapter);
144+ codeView. init (diffsAdapter);
137145```
138146<br >
1391475 . Init footer entities to provide mapper from your view to model:
@@ -146,7 +154,7 @@ adapter.addFooterEntity(11, new MyModel(getString(R.string.py_deletion_11), fals
146154<br >
1471556 . You can also add a multiple diff entities:
148156``` java
149- AbstractCodeAdapter <MyModel >. addFooterEntities(HashMap<Int , List<MyModel > > myEntities)
157+ CodeAdapter <MyModel >. addFooterEntities(HashMap<Int , List<MyModel > > myEntities)
150158```
151159Here 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.
152160<br >
0 commit comments