Skip to content

Instantly share code, notes, and snippets.

View tcw165's full-sized avatar
💭
building AI

TC Wang tcw165

💭
building AI
View GitHub Profile
public final class CanvasExtensionsKt {
public static final void runSafely(android.graphics.Canvas, kotlin.jvm.functions.Function1<? super android.graphics.Canvas, kotlin.Unit>);
Code:
// Some byte-code is hidden
13: invokevirtual #23 // Method android/graphics/Canvas.save:()I
16: istore_2
17: aload_1
18: aload_0
19: invokeinterface #29, 2 // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
24: pop
protected void onDraw(android.graphics.Canvas);
Code:
// Some byte-code is hidden
18: invokestatic #31 // Method CanvasExtensionsKt.runSafely:(Landroid/graphics/Canvas;Lkotlin/jvm/functions/Function1;)V
// ...
fun Canvas.runSafely(
lambda: Canvas.() -> Unit
) {
val c = save()
lambda.invoke(this)
restoreToCount(c)
}
protected void onDraw(android.graphics.Canvas);
Code:
// Some byte-code is hidden
14: invokevirtual #23 // Method android/graphics/Canvas.save:()I
17: istore_3
18: aload_2
19: astore 4
21: ldc #25 // String test
23: astore 5
25: getstatic #31 // Field java/lang/System.out:Ljava/io/PrintStream;
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
// Invoke the inline function
canvas.runSafely {
println("test")
}
}
inline fun Canvas.runSafely(
lambda: Canvas.() -> Unit
) {
val checkPoint = save()
// "this" is Canvas
lambda.invoke(this)
restoreToCount(checkPoint)
}
fun getOrientation(attrs: AttributeSet?): Int {
val b = context.theme.obtainStyledAttributes(
attrs,
intArrayOf(android.R.attr.orientation), 0, 0)
val orientation = b.getInt(0, RecyclerView.VERTICAL)
b.recycle()
return orientation
}
constructor(...) : super(...) {
val a = context.theme.obtainStyledAttributes(
attrs,
R.styleable.StyledRecyclerView, 0, 0)
decorateView(a, getOrientation(attrs))
a.recycle()
}
private fun decorateView(
typedArray: TypedArray,
class TakeWhenObservableTest {
@Test
fun openThrottle_shouldSeeTheItemsAreSentThen() {
val src = PublishSubject.create<Int>()
val whenSrc = PublishSubject.create<Boolean>()
val tester = TakeWhenObservable(src = src,
whenSrc = whenSrc)
.test()
// Activity or Fragment
private val mResumeSignal = PublishSubject.create<Boolean>()
private val mResultSignal = PublishSubject.create<Any>()
override void onResume() {
super.onResume();
mResumeSignal.onNext(true);
}