Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use MessageCompat.setAsynchronous to support API 16+ #33

Merged
merged 6 commits into from Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 3 additions & 5 deletions papa/src/main/java/papa/internal/Handlers.kt
@@ -1,17 +1,15 @@
package papa.internal

import android.os.Build
import android.os.Handler
import android.os.Looper
import android.os.Message
import androidx.core.os.MessageCompat

// Thx @chet and @jreck
// https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:metrics/metrics-performance/src/main/java/androidx/metrics/performance/JankStatsApi16Impl.kt;l=66;drc=523d7a11e46390281ed3f77893671730cd6edb98
internal fun Handler.postAtFrontOfQueueAsync(callback: () -> Unit) {
sendMessageAtFrontOfQueue(Message.obtain(this, callback).apply {
if (Build.VERSION.SDK_INT >= 22) {
isAsynchronous = true
}
MessageCompat.setAsynchronous(this, true)
})
}

Expand All @@ -25,4 +23,4 @@ internal fun checkMainThread() {

internal val mainHandler by lazy {
Handler(Looper.getMainLooper())
}
}
2 changes: 0 additions & 2 deletions sample/src/main/java/com/example/papa/TouchLagActivity.kt
Expand Up @@ -5,8 +5,6 @@ import android.animation.AnimatorListenerAdapter
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.slider.Slider
import com.google.android.material.slider.Slider.OnSliderTouchListener
import papa.Interaction
import papa.InteractionLatencyReporter
import papa.InteractionTrigger
Expand Down