jw
01/23/2018, 5:18 PMyaakov
01/23/2018, 5:19 PMpackage foo.bar
fun Baz.goo(){ ... }
yaakov
01/23/2018, 5:25 PMbachhuberdesign
01/23/2018, 5:25 PMbachhuberdesign
01/23/2018, 5:27 PM@file:JvmName("SomeExtensionFile")
you will be able to call from Java as well (if your codebase is mixed)yaakov
01/23/2018, 5:30 PMbachhuberdesign
01/23/2018, 5:30 PMyaakov
01/23/2018, 5:31 PMfun Bitmap.resize(image: Bitmap, maxWidth: Int = 1920, maxHeight: Int = 1080): Bitmap {
if (maxHeight > 0 && maxWidth > 0) {
val width = image.getWidth()
val height = image.getHeight()
val ratioBitmap = width.toFloat() / height.toFloat()
val ratioMax = maxWidth.toFloat() / maxHeight.toFloat()
var finalWidth = maxWidth
var finalHeight = maxHeight
if (ratioMax > ratioBitmap) {
finalWidth = (maxHeight.toFloat() * ratioBitmap).toInt()
} else {
finalHeight = (maxWidth.toFloat() / ratioBitmap).toInt()
}
var finalimage = Bitmap.createScaledBitmap(image, finalWidth, finalHeight, true)
return finalimage
} else {
return image
}
}
bachhuberdesign
01/23/2018, 5:31 PMyaakov
01/23/2018, 5:32 PMyaakov
01/23/2018, 5:32 PMbachhuberdesign
01/23/2018, 5:33 PMyaakov
01/23/2018, 5:34 PMyaakov
01/23/2018, 5:34 PMbachhuberdesign
01/23/2018, 5:35 PMbachhuberdesign
01/23/2018, 5:35 PMyaakov
01/23/2018, 5:35 PMbachhuberdesign
01/23/2018, 5:36 PMbachhuberdesign
01/23/2018, 5:36 PMbachhuberdesign
01/23/2018, 5:37 PMyaakov
01/23/2018, 5:37 PMyaakov
01/23/2018, 5:39 PMbachhuberdesign
01/23/2018, 5:39 PMcompanion object {
@JvmStatic
fun newInstance(someInt: Int): SomeFragment {
val fragment = SomeFragment()
val bundle = Bundle()
bundle.putInt(SOME_KEY, someInt)
fragment.arguments = bundle
return fragment
}
}
bachhuberdesign
01/23/2018, 5:39 PMbachhuberdesign
01/23/2018, 5:47 PMobject BitmapHelper {
@JvmStatic
fun createScaledBitmap(): Bitmap {
// TODO:
}
}
and then call BitmapHelper.createScaledBitmap()bachhuberdesign
01/23/2018, 5:47 PMyaakov
01/23/2018, 5:57 PM