Sharp


Source link: https://github.com/Pixplicity/sharp

Sharp

Sharp is a Scalable Vector Graphics (SVG) implementation for Android. It facilitates loading vector graphics as SharpDrawables, and can effectively be used wherever a conventional image would be displayed, whether it be as a background, ImageView source, inside a StateListDrawable or used as composites in a TextView.

Forked from:
https://github.com/pents90/svg-android

Merged changes from forks:
https://github.com/b2renger/svg-android
https://github.com/mindon/svg-android
https://github.com/josefpavlik/svg-android

Download

Download the latest AAR or grab from Bintray using Gradle:

dependencies {

  compile 'com.pixplicity.sharp:library:[VERSION_HERE]' 
}
 

Important: Specify the latest version from Bintray as [VERSION_HERE].

Sample

A sample is included in this repository.

It's easy to load an SVG:

Sharp.loadResource(getResources(), R.raw.cartman)

.into(mImageView);
 

SVGs can be loaded from various sources:

  • loadAsset(AssetManager, String) loads SVG data from an Android application asset;
  • loadResource(Resources, int) loads SVG data from an Android application resource;
  • loadString(String) loads SVG data directly from a String;
  • loadInputStream(InputStream) loads SVG data from an InputStream (but it's your responsibility to close it afterwards);
  • loadFile(File) loads SVG data from a File, internally opening and closing a FileInputStream to do so.
  • loadPath(String) loads SVG data directly from a String (but uses a lot of memory doing so).

Sharp facilitates the application of the resulting drawable as well, through the following methods:

  • into(View) takes care of loading the SVG into the source of the ImageView, or setting the background if the view is not an ImageView;
  • getDrawable(View) generates a SharpDrawable, which is a subclass of PictureDrawable that respects the SharpPicture boundaries.
  • getDrawable(View, DrawableCallback) does the same, but on a background thread with callbacks of DrawableCallback;
  • getSharpPicture() generates a SharpPicture, a wrapper containing a Picture and the SVG bounds and limits;
  • getSharpPicture(PictureCallback) does the same, but on a background thread with callbacks of PictureCallback;
  • withAssets(AssetManager) provides access to your application's assets, allowing Sharp to read typefaces;

It's recommended to use into(View) or getDrawable(View), as the View parameter takes care of setting the view's layer type to View.LAYER_TYPE_SOFTWARE.

Typefaces

By loading an SVG from the assets directory using loadAsset(AssetManager, String), or by loading it through a different mechanism and providing access to your application's assets using withAssets(AssetManager), Sharp can read typeface files automatically from the assets directory.

Sharp expects the typeface to be present as:

/assets/fonts/[typeface name].ttf 

If your font does not appear, check Logcat for any insightful error messages.

Why isn't my SVG appearing?

If you're setting your view's drawable manually, instead of using into() or intoBackground(), be sure to set the view's layer type to View.LAYER_TYPE_SOFTWARE.

Why no hardware acceleration?

Excellent question! Aside from the fact that PictureDrawable doesn't render correctly, paths do not efficiently render in hardware acceleration. Even if it worked, it would have poor performance. Read this excellent discussion about why this is, if you're interested.

You don't need to disable hardware acceleration on your entire application. Only individual views need to have the layer type changed, and providing your view into SharpPicture.getDrawable(View) takes care of this for you.

Known issues

  1. Text size and position isn't accurate. It's recommended to convert all text to paths in order for it to appear pixel-perfect.
  2. Android's Gradle plugin 2.0.0 (in the preview channel as of January 2016) no longer allows you to place SVG files in /res/drawable. We recommend placing them in /res/raw (or /assets and using loadAsset()) instead.

License

Licensed under the Apache license 2.0.

Resources

A library that allows you to use a CursorAdapter as the underlying data source for a RecyclerView.Adapter so that it can be used with a CursorLoader as was previously possible using the ListView.

An implementation of the "Bottom Navigation" component from Google Material Design spec.

A fast dependency injector for Android and Java. Kinject has been thought to get the following objectives:

  • Ease to configure.
  • Clean way to satisfy dependencies.
  • High performance without lose flexibility.
  • Integration little intrusive and easily abstractable.
  • Dependencies graph validation in compilation time.
  • Based on code generation.
  • Proguard friendly.

This library provides support to generate Google Material Design colored lists.

PaceholderJ is a simple Android library created to help you handle easily with screens of empty list, no items found, loading and error.

Shade Melange is a library that contains a colour palette with a wide range of pre-defined colours with their names. The implementation of the grid has been done using RecyclerView for memory efficient performance.

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