Skip to content

Commit

Permalink
Merge pull request #3 from Irineu333/release/v1.0.2
Browse files Browse the repository at this point in the history
Release/v1.0.2

+ adicionado scheme para processamento de links
+ maior controle sobre a adição de spans
+ adicionado scheme para processamento de clicks
  • Loading branch information
Irineu333 authored Dec 2, 2021
2 parents 7e917c1 + 4db8ed1 commit f841e5e
Show file tree
Hide file tree
Showing 12 changed files with 382 additions and 81 deletions.
2 changes: 1 addition & 1 deletion .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ android {
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
}

Expand Down
81 changes: 67 additions & 14 deletions app/src/main/java/com/neo/highlightproject/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
package com.neo.highlightproject;

import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.method.LinkMovementMethod;
import android.text.style.StrikethroughSpan;
import android.text.style.UnderlineSpan;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.neo.highlight.core.Highlight;
import com.neo.highlight.core.Scheme;
import com.neo.highlight.util.listener.HighlightTextWatcher;
import com.neo.highlight.util.scheme.ColorScheme;
import com.neo.highlight.util.scheme.LinkScheme;
import com.neo.highlight.util.scheme.OnClickScheme;
import com.neo.highlight.util.scheme.StyleScheme;
import com.neo.highlightproject.databinding.ActivityMainBinding;

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

highlight.addScheme(
new StyleScheme(
"Highlight",
Pattern.compile("Highlight"),
StyleScheme.STYLE.BOLD_ITALIC
)
);

highlight.addScheme(
new ColorScheme(
"light",
Pattern.compile("light"),
Color.parseColor("#FF03DAC5")
)
);

highlight.addScheme(
new ColorScheme(
"Project",
Pattern.compile("Project"),
Color.BLACK
)
);
Expand All @@ -68,35 +75,35 @@ private void initHighlightExample() {

highlightTextWatcher.addScheme(
new ColorScheme(
"\\b(J|j)ava\\b",
Pattern.compile("\\b([Jj])ava\\b"),
Color.parseColor("#FC0400")
)
);

highlightTextWatcher.addScheme(
new ColorScheme(
"\\b(K|k)otlin\\b",
Pattern.compile("\\b([Kk])otlin\\b"),
Color.parseColor("#FC8500")
)
);

highlightTextWatcher.addScheme(
new ColorScheme(
"\\b(J|j)ava(S|s)cript\\b",
Pattern.compile("\\b([Jj])ava([Ss])cript\\b"),
Color.parseColor("#F5E200")
)
);

highlightTextWatcher.addScheme(
new ColorScheme(
"\\b(A|a)ndroid\\b",
Pattern.compile("\\b([Aa])ndroid\\b"),
Color.parseColor("#00CA0E")
)
);

highlightTextWatcher.addScheme(
new StyleScheme(
"\\b([Hh])ighlight\\b",
Pattern.compile("\\b([Hh])ighlight\\b"),
StyleScheme.STYLE.BOLD_ITALIC
)
);
Expand All @@ -113,9 +120,14 @@ public Pattern getRegex() {
}

@Override
public Object getSpan() {
public Object getSpan(@NonNull CharSequence text) {
return new StrikethroughSpan();
}

@Override
public boolean getClearOldSpan() {
return false;
}
}
);

Expand All @@ -131,33 +143,74 @@ public Pattern getRegex() {
}

@Override
public Object getSpan() {
public Object getSpan(@NonNull CharSequence text) {
return new UnderlineSpan();
}

@Override
public boolean getClearOldSpan() {
return false;
}
}
);

highlightTextWatcher.addSpanType(StrikethroughSpan.class);

//add link scheme

highlightTextWatcher.addScheme(
new LinkScheme().setClearOldSpan(true)
);

binding.edittext.setMovementMethod(LinkMovementMethod.getInstance());

//add click scheme

highlightTextWatcher.addScheme(
new OnClickScheme(Pattern.compile("[hH]ighlight"), (CharSequence text) -> showToast())
);

highlightTextWatcher.addScheme(
new OnClickScheme(Pattern.compile("Irineu A\\. Silva"), (CharSequence text) ->
goToMyGithub()
).setPainTextColor(Color.GRAY)
);

binding.edittext.addTextChangedListener(highlightTextWatcher);

//binding.edittext.setText(R.string.example);
initAutoText(getString(R.string.example));
}

private void goToMyGithub() {
String url = "https://github.com/Irineu333";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}

private void showToast() {
Toast.makeText(
MainActivity.this,
"Highlight is the best!!",
Toast.LENGTH_SHORT
).show();
}

private void initAutoText(String text) {

binding.edittext.setText("");
Handler handler = new Handler(Looper.getMainLooper());

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

Thread.sleep(50);
char charToAdd = text.charAt(index);

new Handler(Looper.getMainLooper())
.post(() -> binding.edittext.getText().append(charToAdd));
handler.post(
() -> binding.edittext.getText().append(charToAdd)
);
}
} catch (InterruptedException e) {
e.printStackTrace();
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<resources>
<string name="app_name">HighlightProject</string>
<string name="example">Java\nKotlin\nJavaScript\nAndroid\n\nThis is the best highlight lib!!</string>
<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>
</resources>
6 changes: 3 additions & 3 deletions highlight/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
defaultConfig {
minSdk 21
targetSdk 31
versionCode 2
versionName "1.0.1"
versionCode 3
versionName "1.0.2"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand Down Expand Up @@ -48,7 +48,7 @@ afterEvaluate {
// You can then customize attributes of the publication as shown below.
groupId = 'com.github.Irineu333'
artifactId = 'highlight'
version = '1.0.1'
version = '1.0.2'
}
}
}
Expand Down
Loading

0 comments on commit f841e5e

Please sign in to comment.