Skip to content

Commit

Permalink
Merge pull request #2 from Irineu333/development
Browse files Browse the repository at this point in the history
Publicado versão 1.0.1
  • Loading branch information
Irineu333 authored Dec 1, 2021
2 parents 29185b0 + b265dca commit 7e917c1
Show file tree
Hide file tree
Showing 10 changed files with 285 additions and 43 deletions.
4 changes: 2 additions & 2 deletions .idea/deploymentTargetDropDown.xml

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

99 changes: 84 additions & 15 deletions app/src/main/java/com/neo/highlightproject/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.neo.highlightproject;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.style.StrikethroughSpan;
import android.text.style.UnderlineSpan;

import androidx.appcompat.app.AppCompatActivity;

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

binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

configToolbar();
initHighlightExample();
}

private void initHighlightExample() {
private void configToolbar() {

Highlight highlight = new Highlight();

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

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

highlight.addScheme(
new ColorScheme(
"Project",
Color.BLACK
)
);


highlight.setSpan(binding.toolbarTitle);
}


private void initHighlightExample() {
HighlightTextWatcher highlightTextWatcher =
new HighlightTextWatcher();

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

highlight.addScheme(
highlightTextWatcher.addScheme(
new ColorScheme(
"\\b(K|k)otlin\\b",
Color.parseColor("#FC8500")
)
);

highlight.addScheme(
highlightTextWatcher.addScheme(
new ColorScheme(
"\\b(J|j)ava(S|s)cript\\b",
Color.parseColor("#F5E200")
)
);

highlight.addScheme(
highlightTextWatcher.addScheme(
new ColorScheme(
"\\b(A|a)ndroid\\b",
Color.parseColor("#00CA0E")
)
);

highlight.addScheme(
highlightTextWatcher.addScheme(
new StyleScheme(
"\\b([Hh])ighlight\\b",
StyleScheme.STYLE.BOLD_ITALIC
)
);

//custom example
highlight.addScheme(
highlightTextWatcher.addScheme(
new Scheme() {
final Pattern pattern =
Pattern.compile("\\b([Jj])ava([Ss])cript\\b");
Expand All @@ -85,14 +119,49 @@ public Object getSpan() {
}
);

highlight.addSpanType(StrikethroughSpan.class);
//custom example 2
highlightTextWatcher.addScheme(
new Scheme() {
final Pattern pattern =
Pattern.compile("\\b([Hh])ighlight\\b");

@Override
public Pattern getRegex() {
return pattern;
}

binding.edittext.addTextChangedListener(
new HighlightTextWatcher(
highlight
)
@Override
public Object getSpan() {
return new UnderlineSpan();
}
}
);

binding.edittext.setText(R.string.example);
highlightTextWatcher.addSpanType(StrikethroughSpan.class);

binding.edittext.addTextChangedListener(highlightTextWatcher);

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

private void initAutoText(String text) {

binding.edittext.setText("");

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

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

new Handler(Looper.getMainLooper())
.post(() -> binding.edittext.getText().append(charToAdd));
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}).start();
}
}
32 changes: 27 additions & 5 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<androidx.appcompat.widget.Toolbar
android:background="?attr/colorPrimary"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:textColor="?attr/colorOnPrimary"
android:layout_gravity="center"
android:textSize="22sp"
android:text="@string/app_name"
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

</androidx.appcompat.widget.Toolbar>

<EditText
android:padding="8dp"
android:gravity="top"
android:id="@+id/edittext"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"/>
android:layout_height="0dp"
android:background="@null"
android:gravity="top"
android:inputType="textMultiLine|textNoSuggestions"
android:padding="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar" />

</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.HighlightProject" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<style name="Theme.HighlightProject" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.HighlightProject" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<style name="Theme.HighlightProject" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
Expand Down
8 changes: 4 additions & 4 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 1
versionName "1.0"
versionCode 2
versionName "1.0.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand All @@ -30,7 +30,7 @@ android {

dependencies {

implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
Expand All @@ -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.0'
version = '1.0.1'
}
}
}
Expand Down
Loading

0 comments on commit 7e917c1

Please sign in to comment.