AmniXTension
A Kotlin extensions + Utils library with Bunch of Help inbuild.
Documentation | FileTree | FAQ's | RoadMap | Demo | Suggestion | Bugs
AmniXTension = AmniX's Tension Which Means No Tension to Developers, AmniXTension is Here.
AmniXTension is On Jcenter, Simply implementat the library and simplify Your Life
dependencies {
implementation 'com.amnix.xtension:AmniXtension:x.x.x'
}
Demo
Wanna See Some Demo? Few are mention, Many to explore.
Things Are Collapsed. You need to Expand them ;)
Extensions:-
Global Extensions
Global Extensions Means You can Use them Anywhere
async{
// Some Code Which Will Run in a Worker Thread
// Caution : Make sure you don't do some context related stuff in async, It may cause an memory leak
}
asyncAwait({
// Some Code Which Will Run in a Worker Thread
// Caution : Make sure you don't do some context related stuff in async, It may cause an memory leak
result // Keep the Result in Last Line, You Will Receive it in Await Block Magically.
},{result->
// Some Code Will be Executed After Async Block
// You Will Receive Result Passed From Async Block Last line
})
OR
asyncAwait<Bitmap>({bitmap->
// Some Code Which Will Run in a Worker Thread
// Caution : Make sure you don't do some context related stuff in async, It may cause an memory leak
result // Keep the Result in Last Line, You Will Receive it in Await Block Magically.
},{result->
// Some Code Will be Executed After Async Block
// You Will Receive Result Passed From Async Block Last line
})
tryOrIgnore{
// Code Here Which Can be throw Exception but App Won't Crash At All
}
object.castTo(Object::class) // Cast Object inline and Supports Code Chaining.
OR
object.castAs(Object::class) // Cast Object inline and Supports Code Chaining.
tryAndCatch({
// Try Code
},{
// catch Exception
},{
// Optional Finally Block
})
if(guardRun{
//Run Code in Guarded Way
}){
//Code There If Above Code Executed Without Any Exception
}
object.ifIs(otherObject){
// Run Code if above Object is equal to other Object.
It does Simply Replace below code
if(object == otherObject){
//Your Code
}
}
object.ifIsNot(otherObject){
// Run Code if above Object is equal to other Object.
It does Simply Replace below code
if(object != otherObject){
//Your Code
}
}
closeSafely(inputStream, outputStream) // Clode Streams Safely and prevent any memory leak
if(isDeviceRooted()){
// Alert User that Few Features are disable Because You have Rooted Device
}
val date = currentDate()
runOnUiThread{
// Run Your Code On UI thread Without the Activity Object
}
putInMemory("key",value) // Put Anything In Memory For Later Use
val value = getFromMemory("key") // Get Your Saved Value from Memory
BoilerPlate Extensions
surfaceView.setupCamera{
it.startPreview()
}
textureView.setupCamera{
it.startPreview()
}
Activity Extensions
requestPermission(Manifest.permission.CAMERA){
//No need to check if the Permission Grated Already Or Not, We Will do it for you. Just Place the code in [onResult] Block, We will Execute it SomeHow.
if(it){
// Yay, We have Permission to start the Camera
}else{
// Alas, We Don't have Permission to Start The Camera, Ask User to disable the feature
}
}
getStatusBarHeight()
getNavigationBarSize()
showSnackBar() // Show SnackBar WithOut Design Support Library. Its look better then Actual Snackbar ;)
setStatusBarColor()
setNavigationBarColor()
setNavigationBarDividerColor()
onViewInflated{
// Code On View Inflated
// Mimics the ViewTreeObserver/globalLayoutListener
}
getRootView()
Bitmap Extensions
Bitmap.save("/path/..../image.jpg")
Bitmap.saveAsync("/path/..../image.jpg")
val pixel = bitmap[x,y]
bitmap[x,y] = Color.WHITE
val base64 = bitmap.toBase64()
val resized = bitmap.resize(20,40)
val rotated = bitmap.rotateTo(90)
val round = bitmap.toRound()
val roundCorner = bitmap.toRoundCorner()
val grey = bitmap.toGrayScale()
val byteArray = bitmap.toByteArray
val compressed = bitmap.compressBySampleSize(400,500)
val compressedQuality = bitmap.compressByQuality(80)
Context Extensions
val screenWidth = context.screenWidth
val screenHeight = context.screenHeight
context.showNotification("Hello Notification",...,...,... other params) //Handles Everything For You
context.showToast()
context.showToastHard()
context.showConfirmationDialog()
context.showSinglePicker()
context.showMultiPicker()
context.showDatePicker()
context.showTimePicker()
context.isGPSEnable()
context.isNetworkAvailable()
context.isAppInstalled()
context.isIntentResolvable()
context.checkSelfPermissions()
context.getAndroidID()
context.getDeviceID()
context.getIMEI()
context.requestMediaScanner()
context.vibrate()
context.startApp()
context.startActivity()
context.startService()
context.startApp()
context.getAllImages()
context.getAllVideos()
context.getAllAudios()
context.getAppName() // Current or Given Package
context.getAppIcon() // Current or Given Package
context.getAppSize() // Current or Given Package
context.getAppApk() // Current or Given Package
context.getAppVersionName() // Current or Given Package
context.getAppVersionCode() // Current or Given Package
context.isServiceRunning() //Check If Service is Running Or Not
context.getActivityManager()
context.getAlarmManager()
context.getAudioManager()
context.getClipboardManager()
context.getConnectivityManager()
context.getKeyguardManager()
context.getLocationManager()
context.getNotificationManager()
context.getPowerManager()
context.getSearchManager()
context.getSensorManager()
context.getTelephonyManager()
context.getVibrator()
context.getWifiManager()
context.getWindowManager()
context.getInputMethodManager()
context.getKeyguardManager()
context.getLayoutInflater()
.....And All The...........
......System Service.......
........Are Avaibale.......
File Extensions
val file = File("/a/file/from/anywhere")
val string = file.readToString()
val inputStream = file.open()
val byteArray = file.toByteArray()
file.copy(File("copy to"))
file.move(File("copy to"))
file.deleteAll()
if(file.isImage()){
//do the Stuff Like Decoding File to image
}
Number Extensions
pxFromSp()
spFromPx()
pxFromDp()
dpFromPx()
40.loop{
// Loop Till 0 to 40
}
1.toBoolean()
SeekBar Extensions
seekBar.setOnSeekBarChangeListener(
onProgressChanged={seek,progress,fromUser->
})
String Extensions
encodeToBase64()
decodeToBase64()
toCamelCase()
toTitleCase()
encryptAES("mySecretKey")
decryptAES("mySecretKey")
encodeToBinary()
deCodeToBinary()
View Extensions
val bitmap = view.screenshot()
view.setOnSingleClickListener{
//Prevent Multiple tap from Geeky Users
}
view.fadeIn() // Fade the View In
view.fadeOut() // Fade the View Out
view.showKeyBoard()
view.hideKeyBoard()
setPaddingLeft(40)
setPaddingRight(40)
top
bottom
start
end
Horizontal
setPaddingVertical(40)
setHeight()
setWidth()
isVisible()
isGone()
isInvisible()
getActivity()
Want to Know How Much Does You Code takes to Execute? Let me show you how you can do the same Easily.val bench = BenchMarkUtils()
Your Code Goes Here
And Maybe Here Too
And Might Be Here Too...
val time = bench.dump() // Dumps The Time to Logcat and Returns The Same Too
//Now Check the Logcat With Tha Class name Tag and You will see the Results