HighlightJs View


Source link: https://github.com/PDDStudio/highlightjs-android

HighlightJs View - Android

A syntax highlighting view, powered by highlight.js, for Android.

Demo Application

The demo application shows a simple example usage for this library. It lists the files of this repository's commits and allows you to browse the changed files. Selecting a file show's up the syntax highlighted content.

Screenshot

Download

You can download the sample apk in the release section

Getting Started

Add the library as dependency

Add the library as dependency to your build.gradle file.

dependencies {
  //other dependencies...  compile 'com.pddstudio:highlightjs-android:X.X.X' 
}

Replace X.X.X with the current version - which can be found in the release section

Include the View into your Layout

Add the View to your existing layout file.

<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

<!-- Other views here -->

<com.pddstudio.highlightjs.HighlightJsView  android:id="@+id/highlight_view"

android:layout_width="match_parent"

android:layout_height="match_parent" />

<!-- Other views here -->  </RelativeLayout>

Assign the view and set it's content

In your Activity/Fragment assign the view and set it's content.

@Override
  protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_syntax);

//other stuff here ....

 //find and instantiate the view

highlightJsView = (HighlightJsView) findViewById(R.id.highlight_view);

 //optional: register callbacks and style the view

 //register theme change listener

highlightJsView.setOnThemeChangedListener(this);

//change theme and set language to auto detect

highlightJsView.setTheme(Theme.ANDROID_STUDIO);

highlightJsView.setHighlightLanguage(Language.AUTO_DETECT);

//load the source (can be loaded by String, File or URL)

highlightJsView.setSource(fileObject.getUrl());

  
}

Customize the View

For a complete overview of all themes and languages you can check out the official highlight.js demo here

You can customize the View's Theme and Language. By default the Theme is set to Theme.DEFAULT and the language is set to Language.AUTO_DETECT

Change the view's theme:

//change theme highlightJsView.setTheme(Theme.ANDROID_STUDIO);

The library supports all themes that are included in highlight.js version 9.10.0

Browse the list of themes here

Change the view's language:

//change language highlightJsView.setHighlightLanguage(Language.JAVA);

The library supports all languages that are included in highlight.js version 9.10.0 (more than +130 languages)

Browse the list of languages here

Enable or disable support for zooming:

//enable or disable zooming support for HighlightJsView //note: in case you change this during runtime don't forget to //call highlightJsView.reload();
 for the changes to apply! highlightJsView.setZoomSupportEnabled(true);

Enable or disable line numbers:

//enable or disable line numbers on the left side of the source //note: in case you change this during runtime don't forget to //call highlightJsView.reload();
 for the changes to apply! highlightJsView.setShowLineNumbers(enableLineNumbers);

By default Highlight.js does not support line numbers. However, thanks to wcoder and all the hard work that was put into highlightjs-line-numbers.js. This made it easy for me to port and include this functionality into this library.

Change the view's source

You can load the source you want to be highlighted by either a String containing the actual source code, a File object which represents the file containing the source code or an URL object to load the source code from a remote Url.

try {
  markdownUrl = new URL("https://raw.githubusercontent.com/PDDStudio/highlightjs-android/master/README.md");
 
}
 catch (Exception e) {
  e.printStackTrace();
 
}
 //change the displayed source highlightJsView.setSource(markdownUrl);
 //make sure to call reload() when changing content during runtime highlightJsView.reload();

Notes:

  • Source Code which is loaded via URL requires internet permission (source is loaded asynchronous) <uses-permission android:name="android.permission.INTERNET" />
  • Source Code which is loaded by a File object from the device's internal storage requires storage permission (especially on +Android 6.0)

About & Contact

License


 Copyright 2016 Patrick J

Licensed under the Apache License, Version 2.0 (the "License");

  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
Copyright (c) 2006, Ivan Sagalaev  All rights reserved.  Redistribution and use in source and binary forms, with or without  modification, are permitted provided that the following conditions are met:

 * Redistributions of source code must retain the above copyright

  notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright

  notice, this list of conditions and the following disclaimer in the

  documentation and/or other materials provided with the distribution.

* Neither the name of highlight.js nor the names of its contributors

  may be used to endorse or promote products derived from this software

  without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE  DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 

Resources

A simple to use networking library that makes it easy to retrieve data from REST APIs. Also provides a mock function to build/test your app without actually making the http request.

Features:

  • Supports GET/POST/PUT/DELETE (for now)
  • Supports file downloads and uploads (with progress callbacks)
  • Supports http post data (json, multipart, url-encoded, plain text, xml)
  • Simple OAuth logins using password resource flow
  • Queued requests
  • Global and per request mocking
  • Built in deserialization for JSON (using gson)
  • Automatically handles redirects

This library will help developers to show Image from url and to provide zooming, panning functionalities. This simple ImageView will easily fit in ListView / RecyclerView / Activity / Fragment etc.

Andcre (android creator) is a python script to create professional and ready to use Android projects

A custom view class to enter a four digit code used in cases of authentication.

A powerful force update library for Android.

You can set Version of your app remote and show dialog to force update your app whenever you want.

The bare bone pipeline infrastructure required for using google's android vision detectors. Most of the source codes were extracted from Google's android vision sample.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes