-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.lua
More file actions
235 lines (218 loc) · 6.53 KB
/
Copy pathsettings.lua
File metadata and controls
235 lines (218 loc) · 6.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
require "import"
import "android.os.*"
import "android.graphics.Color"
import "android.graphics.drawable.ColorDrawable"
import "androidx.appcompat.widget.LinearLayoutCompat"
import "com.google.android.material.slider.Slider"
import "com.google.android.material.button.MaterialButton"
import "android.widget.TextView"
import "android.view.Gravity"
import "android.util.TypedValue"
import "com.google.android.material.materialswitch.MaterialSwitch"
import "com.google.android.material.textview.MaterialTextView"
import "android.view.View"
import "android.widget.ImageView"
import "android.content.Intent"
import "android.net.Uri"
activity.setRequestedOrientation(1);
activity.setTheme(R.style.Theme_Material3_Blue)
local supportActionBar = activity.supportActionBar
supportActionBar.setTitle("AndLua Tetris")
supportActionBar.setSubtitle("设置")
supportActionBar.setBackgroundDrawable(ColorDrawable(Color.parseColor("#1c2026")))
supportActionBar.setDisplayHomeAsUpEnabled(true)
local typedValue = TypedValue()
activity.getTheme().resolveAttribute(android.R.attr.textColorPrimary, typedValue, true)
local textColorRes = typedValue.resourceId ~= 0 and typedValue.resourceId or android.R.color.black
local textColor = activity.getResources().getColor(textColorRes, activity.getTheme())
local main = {
LinearLayoutCompat,
orientation = "vertical",
layout_width = "fill",
layout_height = "fill",
gravity = "start",
paddingTop = "50dp",
{
LinearLayoutCompat,
layout_width="fill",
layout_height="wrap",
layout_margin="24dp",
orientation="horizontal",
gravity="center_vertical",
{
MaterialTextView,
layout_width="0dp",
layout_height="wrap",
layout_weight="1",
text="振动",
textSize="16sp",
textColor=textColor,
},
{
MaterialSwitch,
id="shadowSwitch",
layout_width="wrap",
layout_height="wrap",
checked = (activity.getSharedData("shadowEnabled") or "true") == "true",
},
},
-- 分隔线
{
View,
layout_width = "fill",
layout_height = "1dp",
layout_marginLeft = "24dp",
layout_marginRight = "24dp",
layout_marginTop = "8dp",
layout_marginBottom = "8dp",
background = ColorDrawable(Color.parseColor("#1f1f1f")),
},
{
Slider,
id = "slider",
layout_width = "fill",
layout_height = "wrap",
valueFrom = 50,
valueTo = 2000,
value = tonumber(activity.getSharedData("fallDelay") or 1000),
stepSize = 10,
paddingLeft = "24dp",
paddingRight = "24dp",
},
{
TextView,
id = "valueText",
layout_width = "wrap_content",
layout_height = "wrap_content",
textSize = "18sp",
textColor = textColor,
paddingLeft = "24dp",
paddingTop = "8dp",
gravity = "start",
},
{
MaterialButton,
id = "resetBtn",
layout_width = "wrap_content",
layout_height = "wrap_content",
text = "设为默认(1000)",
layout_marginLeft = "24dp",
layout_marginTop = "16dp",
},
-- 分隔线
{
View,
layout_width = "fill",
layout_height = "1dp",
layout_marginLeft = "24dp",
layout_marginRight = "24dp",
layout_marginTop = "24dp",
layout_marginBottom = "8dp",
background = ColorDrawable(Color.parseColor("#1f1f1f")),
},
-- 关于栏
{
LinearLayoutCompat,
layout_width = "fill",
layout_height = "wrap",
orientation = "horizontal",
gravity = "center_vertical",
paddingLeft = "24dp",
paddingRight = "24dp",
paddingTop = "12dp",
paddingBottom = "12dp",
{
ImageView,
layout_width = "24dp",
layout_height = "24dp",
src = "ic_info.png",
layout_marginRight = "16dp",
},
{
MaterialTextView,
layout_width = "0dp",
layout_height = "wrap",
layout_weight = "1",
text = "AndLua Tetris V1.3\nBy Slime",
textSize = "14sp",
textColor = textColor,
},
},
-- 分隔线
{
View,
layout_width = "fill",
layout_height = "1dp",
layout_marginLeft = "24dp",
layout_marginRight = "24dp",
layout_marginTop = "8dp",
layout_marginBottom = "8dp",
background = ColorDrawable(Color.parseColor("#1f1f1f")),
},
-- 跳转栏
{
LinearLayoutCompat,
id = "jumpLayout",
layout_width = "fill",
layout_height = "wrap",
orientation = "horizontal",
gravity = "center_vertical",
paddingLeft = "24dp",
paddingRight = "24dp",
paddingTop = "12dp",
paddingBottom = "12dp",
{
ImageView,
layout_width = "24dp",
layout_height = "24dp",
src = "ic_open.png",
layout_marginRight = "16dp",
},
{
MaterialTextView,
layout_width = "0dp",
layout_height = "wrap",
layout_weight = "1",
text = "GitHub",
textSize = "14sp",
textColor = textColor,
},
},
}
activity.setContentView(loadlayout(main))
shadowSwitch.setOnCheckedChangeListener(luajava.createProxy("android.widget.CompoundButton$OnCheckedChangeListener", {
onCheckedChanged = function(btn, isChecked)
activity.setSharedData("shadowEnabled", tostring(isChecked))
end
}))
valueText.setText(string.format("游戏速度:%d(每%d毫秒下落一次)",
math.floor(slider.getValue() + 0.5),
math.floor(slider.getValue() + 0.5)))
slider.addOnChangeListener(Slider.OnChangeListener{
onValueChange = function(slider, value, fromUser)
valueText.setText(string.format("游戏速度:%d(每%d毫秒下落一次)",
math.floor(value + 0.5),
math.floor(value + 0.5)))
activity.setSharedData("fallDelay", tostring(math.floor(value + 0.5)))
end
})
resetBtn.setOnClickListener(luajava.createProxy("android.view.View$OnClickListener", {
onClick = function(v)
slider.setValue(1000)
valueText.setText("游戏速度:1000(每1000毫秒下落一次)")
activity.setSharedData("fallDelay", "1000")
end
}))
jumpLayout.setOnClickListener(luajava.createProxy("android.view.View$OnClickListener", {
onClick = function(v)
local uri = Uri.parse("https://github.com/SlimeABC/AndLua-Tetris")
local intent = Intent(Intent.ACTION_VIEW, uri)
activity.startActivity(intent)
end
}))
function onOptionsItemSelected(item)
if item.getItemId() == android.R.id.home then
activity.finish()
end
return true
end