<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/scroll_root"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="16dp">

        <TextView
            android:id="@+id/tv_title"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="App 内部利用无线调试进行环回连接（自建 ADB 客户端）"
            android:textSize="16sp"
            android:textStyle="bold"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent" />

        <TextView
            android:id="@+id/tv_hint"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:text="需要 Android 11+。请先到「开发者选项 → 无线调试」开启无线调试，并记录「使用配对码配对设备」的端口/配对码，以及「无线调试」主端口。"
            android:textSize="12sp"
            android:textColor="#888888"
            app:layout_constraintTop_toBottomOf="@id/tv_title"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent" />

        <Button
            android:id="@+id/btn_open_settings"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:text="打开开发者选项"
            app:layout_constraintTop_toBottomOf="@id/tv_hint"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent" />

        <!-- 配对 -->
        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/til_pair_port"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:hint="配对端口 (Pairing Port)"
            app:layout_constraintTop_toBottomOf="@id/btn_open_settings"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/et_pair_port"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="number"
                android:text="37019" />
        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/til_pair_code"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:hint="配对码 (Pairing Code)"
            app:layout_constraintTop_toBottomOf="@id/til_pair_port"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/et_pair_code"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="number"
                android:text="123456" />
        </com.google.android.material.textfield.TextInputLayout>

        <Button
            android:id="@+id/btn_pair"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:text="① 配对 (TLS 握手提交配对码)"
            app:layout_constraintTop_toBottomOf="@id/til_pair_code"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent" />

        <!-- 主端口连接 -->
        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/til_main_port"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:hint="无线调试主端口 (IP Address &amp; Port 下方)"
            app:layout_constraintTop_toBottomOf="@id/btn_pair"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/et_main_port"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="number"
                android:text="12345" />
        </com.google.android.material.textfield.TextInputLayout>

        <Button
            android:id="@+id/btn_connect"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:text="② 连接无线调试主端口"
            app:layout_constraintTop_toBottomOf="@id/til_main_port"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent" />

        <Button
            android:id="@+id/btn_disconnect"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:text="断开连接"
            app:layout_constraintTop_toBottomOf="@id/btn_connect"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent" />

        <!-- Shell 指令 -->
        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/til_tap_x"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:hint="X 坐标"
            app:layout_constraintTop_toBottomOf="@id/btn_disconnect"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toStartOf="@id/til_tap_y">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/et_tap_x"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="number"
                android:text="500" />
        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/til_tap_y"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:layout_marginStart="8dp"
            android:hint="Y 坐标"
            app:layout_constraintTop_toBottomOf="@id/btn_disconnect"
            app:layout_constraintStart_toEndOf="@id/til_tap_x"
            app:layout_constraintEnd_toEndOf="parent">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/et_tap_y"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="number"
                android:text="1000" />
        </com.google.android.material.textfield.TextInputLayout>

        <Button
            android:id="@+id/btn_tap"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:text="③ 执行 input tap (点击)"
            app:layout_constraintTop_toBottomOf="@id/til_tap_y"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent" />

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/til_cmd"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:hint="自定义 shell 命令 (如 getprop ro.build.version.sdk)"
            app:layout_constraintTop_toBottomOf="@id/btn_tap"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/et_cmd"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:imeOptions="actionSend"
                android:text="getprop ro.build.version.sdk" />
        </com.google.android.material.textfield.TextInputLayout>

        <Button
            android:id="@+id/btn_exec"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:text="执行自定义命令"
            app:layout_constraintTop_toBottomOf="@id/til_cmd"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent" />

        <TextView
            android:id="@+id/tv_status"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:text="状态：未连接"
            android:textStyle="bold"
            app:layout_constraintTop_toBottomOf="@id/btn_exec"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent" />

        <TextView
            android:id="@+id/tv_log"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:background="#111111"
            android:textColor="#00FF00"
            android:textSize="11sp"
            android:padding="8dp"
            android:typeface="monospace"
            android:text="日志输出将显示在这里…"
            app:layout_constraintTop_toBottomOf="@id/tv_status"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toBottomOf="parent" />

    </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
