xiongweixp 2 сар өмнө
parent
commit
446b3d8bfb

+ 1 - 1
.idea/compiler.xml

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
   <component name="CompilerConfiguration">
-    <bytecodeTargetLevel target="21" />
+    <bytecodeTargetLevel target="17" />
   </component>
 </project>

+ 2 - 1
.idea/misc.xml

@@ -1,6 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
   <component name="ExternalStorageConfigurationManager" enabled="true" />
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="Android API 35, extension level 13 Platform" project-jdk-type="Android SDK">
     <output url="file://$PROJECT_DIR$/build/classes" />
   </component>
   <component name="ProjectType">

+ 36 - 1
app/src/main/java/tech/xiongweixp/touchaction/MainActivity.kt

@@ -2,6 +2,8 @@ package tech.xiongweixp.touchaction
 
 import android.os.Bundle
 import android.util.Log
+import android.widget.Button
+import android.widget.TextView
 import androidx.activity.ComponentActivity
 import androidx.activity.compose.setContent
 import androidx.activity.enableEdgeToEdge
@@ -12,19 +14,39 @@ import androidx.compose.material3.Text
 import androidx.compose.runtime.Composable
 import androidx.compose.ui.Modifier
 import androidx.compose.ui.tooling.preview.Preview
+import androidx.constraintlayout.widget.ConstraintLayout
 import tech.xiongweixp.touchaction.ui.theme.TouchActionTheme
 import java.net.HttpURLConnection
 import java.net.URL
 
 class MainActivity : ComponentActivity() {
+    private var computerLayout: ConstraintLayout? = null
+    private var lightLayout: ConstraintLayout? = null
+    private var mainLayout: ConstraintLayout? = null
+    private var computerTextView: TextView? = null
+    private var compterCloseBtn: Button? = null
+
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
+        setContentView(R.layout.mainlayout)
+        computerLayout = findViewById(R.id.computerLayout)
+        lightLayout = findViewById(R.id.lightLayout)
+        mainLayout = findViewById(R.id.mainLayout)
+        computerTextView = findViewById(R.id.computerText)
+        compterCloseBtn = findViewById(R.id.computerCloseButton)
+
+        compterCloseBtn!!.setOnClickListener {
+            //退出APP
+            finish()
+        }
         enableEdgeToEdge()
         Log.i("MainActivity", "打开APP")
         Log.i("MainActivity", intent.data.toString())
-        setContentView(R.layout.mainlayout)
+
     }
 
+
+
     private fun hassioRequest(webhookID: String) {
         Thread {
             try {
@@ -55,12 +77,25 @@ class MainActivity : ComponentActivity() {
             when (action) {
                 "computer" -> {
                     // 电脑
+                    computerLayout!!.visibility = ConstraintLayout.VISIBLE
+                    lightLayout!!.visibility = ConstraintLayout.INVISIBLE
+                    mainLayout!!.visibility = ConstraintLayout.INVISIBLE
+                    computerTextView!!.text = "操作电脑开关"
                     hassioRequest("computer")
                 }
                 "light" -> {
                     // 灯
+                    computerLayout!!.visibility = ConstraintLayout.INVISIBLE
+                    lightLayout!!.visibility = ConstraintLayout.VISIBLE
+                    mainLayout!!.visibility = ConstraintLayout.INVISIBLE
                     hassioRequest("light")
                 }
+                else -> {
+                    // 主界面
+                    computerLayout!!.visibility = ConstraintLayout.INVISIBLE
+                    lightLayout!!.visibility = ConstraintLayout.INVISIBLE
+                    mainLayout!!.visibility = ConstraintLayout.VISIBLE
+                }
 //                "save" -> {
 //                    // 保存
 //                }

+ 28 - 0
app/src/main/res/layout/mainlayout.xml

@@ -62,6 +62,34 @@
             android:layout_width="match_parent"
             android:layout_height="match_parent" android:id="@+id/computerLayout" android:visibility="invisible">
 
+        <ImageView
+                android:layout_width="152dp"
+                android:layout_height="144dp" android:id="@+id/imageView"
+                android:src="@mipmap/computer"
+                app:layout_constraintTop_toTopOf="parent"
+                android:layout_marginTop="173dp" app:layout_constraintStart_toStartOf="parent"
+                android:layout_marginStart="90dp" android:layout_marginEnd="100dp"
+                app:layout_constraintEnd_toEndOf="parent" app:layout_constraintBottom_toBottomOf="parent"
+                android:layout_marginBottom="333dp" tools:srcCompat="@drawable/computer"/>
+        <TextView
+                android:text="电脑"
+                android:layout_width="wrap_content"
+                android:layout_height="42dp" android:id="@+id/computerText"
+                tools:text="电脑" android:textSize="24sp"
+                android:layout_marginTop="36dp"
+                app:layout_constraintTop_toBottomOf="@+id/imageView" app:layout_constraintStart_toStartOf="parent"
+                android:layout_marginStart="186dp" android:layout_marginEnd="177dp"
+                app:layout_constraintEnd_toEndOf="parent" app:layout_constraintBottom_toBottomOf="parent"
+                android:layout_marginBottom="295dp"/>
+        <Button
+                android:text="关闭"
+                android:layout_width="316dp"
+                android:layout_height="57dp" android:id="@+id/computerCloseButton"
+                android:layout_marginTop="40dp"
+                app:layout_constraintTop_toBottomOf="@+id/computerText" app:layout_constraintStart_toStartOf="parent"
+                android:layout_marginStart="51dp" android:layout_marginEnd="44dp"
+                app:layout_constraintEnd_toEndOf="parent" app:layout_constraintBottom_toBottomOf="parent"
+                android:layout_marginBottom="198dp" android:background="@drawable/button_shape" android:textColor="@color/white"/>
     </androidx.constraintlayout.widget.ConstraintLayout>
     <androidx.constraintlayout.widget.ConstraintLayout
             android:layout_width="match_parent"

+ 0 - 0
app/src/main/res/drawable/computer.png → app/src/main/res/mipmap-xxhdpi/computer.png


+ 0 - 0
app/src/main/res/drawable/light.png → app/src/main/res/mipmap-xxhdpi/light.png