Skip to content

Instantly share code, notes, and snippets.

View babedev's full-sized avatar

Christopher Ng babedev

  • BabeDev
  • Bangkok, Thailand
View GitHub Profile
@babedev
babedev / android-rotate-bitmap.kt
Created February 14, 2018 02:14
Rotate bitmap on Android
fun rotateBitmap(bitmap: Bitmap, orientation: Int): Bitmap? {
val matrix = Matrix()
when (orientation) {
ExifInterface.ORIENTATION_FLIP_HORIZONTAL -> matrix.setScale(-1F, 1F)
ExifInterface.ORIENTATION_ROTATE_180 -> matrix.setRotate(180F)
ExifInterface.ORIENTATION_FLIP_VERTICAL -> {
matrix.setRotate(180F)
matrix.postScale(-1F, 1F)
}
@babedev
babedev / bnv-set-font.kt
Last active March 22, 2018 14:23
Set font by resource ID got BottomNavigationView
fun BottomNavigationView.setFont(@FontRes rId: Int) {
val menuView = this.getChildAt(0) as BottomNavigationMenuView
val menuCount = menuView.childCount
(0 until menuCount).forEach {
val itemView = menuView.getChildAt(it) as BottomNavigationItemView
val titleView = itemView.getChildAt(1) as BaselineLayout
val smallLabel = titleView.getChildAt(0) as TextView
val largeLabel = titleView.getChildAt(1) as TextView
@babedev
babedev / list_sequence_no_terminal.kt
Last active March 25, 2018 08:48
List vs Sequence no terminal operation
println("List ====> ")
listOf(1, 2, 3)
.filter {
println("Filter: $it")
it % 2 == 0
}
.map {
println("Map: $it")
it
}
@babedev
babedev / sequence_operation.kt
Created March 25, 2018 09:49
Sequence operation
println("List ====> ")
listOf(1, 2, 3)
.filter { println("Filter: $it"); it % 2 == 0 }
.map { println("Map: $it"); it + 1 }
.forEach { println("Each: $it") }
println("Sequence ====> ")
sequenceOf(1, 2, 3)
.filter { println("Filter: $it"); it % 2 == 0 }
.map { println("Map: $it"); it + 1 }