\n" +
101 | "\n" +
102 | "";
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/codeview/src/main/assets/highlight/README.ru.md:
--------------------------------------------------------------------------------
1 | # Highlight.js
2 |
3 | Highlight.js — это инструмент для подсветки синтаксиса, написанный на JavaScript. Он работает
4 | и в браузере, и на сервере. Он работает с практически любой HTML разметкой, не
5 | зависит от каких-либо фреймворков и умеет автоматически определять язык.
6 |
7 |
8 | ## Начало работы
9 |
10 | Минимум, что нужно сделать для использования highlight.js на веб-странице — это
11 | подключить библиотеку, CSS-стили и вызывать [`initHighlightingOnLoad`][1]:
12 |
13 | ```html
14 |
15 |
16 |
17 | ```
18 |
19 | Библиотека найдёт и раскрасит код внутри тегов `
`, попытавшись
20 | автоматически определить язык. Когда автоопределение не срабатывает, можно явно
21 | указать язык в атрибуте class:
22 |
23 | ```html
24 |
...
25 | ```
26 |
27 | Список поддерживаемых классов языков доступен в [справочнике по классам][8].
28 | Класс также можно предварить префиксами `language-` или `lang-`.
29 |
30 | Чтобы отключить подсветку для какого-то блока, используйте класс `nohighlight`:
31 |
32 | ```html
33 |
...
34 | ```
35 |
36 | ## Инициализация вручную
37 |
38 | Чтобы иметь чуть больше контроля за инициализацией подсветки, вы можете
39 | использовать функции [`highlightBlock`][2] и [`configure`][3]. Таким образом
40 | можно управлять тем, *что* и *когда* подсвечивать.
41 |
42 | Вот пример инициализации, эквивалентной вызову [`initHighlightingOnLoad`][1], но
43 | с использованием jQuery:
44 |
45 | ```javascript
46 | $(document).ready(function() {
47 | $('pre code').each(function(i, block) {
48 | hljs.highlightBlock(block);
49 | });
50 | });
51 | ```
52 |
53 | Вы можете использовать любые теги разметки вместо `
`. Если
54 | используете контейнер, не сохраняющий переводы строк, вам нужно сказать
55 | highlight.js использовать для них тег ` `:
56 |
57 | ```javascript
58 | hljs.configure({useBR: true});
59 |
60 | $('div.code').each(function(i, block) {
61 | hljs.highlightBlock(block);
62 | });
63 | ```
64 |
65 | Другие опции можно найти в документации функции [`configure`][3].
66 |
67 |
68 | ## Web Workers
69 |
70 | Подсветку можно запустить внутри web worker'а, чтобы окно
71 | браузера не подтормаживало при работе с большими кусками кода.
72 |
73 | В основном скрипте:
74 |
75 | ```javascript
76 | addEventListener('load', function() {
77 | var code = document.querySelector('#code');
78 | var worker = new Worker('worker.js');
79 | worker.onmessage = function(event) { code.innerHTML = event.data; }
80 | worker.postMessage(code.textContent);
81 | })
82 | ```
83 |
84 | В worker.js:
85 |
86 | ```javascript
87 | onmessage = function(event) {
88 | importScripts('/highlight.pack.js');
89 | var result = self.hljs.highlightAuto(event.data);
90 | postMessage(result.value);
91 | }
92 | ```
93 |
94 |
95 | ## Установка библиотеки
96 |
97 | Highlight.js можно использовать в браузере прямо с CDN хостинга или скачать
98 | индивидуальную сборку, а также установив модуль на сервере. На
99 | [странице загрузки][4] подробно описаны все варианты.
100 |
101 | Обратите внимание, что библиотека не предназначена для использования в виде
102 | исходного кода на GitHub, а требует отдельной сборки. Если вам не подходит ни
103 | один из готовых вариантов, читайте [документацию по сборке][5].
104 |
105 |
106 | ## Лицензия
107 |
108 | Highlight.js распространяется под лицензией BSD. Подробнее читайте файл
109 | [LICENSE][10].
110 |
111 |
112 | ## Ссылки
113 |
114 | Официальный сайт билиотеки расположен по адресу .
115 |
116 | Более подробная документация по API и другим темам расположена на
117 | .
118 |
119 | Авторы и контрибьюторы перечислены в файле [AUTHORS.ru.txt][9] file.
120 |
121 | [1]: http://highlightjs.readthedocs.org/en/latest/api.html#inithighlightingonload
122 | [2]: http://highlightjs.readthedocs.org/en/latest/api.html#highlightblock-block
123 | [3]: http://highlightjs.readthedocs.org/en/latest/api.html#configure-options
124 | [4]: https://highlightjs.org/download/
125 | [5]: http://highlightjs.readthedocs.org/en/latest/building-testing.html
126 | [8]: http://highlightjs.readthedocs.org/en/latest/css-classes-reference.html
127 | [9]: https://github.com/isagalaev/highlight.js/blob/master/AUTHORS.ru.txt
128 | [10]: https://github.com/isagalaev/highlight.js/blob/master/LICENSE
129 |
--------------------------------------------------------------------------------
/codeview/src/main/java/thereisnospon/codeview/CodeView.java:
--------------------------------------------------------------------------------
1 | package thereisnospon.codeview;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.util.AttributeSet;
6 | import android.webkit.WebView;
7 | import org.jsoup.Jsoup;
8 | import org.jsoup.nodes.Document;
9 | import org.jsoup.select.Elements;
10 | /**
11 | * @author thereisnospon
12 | */
13 | public class CodeView extends WebView {
14 |
15 | private CodeViewTheme theme;
16 | private String encode;
17 | private Document document;
18 | private String baseUrl = null;
19 | private String historyUrl = null;
20 |
21 | public CodeView(Context context) {
22 | this(context, null);
23 | }
24 |
25 | public CodeView(Context context, AttributeSet attrs) {
26 | this(context, attrs, 0);
27 | }
28 |
29 | public CodeView(Context context, AttributeSet attrs, int defStyleAttr) {
30 | super(context, attrs, defStyleAttr);
31 | this.theme = CodeViewTheme.DEFAULT;
32 | this.encode = "utf-8";
33 | getSettings().setJavaScriptEnabled(true);
34 | }
35 |
36 | public CodeView setTheme(CodeViewTheme theme) {
37 | this.theme = theme;
38 | return this;
39 | }
40 |
41 | public CodeView setEncode(String encode) {
42 | this.encode = encode;
43 | return this;
44 | }
45 |
46 | public void setBaseUrl(String baseUrl) {
47 | this.baseUrl = baseUrl;
48 | }
49 |
50 | public void setHistoryUrl(String historyUrl) {
51 | this.historyUrl = historyUrl;
52 | }
53 |
54 | public void showCode(Code code) {
55 | this.document = Jsoup.parse(BASE_HTML);
56 | document.head().after(createStyle());
57 | addCode(code);
58 | loadDataWithBaseURL(baseUrl, document.html(), "text/html", encode, historyUrl);
59 | }
60 |
61 | public CodeView fillColor() {
62 | setBackgroundColor(Color.parseColor(theme.getBackgroundColor()));
63 | return this;
64 | }
65 |
66 | public void showCodeHtmlByCssSelect(String localHtml, String cssSelect) {
67 | documentInit(localHtml);
68 | Elements elements = document.select(cssSelect);
69 | showCodeHtml(elements);
70 | loadDataWithBaseURL(baseUrl, document.html(), "text/html", encode, historyUrl);
71 | }
72 |
73 | public void showCodeHtmlByClass(String localHtml, String codeClass) {
74 | documentInit(localHtml);
75 | Elements elements = document.getElementsByClass(codeClass);
76 | showCodeHtml(elements);
77 | loadDataWithBaseURL(baseUrl, document.html(), "text/html", encode, historyUrl);
78 | }
79 |
80 | private void documentInit(String localHtml) {
81 | this.document = Jsoup.parse(localHtml);
82 | document.head().append("\n\n");
83 | document.head().append("\n\n");
84 | document.head().append(createStyle());
85 | }
86 |
87 | private void showCodeHtml(Elements codes) {
88 | if (codes != null) {
89 | for (int i = 0; i < codes.size(); i++) {
90 | String raw = codes.get(i).text();
91 | codes.get(i).html("
" + raw + "
");
92 | }
93 | }
94 | }
95 |
96 | public void showCode(String code) {
97 | Code codeModel = new Code(code);
98 | showCode(codeModel);
99 | }
100 |
101 | public void showCode(String code, Code.Language language) {
102 | Code codeModel = new Code(code, language);
103 | showCode(codeModel);
104 | }
105 |
106 | public int getCodeBackgroundColor() {
107 | return Color.parseColor(theme.getBackgroundColor());
108 | }
109 |
110 | private String createStyle() {
111 | return "";
112 | }
113 |
114 | private void addCode(Code code) {
115 | document.body().appendElement("pre").appendElement("code").text(code.getCode());
116 | }
117 |
118 | private static final String BASE_HTML =
119 | "\n" +
120 | "\n" +
121 | "\n" +
122 | "\t\n" +
123 | "\t\n" +
124 | "\t\n" +
125 | "\n" +
126 | "\n" +
127 | "\n" +
128 | "";
129 | }
130 |
--------------------------------------------------------------------------------
/codeview/src/main/assets/highlight/README.md:
--------------------------------------------------------------------------------
1 | # Highlight.js
2 |
3 | [](https://travis-ci.org/isagalaev/highlight.js)
4 |
5 | Highlight.js is a syntax highlighter written in JavaScript. It works in
6 | the browser as well as on the server. It works with pretty much any
7 | markup, doesn’t depend on any framework and has automatic language
8 | detection.
9 |
10 | ## Getting Started
11 |
12 | The bare minimum for using highlight.js on a web page is linking to the
13 | library along with one of the styles and calling
14 | [`initHighlightingOnLoad`][1]:
15 |
16 | ```html
17 |
18 |
19 |
20 | ```
21 |
22 | This will find and highlight code inside of `
` tags; it tries
23 | to detect the language automatically. If automatic detection doesn’t
24 | work for you, you can specify the language in the `class` attribute:
25 |
26 | ```html
27 |
...
28 | ```
29 |
30 | The list of supported language classes is available in the [class
31 | reference][2]. Classes can also be prefixed with either `language-` or
32 | `lang-`.
33 |
34 | To disable highlighting altogether use the `nohighlight` class:
35 |
36 | ```html
37 |
...
38 | ```
39 |
40 | ## Custom Initialization
41 |
42 | When you need a bit more control over the initialization of
43 | highlight.js, you can use the [`highlightBlock`][3] and [`configure`][4]
44 | functions. This allows you to control *what* to highlight and *when*.
45 |
46 | Here’s an equivalent way to calling [`initHighlightingOnLoad`][1] using
47 | jQuery:
48 |
49 | ```javascript
50 | $(document).ready(function() {
51 | $('pre code').each(function(i, block) {
52 | hljs.highlightBlock(block);
53 | });
54 | });
55 | ```
56 |
57 | You can use any tags instead of `
` to mark up your code. If
58 | you don't use a container that preserve line breaks you will need to
59 | configure highlight.js to use the ` ` tag:
60 |
61 | ```javascript
62 | hljs.configure({useBR: true});
63 |
64 | $('div.code').each(function(i, block) {
65 | hljs.highlightBlock(block);
66 | });
67 | ```
68 |
69 | For other options refer to the documentation for [`configure`][4].
70 |
71 |
72 | ## Web Workers
73 |
74 | You can run highlighting inside a web worker to avoid freezing the browser
75 | window while dealing with very big chunks of code.
76 |
77 | In your main script:
78 |
79 | ```javascript
80 | addEventListener('load', function() {
81 | var code = document.querySelector('#code');
82 | var worker = new Worker('worker.js');
83 | worker.onmessage = function(event) { code.innerHTML = event.data; }
84 | worker.postMessage(code.textContent);
85 | })
86 | ```
87 |
88 | In worker.js:
89 |
90 | ```javascript
91 | onmessage = function(event) {
92 | importScripts('/highlight.pack.js');
93 | var result = self.hljs.highlightAuto(event.data);
94 | postMessage(result.value);
95 | }
96 | ```
97 |
98 |
99 | ## Getting the Library
100 |
101 | You can get highlight.js as a hosted, or custom-build, browser script or
102 | as a server module. Right out of the box the browser script supports
103 | both AMD and CommonJS, so if you wish you can use RequireJS or
104 | Browserify without having to build from source. The server module also
105 | works perfectly fine with Browserify, but there is the option to use a
106 | build specific to browsers rather than something meant for a server.
107 | Head over to the [download page][5] for all the options.
108 |
109 | **Note:** the library is not supposed to work straight from the source
110 | on GitHub; it requires building. If none of the pre-packaged options
111 | work for you refer to the [building documentation][6].
112 |
113 | Also, if you are using something like almond, you need to use the
114 | optimizer to give the module a name. The basic example would be:
115 |
116 | ```
117 | r.js -o name=hljs paths.hljs=/path/to/highlight out=highlight.js
118 | ```
119 |
120 | ## License
121 |
122 | Highlight.js is released under the BSD License. See [LICENSE][7] file
123 | for details.
124 |
125 | ## Links
126 |
127 | The official site for the library is at .
128 |
129 | Further in-depth documentation for the API and other topics is at
130 | .
131 |
132 | Authors and contributors are listed in the [AUTHORS.en.txt][8] file.
133 |
134 | [1]: http://highlightjs.readthedocs.org/en/latest/api.html#inithighlightingonload
135 | [2]: http://highlightjs.readthedocs.org/en/latest/css-classes-reference.html
136 | [3]: http://highlightjs.readthedocs.org/en/latest/api.html#highlightblock-block
137 | [4]: http://highlightjs.readthedocs.org/en/latest/api.html#configure-options
138 | [5]: https://highlightjs.org/download/
139 | [6]: http://highlightjs.readthedocs.org/en/latest/building-testing.html
140 | [7]: https://github.com/isagalaev/highlight.js/blob/master/LICENSE
141 | [8]: https://github.com/isagalaev/highlight.js/blob/master/AUTHORS.en.txt
142 |
--------------------------------------------------------------------------------
/codeview/src/main/java/thereisnospon/codeview/CodeViewTheme.java:
--------------------------------------------------------------------------------
1 | package thereisnospon.codeview;
2 |
3 | /**
4 | * Created by yzr on 16/6/21.
5 | */
6 | public enum CodeViewTheme {
7 |
8 | AGATE("agate", "#030303"),
9 | ANDROIDSTUDIO("androidstudio", "#282b2e"),
10 | ARDUINO_LIGHT("arduino-light", "#FFFFFF"),
11 | ARTA("arta", "#020202"),
12 | ATELIER_CAVE_DARK("atelier-cave-dark", "#19171c"),
13 | ATELIER_CAVE_LIGHT("atelier-cave-light", "#efecf4"),
14 | ATELIER_DUNE_DARK("atelier-dune-dark", "#20201d"),
15 | ATELIER_DUNE_LIGHT("atelier-dune-light", "#fefbec"),
16 | ATELIER_ESTUARY_DARK("atelier-estuary-dark", "#22221b"),
17 | ATELIER_ESTUARY_LIGHT("atelier-estuary-light", "#f4f3ec"),
18 | ATELIER_FOREST_DARK("atelier-forest-dark", "#1b1918"),
19 | ATELIER_FOREST_LIGHT("atelier-forest-light", "#f1efee"),
20 | ATELIER_HEATH_DARK("atelier-heath-dark", "#1b181b"),
21 | ATELIER_HEATH_LIGHT("atelier-heath-light", "#f7f3f7"),
22 | ATELIER_LAKESIDE_DARK("atelier-lakeside-dark", "#161b1d"),
23 | ATELIER_LAKESIDE_LIGHT("atelier-lakeside-light", "#ebf8ff"),
24 | ATELIER_PLATEAU_DARK("atelier-plateau-dark", "#1b1818"),
25 | ATELIER_PLATEAU_LIGHT("atelier-plateau-light", "#f4ecec"),
26 | ATELIER_SAVANNA_DARK("atelier-savanna-dark", "#171c19"),
27 | ATELIER_SAVANNA_LIGHT("atelier-savanna-light", "#ecf4ee"),
28 | ATELIER_SEASIDE_DARK("atelier-seaside-dark", "#131513"),
29 | ATELIER_SEASIDE_LIGHT("atelier-seaside-light", "#f4fbf4"),
30 | ATELIER_SULPHURPOOL_DARK("atelier-sulphurpool-dark", "#202746"),
31 | ATELIER_SULPHURPOOL_LIGHT("atelier-sulphurpool-light", "#f5f7ff"),
32 | CODEPEN_EMBED("codepen-embed", "#020202"),
33 | COLOR_BREWER("color-brewer", "#0f0f0f"),
34 | DARK("dark", "#040404"),
35 | DARKULA("darkula", "#2b2b2b"),
36 | DEFAULT("default", "#F0F0F0"),
37 | DOCCO("docco", "#f8f8ff"),
38 | DRACULA("dracula", "#282a36"),
39 | FAR("far", "#000080"),
40 | FOUNDATION("foundation", "#0e0e0e"),
41 | GITHUB("github", "#f8f8f8"),
42 | GRAYSCALE("grayscale", "#0f0f0f"),
43 | GRUVBOX_DARK("gruvbox-dark", "#282828"),
44 | GRUVBOX_LIGHT("gruvbox-light", "#fbf1c7"),
45 | HOPSCOTCH("hopscotch", "#322931"),
46 | HYBRID("hybrid", "#1d1f21"),
47 | IDEA("idea", "#0f0f0f"),
48 | IR_BLACK("ir-black", "#000000"),
49 | MONO_BLUE("mono-blue", "#eaeef3"),
50 | MONOKAI_SUBLIME("monokai-sublime", "#23241f"),
51 | MONOKAI("monokai", "#272822"),
52 | OBSIDIAN("obsidian", "#282b2e"),
53 | PARAISO_DARK("paraiso-dark", "#2f1e2e"),
54 | PARAISO_LIGHT("paraiso-light", "#e7e9db"),
55 | POJOAQUE("pojoaque", "#073642"),
56 | PUREBASIC("purebasic", "#FFFFDF"),
57 | QTCREATOR_DARK("qtcreator_dark", "#000000"),
58 | QTCREATOR_LIGHT("qtcreator_light", "#ffffff"),
59 | RAILSCASTS("railscasts", "#232323"),
60 | RAINBOW("rainbow", "#474949"),
61 | SOLARIZED_DARK("solarized-dark", "#002b36"),
62 | SOLARIZED_LIGHT("solarized-light", "#fdf6e3"),
63 | SUNBURST("sunburst", "#000000"),
64 | TOMORROW_NIGHT_BLUE("tomorrow-night-blue", "#002451"),
65 | TOMORROW_NIGHT_EIGHTIES("tomorrow-night-eighties", "#2d2d2d"),
66 | TOMORROW_NIGHT("tomorrow-night", "#1d1f21"),
67 | XCODE("xcode", "#0f0f0f"),
68 | XT256("xt256", "#000000"),
69 | ZENBURN("zenburn", "#3f3f3f");
70 |
71 | private String name;
72 | private String backgroundColor;
73 |
74 | private CodeViewTheme(String name, String backgroundColor) {
75 | this.name = name;
76 | this.backgroundColor = backgroundColor;
77 | }
78 |
79 | public String getBackgroundColor() {
80 | return backgroundColor;
81 | }
82 |
83 | public String getName() {
84 | return name;
85 |
86 | }
87 |
88 | private static CodeViewTheme[] themes;
89 |
90 | public static CodeViewTheme[] listThemes() {
91 | if (themes == null) {
92 | themes = new CodeViewTheme[]{
93 | AGATE, ANDROIDSTUDIO, ARDUINO_LIGHT, ARTA, ATELIER_CAVE_DARK, ATELIER_CAVE_LIGHT,
94 | ATELIER_DUNE_DARK, ATELIER_DUNE_LIGHT, ATELIER_ESTUARY_DARK, ATELIER_ESTUARY_LIGHT,
95 | ATELIER_FOREST_DARK, ATELIER_FOREST_LIGHT, ATELIER_HEATH_DARK, ATELIER_HEATH_LIGHT,
96 | ATELIER_LAKESIDE_DARK, ATELIER_LAKESIDE_LIGHT, ATELIER_PLATEAU_DARK, ATELIER_PLATEAU_LIGHT,
97 | ATELIER_SAVANNA_DARK, ATELIER_SAVANNA_LIGHT, ATELIER_SEASIDE_DARK, ATELIER_SEASIDE_LIGHT,
98 | ATELIER_SULPHURPOOL_DARK, ATELIER_SULPHURPOOL_LIGHT, CODEPEN_EMBED, COLOR_BREWER, DARK, DARKULA,
99 | DEFAULT, DOCCO, DRACULA, FAR, FOUNDATION, GITHUB, GRAYSCALE, GRUVBOX_DARK, GRUVBOX_LIGHT, HOPSCOTCH,
100 | HYBRID, IDEA, IR_BLACK, MONO_BLUE, MONOKAI_SUBLIME, MONOKAI, OBSIDIAN, PARAISO_DARK, PARAISO_LIGHT,
101 | POJOAQUE, PUREBASIC, QTCREATOR_DARK, QTCREATOR_LIGHT, RAILSCASTS, RAINBOW, SOLARIZED_DARK,
102 | SOLARIZED_LIGHT, SUNBURST, TOMORROW_NIGHT_BLUE, TOMORROW_NIGHT_EIGHTIES, TOMORROW_NIGHT,
103 | XCODE, XT256, ZENBURN,
104 | };
105 | }
106 | return themes;
107 | }
108 | }
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/uplib.gradle:
--------------------------------------------------------------------------------
1 | class UpData {
2 |
3 | def up_siteUrl = 'thereisnospon.com' // project homepage
4 | def up_gitUrl = 'https://github.com/Thereisnospon' // project git
5 |
6 | def up_projectName = ""
7 |
8 | def up_bintray_pkg_license = "Apache-2.0"
9 | def up_pom_projects_licens = "The Apache Software License, Version 2.0"
10 | def up_pom_projects_url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
11 |
12 | def up_develop_id = 'thereisnospon'
13 | def up_develop_name = 'thereisnospon'
14 | def up_develop_email = 'thereisnospon@qq.com'
15 |
16 | def up_group = ""
17 | def up_version = ""
18 |
19 | def pkg_name = null
20 | }
21 | /**
22 | * ../gradlew bintrayUpload
23 | */
24 | ext {
25 |
26 | publishAar = { Closure closure ->
27 | UpData goData = new UpData()
28 | if (closure == null) {
29 |
30 | } else {
31 | closure.delegate = goData
32 | closure()
33 | configUpload(goData)
34 | }
35 | }
36 | }
37 |
38 | def configUpload(UpData upData) {
39 |
40 |
41 | if ((upData.up_group == null || upData.up_group.isEmpty())) {
42 | throw new IllegalArgumentException("up_group error, ext.uplib.group=$upData.up_group")
43 | } else {
44 | project.group = upData.up_group
45 | }
46 |
47 | if ((upData.up_version == null || upData.up_version.isEmpty())) {
48 | throw new IllegalArgumentException("up_version error, ext.uplib.version=$upData.up_version")
49 | } else {
50 | project.version = upData.up_version
51 | }
52 |
53 | if (upData.up_projectName == null || upData.up_projectName.isEmpty()) {
54 | throw new IllegalArgumentException("up_projectName error,ext.uplib.up_projectName=$upData.up_projectName")
55 | }
56 |
57 | project.with {
58 |
59 | apply plugin: 'com.github.dcendents.android-maven'
60 | apply plugin: 'com.jfrog.bintray'
61 |
62 | // 根节点添加
63 | def siteUrl = upData.up_siteUrl // project homepage
64 | def gitUrl = upData.up_gitUrl // project git
65 |
66 | def projectName = upData.up_projectName
67 |
68 | def bintray_pkg_license = upData.up_bintray_pkg_license
69 | def pom_projects_licens = upData.up_pom_projects_licens
70 | def pom_projects_url = upData.up_pom_projects_url
71 |
72 | def develop_id = upData.up_develop_id
73 | def develop_name = upData.up_develop_name
74 | def develop_email = upData.up_develop_email
75 | def pkg_name = upData.pkg_name
76 |
77 | //配置bintray参数
78 | Properties properties = new Properties()
79 |
80 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
81 | bintray {
82 | user = properties.getProperty("bintrayUser")
83 | key = properties.getProperty("bintrayApiKey")
84 | configurations = ['archives']
85 | pkg {
86 | repo = "maven" //跟上面创建的Maven仓库名字保持一致
87 | name = pkg_name != null ? pkg_name : projectName //发布到JCenter上的项目名字
88 | websiteUrl = siteUrl
89 | vcsUrl = gitUrl
90 | licenses = [bintray_pkg_license]
91 | publish = true
92 | }
93 | }
94 |
95 |
96 |
97 | task sourcesJar(type: Jar) {
98 | from android.sourceSets.main.java.srcDirs
99 | classifier = 'sources'
100 | }
101 | task javadoc(type: Javadoc) {
102 | source = android.sourceSets.main.java.srcDirs
103 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
104 | }
105 |
106 | task javadocJar(type: Jar, dependsOn: javadoc) {
107 | classifier = 'javadoc'
108 | from javadoc.destinationDir
109 | }
110 |
111 | artifacts {
112 | archives javadocJar
113 | archives sourcesJar
114 | }
115 |
116 | tasks.withType(Javadoc) {
117 | options.addStringOption('Xdoclint:none', '-quiet')
118 | options.addStringOption('encoding', 'UTF-8')
119 | options.addStringOption('charSet', 'UTF-8')
120 | }
121 |
122 | // 根节点添加
123 | install {
124 | repositories.mavenInstaller {
125 | // This generates POM.xml with proper parameters
126 | pom {
127 | project {
128 | packaging 'aar'
129 | name projectName
130 | url siteUrl
131 | // Set your license
132 | licenses {
133 | license {
134 | name pom_projects_licens
135 | url pom_projects_url
136 | }
137 | }
138 | developers {
139 | developer { //填写的一些基本信息
140 | id develop_id
141 | name develop_name
142 | email develop_email
143 | }
144 | }
145 | scm {
146 | connection gitUrl
147 | developerConnection gitUrl
148 | url siteUrl
149 | }
150 | }
151 | }
152 | }
153 | }
154 |
155 | tasks.getByName("bintrayUpload").dependsOn("install")
156 |
157 | tasks.getByPath(":${project.name}:javadoc").enabled = false
158 | }
159 | }
160 |
161 |
--------------------------------------------------------------------------------
/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 |
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 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
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 |
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 |
--------------------------------------------------------------------------------
/codeview/codeview.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |