From 94defc1ab5f9f987d5c1b14c91613364ce4ed1ba Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 19 Jun 2017 12:58:44 -0700 Subject: Add thread logging --- library/src/main/kotlin/ca/allanwang/kau/logging/KL.kt | 6 ++++++ library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 library/src/main/kotlin/ca/allanwang/kau/logging/KL.kt diff --git a/library/src/main/kotlin/ca/allanwang/kau/logging/KL.kt b/library/src/main/kotlin/ca/allanwang/kau/logging/KL.kt new file mode 100644 index 0000000..4fa3360 --- /dev/null +++ b/library/src/main/kotlin/ca/allanwang/kau/logging/KL.kt @@ -0,0 +1,6 @@ +package ca.allanwang.kau.logging + +/** + * Created by Allan Wang on 2017-06-19. + */ +object KL : TimberLogger("KAU") \ No newline at end of file diff --git a/library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt b/library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt index e00891d..642c29c 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt @@ -2,6 +2,8 @@ package ca.allanwang.kau.utils import android.content.res.Resources import android.os.Build +import android.os.Looper +import ca.allanwang.kau.logging.KL /** * Created by Allan Wang on 2017-05-28. @@ -17,4 +19,12 @@ val buildIsLollipopAndUp: Boolean get() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP val buildIsMarshmallowAndUp: Boolean - get() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M \ No newline at end of file + get() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M + +/** + * Log whether current state is in the main thread + */ +fun checkThread(id: Int) { + val status = if (Looper.myLooper() == Looper.getMainLooper()) "is" else "is not" + KL.d("$id $status in the main thread") +} \ No newline at end of file -- cgit v1.2.3