项目作者: tiagohm

项目描述 :
Android Code Highlighter
高级语言: CSS
项目地址: git://github.com/tiagohm/CodeView.git
创建时间: 2017-01-15T22:53:09Z
项目社区:https://github.com/tiagohm/CodeView

开源协议:MIT License

下载


CodeView

Android Code Highlighter

Install

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

  1. allprojects {
  2. repositories {
  3. ...
  4. maven { url "https://jitpack.io" }
  5. }
  6. }

Add the dependency:

  1. 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:

  1. <br.tiagohm.codeview.CodeView
  2. android:id="@+id/codeView"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. app:cv_font_size="14"
  6. app:cv_highlight_line_number="36"
  7. app:cv_show_line_number="true"
  8. app:cv_start_line_number="0"
  9. app:cv_wrap_line="true"
  10. app:cv_zoom_enable="true">
  11. </br.tiagohm.codeview.CodeView>
  1. mCodeView = (CodeView)findViewById(R.id.codeView);
  2. mCodeView.setOnHighlightListener(this)
  3. .setOnHighlightListener(this)
  4. .setTheme(Theme.AGATE)
  5. .setCode(JAVA_CODE)
  6. .setLanguage(Language.JAVA)
  7. .setWrapLine(true)
  8. .setFontSize(14)
  9. .setZoomEnabled(true)
  10. .setShowLineNumber(true)
  11. .setStartLineNumber(9000)
  12. .apply();

Other Methods

  1. mCodeView.highlightLineNumber(10);
  2. mCodeView.toggleLineNumber();
  3. mCodeView.getLineCount();

Listeners:

  1. //Interface
  2. new CodeView.OnHighlightListener()
  3. {
  4. @Override
  5. public void onStartCodeHighlight()
  6. {
  7. mProgressDialog = ProgressDialog.show(this, null, "Carregando...", true);
  8. }
  9. @Override
  10. public void onFinishCodeHighlight()
  11. {
  12. if (mProgressDialog != null) {
  13. mProgressDialog.dismiss();
  14. }
  15. }
  16. @Override
  17. public void onLanguageDetected(Language language, int relevance) {
  18. Toast.makeText(this, "language: " + language + " relevance: " + relevance, Toast.LENGTH_SHORT).show();
  19. }
  20. @Override
  21. public void onFontSizeChanged(int sizeInPx) {
  22. Log.d("TAG", "font-size: " + sizeInPx + "px");
  23. }
  24. @Override
  25. public void onLineClicked(int lineNumber, String content) {
  26. Toast.makeText(this, "line: " + lineNumber + " html: " + content, Toast.LENGTH_SHORT).show();
  27. }
  28. }