Skip to content

Instantly share code, notes, and snippets.

View chris-horner's full-sized avatar

Chris Horner chris-horner

View GitHub Profile
@chris-horner
chris-horner / InsetUtils.kt
Created October 31, 2019 10:35
Simple utility for padding with window insets.
import android.graphics.Rect
import android.view.View
import android.view.View.OnAttachStateChangeListener
import android.view.WindowInsets
import androidx.core.view.updatePadding
fun View.updatePaddingWithInsets(left: Boolean = false,
top: Boolean = false,
right: Boolean = false,
bottom: Boolean = false) {
@chris-horner
chris-horner / ArcMotionPlus.kt
Created October 27, 2019 09:59
A simplified implementation of the library found at https://github.com/neild001/ArcMotionPlus
import android.graphics.Path
import android.graphics.PointF
import android.transition.PathMotion
import kotlin.math.atan
import kotlin.math.sin
import kotlin.math.sqrt
import kotlin.math.tan
/**
* A PathMotion that generates a curved path along an arc on an imaginary circle containing the two points. The two
class BottomNavChangeHandler : TransitionChangeHandler() {
override fun getTransition(container: ViewGroup, from: View?, to: View?,
isPush: Boolean): Transition {
if (from == null || to == null) {
throw IllegalArgumentException("from and to must not be null.")
}
val transition = TransitionSet()
@chris-horner
chris-horner / Transitions.kt
Created December 21, 2017 12:38
Extension function forcing a shared element to run in a ViewGroup overlay.
fun Transition.sharedElementsInOverlay(container: ViewGroup, start: View, end: View): Transition =
addListener(object : Transition.TransitionListener {
val endParent = end.parent as ViewGroup
val endOriginalPosition = endParent.indexOfChild(end)
override fun onTransitionStart(transition: Transition) {
start.visibility = View.GONE
container.overlay.add(start)
container.overlay.add(end)
}
import rx.Emitter;
import rx.Observable;
import rx.schedulers.Schedulers;
public final class EmitterTest {
public static void main(String[] args) {
Observable<Integer> obs = Observable.fromEmitter(emitter -> {
for (int i = 1; i < 1000; i++) {
if (i % 5 == 0) {
sleep(300L);
@chris-horner
chris-horner / RxStore.kt
Last active April 13, 2016 04:29
A weird version of RxStore that uses Kotlin and Moshi
import android.content.Context
import android.os.FileObserver
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi
import com.squareup.moshi.Types
import okio.Okio
import rx.Observable
import rx.Scheduler
import rx.lang.kotlin.observable
import rx.lang.kotlin.single
@chris-horner
chris-horner / SimpleString
Created April 14, 2014 06:20
A CharSequence implementation that allocates memory as infrequently as possible
/**
* <p>
* A simplified version of the String class. Unlike the normal implementation of
* String, memory is only allocated during initialisation, or when the internal
* character array must be expanded.
* </p>
* <p>
* This makes it useful for environments where text must be modified at run time
* whilst displaying smooth animations.
* </p>