diff --git a/README.md b/README.md
index 6cffa01..551cd64 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
# CodeView (Android)
[](https://android-arsenal.com/details/1/4216)
-[](https://jitpack.io/#kbiakov/CodeView-Android)
+[](https://jitpack.io/#kbiakov/CodeView-Android)
[](https://travis-ci.org/kbiakov/CodeView-Android)
@@ -226,11 +226,11 @@ List of apps on Play Store where this library used. Ping me if you want to be he
Icon | Application
------------ | -------------
| [GeekBrains]
-
| [Awesome Android - UI Libraries]
| [Codify - Codes On The Go]
+
| [C Programming - 200+ Offline Tutorial and Examples]
+
| [Awesome Android - UI Libraries]
| [GitJourney for GitHub]
| [Source Code - Lập Trình]
-
| [C Programming - CodeSpot]
## Contribute
1. You can add your theme (see [ColorTheme](https://github.com/Softwee/codeview-android/blob/master/codeview/src/main/java/io/github/kbiakov/codeview/highlight/CodeHighlighter.kt) class). Try to add some classic color themes or create your own if it looks cool. You can find many of them in different open-source text editors.
@@ -264,8 +264,8 @@ SOFTWARE.
```
[GeekBrains]:https://play.google.com/store/apps/details?id=ru.geekbrains
+[Codify - Codes On The Go]:https://play.google.com/store/apps/details?id=com.femindharamshi.spa
+[C Programming - 200+ Offline Tutorial and Examples]:https://play.google.com/store/apps/details?id=com.rsd.cprogramming
[Awesome Android - UI Libraries]:https://play.google.com/store/apps/details?id=in.sumeetlubal.aweandroid.aweandroid
[GitJourney for GitHub]:https://play.google.com/store/apps/details?id=com.oklab.githubjourney
-[Codify - Codes On The Go]:https://play.google.com/store/apps/details?id=com.femindharamshi.spa
[Source Code - Lập Trình]:https://play.google.com/store/apps/details?id=com.noah.truongpq.codeview
-[C Programming - CodeSpot]:https://play.google.com/store/apps/details?id=com.rsd.cprogramming
diff --git a/build.gradle b/build.gradle
index 37ef2a4..0173b17 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,18 +1,18 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
- ext.kotlinVersion = '1.3.11'
+ ext.kotlinVersion = '1.3.21'
ext.minSdk = 15
ext.compileSdk = 28
ext.buildTools = '28.0.3'
- ext.supportLibrary = '28.0.0'
+ ext.androidxLibrary = '1.1.0-alpha02'
repositories {
jcenter()
google()
}
dependencies {
- classpath 'com.android.tools.build:gradle:3.3.0'
+ classpath 'com.android.tools.build:gradle:3.3.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
diff --git a/codeview/build.gradle b/codeview/build.gradle
index c460859..3009fee 100644
--- a/codeview/build.gradle
+++ b/codeview/build.gradle
@@ -24,6 +24,6 @@ android {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
- implementation "com.android.support:appcompat-v7:$supportLibrary"
- implementation "com.android.support:recyclerview-v7:$supportLibrary"
+ implementation "androidx.appcompat:appcompat:$androidxLibrary"
+ implementation "androidx.recyclerview:recyclerview:$androidxLibrary"
}
diff --git a/codeview/src/main/java/io/github/kbiakov/codeview/CodeView.kt b/codeview/src/main/java/io/github/kbiakov/codeview/CodeView.kt
index f8f6d0c..3d404e4 100644
--- a/codeview/src/main/java/io/github/kbiakov/codeview/CodeView.kt
+++ b/codeview/src/main/java/io/github/kbiakov/codeview/CodeView.kt
@@ -3,11 +3,11 @@ package io.github.kbiakov.codeview
import android.content.Context
import android.graphics.drawable.Drawable
import android.graphics.drawable.GradientDrawable
-import android.support.v7.widget.LinearLayoutManager
-import android.support.v7.widget.RecyclerView
import android.util.AttributeSet
import android.view.View
import android.widget.RelativeLayout
+import androidx.recyclerview.widget.LinearLayoutManager
+import androidx.recyclerview.widget.RecyclerView
import io.github.kbiakov.codeview.Thread.delayed
import io.github.kbiakov.codeview.adapters.AbstractCodeAdapter
import io.github.kbiakov.codeview.adapters.CodeWithNotesAdapter
@@ -18,7 +18,7 @@ import io.github.kbiakov.codeview.highlight.color
/**
* @class CodeView
*
- * View for showing code content with syntax highlighting.
+ * Display code with syntax highlighting.
*
* @author Kirill Biakov
*/
@@ -28,8 +28,9 @@ class CodeView @JvmOverloads constructor(
defStyleAttr: Int = 0
) : RelativeLayout(context, attrs, defStyleAttr) {
- private val vCodeList: RecyclerView
- private val vShadows: Map
+ private val rvContent: RecyclerView
+ private val shadows: Map
+ private val adapter get() = rvContent.adapter as? AbstractCodeAdapter<*>
/**
* Primary constructor.
@@ -38,12 +39,12 @@ class CodeView @JvmOverloads constructor(
inflate(context, R.layout.layout_code_view, this)
attrs?.let(::checkStartAnimation)
- vCodeList = findViewById(R.id.rv_code_content).apply {
+ rvContent = findViewById(R.id.rv_content).apply {
layoutManager = LinearLayoutManager(context)
isNestedScrollingEnabled = true
}
- vShadows = mapOf(
+ shadows = mapOf(
ShadowPosition.RightBorder to R.id.shadow_right_border,
ShadowPosition.NumBottom to R.id.shadow_num_bottom,
ShadowPosition.ContentBottom to R.id.shadow_content_bottom
@@ -78,39 +79,27 @@ class CodeView @JvmOverloads constructor(
}
}
- /**
- * Highlight code with defined programming language.
- * It holds the placeholder on view until code is not highlighted.
- */
- private fun highlight() {
- getAdapter()?.apply {
- highlight {
- checkHighlightAnimation(::notifyDataSetChanged)
- }
- }
- }
-
/**
* Border shadows will shown if full listing presented.
- * It helps to see what part of code is scrolled & hidden.
+ * It helps to see which part of code is scrolled & hidden.
*
* @param isVisible Is shadows visible
*/
fun setupShadows(isVisible: Boolean) {
val visibility = if (isVisible) VISIBLE else GONE
- val theme = getOptionsOrDefault().theme
- vShadows.forEach { (pos, view) ->
+ val theme = optionsOrDefault.theme
+ shadows.forEach { (pos, view) ->
view.visibility = visibility
view.setSafeBackground(pos.createShadow(theme))
}
}
- // - Initialization
+ // - Options
/**
- * Prepare view with default adapter & options.
+ * View options accessor.
*/
- private fun prepare() = setAdapter(CodeWithNotesAdapter(context))
+ private val optionsOrDefault get() = adapter?.options ?: Options(context)
/**
* Initialize with options.
@@ -119,102 +108,98 @@ class CodeView @JvmOverloads constructor(
*/
fun setOptions(options: Options) = setAdapter(CodeWithNotesAdapter(context, options))
- /**
- * Initialize with adapter.
- *
- * @param adapter Adapter
- */
- fun setAdapter(adapter: AbstractCodeAdapter<*>) {
- vCodeList.adapter = adapter
- highlight()
- }
-
- // - Options
-
- /**
- * View options accessor.
- */
- fun getOptions() = getAdapter()?.options
- fun getOptionsOrDefault() = getOptions() ?: Options(context)
-
/**
* Update options or initialize if needed.
*
* @param options Options
*/
fun updateOptions(options: Options) {
- getAdapter() ?: setOptions(options)
- getAdapter()?.options = options
+ adapter
+ ?.let { it.options = options }
+ ?: setOptions(options)
+
setupShadows(options.shadows)
}
- fun updateOptions(body: Options.() -> Unit) {
- val options = getOptions() ?: getOptionsOrDefault()
- updateOptions(options.apply(body))
- }
+ /**
+ * Update options or initialize if needed.
+ *
+ * @param body Options mutator
+ */
+ fun updateOptions(body: Options.() -> Unit) =
+ optionsOrDefault
+ .apply(body)
+ .apply(::updateOptions)
// - Adapter
/**
- * Code adapter accessor.
+ * Initialize with adapter.
+ *
+ * Highlight code with defined programming language.
+ * It holds the placeholder on view until code is not highlighted.
+ *
+ * @param adapter Adapter
*/
- fun getAdapter() = vCodeList.adapter as? AbstractCodeAdapter<*>
+ fun setAdapter(adapter: AbstractCodeAdapter<*>) {
+ rvContent.adapter = adapter.apply {
+ highlight { checkHighlightAnimation(::notifyDataSetChanged) }
+ }
+ }
/**
* Update adapter or initialize if needed.
*
* @param adapter Adapter
+ * @param isUseCurrent Use options that are already set or default
*/
- fun updateAdapter(adapter: AbstractCodeAdapter<*>) {
- adapter.options = getOptionsOrDefault()
- setAdapter(adapter)
+ fun updateAdapter(adapter: AbstractCodeAdapter<*>, isUseCurrent: Boolean) {
+ setAdapter(adapter.apply {
+ if (isUseCurrent) {
+ options = optionsOrDefault
+ }
+ })
}
// - Set code
/**
- * Set code content.
- *
- * There are two ways before code will be highlighted:
- * 1) view is not initialized (adapter or options are not set),
+ * Set code content. View is:
+ * 1) not initialized (adapter or options is not set):
* prepare with default params & try to classify language
- * 2) view initialized with some params, language:
- * a) is set: used defined programming language
+ * 2) initialized (with some params), language is:
+ * a) set: use defined
* b) not set: try to classify
*
* @param code Code content
*/
- fun setCode(code: String) {
- getAdapter() ?: prepare()
- getAdapter()?.updateCode(code)
- }
+ fun setCode(code: String) = setCode(code, null)
/**
- * Set code content.
- *
- * There are two ways before code will be highlighted:
- * 1) view is not initialized, prepare with default params
- * 2) view initialized with some params, set new language
+ * Set code content. View is:
+ * 1) not initialized: prepare with default params
+ * 2) initialized (with some params): set new language
*
* @param code Code content
* @param language Programming language
*/
- fun setCode(code: String, language: String) {
- val options = getOptionsOrDefault()
- updateOptions(options.withLanguage(language))
- getAdapter()?.updateCode(code)
+ fun setCode(code: String, language: String? = null) {
+ val options = optionsOrDefault.apply {
+ this.language = language
+ }
+ (adapter ?: CodeWithNotesAdapter(context, options)
+ .apply(::setAdapter))
+ .updateCode(code)
}
companion object {
- private fun AttributeSet.isAnimateOnStart(context: Context): Boolean {
- context.theme.obtainStyledAttributes(this, R.styleable.CodeView, 0, 0).apply {
- val flag = getBoolean(R.styleable.CodeView_animateOnStart, false)
- recycle()
- return@isAnimateOnStart flag
- }
- return false
- }
+ private fun AttributeSet.isAnimateOnStart(context: Context) =
+ context.theme.obtainStyledAttributes(this, R.styleable.CodeView, 0, 0).run {
+ val isAnimate = getBoolean(R.styleable.CodeView_animateOnStart, false)
+ recycle()
+ isAnimate
+ }
private fun View.setSafeBackground(newBackground: Drawable) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
diff --git a/codeview/src/main/java/io/github/kbiakov/codeview/Utils.kt b/codeview/src/main/java/io/github/kbiakov/codeview/Utils.kt
index fa5823e..f64ed2f 100644
--- a/codeview/src/main/java/io/github/kbiakov/codeview/Utils.kt
+++ b/codeview/src/main/java/io/github/kbiakov/codeview/Utils.kt
@@ -101,6 +101,14 @@ object Thread {
Handler(Looper.getMainLooper()).post(body)
}
+ /**
+ * Perform async and UI operations sequentially.
+ *
+ * @param asyncBody Async operation body
+ * @param uiBody UI operation body
+ */
+ fun asyncUi(asyncBody: () -> T, uiBody: (T) -> Unit) = async { asyncBody().also { ui { uiBody(it)} } }
+
/**
* Delayed block call.
*
diff --git a/codeview/src/main/java/io/github/kbiakov/codeview/adapters/AbstractCodeAdapter.kt b/codeview/src/main/java/io/github/kbiakov/codeview/adapters/AbstractCodeAdapter.kt
index 68ac317..848d321 100644
--- a/codeview/src/main/java/io/github/kbiakov/codeview/adapters/AbstractCodeAdapter.kt
+++ b/codeview/src/main/java/io/github/kbiakov/codeview/adapters/AbstractCodeAdapter.kt
@@ -3,15 +3,15 @@ package io.github.kbiakov.codeview.adapters
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Typeface
-import android.support.v7.widget.RecyclerView
+import android.util.SparseArray
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
+import androidx.recyclerview.widget.RecyclerView
import io.github.kbiakov.codeview.*
-import io.github.kbiakov.codeview.Thread.async
-import io.github.kbiakov.codeview.Thread.ui
+import io.github.kbiakov.codeview.Thread.asyncUi
import io.github.kbiakov.codeview.adapters.AbstractCodeAdapter.ViewHolderType.Companion.BordersCount
import io.github.kbiakov.codeview.adapters.AbstractCodeAdapter.ViewHolderType.Companion.LineStartIdx
import io.github.kbiakov.codeview.classifier.CodeClassifier
@@ -34,7 +34,7 @@ abstract class AbstractCodeAdapter : RecyclerView.Adapter> = HashMap()
+ private var footerEntities = SparseArray>()
constructor(context: Context) {
this.context = context
@@ -106,12 +106,14 @@ abstract class AbstractCodeAdapter : RecyclerView.Adapter Unit) {
- async {
- val language = options.language ?: classifyContent()
- highlighting(language, onReady)
- }
- }
+ internal fun highlight(onReady: () -> Unit) = asyncUi({
+ val language = options.language ?: classifyContent()
+
+ // TODO: highlight by 10 lines
+ CodeHighlighter.highlight(language, options.code, options.theme)
+ }, {
+ updateContent(it, onReady)
+ })
/**
* Mapper from entity to footer view.
@@ -130,25 +132,12 @@ abstract class AbstractCodeAdapter : RecyclerView.Adapter Unit) {
- // TODO: highlight by 10 lines
- val code = CodeHighlighter.highlight(language, options.code, options.theme)
- updateContent(code, onReady)
+ }
}
/**
@@ -159,35 +148,31 @@ abstract class AbstractCodeAdapter : RecyclerView.Adapter(R.id.tv_line_num)) {
+ typeface = options.font
+ setTextColor(options.theme.numColor.color())
+ setBackgroundColor(options.theme.bgNum.color())
+ }
- val isLine = viewType == ViewHolderType.Line.viewType
+ findViewById(R.id.tv_line_content).typeface = options.font
- options.format.apply {
- val height = if (isLine) lineHeight else borderHeight
- lineView.layoutParams.height = dpToPx(context, height)
- }
- return if (isLine)
- LineViewHolder(lineView).apply { setIsRecyclable(false) }
- else
- BorderViewHolder(lineView)
- }
+ return if (viewType == ViewHolderType.Line.viewType) {
+ layoutParams.height = dpToPx(context, options.format.lineHeight)
+ LineViewHolder(this).apply { setIsRecyclable(false) }
+ } else {
+ layoutParams.height = dpToPx(context, options.format.borderHeight)
+ BorderViewHolder(this)
+ }
+ }
override fun onBindViewHolder(holder: ViewHolder, pos: Int) {
if (holder is LineViewHolder) {
@@ -208,45 +193,39 @@ abstract class AbstractCodeAdapter : RecyclerView.Adapter
- addView(createFooter(context, entity, idx == 0))
- }
+ it.forEachIndexed { idx, entity ->
+ addView(createFooter(context, entity, idx == 0))
}
}
}
@@ -289,13 +268,13 @@ abstract class AbstractCodeAdapter : RecyclerView.Adapter> _shortcutStylePatterns = new ArrayList>();
+ List> _fallthroughStylePatterns = new ArrayList>();
+
+ _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[\\t\\n\\r \\xA0]+"), null, "\t\n\r \\xA0"}));
+ _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^#.*"), null, "#"}));
+ _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^'(?:[^'\\\\]|\\\\(?:.|\\n|\\r))*'?"), null, "\\'"}));
+ _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_ATTRIB_NAME, Pattern.compile("^@\\w+"), null, "@"}));
+ _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^[!%&()*+,\\-;<=>?\\[\\\\\\]^{|}]+"), null, "!%&()*+,-;<=>?[\\\\]^{|}"}));
+ _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(?:0o[0-7](?:[0-7]|_[0-7])*|0x[\\da-fA-F](?:[\\da-fA-F]|_[\\da-fA-F])*|\\d(?:\\d|_\\d)*(?:\\.\\d(?:\\d|_\\d)*)?(?:[eE][+\\-]?\\d(?:\\d|_\\d)*)?)"),
+ null, "0123456789"}));
+
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_ATTRIB_NAME, Pattern.compile("^iex(?:\\(\\d+\\))?> ")}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^::"), null}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^:(?:\\w+[\\!\\?\\@]?|\"(?:[^\"\\\\]|\\\\.)*\"?)")}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_ATTRIB_NAME, Pattern.compile("^(?:__(?:CALLER|ENV|MODULE|DIR)__)")}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^(?:alias|case|catch|def(?:delegate|exception|impl|macrop?|module|overridable|p?|protocol|struct)|do|else|end|fn|for|if|in|import|quote|raise|require|rescue|super|throw|try|unless|unquote(?:_splicing)?|use|when|with|yield)\\b")}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(?:true|false|nil)\\b")}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(?:\\w+[\\!\\?\\@]?|\"(?:[^\"\\\\]|\\\\.)*\"):(?!:)")}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\"\"\"\\s*(\\r|\\n)+(?:\"\"?(?!\")|[^\\\\\"]|\\\\(?:.|\\n|\\r))*\"{0,3}")}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\"(?:[^\"\\\\]|\\\\(?:.|\\n|\\r))*\"?(?!\")")}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_TYPE, Pattern.compile("^[A-Z]\\w*")}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^_\\w*")}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[$a-z]\\w*[\\!\\?]?")}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_ATTRIB_VALUE, Pattern.compile("^~[A-Z](?:\\/(?:[^\\/\\r\\n\\\\]|\\\\.)+\\/|\\|(?:[^\\|\\r\\n\\\\]|\\\\.)+\\||\"(?:[^\"\\r\\n\\\\]|\\\\.)+\"|'(?:[^'\\r\\n\\\\]|\\\\.)+')[A-Z]*", Pattern.CASE_INSENSITIVE)}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_ATTRIB_VALUE, Pattern.compile("^~[A-Z](?:\\((?:[^\\)\\r\\n\\\\]|\\\\.)+\\)|\\[(?:[^\\]\\r\\n\\\\]|\\\\.)+\\]|\\{(?:[^\\}\\r\\n\\\\]|\\\\.)+\\}|\\<(?:[^\\>\\r\\n\\\\]|\\\\.)+\\>)[A-Z]*", Pattern.CASE_INSENSITIVE)}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^(?:\\.+|\\/|[:~])")}));
+
+
+ setShortcutStylePatterns(_shortcutStylePatterns);
+ setFallthroughStylePatterns(_fallthroughStylePatterns);
+ }
+
+ public static List getFileExtensions() {
+ return Arrays.asList(new String[]{"ex", "exs"});
+ }
+}
diff --git a/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangKotlin.java b/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangKotlin.java
new file mode 100644
index 0000000..935eab9
--- /dev/null
+++ b/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangKotlin.java
@@ -0,0 +1,38 @@
+package io.github.kbiakov.codeview.highlight.prettify.lang;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify;
+
+public class LangKotlin extends Lang {
+
+ public LangKotlin() {
+ List> _shortcutStylePatterns = new ArrayList>();
+ List> _fallthroughStylePatterns = new ArrayList>();
+
+ _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[\\t\\n\\r \\xA0]+"), null, "\\t\\n\\r \\xA0"}));
+ _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^[.!%&()*+,\\-;<=>?\\[\\\\\\]^{|}:]+"), null, ".!%&()*+,-;<=>?[\\\\]^{|}:"}));
+
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^\\b(package|public|protected|private|open|abstract|constructor|final|override|import|for|while|as|typealias|get|set|((data|enum|annotation|sealed) )?class|this|super|val|var|fun|is|in|throw|return|break|continue|(companion )?object|if|try|else|do|when|init|interface|typeof)\\b")}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(?:true|false|null)\\b")}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(0[xX][0-9a-fA-F_]+L?|0[bB][0-1]+L?|[0-9_.]+([eE]-?[0-9]+)?[fFL]?)")}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_TYPE, Pattern.compile("^(\\b[A-Z]+[a-z][a-zA-Z0-9_$@]*|`.*`)"), null}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^\\/\\/.*")}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^\\/\\*[\\s\\S]*?(?:\\*\\/|$)")}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("'.'")}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\"([^\"\\\\]|\\\\[\\s\\S])*\"")}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\"{3}[\\s\\S]*?[^\\\\]\"{3}")}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^@([a-zA-Z0-9_$@]*|`.*`)")}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^[a-zA-Z0-9_]+@")}));
+
+ setShortcutStylePatterns(_shortcutStylePatterns);
+ setFallthroughStylePatterns(_fallthroughStylePatterns);
+ }
+
+ public static List getFileExtensions() {
+ return Arrays.asList(new String[]{"kotlin"});
+ }
+}
diff --git a/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangLasso.java b/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangLasso.java
new file mode 100644
index 0000000..4db53e1
--- /dev/null
+++ b/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangLasso.java
@@ -0,0 +1,41 @@
+package io.github.kbiakov.codeview.highlight.prettify.lang;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify;
+
+public class LangLasso extends Lang {
+
+ public LangLasso() {
+ List> _shortcutStylePatterns = new ArrayList>();
+ List> _fallthroughStylePatterns = new ArrayList>();
+
+ _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[\\t\\n\\r \\xA0]+"), null, "\\t\\n\\r \\xA0"}));
+ _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\\'[^\\'\\\\]*(?:\\\\[\\s\\S][^\\'\\\\]*)*(?:\\'|$)"), null, "\'"}));
+ _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\\\"[^\\\"\\\\]*(?:\\\\[\\s\\S][^\\\"\\\\]*)*(?:\\\"|$)"), null, "\""}));
+ _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\\`[^\\`]*(?:\\`|$)"), null, "`"}));
+ _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^0x[\\da-f]+|\\d+", Pattern.CASE_INSENSITIVE), null, "0123456789"}));
+ _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_ATTRIB_NAME, Pattern.compile("^[#$][a-z_][\\w.]*|#\\d+\\b|#![ \\S]+lasso9\\b", Pattern.CASE_INSENSITIVE), null, "#$"}));
+
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_TAG, Pattern.compile("^[\\[\\]]|<\\?(?:lasso(?:script)?|=)|\\?>|(no_square_brackets|noprocess)\\b", Pattern.CASE_INSENSITIVE)}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^\\/\\/[^\\r\\n]*|\\/\\*[\\s\\S]*?\\*\\/")}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_ATTRIB_NAME, Pattern.compile("^-(?!infinity)[a-z_][\\w.]*|\\.\\s*'[a-z_][\\w.]*'|\\.{3}", Pattern.CASE_INSENSITIVE)}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^\\d*\\.\\d+(?:e[-+]?\\d+)?|(infinity|NaN)\\b", Pattern.CASE_INSENSITIVE)}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_ATTRIB_VALUE, Pattern.compile("^::\\s*[a-z_][\\w.]*", Pattern.CASE_INSENSITIVE)}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(?:true|false|none|minimal|full|all|void|and|or|not|bw|nbw|ew|new|cn|ncn|lt|lte|gt|gte|eq|neq|rx|nrx|ft)\\b", Pattern.CASE_INSENSITIVE)}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_TYPE, Pattern.compile("^(?:array|date|decimal|duration|integer|map|pair|string|tag|xml|null|boolean|bytes|keyword|list|locale|queue|set|stack|staticarray|local|var|variable|global|data|self|inherited|currentcapture|givenblock)\\b|^\\.\\.?", Pattern.CASE_INSENSITIVE)}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^(?:cache|database_names|database_schemanames|database_tablenames|define_tag|define_type|email_batch|encode_set|html_comment|handle|handle_error|header|if|inline|iterate|ljax_target|link|link_currentaction|link_currentgroup|link_currentrecord|link_detail|link_firstgroup|link_firstrecord|link_lastgroup|link_lastrecord|link_nextgroup|link_nextrecord|link_prevgroup|link_prevrecord|log|loop|namespace_using|output_none|portal|private|protect|records|referer|referrer|repeating|resultset|rows|search_args|search_arguments|select|sort_args|sort_arguments|thread_atomic|value_list|while|abort|case|else|fail_if|fail_ifnot|fail|if_empty|if_false|if_null|if_true|loop_abort|loop_continue|loop_count|params|params_up|return|return_value|run_children|soap_definetag|soap_lastrequest|soap_lastresponse|tag_name|ascending|average|by|define|descending|do|equals|frozen|group|handle_failure|import|in|into|join|let|match|max|min|on|order|parent|protected|provide|public|require|returnhome|skip|split_thread|sum|take|thread|to|trait|type|where|with|yield|yieldhome)\\b", Pattern.CASE_INSENSITIVE)}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[a-z_][\\w.]*(?:=\\s*(?=\\())?", Pattern.CASE_INSENSITIVE)}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^:=|[-+*\\/%=<>&|!?\\\\]+")}));
+
+ setShortcutStylePatterns(_shortcutStylePatterns);
+ setFallthroughStylePatterns(_fallthroughStylePatterns);
+ }
+
+ public static List getFileExtensions() {
+ return Arrays.asList(new String[]{"lasso", "ls", "lassoscript"});
+ }
+}
diff --git a/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangLogtalk.java b/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangLogtalk.java
new file mode 100644
index 0000000..5f08b24
--- /dev/null
+++ b/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangLogtalk.java
@@ -0,0 +1,35 @@
+package io.github.kbiakov.codeview.highlight.prettify.lang;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify;
+
+public class LangLogtalk extends Lang {
+
+ public LangLogtalk() {
+ List> _shortcutStylePatterns = new ArrayList>();
+ List> _fallthroughStylePatterns = new ArrayList>();
+
+ _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\\\"(?:[^\\\"\\\\\\n\\x0C\\r]|\\\\[\\s\\S])*(?:\\\"|$)"), null, "\""}));
+ _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^[a-z][a-zA-Z0-9_]*")}));
+ _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^\\'(?:[^\\'\\\\\\n\\x0C\\r]|\\\\[^&])+\\'?"), null, "\'"}));
+ _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(?:0'.|0b[0-1]+|0o[0-7]+|0x[\\da-f]+|\\d+(?:\\.\\d+)?(?:e[+\\-]?\\d+)?)", Pattern.CASE_INSENSITIVE), null, "0123456789"}));
+
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^%[^\\r\\n]*"), null, "%"}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^\\/\\*[\\s\\S]*?\\*\\/")}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^\\s*:-\\s(c(a(lls|tegory)|oinductive)|p(ublic|r(ot(ocol|ected)|ivate))|e(l(if|se)|n(coding|sure_loaded)|xport)|i(f|n(clude|itialization|fo))|alias|d(ynamic|iscontiguous)|m(eta_(non_terminal|predicate)|od(e|ule)|ultifile)|reexport|s(et_(logtalk|prolog)_flag|ynchronized)|o(bject|p)|use(s|_module))")}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^\\s*:-\\s(e(lse|nd(if|_(category|object|protocol)))|built_in|dynamic|synchronized|threaded)")}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_TYPE, Pattern.compile("^[A-Z_][a-zA-Z0-9_]*")}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^[.,;{}:^<>=\\\\/+*?#!-]")}));
+
+ setShortcutStylePatterns(_shortcutStylePatterns);
+ setFallthroughStylePatterns(_fallthroughStylePatterns);
+ }
+
+ public static List getFileExtensions() {
+ return Arrays.asList(new String[]{"logtalk", "lgt"});
+ }
+}
\ No newline at end of file
diff --git a/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangSwift.java b/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangSwift.java
new file mode 100644
index 0000000..a92339f
--- /dev/null
+++ b/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangSwift.java
@@ -0,0 +1,35 @@
+package io.github.kbiakov.codeview.highlight.prettify.lang;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify;
+
+public class LangSwift extends Lang {
+
+ public LangSwift() {
+ List> _shortcutStylePatterns = new ArrayList>();
+ List> _fallthroughStylePatterns = new ArrayList>();
+
+ _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[ \\n\\r\\t\\v\\f\\\0]+"), null, " \\n\\r\\t\\v\\f\\0"}));
+ _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\"(?:[^\"\\\\]|(?:\\\\.)|(?:\\\\\\((?:[^\"\\\\)]|\\\\.)*\\)))*\""), null, "\""}));
+
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(?:(?:0x[\\da-fA-F][\\da-fA-F_]*\\.[\\da-fA-F][\\da-fA-F_]*[pP]?)|(?:\\d[\\d_]*\\.\\d[\\d_]*[eE]?))[+-]?\\d[\\d_]*"), null}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^-?(?:(?:0(?:(?:b[01][01_]*)|(?:o[0-7][0-7_]*)|(?:x[\\da-fA-F][\\da-fA-F_]*)))|(?:\\d[\\d_]*))"), null}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(?:_|Any|true|false|nil)\\b"), null}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^\\b(?:__COLUMN__|__FILE__|__FUNCTION__|__LINE__|#available|#colorLiteral|#column|#else|#elseif|#endif|#file|#fileLiteral|#function|#if|#imageLiteral|#line|#selector|#sourceLocation|arch|arm|arm64|associatedtype|associativity|as|break|case|catch|class|continue|convenience|default|defer|deinit|didSet|do|dynamic|dynamicType|else|enum|extension|fallthrough|fileprivate|final|for|func|get|guard|import|indirect|infix|init|inout|internal|i386|if|in|iOS|iOSApplicationExtension|is|lazy|left|let|mutating|none|nonmutating|open|operator|optional|OSX|OSXApplicationExtension|override|postfix|precedence|prefix|private|protocol|Protocol|public|repeat|required|rethrows|return|right|safe|Self|self|set|static|struct|subscript|super|switch|throw|throws|try|Type|typealias|unowned|unsafe|var|weak|watchOS|where|while|willSet|x86_64)\\b"), null}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^\\/\\/.*?[\\n\\r]"), null}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^\\/\\*[\\s\\S]*?(?:\\*\\/|$)"), null}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^<<=|<=|<<|>>=|>=|>>|===|==|\\.\\.\\.|&&=|\\.\\.<|!==|!=|&=|~=|~|\\(|\\)|\\[|\\]|\\{|}|@|#|;|\\.|,|:|\\|\\|=|\\?\\?|\\|\\||&&|&\\*|&\\+|&-|&=|\\+=|-=|\\/=|\\*=|\\^=|%=|\\|=|->|`|==|\\+\\+|--|\\/|\\+|!|\\*|%|<|>|&|\\||\\^|\\?|=|-|_"), null}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_TYPE, Pattern.compile("^\\b(?:[@_]?[A-Z]+[a-z][A-Za-z_$@0-9]*|\\w+_t\\b)"), null}));
+
+ setShortcutStylePatterns(_shortcutStylePatterns);
+ setFallthroughStylePatterns(_fallthroughStylePatterns);
+ }
+
+ public static List getFileExtensions() {
+ return Arrays.asList(new String[]{"swift"});
+ }
+}
\ No newline at end of file
diff --git a/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/parser/Prettify.java b/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/parser/Prettify.java
index 970cdd8..e462202 100644
--- a/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/parser/Prettify.java
+++ b/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/parser/Prettify.java
@@ -31,8 +31,11 @@
import io.github.kbiakov.codeview.highlight.prettify.lang.LangErlang;
import io.github.kbiakov.codeview.highlight.prettify.lang.LangGo;
import io.github.kbiakov.codeview.highlight.prettify.lang.LangHs;
+import io.github.kbiakov.codeview.highlight.prettify.lang.LangKotlin;
+import io.github.kbiakov.codeview.highlight.prettify.lang.LangLasso;
import io.github.kbiakov.codeview.highlight.prettify.lang.LangLisp;
import io.github.kbiakov.codeview.highlight.prettify.lang.LangLlvm;
+import io.github.kbiakov.codeview.highlight.prettify.lang.LangLogtalk;
import io.github.kbiakov.codeview.highlight.prettify.lang.LangLua;
import io.github.kbiakov.codeview.highlight.prettify.lang.LangMatlab;
import io.github.kbiakov.codeview.highlight.prettify.lang.LangMd;
@@ -51,6 +54,8 @@
import io.github.kbiakov.codeview.highlight.prettify.lang.LangWiki;
import io.github.kbiakov.codeview.highlight.prettify.lang.LangXq;
import io.github.kbiakov.codeview.highlight.prettify.lang.LangYaml;
+import io.github.kbiakov.codeview.highlight.prettify.lang.LangEx;
+import io.github.kbiakov.codeview.highlight.prettify.lang.LangSwift;
/**
* This is similar to the prettify.js in JavaScript Prettify.
@@ -394,6 +399,11 @@ public Prettify() {
register(LangWiki.class);
register(LangXq.class);
register(LangYaml.class);
+ register(LangEx.class);
+ register(LangSwift.class);
+ register(LangKotlin.class);
+ register(LangLogtalk.class);
+ register(LangLasso.class);
} catch (Exception ex) {
LOG.log(Level.SEVERE, null, ex);
}
diff --git a/codeview/src/main/java/io/github/kbiakov/codeview/views/LineDiffView.kt b/codeview/src/main/java/io/github/kbiakov/codeview/views/LineDiffView.kt
index 996840d..ff1bcdd 100644
--- a/codeview/src/main/java/io/github/kbiakov/codeview/views/LineDiffView.kt
+++ b/codeview/src/main/java/io/github/kbiakov/codeview/views/LineDiffView.kt
@@ -1,10 +1,10 @@
package io.github.kbiakov.codeview.views
import android.content.Context
-import android.support.v4.content.ContextCompat
import android.view.LayoutInflater
import android.widget.RelativeLayout
import android.widget.TextView
+import androidx.core.content.ContextCompat
import io.github.kbiakov.codeview.R
import io.github.kbiakov.codeview.highlight.FontCache
diff --git a/codeview/src/main/res/layout/layout_code_view.xml b/codeview/src/main/res/layout/layout_code_view.xml
index ab0491f..44165b9 100644
--- a/codeview/src/main/res/layout/layout_code_view.xml
+++ b/codeview/src/main/res/layout/layout_code_view.xml
@@ -11,8 +11,8 @@
android:layout_height="wrap_content"
android:fillViewport="true">
-
diff --git a/example/build.gradle b/example/build.gradle
index 6ab7624..9b51fb5 100644
--- a/example/build.gradle
+++ b/example/build.gradle
@@ -27,8 +27,8 @@ dependencies {
implementation project(':codeview')
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
- implementation "com.android.support:appcompat-v7:$supportLibrary"
- implementation "com.android.support:recyclerview-v7:$supportLibrary"
+ implementation "androidx.appcompat:appcompat:$androidxLibrary"
+ implementation "androidx.recyclerview:recyclerview:$androidxLibrary"
}
repositories {
mavenCentral()
diff --git a/example/src/main/java/io/github/kbiakov/codeviewexample/ListingsActivity.java b/example/src/main/java/io/github/kbiakov/codeviewexample/ListingsActivity.java
index 84cb031..2adc5a7 100644
--- a/example/src/main/java/io/github/kbiakov/codeviewexample/ListingsActivity.java
+++ b/example/src/main/java/io/github/kbiakov/codeviewexample/ListingsActivity.java
@@ -1,22 +1,13 @@
package io.github.kbiakov.codeviewexample;
import android.os.Bundle;
-import android.support.annotation.Nullable;
-import android.support.v7.app.AppCompatActivity;
-import android.util.Log;
-
-import org.jetbrains.annotations.NotNull;
+import androidx.annotation.Nullable;
+import androidx.appcompat.app.AppCompatActivity;
import io.github.kbiakov.codeview.CodeView;
-import io.github.kbiakov.codeview.OnCodeLineClickListener;
-import io.github.kbiakov.codeview.adapters.CodeWithDiffsAdapter;
-import io.github.kbiakov.codeview.adapters.Format;
import io.github.kbiakov.codeview.adapters.Options;
import io.github.kbiakov.codeview.highlight.ColorTheme;
-import io.github.kbiakov.codeview.highlight.ColorThemeData;
import io.github.kbiakov.codeview.highlight.Font;
-import io.github.kbiakov.codeview.highlight.FontCache;
-import io.github.kbiakov.codeview.views.DiffModel;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;