-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
813 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
demo/src/main/java/xyz/wingio/syntakts/demo/AndroidTestActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package xyz.wingio.syntakts.demo | ||
|
||
import android.os.Bundle | ||
import android.widget.TextView | ||
import androidx.activity.ComponentActivity | ||
import xyz.wingio.syntakts.android.render | ||
|
||
class AndroidTestActivity : ComponentActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_android_test) | ||
|
||
val testString = """ | ||
# Header | ||
**Bold** *Italic* __Underline__ ~~Strikethrough~~ <@1234> | ||
""".trimIndent() | ||
|
||
findViewById<TextView>(R.id.test_text).render( | ||
text = testString, | ||
syntakts = TestSyntakts, | ||
context = Context(this), | ||
enableClickable = true | ||
) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
demo/src/main/java/xyz/wingio/syntakts/demo/TestSyntakts.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package xyz.wingio.syntakts.demo | ||
|
||
import android.content.Context as AndroidContext | ||
import android.widget.Toast | ||
import xyz.wingio.syntakts.markdown.addMarkdownRules | ||
import xyz.wingio.syntakts.style.Color | ||
import xyz.wingio.syntakts.style.Style | ||
import xyz.wingio.syntakts.syntakts | ||
|
||
val TestSyntakts = syntakts<Context> { | ||
rule("<@([0-9]+)>") { result, ctx -> | ||
val username = ctx.userMap[result.groupValues[1]] ?: "Unknown" | ||
appendClickable( | ||
"@$username", | ||
Style( | ||
color = Color.MAGENTA, | ||
background = Color.MAGENTA withOpacity 0.2f | ||
), | ||
onLongClick = { | ||
Toast.makeText(ctx.androidContext, "Mention long clicked", Toast.LENGTH_SHORT).show() | ||
}, | ||
onClick = { | ||
Toast.makeText(ctx.androidContext, "Mention clicked", Toast.LENGTH_SHORT).show() | ||
} | ||
) | ||
} | ||
|
||
addMarkdownRules() | ||
} | ||
|
||
data class Context( | ||
val androidContext: AndroidContext, | ||
val userMap: Map<String, String> = mapOf("1234" to "Wing") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".AndroidTestActivity"> | ||
|
||
<TextView | ||
android:id="@+id/test_text" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/app_name" | ||
android:textSize="16sp" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
public final class xyz/wingio/syntakts/android/ClickableMovementMethod : android/text/method/LinkMovementMethod { | ||
public static final field Companion Lxyz/wingio/syntakts/android/ClickableMovementMethod$Companion; | ||
public static final field LONG_TOUCH_DURATION J | ||
public fun <init> ()V | ||
public fun onTouchEvent (Landroid/widget/TextView;Landroid/text/Spannable;Landroid/view/MotionEvent;)Z | ||
} | ||
|
||
public final class xyz/wingio/syntakts/android/ClickableMovementMethod$Companion { | ||
} | ||
|
||
public final class xyz/wingio/syntakts/android/SyntaktsKt { | ||
public static final fun render (Landroid/widget/TextView;Ljava/lang/CharSequence;Lxyz/wingio/syntakts/Syntakts;Ljava/lang/Object;Z)V | ||
public static final fun render (Landroid/widget/TextView;Ljava/lang/CharSequence;Lxyz/wingio/syntakts/Syntakts;Z)V | ||
public static final fun render (Lxyz/wingio/syntakts/Syntakts;Ljava/lang/CharSequence;Landroid/content/Context;)Ljava/lang/CharSequence; | ||
public static final fun render (Lxyz/wingio/syntakts/Syntakts;Ljava/lang/CharSequence;Ljava/lang/Object;Landroid/content/Context;)Ljava/lang/CharSequence; | ||
public static synthetic fun render$default (Landroid/widget/TextView;Ljava/lang/CharSequence;Lxyz/wingio/syntakts/Syntakts;Ljava/lang/Object;ZILjava/lang/Object;)V | ||
public static synthetic fun render$default (Landroid/widget/TextView;Ljava/lang/CharSequence;Lxyz/wingio/syntakts/Syntakts;ZILjava/lang/Object;)V | ||
} | ||
|
||
public final class xyz/wingio/syntakts/android/markdown/MarkdownKt { | ||
public static final fun renderBasicMarkdown (Landroid/widget/TextView;Ljava/lang/CharSequence;)V | ||
public static final fun renderMarkdown (Landroid/widget/TextView;Ljava/lang/CharSequence;)V | ||
} | ||
|
||
public class xyz/wingio/syntakts/android/spans/ClickableSpan : android/text/style/ClickableSpan { | ||
public fun <init> (Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function0;)V | ||
public fun onClick (Landroid/view/View;)V | ||
public final fun onLongClick (Landroid/view/View;)V | ||
public fun updateDrawState (Landroid/text/TextPaint;)V | ||
} | ||
|
||
public class xyz/wingio/syntakts/android/spans/SyntaktsStyleSpan : android/text/style/MetricAffectingSpan { | ||
public static final field Companion Lxyz/wingio/syntakts/android/spans/SyntaktsStyleSpan$Companion; | ||
public fun <init> (Lxyz/wingio/syntakts/style/Style;Landroid/content/Context;)V | ||
public final fun getContext ()Landroid/content/Context; | ||
public final fun getStyle ()Lxyz/wingio/syntakts/style/Style; | ||
public fun updateDrawState (Landroid/text/TextPaint;)V | ||
public fun updateMeasureState (Landroid/text/TextPaint;)V | ||
} | ||
|
||
public final class xyz/wingio/syntakts/android/spans/SyntaktsStyleSpan$Companion { | ||
public final fun apply (Landroid/text/TextPaint;Lxyz/wingio/syntakts/style/Style;Landroid/content/Context;)V | ||
} | ||
|
||
public final class xyz/wingio/syntakts/android/style/ColorKt { | ||
public static final fun fromAndroidColorLong (Lxyz/wingio/syntakts/style/Color$Companion;J)Lxyz/wingio/syntakts/style/Color; | ||
public static final fun toAndroidColorInt (Lxyz/wingio/syntakts/style/Color;)I | ||
public static final fun toSyntaktsColor (J)Lxyz/wingio/syntakts/style/Color; | ||
} | ||
|
||
public final class xyz/wingio/syntakts/android/style/SpannableStyledTextBuilder : xyz/wingio/syntakts/style/StyledTextBuilder { | ||
public fun <init> (Landroid/content/Context;)V | ||
public fun addClickable (IILkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function0;)Lxyz/wingio/syntakts/android/style/SpannableStyledTextBuilder; | ||
public synthetic fun addClickable (IILkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function0;)Lxyz/wingio/syntakts/style/StyledTextBuilder; | ||
public fun addClickable (Lkotlin/ranges/IntRange;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function0;)Lxyz/wingio/syntakts/style/StyledTextBuilder; | ||
public fun addStyle (IILkotlin/jvm/functions/Function1;)Lxyz/wingio/syntakts/android/style/SpannableStyledTextBuilder; | ||
public synthetic fun addStyle (IILkotlin/jvm/functions/Function1;)Lxyz/wingio/syntakts/style/StyledTextBuilder; | ||
public fun addStyle (Lkotlin/ranges/IntRange;Lkotlin/jvm/functions/Function1;)Lxyz/wingio/syntakts/style/StyledTextBuilder; | ||
public fun addStyle (Lxyz/wingio/syntakts/style/Style;II)Lxyz/wingio/syntakts/android/style/SpannableStyledTextBuilder; | ||
public synthetic fun addStyle (Lxyz/wingio/syntakts/style/Style;II)Lxyz/wingio/syntakts/style/StyledTextBuilder; | ||
public fun addStyle (Lxyz/wingio/syntakts/style/Style;Lkotlin/ranges/IntRange;)Lxyz/wingio/syntakts/style/StyledTextBuilder; | ||
public fun append (Ljava/lang/CharSequence;Lkotlin/jvm/functions/Function1;)Lxyz/wingio/syntakts/android/style/SpannableStyledTextBuilder; | ||
public synthetic fun append (Ljava/lang/CharSequence;Lkotlin/jvm/functions/Function1;)Lxyz/wingio/syntakts/style/StyledTextBuilder; | ||
public fun append (Ljava/lang/CharSequence;Lxyz/wingio/syntakts/style/Style;)Lxyz/wingio/syntakts/android/style/SpannableStyledTextBuilder; | ||
public synthetic fun append (Ljava/lang/CharSequence;Lxyz/wingio/syntakts/style/Style;)Lxyz/wingio/syntakts/style/StyledTextBuilder; | ||
public fun appendClickable (Ljava/lang/CharSequence;Lxyz/wingio/syntakts/style/Style;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function0;)Lxyz/wingio/syntakts/android/style/SpannableStyledTextBuilder; | ||
public synthetic fun appendClickable (Ljava/lang/CharSequence;Lxyz/wingio/syntakts/style/Style;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function0;)Lxyz/wingio/syntakts/style/StyledTextBuilder; | ||
public fun build ()Ljava/lang/CharSequence; | ||
public synthetic fun build ()Ljava/lang/Object; | ||
public fun clear ()V | ||
public final fun getContext ()Landroid/content/Context; | ||
public fun getLength ()I | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
plugins { | ||
kotlin("multiplatform") | ||
id("com.android.library") | ||
id("com.vanniktech.maven.publish.base") | ||
alias(libs.plugins.binary.compatibility) | ||
} | ||
|
||
setup( | ||
libName = "Syntakts for Android", | ||
moduleName = "syntakts-android", | ||
moduleDescription = "Support for Syntakts rendering on Android" | ||
) | ||
|
||
kotlin { | ||
androidTarget { | ||
publishLibraryVariants("release") | ||
} | ||
|
||
jvmToolchain(17) | ||
explicitApi() | ||
|
||
sourceSets { | ||
val androidMain by named("androidMain") { | ||
dependencies { | ||
api(project(":syntakts-core")) | ||
implementation(libs.androidx.core.ktx) | ||
implementation(libs.kotlin.coroutines.core) | ||
} | ||
} | ||
|
||
val androidTest by named("androidUnitTest") { | ||
dependencies { | ||
implementation(kotlin("test")) | ||
implementation(libs.junit) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.