require "import"
import "android.widget.*"
import "android.view.WindowManager"

local layout={
LinearLayout;
orientation="vertical";
layout_width="fill";
layout_height="fill";
background="#ff000000";
{
ScrollView;
layout_width=-1;
layout_height="0dp";
layout_weight=0.8;
{
TextView;
text=service.getText(node),
Gravity="center";
background="#ff000000";
textColor="#ffffffff";
id="tv1";
layout_width=-1;
textSize="200sp";
};
};
{
SeekBar;
layout_marginTop="10dp";
layout_marginLeft="20dp";
layout_marginRight="20dp";
layout_width="fill";
layout_height="0dp";
layout_weight=0.05;
max=100; -- 最大值为100
progress=50; -- 初始值
};
{
EditText;
Gravity="center";
background="#ff000000";
textColor="#ffffffff";
id="e1";
layout_width=-1;
layout_height="0dp";
layout_weight=0.1;
textSize="18sp";
};
}

dlg=LuaDialog(service)
dlg.View=loadlayout(layout)

-- 设置对话框窗口的软输入模式为调整平移
local window = dlg.getWindow()
local layoutParams = window.getAttributes()
layoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN
window.setAttributes(layoutParams)

dlg.show()

-- 获取控件（注意顺序变了）
local edittext = dlg.View.getChildAt(2) -- 现在第三个是编辑框
local seekbar = dlg.View.getChildAt(1)  -- 现在第二个是进度条
local scrollView = dlg.View.getChildAt(0) -- 第一个仍然是ScrollView
local textview = scrollView.getChildAt(0) -- ScrollView中的TextView

-- 获取屏幕高度（使用正确的方法）
local displayMetrics = service.getResources().getDisplayMetrics()
local screenHeight = displayMetrics.heightPixels

-- 设置进度条监听器
seekbar.setOnSeekBarChangeListener{
onProgressChanged=function(seekBar, progress, fromUser)
-- 当进度达到100时，字体大小铺满屏幕
if progress == 100 then
-- 计算铺满屏幕所需的字体大小（使用较大的值）
textview.setTextSize(300) -- 使用一个足够大的固定值
else
-- 正常范围内的字体大小变化
local textSize = 20 + progress * 2 -- 20-220sp的范围
textview.setTextSize(textSize)
end
end
}

-- 设置编辑框文本变化监听器
edittext.addTextChangedListener{
onTextChanged=function(text, start, before, count)
textview.setText(text)
end
}