Import Aliases
An import alias is basically an alias that will be used to import many packages (and eventually enums), in one commands. Here is the list of import aliases
- hyperpoetto import packages from my Http Client Library
- gmageto import packages from my Image Processing library
- jsoupto import packages from Jsoup
- timeunitto import enums from java TimeUit class
- timeto import dates Java classes
- jsonto import packages from- groovy.json
- xmlto import packages from- groovy.xml
- chartto import classes from the chart library, wrapper of MPAndroidChart
- bitmapto import classes from Android SDK Bitmap
To use one, simply import it like you would import any package:
import gmage
An import alias can have a script that runs when imported to (for example) add some functions in some objects, by using Groovy meta-programming
Here are some example of codes with added functions for some import aliases
Bitmap
You can use android Bitmap class to manipulate images
import bitmap
f = file("image.png")
b = f.toBitmap()
b = b.scaled(105,105)
// default format is PNG
b.writeInto(file("result.png"))
b.writeInto(file("result.png"), JPEG)
Example:
import hyperpoet
API_URL = "https://jsonplaceholder.typicode.com/"
client = new HttpPoet(url: API_URL, contentType: ContentType.JSON, acceptContentType: ContentType.JSON)
data = client.get("/posts")
println data.title