Giter Club home page Giter Club logo

codeview's Introduction

#Codeview

Codeview is a android library tha lets you preview code in webview very easy and simple with highlighs and colors. With styles to chooses and language.

Also you can inject html and text into webview or any extended webview class.

This library was inspired and is working thanks to highlight.js.
App using Codeview library. https://play.google.com/store/apps/details?id=com.protectsoft.javatutorial

Usage

Codeview

#####1) Get a reference to your WebView or any extended WebView

WebView webview = (WebView) findViewById(R.id.webview);
//set settings here

#####2) Basic usage. Default style is Original, and default language is java.

//your string code 
String code = "public static void main(String[] args) { \n" +
                "\n" +
                "//comments\n" +
                "   for(int i =0; i < 10; i++) {\n" +
                "       addnum();\n" +
                "   }\n" +
                "\n" +
                "}\n";
								
Codeview.with(getApplicationContext())
		.withCode(code)
		.into(webview);

#####3) set style and language.

MyTouchWebView webview = (MyTouchWebView) findViewById(R.id.mytouchwebview);
//set settings here
//your string java code 
String code = "public static void main(String[] args) { \n" +
                "\n" +
                "//comments\n" +
                "   for(int i =0; i < 10; i++) {\n" +
                "       addnum();\n" +
                "   }\n" +
                "\n" +
                "}\n";
								
Codeview.with(getApplicationContext())
		.withCode(code)
		.setStyle(Settings.WithStyle.DARKULA)
        .setLang(Settings.Lang.JAVA)
		.into(webview);

#####4) Inject html head content and text.

WebView webview = (WebView) findViewById(R.id.webview);
//set settings here
//your string javascript code
        String code = "function Constructor(v1,v2,v3)\n" +
                "{\n" +
                "  this.v1 = v1;\n" +
                "  this.v2 = v2;\n" +
                "  this.funk = function()\n" +
                "  {\n" +
                "    console.log(\"Test: \"+ v3 );\n" +
                "  }\n" +
                "}\n" +
                "\n" +
                "var obj1 = new Constructor(\"par1\",\"par2\",\"par3\");\n" +
                "var arr = [\"w1\",\"w2\",\"w3\",obj1];\n" +
                "\n" +
                "function f2()\n" +
                "{            \n" +
                "  obj1.funk(); //works ok\n" +
                "  console.log(\"test \"+tablica[3].funk.call() ); //doesn't work\n" +
                "}";
                
                
        Codeview.with(getApplicationContext())
                .setHtmlHeadContent("<style> table,tr,td {" +
                        " border: 1px solid black;" +
                        " }" +
                        "" +
                        "</style>")
                .withHtml("<h1> h1 injected header</h1>")
                .withText("this text is always wrap inside pre tags")
                .withCode(code)
                .withHtml("<h1> h1 header after code </h1>")
                .withHtml("<table><tr><td> my html table </td></tr></table>")
                .setStyle(Settings.WithStyle.DARKSTYLE)
                .setLang(Settings.Lang.JAVASCRIPT)
                .setAutoWrap(true)
                .into(webView);

####Download

repositories {
        jcenter()
    }
    
compile 'Codeview-1.0.0:webviewcode:1.0.0' 

codeview's People

Contributors

avraampiperidis avatar

Watchers

 avatar

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.