View ConcatObjectAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ConcatObjectAdapter( | |
private vararg val adapters: ObjectAdapter | |
) : ObjectAdapter() { | |
init { | |
adapters.forEach { adapter -> | |
adapter.registerObserver(object : DataObserver() { | |
override fun onChanged() { | |
super.onChanged() | |
this@ConcatObjectAdapter.notifyChanged() | |
} |
View LineHeightSpanCompat.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.os.Build | |
import android.text.style.LineHeightSpan | |
import androidx.annotation.Px | |
import kotlin.math.roundToInt | |
object LineHeightSpanCompat { | |
fun standard(@Px lineHeight: Int): LineHeightSpan = | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { | |
LineHeightSpan.Standard(lineHeight) | |
} else { |
View AnimatedVectorDrawableMarkerIcon.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AnimatedVectorDrawableMarkerIcon( | |
marker: Marker, | |
private val avd: AnimatedVectorDrawableCompat, | |
width: Int = avd.intrinsicWidth, | |
height: Int = avd.intrinsicHeight | |
) { | |
private val handler = Handler(Looper.getMainLooper()) | |
private val invalidateTask = Runnable { avd.invalidateSelf() } | |
private var isRunning = false | |
private var isAutoLoop = false |
View OneShotGlobalLayoutListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OneShotGlobalLayoutListener private constructor( | |
private val view: View, | |
private val runnable: Runnable | |
) : ViewTreeObserver.OnGlobalLayoutListener, View.OnAttachStateChangeListener { | |
private var viewTreeObserver: ViewTreeObserver = view.viewTreeObserver | |
init { | |
view.viewTreeObserver.addOnGlobalLayoutListener(this) | |
view.addOnAttachStateChangeListener(this) | |
} |
View Pixel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* px/dp/sp/pt/mm unit converter. | |
* This is not incompatible with Jetpack Compose. | |
*/ | |
inline class Pixel(private val pxF: Float) { | |
val toPx: Int @Px get() = pxF.roundToInt() | |
fun toDp(res: Resources = Resources.getSystem()): Float = pxF / TypedValue.applyDimension( | |
TypedValue.COMPLEX_UNIT_DIP, 1.0f, res.displayMetrics | |
) |
View _LocaleTimePicker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LocaleTimePicker extends TimePicker { | |
public LocaleTimePicker(Context context) { | |
this(context, null); | |
} | |
public LocaleTimePicker(Context context, @Nullable AttributeSet attrs) { | |
this(context, attrs, Resources.getSystem().getIdentifier("timePickerStyle", "attr", "android")); | |
} |
View DimBehindPopupWindow.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val popup = PopupWindow(...) | |
val container = popup.contentView.takeIf { it.layoutParams is WindowManager.LayoutParams } | |
?: (popup.contentView.parent as? View)?.takeIf { it.layoutParams is WindowManager.LayoutParams } | |
?: (popup.contentView.parent.parent as? View)?.takeIf { it.layoutParams is WindowManager.LayoutParams } | |
?: throw IllegalStateException("NO WindowManager.LayoutParams!") | |
val wm = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager | |
val lp = container.layoutParams as WindowManager.LayoutParams | |
lp.flags = lp.flags or WindowManager.LayoutParams.FLAG_DIM_BEHIND |
View Rx+mapNotNull.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <T, R> Observable<T>.mapNotNull(mapper: (T) -> R?): Observable<R> { | |
return lift { observer -> | |
object: Observer<T> { | |
override fun onNext(t: T) { | |
mapper(t)?.let { observer.onNext(it) } | |
} | |
override fun onComplete() { | |
observer.onComplete() | |
} | |
override fun onError(e: Throwable) { |
View expand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.reactivex.Flowable | |
import io.reactivex.Maybe | |
import io.reactivex.Observable | |
import io.reactivex.Single | |
import io.reactivex.rxkotlin.Flowables | |
import io.reactivex.rxkotlin.Maybes | |
import io.reactivex.rxkotlin.Observables | |
import io.reactivex.rxkotlin.Singles | |
fun <T> Observables.expand(source: Observable<T>, expander: (T) -> Observable<T>): Observable<T> { |
NewerOlder