LoginSignup
3
0

More than 1 year has passed since last update.

HyperionのデバッグメニューアイテムをJetpack Composeで作る

Posted at

ComposeViewを使えばJetpack ComposeでViewがかけるのでHyperionのデバッグメニューのアイテムをJetpack Composeで書くことができる。
Android Viewだとデバッグ用にlayoutを用意する必要があったりして利便性が悪かったが、Jetpack Composeでかけるとコードだけなのでスッキリ書くことができた。
Columnで作ったけども、BoxでもRowでも別に問題はなさそうなきはするのでこれで好きなレイアウトのデバッグメニューが作り放題!

@AutoService(Plugin::class)
class DebugMenuPlugin : Plugin() {
    class PluginModuleImpl : PluginModule() {
        override fun createPluginView(layoutInflater: LayoutInflater, parent: ViewGroup): View =
            ComposeView(parent.context).apply {
                setContent {
                    Column(
                        modifier = Modifier
                            .height(131.dp) // 既存アイテムに合わせたサイズにする
                            .fillMaxWidth()
                            .clickable(
                                interactionSource = remember { MutableInteractionSource() },
                                indication = rememberRipple(bounded = true),
                                onClick = {
                                    // ここで実際のデバッグ処理を書く
                                    Toast.makeText(parent.context, "デバッグメニュー", Toast.LENGTH_LONG).show()
                                },
                            )
                            .padding(16.dp),
                        verticalArrangement = Arrangement.Center,
                    ) {
                        // ここにレイアウトを書く
                        Text("デバッグメニュー")
                    }
                }
            }
    }

    override fun createPluginModule() = PluginModuleImpl()
}
3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0