Autojs 悬浮菜单 欢迎大佬指导
/**
* 通用悬浮窗框架
*/
auto.waitFor()
function FloatyMenu() { }
FloatyMenu.prototype.floatyBtn = function (e, x, y, imgBgColor, src, clickFunc) {
e.Src = src;
e.ImgBgColor = imgBgColor;
let btn = e.floaty.window(
<frame gravity="center">
<frame w="44" h="44" alpha="1">
<img w="44" h="44" src="{{ImgBgColor}}" circle="true" />
<img w="28" h="28" src="{{Src}}" tint="#ffffff" gravity="center" layout_gravity="center" />
<img id="imgBtn" w="*" h="*" src="#ffffff" circle="true" alpha="0" />
</frame>
</frame>
);
btn.setPosition(x, y)
btn.imgBtn.on("click", () => {
clickFunc()
})
this.btnList.push({ "btn": btn, "x": x, "y": y })
return btn;
}
FloatyMenu.prototype.childBtnIsShow = false
FloatyMenu.prototype.btnList = []
FloatyMenu.prototype.setIngPageStatus = true
FloatyMenu.prototype.upSetIngPageStatus = function () {
if (floatyMenu.setIngPageStatus) {
floatyMenu.setingPage.setSize(1, 1)
floatyMenu.setingPage.setPosition(-2, -2)
floatyMenu.setingPage.disableFocus();
} else {
floatyMenu.setingPage.setSize(-1, -1)
floatyMenu.setingPage.setPosition(10, 20)
floatyMenu.setingPage.requestFocus();
}
floatyMenu.setIngPageStatus = !floatyMenu.setIngPageStatus
}
FloatyMenu.prototype.upChildBtn = function () {
if (!this.childBtnIsShow) {
for (j = 1, len = this.btnList.length; j < len; j++) {
btnData = this.btnList[j]
b = btnData.btn;
b.setPosition(btnData.x, btnData.y)
}
} else {
for (j = 1, len = this.btnList.length; j < len; j++) {
btnData = this.btnList[j]
b = btnData.btn;
b.setPosition(-100, -100)
}
}
this.childBtnIsShow = !this.childBtnIsShow
}
FloatyMenu.prototype.show = function (e, palyBtnClick, stopBtnClick, setingBtnClick, exitBtnClick) {
floatyMenu = this
//主控制器
this.setingPage = e.floaty.window(
<frame gravity="center">
<vertical bg="#f0f3f6" id="context" padding="20" >
<text text="精选投放" />
<vertical>
<card >
<horizontal padding="20 10 20 10">
<text text="精选数量:" w="100" />
<input id="jxnumber" w="400" text="请输入你的名字" focusable="true" inputType="number" text="{{jxNum}}" />
</horizontal>
</card>
</vertical>
<text text="指定关键字投放" marginTop="50px" />
<vertical >
<card >
<vertical padding="20 ">
<horizontal>
<text text="搜索关键字:" w="100" />
<input id="ssKey" w="400" focusable="true" number="true" text="{{ssKey}}" textImeMultiLine="true" textMultiLine="true" />
</horizontal>
<horizontal>
<text text="数量:" w="100" />
<input id="ssnumber" w="400" focusable="true" inputType="number" text="{{ssNum}}" />
</horizontal>
</vertical>
</card>
</vertical>
<text text="任务详情" marginTop="50px" />
<vertical >
<card >
<vertical padding="20 ">
<horizontal>
<text text="精投剩余: " /> <text id="jssy" text="" textColor="red" /> <text text=" " textColor="red" />
<text text="正在投放关键字: " /> <text id="gjz" text="" textColor="red" /><text text=" " textColor="red" />
<text text="此投放剩余: " /> <text id="gjzsy" text="" textColor="red" />
</horizontal>
</vertical> </card>
</vertical>
</vertical>
</frame>
);
this.upSetIngPageStatus()
mainController = this.floatyBtn(e, 10, 350, "#44009687", "http://www.autojs.org/assets/uploads/profile/3-profileavatar.png", function () {
})
mainController.setSize(120, 120)
//菜单一
this.floatyBtn(e, 25, 250, "#009687", "@drawable/ic_play_arrow_black_48dp", function () {
floatyMenu.upChildBtn()
if (floatyMenu.setIngPageStatus) {
floatyMenu.upSetIngPageStatus()
}
palyBtnClick()
})
//菜单二
this.floatyBtn(e, 100, 305, "#40a5f3", "@drawable/ic_stop_black_48dp", function () {
floatyMenu.upChildBtn()
if (floatyMenu.setIngPageStatus) {
floatyMenu.upSetIngPageStatus()
}
stopBtnClick()
})
this.floatyBtn(e, 100, 395, "#bfc1c0", "@drawable/ic_settings_black_48dp", function () {
floatyMenu.upChildBtn()
floatyMenu.upSetIngPageStatus()
setingBtnClick()
})
//菜单四
this.floatyBtn(e, 25, 450, "#ee534f", "@drawable/ic_clear_black_48dp", function () {
floatyMenu.upChildBtn()
exitBtnClick()
if (floatyMenu.setIngPageStatus) {
floatyMenu.upSetIngPageStatus()
}
// exit()
for (j = 1, len = floatyMenu.btnList.length; j < len; j++) {
btnData = floatyMenu.btnList[j]
b = btnData.btn;
b.setPosition(-100, -1)
}
})
//设置界面
//隐藏
floatyMenu.upChildBtn()
//主控制按钮移动
mainController.imgBtn.setOnTouchListener(function (view, event) {
switch (event.getAction()) {
case event.ACTION_DOWN:
floatyMenu.upChildBtn()
return true;
case event.ACTION_MOVE:
if (floatyMenu.childBtnIsShow) {
return true;
}
btnData = floatyMenu.btnList[0]
moveX = Math.abs(btnData.x - event.getRawX())
moveY = Math.abs(btnData.y - event.getRawY())
if (moveY > 10) {
mainController.setPosition(event.getRawX(), event.getRawY() - 60)
}
return true;
case event.ACTION_UP:
//手指弹起
deviceWidth = device.width
oldMainBtn = floatyMenu.btnList[0]
mainController.setPosition(10, event.getRawY() - 60)
newBtnList = []
newBtnList.push(oldMainBtn)
for (j = 1, len = floatyMenu.btnList.length; j < len; j++) {
btnData = floatyMenu.btnList[j]
y = event.getRawY() - 60
differenceValue = oldMainBtn.y - btnData.y
btnData.y = Math.abs(y - differenceValue);
newBtnList.push(btnData)
}
oldMainBtn.x = 10
oldMainBtn.y = event.getRawY() - 60
newBtnList[0] = oldMainBtn;
floatyMenu.btnList = newBtnList;
return true;
}
return true;
});
}
//使用方法
var Src;
var ImgBgColor;
var jxNum = 0;
var ssKey = "";
var ssNum = 0;
var floatyMenu = new FloatyMenu();
floatyMenu.show(this, function () { log(1) }, function () { log(2) }, function () { log(3) }, function () { log(4) })
setInterval(() => { }, 1000);
欢迎加群交流q552370492