Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tiagohm/CodeView
Android Code Highlighter
https://github.com/tiagohm/CodeView
android android-library highlighter syntax-highlighting view
Last synced: about 1 month ago
JSON representation
Android Code Highlighter
- Host: GitHub
- URL: https://github.com/tiagohm/CodeView
- Owner: tiagohm
- License: mit
- Archived: true
- Created: 2017-01-15T22:53:09.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-08-03T23:14:19.000Z (over 7 years ago)
- Last Synced: 2024-11-04T15:07:03.386Z (about 1 month ago)
- Topics: android, android-library, highlighter, syntax-highlighting, view
- Language: CSS
- Size: 3.27 MB
- Stars: 211
- Watchers: 9
- Forks: 29
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-github-android-ui - CodeView - Android 代码高亮 (编辑器)
README
# CodeView
### Android Code Highlighter[![](https://jitpack.io/v/tiagohm/CodeView.svg)](https://jitpack.io/#tiagohm/CodeView)
## Install
Add it in your root `build.gradle` at the end of repositories:
```gradle
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
```
Add the dependency:
```gradle
compile 'com.github.tiagohm:CodeView:LATEST-VERSION
```## Features
* Powered by Highlight.js
* 176 languages and 79 styles
* Wrap Line
* Language Detection
* Zoom (Pinch gesture)
* Line Number
* Line Count
* Highlight current line (by click/tap)
* Highlight line
* Tap event of lines (get line number and your content)## Usage
Add view to your layout:
```xml
```
```java
mCodeView = (CodeView)findViewById(R.id.codeView);mCodeView.setOnHighlightListener(this)
.setOnHighlightListener(this)
.setTheme(Theme.AGATE)
.setCode(JAVA_CODE)
.setLanguage(Language.JAVA)
.setWrapLine(true)
.setFontSize(14)
.setZoomEnabled(true)
.setShowLineNumber(true)
.setStartLineNumber(9000)
.apply();
```## Other Methods
```java
mCodeView.highlightLineNumber(10);
mCodeView.toggleLineNumber();
mCodeView.getLineCount();
```Listeners:
```java
//Interface
new CodeView.OnHighlightListener()
{
@Override
public void onStartCodeHighlight()
{
mProgressDialog = ProgressDialog.show(this, null, "Carregando...", true);
}@Override
public void onFinishCodeHighlight()
{
if (mProgressDialog != null) {
mProgressDialog.dismiss();
}
}@Override
public void onLanguageDetected(Language language, int relevance) {
Toast.makeText(this, "language: " + language + " relevance: " + relevance, Toast.LENGTH_SHORT).show();
}@Override
public void onFontSizeChanged(int sizeInPx) {
Log.d("TAG", "font-size: " + sizeInPx + "px");
}@Override
public void onLineClicked(int lineNumber, String content) {
Toast.makeText(this, "line: " + lineNumber + " html: " + content, Toast.LENGTH_SHORT).show();
}
}
```![](https://raw.githubusercontent.com/tiagohm/CodeView/master/1.png)