Last active
March 30, 2020 07:22
-
-
Save ShinichiroFunatsu/386f32db12c79342b11f30af9a1ef66b to your computer and use it in GitHub Desktop.
Beta Android DebugTools
This file contains hidden or 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 Fragment.LogD(tag: String, msg: String) { | |
val activity: String? = activity?.toStringSimple() | |
val fragment: String = this.toStringSimple() | |
Log.d(tag, "Fragment %s %s %s".format(activity, fragment, msg)) | |
} | |
private val nameList = ('A'..'Z').toList() | |
private val nameCache = mutableMapOf<String, String>() | |
private var lastUsedIndexForActivity: Int = 0 | |
fun Activity.toStringSimple(): String { | |
val activityName = hashCode().toString() | |
return nameCache[activityName] | |
?: nameList[lastUsedIndexForActivity].let { "Activity[$it]" }.also { | |
val len = nameList.size | |
lastUsedIndexForActivity = (lastUsedIndexForActivity + 1) % len | |
nameCache[activityName] = it | |
} | |
} | |
private var lastUsedIndexForFragment: Int = 0 | |
fun Fragment.toStringSimple(): String { | |
val fragmentName = hashCode().toString() | |
return nameCache[fragmentName] | |
?: nameList[lastUsedIndexForFragment].let { "Fragment[$it]" }.also { | |
val len = nameList.size | |
lastUsedIndexForFragment = (lastUsedIndexForFragment + 1) % len | |
nameCache[fragmentName] = it | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment