karamba
A collection of useful Kotlin extension for Android
Install
Add to gradle in allprojects
maven { url 'https://jitpack.io' }
then add this
compile 'com.github.matteocrippa:karamba:1.2.0'
Usage
Karamba
provides you a list of different and useful extensions for your project, here the list organized by the type extended.
General
support(apiVersion)
, lambda that allow you to run code only if current SDK is up to specified onesupportKitkat()
, lambda that checks if kitkat is supported and run the codesupportLollipop()
, lambda that checks if lollipop is supported and run the code
Bitmap
base64()
, produces a base64 representation of the current bitmapresize(height, width)
, resize the current bitmap to new format
Boolean
toggle()
, handle the bool as a toogle changing the value to opposite one, then the new value is returned (not yet possible to change this)random()
, returns a random boolean value, then the new value is returned (not yet possible to change this)
Date
convertTo(format)
, converts current date to a custom format provided as argument (eg.dd-MM-yy HH:mm
)toCalendar()
, converts current date toCalendar
isFuture()
, returns true if date is in the futureisPast()
, returns true if date is in the pastisToday()
, returns if current date is todayisTomorrow()
, returns if current date is tomorrowisYesterday()
, returns if current date is yesterdaytoday()
, returns today's datetomorrow()
, returns tomorrow's dateyesterday()
, returns yesterday's datehour()
, returns current date hour as numberminute()
, returns current date minutes as numbersecond()
, returns current date seconds as numbermonth()
, returns current date month as numbermonthName()
, returns current date month as long nameyear()
, returns current date year as numberday()
, returns current date day as numberdayOfWeek()
, returns current date day of the week as numberdayOfWeekName()
, returns current date weekday as stringdayOfYear()
, returns current date day of year as number
Double
localCurrency(currency)
, converts current double to the currency format passed as argument (eg.EUR
)celsiusToFahrenheit()
, converts current double to fahrenheitfahrenheitToCelsius()
, converts current double to celsius
Drawable
toBitmap()
, converts the current drawable inBitmap
Int
readableDistanceFromMeters()
, converts an int amount of meters in a readable meter, kilometers distancecommaSeparatedId()
, converts an array of int, in a string of comma separated itemsrandom()
, provides a random number in the range provided (eg.(0..10).random()
)
String
isValidEmail()
, returns if current string is a valid emailisUrl()
, returns if current string is a valid urlisNumeric()
, returns if current string contains a numberisPhoneNumber()
, returns if current string contains a phone numberrandom(lenght)
, returns a random string of provided lengthtoBitmap()
, convert current base64 string into Bitmapellipsize(chars)
, ellipsizes the current string, truncating at defined amount of characterstoDate(format)
, converts current string in aDate
object using the provided formatplainText()
, removes all html formatting from current stringtoCamelCase()
, camel case the current string current string
View
toBitmap()
, converts current view intoBitmap
Credits
Icon is taken by free emojii set by Vincent Le Moign