Skip to content

Instantly share code, notes, and snippets.

@shkcodes
shkcodes / LazyColumn.kt
Created Jul 25, 2021
ExoPlayer in LazyColumn
View LazyColumn.kt
@Composable
fun TweetList(state: TweetListState) {
val context = LocalContext.current
val listState = rememberLazyListState()
val exoPlayer = remember {
SimpleExoPlayer.Builder(context).build().apply {
repeatMode = Player.REPEAT_MODE_ALL
}
}
View draw_circle.kt
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
canvas.drawCircle(centerX, centerCircleY, radius, circlePaint)
val textCenterY = centerY - ((textPaint.descent() + textPaint.ascent()) / 2)
canvas.drawText(label, centerX, textCenterY, textPaint)
}
View observable_view_property.kt
private fun <T> viewProperty(default: T) = object : ObservableProperty<T>(default) {
override fun beforeChange(property: KProperty<*>, oldValue: T, newValue: T): Boolean =
newValue != oldValue
override fun afterChange(property: KProperty<*>, oldValue: T, newValue: T) {
postInvalidateOnAnimation()
}
}
View scene.xml
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motion="http://schemas.android.com/apk/res-auto">
<Transition
motion:constraintSetEnd="@id/state_top"
motion:constraintSetStart="@id/state_mid"
motion:duration="300">
<OnSwipe
motion:dragDirection="dragUp"
View layout.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/scene_2">
<View
android:id="@+id/rectangle"
android:layout_width="0dp"
View A (fixed).java
class A {
private B objectB;
public A(B objectB) {
this.objectB = objectB;
}
public int doSomeWork() {
int result = objectB.getResult();
View A.java
class A {
public int doSomeWork(int p1, int p2, String p3) {
B objectB = new B(p1, p2, p3);
int result = objectB.getResult();
int finalResult = result * 2;
return finalResult;
}
}
View A.java
Class A {
public int doSomeWork() {
B objectB = new B();
int result = objectB.getResult();
int finalResult = result * 2;
return finalResult;
}
}