Skip to content

Commit

Permalink
Merge pull request #18 from Irineu333/release/v1.0.4
Browse files Browse the repository at this point in the history
Release/v1.0.4
  • Loading branch information
Irineu333 authored Dec 11, 2021
2 parents d4db1c5 + c53fd48 commit 6c0991b
Show file tree
Hide file tree
Showing 31 changed files with 679 additions and 582 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.

93 changes: 52 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ highlight.addScheme(
new ColorScheme(
Pattern.compile("\\b([Jj])ava\\b"),
Color.parseColor("#FC0400")
)
);

highlight.addScheme(
),
new ColorScheme(
Pattern.compile("\\b([Kk])otlin\\b"),
Color.parseColor("#FC8500")
Expand All @@ -41,10 +38,7 @@ highlightTextWatcher.addScheme(
new StyleScheme(
Pattern.compile("\\b([Jj])ava\\b"),
StyleScheme.STYLE.BOLD_ITALIC
).setClearOldSpan(true)
);

highlightTextWatcher.addScheme(
).setClearOldSpan(true),
new StyleScheme(
Pattern.compile("\\b([Kk])otlin\\b"),
StyleScheme.STYLE.BOLD_ITALIC
Expand All @@ -55,34 +49,31 @@ highlightTextWatcher.addScheme(
binding.edittext.addTextChangedListener(highlightTextWatcher);
```
## Schemes
Use the default schemes; `ColorScheme`, `StyleScheme`, `LinkScheme` and `OnClickScheme`, or implement the `Scheme` interface to create a custom scheme.
Use the default schemes; `ColorScheme`, `OnBackgroundScheme`, `StyleScheme`, `FontScheme`, `LinkScheme` and `OnClickScheme`, or implement the `Scheme` interface to create a custom scheme.

``` java
...

highlight.addScheme(
//modify the style
new StyleScheme(
Pattern.compile("Highlight"),
StyleScheme.STYLE.BOLD_ITALIC
).addScopeScheme(
//scheme in scope of other schemes
new ColorScheme(
Pattern.compile("light"),
Color.parseColor("#FF03DAC5")
)
)
);

highlight.addScheme(
//modify the text color
new ColorScheme(
Pattern.compile("light"),
Color.parseColor("#FF03DAC5")
)
);

highlight.addScheme(
//make the links clickable
//clickable links
new LinkScheme().setPainTextUnderline(false)
);

highlight.addScheme(
//make a clickable text
//clickable text
new OnClickScheme(
Pattern.compile("Highlight"),
new OnClickScheme.OnClickListener() {
Expand All @@ -95,30 +86,50 @@ highlight.addScheme(
);

highlight.addScheme(
//create the custom scheme
new Scheme() {
@Override
public Pattern getRegex() {
return Pattern.compile("Highlight");
}

@Override
public Object getSpan(@NonNull CharSequence text) {
return new BackgroundColorSpan(Color.GRAY);
}

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

//for the library to know how to remove span
highlight.addSpanType(BackgroundColorSpan.class);
new ColorScheme(
Pattern.compile("Project"),
Color.BLACK
).addScopeScheme(
//font scheme
new FontScheme(
FontScheme.getFont(this, R.font.pacifico_regular)
)
)
);

...
```

## Performance
## SchemeScope

Every schema has a scope to which other schemas can be added via the `addScopeScheme (...)` method. Schemes added to a scope will run only within that scope, saving processing and creating possibilities for smarter highlights.

``` java
Highlight highlight = new Highlight();

highlight.addScheme(
new StyleScheme(
Pattern.compile("Highlight"),
StyleScheme.STYLE.BOLD_ITALIC
).addScopeScheme(
//add scheme scope in any scheme
new ColorScheme(
Pattern.compile("light"),
Color.parseColor("#FF03DAC5")
)
)
);

highlight.addScheme(
//use scope to group schemes
new Scope(Pattern.compile("Project"),
new ColorScheme(Color.BLACK),
new FontScheme(FontScheme.getFont(this, R.font.pacifico_regular))
)
);

highlight.setSpan(binding.toolbarTitle);
```

## Add to project

Expand Down
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_11
targetCompatibility JavaVersion.VERSION_11
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

Expand Down
Loading

0 comments on commit 6c0991b

Please sign in to comment.