Skip to content

Commit

Permalink
improved README
Browse files Browse the repository at this point in the history
simplified demo text
  • Loading branch information
markusressel committed Aug 27, 2018
1 parent c31a70a commit 36b8fbf
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 52 deletions.
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,64 @@
# KodeEditor
A simple code editor with syntax highlighting and pinch to zoom

# Build Status

| Master | Dev |
|--------|-----|
| [![Master](https://travis-ci.org/markusressel/KodeEditor.svg?branch=master)](https://travis-ci.org/markusressel/KutePreferences/branches) | [![Master](https://travis-ci.org/markusressel/KutePreferences.svg?branch=dev)](https://travis-ci.org/markusressel/KodeEditor/branches) |
| [![codebeat badge](https://codebeat.co/badges/f7fa8602-1d15-457e-904d-cb585e984952)](https://codebeat.co/projects/github-com-markusressel-kodeeditor-master) | [![codebeat badge](https://codebeat.co/badges/19447977-bc96-4519-90b1-e532139ae1a5)](https://codebeat.co/projects/github-com-markusressel-kodeeditor-dev) |

# Features
* Pinch-To-Zoom
* Line numbers
* Syntax highlighting
* import languages you need
* or simply create your own highlighter using **regex** or other techniques
* Written entirely in Kotlin

# How to use
Have a look at the demo app (`app` module) for a complete sample.

## Gradle
To use this library just include it in your dependencies using

repositories {
...
maven { url "https://jitpack.io" }
}

in your project build.gradle file and

dependencies {
implementation("com.github.markusressel.KodeEditor:library:+") {
transitive = true
}
}

in your desired module ```build.gradle``` file.

# License

```
MIT License
Copyright (c) 2018 Markus Ressel
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
38 changes: 3 additions & 35 deletions app/src/main/java/de/markusressel/kodeeditor/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.markusressel.kodeeditor

import android.os.AsyncTask
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import de.markusressel.kodeeditor.library.markdown.MarkdownSyntaxHighlighter
Expand All @@ -15,42 +14,11 @@ class MainActivity : AppCompatActivity() {

codeEditorView
.setSyntaxHighlighter(MarkdownSyntaxHighlighter())
// codeEditorView
// .setText("# Topic 1\n" + "\n" + "This is a *simple* demo ~~text~~ written in **Markdown**")
codeEditorView
.setText(getString(R.string.huge_text))
codeEditorView.zoomTo(codeEditorView.realZoom, false)

// doAsync {
// Thread
// .sleep(5000)
//
// runOnUiThread {
// codeEditorView
// .setSyntaxHighlighter(JavaSyntaxHighlighter())
// codeEditorView
// .setText("package de.markusressel.kodeeditor.libary.java;\n" + "\n" + "import android.content.Context;\n" + "import android.support.test.InstrumentationRegistry;\n" + "import android.support.test.runner.AndroidJUnit4;\n" + "\n" + "import org.junit.Test;\n" + "import org.junit.runner.RunWith;\n" + "\n" + "import static org.junit.Assert.*;\n" + "\n" + "/**\n" + " * Instrumented test, which will execute on an Android device.\n" + " *\n" + " * @see <a href=\"http://d.android.com/tools/testing\">Testing documentation</a>\n" + " */\n" + "@RunWith(AndroidJUnit4.class)\n" + "public class ExampleInstrumentedTest {\n" + " @Test\n" + " public void useAppContext() {\n" + " // Context of the app under test.\n" + " Context appContext = InstrumentationRegistry.getTargetContext();\n" + "\n" + " assertEquals(\"de.markusressel.kodeeditor.libarry.java.test\", appContext.getPackageName());\n" + " }\n" + "}\n")
// }
//
// Thread
// .sleep(5000)
// runOnUiThread {
// codeEditorView
// .setSyntaxHighlighter(KotlinSyntaxHighlighter())
// codeEditorView
// .setText("package de.markusressel.mkdocseditor.data.persistence.entity\n" + "\n" + "import de.markusressel.mkdocseditor.data.persistence.IdentifiableListItem\n" + "import de.markusressel.mkdocsrestclient.document.DocumentModel\n" + "import io.objectbox.annotation.Entity\n" + "import io.objectbox.annotation.Id\n" + "import io.objectbox.relation.ToOne\n" + "import java.util.*\n" + "\n" + "/**\n" + " * Created by Markus on 04.06.2018.\n" + " */\n" + "@Entity\n" + "data class DocumentEntity(@Id var entityId: Long = 0, val type: String = \"Document\", val id: String = \"\", val name: String = \"\", val filesize: Long = -1L, val modtime: Date = Date(), val url: String = \"\") : IdentifiableListItem {\n" + " override fun getItemId(): String = id\n" + "\n" + " lateinit var parentSection: ToOne<SectionEntity>\n" + "\n" + "}\n" + "\n" + "fun DocumentModel.asEntity(parentSection: SectionEntity): DocumentEntity {\n" + " val d = DocumentEntity(0, this.type, this.id, this.name, this.filesize, this.modtime, this.url)\n" + " d\n" + " .parentSection\n" + " .target = parentSection\n" + " return d\n" + "}")
// }
// }
.setText(getString(R.string.demo_text))
codeEditorView
.zoomTo(codeEditorView.realZoom, false)

}

fun Any.doAsync(handler: () -> Unit) {
object : AsyncTask<Void, Void, Void?>() {
override fun doInBackground(vararg p0: Void?): Void? {
handler()
return null
}
}
.execute()
}
}
80 changes: 74 additions & 6 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,74 @@
<resources>
<string name="app_name">KodeEditor</string>

<string name="demo_text"><![CDATA[
# KodeEditor
\nA simple code editor with syntax highlighting and pinch to zoom
\n
\n# Build Status
\n
\n| Master | Dev |
\n|--------|-----|
\n| [![Master](https://travis-ci.org/markusressel/KodeEditor.svg?branch=master)] | [![Dev](https://travis-ci.org/markusressel/KutePreferences.svg?branch=dev)] |
\n| ![codebeat badge](https://codebeat.co/badges/f7fa8602-1d15-457e-904d-cb585e984952) | ![codebeat badge](https://codebeat.co/badges/19447977-bc96-4519-90b1-e532139ae1a5) |
\n
\n# Features
\n* Pinch-To-Zoom
\n* Line numbers
\n* Syntax highlighting
\n * import languages you need
\n * or simply create your own highlighter using **regex** or other techniques
\n* Written entirely in Kotlin
\n
\n# How to use
\nHave a look at the demo app (`app` module) for a complete sample.
\n
\n## Gradle
\nTo use this library just include it in your dependencies using
\n
\n\u0020\u0020\u0020\u0020repositories {
\n\u0020\u0020\u0020\u0020\u0020\u0020…
\n\u0020\u0020\u0020\u0020\u0020\u0020maven { url "https://jitpack.io" }
\n\u0020\u0020\u0020\u0020}
\n
\nin your project build.gradle file and
\n
\n\u0020\u0020\u0020\u0020dependencies {
\n\u0020\u0020\u0020\u0020\u0020\u0020implementation("com.github.markusressel.KodeEditor:library:+") {
\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020transitive = true
\n\u0020\u0020\u0020\u0020\u0020\u0020}
\n\u0020\u0020\u0020\u0020}
\n
\nin your desired module ```build.gradle``` file.
\n
\n# License
\n
\n```
\nMIT License
\n
\nCopyright © 2018 Markus Ressel
\n
\nPermission is hereby granted, free of charge, to any person obtaining a copy
\nof this software and associated documentation files (the "Software"), to deal
\nin the Software without restriction, including without limitation the rights
\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\ncopies of the Software, and to permit persons to whom the Software is
\nfurnished to do so, subject to the following conditions:
\n
\nThe above copyright notice and this permission notice shall be included in all
\ncopies or substantial portions of the Software.
\n
\nTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
\nSOFTWARE.
\n```
]]></string>

<string name="huge_text"><![CDATA[
# TutorialTooltip [![API](https://img.shields.io/badge/API-14%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=14)
\nA simple and easy way to add targeted tutorial messages to your app.
Expand Down Expand Up @@ -30,7 +98,7 @@
\nTo use this library just include it in your depencencies using
\n
\n repositories {
\n ...
\n
\n maven { url "https://jitpack.io" }
\n }
\n
Expand Down Expand Up @@ -290,7 +358,7 @@
\n
\n# License
\n
\n Copyright (c) 2016 Markus Ressel
\n Copyright © 2016 Markus Ressel
\n
\n Licensed under the Apache License, Version 2.0 (the "License");
\n you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -333,7 +401,7 @@
\nTo use this library just include it in your depencencies using
\n
\n repositories {
\n ...
\n
\n maven { url "https://jitpack.io" }
\n }
\n
Expand Down Expand Up @@ -593,7 +661,7 @@
\n
\n# License
\n
\n Copyright (c) 2016 Markus Ressel
\n Copyright © 2016 Markus Ressel
\n
\n Licensed under the Apache License, Version 2.0 (the "License");
\n you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -636,7 +704,7 @@
\nTo use this library just include it in your depencencies using
\n
\n repositories {
\n ...
\n
\n maven { url "https://jitpack.io" }
\n }
\n
Expand Down Expand Up @@ -896,7 +964,7 @@
\n
\n# License
\n
\n Copyright (c) 2016 Markus Ressel
\n Copyright © 2016 Markus Ressel
\n
\n Licensed under the Apache License, Version 2.0 (the "License");
\n you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ open class CodeEditorView : ZoomLayout {
*/
lateinit var editTextView: CodeEditText

/**
* Set to true to force the width of the CodeEditorView to it's parents width
*/
private var forceParentWidth = false

private var moveWithCursorEnabled = false
private var currentLineCount = -1

Expand Down Expand Up @@ -189,17 +194,17 @@ open class CodeEditorView : ZoomLayout {
if (firstInit) {
firstInit = false

val parentView = (parent as View)
parentView
.width

contentLayout
.minimumHeight = parentView
.height
contentLayout
.minimumWidth = parentView
.width

setMinimumDimensions()
if (forceParentWidth) {
// force exact width
val params = contentLayout
.layoutParams
params
.width = (parent as View)
.height
contentLayout
.layoutParams = params
}
updateLineNumbers(editTextView.lineCount)
}
}
Expand Down Expand Up @@ -257,6 +262,20 @@ open class CodeEditorView : ZoomLayout {
})
}

private fun setMinimumDimensions() {
val parentView = (parent as View)

val parentWidth = parentView
.width
val parentHeight = parentView
.height

contentLayout
.minimumHeight = parentHeight
contentLayout
.minimumWidth = parentWidth
}

private fun moveScreenWithCursorIfNecessary() {
val pos = editTextView
.selectionStart
Expand Down

0 comments on commit 36b8fbf

Please sign in to comment.