├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── libraries │ ├── com_android_support_animated_vector_drawable_23_4_0.xml │ ├── com_android_support_appcompat_v7_23_4_0.xml │ ├── com_android_support_support_annotations_23_4_0_jar.xml │ ├── com_android_support_support_v4_23_4_0.xml │ ├── com_android_support_support_vector_drawable_23_4_0.xml │ ├── junit_junit_4_12_jar.xml │ └── org_hamcrest_hamcrest_core_1_3_jar.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── CodeView.iml ├── README.md ├── READ_ENGLISH.md ├── app ├── .DS_Store ├── .gitignore ├── app.iml ├── build.gradle ├── proguard-rules.pro └── src │ ├── .DS_Store │ └── main │ ├── .DS_Store │ ├── AndroidManifest.xml │ ├── java │ └── thereisnospon │ │ └── mcode │ │ ├── Constant.java │ │ ├── IndexActivity.java │ │ ├── MainActivity.java │ │ ├── ShowCodeActivity.java │ │ └── ShowHtmlCodeActivity.java │ └── res │ ├── .DS_Store │ ├── layout │ ├── activity_index.xml │ ├── activity_main.xml │ ├── activity_main2.xml │ └── activity_show_html_code.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── codeview ├── .DS_Store ├── .gitignore ├── build.gradle ├── codeview.iml ├── proguard-rules.pro └── src │ ├── .DS_Store │ └── main │ ├── .DS_Store │ ├── AndroidManifest.xml │ ├── assets │ ├── .DS_Store │ └── highlight │ │ ├── .DS_Store │ │ ├── CHANGES.md │ │ ├── LICENSE │ │ ├── README.md │ │ ├── README.ru.md │ │ ├── highlight.pack.js │ │ └── styles │ │ ├── .DS_Store │ │ ├── agate.css │ │ ├── androidstudio.css │ │ ├── arduino-light.css │ │ ├── arta.css │ │ ├── ascetic.css │ │ ├── atelier-cave-dark.css │ │ ├── atelier-cave-light.css │ │ ├── atelier-dune-dark.css │ │ ├── atelier-dune-light.css │ │ ├── atelier-estuary-dark.css │ │ ├── atelier-estuary-light.css │ │ ├── atelier-forest-dark.css │ │ ├── atelier-forest-light.css │ │ ├── atelier-heath-dark.css │ │ ├── atelier-heath-light.css │ │ ├── atelier-lakeside-dark.css │ │ ├── atelier-lakeside-light.css │ │ ├── atelier-plateau-dark.css │ │ ├── atelier-plateau-light.css │ │ ├── atelier-savanna-dark.css │ │ ├── atelier-savanna-light.css │ │ ├── atelier-seaside-dark.css │ │ ├── atelier-seaside-light.css │ │ ├── atelier-sulphurpool-dark.css │ │ ├── atelier-sulphurpool-light.css │ │ ├── brown-paper.css │ │ ├── brown-papersq.png │ │ ├── codepen-embed.css │ │ ├── color-brewer.css │ │ ├── dark.css │ │ ├── darkula.css │ │ ├── default.css │ │ ├── docco.css │ │ ├── dracula.css │ │ ├── far.css │ │ ├── foundation.css │ │ ├── github-gist.css │ │ ├── github.css │ │ ├── googlecode.css │ │ ├── grayscale.css │ │ ├── gruvbox-dark.css │ │ ├── gruvbox-light.css │ │ ├── hopscotch.css │ │ ├── hybrid.css │ │ ├── idea.css │ │ ├── ir-black.css │ │ ├── kimbie.dark.css │ │ ├── kimbie.light.css │ │ ├── magula.css │ │ ├── mono-blue.css │ │ ├── monokai-sublime.css │ │ ├── monokai.css │ │ ├── obsidian.css │ │ ├── paraiso-dark.css │ │ ├── paraiso-light.css │ │ ├── pojoaque.css │ │ ├── pojoaque.jpg │ │ ├── purebasic.css │ │ ├── qtcreator_dark.css │ │ ├── qtcreator_light.css │ │ ├── railscasts.css │ │ ├── rainbow.css │ │ ├── school-book.css │ │ ├── school-book.png │ │ ├── solarized-dark.css │ │ ├── solarized-light.css │ │ ├── sunburst.css │ │ ├── tomorrow-night-blue.css │ │ ├── tomorrow-night-bright.css │ │ ├── tomorrow-night-eighties.css │ │ ├── tomorrow-night.css │ │ ├── tomorrow.css │ │ ├── vs.css │ │ ├── xcode.css │ │ ├── xt256.css │ │ └── zenburn.css │ ├── java │ └── thereisnospon │ │ └── codeview │ │ ├── Code.java │ │ ├── CodeView.java │ │ └── CodeViewTheme.java │ └── res │ └── values │ └── strings.xml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── mCode.iml ├── settings.gradle └── uplib.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | 3 | # 常用 ignore : android studio 4 | 5 | # Built application files 6 | /*/build/ 7 | 8 | # Crashlytics configuations 9 | com_crashlytics_export_strings.xml 10 | 11 | # Local configuration file (sdk path, etc) 12 | local.properties 13 | 14 | # Gradle generated files 15 | .gradle/ 16 | 17 | # Signing files 18 | .signing/ 19 | 20 | # User-specific configurations 21 | .idea/libraries/ 22 | .idea/workspace.xml 23 | .idea/tasks.xml 24 | .idea/.name 25 | .idea/compiler.xml 26 | .idea/copyright/profiles_settings.xml 27 | .idea/encodings.xml 28 | .idea/misc.xml 29 | .idea/modules.xml 30 | .idea/scopes/scope_settings.xml 31 | .idea/vcs.xml 32 | *.iml 33 | 34 | # OS-specific files 35 | .DS_Store 36 | .DS_Store? 37 | ._* 38 | .Spotlight-V100 39 | .Trashes 40 | ehthumbs.db 41 | Thumbs.db 42 | .idea/ 43 | 44 | 45 | 46 | 47 | 48 | *.iml 49 | .gradle 50 | /local.properties 51 | /.idea/workspace.xml 52 | /.idea/libraries 53 | .DS_Store 54 | /build 55 | /captures 56 | .externalNativeBuild 57 | 58 | 59 | # 常见 ignore : build 60 | 61 | build/ 62 | 63 | 64 | # 常见 ignore : c 语言 65 | 66 | 67 | *.d 68 | 69 | # Object files 70 | *.o 71 | *.ko 72 | *.obj 73 | *.elf 74 | 75 | # Linker output 76 | *.ilk 77 | *.map 78 | *.exp 79 | 80 | # Precompiled Headers 81 | *.gch 82 | *.pch 83 | 84 | # Libraries 85 | *.lib 86 | *.a 87 | *.la 88 | *.lo 89 | 90 | # Shared objects (inc. Windows DLLs) 91 | *.dll 92 | *.so 93 | *.so.* 94 | *.dylib 95 | 96 | # Executables 97 | *.exe 98 | *.out 99 | *.app 100 | *.i*86 101 | *.x86_64 102 | *.hex 103 | 104 | # Debug files 105 | *.dSYM/ 106 | *.su 107 | *.idb 108 | *.pdb 109 | 110 | # Kernel Module Compile Results 111 | *.mod* 112 | *.cmd 113 | .tmp_versions/ 114 | modules.order 115 | Module.symvers 116 | Mkfile.old 117 | dkms.conf 118 | 119 | 120 | # 常见 ignore : cpp 121 | 122 | # Prerequisites 123 | *.d 124 | 125 | # Compiled Object files 126 | *.slo 127 | *.lo 128 | *.o 129 | *.obj 130 | 131 | # Precompiled Headers 132 | *.gch 133 | *.pch 134 | 135 | # Compiled Dynamic libraries 136 | *.so 137 | *.dylib 138 | *.dll 139 | 140 | # Fortran module files 141 | *.mod 142 | *.smod 143 | 144 | # Compiled Static libraries 145 | *.lai 146 | *.la 147 | *.a 148 | *.lib 149 | 150 | # Executables 151 | *.exe 152 | *.out 153 | *.app 154 | 155 | 156 | # 常见 ignore: java build 157 | 158 | *.class 159 | 160 | 161 | # 常见 ignore: gradle 162 | 163 | .gradle 164 | /build/ 165 | 166 | # Ignore Gradle GUI config 167 | gradle-app.setting 168 | 169 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 170 | !gradle-wrapper.jar 171 | 172 | # Cache of project 173 | .gradletasknamecache 174 | 175 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 176 | # gradle/wrapper/gradle-wrapper.properties 177 | 178 | 179 | # 常见 ignore : idea 180 | 181 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 182 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 183 | 184 | # User-specific stuff: 185 | .idea/**/workspace.xml 186 | .idea/**/tasks.xml 187 | .idea/dictionaries 188 | 189 | # Sensitive or high-churn files: 190 | .idea/**/dataSources/ 191 | .idea/**/dataSources.ids 192 | .idea/**/dataSources.local.xml 193 | .idea/**/sqlDataSources.xml 194 | .idea/**/dynamic.xml 195 | .idea/**/uiDesigner.xml 196 | 197 | # Gradle: 198 | .idea/**/gradle.xml 199 | .idea/**/libraries 200 | 201 | # CMake 202 | cmake-build-debug/ 203 | cmake-build-release/ 204 | 205 | # Mongo Explorer plugin: 206 | .idea/**/mongoSettings.xml 207 | 208 | ## File-based project format: 209 | *.iws 210 | 211 | ## Plugin-specific files: 212 | 213 | # IntelliJ 214 | out/ 215 | 216 | # mpeltonen/sbt-idea plugin 217 | .idea_modules/ 218 | 219 | # JIRA plugin 220 | atlassian-ide-plugin.xml 221 | 222 | # Cursive Clojure plugin 223 | .idea/replstate.xml 224 | 225 | # Crashlytics plugin (for Android Studio and IntelliJ) 226 | com_crashlytics_export_strings.xml 227 | crashlytics.properties 228 | crashlytics-build.properties 229 | fabric.properties 230 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | CodeView -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_animated_vector_drawable_23_4_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_appcompat_v7_23_4_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_support_annotations_23_4_0_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_support_v4_23_4_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_support_vector_drawable_23_4_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/libraries/junit_junit_4_12_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/org_hamcrest_hamcrest_core_1_3_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CodeView.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | english version : https://github.com/Thereisnospon/CodeView/blob/master/READ_ENGLISH.md 3 | 4 | # CodeView 5 | 6 | 7 | CodeView 是一个能显示代码,并且能够进行代码高亮的一个控件。 8 | 这里是通过hightlight.js 渲染代码,可以自动识别主流的各种语言 9 | 比如*java,c++,c#,python,bash,ruby*。。。。等等等语言 10 | 并且有很多种主题风格,可以自由选择一种主题,然后将其显示 11 | 比如: 12 | 13 | 14 | 15 | 18 | 21 | 24 | 25 | 26 | 29 | 32 | 35 | 36 |
16 | 17 | 19 | 20 | 22 | 23 |
27 | 28 | 30 | 31 | 33 | 34 |
37 | 38 | 39 | 40 | 41 | 既可以显示单个代码片段,也可以把html文件中所有指定的代码替换为高亮显示出来,而其他部分保留不变。 42 | 大概就是这个效果: 43 | 44 | 45 | 46 | 47 | ## 获取方法(gradle) 48 | 49 | 50 | ``` 51 | compile 'thereisnospon.codeview:codeview:0.3.1' 52 | 53 | ``` 54 | 55 | 然后就获取好了,如果有问题,那应该是被墙的锅。 56 | 57 | 具体使用方法,非常简单,首先在 layout文件中 58 | ```xml 59 | 63 | 64 | ``` 65 | 然后在代码中使用它,就像这样 66 | 67 | ```java 68 | public class MainActivity extends AppCompatActivity { 69 | CodeView codeView; 70 | @Override 71 | protected void onCreate(Bundle savedInstanceState) { 72 | super.onCreate(savedInstanceState); 73 | setContentView(R.layout.activity_main); 74 | codeView=(CodeView)findViewById(R.id.codeview); 75 | codeView.setTheme(CodeViewTheme.ANDROIDSTUDIO).fillColor(); 76 | //这里的CODE 为需要显示的代码,类型为String,使用的时候自己替换下。 77 | codeView.showCode(CODE); 78 | } 79 | } 80 | ``` 81 | 然后就可以了。一般来说,可以自动识别代码的语言。 82 | 以上是用来显示单个代码片段,也可以用来把一个html文件中的代码全部替换为高亮显示。 83 | 比如对于下面的html文件 84 | ```html 85 | 86 | 87 | 88 | 89 | 90 | 91 |

This is a code

92 |
 93 | #include
 94 | int main()
 95 | {
 96 | 	printf("hello world");
 97 | }
 98 | 
99 |

This is another code

100 |
101 | class Main
102 | {
103 | 	private String name;
104 | 	Main(String name){
105 | 		this.name=name;
106 | 	}
107 | 	public static void main(String []args){
108 | 		Main main=new Main("hello");
109 | 		System.out.println("init");
110 | 	}
111 | }
112 | 
113 | 114 | 115 | ``` 116 | 如果要把其中的代码替换为高亮显示的话呢,可以这样,通过原来放代码的标签的类,来将代码高亮显示。 117 | 118 | ```java 119 | codeView.showCodeHtmlByClass(Constant.HTML,"code"); 120 | ``` 121 | 也可以用 css 的选择器,来选中需要高亮的代码区域.就像这样 122 | ```java 123 | codeView.showCodeHtmlByCssSelect(Constant.HTML,".code"); 124 | ``` 125 | 126 | ## 更换主题 127 | 128 | 默认的主题类型为 DEFAULT ,主题类型为一个枚举值,大概这样更换主题。 129 | ```java 130 | codeView.setTheme(CodeViewTheme.DRACULA) 131 | ``` 132 | 可以通过调用方法 查看所有主题类型。 133 | ```java 134 | public static CodeViewTheme[]listThemes(); 135 | ``` 136 | 再介绍几个其它的方法: 137 | ```java 138 | //设置编码类型,默认utf-8 139 | public CodeView setEncode(String encode); 140 | //填充背景颜色 141 | public CodeView fillColor(); 142 | //显示代码,自动识别语言 143 | public void showCode(String code); 144 | //显示代码,指定语言(这个还没搞定,因为目前自动识别已经很方便了。。 145 | public void showCode(Code code) 146 | ``` 147 | 148 | 也可以把这个项目clone到本地,app里有具体的使用demo,可以浏览下所有的主题,和一些具体用法。 149 | 150 | 151 | 如果觉得不错的话,可以点击这里点个赞什么的的 152 | 153 | 当然,这是第一次尝试写开源库,如果有哪些不好的地方,或者有什么bug,可以给我一点建议,每个批评都是一次学习的机会 154 | 155 | 156 | 邮箱:thereisnospon@qq.com 157 | 158 | ## Release Demo 159 | 160 | 应大家要求,发布了 release 版本,大家可以到这里 https://github.com/Thereisnospon/CodeView/releases 161 | 查看demo的效果。 162 | 163 | 164 | 165 | ## 版本微调: 166 | 167 | 0.2.1版本中,把最小sdk版本修改为14,可供更低版本的android 使用。 168 | 169 | ## 0.3.0 更新 170 | 171 | 增加了两个方法,用来解决网页显示图片的时候大多数图片用相对地址,导致图片显示不出的bug 172 | ```java 173 | public void setBaseUrl(String baseUrl 174 | public void setHistoryUrl(String historyUrl) 175 | ``` 176 | 177 | 178 | 代码高亮的渲染部分,是通过highlight.js 实现的。 179 | 180 | Copyright (c) 2006, Ivan Sagalaev 181 | All rights reserved. 182 | Redistribution and use in source and binary forms, with or without 183 | modification, are permitted provided that the following conditions are met: 184 | 185 | * Redistributions of source code must retain the above copyright 186 | notice, this list of conditions and the following disclaimer. 187 | * Redistributions in binary form must reproduce the above copyright 188 | notice, this list of conditions and the following disclaimer in the 189 | documentation and/or other materials provided with the distribution. 190 | * Neither the name of highlight.js nor the names of its contributors 191 | may be used to endorse or promote products derived from this software 192 | without specific prior written permission. 193 | 194 | THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 195 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 196 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 197 | DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 198 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 199 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 200 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 201 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 202 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 203 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 204 | 205 | 206 | 在操作html文件中使用了 Jsoup 库 207 | -------------------------------------------------------------------------------- /READ_ENGLISH.md: -------------------------------------------------------------------------------- 1 | # CodeView 2 | 3 | (my engilsh is not good ,if you have any question,you can ask me by e-mail : thereisnospon@qq.com) 4 | 5 | CodeView is a android widget can show code and hightlight it . 6 | The code is rendering by hightlight.js , it not only can automatically recognize the dominant languages such as java,c++,c#,python,bash,ruby and more.. but also have many kinds of themes you can choose. 7 | 8 | 9 | example: 10 | 11 | 12 | 13 | 16 | 19 | 22 | 23 | 24 | 27 | 30 | 33 | 34 |
14 | 15 | 17 | 18 | 20 | 21 |
25 | 26 | 28 | 29 | 31 | 32 |
35 | 36 | 37 | 38 | it can not only show code snippet,but also have replaced all the specified code in the HTML file with highlighted to come out, and the other part keep unchanged. 39 | 40 | 41 | etc: 42 | 43 | 44 | 45 | 46 | ## get(gradle) 47 | 48 | 49 | 50 | ``` 51 | compile 'thereisnospon.codeview:codeview:0.3.1' 52 | 53 | ``` 54 | 55 | 56 | 57 | ## use 58 | 59 | in the layout: 60 | ```xml 61 | 65 | 66 | ``` 67 | in java code: 68 | 69 | ```java 70 | public class MainActivity extends AppCompatActivity { 71 | CodeView codeView; 72 | @Override 73 | protected void onCreate(Bundle savedInstanceState) { 74 | super.onCreate(savedInstanceState); 75 | setContentView(R.layout.activity_main); 76 | codeView=(CodeView)findViewById(R.id.codeview); 77 | codeView.setTheme(CodeViewTheme.ANDROIDSTUDIO).fillColor(); 78 | //CODE is your code which you want to show,type is String 79 | codeView.showCode(CODE); 80 | } 81 | } 82 | ``` 83 | 84 | then is ok,it can recognize your code language automatically。 85 | 86 | if you want hightlight many code snippet in a html: 87 | 88 | ```html 89 | 90 | 91 | 92 | 93 | 94 | 95 |

This is a code

96 |
 97 | #include
 98 | int main()
 99 | {
100 | 	printf("hello world");
101 | }
102 | 
103 |

This is another code

104 |
105 | class Main
106 | {
107 | 	private String name;
108 | 	Main(String name){
109 | 		this.name=name;
110 | 	}
111 | 	public static void main(String []args){
112 | 		Main main=new Main("hello");
113 | 		System.out.println("init");
114 | 	}
115 | }
116 | 
117 | 118 | 119 | ``` 120 | 121 | this code snippet both have a same class "code" 122 | 123 | you can hightlight them by two ways: 124 | 125 | 126 | ```java 127 | codeView.showCodeHtmlByClass(Constant.HTML,"code"); 128 | ``` 129 | 130 | you can also using css selector ,such as: 131 | 132 | ```java 133 | codeView.showCodeHtmlByCssSelect(Constant.HTML,".code"); 134 | ``` 135 | 136 | ## change theme 137 | 138 | default theme is DEFAULT 。CodeViewTheme is a enum type 139 | ```java 140 | codeView.setTheme(CodeViewTheme.DRACULA) 141 | ``` 142 | you can using this method to list all themes 143 | ```java 144 | public static CodeViewTheme[]listThemes(); 145 | ``` 146 | som other methods: 147 | ```java 148 | //set encoding ,utf-8 is default 149 | public CodeView setEncode(String encode); 150 | //fill background color 151 | public CodeView fillColor(); 152 | //show code ,recognize language automatically。 153 | public void showCode(String code); 154 | //show code and specifying language,but it is undone. 155 | public void showCode(Code code) 156 | ``` 157 | 158 | you can clone this project to local,app have som useage demo,you can browse all theme and concreate useage 159 | 160 | 161 | if you think is interesting ,can give a star 162 | 163 | ofcourse ,it is my first open source library,it must have many trouble,and bug,you can give me some addvice, 164 | and then,i can learn more. 165 | 166 | 167 | 168 | 169 | mail :thereisnospon@qq.com 170 | 171 | ## Release Demo 172 | 173 | 174 | 175 | there is a release version: https://github.com/Thereisnospon/CodeView/releases 176 | 177 | ## version update 1 : 178 | 179 | 0.2.1 change min sdk to 14 180 | 181 | ## 0.3.0 update 182 | 183 | add two methods ,fix show image in html (because many image url is relative address) 184 | ```java 185 | public void setBaseUrl(String baseUrl 186 | public void setHistoryUrl(String historyUrl) 187 | ``` 188 | 189 | 190 | using highlight.js to hightlight 191 | 192 | Copyright (c) 2006, Ivan Sagalaev 193 | All rights reserved. 194 | Redistribution and use in source and binary forms, with or without 195 | modification, are permitted provided that the following conditions are met: 196 | 197 | * Redistributions of source code must retain the above copyright 198 | notice, this list of conditions and the following disclaimer. 199 | * Redistributions in binary form must reproduce the above copyright 200 | notice, this list of conditions and the following disclaimer in the 201 | documentation and/or other materials provided with the distribution. 202 | * Neither the name of highlight.js nor the names of its contributors 203 | may be used to endorse or promote products derived from this software 204 | without specific prior written permission. 205 | 206 | THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 207 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 208 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 209 | DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 210 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 211 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 212 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 213 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 214 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 215 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 216 | 217 | and using Jsoup to parse thml 218 | 219 | -------------------------------------------------------------------------------- /app/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Thereisnospon/CodeView/43a5d5ac2766d64ba5e464ad42c0f200320a966b/app/.DS_Store -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | buildToolsVersion '28.0.3' 6 | 7 | defaultConfig { 8 | applicationId "thereisnospon.mcode" 9 | minSdkVersion 19 10 | targetSdkVersion 26 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation fileTree(dir: 'libs', include: ['*.jar']) 24 | testImplementation 'junit:junit:4.12' 25 | implementation 'com.android.support:appcompat-v7:26.0.0' 26 | implementation project(":codeview") 27 | } 28 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/yzr/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Thereisnospon/CodeView/43a5d5ac2766d64ba5e464ad42c0f200320a966b/app/src/.DS_Store -------------------------------------------------------------------------------- /app/src/main/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Thereisnospon/CodeView/43a5d5ac2766d64ba5e464ad42c0f200320a966b/app/src/main/.DS_Store -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/java/thereisnospon/mcode/Constant.java: -------------------------------------------------------------------------------- 1 | package thereisnospon.mcode; 2 | 3 | /** 4 | * Created by yzr on 16/6/21. 5 | */ 6 | public class Constant { 7 | 8 | public static final String CODE = "#include \n" + 9 | "#include \n" + 10 | "#include \n" + 11 | "#include \n" + 12 | "#include \n" + 13 | "#include \n" + 14 | "#define MAX 2005 \n" + 15 | "using namespace std; \n" + 16 | "int in[MAX]; \n" + 17 | "vectorG[MAX]; \n" + 18 | "int TopSort(int n) \n" + 19 | "{ \n" + 20 | " queuep; \n" + 21 | " int i, t, Count = 0; \n" + 22 | " for (i = 1; i <= n; i++) \n" + 23 | " if (in[i] == 0) \n" + 24 | " p.push(i); \n" + 25 | " while (!p.empty()) \n" + 26 | " { \n" + 27 | " t = p.front(); p.pop(); \n" + 28 | " Count++; \n" + 29 | " for (i = 0; i < G[t].size(); i++) \n" + 30 | " { \n" + 31 | " in[G[t][i]]--; \n" + 32 | " if (in[G[t][i]] == 0) \n" + 33 | " p.push(G[t][i]); \n" + 34 | " } \n" + 35 | " } \n" + 36 | " if (Count > t; \n" + 47 | " while (t--) \n" + 48 | " { \n" + 49 | " cc++; \n" + 50 | " cin >> n; \n" + 51 | " memset(in, 0, sizeof(in)); \n" + 52 | " for (int i = 0; i <= n; i++) G[i].clear(); \n" + 53 | " for (i = 1; i <= n; i++) \n" + 54 | " { \n" + 55 | " cin >> s; \n" + 56 | " for (j = 0; j < s.size(); j++) \n" + 57 | " { \n" + 58 | " if (s[j] == '1') \n" + 59 | " { \n" + 60 | " G[i].push_back(j + 1); \n" + 61 | " in[j+1]++; \n" + 62 | " \n" + 63 | " } \n" + 64 | " } \n" + 65 | " } \n" + 66 | " if (TopSort(n)) \n" + 67 | " printf(\"Case #%d: Yes\\n\", cc); \n" + 68 | " else printf(\"Case #%d: No\\n\", cc); \n" + 69 | " } \n" + 70 | " return 0; \n" + 71 | "} "; 72 | 73 | public static final String HTML = "\n" + 74 | "\n" + 75 | "\n" + 76 | "\t\n" + 77 | "\n" + 78 | "\n" + 79 | "

This is a code

\n" + 80 | "
\n" +
 81 |             "#include\n" +
 82 |             "int main()\n" +
 83 |             "{\n" +
 84 |             "\tprintf(\"hello world\");\n" +
 85 |             "}\n" +
 86 |             "
\n" + 87 | "

This is another code

\n" + 88 | "
\n" +
 89 |             "class Main\n" +
 90 |             "{\n" +
 91 |             "\tprivate String name;\n" +
 92 |             "\tMain(String name){\n" +
 93 |             "\t\tthis.name=name;\n" +
 94 |             "\t}\n" +
 95 |             "\tpublic static void main(String []args){\n" +
 96 |             "\t\tMain main=new Main(\"hello\");\n" +
 97 |             "\t\tSystem.out.println(\"init\");\n" +
 98 |             "\t}\n" +
 99 |             "}\n" +
100 |             "
\n" + 101 | "\n" + 102 | ""; 103 | 104 | } 105 | -------------------------------------------------------------------------------- /app/src/main/java/thereisnospon/mcode/IndexActivity.java: -------------------------------------------------------------------------------- 1 | package thereisnospon.mcode; 2 | 3 | import android.content.Intent; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | import android.widget.AdapterView; 8 | import android.widget.ArrayAdapter; 9 | import android.widget.ListView; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | import thereisnospon.codeview.CodeViewTheme; 15 | 16 | public class IndexActivity extends AppCompatActivity { 17 | 18 | ListView listView; 19 | 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | setContentView(R.layout.activity_index); 24 | listView = (ListView) findViewById(R.id.listview); 25 | List themeList = new ArrayList<>(); 26 | for (CodeViewTheme theme : CodeViewTheme.listThemes()) { 27 | themeList.add(theme.getName()); 28 | } 29 | ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, themeList); 30 | listView.setAdapter(adapter); 31 | listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 32 | @Override 33 | public void onItemClick(AdapterView parent, View view, int position, long id) { 34 | Intent intent = new Intent(IndexActivity.this, ShowCodeActivity.class); 35 | intent.putExtra("theme", position); 36 | startActivity(intent); 37 | } 38 | }); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/java/thereisnospon/mcode/MainActivity.java: -------------------------------------------------------------------------------- 1 | package thereisnospon.mcode; 2 | 3 | import android.content.Intent; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | import android.widget.Button; 8 | 9 | public class MainActivity extends AppCompatActivity { 10 | 11 | @Override 12 | protected void onCreate(Bundle savedInstanceState) { 13 | super.onCreate(savedInstanceState); 14 | setContentView(R.layout.activity_main2); 15 | Button testTheme = (Button) findViewById(R.id.test_theme); 16 | testTheme.setOnClickListener(new View.OnClickListener() { 17 | @Override 18 | public void onClick(View v) { 19 | Intent intent = new Intent(MainActivity.this, IndexActivity.class); 20 | startActivity(intent); 21 | } 22 | }); 23 | Button testHtml = (Button) findViewById(R.id.test_htmlcode); 24 | testHtml.setOnClickListener(new View.OnClickListener() { 25 | @Override 26 | public void onClick(View v) { 27 | Intent intent = new Intent(MainActivity.this, ShowHtmlCodeActivity.class); 28 | startActivity(intent); 29 | } 30 | }); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/thereisnospon/mcode/ShowCodeActivity.java: -------------------------------------------------------------------------------- 1 | package thereisnospon.mcode; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | 6 | import thereisnospon.codeview.CodeView; 7 | import thereisnospon.codeview.CodeViewTheme; 8 | 9 | public class ShowCodeActivity extends AppCompatActivity { 10 | 11 | 12 | CodeView codeView; 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.activity_main); 18 | int theme = getIntent().getIntExtra("theme", 0); 19 | codeView = (CodeView) findViewById(R.id.codeview); 20 | codeView.setTheme(CodeViewTheme.listThemes()[theme]); 21 | codeView.fillColor(); 22 | 23 | codeView.showCode(Constant.CODE); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/java/thereisnospon/mcode/ShowHtmlCodeActivity.java: -------------------------------------------------------------------------------- 1 | package thereisnospon.mcode; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | 6 | import thereisnospon.codeview.CodeView; 7 | import thereisnospon.codeview.CodeViewTheme; 8 | 9 | public class ShowHtmlCodeActivity extends AppCompatActivity { 10 | 11 | CodeView codeView; 12 | 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | setContentView(R.layout.activity_show_html_code); 17 | codeView = (CodeView) findViewById(R.id.codeview); 18 | codeView.setTheme(CodeViewTheme.DRACULA); 19 | codeView.showCodeHtmlByCssSelect(Constant.HTML, ".code"); 20 | codeView.setTheme(CodeViewTheme.DRACULA); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/res/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Thereisnospon/CodeView/43a5d5ac2766d64ba5e464ad42c0f200320a966b/app/src/main/res/.DS_Store -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_index.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 12 | 13 | 14 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main2.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 |