-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
darkengine
committed
Sep 7, 2024
1 parent
8e58507
commit 4ae8b0c
Showing
25 changed files
with
1,792 additions
and
58 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
app/src/main/java/com/dark/androidbox/codeView/Editor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.dark.androidbox.codeView; | ||
|
||
import android.graphics.Color; | ||
import com.amrdeveloper.codeview.CodeView; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.regex.Pattern; | ||
|
||
public class Editor { | ||
public CodeView txtCode; | ||
|
||
// Patterns for syntax highlighting | ||
private final Pattern keywordsPattern = Pattern.compile( | ||
"\\b(void|public|private|protected|static|final|new|return|int|short|long|float|double|boolean|if|else|for|while|do|switch|case|break|continue|try|catch|finally|throw|throws|interface|extends|implements|package|import)\\b"); | ||
private final Pattern classPattern = Pattern.compile( | ||
"\\b(String|Array|ArrayList|HashMap|Map|Pattern)\\b"); | ||
private final Pattern methodPattern = Pattern.compile( | ||
"\\b([a-zA-Z_$][a-zA-Z\\d_$]*)(\\s*\\()"); | ||
private final Pattern variablePattern = Pattern.compile( | ||
"(public|private|protected)?\\s*(static)?\\s*(final)?\\s*([A-Za-z0-9_$<>]+)\\s+([a-zA-Z_$][a-zA-Z\\d_$]*)\\s*([=;])"); | ||
private final Pattern packagePattern = Pattern.compile( | ||
"(?<=import\\s)([\\w.]+\\*?)(?=;)"); | ||
private final Pattern commentPattern = Pattern.compile( | ||
"/\\*(?:[^*]|\\*(?!/))*\\*/|//.*"); | ||
|
||
// Colors for syntax highlighting | ||
private static final int KEYWORD_COLOR = Color.parseColor("#B57AFF"); // Purple | ||
private static final int CLASS_COLOR = Color.parseColor("#A9B7C6"); // Light gray | ||
private static final int METHOD_COLOR = Color.parseColor("#469ded"); // Yellow | ||
private static final int VARIABLE_COLOR = Color.parseColor("#9876AA"); // Purple | ||
private static final int PACKAGE_COLOR = Color.parseColor("#6897BB"); // Blue | ||
private static final int COMMENT_COLOR = Color.parseColor("#808080"); // Gray | ||
|
||
public Editor(CodeView codeView) { | ||
this.txtCode = codeView; | ||
setUp(); | ||
} | ||
|
||
private void setUp() { | ||
// Setup line numbering | ||
txtCode.setEnableLineNumber(true); | ||
txtCode.setLineNumberTextColor(Color.parseColor("#606366")); | ||
txtCode.setLineNumberTextSize(30); | ||
|
||
// Setup auto-complete for code pairs | ||
Map<Character, Character> pairCompleteMap = new HashMap<>(); | ||
pairCompleteMap.put('{', '}'); | ||
pairCompleteMap.put('[', ']'); | ||
pairCompleteMap.put('(', ')'); | ||
pairCompleteMap.put('<', '>'); | ||
pairCompleteMap.put('"', '"'); | ||
txtCode.enablePairComplete(true); | ||
txtCode.setPairCompleteMap(pairCompleteMap); | ||
|
||
// Add syntax highlighting patterns | ||
txtCode.addSyntaxPattern(keywordsPattern, KEYWORD_COLOR); | ||
// txtCode.addSyntaxPattern(classPattern, CLASS_COLOR); | ||
txtCode.addSyntaxPattern(methodPattern, METHOD_COLOR); | ||
//txtCode.addSyntaxPattern(variablePattern, VARIABLE_COLOR); | ||
txtCode.addSyntaxPattern(packagePattern, PACKAGE_COLOR); | ||
txtCode.addSyntaxPattern(commentPattern, COMMENT_COLOR); | ||
|
||
// Set editor background color | ||
txtCode.setBackgroundColor(Color.parseColor("#2B2B2B")); | ||
txtCode.setTextColor(Color.parseColor("#A9B7C6")); | ||
} | ||
|
||
public void setTxtColor(String targetString, int color) { | ||
Pattern pattern = Pattern.compile(Pattern.quote(targetString)); | ||
txtCode.addSyntaxPattern(pattern, color); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
apply plugin: 'com.android.library' | ||
|
||
android { | ||
compileSdk 34 | ||
|
||
defaultConfig { | ||
minSdkVersion 15 | ||
targetSdk 34 | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles "consumer-rules.pro" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
namespace 'com.amrdeveloper.codeview' | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: "libs", include: ["*.jar"]) | ||
implementation 'androidx.appcompat:appcompat:1.7.0' | ||
testImplementation 'junit:junit:4.13.2' | ||
androidTestImplementation 'androidx.test.ext:junit:1.2.1' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' | ||
} |
Empty file.
Oops, something went wrong.