Skip to content

Commit

Permalink
Fix suggest dropdown position
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadaghazadeh committed Oct 17, 2018
1 parent eeeba56 commit 3e1f402
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 134 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

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

3 changes: 1 addition & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,5 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(':library')
implementation 'android.arch.navigation:navigation-fragment:1.0.0-alpha06'
implementation project(':library')
}
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ protected void onCreate(Bundle savedInstanceState) {
ActivityMainBinding mViewDataBinding = DataBindingUtil.setContentView(this, R.layout.activity_main);
mViewDataBinding.setVariable(BR.viewModel, codeModel);
mViewDataBinding.setLifecycleOwner(this);
mViewDataBinding.editor.setOnTextChange(str -> {
Toast.makeText(this,str,Toast.LENGTH_LONG).show();
});
// mViewDataBinding.editor.setOnTextChange(str -> {
// Toast.makeText(this,str,Toast.LENGTH_LONG).show();
// });

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package com.github.ahmadaghazadeh.editor.processor;

import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
Expand Down Expand Up @@ -204,16 +205,16 @@ public void SetTheme() {
protected void initTheme() {
TypedValue colorAttr;

Resources.Theme theme=mContext.getTheme();
Resources.Theme theme = mContext.getTheme();

mLineNumberPaint = new StylePaint(true, false);
colorAttr = new TypedValue();
@ColorInt int color=getContext().getResources().getColor(R.color.colorNumbersText);
if(!theme.resolveAttribute(R.attr.colorNumbersText, colorAttr, true)){
@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);
color = colorAttr.data;
if (color == 0)
color = getContext().getResources().getColor(R.color.colorNumbersText);
}
mLineNumberPaint.setColor(color);
mLineNumberPaint.setTextAlign(StylePaint.Align.RIGHT);
Expand All @@ -227,130 +228,130 @@ protected void initTheme() {
mGutterBackgroundPaint = new StylePaint(false, false);
colorAttr = new TypedValue();

if(!theme.resolveAttribute(R.attr.colorNumbersBackground, colorAttr, true)){
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);
color = colorAttr.data;
if (color == 0)
color = getContext().getResources().getColor(R.color.colorNumbersBackground);
}
mGutterBackgroundPaint.setColor(color);

mSelectedLinePaint = new StylePaint(false, false);

if(!theme.resolveAttribute(R.attr.colorSelectedLine, colorAttr, true)){
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);
color = colorAttr.data;
if (color == 0)
color = getContext().getResources().getColor(R.color.colorSelectedLine);
}
mSelectedLinePaint.setColor(color);

//endregion Paints

mColorSearchSpan = new TypedValue();

if(!theme.resolveAttribute(R.attr.syntaxNumbers, colorAttr, true)){
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);
color = colorAttr.data;
if (color == 0)
color = getContext().getResources().getColor(R.color.syntaxNumbers);
}
mSyntaxNumbers = new StyleSpan(color, false, false);

colorAttr = new TypedValue();

if(!theme.resolveAttribute(R.attr.syntaxSymbols, colorAttr, true)){
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);
color = colorAttr.data;
if (color == 0)
color = getContext().getResources().getColor(R.color.syntaxSymbols);
}

mSyntaxSymbols = new StyleSpan(color, false, false);

colorAttr = new TypedValue();

if(!theme.resolveAttribute(R.attr.syntaxBrackets, colorAttr, true)){
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);
color = colorAttr.data;
if (color == 0)
color = getContext().getResources().getColor(R.color.syntaxBrackets);
}
mSyntaxBrackets = new StyleSpan(color, false, false);

colorAttr = new TypedValue();

if(!theme.resolveAttribute(R.attr.syntaxKeywords, colorAttr, true)){
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);
color = colorAttr.data;
if (color == 0)
color = getContext().getResources().getColor(R.color.syntaxKeywords);
}
mSyntaxKeywords = new StyleSpan(color, false, false);

colorAttr = new TypedValue();

if(!theme.resolveAttribute(R.attr.syntaxMethods, colorAttr, true)){
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);
color = colorAttr.data;
if (color == 0)
color = getContext().getResources().getColor(R.color.syntaxMethods);
}

mSyntaxMethods = new StyleSpan(color, false, false);

colorAttr = new TypedValue();

if(!theme.resolveAttribute(R.attr.syntaxStrings, colorAttr, true)){
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);
color = colorAttr.data;
if (color == 0)
color = getContext().getResources().getColor(R.color.syntaxStrings);
}

mSyntaxStrings = new StyleSpan(color, false, false);

colorAttr = new TypedValue();

if(!theme.resolveAttribute(R.attr.syntaxComments, colorAttr, 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);
color = colorAttr.data;
if (color == 0)
color = getContext().getResources().getColor(R.color.syntaxComments);
}

mSyntaxComments = new StyleSpan(color, false, true);

colorAttr = new TypedValue();

if(!theme.resolveAttribute(R.attr.colorBracketSpan, colorAttr, true)){
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);
color = colorAttr.data;
if (color == 0)
color = getContext().getResources().getColor(R.color.colorBracketSpan);
}

mOpenBracketSpan = new BackgroundColorSpan(color);
mClosedBracketSpan = new BackgroundColorSpan(color);

colorAttr = new TypedValue();

if(!theme.resolveAttribute(R.attr.colorCursor, colorAttr, true)){
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);
color = colorAttr.data;
if (color == 0)
color = getContext().getResources().getColor(R.color.colorCursor);
}

setCursorColor(color); //Cursor Color

colorAttr = new TypedValue();
color=getContext().getResources().getColor(R.color.colorSelection);
if(!theme.resolveAttribute(R.attr.colorSelection, colorAttr, true)){
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);
color = colorAttr.data;
if (color == 0)
color = getContext().getResources().getColor(R.color.colorNumbersText);
}
setHighlightColor(color); //Selection Color
}
Expand Down Expand Up @@ -749,17 +750,19 @@ protected void onPopupChangePosition() {
int offsetHorizontal = (int) x + mGutterWidth;
setDropDownHorizontalOffset(offsetHorizontal);

// int heightVisible = getHeightVisible();
int heightVisible = getHeightVisible();
int offsetVertical = (int) ((y + mCharHeight) - getScrollY());

int tmp = offsetVertical + getDropDownHeight() + mCharHeight;
// if (tmp < heightVisible) {
tmp = -(offsetVertical + mCharHeight) + ((offsetVertical / mCharHeight) * (mCharHeight / 2));
setDropDownVerticalOffset(tmp);
// } else {
// tmp = offsetVertical - getDropDownHeight() - mCharHeight;
// setDropDownVerticalOffset(tmp);
// }
if (tmp < heightVisible) {
tmp = -(offsetVertical + mCharHeight) + ((offsetVertical / mCharHeight) * (mCharHeight / 2));
setDropDownVerticalOffset(tmp);
} else {
tmp = offsetVertical - getDropDownHeight() - mCharHeight;
setDropDownVerticalOffset(tmp);

((Activity)(getContext())).setTitle(" tmp:"+tmp);
}

}
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class HtmlLanguage extends Language {

private static final Pattern SYNTAX_NUMBERS = Pattern.compile("(\\b(\\d*[.]?\\d+)\\b)");
private static final Pattern SYNTAX_SYMBOLS = Pattern.compile(
"(!|\\+|-|\\*|<|>|=|\\?|\\||:|%|&)");
"(!|\\+|-|\\*|=|\\?|\\||:|%|&)");
private static final Pattern SYNTAX_BRACKETS = Pattern.compile("(\\(|\\)|\\{|\\}|\\[|\\])");
private static final Pattern SYNTAX_KEYWORDS = Pattern.compile(
"(?<=\\b)((break)|(continue)|(else)|(for)|(function)|(if)|(in)|(new)" +
Expand Down
Loading

0 comments on commit 3e1f402

Please sign in to comment.