Skip to content

Commit 05949cb

Browse files
authored
Merge pull request #3 from testica/release/1.0.0
Release/1.0.0
2 parents be0802e + 3733bf4 commit 05949cb

7 files changed

Lines changed: 188 additions & 68 deletions

File tree

.idea/codeStyles/Project.xml

Lines changed: 0 additions & 59 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# CHANGELOG
2+
3+
## [1.0.0] - 2019-03-20
4+
- Add first stable version

README.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# Code Editor
2+
[ ![Download](https://api.bintray.com/packages/testica-android/maven/codeeditor/images/download.svg) ](https://bintray.com/testica-android/maven/codeeditor/_latestVersion)
3+
4+
Code Editor is an Android library that simplify the display of code, making easy syntax highlighting and showing number of lines.
5+
6+
## Requirements
7+
- minSdkVersion 15
8+
- compileSdkVersion 28
9+
10+
## Download
11+
12+
Include into the build.gradle file:
13+
14+
```groovy
15+
dependencies {
16+
implementation 'me.testica:codeeditor:1.0.0'
17+
}
18+
```
19+
## Usage
20+
21+
From layout:
22+
```xml
23+
<me.testica.codeeditor.Editor
24+
android:id="@+id/editor"
25+
app:textSize="16sp"
26+
android:layout_width="match_parent"
27+
android:layout_height="match_parent"/>
28+
```
29+
30+
Then, manipulate programmatically:
31+
32+
Java:
33+
```java
34+
Editor editor = (Editor) findViewById(R.id.editor);
35+
editor.setText("Hello Android");
36+
```
37+
Kotlin:
38+
```kotlin
39+
editor.setText("Hello Android")
40+
```
41+
42+
### Syntax Highlight Rules
43+
44+
Define a list of rules using a regular expression and color
45+
46+
Java:
47+
```java
48+
editor.setSyntaxHighlightRules(
49+
new SyntaxHighlightRule("[0-9]*", "#00838f"),
50+
new SyntaxHighlightRule("/\\\\*(?:.|[\\\\n\\\\r])*?\\\\*/|(?<!:)//.*", "#9ea7aa")
51+
);
52+
```
53+
Kotlin:
54+
```kotlin
55+
editor.setSyntaxHighlightRules(
56+
SyntaxHighlightRule("[0-9]*", "#00838f"),
57+
SyntaxHighlightRule("/\\\\*(?:.|[\\\\n\\\\r])*?\\\\*/|(?<!:)//.*", "#9ea7aa")
58+
)
59+
```
60+
**Keep in mind that lasts rules will overwrite the previous ones, so order is important.**
61+
62+
### Customization
63+
64+
From **xml** we can set:
65+
- `text`: text code as string
66+
- `textSize`: text dimension of text including number lines
67+
- `fontFamily`: typeface of text including number lines
68+
69+
The same way we can set and get above attributes programmatically:
70+
- `setText(String)`
71+
- `setTextSize(Float)`
72+
- `setTypeface(Typeface)`
73+
74+
Is it possible to customize the number lines or the code text separately? **Yes!**
75+
Programmatically we can get both widget reference and manipulate them:
76+
77+
- `getEditText()`: returns an `EditText` superclass, with this we can handle the code view.
78+
- `getNumLinesView()`: returns a `TextView` superclass, with this we can handle the number lines view.
79+
80+
Below an example changing the background color of number lines view and applying some padding to code view:
81+
82+
Java:
83+
```java
84+
// changing text color and background color to number lines view
85+
editor.getNumLinesView().setBackgroundColor(Color.BLACK);
86+
editor.getNumLinesView().setTextColor(Color.WHITE);
87+
88+
// applying left padding to code view
89+
editor.getEditText().setPadding(10, 0, 0, 0);
90+
```
91+
92+
Kotlin:
93+
```kotlin
94+
// changing text color and background color to number lines view
95+
editor.getNumLinesView().apply {
96+
setBackgroundColor(Color.BLACK)
97+
setTextColor(Color.WHITE)
98+
}
99+
100+
// applying left padding to code view
101+
editor.getEditText().setPadding(10, 0, 0, 0)
102+
```
103+
104+
You can see another approach inside **codeeditorexample/MainActivity** class.
105+
106+
## Contribute
107+
108+
I accept pull requests to fix, improve performance or well-situated feature! Feel free to submit one.
109+
110+
## License MIT
111+
```
112+
MIT License
113+
114+
Copyright (c) 2019 Leonardo Testa
115+
116+
Permission is hereby granted, free of charge, to any person obtaining a copy
117+
of this software and associated documentation files (the "Software"), to deal
118+
in the Software without restriction, including without limitation the rights
119+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
120+
copies of the Software, and to permit persons to whom the Software is
121+
furnished to do so, subject to the following conditions:
122+
123+
The above copyright notice and this permission notice shall be included in all
124+
copies or substantial portions of the Software.
125+
126+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
127+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
128+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
129+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
130+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
131+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
132+
SOFTWARE.
133+
```

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ buildscript {
1010
dependencies {
1111
classpath 'com.android.tools.build:gradle:3.3.2'
1212
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
13+
14+
classpath 'com.novoda:bintray-release:0.9'
1315
// NOTE: Do not place your application dependencies here; they belong
1416
// in the individual module build.gradle files
1517
}

codeeditor/build.gradle

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
apply plugin: 'com.android.library'
2+
apply plugin: 'com.novoda.bintray-release'
23
apply plugin: 'kotlin-android-extensions'
34
apply plugin: 'kotlin-android'
45

5-
android {
6-
compileSdkVersion 28
7-
6+
publish {
7+
userOrg = _userOrg
8+
repoName = _repoName
9+
groupId = _groupId
10+
artifactId = _artifactId
11+
publishVersion = _versionName
12+
desc = _desc
13+
website = _website
14+
}
815

16+
android {
17+
compileSdkVersion _targetSdkVersion as Integer
918

1019
defaultConfig {
11-
minSdkVersion 15
12-
targetSdkVersion 28
13-
versionCode 1
14-
versionName "1.0"
20+
minSdkVersion _minSdkVersion as Integer
21+
targetSdkVersion _targetSdkVersion as Integer
22+
versionCode _versionCode as Integer
23+
versionName _versionName
1524

1625
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1726

@@ -29,11 +38,16 @@ android {
2938
dependencies {
3039
implementation fileTree(dir: 'libs', include: ['*.jar'])
3140

32-
implementation 'com.android.support:appcompat-v7:28.0.0'
41+
// Android Support dependencies
42+
implementation "com.android.support:appcompat-v7:$androidVersion"
43+
44+
// Kotlin dependencies
45+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
46+
47+
// Test dependencies
3348
testImplementation 'junit:junit:4.12'
3449
androidTestImplementation 'com.android.support.test:runner:1.0.2'
3550
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
36-
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
3751
}
3852
repositories {
3953
mavenCentral()

codeeditor/src/main/java/me/testica/codeeditor/Editor.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ class Editor(context: Context, attrs: AttributeSet) : LinearLayout(context, attr
7979
return editText
8080
}
8181

82+
/**
83+
* Get number lines widget to access the whole API
84+
* Make whatever you want, but keep in mind that you may change default behaviour.
85+
* Get Fun!
86+
*/
87+
fun getNumLinesView(): EditorNumberLines {
88+
return numLinesView
89+
}
90+
8291
/**
8392
* Set syntax highlight rules
8493
* Keep in mind that rules may overlapped highlight of others, so the rule position matter

gradle.properties

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,20 @@ org.gradle.jvmargs=-Xmx1536m
1313
# org.gradle.parallel=true
1414
# Kotlin code style for this project: "official" or "obsolete":
1515
kotlin.code.style=official
16+
17+
# Bintray variables
18+
_userOrg = testica-android
19+
_repoName = maven
20+
_groupId = me.testica
21+
_artifactId = codeeditor
22+
_desc = Code editor android library (custom syntax highlighting, number lines, etc)
23+
_website = https://github.com/testica/codeeditor
24+
25+
# Project variables
26+
_versionCode = 1
27+
_versionName = 1.0.0
28+
_minSdkVersion = 15
29+
_targetSdkVersion = 28
30+
31+
# Dependencies
32+
androidVersion = 28.0.0

0 commit comments

Comments
 (0)