autojs悬浮代码例⼦悬浮动画悬浮组件计算源代码分享/**
*完成时间: 2019年3⽉20⽇下午11:24:54
*测试机型: PD1813D
*Auto.js版本: 4.1.0 Alpha5
*屏幕: 1080*2280
*备注: 暂⽆备注
**/
//此代码由飞云脚本圈整理提供(www.feiyunjs)
var悬浮控制=function(window, windowid, ar){
this.Orientation = ientation;
this.Width =this.Orientation ==1? device.width : device.height;
this.Height =this.Orientation ==2? device.width : device.height;
this.isAutoIntScreen =true;
this.Click=function(){};
this.Move=function(){};
this.LongClick=function(){};
this.setClick=(fun)=>{
fun = fun ||function(){};
this.Click = fun;
};
this.setMove=(fun)=>{
fun = fun ||function(){};
this.Move = fun;
};
this.setLongClick=(fun, ji)=>{
fun = fun ||function(){};
this.LongClick = fun;
if(parseInt(ji)){
this.Tjitime =parseInt(ji)/50;
};
};
setInterval(()=>{
ientation !=this.Orientation){
this.Orientation = ientation;
this.Width =this.Orientation ==1? device.width : device.height;
this.Height =this.Orientation ==2? device.width : device.height;
var xy =this.X(), Y(),this.G(window));
this.windowyidong([
[X(), Y()],
[xy.x, xy.y]
]);
};
},100);
this.TX=0;
this.TY=0;
this.Tx =0;
this.Ty =0;
this.Tyidong =false;
this.Tkeep =false;
this.Tjitime =12;
this.Ttime =0;
setInterval(()=>{
if(this.Tkeep){
this.Ttime++;
if(!this.Tyidong &&this.Ttime >this.Tjitime){
/
/⾮移动且按下时长超过1秒判断为长按
this.Tkeep =false;
this.Ttime =0;
this.LongClick();
};
};
},50);
windowid.setOnTouchListener(new android.view.View.OnTouchListener((view, event)=>{ this.Move(view, event);
Action()){
case event.ACTION_DOWN:
this.Tx = RawX();
this.Ty = RawY();
this.TX= X();
this.TY= Y();
this.Tkeep =true;//按下,开启计时
break;
case event.ACTION_MOVE:
var sx = RawX()-this.Tx;
var sy = RawY()-this.Ty;
if(!this.Tyidong &&this.Tkeep &&this.weiyi(sx, sy)>=10){
this.Tyidong =true;
};
if(this.Tyidong &&this.Tkeep){
window.setPosition(this.TX+ sx,this.TY+ sy);
};
break;
case event.ACTION_UP:
if(!this.Tyidong &&this.Tkeep &&this.Ttime <7){
this.Click();
};
this.Tkeep =false;
this.Ttime =0;
if(this.Tyidong){
if(this.isAutoIntScreen){
threads.start(new java.lang.Runnable(()=>{
this.windowyidong(this.IntScreen());
}));
}else{
threads.start(new java.lang.Runnable(()=>{
this.windowyidong(this.ViewIntScreen());
}));
};
this.Tyidong =false;
};
break;
};
return true;
}));
};
this.G=(win, view)=>{
//返回悬浮窗的坐标范围。
var K=36,//悬浮窗的隐形边矩
H=66;//⼿机通知栏的⾼度
var ary;
if(!ar){
if(view){
ary =[
[-X(),-Y()],
[this.Width -(X()+ Width()),this.Height -(Y()+ Height())-H-K] ];
}else{
ary =[
[0,0],
[this.Width - Width()+K*2,this.Height - Height()-H+K*2]
];
}
}else{
if(view){
[-X(),Y()],
[this.Width -(X()+ Width()),this.Height -(Y()+ Height())]
];
}else{
ary =[
[0,H],
[this.Width - Width(),this.Height - Height()]
];
}
};
return ary;
};
this.weiyi=function(){//平⽅和开⽅
var num =0;
for(var i =0; i < arguments.length; i++){
num += arguments[i]* arguments[i];
};
und(Math.sqrt(num)*1000)/1000
};
this.windowGXY=function(x, y, k){
//修正坐标的所在范围。如果坐标超出了范围,则修正回来。
x =(k[0][0]< x && x < k[1][0])? x :(k[0][0]< x ? k[1][0]: k[0][0]);
y =(k[0][1]< y && y < k[1][1])? y :(k[0][1]< y ? k[1][1]: k[0][1]);
return{
x: x,
y: y
};
};
this.windowyidong=(A, s, w)=>{
//移动悬浮窗的动画效果。
w = w || window;
s = s ||10;
var sx =A[1][0]-A[0][0],
sy =A[1][1]-A[0][1];
var sd =this.weiyi(sx, sy)/ s;
var X= sx / sd,
Y= sy / sd;
var x =0,
y =0;
for(var i =0; i < sd; i++){
x +=X;
y +=Y;
sleep(1);
w.setPosition(A[0][0]+ x,A[0][1]+ y);
};
w.setPosition(A[1][0],A[1][1]);
};
this.OutScreen=()=>{
//算出最短的距离到达屏幕之外。
var F=this.G(window);
var x = X(),
y = Y();
var sx = X()+ Width()/2,
sy = Y()+ Height()/2+66;
var cx = Math.abs(sx <(this.Width - sx)? sx :(this.Width - sx))< Math.abs(sy <(this.Height - sy)? sy :(this.Height - sy))?(sx <this.Width /2?(F[0][ 0]- Width()):(F[1][0]+ Width())): x,
cy = Math.abs(sx <(this.Width - sx)? sx :(this.Width - sx))< Math.abs(sy <(this.Height - sy)? sy :(this.Height - sy))? y :(sy <this.Height /2?(F[ 0][1]- Height()):(F[1][1]+ Height()));
return[
[x, y],
[cx, cy]
];
};
//返回到屏幕边缘的坐标。d为浮点数0.1~1之间。
d = d ||0;
var F=this.G(window);
var x = X(),
y = Y();
var sw = Width()* d;
var sx = X()+ Width()/2,
sy = Y()+ Height()/2+66;
var cx = sx <(this.Width - sx)?-sw :(this.Width + sw - Width()+72);
return[
[x, y],
[cx, y]
]
;
};
//返回距离中⼼位置的⼀个⽅形两个坐标。
var w = Width();
var h = Height();
return[
js arguments
[F[0]+ w /2,F[1]+ h /2],
[F[0]- w /2,F[1]- h /2]
];
};
this.IntScreen=()=>{
//当悬浮超出屏幕之外之后进⼊的坐标。
var A=this.X(), Y(),this.G(window));
return[
[X(), Y()],
[A.x,A.y]
];
};
this.ViewIntScreen=()=>{
//当悬浮超出屏幕之外之后进⼊的坐标。
var A=this.X(), Y(),this.G(window, windowid));
return[
[X(), Y()],
[A.x,A.y]
];
};
threads.start(new java.lang.Runnable(()=>{
this.windowyidong(this.IntScreen());
}));
};
var window = floaty.window(
<vertical bg="#ffeeeeee" padding="5" h="{{Math.floor(device.height*0.7)}}px">
<frame>
<text id="text" w="*" gravity="center" maxLines="1" ellipsize="end"/>
<progressbar id="progress" w="*" h="auto" indeterminate="true" layout_gravity="top" />
</frame>
<frame layout_weight="1">
<webview id="webview" w="*" h="*"/>
<list id="list" w="90dp" h="*" bg="#346489" layout_gravity="right">
<text w="*" h="50" text="{{txt}}" textSize="16sp" bg="#dddddd" margin="5" gravity="center"/>
</list>
</frame>
<horizontal w="*">
<button id="left"  text="上页" layout_weight="1"/>
<button id="center"  text="菜单" layout_weight="1"/>
<button id="right" text="下页" layout_weight="1"/>
</horizontal>
<button id="move"  text="移动及最⼩化" w="*"/>
</vertical>
);
var window_ = floaty.window(
<button id="but_" w="150px" h="150px" text="▽" alpha="0.7"/>
);
var ad =new悬浮控制(window, ve);
ad.isAutoIntScreen =false;
var ad_ =new悬浮控制(window_, window_.but_);
ad.setLongClick(exit);
ad_.setLongClick(exit);
var F= ad.OutScreen();
var F_= ad_.OutScreen();
threads.start(function(){
sleep(100);
F_= ad_.OutScreen();
ad_.windowyidong(F_);
});
ad.setClick(function(){
window.disableFocus();
threads.start(function(){
F= ad.OutScreen();
ad.windowyidong(F);
ad_.windowyidong([F_[1], ad_.XY(F[0])[0])[1]]);        ad_.windowyidong(ad_.IntScreen());
ad_.windowyidong(ad_.toScreenEdge(0));
});
});
ad_.setClick(function(){
window.disableFocus();
threads.start(function(){
F_= ad_.OutScreen();
ad_.windowyidong(F_);
ad.windowyidong([F[1], ad.centerXY(ad_.centerXY(F_[0])[0])[1]]);        ad.windowyidong(ad.IntScreen());
});
});
ui.run(()=>{
window.list.setVisibility(8);
});
var listArray =[{
txt:"Auto.js官⽅⽂档",
url:"hyb1996.github.io/AutoJs-Docs"
},
{
txt:"百度",
url:"www.baidu"
},
{
url:"www.runoob/jsref/jsref-tutorial.html",
txt:"javascript"
},
{
url:"www.runoob/jsref/jsref-obj-array.html",
txt:"array"
},
{
url:"www.runoob/jsref/jsref-obj-boolean.html",
txt:"boolean"

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。