├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── me │ │ └── next │ │ └── markwoncodeex │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── me │ │ │ └── next │ │ │ └── markwoncodeex │ │ │ └── MainActivity.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── ic_launcher_background.xml │ │ ├── rounded_text_bg.xml │ │ ├── rounded_text_bg_left.xml │ │ ├── rounded_text_bg_mid.xml │ │ └── rounded_text_bg_right.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── me │ └── next │ └── markwoncodeex │ └── ExampleUnitTest.kt ├── build.gradle ├── code_extension ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── me │ │ └── next │ │ └── codex │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── me │ │ │ └── next │ │ │ └── codex │ │ │ ├── CodeSingleMetricSpan.kt │ │ │ ├── CodeVisitor.kt │ │ │ └── roundedbg │ │ │ ├── Extentions.kt │ │ │ ├── LayoutExtensions.kt │ │ │ ├── RoundedBgTextView.kt │ │ │ ├── TextRoundedBgAttributeReader.kt │ │ │ ├── TextRoundedBgHelper.kt │ │ │ └── TextRoundedBgRenderer.kt │ └── res │ │ ├── drawable │ │ ├── rounded_text_bg.xml │ │ ├── rounded_text_bg_left.xml │ │ ├── rounded_text_bg_mid.xml │ │ └── rounded_text_bg_right.xml │ │ └── values │ │ ├── attrs.xml │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── me │ └── next │ └── codex │ └── ExampleUnitTest.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches/build_file_checksums.ser 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | .DS_Store 9 | /build 10 | /captures 11 | .externalNativeBuild 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![](https://jitpack.io/v/kingideayou/MarkwonCodeEx.svg)](https://jitpack.io/#kingideayou/MarkwonCodeEx) 2 | 3 | # MarkwonCodeEx 4 | Markwon extensition support elegant code background. 5 | 为 [Markwon](https://github.com/noties/Markwon) 提供优雅的代码块显示效果 6 | 7 | ### Preview 8 | ![](http://ww1.sinaimg.cn/mw690/6db4aff6gy1fy3ye4p2f3j20to0upjwd.jpg) 9 | 10 | ## ProGuard 11 | ```groovy 12 | allprojects { 13 | repositories { 14 | ... 15 | maven { url 'https://jitpack.io' } 16 | } 17 | } 18 | ``` 19 | 20 | ```groovy 21 | implementation 'ru.noties:markwon:2.0.1' 22 | implementation 'com.github.kingideayou:MarkwonCodeEx:1.0.0' 23 | ``` 24 | 25 | ## Simple usage snippet 26 | ```kotlin 27 | val builder = SpannableBuilder() 28 | val visitor = CodeVisitor( 29 | spannableBuilder, 30 | builder, 31 | spannableTheme, 32 | resources.getColor(R.color.codeTextColor) //Note: code text color 33 | ) 34 | 35 | Markwon.createParser().parse("a simple `code`").accept(visitor) 36 | tvContent.text = builder.text() 37 | ``` 38 | ### layout 39 | ```xml 40 | 41 | 46 | ``` 47 | ### style 48 | ```xml 49 | 58 | ``` 59 | 60 | ## Thanks 61 | This library is inspired by [noties/Markwon](https://github.com/noties/Markwon) & [googlesamples/android-text](https://github.com/googlesamples/android-text/tree/master/RoundedBackground-Kotlin) and uses some of its source code. 62 | 63 | ## License 64 | 65 | Copyright 2018 NeXT. 66 | 67 | Licensed under the Apache License, Version 2.0 (the "License"); 68 | you may not use this file except in compliance with the License. 69 | You may obtain a copy of the License at 70 | 71 | http://www.apache.org/licenses/LICENSE-2.0 72 | 73 | Unless required by applicable law or agreed to in writing, software 74 | distributed under the License is distributed on an "AS IS" BASIS, 75 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 76 | See the License for the specific language governing permissions and 77 | limitations under the License. 78 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | apply plugin: 'kotlin-android' 4 | 5 | apply plugin: 'kotlin-android-extensions' 6 | 7 | android { 8 | compileSdkVersion 28 9 | defaultConfig { 10 | applicationId "me.next.markwoncodeex" 11 | minSdkVersion 19 12 | targetSdkVersion 28 13 | versionCode 1 14 | versionName "1.0" 15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 16 | } 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | } 24 | 25 | dependencies { 26 | implementation fileTree(dir: 'libs', include: ['*.jar']) 27 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 28 | implementation 'com.android.support:appcompat-v7:28.0.0' 29 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 30 | testImplementation 'junit:junit:4.12' 31 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 32 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 33 | 34 | implementation 'ru.noties:markwon:2.0.1' 35 | compile project(path: ':code_extension') 36 | } 37 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/me/next/markwoncodeex/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package me.next.markwoncodeex 2 | 3 | import android.support.test.InstrumentationRegistry 4 | import android.support.test.runner.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getTargetContext() 22 | assertEquals("me.next.markwoncodeex", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/me/next/markwoncodeex/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package me.next.markwoncodeex 2 | 3 | import android.os.Bundle 4 | import android.support.v7.app.AppCompatActivity 5 | import android.widget.TextView 6 | import me.next.codex.CodeVisitor 7 | import ru.noties.markwon.Markwon 8 | import ru.noties.markwon.SpannableBuilder 9 | import ru.noties.markwon.SpannableConfiguration 10 | import ru.noties.markwon.spans.SpannableTheme 11 | 12 | class MainActivity : AppCompatActivity() { 13 | 14 | override fun onCreate(savedInstanceState: Bundle?) { 15 | super.onCreate(savedInstanceState) 16 | setContentView(R.layout.activity_main) 17 | 18 | val tvContent = findViewById(R.id.tv_content) 19 | 20 | val builder = SpannableBuilder() 21 | val spannableTheme = SpannableTheme.builderWithDefaults(this) 22 | .codeBlockTextColor(resources.getColor(R.color.codeTextColor)) 23 | .codeBlockBackgroundColor(resources.getColor(R.color.codeBackgroundColor)).build() 24 | val spannableBuilder = SpannableConfiguration.builder(this).theme(spannableTheme).build() 25 | val visitor = CodeVisitor( 26 | spannableBuilder, 27 | builder, 28 | spannableTheme, 29 | resources.getColor(R.color.codeTextColor) // code text color 30 | ) 31 | Markwon.createParser().parse( 32 | // "# Markwon\n" + 33 | // "## Markwon\n" + 34 | // "### Markwon\n" + 35 | // "#### Markwon\n" + 36 | // "##### Markwon\n" + 37 | "`test`aaa`test`bbb`test`ccc`testtesttesttesttesttest`\n" + 38 | "`asasasasasasasasasasasasasasasasasasasasasasasasasasasasa`\n" + 39 | "```\n" + 40 | "asas\n" + 41 | "asasasasasas\n" + 42 | "asasasasasasasas\n" + 43 | "asasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasas\n" + 44 | "```" 45 | ).accept(visitor) 46 | 47 | tvContent.text = builder.text() 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 11 | 16 | 21 | 26 | 31 | 36 | 41 | 46 | 51 | 56 | 61 | 66 | 71 | 76 | 81 | 86 | 91 | 96 | 101 | 106 | 111 | 116 | 121 | 126 | 131 | 136 | 141 | 146 | 151 | 156 | 161 | 166 | 171 | 172 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/rounded_text_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/rounded_text_bg_left.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/rounded_text_bg_mid.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/rounded_text_bg_right.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kingideayou/MarkwonCodeEx/89978003f8a101a49a230ec4bddc33540bd8debc/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kingideayou/MarkwonCodeEx/89978003f8a101a49a230ec4bddc33540bd8debc/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kingideayou/MarkwonCodeEx/89978003f8a101a49a230ec4bddc33540bd8debc/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kingideayou/MarkwonCodeEx/89978003f8a101a49a230ec4bddc33540bd8debc/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kingideayou/MarkwonCodeEx/89978003f8a101a49a230ec4bddc33540bd8debc/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kingideayou/MarkwonCodeEx/89978003f8a101a49a230ec4bddc33540bd8debc/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kingideayou/MarkwonCodeEx/89978003f8a101a49a230ec4bddc33540bd8debc/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kingideayou/MarkwonCodeEx/89978003f8a101a49a230ec4bddc33540bd8debc/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kingideayou/MarkwonCodeEx/89978003f8a101a49a230ec4bddc33540bd8debc/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kingideayou/MarkwonCodeEx/89978003f8a101a49a230ec4bddc33540bd8debc/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | 8 | 9 | #EE6A6C 10 | #dedede 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | MarkwonCodeEx 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/test/java/me/next/markwoncodeex/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package me.next.markwoncodeex 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext.kotlin_version = '1.2.61' 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.2.0' 11 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 12 | 13 | // NOTE: Do not place your application dependencies here; they belong 14 | // in the individual module build.gradle files 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | google() 21 | jcenter() 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } 28 | 29 | ext { 30 | // Config 31 | BUILD_TOOLS = '26.0.3' 32 | TARGET_SDK = 26 33 | MIN_SDK = 19 34 | // Dependencies 35 | final def supportVersion = '26.1.0' 36 | SUPPORT_ANNOTATIONS = "com.android.support:support-annotations:$supportVersion" 37 | SUPPORT_APP_COMPAT = "com.android.support:appcompat-v7:$supportVersion" 38 | } -------------------------------------------------------------------------------- /code_extension/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /code_extension/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'kotlin-android' 3 | 4 | android { 5 | compileSdkVersion TARGET_SDK 6 | 7 | defaultConfig { 8 | minSdkVersion MIN_SDK 9 | targetSdkVersion TARGET_SDK 10 | versionCode 1 11 | versionName "1.0" 12 | 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | 15 | } 16 | 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | 24 | } 25 | 26 | dependencies { 27 | implementation fileTree(dir: 'libs', include: ['*.jar']) 28 | 29 | implementation SUPPORT_APP_COMPAT 30 | testImplementation 'junit:junit:4.12' 31 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 32 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 33 | compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 34 | compileOnly "ru.noties:markwon:2.0.1" 35 | } 36 | repositories { 37 | mavenCentral() 38 | } 39 | -------------------------------------------------------------------------------- /code_extension/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /code_extension/src/androidTest/java/me/next/codex/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package me.next.codex; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("me.next.code_extension.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /code_extension/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /code_extension/src/main/java/me/next/codex/CodeSingleMetricSpan.kt: -------------------------------------------------------------------------------- 1 | package me.next.codex 2 | 3 | import android.text.TextPaint 4 | import android.text.style.MetricAffectingSpan 5 | 6 | import ru.noties.markwon.spans.SpannableTheme 7 | 8 | /** 9 | *
10 |  * author : NeXT
11 |  * time   : 2018/12/11
12 |  * desc   :
13 |  * 
* 14 | */ 15 | class CodeSingleMetricSpan(private val theme: SpannableTheme) : MetricAffectingSpan() { 16 | 17 | override fun updateDrawState(textPaint: TextPaint) { 18 | apply(textPaint) 19 | } 20 | 21 | override fun updateMeasureState(textPaint: TextPaint) { 22 | apply(textPaint) 23 | } 24 | 25 | private fun apply(p: TextPaint) { 26 | theme.applyCodeTextStyle(p, false) 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /code_extension/src/main/java/me/next/codex/CodeVisitor.kt: -------------------------------------------------------------------------------- 1 | package me.next.codex 2 | 3 | import android.text.Spannable 4 | import android.text.style.ForegroundColorSpan 5 | 6 | import org.commonmark.node.Code 7 | 8 | import ru.noties.markwon.SpannableBuilder 9 | import ru.noties.markwon.SpannableConfiguration 10 | import ru.noties.markwon.renderer.SpannableMarkdownVisitor 11 | import ru.noties.markwon.spans.SpannableTheme 12 | 13 | /** 14 | *
15 |  * author : NeXT
16 |  * time   : 2018/12/11
17 |  * desc   :
18 |  * 
* 19 | */ 20 | class CodeVisitor( 21 | configuration: SpannableConfiguration, 22 | private val builder: SpannableBuilder, 23 | private val theme: SpannableTheme, 24 | private val codeTextColor: Int 25 | ) : SpannableMarkdownVisitor(configuration, builder) { 26 | 27 | override fun visit(code: Code) { 28 | val length = builder.length 29 | 30 | // NB, in order to provide a _padding_ feeling code is wrapped inside two unbreakable spaces 31 | // unfortunately we cannot use this for multiline code as we cannot control where a new line break will be inserted 32 | builder.append('\u00a0') 33 | builder.append(code.literal) 34 | val lengthEnd = builder.length 35 | builder.run { 36 | setSpan( 37 | CodeSingleMetricSpan(theme), length + 1, lengthEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE 38 | ) 39 | setSpan( 40 | ForegroundColorSpan(codeTextColor), 41 | length + 1, 42 | lengthEnd, 43 | Spannable.SPAN_EXCLUSIVE_EXCLUSIVE 44 | ) 45 | append('\u00a0') 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /code_extension/src/main/java/me/next/codex/roundedbg/Extentions.kt: -------------------------------------------------------------------------------- 1 | package me.next.codex.roundedbg 2 | 3 | import android.graphics.Canvas 4 | 5 | /** 6 | *
 7 |  *     author : NeXT
 8 |  *     time   : 2018/12/11
 9 |  *     desc   :
10 |  *     copy from: androidx.core.graphics.Canvas.kt
11 |  * 
12 | */ 13 | 14 | inline fun Canvas.withTranslation( 15 | x: Float = 0.0f, 16 | y: Float = 0.0f, 17 | block: Canvas.() -> Unit 18 | ) { 19 | val checkpoint = save() 20 | translate(x, y) 21 | try { 22 | block() 23 | } finally { 24 | restoreToCount(checkpoint) 25 | } 26 | } -------------------------------------------------------------------------------- /code_extension/src/main/java/me/next/codex/roundedbg/LayoutExtensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.next.codex.roundedbg 17 | 18 | import android.os.Build 19 | import android.text.Layout 20 | 21 | // Extension functions for Layout object 22 | 23 | /** 24 | * Android system default line spacing extra 25 | */ 26 | private const val DEFAULT_LINESPACING_EXTRA = 0f 27 | 28 | /** 29 | * Android system default line spacing multiplier 30 | */ 31 | private const val DEFAULT_LINESPACING_MULTIPLIER = 1f 32 | 33 | /** 34 | * Get the line bottom discarding the line spacing added. 35 | */ 36 | fun Layout.getLineBottomWithoutSpacing(line: Int): Int { 37 | val lineBottom = getLineBottom(line) 38 | val lastLineSpacingNotAdded = Build.VERSION.SDK_INT >= 19 39 | val isLastLine = line == lineCount - 1 40 | 41 | val lineBottomWithoutSpacing: Int 42 | val lineSpacingExtra = spacingAdd 43 | val lineSpacingMultiplier = spacingMultiplier 44 | val hasLineSpacing = lineSpacingExtra != DEFAULT_LINESPACING_EXTRA 45 | || lineSpacingMultiplier != DEFAULT_LINESPACING_MULTIPLIER 46 | 47 | if (!hasLineSpacing || isLastLine && lastLineSpacingNotAdded) { 48 | lineBottomWithoutSpacing = lineBottom 49 | } else { 50 | val extra: Float 51 | if (lineSpacingMultiplier.compareTo(DEFAULT_LINESPACING_MULTIPLIER) != 0) { 52 | val lineHeight = getLineHeight(line) 53 | extra = lineHeight - (lineHeight - lineSpacingExtra) / lineSpacingMultiplier 54 | } else { 55 | extra = lineSpacingExtra 56 | } 57 | 58 | lineBottomWithoutSpacing = (lineBottom - extra).toInt() 59 | } 60 | 61 | return lineBottomWithoutSpacing 62 | } 63 | 64 | /** 65 | * Get the line height of a line. 66 | */ 67 | fun Layout.getLineHeight(line: Int): Int { 68 | return getLineTop(line + 1) - getLineTop(line) 69 | } 70 | 71 | /** 72 | * Returns the top of the Layout after removing the extra padding applied by the Layout. 73 | */ 74 | fun Layout.getLineTopWithoutPadding(line: Int): Int { 75 | var lineTop = getLineTop(line) 76 | if (line == 0) { 77 | lineTop -= topPadding 78 | } 79 | return lineTop 80 | } 81 | 82 | /** 83 | * Returns the bottom of the Layout after removing the extra padding applied by the Layout. 84 | */ 85 | fun Layout.getLineBottomWithoutPadding(line: Int): Int { 86 | var lineBottom = getLineBottomWithoutSpacing(line) 87 | if (line == lineCount - 1) { 88 | lineBottom -= bottomPadding 89 | } 90 | return lineBottom 91 | } -------------------------------------------------------------------------------- /code_extension/src/main/java/me/next/codex/roundedbg/RoundedBgTextView.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.next.codex.roundedbg 17 | 18 | import android.content.Context 19 | import android.graphics.Canvas 20 | import android.text.Spanned 21 | import android.util.AttributeSet 22 | import android.widget.TextView 23 | 24 | /** 25 | * A TextView that can draw rounded background to the portions of the text. See 26 | * [TextRoundedBgHelper] for more information. 27 | * 28 | * See [TextRoundedBgAttributeReader] for supported attributes. 29 | */ 30 | class RoundedBgTextView @JvmOverloads constructor( 31 | context: Context, 32 | attrs: AttributeSet? = null, 33 | defStyleAttr: Int = android.R.attr.textViewStyle 34 | ) : TextView(context, attrs, defStyleAttr) { 35 | 36 | private val textRoundedBgHelper: TextRoundedBgHelper 37 | 38 | init { 39 | val attributeReader = TextRoundedBgAttributeReader(context, attrs) 40 | textRoundedBgHelper = TextRoundedBgHelper( 41 | horizontalPadding = attributeReader.horizontalPadding, 42 | verticalPadding = attributeReader.verticalPadding, 43 | drawable = attributeReader.drawable, 44 | drawableLeft = attributeReader.drawableLeft, 45 | drawableMid = attributeReader.drawableMid, 46 | drawableRight = attributeReader.drawableRight 47 | ) 48 | } 49 | 50 | override fun onDraw(canvas: Canvas) { 51 | // need to draw bg first so that text can be on top during super.onDraw() 52 | if (text is Spanned && layout != null) { 53 | canvas.withTranslation(totalPaddingLeft.toFloat(), totalPaddingTop.toFloat()) { 54 | textRoundedBgHelper.draw(canvas, text as Spanned, layout) 55 | } 56 | } 57 | super.onDraw(canvas) 58 | } 59 | } -------------------------------------------------------------------------------- /code_extension/src/main/java/me/next/codex/roundedbg/TextRoundedBgAttributeReader.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.next.codex.roundedbg 17 | 18 | import android.content.Context 19 | import android.graphics.drawable.Drawable 20 | import android.util.AttributeSet 21 | import me.next.codex.R 22 | 23 | /** 24 | * Reads default attributes that [TextRoundedBgHelper] needs from resources. The attributes read 25 | * are: 26 | * 27 | * - chHorizontalPadding: the padding to be applied to left & right of the background 28 | * - chVerticalPadding: the padding to be applied to top & bottom of the background 29 | * - chDrawable: the drawable used to draw the background 30 | * - chDrawableLeft: the drawable used to draw left edge of the background 31 | * - chDrawableMid: the drawable used to draw for whole line 32 | * - chDrawableRight: the drawable used to draw right edge of the background 33 | */ 34 | class TextRoundedBgAttributeReader(context: Context, attrs: AttributeSet?) { 35 | 36 | val horizontalPadding: Int 37 | val verticalPadding: Int 38 | val drawable: Drawable 39 | val drawableLeft: Drawable 40 | val drawableMid: Drawable 41 | val drawableRight: Drawable 42 | 43 | init { 44 | val typedArray = context.obtainStyledAttributes( 45 | attrs, 46 | R.styleable.TextRoundedBgHelper, 47 | 0, 48 | R.style.RoundedBgTextView 49 | ) 50 | horizontalPadding = typedArray.getDimensionPixelSize( 51 | R.styleable.TextRoundedBgHelper_roundedTextHorizontalPadding, 52 | 0 53 | ) 54 | verticalPadding = typedArray.getDimensionPixelSize( 55 | R.styleable.TextRoundedBgHelper_roundedTextVerticalPadding, 56 | 0 57 | ) 58 | drawable = typedArray.getDrawable( 59 | R.styleable.TextRoundedBgHelper_roundedTextDrawable 60 | ) 61 | drawableLeft = typedArray.getDrawable( 62 | R.styleable.TextRoundedBgHelper_roundedTextDrawableLeft 63 | ) 64 | drawableMid = typedArray.getDrawable( 65 | R.styleable.TextRoundedBgHelper_roundedTextDrawableMid 66 | ) 67 | drawableRight = typedArray.getDrawable( 68 | R.styleable.TextRoundedBgHelper_roundedTextDrawableRight 69 | ) 70 | typedArray.recycle() 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /code_extension/src/main/java/me/next/codex/roundedbg/TextRoundedBgHelper.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.next.codex.roundedbg 17 | 18 | import android.graphics.Canvas 19 | import android.graphics.drawable.Drawable 20 | import android.text.Layout 21 | import android.text.Spanned 22 | import me.next.codex.CodeSingleMetricSpan 23 | 24 | /** 25 | * Helper class to draw multi-line rounded background to certain parts of a text. The start/end 26 | * positions of the backgrounds are annotated with [android.text.Annotation] class. Each annotation 27 | * should have the annotation key set to **rounded**. 28 | * 29 | * i.e.: 30 | * ``` 31 | * 33 | * "this is a regular paragraph." 34 | * ``` 35 | * 36 | * **Note:** BiDi text is not supported. 37 | * 38 | * @param horizontalPadding the padding to be applied to left & right of the background 39 | * @param verticalPadding the padding to be applied to top & bottom of the background 40 | * @param drawable the drawable used to draw the background 41 | * @param drawableLeft the drawable used to draw left edge of the background 42 | * @param drawableMid the drawable used to draw for whole line 43 | * @param drawableRight the drawable used to draw right edge of the background 44 | */ 45 | class TextRoundedBgHelper( 46 | val horizontalPadding: Int, 47 | verticalPadding: Int, 48 | drawable: Drawable, 49 | drawableLeft: Drawable, 50 | drawableMid: Drawable, 51 | drawableRight: Drawable 52 | ) { 53 | 54 | private val singleLineRenderer: TextRoundedBgRenderer by lazy { 55 | SingleLineRenderer( 56 | horizontalPadding = horizontalPadding, 57 | verticalPadding = verticalPadding, 58 | drawable = drawable 59 | ) 60 | } 61 | 62 | private val multiLineRenderer: TextRoundedBgRenderer by lazy { 63 | MultiLineRenderer( 64 | horizontalPadding = horizontalPadding, 65 | verticalPadding = verticalPadding, 66 | drawableLeft = drawableLeft, 67 | drawableMid = drawableMid, 68 | drawableRight = drawableRight 69 | ) 70 | } 71 | 72 | /** 73 | * Call this function during onDraw of another widget such as TextView. 74 | * 75 | * @param canvas Canvas to draw onto 76 | * @param text 77 | * @param layout Layout that contains the text 78 | */ 79 | fun draw(canvas: Canvas, text: Spanned, layout: Layout) { 80 | // ideally the calculations here should be cached since they are not cheap. However, proper 81 | // invalidation of the cache is required whenever anything related to text has changed. 82 | // val spans = text.getSpans(0, text.length, Annotation::class.java) 83 | val spans = text.getSpans(0, text.length, CodeSingleMetricSpan::class.java) 84 | spans.forEach { span -> 85 | // if (span.value.equals("rounded")) { 86 | val spanStart = text.getSpanStart(span) 87 | val spanEnd = text.getSpanEnd(span) 88 | val startLine = layout.getLineForOffset(spanStart) 89 | val endLine = layout.getLineForOffset(spanEnd) 90 | 91 | // start can be on the left or on the right depending on the language direction. 92 | val startOffset = (layout.getPrimaryHorizontal(spanStart) 93 | + -1 * layout.getParagraphDirection(startLine) * horizontalPadding).toInt() 94 | // end can be on the left or on the right depending on the language direction. 95 | val endOffset = (layout.getPrimaryHorizontal(spanEnd) 96 | + layout.getParagraphDirection(endLine) * horizontalPadding).toInt() 97 | 98 | val renderer = if (startLine == endLine) singleLineRenderer else multiLineRenderer 99 | renderer.draw(canvas, layout, startLine, endLine, startOffset, endOffset) 100 | // } 101 | } 102 | } 103 | } -------------------------------------------------------------------------------- /code_extension/src/main/java/me/next/codex/roundedbg/TextRoundedBgRenderer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.next.codex.roundedbg 17 | 18 | import android.graphics.Canvas 19 | import android.graphics.drawable.Drawable 20 | import android.text.Layout 21 | import kotlin.math.max 22 | import kotlin.math.min 23 | 24 | /** 25 | * Base class for single and multi line rounded background renderers. 26 | * 27 | * @param horizontalPadding the padding to be applied to left & right of the background 28 | * @param verticalPadding the padding to be applied to top & bottom of the background 29 | */ 30 | internal abstract class TextRoundedBgRenderer( 31 | val horizontalPadding: Int, 32 | val verticalPadding: Int 33 | ) { 34 | 35 | /** 36 | * Draw the background that starts at the {@code startOffset} and ends at {@code endOffset}. 37 | * 38 | * @param canvas Canvas to draw onto 39 | * @param layout Layout that contains the text 40 | * @param startLine the start line for the background 41 | * @param endLine the end line for the background 42 | * @param startOffset the character offset that the background should start at 43 | * @param endOffset the character offset that the background should end at 44 | */ 45 | abstract fun draw( 46 | canvas: Canvas, 47 | layout: Layout, 48 | startLine: Int, 49 | endLine: Int, 50 | startOffset: Int, 51 | endOffset: Int 52 | ) 53 | 54 | /** 55 | * Get the top offset of the line and add padding into account so that there is a gap between 56 | * top of the background and top of the text. 57 | * 58 | * @param layout Layout object that contains the text 59 | * @param line line number 60 | */ 61 | protected fun getLineTop(layout: Layout, line: Int): Int { 62 | return layout.getLineTopWithoutPadding(line) - verticalPadding 63 | } 64 | 65 | /** 66 | * Get the bottom offset of the line and add padding into account so that there is a gap between 67 | * bottom of the background and bottom of the text. 68 | * 69 | * @param layout Layout object that contains the text 70 | * @param line line number 71 | */ 72 | protected fun getLineBottom(layout: Layout, line: Int): Int { 73 | return layout.getLineBottomWithoutPadding(line) + verticalPadding 74 | } 75 | } 76 | 77 | /** 78 | * Draws the background for text that starts and ends on the same line. 79 | * 80 | * @param horizontalPadding the padding to be applied to left & right of the background 81 | * @param verticalPadding the padding to be applied to top & bottom of the background 82 | * @param drawable the drawable used to draw the background 83 | */ 84 | internal class SingleLineRenderer( 85 | horizontalPadding: Int, 86 | verticalPadding: Int, 87 | val drawable: Drawable 88 | ) : TextRoundedBgRenderer(horizontalPadding, verticalPadding) { 89 | 90 | override fun draw( 91 | canvas: Canvas, 92 | layout: Layout, 93 | startLine: Int, 94 | endLine: Int, 95 | startOffset: Int, 96 | endOffset: Int 97 | ) { 98 | val lineTop = getLineTop(layout, startLine) 99 | val lineBottom = getLineBottom(layout, startLine) 100 | // get min of start/end for left, and max of start/end for right since we don't 101 | // the language direction 102 | val left = min(startOffset, endOffset) 103 | val right = max(startOffset, endOffset) 104 | drawable.setBounds(left, lineTop, right, lineBottom) 105 | drawable.draw(canvas) 106 | } 107 | } 108 | 109 | /** 110 | * Draws the background for text that starts and ends on different lines. 111 | * 112 | * @param horizontalPadding the padding to be applied to left & right of the background 113 | * @param verticalPadding the padding to be applied to top & bottom of the background 114 | * @param drawableLeft the drawable used to draw left edge of the background 115 | * @param drawableMid the drawable used to draw for whole line 116 | * @param drawableRight the drawable used to draw right edge of the background 117 | */ 118 | internal class MultiLineRenderer( 119 | horizontalPadding: Int, 120 | verticalPadding: Int, 121 | val drawableLeft: Drawable, 122 | val drawableMid: Drawable, 123 | val drawableRight: Drawable 124 | ) : TextRoundedBgRenderer(horizontalPadding, verticalPadding) { 125 | 126 | override fun draw( 127 | canvas: Canvas, 128 | layout: Layout, 129 | startLine: Int, 130 | endLine: Int, 131 | startOffset: Int, 132 | endOffset: Int 133 | ) { 134 | // draw the first line 135 | val paragDir = layout.getParagraphDirection(startLine) 136 | val lineEndOffset = if (paragDir == Layout.DIR_RIGHT_TO_LEFT) { 137 | layout.getLineLeft(startLine) - horizontalPadding 138 | } else { 139 | layout.getLineRight(startLine) + horizontalPadding 140 | }.toInt() 141 | 142 | var lineBottom = getLineBottom(layout, startLine) 143 | var lineTop = getLineTop(layout, startLine) 144 | drawStart(canvas, startOffset, lineTop, lineEndOffset, lineBottom) 145 | 146 | // for the lines in the middle draw the mid drawable 147 | for (line in startLine + 1 until endLine) { 148 | lineTop = getLineTop(layout, line) 149 | lineBottom = getLineBottom(layout, line) 150 | drawableMid.setBounds( 151 | (layout.getLineLeft(line).toInt() - horizontalPadding), 152 | lineTop, 153 | (layout.getLineRight(line).toInt() + horizontalPadding), 154 | lineBottom 155 | ) 156 | drawableMid.draw(canvas) 157 | } 158 | 159 | val lineStartOffset = if (paragDir == Layout.DIR_RIGHT_TO_LEFT) { 160 | layout.getLineRight(startLine) + horizontalPadding 161 | } else { 162 | layout.getLineLeft(startLine) - horizontalPadding 163 | }.toInt() 164 | 165 | // draw the last line 166 | lineBottom = getLineBottom(layout, endLine) 167 | lineTop = getLineTop(layout, endLine) 168 | 169 | drawEnd(canvas, lineStartOffset, lineTop, endOffset, lineBottom) 170 | } 171 | 172 | /** 173 | * Draw the first line of a multiline annotation. Handles LTR/RTL. 174 | * 175 | * @param canvas Canvas to draw onto 176 | * @param start start coordinate for the background 177 | * @param top top coordinate for the background 178 | * @param end end coordinate for the background 179 | * @param bottom bottom coordinate for the background 180 | */ 181 | private fun drawStart(canvas: Canvas, start: Int, top: Int, end: Int, bottom: Int) { 182 | if (start > end) { 183 | drawableRight.setBounds(end, top, start, bottom) 184 | drawableRight.draw(canvas) 185 | } else { 186 | drawableLeft.setBounds(start, top, end, bottom) 187 | drawableLeft.draw(canvas) 188 | } 189 | } 190 | 191 | /** 192 | * Draw the last line of a multiline annotation. Handles LTR/RTL. 193 | * 194 | * @param canvas Canvas to draw onto 195 | * @param start start coordinate for the background 196 | * @param top top position for the background 197 | * @param end end coordinate for the background 198 | * @param bottom bottom coordinate for the background 199 | */ 200 | private fun drawEnd(canvas: Canvas, start: Int, top: Int, end: Int, bottom: Int) { 201 | if (start > end) { 202 | drawableLeft.setBounds(end, top, start, bottom) 203 | drawableLeft.draw(canvas) 204 | } else { 205 | drawableRight.setBounds(start, top, end, bottom) 206 | drawableRight.draw(canvas) 207 | } 208 | } 209 | } -------------------------------------------------------------------------------- /code_extension/src/main/res/drawable/rounded_text_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /code_extension/src/main/res/drawable/rounded_text_bg_left.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 22 | -------------------------------------------------------------------------------- /code_extension/src/main/res/drawable/rounded_text_bg_mid.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /code_extension/src/main/res/drawable/rounded_text_bg_right.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 22 | -------------------------------------------------------------------------------- /code_extension/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /code_extension/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #424242 4 | #212121 5 | #4caf50 6 | 7 | #CCC 8 | 9 | #FFF176 10 | #CABF45 11 | 12 | #333333 13 | #DD0277BD 14 | 15 | #EE6A6C 16 | #2b2b2b 17 | 18 | 19 | -------------------------------------------------------------------------------- /code_extension/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | 7 | 8dp 8 | 1dp 9 | 10 | 6dp 11 | 2dp 12 | 13 | 4dp 14 | 1dp 15 | 16 | 17 | -------------------------------------------------------------------------------- /code_extension/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | code_extension 3 | 4 | -------------------------------------------------------------------------------- /code_extension/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 14 | 15 | 19 | 20 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /code_extension/src/test/java/me/next/codex/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package me.next.codex; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | 15 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kingideayou/MarkwonCodeEx/89978003f8a101a49a230ec4bddc33540bd8debc/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':code_extension' 2 | --------------------------------------------------------------------------------