11package com.example.tiny_computer
22
3- import android.content.ClipData
4- import android.content.ClipboardManager
5- import android.content.Context
63import android.content.Intent
7- import android.graphics.Color
84import android.net.Uri
5+ import android.os.Build
96import android.os.Bundle
10- import android.view.Gravity
11- import android.view.View
12- import android.widget.Button
13- import android.widget.ScrollView
14- import android.widget.TextView
15- import android.widget.Toast
16- import android.widget.LinearLayout
177import androidx.appcompat.app.AppCompatActivity
18- import androidx.core.content.ContextCompat.startActivity
8+ import androidx.core.content.ContextCompat
9+ import androidx.core.view.isVisible
10+ import com.example.tiny_computer.databinding.ActivitySignal9Binding
1911
2012class Signal9Activity : AppCompatActivity () {
2113
22- private val helperLink = " https://www.vmos.cn/zhushou.htm"
23- private val helperLink2 = " https://www.cnblogs.com/yejiuluo/articles/18271904"
14+ private lateinit var binding: ActivitySignal9Binding
2415
2516 override fun onCreate (savedInstanceState : Bundle ? ) {
2617 super .onCreate(savedInstanceState)
18+ binding = ActivitySignal9Binding .inflate(layoutInflater)
19+ setContentView(binding.root)
20+
21+ // 设置状态栏和导航栏颜色匹配蓝屏背景
22+ window.statusBarColor = ContextCompat .getColor(this , R .color.tc_s9a_blue_screen_blue)
23+ window.navigationBarColor = ContextCompat .getColor(this , R .color.tc_s9a_blue_screen_blue)
24+
25+ setupContent()
26+ }
2727
28- val rootLayout = LinearLayout (this ).apply {
29- layoutParams = LinearLayout .LayoutParams (
30- LinearLayout .LayoutParams .MATCH_PARENT ,
31- LinearLayout .LayoutParams .WRAP_CONTENT
32- )
33- gravity = Gravity .CENTER
34- orientation = LinearLayout .VERTICAL
35- setPadding(16 , 16 , 16 , 16 )
36- setBackgroundColor(Color .parseColor(" #4A148C" ))
37- }
38-
39- val scrollView = ScrollView (this ).apply {
40- layoutParams = LinearLayout .LayoutParams (
41- LinearLayout .LayoutParams .MATCH_PARENT ,
42- LinearLayout .LayoutParams .MATCH_PARENT
43- )
44- }
45-
46- val fullScreen = LinearLayout (this ).apply {
47- layoutParams = LinearLayout .LayoutParams (
48- LinearLayout .LayoutParams .MATCH_PARENT ,
49- LinearLayout .LayoutParams .MATCH_PARENT
50- )
51- orientation = LinearLayout .VERTICAL
52- setBackgroundColor(Color .parseColor(" #4A148C" ))
53- }
54-
55- val text1 = TextView (this ).apply {
56- text = " :(\n 发生了什么?"
57- textSize = 32f
58- setTextColor(Color .WHITE )
59- textAlignment = View .TEXT_ALIGNMENT_CENTER
60- }
61-
62- val text2 = TextView (this ).apply {
63- text = " 终端异常退出, 返回错误码9\n 此错误通常是高版本安卓系统(12+)限制进程造成的, \n 可以使用以下工具修复:"
64- textSize = 16f
65- setTextColor(Color .WHITE )
66- textAlignment = View .TEXT_ALIGNMENT_CENTER
67- setPadding(0 , 16 , 0 , 0 )
68- }
69-
70- val helperLinkText = TextView (this ).apply {
71- text = helperLink
72- textSize = 16f
73- setTextColor(Color .WHITE )
74- textAlignment = View .TEXT_ALIGNMENT_CENTER
75- setPadding(0 , 16 , 0 , 0 )
76- setOnClickListener { copyToClipboard(helperLink) }
77- }
78-
79- val copyHintText = TextView (this ).apply {
80- text = " (复制链接到浏览器查看)"
81- textSize = 16f
82- setTextColor(Color .WHITE )
83- textAlignment = View .TEXT_ALIGNMENT_CENTER
84- setPadding(0 , 8 , 0 , 0 )
85- }
86-
87- val copyButton = Button (this ).apply {
88- text = " 复制"
89- textSize = 16f
90- setOnClickListener { copyToClipboard(helperLink) }
91- }
92-
93- val tutorialText = TextView (this ).apply {
94- text = " 如果你的设备版本大于等于安卓14,可以在开发者选项里开启“停止限制子进程”选项即可,无需额外修复。\n\n 如果不能解决请参考此教程: "
95- textSize = 16f
96- setTextColor(Color .WHITE )
97- textAlignment = View .TEXT_ALIGNMENT_CENTER
98- setPadding(0 , 16 , 0 , 0 )
99- }
100-
101- val viewButton = Button (this ).apply {
102- text = " 查看"
103- textSize = 16f
104- setOnClickListener { copyToClipboard(helperLink2) }
28+ private fun setupContent () {
29+ // 设置错误信息
30+ binding.errorDetails.text = getString(R .string.tc_s9a_error_message)
31+
32+ // 根据Android版本显示不同的解决方案
33+ if (Build .VERSION .SDK_INT < Build .VERSION_CODES .UPSIDE_DOWN_CAKE ) {
34+ // Android 14以下版本
35+ binding.preAndroid14Layout.isVisible = true
36+ binding.solutionIntro.text = getString(R .string.tc_s9a_solution_intro)
37+ binding.solutionAlternative.text = getString(R .string.tc_s9a_solution_alternative)
38+ binding.toolButton.text = getString(R .string.tc_s9a_tool_button)
39+ binding.tutorialButton.text = getString(R .string.tc_s9a_tutorial_button)
40+
41+ binding.toolButton.setOnClickListener {
42+ openBrowserLink(" https://www.vmos.cn/zhushou.htm" )
43+ }
44+
45+ binding.tutorialButton.setOnClickListener {
46+ openBrowserLink(" https://gitee.com/caten/tc-hints/blob/master/pool/signal9fix.md" )
47+ }
48+ } else {
49+ // Android 14及以上版本
50+ binding.solutionAndroid14.isVisible = true
51+ binding.solutionAndroid14.text = getString(R .string.tc_s9a_solution_android14)
10552 }
106-
107- rootLayout.addView(text1)
108- rootLayout.addView(text2)
109- rootLayout.addView(helperLinkText)
110- rootLayout.addView(copyHintText)
111- rootLayout.addView(copyButton)
112- rootLayout.addView(tutorialText)
113- rootLayout.addView(viewButton)
114-
115- scrollView.addView(rootLayout)
116- fullScreen.addView(scrollView)
117-
118- setContentView(fullScreen)
11953 }
12054
121- private fun copyToClipboard (text : String ) {
122- val clipboard = getSystemService(Context .CLIPBOARD_SERVICE ) as ClipboardManager
123- val clip = ClipData .newPlainText(" Copied Text" , text)
124- clipboard.setPrimaryClip(clip)
125- Toast .makeText(this , " 已复制" , Toast .LENGTH_SHORT ).show()
126- val intent = Intent (Intent .ACTION_VIEW , Uri .parse(text))
127- startActivity(this , intent, null )
55+ private fun openBrowserLink (url : String ) {
56+ if (url.isNotEmpty()) {
57+ val intent = Intent (Intent .ACTION_VIEW , Uri .parse(url))
58+ startActivity(intent)
59+ }
60+ // 如果URL为空,则不执行任何操作(等待后续补充链接)
12861 }
129- }
62+ }
0 commit comments