Skip to content

Commit

Permalink
Fix Theme
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad Aghazadeh committed Oct 5, 2018
1 parent 856115c commit 235289e
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 115 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@


<com.github.ahmadaghazadeh.editor.widget.CodeEditor
bind:isReadOnly="@{true}"
bind:isReadOnly="@{false}"
bind:code="@{viewModel.code}"
bind:lang="@{viewModel.lang}"
bind:isShowExtendedKeyboard="@{false}"
bind:isShowExtendedKeyboard="@{true}"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -203,87 +204,155 @@ 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());

mLinePaint = new StylePaint(false, false);
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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@ public static void setCodeView(CodeEditor view, MutableLiveData<String> 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";
Expand Down Expand Up @@ -124,15 +122,15 @@ 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();
}

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();
Expand Down
21 changes: 3 additions & 18 deletions library/src/main/res/layout/item_list_key.xml
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2018 Light Team Software
~
~ This file is part of ModPE IDE.
~
~ ModPE IDE is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ ModPE IDE is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->


<TextView xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/text_view"
android:textColor="@color/colorDocText"
android:layout_width="@dimen/bottom_bar_height"
android:layout_height="@dimen/bottom_bar_height"
android:background="?android:selectableItemBackground"
Expand Down
20 changes: 1 addition & 19 deletions library/src/main/res/layout/item_list_suggest.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2018 Light Team Software
~
~ This file is part of ModPE IDE.
~
~ ModPE IDE is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ ModPE IDE is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
Expand All @@ -27,6 +8,7 @@
android:padding="@dimen/padding_small">

<TextView
android:textColor="@color/colorDocText"
android:id="@+id/suggestion_title"
android:layout_width="match_parent"
android:layout_height="@dimen/suggestion_height"
Expand Down
2 changes: 0 additions & 2 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
</declare-styleable>

<declare-styleable name="ThemeAttributes">
<!-- Интерфейс -->
<attr name="colorTabs" format="color"/>
<attr name="colorTabIndicator" format="color"/>
<attr name="colorDocBackground" format="color"/>
Expand All @@ -47,7 +46,6 @@
<attr name="colorBracketSpan" format="color"/>
<attr name="colorDropDown" format="color"/>

<!-- Цвета для подсветки синтаксиса -->
<attr name="syntaxNumbers" format="color"/>
<attr name="syntaxSymbols" format="color"/>
<attr name="syntaxBrackets" format="color"/>
Expand Down
23 changes: 23 additions & 0 deletions library/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,27 @@
<color name="purple">#653BBF</color>
<color name="fake_transparent">#EEEEEE</color>

<color name="colorPrimary">#3c3f41</color>
<color name="colorPrimaryDark">#3c3f41</color>
<color name="colorAccent">#FF8000</color>
<color name="colorTabs">#37383A</color>
<color name="colorTabIndicator">#FF8000</color>
<color name="colorDocBackground">#303030</color>
<color name="colorDocText">#AAB6C6</color>
<color name="colorNumbersText">#808080</color>
<color name="colorSelection">#214283</color>
<color name="colorCursor">#BBBBBB</color>
<color name="colorSearchSpan">#32593D</color>
<color name="colorNumbersBackground">#343638</color>
<color name="colorSelectedLine">#3A3A3A</color>
<color name="colorBracketSpan">#33654B</color>
<color name="colorDropDown">#3c3f41</color>
<color name="syntaxNumbers">#6897BB</color>
<color name="syntaxSymbols">#E8E2B7</color>
<color name="syntaxBrackets">#E8E2B7</color>
<color name="syntaxKeywords">#EC7600</color>
<color name="syntaxMethods">#FEC76C</color>
<color name="syntaxStrings">#6E875A</color>
<color name="syntaxComments">#66747B</color>

</resources>
Loading

0 comments on commit 235289e

Please sign in to comment.