Giter Site home page Giter Site logo

kbiakov / codeview-android Goto Github PK

View Code? Open in Web Editor NEW
858.0 19.0 106.0 1.48 MB

Display code with syntax highlighting :sparkles: in native way.

License: MIT License

Java 23.32% Python 0.59% Kotlin 76.09%
highlighting syntax-highlighting android naive-bayes-classifier java kotlin kotlin-android custom-view customview android-ui

codeview-android's Introduction

CodeView (Android)

Android Arsenal Release Build Status

CodeView helps to show code content with syntax highlighting in native way.

Description

CodeView contains 3 core parts to implement necessary logic:

  1. CodeView & related abstract adapter to provide options & customization (see below).

  2. For highlighting it uses CodeHighlighter, it highlights your code & returns formatted content. It's based on Google Prettify and their Java implementation & fork.

  3. CodeClassifier is trying to define what language is presented in the code snippet. It's built using Naive Bayes classifier upon found open-source implementation, which I rewrote in Kotlin. There is no need to work with this class directly & you must just follow instructions below. (Experimental module, may not work properly!)

Download

Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

Add the dependency:

compile 'com.github.kbiakov:CodeView-Android:1.3.2'

Usage

If you want to use code classifier to auto language recognizing just add to your Application.java:

// train classifier on app start
CodeProcessor.init(this);

Having done ones on app start you can classify language for different snippets even faster, because the algorithm needs time for training on sets for the presented listings of the languages which the library has.

Add view to your layout & bind as usual:

<io.github.kbiakov.codeview.CodeView
	android:id="@+id/code_view"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content" />
CodeView codeView = (CodeView) findViewById(R.id.code_view);

So now you can set code using implicit form:

// auto language recognition
codeView.setCode(getString(R.string.listing_js));

Or explicit (see available extensions below):

// will work faster!
codeView.setCode(getString(R.string.listing_py), "py");

Customization

When you call setCode(...) the view will be prepared with the default params if the view was not initialized before. So if you want some customization, it can be done using the options and/or adapter.

Initialization

You can initialize the view with options:

codeView.setOptions(Options.Default.get(this)
    .withLanguage("python")
    .withCode(R.string.listing_py)
    .withTheme(ColorTheme.MONOKAI));

Or using adapter (see Adapter or example for more details):

final CustomAdapter myAdapter = new CustomAdapter(this, getString(R.string.listing_md));
codeView.setAdapter(myAdapter);

Note: Each CodeView has a adapter and each adapter has options. When calling setOptions(...) or setAdapter(...) the current adapter is "flushed" with the current options. If you want to save the state and just update options saving adapter or set adapter saving options you must call updateOptions(...) or updateAdapter(...) accordingly.

Options

Options helps to easily set necessary params, such as code & language, color theme, font, format, shortcut params (max lines, note) and code line click listener. Some params are unnecessary.

When the view is initialized (options or adapter are set) you can manipulate the options in various ways:

codeView.getOptions()
    .withCode(R.string.listing_java)
    .withLanguage("java")
    .withTheme(ColorTheme.MONOKAI);

Color theme

There are some default themes (see full list below):

codeView.getOptions().setTheme(ColorTheme.SOLARIZED_LIGHT);

But you can build your own from a existing one:

ColorThemeData myTheme = ColorTheme.SOLARIZED_LIGHT.theme()
    .withBgContent(android.R.color.black)
    .withNoteColor(android.R.color.white);

codeView.getOptions().setTheme(myTheme);

Or create your own from scratch (don't forget to open PR with this stuff!):

ColorThemeData customTheme = new ColorThemeData(new SyntaxColors(...), ...);
codeView.getOptions().setTheme(customTheme);

Font

Set font for your code content:

codeView.getOptions().withFont(Font.Consolas);

Font.Consolas is a font preset (see the list of available below). To use your own font you can use similar method by providing Typeface or font path. Fonts are internally cached.

Format

Manage the space that code line take. There are 3 types: Compact, ExtraCompact and Medium. Setup is similar:

// Kotlin
codeView.getOptions().withFont(Font.Compact)
// Java
codeView.getOptions().withFont(Format.Default.getCompact());

Also you can create custom Format by providing params such as scaleFactor, lineHeight, borderHeight (above first line and below last) and fontSize.

Adapter

Sometimes you may want to take code lines under your control, and that's why you need a Adapter.

You can create your own implementation as follows:

  1. Create your model to store data, for example some MyModel class.
  2. Extend AbstractCodeAdapter<MyModel> typed by your model class.
  3. Implement necessary methods in obtained MyCodeAdapter:
// Kotlin
class MyCodeAdapter : AbstractCodeAdapter<MyModel> {
    constructor(context: Context, content: String) : super(context, content)

    override fun createFooter(context: Context, entity: MyModel, isFirst: Boolean) =
        /* init & return your view here */
}
// Java
public class MyCodeAdapter extends AbstractCodeAdapter<MyModel> {
    public CustomAdapter(@NotNull Context context, @NotNull String content) {
    	// @see params in AbstractCodeAdapter
        super(context, content, true, 10, context.getString(R.string.show_all), null);
    }

    @NotNull
    @Override
    public View createFooter(@NotNull Context context, CustomModel entity, boolean isFirst) {
        return /* your initialized view here */;
    }
}

  1. Set custom adapter to your code view:
final MyCodeAdapter adapter = new MyCodeAdapter(this, getString(R.string.listing_py));
codeView.setAdapter(diffsAdapter);

  1. Init footer entities to provide mapper from your model to view:
// it will add an addition diff to code line
adapter.addFooterEntity(16, new MyModel(getString(R.string.py_addition_16), true));
// and this a deletion diff
adapter.addFooterEntity(11, new MyModel(getString(R.string.py_deletion_11), false));

  1. You can also add a multiple diff entities:
AbstractCodeAdapter<MyModel>.addFooterEntities(HashMap<Int, List<MyModel>> myEntities)

Here you must provide a map from code line numbers (started from 0) to list of line entities. It will be mapped by adapter to specified footer views.

See Github diff as example of my "best practice" implementation.

How it looks in app

See example.

CodeView_Android_Solarized_light

List of available languages & their extensions

C/C++/Objective-C ("c", "cc", "cpp", "cxx", "cyc", "m"), C# ("cs"), Java ("java"), Bash ("bash", "bsh", "csh", "sh"), Python ("cv", "py", "python"), Perl ("perl", "pl", "pm"), Ruby ("rb", "ruby"), JavaScript ("javascript", "js"), CoffeeScript ("coffee"), Rust ("rc", "rs", "rust"), Appollo ("apollo", "agc", "aea"), Basic ("basic", "cbm"), Clojure ("clj"), Css ("css"), Dart ("dart"), Erlang ("erlang", "erl"), Go ("go"), Haskell ("hs"), Lisp ("cl", "el", "lisp", "lsp", "scm", "ss", "rkt"), Llvm ("llvm", "ll"), Lua ("lua"), Matlab ("matlab"), ML (OCaml, SML, F#, etc) ("fs", "ml"), Mumps ("mumps"), N ("n", "nemerle"), Pascal ("pascal"), R ("r", "s", "R", "S", "Splus"), Rd ("Rd", "rd"), Scala ("scala"), SQL ("sql"), Tex ("latex", "tex"), VB ("vb", "vbs"), VHDL ("vhdl", "vhd"), Tcl ("tcl"), Wiki ("wiki.meta"), XQuery ("xq", "xquery"), YAML ("yaml", "yml"), Markdown ("md", "markdown"), formats ("json", "xml", "proto"), "regex"

Didn't found yours? Please, open issue to show your interest & I'll try to add this language in next releases.

List of available themes

List of available fonts

  • Consolas
  • CourierNew
  • DejaVuSansMono
  • DroidSansMonoSlashed
  • Inconsolata
  • Monaco

Used by

List of apps on Play Store where this library used. Ping me if you want to be here too!

Icon Application
GeekBrains
Codify - Codes On The Go
C Programming - 200+ Offline Tutorial and Examples
Awesome Android - UI Libraries
GitJourney for GitHub
Source Code - Lập Trình

Contribute

  1. You can add your theme (see ColorTheme class). Try to add some classic color themes or create your own if it looks cool. You can find many of them in different open-source text editors.
  2. If you are strong in regex, add missed language as shown here. You can find existing regex for some language in different sources of libraries, which plays the same role.
  3. Various adapters also welcome.

Author

License MIT

Copyright (c) 2016 Kirill Biakov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

codeview-android's People

Contributors

kbiakov 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar

codeview-android's Issues

code show in one line

CodeView codeView = (CodeView) findViewById(R.id.code_view);

    codeView.setVerticalFadingEdgeEnabled(true);
    codeView.highlightCode("java")
            .setColorTheme(ColorTheme.SOLARIZED_LIGHT)
            .setCodeContent(getString(R.string.code));

Disable blink animation on refresh of codeview

How do I disable blink animation when a codeview is reset.
programCodeView.setOptions(Options.Default.get(getContext()) .withLanguage(programLanguage) .withCode(programLines) .withTheme(ColorTheme.MONOKAI));

This code is used to set program lines to the code view, there's a blink which happens at this point. Can it be disabled?

Support editing

Would it be possible to support editing? As in writing code while it highlights like an IDE?

Not able to increase font size !

Really not able to find how to increase font size ! can you please write a line of code using
codeview to increase font size !

App Crashed

Process: io.github.kbiakov.codeviewexample, PID: 11381 java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder{d21dbb8 position=22 id=-1, oldPos=-1, pLpos:-1 scrap [attachedScrap] tmpDetached not recyclable(1) no parent} ' @Override' android.support.v7.widget.RecyclerView{8d75bf2 VFED..... .F....ID 0,0-836,1034 #7f07005a app:id/rv_code_content}, adapter:io.github.kbiakov.codeview.adapters.CodeWithNotesAdapter@a88fd7d, layout:android.support.v7.widget.LinearLayoutManager@53e3472, context:io.github.kbiakov.codeviewexample.ListingsActivity@1216248 at android.support.v7.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:5715) at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5898) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5858) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5854) at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2230) at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1557) at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1517) at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:612) at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3924) at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:3336) at android.view.View.measure(View.java:19147) at io.github.kbiakov.codeview.views.BidirectionalScrollView.measureChildWithMargins(BidirectionalScrollView.kt:82) at android.widget.FrameLayout.onMeasure(FrameLayout.java:223) at android.widget.HorizontalScrollView.onMeasure(HorizontalScrollView.java:315) at android.view.View.measure(View.java:19147) at android.widget.RelativeLayout.measureChild(RelativeLayout.java:786) at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:560) at android.view.View.measure(View.java:19147) at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:825) at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:511) at android.view.View.measure(View.java:19147) at android.widget.RelativeLayout.measureChild(RelativeLayout.java:786) at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:560) at android.view.View.measure(View.java:19147) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6113) at android.widget.FrameLayout.onMeasure(FrameLayout.java:223) at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143) at android.view.View.measure(View.java:19147) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6113) at android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:401) at android.view.View.measure(View.java:19147) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6113) at android.widget.FrameLayout.onMeasure(FrameLayout.java:223) at android.view.View.measure(View.java:19147) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6113) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1723) at android.widget.LinearLayout.measureVertical(LinearLayout.java:788) at android.widget.LinearLayout.onMeasure(LinearLayout.java:648) at android.view.View.measure(View.java:19147) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6113) at android.widget.FrameLayout.onMeasure(FrameLayout.java:223) at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2694) at android.view.View.measure(View.java:19147) at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2481) at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1440) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1694) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1321)

Editing code

Hello! Thanks for this very nice library!
I have a small question, does CodeView have an editing mode? If so how can I enable it?
Thanks

Update Syntax Highlights

Please provide this List of Syntax Highlights

    _1C("1c"),
    ABNF("abnf"),
    ACCESS_LOG("accesslog"),
    ACTIONSCRIPT("actionscript"),
    ADA("ada"),
    APACHE("apache"),
    APPLESCRIPT("applescript"),
    ARDUINO("arduino"),
    ARM_ASSEMBLY("armasm"),
    ASCII_DOC("asciidoc"),
    ASPECTJ("aspectj"),
    AUTOHOTKEY("autohotkey"),
    AUTOIT("autoit"),
    AVR_ASSEMBLER("avrasm"),
    AWK("awk"),
    AXAPTA("axapta"),
    BASH("bash"),
    BASIC("basic"),
    BNF("bnf"),
    BRAINFUCK("brainfuck"),
    C_AL("cal"),
    CAP_N_PROTO("capnproto"),
    CEYLON("ceylon"),
    CLEAN("clean"),
    CLOJURE("clojure"),
    CLOJURE_REPL("clojure_repl"),
    CMAKE("cmake"),
    COFFEESCRIPT("coffeescript"),
    COQ("coq"),
    CACHE_OBJECT_SCRIPT("cos"),
    CPP("cpp"),
    CRMSH("crmsh"),
    CRYSTAL("crystal"),
    C_SHARP("cs"),
    CSP("csp"),
    CSS("css"),
    D("d"),
    DART("dart"),
    DELPHI("delphi"),
    DIFF("diff"),
    DJANGO("django"),
    DNS("dns"),
    DOCKERFILE("dockerfile"),
    DOS("dos"),
    DSCONFIG("dsconfig"),
    DEVICE_TREE("dts"),
    DUST("dust"),
    EBNF("ebnf"),
    ELIXIR("elixir"),
    ELM("elm"),
    ERB("erb"),
    ERLANG("erlang"),
    ERLANG_REPL("erlang_repl"),
    EXCEL("excel"),
    FIX("fix"),
    FLIX("flix"),
    FORTRAN("fortran"),
    F_SHARP("fsharp"),
    GAMS("gams"),
    GAUSS("gauss"),
    GCODE("gcode"),
    GHERKIN("gherkin"),
    GLSL("glsl"),
    GO("go"),
    GOLO("golo"),
    GRADLE("gradle"),
    GROOVY("groovy"),
    HAML("haml"),
    HANDLEBARS("handlebars"),
    HASKELL("haskell"),
    HAXE("haxe"),
    HSP("hsp"),
    HTML("html"),
    HTMLBARS("htmlbars"),
    HTTP("http"),
    HY("hy"),
    INFORM_7("inform7"),
    INI("ini"),
    IRPF90("irpf90"),
    JAVA("java"),
    JAVASCRIPT("javascript"),
    JBOSS_CLI("jboss-cli"),
    JSON("json"),
    JULIA("julia"),
    KOTLIN("kotlin"),
    LASSO("lasso"),
    LDIF("ldif"),
    LEAF("leaf"),
    LESS("less"),
    LISP("lisp"),
    LIVECODESERVER("livecodeserver"),
    LIVESCRIPT("livescript"),
    LLVM("llvm"),
    LSL("lsl"),
    LUA("lua"),
    MAKEFILE("makefile"),
    MARKDOWN("markdown"),
    MATHEMATICA("mathematica"),
    MATLAB("matlab"),
    MAXIMA("maxima"),
    MEL("mel"),
    MERCURY("mercury"),
    MIPS_ASSEMBLY("mipsasm"),
    MIZAR("mizar"),
    MOJOLICIOUS("mojolicious"),
    MONKEY("monkey"),
    MOONSCRIPT("moonscript"),
    N1QL("n1ql"),
    NGINX("nginx"),
    NIMROD("nimrod"),
    NIX("nix"),
    NSIS("nsis"),
    OBJECTIVE_C("objectivec"),
    OCAML("ocaml"),
    OPENSCAD("openscad"),
    OXYGENE("oxygene"),
    PARSER3("parser3"),
    PERL("perl"),
    PF("pf"),
    PHP("php"),
    PONY("pony"),
    POWERSHELL("powershell"),
    PROCESSING("processing"),
    PROFILE("profile"),
    PROLOG("prolog"),
    PROTOCOL_BUFFERS("protobuf"),
    PUPPET("puppet"),
    PURE_BASIC("purebasic"),
    PYTHON("python"),
    Q("q"),
    QML("qml"),
    R("r"),
    RIB("rib"),
    ROBOCONF("roboconf"),
    ROUTEROS("routeros"),
    RSL("rsl"),
    RUBY("ruby"),
    ORACLE_RULES_LANGUAGE("ruleslanguage"),
    RUST("rust"),
    SCALA("scala"),
    SCHEME("scheme"),
    SCILAB("scilab"),
    SCSS("scss"),
    SHELL("shell"),
    SMALI("smali"),
    SMALLTALK("smalltalk"),
    SML("sml"),
    SQF("sqf"),
    SQL("sql"),
    STAN("stan"),
    STATA("stata"),
    STEP21("step21"),
    STYLUS("stylus"),
    SUBUNIT("subunit"),
    SWIFT("swift"),
    TAGGERSCRIPT("taggerscript"),
    TAP("tap"),
    TCL("tcl"),
    TEX("tex"),
    THRIFT("thrift"),
    TP("tp"),
    TWIG("twig"),
    TYPESCRIPT("typescript"),
    VALA("vala"),
    VB_NET("vbnet"),
    VBSCRIPT("vbscript"),
    VBSCRIPT_HTML("vbscript_html"),
    VERILOG("verilog"),
    VHDL("vhdl"),
    VIM("vim"),
    X86_ASSEMBLY("x86asm"),
    XL("xl"),
    XML("xml"),
    XQUERY("xquery"),
    YAML("yaml"),
    ZEPHIR("zephir")

I know that you have already added some of these languages ​​but some (important) ones are missing

CodeView inside NestedScrollView scroll issue

when I put the codeview in the nestedScrollView ,in the area of the codeview,the scroll of the nestedScrollView is not work,I guess it beacuse the codeview comsume the touchevent, so I override the onInterceptTouchEvent of the NestedScrollView, make it always return true,then its scroll works,but the codeView cant scroll hehorizontally... so how to make it work correct?

Project versions out-of-date

Hello there,

after improting this project into my IDE, it was screaming towards me the project is using various outdated dependency resources. Only after updating all of them I was able to build the project properly.

In particular I had to update all build.gradle files as well as the gradle-wrapper.properties file in order to make the project build again in Android Studio.
So before opening a pull-request straight away to fix those issues I wanted to make sure if there is not any particular reason not to update all that stuff?

Code selection.

How can the code inside this view be made user selectable?

Scrolling issue

i am using codeview in my recylcer view adapter. it work fine but when i am focus in codeview and scroll horizontal after my recycler view not scrolling. any solution please ?

How wrap code to next line?

I need to put codeview in a scrolling element, but because of this issue I can't so I'm trying to figure out a workaround by disabling clickable on the codeview, but then I can't have code that isn't visible because it's off screen.

For me, it's okay if the code isn't clickable/scrollable/selectable. Is there a way to wrap code to the next line?

Add newline "\n" in every end of line

Is there any solution that adds "\n" in every end of a line? Or any other way that can manage pure code of any programming language without adding "\n" in every line.
Thanks 👍

RecycleView Inconsistency detected bug

hi, this library also has the bug like this: https://stackoverflow.com/questions/31759171/recyclerview-and-java-lang-indexoutofboundsexception-inconsistency-detected-in

i have try to solve it, but finally i can not make the library work perfect.

04-27 16:24:56.512 20163-20163/? E/AndroidRuntime: FATAL EXCEPTION: main Process: io.github.kbiakov.codeviewexample, PID: 20163 java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 31(offset:31).state:40 at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5504) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5440) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5436) at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2224) at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1551) at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1511) at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:595) at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3583) at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:3025) at android.view.View.measure(View.java:22216) at io.github.kbiakov.codeview.views.BidirectionalScrollView.measureChildWithMargins(BidirectionalScrollView.kt:77) at android.widget.FrameLayout.onMeasure(FrameLayout.java:185) at android.widget.HorizontalScrollView.onMeasure(HorizontalScrollView.java:323) at android.view.View.measure(View.java:22216) at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715) at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461) at android.view.View.measure(View.java:22216) at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715) at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461) at android.view.View.measure(View.java:22216) at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715) at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461) at android.view.View.measure(View.java:22216) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6671) at android.widget.FrameLayout.onMeasure(FrameLayout.java:185) at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139) at android.view.View.measure(View.java:22216) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6671) at android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:393) at android.view.View.measure(View.java:22216) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6671) at android.widget.FrameLayout.onMeasure(FrameLayout.java:185) at android.view.View.measure(View.java:22216) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6671) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1539) at android.widget.LinearLayout.measureVertical(LinearLayout.java:823) at android.widget.LinearLayout.onMeasure(LinearLayout.java:702) at android.view.View.measure(View.java:22216) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6671) at android.widget.FrameLayout.onMeasure(FrameLayout.java:185) at com.android.internal.policy.DecorView.onMeasure(DecorView.java:830) at android.view.View.measure(View.java:22216) at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2571) at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1628) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1882) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1512) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7215) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:981) at android.view.Choreographer.doCallbacks(Choreographer.java:790) at android.view.Choreographer.doFrame(Choreographer.java:721) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:967) at android.os.Handler.handleCallback(Handler.java:808) at android.os.Handler.dispatchMessage(Handler.java:101) at android.os.Looper.loop(Looper.java:166) at android.app.ActivityThread.main(ActivityThread.java:7415) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)

Custom Theme Creation

Hi!,
I am trying to create a custom theme from DEFAULT theme but nothing changes.

This is my method that sets the codeview up.

public void setUpCodeView() {

        codeView = findViewById(R.id.code_view);

        int colorAccent = getResources().getColor(R.color.colorAccent);
        int colorPrimary = getResources().getColor(R.color.colorPrimary);

        int colorPrimaryDark = getResources().getColor(R.color.colorPrimaryDark);
        int colorTitles= getResources().getColor(R.color.colorTitles);
        int colorBodies= getResources().getColor(R.color.colorBodies);

        SyntaxColors syntaxColors = new SyntaxColors(
                colorAccent, colorAccent, colorBodies, colorPrimaryDark,
                colorTitles, colorTitles, colorBodies, colorBodies,
                colorTitles, colorTitles, colorBodies
        );

        ColorThemeData myTheme = ColorTheme.DEFAULT.theme()
                .withSyntaxColors(syntaxColors);

        codeView.setOptions(Options.Default.get(this)
                .withTheme(myTheme)
                .withFont(Objects.requireNonNull(ResourcesCompat.getFont(this,
                        R.font.nunito))));
    }

And this is the line where I set code to the codeView

codeView.setCode(myText, "py");

The text appears but there is no code highlight and theme doesnt change.

Ty for help!.

Update dependencies

Use

implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha01'

instead of

compile "com.android.support:appcompat-v7:$supportLibrary"
compile "com.android.support:recyclerview-v7:$supportLibrary"

Customize adapter

It will be really great if we can set something depending on lines.

For example: at Gitskarios i'm gonna use this lib to show content, and commits diff, so sometimes i need to add comments in a line

Editable code view

This can be a new enhancement .. instead of text view this can be made as editable text so that user can use this as code editor

Listener should return line text

For example:

codeView.setCodeListener(new OnCodeLineClickListener() {
      @Override public void onCodeLineClicked(int n, String line) {
       // your logic here 
    }
});

That's because if we only get the position, we should split lines in a different, and maybe we don't do equals than the library does

when i am fetching the string of formatted code from Firebase Realtime database the code showing in a single line.

###DetailActivity.xml
``

<TextView
    android:id="@+id/textViewrv1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginTop="40dp"
    android:layout_marginEnd="8dp"
    android:layout_marginRight="8dp"
    android:text="program name sample as login  to firebase"
    android:layout_centerHorizontal="true"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<!-- CODEVIEW  program-->
<RelativeLayout
    android:layout_below="@+id/textViewrv1"
    android:layout_width="match_parent"
    android:layout_marginTop="10dp"
    android:orientation="vertical"
    android:layout_height="match_parent">


   <io.github.kbiakov.codeview.CodeView
       android:id="@+id/code_view_text"
       android:layout_width="match_parent"
       android:layout_height="match_parent"></io.github.kbiakov.codeview.CodeView>
</RelativeLayout>

DetailActivity.java

package com.rajendra.firebaseproject.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import com.rajendra.firebaseproject.R;
import io.github.kbiakov.codeview.CodeView;
import io.github.kbiakov.codeview.adapters.Options;
import io.github.kbiakov.codeview.classifier.CodeProcessor;
import io.github.kbiakov.codeview.highlight.ColorTheme;
public class DetailActivity extends AppCompatActivity {

String pname,pcontent;
TextView rvpname;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_detail);
    pname = getIntent().getExtras().getString("sendPNAME");
    pcontent = getIntent().getExtras().getString("sendPCONTENT");
    rvpname =findViewById(R.id.textViewrv1);
    rvpname.setText(pname);
    CodeProcessor.init(this);
    CodeView codeView = (CodeView) findViewById(R.id.code_view_text);
    //codeView.setCode(pcontent, "c");

    codeView.setOptions(Options.Default.get(this)
            .withLanguage("c")
            .withCode(pcontent)
            .withTheme(ColorTheme.MONOKAI));


}

}

but the ans is showing like this screenshots :

image

adds 1 MB to APK size

When including the library, a folder assets/training-set is visible in the decompiled APK (Build>Analyze Apk) which is contributing 1 Mb to the APK size.

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.