xuxinyi 9 mesiacov pred
rodič
commit
780fccbbbc

+ 4 - 1
app/src/main/AndroidManifest.xml

@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools">
+    <uses-permission android:name="android.permission.INTERNET" />
 
     <application
         android:allowBackup="true"
@@ -11,7 +12,8 @@
         android:roundIcon="@mipmap/ic_launcher_round"
         android:supportsRtl="true"
         android:theme="@style/Theme.Calculation"
-        tools:targetApi="31" >
+        android:networkSecurityConfig="@xml/network_security_config"
+        tools:targetApi="31">
 
         <!-- 设置 MainActivity 为启动 Activity -->
         <activity android:name=".MainActivity"
@@ -25,4 +27,5 @@
         </activity>
     </application>
 
+
 </manifest>

+ 44 - 36
app/src/main/java/com/aplid/calculation/MainActivity.kt

@@ -1,7 +1,9 @@
 package com.aplid.calculation
 
+import android.annotation.SuppressLint
 import android.os.Bundle
 import android.view.MotionEvent
+import android.webkit.WebView
 import android.widget.LinearLayout
 import android.widget.TextView
 import androidx.appcompat.app.AppCompatActivity
@@ -14,51 +16,57 @@ class MainActivity : AppCompatActivity() {
 
     private lateinit var moveTextView : TextView
 
+    @SuppressLint("SetJavaScriptEnabled")
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
         supportActionBar?.hide()
         setContentView(R.layout.activity_main) // 绑定布局
-        moveTextView = findViewById(R.id.move)
-        // 创建一个列表数据
-        val itemList = listOf(
-            ListItem("Item 1"),
-            ListItem("Item 2"),
-            ListItem("Item 3"),
-            ListItem("Item 4"),
-            ListItem("Item 5")
-        )
 
-        // 设置RecyclerView
-        val recyclerView: RecyclerView = findViewById(R.id.recyclerView)
-        recyclerView.layoutManager = LinearLayoutManager(this)
+        val webView = findViewById<WebView>(R.id.webView)
+        webView.settings.javaScriptEnabled = true // 启用 JavaScript
+        webView.loadUrl("http://60.204.139.57:6002/")
 
-        // 设置Adapter
-        val adapter = MyAdapter(itemList)
-        recyclerView.adapter = adapter
+//        moveTextView = findViewById(R.id.move)
+//        // 创建一个列表数据
+//        val itemList = listOf(
+//            ListItem("Item 1"),
+//            ListItem("Item 2"),
+//            ListItem("Item 3"),
+//            ListItem("Item 4"),
+//            ListItem("Item 5")
+//        )
+
+//        // 设置RecyclerView
+//        val recyclerView: RecyclerView = findViewById(R.id.recyclerView)
+//        recyclerView.layoutManager = LinearLayoutManager(this)
+//
+//        // 设置Adapter
+//        val adapter = MyAdapter(itemList)
+//        recyclerView.adapter = adapter
     }
 
     // 处理触摸事件
-    override fun onTouchEvent(event: MotionEvent): Boolean {
-        when (event.action) {
-            MotionEvent.ACTION_DOWN -> {
-                // 触摸按下,记录触摸位置
-                moveTextView.isPressed = true
-                updatePosition(event)
-                return true // 消费事件
-            }
-            MotionEvent.ACTION_MOVE -> {
-                // 移动过程中更新位置
-                updatePosition(event)
-                return true // 消费事件
-            }
-            MotionEvent.ACTION_UP -> {
-                // 触摸抬起,结束操作
-                moveTextView.isPressed = false
-                return true // 消费事件
-            }
-            else -> return super.onTouchEvent(event)
-        }
-    }
+//    override fun onTouchEvent(event: MotionEvent): Boolean {
+//        when (event.action) {
+//            MotionEvent.ACTION_DOWN -> {
+//                // 触摸按下,记录触摸位置
+//                moveTextView.isPressed = true
+//                updatePosition(event)
+//                return true // 消费事件
+//            }
+//            MotionEvent.ACTION_MOVE -> {
+//                // 移动过程中更新位置
+//                updatePosition(event)
+//                return true // 消费事件
+//            }
+//            MotionEvent.ACTION_UP -> {
+//                // 触摸抬起,结束操作
+//                moveTextView.isPressed = false
+//                return true // 消费事件
+//            }
+//            else -> return super.onTouchEvent(event)
+//        }
+//    }
 
     // 更新 TextView 的位置
     private fun updatePosition(event: MotionEvent) {

+ 5 - 8
app/src/main/res/layout/activity_main.xml

@@ -3,13 +3,10 @@
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical">
-
-    <TextView
-        android:id="@+id/move"
-        android:layout_width="wrap_content"
-        android:layout_height="30dp" />
-    <androidx.recyclerview.widget.RecyclerView
-        android:id="@+id/recyclerView"
+    <!-- WebView组件 -->
+    <WebView
+        android:id="@+id/webView"
         android:layout_width="match_parent"
         android:layout_height="match_parent" />
-</LinearLayout>
+
+</LinearLayout>

+ 6 - 0
app/src/main/res/xml/network_security_config.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<network-security-config>
+    <domain-config cleartextTrafficPermitted="true">
+        <domain includeSubdomains="true">60.204.139.57</domain>
+    </domain-config>
+</network-security-config>