Skip to content

Commit 0c0e601

Browse files
authored
Update README.md
1 parent 3270c2b commit 0c0e601

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed

README.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,105 @@
11
# CodeView (Android)
22
CodeView helps to show code content with syntax highlighting in native way.
3+
4+
## Description
5+
CodeView contains 3 core parts to implement necessary logic:<br>
6+
1. <b>CodeClassifier</b> is trying to define what language presented in code snippet. It built upon <a href="https://github.com/ptnplanet/Java-Naive-Bayes-Classifier">Naive Bayes classifier</a>. There is no need to work with this class directly & you must just follow instructions below.<br>
7+
2. For highlighting it uses <b>CodeHighlighter</b>, just highlights your code & returns formatted content. It based on Google Prettify and <a href="https://github.com/twalcari/java-prettify">their fork</a>.<br>
8+
3. <b>CodeView</b> & necessary adapter.<br>
9+
10+
## Download
11+
Add it in your root ```build.gradle``` at the end of repositories:
12+
```groovy
13+
allprojects {
14+
repositories {
15+
...
16+
maven { url "https://jitpack.io" }
17+
}
18+
}
19+
```
20+
21+
Add the dependency:
22+
```groovy
23+
compile 'com.github.softwee:codeview-android:1.0.0'
24+
```
25+
26+
## Usage
27+
If you want to use code classifier to auto language recognizing just add to your ```Application.java```:
28+
```java
29+
// train classifier on app start
30+
CodeProcessor.init(this);
31+
```
32+
33+
Add view for your layout:
34+
```xml
35+
<io.github.kbiakov.codeview.CodeView
36+
android:id="@+id/code_view"
37+
android:layout_width="wrap_content"
38+
android:layout_height="wrap_content"/>
39+
```
40+
41+
Use chaining syntax when build view:
42+
```java
43+
CodeView codeView = (CodeView) findViewById(R.id.code_view);
44+
45+
codeView.highlightCode("js")
46+
.setColorTheme(ColorTheme.SOLARIZED_LIGHT.withBgContent(myColor))
47+
.setCodeContent(getString(R.string.listing_js));
48+
```
49+
50+
And perform actions sequentially when view built:
51+
```java
52+
codeView.setCodeContent(getString(R.string.listing_java));
53+
codeView.highlightCode("java");
54+
```
55+
56+
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. Instructions above helps you to avoid errors. View has state to handle this behavior.
57+
58+
## Customizing
59+
1. Use implicit or eplixit form to code highlighting:
60+
```java
61+
codeView.highlightCode();
62+
```
63+
```java
64+
codeView.highlightCode("js"); // it will work fast!
65+
```
66+
67+
2. Extend default color theme or create your own (don't forget to open PR with this stuff!):
68+
```java
69+
int myColor = ContextCompat.getColor(this, R.color.code_content_background);
70+
codeView.setColorTheme(ColorTheme.SOLARIZED_LIGHT.withBgContent(myColor));
71+
```
72+
```java
73+
codeView.setColorTheme(new ColorThemeData(new SyntaxColors(...)));
74+
```
75+
76+
3. Handle user clicks on code lines:
77+
```java
78+
codeView.setCodeListener(new OnCodeLineClickListener() {
79+
@Override
80+
public void onCodeLineClicked(int n) {
81+
// your logic here
82+
}
83+
});
84+
```
85+
86+
## License MIT
87+
Copyright (c) 2016 Softwee
88+
89+
Permission is hereby granted, free of charge, to any person obtaining a copy
90+
of this software and associated documentation files (the "Software"), to deal
91+
in the Software without restriction, including without limitation the rights
92+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
93+
copies of the Software, and to permit persons to whom the Software is
94+
furnished to do so, subject to the following conditions:
95+
96+
The above copyright notice and this permission notice shall be included in all
97+
copies or substantial portions of the Software.
98+
99+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
100+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
101+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
102+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
103+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
104+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
105+
SOFTWARE.

0 commit comments

Comments
 (0)