Moving HighlightJS into app. (#477)
Final fixes and improvements. Fixing crash of app in Android 5.0 Removing unused theme. Moving HighlightJS to app. Reviewed-on: https://gitea.com/gitnex/GitNex/pulls/477 Reviewed-by: M M Arif <mmarif@swatian.com>
This commit is contained in:
parent
c41ab845fd
commit
5d1efe0f3f
@ -38,7 +38,7 @@ dependencies {
|
|||||||
def acra = "5.5.0"
|
def acra = "5.5.0"
|
||||||
|
|
||||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||||
implementation "androidx.appcompat:appcompat:1.1.0"
|
implementation "androidx.appcompat:appcompat:1.2.0-beta01"
|
||||||
implementation "com.google.android.material:material:1.2.0-alpha06"
|
implementation "com.google.android.material:material:1.2.0-alpha06"
|
||||||
implementation "androidx.constraintlayout:constraintlayout:1.1.3"
|
implementation "androidx.constraintlayout:constraintlayout:1.1.3"
|
||||||
implementation "androidx.legacy:legacy-support-v4:1.0.0"
|
implementation "androidx.legacy:legacy-support-v4:1.0.0"
|
||||||
@ -79,7 +79,6 @@ dependencies {
|
|||||||
implementation "com.github.HamidrezaAmz:BreadcrumbsView:0.2.9"
|
implementation "com.github.HamidrezaAmz:BreadcrumbsView:0.2.9"
|
||||||
implementation "commons-io:commons-io:20030203.000550"
|
implementation "commons-io:commons-io:20030203.000550"
|
||||||
implementation "com.github.chrisbanes:PhotoView:2.3.0"
|
implementation "com.github.chrisbanes:PhotoView:2.3.0"
|
||||||
implementation "com.pddstudio:highlightjs-android:1.5.0"
|
|
||||||
implementation "com.github.barteksc:android-pdf-viewer:3.2.0-beta.1"
|
implementation "com.github.barteksc:android-pdf-viewer:3.2.0-beta.1"
|
||||||
implementation "ch.acra:acra-mail:$acra"
|
implementation "ch.acra:acra-mail:$acra"
|
||||||
implementation "ch.acra:acra-limiter:$acra"
|
implementation "ch.acra:acra-limiter:$acra"
|
||||||
|
6
app/src/main/assets/highlightjs/highlight.pack.js
Normal file
6
app/src/main/assets/highlightjs/highlight.pack.js
Normal file
File diff suppressed because one or more lines are too long
1
app/src/main/assets/highlightjs/highlightjs-line-numbers.min.js
vendored
Normal file
1
app/src/main/assets/highlightjs/highlightjs-line-numbers.min.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
!function(e){"use strict";function t(){"complete"===document.readyState?n():e.addEventListener("DOMContentLoaded",n)}function n(){try{var e=document.querySelectorAll("code.hljs");for(var t in e)e.hasOwnProperty(t)&&r(e[t])}catch(n){console.error("LineNumbers error: ",n)}}function r(e){if("object"==typeof e){var t=e.parentNode,n=o(t.textContent);if(n>1){for(var r="",c=0;n>c;c++)r+=c+1+"\n";var l=document.createElement("code");l.className="hljs hljs-line-numbers",l.style["float"]="left",l.textContent=r,t.insertBefore(l,e)}}}function o(e){if(0===e.length)return 0;var t=/\r\n|\r|\n/g,n=e.match(t);return n=n?n.length:0,e[e.length-1].match(t)||(n+=1),n}"undefined"==typeof e.hljs?console.error("highlight.js not detected!"):(e.hljs.initLineNumbersOnLoad=t,e.hljs.lineNumbersBlock=r)}(window);
|
66
app/src/main/assets/highlightjs/themes/androidstudio.css
Normal file
66
app/src/main/assets/highlightjs/themes/androidstudio.css
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
Date: 24 Fev 2015
|
||||||
|
Author: Pedro Oliveira <kanytu@gmail . com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
.hljs {
|
||||||
|
color: #a9b7c6;
|
||||||
|
background: #282b2e;
|
||||||
|
display: block;
|
||||||
|
overflow-x: auto;
|
||||||
|
padding: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-number,
|
||||||
|
.hljs-literal,
|
||||||
|
.hljs-symbol,
|
||||||
|
.hljs-bullet {
|
||||||
|
color: #6897BB;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-keyword,
|
||||||
|
.hljs-selector-tag,
|
||||||
|
.hljs-deletion {
|
||||||
|
color: #cc7832;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-variable,
|
||||||
|
.hljs-template-variable,
|
||||||
|
.hljs-link {
|
||||||
|
color: #629755;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-comment,
|
||||||
|
.hljs-quote {
|
||||||
|
color: #808080;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-meta {
|
||||||
|
color: #bbb529;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-string,
|
||||||
|
.hljs-attribute,
|
||||||
|
.hljs-addition {
|
||||||
|
color: #6A8759;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-section,
|
||||||
|
.hljs-title,
|
||||||
|
.hljs-type {
|
||||||
|
color: #ffc66d;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-name,
|
||||||
|
.hljs-selector-id,
|
||||||
|
.hljs-selector-class {
|
||||||
|
color: #e8bf6a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-emphasis {
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-strong {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
87
app/src/main/assets/highlightjs/themes/arduino-light.css
Normal file
87
app/src/main/assets/highlightjs/themes/arduino-light.css
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Arduino® Light Theme - Stefania Mellai <s.mellai@arduino.cc>
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
.hljs {
|
||||||
|
display: block;
|
||||||
|
overflow-x: auto;
|
||||||
|
padding: 0.5em;
|
||||||
|
background: #FFFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs,
|
||||||
|
.hljs-subst {
|
||||||
|
color: #434f54;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-keyword,
|
||||||
|
.hljs-attribute,
|
||||||
|
.hljs-selector-tag,
|
||||||
|
.hljs-doctag,
|
||||||
|
.hljs-name {
|
||||||
|
color: #00979D;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-built_in,
|
||||||
|
.hljs-literal,
|
||||||
|
.hljs-bullet,
|
||||||
|
.hljs-code,
|
||||||
|
.hljs-addition {
|
||||||
|
color: #D35400;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-regexp,
|
||||||
|
.hljs-symbol,
|
||||||
|
.hljs-variable,
|
||||||
|
.hljs-template-variable,
|
||||||
|
.hljs-link,
|
||||||
|
.hljs-selector-attr,
|
||||||
|
.hljs-selector-pseudo {
|
||||||
|
color: #00979D;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-type,
|
||||||
|
.hljs-string,
|
||||||
|
.hljs-selector-id,
|
||||||
|
.hljs-selector-class,
|
||||||
|
.hljs-quote,
|
||||||
|
.hljs-template-tag,
|
||||||
|
.hljs-deletion {
|
||||||
|
color: #005C5F;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-title,
|
||||||
|
.hljs-section {
|
||||||
|
color: #880000;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-comment {
|
||||||
|
color: rgba(149,165,166,.8);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-meta-keyword {
|
||||||
|
color: #728E00;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-meta {
|
||||||
|
color: #434f54;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-emphasis {
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-strong {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-function {
|
||||||
|
color: #728E00;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-number {
|
||||||
|
color: #8A7B52;
|
||||||
|
}
|
71
app/src/main/assets/highlightjs/themes/far.css
Normal file
71
app/src/main/assets/highlightjs/themes/far.css
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
FAR Style (c) MajestiC <majestic2k@gmail.com>
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
.hljs {
|
||||||
|
display: block;
|
||||||
|
overflow-x: auto;
|
||||||
|
padding: 0.5em;
|
||||||
|
background: #000080;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs,
|
||||||
|
.hljs-subst {
|
||||||
|
color: #0ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-string,
|
||||||
|
.hljs-attribute,
|
||||||
|
.hljs-symbol,
|
||||||
|
.hljs-bullet,
|
||||||
|
.hljs-built_in,
|
||||||
|
.hljs-builtin-name,
|
||||||
|
.hljs-template-tag,
|
||||||
|
.hljs-template-variable,
|
||||||
|
.hljs-addition {
|
||||||
|
color: #ff0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-keyword,
|
||||||
|
.hljs-selector-tag,
|
||||||
|
.hljs-section,
|
||||||
|
.hljs-type,
|
||||||
|
.hljs-name,
|
||||||
|
.hljs-selector-id,
|
||||||
|
.hljs-selector-class,
|
||||||
|
.hljs-variable {
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-comment,
|
||||||
|
.hljs-quote,
|
||||||
|
.hljs-doctag,
|
||||||
|
.hljs-deletion {
|
||||||
|
color: #888;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-number,
|
||||||
|
.hljs-regexp,
|
||||||
|
.hljs-literal,
|
||||||
|
.hljs-link {
|
||||||
|
color: #0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-meta {
|
||||||
|
color: #008080;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-keyword,
|
||||||
|
.hljs-selector-tag,
|
||||||
|
.hljs-title,
|
||||||
|
.hljs-section,
|
||||||
|
.hljs-name,
|
||||||
|
.hljs-strong {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-emphasis {
|
||||||
|
font-style: italic;
|
||||||
|
}
|
99
app/src/main/assets/highlightjs/themes/github.css
Normal file
99
app/src/main/assets/highlightjs/themes/github.css
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
github.com style (c) Vasily Polovnyov <vast@whiteants.net>
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
.hljs {
|
||||||
|
display: block;
|
||||||
|
overflow-x: auto;
|
||||||
|
padding: 0.5em;
|
||||||
|
color: #333;
|
||||||
|
background: #f8f8f8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-comment,
|
||||||
|
.hljs-quote {
|
||||||
|
color: #998;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-keyword,
|
||||||
|
.hljs-selector-tag,
|
||||||
|
.hljs-subst {
|
||||||
|
color: #333;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-number,
|
||||||
|
.hljs-literal,
|
||||||
|
.hljs-variable,
|
||||||
|
.hljs-template-variable,
|
||||||
|
.hljs-tag .hljs-attr {
|
||||||
|
color: #008080;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-string,
|
||||||
|
.hljs-doctag {
|
||||||
|
color: #d14;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-title,
|
||||||
|
.hljs-section,
|
||||||
|
.hljs-selector-id {
|
||||||
|
color: #900;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-subst {
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-type,
|
||||||
|
.hljs-class .hljs-title {
|
||||||
|
color: #458;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-tag,
|
||||||
|
.hljs-name,
|
||||||
|
.hljs-attribute {
|
||||||
|
color: #000080;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-regexp,
|
||||||
|
.hljs-link {
|
||||||
|
color: #009926;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-symbol,
|
||||||
|
.hljs-bullet {
|
||||||
|
color: #990073;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-built_in,
|
||||||
|
.hljs-builtin-name {
|
||||||
|
color: #0086b3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-meta {
|
||||||
|
color: #999;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-deletion {
|
||||||
|
background: #fdd;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-addition {
|
||||||
|
background: #dfd;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-emphasis {
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-strong {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
73
app/src/main/assets/highlightjs/themes/ir-black.css
Normal file
73
app/src/main/assets/highlightjs/themes/ir-black.css
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
IR_Black style (c) Vasily Mikhailitchenko <vaskas@programica.ru>
|
||||||
|
*/
|
||||||
|
|
||||||
|
.hljs {
|
||||||
|
display: block;
|
||||||
|
overflow-x: auto;
|
||||||
|
padding: 0.5em;
|
||||||
|
background: #000;
|
||||||
|
color: #f8f8f8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-comment,
|
||||||
|
.hljs-quote,
|
||||||
|
.hljs-meta {
|
||||||
|
color: #7c7c7c;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-keyword,
|
||||||
|
.hljs-selector-tag,
|
||||||
|
.hljs-tag,
|
||||||
|
.hljs-name {
|
||||||
|
color: #96cbfe;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-attribute,
|
||||||
|
.hljs-selector-id {
|
||||||
|
color: #ffffb6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-string,
|
||||||
|
.hljs-selector-attr,
|
||||||
|
.hljs-selector-pseudo,
|
||||||
|
.hljs-addition {
|
||||||
|
color: #a8ff60;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-subst {
|
||||||
|
color: #daefa3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-regexp,
|
||||||
|
.hljs-link {
|
||||||
|
color: #e9c062;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-title,
|
||||||
|
.hljs-section,
|
||||||
|
.hljs-type,
|
||||||
|
.hljs-doctag {
|
||||||
|
color: #ffffb6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-symbol,
|
||||||
|
.hljs-bullet,
|
||||||
|
.hljs-variable,
|
||||||
|
.hljs-template-variable,
|
||||||
|
.hljs-literal {
|
||||||
|
color: #c6c5fe;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-number,
|
||||||
|
.hljs-deletion {
|
||||||
|
color:#ff73fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-emphasis {
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-strong {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
83
app/src/main/assets/highlightjs/themes/monokai-sublime.css
Normal file
83
app/src/main/assets/highlightjs/themes/monokai-sublime.css
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Monokai Sublime style. Derived from Monokai by noformnocontent http://nn.mit-license.org/
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
.hljs {
|
||||||
|
display: block;
|
||||||
|
overflow-x: auto;
|
||||||
|
padding: 0.5em;
|
||||||
|
background: #23241f;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs,
|
||||||
|
.hljs-tag,
|
||||||
|
.hljs-subst {
|
||||||
|
color: #f8f8f2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-strong,
|
||||||
|
.hljs-emphasis {
|
||||||
|
color: #a8a8a2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-bullet,
|
||||||
|
.hljs-quote,
|
||||||
|
.hljs-number,
|
||||||
|
.hljs-regexp,
|
||||||
|
.hljs-literal,
|
||||||
|
.hljs-link {
|
||||||
|
color: #ae81ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-code,
|
||||||
|
.hljs-title,
|
||||||
|
.hljs-section,
|
||||||
|
.hljs-selector-class {
|
||||||
|
color: #a6e22e;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-strong {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-emphasis {
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-keyword,
|
||||||
|
.hljs-selector-tag,
|
||||||
|
.hljs-name,
|
||||||
|
.hljs-attr {
|
||||||
|
color: #f92672;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-symbol,
|
||||||
|
.hljs-attribute {
|
||||||
|
color: #66d9ef;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-params,
|
||||||
|
.hljs-class .hljs-title {
|
||||||
|
color: #f8f8f2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-string,
|
||||||
|
.hljs-type,
|
||||||
|
.hljs-built_in,
|
||||||
|
.hljs-builtin-name,
|
||||||
|
.hljs-selector-id,
|
||||||
|
.hljs-selector-attr,
|
||||||
|
.hljs-selector-pseudo,
|
||||||
|
.hljs-addition,
|
||||||
|
.hljs-variable,
|
||||||
|
.hljs-template-variable {
|
||||||
|
color: #e6db74;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-comment,
|
||||||
|
.hljs-deletion,
|
||||||
|
.hljs-meta {
|
||||||
|
color: #75715e;
|
||||||
|
}
|
@ -28,14 +28,14 @@ import androidx.core.content.ContextCompat;
|
|||||||
import com.github.barteksc.pdfviewer.PDFView;
|
import com.github.barteksc.pdfviewer.PDFView;
|
||||||
import com.github.barteksc.pdfviewer.util.FitPolicy;
|
import com.github.barteksc.pdfviewer.util.FitPolicy;
|
||||||
import com.github.chrisbanes.photoview.PhotoView;
|
import com.github.chrisbanes.photoview.PhotoView;
|
||||||
import com.pddstudio.highlightjs.HighlightJsView;
|
|
||||||
import com.pddstudio.highlightjs.models.Theme;
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
import org.mian.gitnex.fragments.BottomSheetFileViewerFragment;
|
import org.mian.gitnex.fragments.BottomSheetFileViewerFragment;
|
||||||
import org.mian.gitnex.helpers.AlertDialogs;
|
import org.mian.gitnex.helpers.AlertDialogs;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
|
import org.mian.gitnex.helpers.highlightjs.HighlightJsView;
|
||||||
|
import org.mian.gitnex.helpers.highlightjs.models.Theme;
|
||||||
import org.mian.gitnex.models.Files;
|
import org.mian.gitnex.models.Files;
|
||||||
import org.mian.gitnex.util.AppUtil;
|
import org.mian.gitnex.util.AppUtil;
|
||||||
import org.mian.gitnex.util.TinyDB;
|
import org.mian.gitnex.util.TinyDB;
|
||||||
@ -196,7 +196,6 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
|||||||
singleCodeContents.setTheme(Theme.MONOKAI_SUBLIME);
|
singleCodeContents.setTheme(Theme.MONOKAI_SUBLIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
singleCodeContents.setShowLineNumbers(true);
|
|
||||||
singleCodeContents.setSource(appUtil.decodeBase64(response.body().getContent()));
|
singleCodeContents.setSource(appUtil.decodeBase64(response.body().getContent()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,8 @@ public class SettingsFileViewerActivity extends BaseActivity {
|
|||||||
private Context appCtx;
|
private Context appCtx;
|
||||||
private View.OnClickListener onClickListener;
|
private View.OnClickListener onClickListener;
|
||||||
|
|
||||||
private static String[] fileveiwerSourceCodeThemesList = {"Sublime", "Arduino Light", "Github", "Far ", "Ir Black", "Android Studio"};
|
private static String[] fileViewerSourceCodeThemesList = {"Sublime", "Arduino Light", "Github", "Far ", "Ir Black", "Android Studio"};
|
||||||
private static int fileveiwerSourceCodeThemesSelectedChoice = 0;
|
private static int fileViewerSourceCodeThemesSelectedChoice = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getLayoutResourceId() {
|
protected int getLayoutResourceId() {
|
||||||
@ -43,18 +43,18 @@ public class SettingsFileViewerActivity extends BaseActivity {
|
|||||||
initCloseListener();
|
initCloseListener();
|
||||||
closeActivity.setOnClickListener(onClickListener);
|
closeActivity.setOnClickListener(onClickListener);
|
||||||
|
|
||||||
final TextView fileveiwerSourceCodeThemesSelected = findViewById(R.id.sourceCodeThemeSelected); // setter for fileviewer theme
|
final TextView fileViewerSourceCodeThemesSelected = findViewById(R.id.sourceCodeThemeSelected); // setter for fileviewer theme
|
||||||
|
|
||||||
LinearLayout sourceCodeThemeFrame = findViewById(R.id.sourceCodeThemeFrame);
|
LinearLayout sourceCodeThemeFrame = findViewById(R.id.sourceCodeThemeFrame);
|
||||||
|
|
||||||
Switch pdfModeSwitch = findViewById(R.id.switchPdfMode);
|
Switch pdfModeSwitch = findViewById(R.id.switchPdfMode);
|
||||||
|
|
||||||
if(!tinyDb.getString("fileviewerSourceCodeThemeStr").isEmpty()) {
|
if(!tinyDb.getString("fileviewerSourceCodeThemeStr").isEmpty()) {
|
||||||
fileveiwerSourceCodeThemesSelected.setText(tinyDb.getString("fileviewerSourceCodeThemeStr"));
|
fileViewerSourceCodeThemesSelected.setText(tinyDb.getString("fileviewerSourceCodeThemeStr"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fileveiwerSourceCodeThemesSelectedChoice == 0) {
|
if(fileViewerSourceCodeThemesSelectedChoice == 0) {
|
||||||
fileveiwerSourceCodeThemesSelectedChoice = tinyDb.getInt("fileviewerThemeId");
|
fileViewerSourceCodeThemesSelectedChoice = tinyDb.getInt("fileviewerThemeId");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tinyDb.getBoolean("enablePdfMode")) {
|
if(tinyDb.getBoolean("enablePdfMode")) {
|
||||||
@ -70,18 +70,18 @@ public class SettingsFileViewerActivity extends BaseActivity {
|
|||||||
AlertDialog.Builder fvtsBuilder = new AlertDialog.Builder(SettingsFileViewerActivity.this);
|
AlertDialog.Builder fvtsBuilder = new AlertDialog.Builder(SettingsFileViewerActivity.this);
|
||||||
|
|
||||||
fvtsBuilder.setTitle(R.string.fileviewerSourceCodeThemeSelectorDialogTitle);
|
fvtsBuilder.setTitle(R.string.fileviewerSourceCodeThemeSelectorDialogTitle);
|
||||||
if(fileveiwerSourceCodeThemesSelectedChoice != -1) {
|
if(fileViewerSourceCodeThemesSelectedChoice != -1) {
|
||||||
fvtsBuilder.setCancelable(true);
|
fvtsBuilder.setCancelable(true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fvtsBuilder.setCancelable(false);
|
fvtsBuilder.setCancelable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
fvtsBuilder.setSingleChoiceItems(fileveiwerSourceCodeThemesList, fileveiwerSourceCodeThemesSelectedChoice, (dialogInterfaceTheme, i) -> {
|
fvtsBuilder.setSingleChoiceItems(fileViewerSourceCodeThemesList, fileViewerSourceCodeThemesSelectedChoice, (dialogInterfaceTheme, i) -> {
|
||||||
|
|
||||||
fileveiwerSourceCodeThemesSelectedChoice = i;
|
fileViewerSourceCodeThemesSelectedChoice = i;
|
||||||
fileveiwerSourceCodeThemesSelected.setText(fileveiwerSourceCodeThemesList[i]);
|
fileViewerSourceCodeThemesSelected.setText(fileViewerSourceCodeThemesList[i]);
|
||||||
tinyDb.putString("fileviewerSourceCodeThemeStr", fileveiwerSourceCodeThemesList[i]);
|
tinyDb.putString("fileviewerSourceCodeThemeStr", fileViewerSourceCodeThemesList[i]);
|
||||||
tinyDb.putInt("fileviewerSourceCodeThemeId", i);
|
tinyDb.putInt("fileviewerSourceCodeThemeId", i);
|
||||||
|
|
||||||
dialogInterfaceTheme.dismiss();
|
dialogInterfaceTheme.dismiss();
|
||||||
@ -113,9 +113,7 @@ public class SettingsFileViewerActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initCloseListener() {
|
private void initCloseListener() {
|
||||||
onClickListener = view -> {
|
onClickListener = view -> finish();
|
||||||
finish();
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,112 @@
|
|||||||
|
package org.mian.gitnex.helpers.highlightjs;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.View;
|
||||||
|
import android.webkit.WebSettings;
|
||||||
|
import android.webkit.WebView;
|
||||||
|
|
||||||
|
import org.mian.gitnex.helpers.highlightjs.models.Language;
|
||||||
|
import org.mian.gitnex.helpers.highlightjs.models.Theme;
|
||||||
|
import org.mian.gitnex.helpers.highlightjs.utils.SourceUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This Class was created by Patrick J
|
||||||
|
* on 09.06.16. (modified by opyale)
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class HighlightJsView extends WebView {
|
||||||
|
|
||||||
|
private Language language = Language.AUTO_DETECT;
|
||||||
|
private Theme theme = Theme.DEFAULT;
|
||||||
|
|
||||||
|
private boolean zoomSupport = false;
|
||||||
|
private boolean showLineNumbers = true;
|
||||||
|
private TextWrap textWrap = TextWrap.NO_WRAP;
|
||||||
|
|
||||||
|
public HighlightJsView(Context context) {
|
||||||
|
|
||||||
|
super(context);
|
||||||
|
setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
public HighlightJsView(Context context, AttributeSet attrs) {
|
||||||
|
|
||||||
|
super(context, attrs);
|
||||||
|
setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
public HighlightJsView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
|
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SetJavaScriptEnabled")
|
||||||
|
private void setup() {
|
||||||
|
|
||||||
|
WebSettings settings = getSettings();
|
||||||
|
|
||||||
|
settings.setJavaScriptEnabled(true);
|
||||||
|
settings.setBuiltInZoomControls(true);
|
||||||
|
settings.setSupportZoom(zoomSupport);
|
||||||
|
settings.setDisplayZoomControls(false);
|
||||||
|
|
||||||
|
setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void changeZoomSettings(boolean enable) {
|
||||||
|
|
||||||
|
this.zoomSupport = enable;
|
||||||
|
getSettings().setSupportZoom(enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSource(String source) {
|
||||||
|
|
||||||
|
source = (source == null) ? " " : source;
|
||||||
|
|
||||||
|
String html_content = SourceUtils.generateContent(source, theme.getName(), language.getName(), zoomSupport, showLineNumbers, textWrap);
|
||||||
|
loadDataWithBaseURL("file:///android_asset/", html_content, "text/html", "utf-8", null);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refresh() {
|
||||||
|
|
||||||
|
super.reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHighlightLanguage(Language language) {
|
||||||
|
this.language = language;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTheme(Theme theme) {
|
||||||
|
this.theme = theme;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTextWrap(TextWrap textWrap) {
|
||||||
|
this.textWrap = textWrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Language getHighlightLanguage() {
|
||||||
|
return language;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Theme getTheme() {
|
||||||
|
return theme;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setZoomSupportEnabled(boolean supportZoom) {
|
||||||
|
changeZoomSettings(supportZoom);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShowLineNumbers(boolean showLineNumbers) {
|
||||||
|
this.showLineNumbers = showLineNumbers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum TextWrap {
|
||||||
|
NO_WRAP, WORD_WRAP, BREAK_ALL
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,181 @@
|
|||||||
|
package org.mian.gitnex.helpers.highlightjs.models;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This Class was created by Patrick J
|
||||||
|
* on 09.06.16.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public enum Language {
|
||||||
|
AUTO_DETECT(null),
|
||||||
|
DISABLE_HIGHLIGHT("nohighlight"),
|
||||||
|
_1C("1c"),
|
||||||
|
ABNF("abnf"),
|
||||||
|
ACCESS_LOGS("accesslog"),
|
||||||
|
ADA("ada"),
|
||||||
|
ARM_ASSEMBLER("arm"),
|
||||||
|
AVR_ASSEMBLER("avrasm"),
|
||||||
|
ACTION_SCRIPT("actionscript"),
|
||||||
|
APACHE("apache"),
|
||||||
|
APPLE_SCRIPT("applescript"),
|
||||||
|
ASCII_DOC("asciidoc"),
|
||||||
|
ASPECT_J("aspectj"),
|
||||||
|
AUTO_HOTKEY("autohotkey"),
|
||||||
|
AUTO_IT("autoit"),
|
||||||
|
AXAPTA("axapta"),
|
||||||
|
AWK("awk"),
|
||||||
|
BASH("bash"),
|
||||||
|
SHELL("sh"),
|
||||||
|
ZSH("zsh"),
|
||||||
|
BASIC("basic"),
|
||||||
|
BNF("bnf"),
|
||||||
|
BRAINFUCK("brainfuck"),
|
||||||
|
C("c"),
|
||||||
|
C_SHARP("csharp"),
|
||||||
|
C_PLUS_PLUS("cpp"),
|
||||||
|
CACHE_OBJECT_SCRIPT("cos"),
|
||||||
|
C_MAKE("cmake"),
|
||||||
|
COQ("coq"),
|
||||||
|
CSP("csp"),
|
||||||
|
CSS("css"),
|
||||||
|
CAPTAIN_PROTO("capnproto"),
|
||||||
|
CLEAN("clean"),
|
||||||
|
CLOJURE("clojure"),
|
||||||
|
COFFEE_SCRIPT("coffeescript"),
|
||||||
|
CRMSH("crmsh"),
|
||||||
|
CRYSTAL("crystal"),
|
||||||
|
D("d"),
|
||||||
|
DNS_ZONE_FILE("dns"),
|
||||||
|
DOS("dos"),
|
||||||
|
BATCH("bat"),
|
||||||
|
DART("dart"),
|
||||||
|
DELPHI("delphi"),
|
||||||
|
DIFF("diff"),
|
||||||
|
DJANGO("django"),
|
||||||
|
DOCKER_FILE("dockerfile"),
|
||||||
|
DSCONFIG("dsconfig"),
|
||||||
|
DTS("dts"),
|
||||||
|
DUST("dust"),
|
||||||
|
EBNF("ebnf"),
|
||||||
|
ELIXIR("elixir"),
|
||||||
|
ELM("elm"),
|
||||||
|
ERLANG("erlang"),
|
||||||
|
EXCEL("excel"),
|
||||||
|
F_SHARP("fsharp"),
|
||||||
|
FIX("fix"),
|
||||||
|
FLIX("flix"),
|
||||||
|
FORTRAN("fortran"),
|
||||||
|
G_CODE("gcode"),
|
||||||
|
GAMS("gams"),
|
||||||
|
GAUSS("gauss"),
|
||||||
|
GHERKIN("gherkin"),
|
||||||
|
GO("go"),
|
||||||
|
GOLO("golo"),
|
||||||
|
GRADLE("gradle"),
|
||||||
|
GROOVY("groovy"),
|
||||||
|
HTML("html"),
|
||||||
|
XML("xml"),
|
||||||
|
HTTP("http"),
|
||||||
|
HAML("haml"),
|
||||||
|
HANDLEBARS("hbs"),
|
||||||
|
HASKELL("hs"),
|
||||||
|
HAXE("hx"),
|
||||||
|
HY("hy"),
|
||||||
|
INI("ini"),
|
||||||
|
INFORM7("i7"),
|
||||||
|
IRPF90("irpf90"),
|
||||||
|
JSON("json"),
|
||||||
|
JAVA("java"),
|
||||||
|
JAVA_SCRIPT("javascript"),
|
||||||
|
LASSO("lasso"),
|
||||||
|
LEAF("leaf"),
|
||||||
|
LESS("less"),
|
||||||
|
LDIF("ldif"),
|
||||||
|
LISP("lisp"),
|
||||||
|
LIVE_CODE_SERVER("livecodeserver"),
|
||||||
|
LIVE_SCRIPT("livescript"),
|
||||||
|
LLVM("llvm"),
|
||||||
|
LUA("lua"),
|
||||||
|
MAKEFILE("makefile"),
|
||||||
|
MARKDOWN("md"),
|
||||||
|
MATHEMATICA("mma"),
|
||||||
|
MATLAB("matlab"),
|
||||||
|
MAXIMA("maxima"),
|
||||||
|
MAYA_EMBEDDED_LANGUAGE("mel"),
|
||||||
|
MERCURY("mercury"),
|
||||||
|
MIZAR("mizar"),
|
||||||
|
MOJOLICIOUS("mojolicious"),
|
||||||
|
MONKEY("monkey"),
|
||||||
|
MOONSCRIPT("moonscript"),
|
||||||
|
N1QL("n1ql"),
|
||||||
|
NSIS("nsis"),
|
||||||
|
NGINX("nginx"),
|
||||||
|
NIMROD("nimrod"),
|
||||||
|
NIX("nix"),
|
||||||
|
O_CAML("ocaml"),
|
||||||
|
OBJECTIVE_C("objectivec"),
|
||||||
|
OPENGL_SHADING_LANGUAGE("glsl"),
|
||||||
|
OPEN_SCAD("scad"),
|
||||||
|
ORACLE_RULES_LANGUAGE("ruleslanguage"),
|
||||||
|
OXYGENE("oxygene"),
|
||||||
|
PF("pf"),
|
||||||
|
PHP("php"),
|
||||||
|
PARSER3("parser3"),
|
||||||
|
PERL("perl"),
|
||||||
|
PONY("pony"),
|
||||||
|
POWER_SHELL("ps"),
|
||||||
|
PROCESSING("processing"),
|
||||||
|
PROLOG("prolog"),
|
||||||
|
PROTOCOL_BUFFERS("protobuf"),
|
||||||
|
PUPPET("pp"),
|
||||||
|
PYTHON("python"),
|
||||||
|
PYTHON_PROFILER_RESULTS("profile"),
|
||||||
|
Q("k"),
|
||||||
|
QML("qml"),
|
||||||
|
R("r"),
|
||||||
|
RENDER_MAN_RIB("rib"),
|
||||||
|
RENDER_MAN_RSL("rsl"),
|
||||||
|
ROBOCONF("roboconf"),
|
||||||
|
RUBY("ruby"),
|
||||||
|
RUST("rust"),
|
||||||
|
SCSS("scss"),
|
||||||
|
SQL("sql"),
|
||||||
|
STEP_PART_21("p21"),
|
||||||
|
SCALA("scala"),
|
||||||
|
SCHEME("scheme"),
|
||||||
|
SCILAB("sci"),
|
||||||
|
SMALI("smali"),
|
||||||
|
SMALLTALK("smalltalk"),
|
||||||
|
STAN("stan"),
|
||||||
|
STATA("stata"),
|
||||||
|
STYLUS("stylus"),
|
||||||
|
SUB_UNIT("subunit"),
|
||||||
|
SWIFT("swift"),
|
||||||
|
TEST_ANYTHING_PROTOCOL("tap"),
|
||||||
|
TCL("tcl"),
|
||||||
|
TEX("tex"),
|
||||||
|
THRIFT("thrift"),
|
||||||
|
TP("tp"),
|
||||||
|
TWIG("twig"),
|
||||||
|
TYPE_SCRIPT("typescript"),
|
||||||
|
VB_NET("vbnet"),
|
||||||
|
VB_SCRIPT("vbscript"),
|
||||||
|
VHDL("vhdl"),
|
||||||
|
VALA("vala"),
|
||||||
|
VERILOG("v"),
|
||||||
|
VIM("vim"),
|
||||||
|
X86_ASSEMBLY("x86asm"),
|
||||||
|
XL("xl"),
|
||||||
|
X_QUERY("xq"),
|
||||||
|
ZEPHIR("zep");
|
||||||
|
|
||||||
|
private final String className;
|
||||||
|
|
||||||
|
Language(String name) {
|
||||||
|
this.className = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return className;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,96 @@
|
|||||||
|
package org.mian.gitnex.helpers.highlightjs.models;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This Class was created by Patrick J
|
||||||
|
* on 09.06.16.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public enum Theme {
|
||||||
|
AGATE("agate"),
|
||||||
|
ANDROID_STUDIO("androidstudio"),
|
||||||
|
ARDUINO_LIGHT("arduino-light"),
|
||||||
|
ARTA("arta"),
|
||||||
|
ASCETIC("ascetic"),
|
||||||
|
ATELIER_CAVE_DARK("atelier-cave-dark"),
|
||||||
|
ATELIER_CAVE_LIGHT("atelier-cave-light"),
|
||||||
|
ATELIER_DUNE_DARK("atelier-dune-dark"),
|
||||||
|
ATELIER_DUNE_LIGHT("atelier-dune-light"),
|
||||||
|
ATELIER_ESTUARY_DARK("atelier-estuary-dark"),
|
||||||
|
ATELIER_ESTUARY_LIGHT("atelier-estuary-light"),
|
||||||
|
ATELIER_FOREST_DARK("atelier-forest-dark"),
|
||||||
|
ATELIER_FOREST_LIGHT("atelier-forest-light"),
|
||||||
|
ATELIER_HEATH_DARK("atelier-heath-dark"),
|
||||||
|
ATELIER_HEATH_LIGHT("atelier-heath-light"),
|
||||||
|
ATELIER_LAKESIDE_DARK("atelier-lakeside-dark"),
|
||||||
|
ATELIER_LAKESIDE_LIGHT("atelier-lakeside-light"),
|
||||||
|
ATELIER_PLATEAU_DARK("atelier-plateau-dark"),
|
||||||
|
ATELIER_PLATEAU_LIGHT("atelier-plateau-light"),
|
||||||
|
ATELIER_SAVANNA_DARK("atelier-savanna-dark"),
|
||||||
|
ATELIER_SAVANNA_LIGHT("atelier-savanna-light"),
|
||||||
|
ATELIER_SEASIDE_DARK("atelier-seaside-dark"),
|
||||||
|
ATELIER_SEASIDE_LIGHT("atelier-seaside-light"),
|
||||||
|
ATELIER_SULPHURPOOL_DARK("atelier-sulphurpool-dark"),
|
||||||
|
ATELIER_SULPHURPOOL_LIGHT("atelier-sulphurpool-light"),
|
||||||
|
ATOM_ONE_DARK("atom-one-dark"),
|
||||||
|
ATOM_ONE_LIGHT("atom-one-light"),
|
||||||
|
BROWN_PAPER("brown-paper"),
|
||||||
|
CODEPEN_EMBED("codepen-embed"),
|
||||||
|
COLOR_BREWER("color-brewer"),
|
||||||
|
DARK("dark"),
|
||||||
|
DARKULA("darkula"),
|
||||||
|
DEFAULT("default"),
|
||||||
|
DOCCO("docco"),
|
||||||
|
DRAKULA("drakula"),
|
||||||
|
FAR("far"),
|
||||||
|
FOUNDATION("foundaiton"),
|
||||||
|
GITHUB("github"),
|
||||||
|
GITHUB_GIST("github-gist"),
|
||||||
|
GOOGLECODE("googlecode"),
|
||||||
|
GRAYSCALE("grayscale"),
|
||||||
|
GRUVBOX_DARK("gruvbox-dark"),
|
||||||
|
GRUVBOX_LIGHT("gruvbox-light"),
|
||||||
|
HOPSCOTCH("hopscotch"),
|
||||||
|
HYBRID("hybrid"),
|
||||||
|
IDEA("idea"),
|
||||||
|
IR_BLACK("ir-black"),
|
||||||
|
KIMBIE_DARK("kimbie.dark"),
|
||||||
|
KIMBIE_LIGHT("kimbie.light"),
|
||||||
|
MAGULA("magula"),
|
||||||
|
MONO_BLUE("mono-blue"),
|
||||||
|
MONOKAI("monokai"),
|
||||||
|
MONOKAI_SUBLIME("monokai-sublime"),
|
||||||
|
OBSIDIAN("obsidian"),
|
||||||
|
OCEAN("ocean"),
|
||||||
|
PARAISO_DARK("paraiso-dark"),
|
||||||
|
PARAISO_LIGHT("paraiso-light"),
|
||||||
|
POJOAQUE("pojoaque"),
|
||||||
|
PURE_BASIC("purebasic"),
|
||||||
|
QT_CREATOR_DARK("qtcreator_dark"),
|
||||||
|
QT_CREATOR_LIGHT("qtcreator_light"),
|
||||||
|
RAILSCASTS("railscasts"),
|
||||||
|
RAINBOX("rainbow"),
|
||||||
|
SCHOOL_BOOK("school-book"),
|
||||||
|
SOLARIZED_DARK("solarized-dark"),
|
||||||
|
SOLARIZED_LIGHT("solarized-light"),
|
||||||
|
SUNBURST("sunburst"),
|
||||||
|
TOMORROW("tomorrow"),
|
||||||
|
TOMORROW_NIGHT_BLUE("tomorrow-night-blue"),
|
||||||
|
TOMORROW_NIGHT_BRIGHT("tomorrow-night-bright"),
|
||||||
|
TOMORROW_NIGHT("tomorrow-night"),
|
||||||
|
TOMORROW_NIGHT_EIGHTIES("tomorrow-night-eighties"),
|
||||||
|
VS("vs"),
|
||||||
|
X_CODE("xcode"),
|
||||||
|
XT256("xt256"),
|
||||||
|
ZENBURN("zenburn");
|
||||||
|
|
||||||
|
private final String themeName;
|
||||||
|
|
||||||
|
Theme(String themeName) {
|
||||||
|
this.themeName = themeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return themeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,98 @@
|
|||||||
|
package org.mian.gitnex.helpers.highlightjs.utils;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import org.mian.gitnex.helpers.highlightjs.HighlightJsView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This Class was created by Patrick J
|
||||||
|
* on 09.06.16. (modified by opyale)
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class SourceUtils {
|
||||||
|
|
||||||
|
public static String generateContent(String source, @NonNull String theme, @Nullable String language, boolean supportZoom, boolean showLineNumbers,
|
||||||
|
HighlightJsView.TextWrap textWrap) {
|
||||||
|
|
||||||
|
return getStylePageHeader(supportZoom, textWrap) +
|
||||||
|
getSourceForTheme(theme) +
|
||||||
|
(showLineNumbers ? getLineNumberStyling() : "") +
|
||||||
|
getScriptPageHeader(showLineNumbers) +
|
||||||
|
getSourceForLanguage(source, language) +
|
||||||
|
getTemplateFooter();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getStylePageHeader(boolean enableZoom, HighlightJsView.TextWrap textWrap) {
|
||||||
|
|
||||||
|
String preTag;
|
||||||
|
|
||||||
|
switch (textWrap) {
|
||||||
|
|
||||||
|
case WORD_WRAP:
|
||||||
|
preTag = "pre { white-space: pre-wrap; word-wrap: break-word; }";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BREAK_ALL:
|
||||||
|
preTag = "pre { white-space: pre-wrap; word-break: break-all; }";
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
preTag = "pre { }";
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return "<!DOCTYPE html>" +
|
||||||
|
"<html>" +
|
||||||
|
"<head>" +
|
||||||
|
"<meta charset=\"utf-8\">" +
|
||||||
|
(enableZoom ? "" : "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0\">") +
|
||||||
|
"<style>" +
|
||||||
|
"html, body { width:100%; height: 100%; margin: 0px; padding: 0px; }" +
|
||||||
|
preTag +
|
||||||
|
"</style>";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getScriptPageHeader(boolean showLineNumbers) {
|
||||||
|
|
||||||
|
return "<script src=\"./highlightjs/highlight.pack.js\"></script>" +
|
||||||
|
(showLineNumbers ? "<script src=\"./highlightjs/highlightjs-line-numbers.min.js\"></script>" : "") +
|
||||||
|
"<script>hljs.initHighlightingOnLoad();</script>" +
|
||||||
|
(showLineNumbers ? "<script>hljs.initLineNumbersOnLoad();</script>" : "") +
|
||||||
|
"</head><body style=\"margin: 0; padding: 0\" class=\"hljs\">";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getLineNumberStyling() {
|
||||||
|
|
||||||
|
return "<style>" +
|
||||||
|
".hljs-line-numbers { text-align: right; border-right: 1px solid #ccc; color: #999; user-select: none; }" +
|
||||||
|
"</style>";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getTemplateFooter() {
|
||||||
|
|
||||||
|
return "</body></html>";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String escapeCode(String code) {
|
||||||
|
|
||||||
|
return code.replaceAll("<", "<")
|
||||||
|
.replaceAll(">", ">");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getSourceForTheme(String theme) {
|
||||||
|
|
||||||
|
return String.format("<link rel=\"stylesheet\" href=\"./highlightjs/themes/%s.css\">", theme);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getSourceForLanguage(String source, String language) {
|
||||||
|
|
||||||
|
if (language != null) {
|
||||||
|
return String.format("<pre><code class=\"%s\">%s</code></pre>", language, escapeCode(source));
|
||||||
|
} else {
|
||||||
|
return String.format("<pre><code>%s</code></pre>", escapeCode(source));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -89,7 +89,7 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<com.pddstudio.highlightjs.HighlightJsView
|
<org.mian.gitnex.helpers.highlightjs.HighlightJsView
|
||||||
android:id="@+id/singleCodeContents"
|
android:id="@+id/singleCodeContents"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user