Android Code Highlighter

Overview

CodeView

Android Code Highlighter

Install

Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

Add the dependency:

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:

<br.tiagohm.codeview.CodeView
        android:id="@+id/codeView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:cv_font_size="14"
        app:cv_highlight_line_number="36"
        app:cv_show_line_number="true"
        app:cv_start_line_number="0"
        app:cv_wrap_line="true"
        app:cv_zoom_enable="true">
    </br.tiagohm.codeview.CodeView>
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

mCodeView.highlightLineNumber(10);
mCodeView.toggleLineNumber();
mCodeView.getLineCount();

Listeners:

//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();
 }
}

You might also like...
[DISCONTINUED] Rrich text editor for android platform. 安卓富文本编辑器,暂停维护

icarus-android Maybe the best rich text editor on android platform. Base on Simditor Features Alignment (left/center/right) Bold Blockquote Code Horiz

Android Bubble View

BubbleTextView Custom arrow position Custom fillet radius Custom background color Can be placed anywhere Two default style Two default theme Snapshot

A Material Android password view that toggles password visibility via an eye icon.
A Material Android password view that toggles password visibility via an eye icon.

8/17/2016: As of about an hour ago, this library is deprecated! Support for password visibility is now included in the Design Support Library in TextI

RoundedLetterView like the one in Android 5.0 Contacts app
RoundedLetterView like the one in Android 5.0 Contacts app

RoundedLetterView RoundedLetterView like the one in Android 5.0 Contacts app Attributes to choose from: rlv_titleText - The text in the first row. rlv

Android library contain custom realisation of EditText component for masking and formatting input text
Android library contain custom realisation of EditText component for masking and formatting input text

Masked-Edittext Masked-Edittext android library EditText widget wrapper add masking and formatting input text functionality. Install Maven dependency

Circular timer on Android platform.

CircleTimerView [No Longer Support] Circle timer on Android platform. System Requirement Android v2.2+ TODO Developed by AndroidStudio Usage com.gith

An address-autocompleting text field for Android
An address-autocompleting text field for Android

android-PlacesAutocompleteTextView An AutocompleteTextView that interacts with the Google Maps Places API to provide location results and caches selec

library to implement and render emojis For Android
library to implement and render emojis For Android

Release Notes SuperNova-Emoji SuperNova-Emoji is a library to implement and render emojis. Minimum SDK Level: 9 (2.3) Contact Java Usage To use defaul

Chips EditText, Token EditText, Bubble EditText, Spannable EditText and etc.. There are many names of this control. Here I develop easy to understand , modify and integrate Chips Edit Text widget for Android
Chips EditText, Token EditText, Bubble EditText, Spannable EditText and etc.. There are many names of this control. Here I develop easy to understand , modify and integrate Chips Edit Text widget for Android

Chips EditText Library Chips EditText, Token EditText, Bubble EditText, Spannable EditText and etc.. There are many names of this control. Here I deve

Comments
  • Detect whether code was loaded

    Detect whether code was loaded

    How could I detect whether the code was loaded? I am trying to open large files and it takes couple seconds to load the code and display it in the layout. Is there a way I could detect when the code has been displayed so I can display/hide a progressbar?

    Thanks

    opened by kal27 3
  • Automatic language detection

    Automatic language detection

    Hello,

    since those highlighters support automatic language detection, can you support the same in your library please?

    Also, what's the licence? It's not included in the repository.

    Cheers.

    opened by mario 1
Releases(0.4.0)
Owner
Tiago
Tiago
An easy approach on how to create your country code picker for the edit text.

Country-Code-Picker Original Article on Dev.to Click below ?? App's Overview In this article, I am going to demonstrate how to create a simple country

Siddharth Singh 5 Mar 10, 2022
RichEditor for Android is a beautiful Rich Text WYSIWYG Editor for Android.

RichEditor for Android is a beautiful Rich Text WYSIWYG Editor for Android. Looking for iOS? Check out cjwirth/RichEditorView Supported Functions Bold

Daichi Furiya 6k Jan 2, 2023
MarkdownView is an Android webview with the capablity of loading Markdown text or file and display it as HTML, it uses MarkdownJ and extends Android webview.

MarkdownView is an Android webview with the capablity of loading Markdown text or file and display it as HTML, it uses MarkdownJ and extends Android webview.

Feras Alnatsheh 1k Dec 20, 2022
Android's TextView that can expand/collapse like the Google Play's app description

ExpandableTextView ExpandableTextView is an Android library that allows developers to easily create an TextView which can expand/collapse just like th

Manabu S. 4k Dec 28, 2022
A library to show emoji in TextView, EditText (like WhatsApp) for Android

Discontinued This projected is discontinued. Please consider using other alternative, i.e EmojiCompat. Contact me if you want to continue working on a

Hieu Rocker 3.6k Jan 5, 2023
Android experiment showing a sinking TextView

Titanic is an Android experiment reproducing this effect.

Romain Piel 1.8k Dec 15, 2022
:page_facing_up: Android Text Full Jusiftication / Wrapping / Justify / Hyphenate - V2.0

LIBRARY IS NO LONGER MAINTAINED If you want to adopt + maintain this library, please drop me a message - [email protected] Android Full Justific

Mathew Kurian 1.9k Dec 29, 2022
Android form edit text is an extension of EditText that brings data validation facilities to the edittext.

Android Form EditText Android form edit text is an extension of EditText that brings data validation facilities to the edittext. Example App I built a

Andrea 1.5k Dec 14, 2022
Gmail style MultiAutoCompleteTextView for Android

Version 3.0 The 3.0.1 version is now available! This should resolve a number of text handling issues and lay the groundwork for better support of mixe

Splitwise 1.3k Nov 14, 2022
Advanced Android TextView

Advanced Android TextView Companion app for my Advanced Android TextView talk, demostrating: Animated CompoundDrawable Text shadow Custom font Non-bre

Chiu-Ki Chan 1.2k Dec 9, 2022