Skip to content

Instantly share code, notes, and snippets.

View grandstaish's full-sized avatar
🌴
At Kotlin Conf, back Weds 29th

Bradley Campbell grandstaish

🌴
At Kotlin Conf, back Weds 29th
View GitHub Profile
@grandstaish
grandstaish / BottomSheetDialog.kt
Created January 27, 2021 20:20
BottomSheetDialog.kt
package com.monzo.compose
import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.view.Window
@grandstaish
grandstaish / ListSection.kt
Last active January 7, 2022 11:31
*Very* rough POC for what one of our common components at Monzo could look like in Compose
@Composable
@OptIn(ExperimentalSubcomposeLayoutApi::class)
fun ListSection(
modifier: Modifier = Modifier,
header: String? = null,
footer: String? = null,
showDividers: Boolean = true,
dividerInset: Dp = 16.dp,
content: @Composable () -> Unit,
) {
/**
* Sets a background drawable on this view that will draw a slice of [ancestor]'s background that sits underneath
* this view. This is useful when [ancestor] has a gradient background and you want another child to seamlessly
* continue that gradient while also having an opaque background to allow for elevation.
*/
fun View.setBackgroundFromAncestor(ancestor: ViewGroup) {
check(ancestor.isAncestorOf(this))
if (ancestor.background == null) return
background = CopyBackgroundDrawable(this, ancestor)
}
package com.monzo.design.nosymbol
import android.content.Context
import android.util.AttributeSet
import android.view.HapticFeedbackConstants.VIRTUAL_KEY
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import android.view.accessibility.AccessibilityEvent
import androidx.recyclerview.widget.LinearSnapHelper
@grandstaish
grandstaish / RaindropView.kt
Last active May 22, 2024 09:54
A raindrop shaped view
internal class RaindropView(context: Context) : View(context) {
private val backgroundPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
style = Paint.Style.FILL
color = Color.WHITE
}
private val gradientPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
style = Paint.Style.FILL
color = Color.WHITE
}
@grandstaish
grandstaish / RadixSort.kt
Created April 6, 2017 05:14
Basic radix sorting algorithm written in Kotlin
fun IntArray.radixSort(): IntArray {
var result = this
val max = getMax()
var place = 1
while (max / place > 0) {
result = result.countingSort(place)
place *= 10
}
fun Node.format(): String {
return formatInternal().lines.joinToString(separator = "\n")
}
fun max(a: Int, b: Int, c: Int): Int {
return Math.max(Math.max(a, b), c)
}
fun String.center(width: Int, fillChar: Char = ' ') : String {
var s = this
@grandstaish
grandstaish / CustomViewsLayoutInflaterFactory.java
Last active September 13, 2022 05:53
LayoutInflaterFactory examples
package nz.bradcampbell.app.presentation;
import android.content.Context;
import android.support.v4.view.LayoutInflaterFactory;
import android.util.AttributeSet;
import android.view.View;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;