GithubHelp home page GithubHelp logo

amrdeveloper / codeview Goto Github PK

View Code? Open in Web Editor NEW
374.0 12.0 47.0 10.33 MB

Android Library to make it easy to create an Code editor or IDE that support any languages and themes, with auto complete, auto indenting, snippets and more features

Home Page: https://amrdeveloper.github.io/CodeView/

License: MIT License

Java 100.00%
codeview android-codeview codeeditor autocompletetextview ide android-library syntax-highlighting android-ui highlighting hacktoberfest

codeview's People

Contributors

amrdeveloper avatar arashvscode avatar codacy-badger avatar issess avatar m-anshuman2166 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

codeview's Issues

Failed to inflate ColorStateList, leaving it to the framework

I create vertical stepper using this third party library.

Everything work on my android 5.1.1 and 11

But I have android 5.1.1 custom ROM to MIUI global stable 9 and CodeView said error

2022-03-26 14:37:19.556 4083-4083/com.sasmitadeveloper.java W/ResourcesCompat: Failed to inflate ColorStateList, leaving it to the framework
    java.lang.RuntimeException: Failed to resolve attribute at index 0
        at android.content.res.TypedArray.getColor(TypedArray.java:403)
        at android.content.res.XResources$XTypedArray.getColor(XResources.java:1296)
        at androidx.core.content.res.ColorStateListInflaterCompat.inflate(ColorStateListInflaterCompat.java:160)
        at androidx.core.content.res.ColorStateListInflaterCompat.createFromXmlInner(ColorStateListInflaterCompat.java:125)
        at androidx.core.content.res.ColorStateListInflaterCompat.createFromXml(ColorStateListInflaterCompat.java:104)
        at androidx.core.content.res.ResourcesCompat.inflateColorStateList(ResourcesCompat.java:229)
        at androidx.core.content.res.ResourcesCompat.getColorStateList(ResourcesCompat.java:203)
        at androidx.core.content.ContextCompat.getColorStateList(ContextCompat.java:519)
        at androidx.appcompat.content.res.AppCompatResources.getColorStateList(AppCompatResources.java:48)
        at com.google.android.material.resources.MaterialResources.getColorStateList(MaterialResources.java:60)
        at com.google.android.material.button.MaterialButtonHelper.loadFromAttributes(MaterialButtonHelper.java:108)
        at com.google.android.material.button.MaterialButton.<init>(MaterialButton.java:246)
        at com.google.android.material.button.MaterialButton.<init>(MaterialButton.java:217)
        at java.lang.reflect.Constructor.newInstance(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
        at android.view.LayoutInflater.createView(LayoutInflater.java:611)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:747)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:810)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:508)
        at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
        at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:334)
        at android.view.LayoutInflater.inflate(<Xposed>)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:418)
        at ernestoyaquello.com.verticalstepperform.StepHelper.initialize(StepHelper.java:68)
        at ernestoyaquello.com.verticalstepperform.VerticalStepperFormView.initializeStepHelper(VerticalStepperFormView.java:837)
        at ernestoyaquello.com.verticalstepperform.VerticalStepperFormView.initializeForm(VerticalStepperFormView.java:823)
        at ernestoyaquello.com.verticalstepperform.Builder.init(Builder.java:539)
        at com.sasmitadeveloper.java.MainActivity.onCreate(MainActivity.java:35)
        at android.app.Activity.performCreate(Activity.java:6093)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2404)
        at android.app.ActivityThread.access$900(ActivityThread.java:154)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1315)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5296)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707)
        at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:102)

at first i thought error in VerticalStepperLibrary but when I remove pattern in code view, everything work. Of cours codeView will not showing any color. This is my pattern class, copy from example in this project

public class PatternTools {

    //Language Keywords
    private static final Pattern PATTERN_KEYWORDS = Pattern.compile("\\b(abstract|boolean|break|byte|case|catch" +
            "|char|class|continue|default|do|double|else" +
            "|String|true|false" +
            "|enum|extends|final|finally|float|for|if" +
            "|implements|import|instanceof|int|interface" +
            "|long|native|new|null|package|private|protected" +
            "|public|return|short|static|strictfp|super|switch" +
            "|synchronized|this|throw|transient|try|void|volatile|while)\\b");

    private static final Pattern PATTERN_BUILTINS = Pattern.compile("[,:;[->]{}()]");
    private static final Pattern PATTERN_COMMENT = Pattern.compile("//(?!TODO )[^\\n]*" + "|" + "/\\*(.|\\R)*?\\*/");
    private static final Pattern PATTERN_ATTRIBUTE = Pattern.compile("\\.[a-zA-Z0-9_]+");
    private static final Pattern PATTERN_OPERATION = Pattern.compile(":|==|>|<|!=|>=|<=|->|=|>|<|%|-|-=|%=|\\+|\\-|\\-=|\\+=|\\^|\\&|\\|::|\\?|\\*");
    private static final Pattern PATTERN_GENERIC = Pattern.compile("<[a-zA-Z0-9,<>]+>");
    private static final Pattern PATTERN_ANNOTATION = Pattern.compile("@.[a-zA-Z0-9]+");
    private static final Pattern PATTERN_TODO_COMMENT = Pattern.compile("//TODO[^\n]*");
    private static final Pattern PATTERN_NUMBERS = Pattern.compile("\\b(\\d*[.]?\\d+)\\b");
    private static final Pattern PATTERN_CHAR = Pattern.compile("'[a-zA-Z]'");
    private static final Pattern PATTERN_STRING = Pattern.compile("\".*\"");
    private static final Pattern PATTERN_HEX = Pattern.compile("0x[0-9a-fA-F]+");

    public PatternTools() {
    }

    public void addPattern(Context context, CodeView codeView) {
        //View Background monokia pro black
        codeView.setBackgroundColor(codeView.getResources().getColor(R.color.transparant));

        //Syntax Colors
        codeView.addSyntaxPattern(PATTERN_HEX, context.getResources().getColor(R.color.monokia_pro_purple));
        codeView.addSyntaxPattern(PATTERN_CHAR, context.getResources().getColor(R.color.monokia_pro_green));
        codeView.addSyntaxPattern(PATTERN_STRING, context.getResources().getColor(R.color.orange2));
        codeView.addSyntaxPattern(PATTERN_NUMBERS, context.getResources().getColor(R.color.monokia_pro_purple));
        codeView.addSyntaxPattern(PATTERN_KEYWORDS, context.getResources().getColor(R.color.monokia_pro_pink));
        codeView.addSyntaxPattern(PATTERN_BUILTINS, context.getResources().getColor(R.color.monokia_pro_pink));
        codeView.addSyntaxPattern(PATTERN_COMMENT, context.getResources().getColor(R.color.monokia_pro_grey));
        codeView.addSyntaxPattern(PATTERN_ANNOTATION, context.getResources().getColor(R.color.monokia_pro_pink));
        codeView.addSyntaxPattern(PATTERN_ATTRIBUTE, context.getResources().getColor(R.color.green));
        codeView.addSyntaxPattern(PATTERN_GENERIC, context.getResources().getColor(R.color.monokia_pro_pink));
        codeView.addSyntaxPattern(PATTERN_OPERATION, context.getResources().getColor(R.color.monokia_pro_pink));
        //Default Color
        codeView.setTextColor(context.getResources().getColor(R.color.monokia_pro_black));

        codeView.addSyntaxPattern(PATTERN_TODO_COMMENT, context.getResources().getColor(R.color.gold));

        codeView.reHighlightSyntax();
    }
}

this how I use the pattern class

        codeView.setFocusable(false);
        codeView.setEnableLineNumber(false);
        codeView.setVerticalScrollBarEnabled(false);

        codeView.setTabLength(4);
        codeView.setEnableAutoIndentation(true);

        // If I remove this, it works on android i modified
        new PatternTools().addPattern(this, codeView);

        codeView.setText(code);
        codeView.setHighlightWhileTextChanging(false);

For information, I'm completely sure, android that I modified is also version 5.1.1

I'm just afraid when publish my app, other android 5.1.1 will have the same problem

Activity must extend AppCompatActivity

Describe the bug
Documentation does not mention the activity must extend AppCompatActivity that uses codeView

If you do not, you can't edit anything.

To Reproduce
Steps to reproduce the behavior:
use CodeView in a normal Activity, not an AppCompatActivity

Expected behavior
You should be able to use it regardsless (I guess)

Suggestions dont work

my code doesnt work

public static String[] suggestions = {"!DOCTYPE", "a", "acronym", "abbr", "address"};

ArrayAdapter adapter = new ArrayAdapter<>(this, R.layout.code_suggestions, R.id.suggestItemTextView, suggestions);
cd.setAdapter(adapter);

suggestions dont even appear

Nice Project

Great!

I also have similar project.

Implement code editor is so hard.

So, continue to refuel.

Feature request

Hello, dear developer, I want the feature of reading keywords from json and advanced highlighter like vs code. This feature is much better because it has a more open hand of the developer. To understand more, read the Textmeta document. Eclipse and vs code use this template with Thanks and using Library Gosn
Ninja coder

Line numbers bug

Describe the bug
When line numbers is tirned on:

  • There is a blank line when swiping code to the right
  • Numbers easily overlap code

To Reproduce
To reproduce the behavior, try using line numeration
I used CodeView 1.3.7 with programmatic declaration in AndroidView:

AndroidView(
            factory = { ctx ->
                com.amrdeveloper.codeview.CodeView(ctx).apply {
                    isFocusable = true
                    isEnabled = true
                    isClickable = true
                    isFocusableInTouchMode = true
                    maxWidth = context.resources.displayMetrics.widthPixels

                    setText(text, TextView.BufferType.EDITABLE)
                    setTextColor(android.graphics.Color.WHITE)
                    setTextSize(0, 64f)


                    setEnableLineNumber(true)
                    setLineNumberTextSize(64f)
                    setLineNumberTextColor(android.graphics.Color.WHITE)

                    dropDownHorizontalOffset = 0

                    setBackgroundColor(android.graphics.Color.BLACK)

                    layoutParams = LinearLayout.LayoutParams(
                        ViewGroup.LayoutParams.WRAP_CONTENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT
                    )
                    gravity = Gravity.START

                    addTextChangedListener(textWatcher)
                }
            },
)

Expected behavior
I expected line numbers to either disappear completely or not disappear at all while swiping code to the right but it does neither (see attached video).
Also, even 2-digit line number overlaps code if using same text size.
device-2023-03-27-003432.webm

Smartphone (please complete the following information):

  • Device: emulated PIxel 6

  • OS: Android 13 (API 33)

  • Device: real Xiaomi Redmi 4 Pro

  • OS: Android 6 (API 23)

Additional context
I would also like to know if it possible to let "actual" lines to go to next "visual" lines when getting out of view's bounds (something like line break). I have implemented it in Compose if that can help somehow
Tried making my own highlighter with Compose but found no way to use AnnotatedString in editable text composables.

The autocomplete and The keyboard

1.The autocomplete box is in the wrong position
2.The keyboard blocks the input box

_20220504_141800.mp4

android version:6.0.1

Codes:

MainActivity.java

`
@OverRide
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

    // Your language keywords
    String[] languageKeywords = {"hello","world"};
// List item custom layout 
     
// TextView id on your custom layout to put suggestion on it
    CodeView codeView = findViewById(R.id.codeView);
    
    codeView.setEnableLineNumber(true);
    codeView.setLineNumberTextColor(Color.GRAY);
    codeView.enablePairComplete(true);
    codeView.enablePairCompleteCenterCursor(true);
    Map<Character, Character> pairCompleteMap = new HashMap<>();
    pairCompleteMap.put('{', '}');
    pairCompleteMap.put('[', ']');
    pairCompleteMap.put('(', ')');
    pairCompleteMap.put('<', '>');
    pairCompleteMap.put('"', '"');
    codeView.setPairCompleteMap(pairCompleteMap);
    codeView.addSyntaxPattern(Pattern.compile("[0-9]+") , Color.RED);
    codeView.setLineNumberTextSize(15);
    
    
    
// Create ArrayAdapter object that contain all information
    ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.list,R.id.v_m_c, languageKeywords);
// Set the adapter on CodeView object
    codeView.setAdapter(adapter);
    
    Snackbar.make(codeView,"By Ds",Snackbar.LENGTH_SHORT).show();
}

`

activity_main.xml

`

<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

    <com.amrdeveloper.codeview.CodeView
        android:id="@+id/codeView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colo"
        android:dropDownWidth="150dp"
        android:dropDownHorizontalOffset="0dp"
        android:dropDownSelector="@color/colo"
        android:gravity="top|start" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

`

Auto pattern matching with color highliting

Is your feature request related to a problem? Please describe.
Just like any code editor, having some predefined code and colors would be great.

Describe the solution you'd like
As we can't know in which language user will write, we can save some common keywords and leave the rest (keyword he/she wants to add for highlighting) to the user to implement.

Isn't working properly!

I have added the following code in layout from the docs

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <com.amrdeveloper.codeview.CodeView
        android:id="@+id/codeView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/darkGrey"
        android:dropDownHorizontalOffset="0dp"
        android:dropDownSelector="@color/darkGrey"
        android:dropDownWidth="150dp"
	android:gravity="top|start" />

</LinearLayout>

The app looks like this
Screenshot_20220325-153948_Code Editor

Keyboard doesn't appear, no response from the app. Why is that?

Indentation for html

Describe the bug
Hi AMR, I'm using your library in my production apps, it's nice so far.

Just got nailed in indenting html, i tried for indenting but it didn't work . Would you like to explain me how to do it correctly ?

Issue with AutoIndentation (in the context of Javascript)

Hello!

I've tracked a bug back to the mKeyListener that is being used to increment currentIndentation within CodeView.java

For example, if I write the following statement:

var foo = "bar";

The key listener is tracking every space character that I type, and when a new line is created, it adds that much indentation. It's actually adding {space_char}*2 amount of indentation, because the key listener is triggered twice for each character (key_down and key_up events).

I think a better implenmentation for this key listener is required. Until this is fixed, I cannot use the auto indentation feature :(

wrap_content not working properly

I put codeview inside linear layout wrap_content and codeView height wrap_content.

<LinearLayout
    ...
    android:layout_height="wrap_content">
        <CodeView
            ...
            android:layout_height="wrap_content" />

When button clicked, my nestedscrollview will add linear layout that contain codeView.

Code inside codeView sometimes cut off.
Code view can scroll vertical but very very dificult, I should scroll horizontal then vertical.

I try to set

android:layout_height="0dp"

But my code doesn't show up.

Use nestedScrollingEnabled to false still not work

Feature request

  1. Auto wordwrap
  2. Single-line long text cannot be swiped left or right
  3. Highlight the line where the caret currently resides.
  4. Highlight Matching Delimiters ( Highlight the opening or closing delimiter when you set the caret at its pair. )

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.