Skip to content

Commit f841e5e

Browse files
authored
Merge pull request #3 from Irineu333/release/v1.0.2
Release/v1.0.2 + adicionado scheme para processamento de links + maior controle sobre a adição de spans + adicionado scheme para processamento de clicks
2 parents 7e917c1 + 4db8ed1 commit f841e5e

File tree

12 files changed

+382
-81
lines changed

12 files changed

+382
-81
lines changed

.idea/deploymentTargetDropDown.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/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ android {
2727
}
2828

2929
compileOptions {
30-
sourceCompatibility JavaVersion.VERSION_1_8
31-
targetCompatibility JavaVersion.VERSION_1_8
30+
sourceCompatibility JavaVersion.VERSION_11
31+
targetCompatibility JavaVersion.VERSION_11
3232
}
3333
}
3434

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

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
package com.neo.highlightproject;
22

3+
import android.content.Intent;
34
import android.graphics.Color;
5+
import android.net.Uri;
46
import android.os.Bundle;
57
import android.os.Handler;
68
import android.os.Looper;
9+
import android.text.method.LinkMovementMethod;
710
import android.text.style.StrikethroughSpan;
811
import android.text.style.UnderlineSpan;
12+
import android.widget.Toast;
913

14+
import androidx.annotation.NonNull;
1015
import androidx.appcompat.app.AppCompatActivity;
1116

1217
import com.neo.highlight.core.Highlight;
1318
import com.neo.highlight.core.Scheme;
1419
import com.neo.highlight.util.listener.HighlightTextWatcher;
1520
import com.neo.highlight.util.scheme.ColorScheme;
21+
import com.neo.highlight.util.scheme.LinkScheme;
22+
import com.neo.highlight.util.scheme.OnClickScheme;
1623
import com.neo.highlight.util.scheme.StyleScheme;
1724
import com.neo.highlightproject.databinding.ActivityMainBinding;
1825

@@ -38,21 +45,21 @@ private void configToolbar() {
3845

3946
highlight.addScheme(
4047
new StyleScheme(
41-
"Highlight",
48+
Pattern.compile("Highlight"),
4249
StyleScheme.STYLE.BOLD_ITALIC
4350
)
4451
);
4552

4653
highlight.addScheme(
4754
new ColorScheme(
48-
"light",
55+
Pattern.compile("light"),
4956
Color.parseColor("#FF03DAC5")
5057
)
5158
);
5259

5360
highlight.addScheme(
5461
new ColorScheme(
55-
"Project",
62+
Pattern.compile("Project"),
5663
Color.BLACK
5764
)
5865
);
@@ -68,35 +75,35 @@ private void initHighlightExample() {
6875

6976
highlightTextWatcher.addScheme(
7077
new ColorScheme(
71-
"\\b(J|j)ava\\b",
78+
Pattern.compile("\\b([Jj])ava\\b"),
7279
Color.parseColor("#FC0400")
7380
)
7481
);
7582

7683
highlightTextWatcher.addScheme(
7784
new ColorScheme(
78-
"\\b(K|k)otlin\\b",
85+
Pattern.compile("\\b([Kk])otlin\\b"),
7986
Color.parseColor("#FC8500")
8087
)
8188
);
8289

8390
highlightTextWatcher.addScheme(
8491
new ColorScheme(
85-
"\\b(J|j)ava(S|s)cript\\b",
92+
Pattern.compile("\\b([Jj])ava([Ss])cript\\b"),
8693
Color.parseColor("#F5E200")
8794
)
8895
);
8996

9097
highlightTextWatcher.addScheme(
9198
new ColorScheme(
92-
"\\b(A|a)ndroid\\b",
99+
Pattern.compile("\\b([Aa])ndroid\\b"),
93100
Color.parseColor("#00CA0E")
94101
)
95102
);
96103

97104
highlightTextWatcher.addScheme(
98105
new StyleScheme(
99-
"\\b([Hh])ighlight\\b",
106+
Pattern.compile("\\b([Hh])ighlight\\b"),
100107
StyleScheme.STYLE.BOLD_ITALIC
101108
)
102109
);
@@ -113,9 +120,14 @@ public Pattern getRegex() {
113120
}
114121

115122
@Override
116-
public Object getSpan() {
123+
public Object getSpan(@NonNull CharSequence text) {
117124
return new StrikethroughSpan();
118125
}
126+
127+
@Override
128+
public boolean getClearOldSpan() {
129+
return false;
130+
}
119131
}
120132
);
121133

@@ -131,33 +143,74 @@ public Pattern getRegex() {
131143
}
132144

133145
@Override
134-
public Object getSpan() {
146+
public Object getSpan(@NonNull CharSequence text) {
135147
return new UnderlineSpan();
136148
}
149+
150+
@Override
151+
public boolean getClearOldSpan() {
152+
return false;
153+
}
137154
}
138155
);
139156

140157
highlightTextWatcher.addSpanType(StrikethroughSpan.class);
141158

159+
//add link scheme
160+
161+
highlightTextWatcher.addScheme(
162+
new LinkScheme().setClearOldSpan(true)
163+
);
164+
165+
binding.edittext.setMovementMethod(LinkMovementMethod.getInstance());
166+
167+
//add click scheme
168+
169+
highlightTextWatcher.addScheme(
170+
new OnClickScheme(Pattern.compile("[hH]ighlight"), (CharSequence text) -> showToast())
171+
);
172+
173+
highlightTextWatcher.addScheme(
174+
new OnClickScheme(Pattern.compile("Irineu A\\. Silva"), (CharSequence text) ->
175+
goToMyGithub()
176+
).setPainTextColor(Color.GRAY)
177+
);
178+
142179
binding.edittext.addTextChangedListener(highlightTextWatcher);
143180

144181
//binding.edittext.setText(R.string.example);
145182
initAutoText(getString(R.string.example));
146183
}
147184

185+
private void goToMyGithub() {
186+
String url = "https://github.com/Irineu333";
187+
Intent i = new Intent(Intent.ACTION_VIEW);
188+
i.setData(Uri.parse(url));
189+
startActivity(i);
190+
}
191+
192+
private void showToast() {
193+
Toast.makeText(
194+
MainActivity.this,
195+
"Highlight is the best!!",
196+
Toast.LENGTH_SHORT
197+
).show();
198+
}
199+
148200
private void initAutoText(String text) {
149201

150202
binding.edittext.setText("");
203+
Handler handler = new Handler(Looper.getMainLooper());
151204

152205
new Thread(() -> {
153206
try {
154-
for (int index = 0; index < text.length(); index++) {
207+
for (char charToAdd : text.toCharArray()) {
155208

156209
Thread.sleep(50);
157-
char charToAdd = text.charAt(index);
158210

159-
new Handler(Looper.getMainLooper())
160-
.post(() -> binding.edittext.getText().append(charToAdd));
211+
handler.post(
212+
() -> binding.edittext.getText().append(charToAdd)
213+
);
161214
}
162215
} catch (InterruptedException e) {
163216
e.printStackTrace();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<resources>
22
<string name="app_name">HighlightProject</string>
3-
<string name="example">Java\nKotlin\nJavaScript\nAndroid\n\nThis is the best highlight lib!!</string>
3+
<string name="example">Java\nKotlin\nJavaScript\nAndroid\n\nThis is the best highlight lib!!\n\nRepo: https://github.com/Irineu333/Highlight\nAuthor: Irineu A. Silva</string>
44
</resources>

highlight/build.gradle

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

1515
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1616
consumerProguardFiles "consumer-rules.pro"
@@ -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.1'
51+
version = '1.0.2'
5252
}
5353
}
5454
}

0 commit comments

Comments
 (0)