Created
June 8, 2022 22:08
-
-
Save fulcrum6378/9217945bd31f8745a138a65f6e6371c6 to your computer and use it in GitHub Desktop.
ViewGroup analyser for Android in Kotlin
This file contains 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
@file:Suppress("MemberVisibilityCanBePrivate", "unused") | |
package <COM.EXAMPLE.APP> | |
import android.view.View | |
import android.view.ViewGroup | |
import androidx.core.view.children | |
import com.google.gson.GsonBuilder | |
class ViewGroupWalk(vg: ViewGroup) { | |
val data = vg.walk() | |
private fun View.walk(): ViewInfo = ViewInfo( | |
javaClass.name, if (this@walk is ViewGroup) children.toList().map { it.walk() } else null) | |
fun gson(): String = GsonBuilder().setPrettyPrinting().create().toJson(data) | |
inner class ViewInfo(val name: String, val children: List<ViewInfo>?) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment