You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CodeView helps to show code content with syntax highlighting in native way.
7
+
<b>CodeView</b> helps to show code content with syntax highlighting in native way.
8
8
9
9
## Description
10
-
CodeView contains 3 core parts to implement necessary logic:<br>
10
+
<b>CodeView</b> contains 3 core parts to implement necessary logic:<br>
11
11
12
-
1. <b>CodeClassifier</b> is trying to define what language presented in code snippet. It built upon [Naive Bayes classifier](https://github.com/ptnplanet/Java-Naive-Bayes-Classifier). There is no need to work with this class directly & you must just follow instructions below. (Experimental module, may not work properly!)<br>
12
+
1. <b>CodeView</b> & related abstract adapter to provide options & customization (see below).<br>
13
13
14
14
2. For highlighting it uses <b>CodeHighlighter</b>, just highlights your code & returns formatted content. It based on [Google Prettify](https://github.com/google/code-prettify) and their Java implementation & [fork](https://github.com/google/code-prettify).<br>
15
15
16
-
3. <b>CodeView</b> & related abstract adapter to provide customization (see below).<br>
16
+
3. <b>CodeClassifier</b> is trying to define what language presented in code snippet. It built using [Naive Bayes classifier](https://en.wikipedia.org/wiki/Naive_Bayes_classifier) upon found open-source [implementation](https://github.com/ptnplanet/Java-Naive-Bayes-Classifier), which I rewrote in Kotlin. There is no need to work with this class directly & you must just follow instructions below. (Experimental module, may not work properly!)<br>
17
17
18
18
## Download
19
19
Add it in your root ```build.gradle``` at the end of repositories:
@@ -38,72 +38,87 @@ If you want to use code classifier to auto language recognizing just add to your
38
38
CodeProcessor.init(this);
39
39
```
40
40
41
-
Add view for your layout:
41
+
Having done ones on app start you can classify language for different snippets more faster, because algorithm needs time for training on sets for presented listings of languages which library has.
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.
When you call ```setCode(...)``` view will prepared with default params if view was not initialized before. So if you want some customization, it can be done using options and/or adapter.
68
+
69
+
### Initialization
70
+
You can initialize view with options:
72
71
```java
73
-
codeView.highlightCode("js"); // it will work fast!
72
+
codeView.setOptions(Options.Default.get(this)
73
+
.withLanguage("python")
74
+
.withCode(R.string.listing_py)
75
+
.withTheme(ColorTheme.MONOKAI));
74
76
```
75
77
76
-
Use default color theme:
78
+
Or using adapter (see <b>Adapter</b> or example for more details):
<b>Note:</b> Each <b>CodeView</b> has adapter and each adapter has options. When calling ```setOptions(...)``` or ```setAdapter(...)``` current adapter "flushed" with current options. If you want to save the state and just update options saving adapter or set adapter saving options you must call ```updateOptions(...)``` or ```updateAdapter(...)``` accordingly.
85
+
86
+
### Options
87
+
Options helps to easily set necessary params, such as code & language, color theme, shortcut params (max lines, note), code line click listener. Some params are unnecessary.
88
+
89
+
When view initialized (options or adapter are set) you can manipulate options in various ways:
81
90
```java
82
-
int myColor =ContextCompat.getColor(this, R.color.my_color);
Didn't found yours? Please, open issue to show your interest & I'll try to add this language in next releases.
170
185
171
186
## List of available themes
172
-
1. Default (simple light theme)
173
-
2. Solarized Light
174
-
3. Monokai
187
+
1. Default (simple light theme).
188
+
2. Solarized Light.
189
+
3. Monokai.
175
190
176
191
## Contribute
177
192
1. You can add your theme (see [ColorTheme](https://github.com/Softwee/codeview-android/blob/master/codeview/src/main/java/io/github/kbiakov/codeview/highlight/CodeHighlighter.kt) class). Try to add some classic color themes or create your own if it looks cool. You can find many of them in different open-source text editors.<br>
178
-
2. If you are strong in a regex add missed language as shown [here](https://github.com/Softwee/codeview-android/blob/master/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangScala.java). You can find existing regex for some language in different sources of js-libraries, etc, which plays the same role.<br>
179
-
3. Various adapters also welcome, customization is unlimited.
193
+
2. If you are strong in regex, add missed language as shown [here](https://github.com/Softwee/codeview-android/blob/master/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangScala.java). You can find existing regex for some language in different sources of libraries, which plays the same role.<br>
0 commit comments