Skip to content

Commit 717c917

Browse files
authored
Use app compat for textview and edittext (#9)
1 parent 7a378ca commit 717c917

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package me.testica.codeeditor
22

33
import android.content.Context
4+
import android.support.v7.widget.AppCompatTextView
45
import android.text.method.ScrollingMovementMethod
56
import android.util.AttributeSet
67
import android.view.Gravity
7-
import android.widget.TextView
88

99
/**
1010
* Vertical TextView that represent number of lines
1111
*/
12-
class EditorNumberLines(context: Context, attrs: AttributeSet): TextView(context, attrs) {
12+
class EditorNumberLines(context: Context, attrs: AttributeSet): AppCompatTextView(context, attrs) {
1313

1414
companion object {
1515
private const val RIGHT_PADDING = 5

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package me.testica.codeeditor
22

33
import android.content.Context
44
import android.graphics.Color
5+
import android.support.v7.widget.AppCompatEditText
56
import android.text.InputType
67
import android.text.Spanned
78
import android.text.method.ScrollingMovementMethod
89
import android.text.style.ForegroundColorSpan
910
import android.util.AttributeSet
1011
import android.view.Gravity
11-
import android.widget.EditText
1212
import java.util.regex.Pattern
1313

1414

@@ -18,7 +18,7 @@ import java.util.regex.Pattern
1818
* -> Listener when line count changes
1919
* -> Listener when vertical scroll changes
2020
*/
21-
class EditorText(context: Context, attrs: AttributeSet): EditText(context, attrs) {
21+
class EditorText(context: Context, attrs: AttributeSet): AppCompatEditText(context, attrs) {
2222

2323
private var mNumberLines = 0
2424

@@ -100,7 +100,7 @@ class EditorText(context: Context, attrs: AttributeSet): EditText(context, attrs
100100
if (syntaxHighlightRules.isNullOrEmpty()) return
101101

102102
// first remove all spans
103-
text.removeAllSpans()
103+
text?.removeAllSpans()
104104

105105
// set span for proper matching according to a rule
106106
for (syntaxHighlightRule in syntaxHighlightRules!!) {
@@ -109,7 +109,7 @@ class EditorText(context: Context, attrs: AttributeSet): EditText(context, attrs
109109
// TODO: catch exception
110110
val matcher = Pattern.compile(syntaxHighlightRule.regex).matcher(text)
111111

112-
while (matcher.find()) text.setSpan(
112+
while (matcher.find()) text?.setSpan(
113113
ForegroundColorSpan(color),
114114
matcher.start(),
115115
matcher.end(),

0 commit comments

Comments
 (0)