NinePatchChunk

This is a simple Android library which allows you to create a chunk for NinePatchDrawable at runtime. So you are able to load 9.png images, for example, from assets of your application or from other source.
The solution based on this implementation from Android Open Source Project.
Additional information about 9-patch chunk structure you can find here.


Usage

The main class of the library is NinePatchChunk.

Global constants:

public static final int NO_COLOR = 0x00000001; - The 9 patch segment is not a solid color.
public static final int TRANSPARENT_COLOR = 0x00000000; - The 9 patch segment is completely transparent.

Firstly let's go through the fields of the class object you would use.

The class has only one object-dependent method:

Also NinePatchChunk class has some static methods. Let's go through them.

And finally, Div object description. This object is used to define stretchable areas:

  • int start - the starting pixel of stretchable area. The count starts from 0.
  • int stop - the ending pixel of stretchable area. This pixel is right after the latest Color.BLACK pixel of the stretchable area.

Building from sources

NinePatchChunk is a library which delivers as open source project.
As build tool it uses Gradle build system.

In order to build the library you need this environment installed:

  • Java JDK 6
  • Android SDK with build tools version 18.1.1

For success build this environment variables should be defined in your system:

  • JAVA_HOME - will point to your JDK location
  • ANDROID_HOME - will point to Android SDK location

For the next step go to command line and then go to location where NinePatchChunk library sources are stored
cd /NinePatchChunk (where gradlew script file stored)

From this point in order to get output files you just need to run this command from command line:
gradlew assemble to build release and debug aar files
gradlew assembleDebug to build debug aar file only
gradlew assembleRelease to build release aar file only

That's it. So now you can find the output files inside this folder:
NinePatchChunk\NinePatchChunkLib\build\libs


This is it. The using is simple as that. See the java doc to learn more.
If you have some additional question - feel free to contact me.

Thanks!