Skip to content

Commit 65934da

Browse files
author
e16din
authored
Update README.md
1 parent 6744ba8 commit 65934da

1 file changed

Lines changed: 18 additions & 16 deletions

File tree

README.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ allprojects {
2727

2828
Add the dependency:
2929
```groovy
30-
compile 'com.github.softwee:codeview-android:1.1.2'
30+
compile 'com.github.e16din:codeview-android:1.2.0'
3131
```
3232

3333
## Usage
@@ -49,42 +49,44 @@ Use chaining syntax when build view:
4949
```java
5050
CodeView codeView = (CodeView) findViewById(R.id.code_view);
5151

52-
codeView.highlightCode("js")
53-
.setColorTheme(ColorTheme.SOLARIZED_LIGHT.withBgContent(myColor))
54-
.setCodeContent(getString(R.string.listing_js));
52+
codeView.colorTheme(ColorTheme.SOLARIZED_LIGHT.withBgContent(myColor))
53+
.codeContent(getString(R.string.listing_js))
54+
.highlight("js");
5555
```
5656

5757
And perform actions sequentially when view built:
5858
```java
59-
codeView.setCodeContent(getString(R.string.listing_java));
60-
codeView.highlightCode("java");
59+
codeView.codeContent(getString(R.string.listing_java));
60+
codeView.highlight("java");
6161
```
6262

63-
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.
63+
Please firstly set adapter or use codeView.codeContent().
64+
And finally you must call highlight() to process highlighting once.
65+
6466

6567
## Customizing
6668
Use implicit form to code highlighting:
6769
```java
68-
codeView.highlightCode();
70+
codeView.highlight();
6971
```
7072
or eplixit (see available extensions below):
7173
```java
72-
codeView.highlightCode("js"); // it will work fast!
74+
codeView.highlight("js"); // it will work fast!
7375
```
7476

7577
Extend default color theme:
7678
```java
7779
int myColor = ContextCompat.getColor(this, R.color.code_content_background);
78-
codeView.setColorTheme(ColorTheme.SOLARIZED_LIGHT.withBgContent(myColor));
80+
codeView.colorTheme(ColorTheme.SOLARIZED_LIGHT.withBgContent(myColor));
7981
```
8082
or provide your own (don't forget to open PR with this stuff!)
8183
```java
82-
codeView.setColorTheme(new ColorThemeData(new SyntaxColors(...), ...));
84+
codeView.colorTheme(new ColorThemeData(new SyntaxColors(...), ...));
8385
```
8486

8587
Handle user clicks on code lines:
8688
```java
87-
codeView.setCodeListener(new OnCodeLineClickListener() {
89+
codeView.codeListener(new OnCodeLineClickListener() {
8890
@Override
8991
public void onCodeLineClicked(int n, @NotNull String line) {
9092
Log.i("ListingsActivity", "On " + (n + 1) + " line clicked");
@@ -106,7 +108,7 @@ Sometimes you may want to add some content under line. You can create your own i
106108
```kotlin
107109
// Kotlin
108110
class MyCodeAdapter : AbstractCodeAdapter<MyModel> {
109-
constructor(context: Context, content: String) : super(context, content)
111+
constructor(context: Context, content: String, colorTheme: ColorThemeData) : super(context, content, colorTheme)
110112

111113
override fun createFooter(context: Context, entity: MyModel, isFirst: Boolean) =
112114
/* init & return your view here */
@@ -115,9 +117,9 @@ class MyCodeAdapter : AbstractCodeAdapter<MyModel> {
115117
```java
116118
// Java
117119
public class MyCodeAdapter extends AbstractCodeAdapter<MyModel> {
118-
public CustomAdapter(@NotNull Context context, @NotNull String content) {
120+
public CustomAdapter(@NotNull Context context, @NotNull String content, @NotNull ColorThemeData colorTheme) {
119121
// @see params in AbstractCodeAdapter
120-
super(context, content, true, 10, context.getString(R.string.show_all), null);
122+
super(context, content, colorTheme, true, 10, context.getString(R.string.show_all), null);
121123
}
122124

123125
@NotNull
@@ -130,7 +132,7 @@ public class MyCodeAdapter extends AbstractCodeAdapter<MyModel> {
130132
<br>
131133
4. Set custom adapter to your code view:
132134
```java
133-
final MyCodeAdapter adapter = new MyCodeAdapter(this, getString(R.string.listing_py));
135+
final MyCodeAdapter adapter = new MyCodeAdapter(this, getString(R.string.listing_py), ColorTheme.SOLARIZED_LIGHT.theme());
134136
codeView.setAdapter(diffsAdapter);
135137
```
136138
<br>

0 commit comments

Comments
 (0)