diff --git a/README.md b/README.md
index fa46bba..9abb342 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# CodeEditor [![](https://jitpack.io/v/ahmadaghazadeh/CodeEditor.svg)](https://jitpack.io/#ahmadaghazadeh/CodeEditor)
-This is a text/code editor meant for integration as a modular component of the overall UI.
+This is a text/code(Base From [ModPE IDE] ) editor meant for integration as a modular component of the overall UI.
The aim is to provide a powerful editor that can be used just like any other View.
Ace text editor has been used for this purpose because it is feature-rich, fast, and easy to modify and embed in applications.
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 2f5b727..4a45c31 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -16,10 +16,10 @@
diff --git a/library/src/main/java/com/github/ahmadaghazadeh/editor/processor/TextProcessor.java b/library/src/main/java/com/github/ahmadaghazadeh/editor/processor/TextProcessor.java
index d8ca80e..c87aa17 100644
--- a/library/src/main/java/com/github/ahmadaghazadeh/editor/processor/TextProcessor.java
+++ b/library/src/main/java/com/github/ahmadaghazadeh/editor/processor/TextProcessor.java
@@ -22,6 +22,7 @@
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
+import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.PorterDuff;
import android.graphics.Rect;
@@ -203,12 +204,18 @@ public void SetTheme() {
protected void initTheme() {
TypedValue colorAttr;
+ Resources.Theme theme=mContext.getTheme();
mLineNumberPaint = new StylePaint(true, false);
colorAttr = new TypedValue();
- mContext.getTheme()
- .resolveAttribute(R.attr.colorNumbersText, colorAttr, true);
- mLineNumberPaint.setColor(colorAttr.data);
+ @ColorInt int color=getContext().getResources().getColor(R.color.colorNumbersText);
+ if(!theme.resolveAttribute(R.attr.colorNumbersText, colorAttr, true)){
+ theme.resolveAttribute(R.attr.colorNumbersText, colorAttr, true);
+ color=colorAttr.data;
+ if(color==0)
+ color=getContext().getResources().getColor(R.color.colorNumbersText);
+ }
+ mLineNumberPaint.setColor(color);
mLineNumberPaint.setTextAlign(StylePaint.Align.RIGHT);
mLineNumberPaint.setTextSize(getTextSize());
@@ -216,74 +223,136 @@ protected void initTheme() {
mLinePaint.setColor(mLineNumberPaint.getColor());
mLinePaint.setStyle(StylePaint.Style.STROKE);
+
mGutterBackgroundPaint = new StylePaint(false, false);
colorAttr = new TypedValue();
- mContext.getTheme()
- .resolveAttribute(R.attr.colorNumbersBackground, colorAttr, true);
- mGutterBackgroundPaint.setColor(colorAttr.data);
+
+ if(!theme.resolveAttribute(R.attr.colorNumbersBackground, colorAttr, true)){
+ theme.resolveAttribute(R.attr.colorNumbersBackground, colorAttr, true);
+ color=colorAttr.data;
+ if(color==0)
+ color=getContext().getResources().getColor(R.color.colorNumbersBackground);
+ }
+ mGutterBackgroundPaint.setColor(color);
mSelectedLinePaint = new StylePaint(false, false);
- colorAttr = new TypedValue();
- mContext.getTheme()
- .resolveAttribute(R.attr.colorSelectedLine, colorAttr, true);
- mSelectedLinePaint.setColor(colorAttr.data);
+
+ if(!theme.resolveAttribute(R.attr.colorSelectedLine, colorAttr, true)){
+ theme.resolveAttribute(R.attr.colorSelectedLine, colorAttr, true);
+ color=colorAttr.data;
+ if(color==0)
+ color=getContext().getResources().getColor(R.color.colorSelectedLine);
+ }
+ mSelectedLinePaint.setColor(color);
//endregion Paints
mColorSearchSpan = new TypedValue();
- mContext.getTheme()
- .resolveAttribute(R.attr.colorSearchSpan, mColorSearchSpan, true);
- colorAttr = new TypedValue();
- mContext.getTheme()
- .resolveAttribute(R.attr.syntaxNumbers, colorAttr, true);
- mSyntaxNumbers = new StyleSpan(colorAttr.data, false, false);
+ if(!theme.resolveAttribute(R.attr.syntaxNumbers, colorAttr, true)){
+ theme.resolveAttribute(R.attr.syntaxNumbers, colorAttr, true);
+ color=colorAttr.data;
+ if(color==0)
+ color=getContext().getResources().getColor(R.color.syntaxNumbers);
+ }
+ mSyntaxNumbers = new StyleSpan(color, false, false);
colorAttr = new TypedValue();
- mContext.getTheme()
- .resolveAttribute(R.attr.syntaxSymbols, colorAttr, true);
- mSyntaxSymbols = new StyleSpan(colorAttr.data, false, false);
+
+ if(!theme.resolveAttribute(R.attr.syntaxSymbols, colorAttr, true)){
+ theme.resolveAttribute(R.attr.syntaxSymbols, colorAttr, true);
+ color=colorAttr.data;
+ if(color==0)
+ color=getContext().getResources().getColor(R.color.syntaxSymbols);
+ }
+
+ mSyntaxSymbols = new StyleSpan(color, false, false);
colorAttr = new TypedValue();
- mContext.getTheme()
- .resolveAttribute(R.attr.syntaxBrackets, colorAttr, true);
- mSyntaxBrackets = new StyleSpan(colorAttr.data, false, false);
+
+ if(!theme.resolveAttribute(R.attr.syntaxBrackets, colorAttr, true)){
+ theme.resolveAttribute(R.attr.syntaxBrackets, colorAttr, true);
+ color=colorAttr.data;
+ if(color==0)
+ color=getContext().getResources().getColor(R.color.syntaxBrackets);
+ }
+ mSyntaxBrackets = new StyleSpan(color, false, false);
colorAttr = new TypedValue();
- mContext.getTheme()
- .resolveAttribute(R.attr.syntaxKeywords, colorAttr, true);
- mSyntaxKeywords = new StyleSpan(colorAttr.data, false, false);
+
+ if(!theme.resolveAttribute(R.attr.syntaxKeywords, colorAttr, true)){
+ theme.resolveAttribute(R.attr.syntaxKeywords, colorAttr, true);
+ color=colorAttr.data;
+ if(color==0)
+ color=getContext().getResources().getColor(R.color.syntaxKeywords);
+ }
+ mSyntaxKeywords = new StyleSpan(color, false, false);
colorAttr = new TypedValue();
- mContext.getTheme()
- .resolveAttribute(R.attr.syntaxMethods, colorAttr, true);
- mSyntaxMethods = new StyleSpan(colorAttr.data, false, false);
+
+ if(!theme.resolveAttribute(R.attr.syntaxMethods, colorAttr, true)){
+ theme.resolveAttribute(R.attr.syntaxMethods, colorAttr, true);
+ color=colorAttr.data;
+ if(color==0)
+ color=getContext().getResources().getColor(R.color.syntaxMethods);
+ }
+
+ mSyntaxMethods = new StyleSpan(color, false, false);
colorAttr = new TypedValue();
- mContext.getTheme()
- .resolveAttribute(R.attr.syntaxStrings, colorAttr, true);
- mSyntaxStrings = new StyleSpan(colorAttr.data, false, false);
+
+ if(!theme.resolveAttribute(R.attr.syntaxStrings, colorAttr, true)){
+ theme.resolveAttribute(R.attr.syntaxStrings, colorAttr, true);
+ color=colorAttr.data;
+ if(color==0)
+ color=getContext().getResources().getColor(R.color.syntaxStrings);
+ }
+
+ mSyntaxStrings = new StyleSpan(color, false, false);
colorAttr = new TypedValue();
- mContext.getTheme()
- .resolveAttribute(R.attr.syntaxComments, colorAttr, true);
- mSyntaxComments = new StyleSpan(colorAttr.data, false, true);
+
+ if(!theme.resolveAttribute(R.attr.syntaxComments, colorAttr, true)){
+ theme.resolveAttribute(R.attr.syntaxComments, colorAttr, true);
+ color=colorAttr.data;
+ if(color==0)
+ color=getContext().getResources().getColor(R.color.syntaxComments);
+ }
+
+ mSyntaxComments = new StyleSpan(color, false, true);
colorAttr = new TypedValue();
- mContext.getTheme()
- .resolveAttribute(R.attr.colorBracketSpan, colorAttr, true);
- mOpenBracketSpan = new BackgroundColorSpan(colorAttr.data);
- mClosedBracketSpan = new BackgroundColorSpan(colorAttr.data);
+
+ if(!theme.resolveAttribute(R.attr.colorBracketSpan, colorAttr, true)){
+ theme.resolveAttribute(R.attr.colorBracketSpan, colorAttr, true);
+ color=colorAttr.data;
+ if(color==0)
+ color=getContext().getResources().getColor(R.color.colorBracketSpan);
+ }
+
+ mOpenBracketSpan = new BackgroundColorSpan(color);
+ mClosedBracketSpan = new BackgroundColorSpan(color);
colorAttr = new TypedValue();
- mContext.getTheme()
- .resolveAttribute(R.attr.colorCursor, colorAttr, true);
- setCursorColor(colorAttr.data); //Cursor Color
+
+ if(!theme.resolveAttribute(R.attr.colorCursor, colorAttr, true)){
+ theme.resolveAttribute(R.attr.colorCursor, colorAttr, true);
+ color=colorAttr.data;
+ if(color==0)
+ color=getContext().getResources().getColor(R.color.colorCursor);
+ }
+
+ setCursorColor(color); //Cursor Color
colorAttr = new TypedValue();
- mContext.getTheme()
- .resolveAttribute(R.attr.colorSelection, colorAttr, true);
- setHighlightColor(colorAttr.data); //Selection Color
+ color=getContext().getResources().getColor(R.color.colorSelection);
+ if(!theme.resolveAttribute(R.attr.colorSelection, colorAttr, true)){
+ theme.resolveAttribute(R.attr.colorSelection, colorAttr, true);
+ color=colorAttr.data;
+ if(color==0)
+ color=getContext().getResources().getColor(R.color.colorNumbersText);
+ }
+ setHighlightColor(color); //Selection Color
}
protected void initMethods() {
diff --git a/library/src/main/java/com/github/ahmadaghazadeh/editor/widget/CodeEditor.java b/library/src/main/java/com/github/ahmadaghazadeh/editor/widget/CodeEditor.java
index 70165b0..8d70a1e 100644
--- a/library/src/main/java/com/github/ahmadaghazadeh/editor/widget/CodeEditor.java
+++ b/library/src/main/java/com/github/ahmadaghazadeh/editor/widget/CodeEditor.java
@@ -82,10 +82,8 @@ public static void setCodeView(CodeEditor view, MutableLiveData code, Mu
private void init(Context context, AttributeSet attrs) {
try {
-
-
+ removeAllViews();
this.context = context;
- context.setTheme(R.style.Theme_Darcula);
initEditor();
String code = "";
String lang = "html";
@@ -124,7 +122,7 @@ private void init(Context context, AttributeSet attrs) {
editor.setGravity(Gravity.TOP | Gravity.START);
TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.ThemeAttributes, 0, 0);
try {
- int colorResource = a.getColor(R.styleable.ThemeAttributes_colorDocBackground, /*default color*/ 0);
+ int colorResource = a.getColor(R.styleable.ThemeAttributes_colorDocBackground, getResources().getColor(R.color.colorDocBackground));
editor.setBackgroundColor(colorResource);
} finally {
a.recycle();
@@ -132,7 +130,7 @@ private void init(Context context, AttributeSet attrs) {
a = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.ThemeAttributes, 0, 0);
try {
- int colorResource = a.getColor(R.styleable.ThemeAttributes_colorDocText, /*default color*/ 0);
+ int colorResource = a.getColor(R.styleable.ThemeAttributes_colorDocText,getResources().getColor(R.color.colorDocText));
editor.setTextColor(colorResource);
} finally {
a.recycle();
diff --git a/library/src/main/res/layout/item_list_key.xml b/library/src/main/res/layout/item_list_key.xml
index 3d288ce..09fdcfa 100644
--- a/library/src/main/res/layout/item_list_key.xml
+++ b/library/src/main/res/layout/item_list_key.xml
@@ -1,26 +1,11 @@
-
+
-
-
-
@@ -47,7 +46,6 @@
-
diff --git a/library/src/main/res/values/colors.xml b/library/src/main/res/values/colors.xml
index 7988536..6d675e8 100644
--- a/library/src/main/res/values/colors.xml
+++ b/library/src/main/res/values/colors.xml
@@ -32,4 +32,27 @@
#653BBF
#EEEEEE
+ #3c3f41
+ #3c3f41
+ #FF8000
+ #37383A
+ #FF8000
+ #303030
+ #AAB6C6
+ #808080
+ #214283
+ #BBBBBB
+ #32593D
+ #343638
+ #3A3A3A
+ #33654B
+ #3c3f41
+ #6897BB
+ #E8E2B7
+ #E8E2B7
+ #EC7600
+ #FEC76C
+ #6E875A
+ #66747B
+
diff --git a/library/src/main/res/values/styles.xml b/library/src/main/res/values/styles.xml
index c686e1b..2c94891 100644
--- a/library/src/main/res/values/styles.xml
+++ b/library/src/main/res/values/styles.xml
@@ -33,7 +33,6 @@
- @null
- 0dp
- @color/gray
-
- @font/main_sans