Skip to content

Instantly share code, notes, and snippets.

View jossiwolf's full-sized avatar
🐨
Waiting for the pelican emoji

Jossi Wolf jossiwolf

🐨
Waiting for the pelican emoji
View GitHub Profile
@jossiwolf
jossiwolf / EnhancedMotionLayout.kt
Last active December 9, 2019 11:31
Enhanced MotionLayout capabilities such as being able to add multiple listeners and disable touch and await animations using coroutines. Adapted from https://github.com/chrisbanes/tivi/blob/master/common-ui/src/main/java/app/tivi/ui/widget/TiviMotionLayout.kt
class EnhancedMotionLayout @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : MotionLayout(context, attrs, defStyleAttr) {
private val listeners = CopyOnWriteArrayList<TransitionListener>()
fun addTransitionListener(listener: TransitionListener) {
listeners.addIfAbsent(listener)
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.OnLifecycleEvent
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
/**
* Proxy for [LifecycleAwareLazyImpl]
* @see LifecycleAwareLazyImpl
/**
* Merges two [ConstraintSet]s. If a Constraint exists in the first [ConstraintSet] and the second one, the original value will be replaced by the new value.
*/
operator fun ConstraintSet.plus(other: ConstraintSet): ConstraintSet {
return this.copy().apply { updateWith(other) }
}
/**
* Clears the existing constraints and sets them to those of the [constraintSet]
*/
/**
* Helper class for [MotionLayout.TransitionListener] which provides Android Support Annotations and proper parameter names
*/
abstract class TransitionListener: MotionLayout.TransitionListener {
/**
* Called when a transition has been completed
*/
override fun onTransitionCompleted(view: MotionLayout, @IdRes constraintSetId: Int) = Unit
package com.amulyakhare.textdrawable;
import android.graphics.*;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.graphics.drawable.shapes.RectShape;
import android.graphics.drawable.shapes.RoundRectShape;
/**
* @author amulya