Skip to content

Commit 7e917c1

Browse files
authored
Merge pull request #2 from Irineu333/development
Publicado versão 1.0.1
2 parents 29185b0 + b265dca commit 7e917c1

File tree

10 files changed

+285
-43
lines changed

10 files changed

+285
-43
lines changed

.idea/deploymentTargetDropDown.xml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/neo/highlightproject/MainActivity.java

Lines changed: 84 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package com.neo.highlightproject;
22

3-
import androidx.appcompat.app.AppCompatActivity;
4-
53
import android.graphics.Color;
64
import android.os.Bundle;
5+
import android.os.Handler;
6+
import android.os.Looper;
77
import android.text.style.StrikethroughSpan;
8+
import android.text.style.UnderlineSpan;
9+
10+
import androidx.appcompat.app.AppCompatActivity;
811

912
import com.neo.highlight.core.Highlight;
1013
import com.neo.highlight.core.Scheme;
@@ -25,50 +28,81 @@ protected void onCreate(Bundle savedInstanceState) {
2528

2629
binding = ActivityMainBinding.inflate(getLayoutInflater());
2730
setContentView(binding.getRoot());
28-
31+
configToolbar();
2932
initHighlightExample();
3033
}
3134

32-
private void initHighlightExample() {
35+
private void configToolbar() {
36+
3337
Highlight highlight = new Highlight();
3438

3539
highlight.addScheme(
40+
new StyleScheme(
41+
"Highlight",
42+
StyleScheme.STYLE.BOLD_ITALIC
43+
)
44+
);
45+
46+
highlight.addScheme(
47+
new ColorScheme(
48+
"light",
49+
Color.parseColor("#FF03DAC5")
50+
)
51+
);
52+
53+
highlight.addScheme(
54+
new ColorScheme(
55+
"Project",
56+
Color.BLACK
57+
)
58+
);
59+
60+
61+
highlight.setSpan(binding.toolbarTitle);
62+
}
63+
64+
65+
private void initHighlightExample() {
66+
HighlightTextWatcher highlightTextWatcher =
67+
new HighlightTextWatcher();
68+
69+
highlightTextWatcher.addScheme(
3670
new ColorScheme(
3771
"\\b(J|j)ava\\b",
3872
Color.parseColor("#FC0400")
3973
)
4074
);
4175

42-
highlight.addScheme(
76+
highlightTextWatcher.addScheme(
4377
new ColorScheme(
4478
"\\b(K|k)otlin\\b",
4579
Color.parseColor("#FC8500")
4680
)
4781
);
4882

49-
highlight.addScheme(
83+
highlightTextWatcher.addScheme(
5084
new ColorScheme(
5185
"\\b(J|j)ava(S|s)cript\\b",
5286
Color.parseColor("#F5E200")
5387
)
5488
);
5589

56-
highlight.addScheme(
90+
highlightTextWatcher.addScheme(
5791
new ColorScheme(
5892
"\\b(A|a)ndroid\\b",
5993
Color.parseColor("#00CA0E")
6094
)
6195
);
6296

63-
highlight.addScheme(
97+
highlightTextWatcher.addScheme(
6498
new StyleScheme(
6599
"\\b([Hh])ighlight\\b",
66100
StyleScheme.STYLE.BOLD_ITALIC
67101
)
68102
);
69103

70104
//custom example
71-
highlight.addScheme(
105+
highlightTextWatcher.addScheme(
72106
new Scheme() {
73107
final Pattern pattern =
74108
Pattern.compile("\\b([Jj])ava([Ss])cript\\b");
@@ -85,14 +119,49 @@ public Object getSpan() {
85119
}
86120
);
87121

88-
highlight.addSpanType(StrikethroughSpan.class);
122+
//custom example 2
123+
highlightTextWatcher.addScheme(
124+
new Scheme() {
125+
final Pattern pattern =
126+
Pattern.compile("\\b([Hh])ighlight\\b");
127+
128+
@Override
129+
public Pattern getRegex() {
130+
return pattern;
131+
}
89132

90-
binding.edittext.addTextChangedListener(
91-
new HighlightTextWatcher(
92-
highlight
93-
)
133+
@Override
134+
public Object getSpan() {
135+
return new UnderlineSpan();
136+
}
137+
}
94138
);
95139

96-
binding.edittext.setText(R.string.example);
140+
highlightTextWatcher.addSpanType(StrikethroughSpan.class);
141+
142+
binding.edittext.addTextChangedListener(highlightTextWatcher);
143+
144+
//binding.edittext.setText(R.string.example);
145+
initAutoText(getString(R.string.example));
146+
}
147+
148+
private void initAutoText(String text) {
149+
150+
binding.edittext.setText("");
151+
152+
new Thread(() -> {
153+
try {
154+
for (int index = 0; index < text.length(); index++) {
155+
156+
Thread.sleep(50);
157+
char charToAdd = text.charAt(index);
158+
159+
new Handler(Looper.getMainLooper())
160+
.post(() -> binding.edittext.getText().append(charToAdd));
161+
}
162+
} catch (InterruptedException e) {
163+
e.printStackTrace();
164+
}
165+
}).start();
97166
}
98167
}
Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,39 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<androidx.constraintlayout.widget.ConstraintLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
34
xmlns:app="http://schemas.android.com/apk/res-auto"
45
xmlns:tools="http://schemas.android.com/tools"
56
android:layout_width="match_parent"
67
android:layout_height="match_parent"
78
tools:context=".MainActivity">
89

10+
<androidx.appcompat.widget.Toolbar
11+
android:background="?attr/colorPrimary"
12+
android:id="@+id/toolbar"
13+
android:layout_width="match_parent"
14+
android:layout_height="wrap_content"
15+
app:layout_constraintTop_toTopOf="parent">
16+
17+
<TextView
18+
android:textColor="?attr/colorOnPrimary"
19+
android:layout_gravity="center"
20+
android:textSize="22sp"
21+
android:text="@string/app_name"
22+
android:id="@+id/toolbar_title"
23+
android:layout_width="wrap_content"
24+
android:layout_height="wrap_content"/>
25+
26+
</androidx.appcompat.widget.Toolbar>
27+
928
<EditText
10-
android:padding="8dp"
11-
android:gravity="top"
1229
android:id="@+id/edittext"
1330
android:layout_width="match_parent"
14-
android:layout_height="match_parent"
15-
android:background="@color/white"/>
31+
android:layout_height="0dp"
32+
android:background="@null"
33+
android:gravity="top"
34+
android:inputType="textMultiLine|textNoSuggestions"
35+
android:padding="8dp"
36+
app:layout_constraintBottom_toBottomOf="parent"
37+
app:layout_constraintTop_toBottomOf="@+id/toolbar" />
1638

1739
</androidx.constraintlayout.widget.ConstraintLayout>

app/src/main/res/values-night/themes.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<resources xmlns:tools="http://schemas.android.com/tools">
22
<!-- Base application theme. -->
3-
<style name="Theme.HighlightProject" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
3+
<style name="Theme.HighlightProject" parent="Theme.MaterialComponents.DayNight.NoActionBar">
44
<!-- Primary brand color. -->
55
<item name="colorPrimary">@color/purple_200</item>
66
<item name="colorPrimaryVariant">@color/purple_700</item>

app/src/main/res/values/themes.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<resources xmlns:tools="http://schemas.android.com/tools">
22
<!-- Base application theme. -->
3-
<style name="Theme.HighlightProject" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
3+
<style name="Theme.HighlightProject" parent="Theme.MaterialComponents.DayNight.NoActionBar">
44
<!-- Primary brand color. -->
55
<item name="colorPrimary">@color/purple_500</item>
66
<item name="colorPrimaryVariant">@color/purple_700</item>

highlight/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ android {
99
defaultConfig {
1010
minSdk 21
1111
targetSdk 31
12-
versionCode 1
13-
versionName "1.0"
12+
versionCode 2
13+
versionName "1.0.1"
1414

1515
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1616
consumerProguardFiles "consumer-rules.pro"
@@ -30,7 +30,7 @@ android {
3030

3131
dependencies {
3232

33-
implementation 'androidx.appcompat:appcompat:1.3.1'
33+
implementation 'androidx.appcompat:appcompat:1.4.0'
3434
implementation 'com.google.android.material:material:1.4.0'
3535
testImplementation 'junit:junit:4.+'
3636
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
@@ -48,7 +48,7 @@ afterEvaluate {
4848
// You can then customize attributes of the publication as shown below.
4949
groupId = 'com.github.Irineu333'
5050
artifactId = 'highlight'
51-
version = '1.0.0'
51+
version = '1.0.1'
5252
}
5353
}
5454
}

0 commit comments

Comments
 (0)