require "import"
import "android.app.*"
import "android.os.*"
import "android.widget.*"
import "android.view.*"
--import "layout"
import "android.content.Context"
--activity.actionBar.hide()
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
layout={
LinearLayout;
orientation="vertical";
layout_width="match_parent";
layout_height="match_parent";
{
LinearLayout;
backgroundColor="0xFF009AFF";
layout_height="80dp";
layout_width="match_parent";
{
LinearLayout;
layout_height="match_parent";
gravity="center";
layout_width="wrap_content";
{
TextView;
textColor="0xff000000";
layout_marginLeft="15dp";
layout_marginTop="7dp";
textSize="20sp";
text="留言板";
};
};
};
{
ScrollView;
layout_width="match_parent";
layout_height="match_parent";
verticalScrollBarEnabled=false;
{
LinearLayout;
orientation="vertical";
layout_width="match_parent";
layout_height="match_parent";
{
LinearLayout;
layout_height="match_parent";
orientation="vertical";
layout_marginBottom="20dp";
layout_width="match_parent";
gravity="center|bottom";
{
EditText;
layout_width=1040;
id="UserInput";
};
{
CardView;
layout_height="43dp";
backgroundColor="0xFF009AFF";
layout_width=1010;
id="send";
radius="6dp";
{
LinearLayout;
layout_height="match_parent";
layout_width="match_parent";
gravity="center";
{
TextView;
textColor="0xff000000";
text="发送";
};
};
};
};
{
ScrollView;
layout_width="match_parent";
verticalScrollBarEnabled=false;
{
LinearLayout;
orientation="vertical";
layout_width="match_parent";
id="list";
};
};
};
};
};
cjson = import("cjson")
activity.setTitle("留言板")
activity.setContentView(loadlayout(layout))
function 控件圆角(控件,圆角,颜色)
import "android.graphics.drawable.GradientDrawable"
drawable = GradientDrawable()
drawable.setShape(GradientDrawable.RECTANGLE)
drawable.setColor(颜色)
drawable.setCornerRadii({圆角,圆角,圆角,圆角,圆角,圆角,圆角,圆角})
控件.setBackgroundDrawable(drawable)
end
控件圆角(send,20,0xFF009AFF)
function 水珠动画(view,time)
import "android.animation.ObjectAnimator"
ObjectAnimator().ofFloat(view,"scaleX",{1.2,.8,1.1,.9,1}).setDuration(time).start()
ObjectAnimator().ofFloat(view,"scaleY",{1.2,.8,1.1,.9,1}).setDuration(time).start()
end
function 振动()
--vibrator = activity.getSystemService(Context.VIBRATOR_SERVICE)
--vibrator.vibrate( long{10,50} ,-1)
--手册无法使用振动哦~
end
function csh()
Http.get("http://szjlny.cn/lua/table.txt",nil,nil,nil,function(code,content)
Table1 = cjson.decode(content)
function 回复(tid)
InputLayout={
LinearLayout;
orientation="vertical";
Focusable=true,
FocusableInTouchMode=true,
{
TextView;
id="Prompt",
textSize="15sp",
layout_marginTop="10dp";
layout_marginLeft="10dp",
layout_marginRight="10dp",
layout_width="match_parent";
layout_gravity="center",
text="输入:";
};
{
EditText;
hint="输入";
layout_marginTop="5dp";
layout_marginLeft="10dp",
layout_marginRight="10dp",
layout_width="match_parent";
layout_gravity="center",
id="edit";
};
};
AlertDialog.Builder(this)
.setTitle("")
.setView(loadlayout(InputLayout))
.setPositiveButton("确定",{onClick=function(v)
if edit.Text ~="" then
Http.get("http://szjlny.cn/lua/table.txt",nil,nil,nil,function(code,content)
Table1 = cjson.decode(content)
if Table1[tid].reply == "true" then
c = #Table1[tid].ReplyData + 1
Table1[tid].ReplyData[c]=edit.Text
else
Table1[tid].reply="true"
Table1[tid].ReplyData={}
Table1[tid].ReplyData[1]=edit.Text
end
Http.get("http://szjlny.cn/lua/table.php?table="..cjson.encode(Table1),nil,nil,nil,function()
print("回复成功")
activity.setContentView(loadlayout(layout))
控件圆角(send,20,0xFF009AFF)
csh()
end)
end)
else
print("不能为空")
end
end})
.setNegativeButton("取消",nil)
.show()
import "android.view.View$OnFocusChangeListener"
edit.setOnFocusChangeListener(OnFocusChangeListener{
onFocusChange=function(v,hasFocus)
if hasFocus then
Prompt.setTextColor(0xFD009688)
end
end})
end
if Table1 then
count = #Table1
for i=#Table1,1,-1 do
if Table1[count].reply == "true" then
message_layout={
LinearLayout;
layout_width="fill";
layout_height="fill";
gravity="center";
orientation="vertical";
{
CardView;
layout_width=activity.getWidth()-60;
layout_marginTop="10dp";
alpha=0.9;
radius="15dp";
layout_marginBottom="4dp";
onClick=function()回复(i) 振动()end;
{
LinearLayout;
orientation="vertical";
gravity="center|left";
layout_width="fill";
id="lllll";
{
TextView;
text=Table1[count].content;
layout_marginLeft="10dp";
layout_marginTop="20dp";
layout_marginBottom="20dp";
textIsSelectable=true;
textColor="0xff000000";
};
};
};
};
countz = #Table1[count].ReplyData
list.addView(loadlayout(message_layout))
for l=1,countz do
replyLayout={
LinearLayout;
layout_width="fill";
gravity="center";
{
CardView;
layout_width=activity.getWidth()-105;
alpha=0.3;
layout_marginTop="3dp";
layout_marginBottom="3dp";
radius="15dp";
{
TextView;
text="回复:"..Table1[count].ReplyData[l];
layout_marginLeft="10dp";
layout_marginTop="20dp";
layout_marginBottom="20dp";
textIsSelectable=true;
textColor="0xff000000";
};
};
};
list.addView(loadlayout(replyLayout))
end
else
message_layout={
LinearLayout;
layout_width="fill";
layout_height="fill";
gravity="center";
orientation="vertical";
{
CardView;
layout_width=activity.getWidth()-60;
layout_marginTop="10dp";
alpha=0.9;
id="dd";
radius="15dp";
layout_marginBottom="4dp";
onClick=function()回复(i) 振动()end;
{
LinearLayout;
orientation="vertical";
gravity="center|left";
layout_width="fill";
{
TextView;
text=Table1[count].content;
layout_marginLeft="10dp";
layout_marginTop="20dp";
layout_marginBottom="20dp";
textIsSelectable=true;
textColor="0xff000000";
};
};
};
};
list.addView(loadlayout(message_layout))
end
count = count - 1
---table[1].ReplyData[1]
end
function send.onClick()
水珠动画(send,80)
if UserInput.Text ~= "" then
Http.get("http://szjlny.cn/lua/table.txt",nil,nil,nil,function(code,content)
if Table1 == cjson.decode(content) then
count1 = #Table1 + 1
Table1[count1]={}
Table1[count1].content=UserInput.Text
Http.get("http://szjlny.cn/lua/table.php?table="..cjson.encode(Table1),nil,nil,nil,function(code,content) print(content) end)
activity.setContentView(loadlayout(layout))
csh()
else
Table1 = cjson.decode(content)
count1 = #Table1 + 1
Table1[count1]={}
Table1[count1].content=UserInput.Text
Http.get("http://szjlny.cn/lua/table.php?table="..cjson.encode(Table1),nil,nil,nil,function(code,content) print(content) end)
activity.setContentView(loadlayout(layout))
控件圆角(send,20,0xFF009AFF)
csh()
end
end)
else
print("不能为空!")
end
end
end
end)
end
csh()