Skip to content

Commit

Permalink
Fix CodeEditor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad Aghazadeh committed Oct 6, 2018
1 parent ac35975 commit 50171b5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 20 deletions.
30 changes: 26 additions & 4 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,44 @@
type="com.github.ahmadaghazadeh.sample.CodeModel" />

</data>
<android.support.constraint.ConstraintLayout
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >


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

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


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



</android.support.constraint.ConstraintLayout>
</LinearLayout>

</layout>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import android.content.res.TypedArray;
import android.databinding.BindingAdapter;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
Expand All @@ -28,7 +31,7 @@

import java.io.Serializable;

public class CodeEditor extends RelativeLayout implements Serializable {
public class CodeEditor extends RelativeLayout {
RelativeLayout rootView;
private Context context;
private TextProcessor editor;
Expand All @@ -42,11 +45,13 @@ public class CodeEditor extends RelativeLayout implements Serializable {
private ICodeEditorTextChange codeEditorTextChange;
private boolean isDirty; //На данный момент не используется

public interface ICodeEditorTextChange{

public interface ICodeEditorTextChange {
void onTextChange(String str);
}
public void setOnTextChange(ICodeEditorTextChange onTextChange){
codeEditorTextChange=onTextChange;

public void setOnTextChange(ICodeEditorTextChange onTextChange) {
codeEditorTextChange = onTextChange;
editor.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
Expand All @@ -60,7 +65,7 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {

@Override
public void afterTextChanged(Editable s) {
if(codeEditorTextChange!=null){
if (codeEditorTextChange != null) {
codeEditorTextChange.onTextChange(s.toString());
}
}
Expand Down Expand Up @@ -89,7 +94,7 @@ public CodeEditor(Context context, AttributeSet attrs, int defStyleAttr, int def
init(context, null);
}

@BindingAdapter(value = {"code", "lang", "isReadOnly","isShowExtendedKeyboard"})
@BindingAdapter(value = {"code", "lang", "isReadOnly", "isShowExtendedKeyboard"})
public static void setCodeView(CodeEditor view, MutableLiveData<String> code, MutableLiveData<String> lang,
boolean isReadOnly,
boolean isShowExtendedKeyboard) {
Expand Down Expand Up @@ -132,18 +137,15 @@ private void init(Context context, AttributeSet attrs) {
RelativeLayout.LayoutParams rootViewParam = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

rootView = new RelativeLayout(context);
rootView.removeAllViews();
rootView.setLayoutParams(rootViewParam);
GutterView gutterView = new GutterView(context);
gutterView.setId(R.id.gutterView);
RelativeLayout.LayoutParams paramsGutter = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
paramsGutter.alignWithParent = true;
gutterView.setLayoutParams(paramsGutter);
rootView.addView(gutterView);


editor = new TextProcessor(context);
editor.setId(R.id.editor);
RelativeLayout.LayoutParams paramsTxtprocessor = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
editor.setLayoutParams(paramsTxtprocessor);
editor.setScrollBarStyle(SCROLLBARS_OUTSIDE_INSET);
Expand All @@ -158,7 +160,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,getResources().getColor(R.color.colorDocText));
int colorResource = a.getColor(R.styleable.ThemeAttributes_colorDocText, getResources().getColor(R.color.colorDocText));
editor.setTextColor(colorResource);
} finally {
a.recycle();
Expand All @@ -172,7 +174,6 @@ private void init(Context context, AttributeSet attrs) {
editor.setReadOnly(isReadOnly);

FastScrollerView mFastScrollerView = new FastScrollerView(context);
mFastScrollerView.setId(R.id.fastScrollerView);
RelativeLayout.LayoutParams fastParam = new RelativeLayout.LayoutParams(30, LayoutParams.MATCH_PARENT);
fastParam.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, TRUE);
mFastScrollerView.setLayoutParams(fastParam);
Expand All @@ -190,7 +191,6 @@ private void init(Context context, AttributeSet attrs) {


recyclerView = new ExtendedKeyboard(context);
recyclerView.setId(R.id.recyclerView);
RelativeLayout.LayoutParams recyclerViewParam = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, 40);

recyclerViewParam.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, TRUE);
Expand Down
8 changes: 4 additions & 4 deletions library/src/main/res/values/ids.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="gutterView" type="id"/>
<item name="editor" type="id"/>
<item name="fastScrollerView" type="id"/>
<item name="recyclerView" type="id"/>
<!--<item name="gutterView" type="id"/>-->
<!--<item name="editor" type="id"/>-->
<!--<item name="fastScrollerView" type="id"/>-->
<!--<item name="recyclerView" type="id"/>-->
</resources>

0 comments on commit 50171b5

Please sign in to comment.