lua-project/悬浮窗模板(main).lua

884 lines
23 KiB
Lua

--翎乾制作
--二次创作请留名
wmManager=activity.getSystemService(Context.WINDOW_SERVICE) --获取窗口管理器
HasFocus=false --是否有焦点
wmParams =WindowManager.LayoutParams() --对象
if tonumber(Build.VERSION.SDK) >= 26 then
wmParams.type =WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY--安卓8以上悬浮窗打开方式
else
wmParams.type =WindowManager.LayoutParams.TYPE_SYSTEM_ALERT--安卓8以下的悬浮窗打开方式
end
wmParams.format =PixelFormat.RGBA_8888 --设置背景
wmParams.flags=WindowManager.LayoutParams().FLAG_NOT_FOCUSABLE--焦点设置
wmParams.gravity = Gravity.LEFT| Gravity.TOP --重力设置
wmParams.x = activity.getWidth()/6
wmParams.y = activity.getHeight()/5
wmParams.width =WindowManager.LayoutParams.WRAP_CONTENT
wmParams.height =WindowManager.LayoutParams.WRAP_CONTENT
if Build.VERSION.SDK_INT >= Build.VERSION_CODES.M&&!Settings.canDrawOverlays(this) then
print("没有悬浮窗权限悬,请打开权限")
intent=Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION)
intent.setData(Uri.parse("package:" .. activity.getPackageName()));
activity.startActivityForResult(intent, 100)
os.exit()
end
function 开启悬浮窗()
xfq={
LinearLayout;
layout_width="fill";
layout_height="fill";
{
ImageView;
layout_height="27dp";
layout_width="120dp";
onClick="放大";
backgroundColor="0x8929FFFF";
id="图标";
};
};
xfc=
{
LinearLayout;
layout_height="fill";
id="窗体";
layout_width="fill";
backgroundColor="0xffff0000";
{
LinearLayout;
layout_height="280dp";
layout_width="280dp";
backgroundColor="0x4E0056CA";
{
Button;
layout_height="50dp";
text="X";
layout_width="50dp";
id="退出";
};
{
Button;
layout_marginLeft="180dp";
layout_width="50dp";
text="";
layout_height="50dp";
id="隐藏";
};
{
LinearLayout;
layout_marginLeft="-280dp";
orientation="vertical";
layout_width="50dp";
layout_marginTop="50dp";
layout_height="match_parent";
{
Button;
text="";
id="A";
};
{
Button;
text="";
id="B";
};
{
Button;
text="";
id="C";
};
{
Button;
text="";
id="D";
};
{
Button;
text="";
id="E";
};
};
{
ScrollView;
layout_height="match_parent";
layout_marginTop="60dp";
layout_width="match_parent";
backgroundColor="0xffffff00";
{
CardView;
radius="10dp";
layout_width="match_parent";
layout_height="match_parent";
{
LinearLayout;
layout_height="fill";
orientation="vertical";
layout_width="fill";
id="主扳一";
{
Button;
text="功能N";
layout_width="match_parent";
id="a1";
};
{
Button;
text="功能N";
layout_width="match_parent";
id="a2";
};
{
Button;
text="功能N";
layout_width="match_parent";
id="a3";
};
{
Button;
text="功能N";
layout_width="match_parent";
id="a4";
};
{
Button;
text="功能N";
layout_width="match_parent";
id="a5";
};
{
Button;
text="功能N";
layout_width="match_parent";
id="a6";
};
{
Button;
text="功能N";
layout_width="match_parent";
id="a7";
};
{
Button;
text="功能N";
layout_width="match_parent";
id="a8";
};
{
Button;
text="功能N";
layout_width="match_parent";
id="a9";
};
{
Button;
text="功能N";
layout_width="match_parent";
id="a10";
};
{
Button;
text="功能N";
layout_width="match_parent";
id="a11";
};
{
Button;
text="功能N";
layout_width="match_parent";
id="a12";
};
{
Button;
text="功能N";
layout_width="match_parent";
id="a13";
};
{
Button;
text="功能N";
layout_width="match_parent";
id="a14";
};
{
Button;
text="功能N";
layout_width="match_parent";
id="a15";
};
{
Button;
text="功能N";
layout_width="match_parent";
id="a16";
};
{
Button;
text="功能N";
layout_width="match_parent";
id="a17";
};
{
Button;
text="功能N";
layout_width="match_parent";
id="a18";
};
{
Button;
text="功能N";
layout_width="match_parent";
id="a19";
};
{
Button;
layout_width="match_parent";
text="--------翎乾----------";
};
};
{
LinearLayout;
layout_height="fill";
orientation="vertical";
layout_width="fill";
id="主扳二";
{
Button;
text="功能b";
layout_width="match_parent";
id="b1";
};
{
Button;
text="功能b";
layout_width="match_parent";
id="b2";
};
{
Button;
text="功能b";
layout_width="match_parent";
id="b3";
};
{
Button;
text="功能b";
layout_width="match_parent";
id="b4";
};
{
Button;
text="功能b";
layout_width="match_parent";
id="b5";
};
{
Button;
text="功能b";
layout_width="match_parent";
id="b6";
};
{
Button;
text="功能b";
layout_width="match_parent";
id="b7";
};
{
Button;
text="功能b";
layout_width="match_parent";
id="b8";
};
{
Button;
text="功能b";
layout_width="match_parent";
id="b9";
};
{
Button;
text="功能b";
layout_width="match_parent";
id="b10";
};
{
Button;
text="功能b";
layout_width="match_parent";
id="b11";
};
{
Button;
text="功能b";
layout_width="match_parent";
id="b12";
};
{
Button;
text="功能b";
layout_width="match_parent";
id="b13";
};
{
Button;
text="功能b";
layout_width="match_parent";
id="b14";
};
{
Button;
text="功能b";
layout_width="match_parent";
id="b15";
};
{
Button;
text="功能b";
layout_width="match_parent";
id="b16";
};
{
Button;
text="功能b";
layout_width="match_parent";
id="b17";
};
{
Button;
text="功能b";
layout_width="match_parent";
id="b18";
};
{
Button;
text="功能b";
layout_width="match_parent";
id="b19";
};
{
Button;
layout_width="match_parent";
text="-----------------";
};
};
{
LinearLayout;
layout_height="fill";
orientation="vertical";
layout_width="fill";
id="主扳三";
{
Button;
text="功能c";
layout_width="match_parent";
id="c1";
};
{
Button;
text="功能c";
layout_width="match_parent";
id="c2";
};
{
Button;
text="功能c";
layout_width="match_parent";
id="c3";
};
{
Button;
text="功能c";
layout_width="match_parent";
id="c4";
};
{
Button;
text="功能c";
layout_width="match_parent";
id="c5";
};
{
Button;
text="功能c";
layout_width="match_parent";
id="c6";
};
{
Button;
text="功能c";
layout_width="match_parent";
id="c7";
};
{
Button;
text="功能c";
layout_width="match_parent";
id="c8";
};
{
Button;
text="功能c";
layout_width="match_parent";
id="c9";
};
{
Button;
text="功能c";
layout_width="match_parent";
id="c10";
};
{
Button;
text="功能c";
layout_width="match_parent";
id="c11";
};
{
Button;
text="功能c";
layout_width="match_parent";
id="c12";
};
{
Button;
text="功能c";
layout_width="match_parent";
id="c13";
};
{
Button;
text="功能c";
layout_width="match_parent";
id="c14";
};
{
Button;
text="功能c";
layout_width="match_parent";
id="c15";
};
{
Button;
text="功能c";
layout_width="match_parent";
id="c16";
};
{
Button;
text="功能c";
layout_width="match_parent";
id="c17";
};
{
Button;
text="功能c";
layout_width="match_parent";
id="c18";
};
{
Button;
text="功能c";
layout_width="match_parent";
id="c19";
};
{
Button;
layout_width="match_parent";
text="-----------------";
};
};
{
LinearLayout;
layout_height="fill";
orientation="vertical";
layout_width="fill";
id="主扳四";
{
Button;
text="功能d";
layout_width="match_parent";
id="d1";
};
{
Button;
text="功能d";
layout_width="match_parent";
id="d2";
};
{
Button;
text="功能d";
layout_width="match_parent";
id="d3";
};
{
Button;
text="功能d";
layout_width="match_parent";
id="d4";
};
{
Button;
text="功能d";
layout_width="match_parent";
id="d5";
};
{
Button;
text="功能d";
layout_width="match_parent";
id="d6";
};
{
Button;
text="功能d";
layout_width="match_parent";
id="d7";
};
{
Button;
text="功能d";
layout_width="match_parent";
id="d8";
};
{
Button;
text="功能d";
layout_width="match_parent";
id="d9";
};
{
Button;
text="功能d";
layout_width="match_parent";
id="d10";
};
{
Button;
text="功能d";
layout_width="match_parent";
id="d11";
};
{
Button;
text="功能d";
layout_width="match_parent";
id="d12";
};
{
Button;
text="功能d";
layout_width="match_parent";
id="d13";
};
{
Button;
text="功能d";
layout_width="match_parent";
id="d14";
};
{
Button;
text="功能d";
layout_width="match_parent";
id="d15";
};
{
Button;
text="功能d";
layout_width="match_parent";
id="d16";
};
{
Button;
text="功能d";
layout_width="match_parent";
id="d17";
};
{
Button;
text="功能d";
layout_width="match_parent";
id="d18";
};
{
Button;
text="功能d";
layout_width="match_parent";
id="d19";
};
{
Button;
layout_width="match_parent";
text="-----------------";
};
};
{
LinearLayout;
layout_height="fill";
orientation="vertical";
layout_width="fill";
id="主扳五";
{
Button;
text="功能e";
layout_width="match_parent";
id="e1";
};
{
Button;
text="功能e";
layout_width="match_parent";
id="e2";
};
{
Button;
text="功能e";
layout_width="match_parent";
id="e3";
};
{
Button;
text="功能e";
layout_width="match_parent";
id="e4";
};
{
Button;
text="功能e";
layout_width="match_parent";
id="e5";
};
{
Button;
text="功能e";
layout_width="match_parent";
id="e6";
};
{
Button;
text="功能e";
layout_width="match_parent";
id="e7";
};
{
Button;
text="功能e";
layout_width="match_parent";
id="e8";
};
{
Button;
text="功能e";
layout_width="match_parent";
id="e9";
};
{
Button;
text="功能e";
layout_width="match_parent";
id="e10";
};
{
Button;
text="功能e";
layout_width="match_parent";
id="e11";
};
{
Button;
text="功能e";
layout_width="match_parent";
id="e12";
};
{
Button;
text="功能e";
layout_width="match_parent";
id="e13";
};
{
Button;
text="功能e";
layout_width="match_parent";
id="e14";
};
{
Button;
text="功能e";
layout_width="match_parent";
id="e15";
};
{
Button;
text="功能e";
layout_width="match_parent";
id="e16";
};
{
Button;
text="功能e";
layout_width="match_parent";
id="e17";
};
{
Button;
text="功能e";
layout_width="match_parent";
id="e18";
};
{
Button;
text="功能e";
layout_width="match_parent";
id="e19";
};
{
Button;
layout_width="match_parent";
text="-----------------";
};
};
};
};
};
};
=loadlayout(xfq)
=loadlayout(xfc)
function 窗体.OnTouchListener(v,event)--这个图标移动代码
if event.getAction()==MotionEvent.ACTION_DOWN then
firstX=event.getRawX()
firstY=event.getRawY()
wmX=wmParams.x
wmY=wmParams.y
elseif event.getAction()==MotionEvent.ACTION_MOVE then
wmParams.x=wmX+(event.getRawX()-firstX)
wmParams.y=wmY+(event.getRawY()-firstY)
wmManager.updateViewLayout(,wmParams)
elseif event.getAction()==MotionEvent.ACTION_UP then
end
return false
end
function 图标.OnTouchListener(v,event)--这个图标移动代码
if event.getAction()==MotionEvent.ACTION_DOWN then
firstX=event.getRawX()
firstY=event.getRawY()
wmX=wmParams.x
wmY=wmParams.y
elseif event.getAction()==MotionEvent.ACTION_MOVE then
wmParams.x=wmX+(event.getRawX()-firstX)
wmParams.y=wmY+(event.getRawY()-firstY)
wmManager.updateViewLayout(,wmParams)
elseif event.getAction()==MotionEvent.ACTION_UP then
end
return false
end
wmManager.addView(,wmParams)
function 放大()--放大悬浮窗代码
wmManager.removeView()
wmManager.addView(,wmParams )
end
function 隐藏.onClick()--隐藏悬浮窗代码
wmManager.removeView()
wmManager.addView(,wmParams )
end
function 退出.onClick()--退出悬浮窗代码
abcdefghijklmn=nil
wmManager.removeView()
end
.setVisibility(View.INVISIBLE)
.setVisibility(View.INVISIBLE)
.setVisibility(View.INVISIBLE)
.setVisibility(View.INVISIBLE)
function A.onClick()
.setVisibility(View.INVISIBLE)
.setVisibility(View.INVISIBLE)
.setVisibility(View.INVISIBLE)
.setVisibility(View.INVISIBLE)
a="1" .setVisibility(View.VISIBLE)
end
function B.onClick()
b="1"
.setVisibility(View.INVISIBLE)
.setVisibility(View.INVISIBLE)
.setVisibility(View.INVISIBLE)
.setVisibility(View.INVISIBLE)
.setVisibility(View.VISIBLE)
end
function C.onClick()
c="1"
.setVisibility(View.INVISIBLE)
.setVisibility(View.INVISIBLE)
.setVisibility(View.INVISIBLE)
.setVisibility(View.INVISIBLE)
.setVisibility(View.VISIBLE)
end
function D.onClick()
d="1"
.setVisibility(View.INVISIBLE)
.setVisibility(View.INVISIBLE)
.setVisibility(View.INVISIBLE)
.setVisibility(View.INVISIBLE)
.setVisibility(View.VISIBLE)
end
function E.onClick()
e="1"
.setVisibility(View.INVISIBLE)
.setVisibility(View.INVISIBLE)
.setVisibility(View.INVISIBLE)
.setVisibility(View.INVISIBLE)
.setVisibility(View.VISIBLE)
end
-----------------------------------------
--下面放funcrion
function a1.onClick()
print("1")
end
end
--调用
--开启悬浮窗() 关闭悬浮窗()
function 关闭悬浮窗()
wmManager.removeView()
wmManager.removeView()
end
-------------
function 开启.onClick()
if abcdefghijklmn==nil
()
abcdefghijklmn=1
else
abcdefghijklmn=nil
()
end
end