Skip to content

Commit f37a8cb

Browse files
committed
add onTextChangeListener
1 parent 947af0d commit f37a8cb

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/net/cryptobrewery/syntaxviewexample/MainActivity.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import android.support.v7.app.AppCompatActivity;
44
import android.os.Bundle;
5+
import android.text.Editable;
6+
import android.text.TextWatcher;
7+
import android.util.Log;
58

69
import net.cryptobrewery.syntaxview.SyntaxView;
710

@@ -33,6 +36,23 @@ protected void onCreate(Bundle savedInstanceState) {
3336
//this will set special characters color like ;
3437
syntax_view.setSpecialCharsColor("#cc7832");
3538

39+
//on text change listener
40+
syntax_view.code.addTextChangedListener(new TextWatcher() {
41+
@Override
42+
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
43+
}
3644

45+
@Override
46+
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
47+
//on text change listener
48+
Log.d("tester",charSequence.toString());
49+
50+
}
51+
52+
@Override
53+
public void afterTextChanged(Editable editable) {
54+
55+
}
56+
});
3757
}
3858
}

syntax-view/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ android {
2222
}
2323
}
2424

25+
compileOptions {
26+
targetCompatibility 1.8
27+
sourceCompatibility 1.8
28+
}
2529
}
2630

2731
dependencies {

syntax-view/src/main/java/net/cryptobrewery/syntaxview/SyntaxView.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import android.text.style.CharacterStyle;
1212
import android.text.style.ForegroundColorSpan;
1313
import android.util.AttributeSet;
14+
import android.util.Log;
15+
import android.widget.EditText;
1416
import android.widget.RelativeLayout;
1517
import android.widget.ScrollView;
1618
import android.widget.TextView;
@@ -24,7 +26,7 @@
2426
* Created by TOSHIBA on 6/25/2018.
2527
*/
2628

27-
public class SyntaxView extends RelativeLayout {
29+
public class SyntaxView extends RelativeLayout {
2830

2931
private SyntaxHighlighter keywords = new SyntaxHighlighter(
3032
Pattern.compile(
@@ -46,7 +48,7 @@ public class SyntaxView extends RelativeLayout {
4648
private SyntaxHighlighter[] schemes = { keywords, numbers,special,printStatments,annotations };
4749

4850

49-
private MaterialEditText code;
51+
public MaterialEditText code;
5052
private TextView rows;
5153

5254
public SyntaxView(Context context) {
@@ -92,6 +94,8 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
9294
linesText = linesText + i + "\n";
9395
}
9496
rows.setText(linesText);
97+
// printChange(s);
98+
9599
}
96100
//remove old highlighting and set new highlighting
97101
@Override
@@ -120,6 +124,7 @@ void removeSpans(Editable e, Class<? extends CharacterStyle> type) {
120124

121125

122126
});
127+
123128
}
124129

125130
//the user will be able to change color of the view as he wishes
@@ -263,4 +268,7 @@ public void setRowNumbersBgColor (String color) throws Error{
263268
}
264269
rows.setBackgroundColor(Color.parseColor(color));
265270
}
271+
272+
273+
266274
}

0 commit comments

Comments
 (0)